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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- ruff now also checks the SIM, PIE, C4, RET and PERF rule sets on iris/ and tests/, and every finding was fixed without changing behaviour.
- ruff now also checks the PTH and RUF rule sets on iris/ and tests/, and every finding was fixed without changing behaviour; the protected files keep their per-file ignores for the new rules too.
- Tests are type-checked by mypy as well; 14 test modules still sit on the ignore list until they are typed.
- git, Cline CLI and lms output are decoded as UTF-8 with replacement, so the dashboard's agent status and autopilot survive any text on a non-UTF-8 locale code page.

## 1.0.0 (release date): steady, safer and measured

Expand Down
3 changes: 2 additions & 1 deletion iris/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ def discover(cfg: Config | None = None) -> list[tuple[str, Path]]:
def _git(repo: Path, *args: str) -> str:
"""Run a read-only, lock-free git command in `repo`. Raises on failure so the caller can report it."""
cmd = ["git", "--no-optional-locks", "-C", str(repo), *args] # never takes the index lock
proc = subprocess.run(cmd, capture_output=True, text=True, timeout=GIT_TIMEOUT, check=False)
proc = subprocess.run(cmd, capture_output=True, text=True, encoding="utf-8", errors="replace",
timeout=GIT_TIMEOUT, check=False)
if proc.returncode != 0:
raise RuntimeError((proc.stderr or "git failed").strip().splitlines()[-1])
return proc.stdout
Expand Down
2 changes: 2 additions & 0 deletions iris/autopilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def cline_sessions(
capture_output=True,
text=True,
encoding="utf-8",
errors="replace",
timeout=30,
stdin=subprocess.DEVNULL,
check=False,
Expand Down Expand Up @@ -131,6 +132,7 @@ def _dispatch(text: str, cwd: str, run: Callable[..., subprocess.CompletedProces
capture_output=True,
text=True,
encoding="utf-8",
errors="replace",
timeout=120,
stdin=subprocess.DEVNULL,
check=False,
Expand Down
2 changes: 1 addition & 1 deletion iris/dashboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def run_lms(args: list[str]) -> tuple[int, str]:
exe = _lms_exe()
if not exe:
raise ModelActionError(503, "no lms executable found: set IRIS_LMS_BIN or put lms on PATH")
proc = subprocess.run([exe, *args], capture_output=True, text=True,
proc = subprocess.run([exe, *args], capture_output=True, text=True, encoding="utf-8", errors="replace",
timeout=LMS_TIMEOUT_SECONDS)
return proc.returncode, (proc.stderr or proc.stdout or "").strip()

Expand Down
16 changes: 16 additions & 0 deletions tests/test_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ def test_uncommitted_files_are_counted(tmp_path):
assert repo_status(repo).uncommitted == 2


def test_repo_status_reads_utf8_subjects_and_file_names(tmp_path):
"""git output is decoded as UTF-8, so a non-ASCII subject and file name survive the locale code page."""
repo = tmp_path / "cafe"
repo.mkdir()
git(repo, "init", "-b", "main")
git(repo, "config", "user.email", "iris@test.local")
git(repo, "config", "user.name", "Iris test")
(repo / "a.txt").write_text("hello", encoding="utf-8")
git(repo, "add", "a.txt")
git(repo, "commit", "-m", "fix café ☕")
(repo / "notities-é.txt").write_text("new", encoding="utf-8")
s = repo_status(repo)
assert s.exists and s.last_commit == "fix café ☕" # the subject comes back exactly as committed
assert s.uncommitted == 1 # the accented file name is counted, not garbled


def test_stuck_needs_both_uncommitted_changes_and_an_old_commit(tmp_path):
fresh = make_repo(tmp_path, "fresh", minutes_ago=5)
(fresh / "b.txt").write_text("new", encoding="utf-8")
Expand Down
18 changes: 18 additions & 0 deletions tests/test_autopilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from iris.agent import Journal
from iris.autopilot import (
_count_started,
_dispatch,
_started_at_epoch,
cline_cli,
cline_command,
Expand Down Expand Up @@ -319,12 +320,29 @@ def fake_run(argv, **kwargs):
"capture_output": True,
"text": True,
"encoding": "utf-8",
"errors": "replace",
"timeout": 30,
"stdin": subprocess.DEVNULL,
"check": False,
}


def test_dispatch_decodes_cli_output_as_utf8(monkeypatch):
"""The CLI's output is decoded as UTF-8 with replacement, so any text survives the locale code page."""
_clear_cli_env(monkeypatch)
calls: list[tuple[list[str], dict[str, object]]] = []

def fake_run(argv, **kwargs):
calls.append((argv, kwargs))
return SimpleNamespace(stderr="")

out = _dispatch("fix the bug", "W:/Iris", run=fake_run)
assert out == "" # empty stderr means nothing to report
argv, kwargs = calls[0]
assert argv[-1] == "fix the bug" # the prompt stays one argv item
assert kwargs["encoding"] == "utf-8" and kwargs["errors"] == "replace"


def test_started_at_epoch_of_a_non_string_is_none():
assert _started_at_epoch(None) is None
assert _started_at_epoch(1_700_000_000) is None
Expand Down
25 changes: 23 additions & 2 deletions tests/test_dashboard_branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class Proc:
monkeypatch.setattr(d, "_lms_exe", lambda: "/fake/lms")
calls = []

def fake_run(cmd, capture_output=True, text=True, timeout=600):
calls.append((cmd, timeout))
def fake_run(cmd, **kwargs):
calls.append((cmd, kwargs))
return Proc()

monkeypatch.setattr("iris.dashboard.subprocess.run", fake_run)
Expand All @@ -43,6 +43,27 @@ def fake_run(cmd, capture_output=True, text=True, timeout=600):
assert calls[0][0] == ["/fake/lms", "load", "m"]


def test_run_lms_decodes_output_as_utf8(monkeypatch):
"""lms output is decoded as UTF-8 with replacement, so any text survives the locale code page."""

class Proc:
returncode = 0
stderr = ""
stdout = "loaded\n"

calls: list[dict[str, object]] = []

def fake_run(cmd, **kwargs):
calls.append(kwargs)
return Proc()

monkeypatch.setattr(d, "_lms_exe", lambda: "/fake/lms")
monkeypatch.setattr("iris.dashboard.subprocess.run", fake_run)
code, out = d.run_lms(["load", "m"])
assert (code, out) == (0, "loaded") # empty stderr, so the stripped stdout wins
assert calls[0]["encoding"] == "utf-8" and calls[0]["errors"] == "replace"


def test_model_action_rejects_a_body_that_is_not_an_object():
with pytest.raises(d.ModelActionError) as exc:
d.model_action("load", cast(dict[str, Any], ["not", "a", "dict"]))
Expand Down