Skip to content

Add EditorCapabilityResolver to centralize editor-capability gating#22812

Merged
jkmassel merged 4 commits into
trunkfrom
jkmassel/editor-capability-resolver
May 19, 2026
Merged

Add EditorCapabilityResolver to centralize editor-capability gating#22812
jkmassel merged 4 commits into
trunkfrom
jkmassel/editor-capability-resolver

Conversation

@jkmassel
Copy link
Copy Markdown
Contributor

@jkmassel jkmassel commented Apr 22, 2026

Summary

  • Introduces EditorCapabilityResolver as the single source of truth for whether the theme-styles and third-party-blocks capabilities apply to a site, combining the top-level GutenbergKit feature flag, the remote gutenberg_kit_plugins flag, the per-site capability cache (EditorSettingsRepository), and the user's per-site toggle (SiteSettingsProvider).
  • Returns a Resolved sealed hierarchy (Hidden / Unsupported(reason) / Available(userEnabled, advisory?)) that UI callers can branch on directly to pick the right visibility / disabled-with-reason / advisory-note treatment. Non-UI callers collapse the state via shouldApplyInEditor.
  • Models theme-not-a-block-theme as an advisory attached to Available, not a gate — the pref stays enabled with an informational summary, matching today's behaviour.
  • Wires SiteSettingsFragment through the resolver, replacing two inline conditional chains with pattern matches over Resolved.

Extracted from #22579 — the editor-side consumer (the GutenbergKit config builder) will land in that PR alongside its refactor to an injectable class, so the preloading PR only shows the editor-facing plumbing.

Test plan

  • ./gradlew :WordPress:testJetpackDebugUnitTest --tests "org.wordpress.android.ui.posts.EditorCapabilityResolverTest" passes (17 tests covering the decision tree for both capabilities)
  • Open a site's settings for a WP.com simple site — theme-styles pref visible and toggleable, third-party-blocks pref hidden or disabled per remote flag + capability cache
  • Open settings for a classic-theme site — theme-styles toggle still present, summary shows "not a block theme" advisory
  • Open settings with experimental_block_editor feature flag off — both prefs hidden

Related

@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented Apr 22, 2026

App Icon📲 You can test the changes from this Pull Request in WordPress Android by scanning the QR code below to install the corresponding build.

App NameWordPress Android
Build TypeDebug
Versionpr22812-0e21611
Build Number1488
Application IDorg.wordpress.android.prealpha
Commit0e21611
Installation URL4lnkdt9do2u20
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented Apr 22, 2026

App Icon📲 You can test the changes from this Pull Request in Jetpack Android by scanning the QR code below to install the corresponding build.

App NameJetpack Android
Build TypeDebug
Versionpr22812-0e21611
Build Number1488
Application IDcom.jetpack.android.prealpha
Commit0e21611
Installation URL4esep7cof99eg
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented Apr 22, 2026

🤖 Build Failure Analysis

This build has failures. Claude has analyzed them - check the build annotations for details.

@jkmassel jkmassel force-pushed the jkmassel/editor-capability-resolver branch 2 times, most recently from 6968ec2 to 7af2cc5 Compare April 22, 2026 18:35
@jkmassel jkmassel added Gutenberg Editing and display of Gutenberg blocks. Site Management Tech Debt labels Apr 22, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 37.24%. Comparing base (076015c) to head (0e21611).
⚠️ Report is 1 commits behind head on trunk.

Additional details and impacted files
@@            Coverage Diff             @@
##            trunk   #22812      +/-   ##
==========================================
+ Coverage   37.22%   37.24%   +0.02%     
==========================================
  Files        2318     2319       +1     
  Lines      124564   124604      +40     
  Branches    16917    16927      +10     
==========================================
+ Hits        46371    46413      +42     
+ Misses      74443    74441       -2     
  Partials     3750     3750              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jkmassel jkmassel force-pushed the jkmassel/editor-capability-resolver branch from 7af2cc5 to 34887ae Compare April 22, 2026 18:59
