Skip to content

Commit 697746b

Browse files
feat(diff): add DiscoveryDiff.by_filter_reason()
Parity helper that mirrors DiscoveryResult.by_filter_reason() for the diff path. Consumers who rediscover() periodically and group newly- filtered plugins by reason (Settings UIs, audit logs) now get the same one-line accessor instead of iterating diff.states.items() and grouping by hand. Bibliogon adoption feedback: this exact pattern was being hand-rolled after every rediscover() call. Tests: 326 passed (was 325) + 1 skipped. Coverage unchanged at 96%.
1 parent c29ab19 commit 697746b

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

‎pluginforge/state.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,13 @@ class DiscoveryDiff:
195195
unchanged: list[str]
196196
states: dict[str, PluginState]
197197
errors: list[PluginError]
198+
199+
def by_filter_reason(self, reason: FilterReason) -> list[str]:
200+
"""Return plugin names whose filter_reason matches.
201+
202+
Parity helper with DiscoveryResult.by_filter_reason. Consumers that
203+
rediscover() periodically and group newly-filtered plugins by reason
204+
(Settings UI surfaces, audit logs) get the same one-line accessor
205+
instead of iterating states.items() and grouping by hand.
206+
"""
207+
return [name for name, s in self.states.items() if s.filter_reason == reason]

‎tests/test_rediscover.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,35 @@ def test_new_plugin_not_in_enabled_list_is_filtered(self, tmp_path: Path) -> Non
200200
assert diff.states["beta"].filter_reason == "not_enabled"
201201

202202

203+
class TestDiscoveryDiffHelpers:
204+
def test_by_filter_reason(self, tmp_path: Path) -> None:
205+
"""Parity with DiscoveryResult.by_filter_reason: newly-discovered
206+
plugins not in the enabled list show up under 'not_enabled'."""
207+
cfg = _write_config(tmp_path, enabled=["alpha"])
208+
pm = PluginManager(config_path=str(cfg))
209+
210+
with patch(
211+
"pluginforge.manager.discover_entry_points",
212+
return_value={"alpha": AlphaPlugin},
213+
):
214+
pm.discover_plugins()
215+
216+
# Beta + gamma appear but aren't in the enabled list.
217+
with patch(
218+
"pluginforge.manager.discover_entry_points",
219+
return_value={
220+
"alpha": AlphaPlugin,
221+
"beta": BetaPlugin,
222+
"gamma": GammaPlugin,
223+
},
224+
):
225+
diff = pm.rediscover()
226+
227+
not_enabled = diff.by_filter_reason("not_enabled")
228+
assert sorted(not_enabled) == ["beta", "gamma"]
229+
assert "alpha" not in not_enabled
230+
231+
203232
class TestCacheInvalidation:
204233
def test_invalidate_caches_is_called(self, tmp_path: Path) -> None:
205234
cfg = _write_config(tmp_path)

0 commit comments

Comments
 (0)