headroom/tests/test_rtk_installer.py
Parideboy 26e1253df0
chore: bump RTK from v0.28.2 to v0.42.4 (#1362)
## Description

Bumps the pinned RTK binary version from v0.28.2 to v0.42.4. This brings
native Windows hook support — RTK can now auto-rewrite Bash commands via
Claude's PreToolUse hook instead of relying on CLAUDE.md injection
(which only instructs rather than intercepts).

## Type of Change

- [ ] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Performance improvement
- [x] Dependency update
- [ ] Code refactoring (no functional changes)

## Changes Made

- **`headroom/rtk/__init__.py`**: `RTK_VERSION` constant changed from
`v0.28.2` to `v0.42.4`
- **`headroom/rtk/installer.py`**: Updated docstring example version to
match
- **`tests/test_rtk_installer.py`**: Updated test version string for
`test_download_rtk_skips_verify_for_non_native_target`

## Testing

- [x] Unit tests pass (`pytest`)
- [x] Linting passes (`ruff check .`)
- [ ] Type checking passes (`mypy headroom`)
- [ ] New tests added for new functionality
- [ ] Manual testing performed

### Test Output

```text
$ pytest tests/test_rtk_installer.py -v
============================= test session starts =============================
platform win32 -- Python 3.13.11
tests/test_rtk_installer.py::test_get_rtk_path_finds_windows_managed_binary PASSED
tests/test_rtk_installer.py::test_get_target_triple_uses_override PASSED
tests/test_rtk_installer.py::test_download_rtk_skips_verify_for_non_native_target PASSED
============================== 3 passed in 0.12s ==============================

$ ruff check .
All checks passed!

$ ruff format --check .
835 files already formatted
```

## Real Behavior Proof

- Environment: Windows 11 (native, not WSL), Python 3.13.11, RTK upgrade
from v0.28.2 to v0.42.4
- Exact command / steps: (1) Download rtk-x86_64-pc-windows-msvc.zip
from v0.42.4 release, (2) Replace ~/.headroom/bin/rtk.exe, (3) Run `rtk
init -g --auto-patch` to register hook, (4) Run `rtk gain` to verify
- Observed result: `rtk --version` shows "rtk 0.42.4". `rtk init -g
--auto-patch` registers hook in settings.json with "RTK hook registered
(global)" and creates RTK.md. `rtk gain` shows "No tracking data yet"
(expected before sessions run through Claude)
- Not tested: Linux/macOS environments, other AI agent integrations
(Cursor, Codex, etc.), long-running Claude Code sessions with real
traffic

## Review Readiness

- [x] I have performed a self-review
- [x] This PR is ready for human review

## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] I have updated the CHANGELOG.md if applicable

## Additional Notes

This is a dependency version bump only — no logic changes. The test
version string was updated to match for consistency.
2026-06-26 12:39:48 -05:00

74 lines
2.6 KiB
Python

"""Tests for host-target rtk installation overrides."""
from __future__ import annotations
import io
import stat
import tarfile
from pathlib import Path
from unittest.mock import patch
from headroom.rtk import get_rtk_path, installer
def test_get_rtk_path_finds_windows_managed_binary(tmp_path: Path) -> None:
managed_dir = tmp_path / ".headroom" / "bin"
managed_dir.mkdir(parents=True)
managed_path = managed_dir / "rtk.exe"
managed_path.write_bytes(b"binary")
with patch("headroom.rtk.RTK_BIN_DIR", managed_dir):
with patch("headroom.rtk.RTK_BIN_PATH", managed_dir / "rtk"):
with patch("headroom.rtk.shutil.which", return_value=None):
assert get_rtk_path() == managed_path
def test_get_target_triple_uses_override(monkeypatch) -> None:
monkeypatch.setenv("HEADROOM_RTK_TARGET", "x86_64-pc-windows-msvc")
assert installer._get_target_triple() == "x86_64-pc-windows-msvc"
def test_download_rtk_skips_verify_for_non_native_target(monkeypatch, tmp_path: Path) -> None:
archive = io.BytesIO()
with tarfile.open(fileobj=archive, mode="w:gz") as tf:
info = tarfile.TarInfo(name="rtk")
payload = b"fake-binary"
info.size = len(payload)
tf.addfile(info, io.BytesIO(payload))
archive_bytes = archive.getvalue()
class _Response:
def __enter__(self):
return self
def __exit__(self, exc_type, exc, tb):
return False
def read(self) -> bytes:
return archive_bytes
monkeypatch.setenv("HEADROOM_RTK_TARGET", "x86_64-apple-darwin")
with patch.object(installer, "RTK_BIN_DIR", tmp_path):
with patch.object(installer, "urlopen", return_value=_Response()):
with patch.object(installer.subprocess, "run") as subprocess_run:
installed_path = installer.download_rtk("v0.42.4")
assert installed_path == tmp_path / "rtk"
assert installed_path.exists()
subprocess_run.assert_not_called()
def test_register_claude_hooks_survives_forked_daemon(tmp_path: Path) -> None:
"""rtk init that exits fast but leaves a child holding stdout must not hang.
Regression: capturing through pipes made subprocess.run drain until EOF,
which a lingering grandchild deferred past the 10s timeout even though the
hooks were already registered. Output now goes to a temp file, so we wait
only on the direct child.
"""
fake_rtk = tmp_path / "rtk"
fake_rtk.write_text("#!/bin/bash\n( sleep 30 ) &\necho done\nexit 0\n")
fake_rtk.chmod(fake_rtk.stat().st_mode | stat.S_IEXEC)
assert installer.register_claude_hooks(fake_rtk) is True