Files
Claude f86b554616 feat(engine): server-side settings, runtime ref depth limit and database backups
The Settings page's ref recursion limit was stored in localStorage and read
by nothing: every run stopped at 8. Server-side preferences now live in
user/wildcard-pipeline/settings.json (engine/prefs.py, /wp/api/settings) and
PipelineEngine.run seeds __wp_max_ref_depth__ from them, so canvas runs,
previews and the Test Runner honour it.

Database backups (engine/db/backups.py): a copy before any migration that
changes the schema, a daily copy while ComfyUI runs, pruning of automatic
copies beyond the configured count (manual ones are kept), and a restore
that is staged in the DB sidecar and applied on the next start before any
connection opens, after backing up the current database.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BMHPZ4k2kXrePkcgeYJJSF
2026-09-30 09:26:44 +00:00

57 lines
1.9 KiB
Python

"""Root conftest — lets pytest import engine/wp_nodes without installing the package.
If ``comfy_api`` is not importable (running outside ComfyUI), inject the
``tests/stubs/comfy_api_stub`` module into ``sys.modules`` as both
``comfy_api`` and ``comfy_api.latest`` so production code that does
``from comfy_api.latest import ComfyExtension, io`` succeeds in tests.
"""
from __future__ import annotations
import importlib.util
import sys
from pathlib import Path
import pytest
ROOT = Path(__file__).parent
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
if importlib.util.find_spec("comfy_api") is None:
from tests.stubs import comfy_api_stub as _stub
sys.modules.setdefault("comfy_api", _stub)
sys.modules.setdefault("comfy_api.latest", _stub)
sys.modules.setdefault("comfy_api.latest._io", _stub.io._io)
from engine.db.connection import get_connection # noqa: E402
from engine.db.migrations import migrate # noqa: E402
collect_ignore: list[str] = []
@pytest.fixture
def wp_db(tmp_path):
"""Fresh, migrated SQLite DB. Yields a sqlite3.Connection."""
conn = get_connection(tmp_path / "wp.db")
migrate(conn)
try:
yield conn
finally:
conn.close()
@pytest.fixture(autouse=True)
def _isolate_wp_settings(tmp_path, monkeypatch):
"""Keep every test off the real settings file and the backup scheduler.
`PipelineEngine.run` reads `engine/prefs.py` on every run and `migrate`
consults it before upgrading a DB, so without this a test could read — or
a Settings API test write — the developer's real `settings.json`.
`register_routes` starts the daily backup thread; tests that want it call
`engine.db.backups.start_daily_scheduler` directly.
"""
monkeypatch.setenv("WP_SETTINGS_PATH", str(tmp_path / "wp-settings.json"))
monkeypatch.setattr("wp_api._start_backups", lambda: None)