import { spawn, spawnSync } from 'node:child_process'; import { appendFileSync, closeSync, existsSync, mkdtempSync, openSync, readFileSync, realpathSync, rmSync, } from 'node:fs'; import { constants as osConstants, tmpdir } from 'node:os'; import { basename, dirname, extname, join, matchesGlob, relative, } from 'node:path'; import { fileURLToPath, pathToFileURL } from 'node:url'; import { TEST_TIMEOUT_MS, TEST_FAST_IGNORE_PATTERNS, TEST_FILE_PATTERNS, } from '../config/test-suites.mjs'; import { packageTestFiles } from '../entrypoints/entrypoint-turbo.mjs'; import { freshRun, openCache } from './check-cache.mjs'; import { commonDir, ensureStandaloneLockfiles, installLockfile, INTERRUPTED, lockfileInstalled, stepLogger, typicalSeconds, } from './check-steps.mjs'; import { mentionsOutsideComments, runtimeClosure, storedGraph, } from './import-graph.mjs'; import { PLITE_BROWSER_SHARDS, shardAffected, } from './plite-browser-shards.mjs'; import { hasPrivateHalf, trackedFiles } from './private-files.mjs'; import { workerBudget } from './worker-budget.mjs'; const root = fileURLToPath(new URL('../..', import.meta.url)); const touches = (...prefixes) => (files) => files.some((file) => prefixes.some((prefix) => file.startsWith(prefix))); const matches = (path, file) => path.endsWith('/') ? file.startsWith(path) : file === path; const UNLINTED_PATHS = [ '.agents/', '.claude/', '.codex/', 'AGENTS.md', 'docs/', 'skills/', ]; const PROSE = /\.(?:md|mdc|tsv)$/u; const unlinted = (file) => PROSE.test(file) && UNLINTED_PATHS.some((path) => matches(path, file)); export const isProse = (file) => PROSE.test(file) && (!file.includes('/') || unlinted(file)); const FORMATTER_ONLY = new Set(['skills-lock.json']); const isPrivateApp = (file) => file.startsWith('private-apps/'); const formatted = (files) => files.some((file) => !unlinted(file) && !isPrivateApp(file)); const CODE = /\.(?:[cm]?[jt]sx?|sh)$/u; const RESOLVER_CONFIG = /(?:^|\/)(?:tsconfig[^/]*|package)\.json$/u; // Resolution never tries a prose extension, and an import that names one by // its full path could not resolve before the file was added. const canRetargetImports = (files, retargeted) => retargeted.some((file) => !PROSE.test(file)) || touches( '.gitprivate', 'tooling/scripts/import-graph.mjs', 'tooling/scripts/private-files.mjs' )(files) || files.some((file) => RESOLVER_CONFIG.test(file)); // A formal check is one Bun script under the source aliases, so a source file // reaches it only through that script's runtime imports. A public checkout // lacks the private scripts, and drops their steps before any runs. const runsScript = (script, ...paths) => { let closure; return (files, retargeted) => { if (canRetargetImports(files, retargeted)) return true; if (touches(script, 'config/plite-source-aliases.ts', ...paths)(files)) { return true; } closure ??= existsSync(join(root, script)) ? new Set( runtimeClosure([join(root, script)]).map((file) => relative(root, file) ) ) : new Set(); return files.some((file) => closure.has(file)); }; }; const TEST = /\.(?:test|spec)\.[cm]?[jt]sx?$/u; const BUILD_CONFIG = /(?:^|\/)(?:package|turbo|tsconfig[\w.-]*)\.json$/u; const isPackageCodeOrConfig = (pkg) => (file) => file.startsWith(`packages/${pkg}/`) && !file.startsWith(`packages/${pkg}/test/`) && !TEST.test(file) && !PROSE.test(file); const turboPackageTestCommand = (filter, fallbackCores) => `pnpm turbo run test --filter=${filter} --concurrency=\${CHECK_CORES:-${fallbackCores}} --continue --output-logs=errors-only --log-order=grouped`; const inTestSuite = (file) => TEST_FILE_PATTERNS.some((pattern) => matchesGlob(file, pattern)) && !TEST_FAST_IGNORE_PATTERNS.some((pattern) => matchesGlob(file, pattern)); const isToolingScript = (file) => CODE.test(file) && (file.startsWith('tooling/scripts/') || file.startsWith('tooling/entrypoints/') || file.startsWith('.agents/')); const isAgentFile = (file) => file.startsWith('.agents/') && !isProse(file); const CLASSIFIED = new RegExp(`(?:${CODE.source}|${BUILD_CONFIG.source})`, 'u'); let reachSources; const sources = () => (reachSources ??= trackedFiles(root, { untracked: true }).flatMap((file) => { if (file.startsWith('docs/') || !CLASSIFIED.test(file)) return []; try { return [{ bytes: readFileSync(join(root, file)), file, text: null }]; } catch { return []; } })); const latin1Text = (source) => (source.text ??= source.bytes.toString('latin1')); const mayName = (source, extensions) => extensions.some((extension) => source.bytes.includes(extension)); const literal = (text) => text.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&'); const namePattern = (paths) => new RegExp( `(? literal(basename(path))).join('|')})`, 'u' ); const toolingReaches = new Map(); const toolingReach = (file) => { if (!isToolingScript(file) && !isAgentFile(file)) return null; if (toolingReaches.has(file)) return toolingReaches.get(file); const reach = { product: false, scripts: new Set([file]), tests: new Set(TEST.test(file) ? [file] : []), }; const dataImport = CODE.test(file) ? null : new RegExp( `(?:\\bfrom\\s*|\\b(?:import|require)\\s*\\(\\s*)['"][^'"]*(? 0) { const pattern = namePattern(level); const carriers = level.filter((path) => typeCarriers.has(path)); const carrierPattern = carriers.length > 0 ? namePattern(carriers) : null; const extensions = [...new Set(level.map((path) => extname(path)))].map( (extension) => Buffer.from(extension) ); const hits = sources().filter( (source) => mayName(source, extensions) && pattern.test(latin1Text(source)) ); const named = (hit) => mentionsOutsideComments(join(root, hit.file), pattern); const importsData = (hit) => dataImport.test(latin1Text(hit)); const namesCarrier = (hit) => carrierPattern !== null && mentionsOutsideComments(join(root, hit.file), carrierPattern); const carriesTypes = first && dataImport ? importsData : namesCarrier; level = []; for (const hit of hits) { if (TEST.test(hit.file)) { if (!reach.tests.has(hit.file) && named(hit)) { reach.tests.add(hit.file); } } else if (isToolingScript(hit.file)) { if (typeCarriers.has(hit.file) || !named(hit)) continue; const fresh = !reach.scripts.has(hit.file); const carries = carriesTypes(hit); reach.scripts.add(hit.file); if (carries) typeCarriers.add(hit.file); if (fresh || carries) level.push(hit.file); } else if ( !reach.product && hit.file !== 'package.json' && (CODE.test(hit.file) || BUILD_CONFIG.test(hit.file)) ) { reach.product = first ? named(hit) : carriesTypes(hit); } } first = false; } toolingReaches.set(file, reach); return reach; }; const reachesProduct = (file) => toolingReach(file)?.product ?? true; // tsc, oxlint and the audits this rule gates read only scripts and JSON, so // another file reaches them only once deleted, when code may still import it. // A step that reads more, such as plite-docs, names those paths itself. const TYPED = /\.(?:[cm]?[jt]sx?|sh|json)$/u; const source = (files) => files.some( (file) => !isProse(file) && !isPrivateApp(file) && !FORMATTER_ONLY.has(file) && (TYPED.test(file) || !existsSync(join(root, file))) && reachesProduct(file) ); // A change to one of these can reach every step, so --affected runs them all. const GLOBAL_PATHS = [ 'bunfig.toml', 'config/', 'package.json', 'pnpm-workspace.yaml', 'tooling/config/', 'tsconfig.json', 'turbo.json', ]; // pnpm-lock.yaml lists each workspace package's dependencies under // `importers:` and the packages they resolve to under `packages:` and // `snapshots:`. A change that edits only importers, and adds or drops whole // resolved packages, reaches only those importers' manifests; any other // change can reach every step. const LOCKFILE = 'pnpm-lock.yaml'; const RESOLVED = new Set(['packages', 'snapshots']); const LOCKFILE_KEY = /^ *("[^"]*"|'(?:[^']|'')*'|[^\s"':][^:]*?):(?: |$)/u; /** Each top-level key's entries, keyed by name, or null on a line it cannot read. */ const lockfileSections = (text) => { const sections = new Map(); let entries = null; let entry = ''; for (const line of text.split('\n')) { const top = /^\S/u.test(line); if (top || (entries && /^ {2}\S/u.test(line))) { const key = LOCKFILE_KEY.exec(line); if (!key) return null; const value = line.slice(key[0].length); entry = top ? '' : key[1]; if (top) { entries = new Map(); sections.set(key[1], entries); } entries.set(entry, value ? `${value}\n` : ''); } else if (entries && line.trim()) { entries.set(entry, `${entries.get(entry)}${line}\n`); } } return sections; }; const lockfileChange = (before, after) => { const [was, now] = [lockfileSections(before), lockfileSections(after)]; if (!was || !now) return null; const manifests = []; for (const name of new Set([...was.keys(), ...now.keys()])) { const [a, b] = [was.get(name), now.get(name)]; if (!a || !b) return null; for (const key of new Set([...a.keys(), ...b.keys()])) { if (a.get(key) === b.get(key)) continue; if (name === 'importers' && key) { const dir = key.replace(/^'(.*)'$/u, '$1'); manifests.push(dir === '.' ? 'package.json' : `${dir}/package.json`); } else if (!RESOLVED.has(name) || !key || a.has(key) === b.has(key)) { return null; } } } return manifests; }; const lockfileChanges = new Map(); /** The manifests that lockfile changes reach, or null for every step. */ const lockfileReach = (pairs) => { if (!pairs?.length) return null; const manifests = new Set(); for (const [before, after] of pairs) { if (before === null || after === null) return null; let change = lockfileChanges.get(before)?.get(after); if (change === undefined) { change = lockfileChange(before, after); lockfileChanges.set( before, (lockfileChanges.get(before) ?? new Map()).set(after, change) ); } if (change === null) return null; for (const manifest of change) manifests.add(manifest); } return [...manifests]; }; // ci-workflow.test.mjs lists tooling/scripts to find check scripts that no // step runs, so it reaches each one without naming it. const CHECK_SCRIPT = /^tooling\/scripts\/(?:check-.*|.*-check)\.mjs$/u; const packageDiff = () => spawnSync( 'bash', [ '-c', 'git diff --no-ext-diff -- packages; git ls-files --others --exclude-standard -- packages', ], { cwd: root, encoding: 'utf-8', maxBuffer: 1024 * 1024 * 256 } ).stdout; // Steps run side by side within the worker share that land.mjs reserves for // its checks. `cores` is how many of those slots a step occupies, default 1, // passed to its command as CHECK_CORES. Two steps that name the // same folder in `holds` never overlap, because one of them writes it. An // `alone` step runs after every other step, one at a time, for the reason its // value gives. Under --affected, the `quick` steps run first and the rest // start only once every one of them passes, and no step starts after one // fails, so a type, lint or citation error fails a landing before any slow // step starts. Under --affected, which every landing runs, only the `land` // steps run. Local CI runs every other step on next after landing. A formal // check's `light` command runs a smaller bound of the same check, the one a // session runs before a diff panel, and --light runs it in place of `run`. // `light: true` marks a check whose gate already runs in under two minutes at // its 90th percentile, so its light run is the gate. let imports; const importGraph = () => { if (imports) return imports; const real = realpathSync(root); const { moduleSpecifiers, resolveImport, save } = storedGraph( join(commonDir(root), 'plate-imports'), real ); const edges = new Map(); const edgesOf = (file) => { if (!edges.has(file)) { let specifiers = []; try { specifiers = moduleSpecifiers(file); } catch { // A file that does not parse has no imports to follow; typecheck and // the test that loads it report the parse error. } edges.set( file, specifiers .map((specifier) => resolveImport(file, specifier)) .filter(Boolean) ); } return edges.get(file); }; imports = { edgesOf, real, save }; return imports; }; let testImporters; const fastTestImporters = () => { if (testImporters) return testImporters; const { edgesOf, real, save } = importGraph(); testImporters = new Map(); for (const test of trackedFiles(root, { untracked: true }).filter( inTestSuite )) { const seen = new Set(); const pending = [join(real, test)]; while (pending.length > 0) { const file = pending.pop(); if (seen.has(file)) continue; seen.add(file); pending.push(...edgesOf(file)); } for (const file of seen) { const loaded = relative(real, file); if (!testImporters.has(loaded)) testImporters.set(loaded, new Set()); testImporters.get(loaded).add(test); } } save(); return testImporters; }; const namingTests = (file) => { const folder = dirname(file); const names = (dir) => { if (dir === '.') return [file, ...(folder.includes('/') ? [folder] : [])]; const near = folder === dir || folder.startsWith(`${dir}/`); return [ file, ...(folder.includes('/') ? [folder] : []), relative(dir, file), ...(near ? [basename(file)] : []), ...(near && folder !== dir ? [folder.slice(dir.length + 1)] : []), ]; }; const patterns = new Map(); const patternFor = (dir) => { if (!patterns.has(dir)) { patterns.set( dir, new RegExp( `(? { const pattern = patternFor(dirname(script.file)); return pattern.test(latin1Text(script)) && mentionsOutsideComments(join(root, script.file), pattern) ? [...(fastTestImporters().get(script.file) ?? [])] : []; }) ), ]; }; // A test that loads a file through a computed path is missed here, and Local // CI's full run catches it on next after landing. Bun ignores the www // Playwright specs, so editing one cannot change the tests. const reachesTests = (files) => { const product = files.filter( (file) => touches( '.agents/rules/', '.github/workflows/', 'apps/', 'benchmarks/', 'content/', 'packages/', 'tooling/' )([file]) && reachesProduct(file) && !file.startsWith('apps/www/tests/browser/') ); const placed = (file) => { const tests = fastTestImporters().get(file); if (tests) return [...tests]; if (!existsSync(join(root, file)) || BUILD_CONFIG.test(file)) return null; return CODE.test(file) ? [] : namingTests(file); }; const loading = product.map(placed); if (loading.some((tests) => !tests)) return true; return [ ...new Set([ ...loading.flat(), ...files.flatMap((file) => [ ...(toolingReach(file)?.tests ?? []), ...(CHECK_SCRIPT.test(file) ? ['tooling/scripts/ci-workflow.test.mjs'] : []), ].filter(inTestSuite) ), ]), ].filter((test) => existsSync(join(root, test))); }; let packageTestImports; const directPackageTestImporters = (files) => { if (!packageTestImports) { const { edgesOf, real, save } = importGraph(); packageTestImports = new Map(); for (const [test, { browser }] of packageTestFiles()) { if (browser) continue; for (const file of [ test, ...edgesOf(join(real, test)).map((loaded) => relative(real, loaded)), ]) { if (!packageTestImports.has(file)) { packageTestImports.set(file, new Set()); } packageTestImports.get(file).add(test); } } save(); } return [ ...new Set( files.flatMap((file) => [...(packageTestImports.get(file) ?? [])]) ), ].sort((a, b) => a.localeCompare(b)); }; export const steps = [ { name: 'lint', quick: true, run: 'pnpm lint', fix: 'pnpm lint:fix', affected: formatted, key: ['date'], filesOnly: true, standaloneLockfiles: true, }, { name: 'lint-type-aware', cores: 2, holds: [ 'packages/plitejs/dist', 'packages/platejs/dist', 'packages/cli/dist', 'packages/test/dist', ], run: 'pnpm lint:type-aware', affected: source, key: ['date'], filesOnly: true, standaloneLockfiles: true, }, { name: 'lint-baseline', land: true, quick: true, run: 'node tooling/oxlint/plate-baseline.mjs --check', fix: 'pnpm lint:baseline', affected: source, key: ['date'], standaloneLockfiles: true, }, { name: 'typecheck', land: true, quick: true, cores: 3, holds: ['packages/cli/tmp-*'], run: 'pnpm typecheck && node tooling/scripts/check-source-declaration-leaks.mjs', affected: source, key: [], filesOnly: true, }, { // tsc reads the route types in the ignored apps/plite/.next/types, so the // step clears stale route types and writes them from the app's source first. name: 'plite-app-typecheck', quick: true, holds: ['apps/plite/.next'], run: 'pnpm exec rimraf apps/plite/.next/types && pnpm --filter plite exec next typegen && pnpm --filter plite typecheck', affected: source, key: [], filesOnly: true, }, { name: 'plite-device-typecheck', quick: true, private: true, run: 'pnpm --filter plite typecheck:device', affected: source, key: [], filesOnly: true, }, { name: 'type-tests', quick: true, private: true, run: 'pnpm test:types', affected: source, key: [], filesOnly: true, }, { name: 'test', land: true, cores: 4, holds: ['apps/www/.source'], private: true, run: 'pnpm test:fast', key: [], affected: reachesTests, }, { name: 'test-slow', cores: 4, holds: ['apps/www/.source'], private: true, run: 'pnpm test:slow', key: [], affected: reachesTests, }, ...PLITE_BROWSER_SHARDS.map((shard) => ({ name: shard.name, cores: 4, holds: ['packages/test/dist', 'apps/plite/.next', 'apps/plite/out'], private: true, run: `pnpm --filter plite test:plite-browser:shard ${shard.name}`, optIn: '--browser', affected: shardAffected(shard), key: [], })), { name: 'www-tokens-browser', cores: 2, holds: ['apps/www/.source-dev', 'apps/www/.next'], run: 'PLATE_WWW_SKIP_REGISTRY_BUILD=1 pnpm --filter www test:www-browser:chromium tests/browser/suggestion-colors.spec.ts tests/browser/diff-and-cursor-colors.spec.ts tests/browser/dark-mode-chrome-contrast.spec.ts', optIn: '--browser', affected: touches( 'apps/www/playwright.config.ts', 'apps/www/scripts/run-www-browser.mjs', 'apps/www/src/app/globals.css', 'apps/www/src/registry/registry-styles.ts', 'apps/www/src/registry/components/editor/', 'apps/www/tests/browser/global-setup.ts', 'apps/www/tests/browser/suggestion-colors.spec.ts', 'apps/www/tests/browser/diff-and-cursor-colors.spec.ts', 'apps/www/tests/browser/dark-mode-chrome-contrast.spec.ts' ), key: [], }, { name: 'plitejs-test', cores: 4, private: true, run: turboPackageTestCommand('plitejs', 4), affected: (files) => touches( '.changeset/', 'apps/plite/tests/plite-browser/', 'apps/www/src/app/(app)/examples/plite/', 'content/docs/', 'packages/plitejs/', 'tooling/entrypoints/', 'tooling/scripts/run-entrypoint-package-task.mjs', 'tooling/scripts/run-entrypoint-task.mjs' )(files) || files.some((file) => /^packages\/[^/]+\/(?:package\.json|README\.md|Readme\.md)$/u.test(file) ), key: [], }, { name: 'platejs-test', cores: 4, private: true, run: turboPackageTestCommand('platejs', 4), affected: (files) => touches( 'apps/www/src/__tests__/package-integration/docx/', 'packages/platejs/', 'packages/test/package.json', 'tooling/entrypoints/', 'tooling/scripts/run-entrypoint-package-task.mjs', 'tooling/scripts/run-entrypoint-task.mjs' )(files) || files.some(isPackageCodeOrConfig('plitejs')), key: [], }, { name: 'test-package-test', cores: 2, private: true, run: turboPackageTestCommand('@platejs/test', 2), affected: (files) => touches( 'packages/test/', 'tooling/entrypoints/', 'tooling/scripts/run-entrypoint-package-task.mjs', 'tooling/scripts/run-entrypoint-task.mjs' )(files) || files.some( (file) => isPackageCodeOrConfig('platejs')(file) || isPackageCodeOrConfig('plitejs')(file) ), key: [], }, { name: 'package-tests', land: true, partOf: ['plitejs-test', 'platejs-test', 'test-package-test'], onlyAffectedFiles: true, cores: 2, private: true, run: 'node tooling/scripts/package-tests.mjs --skip-slow', key: [], affected: directPackageTestImporters, }, { name: 'authored-order', cores: 4, private: true, optIn: '--audit', run: 'pnpm check:authored-order', light: 'pnpm check:authored-order --light', affected: runsScript( 'packages/plitejs/scripts/authored-decision-order.ts', 'packages/plitejs/scripts/', 'packages/plitejs/test/', 'tooling/scripts/finding-baseline.mjs' ), key: [], }, { name: 'autoformat-rules', cores: 4, private: true, run: 'pnpm check:autoformat-rules', light: 'pnpm check:autoformat-rules --light', affected: runsScript( 'apps/www/scripts/autoformat-input-rules.ts', 'apps/www/scripts/autoformat-input-rules', 'apps/www/src/registry/components/editor/autoformat.tsx', 'apps/www/src/registry/components/editor/basic-marks.tsx', 'tooling/scripts/finding-baseline.mjs' ), key: [], }, { name: 'combobox-invariants', cores: 1, private: true, run: 'pnpm check:combobox-invariants', light: 'pnpm check:combobox-invariants --light', affected: runsScript( 'packages/platejs/scripts/combobox-invariants.ts', 'packages/platejs/src/react/features/combobox/', 'packages/platejs/src/lib/plugins/input-rules/inputRuleVeto.internal.ts', 'packages/plitejs/src/react/editable/typed-text.ts' ), key: [], }, { name: 'menu-ranking-invariants', cores: 1, private: true, run: 'pnpm check:menu-ranking-invariants', light: 'pnpm check:menu-ranking-invariants --light', affected: runsScript( 'apps/www/scripts/menu-ranking-invariants.ts', 'apps/www/src/registry/components/editor/rank-options.ts', 'apps/www/src/registry/lib/emoji-data.ts' ), key: [], }, { name: 'v4-intent-oracle', cores: 2, run: 'pnpm check:v4-intent-oracle', light: 'pnpm check:v4-intent-oracle --light', affected: runsScript( 'packages/plitejs/scripts/v4-intent-oracle.ts', 'packages/plitejs/src/core/change/v4/', 'packages/plitejs/src/sync/server/v4-take-back.ts', 'packages/plitejs/src/history/history-v4-adapters.ts' ), key: [], }, { name: 'authored-safety', cores: 1, private: true, run: 'pnpm check:authored-safety', light: 'pnpm check:authored-safety --light', affected: runsScript( 'packages/plitejs/scripts/authored-safety.ts', 'packages/plitejs/src/authored/', 'packages/plitejs/src/core/authored-runtime.ts', 'packages/plitejs/src/core/change/v4/extract.ts', 'packages/plitejs/src/core/unique-directory.ts', 'packages/plitejs/src/core/view-presentation.ts', 'packages/plitejs/src/sync/server/v4-admission.ts' ), key: [], }, { name: 'clipboard-invariants', cores: 1, private: true, run: 'pnpm check:clipboard-invariants', light: 'pnpm check:clipboard-invariants --light', affected: runsScript( 'packages/plitejs/scripts/clipboard-invariants.ts', 'packages/plitejs/scripts/check-harness.ts', 'packages/plitejs/src/core/slice-fit/', 'packages/plitejs/src/core/slice-landing.ts', 'packages/plitejs/src/core/content-slice.ts', 'packages/plitejs/src/core/transfer.ts', 'packages/plitejs/src/dom/plugin/dom-clipboard-runtime.ts', 'packages/plitejs/src/dom/plugin/data-transfer-format.ts', 'packages/plitejs/src/react/editable/clipboard-input-strategy.ts', 'tooling/scripts/finding-baseline.mjs' ), key: [], }, { name: 'diff-invariants', cores: 2, run: 'pnpm check:diff-invariants', light: 'pnpm check:diff-invariants --light', affected: runsScript( 'packages/plitejs/scripts/diff-invariants.ts', 'packages/plitejs/src/diff/', 'packages/plitejs/src/authored/comparison.ts', 'packages/plitejs/src/core/change/v4/extract.ts', 'tooling/scripts/finding-baseline.mjs' ), key: [], }, { name: 'native-invariants', cores: 1, private: true, run: 'pnpm check:native-invariants', light: 'pnpm check:native-invariants --light', affected: runsScript( 'packages/plitejs/scripts/native-invariants.ts', 'packages/plitejs/src/dom/plugin/dom-editor.ts', 'packages/plitejs/src/dom/plugin/dom-event-range-targets.ts', 'packages/plitejs/src/dom/plugin/dom-input-runtime.ts', 'packages/plitejs/src/dom/plugin/dom-integrity-observer.ts', 'packages/plitejs/src/dom/plugin/dom-root-runtime.ts', 'packages/plitejs/src/dom/plugin/dom-sync-mutation-ownership.ts', 'packages/plitejs/src/dom/plugin/dom-text-display.ts', 'packages/plitejs/src/dom/plugin/dom-text-flow-index.ts', 'packages/plitejs/src/dom/utils/dom.ts', 'packages/plitejs/src/dom/utils/hotkey-match.ts', 'packages/plitejs/src/dom/utils/selection-writes.ts', 'packages/plitejs/src/internal/dom-host-engine.ts', 'packages/plitejs/src/internal/hotkey-matcher.ts', 'packages/plitejs/src/react/editable/android-composition.ts', 'packages/plitejs/src/react/editable/clipboard-input-strategy.ts', 'packages/plitejs/src/react/editable/composition-lease.ts', 'packages/plitejs/src/react/editable/composition-state.ts', 'packages/plitejs/src/react/editable/dom-repair-queue.ts', 'packages/plitejs/src/react/editable/dom-repair-text.ts', 'packages/plitejs/src/react/editable/editable-dom-runtime.ts', 'packages/plitejs/src/react/editable/editing-kernel.ts', 'packages/plitejs/src/react/editable/input-controller.ts', 'packages/plitejs/src/react/editable/input-router.ts', 'packages/plitejs/src/react/editable/input-state.ts', 'packages/plitejs/src/react/editable/interaction-owner.ts', 'packages/plitejs/src/react/editable/keyboard-input-strategy.ts', 'packages/plitejs/src/react/editable/model-input-strategy.ts', 'packages/plitejs/src/react/editable/mutation-controller.ts', 'packages/plitejs/src/react/editable/press-fence.ts', 'packages/plitejs/src/react/editable/runtime-before-input-events.ts', 'packages/plitejs/src/react/editable/runtime-focus-mouse-events.ts', 'packages/plitejs/src/react/editable/selection-change-listener.ts', 'packages/plitejs/src/react/editable/selection-reconciler.ts', 'packages/plitejs/src/react/editable/unread-press.ts', 'tooling/scripts/finding-baseline.mjs' ), key: [], }, { name: 'selection-invariants', cores: 1, private: true, run: 'pnpm check:selection-invariants', light: 'pnpm check:selection-invariants --light', affected: runsScript( 'packages/plitejs/scripts/selection-invariants.ts', 'packages/plitejs/src/interfaces/location.ts', 'packages/plitejs/src/interfaces/path.ts', 'packages/plitejs/src/interfaces/point.ts', 'packages/plitejs/src/interfaces/range.ts', 'packages/plitejs/src/interfaces/selection.ts', 'packages/plitejs/src/core/selection-protocol.ts', 'packages/plitejs/src/core/selection-state.ts', 'packages/plitejs/src/core/anchor.ts', 'packages/plitejs/src/core/anchor-map.ts', 'packages/plitejs/src/core/anchor-shared.ts', 'packages/plitejs/src/core/anchor-state.ts', 'packages/plitejs/src/core/anchor-document-view.ts', 'packages/plitejs/src/core/node-selection.ts', 'packages/plitejs/src/core/state-view.ts', 'packages/plitejs/src/core/transaction-view.ts', 'packages/plitejs/src/editor/before.ts', 'packages/plitejs/src/editor/after.ts', 'packages/plitejs/src/editor/adjacent-character-point.ts', 'packages/plitejs/src/editor/range.ts', 'packages/plitejs/src/editor/delete-backward.ts', 'packages/plitejs/src/editor/delete-slice.ts', 'packages/plitejs/src/transforms-selection/', 'packages/plitejs/src/internal/shadow-dom.ts', 'packages/plitejs/src/dom/plugin/dom-root-runtime.ts', 'packages/plitejs/src/react/editable/selection-import.ts', 'packages/plitejs/src/react/editable/selection-export.ts', 'packages/plitejs/src/react/editable/selection-reconciler.ts', 'packages/plitejs/src/react/editable/selection-controller.ts', 'packages/plitejs/src/react/editable/selection-projected-dom.ts', 'packages/plitejs/src/react/editable/selection-triple-click.ts', 'tooling/scripts/finding-baseline.mjs' ), key: [], }, { name: 'editing-ranges-invariants', cores: 1, private: true, run: 'pnpm check:editing-ranges-invariants', light: 'pnpm check:editing-ranges-invariants --light', affected: runsScript( 'packages/plitejs/scripts/editing-ranges-invariants.ts', 'packages/plitejs/src/transforms-text/', 'packages/plitejs/src/transforms-node/merge-nodes.ts', 'packages/plitejs/src/transforms-node/split-nodes.ts', 'packages/plitejs/src/editor/delete-backward.ts', 'packages/plitejs/src/editor/delete-forward.ts', 'packages/plitejs/src/editor/delete-slice.ts', 'packages/plitejs/src/editor/reach.ts', 'packages/plitejs/src/core/whole-block-landing.ts', 'packages/plitejs/src/core/content-landing.ts', 'packages/plitejs/src/core/target-runtime.ts', 'packages/plitejs/src/core/command-registry.ts', 'packages/plitejs/src/core/representation.ts' ), key: [], }, { name: 'sync-simulation', cores: 4, private: true, run: 'pnpm check:sync-simulation', light: 'pnpm check:sync-simulation --light', affected: runsScript( 'packages/plitejs/scripts/sync-simulation.ts', 'packages/plitejs/scripts/check-harness.ts', 'packages/plitejs/test/support/sync-world.ts' ), key: [], }, { name: 'authored-recording', cores: 4, private: true, optIn: '--audit', run: 'pnpm check:authored-recording', light: 'pnpm check:authored-recording --light', affected: runsScript( 'packages/plitejs/scripts/authored-recording-order.ts', 'packages/plitejs/scripts/authored-recording-order', 'packages/plitejs/scripts/authored-documents', 'packages/plitejs/scripts/check-harness', 'packages/plitejs/scripts/letter-commands', 'packages/plitejs/test/support/', 'tooling/scripts/finding-baseline.mjs' ), key: [], }, { name: 'undo-redo-history', cores: 4, private: true, optIn: '--audit', run: 'pnpm check:undo-redo-history', light: 'pnpm check:undo-redo-history --light', affected: runsScript( 'packages/plitejs/scripts/undo-redo-history.ts', 'packages/plitejs/scripts/undo-redo-history', 'packages/plitejs/scripts/authored-documents', 'packages/plitejs/scripts/check-harness', 'packages/plitejs/scripts/letter-commands', 'packages/plitejs/test/support/', 'tooling/scripts/finding-baseline.mjs' ), key: [], }, { name: 'delete-paste-ranges', cores: 4, private: true, optIn: '--audit', run: 'pnpm check:delete-paste-ranges', light: 'pnpm check:delete-paste-ranges --light', affected: runsScript( 'packages/plitejs/scripts/delete-paste-ranges.ts', 'packages/plitejs/scripts/delete-paste-ranges', 'packages/plitejs/scripts/authored-documents', 'packages/plitejs/scripts/check-harness', 'packages/plitejs/test/support/', 'tooling/scripts/finding-baseline.mjs' ), key: [], }, { name: 'docx-import-report', cores: 4, run: 'pnpm check:docx-import-report', light: true, affected: runsScript( 'packages/platejs/scripts/docx-import-report.ts', 'packages/platejs/scripts/docx-import-report' ), key: [], }, { name: 'docx-round-trip', cores: 4, run: 'pnpm check:docx-round-trip', light: true, affected: runsScript( 'packages/platejs/scripts/docx-round-trip.ts', 'packages/platejs/scripts/docx-round-trip' ), key: [], }, { name: 'markdown-round-trip', optIn: '--audit', cores: 4, private: true, run: 'pnpm check:markdown-round-trip && bun test ./packages/platejs/scripts/markdown-round-trip-previews.spec.ts', light: true, affected: runsScript( 'packages/platejs/scripts/markdown-round-trip.ts', 'packages/platejs/scripts/markdown-round-trip', 'packages/plitejs/scripts/check-harness', 'tooling/scripts/finding-baseline.mjs' ), key: [], }, { name: 'table-grid', cores: 4, private: true, run: 'pnpm check:table-grid', light: true, affected: runsScript( 'packages/platejs/scripts/table-grid-commands.ts', 'packages/platejs/scripts/table-grid-commands', 'packages/plitejs/scripts/check-harness', 'tooling/scripts/finding-baseline.mjs' ), key: [], }, { name: 'comments-invariants', cores: 1, private: true, run: 'pnpm check:comments-invariants', light: 'pnpm check:comments-invariants --light', affected: runsScript( 'packages/platejs/scripts/comments-invariants.ts', 'packages/platejs/src/features/comments/', 'packages/platejs/src/internal/comments/comment-anchor.internal.ts', 'packages/plitejs/scripts/check-harness', 'tooling/scripts/finding-baseline.mjs' ), key: [], }, { name: 'conversion-invariants', cores: 1, private: true, run: 'pnpm check:conversion-invariants', light: 'pnpm check:conversion-invariants --light', affected: runsScript( 'packages/platejs/scripts/conversion-invariants.ts', 'packages/platejs/src/internal/plugin/conversionLaws.ts', 'packages/platejs/src/internal/plugin/pluginFormatOperation.ts', 'packages/platejs/src/internal/utils/urlPolicy.ts', 'packages/platejs/src/lib/plugins/html/', 'packages/platejs/src/html/server/', 'packages/platejs/src/markdown/lib/', 'packages/platejs/src/docx/', 'packages/platejs/src/plain-text.ts', 'packages/plitejs/scripts/check-harness', 'tooling/scripts/finding-baseline.mjs' ), key: [], }, { name: 'upload-invariants', cores: 1, private: true, run: 'pnpm check:upload-invariants', light: 'pnpm check:upload-invariants --light', affected: runsScript( 'packages/platejs/scripts/upload-invariants.ts', 'packages/platejs/src/features/upload/', 'packages/platejs/src/react/features/upload/', 'packages/plitejs/src/authored/facts/grant.ts', 'packages/plitejs/src/authored/facts/writes.ts', 'packages/plitejs/scripts/check-harness', 'tooling/scripts/finding-baseline.mjs' ), key: [], }, { name: 'field-invariants', cores: 1, private: true, run: 'pnpm check:field-invariants', light: 'pnpm check:field-invariants --light', affected: runsScript( 'packages/platejs/scripts/field-invariants.ts', 'packages/platejs/src/features/field/', 'packages/platejs/src/react/features/field/' ), key: [], }, { name: 'find-invariants', cores: 1, private: true, run: 'pnpm check:find-invariants', light: 'pnpm check:find-invariants --light', affected: runsScript( 'packages/platejs/scripts/find-invariants.ts', 'packages/platejs/src/features/find/', 'packages/plitejs/src/internal/text-run.ts', 'packages/plitejs/src/interfaces/node.ts', 'packages/plitejs/scripts/check-harness', 'tooling/scripts/finding-baseline.mjs' ), key: [], }, { name: 'persistence-invariants', cores: 1, private: true, run: 'pnpm check:persistence-invariants', light: 'pnpm check:persistence-invariants --light', affected: runsScript( 'packages/platejs/scripts/persistence-invariants.ts', 'packages/platejs/src/migrations/', 'packages/plitejs/src/core/persisted-document.ts', 'packages/plitejs/src/core/value-codec.ts', 'packages/plitejs/src/core/document-fit.ts', 'packages/plitejs/src/core/document-shape.ts', 'packages/plitejs/src/core/json-fingerprint.ts', 'packages/plitejs/scripts/check-harness', 'tooling/scripts/finding-baseline.mjs' ), key: [], }, { name: 'agent-invariants', cores: 1, private: true, run: 'pnpm check:agent-invariants', light: 'pnpm check:agent-invariants --light', affected: runsScript( 'packages/platejs/scripts/agent-invariants.ts', 'packages/platejs/src/ai/' ), key: [], }, { name: 'ink-invariants', cores: 1, private: true, run: 'pnpm check:ink-invariants', light: 'pnpm check:ink-invariants --light', affected: runsScript( 'packages/platejs/scripts/ink-invariants.ts', 'packages/platejs/src/features/ink/', 'packages/platejs/src/react/features/ink/', 'packages/platejs/src/ai/lib/editorAgent.ts', 'packages/plitejs/src/core/record-policy.ts' ), key: [], }, { name: 'link-invariants', cores: 1, private: true, run: 'pnpm check:link-invariants', light: 'pnpm check:link-invariants --light', affected: runsScript( 'packages/platejs/scripts/link-invariants.ts', 'packages/platejs/src/internal/utils/urlPolicy.ts', 'packages/platejs/src/features/link/', 'packages/platejs/src/features/reference/' ), key: [], }, { name: 'events-handlers-invariants', cores: 1, private: true, run: 'pnpm check:events-handlers-invariants', light: 'pnpm check:events-handlers-invariants --light', affected: runsScript( 'packages/platejs/scripts/events-handlers-invariants.ts', 'packages/platejs/src/internal/plugin/OverridePlugin.ts', 'packages/platejs/src/internal/plugin/compilePlateShortcuts.ts', 'packages/platejs/src/internal/plugin/domHandlers.ts', 'packages/platejs/src/lib/plugins/affinity/', 'packages/platejs/src/react/components/EditorContentView.internal.tsx', 'packages/platejs/src/react/plugin/DOMHandlers.ts', 'packages/platejs/src/react/utils/BlockPlaceholderPlugin.tsx', 'packages/platejs/src/react/utils/dispatchPlateShortcut.internal.ts', 'packages/platejs/src/react/utils/pipeHandler.internal.ts', 'packages/plitejs/src/react/editable/keyboard-input-strategy.ts', 'packages/plitejs/scripts/check-harness', 'tooling/scripts/finding-baseline.mjs' ), key: [], }, { name: 'plugin-invariants', cores: 1, private: true, run: 'pnpm check:plugin-invariants', light: 'pnpm check:plugin-invariants --light', affected: runsScript( 'packages/platejs/scripts/plugin-invariants.ts', 'packages/platejs/src/lib/plugin/', 'packages/platejs/src/react/plugin/', 'packages/platejs/src/react/editor/', 'packages/platejs/src/internal/plugin/resolvePlugin.ts', 'packages/platejs/src/internal/plugin/resolvePluginGraph.ts', 'packages/platejs/src/internal/plugin/compilePlateModel.ts', 'packages/platejs/src/internal/plugin/createPlateModelPublication.ts', 'packages/platejs/src/internal/plugin/createPlateRuntimePlugins.ts', 'packages/platejs/src/internal/utils/mergePlugins.ts', 'packages/platejs/src/lib/editor/withPlite.ts', 'packages/plitejs/src/core/plugin-definition.ts', 'packages/plitejs/src/core/plugin.ts', 'packages/plitejs/src/core/plugin-registry.ts', 'packages/plitejs/src/core/commit.ts', 'packages/plitejs/src/core/element-id.ts', 'packages/plitejs/src/core/reserved-element-id.ts', 'packages/plitejs/src/core/state-field.ts', 'packages/plitejs/src/utils/node-keys.ts', 'packages/plitejs/scripts/check-harness', 'tooling/scripts/finding-baseline.mjs' ), key: [], }, { name: 'root-lock-invariants', cores: 1, private: true, run: 'pnpm check:root-lock-invariants', light: 'pnpm check:root-lock-invariants --light', affected: runsScript( 'packages/platejs/scripts/root-lock-invariants.ts', 'packages/platejs/src/features/lock/', 'packages/platejs/src/features/callout/', 'packages/platejs/src/features/details/', 'packages/platejs/src/features/footnote/', 'packages/plitejs/src/core/non-writable.ts', 'packages/plitejs/src/core/element-owned-root-index.ts', 'packages/plitejs/src/core/unique-values.ts', 'packages/plitejs/src/editor/element-read-only.ts', 'packages/plitejs/src/internal/root-location.ts', 'packages/plitejs/src/sync/server/server.ts' ), key: [], }, { name: 'styles-invariants', cores: 1, private: true, run: 'pnpm check:styles-invariants', light: 'pnpm check:styles-invariants --light', affected: runsScript( 'packages/platejs/scripts/styles-invariants.ts', 'packages/platejs/src/features/basic-styles/', 'packages/platejs/src/features/basic-nodes/lib/BaseMarkPlugins.ts', 'packages/platejs/src/react/features/format-painter/', 'packages/platejs/src/lib/plugins/html/cssLexer.internal.ts', 'packages/platejs/src/lib/plugins/html/cssSafety.internal.ts', 'packages/platejs/src/lib/plugins/html/htmlSafety.ts', 'packages/platejs/src/lib/plugins/html/htmlRules.internal.ts', 'packages/platejs/src/lib/plugins/html/htmlSerialize.internal.ts', 'packages/platejs/src/lib/plugins/html/htmlStyleInline.internal.ts', 'packages/platejs/src/markdown/lib/internal/markdownAttributes.ts', 'packages/platejs/src/markdown/lib/internal/markdownMappings.ts', 'packages/platejs/src/markdown/lib/serializer/convertPhrasingSerialize.ts', 'packages/platejs/src/migrations/migratePlateV54Urls.internal.ts', 'packages/platejs/src/internal/plugin/pluginInjectNodeProps.ts' ), key: [], }, { name: 'styles-toolbar-invariants', cores: 1, private: true, run: 'pnpm check:styles-toolbar-invariants', light: 'pnpm check:styles-toolbar-invariants --light', affected: runsScript( 'apps/www/scripts/styles-toolbar-invariants.tsx', 'apps/www/scripts/styles-toolbar-invariants-dom.ts', 'apps/www/src/registry/components/editor/font-size-toolbar-button.tsx', 'apps/www/src/registry/components/editor/font-color-toolbar-button.tsx', 'apps/www/src/registry/components/editor/mark-toolbar-button.tsx', 'apps/www/src/registry/components/editor/clear-formatting-toolbar-button.tsx', 'apps/www/src/registry/components/editor/format-painter-toolbar-button.tsx', 'apps/www/src/registry/components/editor/more-toolbar-button.tsx' ), key: [], }, { name: 'bench-targets', land: true, private: true, run: 'pnpm plite:bench:targets:check', affected: touches('benchmarks/targets/slate-v2.json'), key: [], }, { name: 'public-types', cores: 2, holds: [ 'packages/plitejs/dist', 'packages/platejs/dist', 'packages/cli/dist', 'packages/test/dist', ], private: true, run: 'pnpm plite:public-types', affected: source, key: [], filesOnly: true, }, { name: 'cli-test', cores: 2, holds: [ 'packages/cli/tmp-*', 'packages/plitejs/dist', 'packages/platejs/dist', 'packages/cli/dist', ], after: ['public-types'], private: true, // The CLI tests pack @platejs/cli and compile/run editors against built plitejs/platejs dist. run: `pnpm turbo run build --filter=@platejs/cli && pnpm --filter @platejs/cli run test --timeout=${TEST_TIMEOUT_MS}`, affected: touches( 'packages/cli/', 'packages/platejs/', 'packages/plitejs/' ), key: [], }, { name: 'core-audits', private: true, run: 'pnpm check:core', affected: (files) => source(files) || touches('content/docs/')(files) || files.some( (file) => /^packages\/[^/]+\/README\.md$/u.test(file) || /^private-apps\/(?:.*\/)?package\.json$/u.test(file) ), key: [], }, { name: 'plite-docs', land: true, private: true, run: 'node tooling/scripts/check-plite-docs.mjs', affected: (files) => source(files) || touches( '.agents/rules/', '.agents/skills/', '.changeset/', 'AGENTS.md', 'apps/www/public/', 'apps/www/src/app/(app)/examples/plite/', 'content/docs/', 'docs/plite/', 'packages/platejs/type-tests/plite-rebound-contracts.tsx', 'packages/plitejs/README.md', 'tooling/scripts/check-plite-release-artifacts.mjs' )(files), key: [], }, { name: 'release-artifacts', cores: 4, holds: [ 'packages/plitejs/dist', 'packages/platejs/dist', 'packages/cli/dist', 'packages/test/dist', ], after: ['public-types'], run: hasPrivateHalf(root) ? 'pnpm plite:release:packages && node tooling/scripts/measure-browser-handle.mjs --skip-build' : 'pnpm plite:release:packages', affected: (files) => touches( 'apps/www/src/generated/api-reference-manifest.json', 'apps/www/src/generated/component-props-manifest.json', 'apps/www/src/generated/spec-evidence-manifest.json', 'apps/www/src/lib/docs-markdown.ts', 'apps/www/src/lib/docs-reference-markdown.ts', 'content/docs/', 'skills/plate/', 'tooling/config/tsdown.config.ts', 'tooling/entrypoints/', 'tooling/scripts/build-package-docs.mjs', 'tooling/scripts/check-plite-release-artifacts.mjs', 'tooling/scripts/docs-sources.mjs', 'tooling/scripts/measure-browser-handle.mjs' )(files) || files.some( (file) => /^packages\/[^/]+\/(?:package\.json$|README\.md$|THIRD_PARTY_NOTICES\.md$|tsdown\.config\.|src\/)/u.test( file ) && !TEST.test(file) ), }, { name: 'plite-bridge', run: 'node tooling/scripts/check-plite-bridge.mjs', affected: source, key: [], }, { name: 'plite-module-cycles', land: true, run: 'node tooling/scripts/check-plite-module-cycles.mjs', affected: touches( 'packages/plitejs/src/', 'tooling/scripts/check-plite-module-cycles.mjs' ), key: [], }, { name: 'selection-writes', run: 'node tooling/scripts/check-selection-writes.mjs', affected: touches('packages/'), key: [], }, { name: 'browser-test-imports', land: true, run: 'node tooling/scripts/check-browser-test-imports.mjs', fix: 'node tooling/scripts/check-browser-test-imports.mjs --fix', affected: touches( 'apps/plite/tests/plite-browser/', 'apps/www/tests/browser/', 'tooling/scripts/check-browser-test-imports' ), key: [], }, { name: 'position-inference', land: true, run: 'node tooling/scripts/check-position-inference.mjs', affected: touches( 'packages/plitejs/src/core/change/', 'packages/plitejs/src/history/', 'tooling/scripts/check-position-inference', 'tooling/scripts/position-inference.json' ), }, { name: 'hook-generics', run: 'node tooling/scripts/check-hook-generics.mjs --check', fix: 'node tooling/scripts/check-hook-generics.mjs', affected: source, key: [], }, { name: 'value-records', run: 'node tooling/scripts/check-value-records.mjs', affected: source, key: [], }, { name: 'entrypoint-graph', private: true, run: 'pnpm entrypoint:turbo:check', write: 'pnpm entrypoint:turbo:generate', // migrate-platejs-entrypoint-imports.mjs scans every code file under // tooling/, product or not, and the Markdown and MDX under the folders it // lists, for root imports of moved symbols. affected: (files) => source(files) || files.some( (file) => (file.startsWith('tooling/') && CODE.test(file)) || (/^(?:apps|content|packages|tooling)\/.*\.mdx?$/u.test(file) && !file.startsWith('apps/www/public/r/')) ), key: [], }, { name: 'registry-icons', land: true, run: 'node apps/www/scripts/check-registry-icons.mts', affected: touches( 'apps/www/scripts/check-registry-icons.mts', 'apps/www/scripts/icon-names.mts', 'apps/www/scripts/lucide-icons.mts', 'apps/www/scripts/registry-imports.mts', 'apps/www/src/lib/registry-icon-placeholder.ts', 'apps/www/src/registry/' ), key: [], }, { name: 'demo-craft', land: true, run: 'node tooling/scripts/check-demo-craft.mjs --check', fix: 'node tooling/scripts/check-demo-craft.mjs', affected: touches( 'apps/www/src/registry/examples/', 'tooling/scripts/check-demo-craft.mjs', 'tooling/scripts/check-demo-craft-baseline.json', 'tooling/scripts/finding-baseline.mjs' ), key: [], }, { name: 'plate-brand', land: true, run: 'node tooling/scripts/check-plate-brand.mjs', affected: touches( 'apps/www/src/app/(app)/page.tsx', 'apps/www/src/app/(app)/_components/', 'apps/www/src/app/(app)/pricing', 'apps/www/src/app/(app)/account', 'apps/www/src/app/(app)/terms/', 'apps/www/src/app/(app)/privacy/', 'apps/www/src/app/(view)/create-preview/', 'apps/www/src/app/cn/page.tsx', 'apps/www/src/app/cn/pricing', 'apps/www/src/app/cn/account', 'apps/www/src/components/sink/', 'apps/www/src/lib/docs-markdown.ts', 'apps/www/src/lib/editor-comparison.ts', 'apps/www/src/lib/pricing.ts', 'apps/www/src/lib/setup-prompts.ts', 'apps/www/src/registry/examples/', 'content/docs/', 'skills/plate/', 'tooling/scripts/check-plate-brand.mjs' ), key: [], }, { name: 'registry-changelog', land: true, run: 'node tooling/scripts/generate-ui-changelog-entries.mjs --check', write: 'node tooling/scripts/generate-ui-changelog-entries.mjs --write', affected: touches( '.changeset/', 'apps/www/src/generated/release-index.json', 'apps/www/src/registry/', 'oxfmt.config.ts' ), key: [], }, { name: 'mathml-tex-symbols', land: true, private: true, run: 'node tooling/scripts/mathml-tex-symbols.mjs --check', write: 'node tooling/scripts/mathml-tex-symbols.mjs', affected: touches( 'packages/platejs/src/math/lib/mathmlTexSymbols.internal.ts', 'packages/platejs/src/math/lib/__fixtures__/katex-supported-tex.json', 'packages/platejs/package.json', 'oxfmt.config.ts' ), key: [], }, { name: 'skill-mirrors', land: true, private: true, run: 'node .agents/rules/plate-next/scripts/sync-resources.mjs --check', fix: 'pnpm install', affected: touches( '.agents/rules/', '.agents/skills/', '.claude/skills/', 'skills-lock.json' ), key: [], }, { name: 'agent-contracts', land: true, private: true, run: 'node tooling/scripts/check-agent-contracts.mjs', affected: touches( 'AGENTS.md', '.agents/hooks.json', '.agents/playbooks/', '.agents/pstack.json', '.agents/pstack/', '.agents/rules/', '.agents/skills/', '.claude/pstack-models.md', '.claude/settings.json', '.codex/hooks.json', 'docs/development/agent-skills.md', 'docs/development/formal-checks.md', 'docs/development/plate-workflow.md', 'tooling/scripts/check-agent-contracts', 'tooling/scripts/read-budget.mjs', 'tooling/scripts/type-probe-guard.mjs' ), key: [], }, { name: 'removed-api-teaching', land: true, private: true, run: 'node tooling/scripts/check-removed-api-teaching.mjs', key: [], }, { name: 'third-party-notices', land: true, quick: true, run: 'node tooling/scripts/third-party-notices.mjs', affected: (files) => files.some( (file) => file === 'tooling/scripts/third-party-notices.mjs' || file === 'tooling/scripts/private-files.mjs' || /^packages\/[^/]+\/(?:src\/|package\.json$|THIRD_PARTY_NOTICES\.md$)/u.test( file ) ), key: [], }, { name: 'triage', land: true, private: true, run: 'node tooling/scripts/triage.mjs check', affected: touches('.agents/pstack.json'), key: [], }, { name: 'private', land: true, run: 'node tooling/scripts/git-private.mjs check', }, { name: 'private-potion', land: true, quick: true, holds: ['packages/plitejs/dist', 'packages/platejs/dist'], private: true, run: 'sh -c "cd private-apps/potion && node tooling/sync-plate.mjs --local --packages-only && bun run check && bun run test"', affected: touches('private-apps/potion/'), key: [], filesOnly: true, }, { name: 'private-paper', land: true, quick: true, holds: ['packages/plitejs/dist', 'packages/platejs/dist'], private: true, run: 'sh -c "cd private-apps/paper && node tooling/sync-plate.mjs --local --packages-only && bun run check && bun run test"', affected: touches('private-apps/paper/'), key: [], filesOnly: true, }, { name: 'private-api', land: true, quick: true, holds: [ 'packages/plitejs/dist', 'packages/platejs/dist', 'packages/cli/dist', ], private: true, run: 'sh -c "pnpm turbo run build --filter=plitejs --filter=platejs --filter=@platejs/cli && cd api && pnpm run check:pro-catalog && pnpm run check:business && pnpm typecheck && pnpm test"', affected: touches('api/', 'business/'), key: [], filesOnly: true, standaloneLockfiles: true, }, { name: 'private-imports', land: true, run: 'node tooling/scripts/git-private.mjs imports', affected: (files, retargeted) => canRetargetImports(files, retargeted) || files.filter((file) => CODE.test(file)), key: [], // Resolving an import probes these generated folders, and git ignores them, // so no file in them can be private. ignoredReads: [ 'apps/www/.source/', 'apps/www/src/__registry__/create-preview/', ], }, { name: 'manifests', land: true, run: 'pnpm test:manifests', affected: touches('.changeset/', 'packages/'), key: [], }, { // It asks shadcn's live theme service about every value /create offers, // and that service can retire a value with no change here, so its pass // lasts one day. name: 'create-options', run: 'pnpm --filter www check:create-options', affected: touches( 'apps/www/package.json', 'apps/www/scripts/check-create-options.mts', 'apps/www/src/lib/plate-create-theme.ts', 'apps/www/src/lib/plate-create.ts', 'apps/www/src/lib/plate-registry-styles.ts' ), key: ['date'], }, { name: 'toolbar-variants', holds: [ 'packages/plitejs/dist', 'packages/platejs/dist', 'packages/cli/dist', ], after: ['public-types'], run: 'pnpm --filter www check:toolbar-variants', affected: source, key: [], }, { name: 'barrels', alone: 'rewrites tracked files', run: 'pnpm brl', unchangedFiles: packageDiff, write: 'pnpm brl', affected: source, key: [], }, { // Builds and packs platejs to verify the exported API manifest and JSDoc // baseline (p90 > 60s), so Local CI runs it rather than per-commit land.mjs. name: 'api-reference', cores: 2, holds: ['packages/plitejs/dist', 'packages/platejs/dist'], run: 'pnpm --filter www api-reference:check', fix: 'pnpm --filter www api-reference', affected: (files) => touches( 'apps/www/api-reference-baseline.json', 'apps/www/scripts/build-api-reference.mts', 'apps/www/src/generated/api-reference-manifest.json' )(files) || files.some( (file) => /^packages\/(?:plitejs|platejs)\/src\//u.test(file) && !TEST.test(file) ), }, { name: 'component-props', land: true, after: ['www'], run: 'pnpm --filter www component-props:check', write: 'pnpm --filter www component-props', affected: (files) => touches( 'apps/www/scripts/build-component-props.mts', 'apps/www/src/__registry__/registry-metadata.json', 'apps/www/src/generated/component-props-manifest.json' )(files) || files.some( (file) => file.startsWith('apps/www/src/registry/') && file.endsWith('.tsx') ), key: [], }, { name: 'spec-evidence', land: true, private: true, run: 'pnpm --filter www spec-evidence:check', write: 'pnpm --filter www spec-evidence', affected: (files) => touches( 'apps/www/scripts/build-spec-evidence.mts', 'apps/www/src/generated/spec-evidence-manifest.json' )(files) || files.some((file) => /^(?:packages\/(?:platejs|plitejs)\/src|apps\/www\/tests)\/.*\.(?:spec|test)\.tsx?$/u.test( file ) ), key: [], }, { name: 'www', land: true, cores: 2, holds: [ 'packages/plitejs/dist', 'packages/platejs/dist', 'packages/cli/dist', 'apps/www/.source', 'apps/www/.next', ], run: 'pnpm turbo run build --filter=@platejs/cli && pnpm --filter www typecheck', affected: touches( 'apps/www/', 'content/', 'docs/plite/reference/', 'packages/', 'skills/plate/', 'tooling/entrypoints/', 'tooling/scripts/build-package-docs.mjs', 'tooling/scripts/docs-sources.mjs', 'tooling/scripts/finding-baseline.mjs', 'tooling/scripts/private-files.mjs' ), key: [], // Its own commands build these from tracked sources before its scripts // read them; build-registry reads its old preview trees and input-hash // stamp only to drop stale files and skip rewriting unchanged preview // trees, so they never change what it writes or validates. ignoredReads: [ 'apps/www/.registry-build/create-preview.sha256', 'apps/www/.source/', 'apps/www/src/__registry__/create-preview/', 'packages/cli/dist/', ], write: 'pnpm turbo run build --filter=@platejs/cli && pnpm --filter www editor:generate && pnpm --filter www api-reference && pnpm --filter www build:registry', }, { name: 'www-build', alone: 'rewrites tracked files', run: 'pnpm build:www:ci && pnpm --filter www check:page-load', optIn: '--build', }, { // It reruns the Node scripts of every keyed step, about two minutes, and // traces www fully only once the www step has built packages/cli/dist. name: 'step-reads', alone: 'reruns the keyed steps', run: 'node tooling/scripts/check-step-reads.mjs', optIn: '--reads', }, ]; export const deepSteps = steps.filter((step) => [undefined, '--browser', '--build'].includes(step.optIn) ); export const manualOnly = { 'bench:targets:report:check': 'Checks generated benchmark target history report on demand during benchmark runs.', 'check:docs': 'Runs commands that the api-reference, component-props, spec-evidence and www steps already cover.', 'check:plate-feature': 'Validates the feature plan passed as its argument; the Build playbook runs it on that plan.', 'check:plite': 'Plans and runs Plite browser proof, which the plite-browser-* shard steps cover.', 'check:plite:browser-matrix': 'Runs the full browser matrix across every engine; run it by hand before a release.', 'check:plite:contracts': 'Runs tooling contract tests that the test step already runs.', 'check:plite:dev': 'Plans Plite proof from changed paths, for local use.', 'check:plite:packages': 'Runs plite:typecheck, plite:test and check:plite:contracts, which other steps cover.', 'local-ci': 'Runs Local CI on next after landing; its launchd job and the operator skill start it.', 'deps:check': 'Lists available dependency updates; it gates nothing.', 'p:test': 'Template that each package test script calls.', test: 'Runs every root test file, which the test and test-slow steps split between them.', 'plite:browser:test': 'Runs the @platejs/test package tests, which the test-package-test step runs.', 'plite:test': 'Runs plitejs, platejs and @platejs/test together, which the plitejs-test, platejs-test and test-package-test steps cover.', 'plite:typecheck': 'Typechecks plitejs, platejs and @platejs/test, which the typecheck step covers.', 'templates:check': 'templates/** is CI-generated output; ci-templates.yml builds it.', 'templates:test': 'Installs registry items into templates/**, which CI generates.', 'test:coverage': 'Reports coverage for the root suite; it gates nothing.', 'test:deferred': 'Runs quarantined __deferred__ specs, which are kept out of every gate.', 'test:plite': 'Alias for plite:test, which the plitejs-test, platejs-test and test-package-test steps cover.', 'test:plite:browser': 'Runs Plite browser proof, which the plite-browser-* shard steps cover.', 'test:plite:full': 'Runs plite:test and Plite browser proof, which the plitejs-test, platejs-test, test-package-test and plite-browser-* shard steps cover.', 'test:profile': 'Timing report; the owner keeps aggregate timing out of the gate.', 'test:slowest': 'Timing report; the owner keeps aggregate timing out of the gate.', 'test:watch': 'Watch mode.', 'test:create-install': 'Installs registry items into disposable workspaces over the network.', 'test:www-browser:firefox': 'Runs www Playwright specs against a running www server.', 'test:www-browser:webkit': 'Runs www Playwright specs against a running www server.', 'typecheck:all': 'Typechecks every workspace, which the typecheck, plite-app-typecheck and www-typecheck steps cover.', 'typecheck:watch': 'Watch mode.', }; export const activeFormalSteps = steps.filter( (step) => Boolean(step.light) && !step.optIn ); export const auditFormalSteps = steps.filter( (step) => Boolean(step.light) && step.optIn === '--audit' ); /** * Active Local CI formal checks in `check.mjs` whose script or import closure * reaches any of `files`. Ignores resolver configs and `.gitprivate` so callers * such as `relapse.mjs` test real product coverage rather than global retargets. */ export const matchingFormalChecks = (files) => { const scoped = files.filter( (file) => !RESOLVER_CONFIG.test(file) && file !== '.gitprivate' ); if (scoped.length === 0) return []; return activeFormalSteps .filter((step) => Boolean(step.affected?.(scoped, []))) .map((step) => step.name); }; export const selectSteps = (args) => { const writing = args.includes('--write'); const names = args.filter((arg) => !arg.startsWith('--')); return steps.filter( (step) => ((names.length === 0 ? !step.optIn : names.includes(step.name)) || args.includes(step.optIn)) && (!writing || step.write) && (!args.includes('--light') || step.light) ); }; const rootScripts = JSON.parse( readFileSync(new URL('../../package.json', import.meta.url), 'utf-8') ).scripts; const expand = (command, seen = new Set()) => { const parts = [command]; for (const [, name] of command.matchAll(/pnpm (?:run )?([\w:.-]+)/gu)) { if (!rootScripts[name] || seen.has(name)) continue; seen.add(name); parts.push(expand(rootScripts[name], seen)); } return parts.join('\n'); }; /** * @returns {(step: object) => null | true | string[]} what a change to * `files` needs from a step: nothing, its whole run, or the files to run * it on */ const needs = (files, retargeted, versions) => { const manifests = files.includes(LOCKFILE) ? lockfileReach(versions?.(LOCKFILE)) : []; const reached = [...files, ...(manifests ?? [])]; const everything = manifests === null || reached.some((file) => GLOBAL_PATHS.some((path) => matches(path, file))); let called; const calls = (step) => { called ??= new Set( files.flatMap((file) => [...(toolingReach(file)?.scripts ?? [])].map((script) => basename(script) ) ) ); return expand(step.run) .split(/[\s"'`;&|()]+/u) .some((token) => called.has(basename(token))); }; return (step) => { if (!step.affected) return true; if (files.length === 0) return null; if ((everything || calls(step)) && !step.onlyAffectedFiles) return true; const hit = step.affected(reached, retargeted); if (!Array.isArray(hit)) return hit ? true : null; return hit.length > 0 ? hit : null; }; }; const commandFor = (step, need) => Array.isArray(need) ? `${step.run} ${need.map((file) => `'${file}'`).join(' ')}` : step.run; /** The base that covers `step`, or else the narrowest need its bases leave. */ const planStep = (step, bases) => { let need = true; // Tracing a changed tooling script to its callers reads every source, so // the base with the fewest changed files goes first and usually covers. const fewest = bases.toSorted((a, b) => a.files.length - b.files.length); for (const base of fewest) { if (base.kind === 'exact') return { cover: base }; const needed = needs(base.files, base.retargeted, base.versions)(step); if (needed === null) return { cover: base }; if ( Array.isArray(needed) && (!Array.isArray(need) || needed.length < need.length) ) { need = needed; } } return { need }; }; /** * Each default step with the command a change to `files` needs, or null. * `versions` gives a changed file's text before and after, as a cache base * does. */ export const planAffected = (files, retargeted = [], versions = () => null) => { const need = needs(files, retargeted, versions); return steps .filter((step) => !step.optIn) .map((step) => { const needed = need(step); return { step, command: needed === null ? null : commandFor(step, needed), }; }); }; const FRESH_ENV = { PLITE_BROWSER_FORCE_PROOF: '1', PLITE_PROOF_FORCE_BUILD: '1', }; const runStep = ( step, command, { cores, forceBuild, fresh, log, running, watchMemory, writing } ) => { const started = Date.now(); const watch = !writing && step.unchangedFiles; const before = watch && step.unchangedFiles(); const output = openSync(log, 'w'); const freshEnv = fresh ? forceBuild ? FRESH_ENV : { PLITE_BROWSER_FORCE_PROOF: '1' } : {}; const child = spawn('bash', ['-o', 'pipefail', '-c', command], { cwd: root, env: { ...process.env, ...freshEnv, CHECK_CORES: String(cores), }, stdio: ['ignore', output, output], }); closeSync(output); running.add(child); const unwatch = watchMemory(child.pid, { stopped: (text) => appendFileSync(log, `\n[check] ${step.name} ${text}\n`), }); return new Promise((resolveStep) => { const finish = (code) => { if (!running.delete(child)) return; unwatch(); let status = code; if (status === 0 && watch && step.unchangedFiles() !== before) { appendFileSync( log, `[check] ${step.name} changed files under packages/.\n` ); status = 1; } resolveStep({ seconds: Math.round((Date.now() - started) / 1000), status, }); }; child.once('error', (error) => { appendFileSync(log, `${error.message}\n`); finish(1); }); child.once('exit', (code) => finish(code ?? 1)); }); }; // The longest steps start first, because a half-hour step that waits for // free cores behind short ones runs past Local CI's hour and reports nothing. const schedule = async (entries, budget, start, stopped, seconds) => { const slots = ({ step }) => Math.min(step.cores ?? 1, budget); const pending = entries .filter(({ step }) => !step.alone) .toSorted( (a, b) => (seconds.get(b.step.name) ?? 0) - (seconds.get(a.step.name) ?? 0) || (b.step.cores ?? 1) - (a.step.cores ?? 1) ); const unfinished = new Set(pending.map(({ step }) => step.name)); const held = new Set(); const active = new Set(); let free = budget; const launch = () => { for (const entry of [...pending]) { const holds = entry.step.holds ?? []; const after = entry.step.after ?? []; if ( slots(entry) > free || holds.some((name) => held.has(name)) || after.some((name) => unfinished.has(name)) ) { continue; } pending.splice(pending.indexOf(entry), 1); free -= slots(entry); for (const name of holds) held.add(name); const run = start(entry).then(() => { free += slots(entry); for (const name of holds) held.delete(name); unfinished.delete(entry.step.name); active.delete(run); }); active.add(run); } }; launch(); while (active.size > 0) { await Promise.race(active); if (!stopped()) launch(); } for (const entry of entries.filter(({ step }) => step.alone)) { if (stopped()) break; await start(entry); } }; const main = async () => { const rawArgs = process.argv.slice(2); let baseRef = null; const args = []; for (let i = 0; i < rawArgs.length; i += 1) { if (rawArgs[i] === '--base') { const value = rawArgs[i + 1]; if (!value || value.startsWith('--')) { console.error('[check] --base needs a git ref.'); return 1; } baseRef = value; i += 1; continue; } args.push(rawArgs[i]); } const flags = [ '--affected', '--audit', '--browser', '--build', '--deep', '--light', '--list', '--reads', '--write', ]; const unknownFlags = args.filter( (arg) => arg.startsWith('--') && !flags.includes(arg) ); if (unknownFlags.length > 0) { console.error( `[check] unknown flag: ${unknownFlags.join(', ')}. Flags: ${flags.join(', ')}.` ); return 1; } const writing = args.includes('--write'); const names = args.filter((arg) => !arg.startsWith('--')); if (args.includes('--list')) { for (const step of steps) { console.info( `${step.name}\t${step.run}${step.optIn ? `\t(opt-in: ${step.optIn} or by name)` : ''}${step.light === true ? '\t(--light: the gate)' : step.light ? `\t(--light: ${step.light})` : ''}` ); } return 0; } const unknown = names.filter( (name) => !steps.some((step) => step.name === name) ); if (unknown.length > 0) { console.error( `[check] unknown step: ${unknown.join(', ')}. Run pnpm check --list.` ); return 1; } const optIns = args.filter((arg) => steps.some((step) => step.optIn === arg)); if (writing && optIns.length > 0) { console.error( `[check] ${optIns.join(' and ')} runs a step with no writer; run it without --write.` ); return 1; } const affected = args.includes('--affected'); if (baseRef && !affected) { console.error('[check] --base needs --affected.'); return 1; } if (affected && (writing || optIns.length > 0 || names.length > 0)) { console.error( '[check] --affected picks its own steps; run it without step names, --write, --audit, --build, --browser or --reads.' ); return 1; } const deep = args.includes('--deep'); if (deep && (affected || writing || optIns.length > 0 || names.length > 0)) { console.error( '[check] --deep runs every step that --build --browser runs; run it without --affected, step names, --write, --audit, --build, --browser or --reads.' ); return 1; } const light = args.includes('--light'); const heavy = names.filter( (name) => !steps.find((step) => step.name === name).light ); if (light && (deep || writing || optIns.length > 0)) { console.error( '[check] --light runs the light bound of the formal checks it names, of affected active formal checks with --affected, or of every one; run it without --deep, --write, --audit, --build, --browser or --reads.' ); return 1; } if (light && heavy.length > 0) { console.error( `[check] ${heavy.join(', ')} has no light bound. Steps with one: ${steps .filter((step) => step.light) .map((step) => step.name) .join(', ')}.` ); return 1; } if (lockfileInstalled(root) === false) { console.info( `[check] ${LOCKFILE} differs from the lockfile pnpm last installed; installing it.` ); const failure = installLockfile(root); if (failure !== null) { console.error( `[check] pnpm install failed, so the steps would run against stale node_modules:\n${failure}` ); return 1; } } let chosen = affected ? steps.filter((step) => !step.optIn && (!light || step.light)) : deep ? deepSteps : selectSteps(args); if (affected && !light) { const later = chosen.filter((step) => !step.land); if (later.length > 0) { console.info( ` skip ${later.map((step) => step.name).join(', ')}: Local CI runs them on next after landing` ); } chosen = chosen.filter((step) => step.land); } chosen = chosen.filter((step) => { if (!step.partOf) return true; const owners = Array.isArray(step.partOf) ? step.partOf : [step.partOf]; return !owners.every((name) => chosen.some((other) => other.name === name)); }); if (!hasPrivateHalf(root)) { const asked = chosen.filter( (step) => step.private && (names.includes(step.name) || args.includes(step.optIn)) ); if (asked.length > 0) { console.error( `[check] ${asked.map((step) => step.name).join(', ')} reads udecode/plate-private's files, which this checkout does not have; in a team clone, node tooling/scripts/git-private.mjs start puts them on disk.` ); return 1; } for (const step of chosen.filter((entry) => entry.private)) { console.info( ` skip ${step.name}: it reads udecode/plate-private's files` ); } chosen = chosen.filter((step) => !step.private); } // A light pass is a pass of its own command, logged under its own name, so // it never covers a full run or moves the step's typical time. if (light) { chosen = chosen.map((step) => ({ ...step, name: `${step.name} --light`, run: step.light === true ? step.run : step.light, })); } const fresh = freshRun(process.env); const landing = process.env.PSTACK_LAND_CHECK === '1'; const logStep = stepLogger(root, { affected, deep, fresh, landing }); const near = affected || deep; const cache = openCache(root, { fresh: writing || fresh }); const selected = []; for (const step of chosen) { const scope = { command: expand(step.run), filesOnly: step.filesOnly, key: step.key, name: step.name, }; const { cover: covered, need } = planStep( step, cache.bases(scope, { baseRef, mergeBase: affected, near }) ); const ran = Array.isArray(need) ? { ...scope, tests: need } : scope; const cover = covered ?? (ran === scope ? null : planStep(step, cache.bases(ran, { near })).cover); if (cover) { console.info( ` skip ${step.name}: ${cover.label}${cover.files.length > 0 ? `, and none of the ${cover.files.length} files changed since reaches it` : ''}` ); logStep({ step: step.name, covered: cover.label }); continue; } selected.push({ command: writing ? step.write : commandFor(step, need), scope: ran, step, }); } if (selected.some(({ step }) => step.standaloneLockfiles)) { const standalone = ensureStandaloneLockfiles(root, { onInstall: (dir) => console.info( `[check] ${relative(root, dir)}/${LOCKFILE} is missing or out of date in node_modules; installing it.` ), }); if (standalone !== null) { console.error( `[check] pnpm install in ${relative(root, standalone.dir)} failed, so the steps would run against missing or stale node_modules:\n${standalone.output}` ); return 1; } } const group = Boolean(process.env.GITHUB_ACTIONS); const results = new Map(); const share = workerBudget(); const typical = typicalSeconds(root); // Writers can read each other's output, so --write keeps one step at a time. let budget = 1; const proofPath = join(root, '.agents', 'pstack', 'proof.mjs'); const { reserve, watchMemory } = existsSync(proofPath) ? await import(pathToFileURL(proofPath).href) : { reserve: () => () => {}, watchMemory: () => () => {}, }; const logs = mkdtempSync(join(tmpdir(), 'plate-check-')); const running = new Set(); let interrupted = 0; // Steps share this process group, so a terminal's or supervisor's signal to // the group reaches each of them; this passes on one sent to this process. const stop = (signal) => { interrupted ||= 128 + osConstants.signals[signal]; for (const child of running) child.kill(signal); }; const signals = ['SIGHUP', 'SIGINT', 'SIGTERM']; for (const signal of signals) process.on(signal, stop); const recordsPasses = selected.some(({ scope }) => scope.key); if (recordsPasses) cache.watch(); let firstFailure = null; let forcedPliteBuild = false; const start = async ({ command, scope, step }) => { console.info(`[check] ${step.name} started`); const log = join(logs, `${step.name}.log`); cache.begin(step.name); const usesPliteBuild = step.holds?.includes('apps/plite/out'); const forceBuild = fresh && (!usesPliteBuild || !forcedPliteBuild); if (usesPliteBuild && forceBuild) forcedPliteBuild = true; const result = await runStep(step, command, { cores: Math.min(step.cores ?? 1, budget), forceBuild, fresh, log, running, watchMemory, writing, }); const reason = cache.end(step.name); results.set(step.name, result); logStep({ cores: Math.min(step.cores ?? 1, budget), exit: interrupted ? INTERRUPTED : result.status, seconds: result.seconds, step: step.name, }); // pnpm exits 0 when an interrupt stops its script, so a step that ends // after one never counts as passed. if (!interrupted && result.status !== 0) { firstFailure ??= step.name; } else if (!interrupted) { cache.record(scope, result.seconds, reason); } if (group) console.info(`::group::${step.name}`); console.info(`${group ? '' : '\n'}[check] ${step.name}: ${command}`); process.stdout.write(readFileSync(log)); rmSync(log, { force: true }); const state = interrupted ? 'interrupted' : result.status === 0 ? 'ok' : `failed (exit ${result.status})`; console.info(`[check] ${step.name} ${state} in ${result.seconds}s`); if (group) console.info('::endgroup::'); }; const stopped = () => interrupted !== 0 || (affected && firstFailure !== null); try { if (writing) { for (const entry of selected) { if (stopped()) break; await start(entry); } } else { const tiers = affected ? [ selected.filter(({ step }) => step.quick), selected.filter(({ step }) => !step.quick), ] : [selected]; // Each tier asks the pool for only the cores its own steps use, so a // landing whose change reaches only the quick steps waits for one or two. for (const tier of tiers.filter((entries) => entries.length > 0)) { if (stopped()) break; budget = Math.min( share, tier.reduce( (sum, { step }) => sum + Math.min(step.cores ?? 1, share), 0 ) ); const release = reserve(budget, 'pnpm check'); try { await schedule(tier, budget, start, stopped, typical); } finally { release(); } } } } finally { for (const signal of signals) process.removeListener(signal, stop); rmSync(logs, { force: true, recursive: true }); } if (interrupted) return interrupted; const { dropped } = cache.flush(); if (dropped) console.info(`[check] ${dropped}.`); console.info('\n[check] summary'); let failed = 0; for (const { step } of selected) { if (!results.has(step.name)) { console.info( ` ${step.name.padEnd(20)} - not started: ${firstFailure} failed first` ); continue; } const { seconds, status } = results.get(step.name); const fix = writing ? null : step.write ? 'pnpm generate' : step.fix; if (status !== 0) failed += 1; const state = status === 0 ? 'ok' : `failed (exit ${status})${fix ? `; fix: ${fix}` : ''}`; console.info( ` ${step.name.padEnd(20)} ${String(seconds).padStart(4)}s ${state}` ); } if (failed > 0) { const unstarted = selected.length - results.size; console.error( `[check] ${failed} of ${selected.length} steps failed${unstarted > 0 ? `, and ${unstarted} did not start` : ''}.` ); return 1; } const covered = chosen.length - selected.length; console.info( `[check] all ${selected.length} steps passed${covered > 0 ? `; ${covered} skipped on an earlier pass` : ''}.` ); return 0; }; if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) { // exitCode instead of exit, so the step logs written to a pipe drain first. void main().then((code) => { process.exitCode = code; }); }