Carries eight template commits: the provider sandbox actually running, release
admission to a named environment, the product feature manifest with its runtime
kill switch, architecture and documentation rules that match what is enforced,
the removability fixtures, and the browser, visual and performance evidence.
Product identity is unchanged. `package.json` keeps `tech-log-frontend` and the
catalog keeps the Tech Log naming; the home page was not in the delta. The
visual baselines are this product's own — the template's were excluded from the
transplant and these were regenerated here, where the only difference is the
platform overview's new product-feature section.
What this repository gains operationally: `config/runtime/{local,development,
staging,production}.json` with `FE-GATE-027` refusing an artifact whose runtime
document does not match the environment it is being admitted to, and
`FEATURE_OVERRIDES` for taking an installed feature out of service without a
rebuild.
Verified here: eight gates green, build green, visual 5/5, and 1,858 of 1,859
tests in the suites that do not need a sandbox — the one failure passes in
isolation and is a jsdom lazy-chunk timeout under parallel load. The provider
suites cannot run on this machine at all: `kernel.apparmor_restrict_unprivileged
_userns=1` makes `bwrap --unshare-net` fail, reproducible without any code from
either repository.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
212 lines
6.6 KiB
TypeScript
212 lines
6.6 KiB
TypeScript
import { normalizeColorSchemePreference } from "./policies/color-scheme.ts";
|
|
import type {
|
|
ApplicationApi,
|
|
ApplicationFeatureId,
|
|
ApplicationFeatureInputs,
|
|
ColorSchemePreference,
|
|
RenderFailureReport,
|
|
RouteChangedReport,
|
|
} from "./ports/in/application-api.ts";
|
|
import type { ApplicationOutputPorts } from "./ports/out/application-output-ports.ts";
|
|
import { decideChunkRecovery } from "./use-cases/decide-chunk-recovery.ts";
|
|
|
|
export type { ApplicationApi, ApplicationOutputPorts };
|
|
|
|
/**
|
|
* Builds the driving API consumed by inbound adapters. Concrete output ports
|
|
* remain inside these closures and are never returned to React.
|
|
*/
|
|
export function createApplication(
|
|
outputPorts: ApplicationOutputPorts,
|
|
featureInputs: Readonly<Partial<ApplicationFeatureInputs>> = {},
|
|
): ApplicationApi {
|
|
const session = Object.freeze({
|
|
getSnapshot: () => outputPorts.session.getState(),
|
|
subscribe: (listener: () => void) =>
|
|
outputPorts.session.subscribe(listener),
|
|
beginSignIn: (returnTo?: string) =>
|
|
outputPorts.session.beginSignIn(returnTo),
|
|
signOut: () => outputPorts.session.signOut(),
|
|
recover: () => outputPorts.session.recover(),
|
|
});
|
|
|
|
const preferences = Object.freeze({
|
|
getColorScheme(): ColorSchemePreference {
|
|
const result = outputPorts.preferences.read("COLOR_SCHEME");
|
|
return normalizeColorSchemePreference(
|
|
result.ok ? result.value : undefined,
|
|
);
|
|
},
|
|
setColorScheme(preference: ColorSchemePreference) {
|
|
const normalized = normalizeColorSchemePreference(preference);
|
|
return outputPorts.preferences.write("COLOR_SCHEME", normalized);
|
|
},
|
|
});
|
|
|
|
const diagnostics = Object.freeze({
|
|
reportRenderFailure(report: RenderFailureReport) {
|
|
try {
|
|
outputPorts.diagnostics.record({
|
|
level: "error",
|
|
eventId: "ui.render.failed",
|
|
context: {
|
|
route_id: report.routeId,
|
|
build_id: report.buildId,
|
|
component_boundary: report.boundaryName,
|
|
},
|
|
});
|
|
} catch {
|
|
// Diagnostics are best-effort and cannot become an application failure.
|
|
}
|
|
try {
|
|
outputPorts.telemetry.emit("ui.render.failed", {
|
|
route_id: report.routeId,
|
|
build_id: report.buildId,
|
|
component_boundary: report.boundaryName,
|
|
});
|
|
} catch {
|
|
// Diagnostics are best-effort and cannot become an application failure.
|
|
}
|
|
},
|
|
reportRouteChanged(report: RouteChangedReport) {
|
|
try {
|
|
outputPorts.diagnostics.record({
|
|
level: "info",
|
|
eventId: "route.changed",
|
|
context: {
|
|
route_id: report.routeId,
|
|
build_id: report.buildId,
|
|
},
|
|
});
|
|
} catch {
|
|
// Diagnostics are best-effort and cannot become navigation failure.
|
|
}
|
|
},
|
|
});
|
|
|
|
const runtime = Object.freeze({
|
|
async getReleaseSummary() {
|
|
const release = await outputPorts.releaseInfo.getCurrent();
|
|
return Object.freeze({
|
|
buildId: release.buildId,
|
|
releaseId: release.releaseId,
|
|
configSchemaVersion: release.configSchemaVersion,
|
|
...(release.apiContractVersion === undefined
|
|
? {}
|
|
: { apiContractVersion: release.apiContractVersion }),
|
|
...(release.contractSetDigest === undefined
|
|
? {}
|
|
: { contractSetDigest: release.contractSetDigest }),
|
|
});
|
|
},
|
|
getCapabilitySnapshot() {
|
|
return outputPorts.runtimeCapabilities.getSnapshot();
|
|
},
|
|
getFeatureSnapshot() {
|
|
return outputPorts.productFeatures.getSnapshot();
|
|
},
|
|
isFeatureActive(featureId: string) {
|
|
return outputPorts.productFeatures.isActive(featureId);
|
|
},
|
|
});
|
|
|
|
const recovery = Object.freeze({
|
|
async recoverChunk(input: {
|
|
chunkId: string;
|
|
failureKind: "CHUNK_LOAD_FAILURE" | "DEPLOY_MISMATCH";
|
|
}) {
|
|
try {
|
|
const current = await outputPorts.releaseInfo.getCurrent();
|
|
const active = await outputPorts.releaseInfo.refresh();
|
|
if (
|
|
current.buildId !== active.buildId ||
|
|
current.releaseId !== active.releaseId
|
|
) {
|
|
const mismatchKind =
|
|
current.buildId !== active.buildId
|
|
? "BUILD_MISMATCH"
|
|
: "RELEASE_MISMATCH";
|
|
try {
|
|
outputPorts.diagnostics.record({
|
|
level: "warn",
|
|
eventId: "release.mismatch.detected",
|
|
context: {
|
|
build_id: current.buildId,
|
|
active_release_id: active.releaseId,
|
|
mismatch_kind: mismatchKind,
|
|
},
|
|
});
|
|
} catch {
|
|
// Recovery remains independent from diagnostics.
|
|
}
|
|
try {
|
|
outputPorts.telemetry.emit("release.mismatch.detected", {
|
|
build_id: current.buildId,
|
|
active_release_id: active.releaseId,
|
|
mismatch_kind: mismatchKind,
|
|
});
|
|
} catch {
|
|
// Recovery remains independent from telemetry.
|
|
}
|
|
}
|
|
if (!active.routeChunks[input.chunkId]) {
|
|
return {
|
|
action: "support" as const,
|
|
reason: "active-chunk-unknown",
|
|
};
|
|
}
|
|
const decision = decideChunkRecovery({
|
|
failureKind: input.failureKind,
|
|
manifestLoaded: true,
|
|
currentBuildId: current.buildId,
|
|
currentReleaseId: current.releaseId,
|
|
activeBuildId: active.buildId,
|
|
activeReleaseId: active.releaseId,
|
|
storage: outputPorts.preferences,
|
|
});
|
|
if (decision.action === "reload-once") {
|
|
try {
|
|
outputPorts.navigation.reload();
|
|
} catch {
|
|
return {
|
|
action: "support" as const,
|
|
reason: "reload-failed",
|
|
};
|
|
}
|
|
}
|
|
return decision;
|
|
} catch {
|
|
return {
|
|
action: "support" as const,
|
|
reason: "manifest-unavailable",
|
|
};
|
|
}
|
|
},
|
|
});
|
|
const installedFeatureInputs = Object.freeze({ ...featureInputs });
|
|
const features = Object.freeze({
|
|
has(featureId: string): featureId is ApplicationFeatureId {
|
|
return Object.hasOwn(installedFeatureInputs, featureId);
|
|
},
|
|
get<FeatureId extends ApplicationFeatureId>(
|
|
featureId: FeatureId,
|
|
): ApplicationFeatureInputs[FeatureId] {
|
|
if (!Object.hasOwn(installedFeatureInputs, featureId)) {
|
|
throw new Error(`Application feature is not installed: ${featureId}`);
|
|
}
|
|
return installedFeatureInputs[
|
|
featureId
|
|
] as ApplicationFeatureInputs[FeatureId];
|
|
},
|
|
});
|
|
|
|
return Object.freeze({
|
|
session,
|
|
preferences,
|
|
diagnostics,
|
|
runtime,
|
|
recovery,
|
|
features,
|
|
});
|
|
}
|