@davoodmehraban89 / Factor-easy / commits / 46892da
Fork 0

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

test(finance): seed foreign reversal fixture under tenant owner

davoodmehraban89 committed Nov 15, 2026 at 13:56 UTC 46892da0e08699e3bdead693f5e62c10f4ed39d5
3 files changed +17 -2
PROJECT_STATE.md
+6 -1
@@ -330,4 +330,9 @@ Owner requests layer-by-layer click/functional testing of all controls and compa
330 ### 2026-11-15 — Independent SQL review: dimension type/value consistency
331 - Review found `private.finora_phase1a_validate_saved` checked that dimension type and value existed in the same company, but did not require `dimensionValues.dimensionTypeId` to equal the linked dimension type, nor require both entities active. A balanced journal could therefore carry a semantically invalid analytic dimension pair.
332 - Added candidate migration `20261115140000_wp1_dimension_value_type_scope.sql`, conservative DOWN, and `wp1_dimension_value_type_scope.sql` regression. It rejects mismatched type/value, inactive dimensions, and wrong-company links; test verifies no partial draft survives and a valid pair still posts.
333 -- Account-specific required/optional dimension rules remain open. This patch has not passed CI and is not Production-authorized.
\ No newline at end of file
333 +- Account-specific required/optional dimension rules remain open. This patch has not passed CI and is not Production-authorized.
334 +
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
docs/audits/WP1_DB_ONLY_INTEGRATION_CANDIDATE_2026-11-15_FA.md
+7 -1
@@ -62,4 +62,10 @@ The current saved-journal validator verified that a dimension type and dimension
62
63 Candidate correction `20261115140000_wp1_dimension_value_type_scope.sql` now requires matching `dimensionValues.dimensionTypeId`, company scope, and active type/value state before accepting the journal graph. The regression `wp1_dimension_value_type_scope.sql` proves mismatched type/value and inactive values are rejected without leaving a partial draft, while a valid pair still posts. The DOWN restores the prior validator.
64
65 -This patch is candidate-only and awaits the full disposable CI run. Account-specific required/optional dimension rules remain unimplemented and are still an explicit blocker; this correction does not claim to complete entity-backed dimension policy.
\ No newline at end of file
65 +This patch is candidate-only and awaits the full disposable CI run. Account-specific required/optional dimension rules remain unimplemented and are still an explicit blocker; this correction does not claim to complete entity-backed dimension policy.
66 +
67 +## Reversal regression fixture correction — 2026-11-15
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
supabase/tests/wp1_reversal_dimensions.sql
+4
@@ -23,9 +23,13 @@ INSERT INTO public.records(owner_id,organization_id,collection,id,data) VALUES
23 (auth.uid(),current_setting('wp1.org')::uuid,'accountDimensionRules','DIM_RULE_B','{"companyId":"DIM_C","accountId":"DIM_B","dimensionTypeId":"DIM_OPTIONAL","applicability":"optional","active":true}');
24 INSERT INTO private.finora_phase1a_guard_modes(organization_id,mode) VALUES(current_setting('wp1.org')::uuid,'enforce');
25 -- Foreign tenant deliberately reuses the line/voucher IDs: a missing org predicate would leak its tag.
26 +-- Seed as that tenant's own actor so the audit guard correctly accepts the
27 +-- setup write; the later authenticated actor A must still be denied access.
28 +SELECT set_config('request.jwt.claim.sub','b6000000-0000-4000-8000-000000000002',true);
29 INSERT INTO public.records(owner_id,organization_id,collection,id,data) VALUES
30 ('b6000000-0000-4000-8000-000000000002',current_setting('wp1.other')::uuid,'journalLineDimensions','FOREIGN_DIM',
31 '{"companyId":"DIM_C","voucherId":"DIM_FULL","journalLineId":"DIM_FULL_A","dimensionTypeId":"FOREIGN_TYPE","dimensionValueId":"FOREIGN_VALUE"}');
32 +SELECT set_config('request.jwt.claim.sub','b6000000-0000-4000-8000-000000000001',true);
33
34 CREATE FUNCTION pg_temp.assert_reversal_dimensions(org uuid, original_id text, reversal_id text, expected_lines int, expected_dimensions int)
35 RETURNS void LANGUAGE plpgsql AS $$