fix(ocr): report the actual provider and PPTX failure location

HTTP OCR failures in PPTX parsing were incorrectly labeled as local OCR failures. Report the selected provider and slide/image location, and retain bounded structured server diagnostics with configured-key redaction and log IDs. Preserve existing fallback behavior.

Validation: 38 focused tests, typecheck and lint passed. Full test run timed out after 200 seconds. Synthetic service probes reproduced HTTP 500; the server-side failure remains unresolved.

Release note: PPTX parsing warnings now identify the actual OCR provider and failed image location, with server diagnostics for troubleshooting.
This commit is contained in:
mesalogo
2026-10-04 14:54:39 +08:00
parent 658e7f100f
commit 629e82545b
7 changed files with 89 additions and 13 deletions
+20 -1
View File
@@ -1,10 +1,13 @@
import { describe, expect, it, vi } from 'vitest'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { defaultHttpOcrSettings } from '../shared/document-parsing-contracts'
import {
defaultDocumentParsingSettings
} from './document-parsing-settings-store'
import { DocumentParsingService } from './document-parsing-service'
import { createImagePptx } from '../../tests/support/pptx-fixture'
afterEach(() => vi.unstubAllGlobals())
function createPdfFixture(...pageTexts: string[]): Buffer {
const texts = pageTexts.length > 0 ? pageTexts : ['']
const fontObjectId = texts.length + 3
@@ -178,6 +181,22 @@ describe('DocumentParsingService', () => {
expect(recognize).toHaveBeenCalledOnce()
})
it('reports HTTP PPTX failures with the image location without consulting local OCR', async () => {
vi.stubGlobal('fetch', vi.fn(async () => Response.json({ errorCode: 500, errorMsg: 'Internal server error', logId: 'pptx-failure' }, { status: 500 })))
const { service, modelManager, recognize } = createService({ settings: {
ocrProvider: 'paddleocr-vl', httpOcr: { ...defaultHttpOcrSettings, baseUrl: 'http://ocr.test' }
} })
const bytes = createImagePptx('Useful native slide body')
const parsed = await service.parse('slides.pptx', bytes, 'chat-attachment')
expect(parsed.content).toContain('Useful native slide body')
expect(parsed.warnings).toEqual([
'HTTP OCR 未完成,已保留 PPTX 文本内容:幻灯片 1 · 图片 1:HTTP OCR /layout-parsing:HTTP 500;服务错误 500;Internal server error;logId: pptx-failure'
])
await expect(service.parse('slides.pptx', bytes, 'knowledge-index')).rejects.toThrow('幻灯片 1 · 图片 1:HTTP OCR /layout-parsing:HTTP 500')
expect(modelManager.getStatus).not.toHaveBeenCalled()
expect(recognize).not.toHaveBeenCalled()
})
it('keeps useful PDF text local without invoking OCR', async () => {
const { recognize, service } = createService()