--- id: fixbug-ledger title: Find and fix six seeded bugs in a double-entry ledger library kind: bugfix expected_rounds: 15-40 --- # Find and fix six seeded bugs in a double-entry ledger library Package `ledger/` (13 modules, about 1160 lines) plus 133 visible unittest tests in `tests/` (13 files incl. `helpers.py`). On the seed 13 visible tests fail; the hidden suite (34 extra cases, `hidden/test_hidden.py`) covers each bug class more broadly. Context grows mainly by reading modules and test output. Seeded bugs (one distinct root cause each; reference fix = `reference/overlay/`, restores the original line): | module | function | bug | visible failures | | --- | --- | --- | --- | | money.py | `Money.allocate` | remainder computed from the signed minor amount, so negative amounts lose cents (also breaks `split`, `Transaction.from_split` for refunds) | 2 | | rounding.py | `round_half_even` | goes through `float`, ties and long values round wrongly (shows in `Money.__mul__`, `RateTable.convert`) | 3 | | accounts.py | `Account.__init__` | mutable default argument `labels=[]` shared by all accounts, no copy of the argument | 2 | | calendar.py | `add_business_days` | rolls a weekend/holiday start to the next business day first, so the result is one business day too late | 2 | | reports.py | `monthly_totals` | groups by month number only, so January 2023 and January 2024 merge (also visible through `cli monthly`) | 2 | | importer.py | `_normalise_separators` | a lone comma is always treated as a decimal mark ("1,234" parses as 1.234) | 2 | Acceptance (`accept.py`): the pristine `tests/` files (incl. `helpers.py`) are byte-identical; the pristine suite passes (it is run from a clean copy of `tests/`, extra files the agent added there are ignored); the 34 hidden cases pass; no top-level file shadows a standard module. ## Prompt This repository contains `ledger/`, a small double-entry bookkeeping library (money amounts, chart of accounts, journal, reports, business-day calendar, currency conversion, CSV import/export and a command line tool), with its unit tests in `tests/`. Right now a number of the tests fail. Please fix the bugs in the library code so that the whole test suite passes. Run it with `python3 -m unittest discover -s tests`. Some notes: - Do not modify, delete, skip or weaken anything under `tests/`; the tests describe the intended behaviour. - Several failures may share one root cause, and the existing tests do not cover every input of the buggy code paths. After you find a bug, check the surrounding logic for the same mistake and fix the underlying logic rather than the individual failing inputs. Do not hard-code expected values or stub out functions. - Keep the code compatible with Python 3.9 or newer and use only the standard library. When you are done, reply with a short summary. For each bug you fixed, name the file and function, the root cause, and what you changed.