Split views_api into a domain package; unshadow /accounts/hierarchy #61

Open
padreug wants to merge 3 commits from refactor/views-api-package into chore/hygiene
Owner

Seventh and final PR of the refactor series (stacked on #60#59#58#57#56#55; merge in order).

Three commits, review each separately:

  1. Route-table snapshot test (pre-split): pins the ordered (methods, path, endpoint) table of libra_api_router — 73 routes — including the wart it must not silently change.
  2. The split (pure move, no logic changes — review with git diff --color-moved): the 4,100-line views_api.py becomes a views_api/ package with one module per domain — accounts, entries, payments (balances + invoices + settlements + manual payment requests), settings_reports, reconciliation, permissions (+equity), admin (chart accounts, sync, roles). Shared imports/helpers live in _shared.py; _extract_entry_id/_SYSTEM_LINK_PREFIXES move to beancount_format.py (pure entry-dict parsing). libra/__init__.py is untouched — the package __init__ builds the same libra_api_router. The snapshot confirms the 73-route set is identical and both order-sensitive overlap families keep their relative order (each lives inside a single module).
  3. Deliberate behavior fix: /api/v1/accounts/hierarchy was registered ~3,300 lines after /accounts/{account_id} and therefore shadowed — the endpoint has been unreachable (404 via account_id="hierarchy") since it was added. Now registered before the param routes, with a functional reachability test.

Largest module is now entries.py at 1,205 lines (from 4,121); everything else is 170–980.

Tests: 180 passed, 3 skipped (route snapshot + overlap-order + hierarchy reachability added).

This completes the refactor series from docs/CODE-REVIEW-2026-06.md. After the full stack merges, these issues are fixed and can be closed manually once deployed: libra-#22 (was already fixed, noted in #56), #23, #35, #36, #38, #39, #51, #52, #53, #54.

🤖 Generated with Claude Code

Seventh and final PR of the refactor series (stacked on #60 → #59 → #58 → #57 → #56 → #55; merge in order). Three commits, review each separately: 1. **Route-table snapshot test** (pre-split): pins the ordered `(methods, path, endpoint)` table of `libra_api_router` — 73 routes — including the wart it must not silently change. 2. **The split** (pure move, no logic changes — review with `git diff --color-moved`): the 4,100-line `views_api.py` becomes a `views_api/` package with one module per domain — `accounts`, `entries`, `payments` (balances + invoices + settlements + manual payment requests), `settings_reports`, `reconciliation`, `permissions` (+equity), `admin` (chart accounts, sync, roles). Shared imports/helpers live in `_shared.py`; `_extract_entry_id`/`_SYSTEM_LINK_PREFIXES` move to `beancount_format.py` (pure entry-dict parsing). `libra/__init__.py` is untouched — the package `__init__` builds the same `libra_api_router`. The snapshot confirms the 73-route set is identical and both order-sensitive overlap families keep their relative order (each lives inside a single module). 3. **Deliberate behavior fix**: `/api/v1/accounts/hierarchy` was registered ~3,300 lines after `/accounts/{account_id}` and therefore shadowed — the endpoint has been unreachable (404 via `account_id="hierarchy"`) since it was added. Now registered before the param routes, with a functional reachability test. Largest module is now `entries.py` at 1,205 lines (from 4,121); everything else is 170–980. **Tests:** 180 passed, 3 skipped (route snapshot + overlap-order + hierarchy reachability added). This completes the refactor series from `docs/CODE-REVIEW-2026-06.md`. After the full stack merges, these issues are fixed and can be closed manually once deployed: libra-#22 (was already fixed, noted in #56), #23, #35, #36, #38, #39, #51, #52, #53, #54. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
FastAPI matches in registration order; the views_api split must keep
the (methods, path, endpoint) table byte-identical. The snapshot also
records the known wart it must NOT silently change: /accounts/hierarchy
is registered after /accounts/{account_id} and therefore shadowed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Pure move — no logic changes. The 4,100-line single file becomes
views_api/ with one module per domain (accounts, entries, payments,
settings_reports, reconciliation, permissions, admin), each
registering full literal paths on its own APIRouter; __init__ builds
the combined libra_api_router so libra/__init__.py is untouched.
Shared imports/helpers live in views_api/_shared.py;
_extract_entry_id and _SYSTEM_LINK_PREFIXES move to
beancount_format.py (they are pure entry-dict parsing).

Route behavior is pinned by tests/test_route_table.py: the 73-route
set is unchanged, and the two order-sensitive families (the shadowed
/accounts/hierarchy wart — deliberately preserved here, fixed in the
next commit — and the admin sync literal/param pair) keep their
relative order inside a single module each.

Addresses CODE-REVIEW-2026-06 structure findings (views_api monolith).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
FastAPI matches in registration order, and hierarchy was registered
~3,300 lines after the {account_id} route — every request resolved as
account_id="hierarchy" and 404'd, so the endpoint has been unreachable
since it was added. Moved above the param routes in the accounts
module, with a functional reachability test and an updated route
snapshot (literal-before-param is now asserted for both overlap
families).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin refactor/views-api-package:refactor/views-api-package
git switch refactor/views-api-package

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch chore/hygiene
git merge --no-ff refactor/views-api-package
git switch refactor/views-api-package
git rebase chore/hygiene
git switch chore/hygiene
git merge --ff-only refactor/views-api-package
git switch refactor/views-api-package
git rebase chore/hygiene
git switch chore/hygiene
git merge --no-ff refactor/views-api-package
git switch chore/hygiene
git merge --squash refactor/views-api-package
git switch chore/hygiene
git merge --ff-only refactor/views-api-package
git switch chore/hygiene
git merge refactor/views-api-package
git push origin chore/hygiene
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
aiolabs/libra!61
No description provided.