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

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

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

Synced Dec 3, 18:15 UTC

docs: verify request workflow D3a runtime

davoodmehraban89 committed Oct 1, 2026 at 22:53 UTC 61a04094c153ae9700fbd6ec5f5c49e80d1c1b34
1 file changed +60
docs/REQUEST_WORKFLOW_D3A_VERIFICATION.md new
+60
@@ -0,0 +1,60 @@
1 +# Request Workflow Slice D3a — Sequential / Parallel Step Runtime Verification
2 +
3 +Date: 2026-10-01
4 +
5 +## Scope
6 +D3a adds versioned server semantics for sequential and parallel approval steps without reusing or mutating the C8 correspondence workflow runtime.
7 +
8 +## Server model
9 +Archived migrations:
10 +- `supabase/migrations/20261001230000_request_workflow_d3a_step_runtime.sql`
11 +- `supabase/migrations/20261001230500_request_workflow_d3a_security_hardening.sql`
12 +
13 +The D3 schema version is `schemaVersion: 2`. A workflow contains 1–50 ordered steps. Each step has a unique machine key, title, mode (`sequential` or `parallel`), approval quorum and required capability. Sequential steps require exactly one approval; parallel steps require 2–20 approvals. Allowed decision capabilities are `approve`, `edit`, or `configure`.
14 +
15 +Runtime state is held in non-exposed private tables:
16 +- `private.request_step_instances`
17 +- `private.request_step_votes`
18 +
19 +Signed-in users have no direct table grants. Public mutation is through `public.request_step_decide`, a SECURITY INVOKER wrapper around a non-exposed privileged implementation.
20 +
21 +## Runtime behavior
22 +- Instance creation validates the pinned workflow snapshot and materializes ordered step instances only for schema version 2.
23 +- The first step activates; later steps remain pending.
24 +- Every decision is capability-checked against the active step on the server.
25 +- Every accepted vote advances the request optimistic revision and appends immutable public request-event evidence.
26 +- A sequential approval completes its step and activates the next step.
27 +- A parallel step remains active until its approval quorum is reached; distinct actors are enforced by a unique step/actor vote constraint.
28 +- Rejection terminates the active step/request as rejected.
29 +- Decision retries are idempotent by organization/idempotency key.
30 +- Tenant/module authorization is checked before an idempotent replay result can be returned, preventing cross-tenant information disclosure through guessed request/key pairs.
31 +
32 +## Automated verification
33 +Quality run `36913565943` on commit `4f362f925de7afb4f29008b1d670aa9ad340578d` completed successfully:
34 +- `d1-request-database`: SUCCESS, including D1, D2 and D3a behavioral assertions.
35 +- `static-quality`: SUCCESS, including full existing static suite and real-DOM smoke regression suite.
36 +- `c8-policy-database`: SUCCESS.
37 +
38 +D3a disposable PostgreSQL assertions verify:
39 +- two-step initialization and activation ordering;
40 +- sequential completion;
41 +- parallel quorum does not complete early;
42 +- idempotent retry does not duplicate a vote or revision;
43 +- a second distinct approver reaches quorum and final approval;
44 +- immutable `step_approve:*` event evidence;
45 +- invalid parallel schema rejection before publish;
46 +- active-step capability denial.
47 +
48 +The first D3a test run correctly failed because the authenticated test role attempted to inspect private runtime tables directly. The test was corrected to inspect private state only as the disposable database owner; production grants were not weakened.
49 +
50 +## Production verification
51 +Both D3a migrations were applied to Supabase project `hcsixhqbyuhpshfwqpjx` after the disposable DB gate passed. Production verification confirms:
52 +- both private runtime tables exist;
53 +- `authenticated` can execute `public.request_step_decide`;
54 +- `anon` cannot execute it;
55 +- the public wrapper is SECURITY INVOKER.
56 +
57 +A fresh Supabase security advisor run reported no new request-workflow SECURITY DEFINER warning; the pre-existing warning set remained at 20. A fresh performance advisor run reported no unindexed-foreign-key finding for D3a; only expected unused-index informational findings exist on the currently low-traffic/new indexes.
58 +
59 +## Boundary / next slice
60 +D3a is server semantics only. D3b remains responsible for the visual workflow editor, runtime timeline and safe condition DSL. D3c remains responsible for SLA/escalation, delegation/substitution and transactional cross-module outbox actions.