arena/094f314c-aram
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 | from __future__ import annotations |
| 2 | |
| 3 | from io import BytesIO |
| 4 | |
| 5 | from openpyxl import load_workbook |
| 6 | |
| 7 | import aram_backend.pilot_api as pilot_api |
| 8 | from test_pilot_engine import build_balanced_workbook |
| 9 | |
| 10 | |
| 11 | def test_meta_exposes_explicit_sign_policy(client): |
| 12 | response = client.get("/api/v1/pilot/meta") |
| 13 | assert response.status_code == 200 |
| 14 | body = response.json() |
| 15 | assert body["rendered_statements"] == ["BS", "IS"] |
| 16 | assert body["deferred_statements"] == ["CF", "EQ"] |
| 17 | assert body["section_policy"]["BS"] == {"Assets": 1, "Liabilities": -1, "Equity": -1} |
| 18 | assert body["section_policy"]["IS"] == {"Revenue": -1, "Expenses": 1} |
| 19 | |
| 20 | |
| 21 | def test_root_serves_workbench_directly_and_ui_is_served(client): |
| 22 | response = client.get("/", follow_redirects=False) |
| 23 | assert response.status_code == 200 |
| 24 | assert "میز کار پایلوت" in response.text |
| 25 | page = client.get("/pilot/") |
| 26 | assert page.status_code == 200 |
| 27 | assert "میز کار پایلوت" in page.text |
| 28 | assert client.get("/pilot/app.js").status_code == 200 |
| 29 | assert client.get("/pilot/styles.css").status_code == 200 |
| 30 | |
| 31 | |
| 32 | def test_demo_full_workflow_from_exceptions_to_approved_export(client): |
| 33 | created = client.post("/api/v1/pilot/demo") |
| 34 | assert created.status_code == 200 |
| 35 | body = created.json() |
| 36 | sid = body["session"]["id"] |
| 37 | assert body["session"]["source"] == "demo" |
| 38 | assert body["report"]["status"]["label"] == "INCOMPLETE" |
| 39 | assert {e["account_code"] for e in body["report"]["exceptions"]} == {"9001", "9002"} |
| 40 | tb = next(c for c in body["report"]["checks"] if c["code"] == "TRIAL_BALANCE_CLOSED") |
| 41 | assert tb["passed"] and tb["amount"] == "0" |
| 42 | |
| 43 | # Map the two suspense accounts; coverage and equation close, approval pending. |
| 44 | for code, statement, section, note in ( |
| 45 | ("9001", "BS", "Assets", "04"), |
| 46 | ("9002", "BS", "Liabilities", "06"), |
| 47 | ): |
| 48 | response = client.put( |
| 49 | f"/api/v1/pilot/sessions/{sid}/mappings/{code}", |
| 50 | json={"statement": statement, "section": section, "note_number": note, |
| 51 | "actor": "آزمون"}, |
| 52 | ) |
| 53 | assert response.status_code == 200 |
| 54 | body = response.json() |
| 55 | assert body["report"]["status"]["label"] == "COMPLETE_DRAFT" |
| 56 | assert body["report"]["totals"]["assets"] == "56000000000" |
| 57 | assert body["report"]["totals"]["liabilities"] == "22800000000" |
| 58 | assert body["report"]["totals"]["equity"] == "33000000000" |
| 59 | assert body["report"]["totals"]["profit"] == "200000000" |
| 60 | assert all(c["passed"] for c in body["report"]["checks"] if c["code"] != "MAPPINGS_APPROVED") |
| 61 | |
| 62 | # Approve the remaining Draft mappings with reviewer evidence. |
| 63 | for code, statement, section, note in ( |
| 64 | ("1004", "BS", "Assets", "04"), |
| 65 | ("9001", "BS", "Assets", "04"), |
| 66 | ("9002", "BS", "Liabilities", "06"), |
| 67 | ): |
| 68 | response = client.put( |
| 69 | f"/api/v1/pilot/sessions/{sid}/mappings/{code}", |
| 70 | json={"statement": statement, "section": section, "note_number": note, |
| 71 | "approval_status": "Approved", "reviewer": "بازبین آزمون", "actor": "آزمون"}, |
| 72 | ) |
| 73 | assert response.status_code == 200 |
| 74 | body = response.json() |
| 75 | assert body["report"]["status"]["label"] == "COMPLETE_APPROVED" |
| 76 | assert len(body["audit_trail"]) == 5 |
| 77 | assert body["audit_trail"][0]["actor"] == "آزمون" |
| 78 | |
| 79 | export = client.get(f"/api/v1/pilot/sessions/{sid}/export.xlsx") |
| 80 | assert export.status_code == 200 |
| 81 | assert "spreadsheetml" in export.headers["content-type"] |
| 82 | book = load_workbook(BytesIO(export.content)) |
| 83 | assert "BalanceSheet" in book.sheetnames |
| 84 | info = {row[0]: row[1] for row in book["Info"].iter_rows(min_row=2, values_only=True)} |
| 85 | assert info["status"] == "COMPLETE_APPROVED" |
| 86 | assert info["synthetic_data"].startswith("TRUE") |
| 87 | assert book["AuditTrail"].max_row == 6 |
| 88 | book.close() |
| 89 | |
| 90 | assert client.delete(f"/api/v1/pilot/sessions/{sid}").status_code == 200 |
| 91 | assert client.get(f"/api/v1/pilot/sessions/{sid}").status_code == 404 |
| 92 | |
| 93 | |
| 94 | def test_upload_valid_workbook_creates_session(client): |
| 95 | response = client.post( |
| 96 | "/api/v1/pilot/sessions", |
| 97 | files={"file": ("pilot.xlsx", build_balanced_workbook(), |
| 98 | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")}, |
| 99 | ) |
| 100 | assert response.status_code == 200 |
| 101 | body = response.json() |
| 102 | assert body["session"]["source"] == "upload" |
| 103 | assert body["report"]["status"]["label"] == "COMPLETE_APPROVED" |
| 104 | assert len(body["accounts"]) == 5 |
| 105 | |
| 106 | |
| 107 | def test_upload_invalid_workbook_returns_exact_preflight_issues(client): |
| 108 | response = client.post( |
| 109 | "/api/v1/pilot/sessions", files={"file": ("bad.xlsx", b"not an xlsx")} |
| 110 | ) |
| 111 | assert response.status_code == 422 |
| 112 | detail = response.json()["detail"] |
| 113 | assert detail["issues"][0]["code"] == "INVALID_WORKBOOK" |
| 114 | |
| 115 | |
| 116 | def test_upload_rejects_wrong_extension_and_empty_file(client): |
| 117 | response = client.post( |
| 118 | "/api/v1/pilot/sessions", files={"file": ("data.csv", b"x,y\n1,2")} |
| 119 | ) |
| 120 | assert response.status_code == 422 |
| 121 | response = client.post( |
| 122 | "/api/v1/pilot/sessions", files={"file": ("empty.xlsx", b"")} |
| 123 | ) |
| 124 | assert response.status_code == 422 |
| 125 | |
| 126 | |
| 127 | def test_upload_size_limit_is_enforced(client, monkeypatch): |
| 128 | monkeypatch.setattr(pilot_api, "MAX_UPLOAD_BYTES", 8) |
| 129 | response = client.post( |
| 130 | "/api/v1/pilot/sessions", files={"file": ("big.xlsx", b"0123456789")} |
| 131 | ) |
| 132 | assert response.status_code == 413 |
| 133 | |
| 134 | |
| 135 | def test_mapping_validation_is_fail_closed(client): |
| 136 | sid = client.post("/api/v1/pilot/demo").json()["session"]["id"] |
| 137 | base = f"/api/v1/pilot/sessions/{sid}/mappings" |
| 138 | # Unknown account. |
| 139 | assert client.put(f"{base}/9999", json={ |
| 140 | "statement": "BS", "section": "Assets", "note_number": "01", |
| 141 | }).status_code == 404 |
| 142 | # Target that does not exist in Notes. |
| 143 | assert client.put(f"{base}/9001", json={ |
| 144 | "statement": "BS", "section": "Assets", "note_number": "99", |
| 145 | }).status_code == 422 |
| 146 | # Approved without reviewer evidence. |
| 147 | assert client.put(f"{base}/9001", json={ |
| 148 | "statement": "BS", "section": "Assets", "note_number": "04", |
| 149 | "approval_status": "Approved", |
| 150 | }).status_code == 422 |
| 151 | # Invalid lifecycle value. |
| 152 | assert client.put(f"{base}/9001", json={ |
| 153 | "statement": "BS", "section": "Assets", "note_number": "04", |
| 154 | "approval_status": "Published", |
| 155 | }).status_code == 422 |
| 156 | |
| 157 | |
| 158 | def test_clear_mapping_reopens_the_exception_queue(client): |
| 159 | sid = client.post("/api/v1/pilot/demo").json()["session"]["id"] |
| 160 | response = client.delete(f"/api/v1/pilot/sessions/{sid}/mappings/1001?actor=tester") |
| 161 | assert response.status_code == 200 |
| 162 | body = response.json() |
| 163 | assert body["report"]["status"]["label"] == "INCOMPLETE" |
| 164 | assert "1001" in {e["account_code"] for e in body["report"]["exceptions"]} |
| 165 | assert body["audit_trail"][-1]["action"] == "clear_mapping" |
| 166 | |
| 167 | |
| 168 | def test_unknown_session_is_404_everywhere(client): |
| 169 | assert client.get("/api/v1/pilot/sessions/nope").status_code == 404 |
| 170 | assert client.get("/api/v1/pilot/sessions/nope/export.xlsx").status_code == 404 |
| 171 | assert client.delete("/api/v1/pilot/sessions/nope").status_code == 404 |
| 172 | assert client.put("/api/v1/pilot/sessions/nope/mappings/10", json={ |
| 173 | "statement": "BS", "section": "Assets", "note_number": "01", |
| 174 | }).status_code == 404 |
| 175 | |
| 176 | |
| 177 | def test_existing_api_surface_is_unchanged(client): |
| 178 | assert client.get("/api/v1/health").json()["status"] == "ok" |
| 179 | assert len(client.get("/api/v1/schema/entities").json()["entities"]) == 9 |