mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-08-27 14:17:10 -04:00
## Description
The CI lint job (`ruff check .` → `ruff format --check .` → `mypy
headroom`) was red on `main`
and therefore on every open PR, for two unrelated reasons that the early
ruff failure was masking:
1. **ruff**: the lint job installs `ruff` unpinned, and ruff 0.15.17
began enforcing import-block
sorting (`I001`) and formatting that older ruff accepted → `ruff check
.` / `ruff format --check .`
fail on files nobody touched.
2. **mypy**: `headroom/providers/opencode/config.py` had two `return
json.loads(...)` statements in
a function declared `-> dict[str, Any]`; `json.loads` is typed `Any`, so
`mypy headroom` fails
with `no-any-return` (reproduced on mypy 1.20.2 — not a version-specific
quirk).
This restores a green lint baseline and pins both linters so a future
release can't silently break
CI again.
## Type of Change
- [x] Bug fix (non-breaking change that fixes an issue)
## Changes Made
- `.github/workflows/ci.yml`: pin `ruff==0.15.17` and `mypy==1.20.2` in
the lint job.
- Applied `ruff check --fix .` (6 `I001` import-sort fixes) and `ruff
format .` (10 files) across
the repo — import ordering and whitespace only, no behavior change.
- `headroom/providers/opencode/config.py`: narrow both
`_parse_json_loose` return sites with an
`isinstance(parsed, dict)` guard, so the `dict[str, Any]` annotation is
true at runtime
(non-dict JSON falls back to `{}`) and mypy's `no-any-return` is
resolved.
## Testing
- [x] Unit tests pass (`pytest`)
- [x] Linting passes (`ruff check .`, `ruff format --check .`, `mypy
headroom --ignore-missing-imports`)
### Test Output
```text
$ python -m ruff check .
All checks passed!
$ python -m ruff format --check .
913 files already formatted
$ python -m mypy headroom/providers/opencode/config.py --ignore-missing-imports
Success: no issues found in 1 source file
$ python -m pytest tests/test_providers_opencode_config.py -q
37 passed
```
## Real Behavior Proof
- Environment: Windows 11, Python 3.13, ruff 0.15.17, mypy 1.20.2,
branch ci/fix-ruff-lint off
headroomlabs-ai/main
- Exact command / steps: reproduced the red lint (latest ruff: 6 `I001`
+ 10 unformatted files;
the mypy failure was read from the #1295 CI lint log —
`config.py:125,133 no-any-return`, and
re-confirmed locally on mypy 1.20.2). Applied the ruff auto-fix/format,
added the dict guard,
pinned both linters, and re-ran each lint step.
- Observed result: `ruff check .` → "All checks passed!"; `ruff format
--check .` → "913 files
already formatted"; `mypy` on the fixed file → "Success: no issues
found"; full `mypy headroom`
reports only Unix `fcntl` attributes that don't exist on this Windows
box (present on the Linux
CI runner, where the prior run showed exactly the two now-fixed errors).
37 opencode-config
tests pass.
- Not tested: did not run the full OS/Python test matrix — the change is
formatting + two CI
dependency pins + a two-line type-narrowing guard, with no runtime
behavior change for dict JSON.
## Review Readiness
- [x] I have performed a self-review
- [x] This PR is ready for human review
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
71 lines
2.8 KiB
Python
71 lines
2.8 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import click
|
|
import pytest
|
|
|
|
from headroom.install import paths as install_paths
|
|
|
|
|
|
def test_validate_profile_name_accepts_and_rejects_values() -> None:
|
|
assert install_paths.validate_profile_name("good.profile-1_2") == "good.profile-1_2"
|
|
|
|
for value in (".", "..", "bad/name", "bad space", ""):
|
|
with pytest.raises(click.ClickException, match="Invalid profile name"):
|
|
install_paths.validate_profile_name(value)
|
|
|
|
|
|
def test_profile_and_artifact_paths(monkeypatch, tmp_path: Path) -> None:
|
|
monkeypatch.setattr("headroom.install.paths._paths.deploy_root", lambda: tmp_path / "deploy")
|
|
|
|
assert install_paths.deploy_root() == tmp_path / "deploy"
|
|
assert install_paths.profile_root("demo") == tmp_path / "deploy" / "demo"
|
|
assert install_paths.manifest_path("demo") == tmp_path / "deploy" / "demo" / "manifest.json"
|
|
assert install_paths.log_path("demo") == tmp_path / "deploy" / "demo" / "runner.log"
|
|
assert install_paths.pid_path("demo") == tmp_path / "deploy" / "demo" / "runner.pid"
|
|
assert (
|
|
install_paths.unix_run_script_path("demo")
|
|
== tmp_path / "deploy" / "demo" / "run-headroom.sh"
|
|
)
|
|
assert install_paths.unix_ensure_script_path("demo") == (
|
|
tmp_path / "deploy" / "demo" / "ensure-headroom.sh"
|
|
)
|
|
assert install_paths.windows_run_script_path("demo") == (
|
|
tmp_path / "deploy" / "demo" / "run-headroom.ps1"
|
|
)
|
|
assert install_paths.windows_run_cmd_path("demo") == (
|
|
tmp_path / "deploy" / "demo" / "run-headroom.cmd"
|
|
)
|
|
assert install_paths.windows_ensure_script_path("demo") == (
|
|
tmp_path / "deploy" / "demo" / "ensure-headroom.ps1"
|
|
)
|
|
assert install_paths.windows_ensure_cmd_path("demo") == (
|
|
tmp_path / "deploy" / "demo" / "ensure-headroom.cmd"
|
|
)
|
|
|
|
|
|
def test_env_target_and_config_paths(monkeypatch, tmp_path: Path) -> None:
|
|
monkeypatch.setattr(Path, "home", lambda: tmp_path)
|
|
monkeypatch.setattr("headroom.install.paths.sys.platform", "linux")
|
|
|
|
assert install_paths.unix_user_env_targets() == [
|
|
tmp_path / ".bashrc",
|
|
tmp_path / ".zshrc",
|
|
tmp_path / ".profile",
|
|
]
|
|
assert install_paths.unix_system_env_targets() == [Path("/etc/profile.d/headroom.sh")]
|
|
|
|
monkeypatch.setattr("headroom.install.paths.sys.platform", "darwin")
|
|
assert install_paths.unix_system_env_targets() == [
|
|
Path("/etc/profile"),
|
|
Path("/etc/zprofile"),
|
|
Path("/etc/bashrc"),
|
|
]
|
|
|
|
assert install_paths.claude_settings_path() == tmp_path / ".claude" / "settings.json"
|
|
assert install_paths.codex_config_path() == tmp_path / ".codex" / "config.toml"
|
|
assert install_paths.openclaw_config_path() == tmp_path / ".openclaw" / "openclaw.json"
|
|
assert (
|
|
install_paths.opencode_config_path() == tmp_path / ".config" / "opencode" / "opencode.json"
|
|
)
|