|
| 1 | +/* |
| 2 | + * Copyright (c) 2018-present, easy-4-java. |
| 3 | + * Licensed under the Apache License, Version 2.0. |
| 4 | + */ |
| 5 | +package io.github.easy4j.kimi.acp; |
| 6 | + |
| 7 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 8 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 9 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 10 | + |
| 11 | +import java.nio.file.Paths; |
| 12 | +import java.util.ArrayList; |
| 13 | +import java.util.List; |
| 14 | + |
| 15 | +import org.junit.jupiter.api.Test; |
| 16 | + |
| 17 | +import io.github.easy4j.kimi.model.KimiPromptRequest; |
| 18 | +import io.github.easy4j.kimi.model.KimiPromptResult; |
| 19 | + |
| 20 | +class KimiAcpTypedProtocolE2ETest { |
| 21 | + |
| 22 | + private static final String FAKE_AGENT = Paths.get("src", "test", "resources", "fake-acp-agent.py") |
| 23 | + .toAbsolutePath().toString(); |
| 24 | + |
| 25 | + private static KimiAcpConfig config() { |
| 26 | + KimiAcpConfig config = new KimiAcpConfig(); |
| 27 | + config.setLocalExecutable("python3"); |
| 28 | + config.setAcpSubcommand(null); |
| 29 | + config.setAcpArgs(new String[] {FAKE_AGENT}); |
| 30 | + config.setConnectTimeoutMillis(10_000); |
| 31 | + config.setReadTimeoutMillis(10_000); |
| 32 | + return config; |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + void shouldRunTypedPromptWithoutRemovingRawApi() { |
| 37 | + try (KimiAcpClient client = new KimiAcpClient(config())) { |
| 38 | + client.connect(); |
| 39 | + String sessionId = client.newSession("/tmp"); |
| 40 | + |
| 41 | + KimiPromptRequest request = KimiPromptRequest.builder() |
| 42 | + .sessionId(sessionId) |
| 43 | + .text("typed prompt") |
| 44 | + .build(); |
| 45 | + |
| 46 | + List<String> deltas = new ArrayList<String>(); |
| 47 | + KimiPromptResult result = client.prompt(request, deltas::add); |
| 48 | + |
| 49 | + assertEquals(sessionId, result.getSessionId()); |
| 50 | + assertEquals("end_turn", result.getStopReason().getValue()); |
| 51 | + assertEquals("你好世界", result.getContent()); |
| 52 | + assertEquals(2, deltas.size()); |
| 53 | + |
| 54 | + assertNotNull(client.listSessions(), |
| 55 | + "typed API must be additive; existing raw JsonNode API remains available"); |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + void shouldRejectIncompleteTypedPromptRequest() { |
| 61 | + assertThrows(IllegalStateException.class, |
| 62 | + () -> KimiPromptRequest.builder().text("missing session").build()); |
| 63 | + assertThrows(IllegalStateException.class, |
| 64 | + () -> KimiPromptRequest.builder().sessionId("s").build()); |
| 65 | + } |
| 66 | +} |
0 commit comments