Reorganize repo structure and standards references

This commit is contained in:
david committed 2026-06-29 05:03:42 +02:00
1 parent 3cb93a81be
commit be2054274d
5885 files changed
+2588 -195

No files matched your search

@@ -0,0 +1,121 @@
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { describe, expect, test } from "vitest";
import { getEnvVariableDefinition, getRequiredEnvVariableNames, groupEnvVariablesByClassification } from "./index.js";
const envVarsDocument = readFileSync(resolve(process.cwd(), "docs/env-vars.md"), "utf8");
describe("env catalog", () => {
test("looks up dynamic SITE_KEY_* definitions without requiring a concrete catalog entry", () => {
expect(getEnvVariableDefinition("SITE_KEY_BOOKING")?.dynamicPrefix).toBe("SITE_KEY_");
expect(getEnvVariableDefinition("SITE_KEY_COMMUNITY")?.name).toBe("SITE_KEY_*");
});
test("classifies worker Redis keys and opt-in toggle", () => {
expect(getEnvVariableDefinition("WORKER_ENABLED")).toMatchObject({
classification: "optional-provider",
targets: ["worker"],
source: "code-and-example",
defaultValue: "false",
});
expect(getEnvVariableDefinition("BULLMQ_REDIS_URL")).toMatchObject({
classification: "optional-provider",
targets: ["web", "api", "worker"],
source: "code-and-example",
});
expect(getEnvVariableDefinition("REDIS_URL")).toMatchObject({
classification: "optional-provider",
targets: ["web", "api", "worker"],
source: "code",
});
expect(getEnvVariableDefinition("EMAIL_QUEUE_NAME")).toMatchObject({
classification: "optional-provider",
targets: ["worker"],
source: "code",
defaultValue: "toolctrl.email",
});
expect(getEnvVariableDefinition("WORKFLOW_QUEUE_NAME")).toMatchObject({
classification: "optional-provider",
targets: ["worker"],
source: "code",
defaultValue: "toolctrl.workflows",
});
expect(getEnvVariableDefinition("WORKER_QUEUE_GROUP")?.description).toContain("plugin");
expect(getEnvVariableDefinition("WORKER_CONCURRENCY_PLUGIN")).toMatchObject({
classification: "optional-provider",
targets: ["worker"],
source: "code-and-example",
defaultValue: "5",
});
expect(getEnvVariableDefinition("WORKER_REDIS_POOL_SIZE")?.notes).toContain("plugin=4");
});
test("keeps active Crisp usage out of deprecated-only classification", () => {
expect(getEnvVariableDefinition("CRISP_CHAT_WEBSITE_ID")).toMatchObject({
classification: "optional-provider",
targets: ["web"],
source: "code-and-example",
});
});
test("catalogs active operational runtime toggles", () => {
expect(getEnvVariableDefinition("TOOLCTRL_API_MAINTENANCE_MODE")).toMatchObject({
classification: "production-only",
targets: ["api"],
source: "code",
});
expect(getEnvVariableDefinition("WEB_BUILD_DIRECTORY")).toMatchObject({
classification: "production-only",
targets: ["web"],
source: "code",
});
});
test("groups required production keys without optional worker fallback keys", () => {
expect(getRequiredEnvVariableNames({ target: "worker", nodeEnv: "production" })).toEqual(
expect.arrayContaining(["APP_NAME", "DATABASE_URL"])
);
expect(getRequiredEnvVariableNames({ target: "worker", nodeEnv: "production" })).not.toEqual(
expect.arrayContaining(["WORKER_ENABLED", "BULLMQ_REDIS_URL", "REDIS_URL", "SITE_KEY_*"])
);
expect(groupEnvVariablesByClassification()["optional-provider"].map((definition) => definition.name)).toEqual(
expect.arrayContaining(["WORKER_ENABLED", "BULLMQ_REDIS_URL", "REDIS_URL", "CRISP_CHAT_WEBSITE_ID", "SITE_KEY_*"])
);
});
test("documents production-required and active provider keys in env-vars", () => {
const requiredKeys = new Set([
...getRequiredEnvVariableNames({ target: "web", nodeEnv: "production" }),
...getRequiredEnvVariableNames({ target: "api", nodeEnv: "production" }),
...getRequiredEnvVariableNames({ target: "worker", nodeEnv: "production" }),
]);
for (const key of requiredKeys) {
expect(envVarsDocument, `docs/env-vars.md missing required key ${key}`).toContain(`\`${key}\``);
}
for (const key of [
"STRIPE_SK",
"STRIPE_WEBHOOK_SIGNING_SECRET",
"PORTAL_SERVER_URL",
"PORTAL_SERVER_FLY_TOKEN",
"IMPORT_QUEUE_ENABLED",
"IMPORT_QUEUE_RUNTIME_READY",
]) {
expect(envVarsDocument, `docs/env-vars.md missing active optional key ${key}`).toContain(`\`${key}\``);
}
});
test("targets provider keys consumed by web config to the web runtime", () => {
for (const key of ["STRIPE_WEBHOOK_SIGNING_SECRET", "MAILJET_API_KEY", "MAILJET_SECRET_KEY", "MAILJET_FROM_EMAIL", "MAILJET_FROM_NAME"]) {
expect(getEnvVariableDefinition(key)?.targets, `${key} must include web because loadWebConfig consumes it`).toContain("web");
}
});
});