Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

threadExecution.test.ts

88 lines2.9 KB

1import { MessageId, RunId, type OrchestrationV2RunStatus } from "@t3tools/contracts";
2import * as DateTime from "effect/DateTime";
3import { describe, expect, it } from "vite-plus/test";
4​
5import { v2Projection } from "./orchestrationV2TestFixtures.ts";
6import {
7 deriveLatestThreadRun,
8 deriveThreadActivityRun,
9 deriveThreadRuntime,
10 threadRuntimeHasInterruptibleRun,
11} from "./threadExecution.ts";
12​
13const now = DateTime.makeUnsafe("2026-07-28T10:00:00.000Z");
14​
15function run(id: string, ordinal: number, status: OrchestrationV2RunStatus) {
16 return {
17 id: RunId.make(id),
18 threadId: v2Projection.thread.id,
19 ordinal,
20 providerInstanceId: v2Projection.thread.providerInstanceId,
21 modelSelection: v2Projection.thread.modelSelection,
22 providerThreadId: null,
23 userMessageId: MessageId.make(`message-${id}`),
24 rootNodeId: null,
25 activeAttemptId: null,
26 status,
27 requestedAt: now,
28 startedAt: status === "queued" ? null : now,
29 completedAt: null,
30 checkpointId: null,
31 contextHandoffId: null,
32 };
34​
35describe("thread execution presentation", () => {
36 it("keeps live activity attached to an executing run when a newer run is queued", () => {
37 const runningRun = run("run-running", 1, "running");
38 const queuedRun = run("run-queued", 2, "queued");
39 const projection = { ...v2Projection, runs: [queuedRun, runningRun], updatedAt: now };
40​
41 expect(deriveLatestThreadRun(projection)?.runId).toBe(queuedRun.id);
42 expect(deriveThreadActivityRun(projection)).toMatchObject({
43 runId: runningRun.id,
44 status: "running",
45 });
46​
47 const runtime = deriveThreadRuntime(projection);
48 expect(runtime).toMatchObject({
49 status: "running",
50 activeRunId: runningRun.id,
51 });
52 expect(threadRuntimeHasInterruptibleRun(runtime)).toBe(true);
53 });
54​
55 it("does not expose a queued-only run as interruptible", () => {
56 const queuedRun = run("run-queued", 1, "queued");
57 const projection = { ...v2Projection, runs: [queuedRun], updatedAt: now };
58​
59 expect(deriveThreadActivityRun(projection)).toMatchObject({
60 runId: queuedRun.id,
61 status: "queued",
62 });
63​
64 const runtime = deriveThreadRuntime(projection);
65 expect(runtime).toMatchObject({
66 status: "queued",
67 activeRunId: null,
68 });
69 expect(threadRuntimeHasInterruptibleRun(runtime)).toBe(false);
70 });
71​
72 it("keeps checkpoint-wait activity visible without exposing a non-functional interrupt", () => {
73 const waitingRun = run("run-waiting", 1, "waiting");
74 const projection = { ...v2Projection, runs: [waitingRun], updatedAt: now };
75​
76 expect(deriveThreadActivityRun(projection)).toMatchObject({
77 runId: waitingRun.id,
78 status: "waiting",
79 });
80​
81 const runtime = deriveThreadRuntime(projection);
82 expect(runtime).toMatchObject({
83 status: "waiting",
84 activeRunId: null,
85 });
86 expect(threadRuntimeHasInterruptibleRun(runtime)).toBe(false);
87 });
88});