Mirrored from https://github.com/davoodmehraban89/Aram.git
Synced Dec 4, 09:15 UTC
codex/aram-analyst-review-workbook-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 | """Safety and content tests for the nonofficial local analyst workbook.""" |
| 2 | from dataclasses import replace |
| 3 | |
| 4 | import pytest |
| 5 | from openpyxl import load_workbook |
| 6 | |
| 7 | from aram_backend.analyst_review_workbook import ( |
| 8 | DISCLAIMER, build_review_workbook_bytes, write_review_workbook, |
| 9 | ) |
| 10 | from aram_backend.coverage_preview import CoverageError |
| 11 | from aram_backend.synthetic_five_statement_demo import cash_transactions |
| 12 | from test_five_statement_pipeline_integration import build_pipeline |
| 13 | |
| 14 | |
| 15 | def test_review_pack_contains_exact_strings_all_statements_and_disclaimers(tmp_path): |
| 16 | result = build_pipeline() |
| 17 | path = write_review_workbook(tmp_path / "review-only.xlsx", result) |
| 18 | assert path.is_file() |
| 19 | workbook = load_workbook(path, read_only=True, data_only=False) |
| 20 | try: |
| 21 | assert workbook.sheetnames == [ |
| 22 | "اطلاعات", "خلاصه مبالغ", "ترازنامه", "سود و زیان", |
| 23 | "حقوق مالکانه", "جریان نقد", "تراز آزمایشی", "کنترلها", |
| 24 | ] |
| 25 | for sheet in workbook.worksheets: |
| 26 | assert DISCLAIMER in sheet["A1"].value |
| 27 | summary = list(workbook["خلاصه مبالغ"].iter_rows(values_only=True)) |
| 28 | assert ("سود و زیان", "سود خالص", "20", "پیشنویس قابل بررسی؛ غیررسمی") in summary |
| 29 | balance = list(workbook["ترازنامه"].iter_rows(values_only=True)) |
| 30 | assert any(row[1] == "Cash and cash equivalents" and row[8] == "50" for row in balance) |
| 31 | trial = list(workbook["تراز آزمایشی"].iter_rows(values_only=True)) |
| 32 | assert len(trial) == len(result.trial_balance.accounts) + 4 |
| 33 | assert all( |
| 34 | cell.data_type != "f" |
| 35 | for sheet in workbook.worksheets |
| 36 | for row in sheet.iter_rows() |
| 37 | for cell in row |
| 38 | ) |
| 39 | finally: |
| 40 | workbook.close() |
| 41 | |
| 42 | |
| 43 | def test_review_pack_never_overwrites_existing_files(tmp_path): |
| 44 | target = tmp_path / "existing.xlsx" |
| 45 | target.write_bytes(b"do not overwrite") |
| 46 | with pytest.raises(CoverageError, match="TARGET_EXISTS"): |
| 47 | write_review_workbook(target, build_pipeline()) |
| 48 | assert target.read_bytes() == b"do not overwrite" |
| 49 | |
| 50 | |
| 51 | def test_review_pack_refuses_wrong_extension_and_missing_parent(tmp_path): |
| 52 | result = build_pipeline() |
| 53 | with pytest.raises(CoverageError, match="EXTENSION"): |
| 54 | write_review_workbook(tmp_path / "review.xls", result) |
| 55 | with pytest.raises(CoverageError, match="PARENT"): |
| 56 | write_review_workbook(tmp_path / "missing" / "review.xlsx", result) |
| 57 | |
| 58 | |
| 59 | def test_formula_like_user_text_is_written_as_a_literal_string(tmp_path): |
| 60 | result = build_pipeline() |
| 61 | line = replace( |
| 62 | result.balance_sheet.lines[0], |
| 63 | line_label='=HYPERLINK("https://example.invalid","open")', |
| 64 | ) |
| 65 | changed = replace( |
| 66 | result, balance_sheet=replace( |
| 67 | result.balance_sheet, lines=(line,) + result.balance_sheet.lines[1:], |
| 68 | ), |
| 69 | ) |
| 70 | path = write_review_workbook(tmp_path / "literal.xlsx", changed) |
| 71 | workbook = load_workbook(path, read_only=True, data_only=False) |
| 72 | try: |
| 73 | rows = list(workbook["ترازنامه"].iter_rows()) |
| 74 | matching = [ |
| 75 | cell for row in rows for cell in row |
| 76 | if cell.value == '=HYPERLINK("https://example.invalid","open")' |
| 77 | ] |
| 78 | assert len(matching) == 1 |
| 79 | assert matching[0].data_type == "s" |
| 80 | assert all( |
| 81 | cell.data_type != "f" |
| 82 | for sheet in workbook.worksheets |
| 83 | for row in sheet.iter_rows() |
| 84 | for cell in row |
| 85 | ) |
| 86 | finally: |
| 87 | workbook.close() |
| 88 | |
| 89 | |
| 90 | def test_blocked_pipeline_pack_is_explicitly_diagnostic(tmp_path): |
| 91 | result = build_pipeline(transactions=cash_transactions()[:-1]) |
| 92 | assert not result.eligible_for_analyst_review |
| 93 | content = build_review_workbook_bytes(result) |
| 94 | assert content.startswith(b"PK") |
| 95 | path = write_review_workbook(tmp_path / "blocked.xlsx", result) |
| 96 | workbook = load_workbook(path, read_only=True, data_only=True) |
| 97 | try: |
| 98 | summary = list(workbook["خلاصه مبالغ"].iter_rows(values_only=True)) |
| 99 | assert any("مسدود" in str(row[3]) for row in summary[4:]) |
| 100 | info = list(workbook["اطلاعات"].iter_rows(values_only=True)) |
| 101 | assert any(row[0] == "وضعیت کلی" and "مسدود" in row[1] for row in info) |
| 102 | finally: |
| 103 | workbook.close() |
| 104 | |
| 105 | |
| 106 | def test_review_pack_rejects_bidi_and_control_text(): |
| 107 | result = build_pipeline() |
| 108 | line = replace(result.income_statement.lines[0], line_label="Revenue\u202eforged") |
| 109 | changed = replace( |
| 110 | result, income_statement=replace( |
| 111 | result.income_statement, lines=(line,) + result.income_statement.lines[1:], |
| 112 | ), |
| 113 | ) |
| 114 | with pytest.raises(CoverageError): |
| 115 | build_review_workbook_bytes(changed) |
| 116 | |
| 117 | |
| 118 | def test_review_pack_refuses_symlink_targets(tmp_path): |
| 119 | target = tmp_path / "real.xlsx" |
| 120 | link = tmp_path / "alias.xlsx" |
| 121 | try: |
| 122 | link.symlink_to(target) |
| 123 | except (OSError, NotImplementedError): |
| 124 | pytest.skip("Symlinks unavailable") |
| 125 | with pytest.raises(CoverageError, match="TARGET_EXISTS"): |
| 126 | write_review_workbook(link, build_pipeline()) |