Skip to content

fix: make all failing tests pass across utility library - #348

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2189-1790007600
Open

stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2189-1790007600

Conversation

@stooit

@stooit stooit commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 failing tests (now 60 pass / 0 fail) by implementing missing functions and correcting edge-case bugs across five utility modules. No test files were modified and no dependencies were added.

Changes

  • src/calculator.ts — divide now throws on a zero divisor instead of silently returning Infinity.
  • src/string-utils.ts — implemented truncate (word-boundary clip with "..." counted toward maxLength, unchanged when str.length <= maxLength, clamped for small/negative maxLength); fixed wordCount to split on runs of whitespace after trimming.
  • src/task-manager.ts — implemented remove (Map-backed true/false contract), update (applies only supplied fields, honouring falsy values like ""), and sortBy (priority/status rank maps, numeric createdAt; sorts a copy so Map order is preserved).
  • src/date-utils.ts — day bucket uses Math.round on the absolute diff, fixing an off-by-one (e.g. 36h → "2 days ago") and making future dates round symmetrically.
  • src/validator.ts — isEmail validates each domain label separately (fixes subdomains and long TLDs) with RFC 5321 length bounds; isUrl accepts a non-empty port while keeping the http/https-only restriction.

Verification

  • bun test → 60 pass / 0 fail (was 44 pass / 16 fail).
  • bunx tsc --noEmit → clean.
  • Reviewed via subagent; two review findings folded in before commit (negative-maxLength clamp in truncate; corrected a misleading ReDoS rationale in the isEmail docstring).

Assumptions / notes

  • truncate with maxLength <= 3 on a longer string hard-clips without an ellipsis (ellipsis alone would exceed the budget) — untested edge, chosen for the length guarantee.
  • update uses !== undefined checks, so an optional field cannot currently be cleared by passing undefined — matches existing untested behaviour; left as-is.
  • Status sort ordering (in_progress > pending > completed) is not test-covered; chosen as a sensible default.

Implement truncate, TaskManager remove/update/sortBy; fix divide-by-zero,
whitespace word counting, day rounding, and email/URL validation.

- calculator: divide throws on zero divisor instead of returning Infinity
- string-utils: implement truncate (word-boundary, ellipsis in budget),
  fix wordCount to split on runs of whitespace after trim
- task-manager: implement remove, update (honours falsy values), sortBy
- date-utils: round day buckets (Math.round + abs) fixing off-by-one
- validator: isEmail validates domain labels (subdomains, long TLDs),
  isUrl accepts non-empty port while keeping http/https restriction
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