Updated labs tests to not rely on specific flags#26622
Conversation
WalkthroughThe test file for labs functionality was updated to use dynamic keys instead of hardcoded values. Tests were refactored to verify config precedence over settings using runtime-computed writable flags or GA keys. Skip conditions were added to prevent execution when relevant allowlists or GA keys are empty. Assertions were adjusted to reference the dynamically selected keys in both config injections and expected results. The changes generalize the test scope to validate behavior across any applicable keys rather than a single fixed flag. 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 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 |
26c87d0 to
63441a4
Compare
| } | ||
|
|
||
| // NOTE: this test should be rewritten to test the alpha flag independently of the internal ALPHA_FEATURES list | ||
| // otherwise we end up in the endless maintenance loop and need to update it every time a feature graduates from alpha |
There was a problem hiding this comment.
i think this test wasn't doing anything. enableDeveloperExperiments doesn't seem to change anything about what labs are returned, i think it just controls whether the tab for editing PRIVATE_FEATURES shows up in the UI.
to further check, i create the inverse of this test ("does not return an alpha flag when dev experiments is false") and it failed.
based on how labs works with getAll() returning all beta and private keys, I don't think a test is needed here.
63441a4 to
f67ad87
Compare
|
I'll plan to review this next week. Let me know if you want me to look sooner. |
EvanHahn
left a comment
There was a problem hiding this comment.
LGTM other than one non-blocking comment.
| urlCache: true | ||
| }); | ||
| it('respects the value in config over settings', function () { | ||
| if (labs.WRITABLE_KEYS_ALLOWLIST.length === 0) { |
There was a problem hiding this comment.
praise: I like this. Keeps us from having to change this test if we ever have nothing in the list.
| }); | ||
| it('respects the value in config over settings', function () { | ||
| if (labs.WRITABLE_KEYS_ALLOWLIST.length === 0) { | ||
| this.skip(); |
There was a problem hiding this comment.
nit: we should return after skipping.
| this.skip(); | |
| this.skip(); | |
| return; |
The same comment applies to the other skips.
f67ad87 to
39407b3
Compare
39407b3 to
ef1b592
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ghost/core/test/unit/shared/labs.test.js (1)
37-38: Optional cleanup: consider extracting repeated key-pick setup.Both tests repeat the same “first writable flag” selection pattern. A tiny helper could reduce duplication and keep intent centralized, but this is non-blocking.
Also applies to: 93-94
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ghost/core/test/unit/shared/labs.test.js` around lines 37 - 38, Tests repeat selecting the first writable flag via labs.WRITABLE_KEYS_ALLOWLIST[0]; extract a small helper (e.g., getFirstWritableKey or pickFirstWritableFlag) placed near the top of ghost/core/test/unit/shared/labs.test.js to return labs.WRITABLE_KEYS_ALLOWLIST[0] and replace the repeated expressions in the tests (including the occurrences around lines 37–38 and 93–94) to reduce duplication and centralize intent.
🤖 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/unit/shared/labs.test.js`:
- Around line 37-38: Tests repeat selecting the first writable flag via
labs.WRITABLE_KEYS_ALLOWLIST[0]; extract a small helper (e.g.,
getFirstWritableKey or pickFirstWritableFlag) placed near the top of
ghost/core/test/unit/shared/labs.test.js to return
labs.WRITABLE_KEYS_ALLOWLIST[0] and replace the repeated expressions in the
tests (including the occurrences around lines 37–38 and 93–94) to reduce
duplication and centralize intent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 54998dc1-60dc-4c8c-ad7e-53fbd9888692
📒 Files selected for processing (1)
ghost/core/test/unit/shared/labs.test.js
no ref
announcementBarflag was removed in RemovedannouncementBarfeature flag #26196. That means this test was looking at a state that wasn't really trueGA_KEYSlist. If there's nothing in the list, the test can be skipped.Note
Low Risk
Test-only changes that reduce brittleness by avoiding references to specific feature flags; no production logic is modified.
Overview
Updates
labs.test.jsto stop hard-coding specific labs flag names and instead derive test flags fromlabs.WRITABLE_KEYS_ALLOWLISTandlabs.GA_KEYS, skipping tests when those lists are empty.Removes a brittle/ineffective alpha-flag test and adjusts remaining assertions to validate precedence rules (config overrides settings/GA) using dynamically selected flags.
Written by Cursor Bugbot for commit ef1b592. This will update automatically on new commits. Configure here.