From ae818826a7be6bf05f9b16b6b3cd36c0465b147f Mon Sep 17 00:00:00 2001 From: "exe.dev user" Date: Sat, 10 Oct 2026 23:30:20 +0000 Subject: [PATCH] ci: make npm test the complete validation suite --- .github/workflows/ci.yml | 26 +++----- .github/workflows/deploy.yml | 6 +- .github/workflows/visual-regressions.yml | 3 +- .node-version | 1 + AGENTS.md | 14 +++++ README.md | 4 +- docs/ci-testing.md | 14 +++++ package.json | 11 +++- scripts/bootstrap-test.mjs | 24 ++++++++ scripts/validation.mjs | 76 ++++++++++++++++++++++++ 10 files changed, 154 insertions(+), 25 deletions(-) create mode 100644 .node-version create mode 100644 scripts/bootstrap-test.mjs create mode 100644 scripts/validation.mjs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d41d4307..581c903a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,8 +32,9 @@ jobs: with: { fetch-depth: 0 } - uses: actions/setup-node@v5 with: - node-version: 24 + node-version-file: .node-version cache: npm + - run: npm install --global npm@11.19.0 - name: Start isolated migrated PostgreSQL database run: | sudo systemctl start postgresql @@ -42,18 +43,10 @@ jobs: pg_isready -h localhost -p 5432 npm ci npm run db:migrate --workspace=factorize - - name: Verify generated API contract once - run: | - npm run generate - git diff --exit-code -- packages/docs/openapi.yaml packages/api-client/src/schema.d.ts - - name: Build static application for Worker dry-run - run: npm run build --workspace=factorize-app - - name: Run docs, API, authorization, integration and Worker checks - run: npm run check:backend - name: Install Chromium for compiled static-slice checks run: npm exec --workspace=factorize -- playwright install --with-deps chromium - - name: Exercise compiled jobs/invocation/run slice against PostgreSQL - run: npm run test:static-slice --workspace=factorize + - name: Run the shared backend validation lane + run: npm run test:backend - name: Record backend timing if: always() run: | @@ -69,17 +62,14 @@ jobs: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: - node-version: 24 + node-version-file: .node-version cache: npm + - run: npm install --global npm@11.19.0 - run: npm ci - - name: Build static application - run: npm run build --workspace=factorize-app - name: Install Chromium for functional checks run: npm exec --workspace=factorize-app -- playwright install --with-deps chromium - - name: Run required functional browser coverage - run: npm run test:functional --workspace=factorize-app - - name: Run non-browser app unit tests - run: npm test --workspace=factorize-app + - name: Run the shared browser validation lane + run: npm run test:browser - name: Record browser timing if: always() run: | diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 775949e3..9f60ee11 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -28,8 +28,9 @@ jobs: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: - node-version: 24 + node-version-file: .node-version cache: npm + - run: npm install --global npm@11.19.0 - run: npm ci - name: Validate explicit cutover on isolated Neon branch run: npx tsx packages/api/scripts/validate-webhook-conditions-cutover.ts --neon @@ -47,8 +48,9 @@ jobs: fetch-depth: 0 - uses: actions/setup-node@v5 with: - node-version: 24 + node-version-file: .node-version cache: npm + - run: npm install --global npm@11.19.0 - run: npm ci - name: Require the additive API stage before static cutover run: node scripts/verify-public-routing.mjs https://app.factorize.sh --api-ready diff --git a/.github/workflows/visual-regressions.yml b/.github/workflows/visual-regressions.yml index be3b689d..75758ea3 100644 --- a/.github/workflows/visual-regressions.yml +++ b/.github/workflows/visual-regressions.yml @@ -21,8 +21,9 @@ jobs: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: - node-version: 24 + node-version-file: .node-version cache: npm + - run: npm install --global npm@11.19.0 - run: npm ci - run: npm run build --workspace=factorize-app - run: npx playwright install --with-deps chromium diff --git a/.node-version b/.node-version new file mode 100644 index 00000000..248216ad --- /dev/null +++ b/.node-version @@ -0,0 +1 @@ +24.12.0 diff --git a/AGENTS.md b/AGENTS.md index 245dc703..4a10872f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -2,6 +2,20 @@ This project in Linear is "Factorize" +## Validation + +Use Node 24.12.0 and npm 11.19.0 (`.node-version` and `package.json`) and run `npm ci` after a clean checkout. +Run `npm test` after the final code change; it is the complete required local +validation and runs the shared backend and browser lanes used by CI. `npm run +check` is an alias for the same suite. Targeted workspace commands remain +available for iteration, but do not replace the root suite before handoff. + +For a fresh local VM, install PostgreSQL and Chromium as needed, then run +`npm run bootstrap:test`. It creates an isolated local database, applies +migrations, and prints the variables to export before `npm test`. Never point +validation at production or a shared database. A missing database, Node +version, or Chromium prerequisite is a hard failure with a recovery command. + ## API architecture - Every JSON application endpoint must live under `/api/v1` and be documented in `packages/docs/openapi.yaml`. diff --git a/README.md b/README.md index 20bcbf18..de1d372b 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,9 @@ MCP provides selected scoped operations, not every REST capability. REST contrac ## Development and documentation -Use Node 24, `npm ci`, `npm run dev`, and `npm run check`. The Worker lives in `packages/api`, React frontend in `packages/app`, and generated public contract in `packages/api-client`. Frontend calls documented `/api/v1` routes. Keep local secrets in ignored `packages/api/.dev.vars`. +Use Node 24.12.0 and npm 11.19.0 (`.node-version` and `package.json`), then run `npm ci`, `npm run dev`, and `npm test`. The root test is the complete required validation used by CI; `npm run check` is an alias, and `npm run test:backend` / `npm run test:browser` are the focused shared lanes. The Worker lives in `packages/api`, React frontend in `packages/app`, and generated public contract in `packages/api-client`. Frontend calls documented `/api/v1` routes. Keep local secrets in ignored `packages/api/.dev.vars`. + +For a fresh VM, install PostgreSQL and Chromium, run `npm run bootstrap:test`, export the three printed database variables, and then run `npm test`. The bootstrap uses only an isolated local database and refuses remote URLs. Missing prerequisites must be fixed before handoff; do not mark work done after only `git diff --check`. Run `npm run generate --workspace=factorize-docs` after guide edits and `npm run validate --workspace=factorize-docs` before publishing. See [docs publishing](docs/mintlify.md) and [package migration](docs/package-migration.md) for development and release gates. diff --git a/docs/ci-testing.md b/docs/ci-testing.md index 0ccc550b..a2f5b151 100644 --- a/docs/ci-testing.md +++ b/docs/ci-testing.md @@ -6,6 +6,20 @@ required-check name while ensuring a browser failure cannot prevent backend validation. Pull-request runs cancel only an older run for the same PR; merge queue runs use a separate, non-cancelable concurrency group. +Both jobs call the repository's shared lanes: `npm run test:backend` and +`npm run test:browser`. The root `npm test` runs both lanes and `npm run check` +is an alias. This keeps generated-contract drift, builds, package checks, +database integration, functional browser coverage, and application tests in one +auditable implementation. Backend CI provisions an isolated PostgreSQL service; +the browser job installs Chromium. A lane reports passed, failed, and unexecuted +steps and exits nonzero on any missing prerequisite or failed step. + +For a fresh exe.dev VM, use Node 24.12.0 and npm 11.19.0, run `npm ci`, install PostgreSQL and +Chromium, and run `npm run bootstrap:test`. Export its three local database +variables before `npm test`. The bootstrap recreates only the named local +database and applies migrations; it refuses remote database URLs. Optional +visual screenshots and stress tests remain outside required validation. + Screenshot regressions and the 20,000-event trace stress case are intentionally outside required CI. Run **Optional visual regressions** from the Actions tab. Set `Update checked-in Playwright visual baselines` when reviewing a baseline diff --git a/package.json b/package.json index ec2e0723..8fb17124 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "factorize-workspace", "version": "0.1.0", "private": true, + "packageManager": "npm@11.19.0", "workspaces": [ "packages/*" ], @@ -10,8 +11,11 @@ "dev:marketing": "npm run dev --workspace=factorize-marketing", "build:marketing": "npm run build:marketing --workspace=factorize-marketing", "build:css": "npm run build:app", - "test": "npm run test --workspaces --if-present", - "check": "npm run check:backend && npm run check:frontend", + "test": "node scripts/validation.mjs all", + "test:backend": "node scripts/validation.mjs backend", + "test:browser": "node scripts/validation.mjs browser", + "check": "npm test", + "bootstrap:test": "node scripts/bootstrap-test.mjs", "check:backend": "npm run check:hosting && npm run check:boundaries && npm run check:client && npm run validate --workspace=factorize-docs && npm run check --workspace=factorize && npm run test:conditions-runtime && npm run test:hosting-runtime && npm run test:oauth-runtime && npm run test:rollback-runtime && npm run check --workspace=factorize-marketing && npm run check --workspace=factorize-tail-relay", "check:frontend": "npm run check --workspace=factorize-app", "deploy": "npm run deploy:marketing && npm run deploy:app && npm run deploy:tail-relay", @@ -35,6 +39,7 @@ "test:conditions-runtime": "node --test scripts/webhook-conditions-runtime.test.mjs" }, "engines": { - "node": ">=24.12.0" + "node": ">=24.12.0", + "npm": ">=11.19.0" } } diff --git a/scripts/bootstrap-test.mjs b/scripts/bootstrap-test.mjs new file mode 100644 index 00000000..91137319 --- /dev/null +++ b/scripts/bootstrap-test.mjs @@ -0,0 +1,24 @@ +import { execFile } from "node:child_process"; +import { promisify } from "node:util"; +import process from "node:process"; + +const exec = promisify(execFile); +const databaseUrl = process.env.VALIDATION_DATABASE_URL ?? "postgresql://postgres:local-validation-only@localhost:5432/factorize_validation"; +const adminUrl = process.env.VALIDATION_DATABASE_ADMIN_URL ?? "postgresql://postgres:local-validation-only@localhost:5432/postgres"; +const url = new URL(databaseUrl); +const admin = new URL(adminUrl); +if (!["localhost", "127.0.0.1"].includes(url.hostname) || !["localhost", "127.0.0.1"].includes(admin.hostname)) { + throw new Error("Validation databases must be local PostgreSQL instances; production or remote database URLs are refused."); +} + +await exec(process.platform === "win32" ? "where" : "which", ["psql"]); +await exec("psql", [admin.href, "-v", "ON_ERROR_STOP=1", "-c", `SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '${url.pathname.slice(1)}' AND pid <> pg_backend_pid();`]); +await exec("psql", [admin.href, "-v", "ON_ERROR_STOP=1", "-c", `DROP DATABASE IF EXISTS \"${url.pathname.slice(1)}\";`]); +await exec("psql", [admin.href, "-v", "ON_ERROR_STOP=1", "-c", `CREATE DATABASE \"${url.pathname.slice(1)}\";`]); +const env = { ...process.env, DATABASE_URL: databaseUrl, AUTH_TEST_DATABASE_URL: databaseUrl, QUEUE_TEST_DATABASE_URL: databaseUrl }; +await exec("npm", ["run", "db:migrate", "--workspace=factorize"], { env, stdio: "inherit" }); +console.log(`Isolated validation database ready: ${databaseUrl.replace(/:[^:@/]+@/, ":***@")}`); +console.log(`export DATABASE_URL=${JSON.stringify(databaseUrl)}`); +console.log(`export AUTH_TEST_DATABASE_URL=${JSON.stringify(databaseUrl)}`); +console.log(`export QUEUE_TEST_DATABASE_URL=${JSON.stringify(databaseUrl)}`); +console.log("Then run: npm test"); diff --git a/scripts/validation.mjs b/scripts/validation.mjs new file mode 100644 index 00000000..e31af8c6 --- /dev/null +++ b/scripts/validation.mjs @@ -0,0 +1,76 @@ +import { spawn } from "node:child_process"; +import { access } from "node:fs/promises"; +import process from "node:process"; + +const lane = process.argv[2] ?? "all"; +const expectedNode = "24.12.0"; +const lanes = { + backend: [ + ["generated contracts", "npm", ["run", "generate"]], + ["generated contract drift", "git", ["diff", "--exit-code", "--", "packages/docs/openapi.yaml", "packages/api-client/src/schema.d.ts"]], + ["application build", "npm", ["run", "build", "--workspace=factorize-app"]], + ["backend checks", "npm", ["run", "check:backend"]], + ["compiled app/API/PostgreSQL integration", "npm", ["run", "test:static-slice", "--workspace=factorize"]], + ], + browser: [ + ["application build", "npm", ["run", "build", "--workspace=factorize-app"]], + ["Chromium availability", process.execPath, ["scripts/validation.mjs", "--check-chromium"]], + ["functional browser checks", "npm", ["run", "test:functional", "--workspace=factorize-app"]], + ["application unit checks", "npm", ["test", "--workspace=factorize-app"]], + ], +}; + +if (lane === "--check-chromium") { + try { + const { chromium } = await import("@playwright/test"); + await access(chromium.executablePath()); + } catch { + console.error("Chromium is required but was not found. Recover with: npm exec --workspace=factorize-app -- playwright install --with-deps chromium"); + process.exit(1); + } + process.exit(0); +} + +if (!["all", "backend", "browser"].includes(lane)) { + console.error(`Unknown validation lane: ${lane}. Use all, backend, or browser.`); + process.exit(2); +} + +const results = []; +const run = (name, command, args) => new Promise((resolve) => { + const child = spawn(command, args, { stdio: "inherit", env: process.env }); + child.on("error", (error) => { console.error(`${name}: ${error.message}`); resolve(127); }); + child.on("exit", (code, signal) => resolve(code ?? (signal ? 1 : 0))); +}); + +if (!/^v?24\.(1[2-9]|[2-9][0-9])\./.test(process.version)) { + console.error(`Node ${expectedNode} or newer in the 24.x line is required; found ${process.version}. Recover with: nvm install ${expectedNode} && nvm use ${expectedNode} && npm ci`); + process.exit(1); +} + +if (lane !== "browser") { + const missing = ["DATABASE_URL", "AUTH_TEST_DATABASE_URL", "QUEUE_TEST_DATABASE_URL"].filter((name) => !process.env[name]); + if (missing.length) { + console.error(`Backend validation requires an isolated PostgreSQL database (${missing.join(", ")}). Recover with: npm run bootstrap:test`); + process.exit(1); + } +} + +const selected = lane === "all" ? ["backend", "browser"] : [lane]; +for (const selectedLane of selected) { + console.log(`\n=== ${selectedLane} validation ===`); + for (const [name, command, args] of lanes[selectedLane]) { + const code = await run(name, command, args); + results.push({ lane: selectedLane, name, status: code === 0 ? "passed" : "failed" }); + if (code !== 0) { + for (const pending of lanes[selectedLane].slice(results.filter((item) => item.lane === selectedLane).length)) { + results.push({ lane: selectedLane, name: pending[0], status: "not run" }); + } + break; + } + } +} + +console.log("\n=== validation summary ==="); +for (const result of results) console.log(`${result.status.padEnd(8)} ${result.lane}: ${result.name}`); +if (results.some(({ status }) => status === "failed" || status === "not run")) process.exit(1);