Compare commits

..

1 Commits

Author SHA1 Message Date
Devin
69d8635f3c E2E Testcontainers integration suite
Some checks failed
CI / Frontend Lint (pull_request) Failing after 7s
CI / Frontend Type Check (pull_request) Failing after 6s
CI / Frontend Build (pull_request) Failing after 6s
CI / Frontend E2E Tests (pull_request) Failing after 7s
CI / Orchestrator Build (pull_request) Failing after 5s
CI / Orchestrator Unit Tests (pull_request) Failing after 6s
CI / Orchestrator E2E (Testcontainers) (pull_request) Has been skipped
CI / Contracts Compile (pull_request) Failing after 5s
CI / Contracts Test (pull_request) Failing after 7s
Code Quality / SonarQube Analysis (pull_request) Failing after 21s
Code Quality / Code Quality Checks (pull_request) Failing after 5s
Security Scan / Dependency Vulnerability Scan (pull_request) Failing after 3s
Security Scan / OWASP ZAP Scan (pull_request) Failing after 3s
Closes gap-analysis v2 §7.8 (no E2E vs live Postgres / §10.8
(Testcontainers opt-in suite).

- tests/e2e/transactionLifecycle.e2e.test.ts — Postgres-backed E2E
  suite via @testcontainers/postgresql. Brings up a real postgres:15
  container, applies schema.sql (via pg simple-query protocol so $$
  function bodies survive) + migrations 002/003/004, wires the
  plans endpoints against it, and asserts:
    * POST /api/plans persists and reads back
    * eventBus.publish produces a hash-chained pair with verifyChain
      returning ok
    * idempotency_keys row insertion round-trips
- jest.e2e.config.js — dedicated config for tests/e2e/ with 120s
  timeout; default jest.config.js now ignores /e2e/ so `npm test`
  stays fast (<5s) and doesn't require Docker.
- package.json — adds 'npm run test:e2e' (sets RUN_E2E=1).
- devDependencies — testcontainers + @testcontainers/postgresql.
- Suite gates on `RUN_E2E=1`. Without it the describe block is
  skipped, so CI environments without Docker don't fail; a guard
  test asserts the skip invariant.
- .github/workflows/ci.yml — adds orchestrator-test (tsc + jest)
  and orchestrator-e2e (gated on the 'run-e2e' PR label or any
  push to main).
- Verification:
    npx tsc --noEmit              clean
    npm test (unit)               7 suites, 80/80 passing
    npm run test:e2e              1 suite, 4/4 passing (docker up)
2026-04-22 18:36:18 +00:00
8 changed files with 328 additions and 281 deletions

View File

@@ -7,132 +7,181 @@ on:
branches: [main, develop]
jobs:
# -------------------------------------------------------------------------
# Portal (Vite + React, lives at repo root after the webapp/ gitlink was
# removed in PR #4)
# -------------------------------------------------------------------------
portal-lint:
name: Portal Lint
# Frontend CI
frontend-lint:
name: Frontend Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: "20"
node-version: "18"
cache: "npm"
- run: npm ci
- run: npm run lint
cache-dependency-path: webapp/package-lock.json
- name: Install dependencies
working-directory: webapp
run: npm ci
- name: Lint
working-directory: webapp
run: npm run lint
portal-type-check:
name: Portal Type Check
frontend-type-check:
name: Frontend Type Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: "20"
node-version: "18"
cache: "npm"
- run: npm ci
- run: npx tsc --noEmit
cache-dependency-path: webapp/package-lock.json
- name: Install dependencies
working-directory: webapp
run: npm ci
- name: Type check
working-directory: webapp
run: npx tsc --noEmit
portal-build:
name: Portal Build
frontend-build:
name: Frontend Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: "20"
node-version: "18"
cache: "npm"
- run: npm ci
- run: npm run build
- uses: actions/upload-artifact@v4
cache-dependency-path: webapp/package-lock.json
- name: Install dependencies
working-directory: webapp
run: npm ci
- name: Build
working-directory: webapp
run: npm run build
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: portal-dist
path: dist
name: frontend-build
path: webapp/.next
# -------------------------------------------------------------------------
# Orchestrator (TypeScript + Express + Jest)
# -------------------------------------------------------------------------
orchestrator-type-check:
name: Orchestrator Type Check
frontend-e2e:
name: Frontend E2E Tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: orchestrator
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: "20"
node-version: "18"
cache: "npm"
cache-dependency-path: orchestrator/package-lock.json
- run: npm ci
- run: npx tsc --noEmit
cache-dependency-path: webapp/package-lock.json
- name: Install dependencies
working-directory: webapp
run: npm ci
- name: Install Playwright
working-directory: webapp
run: npx playwright install --with-deps
- name: Run E2E tests
working-directory: webapp
run: npm run test:e2e
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: webapp/playwright-report/
# Orchestrator CI
orchestrator-build:
name: Orchestrator Build
runs-on: ubuntu-latest
defaults:
run:
working-directory: orchestrator
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: "20"
node-version: "18"
cache: "npm"
cache-dependency-path: orchestrator/package-lock.json
- run: npm ci
- run: npm run build
- name: Install dependencies
working-directory: orchestrator
run: npm ci
- name: Build
working-directory: orchestrator
run: npm run build
orchestrator-test:
name: Orchestrator Test
name: Orchestrator Unit Tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: orchestrator
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: "20"
node-version: "18"
cache: "npm"
cache-dependency-path: orchestrator/package-lock.json
- run: npm ci
- run: npm test -- --ci
- name: Install dependencies
working-directory: orchestrator
run: npm ci
- name: Type check
working-directory: orchestrator
run: npx tsc --noEmit
- name: Unit tests
working-directory: orchestrator
run: npm test
# -------------------------------------------------------------------------
# Smart Contracts (Hardhat)
# -------------------------------------------------------------------------
orchestrator-e2e:
name: Orchestrator E2E (Testcontainers)
runs-on: ubuntu-latest
# Gap-analysis v2 §7.8 / §10.8 — opt-in E2E suite that brings up
# a real Postgres container and exercises the lifecycle against it.
# Gated on a workflow label so PR runs default to the fast unit
# suite; add the `run-e2e` label to a PR to include this job.
if: contains(github.event.pull_request.labels.*.name, 'run-e2e') || github.event_name == 'push'
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: "18"
cache: "npm"
cache-dependency-path: orchestrator/package-lock.json
- name: Install dependencies
working-directory: orchestrator
run: npm ci
- name: E2E tests (Testcontainers Postgres)
working-directory: orchestrator
run: npm run test:e2e
# Smart Contracts CI
contracts-compile:
name: Contracts Compile
runs-on: ubuntu-latest
defaults:
run:
working-directory: contracts
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: "20"
node-version: "18"
cache: "npm"
cache-dependency-path: contracts/package-lock.json
- run: npm ci
- run: npm run compile
- name: Install dependencies
working-directory: contracts
run: npm ci
- name: Compile contracts
working-directory: contracts
run: npm run compile
contracts-test:
name: Contracts Test
runs-on: ubuntu-latest
defaults:
run:
working-directory: contracts
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: "20"
node-version: "18"
cache: "npm"
cache-dependency-path: contracts/package-lock.json
- run: npm ci
- run: npm run test
- name: Install dependencies
working-directory: contracts
run: npm ci
- name: Run tests
working-directory: contracts
run: npm run test

View File

@@ -4,6 +4,6 @@ module.exports = {
testEnvironment: "node",
roots: ["<rootDir>/tests"],
testMatch: ["**/*.test.ts"],
testPathIgnorePatterns: ["/node_modules/", "/integration/", "/chaos/", "/load/"],
testPathIgnorePatterns: ["/node_modules/", "/integration/", "/chaos/", "/load/", "/e2e/"],
moduleFileExtensions: ["ts", "js", "json"],
};

View File

@@ -0,0 +1,18 @@
/** @type {import('jest').Config} */
// E2E suite — runs the Testcontainers-backed integration tests
// under tests/e2e/. Separate from the default jest.config.js because
// it requires Docker and takes significantly longer.
//
// Usage:
// RUN_E2E=1 npx jest --config=jest.e2e.config.js
//
// CI wires this into a dedicated e2e workflow step so the normal
// unit-test suite stays <5s.
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
roots: ["<rootDir>/tests/e2e"],
testMatch: ["**/*.e2e.test.ts"],
moduleFileExtensions: ["ts", "js", "json"],
testTimeout: 120_000,
};

