@davoodmehraban89 / Factor-easy / commits / 7fd5c71
Fork 0

سامانه صدور فاکتور و حسابداری

test: wait for final PostgreSQL server before inventory fixtures

JVK committed Nov 14, 2026 at 14:30 UTC 7fd5c71551a20a0858aeea6db3d4eae00dde5806
2 files changed +5 -2
PROJECT_STATE.md
+1
@@ -308,3 +308,4 @@ Owner requests layer-by-layer click/functional testing of all controls and compa
308 - Local acceptance: four new source cases failed before repair because the real About link did not exist, then4/4 source and4/4 generated Pages PASS; real route/header clicks, existing destination, exact decoded generic draft, no pre-click navigation, keyboard Tab/Enter,390px bounds and noopener verified. Every external request was intercepted; WhatsApp delivery/editing UI itself is not tested. Static quality, public CSP/build checks, release-safety and diff checks PASS.
309 - Independent read-only review found no application/security defect and one CI gap: source-only invocation omitted the generated artifact. Added a dedicated generated-Pages invocation to the existing Quality job; no assertion or security gate weakened. Exact PR/main CI and publication evidence will be maintained in this fix PR. Financial work remains separate and incomplete.
310
311 +- Release gate found an unrelated baseline test-harness race in main201 and PR202: Docker PostgreSQL's temporary Unix-socket initialization server answered pg_isready, then stopped before fixture inserts (psql socket missing, job132399047199). Read the actual image entrypoint: temporary init uses listen_addresses='', while the final server listens on loopback. Correct readiness and test SQL connections to container-local TCP127.0.0.1; preserve network=none, all financial assertions and no host port. This is a test-only prerequisite repair, not a financial query/schema change.
scripts/draft-conversion-inventory.test.mjs
+4 -2
@@ -12,7 +12,7 @@ test('source-derived inventory on isolated PostgreSQL preserves scope, exact amo
12 const r=spawnSync('docker',args,{input,encoding:'utf8',timeout:30000,maxBuffer:4*1024*1024});
13 if(r.status!==0)throw Error(r.stderr||r.error?.message||'docker failed');return r.stdout;
14 }
15 - const sql=q=>docker(['exec','-i',name,'psql','-X','-A','-t','-v','ON_ERROR_STOP=1','-U','postgres'],q).trim();
15 + const sql=q=>docker(['exec','-i',name,'psql','-h','127.0.0.1','-X','-A','-t','-v','ON_ERROR_STOP=1','-U','postgres'],q).trim();
16 const query=readFileSync(new URL('./sql/draft-conversion-inventory.sql',import.meta.url),'utf8');
17 const inventory=()=>JSON.parse(sql(query));
18 const owner='00000000-0000-4000-8000-000000000001',org='00000000-0000-4000-8000-000000000002';
@@ -20,9 +20,11 @@ test('source-derived inventory on isolated PostgreSQL preserves scope, exact amo
20 const insert=(collection,id,data)=>sql(`insert into public.records values (${quote(owner)},${quote(collection)},${quote(id)},${quote(JSON.stringify(data))}::jsonb,now(),${quote(org)});`);
21 try{
22 docker(['run','--detach','--name',name,'--network','none','--tmpfs','/var/lib/postgresql/data','-e','POSTGRES_HOST_AUTH_METHOD=trust','postgres:17-alpine']);
23 + // The image's temporary initialization server accepts Unix sockets before
24 + // restarting. TCP becomes available only on the final server; query the same endpoint.
25 let ready=false;
26 for(let i=0;i<60;i++){
25 - const r=spawnSync('docker',['exec',name,'pg_isready','-U','postgres'],{encoding:'utf8',timeout:3000});
27 + const r=spawnSync('docker',['exec',name,'pg_isready','-h','127.0.0.1','-U','postgres'],{encoding:'utf8',timeout:3000});
28 if(r.status===0){ready=true;break;}await new Promise(resolve=>setTimeout(resolve,250));
29 }
30 assert.ok(ready,'isolated PostgreSQL ready');