fix(workbench): accept a JSON-number decimal and deliver the source's exact string
CI (SIAX Cloud) / integration (push) Skipped
CI (SIAX Cloud) / sonar (push) Skipped
masterplan-lock / check (push) Successful in 6s
Security Scan (SIAX Cloud) / security (push) Successful in 13s
CI (SIAX Cloud) / security (push) Successful in 15s
CI (SIAX Cloud) / quality (push) Successful in 59s
CI (SIAX Cloud) / integration (push) Skipped
CI (SIAX Cloud) / sonar (push) Skipped
masterplan-lock / check (push) Successful in 6s
Security Scan (SIAX Cloud) / security (push) Successful in 13s
CI (SIAX Cloud) / security (push) Successful in 15s
CI (SIAX Cloud) / quality (push) Successful in 59s
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