Skip to content

fix: implement missing utilities and fix edge-case bugs (all tests passing) - #275

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2318-1785687930
Open

fix: implement missing utilities and fix edge-case bugs (all tests passing)#275
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2318-1785687930

Conversation

@stooit

@stooit stooit commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Makes the full test suite pass — 60 pass, 0 fail (was 44 pass / 16 fail). No test files were modified and no dependencies were added.

Fixes by file

  • src/calculator.tsdivide now throws Error("Division by zero") when the divisor is 0 instead of returning Infinity/NaN.
  • src/string-utils.ts
    • wordCount trims and splits on \s+, so leading/trailing/consecutive whitespace no longer inflates the count.
    • Implemented truncate (was a not-implemented TODO): returns the string unchanged when length <= maxLength; otherwise cuts at the last word boundary and appends "...", with the ellipsis counting toward maxLength.
  • src/task-manager.ts — implemented remove (returns false for unknown ids), update (per-field undefined guards so only supplied fields change; false for unknown ids), and sortBy (priority high→medium→low, status rank, and createdAt ascending / oldest-first).
  • src/date-utils.ts — fixed off-by-one in formatRelative day calculation (Math.floor → rounded absolute hours), so exactly 36 hours reports "2 days ago" rather than "1 day ago".
  • src/validator.tsisEmail accepts arbitrary subdomain depth and 2+ char TLDs (e.g. .museum); isUrl accepts hosts with explicit ports (e.g. http://localhost:3000), still restricted to http:/https:.

Verification

bun test -> 60 pass, 0 fail across 5 files. tsc --noEmit clean.

Assumptions & notes

  • Behaviour was implemented to match the intent in the code comments/TODOs and the read-only test expectations.
  • Security note (not covered by tests, behaviour left as the tests require): isUrl now accepts any host including internal addresses (localhost, link-local). If this validator is ever used to gate a server-side fetch, it would need an explicit host/IP allowlist to avoid becoming an SSRF vector. isEmail remains a syntax check only, not input sanitisation.

…ests

Fixes 16 failing tests across the library:
- calculator: divide now throws on division by zero
- string-utils: wordCount collapses consecutive whitespace; implement truncate
  (word-boundary aware, ellipsis counts toward maxLength)
- task-manager: implement remove, update (per-field guards), and sortBy
  (priority/status rank, createdAt oldest-first)
- date-utils: fix off-by-one in formatRelative day rounding (36h -> 2 days)
- validator: isEmail accepts multi-level subdomains and long TLDs;
  isUrl accepts hosts with explicit ports

No test files modified; no new dependencies.
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