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

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

Synced Dec 3, 19:30 UTC

codex/aram-account-note-source-trace-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 167 lines 5.89 KB
Raw
1 """Synthetic end-to-end tests of the non-official BS CLI."""
2 from __future__ import annotations
3
4 import json
5
6 import pytest
7
8 from aram_backend.balance_sheet_candidate_cli import (
9 main, parse_presentation_manifest,
10 )
11 from aram_backend.coverage_preview import CoverageError
12 from test_balance_sheet_candidate import workbook, policies, references
13
14
15 def reference_document():
16 return {
17 "schema_version": 1, "company_code": "001", "fiscal_year": 1404,
18 "references": [
19 {
20 "statement": r.statement, "section": r.section,
21 "note_number": r.note_number, "subnote_code": r.subnote_code,
22 "expected_closing_exposure": r.expected_closing_exposure,
23 "evidence_ref": r.evidence_ref,
24 }
25 for r in references()
26 ],
27 }
28
29
30 def policy_document():
31 return {
32 "schema_version": 1, "company_code": "001", "fiscal_year": 1404,
33 "policies": [
34 {
35 "statement_section": p.statement_section,
36 "note_number": p.note_number,
37 "subnote_code": p.subnote_code, "category": p.category,
38 "sign_multiplier": p.sign_multiplier, "line_label": p.line_label,
39 "policy_evidence_ref": p.policy_evidence_ref,
40 }
41 for p in policies()
42 ],
43 }
44
45
46 def files(tmp_path, *, reference=None, presentation=None, source=None):
47 source_bytes = workbook() if source is None else source
48 ref_doc = reference_document() if reference is None else reference
49 policy_doc = policy_document() if presentation is None else presentation
50 file = tmp_path / "sample.xlsx"
51 reference_file = tmp_path / "controls.json"
52 policy_file = tmp_path / "presentation.json"
53 file.write_bytes(source_bytes)
54 reference_file.write_text(json.dumps(ref_doc), encoding="utf-8")
55 policy_file.write_text(json.dumps(policy_doc), encoding="utf-8")
56 return file, reference_file, policy_file, source_bytes
57
58
59 def command(files):
60 file, refs, pol, _ = files
61 return [
62 "--file", str(file), "--references", str(refs),
63 "--policies", str(pol),
64 ]
65
66
67 def test_cli_presents_three_sections_but_no_official_document(tmp_path, capsys):
68 input_files = files(tmp_path)
69 initial = input_files[3]
70 assert main(command(input_files)) == 0
71 output = capsys.readouterr()
72 data = json.loads(output.out)
73 assert data["assets_total"] == "100"
74 assert data["liabilities_total"] == "60"
75 assert data["equity_total"] == "40"
76 assert data["eligible_for_analyst_review"]
77 assert not data["releasable"]
78 assert not data["official_financial_statement"]
79 assert output.err == ""
80 assert input_files[0].read_bytes() == initial
81 assert sorted(p.name for p in tmp_path.iterdir()) == [
82 "controls.json", "presentation.json", "sample.xlsx"
83 ]
84
85
86 def test_cli_unbalanced_returns_code_three_with_findings(tmp_path, capsys):
87 xlsx = workbook(liability="-59")
88 controls = reference_document()
89 controls["references"][1]["expected_closing_exposure"] = "-59"
90 inputs = files(tmp_path, source=xlsx, reference=controls)
91 assert main(command(inputs)) == 3
92 result = json.loads(capsys.readouterr().out)
93 assert result["balance_difference"] == "1"
94 assert "BALANCE_SHEET_DOES_NOT_BALANCE" in result["findings"]
95 assert not result["export_authorized"]
96
97
98 def test_cli_policy_scope_mismatch_fails_without_stdout(tmp_path, capsys):
99 doc = policy_document()
100 doc["fiscal_year"] = 1403
101 inputs = files(tmp_path, presentation=doc)
102 assert main(command(inputs)) == 2
103 output = capsys.readouterr()
104 assert not output.out.strip()
105 assert "PRESENTATION_SCOPE_MISMATCH" in output.err
106
107
108 @pytest.mark.parametrize("content", [
109 b"[]", b"{}", b"not json", b"null", b"\xff",
110 b'{"schema_version":1,"schema_version":1}',
111 json.dumps({**policy_document(), "extra": "oops"}).encode("utf-8"),
112 json.dumps({**policy_document(), "schema_version": True}).encode("utf-8"),
113 json.dumps({**policy_document(), "company_code": " 001"}).encode("utf-8"),
114 json.dumps({**policy_document(), "fiscal_year": True}).encode("utf-8"),
115 json.dumps({**policy_document(), "policies": "bad"}).encode("utf-8"),
116 json.dumps({**policy_document(), "policies": [{}]}).encode("utf-8"),
117 ])
118 def test_bad_policy_manifest_is_rejected(content):
119 with pytest.raises(CoverageError):
120 parse_presentation_manifest(content)
121
122
123 def test_presentation_sign_boolean_rejected_by_engine(tmp_path, capsys):
124 doc = policy_document()
125 doc["policies"][0]["sign_multiplier"] = True
126 inputs = files(tmp_path, presentation=doc)
127 assert main(command(inputs)) == 2
128 output = capsys.readouterr()
129 assert not output.out.strip()
130 assert "INVALID_PRESENTATION_SIGN" in output.err
131
132
133 def test_extra_policy_and_missing_policy_block_not_silently_ignored(tmp_path, capsys):
134 doc = policy_document()
135 doc["policies"].pop()
136 inputs = files(tmp_path, presentation=doc)
137 assert main(command(inputs)) == 3
138 result = json.loads(capsys.readouterr().out)
139 assert "MISSING_EXPLICIT_PRESENTATION_POLICY" in result["findings"]
140
141
142 def test_missing_xlsx_blocks_safely(tmp_path, capsys):
143 inputs = files(tmp_path)
144 inputs[0].unlink()
145 assert main(command(inputs)) == 2
146 assert capsys.readouterr().out == ""
147
148
149 def test_policy_symlink_is_rejected(tmp_path, capsys):
150 inputs = files(tmp_path)
151 link = tmp_path / "policy_link.json"
152 try:
153 link.symlink_to(inputs[2])
154 except (OSError, NotImplementedError):
155 pytest.skip("Symlink creation unsupported")
156 args = command(inputs)
157 args[-1] = str(link)
158 assert main(args) == 2
159 assert capsys.readouterr().out == ""
160
161
162 def test_reference_file_scope_mismatch_no_fallback(tmp_path, capsys):
163 controls = reference_document()
164 controls["company_code"] = "999"
165 inputs = files(tmp_path, reference=controls)
166 assert main(command(inputs)) == 2
167 assert capsys.readouterr().out == ""