Skip to content

fix(test): wait for email HTML body in Email_settings spec#41893

Open
wyattwalter wants to merge 5 commits into
releasefrom
ww-fix-email-settings-html-guard
Open

fix(test): wait for email HTML body in Email_settings spec#41893
wyattwalter wants to merge 5 commits into
releasefrom
ww-fix-email-settings-html-guard

Conversation

@wyattwalter

@wyattwalter wyattwalter commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Email_settings_Spec fails intermittently in CI (~25-35% of runs) when it shares a duration-balanced shard with heavy specs. It's a null-handling bug in the spec's email flow, exposed under maildev/SMTP contention.

Root cause

waitForEmail matches an email by subject + recipient, then hands it to the test. Under contention maildev can surface an email's metadata before its HTML part is parsed, so the matched email's .html is undefined. Tests #3#6 then do:

const emailHtml = email.html;          // undefined
const match = emailHtml.match(/.../);  // TypeError, thrown inside .then()

That throw is an unhandled promise rejection that aborts the test (the wrapping try/catch is inert against async Cypress failures). Captured CI stack: Email_settings_Spec.ts test #4 (To verify invite workspace email); the same email.html.match pattern is in tests #3, #5 and #6.

Fix

Fix it at the source rather than masking it. Add an opt-in requireHtml flag to waitForEmail: when set, a matched email whose HTML body isn't populated yet is treated as not yet delivered, so polling continues until the body arrives (or the existing timeout). Tests #3#6 opt in; their email-body assertions then run for real on a complete email.

(An earlier revision of this PR used email.html || "", but that only stopped the crash by silently skipping the invite-link verification when the body was missing — masking the flake. Reverted in favor of the helper-level fix.)

waitForEmail is identical in CE and EE, so this lands in CE and the hourly sync carries it to EE. The new flag is optional and defaults to current behavior, so other callers (including this spec's test #2, which reads email.text) are unaffected.

Validation

Attribution and the fix were verified on appsmith-ee via amplified /ci-test-limit runs (multiple copies of the spec downstream of a heavy git spec in one shard): the unfixed baseline reproduced the failure at the exact line above.

Ref APP-15291

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/27509234477
Commit: 56deaca
Cypress dashboard.
Tags: @tag.Email
Spec:


Sun, 14 Jun 2026 19:36:07 UTC

Summary by CodeRabbit

  • Tests
    • Improved email-related test robustness: four end-to-end flows (password reset, workspace invite, application invite — developer role, and application invite — view role) now explicitly require the HTML portion of delivered emails, reducing flakiness and better validating email content.
  • Chores
    • Updated limited-test configuration to run the client-side email regression spec during focused CI runs.

Automation

/ok-to-test tags="@tag.Email"

Email_settings_Spec flakes (~25-35% in CI) when it shares a shard with
heavy specs. Under maildev/SMTP contention, waitForEmail returns an email
whose .html is not yet populated; `const emailHtml = email.html` followed
by `emailHtml.match(...)` then throws a TypeError synchronously inside the
.then callback, which surfaces as an unhandled promise rejection and
aborts the test. The wrapping try/catch is inert against async Cypress
failures. Stack: Email_settings_Spec.ts:293 (test #4); the same
email.html -> .match pattern is in tests #3, #5 and #6.

Default email.html to an empty string so .match() returns null and the
existing if-guards / else cy.log branches handle a missing body without
throwing. Validated via an amplified /ci-test-limit run on appsmith-ee.

Ref APP-15291

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Add an optional requireHtml flag to AggregateHelper.waitForEmail so matches can require a non-empty HTML body; update four Cypress tests to call waitForEmail(..., requireHtml: true) for password reset and invite flows.

Changes

Email wait/matching updates

Layer / File(s) Summary
waitForEmail options and matching predicate
app/client/cypress/support/Pages/AggregateHelper.ts
waitForEmail options now include requireHtml?: boolean; Maildev email typing includes html?: string; matching predicate adds an htmlReady guard that is required when requireHtml is true.
Tests now require HTML on email matches
app/client/cypress/e2e/Regression/ClientSide/AdminSettings/Email_settings_Spec.ts
Four tests (password reset, workspace invite, application invite — developer, application invite — view) now invoke waitForEmail with requireHtml: true.
Limited tests config updated
app/client/cypress/limited-tests.txt
Replaced the limited-test entry to run the client-side Email_settings_Spec.ts instead of the server-side BooleanEnum_Spec.ts.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

ok-to-test

Suggested reviewers

  • sondermanish

Poem

A tiny flag that stands its post,
Waiting for HTML the tests love most,
Four waits now mindful, patient, true,
Emails with bodies come into view. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

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.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding HTML body requirement to email waiting in the Email_settings spec.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed PR description thoroughly documents the intermittent failure root cause, the fix rationale, and validation approach with clear technical context.

✏️ 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 ww-fix-email-settings-html-guard

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Supersedes the earlier `email.html || ""` guard, which only stopped the
crash by silently skipping the invite-link verification when the body was
missing — masking the flake rather than fixing it.

Root cause: under maildev/SMTP contention waitForEmail matched an email by
subject+recipient before its HTML part was populated, so `email.html` was
undefined and `emailHtml.match(...)` threw inside the .then callback
(unhandled rejection, abort). Stack: Email_settings_Spec.ts test #4; same
pattern in #3/#5/#6.

Fix at the source: add an opt-in `requireHtml` flag to waitForEmail so a
matched-but-bodyless email is treated as not-yet-delivered and polling
continues until the HTML body arrives (or the existing timeout). Tests
#3-#6 opt in; the email-body assertions then run for real on a complete
email. Reverted the `|| ""` guard since the body is now guaranteed present.

Ref APP-15291

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@wyattwalter wyattwalter changed the title fix(test): guard undefined email.html in Email_settings spec fix(test): wait for email HTML body in Email_settings spec Jun 12, 2026
wyattwalter and others added 2 commits June 12, 2026 11:17
…-keys)

Ref APP-15291

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…merge)

Ref APP-15291

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@wyattwalter

Copy link
Copy Markdown
Contributor Author

/ci-test-limit

@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/27428547269.
Cypress dashboard url: Click here!
All cypress tests have passed 🎉🎉🎉

ci-test-limit validation is complete; restore limited-tests.txt to its
default so the PR contains only the waitForEmail/Email_settings fix.

Ref APP-15291

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@subrata71 subrata71 added the ok-to-test Required label for CI label Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Required label for CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants