@stigmer/sdk 3.0.9-dev.20260615153829 → 3.1.0
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/execution/__tests__/approval-provenance.test.d.ts +2 -0
- package/execution/__tests__/approval-provenance.test.d.ts.map +1 -0
- package/execution/__tests__/approval-provenance.test.js +42 -0
- package/execution/__tests__/approval-provenance.test.js.map +1 -0
- package/execution/__tests__/file-review-fold.corpus.test.d.ts +2 -0
- package/execution/__tests__/file-review-fold.corpus.test.d.ts.map +1 -0
- package/execution/__tests__/file-review-fold.corpus.test.js +82 -0
- package/execution/__tests__/file-review-fold.corpus.test.js.map +1 -0
- package/execution/__tests__/file-review-fold.test.d.ts +2 -0
- package/execution/__tests__/file-review-fold.test.d.ts.map +1 -0
- package/execution/__tests__/file-review-fold.test.js +184 -0
- package/execution/__tests__/file-review-fold.test.js.map +1 -0
- package/execution/__tests__/to-display-file-change.test.d.ts +2 -0
- package/execution/__tests__/to-display-file-change.test.d.ts.map +1 -0
- package/execution/__tests__/to-display-file-change.test.js +69 -0
- package/execution/__tests__/to-display-file-change.test.js.map +1 -0
- package/execution/__tests__/tool-view.file-changes.test.d.ts +2 -0
- package/execution/__tests__/tool-view.file-changes.test.d.ts.map +1 -0
- package/execution/__tests__/tool-view.file-changes.test.js +86 -0
- package/execution/__tests__/tool-view.file-changes.test.js.map +1 -0
- package/execution/__tests__/tool-view.fixtures.test.js +3 -0
- package/execution/__tests__/tool-view.fixtures.test.js.map +1 -1
- package/execution/__tests__/tool-view.output-ref.test.d.ts +2 -0
- package/execution/__tests__/tool-view.output-ref.test.d.ts.map +1 -0
- package/execution/__tests__/tool-view.output-ref.test.js +64 -0
- package/execution/__tests__/tool-view.output-ref.test.js.map +1 -0
- package/execution/__tests__/tool-view.search.test.d.ts +2 -0
- package/execution/__tests__/tool-view.search.test.d.ts.map +1 -0
- package/execution/__tests__/tool-view.search.test.js +200 -0
- package/execution/__tests__/tool-view.search.test.js.map +1 -0
- package/execution/__tests__/tool-view.shell.test.d.ts +2 -0
- package/execution/__tests__/tool-view.shell.test.d.ts.map +1 -0
- package/execution/__tests__/tool-view.shell.test.js +104 -0
- package/execution/__tests__/tool-view.shell.test.js.map +1 -0
- package/execution/approval-provenance.d.ts +30 -0
- package/execution/approval-provenance.d.ts.map +1 -0
- package/execution/approval-provenance.js +73 -0
- package/execution/approval-provenance.js.map +1 -0
- package/execution/execution-phases.d.ts +7 -0
- package/execution/execution-phases.d.ts.map +1 -0
- package/execution/execution-phases.js +21 -0
- package/execution/execution-phases.js.map +1 -0
- package/execution/file-review-fold.d.ts +44 -0
- package/execution/file-review-fold.d.ts.map +1 -0
- package/execution/file-review-fold.js +182 -0
- package/execution/file-review-fold.js.map +1 -0
- package/execution/to-display-file-change.d.ts +14 -0
- package/execution/to-display-file-change.d.ts.map +1 -0
- package/execution/to-display-file-change.js +57 -0
- package/execution/to-display-file-change.js.map +1 -0
- package/execution/tool-view.d.ts +8 -2
- package/execution/tool-view.d.ts.map +1 -1
- package/execution/tool-view.js +205 -21
- package/execution/tool-view.js.map +1 -1
- package/gen/agentexecution.d.ts +2 -1
- package/gen/agentexecution.d.ts.map +1 -1
- package/gen/agentexecution.js +8 -0
- package/gen/agentexecution.js.map +1 -1
- package/gen/mcpserver.d.ts +1 -0
- package/gen/mcpserver.d.ts.map +1 -1
- package/gen/mcpserver.js +1 -0
- package/gen/mcpserver.js.map +1 -1
- package/gen/workflowexecution.d.ts +2 -1
- package/gen/workflowexecution.d.ts.map +1 -1
- package/gen/workflowexecution.js +8 -0
- package/gen/workflowexecution.js.map +1 -1
- package/index.d.ts +5 -1
- package/index.d.ts.map +1 -1
- package/index.js +5 -1
- package/index.js.map +1 -1
- package/package.json +2 -2
- package/src/execution/__tests__/approval-provenance.test.ts +60 -0
- package/src/execution/__tests__/file-review-fold.corpus.test.ts +127 -0
- package/src/execution/__tests__/file-review-fold.test.ts +281 -0
- package/src/execution/__tests__/to-display-file-change.test.ts +91 -0
- package/src/execution/__tests__/tool-view.file-changes.test.ts +100 -0
- package/src/execution/__tests__/tool-view.fixtures.test.ts +4 -0
- package/src/execution/__tests__/tool-view.output-ref.test.ts +76 -0
- package/src/execution/__tests__/tool-view.search.test.ts +264 -0
- package/src/execution/__tests__/tool-view.shell.test.ts +127 -0
- package/src/execution/approval-provenance.ts +80 -0
- package/src/execution/execution-phases.ts +23 -0
- package/src/execution/file-review-fold.ts +210 -0
- package/src/execution/to-display-file-change.ts +66 -0
- package/src/execution/tool-view.ts +261 -30
- package/src/gen/agentexecution.ts +7 -1
- package/src/gen/mcpserver.ts +2 -0
- package/src/gen/workflowexecution.ts +7 -1
- package/src/index.ts +12 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
// Unit tests for the file-review fold and its display read-seam. The
|
|
2
|
+
// cross-edition parity with the Go/Java projectors is locked separately by
|
|
3
|
+
// file-review-fold.corpus.test.ts; these cover the TS-specific edges and the
|
|
4
|
+
// deliberate terminal divergence of displayFileChangeSets.
|
|
5
|
+
|
|
6
|
+
import { describe, it, expect } from "vitest";
|
|
7
|
+
import { create } from "@bufbuild/protobuf";
|
|
8
|
+
import {
|
|
9
|
+
FileChangeSetSchema,
|
|
10
|
+
CapturedFileChangeSchema,
|
|
11
|
+
FileDecisionSchema,
|
|
12
|
+
FileReviewEventSchema,
|
|
13
|
+
FileReviewEventStreamSchema,
|
|
14
|
+
FileReviewBaselineCapturedSchema,
|
|
15
|
+
FileReviewCandidateCapturedSchema,
|
|
16
|
+
FileReviewReconciledSchema,
|
|
17
|
+
} from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/filereview_pb";
|
|
18
|
+
import { AgentExecutionStatusSchema } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/api_pb";
|
|
19
|
+
import {
|
|
20
|
+
FileChangeKind,
|
|
21
|
+
FileChangeSetStatus,
|
|
22
|
+
FileDecisionAction,
|
|
23
|
+
FileDecisionScope,
|
|
24
|
+
FileReviewEventType,
|
|
25
|
+
} from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
|
|
26
|
+
import type { CapturedFileChange } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/filereview_pb";
|
|
27
|
+
import {
|
|
28
|
+
displayFileChangeSets,
|
|
29
|
+
foldFileReviewEventStream,
|
|
30
|
+
} from "../file-review-fold";
|
|
31
|
+
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// Event builders (keep the tests readable)
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
|
|
36
|
+
function change(id: string, path = `src/${id}.ts`): CapturedFileChange {
|
|
37
|
+
return create(CapturedFileChangeSchema, {
|
|
38
|
+
id,
|
|
39
|
+
pathAfter: path,
|
|
40
|
+
kind: FileChangeKind.MODIFY,
|
|
41
|
+
diffComplete: true,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function baseline(changeSetId: string) {
|
|
46
|
+
return create(FileReviewEventSchema, {
|
|
47
|
+
changeSetId,
|
|
48
|
+
eventType: FileReviewEventType.BASELINE_CAPTURED,
|
|
49
|
+
payload: {
|
|
50
|
+
case: "baselineCaptured",
|
|
51
|
+
value: create(FileReviewBaselineCapturedSchema, {
|
|
52
|
+
changeSetId,
|
|
53
|
+
turnId: "t1",
|
|
54
|
+
harnessId: "deep-agent",
|
|
55
|
+
}),
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function candidate(changeSetId: string, changes: CapturedFileChange[], agg = "agg") {
|
|
61
|
+
return create(FileReviewEventSchema, {
|
|
62
|
+
changeSetId,
|
|
63
|
+
eventType: FileReviewEventType.CANDIDATE_CAPTURED,
|
|
64
|
+
payload: {
|
|
65
|
+
case: "candidateCaptured",
|
|
66
|
+
value: create(FileReviewCandidateCapturedSchema, {
|
|
67
|
+
changeSetId,
|
|
68
|
+
changes,
|
|
69
|
+
aggregateDigest: agg,
|
|
70
|
+
}),
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function fileDecision(
|
|
76
|
+
changeSetId: string,
|
|
77
|
+
fileChangeId: string,
|
|
78
|
+
action = FileDecisionAction.APPROVE,
|
|
79
|
+
) {
|
|
80
|
+
return create(FileReviewEventSchema, {
|
|
81
|
+
changeSetId,
|
|
82
|
+
eventType: FileReviewEventType.FILE_DECIDED,
|
|
83
|
+
payload: {
|
|
84
|
+
case: "fileDecided",
|
|
85
|
+
value: create(FileDecisionSchema, {
|
|
86
|
+
changeSetId,
|
|
87
|
+
fileChangeId,
|
|
88
|
+
scope: FileDecisionScope.FILE,
|
|
89
|
+
action,
|
|
90
|
+
}),
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function changeSetDecision(changeSetId: string) {
|
|
96
|
+
return create(FileReviewEventSchema, {
|
|
97
|
+
changeSetId,
|
|
98
|
+
eventType: FileReviewEventType.FILE_DECIDED,
|
|
99
|
+
payload: {
|
|
100
|
+
case: "fileDecided",
|
|
101
|
+
value: create(FileDecisionSchema, {
|
|
102
|
+
changeSetId,
|
|
103
|
+
scope: FileDecisionScope.CHANGE_SET,
|
|
104
|
+
action: FileDecisionAction.APPROVE,
|
|
105
|
+
}),
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function reconciled(changeSetId: string) {
|
|
111
|
+
return create(FileReviewEventSchema, {
|
|
112
|
+
changeSetId,
|
|
113
|
+
eventType: FileReviewEventType.RECONCILED,
|
|
114
|
+
payload: {
|
|
115
|
+
case: "reconciled",
|
|
116
|
+
value: create(FileReviewReconciledSchema, { changeSetId }),
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function failed(changeSetId: string) {
|
|
122
|
+
return create(FileReviewEventSchema, {
|
|
123
|
+
changeSetId,
|
|
124
|
+
eventType: FileReviewEventType.FAILED,
|
|
125
|
+
payload: { case: undefined },
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function stream(...events: ReturnType<typeof baseline>[]) {
|
|
130
|
+
return create(FileReviewEventStreamSchema, { executionId: "aex_1", events });
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ---------------------------------------------------------------------------
|
|
134
|
+
// foldFileReviewEventStream
|
|
135
|
+
// ---------------------------------------------------------------------------
|
|
136
|
+
|
|
137
|
+
describe("foldFileReviewEventStream", () => {
|
|
138
|
+
it("returns [] for undefined / empty streams", () => {
|
|
139
|
+
expect(foldFileReviewEventStream(undefined)).toEqual([]);
|
|
140
|
+
expect(foldFileReviewEventStream(stream())).toEqual([]);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("opens a set as CAPTURING on baseline, before any candidate", () => {
|
|
144
|
+
const [set] = foldFileReviewEventStream(stream(baseline("cs1")));
|
|
145
|
+
expect(set.status).toBe(FileChangeSetStatus.CAPTURING);
|
|
146
|
+
expect(set.turnId).toBe("t1");
|
|
147
|
+
expect(set.harnessId).toBe("deep-agent");
|
|
148
|
+
expect(set.changes).toHaveLength(0);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("moves to AWAITING_REVIEW once a candidate carries changes", () => {
|
|
152
|
+
const [set] = foldFileReviewEventStream(
|
|
153
|
+
stream(baseline("cs1"), candidate("cs1", [change("fc1")], "agg1")),
|
|
154
|
+
);
|
|
155
|
+
expect(set.status).toBe(FileChangeSetStatus.AWAITING_REVIEW);
|
|
156
|
+
expect(set.changes.map((c) => c.id)).toEqual(["fc1"]);
|
|
157
|
+
expect(set.aggregateDigest).toBe("agg1");
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("replaces the change list wholesale on a later candidate", () => {
|
|
161
|
+
const [set] = foldFileReviewEventStream(
|
|
162
|
+
stream(
|
|
163
|
+
baseline("cs1"),
|
|
164
|
+
candidate("cs1", [change("fc1"), change("fc2")]),
|
|
165
|
+
candidate("cs1", [change("fc3")]),
|
|
166
|
+
),
|
|
167
|
+
);
|
|
168
|
+
expect(set.changes.map((c) => c.id)).toEqual(["fc3"]);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("marks DECIDED only when every file has a verdict", () => {
|
|
172
|
+
const partial = foldFileReviewEventStream(
|
|
173
|
+
stream(
|
|
174
|
+
baseline("cs1"),
|
|
175
|
+
candidate("cs1", [change("fc1"), change("fc2")]),
|
|
176
|
+
fileDecision("cs1", "fc1"),
|
|
177
|
+
),
|
|
178
|
+
)[0];
|
|
179
|
+
expect(partial.status).toBe(FileChangeSetStatus.AWAITING_REVIEW);
|
|
180
|
+
expect(partial.decisions).toHaveLength(1);
|
|
181
|
+
|
|
182
|
+
const full = foldFileReviewEventStream(
|
|
183
|
+
stream(
|
|
184
|
+
baseline("cs1"),
|
|
185
|
+
candidate("cs1", [change("fc1"), change("fc2")]),
|
|
186
|
+
fileDecision("cs1", "fc1"),
|
|
187
|
+
fileDecision("cs1", "fc2"),
|
|
188
|
+
),
|
|
189
|
+
)[0];
|
|
190
|
+
expect(full.status).toBe(FileChangeSetStatus.DECIDED);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("treats a CHANGE_SET decision as covering every file", () => {
|
|
194
|
+
const [set] = foldFileReviewEventStream(
|
|
195
|
+
stream(
|
|
196
|
+
baseline("cs1"),
|
|
197
|
+
candidate("cs1", [change("fc1"), change("fc2")]),
|
|
198
|
+
changeSetDecision("cs1"),
|
|
199
|
+
),
|
|
200
|
+
);
|
|
201
|
+
expect(set.status).toBe(FileChangeSetStatus.DECIDED);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("keeps terminal RECONCILED/FAILED sticky against a later decision", () => {
|
|
205
|
+
const reconciledSet = foldFileReviewEventStream(
|
|
206
|
+
stream(
|
|
207
|
+
baseline("cs1"),
|
|
208
|
+
candidate("cs1", [change("fc1")]),
|
|
209
|
+
reconciled("cs1"),
|
|
210
|
+
fileDecision("cs1", "fc1"), // arrives after reconcile — must not downgrade
|
|
211
|
+
),
|
|
212
|
+
)[0];
|
|
213
|
+
expect(reconciledSet.status).toBe(FileChangeSetStatus.RECONCILED);
|
|
214
|
+
|
|
215
|
+
const failedSet = foldFileReviewEventStream(
|
|
216
|
+
stream(baseline("cs1"), candidate("cs1", [change("fc1")]), failed("cs1"))
|
|
217
|
+
)[0];
|
|
218
|
+
expect(failedSet.status).toBe(FileChangeSetStatus.FAILED);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("groups multiple change sets in first-seen order", () => {
|
|
222
|
+
const sets = foldFileReviewEventStream(
|
|
223
|
+
stream(
|
|
224
|
+
baseline("cs2"),
|
|
225
|
+
candidate("cs2", [change("fc-a")]),
|
|
226
|
+
baseline("cs1"),
|
|
227
|
+
candidate("cs1", [change("fc-b")]),
|
|
228
|
+
),
|
|
229
|
+
);
|
|
230
|
+
expect(sets.map((s) => s.id)).toEqual(["cs2", "cs1"]);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it("skips events with no change_set_id", () => {
|
|
234
|
+
const orphan = create(FileReviewEventSchema, {
|
|
235
|
+
changeSetId: "",
|
|
236
|
+
eventType: FileReviewEventType.BASELINE_CAPTURED,
|
|
237
|
+
});
|
|
238
|
+
expect(foldFileReviewEventStream(stream(orphan))).toEqual([]);
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
// ---------------------------------------------------------------------------
|
|
243
|
+
// displayFileChangeSets — projection-first, fold-on-terminal
|
|
244
|
+
// ---------------------------------------------------------------------------
|
|
245
|
+
|
|
246
|
+
describe("displayFileChangeSets", () => {
|
|
247
|
+
it("returns [] for undefined status", () => {
|
|
248
|
+
expect(displayFileChangeSets(undefined)).toEqual([]);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it("prefers the server projection when present (preserving its reference)", () => {
|
|
252
|
+
const projected = [create(FileChangeSetSchema, { id: "cs1" })];
|
|
253
|
+
const status = create(AgentExecutionStatusSchema, {
|
|
254
|
+
fileChangeSets: projected,
|
|
255
|
+
// A ledger is also present, but the projection wins for a live execution.
|
|
256
|
+
fileReviewEventStream: stream(baseline("cs1")),
|
|
257
|
+
});
|
|
258
|
+
const result = displayFileChangeSets(status);
|
|
259
|
+
expect(result).toBe(status.fileChangeSets); // same ref — no re-fold, memo-safe
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it("folds the ledger when the projection is empty (terminal execution)", () => {
|
|
263
|
+
const status = create(AgentExecutionStatusSchema, {
|
|
264
|
+
fileChangeSets: [], // terminal: server projects nil
|
|
265
|
+
fileReviewEventStream: stream(
|
|
266
|
+
baseline("cs1"),
|
|
267
|
+
candidate("cs1", [change("fc1")]),
|
|
268
|
+
changeSetDecision("cs1"),
|
|
269
|
+
reconciled("cs1"),
|
|
270
|
+
),
|
|
271
|
+
});
|
|
272
|
+
const result = displayFileChangeSets(status);
|
|
273
|
+
expect(result.map((s) => s.id)).toEqual(["cs1"]);
|
|
274
|
+
expect(result[0].status).toBe(FileChangeSetStatus.RECONCILED);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it("returns [] when neither projection nor ledger has content", () => {
|
|
278
|
+
const status = create(AgentExecutionStatusSchema, {});
|
|
279
|
+
expect(displayFileChangeSets(status)).toEqual([]);
|
|
280
|
+
});
|
|
281
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Unit tests for the CapturedFileChange -> FileChange display projection.
|
|
2
|
+
|
|
3
|
+
import { describe, it, expect } from "vitest";
|
|
4
|
+
import { create } from "@bufbuild/protobuf";
|
|
5
|
+
import {
|
|
6
|
+
CapturedFileChangeSchema,
|
|
7
|
+
} from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/filereview_pb";
|
|
8
|
+
import { FileContentSchema } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/message_pb";
|
|
9
|
+
import {
|
|
10
|
+
FileChangeCaptureLevel,
|
|
11
|
+
FileChangeKind,
|
|
12
|
+
FileChangeType,
|
|
13
|
+
} from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
|
|
14
|
+
import { toDisplayFileChange } from "../to-display-file-change";
|
|
15
|
+
|
|
16
|
+
function inline(text: string) {
|
|
17
|
+
return create(FileContentSchema, { body: { case: "inline", value: text } });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe("toDisplayFileChange", () => {
|
|
21
|
+
it("maps a MODIFY with both sides to a WHOLE_FILE before/after change", () => {
|
|
22
|
+
const fc = toDisplayFileChange(
|
|
23
|
+
create(CapturedFileChangeSchema, {
|
|
24
|
+
id: "fc1",
|
|
25
|
+
pathBefore: "src/a.ts",
|
|
26
|
+
pathAfter: "src/a.ts",
|
|
27
|
+
kind: FileChangeKind.MODIFY,
|
|
28
|
+
before: inline("old"),
|
|
29
|
+
after: inline("new"),
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
expect(fc.path).toBe("src/a.ts");
|
|
33
|
+
expect(fc.changeType).toBe(FileChangeType.MODIFY);
|
|
34
|
+
expect(fc.captureLevel).toBe(FileChangeCaptureLevel.WHOLE_FILE);
|
|
35
|
+
expect(fc.before?.body.case).toBe("inline");
|
|
36
|
+
expect(fc.after?.body.case).toBe("inline");
|
|
37
|
+
expect(fc.renameFrom).toBe("");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("maps ADD -> CREATE and uses pathAfter", () => {
|
|
41
|
+
const fc = toDisplayFileChange(
|
|
42
|
+
create(CapturedFileChangeSchema, {
|
|
43
|
+
id: "fc1",
|
|
44
|
+
pathAfter: "src/new.ts",
|
|
45
|
+
kind: FileChangeKind.ADD,
|
|
46
|
+
after: inline("hello"),
|
|
47
|
+
}),
|
|
48
|
+
);
|
|
49
|
+
expect(fc.changeType).toBe(FileChangeType.CREATE);
|
|
50
|
+
expect(fc.path).toBe("src/new.ts");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("maps DELETE -> DELETE and uses pathBefore when pathAfter is empty", () => {
|
|
54
|
+
const fc = toDisplayFileChange(
|
|
55
|
+
create(CapturedFileChangeSchema, {
|
|
56
|
+
id: "fc1",
|
|
57
|
+
pathBefore: "src/gone.ts",
|
|
58
|
+
kind: FileChangeKind.DELETE,
|
|
59
|
+
before: inline("bye"),
|
|
60
|
+
}),
|
|
61
|
+
);
|
|
62
|
+
expect(fc.changeType).toBe(FileChangeType.DELETE);
|
|
63
|
+
expect(fc.path).toBe("src/gone.ts");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("maps RENAME -> RENAME and carries renameFrom = pathBefore", () => {
|
|
67
|
+
const fc = toDisplayFileChange(
|
|
68
|
+
create(CapturedFileChangeSchema, {
|
|
69
|
+
id: "fc1",
|
|
70
|
+
pathBefore: "src/old-name.ts",
|
|
71
|
+
pathAfter: "src/new-name.ts",
|
|
72
|
+
kind: FileChangeKind.RENAME,
|
|
73
|
+
}),
|
|
74
|
+
);
|
|
75
|
+
expect(fc.changeType).toBe(FileChangeType.RENAME);
|
|
76
|
+
expect(fc.path).toBe("src/new-name.ts");
|
|
77
|
+
expect(fc.renameFrom).toBe("src/old-name.ts");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("carries a binary side through so the renderer can detect it", () => {
|
|
81
|
+
const fc = toDisplayFileChange(
|
|
82
|
+
create(CapturedFileChangeSchema, {
|
|
83
|
+
id: "fc1",
|
|
84
|
+
pathAfter: "img.png",
|
|
85
|
+
kind: FileChangeKind.ADD,
|
|
86
|
+
after: create(FileContentSchema, { isBinary: true }),
|
|
87
|
+
}),
|
|
88
|
+
);
|
|
89
|
+
expect(fc.after?.isBinary).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Covers normalizeToolResult's file-edit / file-write views, reconstructed from
|
|
2
|
+
// the tool args (and the Cursor result envelope). Phase 5 Slice 4 removed the
|
|
3
|
+
// ToolCall.file_changes capture (message.proto field 22), so the args are the
|
|
4
|
+
// single source for the inline transcript diff; captured file review renders via
|
|
5
|
+
// FileReviewCard / the FileChangeSet ledger, tested separately.
|
|
6
|
+
|
|
7
|
+
import { describe, it, expect } from "vitest";
|
|
8
|
+
import { create, type JsonObject } from "@bufbuild/protobuf";
|
|
9
|
+
import { ToolCallSchema } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/message_pb";
|
|
10
|
+
import {
|
|
11
|
+
ToolCallStatus,
|
|
12
|
+
ToolKind,
|
|
13
|
+
} from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
|
|
14
|
+
import { normalizeToolResult } from "../tool-view";
|
|
15
|
+
|
|
16
|
+
/** A completed FILE_EDIT tool call carrying the given args/result. */
|
|
17
|
+
function editToolCall(opts: { args?: Record<string, unknown>; result?: string }) {
|
|
18
|
+
return create(ToolCallSchema, {
|
|
19
|
+
id: "tc-1",
|
|
20
|
+
name: "edit_file",
|
|
21
|
+
toolKind: ToolKind.FILE_EDIT,
|
|
22
|
+
status: ToolCallStatus.TOOL_CALL_COMPLETED,
|
|
23
|
+
args: (opts.args ?? {}) as JsonObject,
|
|
24
|
+
result: opts.result ?? "",
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A completed FILE_WRITE tool call carrying the given args. */
|
|
29
|
+
function writeToolCall(opts: { args?: Record<string, unknown> }) {
|
|
30
|
+
return create(ToolCallSchema, {
|
|
31
|
+
id: "tc-w",
|
|
32
|
+
name: "write_file",
|
|
33
|
+
toolKind: ToolKind.FILE_WRITE,
|
|
34
|
+
status: ToolCallStatus.TOOL_CALL_COMPLETED,
|
|
35
|
+
args: (opts.args ?? {}) as JsonObject,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe("normalizeEdit — from args", () => {
|
|
40
|
+
it("reconstructs a diff from old_string / new_string", () => {
|
|
41
|
+
const view = normalizeToolResult(
|
|
42
|
+
editToolCall({
|
|
43
|
+
args: { path: "legacy.ts", old_string: "foo", new_string: "bar" },
|
|
44
|
+
result: "Successfully replaced 1 occurrence(s)",
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
expect(view.type).toBe("diff");
|
|
48
|
+
if (view.type !== "diff") return;
|
|
49
|
+
expect(view.oldText).toBe("foo");
|
|
50
|
+
expect(view.newText).toBe("bar");
|
|
51
|
+
expect(view.path).toBe("legacy.ts");
|
|
52
|
+
// The row carries no whole-file capture; captureLevel is left unset.
|
|
53
|
+
expect(view.captureLevel).toBeUndefined();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("parses the Cursor result envelope stats when present", () => {
|
|
57
|
+
const view = normalizeToolResult(
|
|
58
|
+
editToolCall({
|
|
59
|
+
args: { path: "x.ts" },
|
|
60
|
+
result: JSON.stringify({
|
|
61
|
+
value: { linesAdded: 3, linesRemoved: 2, diffString: "@@ patch @@" },
|
|
62
|
+
}),
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
65
|
+
if (view.type !== "diff") return;
|
|
66
|
+
expect(view.linesAdded).toBe(3);
|
|
67
|
+
expect(view.linesRemoved).toBe(2);
|
|
68
|
+
expect(view.unifiedDiff).toBe("@@ patch @@");
|
|
69
|
+
expect(view.captureLevel).toBeUndefined();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("resolves the path from the args (path / file_path / file / filename)", () => {
|
|
73
|
+
expect(
|
|
74
|
+
(() => {
|
|
75
|
+
const v = normalizeToolResult(editToolCall({ args: { file_path: "src/app/main.ts", old_string: "a", new_string: "b" } }));
|
|
76
|
+
return v.type === "diff" ? v.path : "";
|
|
77
|
+
})(),
|
|
78
|
+
).toBe("src/app/main.ts");
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe("normalizeWrite — from args", () => {
|
|
83
|
+
it("renders the proposed whole-file content from the args (contents)", () => {
|
|
84
|
+
const CONTENT = "# Notes\n\n- first\n- second\n";
|
|
85
|
+
const view = normalizeToolResult(
|
|
86
|
+
writeToolCall({ args: { path: "notes.md", contents: CONTENT } }),
|
|
87
|
+
);
|
|
88
|
+
expect(view.type).toBe("file");
|
|
89
|
+
if (view.type !== "file") return;
|
|
90
|
+
expect(view.path).toBe("notes.md");
|
|
91
|
+
expect(view.content).toBe(CONTENT);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("defaults to empty content when the args carry none", () => {
|
|
95
|
+
const view = normalizeToolResult(writeToolCall({ args: { path: "empty.ts" } }));
|
|
96
|
+
if (view.type !== "file") return;
|
|
97
|
+
expect(view.content).toBe("");
|
|
98
|
+
expect(view.path).toBe("empty.ts");
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -49,6 +49,7 @@ describe("result-view fixtures", () => {
|
|
|
49
49
|
type: string;
|
|
50
50
|
path?: string;
|
|
51
51
|
exitCode?: number;
|
|
52
|
+
command?: string;
|
|
52
53
|
count?: number;
|
|
53
54
|
mcpServerSlug?: string;
|
|
54
55
|
linesAdded?: number;
|
|
@@ -92,6 +93,9 @@ describe("result-view fixtures", () => {
|
|
|
92
93
|
if (c.expected.exitCode !== undefined && view.type === "terminal") {
|
|
93
94
|
expect(view.exitCode).toBe(c.expected.exitCode);
|
|
94
95
|
}
|
|
96
|
+
if (c.expected.command !== undefined && view.type === "terminal") {
|
|
97
|
+
expect(view.command).toBe(c.expected.command);
|
|
98
|
+
}
|
|
95
99
|
if (c.expected.count !== undefined && view.type === "search") {
|
|
96
100
|
expect(view.count).toBe(c.expected.count);
|
|
97
101
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Covers the offloaded tool-output path: when a result is spilled to artifact
|
|
2
|
+
// storage the runner replaces it with a ToolCallOutputRef. The view must surface
|
|
3
|
+
// the STABLE storageKey (+ contentHash) so consumers resolve the bytes/URL on
|
|
4
|
+
// demand — it must never depend on a persisted (ephemeral) URL.
|
|
5
|
+
|
|
6
|
+
import { describe, it, expect } from "vitest";
|
|
7
|
+
import { create, type JsonObject } from "@bufbuild/protobuf";
|
|
8
|
+
import {
|
|
9
|
+
ToolCallSchema,
|
|
10
|
+
ToolCallOutputRefSchema,
|
|
11
|
+
} from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/message_pb";
|
|
12
|
+
import {
|
|
13
|
+
ToolCallStatus,
|
|
14
|
+
ToolKind,
|
|
15
|
+
} from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
|
|
16
|
+
import { normalizeToolResult } from "../tool-view";
|
|
17
|
+
|
|
18
|
+
function toolCallWithOutputRef(ref: ReturnType<typeof create<typeof ToolCallOutputRefSchema>> | undefined, result = "") {
|
|
19
|
+
return create(ToolCallSchema, {
|
|
20
|
+
id: "tc-1",
|
|
21
|
+
name: "some_tool",
|
|
22
|
+
toolKind: ToolKind.UNSPECIFIED,
|
|
23
|
+
status: ToolCallStatus.TOOL_CALL_COMPLETED,
|
|
24
|
+
args: {} as JsonObject,
|
|
25
|
+
result,
|
|
26
|
+
outputRef: ref,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe("normalizeToolResult — offloaded output ref", () => {
|
|
31
|
+
it("emits an outputRef view carrying the stable storageKey and contentHash", () => {
|
|
32
|
+
const ref = create(ToolCallOutputRefSchema, {
|
|
33
|
+
storageKey: "artifacts/exec-1/toolcalls/tc-1.txt",
|
|
34
|
+
contentHash: "sha256:abc",
|
|
35
|
+
sizeBytes: 900_000n,
|
|
36
|
+
mimeType: "text/plain",
|
|
37
|
+
isImage: false,
|
|
38
|
+
truncatedPreview: "head of the output…",
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const view = normalizeToolResult(toolCallWithOutputRef(ref, "[output truncated]"));
|
|
42
|
+
|
|
43
|
+
expect(view.type).toBe("outputRef");
|
|
44
|
+
if (view.type !== "outputRef") return;
|
|
45
|
+
expect(view.storageKey).toBe("artifacts/exec-1/toolcalls/tc-1.txt");
|
|
46
|
+
expect(view.contentHash).toBe("sha256:abc");
|
|
47
|
+
expect(view.isImage).toBe(false);
|
|
48
|
+
expect(view.mimeType).toBe("text/plain");
|
|
49
|
+
expect(view.sizeBytes).toBe(900_000);
|
|
50
|
+
expect(view.preview).toBe("head of the output…");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("gates on storageKey, not a URL — an image ref renders inline", () => {
|
|
54
|
+
const ref = create(ToolCallOutputRefSchema, {
|
|
55
|
+
storageKey: "artifacts/exec-1/toolcalls/tc-1.png",
|
|
56
|
+
contentHash: "sha256:img",
|
|
57
|
+
sizeBytes: 12_345n,
|
|
58
|
+
mimeType: "image/png",
|
|
59
|
+
isImage: true,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const view = normalizeToolResult(toolCallWithOutputRef(ref));
|
|
63
|
+
|
|
64
|
+
expect(view.type).toBe("outputRef");
|
|
65
|
+
if (view.type !== "outputRef") return;
|
|
66
|
+
expect(view.isImage).toBe(true);
|
|
67
|
+
expect(view.storageKey).toBe("artifacts/exec-1/toolcalls/tc-1.png");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("does not produce an outputRef view when no storageKey is present", () => {
|
|
71
|
+
// A ref with no storageKey is not a usable offload pointer; fall back to text.
|
|
72
|
+
const ref = create(ToolCallOutputRefSchema, { sizeBytes: 10n });
|
|
73
|
+
const view = normalizeToolResult(toolCallWithOutputRef(ref, "plain result"));
|
|
74
|
+
expect(view.type).not.toBe("outputRef");
|
|
75
|
+
});
|
|
76
|
+
});
|