inspect-S4-public-records.mjs 2.1 KB

1234567891011121314151617181920
  1. // Read only: four exact ksfGetRecord calls; no import/save/update or retries.
  2. import fs from 'node:fs';
  3. import assert from 'node:assert/strict';
  4. import {invoke} from '../server/scripts/platform-client.mjs';
  5. const output='work/S4-public-record-inspection-20261103.json';
  6. assert.equal(fs.existsSync(output),false,'Preserve existing inspection');
  7. const targets=[['KfSource','PjORcvaRHn'],['KfEvidence','xHGV_mRWcG'],['KfSource','5S_Y4IgT5q'],['KfEvidence','CeAEIwymTa']];
  8. const keep=['objectId','title','sourceKind','sourceUrl','platform','rawText','collectedAt','contentHash','dataMode','recordState','reviewState','schemaVersion','externalKey','quote','locator','evidenceKind','verificationState','quoteForm','authorLabel','parentObjectId','publishedAt','productRef','artifactRef','sourceRef'];
  9. const settled=await Promise.allSettled(targets.map(async([className,objectId])=>{
  10. const response=await invoke('ksfGetRecord',{className,objectId});
  11. assert.equal(response.http,200);assert.equal(response.body?.result?.ok,true);
  12. const row=response.body.result.data.record;assert.equal(row?.objectId,objectId);
  13. return{className,objectId,requestId:response.body.result.requestId??null,record:Object.fromEntries(keep.filter(key=>Object.hasOwn(row,key)).map(key=>[key,row[key]]))};
  14. }));
  15. const failures=settled.flatMap((r,i)=>r.status==='rejected'?[targets[i]]:[]);
  16. const result={ok:failures.length===0,at:new Date().toISOString(),readOnly:true,businessWrites:0,readFunctionCalls:4,failures,records:settled.filter(r=>r.status==='fulfilled').map(r=>r.value)};
  17. fs.writeFileSync(output,JSON.stringify(result,null,2)+'\n',{flag:'wx'});
  18. console.log(JSON.stringify({ok:result.ok,readFunctionCalls:4,failures,records:result.records.map(({className,objectId,record})=>({className,objectId,characters:record.rawText?[...record.rawText].length:undefined,evidenceKind:record.evidenceKind,verificationState:record.verificationState,quoteForm:record.quoteForm,authorLabel:record.authorLabel,publishedAt:record.publishedAt,locatorKeys:record.locator?Object.keys(record.locator):undefined}))},null,2));
  19. if(failures.length)process.exitCode=1;