Skip to content

Commit 35212c7

Browse files
committed
test(cli): share each repeated spawn in the two per-package parity files (#23181 slice 16)
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5pUpKjymejZTAe9SWn
1 parent 51724fb commit 35212c7

2 files changed

Lines changed: 69 additions & 38 deletions

File tree

‎packages/cli/test/lint-per-package-authoring-parity.test.ts‎

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,17 @@ export default defineStack({
212212

213213
const dirs = { flip: '', single: '' };
214214

215+
/** A cold `tsx` spawn of the CLI source entry, the per-case allowance this file always gave one. */
216+
const SPAWN_TIMEOUT_MS = 180_000;
217+
218+
/**
219+
* One run per distinct (command, flags, fixture) triple. The cases below used
220+
* to spawn `os build --json` on the flip fixture three times and `os lint
221+
* --json` on it three times; every case now reads the one run of its triple,
222+
* spawned in sequence in the `beforeAll` below.
223+
*/
224+
const runs = {} as Record<'buildFlip' | 'lintFlip' | 'lintStrictFlip' | 'buildSingle' | 'lintSingle', Run>;
225+
215226
function plant(config: string): string {
216227
const dir = mkdtempSync(join(tmpdir(), 'os-lintpp-'));
217228
mkdirSync(join(dir, 'src'), { recursive: true });
@@ -226,31 +237,36 @@ function plant(config: string): string {
226237
}
227238

228239
describe('#18778 — `os lint` and `os build` report the same per-package finding set', () => {
229-
beforeAll(() => {
240+
beforeAll(async () => {
230241
dirs.flip = plant(CONFIG_FLIP);
231242
dirs.single = plant(CONFIG_SINGLE);
232-
});
243+
runs.buildFlip = await runCli(['build', '--json'], dirs.flip);
244+
runs.lintFlip = await runCli(['lint', '--json'], dirs.flip);
245+
runs.lintStrictFlip = await runCli(['lint', '--json', '--strict'], dirs.flip);
246+
runs.buildSingle = await runCli(['build', '--json'], dirs.single);
247+
runs.lintSingle = await runCli(['lint', '--json'], dirs.single);
248+
}, 5 * SPAWN_TIMEOUT_MS);
233249

234250
afterAll(() => {
235251
for (const dir of Object.values(dirs)) if (dir) rmSync(dir, { recursive: true, force: true });
236252
});
237253

238-
it('the fixture reaches the pass at all, and the UNION sees nothing — `os build` raises exactly the survivor', async () => {
254+
it('the fixture reaches the pass at all, and the UNION sees nothing — `os build` raises exactly the survivor', () => {
239255
// Asserted BEFORE any claim about parity: a fixture that never reaches the
240256
// per-package pass makes every comparison below vacuous, and a fixture whose
241257
// union run raises the same finding makes the comparison an echo count.
242-
const build = await runCli(['build', '--json'], dirs.flip);
258+
const build = runs.buildFlip;
243259
expect(build.code, `os build --json failed:\n${build.stdout}${build.stderr}`).toBe(0);
244260
const warnings = payloadOf(build, 'os build --json').warnings as unknown[];
245261
expect(buildPerPackage(warnings).length).toBeGreaterThan(0);
246262
// Nothing else: every warning on this fixture is a per-package survivor.
247263
expect(warnings.length).toBe(buildPerPackage(warnings).length);
248-
}, 180_000);
264+
});
249265

250-
it('`os lint` reports every per-package finding `os build` does', async () => {
266+
it('`os lint` reports every per-package finding `os build` does', () => {
251267
// The pin. On `origin/main` 7572329069 this read `build: 1, lint: 0`.
252-
const build = await runCli(['build', '--json'], dirs.flip);
253-
const lint = await runCli(['lint', '--json'], dirs.flip);
268+
const build = runs.buildFlip;
269+
const lint = runs.lintFlip;
254270
expect(build.code, `os build --json failed:\n${build.stdout}${build.stderr}`).toBe(0);
255271
expect(lint.code, `os lint --json failed:\n${lint.stdout}${lint.stderr}`).toBe(0);
256272

@@ -261,25 +277,25 @@ describe('#18778 — `os lint` and `os build` report the same per-package findin
261277
missing,
262278
'these per-package findings ride `os build` and `os lint` cannot see them — the #18778 false-clean set',
263279
).toEqual([]);
264-
}, 180_000);
280+
});
265281

266-
it('…and nothing per-package rides `os lint` that `os build` does not report either', async () => {
282+
it('…and nothing per-package rides `os lint` that `os build` does not report either', () => {
267283
// Parity is an equality. A lint that over-reports is its own defect — an
268284
// author fixing a finding the command that SHIPS never raises.
269-
const build = await runCli(['build', '--json'], dirs.flip);
270-
const lint = await runCli(['lint', '--json'], dirs.flip);
285+
const build = runs.buildFlip;
286+
const lint = runs.lintFlip;
271287
const inBuild = new Set(buildPerPackage(payloadOf(build, 'os build --json').warnings as unknown[]));
272288
expect(lintPerPackage(payloadOf(lint, 'os lint --json').issues as unknown[]).filter((w) => !inBuild.has(w))).toEqual([]);
273-
}, 180_000);
289+
});
274290

275-
it('⚠️ THE NARROWING — `os lint --strict` now EXITS 1 on a project it exited 0 for', async () => {
291+
it('⚠️ THE NARROWING — `os lint --strict` now EXITS 1 on a project it exited 0 for', () => {
276292
// The Clause-② evidence, pinned so it can neither regress silently nor widen
277293
// silently. `--strict` is documented as "treat warnings as errors", and a
278294
// per-package advisory is a warning this door could not see before, so the
279295
// verdict moves with it. ⛔ The DEFAULT face is deliberately NOT asserted to
280296
// move: no `error`-severity per-package-only finding was exhibited on this
281297
// fixture, and a pin asserting one would be asserting something unmeasured.
282-
const strict = await runCli(['lint', '--json', '--strict'], dirs.flip);
298+
const strict = runs.lintStrictFlip;
283299
const payload = payloadOf(strict, 'os lint --json --strict');
284300
expect(payload.strict).toBe(true);
285301
expect(payload.failing).toBe(1);
@@ -288,21 +304,21 @@ describe('#18778 — `os lint` and `os build` report the same per-package findin
288304

289305
// …and the same project without `--strict` still exits 0, so what moved is
290306
// the strict verdict and not the default one.
291-
const plain = await runCli(['lint', '--json'], dirs.flip);
307+
const plain = runs.lintFlip;
292308
expect(plain.code).toBe(0);
293309
expect(payloadOf(plain, 'os lint --json').passed).toBe(true);
294-
}, 180_000);
310+
});
295311

296-
it('CONTROL — a single-package project raises NO per-package finding on either door', async () => {
312+
it('CONTROL — a single-package project raises NO per-package finding on either door', () => {
297313
// "Present" must be distinguishable from "always present": the prefix this
298314
// file matches on is not something either command emits unconditionally, and
299315
// `os lint --strict` still exits 1 there for the ORDINARY warning, which is
300316
// how the case above is read as a change and not as a constant.
301-
const build = await runCli(['build', '--json'], dirs.single);
302-
const lint = await runCli(['lint', '--json'], dirs.single);
317+
const build = runs.buildSingle;
318+
const lint = runs.lintSingle;
303319
expect(build.code, `os build --json failed:\n${build.stdout}${build.stderr}`).toBe(0);
304320
expect(lint.code, `os lint --json failed:\n${lint.stdout}${lint.stderr}`).toBe(0);
305321
expect(buildPerPackage(payloadOf(build, 'os build --json').warnings as unknown[])).toEqual([]);
306322
expect(lintPerPackage(payloadOf(lint, 'os lint --json').issues as unknown[])).toEqual([]);
307-
}, 180_000);
323+
});
308324
});

‎packages/cli/test/validate-per-package-authoring-parity.test.ts‎

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,17 @@ export default defineStack({
231231

232232
const dirs = { multi: '', single: '' };
233233

234+
/** A cold `tsx` spawn of the CLI source entry, the per-case allowance this file always gave one. */
235+
const SPAWN_TIMEOUT_MS = 180_000;
236+
237+
/**
238+
* One run per distinct (command, flags, fixture) triple. The cases below used
239+
* to spawn `os build --json` on the multi-package fixture three times and `os
240+
* validate --json` on it twice; every case now reads the one run of its
241+
* triple, spawned in sequence in the `beforeAll` below.
242+
*/
243+
const runs = {} as Record<'buildMulti' | 'validateMulti' | 'buildSingle' | 'validateSingle', Run>;
244+
234245
function plant(config: string): string {
235246
const dir = mkdtempSync(join(tmpdir(), 'os-ppparity-'));
236247
mkdirSync(join(dir, 'src'), { recursive: true });
@@ -245,20 +256,24 @@ function plant(config: string): string {
245256
}
246257

247258
describe('#18677 — `os validate` and `os build` report the same per-package advisory set', () => {
248-
beforeAll(() => {
259+
beforeAll(async () => {
249260
dirs.multi = plant(CONFIG_MULTI);
250261
dirs.single = plant(CONFIG_SINGLE);
251-
});
262+
runs.buildMulti = await runCli(['build', '--json'], dirs.multi);
263+
runs.validateMulti = await runCli(['validate', '--json'], dirs.multi);
264+
runs.buildSingle = await runCli(['build', '--json'], dirs.single);
265+
runs.validateSingle = await runCli(['validate', '--json'], dirs.single);
266+
}, 4 * SPAWN_TIMEOUT_MS);
252267

253268
afterAll(() => {
254269
for (const dir of Object.values(dirs)) if (dir) rmSync(dir, { recursive: true, force: true });
255270
});
256271

257-
it('the multi-package fixture reaches the pass at all — and its survivor is NOT an echo', async () => {
272+
it('the multi-package fixture reaches the pass at all — and its survivor is NOT an echo', () => {
258273
// Asserted BEFORE any claim about parity: a fixture that never reaches the
259274
// per-package pass makes every comparison below vacuous, which is the exact
260275
// way this defect stayed invisible.
261-
const build = await runCli(['build', '--json'], dirs.multi);
276+
const build = runs.buildMulti;
262277
expect(build.code, `os build --json failed:\n${build.stdout}${build.stderr}`).toBe(0);
263278
const warnings = payloadOf(build, 'os build --json').warnings as unknown[];
264279
expect(perPackageWarnings(warnings).length).toBeGreaterThan(0);
@@ -277,12 +292,12 @@ describe('#18677 — `os validate` and `os build` report the same per-package ad
277292
PER_PACKAGE_WHERE.test(named(industryWarnings[0])),
278293
'the `industry` finding is being raised by the UNION run — the survivor would be an echo',
279294
).toBe(true);
280-
}, 180_000);
295+
});
281296

282-
it('`os validate` reports every per-package advisory `os build` does', async () => {
297+
it('`os validate` reports every per-package advisory `os build` does', () => {
283298
// The pin. On `origin/main` 09e16a574 this read `build: 1, validate: 0`.
284-
const build = await runCli(['build', '--json'], dirs.multi);
285-
const validate = await runCli(['validate', '--json'], dirs.multi);
299+
const build = runs.buildMulti;
300+
const validate = runs.validateMulti;
286301
expect(build.code, `os build --json failed:\n${build.stdout}${build.stderr}`).toBe(0);
287302
expect(validate.code, `os validate --json failed:\n${validate.stdout}${validate.stderr}`).toBe(0);
288303

@@ -295,29 +310,29 @@ describe('#18677 — `os validate` and `os build` report the same per-package ad
295310
missingFromValidate,
296311
'these per-package findings ride `os build` and `os validate` cannot see them — the #18677 false-clean set',
297312
).toEqual([]);
298-
}, 180_000);
313+
});
299314

300-
it('…and nothing per-package rides `os validate` that `os build` does not report either', async () => {
315+
it('…and nothing per-package rides `os validate` that `os build` does not report either', () => {
301316
// The reverse end. Parity is an equality, and a validate that over-reports
302317
// is its own defect — an author fixing a finding the command that SHIPS
303318
// never raises.
304-
const build = await runCli(['build', '--json'], dirs.multi);
305-
const validate = await runCli(['validate', '--json'], dirs.multi);
319+
const build = runs.buildMulti;
320+
const validate = runs.validateMulti;
306321
const bw = payloadOf(build, 'os build --json').warnings as unknown[];
307322
const vw = payloadOf(validate, 'os validate --json').warnings as unknown[];
308323

309324
const inBuild = new Set(perPackageWarnings(bw));
310325
expect(perPackageWarnings(vw).filter((w) => !inBuild.has(w))).toEqual([]);
311-
}, 180_000);
326+
});
312327

313-
it('CONTROL — a single-package project raises NO per-package finding on either door', async () => {
328+
it('CONTROL — a single-package project raises NO per-package finding on either door', () => {
314329
// "Present" must be distinguishable from "always present": the prefix this
315330
// file matches on is not something either command emits unconditionally.
316-
const build = await runCli(['build', '--json'], dirs.single);
317-
const validate = await runCli(['validate', '--json'], dirs.single);
331+
const build = runs.buildSingle;
332+
const validate = runs.validateSingle;
318333
expect(build.code, `os build --json failed:\n${build.stdout}${build.stderr}`).toBe(0);
319334
expect(validate.code, `os validate --json failed:\n${validate.stdout}${validate.stderr}`).toBe(0);
320335
expect(perPackageWarnings(payloadOf(build, 'os build --json').warnings as unknown[])).toEqual([]);
321336
expect(perPackageWarnings(payloadOf(validate, 'os validate --json').warnings as unknown[])).toEqual([]);
322-
}, 180_000);
337+
});
323338
});

0 commit comments

Comments
 (0)