chore(tests): encoding="utf-8" on read_text/write_text in test_subdirectory_hints.py

Windows-footgun ratchet for the file touched by this fix (no behaviour change).
This commit is contained in:
teknium1
2026-09-12 06:33:51 -07:00
committed by Teknium
parent 5148b76677
commit 215a820ace
+22 -22
View File
@@ -14,30 +14,30 @@ from agent.subdirectory_hints import SubdirectoryHintTracker
def project(tmp_path):
"""Create a mock project tree with hint files in subdirectories."""
# Root — already loaded at startup
(tmp_path / "AGENTS.md").write_text("Root project instructions")
(tmp_path / "AGENTS.md").write_text("Root project instructions", encoding="utf-8")
# backend/ — has its own AGENTS.md
backend = tmp_path / "backend"
backend.mkdir()
(backend / "AGENTS.md").write_text("Backend-specific instructions:\n- Use FastAPI\n- Always add type hints")
(backend / "AGENTS.md").write_text("Backend-specific instructions:\n- Use FastAPI\n- Always add type hints", encoding="utf-8")
# backend/src/ — no hints
(backend / "src").mkdir()
(backend / "src" / "main.py").write_text("print('hello')")
(backend / "src" / "main.py").write_text("print('hello')", encoding="utf-8")
# frontend/ — has CLAUDE.md
frontend = tmp_path / "frontend"
frontend.mkdir()
(frontend / "CLAUDE.md").write_text("Frontend rules:\n- Use TypeScript\n- No any types")
(frontend / "CLAUDE.md").write_text("Frontend rules:\n- Use TypeScript\n- No any types", encoding="utf-8")
# docs/ — no hints
(tmp_path / "docs").mkdir()
(tmp_path / "docs" / "README.md").write_text("Documentation")
(tmp_path / "docs" / "README.md").write_text("Documentation", encoding="utf-8")
# deep/nested/path/ — has .cursorrules
deep = tmp_path / "deep" / "nested" / "path"
deep.mkdir(parents=True)
(deep / ".cursorrules").write_text("Cursor rules for nested path")
(deep / ".cursorrules").write_text("Cursor rules for nested path", encoding="utf-8")
return tmp_path
@@ -110,7 +110,7 @@ class TestSubdirectoryHintTracker:
sub = tmp_path / "bigdir"
sub.mkdir()
body = "HEAD-MARKER " + ("x" * (sh._MAX_HINT_CHARS + 5_000)) + " TAIL-MARKER"
(sub / "AGENTS.md").write_text(body)
(sub / "AGENTS.md").write_text(body, encoding="utf-8")
tracker = SubdirectoryHintTracker(working_dir=str(tmp_path))
with caplog.at_level(logging.WARNING, logger="agent.prompt_builder"):
@@ -126,7 +126,7 @@ class TestSubdirectoryHintTracker:
sub = tmp_path / "gateway"
sub.mkdir()
body = "# Gateway rules\n" + ("- rule\n" * 1500) # ~12k chars: over the OLD 8k cap, under the new one
(sub / "AGENTS.md").write_text(body)
(sub / "AGENTS.md").write_text(body, encoding="utf-8")
tracker = SubdirectoryHintTracker(working_dir=str(tmp_path))
result = tracker.check_tool_call("read_file", {"path": str(sub / "run.py")})
assert result is not None and "truncated" not in result.lower()
@@ -143,7 +143,7 @@ class TestSubdirectoryHintTracker:
def test_timeout_skips_slow_hint_files(self, project, monkeypatch, caplog):
"""Slow hint reads time out instead of blocking the turn."""
backend = project / "backend"
(backend / "AGENTS.md").write_text("Backend-specific instructions")
(backend / "AGENTS.md").write_text("Backend-specific instructions", encoding="utf-8")
import sys
from agent import subdirectory_hints as sh_mod
@@ -244,7 +244,7 @@ class TestContentDeduplication:
"""Two directories whose AGENTS.md is the same file yield one injection."""
real = tmp_path / "real"
real.mkdir()
(real / "AGENTS.md").write_text("Shared workspace instructions")
(real / "AGENTS.md").write_text("Shared workspace instructions", encoding="utf-8")
mirror = tmp_path / "mirror"
mirror.mkdir()
@@ -264,8 +264,8 @@ class TestContentDeduplication:
b = tmp_path / "b"
a.mkdir()
b.mkdir()
(a / "AGENTS.md").write_text("Same content")
(b / "AGENTS.md").write_text("Same content")
(a / "AGENTS.md").write_text("Same content", encoding="utf-8")
(b / "AGENTS.md").write_text("Same content", encoding="utf-8")
tracker = SubdirectoryHintTracker(working_dir=str(tmp_path))
assert tracker.check_tool_call("read_file", {"path": str(a / "f.py")}) is not None
@@ -277,8 +277,8 @@ class TestContentDeduplication:
b = tmp_path / "b"
a.mkdir()
b.mkdir()
(a / "AGENTS.md").write_text("Alpha rules")
(b / "AGENTS.md").write_text("Beta rules")
(a / "AGENTS.md").write_text("Alpha rules", encoding="utf-8")
(b / "AGENTS.md").write_text("Beta rules", encoding="utf-8")
tracker = SubdirectoryHintTracker(working_dir=str(tmp_path))
first = tracker.check_tool_call("read_file", {"path": str(a / "f.py")})
@@ -289,10 +289,10 @@ class TestContentDeduplication:
def test_working_dir_content_seeded(self, tmp_path):
"""A copy of the CWD's own context file is not re-injected."""
(tmp_path / "AGENTS.md").write_text("Root instructions")
(tmp_path / "AGENTS.md").write_text("Root instructions", encoding="utf-8")
elsewhere = tmp_path / "elsewhere"
elsewhere.mkdir()
(elsewhere / "AGENTS.md").write_text("Root instructions")
(elsewhere / "AGENTS.md").write_text("Root instructions", encoding="utf-8")
tracker = SubdirectoryHintTracker(working_dir=str(tmp_path))
assert tracker.check_tool_call("read_file", {"path": str(elsewhere / "f.py")}) is None
@@ -308,7 +308,7 @@ class TestExcludedDirectories:
def test_excluded_directory_skipped(self, tmp_path, excluded):
target = tmp_path / excluded / "snapshot"
target.mkdir(parents=True)
(target / "AGENTS.md").write_text("Stale archived instructions")
(target / "AGENTS.md").write_text("Stale archived instructions", encoding="utf-8")
tracker = SubdirectoryHintTracker(working_dir=str(tmp_path))
assert tracker.check_tool_call("read_file", {"path": str(target / "f.py")}) is None
@@ -317,7 +317,7 @@ class TestExcludedDirectories:
"""A hint nested under an excluded ancestor is still skipped."""
deep = tmp_path / "backups" / "2026" / "proj"
deep.mkdir(parents=True)
(deep / "AGENTS.md").write_text("Archived")
(deep / "AGENTS.md").write_text("Archived", encoding="utf-8")
tracker = SubdirectoryHintTracker(working_dir=str(tmp_path))
assert tracker.check_tool_call("read_file", {"path": str(deep / "f.py")}) is None
@@ -328,7 +328,7 @@ class TestExcludedDirectories:
root.mkdir(parents=True)
sub = root / "pkg"
sub.mkdir()
(sub / "AGENTS.md").write_text("Package rules")
(sub / "AGENTS.md").write_text("Package rules", encoding="utf-8")
tracker = SubdirectoryHintTracker(working_dir=str(root))
result = tracker.check_tool_call("read_file", {"path": str(sub / "f.py")})
@@ -337,7 +337,7 @@ class TestExcludedDirectories:
def test_normal_directory_unaffected(self, tmp_path):
normal = tmp_path / "backend"
normal.mkdir()
(normal / "AGENTS.md").write_text("Backend rules")
(normal / "AGENTS.md").write_text("Backend rules", encoding="utf-8")
tracker = SubdirectoryHintTracker(working_dir=str(tmp_path))
result = tracker.check_tool_call("read_file", {"path": str(normal / "f.py")})
@@ -347,8 +347,8 @@ class TestExcludedDirectories:
"""AGENTS.override.md takes priority over AGENTS.md per directory."""
sub = tmp_path / "backend"
sub.mkdir()
(sub / "AGENTS.md").write_text("Committed backend rules")
(sub / "AGENTS.override.md").write_text("Personal backend override")
(sub / "AGENTS.md").write_text("Committed backend rules", encoding="utf-8")
(sub / "AGENTS.override.md").write_text("Personal backend override", encoding="utf-8")
tracker = SubdirectoryHintTracker(working_dir=str(tmp_path))
result = tracker.check_tool_call("read_file", {"path": str(sub / "f.py")})