@stigmer/ink 3.1.2 → 3.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/SessionView.d.ts.map +1 -1
- package/app/SessionView.js +2 -1
- package/app/SessionView.js.map +1 -1
- package/components/ApprovalPrompt.d.ts +15 -1
- package/components/ApprovalPrompt.d.ts.map +1 -1
- package/components/ApprovalPrompt.js +9 -3
- package/components/ApprovalPrompt.js.map +1 -1
- package/components/FileChangeProgressBar.d.ts +46 -0
- package/components/FileChangeProgressBar.d.ts.map +1 -0
- package/components/FileChangeProgressBar.js +40 -0
- package/components/FileChangeProgressBar.js.map +1 -0
- package/components/FileDiffBody.d.ts +30 -0
- package/components/FileDiffBody.d.ts.map +1 -0
- package/components/FileDiffBody.js +106 -0
- package/components/FileDiffBody.js.map +1 -0
- package/components/FileReviewAtoms.d.ts +23 -0
- package/components/FileReviewAtoms.d.ts.map +1 -0
- package/components/FileReviewAtoms.js +26 -0
- package/components/FileReviewAtoms.js.map +1 -0
- package/components/FileReviewPrompt.d.ts.map +1 -1
- package/components/FileReviewPrompt.js +16 -5
- package/components/FileReviewPrompt.js.map +1 -1
- package/components/FileReviewRecord.d.ts.map +1 -1
- package/components/FileReviewRecord.js +5 -3
- package/components/FileReviewRecord.js.map +1 -1
- package/components/MessageThread.d.ts.map +1 -1
- package/components/MessageThread.js +11 -3
- package/components/MessageThread.js.map +1 -1
- package/file-review.d.ts +27 -3
- package/file-review.d.ts.map +1 -1
- package/file-review.js +43 -6
- package/file-review.js.map +1 -1
- package/index.d.ts +4 -1
- package/index.d.ts.map +1 -1
- package/index.js +4 -1
- package/index.js.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/components.test.tsx +65 -0
- package/src/__tests__/data-pickers.test.tsx +1 -6
- package/src/__tests__/file-change-progress.test.tsx +295 -0
- package/src/__tests__/file-review.test.tsx +318 -3
- package/src/__tests__/test-support.tsx +25 -0
- package/src/app/SessionView.tsx +12 -0
- package/src/components/ApprovalPrompt.tsx +33 -11
- package/src/components/FileChangeProgressBar.tsx +96 -0
- package/src/components/FileDiffBody.tsx +164 -0
- package/src/components/FileReviewAtoms.tsx +37 -0
- package/src/components/FileReviewPrompt.tsx +34 -2
- package/src/components/FileReviewRecord.tsx +11 -0
- package/src/components/MessageThread.tsx +15 -2
- package/src/file-review.ts +59 -6
- package/src/index.ts +9 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { describe, it, expect } from "vitest";
|
|
3
|
+
import { render } from "ink-testing-library";
|
|
4
|
+
import { create } from "@bufbuild/protobuf";
|
|
5
|
+
import {
|
|
6
|
+
FileChangeProgressSchema,
|
|
7
|
+
FileChangeProgressEntrySchema,
|
|
8
|
+
CapturedFileChangeSchema,
|
|
9
|
+
} from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/filereview_pb";
|
|
10
|
+
import type {
|
|
11
|
+
FileChangeProgress,
|
|
12
|
+
FileChangeProgressEntry,
|
|
13
|
+
} from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/filereview_pb";
|
|
14
|
+
import { FileChangeKind } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
|
|
15
|
+
import { FileChangeProgressBar } from "../components/FileChangeProgressBar.js";
|
|
16
|
+
import { changeDisplayPath, progressEntryDisplayPath } from "../file-review.js";
|
|
17
|
+
|
|
18
|
+
// --- fixtures -------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
interface EntryOpts {
|
|
21
|
+
readonly pathBefore?: string;
|
|
22
|
+
readonly pathAfter?: string;
|
|
23
|
+
readonly kind?: FileChangeKind;
|
|
24
|
+
readonly linesAdded?: number;
|
|
25
|
+
readonly linesRemoved?: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function makeEntry(opts: EntryOpts): FileChangeProgressEntry {
|
|
29
|
+
return create(FileChangeProgressEntrySchema, {
|
|
30
|
+
pathBefore: opts.pathBefore ?? "",
|
|
31
|
+
pathAfter: opts.pathAfter ?? "",
|
|
32
|
+
kind: opts.kind ?? FileChangeKind.MODIFY,
|
|
33
|
+
linesAdded: opts.linesAdded ?? 0,
|
|
34
|
+
linesRemoved: opts.linesRemoved ?? 0,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface ProgressOpts {
|
|
39
|
+
readonly filesChanged?: number;
|
|
40
|
+
readonly linesAdded?: number;
|
|
41
|
+
readonly linesRemoved?: number;
|
|
42
|
+
readonly entries?: FileChangeProgressEntry[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function makeProgress(opts: ProgressOpts): FileChangeProgress {
|
|
46
|
+
const entries = opts.entries ?? [];
|
|
47
|
+
return create(FileChangeProgressSchema, {
|
|
48
|
+
changeSetId: "cs-1",
|
|
49
|
+
filesChanged: opts.filesChanged ?? entries.length,
|
|
50
|
+
linesAdded: opts.linesAdded ?? 0,
|
|
51
|
+
linesRemoved: opts.linesRemoved ?? 0,
|
|
52
|
+
entries,
|
|
53
|
+
capturedAt: "2026-07-05T00:00:00Z",
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// --- FileChangeProgressBar: visibility ------------------------------------
|
|
58
|
+
|
|
59
|
+
describe("FileChangeProgressBar — visibility", () => {
|
|
60
|
+
it("renders nothing when progress is undefined", () => {
|
|
61
|
+
const { lastFrame } = render(<FileChangeProgressBar progress={undefined} />);
|
|
62
|
+
expect((lastFrame() ?? "").trim()).toBe("");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("renders nothing when no files have changed yet", () => {
|
|
66
|
+
const { lastFrame } = render(
|
|
67
|
+
<FileChangeProgressBar progress={makeProgress({ filesChanged: 0 })} />,
|
|
68
|
+
);
|
|
69
|
+
expect((lastFrame() ?? "").trim()).toBe("");
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// --- FileChangeProgressBar: compact summary -------------------------------
|
|
74
|
+
|
|
75
|
+
describe("FileChangeProgressBar — compact summary", () => {
|
|
76
|
+
it("uses the singular noun for a single file", () => {
|
|
77
|
+
const { lastFrame } = render(
|
|
78
|
+
<FileChangeProgressBar
|
|
79
|
+
progress={makeProgress({
|
|
80
|
+
filesChanged: 1,
|
|
81
|
+
entries: [makeEntry({ pathAfter: "one.ts" })],
|
|
82
|
+
})}
|
|
83
|
+
/>,
|
|
84
|
+
);
|
|
85
|
+
expect(lastFrame() ?? "").toContain("1 file changing");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("uses the plural noun for multiple files", () => {
|
|
89
|
+
const { lastFrame } = render(
|
|
90
|
+
<FileChangeProgressBar
|
|
91
|
+
progress={makeProgress({
|
|
92
|
+
filesChanged: 3,
|
|
93
|
+
entries: [makeEntry({ pathAfter: "one.ts" })],
|
|
94
|
+
})}
|
|
95
|
+
/>,
|
|
96
|
+
);
|
|
97
|
+
expect(lastFrame() ?? "").toContain("3 files changing");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("shows the aggregate +N -M when counts exist", () => {
|
|
101
|
+
const { lastFrame } = render(
|
|
102
|
+
<FileChangeProgressBar
|
|
103
|
+
progress={makeProgress({
|
|
104
|
+
filesChanged: 2,
|
|
105
|
+
linesAdded: 12,
|
|
106
|
+
linesRemoved: 4,
|
|
107
|
+
entries: [makeEntry({ pathAfter: "one.ts" })],
|
|
108
|
+
})}
|
|
109
|
+
/>,
|
|
110
|
+
);
|
|
111
|
+
const out = lastFrame() ?? "";
|
|
112
|
+
expect(out).toContain("+12");
|
|
113
|
+
expect(out).toContain("-4");
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("hides the aggregate stat when both counts are zero (never +0 -0)", () => {
|
|
117
|
+
const { lastFrame } = render(
|
|
118
|
+
<FileChangeProgressBar
|
|
119
|
+
progress={makeProgress({
|
|
120
|
+
filesChanged: 1,
|
|
121
|
+
linesAdded: 0,
|
|
122
|
+
linesRemoved: 0,
|
|
123
|
+
entries: [makeEntry({ pathAfter: "one.ts" })],
|
|
124
|
+
})}
|
|
125
|
+
/>,
|
|
126
|
+
);
|
|
127
|
+
// No "+" anywhere means no stat rendered; the count copy carries none.
|
|
128
|
+
expect(lastFrame() ?? "").not.toContain("+");
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// --- FileChangeProgressBar: expansion -------------------------------------
|
|
133
|
+
|
|
134
|
+
describe("FileChangeProgressBar — expansion", () => {
|
|
135
|
+
const progress = makeProgress({
|
|
136
|
+
filesChanged: 2,
|
|
137
|
+
linesAdded: 8,
|
|
138
|
+
linesRemoved: 1,
|
|
139
|
+
entries: [
|
|
140
|
+
makeEntry({ pathAfter: "src/app.ts", linesAdded: 5, linesRemoved: 1 }),
|
|
141
|
+
makeEntry({ pathAfter: "src/util.ts", linesAdded: 3, linesRemoved: 0 }),
|
|
142
|
+
],
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("hides the per-file list when collapsed (default)", () => {
|
|
146
|
+
const { lastFrame } = render(<FileChangeProgressBar progress={progress} />);
|
|
147
|
+
const out = lastFrame() ?? "";
|
|
148
|
+
expect(out).toContain("2 files changing");
|
|
149
|
+
expect(out).not.toContain("src/app.ts");
|
|
150
|
+
expect(out).not.toContain("src/util.ts");
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("shows the per-file list with kind letter, path, and stats when expanded", () => {
|
|
154
|
+
const { lastFrame } = render(
|
|
155
|
+
<FileChangeProgressBar progress={progress} expanded />,
|
|
156
|
+
);
|
|
157
|
+
const out = lastFrame() ?? "";
|
|
158
|
+
expect(out).toContain("src/app.ts");
|
|
159
|
+
expect(out).toContain("src/util.ts");
|
|
160
|
+
expect(out).toContain("M"); // MODIFY kind letter
|
|
161
|
+
expect(out).toContain("+5");
|
|
162
|
+
expect(out).toContain("+3");
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("shows '… and K more' when the entry list is capped below the true total", () => {
|
|
166
|
+
const capped = makeProgress({
|
|
167
|
+
filesChanged: 5,
|
|
168
|
+
entries: [
|
|
169
|
+
makeEntry({ pathAfter: "a.ts" }),
|
|
170
|
+
makeEntry({ pathAfter: "b.ts" }),
|
|
171
|
+
],
|
|
172
|
+
});
|
|
173
|
+
const { lastFrame } = render(
|
|
174
|
+
<FileChangeProgressBar progress={capped} expanded />,
|
|
175
|
+
);
|
|
176
|
+
expect(lastFrame() ?? "").toContain("and 3 more");
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("renders a rename entry as 'before → after'", () => {
|
|
180
|
+
const renamed = makeProgress({
|
|
181
|
+
filesChanged: 1,
|
|
182
|
+
entries: [
|
|
183
|
+
makeEntry({
|
|
184
|
+
pathBefore: "old/name.ts",
|
|
185
|
+
pathAfter: "new/name.ts",
|
|
186
|
+
kind: FileChangeKind.RENAME,
|
|
187
|
+
}),
|
|
188
|
+
],
|
|
189
|
+
});
|
|
190
|
+
const { lastFrame } = render(
|
|
191
|
+
<FileChangeProgressBar progress={renamed} expanded />,
|
|
192
|
+
);
|
|
193
|
+
expect(lastFrame() ?? "").toContain("old/name.ts → new/name.ts");
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("hides per-file stats for a withheld entry (zero counts)", () => {
|
|
197
|
+
const secretish = makeProgress({
|
|
198
|
+
filesChanged: 1,
|
|
199
|
+
entries: [makeEntry({ pathAfter: ".env", linesAdded: 0, linesRemoved: 0 })],
|
|
200
|
+
});
|
|
201
|
+
const { lastFrame } = render(
|
|
202
|
+
<FileChangeProgressBar progress={secretish} expanded />,
|
|
203
|
+
);
|
|
204
|
+
const out = lastFrame() ?? "";
|
|
205
|
+
expect(out).toContain(".env");
|
|
206
|
+
expect(out).not.toContain("+");
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// --- path helpers (direct unit coverage) ----------------------------------
|
|
211
|
+
|
|
212
|
+
interface ChangeOpts {
|
|
213
|
+
readonly pathBefore?: string;
|
|
214
|
+
readonly pathAfter?: string;
|
|
215
|
+
readonly kind: FileChangeKind;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function makeChange(opts: ChangeOpts) {
|
|
219
|
+
return create(CapturedFileChangeSchema, {
|
|
220
|
+
id: "c-1",
|
|
221
|
+
pathBefore: opts.pathBefore ?? "",
|
|
222
|
+
pathAfter: opts.pathAfter ?? "",
|
|
223
|
+
kind: opts.kind,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
describe("changeDisplayPath", () => {
|
|
228
|
+
it("shows the after-path for an add", () => {
|
|
229
|
+
expect(
|
|
230
|
+
changeDisplayPath(makeChange({ pathAfter: "new.ts", kind: FileChangeKind.ADD })),
|
|
231
|
+
).toBe("new.ts");
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("shows the after-path for a modify", () => {
|
|
235
|
+
expect(
|
|
236
|
+
changeDisplayPath(
|
|
237
|
+
makeChange({ pathAfter: "app.ts", kind: FileChangeKind.MODIFY }),
|
|
238
|
+
),
|
|
239
|
+
).toBe("app.ts");
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("falls back to the before-path for a delete", () => {
|
|
243
|
+
expect(
|
|
244
|
+
changeDisplayPath(
|
|
245
|
+
makeChange({ pathBefore: "gone.ts", kind: FileChangeKind.DELETE }),
|
|
246
|
+
),
|
|
247
|
+
).toBe("gone.ts");
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("shows 'before → after' for a rename", () => {
|
|
251
|
+
expect(
|
|
252
|
+
changeDisplayPath(
|
|
253
|
+
makeChange({
|
|
254
|
+
pathBefore: "old.ts",
|
|
255
|
+
pathAfter: "new.ts",
|
|
256
|
+
kind: FileChangeKind.RENAME,
|
|
257
|
+
}),
|
|
258
|
+
),
|
|
259
|
+
).toBe("old.ts → new.ts");
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
describe("progressEntryDisplayPath", () => {
|
|
264
|
+
it("shows the after-path for an add", () => {
|
|
265
|
+
expect(
|
|
266
|
+
progressEntryDisplayPath(makeEntry({ pathAfter: "new.ts", kind: FileChangeKind.ADD })),
|
|
267
|
+
).toBe("new.ts");
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it("shows the after-path for a modify", () => {
|
|
271
|
+
expect(
|
|
272
|
+
progressEntryDisplayPath(makeEntry({ pathAfter: "app.ts" })),
|
|
273
|
+
).toBe("app.ts");
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it("falls back to the before-path for a delete", () => {
|
|
277
|
+
expect(
|
|
278
|
+
progressEntryDisplayPath(
|
|
279
|
+
makeEntry({ pathBefore: "gone.ts", kind: FileChangeKind.DELETE }),
|
|
280
|
+
),
|
|
281
|
+
).toBe("gone.ts");
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it("shows 'before → after' for a rename — identical to changeDisplayPath", () => {
|
|
285
|
+
expect(
|
|
286
|
+
progressEntryDisplayPath(
|
|
287
|
+
makeEntry({
|
|
288
|
+
pathBefore: "old.ts",
|
|
289
|
+
pathAfter: "new.ts",
|
|
290
|
+
kind: FileChangeKind.RENAME,
|
|
291
|
+
}),
|
|
292
|
+
),
|
|
293
|
+
).toBe("old.ts → new.ts");
|
|
294
|
+
});
|
|
295
|
+
});
|
|
@@ -6,8 +6,10 @@ import { FileReviewContext } from "@stigmer/react";
|
|
|
6
6
|
import {
|
|
7
7
|
ToolCallSchema,
|
|
8
8
|
FileContentSchema,
|
|
9
|
+
ToolCallOutputRefSchema,
|
|
9
10
|
AgentMessageSchema,
|
|
10
11
|
} from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/message_pb";
|
|
12
|
+
import type { FileContent } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/message_pb";
|
|
11
13
|
import type { ToolCall } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/message_pb";
|
|
12
14
|
import {
|
|
13
15
|
FileChangeSetSchema,
|
|
@@ -30,7 +32,11 @@ import { ToolCallItem } from "../components/ToolCallItem.js";
|
|
|
30
32
|
import { ToolCallGroup } from "../components/ToolCallGroup.js";
|
|
31
33
|
import { FileReviewPrompt } from "../components/FileReviewPrompt.js";
|
|
32
34
|
import { FileReviewRecord } from "../components/FileReviewRecord.js";
|
|
35
|
+
import { FileDiffBody } from "../components/FileDiffBody.js";
|
|
33
36
|
import { MessageThread } from "../components/MessageThread.js";
|
|
37
|
+
import { FileLineStats } from "../components/FileReviewAtoms.js";
|
|
38
|
+
import { changeSetLineStats } from "../file-review.js";
|
|
39
|
+
import { fakeClient, renderWithClient } from "./test-support.js";
|
|
34
40
|
|
|
35
41
|
// --- fixtures -------------------------------------------------------------
|
|
36
42
|
|
|
@@ -41,6 +47,8 @@ interface ChangeOpts {
|
|
|
41
47
|
readonly diffComplete?: boolean;
|
|
42
48
|
readonly binary?: boolean;
|
|
43
49
|
readonly blockedReason?: FileReviewBlockReason;
|
|
50
|
+
readonly linesAdded?: number;
|
|
51
|
+
readonly linesRemoved?: number;
|
|
44
52
|
}
|
|
45
53
|
|
|
46
54
|
function makeChange(opts: ChangeOpts) {
|
|
@@ -52,6 +60,8 @@ function makeChange(opts: ChangeOpts) {
|
|
|
52
60
|
diffComplete: opts.diffComplete ?? true,
|
|
53
61
|
fileDigest: `fd-${opts.id}`,
|
|
54
62
|
blockedReason: opts.blockedReason ?? FileReviewBlockReason.UNSPECIFIED,
|
|
63
|
+
linesAdded: opts.linesAdded ?? 0,
|
|
64
|
+
linesRemoved: opts.linesRemoved ?? 0,
|
|
55
65
|
before: opts.binary ? create(FileContentSchema, { isBinary: true }) : undefined,
|
|
56
66
|
after: opts.binary ? create(FileContentSchema, { isBinary: true }) : undefined,
|
|
57
67
|
});
|
|
@@ -215,7 +225,9 @@ describe("FileReviewPrompt — per-file", () => {
|
|
|
215
225
|
|
|
216
226
|
it("enters per-file mode and keeps a reviewable file with its file digest", async () => {
|
|
217
227
|
const onSubmit = vi.fn();
|
|
218
|
-
|
|
228
|
+
// Per-file mode mounts FileDiffBody, whose useFileChangeContent reads the
|
|
229
|
+
// Stigmer client — so these tests render under a provider.
|
|
230
|
+
const { stdin, lastFrame } = renderWithClient(
|
|
219
231
|
<FileReviewPrompt changeSet={blockedSet} onSubmit={onSubmit} />,
|
|
220
232
|
);
|
|
221
233
|
stdin.write("f");
|
|
@@ -235,7 +247,7 @@ describe("FileReviewPrompt — per-file", () => {
|
|
|
235
247
|
|
|
236
248
|
it("refuses to keep an unavailable file but allows discard", async () => {
|
|
237
249
|
const onSubmit = vi.fn();
|
|
238
|
-
const { stdin } =
|
|
250
|
+
const { stdin } = renderWithClient(
|
|
239
251
|
<FileReviewPrompt changeSet={blockedSet} onSubmit={onSubmit} />,
|
|
240
252
|
);
|
|
241
253
|
stdin.write("f");
|
|
@@ -262,7 +274,7 @@ describe("FileReviewPrompt — per-file", () => {
|
|
|
262
274
|
],
|
|
263
275
|
});
|
|
264
276
|
const onSubmit = vi.fn();
|
|
265
|
-
const { stdin } =
|
|
277
|
+
const { stdin } = renderWithClient(
|
|
266
278
|
<FileReviewPrompt changeSet={binarySet} onSubmit={onSubmit} />,
|
|
267
279
|
);
|
|
268
280
|
stdin.write("f");
|
|
@@ -494,3 +506,306 @@ describe("MessageThread — file-review integration", () => {
|
|
|
494
506
|
expect(out).not.toContain("File review —"); // but no settled record
|
|
495
507
|
});
|
|
496
508
|
});
|
|
509
|
+
|
|
510
|
+
// --- FileLineStats (shared atom) -----------------------------------------
|
|
511
|
+
|
|
512
|
+
describe("FileLineStats", () => {
|
|
513
|
+
it("renders nothing when both counts are zero (never +0 -0)", () => {
|
|
514
|
+
const { lastFrame } = render(<FileLineStats linesAdded={0} linesRemoved={0} />);
|
|
515
|
+
expect((lastFrame() ?? "").trim()).toBe("");
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
it("renders +N -M when counts exist", () => {
|
|
519
|
+
const { lastFrame } = render(<FileLineStats linesAdded={7} linesRemoved={3} />);
|
|
520
|
+
const out = lastFrame() ?? "";
|
|
521
|
+
expect(out).toContain("+7");
|
|
522
|
+
expect(out).toContain("-3");
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
it("renders a one-sided stat (added only) without hiding it", () => {
|
|
526
|
+
const { lastFrame } = render(<FileLineStats linesAdded={5} linesRemoved={0} />);
|
|
527
|
+
const out = lastFrame() ?? "";
|
|
528
|
+
expect(out).toContain("+5");
|
|
529
|
+
expect(out).toContain("-0"); // both sides always shown once any count exists
|
|
530
|
+
});
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
// --- changeSetLineStats (pure helper) ------------------------------------
|
|
534
|
+
|
|
535
|
+
describe("changeSetLineStats", () => {
|
|
536
|
+
it("sums per-file counts across the set", () => {
|
|
537
|
+
const set = makeSet({
|
|
538
|
+
status: FileChangeSetStatus.RECONCILED,
|
|
539
|
+
changes: [
|
|
540
|
+
makeChange({ id: "a", path: "one.ts", linesAdded: 10, linesRemoved: 2 }),
|
|
541
|
+
makeChange({ id: "b", path: "two.ts", linesAdded: 5, linesRemoved: 3 }),
|
|
542
|
+
],
|
|
543
|
+
});
|
|
544
|
+
expect(changeSetLineStats(set)).toEqual({ linesAdded: 15, linesRemoved: 5 });
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
it("treats an uncountable (binary/withheld) file as a zero contributor — honest understatement", () => {
|
|
548
|
+
const set = makeSet({
|
|
549
|
+
status: FileChangeSetStatus.AWAITING_REVIEW,
|
|
550
|
+
changes: [
|
|
551
|
+
makeChange({ id: "txt", path: "app.ts", linesAdded: 8, linesRemoved: 1 }),
|
|
552
|
+
makeChange({ id: "img", path: "logo.png", kind: FileChangeKind.BINARY_CHANGE, binary: true }),
|
|
553
|
+
],
|
|
554
|
+
});
|
|
555
|
+
expect(changeSetLineStats(set)).toEqual({ linesAdded: 8, linesRemoved: 1 });
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
it("is zero for a set whose files carry no counts (stat then hidden by the atom)", () => {
|
|
559
|
+
const set = makeSet({
|
|
560
|
+
status: FileChangeSetStatus.RECONCILED,
|
|
561
|
+
changes: [makeChange({ id: "a", path: "one.ts" })],
|
|
562
|
+
});
|
|
563
|
+
expect(changeSetLineStats(set)).toEqual({ linesAdded: 0, linesRemoved: 0 });
|
|
564
|
+
});
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
// --- Line stats on the review surfaces -----------------------------------
|
|
568
|
+
|
|
569
|
+
describe("FileReviewPrompt — line stats", () => {
|
|
570
|
+
it("shows the set aggregate +N -M on the header", () => {
|
|
571
|
+
const set = makeSet({
|
|
572
|
+
status: FileChangeSetStatus.AWAITING_REVIEW,
|
|
573
|
+
changes: [
|
|
574
|
+
makeChange({ id: "a", path: "one.ts", linesAdded: 12, linesRemoved: 3 }),
|
|
575
|
+
makeChange({ id: "b", path: "two.ts", linesAdded: 4, linesRemoved: 1 }),
|
|
576
|
+
],
|
|
577
|
+
});
|
|
578
|
+
const out = render(<FileReviewPrompt changeSet={set} onSubmit={() => {}} />).lastFrame() ?? "";
|
|
579
|
+
expect(out).toContain("2 files awaiting review");
|
|
580
|
+
expect(out).toContain("+16");
|
|
581
|
+
expect(out).toContain("-4");
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
it("hides the header aggregate when no file has counts (never +0 -0)", () => {
|
|
585
|
+
const set = makeSet({
|
|
586
|
+
status: FileChangeSetStatus.AWAITING_REVIEW,
|
|
587
|
+
changes: [makeChange({ id: "a", path: "one.ts" })],
|
|
588
|
+
});
|
|
589
|
+
const out = render(<FileReviewPrompt changeSet={set} onSubmit={() => {}} />).lastFrame() ?? "";
|
|
590
|
+
expect(out).not.toContain("+");
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
it("shows per-file +N -M in per-file mode", async () => {
|
|
594
|
+
const set = makeSet({
|
|
595
|
+
status: FileChangeSetStatus.AWAITING_REVIEW,
|
|
596
|
+
changes: [
|
|
597
|
+
makeChange({ id: "a", path: "one.ts", linesAdded: 10, linesRemoved: 2 }),
|
|
598
|
+
makeChange({ id: "b", path: "two.ts", linesAdded: 4, linesRemoved: 0 }),
|
|
599
|
+
],
|
|
600
|
+
});
|
|
601
|
+
const { stdin, lastFrame } = renderWithClient(
|
|
602
|
+
<FileReviewPrompt changeSet={set} onSubmit={() => {}} />,
|
|
603
|
+
);
|
|
604
|
+
stdin.write("f");
|
|
605
|
+
await tick();
|
|
606
|
+
const out = lastFrame() ?? "";
|
|
607
|
+
expect(out).toContain("+10");
|
|
608
|
+
expect(out).toContain("+4");
|
|
609
|
+
});
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
describe("FileReviewRecord — line stats", () => {
|
|
613
|
+
it("shows the set aggregate and per-file +N -M", () => {
|
|
614
|
+
const set = makeSet({
|
|
615
|
+
status: FileChangeSetStatus.RECONCILED,
|
|
616
|
+
changes: [
|
|
617
|
+
makeChange({ id: "a", path: "one.ts", linesAdded: 9, linesRemoved: 2 }),
|
|
618
|
+
makeChange({ id: "b", path: "two.ts", linesAdded: 3, linesRemoved: 1 }),
|
|
619
|
+
],
|
|
620
|
+
decisions: [
|
|
621
|
+
{ scope: FileDecisionScope.CHANGE_SET, action: FileDecisionAction.APPROVE },
|
|
622
|
+
],
|
|
623
|
+
});
|
|
624
|
+
const out = render(<FileReviewRecord fileChangeSet={set} />).lastFrame() ?? "";
|
|
625
|
+
expect(out).toContain("+12"); // aggregate 9+3
|
|
626
|
+
expect(out).toContain("+9"); // per-file
|
|
627
|
+
expect(out).toContain("+3"); // per-file
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
it("renders no stat when the set carries no counts", () => {
|
|
631
|
+
const set = makeSet({
|
|
632
|
+
status: FileChangeSetStatus.RECONCILED,
|
|
633
|
+
changes: [makeChange({ id: "a", path: "one.ts" })],
|
|
634
|
+
});
|
|
635
|
+
expect(render(<FileReviewRecord fileChangeSet={set} />).lastFrame() ?? "").not.toContain("+");
|
|
636
|
+
});
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
// --- FileDiffBody ---------------------------------------------------------
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Polls the rendered frame until it contains `needle`, then returns. Replaces a
|
|
643
|
+
* fixed sleep: an artifact fetch resolves on its own microtask schedule (and a
|
|
644
|
+
* truncated side chains a second download-url fetch), so any single delay raced
|
|
645
|
+
* green locally but timed out under CI load. Polling waits exactly as long as
|
|
646
|
+
* the render needs and no longer, and fails with the actual frame on timeout.
|
|
647
|
+
*/
|
|
648
|
+
async function waitForFrame(
|
|
649
|
+
lastFrame: () => string | undefined,
|
|
650
|
+
needle: string,
|
|
651
|
+
timeoutMs = 2000,
|
|
652
|
+
): Promise<void> {
|
|
653
|
+
const deadline = Date.now() + timeoutMs;
|
|
654
|
+
for (;;) {
|
|
655
|
+
if ((lastFrame() ?? "").includes(needle)) return;
|
|
656
|
+
if (Date.now() >= deadline) {
|
|
657
|
+
throw new Error(
|
|
658
|
+
`waitForFrame timed out after ${timeoutMs}ms waiting for ${JSON.stringify(
|
|
659
|
+
needle,
|
|
660
|
+
)}; last frame was ${JSON.stringify(lastFrame() ?? "")}`,
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
function inlineSide(text: string): FileContent {
|
|
668
|
+
return create(FileContentSchema, { body: { case: "inline", value: text } });
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
function offloadedSide(storageKey: string, contentHash = "h"): FileContent {
|
|
672
|
+
return create(FileContentSchema, {
|
|
673
|
+
body: {
|
|
674
|
+
case: "ref",
|
|
675
|
+
value: create(ToolCallOutputRefSchema, { storageKey, contentHash }),
|
|
676
|
+
},
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
function changeWith(opts: {
|
|
681
|
+
id: string;
|
|
682
|
+
kind?: FileChangeKind;
|
|
683
|
+
before?: FileContent;
|
|
684
|
+
after?: FileContent;
|
|
685
|
+
}) {
|
|
686
|
+
return create(CapturedFileChangeSchema, {
|
|
687
|
+
id: opts.id,
|
|
688
|
+
pathAfter: "file.ts",
|
|
689
|
+
pathBefore: "file.ts",
|
|
690
|
+
kind: opts.kind ?? FileChangeKind.MODIFY,
|
|
691
|
+
fileDigest: `fd-${opts.id}`,
|
|
692
|
+
before: opts.before,
|
|
693
|
+
after: opts.after,
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
describe("FileDiffBody", () => {
|
|
698
|
+
it("renders +/- lines for an inline whole-file diff (computeDiff parity)", () => {
|
|
699
|
+
const change = changeWith({
|
|
700
|
+
id: "m",
|
|
701
|
+
before: inlineSide("keep\nold\ntail\n"),
|
|
702
|
+
after: inlineSide("keep\nnew\ntail\n"),
|
|
703
|
+
});
|
|
704
|
+
const out = renderWithClient(<FileDiffBody change={change} />).lastFrame() ?? "";
|
|
705
|
+
expect(out).toContain("-old"); // removed, red
|
|
706
|
+
expect(out).toContain("+new"); // added, green
|
|
707
|
+
expect(out).toContain("keep"); // context retained
|
|
708
|
+
});
|
|
709
|
+
|
|
710
|
+
it("shows 'Binary file changed.' for a binary side", () => {
|
|
711
|
+
const change = create(CapturedFileChangeSchema, {
|
|
712
|
+
id: "bin",
|
|
713
|
+
pathAfter: "logo.png",
|
|
714
|
+
pathBefore: "logo.png",
|
|
715
|
+
kind: FileChangeKind.BINARY_CHANGE,
|
|
716
|
+
before: create(FileContentSchema, { isBinary: true }),
|
|
717
|
+
after: create(FileContentSchema, { isBinary: true }),
|
|
718
|
+
});
|
|
719
|
+
const out = renderWithClient(<FileDiffBody change={change} />).lastFrame() ?? "";
|
|
720
|
+
expect(out).toContain("Binary file changed.");
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
it("labels a genuinely empty new file (CREATE with no content)", () => {
|
|
724
|
+
const change = changeWith({ id: "new", kind: FileChangeKind.ADD, after: inlineSide("") });
|
|
725
|
+
const out = renderWithClient(<FileDiffBody change={change} />).lastFrame() ?? "";
|
|
726
|
+
expect(out).toContain("Empty new file.");
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
it("falls back to 'No preview available.' for a MODIFY with no renderable diff", () => {
|
|
730
|
+
const change = changeWith({ id: "np" }); // no before/after content
|
|
731
|
+
const out = renderWithClient(<FileDiffBody change={change} />).lastFrame() ?? "";
|
|
732
|
+
expect(out).toContain("No preview available.");
|
|
733
|
+
});
|
|
734
|
+
|
|
735
|
+
it("shows a loading notice while an offloaded side is in flight", () => {
|
|
736
|
+
const change = changeWith({ id: "load", after: offloadedSide("artifacts/aex-1/after") });
|
|
737
|
+
const client = fakeClient({
|
|
738
|
+
agentExecution: { getArtifactContent: () => new Promise(() => {}) },
|
|
739
|
+
});
|
|
740
|
+
const out = renderWithClient(<FileDiffBody change={change} />, client).lastFrame() ?? "";
|
|
741
|
+
expect(out).toContain("Loading diff");
|
|
742
|
+
});
|
|
743
|
+
|
|
744
|
+
it("reports a server-truncated offloaded side as un-diffable inline", async () => {
|
|
745
|
+
const change = changeWith({ id: "trunc", after: offloadedSide("artifacts/aex-1/after") });
|
|
746
|
+
const client = fakeClient({
|
|
747
|
+
agentExecution: {
|
|
748
|
+
getArtifactContent: async () => ({
|
|
749
|
+
content: new TextEncoder().encode("way too big"),
|
|
750
|
+
contentType: "text/plain",
|
|
751
|
+
truncated: true,
|
|
752
|
+
}),
|
|
753
|
+
// A truncated side activates useArtifactDownloadUrl (the notice offers a
|
|
754
|
+
// full-file download). Stub it so the fetch resolves instead of throwing
|
|
755
|
+
// on an undefined method — an unstubbed throw unmounts the ink tree and
|
|
756
|
+
// blanks the frame, which raced green locally but failed under CI load.
|
|
757
|
+
getArtifactDownloadUrl: async () => ({ downloadUrl: "https://example.test/full" }),
|
|
758
|
+
},
|
|
759
|
+
});
|
|
760
|
+
const { lastFrame } = renderWithClient(<FileDiffBody change={change} />, client);
|
|
761
|
+
await waitForFrame(lastFrame, "too large to diff inline");
|
|
762
|
+
expect(lastFrame() ?? "").toContain("too large to diff inline");
|
|
763
|
+
});
|
|
764
|
+
|
|
765
|
+
it("surfaces a fetch failure as an honest error notice", async () => {
|
|
766
|
+
const change = changeWith({ id: "err", after: offloadedSide("artifacts/aex-1/after") });
|
|
767
|
+
const client = fakeClient({
|
|
768
|
+
agentExecution: {
|
|
769
|
+
getArtifactContent: async () => {
|
|
770
|
+
throw new Error("boom");
|
|
771
|
+
},
|
|
772
|
+
},
|
|
773
|
+
});
|
|
774
|
+
const { lastFrame } = renderWithClient(<FileDiffBody change={change} />, client);
|
|
775
|
+
await waitForFrame(lastFrame, "Could not load this file's contents.");
|
|
776
|
+
expect(lastFrame() ?? "").toContain("Could not load this file's contents.");
|
|
777
|
+
});
|
|
778
|
+
|
|
779
|
+
it("caps an oversized diff and reports the overflow", () => {
|
|
780
|
+
const many = Array.from({ length: 250 }, (_, i) => `line ${i}`).join("\n");
|
|
781
|
+
const change = changeWith({ id: "big", before: inlineSide(""), after: inlineSide(`${many}\n`) });
|
|
782
|
+
const out = renderWithClient(<FileDiffBody change={change} />).lastFrame() ?? "";
|
|
783
|
+
expect(out).toMatch(/… \d+ more lines/);
|
|
784
|
+
});
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
describe("FileReviewPrompt — inline diff (master-detail)", () => {
|
|
788
|
+
it("shows only the selected file's diff and follows the selection", async () => {
|
|
789
|
+
const set = makeSet({
|
|
790
|
+
status: FileChangeSetStatus.AWAITING_REVIEW,
|
|
791
|
+
changes: [
|
|
792
|
+
changeWith({ id: "a", before: inlineSide("alpha\n"), after: inlineSide("ALPHA\n") }),
|
|
793
|
+
changeWith({ id: "b", before: inlineSide("bravo\n"), after: inlineSide("BRAVO\n") }),
|
|
794
|
+
],
|
|
795
|
+
});
|
|
796
|
+
const { stdin, lastFrame } = renderWithClient(
|
|
797
|
+
<FileReviewPrompt changeSet={set} onSubmit={() => {}} />,
|
|
798
|
+
);
|
|
799
|
+
stdin.write("f");
|
|
800
|
+
await tick();
|
|
801
|
+
const first = lastFrame() ?? "";
|
|
802
|
+
expect(first).toContain("+ALPHA"); // selected file's diff
|
|
803
|
+
expect(first).not.toContain("+BRAVO"); // the other file's diff is not mounted
|
|
804
|
+
|
|
805
|
+
stdin.write("\u001B[B"); // down → select the second file
|
|
806
|
+
await tick();
|
|
807
|
+
const second = lastFrame() ?? "";
|
|
808
|
+
expect(second).toContain("+BRAVO");
|
|
809
|
+
expect(second).not.toContain("+ALPHA");
|
|
810
|
+
});
|
|
811
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React, { type ReactElement } from "react";
|
|
2
|
+
import { render } from "ink-testing-library";
|
|
3
|
+
import type { Stigmer } from "@stigmer/sdk";
|
|
4
|
+
import { InkStigmerProvider } from "../provider.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Builds a minimal Stigmer stub exposing only the methods a test's hooks call.
|
|
8
|
+
* Anything not overridden is absent, so a test that touches an unstubbed method
|
|
9
|
+
* fails loudly rather than silently no-op'ing.
|
|
10
|
+
*/
|
|
11
|
+
export function fakeClient(overrides: Record<string, unknown> = {}): Stigmer {
|
|
12
|
+
return overrides as unknown as Stigmer;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Renders a tree under an {@link InkStigmerProvider} so hooks that read the
|
|
17
|
+
* Stigmer client (e.g. `useFileChangeContent` → `useStigmer`, which throws
|
|
18
|
+
* without a provider) work. Returns the `ink-testing-library` handle.
|
|
19
|
+
*/
|
|
20
|
+
export function renderWithClient(
|
|
21
|
+
node: ReactElement,
|
|
22
|
+
client: Stigmer = fakeClient(),
|
|
23
|
+
) {
|
|
24
|
+
return render(<InkStigmerProvider client={client}>{node}</InkStigmerProvider>);
|
|
25
|
+
}
|