문제 BoundMutation의 operationId와 requiresIdempotencyKey는 기능이 손으로 다시 적는 자유 값이다. operationId에 오타가 있어도 check:types와 check:registries가 통과하고, 실행기는 intent의 operation ID가 descriptor와 다르다며 보내기 전에 거부한다(MISSING_IDEMPOTENCY_KEY 위반). 화면은 "요청을 처리할 수 없습니다"로 멈추고 원인을 말하지 않는다(리뷰 E-2). 1101/03-03이 같은 재기술을 적었다. 고른 방법 src/contracts/server-state.ts에 commandMutationIdentity(descriptor)를 둔다. descriptor의 operationId와 retrySemantics === "KEYED"를 돌려주고, 정책은 이것을 펼쳐 쓴다. 상수 이름 오타는 tsc가 잡는다. GET·HEAD descriptor를 넘기면 바인딩 때 throw한다. 참조 기능의 생성 정책이 이것을 쓴다. 버린 대안 - BoundMutation.operationId를 brand 타입으로: 자유 문자열도 막지만 테스트 약 27곳과 다운스트림 정책을 깨는 공개 타입 변경이다. - 실행기 위반 이름을 INTENT_OPERATION_MISMATCH로 나누기: http 어댑터의 닫힌 위반 어휘와 화면 매핑을 바꾼다. 값을 descriptor에서 받으면 그 경로에 닿지 않으므로 미뤘다. - 타입에서 method를 쓰기 method로 좁히기: InstalledHttpContract로 주석한 descriptor(method: HttpMethod)가 모두 타입 오류가 나서 실행 때 검사만 둔다. 위험·한계 - 정책에 operationId 문자열을 직접 적는 길은 남는다. 매뉴얼 7단계 "못 잡음"에 적었다. - 참조 기능 presentation이 계약 기여 파일을 import한다. 두 파일 모두 지연 청크라 초기 JS는 바뀌지 않는다(check:bundle은 다음 커밋들과 함께 잰다). 검증 - RED: tests/unit/command-mutation-identity.test.ts 4건이 함수 없음으로 실패. GREEN 뒤 통과. - tests/features/reference-feature, tests/component/application-query.test.tsx 125건 통과. - check:types, check:architecture, lint, verify:documentation 통과. Refs: docs/reviews/2026-11-03-maturity-review/16-structure-patterns.md 16-05
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { commandMutationIdentity } from "../../src/contracts/server-state.ts";
|
|
import {
|
|
TEST_CREATE_HTTP_CONTRACT,
|
|
TEST_LIST_HTTP_CONTRACT,
|
|
} from "../helpers/external-contract-fixture.ts";
|
|
|
|
/**
|
|
* 1103/16-05, 1101/03-03. A mutation policy used to restate its command's
|
|
* operation id and key requirement as free values. A misspelt id passed the
|
|
* type check and the registries, and the executor refused every save before
|
|
* sending, as a missing idempotency key. The policy now takes both from the
|
|
* HTTP descriptor.
|
|
*/
|
|
describe("commandMutationIdentity", () => {
|
|
it("takes the operation id and the key requirement from a KEYED descriptor", () => {
|
|
expect(commandMutationIdentity(TEST_CREATE_HTTP_CONTRACT)).toEqual({
|
|
operationId: "TEST_CREATE_ENTITY",
|
|
requiresIdempotencyKey: true,
|
|
});
|
|
});
|
|
|
|
it.each(["NEVER", "IDEMPOTENT"] as const)(
|
|
"sends no key for a %s command",
|
|
(retrySemantics) => {
|
|
expect(
|
|
commandMutationIdentity({
|
|
contract: { ...TEST_CREATE_HTTP_CONTRACT.contract, retrySemantics },
|
|
}),
|
|
).toEqual({ operationId: "TEST_CREATE_ENTITY", requiresIdempotencyKey: false });
|
|
},
|
|
);
|
|
|
|
it("refuses a read descriptor", () => {
|
|
expect(() => commandMutationIdentity(TEST_LIST_HTTP_CONTRACT)).toThrow(
|
|
"commandMutationIdentity: TEST_LIST_ENTITIES is a GET; a mutation binds a write operation",
|
|
);
|
|
});
|
|
});
|