From 98517c27580e7a2426a2c11c7aaf364db65e2942 Mon Sep 17 00:00:00 2001 From: cliffhall Date: Wed, 8 Jul 2026 16:43:41 -0400 Subject: [PATCH] test(auth): fix type error in remote backend write() test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `tsc -b` (run in CI's validate step, but not by vitest locally) rejected `ok.mock.calls[0][1].body` — under the project's strict indexing the untyped mock's call tuple is `[]`, so `[0]` is possibly-undefined and `[1]` is out of range. Capture the request body inside a `vi.fn` implementation instead of indexing into `mock.calls`. Co-Authored-By: Claude Opus 4.8 (1M context) --- clients/web/src/test/core/auth/oauth-persist.test.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/clients/web/src/test/core/auth/oauth-persist.test.ts b/clients/web/src/test/core/auth/oauth-persist.test.ts index ac0c42ab..f55b37b0 100644 --- a/clients/web/src/test/core/auth/oauth-persist.test.ts +++ b/clients/web/src/test/core/auth/oauth-persist.test.ts @@ -131,19 +131,22 @@ describe("createRemoteOAuthPersistBackend", () => { }); it("write() POSTs the serialized snapshot and throws on failure", async () => { - const ok = vi.fn(async () => new Response("", { status: 200 })); + let capturedBody: string | undefined; + const ok = vi.fn(async (_input, init) => { + capturedBody = init?.body as string | undefined; + return new Response("", { status: 200 }); + }); const backend = createRemoteOAuthPersistBackend({ baseUrl, storeId, - fetchFn: ok as unknown as typeof fetch, + fetchFn: ok, }); await backend.write(SNAPSHOT); expect(ok).toHaveBeenCalledWith( url, expect.objectContaining({ method: "POST" }), ); - const body = ok.mock.calls[0][1].body; - expect(JSON.parse(body)).toEqual(SNAPSHOT); + expect(JSON.parse(capturedBody ?? "")).toEqual(SNAPSHOT); const failing = createRemoteOAuthPersistBackend({ baseUrl,