diff --git a/package.json b/package.json index 618c3c63..d08f60ce 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,8 @@ "l2:smoke": "node scripts/l2-runtime-contract-smoke.mjs", "dev:evidence": "node scripts/dev-evidence-blocker-aggregator.mjs --pretty", "dev:evidence:check": "node scripts/dev-evidence-blocker-aggregator.mjs --check", + "dev:issue-722:trace-integration": "node scripts/run-bun.mjs scripts/dev-issue-722-trace-integration.mjs", + "dev:issue-722:streaming-integration": "node scripts/run-bun.mjs scripts/dev-issue-722-streaming-integration.mjs", "report:lifecycle": "node scripts/report-lifecycle.mjs", "dev-edge:smoke": "node scripts/dev-edge-health-smoke.mjs", "deploy:contract:plan": "node scripts/run-bun.mjs scripts/deploy-contract-plan.mjs --pretty", diff --git a/scripts/dev-issue-722-streaming-integration.mjs b/scripts/dev-issue-722-streaming-integration.mjs new file mode 100644 index 00000000..6b95fe0d --- /dev/null +++ b/scripts/dev-issue-722-streaming-integration.mjs @@ -0,0 +1,36 @@ +import { runHwlabCli } from "../tools/src/hwlab-cli-lib.ts"; + +const streamingText = "streaming ".repeat(2000); + +const result = await runHwlabCli(["client", "agent", "trace", "trc_stream_722", "--base-url", "http://web.test", "--cookie", "hwlab_session=session-a", "--render", "web", "--full"], { + fetchImpl: async () => new Response(JSON.stringify({ + status: "completed", + traceId: "trc_stream_722", + events: [ + { traceId: "trc_stream_722", seq: 1, label: "request:accepted", status: "accepted", createdAt: "2026-06-02T15:00:00.000Z", promptSummary: "请继续" }, + { traceId: "trc_stream_722", seq: 2, label: "assistant:item_completed", type: "assistant_message", status: "completed", itemId: "msg_streaming", createdAt: "2026-06-02T15:00:01.000Z", message: streamingText }, + { traceId: "trc_stream_722", seq: 3, label: "assistant:completed", type: "assistant_message", terminal: true, status: "completed", itemId: "assistant-final", createdAt: "2026-06-02T15:00:02.000Z", message: "完成" } + ], + assistantStreams: [{ itemId: "msg_streaming", text: streamingText, chunkCount: 1 }, { itemId: "assistant-final", text: "完成", chunkCount: 1 }] + }), { status: 200 }) +}); + +const body = result.payload.body; +const streamingRow = (body.rows ?? []).find((r) => r.rowId === "event:2"); +const terminalRow = (body.rows ?? []).find((r) => r.terminal === true); +console.log("CLI exitCode:", result.exitCode); +console.log("CLI streaming row terminal flag:", streamingRow?.terminal); +console.log("CLI streaming row body length:", streamingRow?.body?.length); +console.log("CLI streaming row has ... marker:", streamingRow?.body?.endsWith("...")); +console.log("CLI terminal row body length:", terminalRow?.body?.length); +console.log("CLI terminal row body === final response text:", terminalRow?.body === "完成"); + +const streamingOk = streamingRow?.body && streamingRow.body.endsWith("...") && streamingRow.body.length <= 1203; +const terminalOk = terminalRow?.body === "完成"; +if (streamingOk && terminalOk) { + console.log(`\nPASS: streaming row CLI preview capped at ${streamingRow.body.length} chars; terminal row keeps full text`); + process.exit(0); +} else { + console.log(`\nFAIL: streamingOk=${streamingOk} terminalOk=${terminalOk}`); + process.exit(1); +} diff --git a/scripts/dev-issue-722-trace-integration.mjs b/scripts/dev-issue-722-trace-integration.mjs new file mode 100644 index 00000000..7dafc8fc --- /dev/null +++ b/scripts/dev-issue-722-trace-integration.mjs @@ -0,0 +1,33 @@ +import { runHwlabCli } from "../tools/src/hwlab-cli-lib.ts"; + +const longFinalResponse = `下面是北京时间 2026-06-02 的开发进展总结。三个仓库共 67 个 PR:HWLAB 39 个(全部已合)、AgentRun 27 个已合 + 1 个 OPEN、unidesk 今天没有 PR。功能开发:HWLAB v0.2 Code Agent 接入 AgentRun v0.1 调度。` + "x".repeat(4000) + " 完。"; + +const result = await runHwlabCli(["client", "agent", "trace", "trc_issue_722", "--base-url", "http://web.test", "--cookie", "hwlab_session=session-a", "--render", "web", "--full"], { + fetchImpl: async () => new Response(JSON.stringify({ + status: "completed", + traceId: "trc_issue_722", + events: [ + { traceId: "trc_issue_722", seq: 1, label: "request:accepted", status: "accepted", createdAt: "2026-06-02T15:09:01.000Z", promptSummary: "总结" }, + { traceId: "trc_issue_722", seq: 6, label: "assistant:completed", type: "assistant_message", terminal: true, status: "completed", itemId: "assistant-final", createdAt: "2026-06-02T15:15:40.000Z", message: longFinalResponse } + ], + assistantStreams: [{ itemId: "assistant-final", text: longFinalResponse, chunkCount: 12 }] + }), { status: 200 }) +}); + +const body = result.payload.body; +const terminalRow = (body.rows ?? []).find((r) => r.terminal === true); +console.log("CLI exitCode:", result.exitCode); +console.log("CLI render:", body?.render); +console.log("CLI body.assistantText length:", body?.assistantText?.length); +console.log("CLI terminal row body length:", terminalRow?.body?.length); +console.log("CLI terminal row body === full text:", terminalRow?.body === longFinalResponse); +console.log("CLI terminal row body has trunc marker:", terminalRow?.body?.includes("内容已截断")); +const expected = longFinalResponse.length; +const actual = terminalRow?.body?.length ?? 0; +if (actual === expected && !terminalRow.body.includes("内容已截断")) { + console.log(`\nPASS: terminal final-response body keeps full ${expected} chars (CLI integration)`); + process.exit(0); +} else { + console.log(`\nFAIL: terminal body length ${actual} != expected ${expected}`); + process.exit(1); +}