diff --git a/tests/integration/fileserver-upload.test.ts b/tests/integration/fileserver-upload.test.ts index 41595697..c4981fa0 100644 --- a/tests/integration/fileserver-upload.test.ts +++ b/tests/integration/fileserver-upload.test.ts @@ -372,6 +372,8 @@ describe("Fileserver multipart upload — Envelope failures", () => { { status: 500, code: "AMBIGUOUS_COMPLETION", category: "DATA_INTEGRITY", retryable: false, details: { ambiguous: true, reconciliationRequired: true }, kind: "SERVER_FAILURE", effect: "MAYBE_APPLIED", clientRetryable: false }, { status: 500, code: "INTERNAL_ERROR", category: "INTERNAL", retryable: false, kind: "SERVER_FAILURE", effect: "MAYBE_APPLIED", clientRetryable: false }, { status: 503, code: "STORAGE_UNAVAILABLE", category: "TRANSIENT_DEPENDENCY", retryable: true, kind: "SERVER_FAILURE", effect: "NOT_APPLIED", clientRetryable: true }, + // 1105/01-04. The atomic move itself was refused: nothing was published. + { status: 503, code: "ATOMIC_PUBLISH_UNSUPPORTED", category: "PERMANENT_DEPENDENCY", retryable: false, kind: "SERVER_FAILURE", effect: "NOT_APPLIED", clientRetryable: false }, { status: 503, code: "STORAGE_UNAVAILABLE", category: "TRANSIENT_DEPENDENCY", retryable: true, details: { ambiguous: true }, kind: "SERVER_FAILURE", effect: "MAYBE_APPLIED", clientRetryable: false }, // 1105/01-02. As the V3 table reads it: only an unknown result keeps the key. { status: 503, code: "IDEMPOTENCY_UNAVAILABLE", category: "TRANSIENT_DEPENDENCY", retryable: true, kind: "SERVER_FAILURE", effect: "MAYBE_APPLIED", clientRetryable: false }, @@ -575,6 +577,53 @@ describe("Fileserver multipart upload — unknown results", () => { }); }); + it("adds the file's transfer allowance to the base deadline", async () => { + // 1105/01-04. At one byte per second the file earns one second per byte + // on top of the one-second base, so an answer after 1.5 s still counts. + // Without the allowance a large file on a slow uplink ends at the base. + vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] }); + try { + let respond: (response: Response) => void = () => {}; + let sent: () => void = () => {}; + const requestSent = new Promise((resolve) => { + sent = resolve; + }); + const fetcher = vi.fn( + () => + new Promise((resolve) => { + respond = resolve; + sent(); + }), + ); + const { client: uploader, attachCredentials } = client({ + fetcher: fetcher as unknown as typeof fetch, + timeoutMs: 1_000, + minTransferBytesPerSecond: 1, + monotonicNow: () => 0, + }); + + const pending = uploader.upload(upload()); + await requestSent; + await vi.advanceTimersByTimeAsync(1_500); + respond( + new Response(JSON.stringify(successEnvelope(uploaded("READY"))), { + status: 201, + headers: { "content-type": "application/json" }, + }), + ); + + expect(await pending).toEqual({ ok: true, value: uploaded("READY") }); + expect(attachCredentials).toHaveBeenCalledWith( + expect.anything(), + expect.objectContaining({ + deadlineAtMonotonicMs: 1_000 + FILE_BYTES.byteLength * 1_000, + }), + ); + } finally { + vi.useRealTimers(); + } + }); + it("a caller abort after sending may have applied; before sending it did not", async () => { const controller = new AbortController(); let arrived: () => void = () => {}; @@ -641,6 +690,20 @@ describe("Fileserver multipart upload — refused before sending", () => { }); }); + it("refuses a declared size above maxFileBytes without reading a byte", async () => { + // 1105/01-04. Before the body buffer is sized from the declared length. + const stream = vi.fn(async function* () { + yield { ok: true as const, value: new Uint8Array(3) }; + }); + const source: FileByteSource = { byteLength: 2_000, stream }; + + expect(await unsent({}, { source })).toMatchObject({ + ok: false, + error: { kind: "VALIDATION_REJECTED", code: "FILE_TOO_LARGE", effect: "NOT_STARTED" }, + }); + expect(stream).not.toHaveBeenCalled(); + }); + it("a source that fails mid-stream is not readable", async () => { const source: FileByteSource = { byteLength: 6,