fix(plugin): honor plugin_blacklist and plugin_whitelist when loading - #60
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ncatbot plugin disable <name>writes the name toplugin.plugin_blacklistin the config, but nothing read that list when plugins were loaded, so the plugin was still loaded at startup (#58). The same was true forplugin_whitelist.Changes
PluginLoader.load_pluginnow returns early with an info log (跳过插件 ... (已在配置中禁用)) when the plugin is not enabled.load_all,load_selectedand hot reload all go throughload_plugin, so one check covers them.PluginLoader._is_plugin_enabled. A name inplugin_blacklistis disabled. Otherwise, ifplugin_whitelistis not empty, only names in it are enabled. This is the same rulencatbot plugin listalready uses to show the status.tests/README.md: the LD range is nowLD-01 ~ LD-09.Tests
Added
LD-09intests/unit/plugin/test_plugin_loader.py. It runsload_allwith the realload_pluginon three plugins, with the config patched, and has three cases: blacklist only, whitelist only, and a name in both (blacklist wins).a,bandcare loaded and the log says已加载 3/3.test_plugin_loader.pyhas 12 passed, anduv run pytest tests/unithas 824 passed, 5 skipped, 1 xfailed.ruff check .andruff 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
docs/, which is a separate submodule repo.Fixes #58