Files
clean-architecture-frontend…/tests/unit/feature-override-diagnostics.test.ts
T
DongHyeonkaandClaude Opus 5.5 b685b616e4 fix(bootstrap): report FEATURE_OVERRIDES keys the build does not declare (09-09)
A misspelt kill-switch key was ignored without a trace, so the feature kept
running. Boot now records feature.override.unknown once per such key, and
release admission lists them as warnings in its record without refusing the
artifact (a shared document may still name another build's features).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 23:25:24 +09:00

124 lines
4.1 KiB
TypeScript

import { spawnSync } from "node:child_process";
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
import { createRuntimeAdapters } from "../../src/bootstrap/runtime-adapters.ts";
import { COMPILED_PRODUCT_FEATURE_IDS } from "../../src/features/installed-product-manifest.ts";
import { generateRuntimeConfig } from "../../scripts/generate-runtime-config.ts";
type Runtime = Parameters<typeof createRuntimeAdapters>[0]["runtime"];
// 09-09. An override key this build does not declare stays inert (one runtime
// document may serve several builds), but a misspelt kill switch used to leave
// the feature running without a trace.
const MISSPELT = "reference-featrue";
function runtimeWith(overrides: Readonly<Record<string, "DISABLED">>): Runtime {
return {
config: {
APP_ENV: "local",
API_BASE_URL: "http://localhost:8080",
TELEMETRY_ENABLED: false,
AUTH_MODE: "demo",
REQUEST_TIMEOUT_MS: 1000,
MAX_RETRY_ATTEMPTS: 0,
RELEASE_MANIFEST_URL: "/release-manifest.json",
CONFIG_SCHEMA_VERSION: "2.0",
CAPABILITY_OVERRIDES: {
REALTIME: "DEFAULT",
WEB_WORKER: "DEFAULT",
SERVICE_WORKER: "DEFAULT",
OFFLINE_COMMANDS: "DEFAULT",
},
FEATURE_OVERRIDES: overrides,
},
configSchema: "V2",
build: {
buildId: "build-a",
commitSha: "abc123",
routerBasePath: "/",
runtimeConfigUrl: "/config.json",
},
validationDurationMs: 0,
};
}
const release = {
schemaVersion: 2,
appVersion: "0.1.0",
buildId: "build-a",
commitSha: "abc123",
configSchemaVersion: "2.0",
contractSet: {
setAlgorithm: "CA_CONTRACT_SET_V1",
setDigest: `sha256:${"0".repeat(64)}`,
packages: [],
},
assetManifestHash: "hash-a",
releaseId: "release-a",
builtAt: "2026-07-25T00:00:00Z",
routeChunks: {},
} as Parameters<typeof createRuntimeAdapters>[0]["release"];
describe("unknown feature override keys (09-09)", () => {
it("records one diagnostic per key the build does not declare", async () => {
const declared = COMPILED_PRODUCT_FEATURE_IDS[0];
const adapters = await createRuntimeAdapters({
runtime: runtimeWith({
[MISSPELT]: "DISABLED",
...(declared === undefined ? {} : { [declared]: "DISABLED" }),
}),
release,
host: {},
});
try {
const unknown = adapters.outputPorts.diagnostics
.entries()
.filter((entry) => entry.eventId === "feature.override.unknown");
expect(unknown).toEqual([
expect.objectContaining({
level: "warn",
context: { feature_override_key: MISSPELT },
}),
]);
} finally {
adapters.infrastructure.dispose();
}
});
it("warns in the admission record without refusing the artifact", async () => {
const root = await mkdtemp(path.join(tmpdir(), "admission-override-"));
try {
const config = await generateRuntimeConfig("local", {});
await mkdir(path.join(root, "dist"), { recursive: true });
await writeFile(
path.join(root, "dist/config.json"),
JSON.stringify({ ...config, FEATURE_OVERRIDES: { [MISSPELT]: "DISABLED" } }),
);
const result = spawnSync(
process.execPath,
[path.resolve("scripts/check-release-admission.ts")],
{
cwd: root,
encoding: "utf8",
env: { ...process.env, APP_PROFILE: "local", RELEASE_TARGET: "local" },
},
);
expect(result.status, result.stderr).toBe(0);
expect(result.stderr).toContain(MISSPELT);
const record = JSON.parse(
await readFile(path.join(root, "artifacts/release/deployment-admission.json"), "utf8"),
) as { status: string; warnings: { field: string; reason: string }[] };
expect(record.status).toBe("ADMITTED");
expect(record.warnings).toEqual([
expect.objectContaining({ field: `FEATURE_OVERRIDES.${MISSPELT}` }),
]);
} finally {
await rm(root, { recursive: true, force: true });
}
});
});