Skip to content

Commit bd1ec2e

Browse files
spawn-qa-botclaude
authored 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 5d733c6 commit bd1ec2e

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
@@ -208,52 +208,33 @@ describe("manifest", () => {
208208
await expect(loadManifest(true)).rejects.toThrow("Cannot load manifest");
209209
});
210210

211-
it("throws when manifest from GitHub is invalid", async () => {
212-
const consoleSpy = spyOn(console, "error").mockImplementation(() => {});
213-
global.fetch = mock(
214-
async () =>
211+
const invalidManifestCases: Array<{
212+
label: string;
213+
fetchImpl: () => Promise<Response>;
214+
}> = [
215+
{
216+
label: "non-manifest shape",
217+
fetchImpl: async () =>
215218
new Response(
216219
JSON.stringify({
217220
not: "a manifest",
218221
}),
219222
),
220-
);
221-
222-
const cacheFile = join(env.testDir, "spawn", "manifest.json");
223-
if (existsSync(cacheFile)) {
224-
rmSync(cacheFile);
225-
}
226-
227-
await expect(loadManifest(true)).rejects.toThrow("Cannot load manifest");
228-
consoleSpy.mockRestore();
229-
});
230-
231-
it("rejects manifest with string agents field", async () => {
232-
const consoleSpy = spyOn(console, "error").mockImplementation(() => {});
233-
global.fetch = mock(
234-
async () =>
223+
},
224+
{
225+
label: "string agents field",
226+
fetchImpl: async () =>
235227
new Response(
236228
JSON.stringify({
237229
agents: "claude",
238230
clouds: {},
239231
matrix: {},
240232
}),
241233
),
242-
);
243-
244-
const cacheFile = join(env.testDir, "spawn", "manifest.json");
245-
if (existsSync(cacheFile)) {
246-
rmSync(cacheFile);
247-
}
248-
249-
await expect(loadManifest(true)).rejects.toThrow("Cannot load manifest");
250-
consoleSpy.mockRestore();
251-
});
252-
253-
it("rejects manifest with array clouds field", async () => {
254-
const consoleSpy = spyOn(console, "error").mockImplementation(() => {});
255-
global.fetch = mock(
256-
async () =>
234+
},
235+
{
236+
label: "array clouds field",
237+
fetchImpl: async () =>
257238
new Response(
258239
JSON.stringify({
259240
agents: {},
@@ -264,53 +245,38 @@ describe("manifest", () => {
264245
matrix: {},
265246
}),
266247
),
267-
);
268-
269-
const cacheFile = join(env.testDir, "spawn", "manifest.json");
270-
if (existsSync(cacheFile)) {
271-
rmSync(cacheFile);
272-
}
273-
274-
await expect(loadManifest(true)).rejects.toThrow("Cannot load manifest");
275-
consoleSpy.mockRestore();
276-
});
277-
278-
it("rejects manifest with numeric matrix field", async () => {
279-
const consoleSpy = spyOn(console, "error").mockImplementation(() => {});
280-
global.fetch = mock(
281-
async () =>
248+
},
249+
{
250+
label: "numeric matrix field",
251+
fetchImpl: async () =>
282252
new Response(
283253
JSON.stringify({
284254
agents: {},
285255
clouds: {},
286256
matrix: 42,
287257
}),
288258
),
289-
);
290-
291-
const cacheFile = join(env.testDir, "spawn", "manifest.json");
292-
if (existsSync(cacheFile)) {
293-
rmSync(cacheFile);
294-
}
295-
296-
await expect(loadManifest(true)).rejects.toThrow("Cannot load manifest");
297-
consoleSpy.mockRestore();
298-
});
299-
300-
it("throws when network errors occur and no cache exists", async () => {
301-
const consoleSpy = spyOn(console, "error").mockImplementation(() => {});
302-
global.fetch = mock(async () => {
303-
throw new Error("Network timeout");
259+
},
260+
{
261+
label: "network error",
262+
fetchImpl: async () => {
263+
throw new Error("Network timeout");
264+
},
265+
},
266+
];
267+
268+
for (const { label, fetchImpl } of invalidManifestCases) {
269+
it(`rejects invalid manifest (${label})`, async () => {
270+
const consoleSpy = spyOn(console, "error").mockImplementation(() => {});
271+
global.fetch = mock(fetchImpl);
272+
const cacheFile = join(env.testDir, "spawn", "manifest.json");
273+
if (existsSync(cacheFile)) {
274+
rmSync(cacheFile);
275+
}
276+
await expect(loadManifest(true)).rejects.toThrow("Cannot load manifest");
277+
consoleSpy.mockRestore();
304278
});
305-
306-
const cacheFile = join(env.testDir, "spawn", "manifest.json");
307-
if (existsSync(cacheFile)) {
308-
rmSync(cacheFile);
309-
}
310-
311-
await expect(loadManifest(true)).rejects.toThrow("Cannot load manifest");
312-
consoleSpy.mockRestore();
313-
});
279+
}
314280
});
315281
});
316282

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)