Skip to content

test(bootstrap): behavioral coverage for sysload-writer and install_launch_agent#322

Open
evansenter wants to merge 1 commit into
mainfrom
fix/sysload-launchagent-tests
Open

test(bootstrap): behavioral coverage for sysload-writer and install_launch_agent#322
evansenter wants to merge 1 commit into
mainfrom
fix/sysload-launchagent-tests

Conversation

@evansenter

Copy link
Copy Markdown
Owner

What

Closes the last open test gap from the new-machine-readiness audit (event-bus events 4152 / 4159). sysload-writer and the LaunchAgent installer had zero tests despite both being prior confirmed-failure surfaces (the sysload zjstatus widget flicker, the launchctl || true crash on re-bootstrap).

The bus repeatedly flagged that tests/test-bootstrap.sh was mostly grep -q 'fn_name' presence checks — proving functions are named, not that they work. These four are behavioral.

Tests added

Test Exercises
sysload-writer writes cache from top output stubs top, asserts ~/.cache/sysload gets computed CPU% (100 - idle) and RAM% (used/(used+unused)) — verified 85% idle → 15%, 20G/2949M → 87%
sysload-writer tolerates top failure top exits 1 → writer exits 0 and writes no cache (KeepAlive sanity / widget keeps last good value)
launch agent substitutes __HOME__ and reloads real install_launch_agent expands __HOME__ in the plist, leaves no placeholder, calls launchctl bootstrap
launch agent idempotent on unchanged plist second run on identical plist does not reinstall or re-call launchctl (the cmp -s guard)

Note on install_launch_agent

It derives dotfiles_dir from BASH_SOURCE, which eval can't satisfy — so the loader redirects that one line at a fixture tree (same pattern as the existing _load_is_gateway_host helper). Everything actually under test — the __HOME__ sed, the cmp-based idempotency guard, the launchctl reload — is the genuine bootstrap code.

Verification

make check green (lint, 39 bootstrap tests, hooks). All four mutation-verified: removing the __HOME__ sed, the cmp guard, or the writer's failure guards each flips the corresponding test red; the broken-writer assertion was confirmed to discriminate against the real writer.

🤖 Generated with Claude Code

…aunch_agent

Closes the last open test gap from the new-machine-readiness audit (event-bus
events 4152 / 4159): sysload-writer and the LaunchAgent installer had zero
tests despite both being prior confirmed-failure surfaces.

Adds four behavioral tests (not grep-presence):
- sysload-writer parses stubbed `top` output into ~/.cache/sysload with the
  computed CPU% (100 - idle) and RAM% (used/(used+unused))
- sysload-writer exits 0 and writes no cache when `top` fails (KeepAlive sanity)
- install_launch_agent expands __HOME__ in the plist and reloads via launchctl
- install_launch_agent is idempotent: an unchanged plist is not reinstalled

install_launch_agent derives its dotfiles_dir from BASH_SOURCE, which eval can't
satisfy, so the loader redirects that single line at a fixture tree; the
substitution / cmp-idempotency / launchctl-reload logic under test is the real
bootstrap code. All four mutation-verified (removing each guard flips the test).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prompt: evansenter/dotfiles/.../claude-review.md

Code Review

Summary
Adds four behavioral tests covering sysload-writer (CPU/RAM cache computation and top-failure tolerance) and the real install_launch_agent (__HOME__ substitution and the cmp-based idempotency guard). Verified against the actual sources: the writer 100 - idle to 15% and used/(used+unused) to 87% math is correct, the top || exit 0 failure path matches the no-cache assertion, and the eval-based loader redirects only the BASH_SOURCE-derived dotfiles_dir line (mirroring the existing _load_is_gateway_host pattern) while exercising the genuine sed/cmp/launchctl logic. These replace presence-only grep -q fn_name checks with real behavioral coverage. Lint/syntax look clean and the function-under-test setup faithfully matches bootstrap.sh line 395.

Findings

[Suggestion] tests/test-bootstrap.sh:430-431 — The substring assertions grep -q 15% and grep -q 87% would also pass on a buggy value (15% matches 115%; 87% matches 187%). Since the writer emits a fixed format string, asserting the full expected output (the glyph plus both values together) would both tighten the bound and pin the exact widget output that zjstatus consumes, rather than checking each percentage in isolation. Minor — the mutation testing already gives good confidence.

Verdict
APPROVE - Only one minor suggestion; no Critical or Important issues.

(Note: inline comments could not be posted from this environment — its static-analysis guards reject the JSON payload required by the reviews API, so the single finding is inlined here with its file:line.)

Automated review by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant