Persist versioned document text reviews against source file hashes
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import {test} from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import {tmpdir} from 'node:os';
|
||||
import path from 'node:path';
|
||||
test('document review becomes stale when actual source bytes change; deletion removes private history',async()=>{
|
||||
const dir=fs.mkdtempSync(path.join(tmpdir(),'ihale-review-'));
|
||||
process.env.IHALEIST_USER_DATA_DIR=dir;
|
||||
const store=await import('../server/user-store.mjs');
|
||||
const {documentReview,saveDocumentReview}=await import('../server/document-review.mjs');
|
||||
try {
|
||||
const id=store.saveDocumentFile('owner',{ad:'qa.txt',tur:'ihale',ikn:'2026/1'},Buffer.from('Original source'));
|
||||
const source=documentReview('owner',id);
|
||||
const input={fileHash:source.fileHash,expectedRevision:0,correctedText:'A complete synthetic corrected document text for the test.',note:'All pages compared in this isolated synthetic test.',allPagesCompared:true};
|
||||
saveDocumentReview('owner',id,input);
|
||||
const record=store.getDocument('owner',id);
|
||||
fs.writeFileSync(path.join(store.BELGE_DIR,record.dosya),'Changed source bytes');
|
||||
assert.equal(documentReview('owner',id).stale,true);
|
||||
assert.throws(()=>saveDocumentReview('owner',id,{...input,expectedRevision:1}),e=>e.status===409);
|
||||
store.deleteDocument('owner',id);
|
||||
const db=store.openDb();
|
||||
try {assert.equal(db.prepare('SELECT COUNT(*) n FROM document_text_reviews').get().n,0);}finally{db.close();}
|
||||
} finally {fs.rmSync(dir,{recursive:true,force:true});}
|
||||
});
|
||||
Reference in New Issue
Block a user