From 250ecbc2652548ef3efc449122ba64f8df7305bd Mon Sep 17 00:00:00 2001 From: Cindy Zhang Date: Thu, 19 Nov 2026 13:05:43 -0800 Subject: [PATCH 1/2] chore: preflight --quick reports a typecheck that fails only on missing workspace builds as skipped --- docs/contributing/pull-requests.md | 5 ++- scripts/preflight.mjs | 68 +++++++++++++++++++++++++++--- scripts/preflight.test.mjs | 61 +++++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 6 deletions(-) diff --git a/docs/contributing/pull-requests.md b/docs/contributing/pull-requests.md index 950922d89e774..75ae4d65aec83 100644 --- a/docs/contributing/pull-requests.md +++ b/docs/contributing/pull-requests.md @@ -164,7 +164,10 @@ ESLint on the changed files, the changed test files alone, `pnpm check:knowledge and `pnpm check:changesets`, in minutes. It is not CI-equivalent: it builds nothing, leaves out dependent packages, the tests the change reaches through an import, and the guards, and it ends with "run `pnpm preflight` before you flip" -rather than "ready to flip". +rather than "ready to flip". When every typecheck error names a workspace +package's build output (`@astryxdesign//built` or a `dist` path), the +typecheck reports SKIP ("workspace builds missing; run `pnpm build` first") and +does not count toward "not ready"; any other error fails it. Preflight is not a required step. It reproduces the pre-review checklist and CI's checks; it does not reproduce a reviewer's judgment. diff --git a/scripts/preflight.mjs b/scripts/preflight.mjs index fb93a2be9acd2..6cade3efe5ef5 100644 --- a/scripts/preflight.mjs +++ b/scripts/preflight.mjs @@ -6,7 +6,8 @@ * locally before the change is marked ready. * @input The committed change (`HEAD` against its merge base with `--base * `, default `origin/main`), `--browser`, `--quick` (the - * changed packages, files and tests alone; not CI's scope), and `--wrap + * changed packages, files and tests alone; not CI's scope; a typecheck + * that fails only on missing workspace builds reports SKIP), and `--wrap * ` (or `PREFLIGHT_WRAP`): a command that runs each heavy step as * ` `, such as a machine's * job limiter. A working tree with uncommitted changes stops the run. @@ -59,7 +60,7 @@ export function planChecks({ chromiumScope, quick = false, }) { - if (quick) return quickChecks({scope, mergeBase, changed}); + if (quick) return quickChecks({scope, mergeBase, changed, tmp}); const at = name => path.join(tmp, name); const checks = []; const specOnly = scope.specOnly || scope.timesOnly; @@ -387,7 +388,7 @@ function present(files) { * not CI's scope: no build, no dependent package, no test the change reaches * through an import, and no guard. */ -function quickChecks({scope, mergeBase, changed}) { +function quickChecks({scope, mergeBase, changed, tmp}) { const specOnly = scope.specOnly || scope.timesOnly; const typechecks = !specOnly && !scope.docsiteOnly && !scope.toolingOnly; const linted = present(changed.filter(file => LINTED.test(file))); @@ -414,6 +415,12 @@ function quickChecks({scope, mergeBase, changed}) { 'run', 'typecheck', ], + // Without a build, a package that reads a workspace package's + // build output fails to typecheck: that is not this change's + // error, so the check reports it as skipped. + stdout: path.join(tmp, 'typecheck.log'), + tee: true, + skipWhen: missingBuilds, }, ], } @@ -465,6 +472,24 @@ function quickChecks({scope, mergeBase, changed}) { ]; } +/** A missing module that is a workspace package's build output. */ +const BUILD_OUTPUT = + /error TS2307: Cannot find module '(?:@astryxdesign\/[^']+\/built(?:\/[^']*)?|[^']*\/dist(?:\/[^']*)?)'/; + +/** + * Why a failed typecheck is skipped, or null: every TypeScript error names a + * workspace package's build output (`@astryxdesign//built` or a `dist` + * path) that a run without `pnpm build` lacks. + * @param {string} text the typecheck's output + * @returns {string | null} + */ +export function missingBuilds(text) { + const errors = text.split('\n').filter(line => /error TS\d+/.test(line)); + if (errors.length === 0 || !errors.every(line => BUILD_OUTPUT.test(line))) + return null; + return 'skipped, workspace builds missing; run `pnpm build` first'; +} + function skip(id, why) { return {id, commands: [], skip: why}; } @@ -516,7 +541,27 @@ export function runChecks(checks, {exec, wrap = [], now = Date.now} = {}) { } if (command.kind !== 'light' && wrap.length) argv = [...wrap, command.kind, ...argv]; - const code = exec(argv, {env: command.env, stdout: command.stdout}); + const code = exec(argv, { + env: command.env, + stdout: command.stdout, + tee: command.tee, + }); + const skipped = + code !== 0 && command.skipWhen && command.stdout + ? command.skipWhen( + fs.existsSync(command.stdout) + ? fs.readFileSync(command.stdout, 'utf8') + : '', + ) + : null; + if (skipped) + return { + id: check.id, + result: 'SKIP', + note: skipped, + failed: null, + seconds: Math.round((now() - started) / 1000), + }; if (code !== 0) return { id: check.id, @@ -675,8 +720,21 @@ async function main(argv) { }); const rows = runChecks(checks, { wrap, - exec(command, {env, stdout}) { + exec(command, {env, stdout, tee}) { console.log(`\n== ${command.join(' ')}`); + if (stdout && tee) { + // Shows the output and keeps it for the check to read. + const result = spawnSync(command[0], command.slice(1), { + cwd: ROOT, + env: {...process.env, ...env}, + stdio: ['ignore', 'pipe', 'pipe'], + maxBuffer: 256 * 1024 * 1024, + }); + const text = `${result.stdout ?? ''}${result.stderr ?? ''}`; + process.stdout.write(text); + fs.writeFileSync(stdout, text); + return result.status ?? 1; + } const out = stdout ? fs.openSync(stdout, 'w') : 'inherit'; const result = spawnSync(command[0], command.slice(1), { cwd: ROOT, diff --git a/scripts/preflight.test.mjs b/scripts/preflight.test.mjs index b92043d20e91c..f826caa4a114f 100644 --- a/scripts/preflight.test.mjs +++ b/scripts/preflight.test.mjs @@ -21,6 +21,7 @@ import { chromiumSpecs, classify, formatTable, + missingBuilds, planChecks, runChecks, stopReason, @@ -272,6 +273,66 @@ describe('runChecks', () => { }); }); +describe('--quick with workspace builds missing', () => { + const missing = [ + "assets/templates/pages/a/page.tsx(9,28): error TS2307: Cannot find module '@astryxdesign/theme-neutral/built' or its corresponding type declarations.", + "src/x.ts(1,1): error TS2307: Cannot find module '../../core/dist/index.js' or its corresponding type declarations.", + ].join('\n'); + const real = `${missing}\nsrc/y.ts(3,5): error TS2322: Type 'string' is not assignable to type 'number'.`; + + it('names missing builds only when every error is a missing build output', () => { + expect(missingBuilds(missing)).toBe( + 'skipped, workspace builds missing; run `pnpm build` first', + ); + expect(missingBuilds(real)).toBeNull(); + expect(missingBuilds('no errors here')).toBeNull(); + expect( + missingBuilds( + "a.ts(1,1): error TS2307: Cannot find module 'left-pad' or its corresponding type declarations.", + ), + ).toBeNull(); + }); + + it('plans the quick typecheck to keep its output and judge it', () => { + const typecheck = byId( + plan(['packages/core/src/Button/Button.tsx'], {quick: true}), + 'typecheck', + ).commands[0]; + expect(typecheck.tee).toBe(true); + expect(typecheck.stdout).toMatch(/typecheck\.log$/); + expect(typecheck.skipWhen).toBe(missingBuilds); + }); + + it('reports a SKIP, not a failure, and the verdict does not count it', () => { + const dir = tmp(); + const log = path.join(dir, 'typecheck.log'); + const check = text => [ + { + id: 'typecheck', + commands: [ + { + kind: 'build', + argv: ['tsc'], + stdout: log, + tee: true, + skipWhen: missingBuilds, + }, + ], + }, + ]; + const exec = text => () => (fs.writeFileSync(log, text), 2); + const [skipped] = runChecks(check(), {exec: exec(missing), now: () => 0}); + expect(skipped).toMatchObject({ + result: 'SKIP', + note: 'skipped, workspace builds missing; run `pnpm build` first', + failed: null, + }); + expect(formatTable([skipped], {quick: true})).not.toContain('not ready'); + const [failed] = runChecks(check(), {exec: exec(real), now: () => 0}); + expect(failed).toMatchObject({result: 'FAIL', failed: 'tsc'}); + }); +}); + describe('stopReason', () => { it("stops with exit 2 on uncommitted changes, which CI's listers would not see", () => { expect( From 68876718084ddaaf0bad9b3a5c623465a1dcf2c7 Mon Sep 17 00:00:00 2001 From: Cindy Zhang Date: Thu, 19 Nov 2026 13:08:19 -0800 Subject: [PATCH 2/2] chore: a quick run whose typecheck was skipped for missing builds ends "not checked", never a pass --- docs/contributing/pull-requests.md | 4 ++-- scripts/preflight.mjs | 18 ++++++++++++++---- scripts/preflight.test.mjs | 8 +++++++- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/docs/contributing/pull-requests.md b/docs/contributing/pull-requests.md index 75ae4d65aec83..4fbc4bddfdf11 100644 --- a/docs/contributing/pull-requests.md +++ b/docs/contributing/pull-requests.md @@ -166,8 +166,8 @@ nothing, leaves out dependent packages, the tests the change reaches through an import, and the guards, and it ends with "run `pnpm preflight` before you flip" rather than "ready to flip". When every typecheck error names a workspace package's build output (`@astryxdesign//built` or a `dist` path), the -typecheck reports SKIP ("workspace builds missing; run `pnpm build` first") and -does not count toward "not ready"; any other error fails it. +typecheck reports SKIP ("workspace builds missing; run `pnpm build` first"), +and the run ends "not checked" rather than a pass; any other error fails it. Preflight is not a required step. It reproduces the pre-review checklist and CI's checks; it does not reproduce a reviewer's judgment. diff --git a/scripts/preflight.mjs b/scripts/preflight.mjs index 6cade3efe5ef5..0dfa49dc4beec 100644 --- a/scripts/preflight.mjs +++ b/scripts/preflight.mjs @@ -472,6 +472,9 @@ function quickChecks({scope, mergeBase, changed, tmp}) { ]; } +const MISSING_BUILDS = + 'skipped, workspace builds missing; run `pnpm build` first'; + /** A missing module that is a workspace package's build output. */ const BUILD_OUTPUT = /error TS2307: Cannot find module '(?:@astryxdesign\/[^']+\/built(?:\/[^']*)?|[^']*\/dist(?:\/[^']*)?)'/; @@ -487,7 +490,7 @@ export function missingBuilds(text) { const errors = text.split('\n').filter(line => /error TS\d+/.test(line)); if (errors.length === 0 || !errors.every(line => BUILD_OUTPUT.test(line))) return null; - return 'skipped, workspace builds missing; run `pnpm build` first'; + return MISSING_BUILDS; } function skip(id, why) { @@ -598,13 +601,20 @@ export function formatTable(rows, {quick = false} = {}) { lines.push('', 'Failing commands:'); for (const row of failed) lines.push(` ${row.id}: ${row.failed}`); } + // A typecheck skipped for missing builds checked nothing, so the verdict + // says so instead of reading as a pass. + const unbuilt = rows.filter( + row => row.result === 'SKIP' && row.note === MISSING_BUILDS, + ); lines.push( '', failed.length ? `not ready: ${failed.length}` - : quick - ? 'quick checks pass; run `pnpm preflight` before you flip' - : 'ready to flip', + : unbuilt.length + ? `not checked: ${unbuilt.map(row => row.id).join(', ')} (workspace builds missing); run \`pnpm build\`, then run again before you flip` + : quick + ? 'quick checks pass; run `pnpm preflight` before you flip' + : 'ready to flip', quick ? 'Quick mode is not CI-equivalent: it skips the build, dependent packages, the tests the change reaches and the guards.' : NOT_RUN, diff --git a/scripts/preflight.test.mjs b/scripts/preflight.test.mjs index f826caa4a114f..aa442103094f6 100644 --- a/scripts/preflight.test.mjs +++ b/scripts/preflight.test.mjs @@ -327,7 +327,13 @@ describe('--quick with workspace builds missing', () => { note: 'skipped, workspace builds missing; run `pnpm build` first', failed: null, }); - expect(formatTable([skipped], {quick: true})).not.toContain('not ready'); + const verdict = formatTable([skipped], {quick: true}); + expect(verdict).not.toContain('not ready'); + // A skipped typecheck checked nothing: the verdict says so, never a pass. + expect(verdict).toContain( + 'not checked: typecheck (workspace builds missing); run `pnpm build`, then run again before you flip', + ); + expect(verdict).not.toContain('quick checks pass'); const [failed] = runChecks(check(), {exec: exec(real), now: () => 0}); expect(failed).toMatchObject({result: 'FAIL', failed: 'tsc'}); });