Skip to content

Settle up in whole dollars (#193) - #196

Open
Param-Harrison wants to merge 3 commits into
mainfrom
factory/issue-193
Open

Param-Harrison wants to merge 3 commits into
mainfrom
factory/issue-193

Conversation

@Param-Harrison

Copy link
Copy Markdown
Contributor

Summary

settleUp now settles the whole-dollar part of every balance first, then settles the leftover cents with separate transfers that are each under $1. Cash covers most of the money and every balance still settles to the exact cent.

Closes #193

Plan

Plan comment (rev 1, in the issue thread; .factory/runs/issue-193/plan-comment.md):

  • AC-1 issue example (Ben→Asha 3300 + 33, Chen→Asha 3300 + 34), verified by bun test tests/balances.test.ts -t "issue example"
  • AC-2 every transfer is a positive multiple of 100 cents or strictly under 100, verified by -t "whole dollars or cents only"
  • AC-3 every balance nets to exactly 0, including 2075 / 1050 / -3125 and seeded random groups, verified by -t "settles exactly"
  • AC-4 whole-dollar balances give no sub-dollar transfers and match the one-pass result, verified by -t "whole-dollar balances"
  • AC-5 existing suite and typecheck still pass, verified by make check

Deliberately left out (non-goals): no change to the Transfer type, /balances JSON shape, computeBalances or schema; no rounding that leaves a balance unsettled; no float money; dollar and cents transfers between the same pair are not merged.

Changed files: src/balances.ts, tests/balances.test.ts (new).

Gate evidence

FACTORY_GATES: status=GREEN passed=3 failed=0 skipped=1 failed_gates=audit

The skipped audit gate is optional and flags existing hono advisories this diff does not cause.

Verify verdict

Verdict comment (in the issue thread; .factory/runs/issue-193/verdict-comment.md): pass, AC-1 to AC-5 all pass, no reviewer findings.

Test that bites: settleUp > issue example: $100 dinner for three gives $33 transfers plus cents-only remainders fails with src/balances.ts reverted (3 assertion failures, no compile error) and passes with the change.

Risk and rollback

Risk: low. One non-protected module, no schema or API-shape change. Note that users now see two transfers between the same pair (a dollar amount and a cents remainder), so a reviewer should confirm this reading of the issue.

Rollback: revert this PR; src/balances.ts returns to the one-pass algorithm and nothing is persisted, so there is no data to migrate.

Factory run

Stage Agent Duration Tool calls Cost Outcome
triage claude 25s 6 $0.09 ok
triage claude 17s 6 $0.05 ok
plan claude 1m 33s 9 $0.42 ok
plan claude 1m 3s 6 $0.22 ok
build claude 2m 5s 18 $0.59 ok
plan claude 40s 5 $0.25 ok
build claude 1m 30s 8 $0.25 ok
verify claude 1m 20s 9 $0.31 pass
pr claude 32s 4 $0.08 ok

Proof: the new test fails without the change.

9 stage runs, 9m 25s, $2.26.

Went well

  • verify, pr passed on the first attempt
  • verify approved on the first round

Needed help

  • triage ran 2 times
  • plan ran 3 times
  • build ran 2 times
  • 1 /factory retry

@Param-Harrison
Param-Harrison marked this pull request as ready for review October 14, 2026 11:48
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.

Settle up in whole dollars

1 participant