Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: |
Expand All @@ -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: |
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/visual-regressions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
24.12.0
14 changes: 14 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
14 changes: 14 additions & 0 deletions docs/ci-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "factorize-workspace",
"version": "0.1.0",
"private": true,
"packageManager": "npm@11.19.0",
"workspaces": [
"packages/*"
],
Expand All @@ -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",
Expand All @@ -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"
}
}
24 changes: 24 additions & 0 deletions scripts/bootstrap-test.mjs
Original file line number Diff line number Diff line change
@@ -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");
76 changes: 76 additions & 0 deletions scripts/validation.mjs
Original file line number Diff line number Diff line change
@@ -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);
Loading