문제: 1103/16-05 수정으로 commandMutationIdentity가 생겼지만 BoundMutation.operationId는 여전히 string이다. 정책에 operation ID를 문자열로 직접 적으면 오타가 check:types와 check:registries를 통과하고, 저장할 때마다 실행기가 보내기 전에 MISSING_IDEMPOTENCY_KEY 위반으로 거부한다. 매뉴얼 01은 이것을 "못 잡음"으로 적고 있었다. 고른 방법: BoundMutation.operationId를 brand 타입 MutationOperationId로 바꾼다. 이 값을 돌려주는 것은 commandMutationIdentity뿐이라, 문자열을 직접 적으면 check:types가 실패한다. 런타임 값은 descriptor의 문자열 그대로이고 실행기·intent factory는 바뀌지 않는다. 참조 기능과 쓰기 slice 생성기는 이미 commandMutationIdentity를 spread하므로 고칠 것이 없다. 템플릿 테스트의 손글씨 ID 20곳은 tests/helpers/mutation-operation-id.ts (commandMutationIdentity를 거치는 test helper)나 그 파일의 descriptor로 바꿨다. 매뉴얼 01·patterns 표·state 설계 예시를 맞췄다. 버린 대안: (1) 위반 이름을 INTENT_OPERATION_MISMATCH로 나누는 것. 실행 때만 드러나는 것은 같고, 공개 위반 어휘에 값이 하나 늘어 다운스트림 분기가 바뀐다. (2) 설치된 operation ID의 union 타입. 기능마다 늦게 적재되는 계약 전체를 타입으로 모을 곳이 없다. 위험·한계: 공개 타입(src/contracts/server-state.ts)이 좁아진다. 정책에 operation ID를 문자열로 적은 다운스트림 코드는 동기화 뒤 check:types가 실패한다. commandMutationIdentity에 descriptor 상수 대신 손으로 만든 객체를 넘기면 여전히 오타가 통과한다(매뉴얼 "못 잡음"). HTTP가 아닌 뮤테이션은 descriptor 모양 객체를 넘겨야 한다. 이 repo에는 그런 소비자가 없다. 검증: desktop batch에서 확인. corepack pnpm check:types:test tests/unit/command-mutation-identity.test.ts의 @ts-expect-error가 부모 커밋에서는 쓰이지 않아(TS2578) 실패하고 이 커밋에서 통과한다. node scripts/run-vitest.ts run tests/unit/command-mutation-identity.test.ts tests/component/application-mutation-admission.test.tsx tests/component/application-mutation-scope-fence.test.tsx tests/component/application-query.test.tsx tests/component/form-foundation.test.tsx BREAKING CHANGE: BoundMutation.operationId는 string이 아니라 MutationOperationId다. 뮤테이션 정책의 `operationId: "<ID>"`와 `requiresIdempotencyKey`를 `...commandMutationIdentity(<OPERATION>_CONTRACT)` 로 바꾼다(src/contracts/server-state.ts). commandMutationIdentity의 반환 타입도 operationId가 MutationOperationId다. Refs: 1103/16-05
62 lines
2.4 KiB
TypeScript
62 lines
2.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
commandMutationIdentity,
|
|
type BoundMutation,
|
|
} 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",
|
|
);
|
|
});
|
|
|
|
// 1103/16-05. The rest of the finding: a policy that wrote its operation
|
|
// id by hand still passed the type check. `BoundMutation.operationId` is a
|
|
// `MutationOperationId`, which only commandMutationIdentity returns, so the
|
|
// misspelt id below no longer compiles (check:types:test fails if the
|
|
// directive is unused). At run time the value is the descriptor's string.
|
|
it("takes no hand-written operation id", () => {
|
|
const handWritten: Pick<BoundMutation<string, string>, "operationId"> = {
|
|
// @ts-expect-error a hand-written id is not the descriptor's MutationOperationId.
|
|
operationId: "TEST_CREAT_ENTITY",
|
|
};
|
|
const fromDescriptor: Pick<BoundMutation<string, string>, "operationId"> = {
|
|
operationId: commandMutationIdentity(TEST_CREATE_HTTP_CONTRACT).operationId,
|
|
};
|
|
|
|
expect(fromDescriptor.operationId).toBe("TEST_CREATE_ENTITY");
|
|
expect(handWritten.operationId).not.toBe(fromDescriptor.operationId);
|
|
});
|
|
});
|