jules-gate-2b-mapping-workflow-foundation-4137724387867065330
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 | import pytest |
| 2 | from aram_backend.models import ( |
| 3 | MappingStatus, MappingRule, NoteDefinition, Company, FiscalYear, AccountVersion, FiscalYearStatus |
| 4 | ) |
| 5 | from aram_backend.mapping import create_mapping_rule, MappingValidationError |
| 6 | |
| 7 | def make_year(session, year=1404): |
| 8 | company = Company(code=f"CO-{year}", name="Test Company") |
| 9 | fiscal_year = FiscalYear(company=company, year=year) |
| 10 | session.add(company) |
| 11 | session.commit() |
| 12 | return fiscal_year |
| 13 | |
| 14 | def setup_basic_mapping_data(session): |
| 15 | year = make_year(session) |
| 16 | note = NoteDefinition(year_id=year.id, note_number="10", title="Assets", version=1) |
| 17 | account = AccountVersion(year_id=year.id, account_code="1000", account_name="Cash", version=1) |
| 18 | session.add_all([note, account]) |
| 19 | session.commit() |
| 20 | return year, note, account |
| 21 | |
| 22 | def test_create_mapping_rule_valid(session): |
| 23 | year, note, account = setup_basic_mapping_data(session) |
| 24 | |
| 25 | mapping = create_mapping_rule( |
| 26 | session, |
| 27 | year_id=year.id, |
| 28 | rule_key="rule-1", |
| 29 | account_code="1000", |
| 30 | target_note_id=note.id, |
| 31 | mapping_type="O" |
| 32 | ) |
| 33 | |
| 34 | assert mapping.id is not None |
| 35 | assert mapping.rule_key == "rule-1" |
| 36 | assert mapping.account_code == "1000" |
| 37 | assert mapping.status == MappingStatus.DRAFT |
| 38 | |
| 39 | def test_create_mapping_rule_invalid_year(session): |
| 40 | year, note, account = setup_basic_mapping_data(session) |
| 41 | |
| 42 | with pytest.raises(MappingValidationError, match="Fiscal year 9999 does not exist"): |
| 43 | create_mapping_rule( |
| 44 | session, |
| 45 | year_id=9999, |
| 46 | rule_key="rule-1", |
| 47 | account_code="1000", |
| 48 | target_note_id=note.id, |
| 49 | mapping_type="O" |
| 50 | ) |
| 51 | |
| 52 | def test_create_mapping_rule_invalid_account(session): |
| 53 | year, note, account = setup_basic_mapping_data(session) |
| 54 | |
| 55 | with pytest.raises(MappingValidationError, match="Account 9999 does not exist"): |
| 56 | create_mapping_rule( |
| 57 | session, |
| 58 | year_id=year.id, |
| 59 | rule_key="rule-1", |
| 60 | account_code="9999", |
| 61 | target_note_id=note.id, |
| 62 | mapping_type="O" |
| 63 | ) |
| 64 | |
| 65 | def test_create_mapping_rule_invalid_note(session): |
| 66 | year, note, account = setup_basic_mapping_data(session) |
| 67 | |
| 68 | with pytest.raises(MappingValidationError, match="Target note 9999 is invalid"): |
| 69 | create_mapping_rule( |
| 70 | session, |
| 71 | year_id=year.id, |
| 72 | rule_key="rule-1", |
| 73 | account_code="1000", |
| 74 | target_note_id=9999, |
| 75 | mapping_type="O" |
| 76 | ) |
| 77 | |
| 78 | def test_create_mapping_rule_duplicate(session): |
| 79 | year, note, account = setup_basic_mapping_data(session) |
| 80 | |
| 81 | create_mapping_rule( |
| 82 | session, |
| 83 | year_id=year.id, |
| 84 | rule_key="rule-1", |
| 85 | account_code="1000", |
| 86 | target_note_id=note.id, |
| 87 | mapping_type="O" |
| 88 | ) |
| 89 | |
| 90 | with pytest.raises(MappingValidationError, match="Mapping rule rule-1 version 1 already exists"): |
| 91 | create_mapping_rule( |
| 92 | session, |
| 93 | year_id=year.id, |
| 94 | rule_key="rule-1", |
| 95 | account_code="1000", |
| 96 | target_note_id=note.id, |
| 97 | mapping_type="O" |
| 98 | ) |
| 99 | |
| 100 | def test_create_mapping_rule_locked_year(session): |
| 101 | year, note, account = setup_basic_mapping_data(session) |
| 102 | |
| 103 | year.status = FiscalYearStatus.APPROVED |
| 104 | session.commit() |
| 105 | |
| 106 | with pytest.raises(MappingValidationError, match="is approved and cannot accept mapping changes"): |
| 107 | create_mapping_rule( |
| 108 | session, |
| 109 | year_id=year.id, |
| 110 | rule_key="rule-1", |
| 111 | account_code="1000", |
| 112 | target_note_id=note.id, |
| 113 | mapping_type="O" |
| 114 | ) |