feat: add guarded document workbench foundations
CI (SIAX Cloud) / integration (push) Skipped
CI (SIAX Cloud) / sonar (push) Skipped
masterplan-lock / check (push) Successful in 5s
Security Scan (SIAX Cloud) / security (push) Successful in 15s
CI (SIAX Cloud) / security (push) Successful in 16s
CI (SIAX Cloud) / sonar (pull_request) Skipped
masterplan-lock / check (pull_request) Successful in 7s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 21s
CI (SIAX Cloud) / security (pull_request) Successful in 25s
CI (SIAX Cloud) / quality (push) Successful in 1m17s
CI (SIAX Cloud) / integration (pull_request) Successful in 54s
CI (SIAX Cloud) / quality (pull_request) Successful in 1m7s

This commit is contained in:
2026-11-02 01:26:36 +01:00
parent cb01f948eb
commit bd1c20edb2
34 changed files with 1992 additions and 19 deletions
@@ -75,11 +75,13 @@ describe("DocumentCaptureService.captureFromMailbox", () => {
blobStore: new LocalBlobStore(tmpDir),
aud0BaseUrl: "https://aud0.example.com",
});
const artifactCalls = vi.spyOn(service['st0re'], 'createArtifact');
const result = await service.captureFromMailbox(
{ mailbox: { tenantId: "t", clientId: "c", clientSecret: "s", mailboxAddress: "[email protected]" } },
{ tenant_id: "tenant1", project_id: "proj1", actor_id: "actor1", correlation_id: "corr1" },
);
expect(artifactCalls).toHaveBeenCalledWith(expect.objectContaining({ pii_level: 'high' }));
expect(result.scanned_messages).toBe(1);
expect(result.captured_documents).toHaveLength(1);
const doc = result.captured_documents[0];
@@ -71,6 +71,8 @@ describe("DocumentExtractionService — evidence-based extraction", () => {
documentIntelligence: { endpoint: "https://di.example.com", apiKey: "key123", pollIntervalMs: 1 },
});
const artifactCalls = vi.spyOn(extractionService['st0re'], 'createArtifact');
const fetchMock = vi.fn(async (url: string, init?: RequestInit) => {
if (url.includes(":analyze")) {
return jsonResponse({}, { status: 202, headers: { "operation-location": "https://di.example.com/op/abc" } });
@@ -113,6 +115,7 @@ describe("DocumentExtractionService — evidence-based extraction", () => {
model_id: "prebuilt-invoice",
});
expect(artifactCalls).toHaveBeenCalledWith(expect.objectContaining({ pii_level: 'high' }));
expect(extraction.status).toBe("completed");
// Found fields carry the real value + DI's own confidence.
expect(extraction.fields.VendorName).toEqual({ value: "Acme AB", confidence: 0.97, found: true });
@@ -0,0 +1,25 @@
import { describe, expect, it, vi } from 'vitest';
import { DocumentCaptureService } from '@/src/services/document-capture-service';
import { DocumentExtractionService } from '@/src/services/document-extraction-service';
describe('document extraction scope', () => {
it.each([
{ tenant_id: 'tenant-b', project_id: 'project-a' },
{ tenant_id: 'tenant-a', project_id: 'project-b' },
])('rejects an out-of-scope document before any byte read or external call', async (scope) => {
const capture = new DocumentCaptureService();
vi.spyOn(capture, 'getDocument').mockResolvedValue({ tenant_id: 'tenant-a', project_id: 'project-a' } as never);
const bytes = vi.spyOn(capture, 'getDocumentBytes');
const fetchMock = vi.fn();
vi.stubGlobal('fetch', fetchMock);
try {
const service = new DocumentExtractionService(capture, {
documentIntelligence: { endpoint: 'https://di.example.test', apiKey: 'test-key' },
});
await expect(service.extractDocument('doc', { ...scope, actor_id: 'actor-a', correlation_id: 'corr', model_id: 'test' }))
.rejects.toThrow('Document doc not found');
expect(bytes).not.toHaveBeenCalled();
expect(fetchMock).not.toHaveBeenCalled();
} finally { vi.unstubAllGlobals(); vi.restoreAllMocks(); }
});
});