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>
111 lines
3.0 KiB
TypeScript
111 lines
3.0 KiB
TypeScript
import type { DiagnosticsPort } from "../../application/ports/diagnostics-port.ts";
|
|
import {
|
|
projectDiagnosticRecord,
|
|
safeErrorKind,
|
|
type DiagnosticRecord,
|
|
type DiagnosticRecordInput,
|
|
} from "../../contracts/diagnostics.ts";
|
|
import { projectTelemetryEvent } from "../../contracts/telemetry.ts";
|
|
import { assertBoundedCapacity } from "../platform/bounded-capacity.ts";
|
|
|
|
export const noOpDiagnostics: DiagnosticsPort = Object.freeze({
|
|
record() {},
|
|
});
|
|
|
|
/** N-11. Documented absolute ceiling for bounded in-memory evidence. */
|
|
export const MAX_DIAGNOSTIC_ENTRIES = 10_000;
|
|
|
|
export function createDiagnosticsAdapter(
|
|
options: Readonly<{
|
|
maxEntries?: number;
|
|
now?: () => number;
|
|
sink?: (record: DiagnosticRecord) => void;
|
|
}> = {},
|
|
) {
|
|
const maxEntries = assertBoundedCapacity(
|
|
options.maxEntries ?? 100,
|
|
MAX_DIAGNOSTIC_ENTRIES,
|
|
"diagnostics maxEntries",
|
|
);
|
|
const entries: DiagnosticRecord[] = [];
|
|
const droppedReasons = new Map<string, number>();
|
|
|
|
function drop(reason: string) {
|
|
droppedReasons.set(reason, (droppedReasons.get(reason) ?? 0) + 1);
|
|
}
|
|
|
|
function record(input: DiagnosticRecordInput) {
|
|
try {
|
|
const projected = projectDiagnosticRecord(input, options.now);
|
|
if (!projected.success) {
|
|
drop(projected.reason);
|
|
return;
|
|
}
|
|
if (entries.length >= maxEntries) {
|
|
entries.shift();
|
|
drop("queue-full");
|
|
}
|
|
entries.push(projected.record);
|
|
try {
|
|
options.sink?.(projected.record);
|
|
} catch {
|
|
drop("sink-failure");
|
|
}
|
|
} catch {
|
|
drop("serialization-failure");
|
|
}
|
|
}
|
|
|
|
return Object.freeze({
|
|
record,
|
|
entries: () => structuredClone(entries) as readonly DiagnosticRecord[],
|
|
dropped: () => Object.freeze(Object.fromEntries(droppedReasons)),
|
|
});
|
|
}
|
|
|
|
type BootSafeContext = Readonly<{
|
|
kind?: string;
|
|
buildId?: string;
|
|
configSchemaVersion?: string;
|
|
supportReference?: string;
|
|
}>;
|
|
|
|
let lastBootEvidence:
|
|
| Readonly<{
|
|
diagnostic: DiagnosticRecord | null;
|
|
telemetry: Readonly<Record<string, unknown>> | null;
|
|
}>
|
|
| undefined;
|
|
|
|
export function recordBootFailure(
|
|
error: unknown,
|
|
safe: BootSafeContext,
|
|
now: () => number = Date.now,
|
|
) {
|
|
const errorKind =
|
|
typeof safe.kind === "string" ? safe.kind : safeErrorKind(error);
|
|
const attributes = {
|
|
error_kind: errorKind,
|
|
build_id: safe.buildId ?? "unknown",
|
|
config_schema_version: safe.configSchemaVersion ?? "unknown",
|
|
};
|
|
const diagnostic = projectDiagnosticRecord(
|
|
{
|
|
level: "error",
|
|
eventId: "app.boot.failed",
|
|
context: attributes,
|
|
},
|
|
now,
|
|
);
|
|
const telemetry = projectTelemetryEvent("app.boot.failed", attributes, now);
|
|
lastBootEvidence = Object.freeze({
|
|
diagnostic: diagnostic.success ? diagnostic.record : null,
|
|
telemetry: telemetry.success ? telemetry.event : null,
|
|
});
|
|
return lastBootEvidence;
|
|
}
|
|
|
|
export function getLastBootEvidence() {
|
|
return lastBootEvidence ? structuredClone(lastBootEvidence) : undefined;
|
|
}
|