Skip to content

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

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2199-1786378933
Open

fix: implement missing utilities and fix edge-case bugs#281
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2199-1786378933

Conversation

@stooit

@stooit stooit commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Makes all 60 tests pass (was 44 pass / 16 fail). Fixes edge-case bugs and implements missing functionality across the five utility modules. No test files modified, no dependencies added — changes are confined to src/.

Changes

  • calculator.tsdivide now throws on division by zero instead of returning Infinity/NaN, failing loudly at the boundary.
  • string-utils.ts — implemented truncate (truncates at a word boundary, "..." counts toward maxLength, returns unchanged when within limit, handles strings shorter than the ellipsis). Fixed wordCount to collapse consecutive whitespace (splits on /\s+/, also handles tabs/newlines).
  • task-manager.ts — implemented remove (returns false for unknown id), update (title/priority; false for unknown id), and sortBy (priority: high→medium→low; createdAt: oldest first). sortBy copies before sorting so insertion order in list() is preserved.
  • date-utils.ts — fixed off-by-one in formatRelative day rounding (Math.round instead of Math.floor, consistent with the minute/hour branches).
  • validator.tsisEmail accepts arbitrary-length TLDs and multi-level subdomains (and got stricter: rejects a@b..com, a@.com); isUrl accepts URLs with a port (removed an erroneous url.port === "" check) while retaining the http/https scheme allowlist.

Verification

60 pass / 0 fail — Ran 60 tests across 5 files

tsc --noEmit is clean.

Assumptions & known limitations

Per the task constraint ("fix only what the tests require"), the following untested edge cases were left as-is and are documented here for follow-up:

  • date-utils.formatRelative uses Math.round on days; at exact half-day ties, past vs. future differ by direction (no test covers the future case).
  • string-utils.truncate assumes a positive maxLength; negative/NaN values are unguarded.
  • task-manager.update cannot clear the optional description field (undefined means "leave unchanged").
  • validator.isUrl performs syntactic validation only — it should not gate server-side fetches without a host allowlist. isEmail is syntactic only and does not prove deliverability.

- calculator: divide throws on division by zero instead of returning Infinity/NaN
- string-utils: implement truncate (word-boundary, ellipsis counts toward maxLength);
  fix wordCount to collapse consecutive whitespace
- task-manager: implement remove/update/sortBy (priority and createdAt ordering)
- date-utils: fix off-by-one in day rounding (round instead of floor)
- validator: isEmail accepts long TLDs + multi-level subdomains; isUrl accepts ports

All 60 tests pass. No test files modified, no dependencies added.
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