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

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

Synced Dec 3, 15:45 UTC

codex/aram-five-statement-cli-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 158 lines 5.54 KB
Raw
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"