Repository navigation
Expand file tree
/
Copy pathdiffPanelStore.test.ts
More file actions
118 lines (110 loc) · 3.89 KB
/
Copy pathdiffPanelStore.test.ts
File metadata and controls
118 lines (110 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { EnvironmentId, ThreadId, TurnItemId } from "@t3tools/contracts";
import * as DateTime from "effect/DateTime";
import { scopedThreadKey } from "@t3tools/client-runtime/environment";
import { beforeEach, describe, expect, it } from "vite-plus/test";
import {
resolveToolCallDiffTarget,
useDiffPanelSessionStore,
useDiffPanelStore,
} from "./diffPanelStore";
describe("diffPanelStore", () => {
beforeEach(() => {
useDiffPanelStore.setState({
byThreadKey: {},
branchBaseRefByThreadKey: {},
});
useDiffPanelSessionStore.setState({ collapsedFileKeysByScopeKey: {} });
});
it("keeps a tool call selection independent of checkpoints and allows returning to Git changes", () => {
const ref = { environmentId: EnvironmentId.make("env"), threadId: ThreadId.make("thread") };
const target = {
threadId: ThreadId.make("child"),
itemId: TurnItemId.make("edit"),
revision: "1",
};
const store = useDiffPanelStore.getState();
store.selectToolCall(ref, target);
store.reconcileTurnSelection(ref, []);
expect(useDiffPanelStore.getState().byThreadKey[scopedThreadKey(ref)]).toEqual({
kind: "tool-call",
...target,
});
store.selectGitScope(ref, "branch");
expect(useDiffPanelStore.getState().byThreadKey[scopedThreadKey(ref)]).toEqual({
kind: "branch",
baseRef: null,
});
});
it("refreshes a live tool-call target when its source item completes", () => {
const target = {
threadId: ThreadId.make("child"),
itemId: TurnItemId.make("edit"),
revision: "live",
};
const now = DateTime.makeUnsafe("2026-10-28T00:00:00Z");
const row = {
position: 0,
visibility: "local" as const,
sourceThreadId: target.threadId,
sourceItemId: target.itemId,
item: {
id: target.itemId,
threadId: target.threadId,
runId: null,
nodeId: null,
providerThreadId: null,
providerTurnId: null,
nativeItemRef: null,
parentItemId: null,
ordinal: 1,
status: "running" as const,
title: null,
startedAt: now,
completedAt: null,
updatedAt: now,
type: "file_change" as const,
fileName: "a.ts",
},
};
expect(resolveToolCallDiffTarget(target, [row])).toBe(target);
const completed = {
...row,
item: { ...row.item, status: "completed" as const, completedAt: now },
};
expect(resolveToolCallDiffTarget(target, [completed])).toEqual({
...target,
revision: DateTime.formatIso(now),
});
expect(
resolveToolCallDiffTarget(target, [{ ...completed, sourceThreadId: ThreadId.make("other") }]),
).toBe(target);
expect(resolveToolCallDiffTarget(target, [])).toBe(target);
});
it("retains fold choices when a panel consumer returns with fresh defaults", () => {
const scopeKey = "environment-1:thread-1:branch";
const defaults = new Set(["src/app.ts", "src/index.ts"]);
useDiffPanelSessionStore.getState().updateCollapsedFileKeys(scopeKey, defaults, (current) => {
const next = new Set(current);
next.delete("src/app.ts");
return next;
});
expect(useDiffPanelSessionStore.getState().collapsedFileKeysByScopeKey[scopeKey]).toEqual(
new Set(["src/index.ts"]),
);
useDiffPanelSessionStore.getState().updateCollapsedFileKeys(scopeKey, new Set(), (current) => {
const next = new Set(current);
next.delete("src/index.ts");
return next;
});
expect(useDiffPanelSessionStore.getState().collapsedFileKeysByScopeKey[scopeKey]).toEqual(
new Set(),
);
useDiffPanelSessionStore
.getState()
.updateCollapsedFileKeys(scopeKey, defaults, (current) => current);
expect(useDiffPanelSessionStore.getState().collapsedFileKeysByScopeKey[scopeKey]).toEqual(
new Set(),
);
expect(defaults).toEqual(new Set(["src/app.ts", "src/index.ts"]));
});
});