From 3fba68bebc64d3e266e4ad976fb0a66da8f3835c Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Wed, 4 Nov 2026 22:34:35 +0900 Subject: [PATCH] =?UTF-8?q?refactor(contracts):=20FE-REG-API=20=ED=96=89?= =?UTF-8?q?=EC=9D=B4=20refusedBeforeWrite=EB=A5=BC=20=ED=83=80=EC=9E=85?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=9D=BD=EB=8A=94=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제 fix/r1103-contracts는 fix/r1103-http가 아직 없을 때 CommandEffectDescriptor에 없는 refusedBeforeWrite를 구조 캐스트로 읽었다. 두 브랜치를 합치자 그 칸이 타입에 생겼다. 또 행 투영 테스트가 Envelope가 아닌 operation에 refusedBeforeWrite를 적는데, http 쪽 조립 검사(1103/03-01)는 그것을 거절해 테스트가 ContractContributionError로 실패한다. 고른 방법 - api-operations.ts는 effect.refusedBeforeWrite를 타입으로 읽는다. - 테스트의 create descriptor에 responseEnvelope ENVELOPE_V1을 주고, code를 업무 거절 모양(TEST_ENTITY_INVALID 등)으로 바꾼다. 위험·한계 - 행 모양은 그대로다. 기준선 영향 없음. 검증 - tests/unit/api-operation-rows.test.ts 12건, test:unit 2,790건, check:types, lint 통과. Refs: docs/reviews/2026-11-03-maturity-review/07-contracts.md 07-01 --- src/contracts/api-operations.ts | 13 ++++++------- tests/unit/api-operation-rows.test.ts | 6 ++++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/contracts/api-operations.ts b/src/contracts/api-operations.ts index ae9bc4c3..ca1eb2d1 100644 --- a/src/contracts/api-operations.ts +++ b/src/contracts/api-operations.ts @@ -131,14 +131,13 @@ function commandEffectRow( effect: CommandEffectDescriptor | null, ): ApiCommandEffectRow | null { if (effect === null) return null; - // Read structurally: a descriptor that does not name refused codes has no - // such list, and the row then has no such field. - const refused: unknown = (effect as Readonly<{ refusedBeforeWrite?: unknown }>) - .refusedBeforeWrite; + // A descriptor that does not name refused codes has no such list, and the + // row then has no such field. + const refused = effect.refusedBeforeWrite; return Object.freeze({ classifiesStatus: typeof effect.classifyStatus === "function", - ...(Array.isArray(refused) - ? { refusedBeforeWrite: Object.freeze(refused.map(String)) } - : {}), + ...(refused === undefined + ? {} + : { refusedBeforeWrite: Object.freeze([...refused]) }), }); } diff --git a/tests/unit/api-operation-rows.test.ts b/tests/unit/api-operation-rows.test.ts index fc597cd5..29c72e8c 100644 --- a/tests/unit/api-operation-rows.test.ts +++ b/tests/unit/api-operation-rows.test.ts @@ -105,9 +105,11 @@ describe("FE-REG-API rows projected from HTTP descriptors", () => { contract: { ...TEST_CLASSIFIED_CREATE_HTTP_CONTRACT.contract, // A descriptor that names the codes refused before any write. + // Only an Envelope operation may name them. + responseEnvelope: "ENVELOPE_V1" as const, commandEffect: { ...TEST_CLASSIFIED_CREATE_HTTP_CONTRACT.contract.commandEffect, - refusedBeforeWrite: ["VALIDATION_FAILED", "CONFLICT"], + refusedBeforeWrite: ["TEST_ENTITY_INVALID", "TEST_ENTITY_ALREADY_EXISTS"], }, }, }, @@ -122,7 +124,7 @@ describe("FE-REG-API rows projected from HTTP descriptors", () => { }); expect(rows.TEST_CREATE_ENTITY?.commandEffect).toEqual({ classifiesStatus: true, - refusedBeforeWrite: ["VALIDATION_FAILED", "CONFLICT"], + refusedBeforeWrite: ["TEST_ENTITY_INVALID", "TEST_ENTITY_ALREADY_EXISTS"], }); });