Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "diffui"
version = "0.12.0"
version = "0.12.1"
description = "UI for reviewing AI agent diffs"
requires-python = ">=3.10"
dependencies = [
Expand Down
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,3 +680,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
Loading