feat: complete workflow recovery and safe administration
This commit is contained in:
1 parent
1148aa6f14
commit
69583e8c33
46 files changed
+756
-120
No files matched your search
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
const test=require('node:test'),assert=require('node:assert/strict'),fs=require('node:fs'),os=require('node:os'),path=require('node:path');
|
||||
const {Store}=require('../../src/modules/dashboard/store.cjs');
|
||||
function fixture(t){const dir=fs.mkdtempSync(path.join(os.tmpdir(),'job-retention-'));t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));return {dir,store:new Store(dir)};}
|
||||
test('legacy 5001 PDF jobs migrate intact and an additional export never evicts their evidence',t=>{
|
||||
const f=fixture(t),legacy={...f.store.data,jobs:Array.from({length:5001},(_,i)=>({jobId:'job-'+String(i).padStart(5,'0'),status:'success',filename:'record-'+i+'.pdf',metadata:{order:'ORDER-'+i},updatedAt:'2026-10-21T00:00:00Z'}))};
|
||||
f.store.database(db=>db.prepare('UPDATE dashboard_state SET value=? WHERE id=1').run(JSON.stringify(legacy)));
|
||||
const store=new Store(f.dir);store.recordJob({jobId:'latest',status:'success',filename:'new.pdf'});assert.equal(store.jobs().length,5002);assert.ok(store.jobs().some(job=>job.jobId==='job-00000'));
|
||||
const restarted=new Store(f.dir);assert.equal(restarted.jobs().length,5002);assert.equal(typeof restarted.job,'function');assert.equal(restarted.job('job-00000').filename,'record-0.pdf');
|
||||
const state=restarted.database(db=>JSON.parse(db.prepare('SELECT value FROM dashboard_state WHERE id=1').get().value));assert.ok(!state.jobs,'job rows must not remain in the growing settings JSON');
|
||||
});
|
||||
test('SQL job pagination clamps, searches literal wildcards and retains a stable empty first page',t=>{
|
||||
const f=fixture(t);assert.equal(typeof f.store.jobPage,'function');for(let i=0;i<76;i++)f.store.recordJob({jobId:'j-'+i,status:'running',metadata:{order:i===0?'LITERAL_%':'ORDER-'+i}});
|
||||
const last=f.store.jobPage({page:99,pageSize:25});assert.equal(last.page,4);assert.equal(last.jobs.length,1);assert.equal(last.total,76);
|
||||
assert.equal(f.store.jobPage({q:'_%'}).total,1);const empty=f.store.jobPage({status:'interrupted',page:99});assert.equal(empty.page,1);assert.equal(empty.total,0);assert.deepEqual(empty.jobs,[]);
|
||||
});
|
||||
test('job and audit updates roll back together when SQLite rejects the new evidence row',t=>{
|
||||
const f=fixture(t),exists=f.store.database(db=>db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='pdf_jobs'").get());assert.ok(exists,'jobs require their own durable table');
|
||||
f.store.database(db=>db.exec("CREATE TRIGGER reject_job BEFORE INSERT ON pdf_jobs BEGIN SELECT RAISE(ABORT,'synthetic database failure'); END"));const before=f.store.audit();
|
||||
assert.throws(()=>f.store.recordJob({jobId:'rejected',status:'error',error:'synthetic'}),/synthetic/);assert.deepEqual(f.store.audit(),before);assert.equal(f.store.jobs().length,0);
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
const test=require('node:test'),assert=require('node:assert/strict'),fs=require('node:fs'),os=require('node:os'),path=require('node:path');
|
||||
const {Store}=require('../../src/modules/dashboard/store.cjs'),{createDashboard}=require('../../src/app/dashboard.cjs');
|
||||
test('capacity and history export preserve all rows and expose only authorized safe fields',async t=>{
|
||||
const dir=fs.mkdtempSync(path.join(os.tmpdir(),'maintenance-')),store=new Store(path.join(dir,'dashboard'));store.bootstrap('admin','Synthetic-password-123');store.addUser({username:'viewer',password:'Synthetic-password-123',role:'viewer'},'admin');store.recordJob({jobId:'oldest',status:'success',path:'PRIVATE_PATH',metadata:{order:'ORDER-1',form:'PRIVATE_FORM',password:'PRIVATE_PASSWORD'},error:'PRIVATE_ERROR'});fs.mkdirSync(path.join(dir,'pdf'));fs.writeFileSync(path.join(dir,'pdf','one.pdf'),'%PDF-fixture');const server=createDashboard({store,outputDir:path.join(dir,'pdf')});await new Promise(r=>server.listen(0,'127.0.0.1',r));t.after(async()=>{server.closeAllConnections();await new Promise(r=>server.close(r));fs.rmSync(dir,{recursive:true,force:true});});const base='http://127.0.0.1:'+server.address().port;
|
||||
const login=async username=>(await fetch(base+'/api/login',{method:'POST',headers:{Origin:base,'Content-Type':'application/json'},body:JSON.stringify({username,password:'Synthetic-password-123'})})).headers.get('set-cookie').split(';')[0];
|
||||
assert.equal((await fetch(base+'/api/maintenance')).status,401);const viewer=await login('viewer');assert.equal((await fetch(base+'/api/maintenance',{headers:{Cookie:viewer}})).status,403);const admin=await login('admin'),headers={Cookie:admin};
|
||||
const capacity=await fetch(base+'/api/maintenance',{headers});assert.equal(capacity.status,200);const data=await capacity.json();assert.equal(data.retention,'permanent');assert.equal(data.jobs.total,1);assert.equal(data.pdf.files,1);assert.equal(data.pdf.bytes,12);
|
||||
const exported=await fetch(base+'/api/jobs/export',{headers});assert.equal(exported.status,200);const body=await exported.text();assert.match(body,/ORDER-1/);assert.doesNotMatch(body,/PRIVATE_/);assert.equal(JSON.parse(body.trim()).jobId,'oldest');assert.equal(store.jobs().length,1);
|
||||
});
|
||||
Reference in new issue
Block a user