diff --git a/src/__tests__/baselines/test-as-never.json b/src/__tests__/baselines/test-as-never.json index 98d2db1c7..adf8c6b01 100644 --- a/src/__tests__/baselines/test-as-never.json +++ b/src/__tests__/baselines/test-as-never.json @@ -1,7 +1,7 @@ { "$comment": "as never casts in tests, per test file under src/. Maintained by src/__tests__/test-realism-ratchet.test.ts.", "count": 523, - "total": 5483, + "total": 5476, "entries": { "__tests__/api/auth/login/mfa-branch.test.ts": 10, "__tests__/api/auth/mfa/verify.test.ts": 9, @@ -360,7 +360,7 @@ "lib/documents/__tests__/assist-kinds.test.ts": 1, "lib/documents/__tests__/commit.test.ts": 9, "lib/documents/__tests__/fenced-chat-pipeline.test.ts": 6, - "lib/documents/__tests__/index-document.test.ts": 22, + "lib/documents/__tests__/index-document.test.ts": 15, "lib/documents/__tests__/index-outcome-record.test.ts": 14, "lib/documents/__tests__/prepare-vision-raster-failure.test.ts": 6, "lib/documents/__tests__/provider-order.test.ts": 1, diff --git a/src/lib/documents/__tests__/index-document.test.ts b/src/lib/documents/__tests__/index-document.test.ts index 6b2cb91fa..baa5b0a4e 100644 --- a/src/lib/documents/__tests__/index-document.test.ts +++ b/src/lib/documents/__tests__/index-document.test.ts @@ -85,6 +85,11 @@ const PICK = { }, }; +/** Answer the provider lookup with {@link PICK}. */ +function pickExternal(): void { + vi.mocked(resolveDocumentVisionProvider).mockResolvedValue(PICK as never); +} + /** A LOCAL (self-hosted) document pick — never egresses, toggle-independent. */ const LOCAL_PICK = { chain: [{ providerType: "local", instance: {} }], @@ -123,7 +128,7 @@ beforeEach(() => { describe("indexDocumentContent — provider-first path", () => { it("indexes via an external provider (vision) when configured + toggle ON", async () => { - vi.mocked(resolveDocumentVisionProvider).mockResolvedValue(PICK as never); + pickExternal(); visionOk(); vi.mocked(transcribeDocument).mockResolvedValue({ text: "haemoglobin 14.2 cholesterol 190", @@ -176,7 +181,7 @@ describe("indexDocumentContent — local fallback path", () => { ...DOC, aiReadDeferred: true, } as never); - vi.mocked(resolveDocumentVisionProvider).mockResolvedValue(PICK as never); + pickExternal(); visionOk(); const outcome = await indexDocumentContent("user-1", "doc-1"); expect(outcome).toMatchObject({ indexed: true, source: "local-pdf" }); @@ -186,7 +191,7 @@ describe("indexDocumentContent — local fallback path", () => { it("a deferred import stays local even with an external pick and the toggle ON", async () => { // #1038 — `aiRead=defer`: the person asked for AI reading to wait. - vi.mocked(resolveDocumentVisionProvider).mockResolvedValue(PICK as never); + pickExternal(); visionOk(); const outcome = await indexDocumentContent("user-1", "doc-1", { localOnly: true, @@ -220,7 +225,7 @@ describe("indexDocumentContent — local fallback path", () => { }); it("stays LOCAL for an external pick when the toggle is OFF (never egresses)", async () => { - vi.mocked(resolveDocumentVisionProvider).mockResolvedValue(PICK as never); + pickExternal(); vi.mocked(documentAutoReadEnabled).mockResolvedValue(false); const outcome = await indexDocumentContent("user-1", "doc-1"); @@ -232,7 +237,7 @@ describe("indexDocumentContent — local fallback path", () => { }); it("falls back to local when the provider cannot read the PDF", async () => { - vi.mocked(resolveDocumentVisionProvider).mockResolvedValue(PICK as never); + pickExternal(); vi.mocked(prepareVisionInput).mockReturnValue({ ok: false, reason: "pdfRendererUnavailable", @@ -245,7 +250,7 @@ describe("indexDocumentContent — local fallback path", () => { }); it("leaves a text-layer read of an unrenderable PDF to the local path, with no provider call", async () => { - vi.mocked(resolveDocumentVisionProvider).mockResolvedValue(PICK as never); + pickExternal(); vi.mocked(prepareVisionInput).mockResolvedValue({ ok: true, mode: "text", @@ -260,7 +265,7 @@ describe("indexDocumentContent — local fallback path", () => { }); it("falls back to local when the daily budget is exhausted", async () => { - vi.mocked(resolveDocumentVisionProvider).mockResolvedValue(PICK as never); + pickExternal(); visionOk(); vi.mocked(reserveBudget).mockResolvedValue({ allowed: false, @@ -273,7 +278,7 @@ describe("indexDocumentContent — local fallback path", () => { }); it("refunds and falls back to local when the provider call throws", async () => { - vi.mocked(resolveDocumentVisionProvider).mockResolvedValue(PICK as never); + pickExternal(); visionOk(); vi.mocked(transcribeDocument).mockRejectedValueOnce(new Error("boom")); @@ -324,7 +329,7 @@ describe("indexDocumentContent — local fallback path", () => { }); it("keeps resource-limit over a provider note: the provider never got further either", async () => { - vi.mocked(resolveDocumentVisionProvider).mockResolvedValue(PICK as never); + pickExternal(); vi.mocked(prepareVisionInput).mockResolvedValue({ ok: false, reason: "rasterFailed", diff --git a/src/lib/documents/__tests__/unrenderable-pdf-text-layer.test.ts b/src/lib/documents/__tests__/unrenderable-pdf-text-layer.test.ts index 2550b17b6..c92d8ba1e 100644 --- a/src/lib/documents/__tests__/unrenderable-pdf-text-layer.test.ts +++ b/src/lib/documents/__tests__/unrenderable-pdf-text-layer.test.ts @@ -63,7 +63,7 @@ const DOC = { }; function stored(bytes: Buffer): void { - vi.mocked(decryptDocumentContent).mockReturnValue(bytes as never); + vi.mocked(decryptDocumentContent).mockReturnValue(bytes); } describe("on a server that cannot render PDF pages", () => { diff --git a/src/lib/documents/ai-runs/__tests__/unrenderable-pdf-runs.test.ts b/src/lib/documents/ai-runs/__tests__/unrenderable-pdf-runs.test.ts index 3ed917b31..8bd2295d8 100644 --- a/src/lib/documents/ai-runs/__tests__/unrenderable-pdf-runs.test.ts +++ b/src/lib/documents/ai-runs/__tests__/unrenderable-pdf-runs.test.ts @@ -197,7 +197,7 @@ const FACTS = JSON.stringify({ const wire = (params: CompletionParams) => JSON.stringify(params); function stored(bytes: Buffer) { - vi.mocked(decryptDocumentContent).mockReturnValue(bytes as never); + vi.mocked(decryptDocumentContent).mockReturnValue(bytes); } beforeEach(() => { diff --git a/src/lib/jobs/__tests__/document-content-index-backfill.test.ts b/src/lib/jobs/__tests__/document-content-index-backfill.test.ts index 3a3129e91..ef91897f3 100644 --- a/src/lib/jobs/__tests__/document-content-index-backfill.test.ts +++ b/src/lib/jobs/__tests__/document-content-index-backfill.test.ts @@ -337,9 +337,7 @@ describe("runContentIndexBackfillForUser", () => { vi.mocked(prisma.inboundDocument.findMany).mockResolvedValue([ { id: "pdf-1" }, ] as never); - vi.mocked(detectOcrMimeType).mockReturnValueOnce( - "application/pdf" as never, - ); + vi.mocked(detectOcrMimeType).mockReturnValueOnce("application/pdf"); vi.mocked(rasterizePdf).mockResolvedValue({ ok: true, images: [{ mediaType: "image/png", dataBase64: "cGFnZQ==" }], @@ -380,9 +378,7 @@ describe("runContentIndexBackfillForUser", () => { vi.mocked(prisma.inboundDocument.findMany).mockResolvedValue([ { id: "pdf-1" }, ] as never); - vi.mocked(detectOcrMimeType).mockReturnValueOnce( - "application/pdf" as never, - ); + vi.mocked(detectOcrMimeType).mockReturnValueOnce("application/pdf"); vi.mocked(rasterizePdf).mockResolvedValue({ ok: false } as never); const result = await runContentIndexBackfillForUser("user-1"); @@ -411,9 +407,7 @@ describe("runContentIndexBackfillForUser", () => { vi.mocked(prisma.inboundDocument.findMany).mockResolvedValue([ { id: "pdf-1" }, ] as never); - vi.mocked(detectOcrMimeType).mockReturnValueOnce( - "application/pdf" as never, - ); + vi.mocked(detectOcrMimeType).mockReturnValueOnce("application/pdf"); vi.mocked(rasterizePdf).mockResolvedValue({ ok: false, reason: "unsupported",