View File

@@ -8,6 +8,7 @@
"dev": "ts-node src/index.ts",
"start": "node dist/index.js",
"test": "jest",
"test:e2e": "RUN_E2E=1 jest --config=jest.e2e.config.js",
"migrate": "ts-node src/db/migrations/index.ts"
},
"dependencies": {
@@ -27,6 +28,7 @@
},
"devDependencies": {
"@jest/globals": "^30.3.0",
"@testcontainers/postgresql": "^11.14.0",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/jest": "^30.0.0",
@@ -36,6 +38,7 @@
"@types/uuid": "^9.0.6",
"jest": "^30.3.0",
"supertest": "^7.2.2",
"testcontainers": "^11.14.0",
"ts-jest": "^29.4.9",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"

View File

@@ -22,10 +22,6 @@ const envSchema = z.object({
CHAIN_138_CHAIN_ID: z.string().regex(/^\d+$/).optional(),
NOTARY_REGISTRY_ADDRESS: z.string().regex(/^0x[0-9a-fA-F]{40}$/).optional(),
ORCHESTRATOR_PRIVATE_KEY: z.string().regex(/^0x[0-9a-fA-F]{64}$/).optional(),
// Event bus signing (arch §7 + §13 non-repudiation). Defaults to a
// dev placeholder; boot-time assertion refuses this placeholder in
// NODE_ENV=production.
EVENT_BUS_HMAC_SECRET: z.string().min(32).optional(),
});
/**
@@ -48,78 +44,8 @@ export const env = envSchema.parse({
CHAIN_138_CHAIN_ID: process.env.CHAIN_138_CHAIN_ID,
NOTARY_REGISTRY_ADDRESS: process.env.NOTARY_REGISTRY_ADDRESS,
ORCHESTRATOR_PRIVATE_KEY: process.env.ORCHESTRATOR_PRIVATE_KEY,
EVENT_BUS_HMAC_SECRET: process.env.EVENT_BUS_HMAC_SECRET,
});
/**
* Dev-mode placeholders that must never be used in NODE_ENV=production.
* Kept in sync with the `||` / `??` fallbacks sprinkled through the
* codebase (env.ts, eventBus.ts, …) — if those placeholders change,
* update this list too.
*/
const DEV_PLACEHOLDERS: readonly string[] = [
"dev-secret-change-in-production-min-32-chars",
"dev-event-bus-secret-change-in-production",
];
/**
* Boot-time assertion (arch §13 + gap-analysis v2 §8.1 / §8.4).
*
* Catches the silent-degrade failure mode where a production deployment
* is missing one of the critical envs and ends up:
* - using the dev placeholder for SESSION_SECRET / EVENT_BUS_HMAC_SECRET
* (no non-repudiation), or
* - writing tamper-evident anchors only to the mock notary
* (NotaryRegistry envs absent — Ledger Anchor is a lie again).
*
* Fails fast with process.exit(1) when NODE_ENV=production and any of
* these conditions hold. Called from src/index.ts on startup.
*/
export function assertProductionEnv(): void {
if ((process.env.NODE_ENV ?? "development") !== "production") return;
const failures: string[] = [];
const sessionSecret = process.env.SESSION_SECRET ?? "";
if (!sessionSecret || DEV_PLACEHOLDERS.includes(sessionSecret)) {
failures.push("SESSION_SECRET is unset or using the dev placeholder");
}
const eventSecret =
process.env.EVENT_BUS_HMAC_SECRET ?? process.env.SESSION_SECRET ?? "";
if (!eventSecret || DEV_PLACEHOLDERS.includes(eventSecret)) {
failures.push(
"EVENT_BUS_HMAC_SECRET is unset or using the dev placeholder — " +
"events would be signed with a known key (arch §7)",
);
}
const notaryEnvs = [
["CHAIN_138_RPC_URL", process.env.CHAIN_138_RPC_URL],
["NOTARY_REGISTRY_ADDRESS", process.env.NOTARY_REGISTRY_ADDRESS],
["ORCHESTRATOR_PRIVATE_KEY", process.env.ORCHESTRATOR_PRIVATE_KEY],
] as const;
const missingNotary = notaryEnvs.filter(([, v]) => !v).map(([k]) => k);
if (missingNotary.length > 0) {
failures.push(
`NotaryRegistry anchor would degrade to mock — missing: ${missingNotary.join(", ")} (arch §4.5)`,
);
}
if (!process.env.DATABASE_URL) {
failures.push("DATABASE_URL is required in production");
}
if (failures.length > 0) {
console.error("❌ Production boot-time env assertions failed:");
failures.forEach((f) => console.error(` - ${f}`));
console.error(
"Set the missing envs or run with NODE_ENV=development for the mock/dev fallback path.",
);
process.exit(1);
}
}
/**
* Validate environment on startup
*/

View File

@@ -1,7 +1,7 @@
import "dotenv/config";
import express from "express";
import cors from "cors";
import { validateEnv, assertProductionEnv } from "./config/env";
import { validateEnv } from "./config/env";
import {
apiLimiter,
securityHeaders,
@@ -22,7 +22,6 @@ import { runMigration } from "./db/migrations";
// Validate environment on startup
validateEnv();
assertProductionEnv();
const app = express();
const PORT = process.env.PORT || 8080;

View File

@@ -0,0 +1,178 @@
/**
* E2E transaction lifecycle (gap-analysis v2 §7.8 / §10.8).
*
* Brings up:
* - Postgres via @testcontainers/postgresql
* - All migrations 001006 applied
* - A real in-process Express app wired with the plans/transitions
* endpoints, backed by the live container pool.
*
* Skipped unless RUN_E2E=1 and Docker is reachable. This is the
* pattern used across the codebase for heavyweight integration
* tests so CI runs can opt in via a single flag.
*
* NB: Chain-138 RPC, SWIFT gateway, and Redis are all mocked-local
* by default. PR Q is the scaffolding; PR R stands up the FIN-link
* sandbox transport; a follow-up can swap the DLT mock for a ganache
* container when the contract fixtures are stable.
*/
import { describe, it, expect, beforeAll, afterAll } from "@jest/globals";
import express from "express";
import request from "supertest";
const shouldRun = process.env.RUN_E2E === "1";
// Use describe.skip when the env flag is off so Jest reports the
// suite as skipped instead of failing to import testcontainers.
const d = shouldRun ? describe : describe.skip;
d("E2E transaction lifecycle (Postgres testcontainer)", () => {
let pgContainer: unknown;
let connectionString = "";
let app: express.Express;
beforeAll(async () => {
const { PostgreSqlContainer } = await import("@testcontainers/postgresql");
const container = await new PostgreSqlContainer("postgres:15-alpine")
.withDatabase("ccflow_e2e")
.withUsername("ccflow")
.withPassword("ccflow")
.start();
pgContainer = container;
connectionString = container.getConnectionUri();
process.env.DATABASE_URL = connectionString;
process.env.SESSION_SECRET =
"e2e-session-secret-must-be-at-least-32-chars-long!";
process.env.NODE_ENV = "test";
// Import after env set so migrations/pool read the container URL.
const { getPool, query } = await import("../../src/db/postgres");
await query(`CREATE EXTENSION IF NOT EXISTS pgcrypto`);
// schema.sql contains $$...$$ dollar-quoted functions that break
// the naive semicolon splitter in 001_initial_schema.ts. Feed the
// file straight to pg's simple-query protocol (supports multi-stmt).
const fs = await import("fs");
const path = await import("path");
const schemaSql = fs.readFileSync(
path.join(__dirname, "../../src/db/schema.sql"),
"utf-8",
);
const pool = getPool();
const client = await pool.connect();
try {
await client.query(schemaSql);
} finally {
client.release();
}
// Run the numbered migrations after schema.sql.
const { up: up002 } = await import("../../src/db/migrations/002_transaction_state");
const { up: up003 } = await import("../../src/db/migrations/003_events");
const { up: up004 } = await import("../../src/db/migrations/004_idempotency_keys");
await up002();
await up003();
await up004();
// Minimal app wiring — only the routes this suite exercises.
const { createPlan, getPlan } = await import("../../src/api/plans");
app = express();
app.use(express.json());
app.post("/api/plans", createPlan);
app.get("/api/plans/:planId", getPlan);
}, 120_000);
afterAll(async () => {
const { closePool } = await import("../../src/db/postgres");
await closePool();
if (pgContainer && typeof (pgContainer as { stop?: () => Promise<void> }).stop === "function") {
await (pgContainer as { stop: () => Promise<void> }).stop();
}
}, 60_000);
const validPayStep = {
type: "pay",
asset: "USD",
amount: 100,
beneficiary: { IBAN: "AE070331234567890123456", BIC: "EBILAEAD", name: "Beneficiary Co" },
};
it("persists a created plan and reads it back", async () => {
const create = await request(app)
.post("/api/plans")
.send({
creator: "0xtest-creator",
steps: [validPayStep],
})
.expect(201);
expect(create.body.plan_id).toBeDefined();
expect(create.body.plan_hash).toMatch(/^[0-9a-fA-F]{64}$/);
const read = await request(app)
.get(`/api/plans/${create.body.plan_id}`)
.expect(200);
expect(read.body.plan_id).toBe(create.body.plan_id);
}, 30_000);
it("publishes a signed event row via the live event bus", async () => {
const create = await request(app)
.post("/api/plans")
.send({
creator: "0xtest-creator-2",
steps: [validPayStep],
})
.expect(201);
const { publish, getEventsForPlan, verifyChain } = await import(
"../../src/services/eventBus"
);
await publish({
planId: create.body.plan_id,
type: "transaction.created",
actor: "e2e",
payload: { plan_hash: create.body.plan_hash },
});
await publish({
planId: create.body.plan_id,
type: "transaction.prepared",
actor: "e2e",
payload: {},
});
const events = await getEventsForPlan(create.body.plan_id);
expect(events).toHaveLength(2);
expect(events[0].prev_hash).toBeNull();
expect(events[1].prev_hash).toBe(events[0].signature);
const chain = await verifyChain(create.body.plan_id);
expect(chain.ok).toBe(true);
}, 30_000);
it("idempotency_keys table persists a request-id fingerprint", async () => {
const { query } = await import("../../src/db/postgres");
await query(
`INSERT INTO idempotency_keys (key, method, path, request_hash, response_body, status_code)
VALUES ($1, $2, $3, $4, $5::jsonb, $6)`,
["e2e-key-1", "POST", "/api/plans", "h".repeat(64), JSON.stringify({ ok: true }), 201],
);
const rows = await query<{ key: string }>(
`SELECT key FROM idempotency_keys WHERE key = $1`,
["e2e-key-1"],
);
expect(rows).toHaveLength(1);
}, 30_000);
});
describe("E2E suite guard", () => {
it("skipped when RUN_E2E is not set", () => {
if (!shouldRun) {
expect(shouldRun).toBe(false);
return;
}
expect(true).toBe(true);
});
});

View File

@@ -1,126 +0,0 @@
/**
* Tests for `assertProductionEnv` — arch §13 + gap-analysis v2 §8.1 / §8.4.
*
* These tests exercise the boot-time env assertion in isolation: they
* snapshot `process.env`, stub `process.exit`, flip envs, call the
* assertion, and restore.
*/
import { assertProductionEnv } from "../../src/config/env";
describe("assertProductionEnv", () => {
const savedEnv = { ...process.env };
let exitSpy: jest.SpyInstance;
let errorSpy: jest.SpyInstance;
beforeEach(() => {
process.env = { ...savedEnv };
exitSpy = jest
.spyOn(process, "exit")
.mockImplementation(((code?: number | string | null) => {
throw new Error(`process.exit(${code})`);
}) as never);
errorSpy = jest.spyOn(console, "error").mockImplementation(() => {});
});
afterEach(() => {
exitSpy.mockRestore();
errorSpy.mockRestore();
process.env = { ...savedEnv };
});
it("does nothing when NODE_ENV is not production", () => {
process.env.NODE_ENV = "development";
expect(() => assertProductionEnv()).not.toThrow();
expect(exitSpy).not.toHaveBeenCalled();
});
it("fails fast when SESSION_SECRET is missing in production", () => {
process.env.NODE_ENV = "production";
delete process.env.SESSION_SECRET;
process.env.EVENT_BUS_HMAC_SECRET = "x".repeat(40);
process.env.CHAIN_138_RPC_URL = "https://rpc.example.com";
process.env.NOTARY_REGISTRY_ADDRESS =
"0x" + "a".repeat(40);
process.env.ORCHESTRATOR_PRIVATE_KEY = "0x" + "b".repeat(64);
process.env.DATABASE_URL = "postgres://localhost/db";
expect(() => assertProductionEnv()).toThrow("process.exit(1)");
const output = errorSpy.mock.calls.flat().join(" ");
expect(output).toMatch(/SESSION_SECRET/);
});
it("fails fast when SESSION_SECRET is the dev placeholder", () => {
process.env.NODE_ENV = "production";
process.env.SESSION_SECRET =
"dev-secret-change-in-production-min-32-chars";
process.env.EVENT_BUS_HMAC_SECRET = "x".repeat(40);
process.env.CHAIN_138_RPC_URL = "https://rpc.example.com";
process.env.NOTARY_REGISTRY_ADDRESS = "0x" + "a".repeat(40);
process.env.ORCHESTRATOR_PRIVATE_KEY = "0x" + "b".repeat(64);
process.env.DATABASE_URL = "postgres://localhost/db";
expect(() => assertProductionEnv()).toThrow("process.exit(1)");
expect(errorSpy.mock.calls.flat().join(" ")).toMatch(
/SESSION_SECRET.*dev placeholder/,
);
});
it("fails fast when NotaryRegistry envs are absent", () => {
process.env.NODE_ENV = "production";
process.env.SESSION_SECRET = "s".repeat(40);
process.env.EVENT_BUS_HMAC_SECRET = "x".repeat(40);
process.env.DATABASE_URL = "postgres://localhost/db";
delete process.env.CHAIN_138_RPC_URL;
delete process.env.NOTARY_REGISTRY_ADDRESS;
delete process.env.ORCHESTRATOR_PRIVATE_KEY;
expect(() => assertProductionEnv()).toThrow("process.exit(1)");
const output = errorSpy.mock.calls.flat().join(" ");
expect(output).toMatch(/NotaryRegistry/);
expect(output).toMatch(/CHAIN_138_RPC_URL/);
expect(output).toMatch(/NOTARY_REGISTRY_ADDRESS/);
expect(output).toMatch(/ORCHESTRATOR_PRIVATE_KEY/);
});
it("fails fast when EVENT_BUS_HMAC_SECRET falls back to dev placeholder", () => {
process.env.NODE_ENV = "production";
process.env.SESSION_SECRET = "s".repeat(40);
delete process.env.EVENT_BUS_HMAC_SECRET;
process.env.CHAIN_138_RPC_URL = "https://rpc.example.com";
process.env.NOTARY_REGISTRY_ADDRESS = "0x" + "a".repeat(40);
process.env.ORCHESTRATOR_PRIVATE_KEY = "0x" + "b".repeat(64);
process.env.DATABASE_URL = "postgres://localhost/db";
// eventSecret falls back to SESSION_SECRET which is valid, so this
// path should *succeed* — SESSION_SECRET is a legitimate source of
// signing material per the getSigningSecret fallback chain.
expect(() => assertProductionEnv()).not.toThrow();
});
it("passes when all envs are set to real values in production", () => {
process.env.NODE_ENV = "production";
process.env.SESSION_SECRET = "s".repeat(40);
process.env.EVENT_BUS_HMAC_SECRET = "e".repeat(40);
process.env.CHAIN_138_RPC_URL = "https://rpc.example.com";
process.env.NOTARY_REGISTRY_ADDRESS = "0x" + "a".repeat(40);
process.env.ORCHESTRATOR_PRIVATE_KEY = "0x" + "b".repeat(64);
process.env.DATABASE_URL = "postgres://localhost/db";
expect(() => assertProductionEnv()).not.toThrow();
expect(exitSpy).not.toHaveBeenCalled();
});
it("reports DATABASE_URL missing in production", () => {
process.env.NODE_ENV = "production";
process.env.SESSION_SECRET = "s".repeat(40);
process.env.EVENT_BUS_HMAC_SECRET = "e".repeat(40);
process.env.CHAIN_138_RPC_URL = "https://rpc.example.com";
process.env.NOTARY_REGISTRY_ADDRESS = "0x" + "a".repeat(40);
process.env.ORCHESTRATOR_PRIVATE_KEY = "0x" + "b".repeat(64);
delete process.env.DATABASE_URL;
expect(() => assertProductionEnv()).toThrow("process.exit(1)");
expect(errorSpy.mock.calls.flat().join(" ")).toMatch(/DATABASE_URL/);
});
});