Files
tech-log-frontend/tests/unit/registry-governance.test.ts
T
DongHyeonka c80320dfc7 chore: sync the frontend template from ebea300 to af3d8e6
Carries 359 template commits, tag v0.2.0 plus one documentation commit: the
generator-built feature index with its app, bounded-context and feature
declarations, the src/platform kernel and scale tooling, the 2026-09-24 src
review fixes, and the 2026-09-25 maturity review round with its CHANGELOG
[보안]/[계약] rows. 691 of the 824 template paths are applied, 85 of them
merged with product changes; 127 are not carried.

Product identity is unchanged: name, version 0.1.0, routes, design and the
TechLog domain.

Three decisions worth naming. TechLog stays composed directly, as the last
two syncs recorded; its directory carries a NOT_INSTALLED marker that says so,
and every installed-* composer takes the template's projection with TechLog
added on top. The reference sample is no longer installed: the template now
installs a feature only through feature-module.ts and context-routes.ts,
which load the screens this product deleted, so its three operations, six
schemas and one topic leave the registries, recorded as registry change
evidence. And AppRouter mounts the platform and TechLog routes only; the
template's bounded-context route gateway waits for a generator-installed
feature.

Required fixes: readSubject on the BFF session owner (without it every HTTP
Studio session would close as integration-failed), zod through the facade in
nine TechLog files, noUnusedLocals, and public/config.json written out to
match the local profile. Derived baselines were recomputed after reproducing
both sides' values: CI contract 101 commands / 106 references / 141
artifacts, gate shape c9adcf85; registry approval 2dc6c3a3; the runtime
config schema baseline equals the schema at 8210d48.

Verified here: types, lint, architecture, adapter inventory, CI contract,
i18n, design system, diagnostics, browser security, dev release manifest,
TechLog contract and build pass; 220 component, 155 integration, 15
contract, 418 TechLog, 43 reference-feature, 18 recipe and 46
release-coherence tests pass, and 2381 of 2383 unit tests. Reproduced at
8210d48 first and unchanged: check:registries (byte-identical),
test:runtime-schema, verify:documentation. Brought by the template and
escalated rather than suppressed: check:request-fanout on TechLog's cursor
pagination, check:remediation-ledger (fails upstream too), the shared-chunk
hash test, and the registry-dependent sample removal and second-feature
tests. Playwright suites were not run.

Full record, the five open questions and the follow-ups in
docs/operations/template-sync-2026-09-29.md.

(cherry picked from commit b2170cf265dea45dc9cc05d3c61e627e97f31cdb)
2026-11-12 08:28:54 +09:00

378 lines
12 KiB
TypeScript

