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

test(stage2.2): exact-head isolated baseline schema parity and owner guard audit; record Quality hold

davoodmehraban89 committed Oct 19, 2026 at 19:08 UTC 2486b9cda092c521ae7d159280bb7842f5e5d705
2 files changed +95
.github/workflows/stage22-head-parity.yml new
+89
@@ -0,0 +1,89 @@
1 +name: FINORA Stage 2.2 exact-head baseline parity (local ONLY)
2 +on:
3 + push:
4 + branches: [feature/finora-stage2-manual-canary-20261017]
5 + workflow_dispatch:
6 +permissions:
7 + contents: read
8 +jobs:
9 + stage22-exact-head-parity:
10 + name: stage22-exact-head-parity (snapshot NOT live Production)
11 + runs-on: ubuntu-latest
12 + timeout-minutes: 40
13 + steps:
14 + - uses: actions/checkout@v4
15 + - name: Refuse Production target before any DB connection
16 + run: node scripts/stage21-target-preflight.mjs green
17 + - uses: supabase/setup-cli@v1
18 + with:
19 + version: 2.121.0
20 + - name: Verify migration-version preflight against committed read-only snapshot
21 + run: node scripts/phase1a-migration-preflight.mjs
22 + - name: Start unlinked local Supabase with Stage 1 and 2.2 migrations isolated
23 + run: |
24 + set -euo pipefail
25 + supabase init --force
26 + python3 - <<'PY'
27 + from pathlib import Path
28 + for p in Path('supabase/migrations').glob('*.sql'):
29 + b=p.read_bytes()
30 + if b.endswith(b'\\n'): p.write_bytes(b[:-2]+b'\n')
31 + PY
32 + mkdir -p /tmp/stage22-head-migrations
33 + mv supabase/migrations/2026101610{0000,0500,1000,1500,2000,2500,3000,3100,3500,4000}_*.sql /tmp/stage22-head-migrations/
34 + supabase start -x inbucket
35 + - name: Rebuild baseline and enforce exact object-fingerprint parity
36 + run: |
37 + set -euo pipefail
38 + 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
39 + 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
40 + - name: Require token-aware baseline SQL function parity, not just whitespace
41 + run: |
42 + set -euo pipefail
43 + 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
44 + 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
45 + - name: Apply ordered Stage 1 + 2.2 migrations ONLY to local PostgreSQL
46 + run: |
47 + set -euo pipefail
48 + for migration in /tmp/stage22-head-migrations/*.sql; do
49 + PGPASSWORD=postgres psql -h 127.0.0.1 -p 54322 -U postgres -d postgres -X -v ON_ERROR_STOP=1 -f "$migration" >/dev/null
50 + done
51 + echo 'STAGE22_ORDERED_LOCAL_MIGRATIONS_APPLIED' | tee stage22-migrations.log
52 + - name: Require real owner-only, CAS, append-only audit, opening and closing denial
53 + run: |
54 + set -euo pipefail
55 + PGPASSWORD=postgres psql -h 127.0.0.1 -p 54322 -U postgres -d postgres -X -v ON_ERROR_STOP=1 -f supabase/tests/stage22_mode_contract.sql 2>&1 | tee stage22-parity-mode.log
56 + - name: Require authenticated direct posted-status negative under enforce
57 + run: |
58 + set -euo pipefail
59 + PGPASSWORD=postgres psql -h 127.0.0.1 -p 54322 -U postgres -d postgres -X -v ON_ERROR_STOP=1 -v stage21phase=green -f supabase/tests/stage21_direct_post_canary.sql 2>&1 | tee stage22-parity-direct-write.log
60 + - name: Strict standalone all-definer grants audit
61 + run: |
62 + set -euo pipefail
63 + PGPASSWORD=postgres psql -h 127.0.0.1 -p 54322 -U postgres -d postgres -X -v ON_ERROR_STOP=1 -f supabase/tests/phase1a_stage1_all_definer_security.sql 2>&1 | tee stage22-parity-definer-security.log
64 + - name: Clearly classify snapshot-vs-live and test layer in Job Summary
65 + if: always()
66 + run: |
67 + {
68 + echo '### Stage 2.2 EXACT HEAD SQL PARITY — LOCAL POSTGRES'
69 + echo 'Checks fixed read-only 2026-10-16 Production schema snapshot, NOT current/live Production.'
70 + echo 'Baseline fingerprint + token-aware function parity are strict; no conditional/soft waiver.'
71 + echo 'Later SQL migrations and authenticated negative tests use isolated unlinked Supabase CLI.'
72 + echo 'Distinct from harness and real-stack browser tests, which run in other jobs.'
73 + echo 'FAILURE is not acceptance; read step and raw log.'
74 + } >> "$GITHUB_STEP_SUMMARY"
75 + - name: Archive reproducible sanitized local schema and checks
76 + if: always()
77 + uses: actions/upload-artifact@v4
78 + with:
79 + name: stage22-head-parity-${{ github.sha }}
80 + path: |
81 + stage22-head-baseline-objects.json
82 + stage22-head-baseline-functions.json
83 + stage22-parity-baseline.log
84 + stage22-parity-functions.log
85 + stage22-migrations.log
86 + stage22-parity-mode.log
87 + stage22-parity-direct-write.log
88 + stage22-parity-definer-security.log
89 + if-no-files-found: warn
PROJECT_STATE.md
+6
@@ -181,3 +181,9 @@
181 - **HARNESS PASS** Run 39158782582, Job 117767455701, artifact 12148396252; actual journal JS in Chromium uses test-only SQL bridge, NOT Auth/JWT/gateway. Stage 2.1 canaries Run 39158782572 PASS; Security Run 39158785280 CodeQL/safety PASS; Dependency Review SKIPPED by `vars.DEPENDENCY_GRAPH_ENABLED` guard. Summary in real-stack and harness jobs must identify their distinct test layers.
182 - **Quality remains RED** Run 39158785350 Job 117768601711 Step 54: 122/123 DOM tests passed, `scripts/accounting-document-workflow.spec.js:624–641` treasury-payment correction fault-injection test FAILS (missing required `اصلاح کامل نشد` alert after consumed RPC failure). `js/payments.js:67–103,190–205` amendment/uncertain-ack behavior is OUTSIDE authorized manual Stage 2.2. Do NOT weaken assertion or alter payment/amend production behavior as a workaround; require separate owner approval for its semantic fix. Do not claim Quality green or Stage 2.2 accepted.
183 - Phase1A parity workflow is push-scoped to the Stage1 feature branch (workflow lines 3–6), so **no parity run for exact Stage2 HEAD** is proved. Existing Stage1 parity is older evidence and must not be relabeled as Stage2-head parity. Stage 2.3, commercial correction RPC, Production DDL/DML or enforce, main merge, Phase 1B and separate login-resilience work remain prohibited; PR #162 DRAFT [DO NOT MERGE].
184 +
185 +### 2026-10-19 — Continuing Stage 2.2 QA: exact-head parity gate, acceptance still HOLD
186 +- Current verified Stage2 HEAD before new QA-only change: `45bdef18e33a86e46adbf5f64692258f71e255de`. Real-stack (not harness) Run **39169445452** Job **117799253545** PASS: built Pages, local GoTrue real JWT, Auth/PostgREST, REST direct posted-status HTTP 400 and other-org HTTP 403 rejected, local DB balance/unique number/version=2/posted-audit=1, old-client audit-mode guard violations=3; artifact requires exact listing. Independent harness Run **39169445462** Job **117799253673** PASS (mode + targeted journal no-pullAll and positive 3/3). Security **39169448375** PASS except conditional Dependency Review SKIPPED; Stage2.1 canaries **39169445428** PASS.
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].