Add EditorCapabilityResolver to centralize editor-capability gating#22812
Conversation
|
|
|
|
🤖 Build Failure AnalysisThis build has failures. Claude has analyzed them - check the build annotations for details. |
6968ec2 to
7af2cc5
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
7af2cc5 to
34887ae
Compare
adalpari
left a comment
There was a problem hiding this comment.
It looks like there are some merge conflicts. Could you take a look at them?
34887ae to
d5911f3
Compare
Generated by 🚫 Danger |
d5911f3 to
15e2fdb
Compare
@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.
|
Ah yep, sorry - that's the old block editor, Gutenberg Mobile |
`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.
6687be2 to
0e21611
Compare



Summary
EditorCapabilityResolveras 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 remotegutenberg_kit_pluginsflag, the per-site capability cache (EditorSettingsRepository), and the user's per-site toggle (SiteSettingsProvider).Resolvedsealed 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 viashouldApplyInEditor.Available, not a gate — the pref stays enabled with an informational summary, matching today's behaviour.SiteSettingsFragmentthrough the resolver, replacing two inline conditional chains with pattern matches overResolved.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)experimental_block_editorfeature flag off — both prefs hiddenRelated