be70f56657
Wave A (Phase 1) implements the M1 foundations for REQ-038, REQ-039, REQ-040: Monorepo scaffold (pnpm workspaces, TS strict, NodeNext): - apps/control-plane (Next.js App Router scaffold — Wave B adds routes) - apps/relay-agent (Go module scaffold — Wave D adds WebSocket + install) - packages/db, packages/secrets, packages/runtime, packages/config packages/db (REQ-038, REQ-039): - 0001_init.sql: tenants, users, tenant_memberships, targets, byom_endpoints, invitations, audit_log (append-only hash-chain), runtime_health (not audited) - RLS policies on all tenant-scoped tables + FORCE ROW LEVEL SECURITY - withTenant(tenantId, fn): SET LOCAL app.tenant_id + transaction - audit.ts: appendAudit with sha256(prev_hash || canonical(payload)) chain; AuditWriteHaltError on write failure (Edge 7 — halts + rolls back) - BEFORE INSERT trigger enforces chain integrity (G-006: per-tenant concurrent-write serialization documented; M3 mitigation noted) - create-db.ts: PGlite (dev/test) + pg Pool (prod) behind DbClient interface - pen-test scaffold: cross-tenant isolation (PGlite RLS limitation documented; prod RLS test runs at M1 review) - 12 tests, 98% coverage packages/secrets (REQ-040, G-005, G-010): - SecretProvider interface: get/put/delete + SecretRef + SecretValue (toString returns [REDACTED]; unwrap is the only read path) - AwsSecretsManagerProvider (prod): coreci/<tenantId>/<name>, KMS-backed - LocalEncryptedProvider (dev): AES-256-GCM, PBKDF2 from SECRET_MASTER_KEY_DEV - relay-token.ts: JWT HS256 sign/verify/issue (G-005 contract — locked so Wave B + Wave D parallelize without blocking) - 24 tests (14 provider + 10 relay-token) packages/runtime (G-002, G-003): - Trigger.dev bootstrap (initRuntime) — pre-investment for M3 (G-003) - runtimeHealthCheck task: writes to runtime_health, NOT audit_log (G-002) - 6 tests packages/config (G-010): - Two-tier credential taxonomy: infra env vars (tier a) vs tenant creds (SecretProvider only, tier b). PO's 'no env vars' applies to tenant creds. Coverage: db 98%, secrets/runtime/config typecheck clean. All 45 tests passing. Go relay-agent builds. ---ci--- phase: 1 milestone: v0.1 status: verify ---/ci---
35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
import { describe, it, expect, beforeEach } from "vitest";
|
|
import { loadConfig } from "../src/index.js";
|
|
|
|
describe("@coreci/config", () => {
|
|
beforeEach(() => {
|
|
// Clear relevant env vars between tests.
|
|
delete process.env.DATABASE_URL;
|
|
delete process.env.WORKOS_API_KEY;
|
|
delete process.env.AWS_REGION;
|
|
delete process.env.SECRET_MASTER_KEY_DEV;
|
|
delete process.env.TRIGGER_API_KEY;
|
|
process.env.RELAY_TOKEN_SIGNING_KEY = "test-signing-key";
|
|
});
|
|
|
|
it("loads dev defaults (pglite, local-encrypted)", () => {
|
|
const cfg = loadConfig("development");
|
|
expect(cfg.env).toBe("development");
|
|
expect(cfg.database.mode).toBe("pglite");
|
|
expect(cfg.secrets.provider).toBe("local-encrypted");
|
|
expect(cfg.region).toBe("us-east-1");
|
|
});
|
|
|
|
it("switches to pg + aws-sm in production with DATABASE_URL", () => {
|
|
process.env.DATABASE_URL = "postgres://user:pass@host:5432/db";
|
|
const cfg = loadConfig("production");
|
|
expect(cfg.database.mode).toBe("pg");
|
|
expect(cfg.database.url).toBe("postgres://user:pass@host:5432/db");
|
|
expect(cfg.secrets.provider).toBe("aws-sm");
|
|
});
|
|
|
|
it("throws if RELAY_TOKEN_SIGNING_KEY is missing", () => {
|
|
delete process.env.RELAY_TOKEN_SIGNING_KEY;
|
|
expect(() => loadConfig("development")).toThrow("RELAY_TOKEN_SIGNING_KEY");
|
|
});
|
|
}); |