|
| 1 | +import assert from "node:assert/strict"; |
| 2 | +import { spawnSync } from "node:child_process"; |
| 3 | +import { readFileSync } from "node:fs"; |
| 4 | +import test from "node:test"; |
| 5 | + |
| 6 | +const docs = ["skills/acpx/SKILL.md", "docs/CLI.md", "docs/index.md"]; |
| 7 | + |
| 8 | +test("documented jq pipelines select raw ACP tool calls and sparse updates", (t) => { |
| 9 | + const jq = spawnSync("jq", ["--version"], { encoding: "utf8" }); |
| 10 | + if (jq.error && "code" in jq.error && jq.error.code === "ENOENT") { |
| 11 | + t.skip("jq is required to execute the documented automation examples"); |
| 12 | + return; |
| 13 | + } |
| 14 | + assert.equal(jq.status, 0, jq.stderr); |
| 15 | + |
| 16 | + const updates = [ |
| 17 | + { sessionUpdate: "agent_message_chunk", content: { type: "text", text: "Hello" } }, |
| 18 | + { sessionUpdate: "tool_call", toolCallId: "read-1", status: "in_progress", title: "Read" }, |
| 19 | + { sessionUpdate: "tool_call_update", toolCallId: "read-1", status: "completed" }, |
| 20 | + { sessionUpdate: "tool_call_update", toolCallId: "read-1", title: "Read README" }, |
| 21 | + { sessionUpdate: "tool_call_update", toolCallId: "read-1", content: [] }, |
| 22 | + ]; |
| 23 | + const frames = [ |
| 24 | + { jsonrpc: "2.0", id: 1, method: "initialize", params: { protocolVersion: 1 } }, |
| 25 | + ...updates.map((update) => ({ |
| 26 | + jsonrpc: "2.0", |
| 27 | + method: "session/update", |
| 28 | + params: { sessionId: "session-1", update }, |
| 29 | + })), |
| 30 | + { jsonrpc: "2.0", id: 2, result: { stopReason: "end_turn" } }, |
| 31 | + ]; |
| 32 | + const input = frames.map((frame) => JSON.stringify(frame)).join("\n"); |
| 33 | + |
| 34 | + for (const doc of docs) { |
| 35 | + const source = readFileSync(doc, "utf8"); |
| 36 | + const filters = [...source.matchAll(/\| jq -r '([^']+)'/g)]; |
| 37 | + assert.equal(filters.length, 1, `${doc}: expected one automation pipeline`); |
| 38 | + const result = spawnSync("jq", ["-r", filters[0][1]], { input, encoding: "utf8" }); |
| 39 | + assert.equal(result.status, 0, `${doc}: ${result.stderr}`); |
| 40 | + assert.equal(result.stdout, "in_progress\tRead\ncompleted\t-\n-\tRead README\n-\t-\n", doc); |
| 41 | + } |
| 42 | +}); |
0 commit comments