Skip to content

fix: repair failing utility tests and implement missing functionality - #294

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2216-1787024917
Open

fix: repair failing utility tests and implement missing functionality#294
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2216-1787024917

Conversation

@stooit

@stooit stooit commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 failing tests in the utility library (60 pass / 0 fail, up from 44 pass / 16 fail) and implements the missing functionality the tests require. Only the 5 src/ files were changed — no test files modified, no dependencies added.

Changes

  • src/calculator.tsdivide now throws on division by zero instead of returning Infinity (fail-closed on invalid input).
  • src/string-utils.tswordCount splits on /\s+/ after trimming so runs of whitespace no longer produce phantom words; truncate implemented: returns unchanged within limit, clips at a word boundary, counts the ellipsis toward maxLength, and guards short strings.
  • src/task-manager.tsremove/update honour their boolean return contracts (false for unknown id, partial updates never clobber omitted fields); sortBy orders priority high→medium→low and createdAt oldest-first, copying to an array so internal Map order isn't mutated (relies on stable Array.sort).
  • src/date-utils.tsformatRelative day bucket uses Math.round on the magnitude (Math.abs(diffHours)/24), fixing the off-by-one and keeping past/future symmetric.
  • src/validator.tsisEmail accepts long TLDs (e.g. .museum); isUrl accepts URLs with ports (e.g. http://localhost:3000) while keeping the http/https protocol allowlist.

Verification

  • bun test: 60 pass, 0 fail (70 expect() calls, 5 files).
  • tsc --noEmit: clean.
  • Reviewed by the review subagent; the one flagged correctness concern (future-date rounding asymmetry in formatRelative) was fixed in this branch.

Assumptions / notes

  • Followed the test suite as the source of truth: 36h → "2 days ago" (Math.round), as the test comment specifies.
  • The formatRelative future-days path and sortBy("status") order are unit-tested only indirectly; general-correct behaviour was implemented and verified by direct execution. Follow-up tests (e.g. 36h future → "in 2 days") would lock these in but could not be added under the "do not modify test files" constraint.

🤖 Generated with QuantCode

- calculator: divide throws on division by zero instead of returning Infinity
- string-utils: fix wordCount for consecutive whitespace; implement truncate
  (word-boundary clip, ellipsis counts toward maxLength, short-string guard)
- task-manager: implement remove/update return contracts and sortBy
  (priority high>medium>low, createdAt oldest-first, non-mutating copy)
- date-utils: formatRelative uses Math.round on magnitude, fixing the
  day-bucket off-by-one for both past and future dates
- validator: isEmail accepts long TLDs (.museum); isUrl accepts URLs with ports
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.

1 participant