Skip to content

fix: implement missing utilities and fix edge-case bugs to pass all tests - #323

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2171-1788884467
Open

fix: implement missing utilities and fix edge-case bugs to pass all tests#323
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2171-1788884467

Conversation

@stooit

@stooit stooit commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 previously-failing tests across the utility library. All 60 tests now pass (bun test) and tsc --noEmit is clean. Only the 5 source files were touched — no test files modified, no dependencies added.

Changes

  • src/calculator.tsdivide throws Error("Division by zero") when b === 0 instead of silently returning Infinity.
  • src/string-utils.ts
    • wordCount splits on /\s+/ against the trimmed string, so consecutive spaces no longer count an empty word ("hello world" → 2).
    • truncate implemented per the TODO: unchanged if str.length <= maxLength; otherwise reserves 3 chars for "...", cuts at the last word boundary, and never exceeds maxLength.
  • src/task-manager.ts — implemented remove (returns Map.delete's boolean), update (returns false for unknown id, applies only present fields), and sortBy (priority high>medium>low, status ranking, createdAt oldest-first).
  • src/date-utils.tsformatRelative day bucket uses Math.round(Math.abs(diffHours) / 24), fixing the off-by-one so 36h reads "2 days ago" (and future dates round correctly).
  • src/validator.tsisEmail accepts long TLDs and subdomains ({2,} instead of {2,4}, hyphen-safe labels); isUrl no longer rejects URLs with an explicit port.

Verification

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

Review notes / assumptions

An independent review confirmed the fixes are correct and cleared the validator regex of ReDoS risk (linear on adversarial inputs). It also flagged edge cases not covered by the test suite and left out of scope per the "fix only what the tests require" constraint:

  • formatRelative can display "24 hours ago" / "60 minutes ago" at the rounded top of a bucket.
  • truncate treats only a literal space as a word boundary; negative maxLength slices from the end.
  • sortBy's typed union makes an unknown-field call unreachable via the public API, but a raw JS caller would get undefined.

These are candidates for a follow-up hardening pass; none affect the passing suite.

…ests

- calculator.divide: throw on division by zero instead of returning Infinity
- string-utils.wordCount: split on /\s+/ so consecutive spaces count once
- string-utils.truncate: implement word-boundary truncation with ellipsis
  counting toward maxLength
- task-manager: implement remove, update, and sortBy methods
- date-utils.formatRelative: fix off-by-one day bucketing (round abs hours)
- validator: allow long TLDs in isEmail and 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