سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 3, 22:00 UTC
test(phase1a): separate authenticated seeded generation from global integrity audit
davoodmehraban89 committed
Oct 17, 2026 at 06:50 UTC
2e708fdec5bc29d3b5530b59035d0da82702b4a6
2 files changed
+26
-8
PROJECT_STATE.md
+4
@@ -86,3 +86,7 @@
86
87
### 2026-10-17 — Stage 1 seeded performance tuning (PENDING CI)
88
- Live exact SHA run 38977189304 had 20 successful steps but seeded 1000-event DO was still running >10 minutes; preceding run 38976093909 was cancelled at seeded (not PASS/FAIL). Added tenant-scoped partial index for posted reversal source lookup and NOTICE per 100 events to diagnose without reducing event coverage. No Production changes. Exact-SHA CI required.
89
+
90
+### 2026-10-17 — Stage 1 seeded 1000 generation completed, verification timed out (PENDING CI)
91
+- Exact SHA c198a1b5c71e10fb1a3558d142f49516d8a5e23f, run 38978629359: 20 steps PASS and seeded progress reached event 1000 (23:09:27Z); job cancelled at 23:31:41Z at 35-minute timeout without validation PASS. Counters/races/rollback/security tests skipped; no Stage1 completion claim.
92
+- Changed only disposable seeded SQL test: all 1000 authenticated write operations and deterministic random event definitions retained. Deferred constraints and global read-only invariant checks now execute after RESET ROLE to local Postgres to avoid pathological RLS overhead and ensure all tenant rows are visible during global integrity audit. Added explicit checkpoints for counts, per-voucher and per-org balances, cross-org leaks. No Production DDL/DML, no main merge, no Stage2/3.
supabase/tests/phase1a_stage1_seeded_1000.sql
+22
-8
@@ -83,7 +83,21 @@ BEGIN
83
RAISE NOTICE 'FINORA_SEEDED_PROGRESS seed=% events=% full=% partial=%',seed,i,complete,partial;
84
END IF;
85
END LOOP;
86
- IF posted<>1000 OR partial<1 OR complete<1 THEN RAISE EXCEPTION 'FINORA_SEEDED_COVERAGE_FAILED';END IF;
86
+ IF posted<>1000 OR partial<1 OR complete<1 THEN
87
+ RAISE EXCEPTION 'FINORA_SEEDED_COVERAGE_FAILED';END IF;
88
+ RAISE NOTICE 'FINORA_SEEDED_GENERATION_PASS seed=% events=% full=% partial=%',seed,posted,complete,partial;
89
+END $random$;
90
+-- Every write above ran with authenticated RLS. The read-only global audit
91
+-- below runs as Postgres in a disposable CLI to see BOTH organizations,
92
+-- including cross-org violations which user-scoped RLS could hide.
93
+RESET ROLE;
94
+SET CONSTRAINTS ALL IMMEDIATE;
95
+DO $verify$
96
+BEGIN
97
+ IF (SELECT count(*) FROM public.records WHERE collection='journalVouchers'
98
+ AND id LIKE 'SEEDED_%')<>1000 THEN
99
+ RAISE EXCEPTION 'FINORA_SEEDED_DUPLICATE_OR_MISSING';END IF;
100
+ RAISE NOTICE 'FINORA_SEEDED_VERIFY_COUNTS_PASS originals=1000';
101
IF EXISTS(
102
SELECT 1 FROM public.records rv
103
JOIN public.records l ON l.organization_id=rv.organization_id
@@ -92,24 +106,24 @@ BEGIN
106
GROUP BY rv.organization_id,rv.id
107
HAVING sum((l.data->>'debit')::numeric)<>sum((l.data->>'credit')::numeric)
108
) THEN RAISE EXCEPTION 'FINORA_SEEDED_VOUCHER_UNBALANCED';END IF;
109
+ RAISE NOTICE 'FINORA_SEEDED_VERIFY_VOUCHERS_BALANCED';
110
IF EXISTS(
111
SELECT 1 FROM public.records rv
112
JOIN public.records l ON l.organization_id=rv.organization_id
113
AND l.collection='journalLines' AND l.data->>'voucherId'=rv.id
114
WHERE rv.collection='journalVouchers'
100
- AND (rv.id LIKE 'SEEDED_%' OR rv.id LIKE 'FULL_R_%' OR rv.id LIKE 'PART_R_%' OR rv.id LIKE 'REST_R_%')
115
+ AND (rv.id LIKE 'SEEDED_%' OR rv.id LIKE 'FULL_R_%'
116
+ OR rv.id LIKE 'PART_R_%' OR rv.id LIKE 'REST_R_%')
117
GROUP BY rv.organization_id
118
HAVING sum((l.data->>'debit')::numeric-(l.data->>'credit')::numeric)<>0
119
) THEN RAISE EXCEPTION 'FINORA_SEEDED_ORG_UNBALANCED';END IF;
120
+ RAISE NOTICE 'FINORA_SEEDED_VERIFY_TWO_ORGS_BALANCED';
121
IF EXISTS(SELECT 1 FROM public.records rv JOIN public.records l
122
ON l.collection='journalLines' AND l.data->>'voucherId'=rv.id
123
WHERE rv.collection='journalVouchers' AND rv.id LIKE 'SEEDED_%'
124
AND l.organization_id<>rv.organization_id) THEN
125
RAISE EXCEPTION 'FINORA_SEEDED_ORG_LEAK';END IF;
109
- IF (SELECT count(*) FROM public.records WHERE collection='journalVouchers'
110
- AND id LIKE 'SEEDED_%')<>1000 THEN RAISE EXCEPTION 'FINORA_SEEDED_DUPLICATE_OR_MISSING';END IF;
111
- RAISE NOTICE 'FINORA_SEEDED_PASS seed=% original=% full_reversals=% partial_reversals=% orgs=2 lines=2..8 org_balance=0 leaks=0',
112
- seed,posted,complete,partial;
113
-END $random$;
114
-SET CONSTRAINTS ALL IMMEDIATE;
126
+ RAISE NOTICE 'FINORA_SEEDED_VERIFY_NO_ORG_LEAK';
127
+ RAISE NOTICE 'FINORA_SEEDED_PASS seed=20261016 original=1000 two_orgs=true lines=2..8 full_partial_reversals=true';
128
+END $verify$;
129
ROLLBACK;