سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 3, 19:30 UTC
docs: record C8 runtime verification evidence
davoodmehraban89 committed
Oct 1, 2026 at 21:41 UTC
a0a2450186851079637a78db17d8fcf0f1fe8316
1 file changed
+42
docs/OFFICE_SLICE_C8_RUNTIME_VERIFICATION.md
new
+42
@@ -0,0 +1,42 @@
1
+# Office Slice C8 — Workflow Runtime Verification
2
+
3
+Date: 2026-10-01
4
+
5
+## Scope
6
+C8 adds internal, tenant-scoped correspondence workflow policy and runtime state. It does not replace C1 correspondence status/history, C5 approval evidence, accounting state, external BPM, qualified digital signature, or external delivery.
7
+
8
+## Production migrations
9
+- `20261001173917_office_slice_c8_workflow_policy`
10
+- `20261001180610_office_slice_c8_workflow_runtime`
11
+- `20261001180949_office_c8_policy_publisher_fk_index`
12
+
13
+Exact applied SQL is archived under `supabase/migrations/` using the live migration versions.
14
+
15
+## Runtime contract
16
+- One pinned workflow instance per correspondence.
17
+- Append-only event history with `(instance_id, revision)` uniqueness.
18
+- Organization-scoped idempotency key uniqueness.
19
+- `office_workflow_attach`, `office_workflow_transition`, and `office_workflow_read` are public `SECURITY INVOKER` wrappers.
20
+- Private implementation functions re-check authentication, active organization membership, module entitlement, record visibility/scope, and required edge capability.
21
+- Write paths require active writable entitlement; read preserves expired/read-only entitlement semantics.
22
+- Attach/transition only accept canonical C1 `registered` / `submitted` correspondence states; draft/closed/null states fail closed.
23
+- Transition uses source-letter then workflow-instance row locking plus `expected_revision`; stale competing writes return SQLSTATE `40001`.
24
+- Same request ID + same actor + same payload replays the original result without duplicate evidence; authorization is re-evaluated before replay.
25
+- Event labels are copied into immutable history so historical text does not drift with later policy versions.
26
+
27
+## Verification evidence
28
+The disposable PostgreSQL 17 CI job applies the archived policy and runtime migrations, then runs:
29
+- `supabase/tests/office_c8_workflow.sql`
30
+- `supabase/tests/office_c8_runtime.sql`
31
+- `scripts/office-c8-concurrency.mjs`
32
+- `supabase/tests/office_c8_runtime_security.sql`
33
+
34
+Verified scenarios include legal attach/transition, exact retry idempotency, stale revision, illegal edge, null/negative revision, terminal stage, cursor/limit validation, invalid correspondence states, expired/read-only behavior, capability revocation before retry, suspended membership, foreign tenant, unreadable correspondence, anonymous denial, direct-table grant closure, immutable event history, pinned-policy immutability, private-entry authorization, FK index coverage, and a real two-session race producing exactly one success, one stale result and one revision-1 event.
35
+
36
+CI database gate `36903736300` passed the archived runtime migration, transactional behavior and two-session concurrency test before production deployment. Subsequent hardening added the missing policy `published_by` FK index after the Supabase performance advisor identified it; the corresponding regression assertion is now part of the C8 database gate.
37
+
38
+## Production verification
39
+After deployment, live catalog verification confirmed both runtime tables and all three public RPCs exist; RLS is enabled on both private runtime tables; authenticated direct table SELECT/INSERT privileges remain closed; persistent workflow instance/event row counts remained zero. Supabase performance advisor no longer reports any unindexed foreign key. Security advisor reports only the pre-existing public SECURITY DEFINER warnings plus private-table no-policy informational notices and leaked-password protection warning; C8 public wrappers did not add a public SECURITY DEFINER warning.
40
+
41
+## Remaining C8 work
42
+Runtime UI integration, retry/stale UX, safe text rendering, focused real-DOM coverage, live authenticated browser flow where legitimate fixtures exist, and final C8 closure evidence remain to be completed in the next C8 task.