Skip to content

Commit 59f8aa7

Browse files
spawn-qa-botclaude
andcommitted
test: remove duplicate and theatrical tests
Consolidate 5 near-identical manifest rejection tests into a single data-driven loop, and collapse 4 identical logging-function smoke tests into a data-driven loop. Both changes eliminate copy-paste repetition while preserving exact test coverage. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e44705d commit 59f8aa7

2 files changed

Lines changed: 67 additions & 92 deletions

File tree

packages/cli/src/__tests__/manifest.test.ts

Lines changed: 39 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -217,52 +217,33 @@ describe("manifest", () => {
217217
await expect(loadManifest(true)).rejects.toThrow("Cannot load manifest");
218218
});
219219

220-
it("throws when manifest from GitHub is invalid", async () => {
221-
const consoleSpy = spyOn(console, "error").mockImplementation(() => {});
222-
global.fetch = mock(
223-
async () =>
220+
const invalidManifestCases: Array<{
221+
label: string;
222+
fetchImpl: () => Promise<Response>;
223+
}> = [
224+
{
225+
label: "non-manifest shape",
226+
fetchImpl: async () =>
224227
new Response(
225228
JSON.stringify({
226229
not: "a manifest",
227230
}),
228231
),
229-
);
230-
231-
const cacheFile = join(env.testDir, "spawn", "manifest.json");
232-
if (existsSync(cacheFile)) {
233-
rmSync(cacheFile);
234-
}
235-
236-
await expect(loadManifest(true)).rejects.toThrow("Cannot load manifest");
237-
consoleSpy.mockRestore();
238-
});
239-
240-
it("rejects manifest with string agents field", async () => {
241-
const consoleSpy = spyOn(console, "error").mockImplementation(() => {});
242-
global.fetch = mock(
243-
async () =>
232+
},
233+
{
234+
label: "string agents field",
235+
fetchImpl: async () =>
244236
new Response(
245237
JSON.stringify({
246238
agents: "claude",
247239
clouds: {},
248240
matrix: {},
249241
}),
250242
),
251-
);
252-
253-
const cacheFile = join(env.testDir, "spawn", "manifest.json");
254-
if (existsSync(cacheFile)) {
255-
rmSync(cacheFile);
256-
}
257-
258-
await expect(loadManifest(true)).rejects.toThrow("Cannot load manifest");
259-
consoleSpy.mockRestore();
260-
});
261-
262-
it("rejects manifest with array clouds field", async () => {
263-
const consoleSpy = spyOn(console, "error").mockImplementation(() => {});
264-
global.fetch = mock(
265-
async () =>
243+
},
244+
{
245+
label: "array clouds field",
246+
fetchImpl: async () =>
266247
new Response(
267248
JSON.stringify({
268249
agents: {},
@@ -273,53 +254,38 @@ describe("manifest", () => {
273254
matrix: {},
274255
}),
275256
),
276-
);
277-
278-
const cacheFile = join(env.testDir, "spawn", "manifest.json");
279-
if (existsSync(cacheFile)) {
280-
rmSync(cacheFile);
281-
}
282-
283-
await expect(loadManifest(true)).rejects.toThrow("Cannot load manifest");
284-
consoleSpy.mockRestore();
285-
});
286-
287-
it("rejects manifest with numeric matrix field", async () => {
288-
const consoleSpy = spyOn(console, "error").mockImplementation(() => {});
289-
global.fetch = mock(
290-
async () =>
257+
},
258+
{
259+
label: "numeric matrix field",
260+
fetchImpl: async () =>
291261
new Response(
292262
JSON.stringify({
293263
agents: {},
294264
clouds: {},
295265
matrix: 42,
296266
}),
297267
),
298-
);
299-
300-
const cacheFile = join(env.testDir, "spawn", "manifest.json");
301-
if (existsSync(cacheFile)) {
302-
rmSync(cacheFile);
303-
}
304-
305-
await expect(loadManifest(true)).rejects.toThrow("Cannot load manifest");
306-
consoleSpy.mockRestore();
307-
});
308-
309-
it("throws when network errors occur and no cache exists", async () => {
310-
const consoleSpy = spyOn(console, "error").mockImplementation(() => {});
311-
global.fetch = mock(async () => {
312-
throw new Error("Network timeout");
268+
},
269+
{
270+
label: "network error",
271+
fetchImpl: async () => {
272+
throw new Error("Network timeout");
273+
},
274+
},
275+
];
276+
277+
for (const { label, fetchImpl } of invalidManifestCases) {
278+
it(`rejects invalid manifest (${label})`, async () => {
279+
const consoleSpy = spyOn(console, "error").mockImplementation(() => {});
280+
global.fetch = mock(fetchImpl);
281+
const cacheFile = join(env.testDir, "spawn", "manifest.json");
282+
if (existsSync(cacheFile)) {
283+
rmSync(cacheFile);
284+
}
285+
await expect(loadManifest(true)).rejects.toThrow("Cannot load manifest");
286+
consoleSpy.mockRestore();
313287
});
314-
315-
const cacheFile = join(env.testDir, "spawn", "manifest.json");
316-
if (existsSync(cacheFile)) {
317-
rmSync(cacheFile);
318-
}
319-
320-
await expect(loadManifest(true)).rejects.toThrow("Cannot load manifest");
321-
consoleSpy.mockRestore();
322-
});
288+
}
323289
});
324290
});
325291

packages/cli/src/__tests__/ui-cov.test.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,34 @@ afterEach(() => {
6262
// ── Logging functions ──────────────────────────────────────────────
6363

6464
describe("logging functions", () => {
65-
it("logInfo writes green text to stderr", () => {
66-
logInfo("test info");
67-
expect(stderrOutput.join("")).toContain("test info");
68-
});
69-
70-
it("logWarn writes yellow text to stderr", () => {
71-
logWarn("test warn");
72-
expect(stderrOutput.join("")).toContain("test warn");
73-
});
74-
75-
it("logError writes red text to stderr", () => {
76-
logError("test error");
77-
expect(stderrOutput.join("")).toContain("test error");
78-
});
79-
80-
it("logStep writes cyan text to stderr", () => {
81-
logStep("test step");
82-
expect(stderrOutput.join("")).toContain("test step");
83-
});
65+
for (const [fn, msg] of [
66+
[
67+
logInfo,
68+
"test info",
69+
],
70+
[
71+
logWarn,
72+
"test warn",
73+
],
74+
[
75+
logError,
76+
"test error",
77+
],
78+
[
79+
logStep,
80+
"test step",
81+
],
82+
] satisfies Array<
83+
[
84+
(msg: string) => void,
85+
string,
86+
]
87+
>) {
88+
it(`${fn.name} writes message to stderr`, () => {
89+
fn(msg);
90+
expect(stderrOutput.join("")).toContain(msg);
91+
});
92+
}
8493

8594
it("logStepInline writes message (newline-terminated in non-TTY)", () => {
8695
logStepInline("inline msg");

0 commit comments

Comments
 (0)