سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 19:15 UTC
qa/wp2-financial-paths-reconciliation-20261122
audit-remediation-wave3-4-20261002
audit-remediation-wave3-verify-20261002
audit-remediation-wave4-20261002
audit-remediation-wave4b-20261002
audit-remediation-wave5a-identity-20261002
audit-remediation-wave5b-offboarding-20261002
audit-remediation-wave5c-authorization-20261002
audit-security-intent-review-20261002
audit/finora-financial-core-20261115
audit/finora-master-prompt-phase0-20261016
audit/finora-stage3-legacy-source-readonly-20261023
audit/full-controls-20261030
audit/owner-live-state-reconcile-20261012
audit/owner-review-20261007
audit/phase1-live-permissions-readonly-20261013
audit/reconcile-live-state-20261006
audit/reconcile-state-20261002
audit/wp0-hardening-baseline-20261102
branding-login-favicon-20261002
c8-workflow-task1
c8-workflow-task2
c8-workflow-task3
chore/wave0-pages-gate-closeout
claude-code-plugins-setup
design/finora-c01-authoritative-source-draft-20261124
docs-wave4b-verified-20261002
docs/active-company-invoice-release-evidence-20261014
docs/agent-operating-model-20261114
docs/chart-taxpayer-release-evidence-20261004
docs/cloud-only-agent-orchestration-20261115
docs/confirm-finora-product-charter-20261115
docs/continuation-20261030
docs/d4a-verified
docs/external-work-review-20261121
docs/finora-audit-continuity-20261014
docs/finora-backup-merge-evidence-20261014
docs/finora-ci-reconciliation-20261122
docs/finora-codex-master-prompt
docs/finora-eight-phase-plan-20261011
docs/finora-f002-live-buyer-filter-verified-20261015
docs/finora-license-race-release-evidence-20261014
docs/finora-license-rollout-acceptance-20261015
docs/finora-phase0-repeat-and-pages-nav-verified-20261015
docs/finora-phase0-repeat-evidence-20261015
docs/finora-selectors-release-and-fixture-qa-20261015
docs/finora-stagea-pr240-ci-triage-20261123
docs/finora-test-license-live-pass-20261015
docs/finora-v2-m01-coverage-20261124
docs/handoff-charter-v2-20261124
docs/invoice-product-search-release-20261011
docs/invoice-workspace-release-20261007
docs/phase-status-20261031
docs/phase0-acceptance-release-evidence-20261012
docs/phase0-admin-provision-release-evidence-20261012
docs/phase0-core-bundle-owner-login-open-20261013
docs/phase0-duplicate-js-release-20261016
docs/phase0-f001-auth-rest-shared-timeout-20261013
docs/phase0-f001-owner-login-observed-20261013
docs/phase0-f001-second-device-fail-40s-20261013
docs/phase0-f003-release-verification-20261011
docs/phase0-f004-print-release-evidence-20261012
docs/phase0-f004-watermark-release-evidence-20261012
docs/phase0-f005-large-selector-release-20261012
docs/phase0-f005-release-evidence-20261012
docs/phase0-f006-dark-release-evidence-20261012
docs/phase0-f008-final-pr-closure-evidence-20261012
docs/phase0-f008-reconcile-stale-prs-20261012
docs/phase0-f107-production-evidence-20261012
docs/phase0-kavenegar-otp-preflight-release-20261012
docs/phase0-login-release-evidence-20261012
docs/phase0-login-rest-bootstrap-stage-release-20261012
docs/phase0-owner-app-assets-bundle-release-20261013
docs/phase0-owner-login-csp-release-20261012
docs/phase0-reconcile-postmerge-evidence-20261012
docs/phase0-site-probe-release-evidence-20261012
docs/phase0-startup-release-evidence-20261012
docs/phase3-treasury-release-evidence-20261014
docs/pilot-posted-correction-release-evidence-20261014
docs/pilot-purchase-correction-release-evidence-20261014
docs/print-persian-release-verification-20261011
docs/qa-ci-triage-218-20261122
docs/real-account-qa-20261030
docs/release-state-20261007
docs/seamless-amendment-release-20261014
docs/seamless-document-correction-release-20261014
docs/settings-login-release-20261025
docs/stripe-qa-deployment-evidence-20261011
docs/ux-f2-release-evidence-20261011
docs/ux-f2-release-verification-20261011
docs/wave0-closeout
docs/wave2-closeout
exec-phase1-architecture
exec-phase1-implementation
exec-phase1-qa
exec-phase1-security-release
exec-phase1-ux
feat/accounting-document-draft-approval-20261011
feat/accounting-document-release-candidate-20261011
feat/active-company-strict-isolation-20261014
feat/admin-provisioning-reconciled-20261011
feat/admin-secure-user-provisioning-20261011
feat/admin-user-provisioning-merged-20261011
feat/d4a-request-work-queue
feat/document-lifecycle-atf-20261118
feat/document-lifecycle-temp-permanent-atef
feat/draft-first-attachment-lifecycle-216
feat/finora-offline-encrypted-backup-20261014
feat/finora-phase-a-navigation-20261023
feat/finora-stripe-sandbox-edge-gate
feat/immutable-attachment-temporary-vouchers
feat/iran-accounting-design-audit
feat/journal-document-lifecycle-20261118
feat/journal-rpc-repository-adapter-20261117
feat/office-c7-fulltext-ocr-provenance
feat/password-recovery-admin-reset-20261025
feat/pilot-expense-income-inplace-amendment-20261014
feat/pilot-journal-invoice-correction-20261014
feat/pilot-purchase-correction-20261014
feat/pilot-treasury-unallocated-correction-20261014
feat/retain-document-editor-after-save-20261014
feat/seamless-financial-document-correction-20261014
feat/slice-b-tenant-rbac
feat/stripe-sandbox-invoice-probe
feature/accounting-core-p0
feature/accounting-product-guidance
feature/admin-identity-phone-auth
feature/commercial-rnd
feature/finora-phase1a-supabase-cli-20261016
feature/finora-stage2-manual-canary-20261017
feature/finora-stage3-commercial-payload-20261023
feature/finora-stage3-enforce-invoice-rpc-20261023
feature/finora-stage3-enforce-purchase-red-20261023
feature/invoice-workspace-cleanup
feature/phase0-kavenegar-otp-preflight-20261012
feature/ux-commerce-settings-r2
fix-shell-scroll-live-cache-20261002
fix-shell-scrollbar-explicit-ownership-20261002
fix-shell-scrollbar-ownership-20261002
fix-shell-scrollbar-right-edge-20261002
fix/about-bug-report-20261114
fix/active-company-invoice-scope-20261014
fix/active-company-isolation-reconcile-20261014
fix/admin-central-password-reset-20261028
fix/auth-network-diagnostics
fix/chart-taxpayer-reference-20261003
fix/combobox-enter-reliability
fix/combobox-live-search
fix/combobox-production-cache
fix/combobox-release-asset-v2
fix/company-edit-action-20261028
fix/company-edit-pilot-delete-20261014
fix/company-form-action-state-20261014
fix/company-form-action-state-rebased-20261014
fix/contact-operational-balance-20261111
fix/dark-theme-contrast
fix/financial-lifecycle-recovery-20261124
fix/finora-accounting-test-organization-readiness-20261015
fix/finora-b01-safe-org-switch-20261124
fix/finora-b02-sync-recovery-20261124
fix/finora-b03-conflict-review-20261124
fix/finora-org-license-bootstrap-race-20261014
fix/finora-stage3-posted-source-immutable-20261023
fix/finora-v2-b03-r2-qa-20261124
fix/finora-v2-b03-r3-readonly-20261124
fix/g01-asof-financial-position-20261128
fix/invoice-product-search-rehydrate-20261011
fix/invoice-search-cache-bust
fix/issue229-linked-draft-status-20261122
fix/login-assets-retry-20261014
fix/login-inert-startup-20261110
fix/login-member-access-20261101
fix/login-resilience-20261017
fix/login-short-viewport-20261028
fix/login-startup-readiness-20261024
fix/navigation-utilities-placement-20261105
fix/office-c7-source-ref-binding
fix/office-c7-source-ref-binding-v2
fix/owner-login-network-20261026
fix/password-recovery-invalid-cancel-20261026
fix/payment-amount-format-20261111
fix/phase0-admin-provision-seat-bootstrap-20261012
fix/phase0-auth-bundled-assets-for-unstable-isp-20261013
fix/phase0-auth-handler-binding-stalled-session-20261012
fix/phase0-login-context-stage-visibility-20261012
fix/phase0-login-single-local-bundle-20261013
fix/phase0-login-site-probe-clarity-20261012
fix/phase0-login-ui-ready-20261012
fix/phase0-modal-dashboard-drill-20261011
fix/phase0-pages-blocking-core-bundles-20261013
fix/phase0-print-no-draft-watermark-20261012
fix/phase0-startup-parallel-asset-load-20261012
fix/phase3-behavioral-verification
fix/preserve-pending-edits-20261121
fix/print-persian-digit-consistency-20261011
fix/recovery-login-startup-20261027
fix/report-opening-balance-release-20261130
fix/settings-checkbox-persistence-20261024
fix/taxpayer-arithmetic-20261004
fix/ux-keyboard-search-f2-20261011
fix/wave2-request-input-integrity
hardening/c01-source-draft-20261129
hardening/global-draft-conversion-20261113
hardening/wp1-ledger-integrity-20261102
integration/finora-execution-20261124
integration/issue229-ui-qa-20261122
integration/wp1-ledger-core-20261115
integration/wp2-manual-journal-rpc-20261116
main
ops-heartbeat-v2-20261002
ops-progress-heartbeat-rule-20261002
ops/wave4-production-20261003
plan/financial-core-phase1-approval-20261016
qa/attachment-allocator-two-session-20261122
qa/draft-first-save-red-evidence-20261122
qa/finora-autopost-retry-identity-red-20261122
qa/finora-identity-rpc-security-tripwire-20261122
qa/finora-issue223-manual-kardex-browser-red-20261123
qa/finora-issue223-stock-real-jwt-20261123
qa/finora-issue238-inventory-count-browser-red-20261123
qa/finora-issue238-save-browser-red-20261122
qa/finora-login-cors-header-preflight-20261025
qa/finora-phase0-saved-session-repeat-20261015
qa/finora-phase5-posted-insert-jwt-red-20261123
qa/finora-stage3-ui-jwt-autopost-20261023
qa/finora-v2-g01-report-reconciliation-20261125
qa/free-supabase-local-wp2-20261116
qa/issue229-approval-boundary-jwt-20261122
qa/issue229-sale-save-linked-draft-red-20261122
qa/phase0-acceptance-start-20261012
qa/phase0-f005-account-project-contract-stress-20261012
qa/phase0-f005-selector-stress-20261012
qa/phase0-f006-dark-contrast-20261012
qa/post-wave4-verification-20261003
qa/posted-source-immutable-jwt-20261122
qa/pr219-wp1-disposable-dburl-proof-20261123
qa/purchase-source-jwt-20261122
qa/real-settings-acceptance-20261025
qa/recovery-mail-acceptance-20261026
qa/source-autopost-jwt-atomicity-20261122
qa/wave0-negative-gate-proof
qa/wp2-auth-tenant-e2e-20261117
qa/wp2-authorized-journal-write-20261122
qa/wp2-financial-paths-reconciliation-20261122
qa/wp3-financial-tenant-isolation-20261117
remediation/wave0-liveqa-wave1
remediation/wave2-request-integrity
staging/finora-stage22-free-20261022
state-scroll-verified-20261002
state-wave4b-production-20261002
state-wave5a-production-20261002
test/finora-accounting-boot-readiness-20261015
test/finora-f0-02-production-selectors-20261015
test/finora-pages-commerce-event-wiring-20261015
test/finora-pages-invoice-selectors-readonly-20261015
test/finora-stage3-jwt-source-post-20261023
test/phase0-invoice-fixture-bootstrap-20261016
test/phase0-invoice-persistence-20261011
test/phase0-pages-delayed-dispatcher-20261016
ux-scroll-ownership-20261002
work/finora-stage3-enforce-purchase-green-20261023
work/finora-stage3-enforce-sale-green-20261023
work/finora-stage3-payload-green-20261023
| 1 | # Enterprise Licensing ELI-1 Implementation Plan |
| 2 | |
| 3 | > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. |
| 4 | |
| 5 | **Goal:** Add hard named-user seat capacity and delegated organization administration to the existing organization/RBAC model without breaking existing tenants or accounting history. |
| 6 | |
| 7 | **Architecture:** Extend the current organization-linked license with `max_users` and future-safe `limits` metadata, enforce active named-user seats and legal-company capacity inside Postgres, and make `core/configure` the explicit delegated customer-admin capability. Preserve existing direct member permissions and owner semantics; ELI-2 roles and ELI-3 invitations remain separate later slices. |
| 8 | |
| 9 | **Tech Stack:** PostgreSQL 17 / Supabase RLS+RPC, vanilla JavaScript, Supabase JS, Node 22 invariant scripts, Playwright 1.55 Chromium. |
| 10 | |
| 11 | **Spec:** `docs/superpowers/specs/2026-09-30-enterprise-licensing-organization-identity-design.md` |
| 12 | |
| 13 | ## Global Constraints |
| 14 | |
| 15 | - Existing tenant IDs, posted accounting history, organization ownership and direct member grants must not be rewritten or deleted. |
| 16 | - Named-user seats count active `organization_members`, including the owner; `suspended` and `left` do not consume seats. |
| 17 | - Existing tenants are grandfathered so `max_users >= current active-member count` after migration. |
| 18 | - Seat/company limits are server-enforced; UI counters are informational only. |
| 19 | - Customer administrators cannot change commercial license dates/status/modules/company/user capacity. |
| 20 | - `core` is commercially always present, but `core/configure` is an explicit authorization grant for delegated organization administration. |
| 21 | - A module administrator cannot grant another module or an unlicensed module. |
| 22 | - All production SQL must be archived exactly under `supabase/migrations/` and `PROJECT_STATE.md` updated in the same durable implementation commit. |
| 23 | - Existing accounting Phase 2–6, Golden Accounting Journey, modular-office, Slice-B and Real-DOM gates must remain green. |
| 24 | |
| 25 | ## Review Focus |
| 26 | |
| 27 | - Concurrent activation of the last available seat: exactly one activation succeeds and the next is rejected atomically. |
| 28 | - Reducing `max_users` or `max_companies` below current usage: server rejects without partial mutation. |
| 29 | - Delegated `core/configure`: can manage tenant members/units but cannot mutate commercial license fields. |
| 30 | - Re-activating a suspended/left member at capacity: rejected; suspending an active member immediately frees one seat without deleting identity/audit. |
| 31 | - One legal company with many regions/units: only `companies` records consume company capacity; organization units never consume company capacity. |
| 32 | |
| 33 | --- |
| 34 | |
| 35 | ### Task 1: Database entitlement and delegated-admin contract |
| 36 | |
| 37 | **Files:** |
| 38 | - Create: `supabase/migrations/20260930050000_enterprise_license_seats_delegated_admin.sql` |
| 39 | - Create: `scripts/enterprise-license-check.mjs` |
| 40 | - Modify: `.github/workflows/quality.yml` |
| 41 | - Modify: `PROJECT_STATE.md` |
| 42 | |
| 43 | **Interfaces:** |
| 44 | - Produces: `licenses.max_users integer`, `licenses.limits jsonb`, `private.organization_active_member_count(uuid) -> integer`, `private.organization_has_seat(uuid, uuid default null) -> boolean`, `public.admin_set_user_limit(uuid, integer) -> void`, updated `public.admin_set_company_limit(uuid, integer)`, updated `public.organization_add_member(uuid,text,uuid,text) -> uuid`, `public.organization_set_member_status(uuid,uuid,text) -> void`, and `core` as a valid `member_module_permissions.module_key`. |
| 45 | - Produces authorization rule: owner OR `private.has_org_capability(org,'core','configure')` may manage organization members/units; only platform `is_admin()` may change commercial limits. |
| 46 | - Consumes: existing `organizations`, `organization_members`, `member_module_permissions`, `licenses`, `records`, `private.has_org_capability`, `private.organization_has_module_entitlement`. |
| 47 | |
| 48 | - [ ] **Step 1: Write the failing invariant script** |
| 49 | |
| 50 | Create `scripts/enterprise-license-check.mjs` with assertions that the new migration contains: `max_users`, grandfathering via active-member count, `limits jsonb`, `core` in the permission constraint, seat enforcement on activation, organization-scoped company counting, `admin_set_user_limit`, delegated `core/configure` management, and audit capture for membership/status/permission changes. Assert `js/organization-rbac.js`, `js/admin.js`/`js/platform-modules.js`, `index.html` and the Quality workflow are wired to the new contract only after later tasks. |
| 51 | |
| 52 | - [ ] **Step 2: Run the new invariant script and verify RED** |
| 53 | |
| 54 | Run: `node scripts/enterprise-license-check.mjs` |
| 55 | Expected: FAIL because the ELI-1 migration/UI contract does not yet exist. |
| 56 | |
| 57 | - [ ] **Step 3: Implement the additive SQL migration** |
| 58 | |
| 59 | In `supabase/migrations/20260930050000_enterprise_license_seats_delegated_admin.sql`: |
| 60 | - add `licenses.max_users integer not null default 1` with a bounded positive check and grandfather every license to at least current active-member count; |
| 61 | - add `licenses.limits jsonb not null default '{}'::jsonb` with object-type check; |
| 62 | - replace the `member_module_permissions.module_key` check so `core` is valid while retaining all existing module keys; |
| 63 | - add `private.organization_active_member_count(p_organization_id uuid) returns integer`; |
| 64 | - add `private.organization_has_seat(p_organization_id uuid,p_excluding_member uuid default null) returns boolean`; |
| 65 | - add a BEFORE INSERT/UPDATE membership trigger that only performs a seat check when the resulting row becomes active and prevents race-overbooking by locking the organization license row before counting; |
| 66 | - add `public.admin_set_user_limit(target uuid,new_max_users integer)` guarded by `public.is_admin()` and reject values below current active usage; |
| 67 | - replace `public.admin_set_company_limit` and `private/public` company-limit enforcement so counts and entitlement lookup use `organization_id`, not `owner_id`; |
| 68 | - replace `public.organization_add_member` so owner or `core/configure` may add/reactivate a pre-existing Finora user and the seat trigger remains authoritative; |
| 69 | - add `public.organization_set_member_status` for `active/suspended/left`, owner-protection and delegated administration; |
| 70 | - allow owner or `core/configure` to manage organization units and non-owner membership; ordinary members remain denied; |
| 71 | - update `organization_set_member_permission` so `core` is assignable only by owner or existing `core/configure`, while module configurators remain restricted to their own licensed module; |
| 72 | - extend immutable audit capture to member status/unit/position and delegated permission changes. |
| 73 | |
| 74 | - [ ] **Step 4: Run static SQL-contract test** |
| 75 | |
| 76 | Run: `node scripts/enterprise-license-check.mjs` |
| 77 | Expected: migration assertions PASS; UI assertions may remain intentionally failing until Tasks 2–3, so gate the script by explicit task-stage fixtures or implement only the DB assertions in this first commit. |
| 78 | |
| 79 | - [ ] **Step 5: Run existing non-browser gates** |
| 80 | |
| 81 | Run: `node scripts/syntax-check.mjs && node scripts/quality-check.mjs && node scripts/phase2-check.mjs && node scripts/phase3-check.mjs && node scripts/phase3-behavior-check.mjs && node scripts/phase4-behavior-check.mjs && node scripts/phase5-behavior-check.mjs && node scripts/enterprise-behavior-check.mjs && node scripts/phase6-behavior-check.mjs && node scripts/golden-accounting-core-check.mjs && node scripts/platform-office-check.mjs && node scripts/slice-b-rbac-check.mjs` |
| 82 | Expected: all PASS. |
| 83 | |
| 84 | - [ ] **Step 6: Commit Task 1 with state update** |
| 85 | |
| 86 | Commit migration, invariant script, Quality workflow entry and `PROJECT_STATE.md` together. State must say migration is repository-prepared only until Production apply/test actually succeeds. |
| 87 | |
| 88 | ### Task 2: License admin UI and runtime seat context |
| 89 | |
| 90 | **Files:** |
| 91 | - Modify: `index.html` |
| 92 | - Modify: `js/admin.js` |
| 93 | - Modify: `js/platform-modules.js` |
| 94 | - Modify: `js/organization-rbac.js` |
| 95 | - Modify: `scripts/enterprise-license-check.mjs` |
| 96 | - Modify: `PROJECT_STATE.md` |
| 97 | |
| 98 | **Interfaces:** |
| 99 | - Consumes: `licenses.max_users`, `admin_set_user_limit`, existing `admin_set_company_limit`, `admin_set_license_modules`, organization memberships. |
| 100 | - Produces runtime fields: `currentUser.maxUsers`, `currentUser.activeSeatCount`, `currentUser.remainingSeats`, `currentUser.canConfigureOrganization`. |
| 101 | - Produces UI: platform-admin license editor for named-user capacity; organization access manager usage counter and delegated-admin controls. |
| 102 | |
| 103 | - [ ] **Step 1: Extend failing invariant assertions for UI wiring** |
| 104 | |
| 105 | Assert the license modal has `modal-license-user-limit`; admin list shows user capacity; the license save path calls `admin_set_user_limit`; organization context loads active membership usage; and `core/configure` is used to show delegated organization-management UI. |
| 106 | |
| 107 | - [ ] **Step 2: Run invariant script and verify RED** |
| 108 | |
| 109 | Run: `node scripts/enterprise-license-check.mjs` |
| 110 | Expected: FAIL on missing UI/runtime hooks. |
| 111 | |
| 112 | - [ ] **Step 3: Implement platform-admin capacity UI** |
| 113 | |
| 114 | In `index.html` add a named-user capacity field next to company capacity and add a user-capacity column to the admin license table. In `js/admin.js` render `max_users` safely with backward-compatible fallback. In `js/platform-modules.js` extend the existing license edit override so it validates a positive user limit and calls `admin_set_user_limit` after plan/company/module updates; do not claim success if any RPC fails. |
| 115 | |
| 116 | - [ ] **Step 4: Implement organization runtime/admin context** |
| 117 | |
| 118 | In `js/organization-rbac.js` load enough membership/license context to calculate active seat usage and expose `maxUsers`, `activeSeatCount`, `remainingSeats`. Change organization-manager visibility from owner-or-any-module-configure to: owner or `core/configure` for member/unit administration; module configurators keep only their module permission editor. Add member suspend/reactivate actions through `organization_set_member_status`; prevent owner suspension in UI but rely on server enforcement as authoritative. |
| 119 | |
| 120 | - [ ] **Step 5: Run invariant + syntax checks** |
| 121 | |
| 122 | Run: `node scripts/enterprise-license-check.mjs && node scripts/syntax-check.mjs && node scripts/slice-b-rbac-check.mjs && node scripts/platform-office-check.mjs` |
| 123 | Expected: all PASS. |
| 124 | |
| 125 | - [ ] **Step 6: Commit Task 2 with state update** |
| 126 | |
| 127 | Commit UI/runtime changes and `PROJECT_STATE.md` together; keep Production behavior marked NOT VERIFIED until migration apply and transactional checks. |
| 128 | |
| 129 | ### Task 3: Real-DOM coverage for license seats and delegated administration |
| 130 | |
| 131 | **Files:** |
| 132 | - Create: `scripts/enterprise-license.spec.js` |
| 133 | - Modify: `.github/workflows/quality.yml` |
| 134 | - Modify: `scripts/enterprise-license-check.mjs` |
| 135 | - Modify: `PROJECT_STATE.md` |
| 136 | |
| 137 | **Interfaces:** |
| 138 | - Consumes: ELI-1 DOM IDs/functions from Task 2. |
| 139 | - Produces: Chromium evidence for platform-admin capacity editing, seat counters, delegated-admin visibility and ordinary/module-admin denial in rendered UI. |
| 140 | |
| 141 | - [ ] **Step 1: Write Playwright tests before wiring them into CI** |
| 142 | |
| 143 | Create `scripts/enterprise-license.spec.js` that stubs Supabase responses deterministically and verifies: `300` named-user capacity renders; active usage/remaining seats render; platform admin can enter a changed capacity; delegated `core/configure` sees member management; a module-only configurator does not gain organization-wide administration; an unlicensed module remains unavailable. |
| 144 | |
| 145 | - [ ] **Step 2: Run the Playwright file and verify RED where behavior is missing** |
| 146 | |
| 147 | Run: `python3 -m http.server 4173 >/tmp/finora-http.log 2>&1 & npx playwright test scripts/enterprise-license.spec.js --reporter=line --workers=1` |
| 148 | Expected: initial failing assertion before final DOM wiring, then PASS after correction. |
| 149 | |
| 150 | - [ ] **Step 3: Add the spec to the existing Real DOM CI command** |
| 151 | |
| 152 | Modify `.github/workflows/quality.yml` so the Real DOM step runs `scripts/dom-smoke.spec.js`, `scripts/platform-office.spec.js`, and `scripts/enterprise-license.spec.js` together. |
| 153 | |
| 154 | - [ ] **Step 4: Run the full local quality suite** |
| 155 | |
| 156 | Run the complete commands from `.github/workflows/quality.yml` including Chromium. |
| 157 | Expected: all PASS, including Golden Accounting Journey and all three Real-DOM specs. |
| 158 | |
| 159 | - [ ] **Step 5: Commit Task 3 with state update** |
| 160 | |
| 161 | Record exact local tests run; do not call Production seat/RLS behavior verified yet. |
| 162 | |
| 163 | ### Task 4: Production apply, adversarial SQL verification, and release checkpoint |
| 164 | |
| 165 | **Files:** |
| 166 | - Modify if actual Supabase version differs: `supabase/migrations/20260930050000_enterprise_license_seats_delegated_admin.sql` so repository SQL exactly matches applied SQL/version. |
| 167 | - Create: `docs/ELI_1_ENTERPRISE_LICENSE_VERIFICATION.md` |
| 168 | - Modify: `PROJECT_STATE.md` |
| 169 | |
| 170 | **Interfaces:** |
| 171 | - Consumes: reviewed migration and app changes from Tasks 1–3. |
| 172 | - Produces: Production schema/RLS evidence and release checkpoint; no fabricated two-real-user browser claim. |
| 173 | |
| 174 | - [ ] **Step 1: Re-read Production before mutation** |
| 175 | |
| 176 | Verify project `hcsixhqbyuhpshfwqpjx` health, migration list, active-member counts per organization, current `max_companies/modules`, RLS and advisors. Abort/reconcile if Production differs from the plan assumptions. |
| 177 | |
| 178 | - [ ] **Step 2: Apply the exact ELI-1 migration once** |
| 179 | |
| 180 | Apply the reviewed SQL to Production. If Supabase assigns a different migration version, rename/archive the repository file to the exact applied version before the durable implementation commit. |
| 181 | Expected: migration succeeds with no existing member deactivated and every `max_users >= active_member_count`. |
| 182 | |
| 183 | - [ ] **Step 3: Run transactional adversarial verification and ROLLBACK test data** |
| 184 | |
| 185 | Inside explicit transactions/rollback, prove: platform admin can set user capacity; non-admin cannot; lowering below usage fails; activation at capacity fails; suspension frees a seat; reactivation consumes it; delegated `core/configure` can manage a non-owner member/unit; ordinary member cannot; delegated admin cannot mutate license commercial fields; module configurator cannot grant another/unlicensed module; company capacity counts organization `companies` records and ignores regions/units. Use legitimate existing principals only; if a second principal is unavailable, mark the affected authenticated-browser scenario NOT VERIFIED rather than fabricating one. |
| 186 | |
| 187 | - [ ] **Step 4: Re-run advisors and data invariants** |
| 188 | |
| 189 | Verify RLS remains enabled, no orphan membership/license is introduced, active seats are within limits, and accounting data counts/journal invariants are unchanged. |
| 190 | |
| 191 | - [ ] **Step 5: Write verification evidence** |
| 192 | |
| 193 | Create `docs/ELI_1_ENTERPRISE_LICENSE_VERIFICATION.md` with applied migration version, SQL test matrix/results, CI SHAs/run IDs, advisor results and explicit NOT VERIFIED boundaries. |
| 194 | |
| 195 | - [ ] **Step 6: Push final durable implementation commit and observe GitHub gates** |
| 196 | |
| 197 | Update `PROJECT_STATE.md` in the same commit. Verify Quality, Security/CodeQL and Pages for the final head. Never mark ELI-1 COMPLETED from CI alone: Production transactional tests and Real-DOM tests must both have passed; any unavailable two-real-user browser test stays NOT VERIFIED. |
| 198 | |
| 199 | --- |
| 200 | |
| 201 | ## Self-review result |
| 202 | |
| 203 | - Spec coverage: ELI-1 is fully covered; ELI-2 reusable roles, ELI-3 invitations and ELI-4 organization-tree UX/real-user E2E are intentionally excluded and retain their own future plans. |
| 204 | - Type/interface consistency: `max_users`, `core/configure`, organization-scoped company count and membership status RPC are used consistently across DB/runtime/UI/tests. |
| 205 | - Review-focus coverage: all five listed failure modes are assigned to static, Playwright or transactional Production tests. |
| 206 | - Proportion: tasks describe contracts and testable outcomes without embedding implementation bodies. |