import { spawnSync } from "node:child_process";
import { mkdtemp, readFile, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
import {
diffRegistrySnapshots,
validateBreakingEvidence,
verifyRegistryBaselineApproval,
} from "../../scripts/lib/registry-compatibility.ts";
type RegistryDefinition = Readonly<{
registryId: string;
owner: string;
requiredFields: string[];
fieldTypes: Record<string, string>;
path: string;
exportName: string;
rowsPath?: string;
rowKeyFields?: string[];
uniqueFields?: string[];
uniqueFieldSets?: string[][];
snapshotProjection?: {
singletonRowKey: string;
canonicalArrayKeyFields: Record<string, string[]>;
};
consumers?: Array<{ path: string; token: string }>;
breakingFields?: string[];
}>;
describe("registry governance manifest", () => {
it("declares eleven typed, single-owner executable registries", async () => {
const governance = JSON.parse(
await readFile("config/contracts/registry-governance.json", "utf8"),
);
const registries = governance.registries as RegistryDefinition[];
expect(governance.registries).toHaveLength(11);
expect(new Set(registries.map((entry) => entry.registryId)).size).toBe(
11,
);
expect(registries.every((entry) => entry.owner)).toBe(true);
expect(
registries.every(
(entry) =>
Array.isArray(entry.requiredFields) &&
entry.requiredFields.length > 0 &&
entry.fieldTypes &&
Object.keys(entry.fieldTypes).length > 0,
),
).toBe(true);
});
it("governs the installed invalidation graph and wire versions at their real exports", async () => {
const governance = JSON.parse(
await readFile("config/contracts/registry-governance.json", "utf8"),
) as { registries: RegistryDefinition[] };
const byId = new Map(
governance.registries.map((registry) => [registry.registryId, registry]),
);
expect(byId.get("FE-REG-QUERY-INVALIDATION")).toMatchObject({
path: "src/features/installed-feature-contracts.ts",
exportName: "INVALIDATION_REGISTRY",
rowsPath: "edges",
rowKeyFields: [
"topicId",
"namespace.namespaceId",
"namespace.namespaceVersion",
],
uniqueFieldSets: [
[
"topicId",
"namespace.namespaceId",
"namespace.namespaceVersion",
],
],
snapshotProjection: {
singletonRowKey: "invalidation-graph",
canonicalArrayKeyFields: {
topics: ["$value"],
namespaces: ["namespaceId", "namespaceVersion"],
edges: [
"topicId",
"namespace.namespaceId",
"namespace.namespaceVersion",
],
},
},
consumers: [
{
path: "src/bootstrap/runtime-adapters.ts",
token: "indexInvalidationRegistry(INVALIDATION_REGISTRY)",
},
],
breakingFields: ["topics", "namespaces", "edges"],
});
expect(byId.get("FE-REG-QUERY-INVALIDATION-TOPIC-VERSION")).toMatchObject({
path: "src/features/installed-feature-contracts.ts",
exportName: "INVALIDATION_TOPIC_VERSIONS",
rowKeyFields: ["topicId"],
uniqueFields: ["topicId"],
consumers: [
{
path: "src/bootstrap/runtime-adapters.ts",
token: "indexInvalidationTopicVersions(",
},
],
breakingFields: ["topicId", "topicVersion"],
});
});
it("projects graph and array exports into deterministic governed rows", async () => {
const directory = await mkdtemp(
path.join(tmpdir(), "registry-governance-projection-"),
);
const artifact = path.join(directory, "registries.json");
try {
const result = spawnSync(
process.execPath,
[
"scripts/check-registries.ts",
"--governance",
"tests/fixtures/registry/invalidation/governance.json",
"--artifact",
artifact,
"--no-baseline",
],
{ encoding: "utf8" },
);
expect(result.status, result.stderr).toBe(0);
const report = JSON.parse(await readFile(artifact, "utf8")) as {
registries: Array<{
registryId: string;
rows: Record<string, Record<string, unknown>>;
}>;
};
expect(
report.registries.find(
(registry) => registry.registryId === "FIXTURE-INVALIDATION-EDGES",
)?.rows,
).toEqual({
"invalidation-graph": {
topics: ["orders", "qinv.fixture.changed"],
namespaces: [
{ namespaceId: "orders", namespaceVersion: 1 },
{ namespaceId: "qinv.fixture.changed", namespaceVersion: 1 },
],
edges: [
{
topicId: "orders",
namespace: {
namespaceId: "qinv.fixture.changed",
namespaceVersion: 1,
},
},
{
topicId: "qinv.fixture.changed",
namespace: { namespaceId: "orders", namespaceVersion: 1 },
},
],
},
});
expect(
report.registries.find(
(registry) => registry.registryId === "FIXTURE-INVALIDATION-VERSIONS",
)?.rows,
).toHaveProperty('["qinv.fixture.changed"]');
} finally {
await rm(directory, { recursive: true, force: true });
}
});
it("requires explicit evidence for post-baseline graph and version drift", async () => {
const directory = await mkdtemp(
path.join(tmpdir(), "registry-governance-tamper-"),
);
const artifact = path.join(directory, "registries.json");
try {
const result = spawnSync(
process.execPath,
[
"scripts/check-registries.ts",
"--governance",
"tests/fixtures/registry/invalidation/governance.json",
"--artifact",
artifact,
"--no-baseline",
],
{ encoding: "utf8" },
);
expect(result.status, result.stderr).toBe(0);
const report = JSON.parse(await readFile(artifact, "utf8")) as {
registries: Array<{
registryId: string;
contract: Record<string, unknown>;
rows: Record<string, Record<string, unknown>>;
}>;
};
const baseline = { schemaVersion: 2, registries: report.registries };
expect(
baseline.registries.find(
(registry) => registry.registryId === "FIXTURE-INVALIDATION-EDGES",
)?.rows["invalidation-graph"],
).toBeDefined();
const tamperCases = [
{
name: "topic",
registryId: "FIXTURE-INVALIDATION-EDGES",
field: "topics",
apply(snapshot: typeof baseline) {
const graph = snapshot.registries.find(
(registry) => registry.registryId === this.registryId,
)?.rows["invalidation-graph"];
(graph?.topics as string[])[0] = "tampered-topic";
},
},
{
name: "namespace",
registryId: "FIXTURE-INVALIDATION-EDGES",
field: "namespaces",
apply(snapshot: typeof baseline) {
const graph = snapshot.registries.find(
(registry) => registry.registryId === this.registryId,
)?.rows["invalidation-graph"];
const namespaces = graph?.namespaces as Array<{
namespaceId: string;
}>;
namespaces[0]!.namespaceId = "tampered-namespace";
},
},
{
name: "edge",
registryId: "FIXTURE-INVALIDATION-EDGES",
field: "edges",
apply(snapshot: typeof baseline) {
const graph = snapshot.registries.find(
(registry) => registry.registryId === this.registryId,
)?.rows["invalidation-graph"];
const edges = graph?.edges as Array<{ topicId: string }>;
edges[0]!.topicId = "tampered-edge";
},
},
{
name: "version",
registryId: "FIXTURE-INVALIDATION-VERSIONS",
field: "topicVersion",
apply(snapshot: typeof baseline) {
const versions = snapshot.registries.find(
(registry) => registry.registryId === this.registryId,
)?.rows;
const firstVersion = versions?.[Object.keys(versions)[0] ?? ""];
if (!firstVersion) throw new Error("version fixture row missing");
firstVersion.topicVersion = 2;
},
},
];
for (const tamperCase of tamperCases) {
const current = structuredClone(baseline);
tamperCase.apply(current);
const diff = diffRegistrySnapshots(baseline, current);
expect(diff.impact, tamperCase.name).toBe("breaking");
expect(
diff.changes.some((change) => change.kind === "registry-added"),
tamperCase.name,
).toBe(false);
const breakingChanges = diff.changes.filter(
(change) => change.impact === "breaking",
);
expect(breakingChanges, tamperCase.name).toEqual(
expect.arrayContaining([
expect.objectContaining({
registryId: tamperCase.registryId,
field: tamperCase.field,
}),
]),
);
expect(
validateBreakingEvidence(diff, { changes: [] }).passed,
tamperCase.name,
).toBe(false);
expect(
validateBreakingEvidence(diff, {
changes: breakingChanges.map((change) => ({
changeId: change.changeId,
versionBump: "2",
migration: `migrate ${tamperCase.name}`,
compatibilityWindow: "one release",
rollback: `restore ${tamperCase.name} baseline`,
owner: "fixture-owner",
})),
}).passed,
tamperCase.name,
).toBe(true);
}
} finally {
await rm(directory, { recursive: true, force: true });
}
});
it("pins the full invalidation graph and versions in the approved repository baseline", async () => {
const baseline = JSON.parse(
await readFile("config/contracts/registry-baseline.json", "utf8"),
) as {
schemaVersion: number;
registries: Array<{
registryId: string;
rows: Record<string, Record<string, unknown>>;
}>;
};
const approval = JSON.parse(
await readFile(
"config/contracts/registry-baseline.approval.json",
"utf8",
),
) as Record<string, unknown>;
expect(verifyRegistryBaselineApproval(baseline, approval).passed).toBe(true);
expect(baseline.registries).toHaveLength(11);
const graph = baseline.registries.find(
(registry) => registry.registryId === "FE-REG-QUERY-INVALIDATION",
);
const versions = baseline.registries.find(
(registry) =>
registry.registryId ===
"FE-REG-QUERY-INVALIDATION-TOPIC-VERSION",
);
expect(graph?.rows["invalidation-graph"]).toMatchObject({
topics: expect.any(Array),
namespaces: expect.any(Array),
edges: expect.any(Array),
});
expect(versions?.rows).toBeDefined();
// Who approved and why, not this template's wording: a project that
// re-baselines with update:registry-baseline writes its own (D-13).
expect(approval).toMatchObject({
owner: expect.stringMatching(/\S/u),
reason: expect.stringMatching(/\S/u),
});
});
it("rejects duplicate composite invalidation edges after projection", async () => {
const directory = await mkdtemp(
path.join(tmpdir(), "registry-governance-duplicate-"),
);
const artifact = path.join(directory, "registries.json");
try {
const result = spawnSync(
process.execPath,
[
"scripts/check-registries.ts",
"--governance",
"tests/fixtures/registry/invalidation/duplicate-governance.json",
"--artifact",
artifact,
"--no-baseline",
],
{ encoding: "utf8" },
);
expect(result.status).toBe(1);
const report = JSON.parse(await readFile(artifact, "utf8")) as {
failures: string[];
};
expect(report.failures).toEqual([
expect.stringContaining(
"duplicates topicId+namespace.namespaceId+namespace.namespaceVersion",
),
]);
} finally {
await rm(directory, { recursive: true, force: true });
}
});
});