Base automatically changed from jkmassel/site-settings-rust to trunk May 4, 2026 15:04
@jkmassel jkmassel requested a review from a team as a code owner May 4, 2026 15:04
@jkmassel jkmassel requested review from adalpari and removed request for a team May 4, 2026 15:04
Copy link
Copy Markdown
Contributor

@adalpari adalpari left a comment

Choose a reason for hiding this comment

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

It looks like there are some merge conflicts. Could you take a look at them?

@jkmassel jkmassel force-pushed the jkmassel/editor-capability-resolver branch from 34887ae to d5911f3 Compare May 5, 2026 23:23
@dangermattic
Copy link
Copy Markdown
Collaborator

1 Warning
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

@jkmassel jkmassel force-pushed the jkmassel/editor-capability-resolver branch from d5911f3 to 15e2fdb Compare May 19, 2026 16:00
@jkmassel jkmassel requested review from adalpari and nbradbury May 19, 2026 17:26
@nbradbury
Copy link
Copy Markdown
Contributor

nbradbury commented May 19, 2026

  • Open settings with experimental_block_editor feature flag off — both prefs hidden

@jkmassel I took this to mean that if I disable the experimental feature, both the "Use block editor" and "Use theme styles" prefs should not be visible in the site settings. However, I disabled the experimental block editor and while the theme styles pref is gone, I still see the block editor one.

Screenshot_20260519_144814

@jkmassel
Copy link
Copy Markdown
Contributor Author

I still see the block editor one

Ah yep, sorry - that's the old block editor, Gutenberg Mobile

Copy link
Copy Markdown
Contributor

@nbradbury nbradbury left a comment

Choose a reason for hiding this comment

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

Looks good! :shipit:

jkmassel added 4 commits May 19, 2026 14:16
`SiteSettingsFragment` combined the top-level GutenbergKit feature
flag, the remote `gutenberg_kit_plugins` flag, the per-site capability
cache, and the user's toggle inline — a long conditional chain per
capability that's hard to share with other consumers and easy to drift
from when those consumers get added.

Introduces `EditorCapabilityResolver` as a single source of truth for
both theme styles and third-party blocks. Returns a `Resolved` sealed
result — `Hidden` / `Unsupported(reason)` / `Available(userEnabled,
advisory?)` — that UI callers branch on directly, and non-UI callers
collapse via `shouldApplyInEditor`. The theme-not-a-block-theme case
is modelled as an advisory, not a gate, matching today's behaviour
where the pref stays enabled with an informational summary.

Wires `SiteSettingsFragment` through the resolver. The editor-side
consumer (the GutenbergKit config builder) will land in a follow-up
alongside its refactor to an injectable class.
Renames the sealed result type to a domain-specific name and lifts
`advisory` onto the base class so Java callers can query it without
an `instanceof`-then-cast dance — `themeStyles.getAdvisory()` is now
null-safe across all variants.
- Annotate the implicit "Available without advisory" fall-through in
  the theme-styles branch chain in SiteSettingsFragment.
- Replace `verify(plugins, never()).isEnabled()` (asserts on call
  ordering) with a behavioural check: theme styles still resolve to
  Available when the plugins flag is off.
- Add a symmetric test covering the case where both feature flags are
  disabled simultaneously.
The two tests that assert the resolver *ignores* a given flag (theme
styles vs. the plugins flag; third-party blocks short-circuit on the
top-level GutenbergKit flag) intentionally stub a feature flag that
the code under test never reads. Mockito's strict runner treats those
stubs as unused and fails the suite — `lenient()` is the documented
escape hatch for stubs that exist to encode the contract the test is
asserting.
@jkmassel jkmassel enabled auto-merge (squash) May 19, 2026 20:16
@jkmassel jkmassel force-pushed the jkmassel/editor-capability-resolver branch from 6687be2 to 0e21611 Compare May 19, 2026 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Gutenberg Editing and display of Gutenberg blocks. Site Management Tech Debt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants