Scan complete source text for grounded offer audit requirements

This commit is contained in:
2026-09-06 10:56:04 +03:00
parent 9f70e3e77f
commit 2e16a68565
5 changed files with 75 additions and 2 deletions
+27
View File
@@ -0,0 +1,27 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {sourceRequirements} from '../server/source-requirements.mjs';
test('every source character is scanned and late conditions retain exact location and wording',async()=>{
const text='Standart metin ve açıklamalar. '.repeat(500)+'SON ŞART: Cihazların kurulumu 16 ay boyunca firma sorumluluğundadır.';
const parts=[];
const result=await sourceRequirements(text,async part=>{
parts.push(part);
const start=part.text.indexOf('SON ŞART:');
return {requirements:start<0?[]:[{quote:part.text.slice(start)}]};
});
assert.equal(parts.sort((a,b)=>a.index-b.index).map(p=>p.text).join(''),text);
assert.ok(parts.every(p=>p.text.length<=6000));
assert.equal(result.sourceReview.scannedParts,parts.length);
assert.match(result.requirements[0],/16 ay boyunca/);
const row=result.sourceReview.evidence[0];assert.equal(text.slice(row.start,row.end),row.quote);
});
test('fabricated source quotes and failed source parts stop the audit rather than hiding missing coverage',async()=>{
await assert.rejects(sourceRequirements('Kaynakta yalnız 120 gün vardır.',async()=>({requirements:[{quote:'Kaynakta 60 gün vardır.'}]})),/alıntısı doğrulanamadı/);
await assert.rejects(sourceRequirements('Kaynakta yalnız 120 gün vardır.',async()=>({})),/geçerli liste/);
await assert.rejects(sourceRequirements('X'.repeat(14000),async part=>{if(part.index===1)throw new Error('provider error');return {requirements:[]};}),/provider error/);
});
test('source scan cancellation stops later batches',async()=>{
const controller=new AbortController();let calls=0;
await assert.rejects(sourceRequirements('X'.repeat(20000),async()=>{calls++;controller.abort();return {requirements:[]};},{signal:controller.signal}),{name:'AbortError'});
assert.ok(calls<=2);
});