سامانه صدور فاکتور و حسابداری
ci(stage3): run free local real-stack, parity and rollback on financial UI source patch
davoodmehraban89 committed
Oct 23, 2026 at 02:36 UTC
5214c429abb5d2503a4cb9425a8a935089776807
1 file changed
+260
.github/workflows/stage3-commercial-local-regression.yml
new
+260
@@ -0,0 +1,260 @@
1
+name: FINORA Stage3 payload regression - disposable Supabase
2
+on:
3
+ push:
4
+ branches: [work/finora-stage3-payload-green-20261023]
5
+permissions:
6
+ contents: read
7
+concurrency:
8
+ group: finora-stage3-payload-isolated
9
+ cancel-in-progress: true
10
+
11
+# No hosted staging URL. No paid resources, Production secrets, DB or deployment.
12
+# Public-repo standard ubuntu-latest runners are free; no stored CI artifacts.
13
+jobs:
14
+ stage22-real-stack:
15
+ name: stage22-real-stack (NOT harness)
16
+ runs-on: ubuntu-latest
17
+ timeout-minutes: 40
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+ - name: Preconnection production target canary
21
+ run: node scripts/stage21-target-preflight.mjs green
22
+ - uses: supabase/setup-cli@v1
23
+ with:
24
+ version: 2.121.0
25
+ - name: Start disposable Supabase Auth PostgREST gateway and Stage1 + Stage2.2 SQL
26
+ run: |
27
+ set -euo pipefail
28
+ supabase init --force
29
+ python3 - <<'PY'
30
+ from pathlib import Path
31
+ for p in Path('supabase/migrations').glob('*.sql'):
32
+ b=p.read_bytes()
33
+ if b.endswith(b'\\n'): p.write_bytes(b[:-2]+b'\n')
34
+ PY
35
+ mkdir -p /tmp/stage22-real-migrations
36
+ mv supabase/migrations/2026101610{0000,0500,1000,1500,2000,2500,3000,3100,3500,4000}_*.sql /tmp/stage22-real-migrations/
37
+ supabase start -x inbucket
38
+ for migration in /tmp/stage22-real-migrations/*.sql; do
39
+ PGPASSWORD=postgres psql -h 127.0.0.1 -p 54322 -U postgres -d postgres -X -v ON_ERROR_STOP=1 -f "$migration" >/dev/null
40
+ done
41
+ - name: Build exact production Pages artifact (no deployment)
42
+ run: |
43
+ node scripts/build-pages.mjs
44
+ test -f _site/index.html
45
+ test -f _site/js/finora-pages-accounting.js
46
+ test -f _site/js/finora-extension-bundle.js
47
+ - name: Install Chromium and Playwright real-stack runner
48
+ run: |
49
+ npm install --no-save @playwright/test@1.55.0
50
+ npx playwright install --with-deps chromium
51
+ - name: REAL STACK GoTrue login, JWT gateway REST attacks, UI journal and audit
52
+ run: |
53
+ set -o pipefail
54
+ node scripts/stage22-real-stack.mjs 2>&1 | tee stage22-real-stack.log
55
+ - name: Annotate REAL STACK job (never confuse with harness)
56
+ if: always()
57
+ run: |
58
+ {
59
+ echo '### Stage 2.2 REAL-STACK (not harness)'
60
+ echo 'Real built Pages index, local GoTrue Auth, JWT, Kong/gateway, PostgREST, real PostgreSQL and Chromium.'
61
+ echo 'Result: see mandatory scenario log and evidence; no result is certified on a failed job.'
62
+ echo 'No remote Supabase URL, Production SQL, deployment or Production credentials.'
63
+ } >> "$GITHUB_STEP_SUMMARY"
64
+ stage22-mode-contract:
65
+ name: client-compat-positive-stage2
66
+ runs-on: ubuntu-latest
67
+ timeout-minutes: 40
68
+ steps:
69
+ - uses: actions/checkout@v4
70
+ - name: Local target preflight (never Production)
71
+ run: node scripts/stage21-target-preflight.mjs green
72
+ - uses: supabase/setup-cli@v1
73
+ with:
74
+ version: 2.121.0
75
+ - name: Isolate local CLI and apply only Stage1 and Stage2.2 mode SQL
76
+ run: |
77
+ supabase init --force
78
+ python3 - <<'PY'
79
+ from pathlib import Path
80
+ for p in Path('supabase/migrations').glob('*.sql'):
81
+ b=p.read_bytes()
82
+ if b.endswith(b'\\n'): p.write_bytes(b[:-2]+b'\n')
83
+ PY
84
+ mkdir -p /tmp/stage22-only
85
+ mv supabase/migrations/2026101610{0000,0500,1000,1500,2000,2500,3000,3100,3500,4000}_*.sql /tmp/stage22-only/
86
+ supabase start -x inbucket
87
+ for migration in /tmp/stage22-only/*.sql; do
88
+ PGPASSWORD=postgres psql -h 127.0.0.1 -p 54322 -U postgres -d postgres -X -v ON_ERROR_STOP=1 -f "$migration"
89
+ done
90
+ - name: Owner-only mode RPC and guard in real local database
91
+ run: |
92
+ set -o pipefail
93
+ 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-mode.log
94
+ - name: Legacy client direct posted-status write must remain denied in enforce
95
+ run: |
96
+ set -o pipefail
97
+ 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-legacy-negative.log
98
+ - name: Browser manual journal lifecycle on Ubuntu + local database
99
+ run: |
100
+ set -o pipefail
101
+ npm install --no-save @playwright/test@1.55.0
102
+ npx playwright install --with-deps chromium
103
+ node scripts/stage22-manual-browser.mjs 2>&1 | tee stage22-browser.log
104
+ - name: Strict 3-of-3 positive manual client contract gate
105
+ run: |
106
+ set -o pipefail
107
+ node scripts/stage22-client-compat-gate.mjs stage22-evidence.json 2>&1 | tee stage22-compat.log
108
+ - name: Annotate HARNESS job type explicitly
109
+ if: always()
110
+ run: |
111
+ {
112
+ echo '### Stage 2.2 HARNESS (NOT real-stack)'
113
+ echo 'Runs original journal UI JavaScript in Chromium and tests local PostgreSQL through a restricted psql test bridge.'
114
+ echo 'Does NOT verify GoTrue password login, a real bearer JWT, gateway/PostgREST, or browser-to-backend HTTP.'
115
+ echo 'The separate stage22-real-stack job is mandatory before claiming full integration.'
116
+ } >> "$GITHUB_STEP_SUMMARY"
117
+ - name: Label local PostgreSQL bridge as HARNESS (not real-stack)
118
+ if: always()
119
+ run: |
120
+ {
121
+ echo '### Stage 2.2 HARNESS (not real-stack)'
122
+ echo 'Chromium executes actual journal code/UI via an isolated test-only PostgreSQL bridge and mocked Supabase transport.'
123
+ echo 'This pass does NOT prove real GoTrue auth, browser HTTP PostgREST, or the built Pages entrypoint.'
124
+ echo 'Real-stack is a SEPARATE job and must independently pass.'
125
+ } >> "$GITHUB_STEP_SUMMARY"
126
+ stage22-exact-head-parity:
127
+ name: stage22-exact-head-parity (snapshot NOT live Production)
128
+ runs-on: ubuntu-latest
129
+ timeout-minutes: 40
130
+ steps:
131
+ - uses: actions/checkout@v4
132
+ - name: Refuse Production target before any DB connection
133
+ run: node scripts/stage21-target-preflight.mjs green
134
+ - uses: supabase/setup-cli@v1
135
+ with:
136
+ version: 2.121.0
137
+ - name: Strict Stage1 migration preflight with separately approved Stage2.2 excluded ONLY from Stage1 history
138
+ run: |
139
+ set -euo pipefail
140
+ test -f supabase/migrations/20261016104000_stage22_manual_guard_owner_mode.sql
141
+ mv supabase/migrations/20261016104000_stage22_manual_guard_owner_mode.sql /tmp/stage22-owner-guard-approved-only-local.sql
142
+ node scripts/phase1a-migration-preflight.mjs
143
+ mv /tmp/stage22-owner-guard-approved-only-local.sql supabase/migrations/20261016104000_stage22_manual_guard_owner_mode.sql
144
+ test -f supabase/migrations/20261016104000_stage22_manual_guard_owner_mode.sql
145
+ - name: Start unlinked local Supabase with Stage 1 and 2.2 migrations isolated
146
+ run: |
147
+ set -euo pipefail
148
+ supabase init --force
149
+ python3 - <<'PY'
150
+ from pathlib import Path
151
+ for p in Path('supabase/migrations').glob('*.sql'):
152
+ b=p.read_bytes()
153
+ if b.endswith(b'\\n'): p.write_bytes(b[:-2]+b'\n')
154
+ PY
155
+ mkdir -p /tmp/stage22-head-migrations
156
+ mv supabase/migrations/2026101610{0000,0500,1000,1500,2000,2500,3000,3100,3500,4000}_*.sql /tmp/stage22-head-migrations/
157
+ supabase start -x inbucket
158
+ - name: Rebuild baseline and require all 1069 object identities and non-function definitions (raw hash diagnostic)
159
+ run: |
160
+ set -euo pipefail
161
+ 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
162
+ node scripts/stage22-baseline-structural-gate.mjs 2>&1 | tee stage22-parity-baseline.log
163
+ - name: Require token-aware baseline SQL function parity, not just whitespace
164
+ run: |
165
+ set -euo pipefail
166
+ 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
167
+ 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
168
+ - name: Classify ALL function metadata and raw format differences (diagnostic, strictly gated next)
169
+ run: |
170
+ set -euo pipefail
171
+ 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
172
+ set +e
173
+ 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
174
+ exit_code=${PIPESTATUS[0]}
175
+ set -e
176
+ if [ "$exit_code" -gt 1 ]; then
177
+ echo 'Invalid function classification tool failure'; exit "$exit_code"
178
+ fi
179
+ test -s phase1a-function-classification.json
180
+ - name: HARD GATE entire baseline identity plus 154 lexical-equivalent functions and metadata
181
+ run: node scripts/stage22-baseline-final-gate.mjs 2>&1 | tee stage22-parity-verdict.log
182
+ - name: Apply ordered Stage 1 + 2.2 migrations ONLY to local PostgreSQL
183
+ run: |
184
+ set -euo pipefail
185
+ for migration in /tmp/stage22-head-migrations/*.sql; do
186
+ PGPASSWORD=postgres psql -h 127.0.0.1 -p 54322 -U postgres -d postgres -X -v ON_ERROR_STOP=1 -f "$migration" >/dev/null
187
+ done
188
+ echo 'STAGE22_ORDERED_LOCAL_MIGRATIONS_APPLIED' | tee stage22-migrations.log
189
+ - name: Require real owner-only, CAS, append-only audit, opening and closing denial
190
+ run: |
191
+ set -euo pipefail
192
+ 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
193
+ - name: Require authenticated direct posted-status negative under enforce
194
+ run: |
195
+ set -euo pipefail
196
+ 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
197
+ - name: Strict standalone all-definer grants audit
198
+ run: |
199
+ set -euo pipefail
200
+ 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
201
+ - name: Clearly classify snapshot-vs-live and test layer in Job Summary
202
+ if: always()
203
+ run: |
204
+ {
205
+ echo '### Stage 2.2 EXACT HEAD SQL PARITY — LOCAL POSTGRES'
206
+ echo 'Compares 2026-10-16 Production snapshot; live Production parity was separately checked READ-ONLY, not by this CI job.'
207
+ echo 'Strict parity uses 1069 object identities/nonfunction hashes, 154 lexer-identical SQL function bodies, and equal function metadata.'
208
+ echo 'Later SQL migrations and authenticated negative tests use isolated unlinked Supabase CLI.'
209
+ echo 'Distinct from harness and real-stack browser tests, which run in other jobs.'
210
+ echo 'FAILURE is not acceptance; read step and raw log.'
211
+ } >> "$GITHUB_STEP_SUMMARY"
212
+
213
+ stage1-rollback-rehearsal:
214
+ name: Stage 1 local UP-DOWN-UP preserves versions/data (NOT Production rollback)
215
+ runs-on: ubuntu-latest
216
+ timeout-minutes: 40
217
+ steps:
218
+ - uses: actions/checkout@v4
219
+ with:
220
+ persist-credentials: false
221
+ - name: Reject all remote targets before any test connection
222
+ run: node scripts/stage21-target-preflight.mjs green
223
+ - uses: supabase/setup-cli@v1
224
+ with:
225
+ version: 2.121.0
226
+ - name: Prepare separate local-only baseline and Stage 1 migrations
227
+ shell: bash
228
+ run: |
229
+ set -euo pipefail
230
+ test -z "${SUPABASE_ACCESS_TOKEN:-}" || exit 1
231
+ test -z "${SUPABASE_DB_PASSWORD:-}" || exit 1
232
+ test -z "${SUPABASE_SERVICE_ROLE_KEY:-}" || exit 1
233
+ supabase init --force
234
+ python3 - <<'PY'
235
+ from pathlib import Path
236
+ for p in Path('supabase/migrations').glob('*.sql'):
237
+ b=p.read_bytes()
238
+ if b.endswith(b'\\n'): p.write_bytes(b[:-2]+b'\n')
239
+ PY
240
+ mkdir -p /tmp/finora-phase1a-migrations
241
+ mv supabase/migrations/2026101610{0000,0500,1000,1500,2000,2500,3000,3100,3500}_*.sql /tmp/finora-phase1a-migrations/
242
+ mv supabase/migrations/20261016104000_stage22_manual_guard_owner_mode.sql /tmp/stage22-guard-not-applied.sql
243
+ supabase start -x inbucket
244
+ for migration in /tmp/finora-phase1a-migrations/*.sql; do
245
+ PGPASSWORD=postgres psql -h 127.0.0.1 -p 54322 -U postgres -d postgres -X -v ON_ERROR_STOP=1 -f "$migration" >/dev/null
246
+ done
247
+ - name: Rehearse 1A rollback and forward without data or CAS loss
248
+ shell: bash
249
+ run: |
250
+ set -euo pipefail
251
+ PGPASSWORD=postgres psql -h 127.0.0.1 -p 54322 -U postgres -d postgres -X -v ON_ERROR_STOP=1 -f supabase/tests/phase1a_rollback_up_down_up.sql 2>&1 | tee stage1-local-rollback.log
252
+ grep -q 'FINORA_1A_ROLLBACK_UP_DOWN_UP_PASS' stage1-local-rollback.log
253
+ - name: Label reversible synthetic rehearsal, never Production recovery approval
254
+ if: always()
255
+ run: |
256
+ {
257
+ echo '### Stage 1 rollback test — ephemeral local PostgreSQL ONLY'
258
+ echo 'No Production connection, no real records, no remote Supabase branch, no artifacts.'
259
+ echo 'Successful reversible synthetic UP/DOWN/UP does NOT prove a Production rollback.'
260
+ } >> "$GITHUB_STEP_SUMMARY"