Improved MySQL acceptance test resets#28554
Conversation
no ref The MySQL acceptance suite was spending most of its time rerunning fixture initialization for every Ghost boot. Restoring test data from an in-database baseline keeps the same reset coverage while avoiding repeated knex-migrator init work.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThis PR adds MySQL snapshot functionality to test database utilities for faster reset operations. A new 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
| Command | Status | Duration | Result |
|---|---|---|---|
nx run ghost:test:ci:integration:no-coverage |
✅ Succeeded | 1m 46s | View ↗ |
nx run ghost:test:ci:integration |
✅ Succeeded | 1m 6s | View ↗ |
nx run ghost:test:ci:e2e:no-coverage |
✅ Succeeded | 3m 49s | View ↗ |
nx run ghost:test:ci:e2e |
✅ Succeeded | 3m 44s | View ↗ |
nx run ghost:test:ci:legacy |
✅ Succeeded | 2m 14s | View ↗ |
nx run-many -t lint -p ghost |
✅ Succeeded | 41s | View ↗ |
nx run-many -t test:unit -p ghost |
✅ Succeeded | 32s | View ↗ |
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗
☁️ Nx Cloud last updated this comment at 2026-06-12 16:46:34 UTC
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ghost/core/test/utils/db-utils.js (1)
75-79: ⚡ Quick winLog snapshot restore failures before fallback.
Line 75 catches restore errors and immediately falls back, but drops the original failure context. Adding a debug log here will make intermittent MySQL reset failures much easier to diagnose.
Suggested patch
try { await resetMySQLFromSnapshot(); } catch (err) { + debug('MySQL snapshot reset failed, falling back to force reinit', err); // If it fails, try a normal restore await forceReinit(); await createMySQLSnapshot(); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@ghost/core/test/utils/db-utils.js` around lines 75 - 79, The catch block that falls back to a normal restore currently swallows the original error; update the catch handler to log the caught error (err) before calling forceReinit() and createMySQLSnapshot() so we preserve failure context for debugging. Locate the try/catch around the snapshot restore in db-utils.js and add a debug/error log call that includes a clear message plus the err object (reference the existing catch variable `err` and the surrounding functions `forceReinit` and `createMySQLSnapshot`) so intermittent MySQL reset failures are recorded prior to the fallback.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@ghost/core/test/utils/db-utils.js`:
- Around line 75-79: The catch block that falls back to a normal restore
currently swallows the original error; update the catch handler to log the
caught error (err) before calling forceReinit() and createMySQLSnapshot() so we
preserve failure context for debugging. Locate the try/catch around the snapshot
restore in db-utils.js and add a debug/error log call that includes a clear
message plus the err object (reference the existing catch variable `err` and the
surrounding functions `forceReinit` and `createMySQLSnapshot`) so intermittent
MySQL reset failures are recorded prior to the fallback.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a526d410-eb65-49f5-8724-c929cb73e6ca
📒 Files selected for processing (2)
ghost/core/test/utils/db-utils.jsghost/core/test/utils/e2e-utils.js
- folded snapshot-state invalidation into dropMySQLSnapshots so dropping and invalidating can never drift apart at call sites - hoisted the snapshot cleanup out of teardown's try/catch since both branches ran the identical drop + invalidate pair

Summary
knexMigrator.init({only: 3})for every Ghost boot.e2e-utilsboot helper onto the truncating reset path so it benefits from the same reset behavior.Local runtime data
Initial profiling showed the MySQL suite was spending most of its time in reset lifecycle rather than Ghost boot:
e2e-utilspath also improved locally because it now uses the truncating reset path.Validation
pnpm --dir ghost/core lint:testknexMigrator.initcount 5; wall clock 107.3sNotes
e2e-utils.jschange moves every legacy MySQL e2e boot from a fullknexMigrator.reset+initto the truncating reset path. The behavioral difference: a full reset drops stray tables and repairs schema drift, while the truncate path only deletes rows fromschemaTables + migrations. The full-suite runs above cover this, and the line is severable from the snapshot work if it ever causes flakiness.