Files
Ekklesia/tests/infrastructure.test.ts
T
ekklesia 2465d9c1f7
CI / verify (push) Successful in 24s
CI / infrastructure-smoke (push) Successful in 19s
runner fix
2026-07-13 20:19:30 -05:00

135 lines
5.2 KiB
TypeScript

import { readFile } from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { describe, expect, it } from "vitest";
import { parse } from "yaml";
interface ComposeService {
environment?: Record<string, string>;
healthcheck?: unknown;
image?: string;
ports?: string[];
volumes?: string[];
}
interface ComposeDocument {
services?: Record<string, ComposeService>;
volumes?: Record<string, unknown>;
}
interface PackageDocument {
scripts?: Record<string, string>;
}
interface TurboDocument {
tasks?: Record<string, unknown>;
}
interface WorkspaceDocument {
packages?: string[];
}
const repositoryRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
describe("development infrastructure", () => {
it("has valid, local-only, version-pinned Compose services", async () => {
const source = await readFile(
path.join(repositoryRoot, "infrastructure", "compose.yaml"),
"utf8",
);
const compose = parse(source) as ComposeDocument;
const postgres = compose.services?.postgres;
const objectStorage = compose.services?.["object-storage"];
expect(postgres?.image).toBe("postgres:18.4-alpine3.24");
expect(objectStorage?.image).toBe("chrislusf/seaweedfs:4.28");
expect(postgres?.healthcheck).toBeDefined();
expect(objectStorage?.healthcheck).toBeDefined();
expect(postgres?.environment?.POSTGRES_INITDB_ARGS).toContain("--auth-host=scram-sha-256");
for (const service of [postgres, objectStorage]) {
expect(service).toBeDefined();
expect(service?.image).not.toMatch(/:latest$/u);
expect(service?.ports?.every((port) => port.startsWith("127.0.0.1:"))).toBe(true);
expect(service?.volumes?.length).toBeGreaterThan(0);
}
expect(compose.volumes).toHaveProperty("postgres-data");
expect(compose.volumes).toHaveProperty("object-storage-data");
});
it("has a parseable CI workflow with static and live infrastructure gates", async () => {
const source = await readFile(
path.join(repositoryRoot, ".github", "workflows", "ci.yml"),
"utf8",
);
const workflow = parse(source) as {
jobs?: {
"infrastructure-smoke"?: { steps?: Array<{ run?: string }> };
verify?: { steps?: Array<{ run?: string }> };
};
};
const commands = workflow.jobs?.verify?.steps?.flatMap((step) => step.run ?? []) ?? [];
const infrastructureCommands =
workflow.jobs?.["infrastructure-smoke"]?.steps?.flatMap((step) => step.run ?? []) ?? [];
expect(workflow.jobs?.verify).toBeDefined();
expect(commands).toContain("pnpm install --frozen-lockfile");
expect(commands).toContain("pnpm ci:verify");
expect(infrastructureCommands).toContain("bash scripts/smoke-infrastructure.sh");
});
it("routes containerized S3 smoke checks through the isolated Compose network", async () => {
const source = await readFile(
path.join(repositoryRoot, "scripts", "smoke-infrastructure.sh"),
"utf8",
);
expect(source).toContain("[[ -f /.dockerenv ]]");
expect(source).toContain(`object_storage_container="$("\${compose[@]}" ps -q object-storage)"`);
expect(source).toContain("docker inspect");
expect(source).toContain('docker network connect "$compose_network" "$current_container"');
expect(source).toContain('docker network disconnect "$compose_network" "$current_container"');
expect(source).toContain('s3_endpoint="http://object-storage:8333"');
expect(source).toContain('s3_endpoint="http://127.0.0.1:$s3_port"');
expect(source).not.toContain("0.0.0.0:${S3_PORT");
expect(source.indexOf("docker network disconnect")).toBeLessThan(
source.indexOf(`"\${compose[@]}" down`),
);
});
it("includes every official platform layer in the workspace", async () => {
const source = await readFile(path.join(repositoryRoot, "pnpm-workspace.yaml"), "utf8");
const workspace = parse(source) as WorkspaceDocument;
expect(workspace.packages).toEqual(
expect.arrayContaining([
"apps/*",
"builders/*",
"core",
"modules/*",
"surfaces/*",
"templates/*",
]),
);
});
it("dispatches root and future package quality tasks through Turborepo", async () => {
const packageSource = await readFile(path.join(repositoryRoot, "package.json"), "utf8");
const turboSource = await readFile(path.join(repositoryRoot, "turbo.json"), "utf8");
const packageDocument = JSON.parse(packageSource) as PackageDocument;
const turboDocument = JSON.parse(turboSource) as TurboDocument;
expect(packageDocument.scripts?.lint).toBe("turbo run lint lint:root");
expect(packageDocument.scripts?.test).toBe("turbo run test test:root");
expect(packageDocument.scripts?.typecheck).toBe("turbo run typecheck typecheck:root");
expect(packageDocument.scripts?.["modules:validate"]).toBe(
"turbo run build && node core/dist/cli/validate-modules.js",
);
expect(packageDocument.scripts?.verify).toContain("pnpm modules:validate");
expect(turboDocument.tasks).toHaveProperty("//#lint:root");
expect(turboDocument.tasks).toHaveProperty("//#test:root");
expect(turboDocument.tasks).toHaveProperty("//#typecheck:root");
});
});