سامانه صدور فاکتور و حسابداری
test(finance): attribute scope-move audit to source tenant
davoodmehraban89 committed
Nov 15, 2026 at 14:20 UTC
7b0d058e4eb8f3a791a68c2a82e043a0067ff4a8
3 files changed
+15
-4
PROJECT_STATE.md
+6
-1
@@ -335,4 +335,9 @@ Owner requests layer-by-layer click/functional testing of all controls and compa
335
### 2026-11-15 — WP1 reversal test failure root cause and fixture correction
336
- Latest run `43702886692` on `4e06e15e41573cf39880f1f76767ed73b242ebc7`: baseline RED passed; green SQL fixtures passed through posting negatives, including seeded 1,000 event proof; failure occurred before reversal assertions in fixture setup.
337
- Exact failure: `FINORA_GUARD_AUDIT_SCOPE_FORBIDDEN` from `private.finora_phase1a_log_guard` when `wp1_reversal_dimensions.sql` inserted its synthetic `FOREIGN_DIM` row into tenant B while `auth.uid()` still represented tenant A. The tenant-scoped guard behaved correctly; fixture setup impersonated the wrong actor for a cross-tenant seed.
338
-- Corrected only the fixture: set synthetic JWT subject to tenant B owner for that one setup insert, then restore tenant A before the authenticated cross-tenant reversal denial test. No negative assertion removed or relaxed. Await full exact-head rerun.
\ No newline at end of file
338
+- Corrected only the fixture: set synthetic JWT subject to tenant B owner for that one setup insert, then restore tenant A before the authenticated cross-tenant reversal denial test. No negative assertion removed or relaxed. Await full exact-head rerun.
339
+
340
+### 2026-11-15 — Scope-move audit attribution
341
+- On commit `46892da0e08699e3bdead693f5e62c10f4ed39d5`, WP1 passed baseline RED, all preceding green fixtures including the 1,000-event test and `wp1_reversal_dimensions.sql`.
342
+- `wp1_scope_move_and_null.sql` failed only at its final audit-to-off relocation audit-row assertion. The fixture expected the audit event under destination organization B, but the acting user belongs to source organization A. The tenant-scoped audit writer correctly denied cross-tenant audit insertion.
343
+- Corrected the fixture to require the audit event in source organization A with source actor and voucher ID. No guard behavior or negative assertion was weakened; rerun the full workflow.
\ No newline at end of file
docs/audits/WP1_DB_ONLY_INTEGRATION_CANDIDATE_2026-11-15_FA.md
+7
-1
@@ -68,4 +68,10 @@ This patch is candidate-only and awaits the full disposable CI run. Account-spec
68
69
The latest exact-head WP1 run passed the expected RED baseline and all green SQL fixtures through `wp1_posting_negatives.sql`, including the 1,000-event seed. It then failed while seeding the deliberately foreign-tenant `FOREIGN_DIM` row in `wp1_reversal_dimensions.sql`: the fixture had kept actor A in `auth.uid()` while inserting a row owned by tenant B. The new tenant-scoped audit guard correctly rejected and audited that cross-tenant setup write before the actual reversal assertions ran.
70
71
-This was a fixture-actor error, not evidence that the reversal RPC is broken. The fixture now switches the synthetic JWT subject to tenant B owner only for the privileged setup insert, then restores tenant A before running the authenticated negative cross-tenant reversal assertion. No assertion was removed or weakened. The complete workflow must rerun on this exact updated head.
\ No newline at end of file
71
+This was a fixture-actor error, not evidence that the reversal RPC is broken. The fixture now switches the synthetic JWT subject to tenant B owner only for the privileged setup insert, then restores tenant A before running the authenticated negative cross-tenant reversal assertion. No assertion was removed or weakened. The complete workflow must rerun on this exact updated head.
72
+
73
+## Scope-move audit assertion correction — 2026-11-15
74
+
75
+After correcting the foreign-tenant reversal fixture, `wp1_reversal_dimensions.sql` passed in full. The next fixture `wp1_scope_move_and_null.sql` then reached its final audit-to-off relocation scenario and failed because the test expected the guard event in the destination organization. The source migration invokes the guard logger with the NEW organization on UPDATE, but the actor remains a member of the source organization; the tenant-scoped audit writer correctly refuses to let that actor write an audit row into the destination tenant.
76
+
77
+The event is evidence of an attempted mutation of the source tenant’s posted journal identity. The test assertion is corrected to require the event in the source organization, with the source actor and voucher ID. The relocation behavior and all negative assertions remain unchanged. This is a test expectation correction based on the intended audit ownership, not a production-function change. Full exact-head CI is still required.
\ No newline at end of file
supabase/tests/wp1_scope_move_and_null.sql
+2
-2
@@ -60,7 +60,7 @@ where organization_id=current_setting('wp1.org')::uuid and collection='journalVo
60
set constraints all immediate;
61
do $$begin
62
if not exists(select from public.records where organization_id=current_setting('wp1.org_b')::uuid and collection='journalVouchers' and id='WP1_MOVE_POSTED') then raise exception 'WP1_AUDIT_RELOCATION_BLOCKED';end if;
63
- if not exists(select from private.finora_phase1a_journal_audit where organization_id=current_setting('wp1.org_b')::uuid and reason='FINORA_POSTED_JOURNAL_IDENTITY_IMMUTABLE') then raise exception 'WP1_AUDIT_RELOCATION_NOT_LOGGED';end if;
64
- raise notice 'WP1_AUDIT_TO_OFF_RELOCATION_ALLOWED_AND_LOGGED';
63
+ if not exists(select from private.finora_phase1a_journal_audit where organization_id=current_setting('wp1.org')::uuid and voucher_id='WP1_MOVE_POSTED' and actor_id='b4000000-0000-4000-8000-000000000001' and reason='FINORA_POSTED_JOURNAL_IDENTITY_IMMUTABLE') then raise exception 'WP1_AUDIT_RELOCATION_NOT_LOGGED_IN_SOURCE_TENANT';end if;
64
+ raise notice 'WP1_AUDIT_TO_OFF_RELOCATION_ALLOWED_AND_LOGGED_IN_SOURCE_TENANT';
65
end $$;
66
rollback;