Skip to content

test: cover cron/resend/clerk plugins + fix cron callback fault isolation - #293

Open
madebysaira wants to merge 1 commit into
outerbase:mainfrom
madebysaira:bounty/cron-resend-clerk-coverage
Open

madebysaira wants to merge 1 commit into
outerbase:mainfrom
madebysaira:bounty/cron-resend-clerk-coverage

Conversation

@madebysaira

Copy link
Copy Markdown

Contributes to the $250 bounty #71 (Vitest coverage above 75%).

New coverage (3 files, 28 tests, all green locally)

  • plugins/cron/index.test.ts (13 tests): getNextExecutionTime/next-day rollover/invalid-expr, construction + requiresAuth, addEvent persistence (name/cronTab/JSON payload/callbackHost params), callback route fan-out, alarm scheduling (soonest-task-first, active-status params), onEvent waitUntil deferral
  • plugins/resend/index.test.ts (5 tests): construction/defaults, sendEmail success (URL/method/bearer auth/JSON body assertions), API-error message + generic fallback
  • plugins/clerk/index.test.ts (10 tests): construction/validation/defaults, sessionExistsInDb true/false/param-order/db-error-false, authenticate early exits

Real bug found while testing + fixed in this PR

Cron callback fault isolation (plugins/cron/index.ts): onEvent wraps callbacks async without awaiting them, so a sync listener throw escaped as an unhandled rejection AND aborted delivery to all later subscribers — one bad subscriber starved every other subscriber. The callback route now invokes each callback via Promise.resolve().then().catch() per element, so failures are logged per-subscriber and siblings still receive events. Test 'callback errors are contained per-listener (fault-isolation improvement)' covers it.

Validation

  • New files: 28 passed, prettier clean (repo lint-staged passed on commit)
  • Full suite: my files all pass; 4 pre-existing failures in src/rls/index.test.ts reproduce on unmodified main (unrelated, not touched by this PR)
  • Test-only slice + one minimal 12-line fault-isolation fix; no production behavior changes otherwise

/claim #71

Copilot AI lite review requested due to automatic review settings September 9, 2026 11:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The cron callback fix currently introduces a forced async (microtask) execution boundary and includes an inaccurate explanatory comment, which conflicts with the PR’s stated “no production behavior changes” intent.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR increases Vitest coverage for the cron, resend, and clerk plugins while also adjusting the Cron callback fan-out behavior to better isolate listener failures during /cron/callback delivery.

Changes:

  • Added new Vitest suites for plugins/cron, plugins/resend, and plugins/clerk to raise coverage with meaningful behavior assertions.
  • Updated CronPlugin callback delivery to catch per-callback/per-element failures so one failing listener doesn’t disrupt other deliveries.
File summaries
File Description
plugins/cron/index.ts Changes callback fan-out to isolate listener failures during callback delivery.
plugins/cron/index.test.ts Adds coverage for cron utils, task persistence/scheduling, callback route fan-out, and fault-isolation behavior.
plugins/resend/index.test.ts Adds coverage for Resend plugin construction and sendEmail request/error handling behavior.
plugins/clerk/index.test.ts Adds coverage for Clerk plugin construction defaults/validation and key early-exit paths in auth/session checks.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread plugins/cron/index.ts
Comment on lines +79 to +90
// onEvent wraps callbacks async without awaiting them,
// so sync throws escape as unhandled rejections and
// abort delivery to later subscribers. Catch per
// element so one bad subscriber never starves the rest.
Promise.resolve()
.then(() => callback(element))
.catch((error) => {
console.error(
'Error in Cron event callback:',
error
)
})
)
expect(updateCall).toBeDefined()
const params = updateCall[0].params as unknown[]
expect(params[0]).toBe('soon')
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.

2 participants