From f2f7dc4cdb4690dfbf3b16363ac68b83f313771f Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 5 Nov 2026 22:13:54 +0900 Subject: [PATCH] =?UTF-8?q?test(http):=20Fileserver=20client=EC=9D=98=205x?= =?UTF-8?q?x=C2=B7deadline=C2=B7=EC=9D=BD=EA=B8=B0=20=EC=A0=84=20=ED=81=AC?= =?UTF-8?q?=EA=B8=B0=20=EA=B1=B0=EC=A0=88=20=EA=B7=9C=EC=B9=99=EC=9D=84=20?= =?UTF-8?q?=EA=B3=A0=EC=A0=95=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: Fileserver client 규칙 셋을 바꿔도 통합 테스트 48건이 모두 통과했다(리뷰 변이 FS4·FS5·FS8 생존). - FS4: 5xx ATOMIC_PUBLISH_UNSUPPORTED를 NOT_APPLIED에서 빼도 표에 그 행이 없다. - FS5: deadline에서 바이트 비례 몫을 없애도 시간 초과 테스트는 작은 고정값만 본다. 큰 파일이 느린 망에서 기본 30초에 끊기는 회귀를 못 잡는다. - FS8: 선언 크기가 maxFileBytes보다 큰 파일을 읽기 전에 거절하지 않아도, 읽는 중 상한 검사가 같은 code를 내서 통과한다. 그 사이 선언 크기만큼 버퍼를 먼저 잡는다. 고른 방법(리뷰 01-04 최소 개선 방향): - Envelope 실패 표에 503 ATOMIC_PUBLISH_UNSUPPORTED → NOT_APPLIED 행을 더한다. 504 TRANSFER_TIMEOUT 행은 01-02 커밋이 MAYBE_APPLIED로 더했다. 두 방향(빼기·되넣기)이 모두 실패를 만든다. - 가짜 setTimeout과 주입한 fetcher·monotonicNow로, 기본 1초에 바이트당 1초를 더한 deadline 안에서 1.5초 뒤 온 답이 성공하는지, 자격 증명 owner가 받은 deadline이 1,000 + 바이트 수 × 1,000 ms인지 본다. 실제 시간에 기대지 않아 부하에 흔들리지 않는다. - 선언 크기 초과에서 stream()이 한 번도 불리지 않음을 본다. 버린 대안: MSW에 지연을 넣고 실제 시간으로 deadline을 재는 방법. 부하가 큰 desktop에서 흔들릴 수 있고, 시간 여유를 키우면 테스트가 느려진다. 위험·한계: 테스트만 더했다. 지금 코드는 의도대로라서 부모 src에서도 통과한다. 검출력은 변이로만 확인할 수 있다. 검증: desktop batch에서 확인. node scripts/run-vitest.ts run tests/integration/fileserver-upload.test.ts RED 없음(테스트 추가). 변이 셋이 각각 실패를 만들어야 한다: FS4' NOT_APPLIED_5XX_CODES에서 "ATOMIC_PUBLISH_UNSUPPORTED" 줄 삭제, FS5 timeoutMs 식의 Math.ceil(...) 몫을 0으로, FS8 readMultipartBody의 declared > maxFileBytes 거절 블록 삭제. Refs: 1105/01-04 --- tests/integration/fileserver-upload.test.ts | 63 +++++++++++++++++++++ 1 file changed, 63 insertions(+) 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,