Skip to content

fix: implement missing utils functions and fix edge-case bugs - #325

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2307-1788929421
Open

fix: implement missing utils functions and fix edge-case bugs#325
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2307-1788929421

Conversation

@stooit

@stooit stooit commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 failing tests in the utility library — 60/60 now pass (was 44/60). No test files modified, no dependencies added; scope limited to what the tests require.

Fixes by file

  • src/calculator.tsdivide now throws Error("Division by zero") when the divisor is 0 (also covers -0), instead of silently returning Infinity/NaN.
  • src/string-utils.ts
    • wordCount splits on /\s+/ against the trimmed string, correctly handling consecutive spaces, tabs, and newlines.
    • truncate implemented: returns unchanged when str.length <= maxLength; otherwise truncates at a word boundary with "..." counted toward maxLength.
  • src/task-manager.ts — implemented remove (returns false for unknown id), update (partial update via !== undefined checks; returns false for unknown id), and sortBy (priority high>medium>low, createdAt oldest first, status in workflow order).
  • src/date-utils.tsformatRelative day bucket uses Math.round(Math.abs(diffHours) / 24), fixing the off-by-one at exactly 36 hours (now "2 days ago") while keeping past/future symmetric.
  • src/validator.tsisEmail allows TLDs of length >= 2 ({2,}); isUrl accepts URLs with an explicit port while still rejecting non-http(s) protocols.
  • docs — removed stale BUG: comments in date-utils.ts and validator.ts that described the now-fixed defects.

Testing

bun test -> 60 pass, 0 fail. tsc --noEmit clean.

Assumptions / notes

  • Reviewed but intentionally not changed (outside the tested contract, per "fix only what the tests require"): truncate with negative/NaN maxLength; truncate when the budget window is all whitespace; update clearing an optional field via explicit undefined. These are unguarded edge cases in newly-written code with no prior contract; flagging for a future hardening pass rather than expanding scope here.
  • sortBy("createdAt") relies on stable sort + insertion order for same-millisecond ties (correct, but the test doesn't genuinely exercise timestamp comparison).

🤖 Generated with QuantCode Agent

Fix all 16 failing tests (60/60 now pass) without modifying tests or
adding dependencies:

- calculator: divide now throws on division by zero instead of
  silently returning Infinity/NaN
- string-utils: wordCount splits on /\s+/ (handles consecutive spaces,
  tabs, newlines); implement truncate at word boundary with ellipsis
  counted toward maxLength
- task-manager: implement remove/update (partial, returns false on
  unknown id) and sortBy (priority high>medium>low, createdAt oldest
  first, status workflow order)
- date-utils: formatRelative uses Math.round(abs(hours)/24) to fix the
  off-by-one at exactly 36 hours
- validator: isEmail allows TLDs of length >=2; isUrl accepts URLs with
  an explicit port while still rejecting non-http(s) protocols
- docs: remove stale BUG comments now that the defects are fixed
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