test(documents): type the fixtures the text-layer cases added instead of casting them

The stored bytes are already a Buffer and the MIME literal already fits
its union, so neither needs a cast; the external pick goes through one
helper. The as-never ratchet tightens accordingly.
This commit is contained in:
Marc-André Bombeck committed 2026-11-03 22:36:18 +01:00
1 parent 7cb67c2e75
commit 144840bab9
5 files changed
+21 -22

No files matched your search

+2 -2
View File
@@ -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,
@@ -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",
@@ -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", () => {
@@ -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(() => {
@@ -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",