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

Document verified Office Slice C4 evidence

davoodmehraban89 committed Oct 1, 2026 at 00:02 UTC c3c0fc4e323f8985fdaf81f7dc7d6a783df285b2
1 file changed +60
docs/OFFICE_SLICE_C4_VERIFICATION.md new
+60
@@ -0,0 +1,60 @@
1 +# Office Slice C4 — Versioned Templates + Controlled Draft Application Verification
2 +
3 +Date: 2026-09-30
4 +Project: `hcsixhqbyuhpshfwqpjx`
5 +
6 +## Delivered
7 +- Repaired atomic correspondence registration after tenant migration: the legacy 3-argument overload was removed, eliminating the ambiguous RPC path; the remaining registration RPC writes an explicit organization id.
8 +- Registration now validates optional template provenance before a letter becomes registered.
9 +- Added a private, non-Data-API template-version store: `private.correspondence_template_versions`.
10 +- Template edits are append-only versions; per organization + template key, version allocation is serialized with a transaction advisory lock.
11 +- Public template RPCs are SECURITY INVOKER wrappers; privileged implementations remain in the unexposed `private` schema with empty `search_path` and explicit grants.
12 +- Direct `authenticated` / `anon` table access to the private template store is revoked.
13 +- Office UI now has «قالب‌های نامه», version creation, latest-template catalog, and controlled application to the new-letter editor.
14 +- Applied template provenance (`templateKey`, `templateVersion`) is carried into draft/registration and validated server-side.
15 +- Applying a template only populates the editable new-letter form; it does not mutate registered correspondence.
16 +
17 +## Production migrations
18 +- `20260930202526 office_registration_tenant_repair`
19 +- `20260930202701 office_slice_c4_versioned_templates`
20 +
21 +Archived SQL:
22 +- `supabase/migrations/20260930202526_office_registration_tenant_repair.sql`
23 +- `supabase/migrations/20260930202701_office_slice_c4_versioned_templates.sql`
24 +
25 +## RED / defect evidence
26 +Pre-flight inspection found both:
27 +- `office_register_correspondence(text,text,jsonb)` — legacy owner-only implementation that omitted mandatory `organization_id`;
28 +- `office_register_correspondence(text,text,jsonb,uuid default null)` — tenant-aware implementation.
29 +
30 +A three-argument SQL call was ambiguous because both overloads matched. The C4 repair drops the legacy overload and keeps one tenant-aware RPC. A transactional production test then registered a letter through the three-argument/default path and verified organization id, owner id, assigned number and `registered` status.
31 +
32 +## Transactional production adversarial verification
33 +All template versions, test registry/correspondence, temporary membership/permission and temporary seat expansion were rolled back.
34 +
35 +PASS:
36 +1. Owner/configurator created template version 1 and then version 2 under one stable key.
37 +2. Catalog returned only the latest version for the key.
38 +3. Registered correspondence accepted an existing same-organization template version and persisted its provenance.
39 +4. Registration with nonexistent template version was rejected.
40 +5. Read-only organization member could read the active template catalog.
41 +6. Read-only member could not create a template version.
42 +7. Authenticated role could not directly SELECT/INSERT the private template store.
43 +8. Cross-tenant principal received no template catalog rows.
44 +9. Rollback left zero C4 records/template/member residue and restored `max_users=1`.
45 +
46 +## GitHub verification
47 +Verified C4 runtime/test head: `481f9fed434f127eaa32ccf8d69c649e783b5cad`.
48 +- Quality `36773156535`: PASS, including JavaScript syntax, accounting/Golden, ELI-1/2/3/4, Office C1/C2/C3/C4 invariants and Real-DOM.
49 +- Security `36773156559`: CodeQL JavaScript PASS. Dependency Review remains skipped because Dependency Graph is still disabled.
50 +- Pages `36773155535`: build/deploy/report PASS.
51 +
52 +An earlier C4 run correctly exposed a Real-DOM readiness race: C1/C4 tests waited only for base `officeRender` while mature-office extensions were still loading. The tests were corrected to wait for their actual mature-runtime functions; the full Real-DOM suite then passed.
53 +
54 +## Security/advisor disposition
55 +The public C4 API functions are SECURITY INVOKER. The necessary SECURITY DEFINER helpers are kept in the private schema, use an empty search path and are not exposed as public Data API RPCs. This follows current Supabase guidance to keep definer helpers out of exposed schemas and to restrict function/table privileges.
56 +
57 +The live security advisor remains at 20 public authenticated-callable SECURITY DEFINER warnings; C4 did not add another public warning. Leaked-password protection remains disabled.
58 +
59 +## Scope boundary / NOT VERIFIED
60 +C4 is a controlled text-template/editor foundation, not a Word-compatible document engine. It does not claim approval/signature lifecycle, qualified digital signature, Persian OCR quality, external document gateways or persistent two-real-user browser E2E.