Skip to content

Commit d297282

Browse files
committed
test(ui-merge): the pre-install import graph test pins the root lint-ui job
Sections 4 and 5 of `check-pre-install-import-graph.test.ts` read objectui's `repo-gates.yml`, which GitHub never runs under the monorepo and which the next change deletes. objectstack#25902 ported its steps into the root `ci.yml`'s `lint-ui` job, so the wiring pins read that job by path: one step runs both legs, before the install; the root trigger filters no path and subscribes merge_group; the `ui` filter matches `ci.yml` and the gate; no other job or root workflow runs it; the step keeps the check name. The header count pin and the measurement-point pin read the job's comments. Section 3's floor gains the four repo-gates rows its comment scheduled for this change, now derived under `lint-ui`, and the self-walk case asserts the gate is in its own derived population. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6SEitNngAMugGbuJHWsDS
1 parent 1bc0f01 commit d297282

1 file changed

Lines changed: 96 additions & 53 deletions

File tree

‎ui/scripts/__tests__/check-pre-install-import-graph.test.ts‎

Lines changed: 96 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { execFileSync } from 'node:child_process';
33
import fs from 'node:fs';
44
import path from 'node:path';
55
import { fileURLToPath } from 'node:url';
6+
import { parse as parseYaml } from 'yaml';
67

