@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-integration-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 125 lines 4.47 KB
Raw
1 """Safety and integration tests for the read-only CLI; synthetic files only."""
2 from __future__ import annotations
3
4 import json
5 from io import BytesIO
6
7 import pytest
8 from openpyxl import Workbook
9
10 from aram_backend.coverage_preview import CoverageError, MAX_INPUT_BYTES
11 from aram_backend.coverage_preview_cli import main, safe_read_workbook
12 from aram_backend.pilot_workbook import SHEET_HEADERS
13
14
15 def synthetic_book() -> bytes:
16 book = Workbook()
17 book.remove(book.active)
18 for name, columns in SHEET_HEADERS.items():
19 book.create_sheet(name).append(list(columns))
20
21 def add(name, **values):
22 book[name].append([values.get(column) for column in SHEET_HEADERS[name]])
23
24 add("Company", company_code="001", company_name="Synthetic",
25 fiscal_year=1404, status="Draft")
26 add("Accounts", company_code="001", fiscal_year=1404,
27 general_code="01", general_name="Assets", account_full_code="01",
28 account_name="Cash", opening="100", debit="0", credit="0",
29 closing="100", source_row=2, row_status="Draft", closing_delta="0")
30 add("Notes", company_code="001", fiscal_year=1404, statement="BS",
31 statement_section="Assets", note_number="N1", note_title="Cash")
32 add("Mapping", mapping_id="M1", company_code="001", fiscal_year=1404,
33 account_full_code="01", account_level="General", general_code="01",
34 target_statement="BS", statement_section="Assets",
35 note_number="N1", mapping_version=1, approval_status="Approved",
36 reviewer="Synthetic reviewer", review_date="2026-10-31",
37 validation_status="Valid", source="Manual")
38 buffer = BytesIO()
39 book.save(buffer)
40 book.close()
41 return buffer.getvalue()
42
43
44 def test_safe_read_preserves_bytes(tmp_path):
45 data = synthetic_book()
46 file = tmp_path / "pilot.xlsx"
47 file.write_bytes(data)
48 assert safe_read_workbook(str(file)) == data
49 assert file.read_bytes() == data
50
51
52 def test_cli_outputs_explicitly_unapproved_json(tmp_path, capsys):
53 file = tmp_path / "pilot.xlsx"
54 file.write_bytes(synthetic_book())
55 assert main(["--file", str(file), "--company-code", "001",
56 "--fiscal-year", "1404"]) == 0
57 result = json.loads(capsys.readouterr().out)
58 assert result["candidate_mapped_accounts"] == 1
59 assert result["source_closing_exposure"] == "100"
60 assert result["releasable"] is False
61 assert result["trusted_approvals"] is False
62 assert result["financial_statement"] is False
63
64
65 @pytest.mark.parametrize("name,body", [
66 ("pilot.csv", b"content"),
67 ("bad.xlsx.exe", b"content"),
68 ("empty.xlsx", b""),
69 ])
70 def test_rejects_disallowed_or_empty_file(tmp_path, name, body):
71 file = tmp_path / name
72 file.write_bytes(body)
73 with pytest.raises(CoverageError):
74 safe_read_workbook(str(file))
75
76
77 def test_rejects_missing_path_and_directory(tmp_path):
78 with pytest.raises(CoverageError):
79 safe_read_workbook(str(tmp_path / "absent.xlsx"))
80 folder = tmp_path / "folder.xlsx"
81 folder.mkdir()
82 with pytest.raises(CoverageError):
83 safe_read_workbook(str(folder))
84
85
86 def test_rejects_file_beyond_limit_without_full_read(tmp_path):
87 file = tmp_path / "huge.xlsx"
88 with file.open("wb") as stream:
89 stream.truncate(MAX_INPUT_BYTES + 1)
90 with pytest.raises(CoverageError) as exc:
91 safe_read_workbook(str(file))
92 assert exc.value.code == "WORKBOOK_SIZE_INVALID"
93
94
95 def test_symlink_never_followed(tmp_path):
96 target = tmp_path / "good.xlsx"
97 target.write_bytes(synthetic_book())
98 link = tmp_path / "alias.xlsx"
99 try:
100 link.symlink_to(target)
101 except (NotImplementedError, OSError):
102 pytest.skip("Symlink creation unavailable")
103 with pytest.raises(CoverageError) as exc:
104 safe_read_workbook(str(link))
105 assert exc.value.code == "NOT_REGULAR_FILE"
106
107
108 def test_cli_invalid_workbook_has_no_stdout_success(tmp_path, capsys):
109 file = tmp_path / "invalid.xlsx"
110 file.write_bytes(b"not a workbook")
111 assert main(["--file", str(file), "--company-code", "001",
112 "--fiscal-year", "1404"]) == 2
113 result = capsys.readouterr()
114 assert not result.out.strip()
115 assert "blocked" in result.err
116
117
118 def test_wrong_company_never_falls_back(tmp_path, capsys):
119 file = tmp_path / "pilot.xlsx"
120 file.write_bytes(synthetic_book())
121 assert main(["--file", str(file), "--company-code", "002",
122 "--fiscal-year", "1404"]) == 2
123 captured = capsys.readouterr()
124 assert not captured.out.strip()
125 assert "COMPANY_SCOPE_NOT_FOUND" in captured.err