Files
clean-architecture-frontend…/tests/unit/backend-envelope.test.ts
T
DongHyeonka 5d0f8454c6 test(http): Envelope 판정 경계와 처리 중 409 무재전송을 고정한다
문제
Envelope 실패 판정 표(backend-envelope.ts)와 실행기의 실패 Envelope
처리는 커버리지가 100%인데 경계 다섯 곳이 테스트에 걸리지 않는다. 표의
code를 다른 status로 보내는 행, 표 밖 422, 게이트웨이 408·425, 응답
한도보다 크고 64 KiB보다 작은 실패 본문, JSON이 아닌 실패 본문이 없다.
그래서 변이 H14(=M6, status 대조 제거)·H45(표 밖 422를 분류기로)·H15
(408·425 제거)·H23(실패 한도를 64 KiB 고정)·H10b(실패 media type 검사
제거)가 살아남았다. 처리 중 409를 자동 재전송하게 바꾼 변이 M7도
살아남았다. Envelope 표 테스트는 재시도 예산이 0이라 재전송을 볼 수
없었다. 같은 문서의 이월 항목 둘도 그대로다. 결과 불명 동안 입력
identity를 잡는 네 줄(M1, 0929/03-06)과 반사 correlation 문법 검사(M3,
1101/03-06)를 지워도 테스트가 통과한다.

고른 방법
- tests/unit/backend-envelope.test.ts: envelopeFailureEffect·
  idempotencyRefusalReason·envelopeFailureReading을 status × code 표로
  직접 부른다.
- envelope 통합 테스트: LENIENT 묶음에 422 INTEGRITY_MISMATCH 한 행,
  한도를 넘는 실패 Envelope와 text/plain 실패 본문(네이티브 Response),
  retryBudget 1인 KEYED가 409 IDEMPOTENT_IN_FLIGHT에 한 번만 보내는 행.
- 결과 불명 입력이 두 칸짜리 identity 레지스트리에서 밀려나지 않는지,
  문법 밖 반사 id가 보낸 id로 바뀌는지를 각각 한 건씩 더한다.

위험·한계
테스트만 더했다. 동작은 바꾸지 않았다.

검증
- 변이 8종(H14·H45·H15·H23·H10b·M7·M1·M3)을 하나씩 넣고 관련 테스트를
  돌렸다. 모두 새 테스트에서 실패하고, 되돌리면 통과한다.
- check:types, lint 통과. 바뀐 4파일 83건 통과.

Refs: docs/reviews/2026-11-03-maturity-review/10-tests-fast-layers.md 10-02
Refs: docs/reviews/2026-11-03-maturity-review/03-adapters-http-state.md 03-08
2026-11-04 20:24:09 +09:00

63 lines
2.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
envelopeFailureEffect,
envelopeFailureReading,
idempotencyRefusalReason,
} from "../../src/adapters/http/backend-envelope.ts";
/**
* 1103/10-02. The backend's refusal table, read status by status. The
* integration test sends each table code with its own status; these rows pin
* the edges it does not reach: a table code under another status, a 422
* outside the table, and the gateway statuses that keep the server-failure
* kind.
*/
describe("backend Envelope failure table", () => {
it.each([
[400, "VALIDATION_FAILED", undefined],
[400, "IDEMPOTENCY_KEY_INVALID", "IDEMPOTENCY_KEY_RULE_MISMATCH"],
[422, "IDEMPOTENT_REQUEST_MISMATCH", "IDEMPOTENT_REQUEST_MISMATCH"],
] as const)("reads %i %s as refused before the write", (status, code, reason) => {
expect(envelopeFailureEffect(status, { code })).toBe("NOT_APPLIED");
expect(idempotencyRefusalReason(code, status)).toBe(reason);
});
// The table names a status and a code together. The same code under
// another status is not the refusal the backend documents.
it.each([
[409, "VALIDATION_FAILED"],
[422, "VALIDATION_FAILED"],
[400, "IDEMPOTENT_REQUEST_MISMATCH"],
[409, "IDEMPOTENT_REQUEST_MISMATCH"],
[422, "IDEMPOTENCY_KEY_INVALID"],
] as const)("reads a table code under another status (%i %s) as maybe applied", (status, code) => {
expect(envelopeFailureEffect(status, { code })).toBe("MAYBE_APPLIED");
expect(idempotencyRefusalReason(code, status)).toBeUndefined();
});
it.each([
[400, "BAD_PARAMETER"],
[409, "IDEMPOTENT_IN_FLIGHT"],
[409, "RESOURCE_CONFLICT"],
// A 422 outside the table stays with the backend's verdict, never with a
// package that reads every 422 as refused (fileserver writes first).
[422, "INTEGRITY_MISMATCH"],
] as const)("keeps %i %s, outside the table, maybe applied", (status, code) => {
expect(envelopeFailureEffect(status, { code })).toBe("MAYBE_APPLIED");
});
it("leaves a status the table does not speak for to the package", () => {
expect(envelopeFailureEffect(404, { code: "NOT_FOUND" })).toBeUndefined();
});
it.each([408, 425, 500, 502, 503, 504])(
"reads a gateway %i as a server failure, not a client one",
(status) => {
expect(envelopeFailureReading(status, { code: "GATEWAY_REFUSED" }).kind).toBe(
"SERVER_FAILURE",
);
},
);
});