root-ubuntu: cover configure_sensors with tests - #39
Merged
Conversation
The sensor detection step had no test at all, so the two things that make it more than `sensors-detect --auto` were unguarded: the systemd-detect-virt check that keeps it off VMs, and the i2c-dev modprobe that has to happen first because --auto answers no to loading it. Both are now asserted, along with the re-check of /sys/class/hwmon after detection (sensors-detect exits 0 on a machine with no supported chips, so its status alone proves nothing) and the warn-but-return-0 path that keeps a failed probe from aborting the provisioning run. A last check ties the two halves together: lm-sensors in BASE_PACKAGES, and the step wired into apt. The six commands the function reaches the machine through are shadowed, so the real body runs and nothing touches the box the tests run on. Verified by mutation: neutering the VM guard fails the VM test, dropping the modprobe fails the i2c-dev test. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GFdGuLQcpyGhsKzbU4voLK
ThreatCrush Security Scan16 finding(s) HIGH/CRITICAL: 5 | MEDIUM: 2 | LOW: 9
Snippets are redacted; ThreatCrush never prints matched credential material. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
configure_sensorswas the one step inroot-ubuntu.shwith no test coverage, which mattered more than usual because the function is deliberately not the one-liner it looks like. Three of its behaviours existed only as comments:systemd-detect-virtkeepssensors-detectoff guests, which are never shown the host's thermal hardware. Without it every Droplet run writes an empty config that reads like a failed detection rather than like a machine with nothing to detect.i2c-devmodprobe —sensors-detectfinds SMBus chips through/dev/i2c-*, which do not exist until the module is loaded, and--autotakes the default answer to that prompt, which is no.sensors-detectexits 0 on a machine with no supported chips, so its status alone is not evidence. The honest signal is atemp*_inputappearing under/sys/class/hwmon.Also covered: the warn-but-return-0 path, so a failed probe never aborts provisioning, and one assertion tying the halves together (
lm-sensorsinBASE_PACKAGES, the step wired into the apt run) — a detection step is dead code if the package never lands, and the package is dead weight if nothing probes.How it runs
Following the existing
configure_swappattern: the six commands the function reaches the machine through (command -v,systemd-detect-virt,compgen -G,modprobe,sensors-detect,systemctl) are shadowed, so the real body executes and the tests still cannot touch the box they run on.HWMONstands in for "/sys/class/hwmon has a reading in it" and thesensors-detectstub flips it, which is what makes the post-detection re-check a real assertion instead of a restatement of the stub's return code.Verification
pnpm test— 600 passed across 26 files, 7 of them new.Mutation-checked rather than assumed: neutering the VM guard fails the VM test alone, and dropping the
modprobeline fails the i2c-dev test alone.root-ubuntu.shitself is unchanged in this branch.pnpm typecheckfails on two pre-existingexactOptionalPropertyTypeserrors insrc/free-names.ts, present at master's tip and untouched here.🤖 Generated with Claude Code
https://claude.ai/code/session_01GFdGuLQcpyGhsKzbU4voLK