Skip to content

fix: repair all failing tests across the utility library - #338

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

fix: repair all failing tests across the utility library#338
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2174-1789057098

Conversation

@stooit

@stooit stooit commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 failing tests across the 5 source modules so the full suite passes (60 pass / 0 fail, tsc --noEmit clean). No test files modified, no dependencies added.

Changes

  • src/calculator.tsdivide throws Error("Division by zero") when b === 0 instead of silently returning Infinity.
  • src/string-utils.ts
    • Implemented truncate: unchanged when within maxLength; otherwise reserves 3 chars for "..." (ellipsis counts toward the limit), cuts at the last word boundary with a hard-cut fallback, trims trailing whitespace. Hardened against negative maxLength (clamped to 0) and leading-whitespace inputs.
    • wordCount trims then splits on /\s+/, collapsing whitespace runs.
  • src/task-manager.ts — Implemented remove (Map.delete), update (returns false for unknown ids; only assigns fields present in changes), and sortBy (sorts a copy via typed Record<Priority,number>/Record<Status,number> rank maps).
  • src/date-utils.tsdiffDays uses Math.round(Math.abs(diffHours) / 24), fixing the off-by-one that bucketed 24–47h as "1 day".
  • src/validator.tsisEmail TLD quantifier {2,4}{2,} (accepts long TLDs); isUrl drops the port === "" condition so http://localhost:3000 validates, retaining http/https allowlisting.

Assumptions

  • update treats omitted keys as "leave untouched"; clearing description via { description: undefined } is intentionally a no-op.
  • trimStart() deliberately avoided in truncate to keep within-limit/whitespace-only inputs unchanged.

Testing

  • bun test → 60 pass, 0 fail
  • bunx tsc --noEmit → clean

Reviewer notes (out of scope, non-blocking)

  • isEmail is a format check only, not a deliverability/authorisation control.
  • isUrl allowlists the scheme but not the host — SSRF risk if a caller server-side-fetches a user-supplied URL.

- calculator: divide throws on division by zero instead of returning Infinity
- string-utils: implement truncate (word-boundary, ellipsis in budget, negative/leading-whitespace hardening); wordCount collapses whitespace runs
- task-manager: implement remove, update (partial, no field-blanking), sortBy (typed rank maps)
- date-utils: diffDays uses round(abs()) fixing off-by-one day bucketing
- validator: isEmail accepts long TLDs; isUrl allows 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