Skip to content

fix: repair all failing tests in utility library - #317

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2175-1788382502
Open

fix: repair all failing tests in utility library#317
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2175-1788382502

Conversation

@stooit

@stooit stooit commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 failing tests across 5 source files. Test suite now 60 pass / 0 fail (was 44/16), bunx tsc --noEmit clean. No test files modified, no dependencies added.

Changes

  • src/calculator.tsdivide throws Error("Division by zero") when the divisor is 0 instead of returning Infinity.
  • src/string-utils.tswordCount splits on \s+ after trim (fixes phantom words from consecutive spaces); truncate implemented with word-boundary cut-back and ellipsis counted toward maxLength.
  • src/task-manager.ts — implemented remove (returns Map.delete boolean), update (applies only defined fields, false for unknown id), and sortBy (priority high→medium→low, status, createdAt oldest-first).
  • src/date-utils.tsformatRelative day bucket uses Math.round(Math.abs(diffHours)/24), fixing the off-by-one (36h → "2 days ago") symmetrically for past and future.
  • src/validator.tsisEmail accepts subdomains and TLDs of 2+ letters (user@example.museum); isUrl accepts URLs with ports (http://localhost:3000).

Verification

  • bun test → 60 pass, 0 fail
  • bunx tsc --noEmit → exit 0
  • Independent review pass: fixes confirmed as genuine implementations, not assertion-shaped tricks; regex changes are linear (no ReDoS); no regressions on previously-passing behaviour.

Assumptions & notes

  • Scope limited to what the tests require, per task constraints. Two non-blocking design notes surfaced in review and intentionally left as-is (untested, within spec): update cannot clear an optional field via undefined (JSON-merge semantics); truncate's word-boundary heuristic can under-fill the budget when the first word is long. sortBy status ordering (in_progress > pending > completed) is not test-specified.

- calculator: divide now throws on division by zero instead of returning Infinity
- string-utils: fix wordCount for consecutive whitespace; implement truncate with word-boundary and ellipsis budget
- task-manager: implement remove, update (partial fields), and sortBy (priority/status/createdAt)
- date-utils: fix off-by-one in formatRelative by rounding absolute day diff
- validator: isEmail accepts subdomains and long TLDs; isUrl accepts URLs with ports
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