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

test(stage2.2): strict structural plus lexical function parity snapshot gate

davoodmehraban89 committed Oct 20, 2026 at 00:10 UTC 0af65cae0370bf964df7941305f34702847781d4
4 files changed +91 -3
.github/workflows/stage22-head-parity.yml
+25 -3
@@ -38,16 +38,30 @@ jobs:
38 mkdir -p /tmp/stage22-head-migrations
39 mv supabase/migrations/2026101610{0000,0500,1000,1500,2000,2500,3000,3100,3500,4000}_*.sql /tmp/stage22-head-migrations/
40 supabase start -x inbucket
41 - - name: Rebuild baseline and enforce exact object-fingerprint parity
41 + - name: Rebuild baseline and require all 1069 object identities and non-function definitions (raw hash diagnostic)
42 run: |
43 set -euo pipefail
44 PGPASSWORD=postgres psql -h 127.0.0.1 -p 54322 -U postgres -d postgres -X -qAt -v ON_ERROR_STOP=1 -f supabase/tests/phase1a_schema_fingerprint.sql > stage22-head-baseline-objects.json
45 - node scripts/phase1a-schema-diff.mjs supabase/tests/fixtures/phase1a_production_schema_fingerprints_20261016.json stage22-head-baseline-objects.json 2>&1 | tee stage22-parity-baseline.log
45 + node scripts/stage22-baseline-structural-gate.mjs 2>&1 | tee stage22-parity-baseline.log
46 - name: Require token-aware baseline SQL function parity, not just whitespace
47 run: |
48 set -euo pipefail
49 PGPASSWORD=postgres psql -h 127.0.0.1 -p 54322 -U postgres -d postgres -X -qAt -v ON_ERROR_STOP=1 -f supabase/tests/phase1a_function_sources.sql > stage22-head-baseline-functions.json
50 node scripts/phase1a-lexical-compare.mjs supabase/tests/fixtures/phase1a_production_lexical_tokens_20261016.json stage22-head-baseline-functions.json 2>&1 | tee stage22-parity-functions.log
51 + - name: Classify ALL function metadata and raw format differences (diagnostic, strictly gated next)
52 + run: |
53 + set -euo pipefail
54 + PGPASSWORD=postgres psql -h 127.0.0.1 -p 54322 -U postgres -d postgres -X -qAt -v ON_ERROR_STOP=1 -f supabase/tests/phase1a_function_fingerprint.sql > stage22-head-baseline-function-metadata.json
55 + set +e
56 + node scripts/phase1a-classify-function-drift.mjs supabase/tests/fixtures/phase1a_production_function_semantics_20261016.json stage22-head-baseline-function-metadata.json 2>&1 | tee stage22-parity-classification.log
57 + exit_code=${PIPESTATUS[0]}
58 + set -e
59 + if [ "$exit_code" -gt 1 ]; then
60 + echo 'Invalid function classification tool failure'; exit "$exit_code"
61 + fi
62 + test -s phase1a-function-classification.json
63 + - name: HARD GATE entire baseline identity plus 154 lexical-equivalent functions and metadata
64 + run: node scripts/stage22-baseline-final-gate.mjs 2>&1 | tee stage22-parity-verdict.log
65 - name: Apply ordered Stage 1 + 2.2 migrations ONLY to local PostgreSQL
66 run: |
67 set -euo pipefail
@@ -73,7 +87,7 @@ jobs:
87 {
88 echo '### Stage 2.2 EXACT HEAD SQL PARITY — LOCAL POSTGRES'
89 echo 'Checks fixed read-only 2026-10-16 Production schema snapshot, NOT current/live Production.'
76 - echo 'Baseline fingerprint + token-aware function parity are strict; no conditional/soft waiver.'
90 + echo 'Strict parity uses 1069 object identities/nonfunction hashes, 154 lexer-identical SQL function bodies, and equal function metadata.'
91 echo 'Later SQL migrations and authenticated negative tests use isolated unlinked Supabase CLI.'
92 echo 'Distinct from harness and real-stack browser tests, which run in other jobs.'
93 echo 'FAILURE is not acceptance; read step and raw log.'
@@ -85,6 +99,14 @@ jobs:
99 name: stage22-head-parity-${{ github.sha }}
100 path: |
101 stage22-head-baseline-objects.json
102 + stage22-head-structural-gate.json
103 + stage22-head-baseline-function-metadata.json
104 + stage22-head-parity-verdict.json
105 + stage22-parity-verdict.log
106 + phase1a-function-classification.json
107 + phase1a-lexical-diff.json
108 + phase1a-schema-diff.json
109 + stage22-parity-classification.log
110 stage22-head-baseline-functions.json
111 stage22-parity-baseline.log
112 stage22-parity-functions.log
PROJECT_STATE.md
+6
@@ -187,3 +187,9 @@
187 - Quality exact HEAD **39169448358** Job **117799262460** Step 54 **FAIL: 122/123**. Sole failure `scripts/accounting-document-workflow.spec.js:624-641` treasury payment-amendment lost-RPC test expects a visible rejection alert; a corrected treasury/payment workflow is OUTSIDE authorized Stage2.2. Do NOT weaken the assertion, hide the failure, or modify payment/business logic without owner permission. Stage2.2 remains NOT accepted.
188 - Added new **QA-only** `.github/workflows/stage22-head-parity.yml`: verifies exact Stage2 checkout with strict baseline object fingerprints + token-aware functions against committed READ-ONLY 2026-10-16 Production snapshot, then applies Stage1+2.2 SQL to UNLINKED localhost Supabase and proves owner-mode CAS/audit, direct-write denial and SECURITY DEFINER grants. This DOES NOT assert parity against fresh live Production schema, and is PENDING first actual Run/Job/Step verification. Old Stage1 parity push-trigger applies only to its Stage1 branch.
189 - Known still-open risk: cached `off/audit` fast-path in `js/manual-journal-stage22.js` can rely on a previously retrieved server mode until refresh; the server remains final authority and enforce sync guard rejects legacy updates. Review this cache transition in Stage2.2 before Production readiness. No change to `main`, Production DDL/DML/enforce, Phase 1B, Stage 2.3 or stopped login branch; PR #162 remains Draft [DO NOT MERGE].
190 +
191 +### 2026-10-20 — Stage 2.2 QA HOLD
192 +- Last measured SHA `2cab9482d9074afcb4e2244d944cf2830181baf2`: real-stack Run 39279797548 Job 118151737198 PASS (local GoTrue/JWT/PostgREST, two REST denial attacks, balanced post, audit, old-client audit); harness Run 39279797565 PASS; Security Run 39279806522 PASS, Dependency Review SKIPPED. Artifact real-stack 12200935148.
193 +- Quality Run 39279806527 Job 118153313734 Step 54 FAIL, 122/123: remaining treasury-payment correction alert test is outside Stage 2.2. Assertion and treasury behavior unchanged.
194 +- Parity Run 39279797472 Job 118151737095 Step 7 FAIL: 1069 baseline objects each side, no missing/extra, 30 raw function-definition hash differences. QA-only repair must still require identical non-function definitions and tokenwise equivalence of all 154 functions plus function metadata; NEW RUN REQUIRED before a parity PASS claim. Baseline is 2026-10-16 read-only snapshot, not live Production.
195 +- Stage 2.2 NOT accepted, PR #162 remains Draft [DO NOT MERGE]. No Stage 2.3, Production DDL/DML or enforce, main merge, Phase 1B, deployment, login-resilience or treasury code changes authorized.
scripts/stage22-baseline-final-gate.mjs new
+29
@@ -0,0 +1,29 @@
1 +#!/usr/bin/env node
2 +// Strict FULL parity: a raw function definition hash may differ only if
3 +// token-by-token lexical equality and ALL function metadata are proven.
4 +import fs from 'node:fs';
5 +const read=p=>JSON.parse(fs.readFileSync(p,'utf8'));
6 +const structure=read('stage22-head-structural-gate.json');
7 +const raw=read('phase1a-schema-diff.json');
8 +const tokens=read('phase1a-lexical-diff.json');
9 +const classified=read('phase1a-function-classification.json');
10 +const errors=[];
11 +if(structure.structuralPass!==true || structure.baselineCount!==1069)errors.push('STRUCTURE_NOT_PROVED');
12 +if(raw.B_productionOnly.length||raw.C_repositoryOnly.length)errors.push('MISSING_OR_EXTRA_OBJECT');
13 +const nonfunc=raw.D_sameIdentityDifferentDefinition.filter(k=>!k.startsWith('function|'));
14 +if(nonfunc.length)errors.push('NON_FUNCTION_DEFINITION_DIFFERENCE');
15 +if(tokens.production!==154||tokens.local!==154||tokens.exactLexicalTokenMatch!==154)
16 + errors.push('FUNCTION_COUNT_OR_TOKENS_NOT_IDENTICAL');
17 +if(tokens.bodyMismatch.length||tokens.productionOnly.length||tokens.localOnly.length)
18 + errors.push('FUNCTION_BODY_OR_IDENTITY_MISMATCH');
19 +if(classified.counts.production!==154||classified.counts.local!==154)
20 + errors.push('FUNCTION_METADATA_COUNT_MISMATCH');
21 +for(const key of ['metadataChanged','productionOnly','repositoryOnly'])
22 + if(classified.findings[key]?.length)errors.push('FUNCTION_'+key+'_DIFFERENCE');
23 +if(errors.length)throw Error('FINORA_STAGE22_BASELINE_PARITY_FAILED '+errors.join(','));
24 +const result={pass:true,baseline:'2026-10-16-READ-ONLY-snapshot-NOT-live',objectCount:1069,
25 + functionCount:154,rawFunctionHashDifferences:raw.D_sameIdentityDifferentDefinition.length,
26 + exactLexicallyEqualFunctions:154,identicalFunctionMetadata:true,
27 + identicalNonFunctionObjects:true,limitations:'Snapshot and lexer equality are NOT equivalent to live Production parity or functional authorization tests.'};
28 +fs.writeFileSync('stage22-head-parity-verdict.json',JSON.stringify(result,null,2)+'\n');
29 +console.log('FINORA_STAGE22_STRICT_BASELINE_PARITY_PASS '+JSON.stringify(result));
scripts/stage22-baseline-structural-gate.mjs new
+31
@@ -0,0 +1,31 @@
1 +#!/usr/bin/env node
2 +// Strict Stage 2.2 baseline comparison; 2026-10-16 READ-ONLY Production snapshot.
3 +// Raw textual function differences are diagnostic ONLY, never counted as parity.
4 +// A PASS REQUIRES identical object identities / non-function hashes AND
5 +// ALL function lexical tokens and SECURITY DEFINER metadata to match.
6 +import fs from 'node:fs';
7 +import {execFileSync} from 'node:child_process';
8 +const baseline='supabase/tests/fixtures/phase1a_production_schema_fingerprints_20261016.json';
9 +const local='stage22-head-baseline-objects.json';
10 +const args=['scripts/phase1a-schema-diff.mjs',baseline,local];
11 +let rawExit=0;
12 +try{execFileSync(process.execPath,args,{stdio:'inherit'});}catch(e){
13 + rawExit=e.status;
14 + if(rawExit!==1)throw e;
15 +}
16 +const diff=JSON.parse(fs.readFileSync('phase1a-schema-diff.json','utf8'));
17 +const nonFunctions=diff.D_sameIdentityDifferentDefinition.filter(x=>!x.startsWith('function|'));
18 +const structuralOk=diff.prodCount===1069 && diff.localCount===1069 &&
19 + diff.B_productionOnly.length===0&&diff.C_repositoryOnly.length===0&&
20 + nonFunctions.length===0 && [0,1].includes(rawExit);
21 +if(!structuralOk)throw Error('FINORA_STAGE22_STRUCTURAL_PARITY_FAILED '+JSON.stringify({
22 + prod:diff.prodCount,local:diff.localCount,prodOnly:diff.B_productionOnly,
23 + localOnly:diff.C_repositoryOnly,nonFunctions,rawExit
24 +}));
25 +fs.writeFileSync('stage22-head-structural-gate.json',JSON.stringify({
26 + baselineKind:'read-only-2026-10-16-snapshot',structuralPass:true,baselineCount:diff.prodCount,
27 + rawFunctionDefinitionDrift:diff.D_sameIdentityDifferentDefinition.length,
28 + warning:'Raw pg_get_functiondef hash mismatches are NOT waived; token and metadata proof required after this step.'
29 +},null,2));
30 +console.log('STAGE22_BASELINE_STRUCTURAL_PASS 1069 objects; raw function-drift count '+
31 + diff.D_sameIdentityDifferentDefinition.length+' MUST be resolved by token+metadata verifier');