From 00b12b35b97c1881bea2591c46c615f915aecbb5 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 5 Nov 2026 22:06:55 +0900 Subject: [PATCH] =?UTF-8?q?test(bootstrap):=20=ED=94=8C=EB=9E=AB=ED=8F=BC?= =?UTF-8?q?=20=EA=B7=9C=EC=B9=99=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=91=98?= =?UTF-8?q?=EC=9D=84=20=EC=83=98=ED=94=8C=20=EB=B0=96=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=98=AE=EA=B8=B4=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제 1103 수정이 더한 플랫폼 규칙 테스트 둘이 참조 샘플에 기댄다. 샘플을 지우면 두 테스트가 사라지거나 비어도 test:all과 제거 드릴이 통과한다. - MAX_RETRY_ATTEMPTS가 실행기에 닿는다: 유일한 테스트가 tests/features/reference-feature/reference-runtime-composition.test.ts 에 있다. createRuntimeAdapters는 설치된 기능의 HTTP로만 실행기에 닿아, 기능이 없으면 시험할 길이 없다. REQUEST_TIMEOUT_MS도 같은 모양이다. - 복구 중인 세션은 보호 라우트에서 기다린다: tests/unit/navigation-policy.test.ts는 설치된 보호 라우트를 돌며 단언하는데, 보호 라우트는 모두 샘플 것이라 샘플을 지우면 반복이 0번이다. 고른 방법과 버린 대안 - src/bootstrap/runtime-adapters.ts: 설정 두 값과 auth profile 표로 실행기를 만드는 부분을 createRuntimeContractHttpExecutor로 뺀다. 조립 루트는 이 함수로만 실행기를 만든다. tests/unit/runtime-adapters .test.ts가 테스트 계약(TEST_LIST, 재시도 예산 2)으로 MAX_RETRY_ATTEMPTS 0·1·2에 1·2·3번 나가는지, REQUEST_TIMEOUT_MS 5가 10초 계약을 5ms에 끊는지 본다. 이 파일은 이미 제거 드릴의 공통 테스트 목록에 있다. - tests/unit/session-route-access.test.ts(새 파일): component 테스트와 같은 방법으로 생성 index를 mock해 tests/helpers/fixture-feature.tsx를 설치하고, 보호 라우트 FIXTURE_ITEMS에서 네 세션 상태의 결정을 본다. decideRouteAccess에 라우트 정의를 받는 순수 함수를 따로 두는 안(리뷰 ⓐ)은 버렸다. fixture 기능을 설치하는 방법이 이미 있어서 운영 코드를 바꾸지 않고 실제 getRoute 경로까지 시험할 수 있다. - scripts/test-sample-removal.ts: 새 파일을 공통 테스트 목록에 넣어, 제거 드릴이 그 파일이 남았는지 본다. - 매뉴얼에 "샘플을 지우면 다시 고정한다"고만 적는 안(ⓒ)은 사람이 기억해야 해서 버렸다. 위험·한계 - 조립 루트가 이 함수 대신 실행기를 직접 만들도록 바뀌면 새 unit 테스트는 그걸 모른다. 템플릿 상태에서는 참조 기능 테스트가 계속 조립 루트 전체를 지킨다. - 샘플을 지운 복사본에 변이를 넣어 돌리지는 않았다. 검증 - desktop batch에서 확인: node scripts/run-vitest.ts run tests/unit/runtime-adapters.test.ts tests/unit/session-route-access.test.ts tests/unit/navigation-policy.test.ts tests/features/reference-feature/reference-runtime-composition.test.ts - RED: 부모 커밋의 운영 코드에는 createRuntimeContractHttpExecutor가 없어 runtime-adapters.test.ts의 새 4건이 실패한다. - 변이: 새 함수의 maxRetryAttempts를 상수 2로 바꾸면 "honours MAX_RETRY_ATTEMPTS 0/1"이, navigation-policy.ts의 recovery-pending 분기를 show-sign-in으로 바꾸면 session-route-access.test.ts의 "answers a recovery-pending session …"이 실패해야 한다. Refs: 1105/10-01 --- scripts/test-sample-removal.ts | 4 + src/bootstrap/runtime-adapters.ts | 52 +++++++--- .../reference-runtime-composition.test.ts | 2 + tests/unit/navigation-policy.test.ts | 3 + tests/unit/runtime-adapters.test.ts | 99 ++++++++++++++++++- tests/unit/session-route-access.test.ts | 57 +++++++++++ 6 files changed, 205 insertions(+), 12 deletions(-) create mode 100644 tests/unit/session-route-access.test.ts diff --git a/scripts/test-sample-removal.ts b/scripts/test-sample-removal.ts index 2fe4c041..88173ba0 100644 --- a/scripts/test-sample-removal.ts +++ b/scripts/test-sample-removal.ts @@ -137,7 +137,11 @@ const isSample = featureId in SAMPLE_EXTRAS; const commonTestPaths = [ "tests/unit/external-contract-runtime.test.ts", "tests/unit/http-execution-v3.test.ts", + // 1105/10-01. MAX_RETRY_ATTEMPTS and REQUEST_TIMEOUT_MS reach the executor + // (`createRuntimeContractHttpExecutor`), and a session being recovered waits + // on a session-required route. Before, only sample tests held these rules. "tests/unit/runtime-adapters.test.ts", + "tests/unit/session-route-access.test.ts", "tests/integration/http-execution-v3-observability.test.ts", // 0929/10-02. HTTP scenario evidence (FE-GATE-007) and the feature API // negative type fixtures (FE-GATE-003) run on the test contracts. diff --git a/src/bootstrap/runtime-adapters.ts b/src/bootstrap/runtime-adapters.ts index 995c2e30..340c68a6 100644 --- a/src/bootstrap/runtime-adapters.ts +++ b/src/bootstrap/runtime-adapters.ts @@ -7,6 +7,8 @@ import { import { createDiagnosticsAdapter } from "../adapters/diagnostics/index.ts"; import { createContractHttpExecutor, + type ContractHttpExecutor, + type ContractHttpExecutorDependencies, type HttpExecutionObservation, type InstalledHttpOperationExecutor, } from "../adapters/http/index.ts"; @@ -57,6 +59,7 @@ import { type ReleaseManifest, } from "./load-release-manifest.ts"; import type { RuntimeConfigLoadResult } from "./load-runtime-config.ts"; +import type { RuntimeConfig } from "./runtime-config-schema.ts"; import { createServerStateGenerationStore } from "./server-state-generation-store.ts"; import { composeProduct, @@ -278,6 +281,43 @@ function isTerminalNonAbortFailure( ); } +/** + * 1105/10-01. Where Runtime Config's two HTTP dials reach the V3 executor: + * `MAX_RETRY_ATTEMPTS` caps every contract's retry budget and + * `REQUEST_TIMEOUT_MS` caps every contract's deadline. The composition root + * below builds its executor only through this function. It is a function of + * its own so a platform test can drive the dials without an installed + * feature: `createRuntimeAdapters` reaches the executor only through a + * feature's HTTP, and a product that removed the sample has none + * (tests/unit/runtime-adapters.test.ts). + */ +export function createRuntimeContractHttpExecutor( + config: Pick< + RuntimeConfig, + "API_BASE_URL" | "MAX_RETRY_ATTEMPTS" | "REQUEST_TIMEOUT_MS" + >, + collaborators: Pick< + ContractHttpExecutorDependencies, + "fetcher" | "attachCredentials" | "observe" + >, +): ContractHttpExecutor { + return createContractHttpExecutor({ + baseUrl: config.API_BASE_URL, + maxRetryAttempts: config.MAX_RETRY_ATTEMPTS, + // §6.1. `REQUEST_TIMEOUT_MS` was declared, validated and then dropped on the + // floor here: every V3 operation ran on its contract's own 10s deadline and + // the deployment dial did nothing. It is a ceiling, so it can tighten an + // operation but never loosen one. + requestDeadlineCeilingMs: config.REQUEST_TIMEOUT_MS, + fetcher: collaborators.fetcher, + // §7.7. The installed registry owns Fetch credentials and the exact + // credential-header sets; `attachCredentials` only supplies proof headers. + authProfiles: INSTALLED_REST_AUTH_PROFILES, + attachCredentials: collaborators.attachCredentials, + observe: collaborators.observe, + }); +} + export async function createRuntimeAdapters( context: RuntimeAdaptersContext, ) { @@ -497,18 +537,8 @@ export async function createRuntimeAdapters( diagnostics, telemetry, }); - const contractHttp = createContractHttpExecutor({ - baseUrl: config.API_BASE_URL, - maxRetryAttempts: config.MAX_RETRY_ATTEMPTS, - // §6.1. `REQUEST_TIMEOUT_MS` was declared, validated and then dropped on the - // floor here: every V3 operation ran on its contract's own 10s deadline and - // the deployment dial did nothing. It is a ceiling, so it can tighten an - // operation but never loosen one. - requestDeadlineCeilingMs: config.REQUEST_TIMEOUT_MS, + const contractHttp = createRuntimeContractHttpExecutor(config, { fetcher: context.fetcher, - // §7.7. The installed registry owns Fetch credentials and the exact - // credential-header sets; this collaborator only supplies proof headers. - authProfiles: INSTALLED_REST_AUTH_PROFILES, async attachCredentials(operation, authContext) { if (serverStateScope.getPhase() !== "READY") { return Object.freeze({ kind: "SCOPE_FENCED" as const }); diff --git a/tests/features/reference-feature/reference-runtime-composition.test.ts b/tests/features/reference-feature/reference-runtime-composition.test.ts index 5661d2bd..bc76418f 100644 --- a/tests/features/reference-feature/reference-runtime-composition.test.ts +++ b/tests/features/reference-feature/reference-runtime-composition.test.ts @@ -163,6 +163,8 @@ describe("reference feature runtime composition", () => { // 1103/10-04 ①. MAX_RETRY_ATTEMPTS is the operator's dial over every // contract's retry budget (the list declares 2). Zero must stop retries. + // This drives it through the whole composition; the same rule without the + // sample is in tests/unit/runtime-adapters.test.ts (1105/10-01). it.each([ [0, 1], [1, 2], diff --git a/tests/unit/navigation-policy.test.ts b/tests/unit/navigation-policy.test.ts index c4903c86..cda4480b 100644 --- a/tests/unit/navigation-policy.test.ts +++ b/tests/unit/navigation-policy.test.ts @@ -29,6 +29,9 @@ describe("installed route registry", () => { }); }); + // Every protected route the template installs is the sample's, so this loop + // is empty once a product removes it. session-route-access.test.ts holds the + // same decisions on the platform's fixture feature (1105/10-01). it("treats every non-public route as explicitly session-required", () => { const protectedRoutes = Object.values( ROUTE_REGISTRY as Readonly>, diff --git a/tests/unit/runtime-adapters.test.ts b/tests/unit/runtime-adapters.test.ts index 62f0a561..892e4323 100644 --- a/tests/unit/runtime-adapters.test.ts +++ b/tests/unit/runtime-adapters.test.ts @@ -1,12 +1,17 @@ import { describe, expect, it, vi } from "vitest"; -import { createRuntimeAdapters } from "../../src/bootstrap/runtime-adapters.ts"; +import { + createRuntimeAdapters, + createRuntimeContractHttpExecutor, +} from "../../src/bootstrap/runtime-adapters.ts"; import { createBrowserMutationIntentFactory } from "../../src/adapters/platform/browser-mutation-intent-factory.ts"; import { createApplication } from "../../src/application/create-application.ts"; import type { ApplicationFeatureId } from "../../src/application/ports/in/application-api.ts"; import { loadFeatureRuntime } from "../../src/features/feature-module.ts"; import { INSTALLED_PRODUCT_FEATURE_MODULES } from "../../src/features/installed-product-manifest.ts"; +import { TEST_LIST_HTTP_CONTRACT } from "../helpers/external-contract-fixture.ts"; import { testRuntimeConfig } from "../helpers/runtime-config.ts"; +import { scopeSnapshot } from "../helpers/traffic-test-kit.ts"; type Runtime = Parameters[0]["runtime"]; type Release = Parameters[0]["release"]; @@ -496,3 +501,95 @@ describe("runtime adapter composition", () => { ); }); }); + +/** + * 1105/10-01. Runtime Config's two HTTP dials, on the test contracts. The + * reference feature's composition test drives MAX_RETRY_ATTEMPTS through + * `createRuntimeAdapters`, which needs an installed feature's HTTP. These need + * none, so they stay when a product removes the sample + * (`scripts/test-sample-removal.ts` keeps this file). + */ +describe("runtime contract HTTP executor", () => { + const answerReady = () => ({ kind: "READY" as const, headers: {} }); + + // The test list read is SAFE and declares a retry budget of 2. + it.each([ + [0, 1], + [1, 2], + [2, 3], + ])( + "honours MAX_RETRY_ATTEMPTS %i: a retryable read goes out %i time(s)", + async (maxRetryAttempts, sends) => { + const fetcher = vi.fn(async (_input: RequestInfo | URL) => + Response.json( + { type: "about:blank", title: "temporary", status: 503 }, + { status: 503 }, + ), + ); + // No backoff wait: the jitter is the random draw times a ceiling. + const random = vi.spyOn(Math, "random").mockReturnValue(0); + try { + const executor = createRuntimeContractHttpExecutor( + { ...runtime.config, MAX_RETRY_ATTEMPTS: maxRetryAttempts }, + { fetcher, attachCredentials: answerReady }, + ); + + const outcome = await executor.execute( + TEST_LIST_HTTP_CONTRACT, + { limit: 20 }, + { routeId: "TEST_ROUTE", scope: scopeSnapshot() }, + ); + + expect(outcome.kind).not.toBe("SUCCESS"); + expect(fetcher).toHaveBeenCalledTimes(sends); + } finally { + random.mockRestore(); + } + }, + ); + + // The test list read declares a 10s deadline; REQUEST_TIMEOUT_MS may only + // shorten it. + it("holds a contract's deadline to REQUEST_TIMEOUT_MS", async () => { + vi.useFakeTimers(); + try { + const fetcher = vi.fn( + (_input: RequestInfo | URL, init?: RequestInit) => + new Promise((_resolve, reject) => { + init?.signal?.addEventListener( + "abort", + () => reject(new DOMException("Aborted", "AbortError")), + { once: true }, + ); + }), + ); + const executor = createRuntimeContractHttpExecutor( + { ...runtime.config, MAX_RETRY_ATTEMPTS: 0, REQUEST_TIMEOUT_MS: 5 }, + { fetcher, attachCredentials: answerReady }, + ); + let settled = false; + + const result = executor + .execute( + TEST_LIST_HTTP_CONTRACT, + { limit: 20 }, + { routeId: "TEST_ROUTE", scope: scopeSnapshot() }, + ) + .then((outcome) => { + settled = true; + return outcome; + }); + await vi.advanceTimersByTimeAsync(5); + await Promise.resolve(); + await Promise.resolve(); + + expect(settled).toBe(true); + await expect(result).resolves.toMatchObject({ + kind: "TRANSPORT_FAILURE", + failure: { kind: "TIMEOUT" }, + }); + } finally { + vi.useRealTimers(); + } + }); +}); diff --git a/tests/unit/session-route-access.test.ts b/tests/unit/session-route-access.test.ts new file mode 100644 index 00000000..fcf14e86 --- /dev/null +++ b/tests/unit/session-route-access.test.ts @@ -0,0 +1,57 @@ +import { describe, expect, it, vi } from "vitest"; + +import { getRoute } from "../../src/features/installed-feature-contracts.ts"; +import { decideRouteAccess } from "../../src/presentation/routes/navigation-policy.ts"; + +/** + * 1105/10-01. The route access rule on the platform's own test feature + * (`tests/helpers/fixture-feature.tsx`), not on the removable sample. The + * sample owns every session-required route the template installs, so with it + * removed navigation-policy.test.ts loops over no protected route at all. + * `scripts/test-sample-removal.ts` keeps this file. + */ +vi.mock("../../src/.generated/product-feature-index.ts", async () => ({ + DECLARED_PRODUCT_FEATURE_IDS: ["fixture-feature"], + PRODUCT_FEATURE_MODULES: [ + (await import("../helpers/fixture-feature.tsx")).FIXTURE_FEATURE_MODULE, + ], +})); +vi.mock("../../src/.generated/product-context-index.ts", async () => ({ + PRODUCT_CONTEXT_MODULES: [ + (await import("../helpers/fixture-feature.tsx")).FIXTURE_CONTEXT_MODULE, + ], +})); + +const SESSION_ROUTE = "FIXTURE_ITEMS"; + +describe("route access on an installed session-required route", () => { + it("installs the fixture route as session-required", () => { + expect(getRoute(SESSION_ROUTE).access).toBe("session-required"); + }); + + it.each([ + ["authenticated", { allowed: true, action: "none" }], + ["unauthenticated", { allowed: false, action: "show-sign-in" }], + // 1101/10-03. A session still being recovered waits; showing sign-in + // there would bounce a returning user out of a page they may enter. + ["recovery-pending", { allowed: false, action: "wait-for-session" }], + ["integration-failed", { allowed: false, action: "show-sign-in" }], + ] as const)("answers a %s session with %o", (sessionState, decision) => { + expect(decideRouteAccess(SESSION_ROUTE, sessionState)).toEqual(decision); + }); + + it("lets every session state through a public route", () => { + expect(getRoute("FIXTURE_FIRST_PAGE").access).toBe("public"); + for (const sessionState of [ + "authenticated", + "unauthenticated", + "recovery-pending", + "integration-failed", + ] as const) { + expect(decideRouteAccess("FIXTURE_FIRST_PAGE", sessionState)).toEqual({ + allowed: true, + action: "none", + }); + } + }); +});