From e6b2a4f6bfb377b34afb3c498863d1ae265bad17 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 5 Nov 2026 23:10:40 +0900 Subject: [PATCH] =?UTF-8?q?fix(manual):=20=EC=A7=9D=20=EB=B0=B1=EC=97=94?= =?UTF-8?q?=EB=93=9C=20OIDC=20=EC=84=A4=EC=A0=95=20=ED=82=A4=20=EC=98=88?= =?UTF-8?q?=EC=8B=9C=EC=9D=98=20FE-REG-ENV=20=ED=96=89=EC=97=90=20defaultV?= =?UTF-8?q?alue=EB=A5=BC=20=EC=A0=81=EB=8A=94=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제 매뉴얼 04 §3.2의 PRODUCT_ENV_REGISTRY 예시 두 행(OIDC_ISSUER, OIDC_CLIENT_ID)에 defaultValue가 없다. 행 타입은 defaultValue를 필수 칸으로 가진다(src/contracts/env.ts). 그래서 제품이 그대로 붙이면 check:types:app이 env.ts에서 TS2322로, env-registry-coverage가 `row {"required":false}`로 실패한다(리뷰 14-R3). 매뉴얼 03 C절과 product-contracts.ts 주석은 defaultValue를 쓴다. 고른 방법 - 두 행에 `defaultValue: null`을 더하고(.optional() 키), 행 칸의 규칙을 예시 아래 한 줄로 적었다. - 테스트 tests/unit/manual-paired-backend-settings.test.ts: 매뉴얼 §3.2의 ts 블록을 그대로 저장소 사본의 새 파일로 두고, 사본의 product-contracts.ts가 제품 자신의 파일(옆에 보존)에 그 키를 더해 내보낸다. 그 사본에서 tsconfig.app.json 타입 검사와, env-registry-coverage와 같은 행 대조(키가 없을 때 스키마가 내는 required·defaultValue)를 node로 돌린다. 제품 파일을 덮어쓰지 않으므로 다운스트림에서도 그대로 돈다(1105/09-01과 같은 방식). - 문서를 읽는 테스트라 REMOVAL_FIXTURE_DOCUMENT_TESTS에 더했다. 그 목록의 항목이 문서를 읽는지 보는 removal-fixture.test.ts 정규식에 `docs/`를 더했다. 문서 대상(REMOVAL_FIXTURE_DOCUMENT_TARGETS)에 docs가 있어 README나 CHANGELOG를 읽지 않는 문서 테스트도 있을 수 있다. 목록의 뜻은 그대로다. - 버린 대안: 예시 행을 recipe에서 export하고 recipe 테스트가 그것으로 조립하기(리뷰 ②). contracts가 recipe를 import할 수 없어 매뉴얼이 다시 복사를 시킨다. 이번 테스트가 매뉴얼 블록 자체를 지킨다. 위험·한계 - 행 대조는 env-registry-coverage의 schemaDeclaration을 이 테스트 안에 다시 적었다(사본에서 vitest를 띄우지 않으려고). 규칙이 바뀌면 둘을 함께 고친다. - §3.3·§4.3의 코드 예시는 여전히 컴파일하지 않는다(recipe를 복사한 뒤의 모양이라 사본 구성이 더 크다). - 테스트가 저장소 사본을 만들고 tsc app 프로그램을 돈다. test:unit이 몇 초 는다. 검증 - desktop batch에서 확인: node scripts/run-vitest.ts run tests/unit/manual-paired-backend-settings.test.ts tests/unit/removal-fixture.test.ts, corepack pnpm verify:documentation Refs: 1105/14-02 --- docs/manual/04-paired-backend-session.md | 5 +- scripts/lib/removal-fixture.ts | 2 + .../manual-paired-backend-settings.test.ts | 145 ++++++++++++++++++ tests/unit/removal-fixture.test.ts | 3 +- 4 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 tests/unit/manual-paired-backend-settings.test.ts diff --git a/docs/manual/04-paired-backend-session.md b/docs/manual/04-paired-backend-session.md index a09a40c8..9a9b6b2c 100644 --- a/docs/manual/04-paired-backend-session.md +++ b/docs/manual/04-paired-backend-session.md @@ -126,12 +126,13 @@ export const PRODUCT_RUNTIME_CONFIG_FIELDS = Object.freeze({ }); export const PRODUCT_ENV_REGISTRY = Object.freeze({ - OIDC_ISSUER: { phase: "runtime", classification: "public", required: false }, - OIDC_CLIENT_ID: { phase: "runtime", classification: "public", required: false }, + OIDC_ISSUER: { phase: "runtime", classification: "public", required: false, defaultValue: null }, + OIDC_CLIENT_ID: { phase: "runtime", classification: "public", required: false, defaultValue: null }, } as const); ``` - `.optional()`로 둔다. 값이 비면 owner는 `integration-failed`로 닫힌다. 잘못된 곳으로 로그인하지 않는다. +- 행의 `required`·`defaultValue`는 그 키가 없을 때 스키마가 하는 것과 같아야 한다. `.optional()`이면 `required: false, defaultValue: null`이다(`tests/unit/env-registry-coverage.test.ts`). 이 블록은 그대로 `tests/unit/manual-paired-backend-settings.test.ts`가 타입 검사와 그 대조를 돌린다. - `config/runtime/local.json`에 `"OIDC_ISSUER": "http://localhost:8081/realms/ca-skeleton"`, `"OIDC_CLIENT_ID": "ca-frontend"`를 더한다. - `OIDC_ISSUER`는 백엔드 `APP_SECURITY_JWT_ISSUER`와 글자 하나까지 같아야 한다. 끝의 `/`도 같아야 한다. - 원격 issuer는 HTTPS만 받는다. HTTP는 `localhost`, `127.0.0.1`, `[::1]`에서만 받는다. diff --git a/scripts/lib/removal-fixture.ts b/scripts/lib/removal-fixture.ts index e892a57c..2eee70cf 100644 --- a/scripts/lib/removal-fixture.ts +++ b/scripts/lib/removal-fixture.ts @@ -76,6 +76,8 @@ export const REMOVAL_FIXTURE_DOCUMENT_TESTS = Object.freeze([ "tests/unit/feature-tracked-files.test.ts", // 1105/14-01 "tests/unit/template-feature-removal-documents.test.ts", + // 1105/14-02. Reads a code block of docs/manual. + "tests/unit/manual-paired-backend-settings.test.ts", ] as const); /** The tests a fixture copied from `copyTargets` cannot run. */ diff --git a/tests/unit/manual-paired-backend-settings.test.ts b/tests/unit/manual-paired-backend-settings.test.ts new file mode 100644 index 00000000..8615b9e3 --- /dev/null +++ b/tests/unit/manual-paired-backend-settings.test.ts @@ -0,0 +1,145 @@ +import { spawnSync } from "node:child_process"; +import { existsSync } from "node:fs"; +import { cp, mkdtemp, readFile, rename, rm, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import path from "node:path"; + +import { afterAll, describe, expect, it } from "vitest"; + +import { linkFixtureNodeModules } from "../../scripts/lib/fixture-node-modules.ts"; +import { REMOVAL_FIXTURE_COPY_TARGETS } from "../../scripts/lib/removal-fixture.ts"; + +/** + * 1105/14-02. docs/manual/04-paired-backend-session.md §3.2 is the block a + * product pastes into src/contracts/product-contracts.ts for the OIDC + * settings of the paired backend's jwt mode. Its FE-REG-ENV rows had no + * `defaultValue`, so pasted as written `check:types` failed (TS2322 in + * src/contracts/env.ts) and so did env-registry-coverage. This puts the + * block, unchanged, into a copy of the repository next to the product's own + * settings and runs the app typecheck program and that row check on it. + */ +const MANUAL = "docs/manual/04-paired-backend-session.md"; +const PRODUCT_CONTRACTS = "src/contracts/product-contracts.ts"; +/** Reserved for this test, so a product's own files are never overwritten. */ +const MANUAL_SETTINGS = "src/contracts/manual-04-product-settings.ts"; +const KEPT_CONTRACTS = "src/contracts/manual-04-kept-product-contracts.ts"; +const ROW_CHECK = "manual-04-env-rows.ts"; + +/** The first ts block of the manual's §3.2. */ +function settingsBlock(manual: string): string { + const section = manual.split(/^### 3\.2 /mu)[1]?.split(/^### /mu)[0] ?? ""; + const block = /```ts\n([\s\S]*?)\n```/u.exec(section)?.[1]; + if (block === undefined) throw new Error(`${MANUAL} §3.2 has no ts block`); + return `${block}\n`; +} + +/** product-contracts.ts: the product's own file, kept beside it, plus the manual's keys. */ +const PRODUCT_CONTRACTS_SOURCE = `import { + PRODUCT_ENV_REGISTRY as KEPT_PRODUCT_ENV_REGISTRY, + PRODUCT_RUNTIME_CONFIG_FIELDS as KEPT_PRODUCT_RUNTIME_CONFIG_FIELDS, +} from "./${path.posix.basename(KEPT_CONTRACTS)}"; +import { + PRODUCT_ENV_REGISTRY as MANUAL_PRODUCT_ENV_REGISTRY, + PRODUCT_RUNTIME_CONFIG_FIELDS as MANUAL_PRODUCT_RUNTIME_CONFIG_FIELDS, +} from "./${path.posix.basename(MANUAL_SETTINGS)}"; + +export * from "./${path.posix.basename(KEPT_CONTRACTS)}"; + +export const PRODUCT_RUNTIME_CONFIG_FIELDS = Object.freeze({ + ...KEPT_PRODUCT_RUNTIME_CONFIG_FIELDS, + ...MANUAL_PRODUCT_RUNTIME_CONFIG_FIELDS, +}); + +export const PRODUCT_ENV_REGISTRY = Object.freeze({ + ...KEPT_PRODUCT_ENV_REGISTRY, + ...MANUAL_PRODUCT_ENV_REGISTRY, +} as const); +`; + +/** + * The rule of tests/unit/env-registry-coverage.test.ts, for the manual's + * keys: each has a runtime row whose `required` and `defaultValue` are what + * the schema field does with an absent key. + */ +const ROW_CHECK_SOURCE = `import { isDeepStrictEqual } from "node:util"; + +import { ENV_REGISTRY } from "./src/contracts/env.ts"; +import { PRODUCT_ENV_REGISTRY } from "./${MANUAL_SETTINGS}"; +import { runtimeConfigV2ArtifactSchema } from "./src/contracts/release-artifacts.ts"; + +const shape = runtimeConfigV2ArtifactSchema.shape as Record< + string, + { safeParse(value: unknown): { success: boolean; data?: unknown } } +>; +const rows = ENV_REGISTRY as Record; +const problems = Object.keys(PRODUCT_ENV_REGISTRY).flatMap((key) => { + const field = shape[key]; + const row = rows[key]; + if (field === undefined || row?.phase !== "runtime") return [key + ": no runtime config field or runtime row"]; + const parsed = field.safeParse(undefined); + const expected = parsed.success + ? { required: false, defaultValue: parsed.data ?? null } + : { required: true, defaultValue: null }; + const declared = { required: row.required, defaultValue: row.defaultValue }; + return isDeepStrictEqual(declared, expected) + ? [] + : [key + ": row " + JSON.stringify(declared) + ", schema " + JSON.stringify(expected)]; +}); +process.stdout.write(JSON.stringify(problems)); +`; + +const roots: string[] = []; + +afterAll(async () => { + await Promise.all(roots.map((root) => rm(root, { recursive: true, force: true }))); +}); + +async function copyRepository(): Promise { + const root = await mkdtemp(path.join(tmpdir(), "manual-paired-backend-settings-")); + roots.push(root); + for (const entry of REMOVAL_FIXTURE_COPY_TARGETS) { + // A removal drill runs this test in a copy that has already lost some. + if (!existsSync(path.resolve(entry))) continue; + await cp(path.resolve(entry), path.join(root, entry), { + recursive: true, + filter: (source) => !source.includes(`${path.sep}.generated`), + }); + } + await linkFixtureNodeModules(root); + return root; +} + +describe("docs/manual/04 §3.2 product settings, pasted as written (1105/14-02)", () => { + it("typechecks and states the FE-REG-ENV rows as the schema reads the keys", async () => { + const block = settingsBlock(await readFile(MANUAL, "utf8")); + expect(block).toContain("PRODUCT_ENV_REGISTRY"); + const root = await copyRepository(); + for (const reserved of [MANUAL_SETTINGS, KEPT_CONTRACTS, ROW_CHECK]) { + expect(existsSync(path.join(root, reserved)), reserved).toBe(false); + } + await rename(path.join(root, PRODUCT_CONTRACTS), path.join(root, KEPT_CONTRACTS)); + await writeFile(path.join(root, MANUAL_SETTINGS), block); + await writeFile(path.join(root, PRODUCT_CONTRACTS), PRODUCT_CONTRACTS_SOURCE); + await writeFile(path.join(root, ROW_CHECK), ROW_CHECK_SOURCE); + + const generated = spawnSync( + process.execPath, + [path.resolve("scripts/generate-product-feature-index.ts"), `--root=${root}`], + { encoding: "utf8" }, + ); + expect(generated.stderr).toBe(""); + expect(generated.status).toBe(0); + + const typecheck = spawnSync( + path.resolve("node_modules/.bin/tsc"), + ["--project", path.join(root, "tsconfig.app.json")], + { encoding: "utf8" }, + ); + expect(typecheck.stdout + typecheck.stderr).toBe(""); + expect(typecheck.status).toBe(0); + + const rows = spawnSync(process.execPath, [path.join(root, ROW_CHECK)], { cwd: root, encoding: "utf8" }); + expect(rows.stderr).toBe(""); + expect(JSON.parse(rows.stdout)).toEqual([]); + }, 120_000); +}); diff --git a/tests/unit/removal-fixture.test.ts b/tests/unit/removal-fixture.test.ts index e48b8283..017aa20e 100644 --- a/tests/unit/removal-fixture.test.ts +++ b/tests/unit/removal-fixture.test.ts @@ -157,7 +157,8 @@ describe("document tests in a removal fixture", () => { for (const test of REMOVAL_FIXTURE_DOCUMENT_TESTS) { expect(existsSync(test), test).toBe(documentsPresent); if (documentsPresent) { - await expect(readFile(test, "utf8")).resolves.toMatch(/README\.md|CHANGELOG\.md/u); + // 1105/14-02. docs/ is one of the document targets too. + await expect(readFile(test, "utf8")).resolves.toMatch(/README\.md|CHANGELOG\.md|docs\//u); } } });