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

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

Synced Dec 3, 22:00 UTC

codex/aram-windows-statement-figures-20261031
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
py 174 lines 6.32 KB
Raw
1 """Synthetic CLI tests for direct cash flow manifests and local file safety."""
2 from __future__ import annotations
3
4 import json
5
6 import pytest
7
8 from aram_backend.cash_flow_direct_candidate_cli import (
9 MAX_CASH_MANIFEST_BYTES, main, parse_cash_manifest,
10 )
11 from aram_backend.coverage_preview import CoverageError
12 from test_cash_flow_direct_candidate import (
13 cash_accounts, counterpart_policies, transactions, workbook,
14 )
15
16
17 def cash_manifest():
18 return {
19 "schema_version": 1,
20 "company_code": "001",
21 "fiscal_year": 1404,
22 "currency": "IRR",
23 "unit": "Rial",
24 "cash_accounts": [
25 {"account_code": p.account_code, "evidence_ref": p.evidence_ref}
26 for p in cash_accounts()
27 ],
28 "counterpart_policies": [
29 {"account_code": p.account_code, "activity": p.activity,
30 "evidence_ref": p.evidence_ref}
31 for p in counterpart_policies()
32 ],
33 "transactions": [
34 {
35 "company_code": t.company_code, "fiscal_year": t.fiscal_year,
36 "line_id": t.line_id, "transaction_id": t.transaction_id,
37 "posting_date": t.posting_date,
38 "cash_account_code": t.cash_account_code,
39 "counterpart_account_code": t.counterpart_account_code,
40 "cash_debit": t.cash_debit, "cash_credit": t.cash_credit,
41 "counterpart_debit": t.counterpart_debit,
42 "counterpart_credit": t.counterpart_credit,
43 "evidence_ref": t.evidence_ref,
44 }
45 for t in transactions()
46 ],
47 }
48
49
50 def files(tmp_path, *, manifest=None, data=None):
51 data = workbook() if data is None else data
52 manifest = cash_manifest() if manifest is None else manifest
53 xlsx = tmp_path / "synthetic.xlsx"
54 json_file = tmp_path / "cash-manifest.json"
55 xlsx.write_bytes(data)
56 json_file.write_text(json.dumps(manifest), encoding="utf-8")
57 return xlsx, json_file, data
58
59
60 def command(paths):
61 return ["--file", str(paths[0]), "--manifest", str(paths[1])]
62
63
64 def test_cli_direct_cash_flow_json_and_source_are_unchanged(tmp_path, capsys):
65 paths = files(tmp_path)
66 original = paths[2]
67 assert main(command(paths)) == 0
68 output = capsys.readouterr()
69 result = json.loads(output.out)
70 assert result["operating_net_cash_flow"] == "10"
71 assert result["investing_net_cash_flow"] == "-10"
72 assert result["financing_net_cash_flow"] == "10"
73 assert result["net_change_in_cash"] == "10"
74 assert result["closing_cash_and_equivalents"] == "130"
75 assert result["eligible_for_analyst_review"]
76 assert not result["official_financial_statement"]
77 assert not result["releasable"]
78 assert output.err == ""
79 assert paths[0].read_bytes() == original
80 assert sorted(p.name for p in tmp_path.iterdir()) == [
81 "cash-manifest.json", "synthetic.xlsx"
82 ]
83
84
85 def test_cli_blocked_transaction_manifest_returns_three(tmp_path, capsys):
86 manifest = cash_manifest()
87 manifest["transactions"].pop()
88 paths = files(tmp_path, manifest=manifest)
89 assert main(command(paths)) == 3
90 result = json.loads(capsys.readouterr().out)
91 assert not result["eligible_for_analyst_review"]
92 assert "CASH_ACCOUNT_CREDIT_TURNOVER_MISMATCH" in result["findings"]
93
94
95 def test_cli_wrong_transaction_scope_returns_two_without_stdout(tmp_path, capsys):
96 manifest = cash_manifest()
97 manifest["transactions"][0]["company_code"] = "002"
98 paths = files(tmp_path, manifest=manifest)
99 assert main(command(paths)) == 2
100 output = capsys.readouterr()
101 assert output.out == ""
102 assert "CASH_FLOW_TRANSACTION_SCOPE_MISMATCH" in output.err
103
104
105 @pytest.mark.parametrize("raw", [
106 b"null", b"[]", b"{}", b"not-json", b"\xff",
107 b'{"schema_version":1,"schema_version":1}',
108 json.dumps({**cash_manifest(), "extra": True}).encode("utf-8"),
109 json.dumps({**cash_manifest(), "schema_version": True}).encode("utf-8"),
110 json.dumps({**cash_manifest(), "company_code": " 001"}).encode("utf-8"),
111 json.dumps({**cash_manifest(), "fiscal_year": True}).encode("utf-8"),
112 json.dumps({**cash_manifest(), "cash_accounts": "bad"}).encode("utf-8"),
113 json.dumps({**cash_manifest(), "cash_accounts": [{}]}).encode("utf-8"),
114 json.dumps({**cash_manifest(), "counterpart_policies": [{}]}).encode("utf-8"),
115 json.dumps({**cash_manifest(), "transactions": [{}]}).encode("utf-8"),
116 ])
117 def test_invalid_cash_manifest_schema_fails_closed(raw):
118 with pytest.raises(CoverageError):
119 parse_cash_manifest(raw)
120
121
122 def test_duplicate_nested_transaction_key_fails_closed():
123 raw = (
124 '{"schema_version":1,"company_code":"001","fiscal_year":1404,'
125 '"currency":"IRR","unit":"Rial","cash_accounts":[],"counterpart_policies":[],'
126 '"transactions":[{"line_id":"A","line_id":"B"}]}'
127 ).encode("utf-8")
128 with pytest.raises(CoverageError) as error:
129 parse_cash_manifest(raw)
130 assert error.value.code == "DUPLICATE_MANIFEST_KEY"
131
132
133 def test_manifest_transaction_limit_is_enforced():
134 manifest = cash_manifest()
135 manifest["transactions"] = manifest["transactions"] * 5001
136 with pytest.raises(CoverageError) as error:
137 parse_cash_manifest(json.dumps(manifest).encode("utf-8"))
138 assert error.value.code == "CASH_MANIFEST_TRANSACTIONS_INVALID"
139
140
141 def test_manifest_size_limit_is_enforced():
142 with pytest.raises(CoverageError) as error:
143 parse_cash_manifest(b" " * (MAX_CASH_MANIFEST_BYTES + 1))
144 assert error.value.code == "CASH_MANIFEST_SIZE_INVALID"
145
146
147 def test_symlink_manifest_rejected(tmp_path, capsys):
148 paths = files(tmp_path)
149 alias = tmp_path / "alias.json"
150 try:
151 alias.symlink_to(paths[1])
152 except (OSError, NotImplementedError):
153 pytest.skip("Symlinks unavailable")
154 args = command(paths)
155 args[-1] = str(alias)
156 assert main(args) == 2
157 assert capsys.readouterr().out == ""
158
159
160 def test_missing_manifest_or_workbook_rejected(tmp_path, capsys):
161 paths = files(tmp_path)
162 paths[1].unlink()
163 assert main(command(paths)) == 2
164 assert capsys.readouterr().out == ""
165 paths = files(tmp_path)
166 paths[0].unlink()
167 assert main(command(paths)) == 2
168 assert capsys.readouterr().out == ""
169
170
171 def test_invalid_workbook_rejected_before_json_success(tmp_path, capsys):
172 paths = files(tmp_path, data=b"broken")
173 assert main(command(paths)) == 2
174 assert capsys.readouterr().out == ""