سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 3, 22:00 UTC
ci: isolate and strictly verify known-RED Stage 2 client compatibility with enforce guard
davoodmehraban89 committed
Oct 17, 2026 at 09:30 UTC
44914b4a8f465c1c1a521de76fae6edb07b68f21
3 files changed
+80
-4
.github/workflows/phase1a-supabase-parity.yml
+32
-2
@@ -142,5 +142,35 @@ jobs:
142
phase1a-migration-preflight.json
143
retention-days: 7
144
if-no-files-found: ignore
145
- - name: Stage 2 legacy JS positive compatibility contract (known RED; retained after Stage 1 checks)
146
- run: node scripts/phase1a-positive-client-contract.mjs
145
+
146
+ client-compat-expected-red-until-stage2:
147
+ name: client-compat-expected-red-until-stage2
148
+ runs-on: ubuntu-latest
149
+ timeout-minutes: 20
150
+ steps:
151
+ - uses: actions/checkout@v4
152
+ - uses: supabase/setup-cli@v1
153
+ with:
154
+ version: 2.121.0
155
+ - name: Verify isolated migration preflight
156
+ run: node scripts/phase1a-migration-preflight.mjs
157
+ - name: Prepare disposable Supabase (never linked to remote)
158
+ run: |
159
+ supabase init --force
160
+ python3 - <<'PY'
161
+ from pathlib import Path
162
+ for p in Path('supabase/migrations').glob('*.sql'):
163
+ b=p.read_bytes()
164
+ if b.endswith(b'\\n'):
165
+ p.write_bytes(b[:-2]+b'\n')
166
+ PY
167
+ mkdir -p /tmp/finora-stage1-migrations
168
+ mv supabase/migrations/2026101610{0000,0500,1000,1500,2000}_*.sql /tmp/finora-stage1-migrations/
169
+ supabase start -x inbucket
170
+ - name: Apply Stage 1 SQL only to disposable database
171
+ run: |
172
+ for migration in /tmp/finora-stage1-migrations/*.sql; do
173
+ PGPASSWORD=postgres psql -h 127.0.0.1 -p 54322 -U postgres -d postgres -X -v ON_ERROR_STOP=1 -f "$migration"
174
+ done
175
+ - name: EXPECTED RED — assert exactly three known Stage 2 client incompatibilities (guard enforce)
176
+ run: node scripts/phase1a-client-compat-expected-red.mjs
scripts/phase1a-client-compat-expected-red.mjs
new
+46
@@ -0,0 +1,46 @@
1
+#!/usr/bin/env node
2
+// Separate, strict KNOWN-RED sentinel. Never certify Stage 1 integration.
3
+import {spawnSync} from 'node:child_process';
4
+import {appendFileSync} from 'node:fs';
5
+const expected=new Map([
6
+ ['existing-client-draft-with-status-and-number','FINORA_SERVER_ONLY_JOURNAL_FIELDS'],
7
+ ['existing-client-batched-draft-and-lines','FINORA_CHILD_PARENT_NOT_FOUND'],
8
+ ['existing-client-post-status-transition','FINORA_SERVER_ONLY_JOURNAL_FIELDS']
9
+]);
10
+const child=spawnSync(process.execPath,['scripts/phase1a-positive-client-contract.mjs'],{encoding:'utf8',timeout:90000});
11
+process.stdout.write(child.stdout||'');
12
+process.stderr.write(child.stderr||'');
13
+const records=(child.stdout||'').split('\n').flatMap(line=>{try{return [JSON.parse(line)]}catch{return []}});
14
+const cases=records.filter(x=>x.scenario);
15
+const totals=records.find(x=>x.clientContractTotal!==undefined);
16
+const errors=[];
17
+if(child.error)errors.push(String(child.error));
18
+if(child.status!==1)errors.push('positive compatibility contract exit must be 1 for known RED');
19
+if(cases.length!==3||new Set(cases.map(x=>x.scenario)).size!==3)errors.push('expected exactly 3 executed distinct scenarios');
20
+if(!totals||totals.clientContractTotal!==3||totals.passed!==0||totals.failed!==3)errors.push('scenario totals changed');
21
+for(const [name,error] of expected){
22
+ const actual=cases.find(x=>x.scenario===name);
23
+ if(!actual){errors.push('missing scenario '+name);continue}
24
+ if(actual.result!=='RED compatibility failure'||!actual.guardEnforceProved||actual.exit===0||!actual.diagnostic.includes('ERROR: '+error)){
25
+ errors.push('unexpected result / no enforce proof / changed error for '+name);
26
+ }
27
+}
28
+const summary=[
29
+ '## EXPECTED RED — client compatibility blocked until Stage 2',
30
+ '',
31
+ '**This is not a green client test and does not certify Stage 1 deployment.**',
32
+ '',
33
+ '| Scenario | Expected failure | Actual |',
34
+ '|---|---|---|',
35
+ ...[...expected].map(([name,e])=>{
36
+ const v=cases.find(x=>x.scenario===name);
37
+ return '| '+name+' | '+e+' | '+(v?.diagnostic||'not executed')+' |';
38
+ }),
39
+ '',
40
+ errors.length?'**SENTINEL FAILED:** '+errors.join(' ; '):'**KNOWN EXPECTED RED CONFIRMED: 3/3, authenticated org guard=enforce.**',
41
+ ''
42
+].join('\n');
43
+if(process.env.GITHUB_STEP_SUMMARY)appendFileSync(process.env.GITHUB_STEP_SUMMARY,summary);
44
+console.log(errors.length?'EXPECTED_RED_SENTINEL_FAILED':'EXPECTED_RED_CONFIRMED_NOT_STAGE1_GREEN');
45
+for(const e of errors)console.error(e);
46
+if(errors.length)process.exitCode=1;
scripts/phase1a-positive-client-contract.mjs
+2
-2
@@ -12,7 +12,7 @@ const q=s=>"'"+JSON.stringify(s).replace(/'/g,"''")+"'::jsonb";
12
const voucher={id:'POSITIVE_JV_1',companyId:'CO',fiscalYearId:'FY',date:'1405/07/24',status:'draft',number:'1',totalDebit:100,totalCredit:100,createdBy:uid};
13
const line=(id,debit,credit)=>({collection:'journalLines',id,data:{voucherId:voucher.id,companyId:'CO',accountId:id,debit,credit},expected_version:0});
14
const v={collection:'journalVouchers',id:voucher.id,data:voucher,expected_version:0};
15
-const head=["BEGIN;","INSERT INTO auth.users(id,instance_id,aud,role,email,email_confirmed_at,raw_user_meta_data) VALUES('"+uid+"','00000000-0000-0000-0000-000000000000','authenticated','authenticated','phase1a-positive@example.invalid',now(),'{}'::jsonb);","INSERT INTO private.finora_phase1a_guard_modes(organization_id,mode) SELECT organization_id,'enforce' FROM public.organization_members WHERE user_id='"+uid+"';"].join('\n');
15
+const head=["BEGIN;","INSERT INTO auth.users(id,instance_id,aud,role,email,email_confirmed_at,raw_user_meta_data) VALUES('"+uid+"','00000000-0000-0000-0000-000000000000','authenticated','authenticated','phase1a-positive@example.invalid',now(),'{}'::jsonb);","INSERT INTO private.finora_phase1a_guard_modes(organization_id,mode) SELECT organization_id,'enforce' FROM public.organization_members WHERE user_id='"+uid+"';","DO $guard$ BEGIN IF (SELECT mode FROM private.finora_phase1a_guard_modes WHERE organization_id=(SELECT organization_id FROM public.organization_members WHERE user_id='"+uid+"' LIMIT 1)) IS DISTINCT FROM 'enforce' THEN RAISE EXCEPTION 'FINORA_GUARD_NOT_ENFORCE'; END IF; RAISE NOTICE 'FINORA_GUARD_ENFORCE_CONFIRMED'; END $guard$;"].join('\n');
16
const rpc=(up)=>"SELECT public.finora_sync_records_v2("+q(up)+",'[]'::jsonb,"+org+");";
17
const scenarios=[
18
{name:'existing-client-draft-with-status-and-number',body:[rpc([v])]},
@@ -33,7 +33,7 @@ for(const s of scenarios){
33
const p=spawnSync('psql',['-X','-qAt','-v','ON_ERROR_STOP=1','-h','127.0.0.1','-p','54322','-U','postgres','-d','postgres'],{input,encoding:'utf8',env:{...process.env,PGPASSWORD:'postgres'},timeout:25000});
34
const ok=p.status===0;
35
if(ok)pass++;
36
- console.log(JSON.stringify({scenario:s.name,result:ok?'PASS':'RED compatibility failure',exit:p.status,diagnostic:(p.stderr||'').split('\n').find(x=>/ERROR:/.test(x))?.slice(0,180)||''}));
36
+ console.log(JSON.stringify({scenario:s.name,result:ok?'PASS':'RED compatibility failure',guardEnforceProved:(p.stderr||'').includes('FINORA_GUARD_ENFORCE_CONFIRMED'),exit:p.status,diagnostic:(p.stderr||'').split('\n').find(x=>/ERROR:/.test(x))?.slice(0,180)||''}));
37
}
38
console.log(JSON.stringify({clientContractTotal:scenarios.length,passed:pass,failed:scenarios.length-pass}));
39
if(pass!==scenarios.length)process.exitCode=1;