Skip to content

Commit 70d9020

Browse files
committed
Remove fragile spread pattern from snapshot test harness
1 parent 86620c1 commit 70d9020

1 file changed

Lines changed: 20 additions & 19 deletions

File tree

tests/unit/render-snapshots.test.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,13 @@ function matchSnapshot(name: string, actual: string): void {
8181
assert.equal(cleaned, expected, `Snapshot ${name} does not match`);
8282
}
8383

84-
function withHarness(run: (h: { state: AgenticodingState } & ReturnType<typeof createTestHarness>) => void): void {
85-
const h = { state: createState(), ...createTestHarness() };
84+
function withHarness(run: (state: AgenticodingState) => void): void {
85+
const harness = createTestHarness();
86+
const state = createState();
8687
try {
87-
run(h);
88+
run(state);
8889
} finally {
89-
h.teardown();
90+
harness.teardown();
9091
}
9192
}
9293

@@ -134,7 +135,7 @@ test("spawn call long prompt matches snapshot", () => {
134135
// 3–5: Spawn result (renderSpawnResult, static Text path, no child session)
135136
// ═══════════════════════════════════════════════════════════════════════
136137

137-
test("spawn result success matches snapshot", () => withHarness((h) => {
138+
test("spawn result success matches snapshot", () => withHarness((state) => {
138139
const component = renderSpawnResult(
139140
{
140141
content: [{ type: "text", text: "Task completed successfully. All tests pass and documentation is updated." }],
@@ -148,14 +149,14 @@ test("spawn result success matches snapshot", () => withHarness((h) => {
148149
false,
149150
theme,
150151
{ toolCallId: "tc-1", invalidate: () => {}, showImages: false, lastComponent: undefined },
151-
h.state,
152+
state,
152153
);
153154

154155
const rtb = new RenderTestBackend().render(component as any, SNAP_WIDTH);
155156
matchSnapshot("spawn-result-success", rtb.toSnapshot());
156157
}));
157158

158-
test("spawn result error matches snapshot", () => withHarness((h) => {
159+
test("spawn result error matches snapshot", () => withHarness((state) => {
159160
const component = renderSpawnResult(
160161
{
161162
content: [{ type: "text", text: "Failed to connect to API: rate limit exceeded. Retry after 60 seconds." }],
@@ -169,14 +170,14 @@ test("spawn result error matches snapshot", () => withHarness((h) => {
169170
false,
170171
theme,
171172
{ toolCallId: "tc-2", invalidate: () => {}, showImages: false, lastComponent: undefined },
172-
h.state,
173+
state,
173174
);
174175

175176
const rtb = new RenderTestBackend().render(component as any, SNAP_WIDTH);
176177
matchSnapshot("spawn-result-error", rtb.toSnapshot());
177178
}));
178179

179-
test("spawn result aborted matches snapshot", () => withHarness((h) => {
180+
test("spawn result aborted matches snapshot", () => withHarness((state) => {
180181
const component = renderSpawnResult(
181182
{
182183
content: [{ type: "text", text: "Operation cancelled by user request." }],
@@ -190,7 +191,7 @@ test("spawn result aborted matches snapshot", () => withHarness((h) => {
190191
false,
191192
theme,
192193
{ toolCallId: "tc-3", invalidate: () => {}, showImages: false, lastComponent: undefined },
193-
h.state,
194+
state,
194195
);
195196

196197
const rtb = new RenderTestBackend().render(component as any, SNAP_WIDTH);
@@ -201,9 +202,9 @@ test("spawn result aborted matches snapshot", () => withHarness((h) => {
201202
// 6–8: NestedAgentSessionComponent (via renderSpawnResult with child session)
202203
// ═══════════════════════════════════════════════════════════════════════
203204

204-
test("nested collapsed running matches snapshot", () => withHarness((h) => {
205+
test("nested collapsed running matches snapshot", () => withHarness((state) => {
205206
const session = createSession([]);
206-
h.state.childSessions.set("tc-nested-1", session);
207+
state.childSessions.set("tc-nested-1", session);
207208

208209
const component = renderSpawnResult(
209210
{
@@ -213,21 +214,21 @@ test("nested collapsed running matches snapshot", () => withHarness((h) => {
213214
false,
214215
theme,
215216
{ toolCallId: "tc-nested-1", invalidate: () => {}, showImages: false, lastComponent: undefined },
216-
h.state,
217+
state,
217218
);
218219

219220
const rtb = new RenderTestBackend().render(component as any, SNAP_WIDTH);
220221
matchSnapshot("nested-collapsed-running", rtb.toSnapshot());
221222
}));
222223

223-
test("nested collapsed success matches snapshot", () => withHarness((h) => {
224+
test("nested collapsed success matches snapshot", () => withHarness((state) => {
224225
const session = createSession([
225226
{
226227
role: "assistant",
227228
content: [{ type: "text", text: "Analysis complete. The optimal solution is to use a cache layer with TTL of 300s." }],
228229
},
229230
]);
230-
h.state.childSessions.set("tc-nested-2", session);
231+
state.childSessions.set("tc-nested-2", session);
231232

232233
const component = renderSpawnResult(
233234
{
@@ -242,21 +243,21 @@ test("nested collapsed success matches snapshot", () => withHarness((h) => {
242243
false,
243244
theme,
244245
{ toolCallId: "tc-nested-2", invalidate: () => {}, showImages: false, lastComponent: undefined },
245-
h.state,
246+
state,
246247
);
247248

248249
const rtb = new RenderTestBackend().render(component as any, SNAP_WIDTH);
249250
matchSnapshot("nested-collapsed-success", rtb.toSnapshot());
250251
}));
251252

252-
test("nested expanded matches snapshot", () => withHarness((h) => {
253+
test("nested expanded matches snapshot", () => withHarness((state) => {
253254
const session = createSession([
254255
{
255256
role: "assistant",
256257
content: [{ type: "text", text: "Here is the implementation plan. Create data access layer, add caching middleware, wire up the controller." }],
257258
},
258259
]);
259-
h.state.childSessions.set("tc-nested-3", session);
260+
state.childSessions.set("tc-nested-3", session);
260261

261262
const component = renderSpawnResult(
262263
{
@@ -271,7 +272,7 @@ test("nested expanded matches snapshot", () => withHarness((h) => {
271272
true,
272273
theme,
273274
{ toolCallId: "tc-nested-3", invalidate: () => {}, showImages: false, lastComponent: undefined },
274-
h.state,
275+
state,
275276
);
276277

277278
const rtb = new RenderTestBackend().render(component as any, SNAP_WIDTH);

0 commit comments

Comments
 (0)