Skip to content

Fixed flaky data seeder test#26985

Open
kevinansfield wants to merge 1 commit intomainfrom
codex/fix-flaky-data-generator-test
Open

Fixed flaky data seeder test#26985
kevinansfield wants to merge 1 commit intomainfrom
codex/fix-flaky-data-generator-test

Conversation

@kevinansfield
Copy link
Copy Markdown
Member

@kevinansfield kevinansfield commented Mar 26, 2026

no issue

When seeder database timestamp strings were reparsed in non-UTC CI environments, they could shift into the future and make Faker reject inverted date ranges causing flaky CI failures. Parsing those values as UTC and guarding the date range logic keeps the data generator test stable across timezones.

What this does

  • parse seeder database timestamp strings as UTC instead of local time
  • guard date generation against inverted ranges when referenced records are at or after the current time
  • add regression coverage for timezone parsing and date range handling

Example flaky run: https://github.com/TryGhost/Ghost/actions/runs/23592298819/job/68700344677?pr=26958

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 26, 2026

Walkthrough

This pull request refactors date handling across multiple seeder importer files to use a centralized utility. The database-date utility module is enhanced with two new static methods: parse() for standardized date parsing and randomBetween() for generating random dates within a range. Across fifteen importer files, direct new Date() constructor calls are replaced with dateToDatabaseString.parse(), and faker.date.between() calls are replaced with dateToDatabaseString.randomBetween(). Additionally, a paging loop bug in the members-stripe-customers-subscriptions-importer is fixed, and timezone-aware test coverage is added for the new date parsing functionality.

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Title check ✅ Passed The title describes fixing a flaky data seeder test, which aligns with the PR's core objective of stabilizing timezone-dependent timestamp parsing, though it doesn't capture the technical detail that it involves UTC parsing and date range guarding.
Description check ✅ Passed The description clearly relates to the changeset, explaining the timezone parsing issue and the solution implemented across the seeder files.

✏️ 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-flaky-data-generator-test

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

When seeder database timestamp strings were reparsed in non-UTC CI environments, they could shift into the future and make Faker reject inverted date ranges. Parsing those values as UTC and guarding the date range logic keeps the data generator test stable across timezones.
@kevinansfield kevinansfield changed the title Fix timezone parsing in data seeder timestamps Fixed timezone parsing in data seeder timestamps Mar 26, 2026
@kevinansfield kevinansfield force-pushed the codex/fix-flaky-data-generator-test branch from ce82048 to 554eb8a Compare March 26, 2026 13:45
@kevinansfield kevinansfield changed the title Fixed timezone parsing in data seeder timestamps Fixed flaky data seeder test Mar 26, 2026
@sonarqubecloud
Copy link
Copy Markdown

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/core/server/data/seeders/importers/members-click-events-importer.js (1)

53-55: LGTM on the parse change, but note the inconsistency with other importers.

Line 53 correctly uses dateToDatabaseString.parse(). However, line 55 still uses faker.date.between() directly while other importers in this PR switched to dateToDatabaseString.randomBetween(). This may be intentional since the 15-minute window ensures a valid forward range, but consider updating for consistency.

♻️ Optional: Use randomBetween for consistency
-        const openedAt = dateToDatabaseString.parse(this.model.opened_at);
-        const laterOn = new Date(openedAt.getTime() + 1000 * 60 * 15);
-        const clickTime = faker.date.between(openedAt.getTime(), laterOn.getTime()); //added getTime here because it threw random errors
+        const openedAt = dateToDatabaseString.parse(this.model.opened_at);
+        const laterOn = new Date(openedAt.getTime() + 1000 * 60 * 15);
+        const clickTime = dateToDatabaseString.randomBetween(openedAt, laterOn);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@ghost/core/core/server/data/seeders/importers/members-click-events-importer.js`
around lines 53 - 55, The code uses faker.date.between to compute clickTime
while other importers use dateToDatabaseString.randomBetween; replace the faker
call with dateToDatabaseString.randomBetween to keep behavior consistent (use
openedAt and laterOn as the range to preserve the 15-minute window), i.e.
compute clickTime via dateToDatabaseString.randomBetween(openedAt, laterOn)
instead of faker.date.between(openedAt.getTime(), laterOn.getTime()); keep
openedAt and laterOn as defined so the time window is unchanged.
🤖 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/core/server/data/seeders/importers/members-click-events-importer.js`:
- Around line 53-55: The code uses faker.date.between to compute clickTime while
other importers use dateToDatabaseString.randomBetween; replace the faker call
with dateToDatabaseString.randomBetween to keep behavior consistent (use
openedAt and laterOn as the range to preserve the 15-minute window), i.e.
compute clickTime via dateToDatabaseString.randomBetween(openedAt, laterOn)
instead of faker.date.between(openedAt.getTime(), laterOn.getTime()); keep
openedAt and laterOn as defined so the time window is unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 29ad4bc7-ecd4-451b-be7a-373fdda1f968

📥 Commits

Reviewing files that changed from the base of the PR and between e6fbbb8 and 554eb8a.

📒 Files selected for processing (17)
  • ghost/core/core/server/data/seeders/importers/comment-reports-importer.js
  • ghost/core/core/server/data/seeders/importers/comments-importer.js
  • ghost/core/core/server/data/seeders/importers/email-batches-importer.js
  • ghost/core/core/server/data/seeders/importers/email-recipients-importer.js
  • ghost/core/core/server/data/seeders/importers/emails-importer.js
  • ghost/core/core/server/data/seeders/importers/members-click-events-importer.js
  • ghost/core/core/server/data/seeders/importers/members-created-events-importer.js
  • ghost/core/core/server/data/seeders/importers/members-feedback-importer.js
  • ghost/core/core/server/data/seeders/importers/members-login-events-importer.js
  • ghost/core/core/server/data/seeders/importers/members-status-events-importer.js
  • ghost/core/core/server/data/seeders/importers/members-stripe-customers-importer.js
  • ghost/core/core/server/data/seeders/importers/members-stripe-customers-subscriptions-importer.js
  • ghost/core/core/server/data/seeders/importers/members-subscribe-events-importer.js
  • ghost/core/core/server/data/seeders/importers/members-subscription-created-events-importer.js
  • ghost/core/core/server/data/seeders/importers/offer-redemptions-importer.js
  • ghost/core/core/server/data/seeders/utils/database-date.js
  • ghost/core/test/unit/server/data/seeders/data-generator.test.js

@kevinansfield kevinansfield requested a review from 9larsons March 26, 2026 15:36
@kevinansfield kevinansfield added the ok to merge for me You can merge this on my behalf if you want. label Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok to merge for me You can merge this on my behalf if you want.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant