Files
pikasTech-HWLAB/scripts/dev-issue-722-streaming-integration.mjs
Codex 4221760a29 test(issue722): add CLI integration scripts for terminal vs streaming trace rows
- dev-issue-722-trace-integration.mjs: drives hwlab-cli agent trace --render web
  with a 4151-char final response and asserts the rendered terminal row body
  equals the full text without any 内容已截断 marker
- dev-issue-722-streaming-integration.mjs: drives the same path with a long
  non-terminal streaming message and asserts the CLI preview cap still fires
  at 1200 chars + the ... marker, while the terminal row in the same trace
  keeps the full text
- package.json: expose the two scripts as dev:issue-722:* for repeatable
  CLI verification on the v0.2 runtime

Refs: pikasTech/HWLAB#722
2026-06-03 13:43:21 +08:00

37 lines
2.2 KiB
JavaScript

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);
}