fix(workbench): accept a JSON-number decimal and deliver the source's exact string
CI (SIAX Cloud) / sonar (pull_request) Skipped
CI (SIAX Cloud) / sonar (push) Skipped
CI (SIAX Cloud) / integration (push) Skipped
masterplan-lock / check (push) Successful in 4s
masterplan-lock / check (pull_request) Successful in 8s
CI (SIAX Cloud) / security (push) Successful in 17s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 24s
CI (SIAX Cloud) / security (pull_request) Successful in 25s
CI (SIAX Cloud) / integration (pull_request) Successful in 33s
Security Scan (SIAX Cloud) / security (push) Successful in 33s
CI (SIAX Cloud) / quality (push) Successful in 54s
CI (SIAX Cloud) / quality (pull_request) Successful in 58s
CI (SIAX Cloud) / sonar (pull_request) Skipped
CI (SIAX Cloud) / sonar (push) Skipped
CI (SIAX Cloud) / integration (push) Skipped
masterplan-lock / check (push) Successful in 4s
masterplan-lock / check (pull_request) Successful in 8s
CI (SIAX Cloud) / security (push) Successful in 17s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 24s
CI (SIAX Cloud) / security (pull_request) Successful in 25s
CI (SIAX Cloud) / integration (pull_request) Successful in 33s
Security Scan (SIAX Cloud) / security (push) Successful in 33s
CI (SIAX Cloud) / quality (push) Successful in 54s
CI (SIAX Cloud) / quality (pull_request) Successful in 58s
The local model returns 12500.00 as a JSON number, which the contract rejects as a non-string decimal. A numeric value now matches a source span numerically and the delivered value is rewritten to that span's decimal string (12500.00), so precision is preserved instead of rounded. Exact string equality is still required for string decimals, and ambiguous formats still go to review.
This commit is contained in:
@@ -181,6 +181,21 @@ describe('structure document workflow', () => {
|
||||
expect(out.evidence.map((e) => e.transform)).toEqual(['decimal', 'date']);
|
||||
expect(out.evidence[0]).toMatchObject({ start: 8, end: 17 });
|
||||
});
|
||||
it('rewrites a JSON-number decimal to the exact source string (no rounding)', async () => {
|
||||
const out = await structureDocument({
|
||||
request,
|
||||
countTokens: vi.fn(async () => 50),
|
||||
instructions: 'Extract the amount',
|
||||
fields: [{ name: 'amount', type: 'decimal' as const, required: true }],
|
||||
sources: [{ id: 'p1', text: 'Belopp: 12 500,00 SEK' }],
|
||||
gateway: {
|
||||
complete: vi.fn(async () => ({ ...response, content: JSON.stringify({ amount: 12500 }) })),
|
||||
},
|
||||
});
|
||||
expect(out.status).toBe('mechanically_validated');
|
||||
if (out.status !== 'mechanically_validated') throw new Error('expected validated');
|
||||
expect(out.value.amount).toBe('12500.00');
|
||||
});
|
||||
it('rejects malformed contracts before a model call', async () => {
|
||||
const complete = vi.fn(async () => response);
|
||||
await expect(structureDocument({ ...base, fields: [], gateway: { complete } })).rejects.toThrow(
|
||||
|
||||
Reference in New Issue
Block a user