diff --git a/docs/architecture/realtime-events-web-push-and-bounded-polling.md b/docs/architecture/realtime-events-web-push-and-bounded-polling.md index 3038cacb..842c6db5 100644 --- a/docs/architecture/realtime-events-web-push-and-bounded-polling.md +++ b/docs/architecture/realtime-events-web-push-and-bounded-polling.md @@ -1547,6 +1547,11 @@ NotificationClickDataV1 -> authoritative notification/resource fetch ``` +registry `path`는 router base path를 뺀 앱 기준 경로다. 정상 click은 그 경로를 +같은 앱 루트 아래에서 연다(`/app/` + `/inbox` → `/app/inbox`). 열린 창에 보내는 +handoff `path`는 registry 값 그대로(`/inbox`)라서 router basename과 겹치지 +않는다(06-01). + route intent가 stale/unknown이면 안전한 notification inbox/home으로 이동한다. notification action 자체에서 destructive 업무 mutation을 실행하려면 별도의 confirmed UI 또는 idempotent authorized server command 설계가 필요하다. diff --git a/src/adapters/web-push/inbound/notification-click-adapter.ts b/src/adapters/web-push/inbound/notification-click-adapter.ts index dba1d551..4faab467 100644 --- a/src/adapters/web-push/inbound/notification-click-adapter.ts +++ b/src/adapters/web-push/inbound/notification-click-adapter.ts @@ -85,8 +85,9 @@ export function createNotificationClickAdapter(dependencies: Readonly<{ clients: WorkerClientsFacade; origin: string; /** - * 06-09. Where a refused click opens: the registration scope, which is the - * router base path. Defaults to the origin root; must be same-origin. + * The registration scope, which is the router base path. A refused click + * opens it (06-09) and an accepted click opens its registry path under it + * (06-01). Defaults to the origin root; must be same-origin. */ appRootUrl?: string; now?: () => number; @@ -114,6 +115,7 @@ export function createNotificationClickAdapter(dependencies: Readonly<{ throw new TypeError("Web Push click adapter configuration is invalid."); } const appRootUrl: string = parsedAppRootUrl; + const appBasePath = new URL(appRootUrl).pathname.replace(/\/$/u, ""); return Object.freeze({ handle(event) { @@ -187,7 +189,8 @@ export function createNotificationClickAdapter(dependencies: Readonly<{ if (!path) { return webPushFailure("CONTRACT_REJECTED", "NOTIFICATION_CLICK"); } - const target = safeTarget(origin, path); + // 06-01. The registry path is an app path; the handoff keeps it as is. + const target = safeTarget(origin, `${appBasePath}${path}`); if (!target) { return webPushFailure("CONTRACT_REJECTED", "NOTIFICATION_CLICK"); } diff --git a/src/adapters/web-push/notification-registry.ts b/src/adapters/web-push/notification-registry.ts index 17c0bbde..09eb0ed1 100644 --- a/src/adapters/web-push/notification-registry.ts +++ b/src/adapters/web-push/notification-registry.ts @@ -19,6 +19,7 @@ export type WebPushNotificationDefinition = Readonly<{ routeIntent: NotificationRouteIntentId; title: string; body: string; + /** App path, without the router base path (`/inbox`, not `/app/inbox`). */ path: string; }>; diff --git a/tests/unit/web-push-worker-runtime.test.ts b/tests/unit/web-push-worker-runtime.test.ts index 0e3bc6d2..093d6e25 100644 --- a/tests/unit/web-push-worker-runtime.test.ts +++ b/tests/unit/web-push-worker-runtime.test.ts @@ -7,7 +7,10 @@ import { import { createPushAssociationFenceStore } from "../../src/adapters/web-push/push-association-fence-store.ts"; import { createWebPushNotificationRegistry } from "../../src/adapters/web-push/notification-registry.ts"; import { createPushEventAdapter } from "../../src/adapters/web-push/inbound/push-event-adapter.ts"; -import { createNotificationClickAdapter } from "../../src/adapters/web-push/inbound/notification-click-adapter.ts"; +import { + createNotificationClickAdapter, + type WindowClientFacade, +} from "../../src/adapters/web-push/inbound/notification-click-adapter.ts"; import { createWebPushServiceWorkerRuntime } from "../../src/adapters/web-push/service-worker-runtime.ts"; import type { TimeoutScheduler } from "../../src/adapters/web-push/runtime-support.ts"; import { @@ -365,6 +368,56 @@ describe("Web Push worker runtime", () => { expect(focus).not.toHaveBeenCalled(); }); + // 06-01. A registry path is an app path: an accepted click opens it + // under the base path, and the handoff keeps the app path for the router. + it("opens an accepted click's route under the base path", async () => { + const store = await activeFence(); + const messages: unknown[] = []; + const openWindow = vi.fn( + async (url: string): Promise => ({ + url, + focus: async () => {}, + postMessage() {}, + }), + ); + let windows: readonly WindowClientFacade[] = []; + const adapter = createNotificationClickAdapter({ + fenceStore: store, + registry, + origin: "https://app.example.test", + appRootUrl: "https://app.example.test/app/", + now: () => now, + clients: { + matchControlledWindowClients: async () => windows, + openWindow, + }, + }); + const click = () => + adapter.handle({ + notification: { data: clickData(), close() {} }, + waitUntil() {}, + }); + + await expect(click()).resolves.toEqual({ ok: true, value: undefined }); + expect(openWindow.mock.calls).toEqual([ + ["https://app.example.test/app/inbox"], + ]); + + windows = [ + { + url: "https://app.example.test/app/current", + focus: async () => {}, + postMessage(message) { + messages.push(message); + }, + }, + ]; + await expect(click()).resolves.toEqual({ ok: true, value: undefined }); + expect(messages).toEqual([ + expect.objectContaining({ path: "/inbox" }), + ]); + }); + describe("a rejected click opens the app root (Q-6.6-11, D-14)", () => { async function rejectedClick( options: Readonly<{ at?: number; data?: unknown }>,