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
| 1 | """End-to-end synthetic CLI tests for unapproved IS preview and invalid inputs.""" |
| 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.income_statement_candidate_cli import main, parse_income_manifest |
| 10 | from test_income_statement_candidate import workbook, references, policies |
| 11 | |
| 12 | |
| 13 | def references_doc(): |
| 14 | return { |
| 15 | "schema_version": 1, "company_code": "001", "fiscal_year": 1404, |
| 16 | "references": [ |
| 17 | { |
| 18 | "statement": r.statement, "section": r.section, |
| 19 | "note_number": r.note_number, "subnote_code": r.subnote_code, |
| 20 | "expected_closing_exposure": r.expected_closing_exposure, |
| 21 | "evidence_ref": r.evidence_ref, |
| 22 | } |
| 23 | for r in references() |
| 24 | ], |
| 25 | } |
| 26 | |
| 27 | |
| 28 | def policies_doc(): |
| 29 | return { |
| 30 | "schema_version": 1, "company_code": "001", "fiscal_year": 1404, |
| 31 | "policies": [ |
| 32 | { |
| 33 | "statement_section": p.statement_section, |
| 34 | "note_number": p.note_number, "subnote_code": p.subnote_code, |
| 35 | "category": p.category, "sign_multiplier": p.sign_multiplier, |
| 36 | "line_label": p.line_label, "policy_evidence_ref": p.policy_evidence_ref, |
| 37 | } |
| 38 | for p in policies() |
| 39 | ], |
| 40 | } |
| 41 | |
| 42 | |
| 43 | def fixtures(tmp_path, *, refs=None, pols=None, data=None): |
| 44 | data = workbook() if data is None else data |
| 45 | ref = references_doc() if refs is None else refs |
| 46 | pol = policies_doc() if pols is None else pols |
| 47 | excel = tmp_path / "synthetic.xlsx" |
| 48 | control = tmp_path / "control.json" |
| 49 | policy = tmp_path / "policy.json" |
| 50 | excel.write_bytes(data) |
| 51 | control.write_text(json.dumps(ref), encoding="utf-8") |
| 52 | policy.write_text(json.dumps(pol), encoding="utf-8") |
| 53 | return excel, control, policy, data |
| 54 | |
| 55 | |
| 56 | def argv(paths): |
| 57 | return [ |
| 58 | "--file", str(paths[0]), "--references", str(paths[1]), |
| 59 | "--policies", str(paths[2]), |
| 60 | ] |
| 61 | |
| 62 | |
| 63 | def test_cli_profit_is_unapproved_and_does_not_mutate_inputs(tmp_path, capsys): |
| 64 | original = workbook() |
| 65 | paths = fixtures(tmp_path, data=original) |
| 66 | assert main(argv(paths)) == 0 |
| 67 | output = capsys.readouterr() |
| 68 | result = json.loads(output.out) |
| 69 | assert result["net_result"] == "45" |
| 70 | assert result["eligible_for_analyst_review"] |
| 71 | assert not result["official_financial_statement"] |
| 72 | assert not result["releasable"] |
| 73 | assert output.err == "" |
| 74 | assert paths[0].read_bytes() == original |
| 75 | assert sorted(item.name for item in tmp_path.iterdir()) == [ |
| 76 | "control.json", "policy.json", "synthetic.xlsx", |
| 77 | ] |
| 78 | |
| 79 | |
| 80 | def test_cli_loss_is_not_a_failure(tmp_path, capsys): |
| 81 | data = workbook(costs="290") |
| 82 | doc = references_doc() |
| 83 | next(r for r in doc["references"] if r["note_number"] == "C01")[ |
| 84 | "expected_closing_exposure" |
| 85 | ] = "290" |
| 86 | paths = fixtures(tmp_path, refs=doc, data=data) |
| 87 | assert main(argv(paths)) == 0 |
| 88 | assert json.loads(capsys.readouterr().out)["net_result"] == "-135" |
| 89 | |
| 90 | |
| 91 | def test_cli_missing_policy_blocks_and_reports_findings(tmp_path, capsys): |
| 92 | doc = policies_doc() |
| 93 | doc["policies"].pop() |
| 94 | paths = fixtures(tmp_path, pols=doc) |
| 95 | assert main(argv(paths)) == 3 |
| 96 | output = json.loads(capsys.readouterr().out) |
| 97 | assert "MISSING_INCOME_POLICY" in output["findings"] |
| 98 | assert not output["export_authorized"] |
| 99 | |
| 100 | |
| 101 | def test_cli_company_mismatch_blocks_without_json_data(tmp_path, capsys): |
| 102 | doc = policies_doc() |
| 103 | doc["company_code"] = "002" |
| 104 | paths = fixtures(tmp_path, pols=doc) |
| 105 | assert main(argv(paths)) == 2 |
| 106 | output = capsys.readouterr() |
| 107 | assert not output.out.strip() |
| 108 | assert "INCOME_SCOPE_MISMATCH" in output.err |
| 109 | |
| 110 | |
| 111 | @pytest.mark.parametrize("raw", [ |
| 112 | b"null", b"[]", b"{}", b"not-json", b"\xff", |
| 113 | b'{"schema_version":1,"schema_version":1}', |
| 114 | json.dumps({**policies_doc(), "unexpected": "value"}).encode("utf-8"), |
| 115 | json.dumps({**policies_doc(), "schema_version": True}).encode("utf-8"), |
| 116 | json.dumps({**policies_doc(), "company_code": " 001"}).encode("utf-8"), |
| 117 | json.dumps({**policies_doc(), "fiscal_year": True}).encode("utf-8"), |
| 118 | json.dumps({**policies_doc(), "policies": "not-list"}).encode("utf-8"), |
| 119 | json.dumps({**policies_doc(), "policies": [{"category": "REVENUE"}]}).encode("utf-8"), |
| 120 | ]) |
| 121 | def test_invalid_json_manifest_blocked(raw): |
| 122 | with pytest.raises(CoverageError): |
| 123 | parse_income_manifest(raw) |
| 124 | |
| 125 | |
| 126 | def test_boolean_sign_cannot_pass_through_json(tmp_path, capsys): |
| 127 | doc = policies_doc() |
| 128 | doc["policies"][0]["sign_multiplier"] = True |
| 129 | paths = fixtures(tmp_path, pols=doc) |
| 130 | assert main(argv(paths)) == 2 |
| 131 | assert capsys.readouterr().out == "" |
| 132 | |
| 133 | |
| 134 | def test_symlink_to_policy_file_is_rejected(tmp_path, capsys): |
| 135 | paths = fixtures(tmp_path) |
| 136 | link = tmp_path / "alias.json" |
| 137 | try: |
| 138 | link.symlink_to(paths[2]) |
| 139 | except (OSError, NotImplementedError): |
| 140 | pytest.skip("Symlinks unavailable") |
| 141 | params = argv(paths) |
| 142 | params[-1] = str(link) |
| 143 | assert main(params) == 2 |
| 144 | assert capsys.readouterr().out == "" |
| 145 | |
| 146 | |
| 147 | def test_invalid_excel_rejected_before_processing(tmp_path, capsys): |
| 148 | paths = fixtures(tmp_path, data=b"broken") |
| 149 | assert main(argv(paths)) == 2 |
| 150 | assert capsys.readouterr().out == "" |
| 151 | |
| 152 | |
| 153 | def test_missing_reference_file_is_rejected(tmp_path, capsys): |
| 154 | paths = fixtures(tmp_path) |
| 155 | paths[1].unlink() |
| 156 | assert main(argv(paths)) == 2 |
| 157 | assert capsys.readouterr().out == "" |
| 158 | |
| 159 | |
| 160 | def test_manifest_size_limit_applies_before_json_parsing(): |
| 161 | from aram_backend.reconciliation_review_cli import MAX_MANIFEST_BYTES |
| 162 | with pytest.raises(CoverageError) as exc: |
| 163 | parse_income_manifest(b" " * (MAX_MANIFEST_BYTES + 1)) |
| 164 | assert exc.value.code == "INCOME_MANIFEST_SIZE_INVALID" |