Skip to content

Fixed flaky scheduled publishing tests near midnight#26794

Merged
cmraible merged 5 commits intomainfrom
cmraible/fix-schedule-midnight
Mar 12, 2026
Merged

Fixed flaky scheduled publishing tests near midnight#26794
cmraible merged 5 commits intomainfrom
cmraible/fix-schedule-midnight

Conversation

@cmraible
Copy link
Copy Markdown
Collaborator

@cmraible cmraible commented Mar 12, 2026

Summary

  • Fixed 4 flaky browser tests in publishing.spec.js that fail daily near midnight UTC
  • Root cause: When scheduling a post to publish in the future, the timepicker in admin defaults to now + 10 minutes. Tests schedule posts by changing the scheduled time to 00:00 — a time that is usually in the past — and the UI autocorrects it to "a few seconds from now." But when running within ~10 minutes of midnight, the default scheduled date (now + 10 min) rolls to tomorrow — making 00:00 tomorrow still in the future, so no auto-correction occurs.
  • Fix: Explicitly pass yesterday's date alongside time: '00:00', ensuring the resulting datetime is always in the past regardless of when the tests run
  • Affected tests: "At the scheduled time" (page), "Scheduled Publish and email", "Scheduled Publish only", "Scheduled Email only"

The tests set time to 00:00 expecting auto-correction to 5 seconds
from now, but near midnight the default schedule date (now + 10 min)
rolls to tomorrow, making 00:00 tomorrow still in the future.
Fixed by explicitly passing today's date alongside the time.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 12, 2026

Walkthrough

Added a new scheduleAsap(page, options = {}) helper in the browser test file that schedules a post by setting date to yesterday (formatted yyyy-MM-dd) and time to 00:00, then delegating to publishPost with merged options. Updated multiple tests to use scheduleAsap instead of calling publishPost directly with time: '00:00'. Net change: +10/-8 lines.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the specific issue fixed: flaky scheduled publishing tests that fail near midnight UTC, directly matching the main changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description clearly explains the root cause of flaky tests (midnight UTC scheduling issue), the fix (explicitly passing yesterday's date), and lists all affected test cases, directly relating to the changeset.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cmraible/fix-schedule-midnight
📝 Coding Plan for PR comments
  • Generate coding plan

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.

@cmraible cmraible marked this pull request as ready for review March 12, 2026 01:35
@ErisDS
Copy link
Copy Markdown
Member

ErisDS commented Mar 12, 2026

🤖 Velo CI Failure Analysis

Classification: 🟠 SOFT FAIL

  • Workflow: CI
  • Failed Step: Run Playwright tests locally
  • Run: View failed run
    What failed: CI failure - likely code issue
    Why: The failure appears to be related to code changes. Check the error output for details.
    Action:
    Review the error logs and fix the issue in your code.

publishPost waits for the schedule summary text to change after
setting the date. Using today's date was a no-op (default schedule
is already today), causing the assertion to time out.
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.

🧹 Nitpick comments (1)
ghost/core/test/e2e-browser/admin/publishing.spec.js (1)

7-11: Well-designed fix for the midnight flakiness issue.

The approach is sound: using yesterday's date ensures the composed datetime is always in the past, regardless of when tests run. The comment clearly documents both the "what" and "why", including the subtle reason for using yesterday instead of today (avoiding a no-op when publishPost waits for the schedule summary to change).

Minor readability suggestion: the one-liner is long. Consider breaking it for easier scanning.

🔧 Optional: Multi-line formatting
-const scheduleAsap = (page, options = {}) => publishPost(page, {date: DateTime.now().minus({days: 1}).toFormat('yyyy-MM-dd'), time: '00:00', ...options});
+const scheduleAsap = (page, options = {}) => publishPost(page, {
+    date: DateTime.now().minus({days: 1}).toFormat('yyyy-MM-dd'),
+    time: '00:00',
+    ...options
+});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ghost/core/test/e2e-browser/admin/publishing.spec.js` around lines 7 - 11,
The one-line scheduleAsap helper is correct but hard to scan; refactor the arrow
function into multiple lines for readability by splitting the date construction
and options merge: create a local const scheduledDate =
DateTime.now().minus({days: 1}).toFormat('yyyy-MM-dd') and then return
publishPost(page, { date: scheduledDate, time: '00:00', ...options }); (update
the scheduleAsap declaration accordingly) so the intent in scheduleAsap and the
use of publishPost are clearer.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@ghost/core/test/e2e-browser/admin/publishing.spec.js`:
- Around line 7-11: The one-line scheduleAsap helper is correct but hard to
scan; refactor the arrow function into multiple lines for readability by
splitting the date construction and options merge: create a local const
scheduledDate = DateTime.now().minus({days: 1}).toFormat('yyyy-MM-dd') and then
return publishPost(page, { date: scheduledDate, time: '00:00', ...options });
(update the scheduleAsap declaration accordingly) so the intent in scheduleAsap
and the use of publishPost are clearer.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4733228a-5f9b-49ed-95f1-c3150137efcd

📥 Commits

Reviewing files that changed from the base of the PR and between b4abf5f and 1167303.

📒 Files selected for processing (1)
  • ghost/core/test/e2e-browser/admin/publishing.spec.js

@cmraible cmraible enabled auto-merge (squash) March 12, 2026 15:11
@cmraible cmraible merged commit 54cb356 into main Mar 12, 2026
30 checks passed
@cmraible cmraible deleted the cmraible/fix-schedule-midnight branch March 12, 2026 15:20
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