chore: sync the frontend template from ebea300 to af3d8e6
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)
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import type {
|
||||
PublicCacheAsset,
|
||||
PublicCacheReleaseManifest,
|
||||
} from "../../src/application/ports/browser-file-storage/cache-storage-ports.ts";
|
||||
import type { ByteSource } from "../../src/application/ports/browser-file-storage/shared.ts";
|
||||
import {
|
||||
assertPublicCachePolicy,
|
||||
createDefaultPublicCachePolicy,
|
||||
resolvePublicCachePolicy,
|
||||
type PublicCacheRuntimePolicy,
|
||||
@@ -49,6 +51,116 @@ describe("public response Cache Storage adapter", () => {
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it("rejects a policy that strips Content-Type from stored responses", () => {
|
||||
const base = createDefaultPublicCachePolicy(
|
||||
"https://assets.example.test",
|
||||
);
|
||||
// Activation re-validates the stored Content-Type, so without it every
|
||||
// activation would fail as INTEGRITY_FAILED.
|
||||
expect(() =>
|
||||
assertPublicCachePolicy({
|
||||
...base,
|
||||
allowedResponseHeaderNames: base.allowedResponseHeaderNames.filter(
|
||||
(name) => name !== "content-type",
|
||||
),
|
||||
}),
|
||||
).toThrow(TypeError);
|
||||
});
|
||||
|
||||
it("stages, activates and looks up a Vary: Accept-Encoding response with the default policy", async () => {
|
||||
const policy = createDefaultPublicCachePolicy(
|
||||
"https://assets.example.test",
|
||||
);
|
||||
const bytes = new Uint8Array([7, 7, 7, 7]);
|
||||
const asset: PublicCacheAsset = {
|
||||
absoluteUrl: "https://assets.example.test/gzip-vary.js",
|
||||
expectedByteLength: bytes.byteLength,
|
||||
expectedContentType: "application/javascript",
|
||||
integrity: {
|
||||
algorithm: "SHA-256",
|
||||
digestHex: await digestHex(bytes),
|
||||
},
|
||||
};
|
||||
const adapter = createPublicResponseCacheAdapter({
|
||||
cacheStorage: new MemoryCacheStorage() as unknown as CacheStorage,
|
||||
crypto: globalThis.crypto,
|
||||
mutationLock: immediateLock,
|
||||
policy,
|
||||
// nginx `gzip_vary on` and most CDNs add this header to JS and CSS.
|
||||
fetcher: async () =>
|
||||
new Response(bytes, {
|
||||
headers: {
|
||||
"cache-control": "public, max-age=31536000, immutable",
|
||||
"content-type": "application/javascript",
|
||||
vary: "Accept-Encoding",
|
||||
},
|
||||
}),
|
||||
});
|
||||
const manifest = await manifestFor("gzip-vary-release", [asset], policy);
|
||||
|
||||
expect(await adapter.admin.stageRelease(manifest)).toMatchObject({
|
||||
ok: true,
|
||||
});
|
||||
expect(
|
||||
await adapter.admin.activateRelease(
|
||||
manifest.releaseRegistryId,
|
||||
manifest.manifestDigestHex,
|
||||
),
|
||||
).toMatchObject({ ok: true });
|
||||
const match = await adapter.responses.matchActiveExact({
|
||||
absoluteUrl: asset.absoluteUrl,
|
||||
});
|
||||
expect(match.ok && match.value !== null).toBe(true);
|
||||
});
|
||||
|
||||
it("stages with an anonymous same-origin request that fails on redirect (02-02)", async () => {
|
||||
const policy = createDefaultPublicCachePolicy(
|
||||
"https://assets.example.test",
|
||||
);
|
||||
const bytes = new Uint8Array([5, 5, 5, 5]);
|
||||
const asset: PublicCacheAsset = {
|
||||
absoluteUrl: "https://assets.example.test/anonymous.js",
|
||||
expectedByteLength: bytes.byteLength,
|
||||
expectedContentType: "application/javascript",
|
||||
integrity: {
|
||||
algorithm: "SHA-256",
|
||||
digestHex: await digestHex(bytes),
|
||||
},
|
||||
};
|
||||
const requests: Request[] = [];
|
||||
const adapter = createPublicResponseCacheAdapter({
|
||||
cacheStorage: new MemoryCacheStorage() as unknown as CacheStorage,
|
||||
crypto: globalThis.crypto,
|
||||
mutationLock: immediateLock,
|
||||
policy,
|
||||
fetcher: async (request) => {
|
||||
requests.push(request);
|
||||
return new Response(bytes, {
|
||||
headers: {
|
||||
"cache-control": "public, max-age=31536000, immutable",
|
||||
"content-type": "application/javascript",
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
const manifest = await manifestFor("anonymous-release", [asset], policy);
|
||||
|
||||
expect(await adapter.admin.stageRelease(manifest)).toMatchObject({
|
||||
ok: true,
|
||||
});
|
||||
// The Cache Storage is origin-wide and has no logout purge, so a cookie
|
||||
// on this request would let a per-user response outlive the session.
|
||||
expect(
|
||||
requests.map(({ credentials, mode, redirect }) => ({
|
||||
credentials,
|
||||
mode,
|
||||
redirect,
|
||||
})),
|
||||
).toEqual([
|
||||
{ credentials: "omit", mode: "same-origin", redirect: "error" },
|
||||
]);
|
||||
});
|
||||
|
||||
it("restages an evicted entry even when the release marker remains", async () => {
|
||||
const policy = createDefaultPublicCachePolicy(
|
||||
"https://assets.example.test",
|
||||
@@ -97,12 +209,23 @@ describe("public response Cache Storage adapter", () => {
|
||||
);
|
||||
expect(payloadIndex).toBeGreaterThanOrEqual(0);
|
||||
cache.responses.splice(payloadIndex, 1);
|
||||
const candidates = async () => {
|
||||
const inspection = await adapter.admin.inspect();
|
||||
return inspection.ok ? inspection.value.releaseCandidates : null;
|
||||
};
|
||||
// 02-05. inspect() does not report the marker's claim as verified.
|
||||
expect(await candidates()).toEqual([
|
||||
{ releaseRegistryId: "evicted-release", verified: false, entryCount: 1 },
|
||||
]);
|
||||
|
||||
// A marker is a claim, not evidence: restaging must repair.
|
||||
expect(await adapter.admin.stageRelease(manifest)).toMatchObject({
|
||||
ok: true,
|
||||
});
|
||||
expect(fetches).toBe(2);
|
||||
expect(await candidates()).toEqual([
|
||||
{ releaseRegistryId: "evicted-release", verified: true, entryCount: 1 },
|
||||
]);
|
||||
expect(
|
||||
await adapter.admin.activateRelease(
|
||||
manifest.releaseRegistryId,
|
||||
@@ -1394,4 +1517,214 @@ describe("public response Cache Storage adapter", () => {
|
||||
expect(bodyCancelled).toBe(true);
|
||||
expect(await cacheStorage.keys()).toEqual([]);
|
||||
});
|
||||
|
||||
it("spends one keys() and at most two body copies per lookup (02-07)", async () => {
|
||||
const policy = createDefaultPublicCachePolicy(
|
||||
"https://assets.example.test",
|
||||
);
|
||||
const bytes = new Uint8Array([6, 6, 6, 6, 6]);
|
||||
const asset: PublicCacheAsset = {
|
||||
absoluteUrl: "https://assets.example.test/cost.js",
|
||||
expectedByteLength: bytes.byteLength,
|
||||
expectedContentType: "application/javascript",
|
||||
integrity: {
|
||||
algorithm: "SHA-256",
|
||||
digestHex: await digestHex(bytes),
|
||||
},
|
||||
};
|
||||
const cacheStorage = new MemoryCacheStorage();
|
||||
let keysCalls = 0;
|
||||
const listKeys = cacheStorage.keys.bind(cacheStorage);
|
||||
cacheStorage.keys = async () => {
|
||||
keysCalls += 1;
|
||||
return await listKeys();
|
||||
};
|
||||
const adapter = createPublicResponseCacheAdapter({
|
||||
cacheStorage: cacheStorage as unknown as CacheStorage,
|
||||
crypto: globalThis.crypto,
|
||||
mutationLock: immediateLock,
|
||||
policy,
|
||||
fetcher: async () =>
|
||||
new Response(Uint8Array.from(bytes), {
|
||||
headers: {
|
||||
"cache-control": "public",
|
||||
"content-type": "application/javascript",
|
||||
},
|
||||
}),
|
||||
});
|
||||
const manifest = await manifestFor("cost-release", [asset], policy);
|
||||
expect(await adapter.admin.stageRelease(manifest)).toMatchObject({
|
||||
ok: true,
|
||||
});
|
||||
expect(
|
||||
await adapter.admin.activateRelease(
|
||||
manifest.releaseRegistryId,
|
||||
manifest.manifestDigestHex,
|
||||
),
|
||||
).toMatchObject({ ok: true });
|
||||
const read = async (body: ByteSource): Promise<Uint8Array[]> => {
|
||||
const chunks: Uint8Array[] = [];
|
||||
for await (const chunk of body.stream(new AbortController().signal)) {
|
||||
if (chunk.ok) chunks.push(chunk.value);
|
||||
}
|
||||
return chunks;
|
||||
};
|
||||
|
||||
keysCalls = 0;
|
||||
const copy = vi.spyOn(Uint8Array, "from");
|
||||
const match = await adapter.responses.matchActiveExact({
|
||||
absoluteUrl: asset.absoluteUrl,
|
||||
});
|
||||
if (!match.ok || !match.value) throw new Error("lookup");
|
||||
const [chunk] = await read(match.value.body);
|
||||
const bodyCopies = copy.mock.calls.filter(
|
||||
([source]) =>
|
||||
source instanceof Uint8Array &&
|
||||
source.byteLength === bytes.byteLength,
|
||||
).length;
|
||||
copy.mockRestore();
|
||||
|
||||
expect(keysCalls).toBe(1);
|
||||
// The bounded read buffer plus one copy for the stream consumer.
|
||||
expect(bodyCopies).toBe(1);
|
||||
// That copy is the consumer's own: changing it leaves the body intact.
|
||||
chunk!.fill(0);
|
||||
expect(await read(match.value.body)).toEqual([bytes]);
|
||||
});
|
||||
|
||||
it("reuses a verified release marker across lookups (Q-6.2-6)", async () => {
|
||||
const policy = createDefaultPublicCachePolicy(
|
||||
"https://assets.example.test",
|
||||
);
|
||||
const cacheStorage = new MemoryCacheStorage();
|
||||
let digests = 0;
|
||||
const countingCrypto = {
|
||||
subtle: {
|
||||
digest: async (
|
||||
algorithm: AlgorithmIdentifier,
|
||||
data: BufferSource,
|
||||
): Promise<ArrayBuffer> => {
|
||||
digests += 1;
|
||||
return await globalThis.crypto.subtle.digest(algorithm, data);
|
||||
},
|
||||
},
|
||||
} as unknown as Crypto;
|
||||
const bodies = new Map<string, Uint8Array>();
|
||||
const release = async (
|
||||
releaseRegistryId: string,
|
||||
files: Readonly<Record<string, readonly number[]>>,
|
||||
): Promise<PublicCacheReleaseManifest> => {
|
||||
const assets: PublicCacheAsset[] = [];
|
||||
for (const [path, content] of Object.entries(files)) {
|
||||
const bytes = Uint8Array.from(content);
|
||||
const absoluteUrl = `https://assets.example.test/${path}`;
|
||||
bodies.set(absoluteUrl, bytes);
|
||||
assets.push({
|
||||
absoluteUrl,
|
||||
expectedByteLength: bytes.byteLength,
|
||||
expectedContentType: "application/javascript",
|
||||
integrity: {
|
||||
algorithm: "SHA-256",
|
||||
digestHex: await digestHex(bytes),
|
||||
},
|
||||
});
|
||||
}
|
||||
return await manifestFor(releaseRegistryId, assets, policy);
|
||||
};
|
||||
const adapter = createPublicResponseCacheAdapter({
|
||||
cacheStorage: cacheStorage as unknown as CacheStorage,
|
||||
crypto: countingCrypto,
|
||||
mutationLock: immediateLock,
|
||||
policy,
|
||||
fetcher: async (request) =>
|
||||
new Response(Uint8Array.from(bodies.get(request.url)!), {
|
||||
headers: {
|
||||
"cache-control": "public",
|
||||
"content-type": "application/javascript",
|
||||
},
|
||||
}),
|
||||
});
|
||||
const publish = async (manifest: PublicCacheReleaseManifest) => {
|
||||
expect(await adapter.admin.stageRelease(manifest)).toMatchObject({
|
||||
ok: true,
|
||||
});
|
||||
expect(
|
||||
await adapter.admin.activateRelease(
|
||||
manifest.releaseRegistryId,
|
||||
manifest.manifestDigestHex,
|
||||
),
|
||||
).toMatchObject({ ok: true });
|
||||
};
|
||||
const markerUrl =
|
||||
"https://assets.example.test/.well-known/ca-public-cache-v1/candidate";
|
||||
let markerReads = 0;
|
||||
const countMarkerReads = (releaseRegistryId: string): void => {
|
||||
const name = [...cacheStorage.caches.keys()].find((key) =>
|
||||
key.includes(`:${releaseRegistryId}:`),
|
||||
)!;
|
||||
const cache = cacheStorage.caches.get(name)!;
|
||||
const match = cache.match.bind(cache);
|
||||
cache.match = async (request: RequestInfo | URL) => {
|
||||
if (request instanceof Request && request.url === markerUrl) {
|
||||
markerReads += 1;
|
||||
}
|
||||
return await match(request);
|
||||
};
|
||||
};
|
||||
const lookup = async (path: string): Promise<number[] | null> => {
|
||||
const match = await adapter.responses.matchActiveExact({
|
||||
absoluteUrl: `https://assets.example.test/${path}`,
|
||||
});
|
||||
if (!match.ok) throw new Error(match.error.code);
|
||||
if (!match.value) return null;
|
||||
const bytes: number[] = [];
|
||||
for await (const chunk of match.value.body.stream(
|
||||
new AbortController().signal,
|
||||
)) {
|
||||
if (chunk.ok) bytes.push(...chunk.value);
|
||||
}
|
||||
return bytes;
|
||||
};
|
||||
|
||||
const first = await release("marker-reuse-1", {
|
||||
"a.js": [1],
|
||||
"b.js": [2, 2],
|
||||
"c.js": [3, 3, 3],
|
||||
});
|
||||
await publish(first);
|
||||
countMarkerReads("marker-reuse-1");
|
||||
|
||||
digests = 0;
|
||||
expect(await lookup("b.js")).toEqual([2, 2]);
|
||||
// First lookup verifies the marker (manifest digest) and the body.
|
||||
expect(markerReads).toBe(1);
|
||||
expect(digests).toBe(2);
|
||||
|
||||
digests = 0;
|
||||
markerReads = 0;
|
||||
expect(await lookup("c.js")).toEqual([3, 3, 3]);
|
||||
expect(await lookup("a.js")).toEqual([1]);
|
||||
expect(await lookup("missing.js")).toBeNull();
|
||||
// Later lookups neither re-read nor re-hash the verified marker; only
|
||||
// each served body is still verified.
|
||||
expect(markerReads).toBe(0);
|
||||
expect(digests).toBe(2);
|
||||
|
||||
// A newly activated release is never answered from the old marker.
|
||||
const second = await release("marker-reuse-2", { "d.js": [4] });
|
||||
await publish(second);
|
||||
expect(await lookup("d.js")).toEqual([4]);
|
||||
expect(await lookup("a.js")).toBeNull();
|
||||
|
||||
// An evicted candidate is still reported even though its marker is known.
|
||||
const secondName = [...cacheStorage.caches.keys()].find((key) =>
|
||||
key.includes(":marker-reuse-2:"),
|
||||
)!;
|
||||
cacheStorage.caches.delete(secondName);
|
||||
expect(
|
||||
await adapter.responses.matchActiveExact({
|
||||
absoluteUrl: "https://assets.example.test/d.js",
|
||||
}),
|
||||
).toMatchObject({ ok: false, error: { code: "STORAGE_EVICTED" } });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user