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>
214 lines
6.7 KiB
TypeScript
214 lines
6.7 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import { createRuntimeAdapters } from "../../../src/bootstrap/runtime-adapters.ts";
|
|
import { createRuntimeIdentityRegistry } from "../../../src/contracts/query-keys.ts";
|
|
import { bindQuery } from "../../../src/contracts/server-state.ts";
|
|
import type { CacheScopeSnapshot } from "../../../src/contracts/server-state-scope.ts";
|
|
import {
|
|
REFERENCE_FEATURE_ID,
|
|
REFERENCE_RESOURCE_INVALIDATION_TOPIC,
|
|
} from "../../../src/features/reference-feature/contracts/reference-feature-contract.ts";
|
|
|
|
type Runtime = Parameters<typeof createRuntimeAdapters>[0]["runtime"];
|
|
type Release = Parameters<typeof createRuntimeAdapters>[0]["release"];
|
|
|
|
const runtime: Runtime = {
|
|
config: {
|
|
APP_ENV: "local",
|
|
API_BASE_URL: "http://localhost:8080",
|
|
TELEMETRY_ENABLED: false,
|
|
AUTH_MODE: "demo",
|
|
REQUEST_TIMEOUT_MS: 4321,
|
|
MAX_RETRY_ATTEMPTS: 0,
|
|
RELEASE_MANIFEST_URL: "/release-manifest.json",
|
|
CONFIG_SCHEMA_VERSION: "2.0",
|
|
CAPABILITY_OVERRIDES: {
|
|
REALTIME: "DEFAULT",
|
|
WEB_WORKER: "DEFAULT",
|
|
SERVICE_WORKER: "DEFAULT",
|
|
OFFLINE_COMMANDS: "DEFAULT",
|
|
},
|
|
FEATURE_OVERRIDES: {},
|
|
},
|
|
configSchema: "V2",
|
|
build: {
|
|
buildId: "build-a",
|
|
commitSha: "abc123",
|
|
routerBasePath: "/",
|
|
runtimeConfigUrl: "/config.json",
|
|
},
|
|
validationDurationMs: 0,
|
|
};
|
|
|
|
const release: Release = {
|
|
schemaVersion: 2,
|
|
appVersion: "0.1.0",
|
|
buildId: "build-a",
|
|
commitSha: "abc123",
|
|
configSchemaVersion: "2.0",
|
|
contractSet: {
|
|
setAlgorithm: "CA_CONTRACT_SET_V1",
|
|
setDigest: `sha256:${"0".repeat(64)}`,
|
|
packages: [],
|
|
},
|
|
assetManifestHash: "hash-a",
|
|
releaseId: "release-a",
|
|
builtAt: "2026-07-25T00:00:00Z",
|
|
routeChunks: { "route-home": "assets/home.js" },
|
|
};
|
|
|
|
function referenceBoundQueryKey() {
|
|
const scope: CacheScopeSnapshot = {
|
|
generation: 1,
|
|
fingerprint: "runtime-scope-fingerprint-0001",
|
|
identities: createRuntimeIdentityRegistry({
|
|
tokenFactory: () => "runtime-identity-token-0001",
|
|
}),
|
|
signal: new AbortController().signal,
|
|
isCurrent: () => true,
|
|
};
|
|
return bindQuery(
|
|
{
|
|
definitionId: "reference-resource-runtime-test-v1",
|
|
definitionVersion: 1,
|
|
owner: REFERENCE_FEATURE_ID,
|
|
namespace: "reference-resource",
|
|
namespaceVersion: 1,
|
|
operationId: "GET_REFERENCE_RESOURCE",
|
|
profileId: "DETAIL_STANDARD",
|
|
measureResult: () => ({ itemCount: 1, estimatedBytes: 8 }),
|
|
execute: async () => ({ ok: true as const, value: "reference-1" }),
|
|
},
|
|
"reference-1",
|
|
scope,
|
|
).queryKey;
|
|
}
|
|
|
|
/**
|
|
* The installed feature inputs are partial by design: a feature the product
|
|
* manifest did not select supplies none. This suite is about the reference
|
|
* feature being composed, so it asserts that first and narrows once.
|
|
*/
|
|
function referenceInput<
|
|
Inputs extends Readonly<Partial<Record<typeof REFERENCE_FEATURE_ID, unknown>>>,
|
|
>(adapters: Readonly<{ featureInputs: Inputs }>) {
|
|
const input = adapters.featureInputs[REFERENCE_FEATURE_ID];
|
|
if (!input) {
|
|
throw new Error(
|
|
`${REFERENCE_FEATURE_ID} is not installed; the manifest did not select it`,
|
|
);
|
|
}
|
|
return input as NonNullable<Inputs[typeof REFERENCE_FEATURE_ID]>;
|
|
}
|
|
|
|
describe("reference feature runtime composition", () => {
|
|
it("invalidates a real bound query through the installed production graph", async () => {
|
|
const adapters = await createRuntimeAdapters({ runtime, release, host: {} });
|
|
const queryKey = referenceBoundQueryKey();
|
|
adapters.infrastructure.queryClient.setQueryData(queryKey, {
|
|
resourceId: "reference-1",
|
|
});
|
|
|
|
await adapters.infrastructure.queryInvalidation.invalidate([
|
|
REFERENCE_RESOURCE_INVALIDATION_TOPIC,
|
|
]);
|
|
|
|
expect(
|
|
adapters.infrastructure.queryClient.getQueryState(queryKey)?.isInvalidated,
|
|
).toBe(true);
|
|
adapters.infrastructure.dispose();
|
|
});
|
|
|
|
it("executes installed feature HTTP through the composed contract registry", async () => {
|
|
const fetcher = vi.fn(async () =>
|
|
Response.json([{ id: "reference-1", name: "Direct contract payload" }]),
|
|
);
|
|
const adapters = await createRuntimeAdapters({
|
|
runtime,
|
|
release,
|
|
host: {},
|
|
fetcher,
|
|
});
|
|
await adapters.outputPorts.session.beginSignIn();
|
|
await vi.waitFor(() =>
|
|
expect(adapters.infrastructure.serverStateScope.getPhase()).toBe("READY"),
|
|
);
|
|
|
|
await expect(
|
|
referenceInput(adapters).listResources({ limit: 20 }),
|
|
).resolves.toEqual({
|
|
ok: true,
|
|
value: [
|
|
{
|
|
resourceId: "reference-1",
|
|
title: "Direct contract payload",
|
|
createdAt: null,
|
|
},
|
|
],
|
|
});
|
|
expect(fetcher).toHaveBeenCalledWith(
|
|
"http://localhost:8080/api/reference-resources?limit=20",
|
|
expect.objectContaining({
|
|
method: "GET",
|
|
redirect: "error",
|
|
cache: "no-store",
|
|
}),
|
|
);
|
|
adapters.infrastructure.dispose();
|
|
});
|
|
|
|
it("keeps private command intent identity out of URLs and diagnostics", async () => {
|
|
const requests: Array<Readonly<{ url: string; headers: Headers }>> = [];
|
|
const fetcher = vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
requests.push({
|
|
url: String(input),
|
|
headers: new Headers(init?.headers),
|
|
});
|
|
return Response.json(
|
|
{ id: "resource-1", name: "Created resource" },
|
|
{ status: 201 },
|
|
);
|
|
});
|
|
const adapters = await createRuntimeAdapters({
|
|
runtime,
|
|
release,
|
|
host: {},
|
|
fetcher,
|
|
});
|
|
await adapters.outputPorts.session.beginSignIn();
|
|
await vi.waitFor(() =>
|
|
expect(adapters.infrastructure.serverStateScope.getPhase()).toBe("READY"),
|
|
);
|
|
const intent = Object.freeze({
|
|
intentId: "private-intent-id",
|
|
operationId: "CREATE_REFERENCE_RESOURCE",
|
|
canonicalInputIdentity: "private-canonical-input",
|
|
idempotencyKey: "private-idempotency-key",
|
|
createdAtMonotonicMs: 42,
|
|
});
|
|
|
|
await expect(
|
|
referenceInput(adapters).createResource(
|
|
{ name: "Created resource" },
|
|
{ intent },
|
|
),
|
|
).resolves.toMatchObject({ ok: true });
|
|
|
|
expect(requests).toHaveLength(1);
|
|
expect(requests[0]?.headers.get("Idempotency-Key")).toBe(
|
|
"private-idempotency-key",
|
|
);
|
|
expect(requests[0]?.url).toBe(
|
|
"http://localhost:8080/api/reference-resources",
|
|
);
|
|
const safeEvidence = JSON.stringify({
|
|
requests: requests.map((request) => request.url),
|
|
diagnostics: adapters.outputPorts.diagnostics.entries(),
|
|
});
|
|
expect(safeEvidence).not.toContain("private-intent-id");
|
|
expect(safeEvidence).not.toContain("private-canonical-input");
|
|
expect(safeEvidence).not.toContain("private-idempotency-key");
|
|
adapters.infrastructure.dispose();
|
|
});
|
|
});
|