Files
FabledSteward/tests/core/test_settings_default_plugins.py
T
bvandeusenandClaude Opus 5 59fece855d
CI / lint (push) Successful in 3s
CI / unit (push) Successful in 46s
CI / integration (push) Successful in 2m22s
CI / publish (push) Successful in 1m16s
fix(plugins): remove the phantom http plugin; surface orphaned plugin settings
Operator saw the `http` plugin -- deleted when ping/dns/http were unified into
the Monitor entity -- still reported as enabled, with no way to clear it.

It was never an orphaned row. `plugin.http` was hardcoded in core DEFAULTS, so
deleting the app_settings row did nothing: the default reasserted it on the
next settings load. That is precisely why no cleanup UI could have fixed it.
Rule 22 says the removed subsystem should have taken its setting with it.

Purged the surviving references -- the DEFAULTS key, "http" in
CAPABILITY_PLUGINS, the stale plugin_manager docstring example, and the
capabilities blurb still advertising HTTP/uptime as a bundled capability --
plus a migration dropping any stored plugin.http row. Untouched: `http` as a
MONITOR TYPE (icmp/tcp/dns/http) everywhere it appears, and http_001_initial,
which is kept deliberately so existing DBs resolve the revision graph.

For the general case, cleanup splits by provenance rather than being uniformly
automatic or uniformly manual:

  Bundled plugins ship in the image and version atomically with core, so they
  cannot be transiently missing -- a plugin.* default with no bundled directory
  is unambiguously a bug. Guarded by a unit test that fails CI, which is the
  only part safe to automate.

  External plugins live in operator-mounted /data/plugins, where absence is
  ambiguous: unmounted volume, failed install, mid-upgrade. Auto-deleting their
  config would silently destroy unrecoverable credentials on a transient
  condition, so Settings now lists them under "Configured but not installed"
  with an explicit, confirmed, audit-logged Remove. The section hides entirely
  when empty, and the remove route refuses if the plugin is actually installed.

Orphan detection reads STORED rows, never the DEFAULTS-merged view -- offering
to remove a default-only key would be a lie -- and returns names only, since
plugin config can hold credentials and listing orphans never needs their values.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-12 23:41:06 -04:00

44 lines
1.7 KiB
Python

"""Pure-function tests for the default-enabled plugin set.
A fresh install (no stored plugin.* rows) should come up with the generic,
non-vendor-specific bundled plugins already enabled, while vendor-specific
plugins stay opt-in. An operator's stored choice must override the default.
No DB / Quart fixtures — we exercise to_plugins_cfg over the DEFAULTS dict
and a DEFAULTS-merged-with-stored dict, mirroring get_all_settings' merge.
"""
from steward.core import settings as settings_module
from steward.core.settings import DEFAULTS, to_plugins_cfg
# NB: no "http" — that plugin was dissolved into the unified Monitor entity, and
# its lingering default is what test_plugin_settings_hygiene.py now guards against.
DEFAULT_ON = {"docker", "host_agent", "snmp"}
VENDOR_OPT_IN = {"traefik", "unifi"}
def test_generic_plugins_enabled_by_default():
cfg = to_plugins_cfg(DEFAULTS)
for name in DEFAULT_ON:
assert cfg.get(name, {}).get("enabled") is True, name
def test_vendor_plugins_not_enabled_by_default():
cfg = to_plugins_cfg(DEFAULTS)
for name in VENDOR_OPT_IN:
assert name not in cfg, name
def test_stored_choice_overrides_default():
# get_all_settings / load_settings_sync overlay stored values onto DEFAULTS;
# a stored disable must win over the built-in default-on.
merged = {**DEFAULTS, "plugin.docker": {"enabled": False}}
cfg = to_plugins_cfg(merged)
assert cfg["docker"]["enabled"] is False
# untouched defaults remain enabled
assert cfg["snmp"]["enabled"] is True
def test_defaults_use_plugin_dot_namespace():
# The keys must live under the plugin.<name> namespace to_plugins_cfg reads.
for name in DEFAULT_ON:
assert f"plugin.{name}" in settings_module.DEFAULTS