Skip to content

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

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2174-1789662024
Open

stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2174-1789662024

Conversation

@stooit

@stooit stooit commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 previously-failing tests (now 60 pass / 0 fail) across the TypeScript utility library, implementing missing functionality and correcting edge-case bugs. No test files modified, no dependencies added.

Changes by file

  • src/calculator.ts — divide now throws Error("Division by zero") when the divisor is 0 (also catches -0) instead of returning Infinity.
  • src/string-utils.ts
    • wordCount — splits on /\s+/ after trimming, so consecutive spaces/tabs/newlines collapse correctly.
    • truncate — implemented: returns the string unchanged when length <= maxLength; otherwise cuts at a word boundary with "..." counting toward maxLength, falling back to a hard character cut when there's no space. Guards maxLength <= 0 (returns "") and preserves content when the boundary lands in leading whitespace.
  • src/task-manager.ts — implemented remove (delete + boolean), update (partial update, only applies present keys), and sortBy (priority / status / createdAt ordering on a copied array).
  • src/date-utils.ts — formatRelative day calculation fixed: Math.round(Math.abs(diffHours) / 24), correcting both the past-date off-by-one and a signed-rounding regression that would have broken future dates >=24h.
  • src/validator.ts — isEmail accepts TLDs longer than 4 chars ({2,}); isUrl no longer rejects URLs with an explicit port (e.g. http://localhost:3000) while still rejecting non-http(s) schemes.

Verification

  • bun test -> 60 pass / 0 fail
  • bunx tsc --noEmit -> clean
  • Only the 5 src/ files changed; no test files, no dependency changes.

Review notes / assumptions

  • A review pass caught a signed-rounding regression in date-utils (future dates >=24h) that the test suite doesn't cover; fixed proactively.
  • truncate hardened against maxLength <= 0 and leading-whitespace inputs beyond what the tests assert, to avoid returning bare "..." or stray fragments.
  • The sortBy status ordering (in_progress > pending > completed) is not spec'd beyond the tests — chosen to satisfy the test and left as a reasonable convention.
  • isEmail remains a permissive structural regex (satisfies tests; not a security-grade validator). Not hardened per the "fix only what tests require" constraint.

Guard divide against zero, fix wordCount whitespace handling, implement
truncate/remove/update/sortBy, correct signed day rounding in
formatRelative, and relax over-strict email TLD and URL port validation.

All 60 tests pass.
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