Synthesize runtime state transition fixes for compaction tool-use integrity and long-running handler backpressure. Sources: #33630, #33583 Co-authored-by: Kevin Shenghui <shenghuikevin@gmail.com> Co-authored-by: Theo Tarr <theodore@tarr.com>
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { createRunStateMachine } from "./run-state-machine.js";
|
|
|
|
describe("createRunStateMachine", () => {
|
|
it("resets stale busy fields on init", () => {
|
|
const setStatus = vi.fn();
|
|
createRunStateMachine({ setStatus });
|
|
expect(setStatus).toHaveBeenCalledWith({ activeRuns: 0, busy: false });
|
|
});
|
|
|
|
it("emits busy status while active and clears when done", () => {
|
|
const setStatus = vi.fn();
|
|
const machine = createRunStateMachine({
|
|
setStatus,
|
|
now: () => 123,
|
|
});
|
|
machine.onRunStart();
|
|
machine.onRunEnd();
|
|
expect(setStatus).toHaveBeenNthCalledWith(
|
|
2,
|
|
expect.objectContaining({ activeRuns: 1, busy: true, lastRunActivityAt: 123 }),
|
|
);
|
|
expect(setStatus).toHaveBeenLastCalledWith(
|
|
expect.objectContaining({ activeRuns: 0, busy: false, lastRunActivityAt: 123 }),
|
|
);
|
|
});
|
|
|
|
it("stops publishing after lifecycle abort", () => {
|
|
const setStatus = vi.fn();
|
|
const abortController = new AbortController();
|
|
const machine = createRunStateMachine({
|
|
setStatus,
|
|
abortSignal: abortController.signal,
|
|
now: () => 999,
|
|
});
|
|
machine.onRunStart();
|
|
const callsBeforeAbort = setStatus.mock.calls.length;
|
|
abortController.abort();
|
|
machine.onRunEnd();
|
|
expect(setStatus.mock.calls.length).toBe(callsBeforeAbort);
|
|
});
|
|
});
|