diff --git a/tests/unit/resumable-upload-fetch-transport.test.ts b/tests/unit/resumable-upload-fetch-transport.test.ts index 869e9752..add1791e 100644 --- a/tests/unit/resumable-upload-fetch-transport.test.ts +++ b/tests/unit/resumable-upload-fetch-transport.test.ts @@ -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 }>>([ + { 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) => { diff --git a/tests/unit/resumable-upload-runtime-recovery.test.ts b/tests/unit/resumable-upload-runtime-recovery.test.ts index 14f069ae..b46b6e57 100644 --- a/tests/unit/resumable-upload-runtime-recovery.test.ts +++ b/tests/unit/resumable-upload-runtime-recovery.test.ts @@ -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[0], + ): ReturnType => + 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)", () => {