Add tests/: four suites, a runner, and a sandbox that can't escape

These grew one bug at a time in a scratch directory and were about to be thrown
away, having caught four real regressions between them. Move them in as they
are -- plain scripts, stdlib only, no test dependency -- behind a shared harness
and `python3 tests/run.py`.

The harness exists mostly for its guard. A suite testing the purge path once
sandboxed LLMHOST_CONFIG but not LLMHOST_HOME and deleted a live install's data
directory; BIN_DIR and SHIM have no env override at all, coming straight off
Path.home(). So the harness repoints those into the sandbox and then asserts
that every path llmhost could write or delete is inside it, aborting the run if
not -- verified by pointing it at a real path and watching it refuse.

The model plan the opencode suite needs is now a fixture rather than a file read
out of someone's home directory; it carries no key (the key lives in its own
file) and its machine-specific fields are pinned.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Neil Bantoc 2026-11-03 02:23:15 -08:00
parent ba7bd76af6
commit 51c2880a2e
8 changed files with 852 additions and 0 deletions

View file

@ -166,6 +166,25 @@ These avoid problems that come up on a fresh desktop install without sudo:
- Kernel builds are limited to one compile job per ~12 GB of RAM (unlimited builds can exhaust memory).
- `loginctl enable-linger` keeps the services running when you're logged out (and starts them at boot).
## Tests
Stdlib only, no test dependencies, and nothing touches a real install — every suite redirects
`LLMHOST_HOME`, `LLMHOST_CONFIG` and `XDG_*` into a temp dir, and `tests/harness.py` aborts the
run if any path llmhost could write to resolves outside it.
```bash
python3 tests/run.py # every suite
python3 tests/run.py proxy # just the ones matching "proxy"
python3 tests/test_opencode.py # or run one directly
```
| | |
|---|---|
| `tests/test_opencode.py` | provider naming and ownership, removal, the credential cache |
| `tests/test_proxy.py` | the API refusing a model that isn't loaded, against a fake `mlx_lm` |
| `tests/test_dashboard.py` | KV parsing, per-run summaries, log collapsing |
| `tests/test_reasoning.py` | effort options matching the real chat templates |
## Files
| Path | |