Skip to content

fix: repair 16 failing tests across utility library - #301

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2266-1787501282
Open

fix: repair 16 failing tests across utility library#301
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2266-1787501282

Conversation

@stooit

@stooit stooit commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 failing tests across the TypeScript utility library. 60/60 tests now pass (was 44 pass / 16 fail). No test files modified, no dependencies added.

Changes by file

src/calculator.tsdivide throws Error("Division by zero") when the divisor is 0 instead of returning Infinity. The b === 0 guard also covers -0.

src/string-utils.ts

  • wordCount splits on /\s+/ against the trimmed string, so consecutive spaces/tabs/newlines collapse correctly.
  • truncate implemented: returns input unchanged when within maxLength; otherwise takes a maxLength - 3 budget, backs up to the last whitespace (regex /\s\S*$/, consistent with wordCount), and appends "...". Output is guaranteed <= maxLength, including when maxLength <= 3.

src/task-manager.ts — implemented three stubbed methods:

  • remove — deletes by id, returns true/false.
  • update — returns false for unknown ids; applies only explicitly-present fields (!== undefined) so omitted keys don't clobber existing values.
  • sortBy — rank tables for priority (high→medium→low) and status, timestamp comparison for createdAt. Non-mutating (copies before sort); stable sort preserves insertion order on ties.

src/date-utils.tsformatRelative rounds day deltas with Math.round(Math.abs(diffHours) / 24), so 36 hours reads as "2 days ago" and past/future directions are symmetric.

src/validator.ts

  • isEmail — TLD cap widened from {2,4} to {2,} and domain modelled as explicit labels, so .museum and multi-level subdomains validate; labels can't start/end with a hyphen.
  • isUrl — dropped the port === "" restriction (it wrongly rejected http://localhost:3000); the http/https protocol allow-list still enforces the intended restriction.

Verification

  • bun test60 pass, 0 fail (70 assertions, 5 files)
  • tsc --noEmit → clean
  • Reviewed by the review subagent (verdict: no blockers). Two consistency Warnings it raised — formatRelative future-direction asymmetry and truncate whitespace handling — were fixed in the second commit.

Assumptions

  • sortBy("status") ordering (pending→in_progress→completed) is not covered by tests; chose the natural lifecycle order.
  • update cannot clear a field to undefined (an absent key and an explicit undefined are indistinguishable) — only matters if clearing is ever required.

Notes for follow-up (out of scope, not blocking)

  • isEmail/isUrl are syntactic format checks, not security boundaries — isUrl accepts any http(s) host and should not be relied on as an SSRF control.
  • The newly-fixed future-direction and tab/newline cases would be worth adding as regression tests.

- calculator: divide now throws on division by zero instead of returning Infinity
- string-utils: wordCount splits on \s+ (collapses consecutive whitespace);
  implement truncate with word-boundary breaking, ellipsis budget, and
  guaranteed output length <= maxLength
- task-manager: implement TaskManager.remove, update, and sortBy
  (priority/status/createdAt ordering)
- date-utils: formatRelative rounds day deltas (Math.round on abs hours) so
  36h reads as '2 days ago' and past/future are symmetric
- validator: isEmail accepts long TLDs and multi-level subdomains;
  isUrl accepts URLs with ports (protocol allow-list still enforced)

All 60 tests pass. No test files or dependencies modified.
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