codex/gate3-carry-forward-preview-20261023
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 sqlalchemy import select |
| 3 | |
| 4 | from aram_backend.mapping_carry_forward import preview_mapping_carry_forward |
| 5 | from aram_backend.mapping_service import MappingValidationError |
| 6 | from aram_backend.models import ( |
| 7 | AccountVersion, Company, FiscalYear, FiscalYearStatus, MappingRule, NoteDefinition, |
| 8 | ) |
| 9 | |
| 10 | |
| 11 | def make_year(session, company, year, accounts=("001",), note_numbers=("1",)): |
| 12 | fiscal = FiscalYear(company=company, year=year) |
| 13 | session.add(fiscal) |
| 14 | session.flush() |
| 15 | for code in accounts: |
| 16 | session.add(AccountVersion(year_id=fiscal.id, account_code=code, account_name=code, version=1)) |
| 17 | notes = [] |
| 18 | for number in note_numbers: |
| 19 | note = NoteDefinition(year_id=fiscal.id, note_number=number, title=number, version=1) |
| 20 | session.add(note) |
| 21 | notes.append(note) |
| 22 | session.flush() |
| 23 | return fiscal, notes |
| 24 | |
| 25 | |
| 26 | def fixture_years(session, target_accounts=("001",), target_notes=("1",)): |
| 27 | company = Company(code="CF-A", name="Carry forward") |
| 28 | source, old_notes = make_year(session, company, 1403) |
| 29 | target, new_notes = make_year(session, company, 1404, target_accounts, target_notes) |
| 30 | session.add(MappingRule(year_id=source.id, rule_key="cash", account_code="001", |
| 31 | target_note_id=old_notes[0].id, mapping_type="direct", version=1)) |
| 32 | session.commit() |
| 33 | return source, target, old_notes, new_notes |
| 34 | |
| 35 | |
| 36 | def test_valid_preview_is_read_only(session): |
| 37 | source, target, _, notes = fixture_years(session) |
| 38 | before = session.scalars(select(MappingRule)).all() |
| 39 | result = preview_mapping_carry_forward(session, source_year_id=source.id, target_year_id=target.id) |
| 40 | assert len(result.candidates) == 1 |
| 41 | assert result.candidates[0].target_note_id == notes[0].id |
| 42 | assert result.candidates[0].source_note_number == "1" |
| 43 | assert result.skipped == () |
| 44 | assert session.scalars(select(MappingRule)).all() == before |
| 45 | |
| 46 | |
| 47 | @pytest.mark.parametrize("accounts,notes,reason", [ |
| 48 | ((), ("1",), "target_account_missing"), |
| 49 | (("001",), ("2",), "target_note_missing"), |
| 50 | ]) |
| 51 | def test_missing_reference_skipped(session, accounts, notes, reason): |
| 52 | source, target, _, _ = fixture_years(session, accounts, notes) |
| 53 | result = preview_mapping_carry_forward(session, source_year_id=source.id, target_year_id=target.id) |
| 54 | assert result.candidates == () |
| 55 | assert result.skipped == (("cash", reason),) |
| 56 | |
| 57 | |
| 58 | def test_existing_target_rule_is_not_overwritten(session): |
| 59 | source, target, _, notes = fixture_years(session) |
| 60 | session.add(MappingRule(year_id=target.id, rule_key="cash", account_code="001", |
| 61 | target_note_id=notes[0].id, mapping_type="manual", version=1)) |
| 62 | session.commit() |
| 63 | result = preview_mapping_carry_forward(session, source_year_id=source.id, target_year_id=target.id) |
| 64 | assert result.skipped == (("cash", "target_rule_exists"),) |
| 65 | |
| 66 | |
| 67 | def test_latest_source_rule_and_target_note_versions(session): |
| 68 | source, target, old_notes, new_notes = fixture_years(session) |
| 69 | session.add(NoteDefinition(year_id=target.id, note_number="1", title="Updated", version=2)) |
| 70 | session.add(MappingRule(year_id=source.id, rule_key="cash", account_code="001", |
| 71 | target_note_id=old_notes[0].id, mapping_type="manual", version=2)) |
| 72 | session.commit() |
| 73 | result = preview_mapping_carry_forward(session, source_year_id=source.id, target_year_id=target.id) |
| 74 | assert result.candidates[0].source_version == 2 |
| 75 | assert result.candidates[0].mapping_type == "manual" |
| 76 | assert result.candidates[0].target_note_id != new_notes[0].id |
| 77 | |
| 78 | |
| 79 | def test_protected_target_rejected(session): |
| 80 | source, target, _, _ = fixture_years(session) |
| 81 | target.status = FiscalYearStatus.APPROVED |
| 82 | session.commit() |
| 83 | with pytest.raises(MappingValidationError, match="Draft"): |
| 84 | preview_mapping_carry_forward(session, source_year_id=source.id, target_year_id=target.id) |
| 85 | |
| 86 | |
| 87 | def test_different_company_rejected(session): |
| 88 | source, target, _, _ = fixture_years(session) |
| 89 | other = Company(code="CF-B", name="Other") |
| 90 | other_year, _ = make_year(session, other, 1405) |
| 91 | session.commit() |
| 92 | with pytest.raises(MappingValidationError, match="same company"): |
| 93 | preview_mapping_carry_forward(session, source_year_id=source.id, target_year_id=other_year.id) |
| 94 | |
| 95 | |
| 96 | @pytest.mark.parametrize("source_id,target_id", [(0, 1), (True, 1), (1, False), ("1", 2), (1, 1), (99999, 100000)]) |
| 97 | def test_invalid_year_inputs_rejected(session, source_id, target_id): |
| 98 | with pytest.raises(MappingValidationError): |
| 99 | preview_mapping_carry_forward(session, source_year_id=source_id, target_year_id=target_id) |
| 100 | |
| 101 | |
| 102 | def test_reverse_year_order_rejected(session): |
| 103 | source, target, _, _ = fixture_years(session) |
| 104 | with pytest.raises(MappingValidationError, match="later"): |
| 105 | preview_mapping_carry_forward(session, source_year_id=target.id, target_year_id=source.id) |
| 106 | |
| 107 | |
| 108 | def test_preview_does_not_autoflush_unrelated_changes(session): |
| 109 | source, target, _, _ = fixture_years(session) |
| 110 | pending = AccountVersion(year_id=target.id, account_code="NEW", account_name="Pending", version=1) |
| 111 | session.add(pending) |
| 112 | preview_mapping_carry_forward(session, source_year_id=source.id, target_year_id=target.id) |
| 113 | assert pending in session.new |
| 114 | assert pending.id is None |