سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 08:00 UTC
docs(phase1a): record parity and rollback successes plus three reproducible client release blockers
davoodmehraban89 committed
Oct 16, 2026 at 14:38 UTC
c7e4c9378474e7b65516775299ab6df4464a7d91
1 file changed
+60
-33
docs/FINORA_PHASE1A_CLI_QA_CHECKPOINT_2026-10-16.md
+60
-33
@@ -1,33 +1,60 @@
1
-# FINORA Phase 1A — Supabase CLI QA checkpoint (2026-10-16)
2
-
3
-## Scope and isolation
4
-- Owner approved Phase 1A test-branch implementation and Supabase CLI testing only.
5
-- Production Supabase ref `hcsixhqbyuhpshfwqpjx`: **read-only SELECT/catalog/aggregates only**. No Production DDL, DML, migrations, history repair, or 1B.
6
-- Protected main baseline SHA `bccd474433b4188e43aae345773498ea6fc65209`; unmerged work solely on `feature/finora-phase1a-supabase-cli-20261016`.
7
-- Source migrations previously applied remain unrenamed. CI normalizes terminal literal backslash-n in its *ephemeral checkout only*.
8
-
9
-## Verified isolated CI evidence
10
-**GitHub Actions run 38889304877: completed SUCCESS.**
11
-https://github.com/davoodmehraban89/Factor-easy/actions/runs/38889304877
12
-
13
-- Full Supabase CLI Docker stack booted; auth/role/RLS integration available.
14
-- Production fingerprint snapshot: 1069 catalog objects. Repository baseline after one idempotent phone-identity compatibility bridge: 1069 objects.
15
-- SQL-function definition comparison: 154 functions; previously reported 30 formatting/comment-sensitive hashes were reconciled by lexical token comparison preserving quoted SQL string contents. Non-function catalog object identities and hashes matched. This is schema *baseline* matching, not a claim that production is updated to Phase 1A.
16
-- Red-before-fix: 11/11 original test scenarios failed (10 unauthorized financial operations accepted, plus 2-arg sync ambiguous).
17
-- After Phase 1A migrations: 11/11 passed (10 forbidden operations blocked with FINORA errors, 2-arg legacy sync operational).
18
-- CAS test: create version 1, update version 2, reject stale version, preserve winner, reject cross-tenant write — PASS.
19
-- Synthetic 1000 postings plus 1000 compensating reversals; 2000 posted vouchers / 4000 lines; aggregate accounts net zero — PASS.
20
-- 10,000 vouchers / 20,000 journal lines index benchmark — PASS; one exemplar scoped lookup execution time ~0.037 ms on GitHub-hosted disposable DB (not a production latency measurement).
21
-- JavaScript syntax check of `js/sync.js` — PASS.
22
-- Existing 2-arg and 3-arg legacy sync signatures remain distinguishable; new `finora_sync_records_v2` uses expected_version. Sunset coded 2027-02-01 in test branch.
23
-
24
-## Important NOT VERIFIED / release blockers
25
-1. Browser-side journal UI `js/journal-engine.js` still constructs `status:'draft'` and `number` on direct client draft creation and changes `status/postedAt` via `saveDatastore()`, while Phase 1A DB rejects these fields on authenticated writes. A green adverse-write test **does not prove the legitimate journal creation/posting workflow**. Requires explicit authorized server-side workflow RPC and real non-production UI integration proof; never try CRUD in Production.
26
-2. Rollback/up–down–up preservation of actual prior records has **not been executed yet**; synthetic transaction rollbacks for test data are not the same.
27
-3. Actual concurrent multi-session races and two-actor browser flows with a hosted staging URL are NOT VERIFIED. JS `sync.js` only passed syntax, not end-to-end compatibility and merge/reload UX.
28
-4. Need independent SECURITY DEFINER search_path, function EXECUTE grants, anon denial, direct PostgREST bypass and tenant-bound behavior audit across all new SQL functions.
29
-5. Benchmark alone does not demonstrate performance under production-size data or realistic multi-tenant load.
30
-6. Historic anomaly report is still required as read-only aggregate.
31
-7. Root `main` and Production must remain untouched until later explicit release permission.
32
-
33
-**Acceptance status: IN PROGRESS / not production ready. Phase 1B not started.**
1
+# FINORA — Phase 1A isolated Supabase CLI QA checkpoint
2
+Date: 2026-10-16. No Production DDL/DML and no Phase 1B.
3
+
4
+## Exact environments and evidence
5
+- Repository: `davoodmehraban89/Factor-easy`; protected main at baseline `bccd474433b4188e43aae345773498ea6fc65209`; all 1A work isolated on `feature/finora-phase1a-supabase-cli-20261016`.
6
+- Supabase Production ref `hcsixhqbyuhpshfwqpjx`: **SELECT-only catalog and aggregate queries**, no migration/history repair, no app data writes, no RLS/grant changes.
7
+- Final Production read-only verification: **608 records, 82 applied migrations, 0 records.version columns, 0 finora_sync_records_v2 functions, 0 phase1A record triggers, 0 finora_post_event functions**. This work did not alter Production.
8
+- Isolated Supabase CLI 2.121.0 boots full Postgres/Auth/PostgREST/RLS stack in GitHub-hosted Docker; no remote project linked.
9
+- Legacy previously applied source migrations **not renamed or altered**; CI corrects literal trailing `\\n` *in its ephemeral checkout only*. The repository history and Production migrations are not repaired or rewritten.
10
+
11
+## Required source-versus-Production baseline schema categories
12
+- Original strict version-ID differences: 25 Production-only vs 24 repo-only; mostly retimestamped versions; see `docs/FINORA_PHASE1A_MIGRATION_VERSION_DIFF_2026-10-16.md`. Do not auto-repair ledger or infer schema drift from ID mismatch.
13
+- **(A) Numbering differences**: 23 same-named migrations with different timestamp versions, plus other historical duplicate-version/name cases recorded in the migration diff manifest. Names alone are not proof of bytewise migration equality.
14
+- **(B) Production-only schema objects before bridge**: `public.profiles.phone`, `public.profiles_phone_unique`, `public.update_my_identity_profile(text,text)` and its function grants. Reconstructed by *one idempotent, repository-only* phone identity compatibility bridge, never applied to Production.
15
+- **(C) Repository-only pre-1A baseline objects after phone bridge**: none in the 1069 app catalog objects compared. After **new** 1A migrations are applied in disposable DB, new objects of course exist locally but not Production; do not mistake intentional pending changes for historical drift.
16
+- Scope of catalog snapshot: `public`, `private` and noninternal `auth.users` custom triggers; relations, columns, constraints, indexes, functions, triggers, RLS policies and relation/function grants.
17
+- **Full Supabase CLI baseline parity PASS**: 1069 Production versus 1069 local objects, same nonfunction object hashes; 154 out of 154 function bodies had identical lexical token sequences after ignoring SQL comments/formatting while **preserving quoted SQL literal contents**. Function security flags, signature, volatility, config and grants consistent. Raw `pg_get_functiondef` hashes differed for 30 functions (29 formatting candidates and one comment-only `private.request_transition_instance`); proved equivalent by lexical comparison.
18
+- Baseline successful run: https://github.com/davoodmehraban89/Factor-easy/actions/runs/38889304877
19
+
20
+## TDD and security coverage that PASSED in disposable Supabase
21
+- **RED before guards**: 11/11 regression scenarios were failing (10 malicious writes accepted and old 2-arg sync overloaded dispatch ambiguous).
22
+- **GREEN after guards**: 11/11 passed; unauthorised post/status/number/postedAt, child and dimension INSERT under posted, cross-organization parent reference, negative/fractional/string/null JSONB Rial amounts were rejected with FINORA-specific errors. Legacy two-argument RPC callable again.
23
+- Server-side **deferred invariant** independently passed four tests: reject posted INSERT with no lines; reject draft→posted with only one line; reject unequal two lines; **accept** balanced two-line posting.
24
+- CAS version workflow, stale expected_version rejection, winner preservation, and cross-tenant auth test — PASS.
25
+- Synthetic **1,000 postings + 1,000 compensating reversals**, 2,000 posted vouchers, 4,000 lines and zero account net — PASS.
26
+- **10,000 synthetic vouchers, 20,000 journal lines** index benchmark — PASS. Example scoped lookup `EXPLAIN ANALYZE` ~0.037 ms in runner only; not a Production performance guarantee.
27
+- Five private 1A functions checked: **zero** `SECURITY DEFINER` search_path failures and **zero** anon EXECUTE privilege leaks. Authenticated sync-v2 grants also checked — PASS.
28
+- **Up → non-destructive down → up**: old legacy overloads restored from read-only Production function bodies in disposable DB; phase1A triggers and v2 removed/reapplied. Synthetic record payload and version **2** survived; subsequent update correctly reached version **3**, then test transaction rolled back. Expand-only rollback intentionally retains records.version and call-count data to avoid data loss.
29
+- JS `sync.js` syntax — PASS.
30
+- Green rollback/deferred/security run: https://github.com/davoodmehraban89/Factor-easy/actions/runs/38890548772
31
+- Read-only Production aggregate leakage precheck on 608 records: zero rows with missing owner membership, zero cross-org duplicate logical owner/collection/id keys, zero cross-org journal-child parent references. **This is not proof that every API path is leak-free.**
32
+
33
+## BLOCKER: positive legacy JavaScript client compatibility is RED (release-blocking)
34
+**Latest exact-sha run 38891056286 FAILURE**: https://github.com/davoodmehraban89/Factor-easy/actions/runs/38891056286
35
+
36
+Three *legitimate* scenarios tested with role `authenticated` and real Supabase RLS:
37
+1. Existing browser-created draft with `status:'draft'` and client-chosen `number` — **FAIL**, `FINORA_SERVER_ONLY_JOURNAL_FIELDS`.
38
+2. Same batched voucher + journalLines — **FAIL**, `FINORA_CHILD_PARENT_NOT_FOUND`. The versioned sync currently orders by collection text, causing journalLines to be inserted before journalVouchers.
39
+3. Existing `jePost` browser mutation to `status:'posted'`/`postedAt` — **FAIL**, `FINORA_SERVER_ONLY_JOURNAL_FIELDS`.
40
+
41
+These failures correctly prove that the server security checks work but current manual/source journal UI would be broken if Phase1A were deployed as-is. **Do not loosen DB guards to force a green test.**
42
+
43
+Further user-visible and security release blockers:
44
+- Introduce **Phase1A-specific server-authorized draft/create, post and reversal action contracts**, with organization entitlement checks, version CAS, atomic parent→line→dimension ordering, and safe server-owned number/status/timestamps. Do not implement Phase1B gapless numbering, fiscal-source locking, audit hash chain, or `finora_post_event`.
45
+- Update `js/journal-engine.js` and all synchronous callers in `js/journal-ui.js`, `js/phase4-contracting.js`, `js/phase5-enterprise.js`, and source posting flows, so the browser cannot directly write protected fields. Never display a premature save/post success.
46
+- Replace blind conflict reset with clear Persian **compare / reload / merge** UX that preserves unsaved edits safely; verify non-owner org members and real multi-session concurrent writes.
47
+- Test full PostgREST HTTP dispatch for two legacy overloads and new RPC; add source status bypass and direct CRUD tests. The existing psql `SET ROLE` tests exercise real database roles/RLS but are **not HTTP browser E2E**.
48
+- A separate hosted **staging app pointing only to disposable/non-Production Supabase** is required before TinyFish write tests. TinyFish Production session has been inspected read-only only.
49
+- No PR merge, Production rollout, Phase1A acceptance or Phase1B work until all blockers fixed, retested and separately authorized where necessary.
50
+
51
+## Files (major)
52
+- `supabase/migrations/20261007170000_phase1a_phone_identity_compat_bridge.sql`
53
+- `supabase/migrations/20261016100000_phase1a_server_journal_invariants.sql`
54
+- `supabase/migrations/20261016100500_phase1a_optimistic_version_sync.sql`
55
+- `js/sync.js`
56
+- `.github/workflows/phase1a-supabase-parity.yml`
57
+- `scripts/phase1a-adversarial-red.mjs`, `scripts/phase1a-deferred-posting-test.mjs`, `scripts/phase1a-positive-client-contract.mjs`, `scripts/phase1a-classify-function-drift.mjs`, `scripts/phase1a-lexical-compare.mjs`
58
+- `supabase/tests/phase1a_cas_rls_behavior.sql`, `phase1a_property_1000.sql`, `phase1a_10000_voucher_index_benchmark.sql`, `phase1a_security_grants.sql`, `phase1a_rollback_up_down_up.sql`, `phase1a_restore_legacy_sync_for_rollback.sql`, and non-PII schema/function fingerprint fixtures.
59
+
60
+**STATUS: Phase1A isolated DB regression PASS; existing-client integration FAIL; release/production STOP. Phase1B not started.**