71 lines
2.4 KiB
JavaScript
71 lines
2.4 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import {
|
|
buildLongRunningCodexProgressSnapshot,
|
|
normalizeLongRunningProgressIntervalMs,
|
|
} from "./master-task-progress-heartbeat.mjs";
|
|
|
|
test("long-running codex progress snapshot exposes visible waiting state", () => {
|
|
const snapshot = buildLongRunningCodexProgressSnapshot({
|
|
task: {
|
|
taskId: "mastertask-slow",
|
|
targetThreadDisplayName: "juyuwan",
|
|
},
|
|
startedAtMs: Date.parse("2026-06-07T07:35:33.000Z"),
|
|
nowMs: Date.parse("2026-06-07T07:37:03.000Z"),
|
|
phase: "awaiting_reply",
|
|
heartbeatCount: 3,
|
|
});
|
|
|
|
assert.equal(snapshot.phase, "awaiting_reply");
|
|
assert.equal(snapshot.status, "running");
|
|
assert.equal(snapshot.longRunning.elapsedSeconds, 90);
|
|
assert.equal(snapshot.longRunning.heartbeatCount, 3);
|
|
assert.equal(snapshot.steps.length, 5);
|
|
assert.deepEqual(snapshot.steps.map((step) => step.status), [
|
|
"done",
|
|
"done",
|
|
"done",
|
|
"running",
|
|
"pending",
|
|
]);
|
|
assert.equal(snapshot.steps[3].text, "等待目标线程回复,已等待 1 分 30 秒");
|
|
assert.equal(snapshot.warnings[0].id, "codex-turn-long-running");
|
|
});
|
|
|
|
test("long-running codex progress snapshot preserves live app-server steps when available", () => {
|
|
const snapshot = buildLongRunningCodexProgressSnapshot({
|
|
task: {
|
|
taskId: "mastertask-streaming",
|
|
targetThreadDisplayName: "boss",
|
|
},
|
|
startedAtMs: 1_000,
|
|
nowMs: 21_000,
|
|
baseProgress: {
|
|
steps: [
|
|
{ id: "plan-1", text: "读取项目文档", status: "done" },
|
|
{ id: "plan-2", text: "运行验证命令", status: "running" },
|
|
],
|
|
streamEvents: {
|
|
status: "streaming",
|
|
agentDeltaCount: 2,
|
|
},
|
|
},
|
|
});
|
|
|
|
assert.deepEqual(snapshot.steps, [
|
|
{ id: "plan-1", text: "读取项目文档", status: "done" },
|
|
{ id: "plan-2", text: "运行验证命令", status: "running" },
|
|
]);
|
|
assert.equal(snapshot.streamEvents.agentDeltaCount, 2);
|
|
assert.equal(snapshot.longRunning.elapsedSeconds, 20);
|
|
});
|
|
|
|
test("long-running progress interval defaults to fast but bounded updates", () => {
|
|
assert.equal(normalizeLongRunningProgressIntervalMs(undefined), 20_000);
|
|
assert.equal(normalizeLongRunningProgressIntervalMs(1_000), 5_000);
|
|
assert.equal(normalizeLongRunningProgressIntervalMs(120_000), 60_000);
|
|
assert.equal(normalizeLongRunningProgressIntervalMs(0), 0);
|
|
});
|