Mirrored from https://github.com/davoodmehraban89/Aram.git
Synced Dec 3, 22:00 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
| 1 | """CLI tests use only ephemeral synthetic workbooks and control references.""" |
| 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.reconciliation_review_cli import ( |
| 10 | MAX_MANIFEST_BYTES, main, parse_manifest, safe_read_manifest, |
| 11 | ) |
| 12 | from test_reconciliation_review import workbook |
| 13 | |
| 14 | |
| 15 | def manifest(*, expected="126.00", company="001", year=1404): |
| 16 | return { |
| 17 | "schema_version": 1, "company_code": company, "fiscal_year": year, |
| 18 | "references": [{ |
| 19 | "statement": "BS", "section": "Assets", |
| 20 | "note_number": "N01", "subnote_code": "", |
| 21 | "expected_closing_exposure": expected, |
| 22 | "evidence_ref": "SYNTHETIC-REFERENCE-1", |
| 23 | }], |
| 24 | } |
| 25 | |
| 26 | |
| 27 | def run(tmp_path, capsys, *, expected="126.00", company="001", data=None): |
| 28 | xlsx = tmp_path / "synthetic.xlsx" |
| 29 | controls = tmp_path / "synthetic.json" |
| 30 | xlsx.write_bytes(workbook() if data is None else data) |
| 31 | controls.write_text(json.dumps(manifest(expected=expected, company=company)), |
| 32 | encoding="utf-8") |
| 33 | code = main(["--file", str(xlsx), "--references", str(controls)]) |
| 34 | captured = capsys.readouterr() |
| 35 | return code, captured, xlsx, controls |
| 36 | |
| 37 | |
| 38 | def test_cli_matched_is_still_unapproved(tmp_path, capsys): |
| 39 | source_bytes = workbook() |
| 40 | code, captured, xlsx, controls = run(tmp_path, capsys, data=source_bytes) |
| 41 | assert code == 0 |
| 42 | result = json.loads(captured.out) |
| 43 | assert result["matched_for_analyst_review"] |
| 44 | assert not result["approved"] |
| 45 | assert not result["releasable"] |
| 46 | assert len(result["reference_sha256"]) == 64 |
| 47 | assert captured.err == "" |
| 48 | assert xlsx.read_bytes() == source_bytes |
| 49 | assert json.loads(controls.read_text()) == manifest() |
| 50 | |
| 51 | |
| 52 | def test_cli_mismatch_returns_three_and_json_findings(tmp_path, capsys): |
| 53 | code, captured, _, _ = run(tmp_path, capsys, expected="127.00") |
| 54 | assert code == 3 |
| 55 | result = json.loads(captured.out) |
| 56 | assert not result["matched_for_analyst_review"] |
| 57 | assert any(f["code"] == "NOTE_EXPOSURE_MISMATCH" for f in result["findings"]) |
| 58 | |
| 59 | |
| 60 | def test_cli_wrong_scope_returns_two_without_leaking_workbook(tmp_path, capsys): |
| 61 | code, captured, _, _ = run(tmp_path, capsys, company="999") |
| 62 | assert code == 2 |
| 63 | assert captured.out == "" |
| 64 | assert "COMPANY_SCOPE_NOT_FOUND" in captured.err |
| 65 | |
| 66 | |
| 67 | def test_duplicate_json_keys_rejected(): |
| 68 | content = b'{"schema_version":1,"schema_version":1}' |
| 69 | with pytest.raises(CoverageError) as error: |
| 70 | parse_manifest(content) |
| 71 | assert error.value.code == "DUPLICATE_MANIFEST_KEY" |
| 72 | |
| 73 | |
| 74 | @pytest.mark.parametrize("content", [ |
| 75 | b"[]", b"null", b"{}", b"{not json", b"\xff", |
| 76 | json.dumps({**manifest(), "extra": 1}).encode("utf-8"), |
| 77 | json.dumps({**manifest(), "schema_version": True}).encode("utf-8"), |
| 78 | json.dumps({**manifest(), "fiscal_year": True}).encode("utf-8"), |
| 79 | json.dumps({**manifest(), "references": "not list"}).encode("utf-8"), |
| 80 | json.dumps({**manifest(), "references": [{"note_number": "N01"}]}).encode("utf-8"), |
| 81 | ]) |
| 82 | def test_invalid_manifest_blocks(content): |
| 83 | with pytest.raises(CoverageError): |
| 84 | parse_manifest(content) |
| 85 | |
| 86 | |
| 87 | def test_large_manifest_bytes_rejected(): |
| 88 | with pytest.raises(CoverageError) as error: |
| 89 | parse_manifest(b" " * (MAX_MANIFEST_BYTES + 1)) |
| 90 | assert error.value.code == "MANIFEST_SIZE_INVALID" |
| 91 | |
| 92 | |
| 93 | def test_cli_invalid_reference_type_blocks_safely(tmp_path, capsys): |
| 94 | xlsx = tmp_path / "synthetic.xlsx" |
| 95 | controls = tmp_path / "synthetic.json" |
| 96 | xlsx.write_bytes(workbook()) |
| 97 | payload = manifest() |
| 98 | payload["references"][0]["expected_closing_exposure"] = 126.0 |
| 99 | controls.write_text(json.dumps(payload), encoding="utf-8") |
| 100 | assert main(["--file", str(xlsx), "--references", str(controls)]) == 2 |
| 101 | assert capsys.readouterr().out == "" |
| 102 | |
| 103 | |
| 104 | def test_manifest_symlink_rejected(tmp_path): |
| 105 | target = tmp_path / "reference.json" |
| 106 | target.write_text(json.dumps(manifest()), encoding="utf-8") |
| 107 | alias = tmp_path / "alias.json" |
| 108 | try: |
| 109 | alias.symlink_to(target) |
| 110 | except (OSError, NotImplementedError): |
| 111 | pytest.skip("No symlinks on this filesystem") |
| 112 | with pytest.raises(CoverageError) as error: |
| 113 | safe_read_manifest(str(alias)) |
| 114 | assert error.value.code == "MANIFEST_NOT_REGULAR_FILE" |
| 115 | |
| 116 | |
| 117 | def test_manifest_directory_and_missing_path_are_rejected(tmp_path): |
| 118 | folder = tmp_path / "folder.json" |
| 119 | folder.mkdir() |
| 120 | with pytest.raises(CoverageError): |
| 121 | safe_read_manifest(str(folder)) |
| 122 | with pytest.raises(CoverageError): |
| 123 | safe_read_manifest(str(tmp_path / "missing.json")) |
| 124 | |
| 125 | |
| 126 | def test_manifest_size_checked_before_read(tmp_path): |
| 127 | source = tmp_path / "large.json" |
| 128 | with source.open("wb") as stream: |
| 129 | stream.truncate(MAX_MANIFEST_BYTES + 1) |
| 130 | with pytest.raises(CoverageError) as error: |
| 131 | safe_read_manifest(str(source)) |
| 132 | assert error.value.code == "MANIFEST_SIZE_INVALID" |
| 133 | |
| 134 | |
| 135 | def test_no_snapshot_written_or_input_edited_on_mismatch(tmp_path, capsys): |
| 136 | source_bytes = workbook() |
| 137 | code, _, xlsx, controls = run(tmp_path, capsys, expected="-100.00", data=source_bytes) |
| 138 | assert code == 3 |
| 139 | assert sorted(path.name for path in tmp_path.iterdir()) == [ |
| 140 | "synthetic.json", "synthetic.xlsx", |
| 141 | ] |
| 142 | assert xlsx.read_bytes() == source_bytes |
| 143 | assert json.loads(controls.read_text()) == manifest(expected="-100.00") |
| 144 | |
| 145 | |
| 146 | @pytest.mark.parametrize("company", [" 001", "001 ", "001" + chr(9), "x" * 65]) |
| 147 | def test_company_scope_is_never_silently_normalized(company): |
| 148 | payload = manifest(company=company) |
| 149 | with pytest.raises(CoverageError) as error: |
| 150 | parse_manifest(json.dumps(payload).encode("utf-8")) |
| 151 | assert error.value.code == "INVALID_MANIFEST_COMPANY" |