Skip to content

fix(plugin): honor plugin_blacklist and plugin_whitelist when loading - #60

Merged
GEYUANwuqi merged 1 commit into
ncatbot:mainfrom
adityaanikam:fix/plugin-blacklist-58
Oct 4, 2026
Merged

GEYUANwuqi merged 1 commit into
ncatbot:mainfrom
adityaanikam:fix/plugin-blacklist-58

Conversation

@adityaanikam

Copy link
Copy Markdown
Contributor

Summary

ncatbot plugin disable <name> writes the name to plugin.plugin_blacklist in the config, but nothing read that list when plugins were loaded, so the plugin was still loaded at startup (#58). The same was true for plugin_whitelist.

Changes

  • PluginLoader.load_plugin now returns early with an info log (跳过插件 ... (已在配置中禁用)) when the plugin is not enabled. load_all, load_selected and hot reload all go through load_plugin, so one check covers them.
  • New helper PluginLoader._is_plugin_enabled. A name in plugin_blacklist is disabled. Otherwise, if plugin_whitelist is not empty, only names in it are enabled. This is the same rule ncatbot plugin list already uses to show the status.
  • Built-in plugins use a separate loading path and are not affected.
  • tests/README.md: the LD range is now LD-01 ~ LD-09.

Tests

Added LD-09 in tests/unit/plugin/test_plugin_loader.py. It runs load_all with the real load_plugin on three plugins, with the config patched, and has three cases: blacklist only, whitelist only, and a name in both (blacklist wins).

  • Before the change all three cases fail: all of a, b and c are loaded and the log says 已加载 3/3.
  • After the change test_plugin_loader.py has 12 passed, and uv run pytest tests/unit has 824 passed, 5 skipped, 1 xfailed.
  • ruff check . and ruff format --check . are clean.

Not run: the integration and e2e tests, Python 3.13, or a real bot with NapCat. I did not reproduce the original report through the CLI.

Notes

  • A plugin that declares a dependency on a disabled plugin is still loaded, the same as with the existing skip for unmet pip dependencies. I kept this change small. Skipping dependents as well could be a follow-up if you want it.
  • I did not touch docs/, which is a separate submodule repo.

Fixes #58

The CLI commands "plugin enable" and "plugin disable" edit
plugin_blacklist and plugin_whitelist in the config, but PluginLoader
never read them, so a disabled plugin was still loaded at startup.

Check both lists in PluginLoader.load_plugin, which load_all,
load_selected and hot reload all go through. A blacklisted plugin is
skipped, and when the whitelist is not empty only plugins in it are
loaded. The blacklist wins if a name is in both, which matches the
status shown by "ncatbot plugin list". Built-in plugins are not
affected.

Fixes ncatbot#58
Copilot AI balanced review requested due to automatic review settings October 2, 2026 19:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@GEYUANwuqi
GEYUANwuqi merged commit 9835409 into ncatbot:main Oct 4, 2026
3 checks passed
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.

[BUG] 插件禁用失效

3 participants