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

threadActivityInspector.test.ts

96 lines2.6 KB

1import { EMPTY_V2_ITEM_SUPPORT } from "@t3tools/client-runtime/state/item-support";
2import {
3 CheckpointId,
4 CheckpointScopeId,
5 NodeId,
6 RunId,
7 ThreadId,
8 TurnItemId,
9 type OrchestrationV2ProjectedTurnItem,
10 type OrchestrationV2TurnItem,
11} from "@t3tools/contracts";
12import * as DateTime from "effect/DateTime";
13import { describe, expect, it } from "vite-plus/test";
14​
15import type { ThreadFeedActivity } from "./threadActivity";
16import { buildThreadActivityInspector } from "./threadActivityInspector";
17​
18const threadId = ThreadId.make("thread-1");
19const sourceThreadId = ThreadId.make("thread-source");
20const runId = RunId.make("run-1");
21const nodeId = NodeId.make("node-1");
22const startedAt = DateTime.makeUnsafe("2026-06-20T00:00:00.000Z");
23const completedAt = DateTime.makeUnsafe("2026-06-20T00:00:02.000Z");
24​
25function itemBase(id: string) {
26 return {
27 id: TurnItemId.make(id),
28 threadId,
29 runId,
30 nodeId,
31 providerThreadId: null,
32 providerTurnId: null,
33 nativeItemRef: null,
34 parentItemId: null,
35 ordinal: 0,
36 status: "completed" as const,
37 title: null,
38 startedAt,
39 completedAt,
40 updatedAt: completedAt,
41 };
43​
44function activityFor(item: OrchestrationV2TurnItem): Pick<ThreadFeedActivity, "projectedItem"> {
45 const row: OrchestrationV2ProjectedTurnItem = {
46 position: 0,
47 visibility: "inherited",
48 sourceThreadId,
49 sourceItemId: item.id,
50 item,
51 };
52 return { projectedItem: row };
54​
55describe("buildThreadActivityInspector", () => {
56 it("enables rollback only for the matching ready checkpoint", () => {
57 const checkpointId = CheckpointId.make("checkpoint-1");
58 const scopeId = CheckpointScopeId.make("scope-1");
59 const item: OrchestrationV2TurnItem = {
60 ...itemBase("checkpoint"),
61 type: "checkpoint",
62 checkpointId,
63 scopeId,
64 files: [{ path: "src/main.ts", kind: "modified", additions: 2, deletions: 1 }],
65 };
66 const checkpoint = { id: checkpointId, scopeId, status: "ready" } as never;
67 const model = buildThreadActivityInspector(
68 activityFor(item),
69 {
70 ...EMPTY_V2_ITEM_SUPPORT,
71 item,
72 checkpoint,
73 },
74 sourceThreadId,
75 );
76​
77 expect(model.canRollback).toBe(true);
78 expect(model.rollbackTarget).toEqual({
79 threadId: sourceThreadId,
80 checkpointId,
81 scopeId,
82 });
83​
84 const inheritedModel = buildThreadActivityInspector(
85 activityFor(item),
86 {
87 ...EMPTY_V2_ITEM_SUPPORT,
88 item,
89 checkpoint,
90 },
91 ThreadId.make("child-thread"),
92 );
93 expect(inheritedModel.canRollback).toBe(false);
94 expect(inheritedModel.rollbackTarget).toBeNull();
95 });
96});