nightshift/tests/test_repo_tools.py
K. Hodges 646c655314 Repo Lookup, Request Context, Planner, Context Stage, QoL improvements
- Added operational run logging via nightshift/runlog.py.
  - CLI now streams progress during run / run --all.
  - Runs write .nightshift/runs/<run-id>/run.log and aggregate .nightshift/nightshift.log.
  - Web dashboard now shows the last 100 run log lines.
  - Added agent temperature config.
  - Added minimal openai_compatible backend and temperature passing for it.
  - Added Ollama temperature handling.
  - Added scoped repo lookup tools in nightshift/repo_tools.py: list_files, read_file, grep.
  - Planner agents can request lookup context with lookup_requests; NightShift saves files-inspected.md and reruns the planner with retrieved context.
  - Added repo_context stage type that writes context-pack.md.
  - Marked phases 23-27 complete in docs/design.md:990.
2026-05-17 09:56:28 -07:00

48 lines
1.6 KiB
Python

from pathlib import Path
import tempfile
import unittest
from nightshift.artifacts import ArtifactStore
from nightshift.config import SafetyConfig
from nightshift.repo_tools import RepoTools, parse_lookup_requests
class RepoToolsTests(unittest.TestCase):
def test_repo_tools_are_scoped_and_line_numbered(self) -> None:
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
(root / "src").mkdir()
(root / "src" / "app.py").write_text("def hello():\n return 'hi'\n", encoding="utf-8")
safety = SafetyConfig(
require_clean_worktree=False,
scoped_paths=("src",),
allowed_commands=(),
forbidden_commands=(),
)
tools = RepoTools(root, safety, ArtifactStore(root, ".nightshift", run_id="test-run"))
self.assertIn("src/app.py", tools.list_files("src", "*.py"))
self.assertIn("1: def hello():", tools.read_file("src/app.py"))
self.assertIn("src/app.py:1", tools.grep("hello", "src"))
def test_parse_lookup_requests(self) -> None:
output = """Plan needs context.
lookup_requests:
- tool: read_file
path: nightshift/pipeline.py
- tool: grep
path: nightshift
pattern: PipelineRunner
"""
requests = parse_lookup_requests(output)
self.assertEqual([request.name for request in requests], ["read_file", "grep"])
self.assertEqual(requests[0].arguments["path"], "nightshift/pipeline.py")
self.assertEqual(requests[1].arguments["pattern"], "PipelineRunner")
if __name__ == "__main__":
unittest.main()