@davoodmehraban89 / Aram-1 / commits / 4641e57
Fork 0

fix(gate3): enforce maker-approver separation and audited state integrity

Davood Mehraban committed Nov 1, 2026 at 21:48 UTC 4641e57d6f94904215261c1f9518c56a26ee0982
7 files changed +84 -3
PROJECT_STATUS.md
+10
@@ -87,3 +87,13 @@ The accepted branch does not include PR #7 desktop/release work, PR #16 alternat
87 - [Master recovery prompt](docs/handoff/MASTER_RECOVERY_PROMPT.md)
88 - [Latest handoff snapshot](docs/handoff/LATEST_HANDOFF.md)
89 - [Saveable ChatGPT bootstrap prompt](docs/handoff/CHATGPT_BOOTSTRAP_PROMPT.txt)
90 +
91 +
92 +## 2026-11-01 — Gate 3 current review status (supersedes older Gate 3 status above)
93 +- Candidate: Draft PR #82 on feat/gate3-governed-mapping-20261101, based on source-data-cleanup@7dc864fd032f0c4ae4d650d89304a01286a6d914.
94 +- Local Gate 3 implementation includes scoped mapping lifecycle, SQLite state/audit, optimistic concurrency, Pilot workbook roundtrip and unknown-account queue.
95 +- Package 3 hardening adds separation of maker/reviewer/approver and validation that persisted mapping state agrees with append-only audit transitions.
96 +- Three sequential self-audit passes documented at docs/GATE3_REVIEW_82.md; independent GitHub reviewers have not signed off.
97 +- Status: CHANGES REQUESTED; Gate 3 is not formally accepted. No merge or release.
98 +- Unresolved: authenticated identity and authorization, privileged-database tamper resistance, independent review, operational recovery drill, mapping ambiguity and real-data acceptance.
99 +- Rollback: revert isolated PR commits; accepted base and canonical financial source files remain untouched.
backend/src/aram_backend/mapping_store.py
+21
@@ -70,6 +70,27 @@ class MappingStore:
70 for event in workspace.audit:
71 if (event.company_code, event.fiscal_year) != (workspace.company_code, workspace.fiscal_year):
72 raise MappingWorkflowError("foreign audit event")
73 + # Reject forged state and invalid audit sequences before starting a write.
74 + latest = {}
75 + for event in workspace.audit:
76 + prior = latest.get(event.mapping_id)
77 + if prior is None:
78 + valid = (event.previous_status is None and
79 + event.previous_version is None and
80 + event.new_status == "Draft" and event.new_version == 1)
81 + else:
82 + previous_status, previous_version = prior
83 + valid = (event.previous_status == previous_status and
84 + event.previous_version == previous_version and
85 + event.new_version == previous_version + 1 and
86 + ((previous_status == "Draft" and event.new_status == "Reviewed") or
87 + (previous_status == "Reviewed" and event.new_status == "Approved") or
88 + event.new_status == "Draft"))
89 + if not valid or not event.actor.strip():
90 + raise MappingWorkflowError("invalid audit transition or version chain")
91 + latest[event.mapping_id] = (event.new_status, event.new_version)
92 + if {d.mapping_id: (d.status, d.version) for d in workspace.decisions} != latest:
93 + raise MappingWorkflowError("mapping state and audit history diverged")
94 payload = json.dumps({
95 "decisions": [asdict(item) for item in workspace.decisions],
96 "audit": [asdict(item) for item in workspace.audit],
backend/src/aram_backend/mapping_workflow.py
+5 -2
@@ -111,8 +111,11 @@ class MappingWorkspace:
111 and event.actor == actor for event in self._audit
112 ):
113 raise MappingWorkflowError("maker cannot review own mapping")
114 - if status == "Approved" and actor == old.reviewer:
115 - raise MappingWorkflowError("approval requires independent reviewer")
114 + if status == "Approved" and (actor == old.reviewer or any(
115 + event.mapping_id == mapping_id and event.new_status == "Draft"
116 + and event.actor == actor for event in self._audit
117 + )):
118 + raise MappingWorkflowError("approval requires independent maker and reviewer")
119 new = replace(old, status=status, reviewer=actor,
120 review_date=datetime.now(timezone.utc).date().isoformat(),
121 version=old.version + 1)
backend/tests/test_mapping_store.py
+15 -1
@@ -68,7 +68,7 @@ def test_append_only_audit_and_scope(tmp_path):
68 store.save(space, rev)
69 loaded, rev = store.load("001", 1405)
70 loaded._audit.clear()
71 - with pytest.raises(MappingWorkflowError, match="append-only"):
71 + with pytest.raises(MappingWorkflowError, match="audit history diverged"):
72 store.save(loaded, rev)
73 assert len(store.audit_log("001", 1405)) == 1
74 other, rev = store.load("002", 1405)
@@ -109,3 +109,17 @@ def test_approved_workbook_roundtrip_with_review_evidence():
109 exported = export_pilot_mapping_workbook(original, [approved],
110 company_code="001", fiscal_year=1405)
111 assert import_mapping_workbook(exported, "001", 1405) == (approved,)
112 +
113 +
114 +def test_store_rejects_forged_mapping_state_and_audit_chain(tmp_path):
115 + store = MappingStore(tmp_path / "forged.db")
116 + state, revision = store.load("001", 1405)
117 + state.propose(decision(), actor="maker")
118 + state._decisions["M001"] = replace(decision(), status="Approved", version=3)
119 + with pytest.raises(MappingWorkflowError, match="diverged"):
120 + store.save(state, revision)
121 + state._decisions["M001"] = decision()
122 + state._audit[0] = replace(state._audit[0], new_version=99)
123 + with pytest.raises(MappingWorkflowError, match="audit"):
124 + store.save(state, revision)
125 + assert store.load("001", 1405)[1] == 0
backend/tests/test_mapping_workflow.py
+10
@@ -129,3 +129,13 @@ def test_maker_cannot_review_own_mapping():
129 with pytest.raises(MappingWorkflowError, match="maker"):
130 space.transition("M001", "Reviewed", actor="maker")
131 assert len(space.audit) == 1
132 +
133 +
134 +def test_maker_cannot_approve_own_mapping_even_after_independent_review():
135 + space = MappingWorkspace("001", 1405)
136 + space.propose(sample(), actor="maker")
137 + space.transition("M001", "Reviewed", actor="reviewer")
138 + with pytest.raises(MappingWorkflowError, match="independent"):
139 + space.transition("M001", "Approved", actor="maker")
140 + assert space.decisions[0].status == "Reviewed"
141 + assert len(space.audit) == 2
docs/GATE3_REVIEW_82.md
+14
@@ -46,3 +46,17 @@ production data. This PR remains Draft.
46 These are three sequential self-audit perspectives, not three independent
47 human or separately instantiated reviewer identities. External independent
48 review and updated final-head CI are required before formal acceptance.
49 +
50 +
51 +## Package 3 review extension — 2026-11-01
52 +- Exact approved base checked locally: source-data-cleanup at 7dc864fd032f0c4ae4d650d89304a01286a6d914.
53 +- Prior reviewed head: ff6843cd0a1544a3a5355a8d555d4d692b8716fc.
54 +- Working tree initially clean; feature branch isolated.
55 +- Reviewer 1 (functional self-audit): found that maker could approve after another user reviewed; fixed maker/approver separation and added regression test.
56 +- Reviewer 2 (security/architecture self-audit): found state could be persisted with a forged final status/version inconsistent with audit. Added audit-transition/version-chain and state consistency checks plus regression test.
57 +- Reviewer 3 (adversarial self-audit): exercised invalid state and forged audit, rollback, stale concurrent writers, workbook roundtrip and foreign scope. New tests cover forged status and event version.
58 +- These are three sequential self-audits by the implementation assistant, **not independent reviewers**. GitHub review list was empty at start.
59 +- Known unresolved risks: no trusted identity provider / role authorization; SQLite audit is not cryptographically tamper-evident against privileged DB writers; no production recovery drill; no independent reviewer sign-off; Gate 3 financial mapping ambiguity remains material. These require separate controls and block acceptance.
60 +- No merge, release or production financial data modification is authorized.
61 +- Final CI and full local test evidence must be checked against the new head before any acceptance decision.
62 +- Decision: CHANGES REQUESTED; PR remains Draft pending independent review and closure of material controls.
docs/PROJECT_LOG.md
+9
@@ -278,3 +278,12 @@ Each new entry must record: UTC timestamp, actor, task/phase, base branch and SH
278 - Recovery: close the candidate PR without merge; accepted branch remains at the recorded base
279 - Remaining risks: comprehensive Mapping, note/sub-note workflow, real Pilot UI/output, Windows packaging, and user acceptance remain incomplete
280 - Next action: publish the focused PR and obtain independent remote review after CI
281 +
282 +
283 +## 2026-11-01 — Gate 3 PR #82 Package 3
284 +- Branch: feat/gate3-governed-mapping-20261101; base: source-data-cleanup@7dc864fd032f0c4ae4d650d89304a01286a6d914.
285 +- Initial reviewed head: ff6843cd0a1544a3a5355a8d555d4d692b8716fc.
286 +- Scope: MappingWorkflow maker/approver separation; MappingStore audit-chain/state integrity; regression tests; Gate 3 review evidence and project status.
287 +- Three sequential adversarial self-audits documented in docs/GATE3_REVIEW_82.md. No claim of independent reviewers.
288 +- Formal decision: CHANGES REQUESTED, Gate 3 not accepted; independent reviewer and material operational/security controls outstanding.
289 +- Rollback: revert Package 3 commits on isolated feature branch; no production schema/data migration.