Skip to content

fix: repair failing utility tests and implement missing functions - #343

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2170-1789489140
Open

stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2170-1789489140

Conversation

@stooit

@stooit stooit commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 failing tests in the utility library (was 44 pass / 16 fail, now 60 pass / 0 fail). Only src/ files were changed — no test files modified, no dependencies added.

Changes

  • calculator.ts — divide now throws on division by zero instead of returning Infinity/NaN.
  • string-utils.ts — wordCount splits on \s+ (handles consecutive spaces/tabs/newlines); truncate implemented with word-boundary truncation, ellipsis counting toward maxLength, returns unchanged when within limit, and handles strings shorter than the ellipsis.
  • task-manager.ts — remove and update return false for unknown ids; update applies only supplied fields; sortBy supports priority (high→medium→low) and createdAt (oldest first), with deterministic tie-breaking on id.
  • date-utils.ts — formatRelative off-by-one fixed: day count now rounds hours to days (36h → "2 days ago").
  • validator.ts — isEmail accepts long TLDs (relaxed {2,4}→{2,}, added RFC-5321 254-char cap); isUrl accepts URLs with a port (dropped the erroneous empty-port requirement, protocol allowlist retained).

Testing

bun test → 60 pass, 0 fail (70 expect() calls). tsc --noEmit exits 0.

Assumptions

  • The test suite is the source of truth for expected behaviour.
  • truncate reserves 3 chars for ... only when maxLength > 3; otherwise it hard-slices.
  • update treats omitted fields as "leave unchanged" (fields cleared only when explicitly present).
  • sortBy breaks ties on numeric id for deterministic ordering.

Notes

  • isEmail/isUrl are format checks, not deliverability/reachability checks.

- calculator: divide throws on division by zero
- string-utils: wordCount handles consecutive whitespace; implement truncate
  with word-boundary logic and ellipsis counting toward maxLength
- task-manager: implement remove/update return semantics and sortBy for
  priority and createdAt
- date-utils: fix formatRelative off-by-one (round hours to days)
- validator: isEmail accepts long TLDs; isUrl accepts URLs with 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