fix/password-unicode-validation-20261111
add-index-html-10623938925177053894
arena/094f314c-aram
chatgpt-phase1b2-autopilot
codex/adr-future-connectors-pi-v1
codex/aram-account-note-source-trace-20261031
codex/aram-actions-node24-maintenance-20261031
codex/aram-analyst-review-workbook-20261031
codex/aram-bs-candidate-statement-20261031
codex/aram-cash-flow-direct-candidate-20261031
codex/aram-clean-reference-year-integrity-20261030
codex/aram-cross-statement-controls-20261031
codex/aram-equity-changes-candidate-20261031
codex/aram-five-statement-cli-20261031
codex/aram-five-statement-integration-20261031
codex/aram-five-statement-orchestrator-20261031
codex/aram-gate3-coverage-target-guard-20261030
codex/aram-gate3-hidden-xlsx-guard-20261030
codex/aram-gate3-integration-validation-20261030
codex/aram-gate3-mapping-change-preview-20261030
codex/aram-gate3-stale-note-guard-20261030
codex/aram-income-statement-candidate-20261031
codex/aram-manifest-referential-integrity-20261031
codex/aram-mapping-source-parser-20261101
codex/aram-multidimensional-mapping-20261101
codex/aram-multistatement-mapping-20261031
codex/aram-pipeline-manifest-schema-20261031
codex/aram-readonly-mapping-coverage-20261031
codex/aram-reconciliation-review-gate-20261031
codex/aram-same-flush-fiscal-lock-20261030
codex/aram-synthetic-windows-demo-20261031
codex/aram-trial-balance-diagnostic-20261031
codex/aram-windows-background-detail-search-20261031
codex/aram-windows-detail-review-20261031
codex/aram-windows-five-statement-pilot-20261031
codex/aram-windows-statement-figures-20261031
codex/gate-2a-pilot-workbook
codex/gate-2a-pilot-workbook-6864754244772568979
codex/gate3-authenticated-principal-boundary-20261030
codex/gate3-authored-draft-staging-20261030
codex/gate3-carry-forward-preview-20261023
codex/gate3-draft-staging-audit-20261030
codex/gate3-mapping-batch-freshness-20261030
codex/gate3-mapping-batch-review-20261030
codex/gate3-mapping-core
codex/gate3-mapping-coverage-20261023
codex/gate3-mapping-excel-20261023
codex/gate3-note-mapping-review-20261023
codex/gate3-signed-year-scope-20261030
codex/gate3-unapproved-proposal-storage-20261030
codex/payvast-mapping-discovery-20261023
codex/phase-2a-backend-foundation
codex/phase-2b-post-merge-record
codex/phase-2b-source-registration
codex/phase-2b-source-registration-12955190277775369594
codex/post-gate2a-control-reconciliation
codex/post-pr18-acceptance-record
codex/project-control-foundation
codex/t1-repo-hygiene-20261023
codex/t2-ci-hardening-20261023
codex/t3-explicit-migrations-20261023
codex/t6a-readonly-diagnostics-20261023
codex/v1-01-safety-gate-hardening
codex/v1-year-isolation-followup-20261023
codex/windows-native-pilot-shell-20261030
docs/aram-master-control-plan-20261111
docs/aram-roadmap-dashboard-20261030
docs/financial-statement-reconciliation-1402-1404-20261110
feat/gate3-governed-mapping-20261101
feat/gate3-package9-1-security-20261103
feat/gate3-package9-isolated-20261103
fix/password-unicode-validation-20261111
governance/aram-5-1-3-controls-20261030
governance/role-based-operating-model
jules-1168663913887856558-73b8a885
jules-gate-2b-mapping-workflow-foundation-4137724387867065330
phase-1b1-audit-report-7365389436990903239
phase-2a-backend-foundation-10237597358138521261
phase1b2-postmerge-metadata-fix
refactor/drg-parent-year-id-15088443704684163304
source-data-cleanup
| 1 | import pytest |
| 2 | |
| 3 | from aram_backend.mapping_store import MappingStore |
| 4 | from aram_backend.mapping_workflow import MappingDecision, MappingWorkflowError |
| 5 | |
| 6 | |
| 7 | def test_owner_exception_persists_reason_and_does_not_approve(tmp_path): |
| 8 | store = MappingStore(tmp_path / "owner.db") |
| 9 | space, revision = store.load("001", 1405) |
| 10 | space.propose(MappingDecision("M1", "001", 1405, "100", "BS", "Assets", "1", None, 1, "Draft", None, "Manual"), actor="owner") |
| 11 | with pytest.raises(MappingWorkflowError, match="reason"): |
| 12 | space.owner_accept("M1", actor="owner", reason="too short") |
| 13 | accepted = space.owner_accept("M1", actor="owner", reason="Owner knowingly accepts missing independent review") |
| 14 | assert accepted.status == "OwnerAcceptedWithException" |
| 15 | assert accepted.reviewer is None |
| 16 | assert space.audit[-1].reason.startswith("Owner knowingly") |
| 17 | store.save(space, revision) |
| 18 | loaded, _ = store.load("001", 1405) |
| 19 | assert loaded.decisions[0].status != "Approved" |
| 20 | assert loaded.audit[-1].reason == space.audit[-1].reason |
| 21 | store.verify_integrity() |
| 22 | with pytest.raises(MappingWorkflowError, match="invalid mapping lifecycle"): |
| 23 | loaded.transition("M1", "Approved", actor="owner") |
| 24 | |
| 25 | |
| 26 | def test_owner_exception_cannot_be_made_from_reviewed(tmp_path): |
| 27 | store = MappingStore(tmp_path / "owner2.db") |
| 28 | space, _ = store.load("001", 1405) |
| 29 | space.propose(MappingDecision("M1", "001", 1405, "100", "BS", "Assets", "1", None, 1, "Draft", None, "Manual"), actor="maker") |
| 30 | space.transition("M1", "Reviewed", actor="reviewer") |
| 31 | with pytest.raises(MappingWorkflowError, match="unreviewed Draft"): |
| 32 | space.owner_accept("M1", actor="maker", reason="I acknowledge missing independent approval") |
| 33 | |
| 34 | def test_owner_http_is_scoped_and_never_independent_approval(tmp_path): |
| 35 | from fastapi.testclient import TestClient |
| 36 | |
| 37 | from aram_backend.main import app |
| 38 | from aram_backend.mapping_access import AuthenticatedPrincipal |
| 39 | from aram_backend.mapping_api import ( |
| 40 | configure_mapping_service, |
| 41 | reset_mapping_service, |
| 42 | ) |
| 43 | |
| 44 | people = { |
| 45 | "owner-token": AuthenticatedPrincipal("owner", frozenset({"001"}), frozenset({"owner", "maker"})), |
| 46 | "maker-token": AuthenticatedPrincipal("maker", frozenset({"001"}), frozenset({"maker"})), |
| 47 | "foreign-token": AuthenticatedPrincipal("other", frozenset({"002"}), frozenset({"owner"})), |
| 48 | } |
| 49 | store = MappingStore(tmp_path / "http-owner.db") |
| 50 | configure_mapping_service(store=store, identity_resolver=people.get) |
| 51 | try: |
| 52 | client = TestClient(app) |
| 53 | base = "/api/v1/mapping/001/1405" |
| 54 | def post(path, token, data): |
| 55 | return client.post(base + path, headers={"Authorization": "Bearer " + token}, json=data) |
| 56 | proposal = {"mapping_id": "M1", "account_full_code": "100", "target_statement": "BS", "statement_section": "Assets", "note_number": "1"} |
| 57 | assert post("/proposals", "maker-token", proposal).status_code == 200 |
| 58 | path = "/M1/owner-accept" |
| 59 | reason = {"reason": "Owner explicitly accepts the lack of independent review"} |
| 60 | assert post(path, "maker-token", reason).status_code == 403 |
| 61 | assert post(path, "foreign-token", reason).status_code == 403 |
| 62 | assert post(path, "owner-token", {"reason": "short"}).status_code == 422 |
| 63 | result = post(path, "owner-token", reason) |
| 64 | assert result.status_code == 200, result.text |
| 65 | assert result.json()["status"] == "OwnerAcceptedWithException" |
| 66 | assert post("/M1/approve", "owner-token", {}).status_code == 403 |
| 67 | store.verify_integrity() |
| 68 | assert store.audit_log("001", 1405)[-1].reason == reason["reason"] |
| 69 | finally: |
| 70 | reset_mapping_service() |
| 71 | |
| 72 | def test_owner_api_requires_trusted_owner_role(tmp_path): |
| 73 | from fastapi.testclient import TestClient |
| 74 | |
| 75 | from aram_backend.main import app |
| 76 | from aram_backend.mapping_access import AuthenticatedPrincipal |
| 77 | from aram_backend.mapping_api import ( |
| 78 | configure_mapping_service, |
| 79 | reset_mapping_service, |
| 80 | ) |
| 81 | store = MappingStore(tmp_path / "owner-api.db") |
| 82 | people = { |
| 83 | "maker": AuthenticatedPrincipal("owner", frozenset({"001"}), frozenset({"maker"})), |
| 84 | "owner": AuthenticatedPrincipal("owner", frozenset({"001"}), frozenset({"owner"})), |
| 85 | "foreign": AuthenticatedPrincipal("other", frozenset({"002"}), frozenset({"owner"})), |
| 86 | } |
| 87 | configure_mapping_service(store=store, identity_resolver=people.get) |
| 88 | client = TestClient(app) |
| 89 | base = "/api/v1/mapping/001/1405" |
| 90 | try: |
| 91 | payload = {"mapping_id": "M1", "account_full_code": "100", "target_statement": "BS", |
| 92 | "statement_section": "Assets", "note_number": "1"} |
| 93 | assert client.post(base + "/proposals", headers={"Authorization": "Bearer maker"}, json=payload).status_code == 200 |
| 94 | path = base + "/M1/owner-accept" |
| 95 | body = {"reason": "Owner acknowledges missing independent review"} |
| 96 | assert client.post(path, json=body).status_code == 401 |
| 97 | assert client.post(path, headers={"Authorization": "Bearer maker"}, json=body).status_code == 403 |
| 98 | assert client.post(path, headers={"Authorization": "Bearer foreign"}, json=body).status_code == 403 |
| 99 | assert client.post(path, headers={"Authorization": "Bearer owner"}, json={"reason": "short"}).status_code == 422 |
| 100 | result = client.post(path, headers={"Authorization": "Bearer owner"}, json=body) |
| 101 | assert result.status_code == 200 |
| 102 | assert result.json()["status"] == "OwnerAcceptedWithException" |
| 103 | assert store.load("001", 1405)[0].audit[-1].reason == body["reason"] |
| 104 | assert client.post(base + "/M1/approve", headers={"Authorization": "Bearer owner"}).status_code == 403 |
| 105 | finally: |
| 106 | reset_mapping_service() |
| 107 | |
| 108 | def test_owner_acceptance_is_included_in_audit_hash(tmp_path): |
| 109 | import sqlite3 |
| 110 | |
| 111 | from aram_backend.mapping_integrity import audit_chain |
| 112 | store = MappingStore(tmp_path / "hash-owner.db") |
| 113 | space, revision = store.load("001", 1405) |
| 114 | space.propose(MappingDecision("M1", "001", 1405, "100", "BS", "Assets", "1", None, 1, "Draft", None, "Manual"), actor="maker") |
| 115 | space.owner_accept("M1", actor="owner", reason="Owner accepts the missing independent approval") |
| 116 | store.save(space, revision) |
| 117 | expected = audit_chain(store.audit_log("001", 1405))[-1] |
| 118 | with sqlite3.connect(store.path) as conn: |
| 119 | actual = conn.execute("SELECT digest FROM mapping_audit_hash ORDER BY sequence DESC LIMIT 1").fetchone()[0] |
| 120 | assert actual == expected |
| 121 | assert store.audit_receipt("001", 1405)["sha256"] == expected |