From 1306163446ceac9b16de56ab01847f839c3d9965 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Mon, 23 Feb 2026 12:06:53 -0500 Subject: [PATCH] feat(api): Add CLI flag and env var to enable test hooks --- gui.py | 3 +++ tests/test_hooks.py | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/test_hooks.py diff --git a/gui.py b/gui.py index 2d5fec1..9176163 100644 --- a/gui.py +++ b/gui.py @@ -14,6 +14,8 @@ import tomli_w import threading import time import math +import sys +import os from pathlib import Path from tkinter import filedialog, Tk import aggregate @@ -393,6 +395,7 @@ def _parse_history_entries(history: list[str], roles: list[str] | None = None) - class App: def __init__(self): self.config = load_config() + self.test_hooks_enabled = '--enable-test-hooks' in sys.argv or os.environ.get('SLOP_TEST_HOOKS') == '1' # ---- global settings from config.toml ---- ai_cfg = self.config.get("ai", {}) diff --git a/tests/test_hooks.py b/tests/test_hooks.py new file mode 100644 index 0000000..db67ab9 --- /dev/null +++ b/tests/test_hooks.py @@ -0,0 +1,24 @@ +import os +import sys +sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) +import pytest +from unittest.mock import patch +import gui + +def test_hooks_enabled_via_cli(): + with patch.object(sys, 'argv', ['gui.py', '--enable-test-hooks']): + app = gui.App() + assert app.test_hooks_enabled is True + +def test_hooks_disabled_by_default(): + with patch.object(sys, 'argv', ['gui.py']): + if 'SLOP_TEST_HOOKS' in os.environ: + del os.environ['SLOP_TEST_HOOKS'] + app = gui.App() + assert getattr(app, 'test_hooks_enabled', False) is False + +def test_hooks_enabled_via_env(): + with patch.object(sys, 'argv', ['gui.py']): + with patch.dict(os.environ, {'SLOP_TEST_HOOKS': '1'}): + app = gui.App() + assert app.test_hooks_enabled is True