89 lines
2.9 KiB
TypeScript
89 lines
2.9 KiB
TypeScript
import { MessageId, RunId, type OrchestrationV2RunStatus } from "@t3tools/contracts";
|
|
import * as DateTime from "effect/DateTime";
|
|
import { describe, expect, it } from "vite-plus/test";
|
|
|
|
import { v2Projection } from "./orchestrationV2TestFixtures.ts";
|
|
import {
|
|
deriveLatestThreadRun,
|
|
deriveThreadActivityRun,
|
|
deriveThreadRuntime,
|
|
threadRuntimeHasInterruptibleRun,
|
|
} from "./threadExecution.ts";
|
|
|
|
const now = DateTime.makeUnsafe("2026-07-28T10:00:00.000Z");
|
|
|
|
function run(id: string, ordinal: number, status: OrchestrationV2RunStatus) {
|
|
return {
|
|
id: RunId.make(id),
|
|
threadId: v2Projection.thread.id,
|
|
ordinal,
|
|
providerInstanceId: v2Projection.thread.providerInstanceId,
|
|
modelSelection: v2Projection.thread.modelSelection,
|
|
providerThreadId: null,
|
|
userMessageId: MessageId.make(`message-${id}`),
|
|
rootNodeId: null,
|
|
activeAttemptId: null,
|
|
status,
|
|
requestedAt: now,
|
|
startedAt: status === "queued" ? null : now,
|
|
completedAt: null,
|
|
checkpointId: null,
|
|
contextHandoffId: null,
|
|
};
|
|
}
|
|
|
|
describe("thread execution presentation", () => {
|
|
it("keeps live activity attached to an executing run when a newer run is queued", () => {
|
|
const runningRun = run("run-running", 1, "running");
|
|
const queuedRun = run("run-queued", 2, "queued");
|
|
const projection = { ...v2Projection, runs: [queuedRun, runningRun], updatedAt: now };
|
|
|
|
expect(deriveLatestThreadRun(projection)?.runId).toBe(queuedRun.id);
|
|
expect(deriveThreadActivityRun(projection)).toMatchObject({
|
|
runId: runningRun.id,
|
|
status: "running",
|
|
});
|
|
|
|
const runtime = deriveThreadRuntime(projection);
|
|
expect(runtime).toMatchObject({
|
|
status: "queued",
|
|
activeRunId: runningRun.id,
|
|
});
|
|
expect(threadRuntimeHasInterruptibleRun(runtime)).toBe(true);
|
|
});
|
|
|
|
it("does not expose a queued-only run as interruptible", () => {
|
|
const queuedRun = run("run-queued", 1, "queued");
|
|
const projection = { ...v2Projection, runs: [queuedRun], updatedAt: now };
|
|
|
|
expect(deriveThreadActivityRun(projection)).toMatchObject({
|
|
runId: queuedRun.id,
|
|
status: "queued",
|
|
});
|
|
|
|
const runtime = deriveThreadRuntime(projection);
|
|
expect(runtime).toMatchObject({
|
|
status: "queued",
|
|
activeRunId: null,
|
|
});
|
|
expect(threadRuntimeHasInterruptibleRun(runtime)).toBe(false);
|
|
});
|
|
|
|
it("keeps checkpoint-wait activity visible without exposing a non-functional interrupt", () => {
|
|
const waitingRun = run("run-waiting", 1, "waiting");
|
|
const projection = { ...v2Projection, runs: [waitingRun], updatedAt: now };
|
|
|
|
expect(deriveThreadActivityRun(projection)).toMatchObject({
|
|
runId: waitingRun.id,
|
|
status: "waiting",
|
|
});
|
|
|
|
const runtime = deriveThreadRuntime(projection);
|
|
expect(runtime).toMatchObject({
|
|
status: "waiting",
|
|
activeRunId: null,
|
|
});
|
|
expect(threadRuntimeHasInterruptibleRun(runtime)).toBe(false);
|
|
});
|
|
});
|