test(contracts): HTTP 스키마 행이 방향·모르는 필드 정책을 빼면 실패한다
문제: FE-REG-SCHEMA 행의 direction·unknownFieldPolicy는 타입에서 선택 칸이다. tests/unit/schema-metadata-policy.test.ts는 행이 값을 적지 않으면 그 자리를 건너뛰었다(direction의 `declared === undefined`, 정책의 `if (declared === undefined) return []`). 1105/07-02는 RESPONSE 행의 정책이 REJECT_UNKNOWN으로 바뀔 때만 breaking으로 본다. 그래서 손으로 쓴 응답 행이 두 칸을 빼고 들어오면, 뒤에 응답 DTO를 .strict()로 바꿔도 행이 바뀌지 않아 check:registries는 아무것도 보지 않고 정책 테스트도 건너뛴다. 백엔드가 응답에 필드 하나를 더하면 그 API가 SCHEMA_MISMATCH로 실패한다. 고른 방법: 리뷰의 (A). descriptor의 입력·응답·실패 검증기(`slots`)로 쓰인 스키마의 행이 두 칸을 적지 않으면 두 테스트가 실패로 센다. 메시지는 `row states no direction, used as <방향>`과 `row states no unknownFieldPolicy, validator <탐침 결과>`다. 행이 아예 없으면 같은 메시지가 나오고, boundary 테스트도 `no FE-REG-SCHEMA row`로 실패한다. 템플릿 HTTP 행과 생성기가 쓰는 행(create-feature.ts, create-feature- write-slice.ts)은 이미 두 칸을 적어 통과한다. 라우트에만 쓰이는 행 (NotFoundSplat)은 slots에 없어 그대로 두 칸이 없어도 된다. 매뉴얼 01 4단계와 errors.md에 규칙과 메시지를 적었다. 버린 대안: (B) governance가 api-* 경계 행에 두 칸을 필수로 둔다. 경계별 필수 칸 규칙이 governance에 없어 분류기 변경과 기준선 재승인이 필요하다. 타입에서 두 칸을 필수로 만들면 route 전용 행까지 바뀌고, src/contracts export의 모양이 바뀐다. 위험·한계: 다운스트림이 두 칸 없는 HTTP 행을 가졌다면 동기화 뒤 test:unit이 실패한다. 메시지대로 두 칸을 적으면 된다. 고친 곳이 검사(테스트 파일) 자신이라 RED는 테스트 파일만으로 만들 수 없다. 참조 응답 행에서 두 칸을 지운 변이로 확인한다. 검증: desktop batch에서 확인. node scripts/run-vitest.ts run tests/unit/schema-metadata-policy.test.ts (변이 없이 통과, ReferenceResourcePayload 행의 두 칸을 지운 변이에서 두 테스트 실패) Refs: 1106/07-02
This commit is contained in:
@@ -269,6 +269,7 @@ DTO와 problem details(`type`·`title`·`status`)를 감싸지 않고 보내는
|
||||
- `boundary`: descriptor의 입력·응답·실패 검증기와 라우트의 `paramsSchema`·`searchSchema`에서 쓰인 자리로 정해진다. 다르면 `<schemaId>: row <적은 값>, used as <맞는 값>`으로 실패한다. 쓰이는데 행이 없으면 `<schemaId>: no FE-REG-SCHEMA row`.
|
||||
- `direction`: 입력은 `REQUEST`, 응답·실패는 `RESPONSE`.
|
||||
- `unknownFieldPolicy`: zod가 모르는 키를 거부하면(`.strict()`) `REJECT_UNKNOWN`, 버리면(`.strip()`) `STRIP_UNKNOWN`.
|
||||
- descriptor의 입력·응답·실패 검증기로 쓰인 스키마의 행은 `direction`·`unknownFieldPolicy`를 빼지 않는다. 빼면 `row states no direction` 또는 `row states no unknownFieldPolicy`로 실패한다(1106/07-02). 칸이 없으면 응답 DTO를 `.strict()`로 바꿔도 행이 바뀌지 않아 `check:registries`가 breaking으로 보지 못한다. 라우트에만 쓰이는 행은 두 칸이 없어도 된다.
|
||||
- 이 테스트는 설치된 기능을 읽는다. 기능을 더한 상태에서 `test:unit`을 돌릴 때 잡힌다.
|
||||
|
||||
예: 공지 기능의 검색값 GET과 경로 파라미터 GET. 입력에 관한 칸과 응답 모양 줄만 적었다.
|
||||
|
||||
@@ -86,6 +86,7 @@ lint / check:architecture / check:i18n → FE-GATE-002, FE-GATE-010
|
||||
| `duplicate operation: <operationId>` (계약 조립 오류의 `reason`) | operation ID 중복 | `contracts/<base>-contract-contribution.ts`. 접두어를 붙인다 |
|
||||
| `FE-REG-API.<operationId>.requestSchema references unknown FE-REG-SCHEMA.schemaId=<id>` | descriptor의 입력 스키마 ID가 스키마 메타데이터에 없다 (`responseSchema`, `problemSchema`도 같은 꼴. 실패 본문 행은 `boundary: "api-problem"`) | `contracts/<base>-schema-metadata.ts` |
|
||||
| `<schemaId>: row <boundary>, used as <boundary>` (`tests/unit/schema-metadata-policy.test.ts`) | 스키마 메타 행의 `boundary`가 그 스키마가 쓰인 자리와 다르다. `no FE-REG-SCHEMA row`는 쓰이는데 행이 없다 | `contracts/<base>-schema-metadata.ts` |
|
||||
| `<operationId> <schemaId>: row states no direction, used as <direction>` 또는 `row states no unknownFieldPolicy, validator <policy>` (`tests/unit/schema-metadata-policy.test.ts`) | descriptor가 쓰는 스키마의 행이 `direction`·`unknownFieldPolicy`를 적지 않았다(1106/07-02) | `contracts/<base>-schema-metadata.ts`에 두 칸을 적는다. 값은 쓰인 자리와 검증기가 정한다 |
|
||||
| `Unregistered route codec: <codecId>` | URL 함수가 기능 codec을 `buildRouteUrl`에 넘기지 않았다 | `presentation/<base>-routes.ts` |
|
||||
| `contract package <packageId> is declared, but no loaded contribution pins it` | 계약 `contractPackages`에 적은 패키지를 계약 기여가 쓰지 않는다 | `contracts/<base>-contract-contribution.ts`의 `source` |
|
||||
| `<id> contributes contract package <packageId>, which no installed feature declares in contracts.contractPackages` | 계약 기여의 신원과 계약 선언의 신원이 다르다 | 둘 다 `<BASE>_CONTRACT_PACKAGE` 하나를 쓰게 한다 |
|
||||
|
||||
@@ -21,6 +21,13 @@ import {
|
||||
* `unrecognized_keys` rejects unknown fields; one that reaches the object
|
||||
* without that issue tolerates them. A nested object below that level is not
|
||||
* probed.
|
||||
*
|
||||
* 1106/07-02. Both fields are optional in the row type, and a row that left
|
||||
* them out used to be skipped here. 1105/07-02 grades a response row whose
|
||||
* policy turns `REJECT_UNKNOWN` as breaking, but a row with no policy does not
|
||||
* change when its DTO turns `.strict()`, so nothing saw it. A schema an HTTP
|
||||
* operation uses now fails here without them. Route-only rows (`NotFoundSplat`)
|
||||
* are not in `slots` and still need neither.
|
||||
*/
|
||||
const PROBE_KEY = "__unknownFieldProbe";
|
||||
|
||||
@@ -127,9 +134,11 @@ describe("FE-REG-SCHEMA policy of the installed HTTP schemas (1103/07-03)", () =
|
||||
it("declares the direction each schema is used in", () => {
|
||||
const wrong = slots.flatMap(({ operationId, direction, validator }) => {
|
||||
const declared = SCHEMA_REGISTRY[validator.schemaId]?.direction;
|
||||
return declared === undefined || declared === direction
|
||||
return declared === direction
|
||||
? []
|
||||
: [`${operationId} ${validator.schemaId}: row ${declared}, used as ${direction}`];
|
||||
: [
|
||||
`${operationId} ${validator.schemaId}: row ${declared ?? "states no direction"}, used as ${direction}`,
|
||||
];
|
||||
});
|
||||
|
||||
expect(wrong).toEqual([]);
|
||||
@@ -154,11 +163,12 @@ describe("FE-REG-SCHEMA policy of the installed HTTP schemas (1103/07-03)", () =
|
||||
it("declares the unknown-field policy its validator applies", () => {
|
||||
const wrong = slots.flatMap(({ operationId, validator }) => {
|
||||
const declared = SCHEMA_REGISTRY[validator.schemaId]?.unknownFieldPolicy;
|
||||
if (declared === undefined) return [];
|
||||
const probed = probeUnknownFieldPolicy(validator);
|
||||
return probed === declared
|
||||
? []
|
||||
: [`${operationId} ${validator.schemaId}: row ${declared}, validator ${probed}`];
|
||||
: [
|
||||
`${operationId} ${validator.schemaId}: row ${declared ?? "states no unknownFieldPolicy"}, validator ${probed}`,
|
||||
];
|
||||
});
|
||||
|
||||
expect(wrong).toEqual([]);
|
||||
|
||||
Reference in New Issue
Block a user