Skip to content

fix: implement missing utilities and fix edge-case bugs - #278

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2302-1786119722
Open

fix: implement missing utilities and fix edge-case bugs#278
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2302-1786119722

Conversation

@stooit

@stooit stooit commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 previously-failing tests across the utility library. The full suite is now 60 pass / 0 fail, and tsc --noEmit is clean. No test files were modified and no dependencies were added.

Changes

  • src/calculator.tsdivide now throws on a zero divisor instead of returning Infinity.
  • src/string-utils.ts — implemented truncate (cuts at a word boundary, "..." counts toward maxLength, returns unchanged when it fits, UTF-16 surrogate-pair safe). Fixed wordCount to split on /\s+/ after trimming.
  • src/task-manager.ts — implemented remove (false for unknown id), update (partial updates), and sortBy (priority high>medium>low; createdAt oldest first).
  • src/date-utils.ts — fixed off-by-one in formatRelative (Math.round instead of Math.floor; 36h now reports "2 days ago").
  • src/validator.tsisEmail accepts long TLDs (e.g. example.museum) and deeper subdomains while still rejecting empty labels; isUrl no longer rejects URLs with a port.

Verification

  • bun test → 60 pass, 0 fail
  • bunx tsc --noEmit → clean

Assumptions / notes

  • divide throwing on zero is a deliberate contract change for an exported function (test asserts it throws).
  • update() uses the conventional partial-update pattern (!== undefined), so it cannot clear an optional field to undefined.
  • truncate behaviour for maxLength <= 3 is a judgement call not pinned by tests.
  • isEmail/isUrl remain pragmatic regex validators, not RFC-compliant.

Reviewed by the review subagent; the one blocker raised (surrogate-pair splitting in truncate) is fixed in this branch.

- calculator: throw on division by zero instead of returning Infinity
- string-utils: implement truncate (word-boundary, ellipsis counts toward
  maxLength, surrogate-pair safe) and fix wordCount for consecutive whitespace
- task-manager: implement remove, update (partial), and sortBy (priority/createdAt)
- date-utils: fix off-by-one in formatRelative (round instead of floor)
- validator: allow long TLDs in isEmail and ports in isUrl

All 60 tests pass; tsc --noEmit clean.
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