Test both installers against a fake root #16

Merged
patrick merged 2 commits from test/installers into main 2026-10-30 14:22:02 +00:00
Owner

Summary

agent/install.sh and server/install.sh handle tokens, root-owned config and
systemd units, and had no tests. I changed them twice recently (REPORT_HOSTNAME,
the Livepatch unit) and checked by hand.

They now take a KERNELWATCH_ROOT prefix (the agent already has one) that
prefixes every path they read or write and skips the root check. Unset, as on
real hosts, paths are unchanged; the other edits are quoting and mkdir -p
(instead of install -d) for system dirs that already exist, so nothing gets
chmod'd. Reviewers: the install.sh diffs are the part to read closely.

tests/test_install.py (27 tests) runs the real scripts against a fake root
with systemctl, apt-get, useradd, chown and others stubbed to log their
arguments:

  • fresh installs, with contents, modes and systemctl call order
  • token sources (env, file, prompt), empty tokens refused, token not echoed
  • upgrades keep config and token; rotation replaces the token
  • REPORT_HOSTNAME set, kept across upgrade and --server rewrite, cleared
  • apt-update marker, private CA, needrestart install/skip
  • failed first report, OS warnings, bad arguments, --help, refuses non-root
  • server: user created only if missing, config preserved on upgrade, old code
    replaced, interrupted upgrade recovered
  • guards: every unit/script is installed, and deploy.sh ships every file the
    agent installer uses

I checked the tests catch real breakage by mutating the scripts (world-readable
token, dropped unit, timer not started, ignored failed report, overwritten
server.toml, missing deploy file, etc.); each mutation failed a test.

Not covered

Real systemctl/apt-get/useradd behavior (stubbed). make lint couldn't run
locally (no shellcheck); CI covers it.

🤖 Generated with Claude Code

## Summary agent/install.sh and server/install.sh handle tokens, root-owned config and systemd units, and had no tests. I changed them twice recently (REPORT_HOSTNAME, the Livepatch unit) and checked by hand. They now take a `KERNELWATCH_ROOT` prefix (the agent already has one) that prefixes every path they read or write and skips the root check. Unset, as on real hosts, paths are unchanged; the other edits are quoting and `mkdir -p` (instead of `install -d`) for system dirs that already exist, so nothing gets chmod'd. Reviewers: the install.sh diffs are the part to read closely. `tests/test_install.py` (27 tests) runs the real scripts against a fake root with systemctl, apt-get, useradd, chown and others stubbed to log their arguments: - fresh installs, with contents, modes and systemctl call order - token sources (env, file, prompt), empty tokens refused, token not echoed - upgrades keep config and token; rotation replaces the token - REPORT_HOSTNAME set, kept across upgrade and --server rewrite, cleared - apt-update marker, private CA, needrestart install/skip - failed first report, OS warnings, bad arguments, --help, refuses non-root - server: user created only if missing, config preserved on upgrade, old code replaced, interrupted upgrade recovered - guards: every unit/script is installed, and deploy.sh ships every file the agent installer uses I checked the tests catch real breakage by mutating the scripts (world-readable token, dropped unit, timer not started, ignored failed report, overwritten server.toml, missing deploy file, etc.); each mutation failed a test. ## Not covered Real systemctl/apt-get/useradd behavior (stubbed). `make lint` couldn't run locally (no shellcheck); CI covers it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
patrick added 2 commits 2026-10-30 13:52:35 +00:00
KERNELWATCH_ROOT prefixes every path agent/install.sh and server/install.sh
read or write and skips their root check. Unset (as in production) every path
is unchanged; the only edits are quoting and mkdir -p for system directories
that already exist.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Test both installers against a fake root
CI / tests (Python 3.10) (pull_request) Successful in 25s
CI / tests (Python 3.11) (pull_request) Successful in 25s
CI / tests (Python 3.12) (pull_request) Successful in 24s
CI / tests (Python 3.13) (pull_request) Successful in 24s
CI / lint (pull_request) Successful in 4s
3624f0e5d9
27 tests run the real scripts with systemctl, apt-get, useradd and friends
stubbed: fresh installs, upgrades keeping config and token, token sources,
REPORT_HOSTNAME handling, apt-update marker, private CA, needrestart, failed
first report, OS warnings, argument errors, and the server's user creation,
config preservation and interrupted-upgrade recovery. Guards that every unit
and script is installed and that deploy.sh ships every file the agent
installer uses.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
patrick merged commit e3010321d7 into main 2026-10-30 14:22:02 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: patrick/kernel-automation#16