Skip to content

fix: repair 16 failing tests across utility library - #305

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2157-1787859476
Open

fix: repair 16 failing tests across utility library#305
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2157-1787859476

Conversation

@stooit

@stooit stooit commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 failing tests in the utility library. Test suite now reports 60 pass, 0 fail, and tsc --noEmit is clean. No test files were modified and no dependencies were added.

Changes

File Fix
src/calculator.ts divide now throws Error("Division by zero") when the divisor is 0 (previously returned Infinity). Covers -0 too.
src/string-utils.ts wordCount splits on /\s+/ against the trimmed string so consecutive/leading/trailing whitespace no longer counts as words. truncate implemented: returns input unchanged when within maxLength, otherwise cuts at the last word boundary with the ellipsis counted toward maxLength.
src/task-manager.ts Implemented the three stubbed methods: remove (returns false for unknown id), update (partial update, false for unknown id), and sortBy for priority (high→medium→low) and createdAt (oldest first). Sorts a copy so internal order is preserved.
src/date-utils.ts formatRelative day rounding fixed: rounds the magnitude (Math.round(Math.abs(diffHours) / 24)) so past and future intervals are symmetric — 36h resolves to "2 days ago" / "in 2 days".
src/validator.ts isEmail allows TLDs longer than 4 chars (e.g. .museum) and subdomains. isUrl accepts a port (e.g. http://localhost:3000) while still restricting the protocol to http/https.

Verification

  • bun test → 60 pass / 0 fail
  • tsc --noEmit → clean
  • Independent review pass caught a Math.round-on-signed-value regression in date-utils (future dates were asymmetric with past dates); this was fixed before commit.

Assumptions & notes

  • The test files define the contract; fixes satisfy the tests without altering test files.
  • sortBy("createdAt") relies on ES2019 stable-sort for tasks created within the same millisecond (falls back to insertion order) — safe on Bun/Node.
  • isEmail/isUrl are format validators, not safety checks. isUrl accepts localhost/private hosts by design (required by the tests); if its output ever gates an outbound fetch it needs separate SSRF/open-redirect controls.

Fix 16 failing tests without modifying test files or adding dependencies:

- calculator: divide now throws on division by zero instead of returning Infinity
- string-utils: fix wordCount for consecutive whitespace; implement truncate
  with word-boundary cutting and ellipsis counting toward maxLength
- task-manager: implement remove, update (partial), and sortBy (priority/createdAt)
- date-utils: round day magnitude for symmetric past/future relative times
- validator: allow long TLDs in isEmail; allow ports in isUrl
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