feat(bootstrap): 제품이 세션과 함께 닫을 것을 scopeParticipants로 넘긴다
문제: browser-files runtime은 세션을 모르고, 닫는 수단은 runtime.dispose() 하나다. 설계 문서는 로그아웃·계정 전환에 "server-state scope reset participant로 dispose()를 등록하라"며 템플릿 소유 파일 runtime-adapters.ts를 가리키는데, 매뉴얼은 제품이 그 파일을 고치지 않는다고 한다(09-02). 제품 확장 지점 composeProduct는 부팅 때 한 번 불리고, context에 participant 등록도 lifecycle 구독도 없다. 그래서 연결하지 않으면 이전 사용자가 고른 File, preview blob URL, 진행 중 download가 다음 세션까지 남는다(공유 기기에서 이전 사용자 파일이 메모리와 다운로드 폴더에 남을 수 있다). 고른 방법(리뷰 5.3절 (다) + 레시피 예제): - ProductComposition에 선택 칸 scopeParticipants(ProductScopeParticipant: label, close)를 둔다. 템플릿은 scope reset의 §10.6 10단계(offline lease 해제) 자리에 "product" participant 하나를 두고, composeProduct가 돌려준 것을 순서대로 부른다. 하나가 실패해도 나머지를 부르고, 실패가 있으면 template participant와 같이 READY로 가지 않는다(FAILED). composeProduct는 scope가 생긴 뒤 불리므로(context가 fence를 쓴다) 이 자리를 미리 만들고 나중에 채운다. - recipes/frontend-capabilities/browser-file-session-capability.ts: 기능에는 runtime 대신 current() getter를 주고, participant가 dispose한 뒤 다음 호출에서 새 runtime을 만든다. indexeddb 레시피와 같은 자리다. - 설계 문서와 매뉴얼 03 C절이 이 방법을 가리킨다. 제거 드릴이 새 레시피 파일도 같이 지운다. 버린 대안: (가) 문서만 고침 — feature presentation은 adapter를 만들 수 없어 제품마다 factory를 다시 설계한다. (나) context에 lifecycle 구독 위임 — FENCED → participant → READY 순서와 "실패는 READY를 막는다"를 제품이 직접 지켜야 한다. (라) runtime이 세대 AbortSignal을 받음 — adapter가 세대를 알게 되고 다른 opt-in runtime도 따로 받아야 한다. 위험·한계: - 제품 계약 표면이 하나 는다(선택 칸이라 기존 제품 파일은 그대로 컴파일된다, [계약]). - 기능은 current()를 작업마다 불러야 한다. 이전 세대에서 받은 runtime을 들고 있으면 UNAVAILABLE을 받는다. FENCED 동안 current()를 부르면 다음 세대 runtime이 미리 만들어진다(빈 runtime이라 이전 사용자 데이터는 없다). - app dispose(infrastructure.dispose)는 제품 participant를 부르지 않는다. - 실제 브라우저 2탭 로그아웃 E2E는 없다(조립된 화면이 없다). - scripts/test-browser-file-storage-runtime-removal.ts는 02-06 담당 작업도 고칠 수 있는 파일이다. runtimePaths에 한 줄만 더했다. 검증: - RED: tests/recipes/browser-file-session-capability.test.ts가 계정 전환 뒤에도 이전 runtime의 readRange가 ok로 실패. - GREEN: 같은 테스트에서 계정 전환 뒤 ① 이전 runtime readRange UNAVAILABLE ② 진행 중 bounded download ABORTED, handoff 0회 ③ 새 세대 runtime의 파일 선택 SELECTED. tests/unit/runtime-adapters-product-scope- participants.test.ts 2건(순서, 실패 시 FAILED와 나머지 실행). - 변이 4개(등록 누락, 실패 삼킴, 첫 실패에서 멈춤, 레시피 dispose 누락) 모두 새 테스트가 잡았다. - runtime-adapters 관련 unit 3파일 + tests/recipes 47건 통과. check:types, 바꾼 파일 eslint, check:architecture, verify:documentation 통과. Refs: docs/reviews/2026-11-03-maturity-review/02-adapters-browser-files-cache.md 02-01
This commit is contained in:
@@ -55,10 +55,29 @@ export type ProductCompositionContext = Readonly<{
|
||||
isScopeReady(): boolean;
|
||||
}>;
|
||||
|
||||
/**
|
||||
* 2026-11-03 02-01. Something a product built that must not outlive a session,
|
||||
* such as a browser file runtime holding the previous user's files. The
|
||||
* template closes it on every sign-out and account switch, after FENCED and
|
||||
* before READY, at the step that releases offline leases. A close that throws
|
||||
* or rejects keeps the scope from reaching READY, as the template's own do.
|
||||
*/
|
||||
export type ProductScopeParticipant = Readonly<{
|
||||
label: string;
|
||||
close(): void | Promise<void>;
|
||||
}>;
|
||||
|
||||
export type ProductComposition = Readonly<{
|
||||
capabilities: Readonly<
|
||||
Partial<Omit<FeaturePlatformCapabilities, TemplatePlatformCapabilityId>>
|
||||
>;
|
||||
/** Auth profile id → provider. An ANONYMOUS profile never reaches one. */
|
||||
credentialProviders: Readonly<Record<string, ProductCredentialProvider>>;
|
||||
/**
|
||||
* Closed in this order on each identity change. A capability that needs a
|
||||
* fresh object for the next session hands features a getter and rebuilds
|
||||
* behind it, as `recipes/frontend-capabilities/browser-file-session-capability.ts`
|
||||
* does.
|
||||
*/
|
||||
scopeParticipants?: readonly ProductScopeParticipant[];
|
||||
}>;
|
||||
|
||||
@@ -62,7 +62,10 @@ import {
|
||||
composeProduct,
|
||||
composeProductSessionOwner,
|
||||
} from "./product-composition.ts";
|
||||
import type { ProductComposition } from "./product-composition-contract.ts";
|
||||
import type {
|
||||
ProductComposition,
|
||||
ProductScopeParticipant,
|
||||
} from "./product-composition-contract.ts";
|
||||
import { createInstalledContractRegistry } from "../features/installed-contract-contributions.ts";
|
||||
import {
|
||||
indexInvalidationRegistry,
|
||||
@@ -377,6 +380,11 @@ export async function createRuntimeAdapters(
|
||||
crossContextInvalidation?.getStatus() ?? "DEGRADED_LOCAL_ONLY",
|
||||
});
|
||||
});
|
||||
// 2026-11-03 02-01. The product's closers. `composeProduct` runs after the
|
||||
// scope exists (its context needs the fence), so they join through this one
|
||||
// slot, filled below. Each runs even when an earlier one fails, and any
|
||||
// failure keeps the scope from READY, as for the template's own.
|
||||
const productScopeParticipants: ProductScopeParticipant[] = [];
|
||||
const serverStateScope = createServerStateScopeRuntime({
|
||||
session: authSession,
|
||||
diagnostics,
|
||||
@@ -389,6 +397,21 @@ export async function createRuntimeAdapters(
|
||||
label: "conditional-validators",
|
||||
close: () => conditionalValidators.clear(),
|
||||
},
|
||||
{
|
||||
order: 10,
|
||||
label: "product",
|
||||
async close() {
|
||||
let failed = false;
|
||||
for (const participant of productScopeParticipants) {
|
||||
try {
|
||||
await participant.close();
|
||||
} catch {
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
if (failed) throw new Error("A product scope participant failed.");
|
||||
},
|
||||
},
|
||||
],
|
||||
activateNextGeneration: () => serverStateGeneration.activateNext(),
|
||||
});
|
||||
@@ -615,6 +638,10 @@ export async function createRuntimeAdapters(
|
||||
}) satisfies ProductComposition;
|
||||
const productCredentialProviders: ProductComposition["credentialProviders"] =
|
||||
product.credentialProviders;
|
||||
// `product` keeps its narrow type above so a missing capability still fails
|
||||
// the typecheck; the optional field is read through the contract type.
|
||||
const composedProduct: ProductComposition = product;
|
||||
productScopeParticipants.push(...(composedProduct.scopeParticipants ?? []));
|
||||
// Each installed contribution receives only the capabilities it declares.
|
||||
// The template's own capabilities come last, so a product cannot replace
|
||||
// them. 09-05. `indexedDb` is not built here: IndexedDB is an opt-in
|
||||
|
||||
Reference in New Issue
Block a user