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
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.git
node_modules
**/node_modules
.wrangler
packages/*/dist
packages/*/coverage
npm-debug.log
19 changes: 14 additions & 5 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@ 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.
For a fresh exe.dev VM, use the Factorize validation runner image described in
[`docs/factorize-validation-runner.md`](docs/factorize-validation-runner.md).
It provides Node 24.12.0, npm 11.19.0, PostgreSQL and the matching Playwright
Chromium build. After checkout, run `npm ci` and `npm run test:local`; this
resets only the isolated local validation database, applies migrations, and
runs the complete root suite with the database variables in its child
process. The image smoke command checks PostgreSQL password authentication
and Chromium through the non-login `exedev` process environment. Do not repair
the VM manually with apt or a browser download; fix the image and publish a
new digest instead.

To prepare the database without running tests, use `npm run bootstrap:test`;
it prints the variables to export before `npm test`. Never point validation at
production or a shared database. The bootstrap refuses remote database URLs.

## API architecture

Expand Down
45 changes: 45 additions & 0 deletions Dockerfile.validation-runner
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM ghcr.int.exe.xyz/boldsoftware/exeuntu:latest

SHELL ["/bin/bash", "-euo", "pipefail", "-c"]

ARG NODE_VERSION=24.12.0
ARG NPM_VERSION=11.19.0
ARG PLAYWRIGHT_VERSION=1.64.0

# This is an image-level environment variable so exe.dev's non-login job
# process inherits the same browser location as an interactive shell.
ENV PLAYWRIGHT_BROWSERS_PATH=/opt/ms-playwright

COPY docker/factorize-validation-postgres-auth.sh /usr/local/sbin/factorize-validation-postgres-auth
COPY docker/factorize-validation-postgres-auth.service /etc/systemd/system/factorize-validation-postgres-auth.service
COPY docker/factorize-validation-postgres.conf /tmp/factorize-validation-postgres.conf

