From 93dd0aba4c85a5cf3a43b4bab357725335406aa1 Mon Sep 17 00:00:00 2001 From: Gregory Kieffer Date: Fri, 20 Nov 2026 17:01:16 +0100 Subject: [PATCH] Keep the developer's own settings out of the test suite app_state is built when diffui.server.state is imported, and it reads settings.json then, from the real ~/.config/diffui. The session fixture points _CONFIG_ROOT at a temp dir only afterwards, so the developer's theme, keybindings and display settings were what the tests started from. The fixture now reloads app_state from the temp config root, and a test checks the server starts at the defaults. Bump version to 0.11.4 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Xshwvphn2wQmVKLLS2G9kJ --- AGENTS.md | 2 +- pyproject.toml | 2 +- tests/conftest.py | 4 ++++ tests/test_server.py | 10 ++++++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 44b436a..41e2f27 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -160,7 +160,7 @@ CI (`.github/workflows/ci.yml`) runs `ruff check`, `ruff format --check` and `py ## Testing -- `tests/conftest.py` points `_CONFIG_ROOT` at a temp dir for the whole session, clears `HERDR_WORKSPACE_ID`, and builds the `temp_repo` fixture (a `feature` branch with a dirty tree and an untracked file). It also provides `_server_app` (a `TestClient` on `temp_repo` with `base_url="http://localhost"`) and `post_comment`, and after every test resets the comments, reviewed marks and active repo, so tests need no cleanup of their own. +- `tests/conftest.py` points `_CONFIG_ROOT` at a temp dir for the whole session and reloads `app_state` from it (the import already read the real `settings.json`), clears `HERDR_WORKSPACE_ID`, and builds the `temp_repo` fixture (a `feature` branch with a dirty tree and an untracked file). It also provides `_server_app` (a `TestClient` on `temp_repo` with `base_url="http://localhost"`) and `post_comment`, and after every test resets the comments, reviewed marks and active repo, so tests need no cleanup of their own. - `tests/test_server.py` covers the routes that `test_comments.py` and `test_search.py` don't. Its `fake_herdr` fixture puts a fake `herdr` on `PATH`. `test_risk.py` covers `_score_risk` and `_order_files`. - `tests/test_tui.py` runs the real `DiffuiApp` under `App.run_test()` against a `LocalServer` on `temp_repo`. Tests drive the app with `asyncio.run` and wait with `until()`, because the server reaches the view through the watcher and SSE. - `test_diff.py`, `test_highlight.py`, `test_git_utils.py`, `test_events.py`, `test_agent_terminal.py` and `test_themes.py` cover the matching modules. diff --git a/pyproject.toml b/pyproject.toml index 7dd2c42..a0e9ed2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "diffui" -version = "0.11.3" +version = "0.11.4" description = "UI for reviewing AI agent diffs" requires-python = ">=3.10" dependencies = [ diff --git a/tests/conftest.py b/tests/conftest.py index 58f6491..69986b4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,6 +8,7 @@ import diffui.git_utils from diffui.server.app import create_app +from diffui.server.state import app_state _APP_V1 = "\n".join(f"line {i}" for i in range(1, 21)) + "\n" _APP_V2 = _APP_V1.replace("line 5", "line five").replace("line 12", "line twelve") @@ -27,6 +28,9 @@ def diffui_config_root(tmp_path_factory): root = tmp_path_factory.mktemp("diffui-config") mp = pytest.MonkeyPatch() mp.setattr(diffui.git_utils, "_CONFIG_ROOT", root) + # app_state read settings.json when diffui.server.state was imported, from the real + # config root, so the developer's own theme, keys and display settings reached the tests. + app_state.__init__() # A suite run from a herdr pane would otherwise write to the live sidebar. mp.delenv("HERDR_WORKSPACE_ID", raising=False) # A pre-push hook in a linked worktree exports GIT_DIR, which points the temp repos' git calls at the checkout. diff --git a/tests/test_server.py b/tests/test_server.py index 8d33811..0b33312 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -678,3 +678,13 @@ def test_foreign_websocket_is_rejected(self, _server_app): ) as ws, ): ws.receive_json() + + +def test_settings_start_at_the_defaults_whatever_the_developer_saved(_server_app): + # Each settings test restores what it changes, so the server must report what a fresh + # AppState loads from the empty test config root, not the real ~/.config/diffui. + from diffui.server.state import AppState + + defaults = AppState().settings() + reported = _server_app.get("/api/settings").json() + assert {k: reported[k] for k in defaults} == defaults