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 .claude/skills/check-tests/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: Check that a branch covers the behavior it changes, and that every

Review the behavior the non-test code changes and every test the diff adds or edits. Read each changed test next to the code it calls. Open an unchanged test only to confirm a redundant finding. Don't run the tests.

A test earns its place by catching a named bug that no existing test catches. If you can't name the bug, it is a finding. Tests live in `tests/`: `test_server.py` drives the routes through a `TestClient`, `test_tui.py` drives the real `DiffuiApp` under `run_test()`, and the rest cover one module each.
A test earns its place by catching a named bug that no existing test catches. If you can't name the bug, it is a finding. Tests live in `tests/`: `test_server.py`, `test_comments.py` and `test_search.py` drive the routes through a `TestClient`, `test_tui.py` drives the real `DiffuiApp` under `run_test()`, and the rest cover one module each.

## What to check

Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ jobs:
python: ["3.10", "3.13"]
runs-on: ${{ matrix.os }}
steps:
# Some tests diff this checkout against origin/main, which a shallow clone lacks.
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python }}
Expand Down
6 changes: 3 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ ruff format --check . # Format check
git config core.hooksPath .githooks # Once per clone: enables the pre-push hook
```

CI (`.github/workflows/ci.yml`) runs `ruff check`, `ruff format --check` and `pytest` on Ubuntu and macOS, Python 3.10 and 3.13. The checkout is full-depth because some tests diff the repo against `origin/main`.
CI (`.github/workflows/ci.yml`) runs `ruff check`, `ruff format --check` and `pytest` on Ubuntu and macOS, Python 3.10 and 3.13.

`.githooks/pre-push` runs the same three checks, then `scripts/check_suite.py` (the README's Development section describes it). Change what the review looks for in the skills, not in the script.

## 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). Server tests use a `TestClient` with `base_url="http://localhost"`.
- `tests/test_server.py` covers the routes. Its `fake_herdr` fixture puts a fake `herdr` on `PATH`.
- `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/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.
- `test_check_suite.py` covers the verdict parsing and skip paths of `scripts/check_suite.py` with `subprocess` patched. It never starts `claude`.
Expand Down
30 changes: 30 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
from pathlib import Path

import pytest
from fastapi.testclient import TestClient

import diffui.git_utils
from diffui.server.app import create_app

_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 Down Expand Up @@ -34,6 +36,21 @@ def diffui_config_root(tmp_path_factory):
mp.undo()


@pytest.fixture(autouse=True)
def _isolate_repo_state():
"""Comments, reviewed marks and the active repo are process-wide, so one test's leftovers would reach the next."""
from diffui.server.state import app_state

active = diffui.git_utils._active_repo_root
yield
if active is not None:
diffui.git_utils.set_active_repo(active)
app_state.comments = {}
app_state.reviewed = {}
diffui.git_utils.save_comments({})
diffui.git_utils.save_reviewed({})


@pytest.fixture(scope="session")
def temp_repo(tmp_path_factory) -> Path:
repo = tmp_path_factory.mktemp("diffui-repo")
Expand All @@ -55,3 +72,16 @@ def temp_repo(tmp_path_factory) -> Path:
(repo / "app.py").write_text(_APP_DIRTY)
(repo / "untracked.txt").write_text("never committed\n")
return repo


@pytest.fixture(scope="class")
def _server_app(temp_repo) -> TestClient:
diffui.git_utils.set_active_repo(temp_repo)
return TestClient(create_app([temp_repo]), base_url="http://localhost")


def post_comment(client: TestClient, **fields) -> str:
"""Add a comment on app.py line 1 unless `fields` say otherwise, and return its id."""
payload = {"file_path": "app.py", "line_index": 1, "comment": "check", **fields}
client.post("/api/comments", json=payload)
return client.get("/api/comments").json()[payload["file_path"]][-1]["id"]
Loading
Loading