@davoodmehraban89 / Aram-2 Mirror · read-only / commits / 7bffb2f
Fork 0

Mirrored from https://github.com/davoodmehraban89/Aram.git

Synced Dec 3, 22:00 UTC

fix(control): fail closed on malformed nested statement category and account collections

davoodmehraban89 committed Oct 31, 2026 at 11:33 UTC 7bffb2f0c1081ad232357aadc9ef8710e42c9233
1 file changed +18 -8
backend/src/aram_backend/cross_statement_reconciliation.py
+18 -8
@@ -174,7 +174,8 @@ def _balance_sheet_detail_bridge(balance: BalanceSheetCandidate) -> bool:
174 _text(line.note_number, "BS_DETAIL_NOTE"),
175 _text(line.subnote_code, "BS_DETAIL_SUBNOTE", blank_ok=True),
176 )
177 - if key in seen or line.category not in BALANCE_SHEET_CATEGORIES:
177 + if (key in seen or not isinstance(line.category, str)
178 + or line.category not in BALANCE_SHEET_CATEGORIES):
179 return False
180 seen.add(key)
181 if type(line.sign_multiplier) is not int or line.sign_multiplier not in (-1, 1):
@@ -215,7 +216,8 @@ def _income_detail_bridge(income: IncomeStatementCandidate) -> bool:
216 _text(line.note_number, "IS_DETAIL_NOTE"),
217 _text(line.subnote_code, "IS_DETAIL_SUBNOTE", blank_ok=True),
218 )
218 - if key in seen or line.category not in INCOME_STATEMENT_CATEGORIES:
219 + if (key in seen or not isinstance(line.category, str)
220 + or line.category not in INCOME_STATEMENT_CATEGORIES):
221 return False
222 seen.add(key)
223 if type(line.sign_multiplier) is not int or line.sign_multiplier not in (-1, 1):
@@ -286,7 +288,9 @@ def _equity_detail_bridge(
288 _text(account.note_number, "EQ_DETAIL_NOTE"),
289 _text(account.subnote_code, "EQ_DETAIL_SUBNOTE", blank_ok=True),
290 )
289 - if (account.equity_component not in EQUITY_COMPONENTS
291 + if (not isinstance(account.equity_component, str)
292 + or account.equity_component not in EQUITY_COMPONENTS
293 + or not isinstance(account.movement_category, str)
294 or account.movement_category not in MOVEMENT_CATEGORIES
295 or type(account.sign_multiplier) is not int
296 or account.sign_multiplier not in (-1, 1)
@@ -335,7 +339,9 @@ def _equity_detail_bridge(
339 )
340 if key in note_by_key or key not in accounts_by_note:
341 return False
338 - if (note.equity_component not in EQUITY_COMPONENTS
342 + if (not isinstance(note.equity_component, str)
343 + or note.equity_component not in EQUITY_COMPONENTS
344 + or not isinstance(note.movement_category, str)
345 or note.movement_category not in MOVEMENT_CATEGORIES):
346 return False
347 _text(note.line_label, "EQ_DETAIL_LABEL")
@@ -382,7 +388,9 @@ def _equity_detail_bridge(
388 for item in equity.component_totals:
389 if not isinstance(item, EquityComponentTotal):
390 return False
385 - if item.equity_component not in EQUITY_COMPONENTS or item.equity_component in component_by_key:
391 + if (not isinstance(item.equity_component, str)
392 + or item.equity_component not in EQUITY_COMPONENTS
393 + or item.equity_component in component_by_key):
394 return False
395 component_by_key[item.equity_component] = item
396 if set(component_by_key) != set(component_values):
@@ -572,13 +580,15 @@ def _cash_accounts_match_trial_balance(
580 ) -> tuple[bool, bool]:
581 findings_valid = True
582 totals_valid = True
583 + if (not isinstance(trial.accounts, tuple)
584 + or not isinstance(cash.account_reconciliations, tuple)
585 + or not isinstance(cash.cash_flow_lines, tuple)):
586 + return False, False
587 if (type(trial.account_count) is not int
588 or trial.account_count != len(trial.accounts)
589 or type(cash.cash_account_count) is not int
578 - or not isinstance(cash.account_reconciliations, tuple)
590 or cash.cash_account_count != len(cash.account_reconciliations)
580 - or cash.cash_account_count < 1
581 - or not isinstance(cash.cash_flow_lines, tuple)):
591 + or cash.cash_account_count < 1):
592 findings_valid = False
593
594 trial_by_code: dict[str, TrialBalanceAccount] = {}