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)
419 lines
13 KiB
TypeScript
419 lines
13 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
WEB_PUSH_PROTOCOLS,
|
|
webPushSuccess,
|
|
} from "../../src/contracts/web-push.ts";
|
|
import {
|
|
clickDataFromHint,
|
|
decodeNotificationClickData,
|
|
decodeWebPushHint,
|
|
} from "../../src/adapters/web-push/push-codec.ts";
|
|
import {
|
|
createAssociationNotificationTag,
|
|
createWebPushNotificationRegistry,
|
|
} from "../../src/adapters/web-push/notification-registry.ts";
|
|
import {
|
|
WEB_PUSH_REGISTRATION_OPERATIONS,
|
|
createWebPushRegistrationGateway,
|
|
type WebPushRegistrationExecutor,
|
|
} from "../../src/adapters/web-push/push-registration-gateway.ts";
|
|
import { createPushAssociationFenceStore } from "../../src/adapters/web-push/push-association-fence-store.ts";
|
|
import { createWebPushSubscriptionAdapter } from "../../src/adapters/web-push/push-subscription-adapter.ts";
|
|
import { createFakePushControlStoreDependencies } from "../helpers/fake-push-control-repository.ts";
|
|
import {
|
|
base64UrlDecode,
|
|
base64UrlEncode,
|
|
} from "../../src/adapters/web-push/codec-primitives.ts";
|
|
|
|
const now = Date.parse("2026-07-28T00:00:00.000Z");
|
|
|
|
function hint(overrides: Readonly<Record<string, unknown>> = {}) {
|
|
return {
|
|
protocol: WEB_PUSH_PROTOCOLS.hint,
|
|
notificationType: "INBOX_ACTIVITY",
|
|
notificationId: "notification_01",
|
|
associationEpoch: "association_01",
|
|
releaseEpoch: "release_01",
|
|
issuedAt: "2026-07-27T23:59:00.000Z",
|
|
expiresAt: "2026-07-28T01:00:00.000Z",
|
|
routeIntent: "OPEN_INBOX",
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function encoded(value: unknown): Uint8Array {
|
|
return new TextEncoder().encode(JSON.stringify(value));
|
|
}
|
|
|
|
describe("Web Push contracts", () => {
|
|
it("decodes an exact bounded hint and persists only typed click data", () => {
|
|
const decoded = decodeWebPushHint(encoded(hint()), now);
|
|
expect(decoded).toEqual({ ok: true, value: hint() });
|
|
if (!decoded.ok) throw new Error("expected a decoded hint");
|
|
|
|
const click = clickDataFromHint(decoded.value);
|
|
expect(decodeNotificationClickData(click, now)).toEqual({
|
|
ok: true,
|
|
value: click,
|
|
});
|
|
expect(click).not.toHaveProperty("notificationType");
|
|
expect(click).not.toHaveProperty("issuedAt");
|
|
});
|
|
|
|
it("fails closed for declarative, unknown, expired, and oversized payloads", () => {
|
|
expect(
|
|
decodeWebPushHint(encoded({ web_push: 8030 }), now),
|
|
).toMatchObject({
|
|
ok: false,
|
|
error: { code: "DECLARATIVE_PUSH_FORBIDDEN" },
|
|
});
|
|
expect(
|
|
decodeWebPushHint(encoded(hint({ unexpected: true })), now),
|
|
).toMatchObject({
|
|
ok: false,
|
|
error: { code: "CONTRACT_REJECTED" },
|
|
});
|
|
expect(
|
|
decodeWebPushHint(
|
|
encoded(
|
|
hint({
|
|
issuedAt: "2026-07-27T22:00:00.000Z",
|
|
expiresAt: "2026-07-27T23:00:00.000Z",
|
|
}),
|
|
),
|
|
now,
|
|
),
|
|
).toMatchObject({
|
|
ok: false,
|
|
error: { code: "EXPIRED" },
|
|
});
|
|
expect(
|
|
decodeWebPushHint(new Uint8Array(3 * 1024 + 1), now),
|
|
).toMatchObject({
|
|
ok: false,
|
|
error: { code: "LIMIT_EXCEEDED" },
|
|
});
|
|
expect(
|
|
decodeWebPushHint(
|
|
encoded(
|
|
hint({
|
|
issuedAt: "2026-07-28T00:06:00.000Z",
|
|
expiresAt: "2026-07-28T01:00:00.000Z",
|
|
}),
|
|
),
|
|
now,
|
|
),
|
|
).toMatchObject({
|
|
ok: false,
|
|
error: { code: "CONTRACT_REJECTED" },
|
|
});
|
|
expect(
|
|
decodeWebPushHint(
|
|
encoded(
|
|
hint({
|
|
issuedAt: "2026-07-28T00:00:00.000Z",
|
|
expiresAt: "2026-07-29T00:00:00.001Z",
|
|
}),
|
|
),
|
|
now,
|
|
),
|
|
).toMatchObject({
|
|
ok: false,
|
|
error: { code: "CONTRACT_REJECTED" },
|
|
});
|
|
const duplicateNotificationId = JSON.stringify(hint()).replace(
|
|
'"notificationId":"notification_01"',
|
|
'"notificationId":"notification_old","notificationId":"notification_01"',
|
|
);
|
|
expect(
|
|
decodeWebPushHint(
|
|
new TextEncoder().encode(duplicateNotificationId),
|
|
now,
|
|
),
|
|
).toMatchObject({
|
|
ok: false,
|
|
error: { code: "CONTRACT_REJECTED" },
|
|
});
|
|
});
|
|
|
|
it("rejects duplicate keys at any depth without a nesting budget", () => {
|
|
const deepDeclarative = {
|
|
web_push: 8030,
|
|
notification: { title: "t", data: { a: [[[[{ b: 1 }]]]] } },
|
|
};
|
|
expect(
|
|
decodeWebPushHint(encoded(deepDeclarative), now),
|
|
).toMatchObject({
|
|
ok: false,
|
|
error: { code: "DECLARATIVE_PUSH_FORBIDDEN" },
|
|
});
|
|
const nestedDuplicate = JSON.stringify(deepDeclarative).replace(
|
|
'"title":"t"',
|
|
'"title":"t","title":"u"',
|
|
);
|
|
expect(
|
|
decodeWebPushHint(new TextEncoder().encode(nestedDuplicate), now),
|
|
).toMatchObject({
|
|
ok: false,
|
|
error: { code: "CONTRACT_REJECTED" },
|
|
});
|
|
});
|
|
|
|
it("uses an injected closed notification and route registry", async () => {
|
|
const registry = createWebPushNotificationRegistry([
|
|
{
|
|
notificationType: "INBOX_ACTIVITY",
|
|
routeIntent: "OPEN_INBOX",
|
|
title: "새 알림이 있습니다",
|
|
body: "앱을 열어 최신 내용을 확인하세요.",
|
|
path: "/inbox",
|
|
},
|
|
]);
|
|
expect(
|
|
registry.resolve("INBOX_ACTIVITY", "OPEN_INBOX"),
|
|
).toMatchObject({ path: "/inbox" });
|
|
expect(registry.resolve("UNKNOWN", "OPEN_INBOX")).toBeNull();
|
|
expect(registry.routePath("OPEN_INBOX")).toBe("/inbox");
|
|
|
|
const tag = await createAssociationNotificationTag(
|
|
"association_01",
|
|
"INBOX_ACTIVITY",
|
|
async () => new Uint8Array(32).fill(7).buffer,
|
|
);
|
|
expect(tag).toMatch(/^ca-push-v1-[0-9a-f]{24}-inbox_activity$/u);
|
|
expect(tag).not.toContain("association_01");
|
|
});
|
|
|
|
it("binds backend calls to fixed operations and strict response codecs", async () => {
|
|
const calls: Array<Readonly<{ operationId: string; body: unknown }>> = [];
|
|
const executor: WebPushRegistrationExecutor = {
|
|
async execute(input) {
|
|
calls.push(input);
|
|
switch (input.operationId) {
|
|
case WEB_PUSH_REGISTRATION_OPERATIONS.register:
|
|
return webPushSuccess({
|
|
protocol: WEB_PUSH_PROTOCOLS.registration,
|
|
associationEpoch: "association_01",
|
|
sessionBindingEpoch: "session_01",
|
|
});
|
|
case WEB_PUSH_REGISTRATION_OPERATIONS.reconcile:
|
|
return webPushSuccess({
|
|
protocol: WEB_PUSH_PROTOCOLS.reconciliation,
|
|
state: "ABSENT",
|
|
});
|
|
case WEB_PUSH_REGISTRATION_OPERATIONS.revoke:
|
|
return webPushSuccess({
|
|
protocol: WEB_PUSH_PROTOCOLS.revoke,
|
|
state: "ALREADY_GONE",
|
|
});
|
|
}
|
|
},
|
|
};
|
|
const gateway = createWebPushRegistrationGateway(executor);
|
|
const p256dh = new Uint8Array(65);
|
|
p256dh[0] = 4;
|
|
const material = {
|
|
endpoint: "https://push.example.test/subscription/opaque",
|
|
p256dh: Buffer.from(p256dh).toString("base64url"),
|
|
auth: Buffer.from(new Uint8Array(16)).toString("base64url"),
|
|
expirationTime: null,
|
|
};
|
|
const authority = {
|
|
fenceGeneration: "fence_01",
|
|
sessionBindingEpoch: "session_01",
|
|
releaseEpoch: "release_01",
|
|
};
|
|
|
|
expect(
|
|
await gateway.register({
|
|
material,
|
|
authority,
|
|
idempotencyKey: "idempotency_01",
|
|
}),
|
|
).toEqual({
|
|
ok: true,
|
|
value: {
|
|
associationEpoch: "association_01",
|
|
sessionBindingEpoch: "session_01",
|
|
},
|
|
});
|
|
expect(await gateway.reconcile({ material, authority })).toEqual({
|
|
ok: true,
|
|
value: { state: "ABSENT" },
|
|
});
|
|
expect(
|
|
await gateway.revoke({ associationEpoch: "association_01" }),
|
|
).toEqual({
|
|
ok: true,
|
|
value: { state: "ALREADY_GONE" },
|
|
});
|
|
expect(calls.map((call) => call.operationId)).toEqual([
|
|
WEB_PUSH_REGISTRATION_OPERATIONS.register,
|
|
WEB_PUSH_REGISTRATION_OPERATIONS.reconcile,
|
|
WEB_PUSH_REGISTRATION_OPERATIONS.revoke,
|
|
]);
|
|
expect(
|
|
await gateway.register({
|
|
material: {
|
|
...material,
|
|
p256dh: Buffer.from(new Uint8Array(65)).toString(
|
|
"base64url",
|
|
),
|
|
},
|
|
authority,
|
|
idempotencyKey: "idempotency_02",
|
|
}),
|
|
).toMatchObject({
|
|
ok: false,
|
|
error: { code: "INVALID_INPUT" },
|
|
});
|
|
const throwing = createWebPushRegistrationGateway({
|
|
async execute() {
|
|
throw new Error("native transport detail must not escape");
|
|
},
|
|
});
|
|
expect(
|
|
await throwing.revoke({
|
|
associationEpoch: "association_01",
|
|
}),
|
|
).toMatchObject({
|
|
ok: false,
|
|
error: { code: "NATIVE_FAILURE" },
|
|
});
|
|
});
|
|
});
|
|
|
|
/**
|
|
* Q-6.6-12. The web-push files each carried their own base64url decoder,
|
|
* opaque-id pattern, authority check and exact-record check. These pin what
|
|
* every caller observes, so merging them into one module cannot loosen any.
|
|
*/
|
|
describe("web-push codec primitives as seen by their callers (Q-6.6-12)", () => {
|
|
const authority = {
|
|
fenceGeneration: "fence_01",
|
|
sessionBindingEpoch: "session_01",
|
|
releaseEpoch: "release_01",
|
|
};
|
|
const p256dhBytes = new Uint8Array(65);
|
|
p256dhBytes[0] = 4;
|
|
const material = {
|
|
endpoint: "https://push.example.test/subscription/opaque",
|
|
p256dh: Buffer.from(p256dhBytes).toString("base64url"),
|
|
auth: Buffer.from(new Uint8Array(16)).toString("base64url"),
|
|
expirationTime: null,
|
|
};
|
|
/** 87 chars carry 2 spare bits and 22 chars carry 4; they must be zero. */
|
|
const withSpareBitSet = (encoded: string) =>
|
|
`${encoded.slice(0, -1)}${encoded.endsWith("A") ? "B" : "A"}`;
|
|
const registered: WebPushRegistrationExecutor = {
|
|
async execute() {
|
|
return webPushSuccess({
|
|
protocol: WEB_PUSH_PROTOCOLS.registration,
|
|
associationEpoch: "association_01",
|
|
sessionBindingEpoch: "session_01",
|
|
});
|
|
},
|
|
};
|
|
|
|
it("rejects subscription keys whose spare base64url bits are set", async () => {
|
|
const gateway = createWebPushRegistrationGateway(registered);
|
|
for (const broken of [
|
|
{ ...material, p256dh: withSpareBitSet(material.p256dh) },
|
|
{ ...material, auth: withSpareBitSet(material.auth) },
|
|
]) {
|
|
expect(
|
|
await gateway.register({
|
|
material: broken,
|
|
authority,
|
|
idempotencyKey: "idempotency_01",
|
|
}),
|
|
).toMatchObject({ ok: false, error: { code: "INVALID_INPUT" } });
|
|
}
|
|
});
|
|
|
|
it("rejects a VAPID key whose spare base64url bits are set", () => {
|
|
const key = new Uint8Array(65);
|
|
key[0] = 4;
|
|
const valid = Buffer.from(key).toString("base64url");
|
|
expect(() =>
|
|
createWebPushSubscriptionAdapter({
|
|
vapidPublicKey: withSpareBitSet(valid),
|
|
} as never),
|
|
).toThrow(TypeError);
|
|
});
|
|
|
|
it("rejects a null authority as invalid input in the fence store", async () => {
|
|
const store = createPushAssociationFenceStore(
|
|
createFakePushControlStoreDependencies(),
|
|
);
|
|
expect(
|
|
await store.prepare({
|
|
authority: null as never,
|
|
updatedAt: "2026-07-28T00:00:00.000Z",
|
|
}),
|
|
).toMatchObject({ ok: false, error: { code: "INVALID_INPUT" } });
|
|
});
|
|
|
|
it("rejects a null authority as invalid input in the gateway", async () => {
|
|
const gateway = createWebPushRegistrationGateway(registered);
|
|
await expect(
|
|
gateway.register({
|
|
material,
|
|
authority: null as never,
|
|
idempotencyKey: "idempotency_01",
|
|
}),
|
|
).resolves.toMatchObject({ ok: false, error: { code: "INVALID_INPUT" } });
|
|
await expect(
|
|
gateway.reconcile({ material, authority: null as never }),
|
|
).resolves.toMatchObject({ ok: false, error: { code: "INVALID_INPUT" } });
|
|
});
|
|
|
|
it("rejects backend answers that are arrays or carry extra keys", async () => {
|
|
for (const answer of [
|
|
[WEB_PUSH_PROTOCOLS.revoke, "REVOKED"],
|
|
{ protocol: WEB_PUSH_PROTOCOLS.revoke, state: "REVOKED", extra: 1 },
|
|
]) {
|
|
const gateway = createWebPushRegistrationGateway({
|
|
execute: async () => webPushSuccess(answer),
|
|
});
|
|
expect(
|
|
await gateway.revoke({ associationEpoch: "association_01" }),
|
|
).toMatchObject({ ok: false, error: { code: "CONTRACT_REJECTED" } });
|
|
}
|
|
});
|
|
|
|
it("gives every accepted base64url string exactly one decoding", () => {
|
|
expect([...base64UrlDecode("AQID")!]).toEqual([1, 2, 3]);
|
|
expect([...base64UrlDecode("AQ")!]).toEqual([1]);
|
|
expect(base64UrlDecode("")?.byteLength).toBe(0);
|
|
// "AQIDA": a lone trailing character cannot finish a byte. The window
|
|
// adapter's old copy accepted it because its spare bits were zero.
|
|
for (const invalid of ["A", "AQIDA", "AR", "AQ==", "AQ+/", null, 7]) {
|
|
expect(base64UrlDecode(invalid), String(invalid)).toBeNull();
|
|
}
|
|
});
|
|
|
|
it("encodes base64url exactly like Node and round-trips through the decoder", () => {
|
|
for (let length = 0; length <= 66; length += 1) {
|
|
const bytes = Uint8Array.from({ length }, (_, index) => (index * 37 + 11) & 255);
|
|
const encoded = base64UrlEncode(bytes);
|
|
expect(encoded).toBe(Buffer.from(bytes).toString("base64url"));
|
|
expect([...base64UrlDecode(encoded)!]).toEqual([...bytes]);
|
|
}
|
|
});
|
|
|
|
it("rejects opaque ids outside the shared pattern", async () => {
|
|
const gateway = createWebPushRegistrationGateway(registered);
|
|
for (const associationEpoch of ["", "-leading", "a b", "a".repeat(129)]) {
|
|
expect(await gateway.revoke({ associationEpoch })).toMatchObject({
|
|
ok: false,
|
|
error: { code: "INVALID_INPUT" },
|
|
});
|
|
}
|
|
expect(
|
|
decodeWebPushHint(encoded(hint({ notificationId: "a b" })), now),
|
|
).toMatchObject({ ok: false });
|
|
});
|
|
});
|