RUN chmod 0755 /usr/local/sbin/factorize-validation-postgres-auth && \
printf '#!/bin/sh\nexit 101\n' > /usr/sbin/policy-rc.d && chmod 0755 /usr/sbin/policy-rc.d && \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends postgresql postgresql-client xz-utils && \
mkdir -p /etc/postgresql/16/main/conf.d && \
install -m 0644 /tmp/factorize-validation-postgres.conf /etc/postgresql/16/main/conf.d/99-factorize-validation.conf && \
rm -f /tmp/factorize-validation-postgres.conf && \
arch="$(dpkg --print-architecture)" && \
case "$arch" in amd64) node_arch=x64 ;; arm64) node_arch=arm64 ;; *) echo "Unsupported Node architecture: $arch" >&2; exit 1 ;; esac && \
curl --fail --silent --show-error --location --retry 5 --retry-all-errors \
"https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${node_arch}.tar.xz" \
| tar -xJ --strip-components=1 -C /usr/local && \
npm install --global "npm@${NPM_VERSION}" "playwright@${PLAYWRIGHT_VERSION}" && \
PLAYWRIGHT_BROWSERS_PATH=/opt/ms-playwright playwright install --with-deps chromium && \
rm -f /usr/sbin/policy-rc.d && \
rm -rf /var/lib/apt/lists/* && \
chmod -R a+rX /opt/ms-playwright && \
systemctl enable postgresql.service factorize-validation-postgres-auth.service && \
mkdir -p /etc/profile.d && \
printf 'export PLAYWRIGHT_BROWSERS_PATH=/opt/ms-playwright\n' \
> /etc/profile.d/factorize-playwright.sh && \
printf 'PLAYWRIGHT_BROWSERS_PATH=/opt/ms-playwright\n' >> /etc/environment && \
node --version | grep -Fx "v${NODE_VERSION}" && \
npm --version | grep -Fx "${NPM_VERSION}" && \
test "$(node -p 'require("/usr/local/lib/node_modules/playwright/package.json").version')" = "${PLAYWRIGHT_VERSION}" && \
runuser --preserve-environment -u exedev -- node -e 'const { chromium } = require("/usr/local/lib/node_modules/playwright"); (async () => { if (process.env.PLAYWRIGHT_BROWSERS_PATH !== "/opt/ms-playwright") throw new Error("missing image browser environment"); const browser = await chromium.launch({ headless: true }); console.log(await browser.version()); await browser.close(); })().catch(error => { console.error(error); process.exit(1); });'

COPY scripts/smoke-validation-runner-image.sh /usr/local/bin/smoke-validation-runner-image
RUN chmod 0755 /usr/local/bin/smoke-validation-runner-image
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ MCP provides selected scoped operations, not every REST capability. REST contrac

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`.
On exe.dev, use the [Factorize validation runner image](docs/factorize-validation-runner.md), then run `npm ci` and `npm run test:local` after checkout. The image supplies the pinned Node, npm, PostgreSQL authentication, Playwright Chromium, and browser OS dependencies; `test:local` resets only the local validation database, applies migrations, and runs the complete root suite. The bootstrap refuses remote database URLs. To prepare the database without running tests, use `npm run bootstrap:test` and export its three printed variables before `npm test`. Missing prerequisites must be fixed in the image and published as a new digest; do not repair a fresh VM by hand or 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
12 changes: 12 additions & 0 deletions docker/factorize-validation-postgres-auth.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Configure loopback-only Factorize validation database authentication
Requires=postgresql.service
After=postgresql.service

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/factorize-validation-postgres-auth
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
7 changes: 7 additions & 0 deletions docker/factorize-validation-postgres-auth.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
set -eu

# ExecStartPost runs as root after PostgreSQL has initialized/started. Use the
# postgres OS account and local peer auth so no credential is needed at build.
runuser -u postgres -- psql --dbname=postgres --set=ON_ERROR_STOP=1 \
--command="ALTER ROLE postgres WITH LOGIN PASSWORD 'local-validation-only'"
2 changes: 2 additions & 0 deletions docker/factorize-validation-postgres.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
listen_addresses = 'localhost'
password_encryption = 'scram-sha-256'
15 changes: 10 additions & 5 deletions docs/ci-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ 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.
For a fresh exe.dev VM, boot the Factorize validation runner image described
in [`factorize-validation-runner.md`](factorize-validation-runner.md). Run
`scripts/smoke-validation-runner-image.sh` once after boot to check the
PostgreSQL password over loopback and launch the matching Chromium as `exedev`
through the non-login image environment. Then check out the repository, run
`npm ci`, and run `npm run test:local`. The image build enables PostgreSQL for
VM boot but does not start systemd during the build. The bootstrap recreates
only the isolated local validation database and applies the checkout's
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.
Expand Down
74 changes: 74 additions & 0 deletions docs/factorize-validation-runner.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Factorize validation runner image

The Factorize-specific exe.dev runner image is built from
[`Dockerfile.validation-runner`](../Dockerfile.validation-runner), using the
documented exe.dev `exeuntu` base. It keeps the base image's SSH, systemd,
`exedev` user, and agent setup while adding prerequisites for the complete
Factorize test suite.

The image pins Node 24.12.0, npm 11.19.0, and Playwright/Chromium 1.64.0. It
installs PostgreSQL 16 without starting systemd during image build, enables
the PostgreSQL service for VM boot, and sets the `postgres` password used by
`scripts/bootstrap-test.mjs`. PostgreSQL listens on loopback; the test
bootstrap creates and recreates only its isolated validation database. The
image sets `PLAYWRIGHT_BROWSERS_PATH=/opt/ms-playwright` as an OCI environment
variable so non-login job processes inherit the installed browser location.
The Docker build launches Chromium as `exedev`; the post-boot smoke command
also checks password authentication over TCP and Chromium from the job user.

## Build, publish, and pin

The build/publish script uses the attached GHCR integration and prints the
immutable public image reference with its registry digest:

```sh
scripts/build-validation-runner-image.sh
```

The resulting package must be public because exe.dev job images are pulled by
the host and private images are unsupported for jobs. Set the Factorize Dev
job's image to the printed
`ghcr.io/generationsoftware/factorize-validation-runner@sha256:…` reference,
preserving its other execution configuration. Do not use a mutable tag for
the job image. Record the exact digest in the issue handoff and validation
record below.

## Fresh-VM acceptance

After booting the pinned image, run the image smoke check, then check out the
Factorize repository and run the full local validation:

```sh
scripts/smoke-validation-runner-image.sh
npm ci
npm run test:local
```

`test:local` resets the local validation database, applies the migrations
from that checkout, sets all three isolated database URLs in the root test
process, and runs `npm test`. Before it drops or recreates the database,
`test:local` launches Chromium and authenticates to the configured local
PostgreSQL admin URL, so missing image prerequisites fail before migrations
or the full suite. A failure requires correcting the image or bootstrap and
publishing a new digest, followed by repeating this sequence.

## Validated image record

| Field | Value |
| --- | --- |
| Public image digest | `ghcr.io/generationsoftware/factorize-validation-runner@sha256:1333c4a7bb49c4cbcdd28ca2b57331dfcbff7cf611db1aaeaa4830517aacf6d4` |
| Node / npm / Playwright | 24.12.0 / 11.19.0 / 1.64.0 |
| Image smoke and full suite | Passed in a Docker container pulled anonymously from the immutable digest; not fresh-VM evidence |
| Fresh Dev VM and Dev job image pin | Pending; keep PR #392 draft and GEN-2889 In Progress until this gate passes |

The checkpoint pull and container validation were repeated on 2026-11-11.
An unauthenticated GHCR manifest request returned HTTP 200 for the digest,
and `docker pull` with an empty Docker config downloaded the same digest. In a
container from that image, the PostgreSQL authentication helper and image smoke
passed, followed by `npm ci` and `npm run test:local` on Factorize commit
`02f96e9e23908537fffc2584b26abe85c34b1090` (backend 569 passed / 5 skipped,
browser 102 passed / 1 skipped, proxy checks and builds passed). The container
test starts PostgreSQL and invokes the image's authentication helper as setup;
it does not verify exe.dev VM boot behavior. The Dev job remains on
`ghcr.io/generationsoftware/anarack:latest`. A fresh Dev VM must still boot
from the digest and pass these checks before the job image is pinned.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"test:proxy": "node scripts/validation.mjs proxy",
"check": "npm test",
"bootstrap:test": "node scripts/bootstrap-test.mjs",
"test:local": "node scripts/bootstrap-test.mjs --test",
"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 Down
30 changes: 29 additions & 1 deletion scripts/bootstrap-test.mjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,52 @@
import { execFile } from "node:child_process";
import { execFile, spawn } from "node:child_process";
import { promisify } from "node:util";
import process from "node:process";

const exec = promisify(execFile);
const runTests = process.argv.includes("--test");
const expectedNode = "v24.12.0";
const expectedNpm = "11.19.0";
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.");
}
if (process.version !== expectedNode) throw new Error(`Validation requires Node ${expectedNode}; found ${process.version}. Boot the pinned Factorize validation runner image.`);
const npmVersion = (await exec("npm", ["--version"])).stdout.trim();
if (npmVersion !== expectedNpm) throw new Error(`Validation requires npm ${expectedNpm}; found ${npmVersion}. Boot the pinned Factorize validation runner image.`);

function runInherited(command, args, options) {
return new Promise((resolve, reject) => {
const child = spawn(command, args, { ...options, stdio: "inherit" });
child.once("error", reject);
child.once("close", (code, signal) => {
if (code === 0) resolve();
else reject(new Error(`${command} ${args.join(" ")} failed${signal ? ` with signal ${signal}` : ` with exit code ${code}`}`));
});
});
}

await exec(process.platform === "win32" ? "where" : "which", ["psql"]);
try {
const { chromium } = await import("@playwright/test");
const browser = await chromium.launch({ headless: true });
await browser.close();
} catch (error) {
throw new Error("Validation Chromium is unavailable before database reset. Boot the pinned Factorize validation runner image and preserve PLAYWRIGHT_BROWSERS_PATH from its image environment.", { cause: error });
}
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(/:[^:@/]+@/, ":***@")}`);
if (runTests) {
await runInherited("npm", ["test"], { env });
} else {
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");
}
19 changes: 19 additions & 0 deletions scripts/build-validation-runner-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -euo pipefail

repository='generationsoftware/factorize-validation-runner'
registry='ghcr.int.exe.xyz'
tag="${1:-$(git rev-parse --short=12 HEAD)}"
metadata_file="$(mktemp)"
trap 'rm -f "$metadata_file"' EXIT

docker buildx build \
--platform linux/amd64 \
--file Dockerfile.validation-runner \
--tag "${registry}/${repository}:${tag}" \
--push \
--metadata-file "$metadata_file" \
.

digest="$(jq -er '.["containerimage.digest"] | select(test("^sha256:[0-9a-f]{64}$"))' "$metadata_file")"
printf 'Published image: ghcr.io/%s@%s\n' "$repository" "$digest"
25 changes: 25 additions & 0 deletions scripts/smoke-validation-runner-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -euo pipefail

expected_node=24.12.0
expected_npm=11.19.0
expected_playwright=1.64.0

[[ "$(node --version)" == "v${expected_node}" ]]
[[ "$(npm --version)" == "${expected_npm}" ]]
[[ "$(node -p 'require("/usr/local/lib/node_modules/playwright/package.json").version')" == "${expected_playwright}" ]]
[[ "${PLAYWRIGHT_BROWSERS_PATH:-}" == "/opt/ms-playwright" ]]

# This must work for an ordinary non-login exedev process with the environment
# inherited from the VM image, as used by job execution.
runuser --preserve-environment -u exedev -- node --input-type=module -e '
import { chromium } from "/usr/local/lib/node_modules/playwright/index.mjs";
if (process.env.PLAYWRIGHT_BROWSERS_PATH !== "/opt/ms-playwright") throw new Error("Playwright image environment was not inherited");
const browser = await chromium.launch({ headless: true });
console.log(`Chromium ${browser.version()} launched as uid ${process.getuid()} via the non-login image environment`);
await browser.close();
'

# Password authentication uses the same URL and password as bootstrap-test.mjs.
psql 'postgresql://postgres:local-validation-only@localhost:5432/postgres' \
--no-psqlrc --set=ON_ERROR_STOP=1 --tuples-only --command='SELECT current_user, inet_server_addr()'
Loading