Skip to content

Updated labs tests to not rely on specific flags#26622

Merged
troyciesco merged 2 commits intomainfrom
update-GA-labs-test
Mar 4, 2026
Merged

Updated labs tests to not rely on specific flags#26622
troyciesco merged 2 commits intomainfrom
update-GA-labs-test

Conversation

@troyciesco
Copy link
Copy Markdown
Contributor

@troyciesco troyciesco commented Feb 26, 2026

no ref

  • a test for labs ensures that config values take precedence over GA keys. However, the test referenced the announcementBar flag was removed in Removed announcementBar feature flag #26196. That means this test was looking at a state that wasn't really true
  • instead, we can check for the first item in the GA_KEYS list. If there's nothing in the list, the test can be skipped.
  • a few other tests had this same issue, so this PR updates them as well
  • there was a test for alpha flags that wasn't actually doing anything, so it's deleted

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.js to stop hard-coding specific labs flag names and instead derive test flags from labs.WRITABLE_KEYS_ALLOWLIST and labs.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.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 26, 2026

Walkthrough

The 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)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: updating labs tests to avoid hardcoding specific flags, which aligns with the changeset's core objective.
Description check ✅ Passed The description clearly explains the rationale for the changes, referencing the removal of the announcementBar flag and the shift to dynamic flag selection from GA_KEYS and WRITABLE_KEYS_ALLOWLIST.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 update-GA-labs-test

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.

@troyciesco troyciesco force-pushed the update-GA-labs-test branch 2 times, most recently from 26c87d0 to 63441a4 Compare February 26, 2026 19:24
@troyciesco troyciesco changed the title Updated labs tests to not rely on a specific flags Updated labs tests to not rely on specific flags Feb 26, 2026
}

// 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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@troyciesco troyciesco marked this pull request as ready for review February 26, 2026 19:39
@troyciesco troyciesco requested a review from EvanHahn February 26, 2026 20:12
@EvanHahn
Copy link
Copy Markdown
Contributor

I'll plan to review this next week. Let me know if you want me to look sooner.

Copy link
Copy Markdown
Contributor

@EvanHahn EvanHahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we should return after skipping.

Suggested change
this.skip();
this.skip();
return;

The same comment applies to the other skips.

@troyciesco troyciesco force-pushed the update-GA-labs-test branch from f67ad87 to 39407b3 Compare March 4, 2026 21:04
@troyciesco troyciesco force-pushed the update-GA-labs-test branch from 39407b3 to ef1b592 Compare March 4, 2026 21:05
@troyciesco troyciesco enabled auto-merge (squash) March 4, 2026 21:05
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/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

📥 Commits

Reviewing files that changed from the base of the PR and between f67ad87 and ef1b592.

📒 Files selected for processing (1)
  • ghost/core/test/unit/shared/labs.test.js

@troyciesco troyciesco merged commit c386250 into main Mar 4, 2026
34 checks passed
@troyciesco troyciesco deleted the update-GA-labs-test branch March 4, 2026 21:31
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