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

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

Synced Dec 3, 20:45 UTC

test(statements): exercise equity CLI scope, policy, symlink and input safety

davoodmehraban89 committed Oct 31, 2026 at 08:15 UTC 58f6b6c4dc2a5b45cc69996534654d8fb97171c6
1 file changed +158
backend/tests/test_equity_changes_candidate_cli.py new
+158
@@ -0,0 +1,158 @@
1 +"""Synthetic-only CLI tests for equity changes preview and safe input handling."""
2 +from __future__ import annotations
3 +
4 +import json
5 +
6 +import pytest
7 +
8 +from aram_backend.coverage_preview import CoverageError
9 +from aram_backend.equity_changes_candidate_cli import main, parse_equity_manifest
10 +from test_equity_changes_candidate import workbook, references, policies
11 +
12 +
13 +def reference_document():
14 + return {
15 + "schema_version": 1, "company_code": "001", "fiscal_year": 1404,
16 + "references": [
17 + {
18 + "statement": item.statement, "section": item.section,
19 + "note_number": item.note_number, "subnote_code": item.subnote_code,
20 + "expected_closing_exposure": item.expected_closing_exposure,
21 + "evidence_ref": item.evidence_ref,
22 + }
23 + for item in references()
24 + ],
25 + }
26 +
27 +
28 +def policy_document():
29 + return {
30 + "schema_version": 1, "company_code": "001", "fiscal_year": 1404,
31 + "policies": [
32 + {
33 + "statement_section": item.statement_section,
34 + "note_number": item.note_number, "subnote_code": item.subnote_code,
35 + "equity_component": item.equity_component,
36 + "movement_category": item.movement_category,
37 + "sign_multiplier": item.sign_multiplier,
38 + "line_label": item.line_label,
39 + "policy_evidence_ref": item.policy_evidence_ref,
40 + }
41 + for item in policies()
42 + ],
43 + }
44 +
45 +
46 +def files(tmp_path, *, ref=None, policy=None, data=None):
47 + data = workbook() if data is None else data
48 + ref = reference_document() if ref is None else ref
49 + policy = policy_document() if policy is None else policy
50 + xlsx = tmp_path / "synthetic.xlsx"
51 + references_path = tmp_path / "references.json"
52 + policies_path = tmp_path / "equity-policies.json"
53 + xlsx.write_bytes(data)
54 + references_path.write_text(json.dumps(ref), encoding="utf-8")
55 + policies_path.write_text(json.dumps(policy), encoding="utf-8")
56 + return xlsx, references_path, policies_path, data
57 +
58 +
59 +def command(paths):
60 + return [
61 + "--file", str(paths[0]), "--references", str(paths[1]),
62 + "--policies", str(paths[2]),
63 + ]
64 +
65 +
66 +def test_cli_prints_equity_rollforward_and_preserves_source(tmp_path, capsys):
67 + paths = files(tmp_path)
68 + original = paths[3]
69 + assert main(command(paths)) == 0
70 + captured = capsys.readouterr()
71 + result = json.loads(captured.out)
72 + assert result["opening_equity_total"] == "150"
73 + assert result["total_movement"] == "5"
74 + assert result["closing_equity_total"] == "155"
75 + assert result["eligible_for_analyst_review"]
76 + assert not result["official_financial_statement"]
77 + assert not result["releasable"]
78 + assert captured.err == ""
79 + assert paths[0].read_bytes() == original
80 + assert sorted(p.name for p in tmp_path.iterdir()) == [
81 + "equity-policies.json", "references.json", "synthetic.xlsx"
82 + ]
83 +
84 +
85 +def test_cli_missing_policy_returns_three_and_findings(tmp_path, capsys):
86 + policy = policy_document()
87 + policy["policies"].pop()
88 + paths = files(tmp_path, policy=policy)
89 + assert main(command(paths)) == 3
90 + result = json.loads(capsys.readouterr().out)
91 + assert "MISSING_EQUITY_POLICY" in result["findings"]
92 + assert not result["export_authorized"]
93 +
94 +
95 +def test_cli_wrong_company_scope_blocks_without_stdout(tmp_path, capsys):
96 + policy = policy_document()
97 + policy["company_code"] = "002"
98 + paths = files(tmp_path, policy=policy)
99 + assert main(command(paths)) == 2
100 + output = capsys.readouterr()
101 + assert output.out == ""
102 + assert "EQUITY_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({**policy_document(), "extra": 1}).encode("utf-8"),
109 + json.dumps({**policy_document(), "schema_version": True}).encode("utf-8"),
110 + json.dumps({**policy_document(), "company_code": " 001"}).encode("utf-8"),
111 + json.dumps({**policy_document(), "fiscal_year": True}).encode("utf-8"),
112 + json.dumps({**policy_document(), "policies": "bad"}).encode("utf-8"),
113 + json.dumps({**policy_document(), "policies": [{}]}).encode("utf-8"),
114 +])
115 +def test_invalid_policy_manifest_fails_closed(raw):
116 + with pytest.raises(CoverageError):
117 + parse_equity_manifest(raw)
118 +
119 +
120 +def test_json_boolean_sign_is_not_accepted(tmp_path, capsys):
121 + policy = policy_document()
122 + policy["policies"][0]["sign_multiplier"] = True
123 + paths = files(tmp_path, policy=policy)
124 + assert main(command(paths)) == 2
125 + assert capsys.readouterr().out == ""
126 +
127 +
128 +def test_symlinked_policy_file_is_rejected(tmp_path, capsys):
129 + paths = files(tmp_path)
130 + alias = tmp_path / "alias.json"
131 + try:
132 + alias.symlink_to(paths[2])
133 + except (OSError, NotImplementedError):
134 + pytest.skip("Symlinks unavailable")
135 + args = command(paths)
136 + args[-1] = str(alias)
137 + assert main(args) == 2
138 + assert capsys.readouterr().out == ""
139 +
140 +
141 +def test_missing_workbook_is_rejected(tmp_path, capsys):
142 + paths = files(tmp_path)
143 + paths[0].unlink()
144 + assert main(command(paths)) == 2
145 + assert capsys.readouterr().out == ""
146 +
147 +
148 +def test_bad_xlsx_is_rejected(tmp_path, capsys):
149 + paths = files(tmp_path, data=b"not xlsx")
150 + assert main(command(paths)) == 2
151 + assert capsys.readouterr().out == ""
152 +
153 +
154 +def test_manifest_size_limit_is_enforced():
155 + from aram_backend.reconciliation_review_cli import MAX_MANIFEST_BYTES
156 + with pytest.raises(CoverageError) as error:
157 + parse_equity_manifest(b" " * (MAX_MANIFEST_BYTES + 1))
158 + assert error.value.code == "EQUITY_MANIFEST_SIZE_INVALID"