Skip to content

fix: repair failing tests across utility modules - #298

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2222-1787328704
Open

fix: repair failing tests across utility modules#298
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2222-1787328704

Conversation

@stooit

@stooit stooit commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 failing tests across the utility library. Only source files under src/ were changed — no test files modified, no dependencies added.

Result: 60 pass / 0 fail; tsc --noEmit clean.

Changes

  • calculatordivide throws on division by zero (was returning Infinity). b === 0 also covers -0.
  • string-utils — implemented truncate (returns unchanged when within limit; ellipsis counts toward maxLength; word-boundary aware; handles maxLength <= 3). wordCount trims and splits on /\s+/, so consecutive spaces/tabs/newlines don't inflate the count.
  • task-manager — implemented remove (false for unknown id), update (applies only provided fields; false for unknown id), and sortBy (priority high>medium>low; createdAt oldest-first). sortBy sorts a copy and does not mutate internal state.
  • date-utilsformatRelative off-by-one fixed via Math.round(Math.abs(diffHours)/24); 36h now reports "2 days ago".
  • validatorisEmail accepts long TLDs (e.g. .museum) via a {2,63} quantifier plus a 254-char length guard; isUrl accepts URLs with a port (protocol allowlist retained, so ftp:/javascript:/data:/file: still rejected).

Assumptions / notes

  • The date-utils fix also silently corrected a previously-untested future-date skew: e.g. 50h future was "in 3 days", now correctly "in 2 days". Improvement, called out so it isn't mistaken for a regression.
  • update uses !== undefined checks, so it cannot clear an optional field — matches the common convention and no test requires clearing.
  • Verified independently: no test files, package.json, or tsconfig.json changed.

Out of scope (flagged, not fixed)

  • isUrl accepts any http/https host including loopback/private addresses — if ever used to guard a server-side fetch, that's an SSRF vector needing separate host allowlisting.
  • Pre-existing isEmail looseness (user@example..com) is unchanged.

Fix 16 failing tests without touching test files or adding deps:

- calculator: divide now throws on division by zero instead of Infinity
- string-utils: implement truncate (ellipsis counts toward maxLength,
  word-boundary aware); wordCount handles consecutive/other whitespace
- task-manager: implement remove/update/sortBy (priority + createdAt)
- date-utils: formatRelative rounds day diff (36h => "2 days ago");
  also corrects a previously-untested future-date skew ("in N days")
- validator: isEmail accepts long TLDs (.museum); isUrl accepts a port

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