Skip to content

test: fix cron email CI expectations#1853

Merged
riderx merged 2 commits into
mainfrom
codex/fix-cron-email-tests
Mar 25, 2026
Merged

test: fix cron email CI expectations#1853
riderx merged 2 commits into
mainfrom
codex/fix-cron-email-tests

Conversation

@riderx
Copy link
Copy Markdown
Member

@riderx riderx commented Mar 25, 2026

Summary (AI generated)

  • align /triggers/cron_email test expectations with the current validation order
  • skip Bento-dependent preference fan-out assertions when Bento is intentionally unavailable in CI
  • reset email preference state before and after each test and document the file as isolated/write-heavy in the test matrix

Motivation (AI generated)

The backend test workflow was failing because several cron email tests asserted response shapes that no longer match the current handler behavior, and one preference test assumed Bento-backed notification fan-out was active in CI. That created deterministic failures that looked like flaky test interactions.

Business Impact (AI generated)

This restores green CI for the backend suite, reduces noise around false regression failures, and makes the email preference tests safer to run in parallel by containing their user-state mutations.

Test Plan (AI generated)

  • Run bun lint
  • Run bun lint:backend
  • Run bun run supabase:with-env -- bunx vitest run tests/email-preferences.test.ts tests/error-cases.test.ts tests/trigger-error-cases.test.ts
  • Run bun run test:all

Generated with AI

Summary by CodeRabbit

  • Tests
    • Improved parallelization compatibility by making user-record tests isolated.
    • Centralized and standardized default email-preferences setup and resets.
    • Refined lifecycle hooks to reset state before and after each test (and at teardown).
    • Added conditional gating for integration-style preference tests when external config is absent.
    • Updated several error-case assertions to match current validation behavior.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 306f7914-b74a-45e7-90b1-08575bc48362

📥 Commits

Reviewing files that changed from the base of the PR and between 21be798 and 8e468e8.

📒 Files selected for processing (1)
  • tests/email-preferences.test.ts

📝 Walkthrough

Walkthrough

Refactors email-preferences tests to use isolated user state and a shared reset helper, adds Bento-configuration gating for certain cron_email tests, and updates cron_email error-case expectations and test inputs to reflect new validation/error behaviors.

Changes

Cohort / File(s) Summary
Test matrix
tests/TEST_USER_MATRIX.md
Changed email-preferences test user classification from `R
Email preferences tests
tests/email-preferences.test.ts
Added defaultEmailPreferences and resetEmailPreferences(); moved resets into beforeEach/afterEach (plus afterAll); introduced isBentoConfiguredForTests() gating; adjusted Vitest hook imports and test refactor for multi-preference update.
cron_email error cases
tests/error-cases.test.ts, tests/trigger-error-cases.test.ts
Updated assertions and test inputs for cron_email error scenarios: changed expected error codes and request type values to match new validation paths (invalid_stats_type, missing_version_id).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰
I nibbled code near midnight light,
Reset the prefs to make tests right,
Bento sleeps—some tests will pause,
Each case isolated, no shared claws,
Hop, assert, and green lights in sight.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description covers motivation, changes, and test plan execution, but lacks the structured sections (Summary, Test plan, Screenshots, Checklist) defined in the template. Reformat the description to follow the template structure with explicit Summary, Test plan, Screenshots, and Checklist sections to improve clarity and consistency.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: fixing cron email CI test expectations to align with current validation behavior.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-cron-email-tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/email-preferences.test.ts`:
- Around line 39-44: The helper resetEmailPreferences silently ignores Supabase
errors; update it (the async function resetEmailPreferences that calls
getSupabaseClient().from('users').update(...).eq('id', USER_ID_EMAIL_PREFS)) to
capture the update response, check for response.error (and/or non-OK status),
and throw or fail the test when an error exists so the reset cannot silently
fail and leak state to other tests; ensure the error message includes context
(e.g., "resetEmailPreferences failed") and the Supabase error details.
- Around line 54-65: Reorder the test lifecycle hooks so they follow the
required sequence: beforeAll → beforeEach → afterEach → afterAll; specifically
move the beforeEach(async () => { await resetEmailPreferences() }) so it appears
before the afterEach and afterAll blocks (retaining the afterEach(async () => {
await resetEmailPreferences() }) and afterAll(async () => { await
resetAppData(APPNAME_PREFS); await resetEmailPreferences() }) unchanged),
ensuring the hooks around resetEmailPreferences and resetAppData remain but
follow the correct hook order.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3cf6bb57-0646-42d6-ae91-6974cb363677

📥 Commits

Reviewing files that changed from the base of the PR and between 55662cb and 21be798.

📒 Files selected for processing (4)
  • tests/TEST_USER_MATRIX.md
  • tests/email-preferences.test.ts
  • tests/error-cases.test.ts
  • tests/trigger-error-cases.test.ts

Comment thread tests/email-preferences.test.ts
Comment thread tests/email-preferences.test.ts Outdated
@sonarqubecloud
Copy link
Copy Markdown

@riderx riderx merged commit 8361662 into main Mar 25, 2026
15 checks passed
@riderx riderx deleted the codex/fix-cron-email-tests branch March 25, 2026 02:19
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