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)
263 lines
8.0 KiB
TypeScript
263 lines
8.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { installBrowserRpcContractBindings } from "../../src/contracts/browser-rpc.ts";
|
|
import { parseCacheInvalidationWireEvent } from "../../src/contracts/cache-invalidation.ts";
|
|
import {
|
|
composeContractContributions,
|
|
ContractContributionError,
|
|
} from "../../src/contracts/external-contract-runtime.ts";
|
|
import { createRealtimePolicyRegistry } from "../../src/contracts/realtime-streams.ts";
|
|
import {
|
|
installRestAuthProfileRegistry,
|
|
REST_AUTH_PROFILES,
|
|
} from "../../src/contracts/rest-profiles.ts";
|
|
import { decodeStaticAssetManifest } from "../../src/contracts/service-worker-static-manifest.ts";
|
|
import { TEST_CONTRACT_CONTRIBUTION } from "../helpers/external-contract-fixture.ts";
|
|
import {
|
|
MAPPERS,
|
|
SCHEMA_CODECS,
|
|
UNARY_ENCODER,
|
|
unaryOperation,
|
|
unaryProfile,
|
|
} from "./browser-rpc/fixture.ts";
|
|
import {
|
|
EFFECT_PROFILE_ID,
|
|
ENDPOINT_ID,
|
|
KILL_SWITCH_ID,
|
|
TEST_API_OPERATIONS,
|
|
TEST_MAPPERS,
|
|
TEST_SCHEMA_CODECS,
|
|
createTestRealtimeRegistry,
|
|
} from "./realtime/fixture.ts";
|
|
|
|
/**
|
|
* Q-6.7-6. Every contract that installs a caller-supplied row must validate
|
|
* and install one owned snapshot. An own `Symbol.iterator` on an array or an
|
|
* accessor on a row lets the value that was checked differ from the value
|
|
* that was installed.
|
|
*/
|
|
|
|
/** An array whose length and indices say one thing and whose iterator says another. */
|
|
function iteratorSmuggling<T>(visible: readonly T[], smuggled: readonly T[]): T[] {
|
|
const array = [...visible];
|
|
Object.defineProperty(array, Symbol.iterator, {
|
|
value: function* () {
|
|
yield* smuggled;
|
|
},
|
|
});
|
|
return array;
|
|
}
|
|
|
|
const validator = Object.freeze({
|
|
schemaId: "SmuggledSchema",
|
|
safeParse: (value: unknown) =>
|
|
Object.freeze({ success: true as const, data: value }),
|
|
});
|
|
|
|
describe("external contract composition", () => {
|
|
it("does not install an event hidden behind an array iterator", () => {
|
|
const smuggled = Object.freeze({
|
|
eventType: "test.smuggled",
|
|
envelopeValidator: validator,
|
|
payloadValidator: validator,
|
|
});
|
|
let composed: ReturnType<typeof composeContractContributions> | undefined;
|
|
try {
|
|
composed = composeContractContributions([
|
|
{
|
|
contributionId: "fixture-v1",
|
|
featureId: "test-feature",
|
|
source: {
|
|
kind: "TEMPLATE_FIXTURE",
|
|
fixtureId: "REFERENCE_FEATURE_V1",
|
|
revision: 1,
|
|
},
|
|
http: [],
|
|
events: iteratorSmuggling([], [smuggled]),
|
|
},
|
|
] as never);
|
|
} catch (error) {
|
|
expect(error).toBeInstanceOf(ContractContributionError);
|
|
return;
|
|
}
|
|
expect(composed.eventByType.has("test.smuggled")).toBe(false);
|
|
});
|
|
|
|
it("reports a throwing reflection trap as a composition failure", () => {
|
|
const row = new Proxy(
|
|
{ ...TEST_CONTRACT_CONTRIBUTION.http[0]! },
|
|
{
|
|
ownKeys() {
|
|
throw new TypeError("hostile ownKeys trap");
|
|
},
|
|
},
|
|
);
|
|
expect(() =>
|
|
composeContractContributions([
|
|
{ ...TEST_CONTRACT_CONTRIBUTION, http: [row] },
|
|
] as never),
|
|
).toThrow(ContractContributionError);
|
|
});
|
|
});
|
|
|
|
describe("realtime policy registry", () => {
|
|
it("rejects a limit accessor instead of reading it twice", () => {
|
|
const baseline = createTestRealtimeRegistry();
|
|
const stream = baseline.listStreams()[0]!;
|
|
let reads = 0;
|
|
const limits = { ...stream.limits };
|
|
Object.defineProperty(limits, "maxEventBytes", {
|
|
enumerable: true,
|
|
configurable: true,
|
|
get: () => {
|
|
reads += 1;
|
|
// Three reads validate it; the fourth is the install copy.
|
|
return reads <= 3 ? 1_024 : 999_999_999;
|
|
},
|
|
});
|
|
expect(() =>
|
|
createRealtimePolicyRegistry({
|
|
streams: [{ ...stream, limits }],
|
|
eventTypes: [baseline.listEventTypes()[0]!],
|
|
bindings: {
|
|
schemaCodecs: TEST_SCHEMA_CODECS,
|
|
mappers: TEST_MAPPERS,
|
|
apiOperations: TEST_API_OPERATIONS,
|
|
endpointIds: [ENDPOINT_ID],
|
|
effectProfileIds: [EFFECT_PROFILE_ID],
|
|
killSwitchIds: [KILL_SWITCH_ID],
|
|
rebuildInputIds: ["referenceRealtimeRebuild"],
|
|
},
|
|
}),
|
|
).toThrow();
|
|
});
|
|
});
|
|
|
|
describe("cache invalidation wire event", () => {
|
|
it("rejects an accessor field", () => {
|
|
const now = 1_000_000;
|
|
const event = {
|
|
protocolVersion: 1,
|
|
eventId: "remote-event-00000001",
|
|
sourceId: "remote-source-0000001",
|
|
sourceEpoch: "remote-epoch-0000001",
|
|
sequence: 1,
|
|
cacheEpoch: "cache-epoch-0001",
|
|
topicVersion: 1,
|
|
emittedAt: now,
|
|
expiresAt: now + 60_000,
|
|
};
|
|
Object.defineProperty(event, "topic", {
|
|
enumerable: true,
|
|
get: () => "sample-topic-alpha",
|
|
});
|
|
expect(
|
|
parseCacheInvalidationWireEvent(event, {
|
|
cacheEpoch: "cache-epoch-0001",
|
|
topicVersions: { "sample-topic-alpha": 1 },
|
|
nowEpochMilliseconds: now,
|
|
}),
|
|
).toEqual({ ok: false, reason: "INVALID_ENVELOPE" });
|
|
});
|
|
});
|
|
|
|
describe("static asset manifest", () => {
|
|
const row = {
|
|
url: "/assets/app-abcdefgh.js",
|
|
sha256: `sha256:${"a".repeat(64)}`,
|
|
bytes: 16,
|
|
contentType: "text/javascript",
|
|
};
|
|
const manifest = (assets: unknown) => ({
|
|
schemaVersion: 1,
|
|
buildId: "build-1",
|
|
releaseId: "release-1",
|
|
setDigest: `sha256:${"b".repeat(64)}`,
|
|
assets,
|
|
});
|
|
|
|
it("rejects an accessor on a row", () => {
|
|
const accessorRow = { ...row };
|
|
Object.defineProperty(accessorRow, "bytes", {
|
|
enumerable: true,
|
|
get: () => 16,
|
|
});
|
|
expect(decodeStaticAssetManifest(manifest([accessorRow])).ok).toBe(false);
|
|
});
|
|
|
|
it("does not decode rows hidden behind an array iterator", () => {
|
|
const decoded = decodeStaticAssetManifest(
|
|
manifest(iteratorSmuggling([], [row])),
|
|
);
|
|
expect(decoded.ok && decoded.manifest.assets.length > 0).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("browser RPC contract bindings", () => {
|
|
const install = (operations: Record<string, unknown>) =>
|
|
installBrowserRpcContractBindings({
|
|
operations: operations as never,
|
|
profiles: { [unaryProfile().runtimeProfileId]: unaryProfile() },
|
|
schemaCodecs: SCHEMA_CODECS,
|
|
mappers: MAPPERS,
|
|
requestEncoders: { RpcResourceRequestEncoder: UNARY_ENCODER },
|
|
});
|
|
|
|
it("rejects a non-enumerable registry entry", () => {
|
|
const operations = {};
|
|
Object.defineProperty(operations, "GET_RPC_RESOURCE", {
|
|
enumerable: false,
|
|
value: unaryOperation(),
|
|
});
|
|
expect(() => install(operations)).toThrow(TypeError);
|
|
});
|
|
|
|
it("rejects a non-enumerable row field", () => {
|
|
const { totalDeadlineMs, ...rest } = unaryOperation();
|
|
const operation = Object.defineProperty(rest, "totalDeadlineMs", {
|
|
enumerable: false,
|
|
value: totalDeadlineMs,
|
|
});
|
|
expect(() => install({ GET_RPC_RESOURCE: operation })).toThrow(TypeError);
|
|
});
|
|
});
|
|
|
|
describe("REST auth profile registry", () => {
|
|
it("rejects an accessor field", () => {
|
|
const profile = { ...REST_AUTH_PROFILES.ANONYMOUS };
|
|
Object.defineProperty(profile, "transport", {
|
|
enumerable: true,
|
|
get: () => "ANONYMOUS",
|
|
});
|
|
expect(() => installRestAuthProfileRegistry({ ANONYMOUS: profile })).toThrow(
|
|
TypeError,
|
|
);
|
|
});
|
|
|
|
it("installs the header set it validated, not the one an iterator yields", () => {
|
|
let iterations = 0;
|
|
const allowed = ["authorization"];
|
|
Object.defineProperty(allowed, Symbol.iterator, {
|
|
value: function* () {
|
|
iterations += 1;
|
|
yield "authorization";
|
|
if (iterations > 1) yield* ["x-csrf-token", "x-csrf-token"];
|
|
},
|
|
});
|
|
let installed: ReturnType<typeof installRestAuthProfileRegistry> | undefined;
|
|
try {
|
|
installed = installRestAuthProfileRegistry({
|
|
REFERENCE_EXTERNAL_BEARER: {
|
|
...REST_AUTH_PROFILES.REFERENCE_EXTERNAL_BEARER,
|
|
allowedCredentialHeaders: allowed as never,
|
|
},
|
|
});
|
|
} catch {
|
|
return;
|
|
}
|
|
expect(
|
|
installed.get("REFERENCE_EXTERNAL_BEARER")?.allowedCredentialHeaders,
|
|
).toEqual(["authorization"]);
|
|
});
|
|
});
|