@davoodmehraban89 / Factor-easy-2 Mirror · read-only / commits / c3afc20
Fork 0

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

Mirrored from https://github.com/davoodmehraban89/Factor-easy.git

Synced Dec 3, 20:45 UTC

Close ELI-3 with production verification evidence

davoodmehraban89 committed Sep 30, 2026 at 09:01 UTC c3afc202248cb2acd789bebc33c6a36fadba0d7c
4 files changed +81 -23
PROJECT_STATE.md
+25 -22
@@ -4,48 +4,51 @@
4 >
5 > Repository: `davoodmehraban89/Factor-easy` · Canonical branch: `main` · Product: **Finora 1.0**
6
7 -Read `AGENTS.md` first, then this file. Latest user chat is the only source of new instructions; repo files are continuity/context. Detailed older history remains at `9d9caade2c3e34d7608e540e40b09ab23f0d19e9`.
7 +Read `AGENTS.md` first, then this file. Latest user chat is the only source of new instructions; repo files are continuity/context. Detailed older history remains available in Git history.
8
9 ## Protocol / authority
10 -Verify live GitHub+Supabase before acting; record material requests before implementation; implement/test/fix/retest/commit/verify in vertical slices; update this file with every durable implementation commit; archive exact production SQL; never call unrun work verified. Owner granted standing authority on 2026-09-30 for in-scope GitHub/Supabase engineering, excluding platform-required confirmations, paid/public/external actions and unsafe destructive financial-history changes. Owner further directed on 2026-09-30 that implementation must continue autonomously without waiting for routine confirmations; questions or progress messages must not stop executable work unless the owner explicitly says stop or a real safety/tool blocker requires input.
10 +Verify live GitHub + Supabase before acting; implement/test/fix/retest/commit/verify in vertical slices; update this file with durable implementation state; archive exact production SQL; never call unrun work verified. Owner granted standing authority on 2026-09-30 for in-scope GitHub/Supabase engineering, excluding platform-required confirmations, paid/public/external actions and unsafe destructive financial-history changes. Owner explicitly directed that implementation continue autonomously without waiting for routine confirmations; progress messages/questions must not stop executable work unless the owner explicitly says stop or a real safety/tool blocker requires input.
11
12 ## Current change ledger
13 | Date | Request / decision | Status | Evidence / next action |
14 |---|---|---|---|
15 -| 2026-09-30 | Continue autonomously: do not pause for routine confirmations; keep implementation moving unless explicitly stopped or a real blocker requires owner action. | **ACTIVE OPERATING DIRECTIVE** | Applies to all in-scope reversible engineering work. No claim of background execution; each chat turn continues as far as available tools permit. |
16 -| 2026-09-30 | Continue automatically into ELI-3 secure invitations after ELI-2: allow customer admins to onboard named users, bind invitations to email, roles and seat capacity, and keep external mail delivery separate. | **ELI-3 SERVER CONTRACT PREPARED — PRODUCTION NOT YET APPLIED** | Plan: `docs/superpowers/plans/2026-09-30-enterprise-licensing-eli3-invitations.md`. Repository migration adds hash-only invitation tokens, role links, create/accept/revoke/expire lifecycle, atomic seat-safe acceptance, email binding and audit without token hash. UI/external email not yet implemented. |
17 -| 2026-09-30 | Continue into ELI-2 reusable tenant roles without pausing after ELI-1; preserve direct member grants as overrides and keep commercial entitlement independent. | **ELI-2 IMPLEMENTED / PRODUCTION + REAL-DOM + SECURITY VERIFIED** | Plan: `docs/superpowers/plans/2026-09-30-enterprise-licensing-eli2-roles.md`. Production migration `20260930050542_enterprise_reusable_roles` applied. Transactional adversarial verification PASS with rollback: delegated core admin creates role/permission/assignment; role-only accounting read becomes effective; ordinary assignee cannot administer roles; cross-tenant assignment rejects; unlicensed role permission rejects after transactionally narrowing modules; system role deletion rejects; role audit emits. Follow-up production migration `20260930050904_eli2_role_tenant_hardening` closes direct-table bypasses with tenant-integrity triggers + entitlement-aware RLS. Direct-table adversarial rollback tests PASS. Runtime/UI loads role grants, unions them with direct grants, exposes reusable role creation/assignment/permission editing only to owner/core-configure, and retains direct grants as advanced overrides. Product head `c2ecd2a0451b8b7db6a246af0e5c49cf617ef8e5`: Quality `36672058163` PASS including Real-DOM and accounting/Golden gates; Pages `36672058038` PASS; Security `36672058144` PASS. Production has 24 seeded system roles across 4 organizations, 28 starter permission rows, 0 persistent assignments and 0 test-role residue. Evidence: `docs/ELI_2_REUSABLE_ROLES_VERIFICATION.md`. |
18 -| 2026-09-30 | Implement approved enterprise licensing/organization identity model: named-user seat capacity, company capacity, module entitlements, delegated organization/system admin, regions/units/positions, later invitations and reusable roles; keep packaging evolvable. | **ELI-1 IMPLEMENTED / PRODUCTION + REAL-DOM VERIFIED** | Approved spec: `docs/superpowers/specs/2026-09-30-enterprise-licensing-organization-identity-design.md`. Plan: `docs/superpowers/plans/2026-09-30-enterprise-licensing-eli1.md`. Live pre-change head `665c2d6e2a71026ad171e234786a4495e2211d0a`; Supabase ACTIVE_HEALTHY, 30 migrations through `20260930041735`, 4 organizations each currently one active owner. Task 1 commit `e04e7b49` introduced the server contract; Task 2–3 product head `b410145a5e821b3f39453ba10008b80d52151c37` added platform-admin capacity UI, organization seat counters, delegated `core/configure`, suspend/reactivate UI and Chromium coverage. Production migration `20260930045827_enterprise_license_seats_delegated_admin` applied successfully. Transactional adversarial verification PASS using only existing legitimate principals and ROLLBACK test data: platform admin capacity mutation succeeds; non-admin commercial mutation rejects; limit-below-usage rejects; suspension frees a seat; reactivation at capacity rejects atomically; delegated core/configure manages non-owner member/unit; ordinary member denied; module configurator cannot cross-grant another module; company capacity counts legal-company records and ignores organization units; membership audit is emitted. No test residue remained and 0/4 licenses are below active-user or company usage. Product-head Quality `36671228468` PASS including accounting/Golden/ELI invariant and all Real-DOM specs; Security `36671228442` PASS; Pages `36671227923` PASS. Evidence: `docs/ELI_1_ENTERPRISE_LICENSE_VERIFICATION.md`. |
19 -| 2026-09-30 | Continue closing current-stage gap register autonomously, prioritizing production safety and real evidence. | **IN PROGRESS** | Security hardening migration `20260930041735` applied/archived; 7 intentional authenticated SECURITY DEFINER warnings remain plus leaked-password protection disabled. Controlled accounting cutover remains blocked by missing approved chart/company classification. |
20 -| 2026-09-30 | Audit Gmail GitHub Run failed notifications and rank remaining gaps. | **AUDITED / GAP REGISTERED** | Final audit checkpoint `5182b786dc7488146eaaa68d87dcc2f1d2c9a725` passed Quality `36666677736`, Security `36666677677`, Pages `36666676797`. Gap register: `docs/CURRENT_STAGE_GAP_REGISTER_2026-09-30.md`. |
21 -| 2026-09-30 | Slice B organization tenant/RBAC/shared office foundation. | **IMPLEMENTED / VERIFIED** | Merge `d212c6aeef5b49f33351166771a0899f307a9067`; production migrations through `20260930033010`; final verified checkpoint `99a23edcaddf542f9080bbe70bb0b450af14913f`. |
15 +| 2026-09-30 | Continue autonomously without routine confirmation pauses. | **ACTIVE OPERATING DIRECTIVE** | Applies to reversible in-scope engineering. No claim of background execution. |
16 +| 2026-09-30 | ELI-3 secure invitations for named users, bound to email, roles and seat capacity. | **IMPLEMENTED / PRODUCTION + REAL-DOM + SECURITY VERIFIED** | Production migrations `20260930051849_enterprise_invitations` and `20260930052909_eli3_fk_index_hardening`. Transactional rollback verification PASS: hash-only token persistence, wrong-email denial, intended-user acceptance, role assignment, same-user replay idempotence, full-seat atomic rejection, revoke lifecycle, audit redaction and zero residue. Runtime/UI adds invite creation/revoke/copy-link and `?invite=` acceptance. Product head before evidence commit `71d6cd7196ef308c67f927644503f563bf4693ea`: Quality `36673537775` PASS including all accounting/Golden/ELI + Real-DOM; Security `36673537771` PASS; Pages `36673537056` PASS. Performance advisor unindexed-FK findings reduced to zero after hardening. Evidence: `docs/ELI_3_INVITATIONS_VERIFICATION.md`. External automatic email delivery remains NOT VERIFIED. |
17 +| 2026-09-30 | ELI-2 reusable tenant roles; direct member grants remain explicit overrides. | **IMPLEMENTED / PRODUCTION + REAL-DOM + SECURITY VERIFIED** | Production migrations `20260930050542_enterprise_reusable_roles`, `20260930050904_eli2_role_tenant_hardening`; role catalog/permissions/assignments, direct+role union, tenant integrity, commercial entitlement gate, audit and UI verified. Evidence: `docs/ELI_2_REUSABLE_ROLES_VERIFICATION.md`. |
18 +| 2026-09-30 | ELI-1 named-user seats, company capacity and delegated organization admin. | **IMPLEMENTED / PRODUCTION + REAL-DOM + SECURITY VERIFIED** | Production migration `20260930045827_enterprise_license_seats_delegated_admin`; seat/company limits, delegated `core/configure`, suspend/reactivate, audit and UI verified. Evidence: `docs/ELI_1_ENTERPRISE_LICENSE_VERIFICATION.md`. |
19 +| 2026-09-30 | Slice B organization tenant/RBAC/shared office foundation. | **IMPLEMENTED / VERIFIED** | Production migrations through `20260930033010`; tenant/RBAC verification retained. |
20 | 2026-09-30 | Modular organization-wide ERP + office automation/request foundation. | **SLICE A IMPLEMENTED / VERIFIED** | Product head `df82067ecb1fda9007eb11a30d0a9d7cc1b113cd` passed Quality/Security/Pages. |
23 -| 2026-09-30 | Iran-first high-assurance ERP expansion. | IN PROGRESS — broader roadmap | `docs/IRAN_COMPLIANCE_MATRIX_V1.md`; do not claim statutory consolidation/full tax submission/full HR/CRM until complete lifecycle/accounting/permissions/tests exist. |
21 +| 2026-09-30 | Iran-first high-assurance ERP expansion. | **IN PROGRESS — BROADER ROADMAP** | `docs/IRAN_COMPLIANCE_MATRIX_V1.md`; do not claim statutory consolidation/full tax submission/full HR/CRM until lifecycle/accounting/permissions/tests exist. |
22
23 ## Current production state — 2026-09-30
26 -- Verified ELI-1 product head: `b410145a5e821b3f39453ba10008b80d52151c37`; Quality `36671228468` PASS, Security `36671228442` PASS, Pages `36671227923` PASS.
27 -- Supabase `hcsixhqbyuhpshfwqpjx`: `ACTIVE_HEALTHY`, PostgreSQL `17.6.1.166`, 33 migrations through `20260930050904 eli2_role_tenant_hardening`.
28 -- `licenses`: 4 rows, organization-linked, with server-enforced `max_companies`, `max_users`, modules and future-safe `limits`; grandfather verification shows no license below current active seat/company usage.
29 -- `organization_members`: persistent production data remains 4 active owners / zero persistent non-owner members; adversarial multi-member tests were transactionally rolled back.
30 -- RLS enabled on all listed public tables. Security advisor: 7 intentional authenticated SECURITY DEFINER warnings + leaked-password protection disabled. Performance advisor: 5 new unused-index informational findings.
31 -- Production invoice history remains 7 records; controlled accounting cutover is unchanged and not part of ELI-1.
24 +- Supabase project `hcsixhqbyuhpshfwqpjx`: `ACTIVE_HEALTHY`, PostgreSQL `17.6.1.166`, **35 migrations through `20260930052909 eli3_fk_index_hardening`**.
25 +- Four organization-linked licenses with server-enforced `max_companies`, `max_users`, modules and future-safe `limits`; no license is below current active seat/company usage.
26 +- Persistent production membership remains four active owners and zero non-owner members. All ELI adversarial multi-user tests used existing legitimate principals inside transactions and rolled back.
27 +- ELI-2 persistent seeded state: 24 system roles across four organizations, 28 starter role-permission rows, zero persistent member-role assignments.
28 +- ELI-3 persistent state after tests: zero invitations, zero invitation-role links, zero non-owner members and zero role assignments.
29 +- RLS is enabled on the public tenant tables. Security advisor reports intentional authenticated SECURITY DEFINER RPC warnings (internally authorization-gated) plus leaked-password protection disabled. Negative authorization tests for ELI RPCs passed.
30 +- Performance advisor currently reports only unused-index informational notices; **no unindexed foreign-key findings remain** after `20260930052909`.
31 +- Production invoice history remains unchanged; controlled accounting cutover is not part of ELI work.
32
33 ## Implemented foundations
34 - Slice A: server-enforced commercial module entitlements, module launcher, office registries/correspondence/private scans, configurable request-type foundation.
35 - Slice B: organizations, hierarchical units, memberships, direct per-member module capabilities, row scopes, confidentiality, organization-aware sync/license context, shared office records/referrals/audit.
36 +- ELI-1: named-user seats, company capacity, delegated customer admin and member lifecycle.
37 +- ELI-2: reusable roles, role permissions, multi-role assignment, direct+role effective authorization and role audit.
38 +- ELI-3: secure hash-only invitations, email binding, role-bound acceptance, atomic seat enforcement, revoke/expire lifecycle, invitation UI and URL acceptance.
39 - Existing accounting Phases 1–6 and Iran enterprise foundation remain accepted; ELI work must not rewrite posted accounting history.
40
41 ## Invariants
39 -Posted accounting history is immutable and balanced; tenant isolation is enforced at the data boundary; commercial entitlement and member authorization are independent; UI hiding is never security; expired licenses are read-only; office numbering is server-atomic; private scans remain private; seat/company limits are server-enforced; no delegated customer admin can mutate commercial license entitlements.
42 +Posted accounting history is immutable and balanced; tenant isolation is enforced at the data boundary; commercial entitlement and member authorization are independent; UI hiding is never security; expired licenses are read-only; office numbering is server-atomic; private scans remain private; seat/company limits are server-enforced; delegated customer admins cannot mutate commercial license entitlements; invitation acceptance is authenticated, email-bound and seat-safe; raw invitation tokens are never persisted or audited.
43
44 ## Required evidence
42 -`docs/PHASE_1_REDESIGN_VERIFICATION.md` · `docs/PHASE_2_REDESIGN_VERIFICATION.md` · `docs/PHASE_3_REDESIGN_VERIFICATION.md` · `docs/PHASE_4_REDESIGN_VERIFICATION.md` · `docs/PHASE_5_VERIFICATION.md` · `docs/PHASE_6_VERIFICATION.md` · `docs/PHASE_6_CUTOVER_MANIFEST.md` · `docs/PRODUCTION_ACCOUNTING_CUTOVER_READINESS_2026-09-30.md` · `docs/IRAN_COMPLIANCE_MATRIX_V1.md` · `docs/FINORA_ERP_EXPANSION_ROADMAP_V4.md` · `docs/FINORA_UX_ACCOUNTING_BENCHMARK_V3.md` · `docs/FINORA_MODULAR_ERP_OFFICE_AUTOMATION_V1.md` · `docs/SLICE_B_TENANT_RBAC_VERIFICATION.md` · `docs/SECURITY_DEFINER_HARDENING_2026-09-30.md` · `docs/CURRENT_STAGE_GAP_REGISTER_2026-09-30.md` · `docs/superpowers/specs/2026-09-30-enterprise-licensing-organization-identity-design.md` · `docs/superpowers/plans/2026-09-30-enterprise-licensing-eli1.md` · `docs/PRODUCTION_RUNBOOK.md` · `supabase/migrations/`.
45 +`docs/PHASE_1_REDESIGN_VERIFICATION.md` · `docs/PHASE_2_REDESIGN_VERIFICATION.md` · `docs/PHASE_3_REDESIGN_VERIFICATION.md` · `docs/PHASE_4_REDESIGN_VERIFICATION.md` · `docs/PHASE_5_VERIFICATION.md` · `docs/PHASE_6_VERIFICATION.md` · `docs/PHASE_6_CUTOVER_MANIFEST.md` · `docs/PRODUCTION_ACCOUNTING_CUTOVER_READINESS_2026-09-30.md` · `docs/IRAN_COMPLIANCE_MATRIX_V1.md` · `docs/FINORA_ERP_EXPANSION_ROADMAP_V4.md` · `docs/FINORA_UX_ACCOUNTING_BENCHMARK_V3.md` · `docs/FINORA_MODULAR_ERP_OFFICE_AUTOMATION_V1.md` · `docs/SLICE_B_TENANT_RBAC_VERIFICATION.md` · `docs/SECURITY_DEFINER_HARDENING_2026-09-30.md` · `docs/CURRENT_STAGE_GAP_REGISTER_2026-09-30.md` · `docs/superpowers/specs/2026-09-30-enterprise-licensing-organization-identity-design.md` · `docs/superpowers/plans/2026-09-30-enterprise-licensing-eli1.md` · `docs/superpowers/plans/2026-09-30-enterprise-licensing-eli2-roles.md` · `docs/superpowers/plans/2026-09-30-enterprise-licensing-eli3-invitations.md` · `docs/ELI_1_ENTERPRISE_LICENSE_VERIFICATION.md` · `docs/ELI_2_REUSABLE_ROLES_VERIFICATION.md` · `docs/ELI_3_INVITATIONS_VERIFICATION.md` · `docs/PRODUCTION_RUNBOOK.md` · `supabase/migrations/`.
46
47 ## NOT VERIFIED / external boundary
45 -Authenticated two-real-user production browser E2E with a persistent legitimate non-owner member; ELI-3 invitations for users without an account; owner-approved accounting cutover; real Persian OCR; qualified digital signature; physical printer; live external adapters; GitHub Dependency graph; leaked-password protection; PostgreSQL 17.11 upgrade; CodeQL v4 migration.
48 +Authenticated two-real-user production browser E2E with a persistent legitimate non-owner member; automatic external invitation email delivery; owner-approved accounting cutover; real Persian OCR; qualified digital signature; physical printer; live external adapters; GitHub Dependency graph; leaked-password protection; PostgreSQL 17.11 upgrade; CodeQL v4 migration.
49
50 ## Exact next executable work
48 -1. ELI-3 is now IN PROGRESS: verify server contract in CI, apply exact migration, run rollback adversarial acceptance/security tests, then implement invitation UI and Real-DOM.
49 -2. External invitation email delivery remains NOT VERIFIED until a real provider is connected and tested.
50 -3. ELI-4 organization-tree UX/unit kinds and authenticated two-real-user browser verification when a legitimate persistent non-owner principal exists.
51 +1. Continue ELI-4 organization-tree UX/unit kinds and organization administration polish without weakening ELI-1/2/3 invariants.
52 +2. Authenticated two-real-user production browser verification remains blocked until a legitimate persistent non-owner principal is intentionally available; do not fabricate or permanently cross-add one.
53 +3. External invitation email delivery remains an adapter boundary; do not claim it until a real provider is connected and tested.
54 4. Then resume mature Office Slice C on the finalized enterprise identity/RBAC model.
docs/ELI_3_INVITATIONS_VERIFICATION.md new
+55
@@ -0,0 +1,55 @@
1 +# ELI-3 Secure Organization Invitations Verification
2 +
3 +Date: 2026-09-30
4 +Project: `hcsixhqbyuhpshfwqpjx`
5 +
6 +## Delivered
7 +- Tenant-scoped invitation lifecycle with pending / accepted / revoked / expired states.
8 +- Server-generated 256-bit random invitation token; only SHA-256 token hash is persisted.
9 +- Invitation bound to normalized email, optional unit/position and reusable role assignments.
10 +- Create/revoke/expire management restricted to organization owner or delegated `core/configure`.
11 +- Acceptance requires authenticated user, matching email and active organization license.
12 +- Membership activation and invited-role assignment occur in one transaction and consume named-user seat capacity through the existing ELI-1 trigger.
13 +- Same-user accepted-token replay is idempotent; wrong-user/wrong-email and full-seat paths reject.
14 +- Invitation audit deliberately removes `token_hash` from before/after JSON.
15 +- Organization admin UI creates/revokes invitations, shows the one-time invitation URL and supports copying it.
16 +- App startup/login accepts `?invite=<token>` after authentication and removes the token from browser address state after success.
17 +- External automatic email sending is intentionally not claimed.
18 +
19 +## Production migrations
20 +- `20260930051849 enterprise_invitations`
21 +- `20260930052909 eli3_fk_index_hardening`
22 +
23 +The second migration was added after the Supabase performance advisor identified six uncovered foreign keys across ELI-2/3 tables. After apply, the unindexed-foreign-key advisor category is clear; remaining performance notices are unused-index informational findings only.
24 +
25 +## Transactional adversarial verification
26 +All mutations used existing legitimate principals and were rolled back.
27 +
28 +PASS:
29 +1. Raw invitation token is not persisted.
30 +2. Wrong authenticated email cannot accept the invitation.
31 +3. Intended authenticated principal can accept.
32 +4. Acceptance creates/reactivates active membership and assigns invited role atomically.
33 +5. Same accepted user replay returns the same membership without duplicate side effects.
34 +6. Full named-user capacity rejects another acceptance without creating an active member or consuming the invitation.
35 +7. Owner can revoke a pending invitation.
36 +8. Invitation audit contains no `token_hash` field.
37 +9. Existing ELI-1 seat trigger remains the authoritative atomic capacity gate.
38 +10. Post-test persistent residue: 0 invitations, 0 invitation-role links, 0 non-owner members, 0 member-role assignments.
39 +
40 +## TDD / Real-DOM evidence
41 +A failing Real-DOM test was committed first at `93cd9120eaaca8f0a42f25dbb8bd842f8a658999`; Quality run `36673008772` failed specifically because the invitation UI actions and URL processor were not yet implemented. The runtime/UI implementation then made the same coverage pass.
42 +
43 +Final verified product head before this evidence commit: `71d6cd7196ef308c67f927644503f563bf4693ea`.
44 +- Quality `36673537775`: PASS, including all accounting/Golden/ELI invariants and invitation Real-DOM tests.
45 +- Security `36673537771`: PASS.
46 +- Pages `36673537056`: PASS.
47 +
48 +## Supabase advisor status
49 +Security advisor still reports authenticated-callable SECURITY DEFINER RPC warnings, including the invitation RPCs. These invitation RPCs are intentionally exposed to authenticated clients and contain internal owner/core-configure, email, active-license and seat checks; adversarial negative paths passed. Leaked-password protection remains disabled and is an external configuration gap.
50 +
51 +Performance advisor after FK hardening reports no unindexed foreign keys. Newly created indexes may appear as unused immediately because production traffic has not exercised them yet; no index is removed on that basis.
52 +
53 +## NOT VERIFIED
54 +- Automatic external invitation email delivery through a real provider.
55 +- Authenticated production browser E2E with a deliberately persistent second non-owner organization member.
scripts/enterprise-invitation-check.mjs
+1 -1
@@ -15,7 +15,7 @@ need(m,/organization_has_module_entitlement\(v_inv\.organization_id,'core',true\
15 need(m,/organization_members[\s\S]*status='active'/i,'seat-consuming membership activation');
16 need(m,/organization_member_roles/i,'invited role assignment');
17 need(m,/to_jsonb\(new\)-'token_hash'/i,'audit omits token hash');
18 -const h=fs.readFileSync('supabase/migrations/20260930054500_eli3_fk_index_hardening.sql','utf8');
18 +const h=fs.readFileSync('supabase/migrations/20260930052909_eli3_fk_index_hardening.sql','utf8');
19 for(const name of ['organization_invitation_roles_role_idx','organization_invitations_accepted_by_idx','organization_invitations_invited_by_idx','organization_invitations_unit_idx','organization_member_roles_assigned_by_idx','organization_roles_created_by_idx'])need(h,new RegExp(name,'i'),'FK index '+name);
20 const ui=fs.readFileSync('js/organization-invitations.js','utf8');
21 need(ui,/organizationCreateInvitationFromUi/i,'invitation creation UI');
supabase/migrations/20260930052909_eli3_fk_index_hardening.sql renamed