Skip to content

feat: cap envelope assignment at Ready to Assign (Issue #7)#15

Merged
toolpathguy merged 1 commit into
mainfrom
chore/enforce-budget-availability
Jun 17, 2026
Merged

feat: cap envelope assignment at Ready to Assign (Issue #7)#15
toolpathguy merged 1 commit into
mainfrom
chore/enforce-budget-availability

Conversation

@toolpathguy

Copy link
Copy Markdown
Owner

Fixes #7

What & why

You could assign more to an envelope than actually existed — there was no availability check on assignment. This adds one: you can't budget money that doesn't exist.

"Money that exists" = Ready to Assign = net worth across all real accounts − envelopes, so funds physically held in savings count even when the budget-host account (checking) is empty. The gate is the net-worth pool, never a single account's balance — which is exactly the scenario in #7 ("budget in an envelope, money kept in savings").

The product owner clarified the model (this is YNAB-faithful, not the original "just show a red number" idea):

  • Assigning is capped at Ready to Assign — over-assignment is rejected.
  • Overspending an envelope stays allowed and is covered by moving funds between envelopes (transfers are never gated).

Changes

  • server/utils/budgetData.ts (new)getReadyToAssign() + READY_TO_ASSIGN_EPSILON, the single source of truth for the RTA pool. GET /api/budget is refactored to use it (figures unchanged), so the report and the gate can never disagree.
  • server/api/budget/assign.post.ts — rejects an over-assignment with 400 "Can't assign $X — only $Y left to assign." and no journal write.
  • pages/budget.vue — client-side guard + toast for instant feedback (server stays authoritative).
  • Docs — single-host / availability decision recorded in the design doc; new util noted in AI-MAP.md.
  • Spec: .kiro/specs/enforce-budget-availability/.

Decision recorded

Single budget host is intentional; multi-account envelope hosting is not a goal. A negative …:budget:unallocated (from assigning savings-backed money) is numerically correct and intentionally not surfaced.

Tests & verification

  • New server/api/__tests__/budget-assign.test.ts — over-assign vs net worth rejected (single + summed envelopes), within/boundary accepted, savings-backed assignment accepted with empty checking (net-worth basis).
  • Full suite: 41 test files pass; npx nuxi typecheck clean.
  • Verified end-to-end against a running dev server: over-assign → 400 + no write; within-budget → 201; savings-backed assignment with $0 checking → 201; epsilon boundary; transfers not gated.

🤖 Generated with Claude Code

Prevent assigning more to an envelope than actually exists. "Money that
exists" is Ready to Assign = net worth across all real accounts minus
envelopes, so savings-held funds count even when the budget-host account is
empty; the gate is the net-worth pool, never a single account's balance.

- Extract getReadyToAssign() into server/utils/budgetData.ts as the single
  source of truth, shared by GET /api/budget and the assign availability gate
- Reject over-assignment in budget/assign.post.ts (400, no journal write)
  with a clear "Can't assign $X — only $Y left to assign." message
- Add a client-side guard + toast in budget.vue for instant feedback
  (server stays authoritative)
- Overspending an envelope and inter-envelope transfers stay unrestricted
  (the coverage mechanism), only assigning beyond the pool is blocked
- Document the single-host / availability model decision in the design doc

Verified end-to-end against a running dev server: over-assign rejected with
no write, within-budget accepted, savings-backed assignment accepted with an
empty checking account, epsilon boundary, and transfers not gated.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@toolpathguy toolpathguy merged commit 0ae1481 into main Jun 17, 2026
2 checks passed
@toolpathguy toolpathguy deleted the chore/enforce-budget-availability branch June 17, 2026 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Envelopes physically backed by a non-host account (e.g. budget in an envelope, money kept in savings)

1 participant