78
// Plain-JS CI helper. Its types are INFERRED from the .mjs source by
89
// `tsconfig.scripts.json` (`allowJs`), so no `@ts-expect-error` here —
@@ -19,6 +20,20 @@ import {
1920
import { REQUIRED_CONTEXTS } from '../dependabot-merge-gate.mjs';
2021

2122
import { selfTestCases, stripAnsi } from './helpers/child-verdict';
23+
import {
24+
globMatches,
25+
jobBlock,
26+
repoPath,
27+
rootCi,
28+
rootCiPath,
29+
rootWorkflow,
30+
rootWorkflowFiles,
31+
triggerBlock,
32+
uiFilterGlobs,
33+
uiRun,
34+
UI_JOBS,
35+
withoutComments,
36+
} from './helpers/root-ci';
2237

2338
/**
2439
* objectui#6148 — the gate for the property that lets a gate run pre-install.
@@ -45,8 +60,8 @@ import { selfTestCases, stripAnsi } from './helpers/child-verdict';
4560
* 3. **the floor over the real tree** — every step objectui#6148 measured
4661
* that still runs is still derived, by workflow and job rather than by count;
4762
* 4. **the wiring** — a gate nobody runs is indistinguishable from a gate that
48-
* passes, so the workflow, the alias and the Dependabot classification are
49-
* asserted here rather than trusted by reading;
63+
* passes, so the root `Lint UI` step, the alias and the Dependabot
64+
* classification are asserted here rather than trusted by reading;
5065
* 5. **the header states its population and never counts it** — objectui#8606.
5166
* The header sentence describing this run carried a literal population of
5267
* workflow files, derived from the same directory the gate derives from,
@@ -60,22 +75,18 @@ import { selfTestCases, stripAnsi } from './helpers/child-verdict';
6075
* `lint-workflow.test.ts` records at length.
6176
*/
6277
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
63-
const workflowDir = path.join(repoRoot, '.github/workflows');
6478
/** Where the gate reads `.github/workflows/`: the repository root, which GitHub runs. */
6579
const rootWorkflowRoot = workflowRoot(repoRoot);
6680
const SCRIPT = 'scripts/check-pre-install-import-graph.mjs';
67-
const WORKFLOW = 'repo-gates.yml';
81+
const ALIAS = 'check:pre-install-import-graph';
82+
/**
83+
* The gate's home, as failure messages name it: the root `lint-ui` job, which
84+
* runs objectui's former `repo-gates.yml` steps since objectstack#25902
85+
* (objectstack#25712 deleted that workflow with the rest of `ui/.github/workflows/`).
86+
*/
87+
const WORKFLOW = `ci.yml (${UI_JOBS.lint})`;
6888
const CHECK_NAME = 'Pre-Install Import Graph Check';
6989

70-
/** A workflow's YAML with whole-line comments removed — every file here discusses the shapes in prose. */
71-
const withoutComments = (yaml: string): string =>
72-
yaml
73-
.split('\n')
74-
.filter((line) => !/^\s*#/.test(line))
75-
.join('\n');
76-
77-
const readWorkflow = (file: string): string => fs.readFileSync(path.join(workflowDir, file), 'utf8');
78-
7990
// ── 1. the derivation is a derivation ────────────────────────────────────────
8091

8192
describe('the population follows the workflows', () => {
@@ -290,25 +301,27 @@ describe('the real tree — every step objectui#6148 measured is still derived',
290301
* drift.
291302
*
292303
* Since objectstack#25712 the rows are the repository root's `ci.yml`, the
293-
* workflow GitHub runs. Two of objectui#6148's rows run there:
294-
* `ci.yml : type-check` is now `type-check-ui`, and `lint.yml : lint` is now
295-
* `lint-ui` (roster rows 7 and 16 of objectstack#25697). The others ran in
296-
* workflows nothing runs since the monorepo merge:
297-
*
298-
* - `changeset-guard.yml : no-major`, `changeset-presence.yml :
299-
* changeset-presence` and `ci.yml : changeset-check`: roster rows 3, 4
300-
* and 7 (→ sub-issue 4 of objectstack#25677);
301-
* - the four `repo-gates.yml : repo-gates` rows (`check-control-bytes`,
302-
* `check-doc-component-types`, `check-doc-links`, `check-skills-paths`):
303-
* objectstack#25880 ports those gates into `lint-ui` ahead of its
304-
* install, and they rejoin this floor under that job when
305-
* `ui/.github/workflows/` is deleted (objectstack#25712).
304+
* workflow GitHub runs. Six of objectui#6148's rows run there:
305+
* `ci.yml : type-check` is now `type-check-ui`, `lint.yml : lint` is now
306+
* `lint-ui` (roster rows 7 and 16 of objectstack#25697), and the four
307+
* `repo-gates.yml : repo-gates` rows (`check-control-bytes`,
308+
* `check-doc-component-types`, `check-doc-links`, `check-skills-paths`) run in
309+
* `lint-ui` ahead of its install since objectstack#25902 ported that workflow's
310+
* steps there. The others ran in workflows objectstack#25712 deleted, which
311+
* GitHub never ran under the monorepo: `changeset-guard.yml : no-major`,
312+
* `changeset-presence.yml : changeset-presence` and `ci.yml :
313+
* changeset-check`, roster rows 3, 4 and 7 (→ sub-issue 4 of
314+
* objectstack#25677).
306315
*/
307316
const MEASURED = [
308317
'ci.yml : type-check-ui -> scripts/check-type-check-coverage.mjs',
309318
'ci.yml : lint-ui -> scripts/check-lint-coverage.mjs',
310319
'ci.yml : lint-ui -> scripts/check-entry-guard.mjs',
311320
'ci.yml : lint-ui -> scripts/check-bash32-floor.mjs',
321+
'ci.yml : lint-ui -> scripts/check-control-bytes.mjs',
322+
'ci.yml : lint-ui -> scripts/check-doc-component-types.mjs',
323+
'ci.yml : lint-ui -> scripts/check-doc-links.mjs',
324+
'ci.yml : lint-ui -> scripts/check-skills-paths.mjs',
312325
];
313326

314327
it.each(MEASURED)('still derives %s', (row) => {
@@ -325,10 +338,10 @@ describe('the real tree — every step objectui#6148 measured is still derived',
325338

326339
it('holds its own import graph to the floor — the gate walks itself', () => {
327340
// A floor that exempted its own enforcer would be the first thing to rot.
328-
// Its home was objectui's `repo-gates.yml`, which runs nowhere since the
329-
// monorepo merge, so it is not in its own DERIVED population until the root
330-
// `Lint UI` job runs it (objectstack#25712 adds that step when it deletes
331-
// `ui/.github/workflows/`). Until then it is walked by name.
341+
// The root `Lint UI` job runs it before its install (objectstack#25902), so
342+
// it is in its own DERIVED population and the findings case below covers
343+
// it. The walk by name stays as the control that reaches past the entry.
344+
expect(rows, 'the gate left its own derived population').toContain(`ci.yml : ${UI_JOBS.lint} -> ${SCRIPT}`);
332345
const read = (rel: string): string | null => {
333346
try {
334347
return fs.readFileSync(path.join(repoRoot, rel), 'utf8');
@@ -357,58 +370,88 @@ describe('the real tree — every step objectui#6148 measured is still derived',
357370
// ── 4. the wiring ────────────────────────────────────────────────────────────
358371

359372
describe('the gate is wired, not merely present', () => {
360-
const yaml = withoutComments(readWorkflow(WORKFLOW));
373+
/**
374+
* GitHub runs only the repository root's `.github/workflows/`, so the wiring is
375+
* the root `ci.yml`'s: objectstack#25902 ported objectui's `repo-gates.yml`
376+
* into its `lint-ui` job, which runs the gate through its alias
377+
* (objectstack#25712). Every pin below reads that file by path.
378+
*/
379+
const ci = rootCi();
380+
const steps: Array<Record<string, unknown>> = parseYaml(ci).jobs[UI_JOBS.lint].steps;
381+
const runs = (s: Record<string, unknown>) => typeof s.run === 'string' && (s.run as string).includes(uiRun(ALIAS));
382+
const gateSteps = steps.filter(runs);
361383

362384
it('exists, with a package.json alias that names the same file', () => {
363385
expect(fs.existsSync(path.join(repoRoot, SCRIPT))).toBe(true);
364386
const pkg = JSON.parse(fs.readFileSync(path.join(repoRoot, 'package.json'), 'utf8'));
365-
expect(pkg.scripts['check:pre-install-import-graph']).toContain(SCRIPT);
387+
expect(pkg.scripts[ALIAS]).toBe(`node ${SCRIPT}`);
366388
});
367389

368390
it('runs both legs — the self-test first, then the scan', () => {
369-
expect(yaml).toContain(`node ${SCRIPT} --self-test`);
370-
expect(yaml.split('\n').some((l) => l.trim() === `node ${SCRIPT}`)).toBe(true);
391+
expect(gateSteps, `${WORKFLOW} must run the gate in exactly one step`).toHaveLength(1);
392+
const lines = (gateSteps[0].run as string).split('\n').map((l) => l.trim());
393+
const selfTestAt = lines.indexOf(`${uiRun(ALIAS)} --self-test`);
394+
const scanAt = lines.indexOf(uiRun(ALIAS));
395+
expect(selfTestAt).toBeGreaterThan(-1);
396+
expect(scanAt, 'the scan must follow the self-test').toBeGreaterThan(selfTestAt);
371397
});
372398

373399
it('runs before its job installs anything, which is the property it exists to protect', () => {
374-
// Since objectui#12214 the home is `repo-gates.yml`, one job that installs
375-
// AFTER its install-free gates; this gate must stay on the near side.
376-
const gateAt = yaml.indexOf(`node ${SCRIPT} --self-test`);
377-
const installAt = yaml.indexOf('pnpm install');
400+
// Since objectui#12214 the home is one job that installs AFTER its
401+
// install-free gates (`repo-gates.yml` then, the root `lint-ui` now); this
402+
// gate must stay on the near side.
403+
const gateAt = steps.findIndex(runs);
404+
const installAt = steps.findIndex((s) => typeof s.run === 'string' && /\bpnpm install\b/.test(s.run as string));
378405
expect(gateAt).toBeGreaterThan(-1);
379406
expect(installAt === -1 || gateAt < installAt, 'the gate step moved below the install step').toBe(true);
380407
});
381408

382409
it('carries NO path filter of any kind', () => {
383410
// Deliberate: its input is the workflows themselves, and a workflow edit is
384411
// the change most likely to break it. A filter would also make the check
385-
// unrequirable (objectui#3523).
386-
expect(yaml).not.toMatch(/paths-ignore:/);
387-
expect(yaml).not.toMatch(/^\s+paths:/m);
412+
// unrequirable (objectui#3523). The root trigger filters no path; the job
413+
// runs on the `filter` job's `ui` globs, which must match the workflow
414+
// whose steps are the population today and the gate itself.
415+
const on = withoutComments(triggerBlock(ci));
416+
expect(on).not.toMatch(/paths-ignore:/);
417+
expect(on).not.toMatch(/^\s+paths:/m);
418+
const globs = uiFilterGlobs(ci);
419+
const missed = ['.github/workflows/ci.yml', repoPath(SCRIPT)]
420+
.filter((file) => !globs.some((glob) => globMatches(glob, file)));
421+
expect(missed, `a change to these would skip ${WORKFLOW}`).toEqual([]);
388422
});
389423

390424
it('subscribes merge_group, so a queue build is not stalled by a silent context', () => {
391-
expect(yaml).toMatch(/^\s{2}merge_group:/m);
425+
expect(triggerBlock(ci)).toMatch(/^\s{2}merge_group:/m);
392426
});
393427

394-
it('is the only workflow that runs it — one gate, one home', () => {
395-
const runners = fs
396-
.readdirSync(workflowDir)
397-
.filter((f) => f.endsWith('.yml'))
398-
.filter((f) => withoutComments(readWorkflow(f)).includes(SCRIPT));
399-
expect(runners).toEqual([WORKFLOW]);
428+
it('is the only job and workflow that runs it — one gate, one home', () => {
429+
const jobs = Object.entries(parseYaml(ci).jobs as Record<string, { steps?: Array<Record<string, unknown>> }>)
430+
.filter(([, job]) => (job.steps ?? []).some(runs))
431+
.map(([key]) => key);
432+
expect(jobs).toEqual([UI_JOBS.lint]);
433+
const others = rootWorkflowFiles()
434+
.filter((f) => f !== path.basename(rootCiPath))
435+
.filter((f) => {
436+
const text = withoutComments(rootWorkflow(f));
437+
return text.includes(ALIAS) || text.includes(SCRIPT);
438+
});
439+
expect(others).toEqual([]);
400440
});
401441

402442
it('is classified by the Dependabot merge gate as a blocking check', () => {
403443
// objectui#6135: an UNCLASSIFIED blocking check is one a Dependabot merge
404444
// would be let past. `dependabot-merge-gate.test.ts` asserts the partition
405445
// itself; this asserts the direction that matters for this check.
406-
// Since objectui#12214 it reports as a step of the one `Repo Gates` context.
446+
// Since objectui#12214 it reports as a step of the one `Repo Gates` context
447+
// in objectui's register. In this repository the step reports under
448+
// `Lint UI`, and that register is roster row 9's (→ sub-issue 4).
407449
expect(REQUIRED_CONTEXTS).toContain('Repo Gates');
408450
});
409451

410452
it('names the same check in the workflow as the gate requires', () => {
411-
expect(yaml).toContain(`name: ${CHECK_NAME}`);
453+
expect(gateSteps).toHaveLength(1);
454+
expect(String(gateSteps[0].name)).toMatch(new RegExp(`^${CHECK_NAME} — `));
412455
});
413456

414457
it('passes its own self-test', () => {
@@ -549,7 +592,7 @@ describe("the header's population is a pointer, not a copy", () => {
549592
*/
550593
it('states no count that adding a workflow would falsify', () => {
551594
const surfaces = [
552-
[WORKFLOW, headerComments(readWorkflow(WORKFLOW))],
595+
[WORKFLOW, headerComments(jobBlock(rootCi(), UI_JOBS.lint))],
553596
["this test file's own header", ownHeaderComment()],
554597
] as const;
555598

@@ -575,8 +618,8 @@ describe("the header's population is a pointer, not a copy", () => {
575618
// read out of the gate. A header that stops naming it leaves the reader
576619
// with no way to take the reading, which is the state this card found.
577620
const dir = derivedPopulationDir();
578-
const prose = headerComments(readWorkflow(WORKFLOW));
579-
expect(prose, `${WORKFLOW}'s header must name \`${dir}\` — the population's one live source`).toContain(dir);
621+
const prose = headerComments(jobBlock(rootCi(), UI_JOBS.lint));
622+
expect(prose, `${WORKFLOW}'s comments must name \`${dir}\` — the population's one live source`).toContain(dir);
580623

581624
// …and the pointer must point at something. A named directory that holds no
582625
// workflows is a measurement point in form only. The gate resolves it

0 commit comments

Comments
 (0)