Skip to content

test(tms): cover the driver-pay domain and service money math - #559

Merged
emoss08 merged 3 commits into
masterfrom
claude/driver-pay-tests-b1j99m
Aug 31, 2026
Merged

test(tms): cover the driver-pay domain and service money math#559
emoss08 merged 3 commits into
masterfrom
claude/driver-pay-tests-b1j99m

Conversation

@emoss08

@emoss08 emoss08 commented Aug 31, 2026

Copy link
Copy Markdown
Owner

Description

Third slice of the codebase completeness review: first test coverage for the driver-pay vertical, which previously had zero tests across ~5,000 LOC of money math. Coverage goes from 0% → 61.3% on the driverpay domain package and 0% → 49.8% on driverpayservice (~2,600 lines of tests).

Domain (internal/core/domain/driverpay): escrow account/transaction validation including per-type sign rules (contributions and interest accruals must be positive; applications and refunds negative), funded-percent math and full-funding detection, pay-advance outstanding-balance math and status-sync transitions, pay-code pattern rules, reimbursement classification and the system code catalog, pay-profile component validation, mileage-band validation and rate resolution (including band boundaries and open-ended bands), worker-pay-assignment effective windows and rate overrides, and recurring deduction/earning cap math with next-amount clamping.

Service (internal/core/services/driverpayservice): escrow open (default interest rate from settlement control, duplicate-active-account rejection), adjust (balance-floor enforcement, transaction append with correct BalanceAfterMinor), close (refund of the remaining balance per 49 CFR 376.12(k), no refund on zero balance), interest accrual (exact year-fraction math, accrual-date advancement, ineligible-account no-ops), assignment overlap handling (earlier open assignments get ended at the new effective date; later-starting ones are rejected), rate-override component validation, advance issue/update/write-off transitions, and deduction pay-code direction checks with escrow auto-linking.

The generated mocks don't yet cover the driver-pay repositories (and CLAUDE.md forbids a full mockery regeneration), so the service tests use package-local interface fakes — the same pattern bankreceiptbatchservice's tests use.

Bug found and fixed by the new tests: validateBands rejected contiguous mileage bands (next.MinMiles == previous.MaxMiles) as overlapping, but ResolveMileageRate treats MaxMiles as exclusive — so the only encoding that produces gap-free mileage coverage could not pass validation, silently forcing 1-mile rate gaps in every banded pay profile. The check is now band.MinMiles < prevMax, which still rejects genuine overlaps.

Related Issue or Discussion

Found during a codebase completeness review; maintainer-driven session. Follow-up to #557 and #558.

Type of Change

  • Bug fix
  • Feature
  • Documentation
  • Refactor
  • Tests
  • Build, CI, or infrastructure

Scope

  • services/tms/internal/core/domain/driverpay — 6 new test files + the one-line validateBands fix in payprofile.go
  • services/tms/internal/core/services/driverpayservice — 4 new test files + shared test fakes

Validation

  • Other: go test -cover for both packages (all pass; coverage above), go vet, go build ./internal/..., go test -run TestFullSeedRunOnSQLite ./internal/infrastructure/database/seeder/ (the dev seed still validates after the band fix), gofmt clean, golines applied with the repo's formatter settings. golangci-lint could not run in this environment (binary built with Go 1.25, repo targets Go 1.26).
  • cd services/tms && task test — full suite not run in this environment; changed-package tests pass.
  • cd services/tms && task lint — see above.
  • cd client && pnpm build — not run; no client changes.
  • cd client && pnpm lint — not run; no client changes.

Deployment Notes

  • The validateBands change only loosens validation (contiguous bands now accepted); every previously-valid pay profile remains valid. No schema, config, or API changes.

Checklist

  • I kept the change focused and reviewable.
  • I followed AGENTS.md, CLAUDE.md, and existing repository patterns.
  • I added or updated tests for behavior changes, or explained why tests are not applicable.
  • I updated relevant documentation, examples, migrations, or configuration.
  • I did not include secrets, credentials, private customer data, unrelated refactors, or placeholder code.

🤖 Generated with Claude Code

https://claude.ai/code/session_015houJkqb8SuqPW4YpLoWCq


Generated by Claude Code

claude added 2 commits August 31, 2026 00:54
Adds the first test coverage for the driver-pay vertical:

- Domain: validation and money math for escrow accounts/transactions
  (sign rules per transaction type, funded percent, full funding),
  pay advances (outstanding balance, status sync), pay codes (code
  pattern, reimbursement classification, system code catalog), pay
  profiles (component rules, mileage band validation and resolution),
  worker pay assignments (effective windows, rate overrides), and
  recurring deductions/earnings (cap math, next-amount clamping).
- Service: escrow open/adjust/close/interest-accrual flows (duplicate
  active account rejection, balance-floor enforcement, closure refunds
  per 49 CFR 376.12(k), interest math and accrual-date advancement),
  assignment overlap handling and rate-override validation, advance
  issue/update/write-off transitions, and deduction pay-code direction
  and escrow auto-linking.

Also fixes an off-by-one in mileage band validation: contiguous bands
(next.MinMiles == previous.MaxMiles) were rejected as overlapping even
though ResolveMileageRate treats MaxMiles as exclusive, so the only
gap-free encoding could not pass validation.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015houJkqb8SuqPW4YpLoWCq
@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/driver-pay-tests-b1j99m

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@emoss08
emoss08 merged commit 6a43fc5 into master Aug 31, 2026
9 of 14 checks passed
@emoss08
emoss08 deleted the claude/driver-pay-tests-b1j99m branch August 31, 2026 16:08
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.

2 participants