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

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

Synced Dec 3, 18:15 UTC

codex/windows-native-pilot-shell-20261030
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 187 lines 6.58 KB
Raw
1 """Desktop pilot safety and command tests; all source data is synthetic."""
2 from hashlib import sha256
3 from io import BytesIO
4
5 import pytest
6 from openpyxl import Workbook
7
8 from aram_backend.desktop_pilot_core import (
9 MAX_WORKBOOK_BYTES, DesktopPilotController, PilotInputError,
10 )
11
12
13 def workbook_bytes():
14 from aram_backend.pilot_workbook import SHEET_HEADERS
15 wb = Workbook()
16 wb.remove(wb.active)
17 for sheet_name, headers in SHEET_HEADERS.items():
18 wb.create_sheet(sheet_name).append(list(headers))
19 stream = BytesIO()
20 wb.save(stream)
21 return stream.getvalue()
22
23
24 def test_selection_uses_local_xlsx_only_and_does_not_write(tmp_path):
25 original = workbook_bytes()
26 selected = tmp_path / "pilot.xlsx"
27 selected.write_bytes(original)
28 before = sha256(selected.read_bytes()).hexdigest()
29 controller = DesktopPilotController()
30 controller.choose_file(selected)
31 assert controller.selected_path == selected
32 assert controller.result is None
33 result = controller.validate()
34 assert result is controller.result
35 assert isinstance(result.valid, bool)
36 assert sha256(selected.read_bytes()).hexdigest() == before
37 assert not any(path.name.endswith(".db") for path in tmp_path.iterdir())
38
39
40 def test_selection_does_not_validate_implicitly(tmp_path):
41 selected = tmp_path / "pilot.xlsx"
42 selected.write_bytes(b"not a workbook")
43 controller = DesktopPilotController()
44 controller.choose_file(selected)
45 assert controller.result is None
46 assert controller.state == "SELECTED"
47 result = controller.validate()
48 assert not result.valid
49 assert any(issue.code == "INVALID_WORKBOOK" for issue in result.issues)
50 assert controller.state == "INVALID"
51
52
53 @pytest.mark.parametrize("name", ["budget.csv", "mapping.xls", "scan.pdf", "backup.xlsx.exe", "not_file"])
54 def test_rejects_non_xlsx_paths_and_fails_closed(tmp_path, name):
55 controller = DesktopPilotController()
56 selected = tmp_path / name
57 selected.write_bytes(b"x")
58 with pytest.raises(PilotInputError):
59 controller.choose_file(selected)
60 assert controller.selected_path is None
61 assert controller.result is None
62 assert controller.state == "EMPTY"
63
64
65 def test_rejects_missing_or_directory_and_cannot_validate_without_selection(tmp_path):
66 controller = DesktopPilotController()
67 with pytest.raises(PilotInputError):
68 controller.validate()
69 with pytest.raises(PilotInputError):
70 controller.choose_file(tmp_path / "missing.xlsx")
71 directory = tmp_path / "folder.xlsx"
72 directory.mkdir()
73 with pytest.raises(PilotInputError):
74 controller.choose_file(directory)
75
76
77 def test_file_over_limit_rejected_without_reading_payload(tmp_path):
78 selected = tmp_path / "oversized.xlsx"
79 with selected.open("wb") as stream:
80 stream.truncate(MAX_WORKBOOK_BYTES + 1)
81 controller = DesktopPilotController()
82 with pytest.raises(PilotInputError):
83 controller.choose_file(selected)
84 assert controller.selected_path is None
85
86
87 def test_modified_file_becomes_invalid_and_never_uses_stale_result(tmp_path):
88 selected = tmp_path / "original.xlsx"
89 selected.write_bytes(workbook_bytes())
90 controller = DesktopPilotController()
91 controller.choose_file(selected)
92 controller.validate()
93 selected.write_bytes(b"broken")
94 changed = controller.validate()
95 assert not changed.valid
96 assert controller.result is changed
97 assert controller.state == "INVALID"
98
99
100 def test_removed_file_clears_prior_validation(tmp_path):
101 selected = tmp_path / "pilot.xlsx"
102 selected.write_bytes(workbook_bytes())
103 controller = DesktopPilotController()
104 controller.choose_file(selected)
105 controller.validate()
106 selected.unlink()
107 with pytest.raises(PilotInputError):
108 controller.validate()
109 assert controller.result is None
110 assert controller.state == "SELECTED"
111
112
113 def test_clearing_never_mutates_the_selected_workbook(tmp_path):
114 selected = tmp_path / "pilot.xlsx"
115 selected.write_bytes(workbook_bytes())
116 before = sha256(selected.read_bytes()).hexdigest()
117 controller = DesktopPilotController()
118 controller.choose_file(selected)
119 controller.validate()
120 controller.clear()
121 assert controller.selected_path is None
122 assert controller.result is None
123 assert controller.state == "EMPTY"
124 assert sha256(selected.read_bytes()).hexdigest() == before
125
126
127 def test_selecting_new_file_discards_previous_issue_list(tmp_path):
128 invalid = tmp_path / "invalid.xlsx"
129 invalid.write_bytes(b"bad")
130 valid_shape = tmp_path / "new.xlsx"
131 valid_shape.write_bytes(workbook_bytes())
132 controller = DesktopPilotController()
133 controller.choose_file(invalid)
134 controller.validate()
135 assert controller.result.issues
136 controller.choose_file(valid_shape)
137 assert controller.result is None
138 assert controller.state == "SELECTED"
139
140
141 def test_headless_self_diagnostic_uses_real_validator_without_financial_write():
142 from aram_backend.desktop_pilot import self_test
143 assert self_test() == 0
144
145
146 def test_all_enabled_controls_are_backed_by_implemented_callbacks():
147 from aram_backend.desktop_pilot import PILOT_ACTIONS, PilotWindow
148 assert set(PILOT_ACTIONS) == {
149 "file.open", "file.validate", "file.clear",
150 "file.exit", "help.about",
151 }
152 for action, method_name in PILOT_ACTIONS.items():
153 assert callable(getattr(PilotWindow, method_name)), action
154
155
156 def test_bounded_zip_metadata_rejects_expansion_and_many_entries():
157 from types import SimpleNamespace
158 from aram_backend.desktop_pilot_core import (
159 MAX_ZIP_ENTRIES, MAX_UNCOMPRESSED_BYTES, _check_archive_limits,
160 )
161 with pytest.raises(PilotInputError):
162 _check_archive_limits([
163 SimpleNamespace(file_size=MAX_UNCOMPRESSED_BYTES + 1),
164 ])
165 with pytest.raises(PilotInputError):
166 _check_archive_limits([
167 SimpleNamespace(file_size=1) for _ in range(MAX_ZIP_ENTRIES + 1)
168 ])
169 with pytest.raises(PilotInputError):
170 _check_archive_limits([
171 SimpleNamespace(file_size=MAX_UNCOMPRESSED_BYTES // 2 + 1),
172 SimpleNamespace(file_size=MAX_UNCOMPRESSED_BYTES // 2 + 1),
173 ])
174
175
176 def test_symlink_cannot_be_selected_for_financial_preflight(tmp_path):
177 target = tmp_path / "trusted.xlsx"
178 target.write_bytes(workbook_bytes())
179 link = tmp_path / "untrusted.xlsx"
180 try:
181 link.symlink_to(target)
182 except (NotImplementedError, OSError):
183 pytest.skip("Symlinks are not available on this test filesystem")
184 controller = DesktopPilotController()
185 with pytest.raises(PilotInputError):
186 controller.choose_file(link)
187 assert controller.state == "EMPTY"