Which features a build contains was not a decision anybody could express. The reference feature was spread directly into the route, API, schema, codec and adapter registries, so shipping without it meant editing five files by hand and hoping nothing still referred to it — and there was no way at all to take it out of service on a running deployment. The removability gate proved the editing worked; nothing made it a choice. There is now one manifest. `VITE_PRODUCT_FEATURES` narrows it at build time and `FEATURE_OVERRIDES` in the runtime document takes an installed feature out of service without a rebuild. Every registry composes from the manifest, and a test fails if a new one forgets to. Both inputs are subtractive, and the vocabulary is what enforces it rather than a check somewhere downstream: the override enum has no `ENABLED`, and a build-time selection naming something the source tree does not declare is refused instead of ignored. A configuration document that could name a feature into existence would be a configuration document choosing which code runs. Disabling is not just hiding. Withdrawing a route from navigation would leave a typed deep link that still mounts the feature, so the router refuses it too and answers with a surface that says the deployment switched it off. The platform overview now distinguishes the three states an operator actually needs: serving, switched off, and not in this build. What this is not: an env var does not shrink the bundle. A static import cannot be undone by a value, and making the import graph itself depend on a configuration string is the thing §3.5 exists to prevent — measured, `none` changes the output by 58 bytes. Physical removal remains FE-GATE-020's job, and the code comments say so rather than implying otherwise. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
158 lines
4.7 KiB
TypeScript
158 lines
4.7 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import { createApplication } from "../../src/application/create-application.ts";
|
|
import { createAnonymousSessionAdapter } from "../../src/adapters/auth/external-session-adapter.ts";
|
|
import type { StoragePort } from "../../src/application/ports/storage-port.ts";
|
|
import type { DiagnosticsPort } from "../../src/application/ports/diagnostics-port.ts";
|
|
import type { TelemetryPort } from "../../src/application/ports/telemetry-port.ts";
|
|
import { createProductFeaturesStub, createRuntimeCapabilitiesStub } from "../helpers/runtime-capabilities-stub.ts";
|
|
|
|
type ReleaseFixture = {
|
|
buildId: string;
|
|
releaseId: string;
|
|
configSchemaVersion: string;
|
|
apiContractVersion: string;
|
|
assetManifestHash: string;
|
|
routeChunks: Record<string, string>;
|
|
};
|
|
|
|
function release(buildId: string, releaseId: string): ReleaseFixture {
|
|
return {
|
|
buildId,
|
|
releaseId,
|
|
configSchemaVersion: "1",
|
|
apiContractVersion: "1",
|
|
assetManifestHash: `${buildId}-assets`,
|
|
routeChunks: { "route-home": `assets/${buildId}-home.js` },
|
|
};
|
|
}
|
|
|
|
function memoryStorage(): StoragePort {
|
|
let value: unknown;
|
|
return {
|
|
read: () => ({ ok: true, value }),
|
|
write: (_name, next) => {
|
|
value = next;
|
|
return { ok: true };
|
|
},
|
|
remove: () => ({ ok: true }),
|
|
};
|
|
}
|
|
|
|
function applicationWith(options: {
|
|
storage?: StoragePort;
|
|
refresh?: () => Promise<ReturnType<typeof release>>;
|
|
reload?: () => void;
|
|
diagnostics?: DiagnosticsPort;
|
|
telemetry?: TelemetryPort;
|
|
}) {
|
|
const current = release("build-a", "release-a");
|
|
return createApplication({
|
|
session: createAnonymousSessionAdapter(),
|
|
preferences: options.storage ?? memoryStorage(),
|
|
diagnostics: options.diagnostics ?? { record: () => {} },
|
|
telemetry: options.telemetry ?? { emit: () => {} },
|
|
runtimeCapabilities: createRuntimeCapabilitiesStub(),
|
|
productFeatures: createProductFeaturesStub(),
|
|
releaseInfo: {
|
|
getCurrent: async () => current,
|
|
refresh:
|
|
options.refresh ??
|
|
(async () => release("build-b", "release-b")),
|
|
},
|
|
navigation: { reload: options.reload ?? (() => {}) },
|
|
});
|
|
}
|
|
|
|
describe("production chunk recovery application input", () => {
|
|
it("reloads exactly once for one active build/release pair", async () => {
|
|
const reload = vi.fn();
|
|
const record = vi.fn<DiagnosticsPort["record"]>();
|
|
const emit = vi.fn<TelemetryPort["emit"]>();
|
|
const application = applicationWith({
|
|
reload,
|
|
diagnostics: { record },
|
|
telemetry: { emit },
|
|
});
|
|
const input = {
|
|
chunkId: "route-home",
|
|
failureKind: "CHUNK_LOAD_FAILURE" as const,
|
|
};
|
|
|
|
await expect(application.recovery.recoverChunk(input)).resolves.toEqual({
|
|
action: "reload-once",
|
|
releasePair: "build-a/release-a->build-b/release-b",
|
|
});
|
|
expect(record).toHaveBeenCalledWith({
|
|
level: "warn",
|
|
eventId: "release.mismatch.detected",
|
|
context: {
|
|
build_id: "build-a",
|
|
active_release_id: "release-b",
|
|
mismatch_kind: "BUILD_MISMATCH",
|
|
},
|
|
});
|
|
expect(emit).toHaveBeenCalledWith("release.mismatch.detected", {
|
|
build_id: "build-a",
|
|
active_release_id: "release-b",
|
|
mismatch_kind: "BUILD_MISMATCH",
|
|
});
|
|
await expect(application.recovery.recoverChunk(input)).resolves.toEqual({
|
|
action: "support",
|
|
reason: "reload-already-attempted",
|
|
});
|
|
expect(reload).toHaveBeenCalledOnce();
|
|
});
|
|
|
|
it.each([
|
|
[
|
|
{
|
|
refresh: async () => {
|
|
throw new Error("offline");
|
|
},
|
|
},
|
|
"manifest-unavailable",
|
|
],
|
|
[
|
|
{
|
|
refresh: async () => ({
|
|
...release("build-b", "release-b"),
|
|
routeChunks: {},
|
|
}),
|
|
},
|
|
"active-chunk-unknown",
|
|
],
|
|
[
|
|
{
|
|
storage: {
|
|
read: () => ({
|
|
ok: false as const,
|
|
error: {
|
|
kind: "STORAGE_UNAVAILABLE" as const,
|
|
code: "STORAGE_UNAVAILABLE",
|
|
retryable: false,
|
|
operationId: "STORAGE",
|
|
attemptCount: 1,
|
|
userMessageKey: "error.storage_unavailable",
|
|
action: "none" as const,
|
|
},
|
|
}),
|
|
write: () => ({ ok: true as const }),
|
|
remove: () => ({ ok: true as const }),
|
|
},
|
|
},
|
|
"guard-read-failed",
|
|
],
|
|
])("fails closed for recovery dependency case %#", async (options, reason) => {
|
|
const reload = vi.fn();
|
|
const application = applicationWith({ ...options, reload });
|
|
await expect(
|
|
application.recovery.recoverChunk({
|
|
chunkId: "route-home",
|
|
failureKind: "CHUNK_LOAD_FAILURE",
|
|
}),
|
|
).resolves.toEqual({ action: "support", reason });
|
|
expect(reload).not.toHaveBeenCalled();
|
|
});
|
|
});
|