@davoodmehraban89 / Aram-2 Mirror · read-only
Fork 0

Mirrored from https://github.com/davoodmehraban89/Aram.git

Synced Dec 4, 14:15 UTC

dependabot/github_actions/actions/checkout-7
add-index-html-10623938925177053894 arena/094f314c-aram arena/2d4eda07-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 dependabot/github_actions/actions/checkout-7 dependabot/github_actions/actions/setup-node-6 dependabot/github_actions/actions/setup-python-7 dependabot/github_actions/actions/upload-artifact-7 dependabot/npm_and_yarn/frontend/eslint-plugin-react-hooks-7.1.1 dependabot/npm_and_yarn/frontend/globals-17.15.0 dependabot/npm_and_yarn/frontend/vite-8.4.0 dependabot/npm_and_yarn/frontend/vitest-5.1.2 dependabot/npm_and_yarn/frontend/vitest/coverage-v8-5.1.2 dependabot/pip/backend/mypy-gte-1.13-and-lt-3 dependabot/pip/backend/pytest-cov-gte-6.0-and-lt-8 dependabot/pip/backend/setuptools-gte-75-and-lt-85 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
py 200 lines 8.44 KB
Raw
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(pilot_client):
12 client = pilot_client
13 response = client.get("/api/v1/pilot/meta")
14 assert response.status_code == 200
15 body = response.json()
16 assert body["rendered_statements"] == ["BS", "IS"]
17 assert body["deferred_statements"] == ["CF", "EQ"]
18 assert body["section_policy"]["BS"] == {"Assets": 1, "Liabilities": -1, "Equity": -1}
19 assert body["section_policy"]["IS"] == {"Revenue": -1, "Expenses": 1}
20
21
22 def test_legacy_pilot_ui_is_no_longer_served(client):
23 """R1 (booklet 2.1): "/" must not serve the legacy in-memory workbench, and
24 neither the pilot pages nor its routes are part of the shipped app."""
25 root = client.get("/")
26 assert root.status_code == 404
27 assert "میز کار پایلوت" not in root.text
28 assert client.get("/pilot/").status_code == 404
29 assert client.get("/pilot/app.js").status_code == 404
30 assert client.get("/api/v1/pilot/meta").status_code == 404
31 assert client.post("/api/v1/pilot/demo").status_code == 404
32 paths = {getattr(route, "path", "") for route in client.app.routes}
33 assert not any(path.startswith("/api/v1/pilot") for path in paths)
34 assert not any(path.startswith("/pilot") for path in paths)
35
36
37 def test_demo_full_workflow_from_exceptions_to_approved_export(pilot_client):
38 client = pilot_client
39 created = client.post("/api/v1/pilot/demo")
40 assert created.status_code == 200
41 body = created.json()
42 sid = body["session"]["id"]
43 assert body["session"]["source"] == "demo"
44 assert body["report"]["status"]["label"] == "INCOMPLETE"
45 assert {e["account_code"] for e in body["report"]["exceptions"]} == {"9001", "9002"}
46 tb = next(c for c in body["report"]["checks"] if c["code"] == "TRIAL_BALANCE_CLOSED")
47 assert tb["passed"] and tb["amount"] == "0"
48
49 # Map the two suspense accounts; coverage and equation close, approval pending.
50 for code, statement, section, note in (
51 ("9001", "BS", "Assets", "04"),
52 ("9002", "BS", "Liabilities", "06"),
53 ):
54 response = client.put(
55 f"/api/v1/pilot/sessions/{sid}/mappings/{code}",
56 json={"statement": statement, "section": section, "note_number": note,
57 "actor": "آزمون"},
58 )
59 assert response.status_code == 200
60 body = response.json()
61 assert body["report"]["status"]["label"] == "COMPLETE_DRAFT"
62 assert body["report"]["totals"]["assets"] == "56000000000"
63 assert body["report"]["totals"]["liabilities"] == "22800000000"
64 assert body["report"]["totals"]["equity"] == "33000000000"
65 assert body["report"]["totals"]["profit"] == "200000000"
66 assert all(c["passed"] for c in body["report"]["checks"] if c["code"] != "MAPPINGS_APPROVED")
67
68 # Approve the remaining Draft mappings with reviewer evidence.
69 for code, statement, section, note in (
70 ("1004", "BS", "Assets", "04"),
71 ("9001", "BS", "Assets", "04"),
72 ("9002", "BS", "Liabilities", "06"),
73 ):
74 response = client.put(
75 f"/api/v1/pilot/sessions/{sid}/mappings/{code}",
76 json={"statement": statement, "section": section, "note_number": note,
77 "approval_status": "Approved", "reviewer": "بازبین آزمون", "actor": "آزمون"},
78 )
79 assert response.status_code == 200
80 body = response.json()
81 assert body["report"]["status"]["label"] == "COMPLETE_APPROVED"
82 assert len(body["audit_trail"]) == 5
83 assert body["audit_trail"][0]["actor"] == "آزمون"
84
85 export = client.get(f"/api/v1/pilot/sessions/{sid}/export.xlsx")
86 assert export.status_code == 200
87 assert "spreadsheetml" in export.headers["content-type"]
88 book = load_workbook(BytesIO(export.content))
89 assert "BalanceSheet" in book.sheetnames
90 info = {row[0]: row[1] for row in book["Info"].iter_rows(min_row=2, values_only=True)}
91 assert info["status"] == "COMPLETE_APPROVED"
92 assert info["synthetic_data"].startswith("TRUE")
93 assert book["AuditTrail"].max_row == 6
94 book.close()
95
96 assert client.delete(f"/api/v1/pilot/sessions/{sid}").status_code == 200
97 assert client.get(f"/api/v1/pilot/sessions/{sid}").status_code == 404
98
99
100 def test_upload_valid_workbook_creates_session(pilot_client):
101 client = pilot_client
102 response = client.post(
103 "/api/v1/pilot/sessions",
104 files={"file": ("pilot.xlsx", build_balanced_workbook(),
105 "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")},
106 )
107 assert response.status_code == 200
108 body = response.json()
109 assert body["session"]["source"] == "upload"
110 assert body["report"]["status"]["label"] == "COMPLETE_APPROVED"
111 assert len(body["accounts"]) == 5
112
113
114 def test_upload_invalid_workbook_returns_exact_preflight_issues(pilot_client):
115 client = pilot_client
116 response = client.post(
117 "/api/v1/pilot/sessions", files={"file": ("bad.xlsx", b"not an xlsx")}
118 )
119 assert response.status_code == 422
120 detail = response.json()["detail"]
121 assert detail["issues"][0]["code"] == "INVALID_WORKBOOK"
122
123
124 def test_upload_rejects_wrong_extension_and_empty_file(pilot_client):
125 client = pilot_client
126 response = client.post(
127 "/api/v1/pilot/sessions", files={"file": ("data.csv", b"x,y\n1,2")}
128 )
129 assert response.status_code == 422
130 response = client.post(
131 "/api/v1/pilot/sessions", files={"file": ("empty.xlsx", b"")}
132 )
133 assert response.status_code == 422
134
135
136 def test_upload_size_limit_is_enforced(pilot_client, monkeypatch):
137 client = pilot_client
138 monkeypatch.setattr(pilot_api, "MAX_UPLOAD_BYTES", 8)
139 response = client.post(
140 "/api/v1/pilot/sessions", files={"file": ("big.xlsx", b"0123456789")}
141 )
142 assert response.status_code == 413
143
144
145 def test_mapping_validation_is_fail_closed(pilot_client):
146 client = pilot_client
147 sid = client.post("/api/v1/pilot/demo").json()["session"]["id"]
148 base = f"/api/v1/pilot/sessions/{sid}/mappings"
149 # Unknown account.
150 assert client.put(f"{base}/9999", json={
151 "statement": "BS", "section": "Assets", "note_number": "01",
152 }).status_code == 404
153 # Target that does not exist in Notes.
154 assert client.put(f"{base}/9001", json={
155 "statement": "BS", "section": "Assets", "note_number": "99",
156 }).status_code == 422
157 # Approved without reviewer evidence.
158 assert client.put(f"{base}/9001", json={
159 "statement": "BS", "section": "Assets", "note_number": "04",
160 "approval_status": "Approved",
161 }).status_code == 422
162 # Invalid lifecycle value.
163 assert client.put(f"{base}/9001", json={
164 "statement": "BS", "section": "Assets", "note_number": "04",
165 "approval_status": "Published",
166 }).status_code == 422
167
168
169 def test_clear_mapping_reopens_the_exception_queue(pilot_client):
170 client = pilot_client
171 sid = client.post("/api/v1/pilot/demo").json()["session"]["id"]
172 response = client.delete(f"/api/v1/pilot/sessions/{sid}/mappings/1001?actor=tester")
173 assert response.status_code == 200
174 body = response.json()
175 assert body["report"]["status"]["label"] == "INCOMPLETE"
176 assert "1001" in {e["account_code"] for e in body["report"]["exceptions"]}
177 assert body["audit_trail"][-1]["action"] == "clear_mapping"
178
179
180 def test_unknown_session_is_404_everywhere(pilot_client):
181 client = pilot_client
182 assert client.get("/api/v1/pilot/sessions/nope").status_code == 404
183 assert client.get("/api/v1/pilot/sessions/nope/export.xlsx").status_code == 404
184 assert client.delete("/api/v1/pilot/sessions/nope").status_code == 404
185 assert client.put("/api/v1/pilot/sessions/nope/mappings/10", json={
186 "statement": "BS", "section": "Assets", "note_number": "01",
187 }).status_code == 404
188
189
190 def test_health_stays_public_and_schema_needs_a_session(anon_client):
191 """R1: /health is the only unauthenticated read; the schema catalog is not."""
192 assert anon_client.get("/api/v1/health").json()["status"] == "ok"
193 assert anon_client.get("/api/v1/schema/entities").status_code == 401
194
195
196 def test_pilot_router_is_authenticated_wherever_mounted(pilot_client):
197 """The legacy router carries the same dependency, so it can never be anonymous."""
198 pilot_client.headers.pop("Authorization", None)
199 assert pilot_client.get("/api/v1/pilot/meta").status_code == 401
200 assert pilot_client.post("/api/v1/pilot/demo").status_code == 401