Skip to content

fix: implement missing utilities and fix edge-case bugs - #346

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

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

Conversation

@stooit

@stooit stooit commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Summary

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

Changes

  • src/calculator.ts — divide throws on division by zero (was returning Infinity).
  • src/string-utils.ts — wordCount collapses consecutive whitespace via /\s+/; truncate implemented (word-boundary cut, "..." counting toward maxLength, unchanged when within limit, handles strings shorter than the ellipsis).
  • src/task-manager.ts — implemented remove (returns bool), update (partial updates, ignores undefined keys), and sortBy (priority high>medium>low; createdAt oldest-first).
  • src/date-utils.ts — fixed off-by-one in formatRelative (Math.round instead of Math.floor; 36h → "2 days ago").
  • src/validator.ts — isEmail accepts multi-level subdomains and long TLDs; isUrl accepts URLs with ports (scheme still restricted to http/https).

Verification

  • bun test → 60 pass, 0 fail
  • npx tsc --noEmit → clean
  • Code review passed (no blockers). ReDoS check on the isEmail regex confirmed linear time on adversarial input.

Assumptions & notes (deliberately out of scope — no test coverage)

Kept changes minimal per the "fix only what the tests require" constraint. Review flagged these as potential follow-ups, left unchanged to avoid untested scope creep:

  • isEmail local-part uses an explicit allow-list; apostrophe/non-ASCII local parts (e.g. O'Brien, non-Anglicised names) are rejected. Worth widening for inclusivity if this gates a user-facing form.
  • truncate can return bare "..." when the only space in the budget is leading whitespace.
  • update cannot explicitly clear an optional field (uses !== undefined rather than "key" in changes).
  • sortBy("status") ordering (in_progress>pending>completed) is implemented but untested/invented so the declared type isn't lying.
  • isUrl validates scheme+syntax only, not destination safety (not an SSRF guard).

Fix 16 failing tests across the utility library:
- calculator: divide now throws on division by zero
- string-utils: wordCount collapses consecutive whitespace; implement truncate at word boundary with ellipsis counting toward maxLength
- task-manager: implement remove, update (partial), and sortBy (priority, createdAt)
- date-utils: fix off-by-one in formatRelative (round vs floor)
- validator: isEmail accepts long TLDs/subdomains; isUrl accepts 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