Skip to content

fix: repair failing utility-library tests across 5 modules - #340

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2176-1789229826
Open

fix: repair failing utility-library tests across 5 modules#340
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2176-1789229826

Conversation

@stooit

@stooit stooit commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 failing tests in the utility library. 60/60 tests now pass, tsc --noEmit is clean, and no previously-passing tests were broken. No test files were modified and no dependencies were added.

Changes by module

  • src/calculator.tsdivide now throws Error("Division by zero") on b === 0 instead of silently returning Infinity/NaN.
  • src/date-utils.ts — fixed off-by-one in relative-day formatting: the day bucket used Math.floor(diffHours / 24) (36h → "1 day"); now rounds at format time so 36h correctly reads "2 days ago".
  • src/string-utils.ts — implemented truncate (breaks on word boundary, ellipsis counts toward maxLength, returns unchanged when within limit). Also fixed wordCount to split on /\s+/ after trimming so runs of whitespace (incl. tabs/newlines) count as one separator.
  • src/task-manager.ts — implemented remove (true/false on delete), update (applies only present keys, false if id absent), and sortBy (priority high→medium→low, status, ascending createdAt; sorts a copy so the internal Map order is untouched).
  • src/validator.tsisEmail now accepts long TLDs and subdomains (old {2,4} cap rejected .museum) while still tightening malformed domains like a..com; isUrl now accepts explicit ports (e.g. http://localhost:3000) while keeping the http/https scheme allowlist.

Assumptions

  • Interpreted each function's contract from the assertions in test/ where the source lacked a spec (notably truncate word-boundary behaviour and sortBy ordering).
  • sortBy("status") ordering is not asserted by any test; chose a reasonable fixed ranking.
  • Kept the change set to exactly what the tests require, per the task constraint.

Reviewer notes (out-of-scope edge cases, non-blocking)

A review pass flagged edge cases the tests don't cover — left as-is to respect the "fix only what tests require" constraint:

  • truncate with a negative/NaN maxLength behaves oddly (slice offset semantics); no test exercises this.
  • isUrl/isEmail validate syntax only — not SSRF/injection guards. Callers using them to gate server-side requests or output should add their own allowlist/sanitisation.
  • divide only guards 0, not NaN divisors.
  • update treats an explicit {field: undefined} as a no-op rather than clearing the field.

Testing

60 pass
 0 fail
Ran 60 tests across 5 files.

- calculator: divide throws on division by zero instead of returning Infinity/NaN
- date-utils: fix off-by-one in relative-day formatting (round at format time)
- string-utils: implement truncate (word-boundary, ellipsis in budget); fix wordCount whitespace handling
- task-manager: implement remove/update/sortBy
- validator: allow long TLDs/subdomains in isEmail; allow ports in isUrl

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