feat(backend): deliver Phase 3 document and voice integration
Add authenticated upload, review, retry and knowledge-selection HTTP flows with bounded JSON processing and frozen OCR policy. Preserve Gemini/OpenAI provider selection and fenced lifecycle semantics; retain FAQ preambles and uncertain vision candidates, and expose opt-in uncalibrated voice transport diagnostics. Include frontend integration examples, aligned contracts and deterministic regressions. Validation: 1767 provider-free tests passed; all 404 PostgreSQL scenarios have passing evidence across the documented runs.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
"""Execute the delivered HTTP helper; multipart boundaries stay browser-owned."""
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
|
||||
def test_executable_document_http_handoff():
|
||||
node = shutil.which('node')
|
||||
assert node, 'Node is required for the executable frontend handoff check'
|
||||
source = Path('examples/document-client.js').read_text()
|
||||
script = '''
|
||||
import assert from 'node:assert/strict';
|
||||
const {DocumentClient} = await import('data:text/javascript;base64,' + Buffer.from(SOURCE).toString('base64'));
|
||||
const calls = [];
|
||||
globalThis.fetch = async (path, options) => {calls.push({path, options}); return {ok:true,json:async()=>({status:'queued'})};};
|
||||
const client = new DocumentClient({csrf:'session-csrf'});
|
||||
const file = new File(['original'], 'source.md');
|
||||
await client.upload(file, 'Source', 'stable-upload-key');
|
||||
assert.equal(calls[0].options.body.get('file').name, 'source.md');
|
||||
assert.equal(calls[0].options.headers['Content-Type'], undefined);
|
||||
assert.equal(calls[0].options.headers['Idempotency-Key'], 'stable-upload-key');
|
||||
assert.equal(calls[0].options.headers['X-CSRF-Token'], 'session-csrf');
|
||||
assert.equal(calls[0].options.credentials, 'same-origin');
|
||||
await client.retry('document-id', 'retry-key');
|
||||
assert.equal(calls[1].options.body, undefined);
|
||||
await client.replace(3, ['document-id']);
|
||||
assert.deepEqual(JSON.parse(calls[2].options.body), {expected_revision:3,document_ids:['document-id']});
|
||||
await client.review('document-id', 'digest');
|
||||
assert.equal(calls[3].path, '/api/v1/documents/document-id/extraction-review?cursor=digest');
|
||||
globalThis.fetch = async () => ({ok:false,status:409,json:async()=>({error:{code:'REVISION_CONFLICT',request_id:'correlation',details:{}}})});
|
||||
await assert.rejects(client.replace(1, []), {message:'REVISION_CONFLICT',requestID:'correlation'});
|
||||
'''
|
||||
import json
|
||||
result = subprocess.run([node, '--input-type=module', '-e', 'const SOURCE = ' + json.dumps(source) + ';\n' + script], capture_output=True, text=True, timeout=10)
|
||||
assert result.returncode == 0, result.stderr
|
||||
Reference in New Issue
Block a user