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 at8210d48. 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 at8210d48first 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)
272 lines
9.6 KiB
TypeScript
272 lines
9.6 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
|
import { mkdir, mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
DEPLOYMENT_TARGETS,
|
|
findAdmissionViolations,
|
|
isDeploymentTarget,
|
|
type AdmissionInput,
|
|
} from "../../src/contracts/deployment-admission.ts";
|
|
import { ENV_REGISTRY, getBuildConfig } from "../../src/contracts/env.ts";
|
|
import { runtimeConfigV2ArtifactSchema } from "../../src/contracts/release-artifacts.ts";
|
|
import { generateRuntimeConfig } from "../../scripts/generate-runtime-config.ts";
|
|
|
|
const PRODUCTION_ARTIFACT: AdmissionInput = Object.freeze({
|
|
APP_ENV: "production",
|
|
API_BASE_URL: "https://api.example.com/",
|
|
REQUEST_TIMEOUT_MS: 10_000,
|
|
MAX_RETRY_ATTEMPTS: 2,
|
|
TELEMETRY_ENABLED: false,
|
|
AUTH_MODE: "external",
|
|
CONFIG_SCHEMA_VERSION: "2.0",
|
|
RELEASE_MANIFEST_URL: "/release-manifest.json",
|
|
BUILD_ID: "20260815.42",
|
|
RELEASE_ID: "r-2026.08.15-1",
|
|
CAPABILITY_OVERRIDES: Object.freeze({
|
|
REALTIME: "DEFAULT",
|
|
WEB_WORKER: "DEFAULT",
|
|
SERVICE_WORKER: "DEFAULT",
|
|
OFFLINE_COMMANDS: "DEFAULT",
|
|
}),
|
|
}) as AdmissionInput;
|
|
|
|
const LOCAL_ARTIFACT: AdmissionInput = Object.freeze({
|
|
...PRODUCTION_ARTIFACT,
|
|
APP_ENV: "local",
|
|
API_BASE_URL: "http://localhost:8080/",
|
|
AUTH_MODE: "demo",
|
|
BUILD_ID: "local-build",
|
|
RELEASE_ID: "local-release",
|
|
}) as AdmissionInput;
|
|
|
|
describe("deployment admission", () => {
|
|
it("admits an artifact only to the environment it declares", () => {
|
|
expect(findAdmissionViolations("production", PRODUCTION_ARTIFACT)).toEqual([]);
|
|
expect(findAdmissionViolations("local", LOCAL_ARTIFACT)).toEqual([]);
|
|
});
|
|
|
|
it("refuses the exact local build that release coherence used to approve", () => {
|
|
// The review's strongest reproduction: FE-GATE-015 passed on a build whose
|
|
// runtime document was APP_ENV=local / AUTH_MODE=demo / loopback API. Each
|
|
// of those is now an independent refusal, so fixing one does not admit it.
|
|
const violations = findAdmissionViolations("production", LOCAL_ARTIFACT);
|
|
const fields = violations.map((violation) => violation.field);
|
|
expect(fields).toContain("APP_ENV");
|
|
expect(fields).toContain("AUTH_MODE");
|
|
expect(fields).toContain("API_BASE_URL");
|
|
expect(fields).toContain("BUILD_ID");
|
|
expect(fields).toContain("RELEASE_ID");
|
|
});
|
|
|
|
it("refuses endpoints a browser on the public internet cannot reach", () => {
|
|
for (const host of [
|
|
"http://api.example.com/",
|
|
"https://localhost/",
|
|
"https://127.0.0.1/",
|
|
"https://10.0.0.5/",
|
|
"https://192.168.1.10/",
|
|
"https://172.16.4.4/",
|
|
"https://169.254.169.254/",
|
|
"https://[::1]/",
|
|
]) {
|
|
const violations = findAdmissionViolations("production", {
|
|
...PRODUCTION_ARTIFACT,
|
|
API_BASE_URL: host,
|
|
} as AdmissionInput);
|
|
expect(violations.map((violation) => violation.field), host).toContain(
|
|
"API_BASE_URL",
|
|
);
|
|
}
|
|
});
|
|
|
|
it("refuses IPv6, mapped, CGNAT, 0/8 and internal-name hosts (Q-6.7-10)", () => {
|
|
for (const host of [
|
|
"https://[::ffff:127.0.0.1]/",
|
|
"https://[::ffff:8.8.8.8]/",
|
|
"https://[fd00::1]/",
|
|
"https://[fc12:3456::1]/",
|
|
"https://[fe80::1]/",
|
|
"https://[febf::1]/",
|
|
"https://[0:0:0:0:0:0:0:1]/",
|
|
"https://100.64.0.1/",
|
|
"https://100.127.255.254/",
|
|
"https://0.1.2.3/",
|
|
"https://api.internal/",
|
|
"https://printer.local/",
|
|
"https://localhost./",
|
|
"https://api.internal./",
|
|
]) {
|
|
const violations = findAdmissionViolations("production", {
|
|
...PRODUCTION_ARTIFACT,
|
|
API_BASE_URL: host,
|
|
} as AdmissionInput);
|
|
expect(violations.map((violation) => violation.field), host).toContain(
|
|
"API_BASE_URL",
|
|
);
|
|
}
|
|
});
|
|
|
|
it("permits a routable public host", () => {
|
|
for (const host of [
|
|
"https://api.172.16.example.com/",
|
|
"https://100.128.0.1/",
|
|
"https://100.63.255.255/",
|
|
"https://[2001:db8::1]/",
|
|
"https://[fec0::1]/",
|
|
"https://internal.example.com/",
|
|
"https://local.example.com/",
|
|
]) {
|
|
expect(
|
|
findAdmissionViolations("production", {
|
|
...PRODUCTION_ARTIFACT,
|
|
API_BASE_URL: host,
|
|
} as AdmissionInput),
|
|
host,
|
|
).toEqual([]);
|
|
}
|
|
});
|
|
|
|
it("refuses a placeholder identity on a public target", () => {
|
|
for (const buildId of ["local-build", "local", "dev", "unknown", ""]) {
|
|
const violations = findAdmissionViolations("production", {
|
|
...PRODUCTION_ARTIFACT,
|
|
BUILD_ID: buildId,
|
|
} as AdmissionInput);
|
|
expect(violations.map((violation) => violation.field), buildId).toContain(
|
|
"BUILD_ID",
|
|
);
|
|
}
|
|
});
|
|
|
|
it("treats an unknown target as not a target at all", () => {
|
|
for (const value of ["prod", "PRODUCTION", "", undefined, null, 1]) {
|
|
expect(isDeploymentTarget(value), String(value)).toBe(false);
|
|
}
|
|
for (const target of DEPLOYMENT_TARGETS) {
|
|
expect(isDeploymentTarget(target)).toBe(true);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("runtime config profiles", () => {
|
|
it("ships one valid profile per deployment target", async () => {
|
|
const files = (await readdir("config/runtime")).sort();
|
|
expect(files).toEqual(
|
|
[...DEPLOYMENT_TARGETS].map((target) => `${target}.json`).sort(),
|
|
);
|
|
for (const target of DEPLOYMENT_TARGETS) {
|
|
const source: unknown = JSON.parse(
|
|
await readFile(path.join("config/runtime", `${target}.json`), "utf8"),
|
|
);
|
|
const parsed = runtimeConfigV2ArtifactSchema.safeParse({
|
|
...(source as Record<string, unknown>),
|
|
BUILD_ID: "20260815.42",
|
|
RELEASE_ID: "r-1",
|
|
});
|
|
expect(parsed.success, `${target}: ${JSON.stringify(parsed.error?.issues)}`).toBe(
|
|
true,
|
|
);
|
|
expect((source as Record<string, unknown>)["APP_ENV"]).toBe(target);
|
|
}
|
|
});
|
|
|
|
it("produces an admissible document for every public target", async () => {
|
|
for (const target of ["staging", "production"] as const) {
|
|
const config = await generateRuntimeConfig(target, {
|
|
VITE_BUILD_ID: "20260815.42",
|
|
RELEASE_ID: "r-2026.08.15-1",
|
|
});
|
|
expect(
|
|
findAdmissionViolations(target, config as unknown as AdmissionInput),
|
|
).toEqual([]);
|
|
}
|
|
});
|
|
|
|
it("refuses a deployment override that would make the document unservable", async () => {
|
|
await expect(
|
|
generateRuntimeConfig("production", {
|
|
VITE_BUILD_ID: "20260815.42",
|
|
RELEASE_ID: "r-1",
|
|
RUNTIME_API_BASE_URL: "http://api.example.com/",
|
|
}),
|
|
).rejects.toThrow(/runtime config is invalid/u);
|
|
});
|
|
|
|
it("refuses a staging or production build without VITE_BUILD_ID (F-6)", async () => {
|
|
for (const target of ["staging", "production"] as const) {
|
|
await expect(
|
|
generateRuntimeConfig(target, { RELEASE_ID: "r-1" }),
|
|
).rejects.toThrow(/VITE_BUILD_ID/u);
|
|
await expect(
|
|
generateRuntimeConfig(target, { VITE_BUILD_ID: "", RELEASE_ID: "r-1" }),
|
|
).rejects.toThrow(/VITE_BUILD_ID/u);
|
|
}
|
|
});
|
|
|
|
it("declares the build defaults that getBuildConfig applies (F-6)", () => {
|
|
const applied = getBuildConfig({});
|
|
expect({
|
|
VITE_BUILD_ID: ENV_REGISTRY.VITE_BUILD_ID.defaultValue,
|
|
VITE_COMMIT_SHA: ENV_REGISTRY.VITE_COMMIT_SHA.defaultValue,
|
|
VITE_ROUTER_BASE_PATH: ENV_REGISTRY.VITE_ROUTER_BASE_PATH.defaultValue,
|
|
VITE_RUNTIME_CONFIG_URL: ENV_REGISTRY.VITE_RUNTIME_CONFIG_URL.defaultValue,
|
|
}).toEqual({
|
|
VITE_BUILD_ID: applied.buildId,
|
|
VITE_COMMIT_SHA: applied.commitSha,
|
|
VITE_ROUTER_BASE_PATH: applied.routerBasePath,
|
|
VITE_RUNTIME_CONFIG_URL: applied.runtimeConfigUrl,
|
|
});
|
|
});
|
|
|
|
it("keeps a developer build from carrying a released identity by default", async () => {
|
|
const config = await generateRuntimeConfig("local", {});
|
|
expect(config["BUILD_ID"]).toBe("local-build");
|
|
expect(
|
|
findAdmissionViolations("production", config as unknown as AdmissionInput)
|
|
.length,
|
|
).toBeGreaterThan(0);
|
|
});
|
|
|
|
// F-5 (13-15). `corepack pnpm dev` serves public/config.json while every
|
|
// build writes the local profile instead, so the two copies must not drift.
|
|
it("keeps public/config.json equal to what a local build writes", async () => {
|
|
const served: unknown = JSON.parse(await readFile("public/config.json", "utf8"));
|
|
expect(served).toEqual(await generateRuntimeConfig("local", {}));
|
|
});
|
|
|
|
// 13-01: the build profile and the admission target are two repository
|
|
// variables. A staging profile left in place for a production release has to
|
|
// stop the release, whatever the built document happens to say.
|
|
it.each([
|
|
["staging", 1],
|
|
["production", 0],
|
|
] as const)("admits a production artifact under APP_PROFILE=%s only when it names the target", async (profile, status) => {
|
|
const root = await mkdtemp(path.join(tmpdir(), "release-admission-profile-"));
|
|
try {
|
|
const config = await generateRuntimeConfig("production", {
|
|
VITE_BUILD_ID: "20260815.42",
|
|
RELEASE_ID: "r-2026.08.15-1",
|
|
});
|
|
await mkdir(path.join(root, "dist"), { recursive: true });
|
|
await writeFile(path.join(root, "dist/config.json"), JSON.stringify(config));
|
|
const result = spawnSync(
|
|
process.execPath,
|
|
[path.resolve("scripts/check-release-admission.ts")],
|
|
{
|
|
cwd: root,
|
|
encoding: "utf8",
|
|
env: { ...process.env, APP_PROFILE: profile, RELEASE_TARGET: "production" },
|
|
},
|
|
);
|
|
expect(result.status, result.stderr).toBe(status);
|
|
if (status === 1) expect(result.stderr).toMatch(/APP_PROFILE=staging/u);
|
|
} finally {
|
|
await rm(root, { recursive: true, force: true });
|
|
}
|
|
});
|
|
});
|