axio-tools-local 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,40 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ env:
8
+ FORCE_COLOR: 1
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ - uses: astral-sh/setup-uv@v6
16
+
17
+ - name: Set version from release tag
18
+ run: uv version "${GITHUB_REF_NAME#v}"
19
+
20
+ - name: Build package
21
+ run: uv build
22
+
23
+ - uses: actions/upload-artifact@v4
24
+ with:
25
+ name: dist
26
+ path: dist/
27
+
28
+ publish:
29
+ runs-on: ubuntu-latest
30
+ needs: build
31
+ environment: pypi
32
+ permissions:
33
+ id-token: write
34
+ steps:
35
+ - uses: actions/download-artifact@v4
36
+ with:
37
+ name: dist
38
+ path: dist/
39
+
40
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,44 @@
1
+ name: tests
2
+
3
+ on:
4
+ push:
5
+ branches: [ master, main ]
6
+ pull_request:
7
+ branches: [ master, main ]
8
+
9
+ env:
10
+ FORCE_COLOR: 1
11
+
12
+ jobs:
13
+ ruff:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - uses: astral-sh/setup-uv@v6
18
+ - run: uv sync --frozen
19
+ - run: uv run ruff check
20
+ - run: uv run ruff format --check
21
+
22
+ mypy:
23
+ runs-on: ubuntu-latest
24
+ steps:
25
+ - uses: actions/checkout@v4
26
+ - uses: astral-sh/setup-uv@v6
27
+ - run: uv sync --frozen
28
+ - run: uv run mypy .
29
+
30
+ tests:
31
+ runs-on: ubuntu-latest
32
+ strategy:
33
+ fail-fast: false
34
+ matrix:
35
+ python:
36
+ - "3.12"
37
+ - "3.13"
38
+ steps:
39
+ - uses: actions/checkout@v4
40
+ - uses: astral-sh/setup-uv@v6
41
+ with:
42
+ python-version: ${{ matrix.python }}
43
+ - run: uv sync --frozen
44
+ - run: uv run pytest -vv --cov=axio_tools_local --cov-report=term-missing
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Axio contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,16 @@
1
+ .PHONY: fmt lint typecheck test all
2
+
3
+ fmt:
4
+ uv run ruff format src/ tests/
5
+ uv run ruff check --fix src/ tests/
6
+
7
+ lint:
8
+ uv run ruff check src/ tests/
9
+
10
+ typecheck:
11
+ uv run mypy src/
12
+
13
+ test:
14
+ uv run pytest tests/ -v
15
+
16
+ all: fmt lint typecheck test
@@ -0,0 +1,8 @@
1
+ Metadata-Version: 2.4
2
+ Name: axio-tools-local
3
+ Version: 0.1.0
4
+ Summary: Core filesystem and execution tools for Axio
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.12
8
+ Requires-Dist: axio
@@ -0,0 +1,15 @@
1
+ # axio-tools-local
2
+
3
+ Core filesystem and execution tools for Axio.
4
+
5
+ Part of the [axio-agent](https://github.com/axio-agent) ecosystem.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install axio-tools-local
11
+ ```
12
+
13
+ ## License
14
+
15
+ MIT
@@ -0,0 +1,39 @@
1
+ [project]
2
+ name = "axio-tools-local"
3
+ version = "0.1.0"
4
+ description = "Core filesystem and execution tools for Axio"
5
+ requires-python = ">=3.12"
6
+ license = {text = "MIT"}
7
+ dependencies = ["axio"]
8
+
9
+ [project.entry-points."axio.tools"]
10
+ shell = "axio_tools_local.shell:Shell"
11
+ run_python = "axio_tools_local.run_python:RunPython"
12
+ write_file = "axio_tools_local.write_file:WriteFile"
13
+ patch_file = "axio_tools_local.patch_file:PatchFile"
14
+ read_file = "axio_tools_local.read_file:ReadFile"
15
+ list_files = "axio_tools_local.list_files:ListFiles"
16
+
17
+ [build-system]
18
+ requires = ["hatchling"]
19
+ build-backend = "hatchling.build"
20
+
21
+ [tool.hatch.build.targets.wheel]
22
+ packages = ["src/axio_tools_local"]
23
+
24
+ [tool.pytest.ini_options]
25
+ asyncio_mode = "auto"
26
+
27
+ [tool.ruff]
28
+ line-length = 119
29
+ target-version = "py312"
30
+
31
+ [tool.ruff.lint]
32
+ select = ["E", "F", "I", "UP"]
33
+
34
+ [tool.mypy]
35
+ strict = true
36
+ python_version = "3.12"
37
+
38
+ [dependency-groups]
39
+ dev = ["pytest>=8", "pytest-asyncio>=0.24", "mypy>=1.14", "ruff>=0.9"]
@@ -0,0 +1,6 @@
1
+ from typing import Any
2
+
3
+
4
+ def _short(value: Any, limit: int = 60) -> str:
5
+ s = str(value)
6
+ return s if len(s) <= limit else s[:limit] + "..."
@@ -0,0 +1,36 @@
1
+ import asyncio
2
+ import os
3
+ import stat as stat_module
4
+ from datetime import datetime
5
+ from pathlib import Path
6
+
7
+ from axio.tool import ToolHandler
8
+
9
+
10
+ class ListFiles(ToolHandler):
11
+ """List files and directories. Shows permissions, size, modification time,
12
+ and name for each entry. Directories are listed first and marked with
13
+ a trailing slash. Use this to explore the project structure before
14
+ reading or editing files."""
15
+
16
+ directory: str = "."
17
+
18
+ def __repr__(self) -> str:
19
+ return f"ListFiles(directory={self.directory!r})"
20
+
21
+ def _blocking(self) -> str:
22
+ path = Path(os.getcwd()) / self.directory
23
+ if not path.is_dir():
24
+ raise FileNotFoundError(f"{self.directory} is not a valid directory")
25
+ lines: list[str] = []
26
+ for fpath in sorted(path.glob("*"), key=lambda p: (not p.is_dir(), p.name)):
27
+ st = fpath.stat()
28
+ mode = stat_module.filemode(st.st_mode)
29
+ size = st.st_size
30
+ mtime = datetime.fromtimestamp(st.st_mtime).strftime("%b %d %H:%M")
31
+ name = fpath.name + ("/" if fpath.is_dir() else "")
32
+ lines.append(f"{mode} {size:>8} {mtime} {name}")
33
+ return "\n".join(lines) or "(empty directory)"
34
+
35
+ async def __call__(self) -> str:
36
+ return await asyncio.to_thread(self._blocking)
@@ -0,0 +1,46 @@
1
+ import asyncio
2
+ import os
3
+ from pathlib import Path
4
+
5
+ from axio.tool import ToolHandler
6
+
7
+
8
+ class PatchFile(ToolHandler):
9
+ """Replace a range of lines in an existing file. Lines are 0-indexed:
10
+ from_line is inclusive, to_line is exclusive. The content string replaces
11
+ lines[from_line:to_line]. Always read the file first to get correct
12
+ line numbers. Use this for surgical edits instead of rewriting the
13
+ whole file with write_file."""
14
+
15
+ file_path: str
16
+ mode: int = 0o644
17
+ from_line: int
18
+ to_line: int
19
+ content: str
20
+
21
+ def __repr__(self) -> str:
22
+ return (
23
+ f"PatchFile(file_path={self.file_path!r},"
24
+ f" lines={self.from_line}:{self.to_line}, content=<{len(self.content)} chars>)"
25
+ )
26
+
27
+ def _blocking(self) -> str:
28
+ path = Path(os.getcwd()) / self.file_path
29
+ if not path.is_file():
30
+ raise FileNotFoundError(f"{self.file_path} is not a valid file")
31
+
32
+ # read all lines
33
+ with path.open("r") as f:
34
+ lines = f.readlines()
35
+
36
+ # content lines
37
+ content = self.content.splitlines()
38
+
39
+ # patch lines
40
+ new_lines = lines[: self.from_line] + content + lines[self.to_line :]
41
+ with path.open("w") as f:
42
+ f.writelines(new_lines)
43
+ return f"{f.tell()} bytes written to {self.file_path}"
44
+
45
+ async def __call__(self) -> str:
46
+ return await asyncio.to_thread(self._blocking)
@@ -0,0 +1,41 @@
1
+ import asyncio
2
+ import os
3
+
4
+ from axio.tool import ToolHandler
5
+
6
+
7
+ class ReadFile(ToolHandler):
8
+ """Read file contents. Returns text for text files, hex for binaries.
9
+ Use start_line/end_line to read a specific range of lines (0-indexed).
10
+ Large files are truncated to max_chars. Always read the file before
11
+ editing it with write_file or patch_file."""
12
+
13
+ filename: str
14
+ max_chars: int = 32768
15
+ binary_as_hex: bool = True
16
+ start_line: int | None = None
17
+ end_line: int | None = None
18
+
19
+ def __repr__(self) -> str:
20
+ return f"ReadFile(filename={self.filename!r})"
21
+
22
+ def _blocking(self) -> str:
23
+ path = os.path.join(os.getcwd(), self.filename)
24
+ if self.start_line is None and self.end_line is None:
25
+ with open(path, "rb") as f:
26
+ result = f.read(self.max_chars)
27
+ try:
28
+ return result.decode()
29
+ except UnicodeDecodeError:
30
+ if self.binary_as_hex:
31
+ return "Encoded binary data HEX: " + result.hex()
32
+ raise
33
+ with open(path) as f:
34
+ lines = f.readlines()[self.start_line : self.end_line]
35
+ content = "".join(lines)
36
+ if len(content) > self.max_chars:
37
+ return content[: self.max_chars] + "\n...[truncated]"
38
+ return content.strip()
39
+
40
+ async def __call__(self) -> str:
41
+ return await asyncio.to_thread(self._blocking)
@@ -0,0 +1,56 @@
1
+ import asyncio
2
+ import os
3
+ import subprocess
4
+ import sys
5
+ import tempfile
6
+
7
+ from axio.tool import ToolHandler
8
+
9
+ from . import _short
10
+
11
+
12
+ class RunPython(ToolHandler):
13
+ """Run a Python code snippet in a subprocess and return stdout/stderr.
14
+ The code is written to a temp file and executed with the current
15
+ interpreter. Use for calculations, data processing, or testing
16
+ small scripts. Optionally pass stdin data. Non-zero exit codes
17
+ and tracebacks are returned as-is."""
18
+
19
+ code: str
20
+ cwd: str = "."
21
+ timeout: int = 5
22
+ stdin: str | None = None
23
+
24
+ def __repr__(self) -> str:
25
+ return f"RunPython(code={_short(self.code)!r}, cwd={self.cwd!r})"
26
+
27
+ def _blocking(self) -> str:
28
+ with tempfile.NamedTemporaryFile(mode="w", suffix=".py") as f:
29
+ f.write(self.code)
30
+ f.flush()
31
+
32
+ path = f.name
33
+
34
+ try:
35
+ result = subprocess.run(
36
+ [sys.executable, path],
37
+ capture_output=True,
38
+ text=True,
39
+ timeout=self.timeout,
40
+ cwd=self.cwd,
41
+ input=self.stdin if self.stdin is not None else None,
42
+ stdin=subprocess.DEVNULL if self.stdin is None else None,
43
+ )
44
+ output = ""
45
+ if result.stdout:
46
+ output += result.stdout
47
+ if result.stderr:
48
+ output += f"\n[stderr]\n{result.stderr}"
49
+ if result.returncode != 0:
50
+ output += f"\n[exit code: {result.returncode}]"
51
+ return output.strip() or "(no output)"
52
+ finally:
53
+ os.unlink(path)
54
+
55
+ async def __call__(self) -> str:
56
+ return await asyncio.to_thread(self._blocking)
@@ -0,0 +1,44 @@
1
+ import asyncio
2
+ import subprocess
3
+
4
+ from axio.tool import ToolHandler
5
+
6
+ from . import _short
7
+
8
+
9
+ class Shell(ToolHandler):
10
+ """Run a shell command and return combined stdout/stderr. Use for git,
11
+ build tools, grep, tests, or any CLI operation. Non-zero exit codes
12
+ are reported. Optionally pass stdin data for commands that read from
13
+ standard input. Prefer short timeouts and avoid interactive commands."""
14
+
15
+ command: str
16
+ timeout: int = 5
17
+ cwd: str = "."
18
+ stdin: str | None = None
19
+
20
+ def __repr__(self) -> str:
21
+ return f"Shell(command={_short(self.command)!r}, cwd={self.cwd!r})"
22
+
23
+ def _blocking(self) -> str:
24
+ result = subprocess.run(
25
+ self.command,
26
+ shell=True,
27
+ capture_output=True,
28
+ text=True,
29
+ timeout=self.timeout,
30
+ cwd=self.cwd,
31
+ input=self.stdin if self.stdin is not None else None,
32
+ stdin=subprocess.DEVNULL if self.stdin is None else None,
33
+ )
34
+ output = ""
35
+ if result.stdout:
36
+ output += result.stdout
37
+ if result.stderr:
38
+ output += f"\n[stderr]\n{result.stderr}"
39
+ if result.returncode != 0:
40
+ output += f"\n[exit code: {result.returncode}]"
41
+ return output.strip() or "(no output)"
42
+
43
+ async def __call__(self) -> str:
44
+ return await asyncio.to_thread(self._blocking)
@@ -0,0 +1,28 @@
1
+ import asyncio
2
+ import os
3
+
4
+ from axio.tool import ToolHandler
5
+
6
+
7
+ class WriteFile(ToolHandler):
8
+ """Create or overwrite a file with the given content. Parent directories
9
+ are created automatically. Use this for new files or full rewrites.
10
+ For partial edits prefer patch_file instead."""
11
+
12
+ file_path: str
13
+ content: str
14
+ mode: int = 0o644
15
+
16
+ def __repr__(self) -> str:
17
+ return f"WriteFile(file_path={self.file_path!r}, content=<{len(self.content)} chars>)"
18
+
19
+ def _blocking(self) -> str:
20
+ path = os.path.join(os.getcwd(), self.file_path)
21
+ os.makedirs(os.path.dirname(path), exist_ok=True)
22
+ with open(path, "w") as f:
23
+ f.write(self.content)
24
+ os.chmod(path, mode=self.mode)
25
+ return f"Wrote {len(self.content)} bytes to {self.file_path}"
26
+
27
+ async def __call__(self) -> str:
28
+ return await asyncio.to_thread(self._blocking)
@@ -0,0 +1 @@
1
+ """Shared test fixtures for axio-tools-local."""
@@ -0,0 +1,62 @@
1
+ """Tests for ListFiles tool handler."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from pathlib import Path
7
+
8
+ from axio_tools_local.list_files import ListFiles
9
+
10
+
11
+ class TestListFiles:
12
+ async def test_list_directory(self, tmp_path: Path) -> None:
13
+ (tmp_path / "a.txt").write_text("a")
14
+ (tmp_path / "b.txt").write_text("b")
15
+ (tmp_path / "subdir").mkdir()
16
+ old_cwd = os.getcwd()
17
+ try:
18
+ os.chdir(tmp_path)
19
+ handler = ListFiles(directory=".")
20
+ result = await handler()
21
+ assert "a.txt" in result
22
+ assert "b.txt" in result
23
+ assert "subdir/" in result
24
+ finally:
25
+ os.chdir(old_cwd)
26
+
27
+ async def test_empty_directory(self, tmp_path: Path) -> None:
28
+ empty = tmp_path / "empty"
29
+ empty.mkdir()
30
+ old_cwd = os.getcwd()
31
+ try:
32
+ os.chdir(tmp_path)
33
+ handler = ListFiles(directory="empty")
34
+ result = await handler()
35
+ assert result == "(empty directory)"
36
+ finally:
37
+ os.chdir(old_cwd)
38
+
39
+ async def test_default_directory(self, tmp_path: Path) -> None:
40
+ (tmp_path / "file.txt").write_text("x")
41
+ old_cwd = os.getcwd()
42
+ try:
43
+ os.chdir(tmp_path)
44
+ handler = ListFiles()
45
+ assert handler.directory == "."
46
+ result = await handler()
47
+ assert "file.txt" in result
48
+ finally:
49
+ os.chdir(old_cwd)
50
+
51
+ async def test_not_a_directory(self, tmp_path: Path) -> None:
52
+ old_cwd = os.getcwd()
53
+ try:
54
+ os.chdir(tmp_path)
55
+ handler = ListFiles(directory="nope")
56
+ try:
57
+ await handler()
58
+ assert False, "Should have raised"
59
+ except FileNotFoundError:
60
+ pass
61
+ finally:
62
+ os.chdir(old_cwd)
@@ -0,0 +1,45 @@
1
+ """Tests for PatchFile tool handler."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from pathlib import Path
7
+
8
+ from axio_tools_local.patch_file import PatchFile
9
+
10
+
11
+ class TestPatchFile:
12
+ async def test_patch_lines(self, tmp_path: Path) -> None:
13
+ target = tmp_path / "file.txt"
14
+ target.write_text("line0\nline1\nline2\nline3\n")
15
+ old_cwd = os.getcwd()
16
+ try:
17
+ os.chdir(tmp_path)
18
+ handler = PatchFile(file_path="file.txt", from_line=1, to_line=3, content="replaced\n")
19
+ result = await handler()
20
+ assert "bytes written" in result
21
+ content = target.read_text()
22
+ assert "replaced" in content
23
+ assert "line1" not in content
24
+ assert "line2" not in content
25
+ finally:
26
+ os.chdir(old_cwd)
27
+
28
+ async def test_file_not_found(self, tmp_path: Path) -> None:
29
+ old_cwd = os.getcwd()
30
+ try:
31
+ os.chdir(tmp_path)
32
+ handler = PatchFile(file_path="missing.txt", from_line=0, to_line=1, content="x")
33
+ try:
34
+ await handler()
35
+ assert False, "Should have raised"
36
+ except FileNotFoundError:
37
+ pass
38
+ finally:
39
+ os.chdir(old_cwd)
40
+
41
+ async def test_repr(self) -> None:
42
+ handler = PatchFile(file_path="f.py", from_line=5, to_line=10, content="code")
43
+ r = repr(handler)
44
+ assert "f.py" in r
45
+ assert "5:10" in r
@@ -0,0 +1,49 @@
1
+ """Tests for ReadFile tool handler."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from pathlib import Path
7
+
8
+ from axio_tools_local.read_file import ReadFile
9
+
10
+
11
+ class TestReadFile:
12
+ async def test_read_text(self, tmp_path: Path) -> None:
13
+ (tmp_path / "hello.txt").write_text("content here")
14
+ old_cwd = os.getcwd()
15
+ try:
16
+ os.chdir(tmp_path)
17
+ handler = ReadFile(filename="hello.txt")
18
+ result = await handler()
19
+ assert result == "content here"
20
+ finally:
21
+ os.chdir(old_cwd)
22
+
23
+ async def test_read_binary_as_hex(self, tmp_path: Path) -> None:
24
+ (tmp_path / "bin.dat").write_bytes(b"\x80\x81\xff")
25
+ old_cwd = os.getcwd()
26
+ try:
27
+ os.chdir(tmp_path)
28
+ handler = ReadFile(filename="bin.dat", binary_as_hex=True)
29
+ result = await handler()
30
+ assert "8081ff" in result
31
+ finally:
32
+ os.chdir(old_cwd)
33
+
34
+ async def test_file_not_found(self, tmp_path: Path) -> None:
35
+ old_cwd = os.getcwd()
36
+ try:
37
+ os.chdir(tmp_path)
38
+ handler = ReadFile(filename="nope.txt")
39
+ try:
40
+ await handler()
41
+ assert False, "Should have raised"
42
+ except FileNotFoundError:
43
+ pass
44
+ finally:
45
+ os.chdir(old_cwd)
46
+
47
+ async def test_repr(self) -> None:
48
+ handler = ReadFile(filename="test.py")
49
+ assert "test.py" in repr(handler)
@@ -0,0 +1,38 @@
1
+ """Tests for RunPython tool handler."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from axio_tools_local.run_python import RunPython
6
+
7
+
8
+ class TestRunPython:
9
+ async def test_simple_print(self) -> None:
10
+ handler = RunPython(code="print('hello')", timeout=5)
11
+ result = await handler()
12
+ assert "hello" in result
13
+
14
+ async def test_error(self) -> None:
15
+ handler = RunPython(code="raise ValueError('boom')", timeout=5)
16
+ result = await handler()
17
+ assert "ValueError" in result
18
+ assert "exit code:" in result
19
+
20
+ async def test_stdin_devnull(self) -> None:
21
+ """stdin must be /dev/null so subprocesses can't steal TUI key events."""
22
+ handler = RunPython(code="import sys; data = sys.stdin.read(); print(repr(data))", timeout=2)
23
+ result = await handler()
24
+ # stdin is /dev/null → immediate EOF → empty string
25
+ assert "''" in result
26
+
27
+ async def test_stdin_passthrough(self) -> None:
28
+ handler = RunPython(
29
+ code="import sys; print(sys.stdin.read())",
30
+ timeout=5,
31
+ stdin="hello from stdin",
32
+ )
33
+ result = await handler()
34
+ assert "hello from stdin" in result
35
+
36
+ async def test_repr(self) -> None:
37
+ handler = RunPython(code="x = 1")
38
+ assert "x = 1" in repr(handler)
@@ -0,0 +1,45 @@
1
+ """Tests for Shell tool handler."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+
7
+ from axio_tools_local.shell import Shell
8
+
9
+
10
+ class TestShell:
11
+ async def test_echo(self) -> None:
12
+ handler = Shell(command="echo hello", timeout=5)
13
+ result = await handler()
14
+ assert "hello" in result
15
+
16
+ async def test_stderr(self) -> None:
17
+ handler = Shell(command="echo err >&2", timeout=5)
18
+ result = await handler()
19
+ assert "err" in result
20
+
21
+ async def test_nonzero_exit(self) -> None:
22
+ handler = Shell(command="exit 42", timeout=5)
23
+ result = await handler()
24
+ assert "exit code: 42" in result
25
+
26
+ async def test_cwd(self, tmp_path: Path) -> None:
27
+ handler = Shell(command="pwd", timeout=5, cwd=str(tmp_path))
28
+ result = await handler()
29
+ assert str(tmp_path) in result
30
+
31
+ async def test_stdin_devnull(self) -> None:
32
+ """stdin must be /dev/null so subprocesses can't steal TUI key events."""
33
+ handler = Shell(command="cat", timeout=2)
34
+ result = await handler()
35
+ # cat with no args + /dev/null stdin → immediate EOF → "(no output)"
36
+ assert result == "(no output)"
37
+
38
+ async def test_stdin_passthrough(self) -> None:
39
+ handler = Shell(command="cat", timeout=5, stdin="hello from stdin")
40
+ result = await handler()
41
+ assert "hello from stdin" in result
42
+
43
+ async def test_repr(self) -> None:
44
+ handler = Shell(command="echo hi")
45
+ assert "echo hi" in repr(handler)
@@ -0,0 +1,37 @@
1
+ """Tests for WriteFile tool handler."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from pathlib import Path
7
+
8
+ from axio_tools_local.write_file import WriteFile
9
+
10
+
11
+ class TestWriteFile:
12
+ async def test_write_and_read_back(self, tmp_path: Path) -> None:
13
+ target = tmp_path / "out.txt"
14
+ old_cwd = os.getcwd()
15
+ try:
16
+ os.chdir(tmp_path)
17
+ handler = WriteFile(file_path="out.txt", content="hello world")
18
+ result = await handler()
19
+ assert "11" in result # 11 bytes
20
+ assert target.read_text() == "hello world"
21
+ finally:
22
+ os.chdir(old_cwd)
23
+
24
+ async def test_creates_subdirectories(self, tmp_path: Path) -> None:
25
+ old_cwd = os.getcwd()
26
+ try:
27
+ os.chdir(tmp_path)
28
+ handler = WriteFile(file_path="sub/dir/file.txt", content="nested")
29
+ await handler()
30
+ assert (tmp_path / "sub" / "dir" / "file.txt").read_text() == "nested"
31
+ finally:
32
+ os.chdir(old_cwd)
33
+
34
+ async def test_repr(self) -> None:
35
+ handler = WriteFile(file_path="f.txt", content="abc")
36
+ assert "f.txt" in repr(handler)
37
+ assert "3 chars" in repr(handler)