Skip to content

Commit 8dcd9de

Browse files
committed
test: 同步 generateJson 成功路径夹具测试(Jackson 2 适配)
1 parent 6106e4c commit 8dcd9de

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

‎src/test/java/io/github/easy4j/comfy/ComfyClientTest.java‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.junit.jupiter.api.Test;
2525

2626
import io.github.easy4j.comfy.cli.ComfyCli;
27+
import com.fasterxml.jackson.databind.JsonNode;
2728
import io.github.easy4j.comfy.cli.ComfyCliExecutor;
2829

2930
/**
@@ -77,18 +78,14 @@ void shouldRaiseWhenGenerateJsonPrintsNonJson() {
7778
}
7879

7980
@Test
80-
void shouldParseGenerateJsonOutput() {
81-
// /bin/sh built-ins let us emit a real JSON document for --json runs.
81+
void shouldParseGenerateJsonOutput() throws Exception {
8282
ComfyClientConfig config = echoConfig();
83-
config.setLocalExecutable("/bin/sh");
83+
config.setLocalExecutable(
84+
java.nio.file.Paths.get("src", "test", "resources", "comfy-json.sh").toAbsolutePath().toString());
8485
try (ComfyClient client = new ComfyClient(config)) {
85-
ComfyCli.GenerateOptions options = new ComfyCli.GenerateOptions()
86-
.prompt("x").json(true)
87-
.download("/nonexistent-dir-xyz/out.png");
88-
// echo 不可用,改为直接断言失败路径之外的成功解析:
89-
// 用 sh 打印固定 JSON 并跳过 generateJson(其内部先执行后解析),
90-
// 这里以 mapper 直测——保持端到端语义由 MCP/CLI 契约测试覆盖。
91-
assertTrue(client.version().getExitCode() == 0);
86+
JsonNode json = client.generateJson("flux-pro",
87+
new ComfyCli.GenerateOptions().prompt("hi").json(true));
88+
assertEquals("https://example/asset.png", json.path("data").get(0).path("url").asText());
9289
}
9390
}
9491

‎src/test/resources/comfy-json.sh‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
#
3+
# Test double that emits a fixed JSON document regardless of arguments —
4+
# backs the `generateJson` success path (`comfy generate <model> --json`).
5+
#
6+
cat > /dev/null 2>/dev/null
7+
printf '{"code":0,"msg":"ok","data":[{"url":"https://example/asset.png"}]}'

0 commit comments

Comments
 (0)