#!/usr/bin/env bun // A freshly scaffolded app's OWN `bun run setup && bun run verify`, run as CI's check — the two // commands a platform box runs on an Ubuntu VM with bun and git and nothing else, and the contract the // platform depends on. Nothing here re-spells them: the scripts under test are the ones `x new` // wrote, so a change to either is measured on the next push rather than discovered on a box. // // NO WAIVER AND NO FIX-FOLLOW, and both absences are the point: // // * The ratchet this file used to carry allowed `budgets` to stay red, because `x verify` weighed // `.x/build-stats.json` and nothing in the gate wrote one. The step now builds when the stats // are missing (plan 101, 21), which is what makes it measurable — so the allowance has nothing // to excuse, and an allowance nobody needs is a hole waiting for the next red step to fall into. // * The fix-follow loop asked a weaker question than the contract does. "Red, then green after // running the printed `fix:`" is not what a box gets: it runs the two commands once. The FIRST // `bun run verify` is the one that has to be green, and a gate that repairs the tree it is // measuring cannot tell you whether it was. // // bun run scripts/scaffold-gate.ts [--json] // why: Bun has no path resolve — both commands run with an ABSOLUTE cwd, and `resolve` is what // makes that true for a relative `` (`x new --dir` accepts one, so that spelling is a real // caller). `bun run` finds the app's `package.json` from its cwd; a relative cwd resolved against a // second relative path is how this gate once looked for `demoapp/demoapp/bin/setup`. import { resolve } from 'node:path'; import type { Runner } from '@ultimat3/cli'; import { exec, quoteArg, VERIFY_STEP_NAMES } from '@ultimat3/cli'; import { parseScriptArgs } from './lib/args'; import type { Finding } from './lib/log'; import { report } from './lib/log'; import { repoRoot } from './lib/run'; import { strangerOverlayAt } from './lib/stranger-env'; import type { GateStep } from './reference-app-gate'; import { declaredStepIssues, parseStepPayloads, parseSteps, redSteps, stepLines, } from './reference-app-gate'; const SCRIPT = 'scaffold-gate'; /** * The two commands `x new`'s README opens with and a bare VM runs, named once. `bun run`, never a * `bin/` path: the scripts are `bin/*.ts` that Bun runs, the same on Linux, macOS and Windows. */ export const SETUP_COMMAND = 'bun run setup'; export const GATE_COMMAND = 'bun run verify'; /** * Steps that must be GREEN, not merely not-red. A skipped step satisfies every other rule here, * and `budgets` is the one where that would be a silent regression: on a fresh scaffold it spends * a whole static build for no other reason than to make itself measurable, so a * `budgets` that reports `skipped` means the build bought nothing and nobody would see it. */ export const MEASURED_STEPS: readonly string[] = ['budgets']; /** * Runnable in the scaffolded app itself, which is the only place the contract can be reproduced. * `quoteArg` because the directory is the runner's, not ours: `x new --dir` accepts a path with a * space in it, and `cd /tmp/my app` enters `/tmp/my` or nothing at all. */ export const reproduce = (dir: string): string => `cd ${quoteArg(dir)} && ${SETUP_COMMAND} && ${GATE_COMMAND} --json`; /** The first half alone, for a finding raised before the gate could run. */ export const reproduceSetup = (dir: string): string => `cd ${quoteArg(dir)} && ${SETUP_COMMAND}`; /** Absolute, so neither command depends on the cwd a caller happens to have. */ export const appDir = (dir: string): string => resolve(dir); /** `bun run