Retain one pending intermediate observation and drop stale live status before terminal cleanup. Preserve monotonic counts and final delivery while an observer is slow or rejects an update. Verify the send rate at its controlled-clock owner and lifecycle notification density at the CLI/MCP boundary, where receive timestamps include buffering and scheduling.
34 lines
848 B
TypeScript
34 lines
848 B
TypeScript
import { expect, it } from "vitest";
|
|
|
|
import { createProgressReporter } from "./ProgressReporter.js";
|
|
|
|
it("limits intermediate sends to 100 ms and always delivers terminal status", async () => {
|
|
let now = 0;
|
|
const sent: number[] = [];
|
|
const reporter = createProgressReporter(
|
|
async () => {
|
|
sent.push(now);
|
|
},
|
|
{ now: () => now },
|
|
);
|
|
for (const [completed, elapsed] of [0, 25, 50, 99, 100, 199, 200].entries()) {
|
|
now = elapsed;
|
|
await reporter.report({
|
|
phase: "running",
|
|
completed,
|
|
total: null,
|
|
message: "Observed capture status",
|
|
});
|
|
}
|
|
expect(sent).toEqual([0, 100, 200]);
|
|
now = 201;
|
|
await reporter.report({
|
|
phase: "cleanup",
|
|
completed: 7,
|
|
total: null,
|
|
message: "Owned cleanup complete",
|
|
terminal: true,
|
|
});
|
|
expect(sent).toEqual([0, 100, 200, 201]);
|
|
});
|