سامانه صدور فاکتور و حسابداری
ci(staging): add exact-head SQL parity and guard checks to zero-cost disposable test workflow
davoodmehraban89 committed
Oct 22, 2026 at 23:23 UTC
ad3413c7a28c22c02e0a06b3145b4b63ff62b7e3
1 file changed
+86
.github/workflows/stage22-free-ephemeral-staging.yml
+86
@@ -123,3 +123,89 @@ jobs:
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"