pytest rewrites config/vigilar.toml in place — test isolation bug #3

Closed
opened 2026-04-05 14:50:10 +00:00 by alee · 0 comments
Owner

Severity: bug
Files: vigilar/config.py:420, vigilar/web/blueprints/system.py:24, some web test (unidentified)

Running the full pytest suite from a clean checkout modifies the committed config/vigilar.toml: comments are stripped, [[cameras]] / [[sensors]] / [[rules]] blocks are dropped, and default field values are materialized. Git shows it as M config/vigilar.toml after pytest exits.

Root cause: Both load_config() (vigilar/config.py:420) and _get_config_path() (vigilar/web/blueprints/system.py:24) default to the relative path "config/vigilar.toml" when the VIGILAR_CONFIG env var is unset. Some test exercises a web endpoint that calls _save_and_reload(), which calls save_config() against whatever path _get_config_path() returns. Because the tests don't set VIGILAR_CONFIG, the real on-disk config is rewritten via a Pydantic model_dump() round-trip.

Fix options:

  • conftest.py: set VIGILAR_CONFIG to a tmp_path fixture for all tests, or autouse a fixture that does so.
  • Identify the offending test and make it patch _get_config_path or inject VIGILAR_CONFIG.
  • Harden _save_and_reload to refuse to write when the target path resolves to a tracked file under the repo.

Reproduce: git clean -f && git checkout config/vigilar.toml && pytest -q && git status --shortconfig/vigilar.toml will be listed as modified.

Discovered while working on unrelated fixes in branch fix/audit-followups.

**Severity:** bug **Files:** `vigilar/config.py:420`, `vigilar/web/blueprints/system.py:24`, some web test (unidentified) Running the full `pytest` suite from a clean checkout **modifies the committed `config/vigilar.toml`**: comments are stripped, `[[cameras]]` / `[[sensors]]` / `[[rules]]` blocks are dropped, and default field values are materialized. Git shows it as `M config/vigilar.toml` after `pytest` exits. **Root cause:** Both `load_config()` (`vigilar/config.py:420`) and `_get_config_path()` (`vigilar/web/blueprints/system.py:24`) default to the relative path `"config/vigilar.toml"` when the `VIGILAR_CONFIG` env var is unset. Some test exercises a web endpoint that calls `_save_and_reload()`, which calls `save_config()` against whatever path `_get_config_path()` returns. Because the tests don't set `VIGILAR_CONFIG`, the real on-disk config is rewritten via a Pydantic `model_dump()` round-trip. **Fix options:** - `conftest.py`: set `VIGILAR_CONFIG` to a `tmp_path` fixture for all tests, or autouse a fixture that does so. - Identify the offending test and make it patch `_get_config_path` or inject `VIGILAR_CONFIG`. - Harden `_save_and_reload` to refuse to write when the target path resolves to a tracked file under the repo. Reproduce: `git clean -f && git checkout config/vigilar.toml && pytest -q && git status --short` — `config/vigilar.toml` will be listed as modified. Discovered while working on unrelated fixes in branch `fix/audit-followups`.
alee closed this issue 2026-04-05 16:54:13 +00:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: alee/vigilar#3