test(browser-transfer): Retry-After와 abort 멱등 키 규칙 세 개를 테스트로 고정한다

문제: 문서와 주석이 적은 규칙 세 개를 바꿔도 영역 단위 테스트가 모두
통과한다. 리뷰 변이 N2(part 단계가 503의 Retry-After를 읽지 않음),
N10(abort 재시도마다 ABORT 멱등 키를 바꿈, 세 라운드째 생존),
N17(control plane이 헤더 없는 429를 retryable:true로 냄)이 살아남았다.

고친 방법: 규칙마다 실패하는 테스트를 더한다.
- part 단계 Retry-After 묶음에 503을 더한다. 실제 presigned provider·
  vault·실행기로 발급과 PUT 두 단계를 본다.
- abort가 한 호출 안에서 재시도하고 다음 abort() 호출에서 다시 보낼 때
  세 요청의 idempotencyKey가 모두 같은지 본다. 같은 파일의
  createSession·part·complete 키 테스트와 같은 방식이다.
- fetch transport가 헤더 없는 429와 상한 밖 429를 retryable:false,
  retryAfterMs 없음으로 내는지 본다.

위험·한계: 테스트만 더했다. 동작은 바뀌지 않는다.

검증:
- 영역 단위 테스트(resumable-upload, presigned-transfer, image-cdn,
  upload-cancellation) 15파일 272건 통과
- 변이를 하나씩 넣고 돌렸다: N2 4건 실패, N10 1건 실패, N17 2건 실패.
  변이는 원본으로 되돌렸다
- check:types, eslint(바꾼 두 파일) 통과

Refs: docs/reviews/2026-11-03-maturity-review/01-adapters-browser-transfer.md 01-03
This commit is contained in:
DongHyeonka
2026-11-04 20:20:51 +09:00
parent 004a205748
commit 3af2c8ea2b
2 changed files with 83 additions and 5 deletions
@@ -319,6 +319,33 @@ describe("resumable upload fetch transport", () => {
expect(cancel).toHaveBeenCalledTimes(1);
});
// 2026-11-03 01-03 (N17). Without a usable wait the transport does not
// invite a retry (presigned-transfer-and-image-cdn.md, Retry-After).
it.each<Readonly<{ label: string; headers: Record<string, string> }>>([
{ label: "no Retry-After", headers: {} },
{ label: "Retry-After past the ceiling", headers: { "retry-after": "4" } },
])("classifies a 429 with $label as not retryable", async ({ headers }) => {
const fetcher = vi.fn(async () =>
responseAt(ENDPOINTS.GET_STATUS, null, { status: 429, headers }),
) as unknown as typeof fetch;
const result = await createTransport(fetcher).execute({
operation: "GET_STATUS",
body: {},
signal: activeSignal,
});
expect(result).toEqual({
ok: false,
error: {
code: "UNAVAILABLE",
operation: "UPLOAD_RECONCILE",
retryable: false,
recovery: "RESUME",
},
});
});
it.each([500, 599])(
"classifies HTTP %s as retryable; runtime attempt limits remain authoritative",
async (status) => {
@@ -328,13 +328,17 @@ describe("issuance refusal versus PUT refusal (0929/01-01)", () => {
});
describe("part-stage Retry-After (2026-11-01 01-01)", () => {
// 2026-11-03 01-03 (N2). A 503 carries the server's Retry-After as a 429
// does (`statusFailure` in presigned/http-common.ts).
const stages = [
{ stage: "BFF issuance", issueStatuses: [429], putStatuses: [] },
{ stage: "object-store PUT", issueStatuses: [], putStatuses: [429] },
{ stage: "BFF issuance", status: 429, issueStatuses: [429], putStatuses: [] },
{ stage: "object-store PUT", status: 429, issueStatuses: [], putStatuses: [429] },
{ stage: "BFF issuance", status: 503, issueStatuses: [503], putStatuses: [] },
{ stage: "object-store PUT", status: 503, issueStatuses: [], putStatuses: [503] },
] as const;
it.each(stages)(
"waits the server's Retry-After before retrying a $stage 429",
"waits the server's Retry-After before retrying a $stage $status",
async ({ issueStatuses, putStatuses }) => {
const real = presignedRuntime(putStatuses, undefined, {
issueStatuses,
@@ -353,7 +357,7 @@ describe("part-stage Retry-After (2026-11-01 01-01)", () => {
);
it.each(stages)(
"does not retry a $stage 429 whose Retry-After exceeds maxRetryAfterMs",
"does not retry a $stage $status whose Retry-After exceeds maxRetryAfterMs",
async ({ issueStatuses, putStatuses }) => {
const real = presignedRuntime(putStatuses, undefined, {
issueStatuses,
@@ -377,7 +381,11 @@ describe("part-stage Retry-After (2026-11-01 01-01)", () => {
describe("resumable upload idempotency keys (01-04)", () => {
const unavailable = (
operation: "UPLOAD_SESSION" | "UPLOAD_PART" | "UPLOAD_COMPLETE",
operation:
| "UPLOAD_SESSION"
| "UPLOAD_PART"
| "UPLOAD_COMPLETE"
| "UPLOAD_ABORT",
) =>
browserDataFailure("UNAVAILABLE", operation, {
retryable: true,
@@ -531,6 +539,49 @@ describe("resumable upload idempotency keys (01-04)", () => {
complete.mock.calls[0]?.[0].idempotencyKey,
);
});
// 2026-11-03 01-03 (N10). The same key is how the server recognises an
// abort whose answer was lost as the same abort.
it("retries abort with the same key, within one abort() and from the next", async () => {
const harness = createControlHarness();
const abort = vi.fn(
async (
_input: Parameters<typeof harness.control.abort>[0],
): ReturnType<typeof harness.control.abort> =>
abort.mock.calls.length <= 2
? unavailable("UPLOAD_ABORT")
: browserDataSuccess({ state: "ABORTED" as const }),
);
harness.control.abort = abort;
const checkpoints = new MemoryCheckpointStore();
const runtime = createResumableUploadRuntime({
controlPlane: harness.control,
// Every PUT fails, so upload() leaves an ACTIVE checkpoint to abort.
partExecutor: { uploadPart: async () => unavailable("UPLOAD_PART") },
checkpoints,
mutationLock: noContentionLock,
crypto,
policy: runtimePolicy({ maxRetries: 1 }),
now: () => 1_000,
sleep: async () => {},
});
const key = "upload_key_abort_retry";
expect((await runtime.upload(request(key))).ok).toBe(false);
// Two attempts inside the first abort() both fail; the next abort() wins.
const failed = await runtime.abort({ uploadKey: key, signal: activeSignal });
expect(failed).toMatchObject({
ok: false,
error: { operation: "UPLOAD_ABORT" },
});
const retried = await runtime.abort({ uploadKey: key, signal: activeSignal });
expect(retried).toEqual({ ok: true, value: { state: "ABORTED" } });
expect(abort).toHaveBeenCalledTimes(3);
const keys = abort.mock.calls.map(([input]) => input.idempotencyKey);
expect(keys[0]).toMatch(/\S/u);
expect(new Set(keys).size).toBe(1);
});
});
describe("resumable upload completed-result reporting (01-02)", () => {