mirror of
https://github.com/open-jarvis/OpenJarvis.git
synced 2026-07-30 10:52:15 +00:00
Complete implementation across six development phases (v0.1 through v1.0): - Core: Registry system, config, event bus, types (Phase 0) - Intelligence + Inference: Model routing, Ollama/vLLM/llama.cpp/Cloud engines (Phase 1) - Memory: SQLite/FAISS/ColBERT/BM25/Hybrid backends, document ingest, context injection (Phase 2) - Agents: Simple/Orchestrator/Custom/OpenClaw agents, tool system (Phase 3) - Learning: HeuristicRouter, reward functions, GRPO stub, telemetry aggregation (Phase 4) - SDK: Jarvis class, OpenClaw protocol/transport, benchmarks, Docker deployment (Phase 5) 520 tests passing, 8 skipped (optional deps). Ruff lint clean. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
"""Tests for the file_read tool."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from openjarvis.tools.file_read import FileReadTool
|
|
|
|
|
|
class TestFileReadTool:
|
|
def test_spec(self):
|
|
tool = FileReadTool()
|
|
assert tool.spec.name == "file_read"
|
|
assert tool.spec.category == "filesystem"
|
|
|
|
def test_no_path(self):
|
|
tool = FileReadTool()
|
|
result = tool.execute(path="")
|
|
assert result.success is False
|
|
|
|
def test_file_not_found(self):
|
|
tool = FileReadTool()
|
|
result = tool.execute(path="/nonexistent/file.txt")
|
|
assert result.success is False
|
|
assert "File not found" in result.content
|
|
|
|
def test_read_file(self, tmp_path):
|
|
f = tmp_path / "test.txt"
|
|
f.write_text("hello world\nsecond line\n", encoding="utf-8")
|
|
tool = FileReadTool()
|
|
result = tool.execute(path=str(f))
|
|
assert result.success is True
|
|
assert "hello world" in result.content
|
|
assert result.metadata["size_bytes"] > 0
|
|
|
|
def test_max_lines(self, tmp_path):
|
|
f = tmp_path / "test.txt"
|
|
f.write_text("line1\nline2\nline3\nline4\n", encoding="utf-8")
|
|
tool = FileReadTool()
|
|
result = tool.execute(path=str(f), max_lines=2)
|
|
assert result.success is True
|
|
assert "line1" in result.content
|
|
assert "line2" in result.content
|
|
assert "line3" not in result.content
|
|
|
|
def test_allowed_dirs_blocks(self, tmp_path):
|
|
f = tmp_path / "secret.txt"
|
|
f.write_text("secret data", encoding="utf-8")
|
|
tool = FileReadTool(allowed_dirs=["/some/other/dir"])
|
|
result = tool.execute(path=str(f))
|
|
assert result.success is False
|
|
assert "Access denied" in result.content
|
|
|
|
def test_allowed_dirs_permits(self, tmp_path):
|
|
f = tmp_path / "ok.txt"
|
|
f.write_text("ok data", encoding="utf-8")
|
|
tool = FileReadTool(allowed_dirs=[str(tmp_path)])
|
|
result = tool.execute(path=str(f))
|
|
assert result.success is True
|
|
assert "ok data" in result.content
|
|
|
|
def test_directory_not_file(self, tmp_path):
|
|
tool = FileReadTool()
|
|
result = tool.execute(path=str(tmp_path))
|
|
assert result.success is False
|
|
assert "Not a file" in result.content
|