سامانه صدور فاکتور و حسابداری
docs: close verified D3b workflow slice
davoodmehraban89 committed
Oct 1, 2026 at 23:10 UTC
2bcc3854854e969d7eb4bc3339f84cd1d4985367
2 files changed
+66
-22
PROJECT_STATE.md
+24
-22
@@ -14,25 +14,26 @@ This is high-assurance accounting/ERP software. Posted financial history, tenant
14
## Current change ledger
15
| Date | Request / decision | Status | Evidence / next action |
16
|---|---|---|---|
17
-| 2026-10-01 | Owner said «ادامه بده» after verified D3a handoff. | **IN PROGRESS — D3B** | Execute the already-defined D3b slice autonomously: visual workflow editor + read-only runtime timeline + bounded server-validated condition DSL, with real-DOM and database verification. |
18
-| 2026-10-01 | Owner said «ادامه بده» after D1 closure. | **D2 + D3A VERIFIED; CONTINUE D3B** | D2 server UI/read-model cutover and D3a sequential/parallel server runtime are verified. Continue with D3b visual workflow editor/runtime timeline + safe condition DSL. |
19
-| 2026-10-01 | Slice D3a — sequential/parallel request workflow runtime. | **IMPLEMENTED / PRODUCTION + DISPOSABLE-DB + CI VERIFIED** | Migrations `20261001230000`, `20261001230500`; private step/vote runtime, schema-v2 validation, quorum semantics, capability checks, idempotent decisions and immutable event evidence. Quality run `36913565943`: all three jobs SUCCESS. Production public decision RPC is SECURITY INVOKER; anon denied; security advisor has no new request warning. Evidence: `docs/REQUEST_WORKFLOW_D3A_VERIFICATION.md`. |
20
-| 2026-10-01 | Slice D2 — request UI/read-model + legacy cutover. | **IMPLEMENTED / PRODUCTION + DISPOSABLE-DB + REAL-DOM + CI VERIFIED** | `js/request-workflow-d2.js`; migrations `20261001223500`, `20261001224500`; Quality run `36912668369` all three jobs SUCCESS including D2 real-DOM and disposable PostgreSQL assertions. Production reconciliation preserved 2 legacy types + 4 legacy requests and imported 2 definitions + 2 versions + 4 instances + 4 immutable import events. Evidence: `docs/REQUEST_WORKFLOW_D2_CUTOVER_VERIFICATION.md`. |
21
-| 2026-10-01 | Slice D1 — requests/BPMS-lite server foundation. | **IMPLEMENTED / PRODUCTION + DISPOSABLE-DB + CI VERIFIED** | Migrations `20261001204500`, `20261001205500`, `20261001210500`, `20261001211500`; production RLS/RPC/security verified. Quality run `36910187257`: `static-quality`, `c8-policy-database`, and `d1-request-database` all SUCCESS. |
22
-| 2026-10-01 | Office Slice C8: versioned correspondence workflow policy + runtime. | **IMPLEMENTED / PRODUCTION + ADVERSARIAL + CONCURRENCY + REAL-DOM + SECURITY VERIFIED** | Production migrations `20261001173917`, `20261001180610`, `20261001180949`; immutable workflow evidence, pinned policy versions, capability-gated transitions, optimistic revision checks, idempotent request IDs, private runtime tables, SECURITY INVOKER public wrappers, two-session race test and safe correspondence workflow UI. |
17
+| 2026-10-01 | Owner said «ادامه بده» after verified D3a handoff. | **D3B VERIFIED; CONTINUE D3C** | D3b visual workflow editor, bounded condition DSL and read-only timeline are production + disposable-DB + real-DOM verified. Continue with D3c SLA/escalation evidence, delegation/substitution and transactional cross-module outbox actions. |
18
+| 2026-10-01 | Slice D3b — visual workflow editor + conditions + timeline. | **IMPLEMENTED / PRODUCTION + DISPOSABLE-DB + REAL-DOM + CI VERIFIED** | `js/request-workflow-d3b.js`; migration `20261001233000`; bounded predicate DSL, skipped-step evidence and authorized timeline RPC. Quality run `36915696611`: all three jobs SUCCESS, including 33 Real DOM tests. Evidence: `docs/REQUEST_WORKFLOW_D3B_VERIFICATION.md`. |
19
+| 2026-10-01 | Slice D3a — sequential/parallel request workflow runtime. | **IMPLEMENTED / PRODUCTION + DISPOSABLE-DB + CI VERIFIED** | Migrations `20261001230000`, `20261001230500`; private step/vote runtime, schema-v2 validation, quorum semantics, capability checks, idempotent decisions and immutable event evidence. Quality run `36913565943`: all three jobs SUCCESS. Evidence: `docs/REQUEST_WORKFLOW_D3A_VERIFICATION.md`. |
20
+| 2026-10-01 | Slice D2 — request UI/read-model + legacy cutover. | **IMPLEMENTED / PRODUCTION + DISPOSABLE-DB + REAL-DOM + CI VERIFIED** | `js/request-workflow-d2.js`; migrations `20261001223500`, `20261001224500`; Quality run `36912668369` all three jobs SUCCESS. Legacy source records remain preserved and imported rows remain traceable. |
21
+| 2026-10-01 | Slice D1 — requests/BPMS-lite server foundation. | **IMPLEMENTED / PRODUCTION + DISPOSABLE-DB + CI VERIFIED** | Migrations `20261001204500`, `20261001205500`, `20261001210500`, `20261001211500`; production RLS/RPC/security verified. Quality run `36910187257` all three jobs SUCCESS. |
22
+| 2026-10-01 | Office Slice C8: versioned correspondence workflow policy + runtime. | **IMPLEMENTED / PRODUCTION + ADVERSARIAL + CONCURRENCY + REAL-DOM + SECURITY VERIFIED** | Production migrations `20261001173917`, `20261001180610`, `20261001180949`; immutable workflow evidence, pinned policy versions, capability-gated transitions, optimistic revision checks, idempotent request IDs, private runtime tables, SECURITY INVOKER public wrappers and two-session race test. |
23
| 2026-10-01 | Owner reconfirmed autonomous GitHub + Supabase execution and five-specialist operating model. | **ACTIVE OPERATING DIRECTIVE** | No repeated routine approval requests. Preserve the safety/cost boundaries above. |
24
| 2026-10-01 | Free-tier-only development/verification. | **ACTIVE OPERATING DIRECTIVE** | No paid Supabase branch or other billable development resource. |
25
-| 2026-10-01 | Live QA: commerce/tax IDs/request builder/personnel/license/floating-detail coding. | **PARTIALLY IMPLEMENTED / FOLLOW-UPS OPEN** | Kardex/tax-ID/request/profile/license/floating-code work landed. Exact Taxpayer-System print layout still waits for owner reference images. Request builder/runtime now uses D1/D2 server model; legacy records remain preserved only for rollback/audit. |
25
+| 2026-10-01 | Live QA: commerce/tax IDs/request builder/personnel/license/floating-detail coding. | **PARTIALLY IMPLEMENTED / FOLLOW-UPS OPEN** | Kardex/tax-ID/request/profile/license/floating-code work landed. Exact Taxpayer-System print layout still waits for owner reference images. Legacy request records remain preserved only for rollback/audit. |
26
| 2026-09-30—2026-10-01 | Office C1–C7, ELI-1–ELI-4, Slice A/B and accounting phases 1–6. | **VERIFIED WITH DOCUMENTED BOUNDARIES** | See required evidence below; do not redo completed phases without verified regression evidence. |
27
| 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. |
28
29
-## Live reconciliation — 2026-10-01 after D3a verification
30
-- D3a verified commit: `4f362f925de7afb4f29008b1d670aa9ad340578d`; Quality run `36913565943`: `static-quality`, `c8-policy-database`, and `d1-request-database` all SUCCESS. D3a disposable PostgreSQL assertions cover sequential activation/completion, parallel quorum, distinct approvers, idempotent retry, invalid schema and capability denial.
31
-- The first D3a behavior run failed because the authenticated test role attempted direct inspection of private runtime tables. The test was corrected to inspect private state only as the disposable DB owner; production grants were not weakened.
32
-- Production Supabase `hcsixhqbyuhpshfwqpjx`: D3a private step/vote tables exist; `authenticated` can execute `public.request_step_decide`, `anon` cannot; public wrapper is SECURITY INVOKER. The hardening migration checks tenant/module access before returning an idempotent replay result.
33
-- Production security advisor after D3a: no new request-workflow SECURITY DEFINER warning; the pre-existing 20 public warnings, C8 private RLS informational notices and leaked-password protection warning remain open.
34
-- Production performance advisor after D3a: no unindexed-foreign-key finding; only expected unused-index informational findings exist on the new/low-traffic indexes.
35
-- D2 legacy source records remain intact (2 requestTypes, 4 requests) and imported D1/D2 rows remain traceable; D3a did not mutate legacy source data.
29
+## Live reconciliation — 2026-10-01 after D3b verification
30
+- D3b final code commit: `eb04c5a2cc2160d6f1abab22104336ff522b89de`; Quality run `36915696611`: `static-quality`, `c8-policy-database`, and `d1-request-database` all SUCCESS. Real DOM smoke passed all 33 tests including D3b publish/remount and timeline behavior.
31
+- D3b followed test-first evidence: red contract commit `8371918f8a0792a2c156161820ed622117d0006c`; implementation `175c00529e4005c15cea352f7c5e9fb11867e96e`; regression test `ca1fe68dc8c8624281824e43f16d4a20d7f49030` exposed editor loss after publish; `eb04c5a...` fixed it.
32
+- Production Supabase `hcsixhqbyuhpshfwqpjx`: D3b migration applied; private step instances retain `condition_json` + `condition_matched`; false conditions persist as `skipped`; public timeline RPC is SECURITY INVOKER, authenticated-only, and rechecks tenant/module/request visibility in its private implementation.
33
+- Production condition checks verified numeric-string comparison semantics (`1200 >= 1000` true, `500 >= 1000` false). Unsafe field/operator forms are rejected by disposable PostgreSQL behavioral tests.
34
+- Production security advisor after D3b: no new request-workflow warning; pre-existing 20 public SECURITY DEFINER warnings, C8 private RLS informational notices and leaked-password protection warning remain open.
35
+- Production performance advisor after D3b: no unindexed-foreign-key finding; only expected unused-index informational findings remain.
36
+- D2 legacy source records remain intact and traceable; D3b did not mutate legacy source data.
37
- C8 correspondence workflow remains separate from Requests; request workflow state does not replace C1 registration or C5 approval evidence.
38
39
## Implemented foundations
@@ -42,22 +43,23 @@ This is high-assurance accounting/ERP software. Posted financial history, tenant
43
- Requests D1: independent versioned request definition/form/workflow foundation, pinned versions, idempotent create, expected-revision transition, immutable evidence and server authorization.
44
- Requests D2: server-backed request builder/runtime UI, immutable version publishing, retry-safe create, stale-revision recovery, capability-gated configure UI, non-destructive legacy import and traceability.
45
- Requests D3a: validated workflow schema v2, ordered sequential/parallel approval steps, quorum voting, per-step capability authorization, idempotent decisions and private runtime state.
46
+- Requests D3b: visual ordered-step editor, immutable combined form/workflow publication, bounded condition predicates, persisted skipped-step evidence and authorized read-only runtime timeline.
47
48
## Invariants
47
-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/seat-safe; raw invitation tokens are never persisted or audited; organization-unit parents cannot cross tenants or form cycles; referral targets must already be authorized to read the source correspondence; OCR provenance must reference a real attachment belonging to the same organization/correspondence; C8 workflow policy is pinned per correspondence instance and its evidence is append-only. Request type/workflow versions are immutable snapshots; request instances pin both versions; runtime mutation is server-authorized, idempotency/revision guarded and append-only evidence is retained. D2 legacy import is non-destructive/idempotent/traceable. D3a step votes require distinct actors for parallel quorum and active-step capability authorization. Request workflow state never replaces C1 registration status or C5 correspondence approval evidence.
49
+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/seat-safe; raw invitation tokens are never persisted or audited; organization-unit parents cannot cross tenants or form cycles; referral targets must already be authorized to read the source correspondence; OCR provenance must reference a real attachment belonging to the same organization/correspondence; C8 workflow policy is pinned per correspondence instance and its evidence is append-only. Request type/workflow versions are immutable snapshots; request instances pin both versions; runtime mutation is server-authorized, idempotency/revision guarded and append-only evidence is retained. D2 legacy import is non-destructive/idempotent/traceable. D3a step votes require distinct actors for parallel quorum and active-step capability authorization. D3b conditions are bounded server-validated predicates only; skipped condition results remain evidence and timeline reads are authorization-checked. Request workflow state never replaces C1 registration status or C5 correspondence approval evidence.
50
51
## Required evidence
50
-`docs/PHASE_1_REDESIGN_VERIFICATION.md` through `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/ELI_1_ENTERPRISE_LICENSE_VERIFICATION.md` through `docs/ELI_4_ENTERPRISE_ORGANIZATION_UX_VERIFICATION.md` · `docs/OFFICE_SLICE_C1_VERIFICATION.md` through `docs/OFFICE_SLICE_C8_RUNTIME_UI_VERIFICATION.md` · `docs/REQUEST_WORKFLOW_D2_CUTOVER_VERIFICATION.md` · `docs/REQUEST_WORKFLOW_D3A_VERIFICATION.md` · `docs/PRODUCTION_RUNBOOK.md` · `supabase/migrations/` · `supabase/tests/request_d1_behavior.sql` · `supabase/tests/request_d2_legacy_behavior.sql` · `supabase/tests/request_d3a_workflow_behavior.sql`.
52
+`docs/PHASE_1_REDESIGN_VERIFICATION.md` through `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/ELI_1_ENTERPRISE_LICENSE_VERIFICATION.md` through `docs/ELI_4_ENTERPRISE_ORGANIZATION_UX_VERIFICATION.md` · `docs/OFFICE_SLICE_C1_VERIFICATION.md` through `docs/OFFICE_SLICE_C8_RUNTIME_UI_VERIFICATION.md` · `docs/REQUEST_WORKFLOW_D2_CUTOVER_VERIFICATION.md` · `docs/REQUEST_WORKFLOW_D3A_VERIFICATION.md` · `docs/REQUEST_WORKFLOW_D3B_VERIFICATION.md` · `docs/PRODUCTION_RUNBOOK.md` · `supabase/migrations/` · `supabase/tests/request_d1_behavior.sql` · `supabase/tests/request_d2_legacy_behavior.sql` · `supabase/tests/request_d3a_workflow_behavior.sql` · `supabase/tests/request_d3b_condition_timeline.sql`.
53
54
## NOT VERIFIED / external boundary
53
-D3b visual workflow editor/runtime timeline and condition DSL are not yet implemented. D3c SLA/escalation, delegation/substitution and cross-module outbox actions are not yet implemented. 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 accuracy/provider; qualified digital signature; physical printer; live external adapters; GitHub Dependency graph/enforceable dependency review; leaked-password protection; PostgreSQL upgrade; CodeQL v4 migration; external BPM/provider integration remain outside verified scope.
55
+D3c SLA/escalation, delegation/substitution and transactional cross-module outbox actions are not yet implemented. 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 accuracy/provider; qualified digital signature; physical printer; live external adapters; GitHub Dependency graph/enforceable dependency review; leaked-password protection; PostgreSQL upgrade; CodeQL v4 migration; external BPM/provider integration remain outside verified scope.
56
57
## Exact next executable work
56
-1. D3b: add visual workflow editor and read-only runtime timeline on top of D3a, with a bounded condition DSL that is validated server-side and never executes arbitrary SQL/JavaScript.
57
-2. Add D3b real-DOM coverage for sequential/parallel editor state, publish validation, timeline rendering and stale-revision/error recovery.
58
-3. D3c: add SLA/escalation evidence, delegation/substitution and transactional cross-module outbox actions.
59
-4. Keep qualified digital signature, external delivery/BPM adapters and real OCR provider outside verified scope until real providers are connected and tested.
60
-5. Continue compliance/accounting roadmap only with sourced legal/tax/accounting evidence and controlled cutover safeguards.
58
+1. D3c: add request SLA/deadline evidence and escalation state without mutating historical events.
59
+2. Add delegation/substitution with explicit effective windows, tenant/capability checks and immutable evidence; do not silently impersonate approvers.
60
+3. Add a transactional cross-module outbox for approved request side effects; delivery must be idempotent and retry-safe and must not directly mutate posted accounting history.
61
+4. Add disposable PostgreSQL, real-DOM and failure/retry tests before production application.
62
+5. Keep qualified digital signature, external delivery/BPM adapters and real OCR provider outside verified scope until real providers are connected and tested.
63
64
## Live QA open items
65
- Exact Taxpayer-System print redesign: waiting for the two owner reference images; do not guess the official visual form.
docs/REQUEST_WORKFLOW_D3B_VERIFICATION.md
new
+42
@@ -0,0 +1,42 @@
1
+# Request Workflow D3b Verification
2
+
3
+Date: 2026-10-01
4
+
5
+## Scope
6
+D3b adds a visual request-workflow editor on top of D3a, a bounded server-validated condition DSL, persisted skipped-step condition evidence, and an authorized read-only runtime timeline. It does not merge Requests with the C8 correspondence workflow.
7
+
8
+## Implementation
9
+- UI: `js/request-workflow-d3b.js`, loaded after D2 from `js/bootstrap.js`.
10
+- Database: `supabase/migrations/20261001233000_request_workflow_d3b_conditions_timeline.sql`.
11
+- Static contract: `scripts/request-workflow-d3b-check.mjs`.
12
+- Real DOM: `scripts/request-workflow-d3b.spec.js`.
13
+- Disposable PostgreSQL: `supabase/tests/request_d3b_condition_timeline.sql`.
14
+
15
+## Condition boundary
16
+The D3b condition language is intentionally bounded to one predicate per step: a validated field key plus one of `eq`, `neq`, `gt`, `gte`, `lt`, `lte`, `exists`, `not_exists` and an optional scalar value. Field keys are restricted to `[a-z][a-z0-9_]{0,63}`. No arbitrary SQL, JavaScript, function name, expression string, nested executable expression or user-supplied operator is evaluated.
17
+
18
+Conditions are evaluated by the database against the immutable request values at instance creation. False conditions create a retained `skipped` step instance with `condition_json` and `condition_matched=false`; they are not silently deleted. The first matched step becomes active. If every D3b step is skipped, the request is server-completed as approved with a `workflow_auto_complete` immutable event and revision advance.
19
+
20
+## Timeline authorization
21
+`public.request_workflow_timeline(uuid)` is SECURITY INVOKER and executable by `authenticated`, not `anon`. The private implementation rechecks authentication, organization membership, module entitlement and requester/approve/edit visibility before reading private step state. It returns request state, ordered step state/approval counts/condition evidence and immutable request events.
22
+
23
+## TDD evidence
24
+- Red commit `8371918f8a0792a2c156161820ed622117d0006c` added D3b contracts before production implementation; `static-quality` failed because the D3b production files did not yet exist.
25
+- Green implementation commit `175c00529e4005c15cea352f7c5e9fb11867e96e` made static contracts, disposable PostgreSQL behavior and the initial D3b real-DOM tests pass.
26
+- A follow-up regression test commit `ca1fe68dc8c8624281824e43f16d4a20d7f49030` intentionally failed Real DOM because publishing replaced the D2 builder DOM and removed the D3b editor.
27
+- Fix commit `eb04c5a2cc2160d6f1abab22104336ff522b89de` remounts the editor after publish. Quality run `36915696611` completed with `static-quality`, `d1-request-database`, and `c8-policy-database` all SUCCESS; Real DOM smoke passed all 33 tests including the D3b editor/timeline cases.
28
+
29
+## Production verification
30
+Migration `request_workflow_d3b_conditions_timeline` was applied to Supabase project `hcsixhqbyuhpshfwqpjx` after disposable-DB verification. Production checks confirmed:
31
+- `condition_json` and `condition_matched` exist on private request step instances.
32
+- authenticated can execute the public timeline RPC; anon cannot.
33
+- the public timeline wrapper is SECURITY INVOKER.
34
+- numeric comparisons safely handle form values stored as numeric strings (`1200 >= 1000` true; `500 >= 1000` false).
35
+- the post-migration security advisor added no D3b/request-workflow SECURITY DEFINER warning; the existing 20 public SECURITY DEFINER warnings, C8 private-RLS informational notices and leaked-password protection warning remain pre-existing open items.
36
+- the performance advisor reports no unindexed-foreign-key finding; only expected unused-index informational notices on the low-traffic dataset.
37
+
38
+## Preserved boundaries
39
+- D2 legacy request records remain preserved for rollback/audit and are not reactivated as the runtime source.
40
+- C8 correspondence registration/approval/workflow evidence remains independent from Requests.
41
+- D3b does not implement SLA/escalation, delegation/substitution, cross-module outbox actions, external BPM adapters or qualified digital signatures. Those remain D3c/external work.
42
+- Authenticated two-real-user production browser E2E remains outside verified scope because no persistent legitimate second member was provisioned for this slice.