#!/usr/bin/env node /** * Fast provider-scoped preflight: format + lint + test ONLY the provider in * question. * * The full `dev:preflight` gate runs `prettier --write .` and full-repo * checks. This scopes the expensive prettier + eslint passes to just the * provider package and its integration tests, then runs the provider's * typecheck/replay gate. Use `dev:preflight:fast` for narrow provider work; * use `dev:preflight` or `ci:local` when the diff touches shared tooling, * package metadata, docs, or test harness code. * * The provider scope can be a provider name, a path under * packages/provider/, or an integration test path. With no argument, * the script tries APICITY_PROVIDER_PATH, pnpm's INIT_CWD, then process.cwd(). * * The checklist itself lives in scripts/lib/fast-gate-steps.mjs — the single * definition this script prints from and the documentation guard reads. It is * deliberately not restated here: a copy in this docstring is exactly the kind * of second list that goes stale. * * Steps are named by their `FAST_GATE_STEPS` id, never by position: the banner * numbers itself from the list, so an ordinal written down here goes stale the * moment a step is inserted anywhere but the end. * * Step `typecheck-tests` is the one step here that is NOT scoped: * `tests/tsconfig.json` is a single whole-tree project, so the step runs * unconditionally and a type error in any file it compiles fails this gate * whichever provider it was invoked for. Why that step exists and what it * costs: scripts/lib/tests-project.mjs. * * Endpoint-surface inventory covers cost tiers and exact billing records. * * Step `cross-cutting` runs the repo-wide guards in * scripts/lib/cross-cutting-tests.mjs that provider scopes do not select * consistently: recording-corpus allowlists, endpoint-surface inventory, * cross-provider source pins, cross-provider registry parity, documentation * inventories, fal credential wiring, provider export surface, cross-ref * namespace shape, namespace-shape CLI, recorded request secrets, example * provenance, har report golden, captured payload failures, and recording * accuracy. Those are the categories tests/unit/cross-cutting-tests.test.ts * sorts the block into, and it fails when this paragraph stops naming one of * them. The registry-parity guard, `tests/unit/cost-slugs.test.ts`, enforces * exact `fal` pricing/slug key sets, slug/display coverage for every provider, * every `kie` pricing key resolving through both slug and display * registries, and exact `googleflow` slug/display keys; * `tests/unit/cost-pricing.test.ts` enforces the mirror direction. The * documentation inventories, * `tests/unit/provider-inventory-docs.test.ts`, pin the provider and * script-alias lists to the repository. The credential-wiring guard, * `tests/unit/recording-credential-hosts.test.ts`, requires every fal * recording to be replayed by a call site wired to the credential its host * needs; replay never contacts fal, so a miswiring is invisible until the * next paid `dev:record` (ac-wt8fzl). The recorded-request-secrets guard, * `tests/unit/har-request-secrets.test.ts`, holds every request header the * harness redacts to the exact placeholder it writes, in every committed * recording, so a hand-edited HAR carrying a live key fails here rather than * reaching a public repository (ac-1zmydw). Without this step, provider-scoped * work can leave a whole-repo invariant stale until full CI — among them the * gaps behind ac-05hrc, ac-t2gfln, the `92323c18` hand repair, ac-y39i64, * ac-kabm2y, ac-gk1mlr, and ac-wt8fzl. Their measured cost lives in * `CROSS_CUTTING_COST_SECONDS`; the banner prints it via * `crossCuttingCostNote()` rather than restating the number here. * * For typecheck-only loops, use `pnpm run typecheck:provider -- `. * * Usage: node scripts/preflight-provider.mjs * pnpm run dev:preflight:fast -- openai * pnpm run dev:preflight:provider -- packages/provider/openai/src */ import { spawnSync } from "node:child_process"; import { crossCuttingCostNote, listCrossCuttingTests, } from "./lib/cross-cutting-tests.mjs"; import { FAST_GATE_STEPS } from "./lib/fast-gate-steps.mjs"; import { repoRoot, resolveProviderScope } from "./lib/provider-scope.mjs"; import { TESTS_TYPECHECK_STEP } from "./lib/tests-project.mjs"; const rawArgs = process.argv.slice(2).filter((arg) => arg !== "--"); if (rawArgs.includes("-h") || rawArgs.includes("--help")) { printUsage(); process.exit(0); } const scopeArg = rawArgs.find((arg) => !arg.startsWith("-")); const passthrough = rawArgs.filter((arg) => arg !== scopeArg); let scope; try { scope = resolveProviderScope(scopeArg); } catch (error) { printUsage(); console.error(""); console.error(error instanceof Error ? error.message : String(error)); process.exit(1); } const provider = scope.provider; const pkgDir = scope.packageDir; const tests = scope.tests; if (tests.length === 0) { console.error( `No integration tests match "${provider}" in tests/integration` ); process.exit(1); } // Only the provider package + its tests and their `*.types.ts` companions — // NOT the whole root tree. Only `tests` is ever handed to Vitest. const targets = [pkgDir, ...tests, ...scope.typeTests]; const crossCuttingTests = listCrossCuttingTests({ alreadySelected: passthrough.length === 0 ? tests : [], }); console.error(`Fast provider preflight: ${provider}`); console.error("Steps:"); FAST_GATE_STEPS.forEach((step, index) => { console.error(` ${index + 1}. ${step.title}`); }); function run(title, cmd, args, { repro } = {}) { console.error(`\n▸ ${title}`); const result = spawnSync(cmd, args, { cwd: repoRoot, stdio: "inherit" }); if (result.status !== 0) { console.error(`\n✗ ${title} failed (exit ${result.status ?? 1})`); if (repro) { console.error(` reproduce: ${repro}`); } process.exit(result.status ?? 1); } } function printUsage() { console.error( "Usage: pnpm run dev:preflight:fast -- [-- test args]" ); console.error( " pnpm run dev:preflight:provider -- [-- test args]" ); } // Step `format`: the provider package + its tests only. run("prettier --write (scoped)", "pnpm", [ "exec", "prettier", "--write", ...targets, ]); // Step `lint`: the same scope, plus provider-relevant repository checks. run(`lint:provider ${provider}`, "pnpm", [ "run", "lint:provider", "--", provider, ]); // Step `typecheck-tests`: the whole tests project. Unconditional and // provider-independent: // tests/tsconfig.json is a single whole-tree project, so per-provider or // per-diff scoping would reopen the gap for shared helpers under tests/ // (ac-6g2rnr). No passthrough — those are Vitest args, not tsc args. run( TESTS_TYPECHECK_STEP.title, TESTS_TYPECHECK_STEP.command, [...TESTS_TYPECHECK_STEP.args], { repro: TESTS_TYPECHECK_STEP.repro } ); // Step `test-provider`: typecheck the provider package, then replay its tests. run(`test:provider ${provider}`, "pnpm", [ "run", "test:provider", provider, ...passthrough, ]); // Step `cross-cutting`: repo-wide guards that provider scopes do not select // consistently. De-duplicate files already replayed by the provider unless // passthrough filters make that unsafe. Provider filters are deliberately not // forwarded: the guard run must execute every selected test. These tests are // filesystem/source-parse only; no network or replay. console.error(` (${crossCuttingCostNote()})`); run("cross-cutting repo-wide guard tests", "pnpm", [ "run", "test:run", ...crossCuttingTests, ]); console.error(`\n✓ provider preflight green: ${provider}`);