Skip to content

test: add CLI behavior spec and defaults-isolation seam - #30

Merged
toobuntu merged 5 commits into
mainfrom
feature/cli-test-harness
Jul 20, 2026
Merged

test: add CLI behavior spec and defaults-isolation seam#30
toobuntu merged 5 commits into
mainfrom
feature/cli-test-harness

Conversation

@toobuntu

@toobuntu toobuntu commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Summary

PR #29 shipped the cursor-on-black CLI surface (recovery, recover --method, repro --trigger/--lock, the auto-recovery pref) with no automated tests — and, as it turned out, none of the existing CLI had ever been tested either. This adds a full CLI behavior spec plus the isolation seam that lets it run hermetically, and records the hardware-only behaviors as manual checklist items.

What's here

  • test: add BLACKOUTD_DEFAULTS_SUITE isolation seam — the CLI preference helpers now read/write through cliSuiteName(), which honors a BLACKOUTD_DEFAULTS_SUITE env override. When set, the auto/verbosity/recovery write-backs divert to a throwaway suite and skip signalling the daemon, printing an isolated test suite marker. The daemon (AppDelegate.m) is deliberately not wired to the seam — it always reads the real blackoutd suite — so a test can never perturb real daemon behavior. Env unset ⇒ behavior identical to before.
  • test: add CLI behavior spec (31 examples)spec/integration/cli_spec.rb builds the binary once (the RSpec CI job runs on macOS but doesn't build) and covers top-level dispatch, --version, every validation/rejection path, all three recover --method dry-runs, and the repro --dry-run walkthrough. The walkthrough assertions pin the W1 ordering fix (trigger before schedule, lock before schedule, an awake cue between sleep and capture, --wake 0 skips sudo). Accept-paths run against an isolated suite; one example proves an isolated write leaves the real suite untouched.
  • docs: add manual tests for recovery and repro — the hardware/daemon behaviors (auto-recovery firing at wake, recover --method extcycle unlocked-only, the repro harness) go to spec/manual/TESTING.md, satisfying P20's manual-test acceptance item.

Verification

bundle exec rspec goes from 59 → 90 examples, 0 failures (the pre-existing prepush_signing_spec gpg-agent case needs a live agent). clang-format, clang-tidy, and reuse --no-multiprocessing lint all clean. The isolation seam was checked directly: an isolated recovery none leaves the real suite's recoveryStrategy at displaysleep.

The test-scope split (automated CLI/dry-run + isolated accept-paths; hardware/daemon behavior manual) is intentional.

Written with AI assistance (Claude Opus 4.8).

Summary by CodeRabbit

  • New Features

    • Added CLI support for managing verbosity, recovery, and automatic behavior settings.
    • Added recovery and reproduction workflows with validation, dry-run guidance, and detailed progress cues.
    • Expanded command usage and help output with the new subcommands, methods, and options.
  • Documentation

    • Added manual testing guidance for cursor-on-black recovery scenarios and the reproduction workflow.
  • Tests

    • Added comprehensive integration coverage for CLI dispatch, validation, persistence, status reporting, recovery, and dry-run behavior.

toobuntu and others added 3 commits July 20, 2026 11:33
Route the CLI preference helpers (status/config reads and the
auto/verbosity/recovery write-backs) through cliSuiteName(), which
returns the BLACKOUTD_DEFAULTS_SUITE env override when set and the
real "blackoutd" suite otherwise. When the override is present the
write-back subcommands also skip signalling the daemon and print an
"isolated test suite" marker.

This lets the RSpec CLI harness exercise the accept-paths without
mutating the user's real preferences or perturbing the running
daemon. The daemon (AppDelegate.m) is deliberately NOT wired to the
seam — it always reads the hardcoded kSuiteName — so a test suite can
never change real daemon behavior. Env unset reproduces today's
behavior exactly.

Verified: an isolated `recovery none` leaves the real suite's
recoveryStrategy unchanged and emits the isolation marker.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
First automated coverage of the blackoutd CLI, none of which existed
before. Builds the binary once in before(:all) (the RSpec CI job runs
on macOS but does not build) and exercises the pure surface —
top-level dispatch and usage, --version, and every
validation/rejection path for verbosity/recovery/auto/recover/repro —
plus the --dry-run repro walkthrough, whose ordering assertions pin
the W1 fix (trigger precedes scheduling the wake; lock precedes
schedule; an "awake" cue lands between sleep and capture; --wake 0
skips sudo).

The auto/verbosity/recovery accept-paths run against a throwaway
NSUserDefaults suite via BLACKOUTD_DEFAULTS_SUITE, asserting the
isolation marker; one example confirms an isolated write leaves the
real suite untouched. Hardware- and daemon-affecting behavior stays
in spec/manual/TESTING.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Record the hardware- and daemon-dependent behaviors that the CLI spec
cannot cover: auto-recovery firing (and not firing) at wake per the
recoveryStrategy pref, manual recover methods (extcycle unlocked-only),
and the repro harness (trigger, awake cue, --lock). Satisfies P20's
"manual repro test added to spec/manual/TESTING.md" acceptance item.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@toobuntu, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 23 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 3fe22596-dc95-45e3-bf17-480e2431901b

📥 Commits

Reviewing files that changed from the base of the PR and between 4434b46 and cc0c8ea.

📒 Files selected for processing (2)
  • spec/integration/cli_spec.rb
  • src/main.m
📝 Walkthrough

Walkthrough

The PR adds macOS CLI integration tests, isolated defaults-suite support for preference writes, recovery and repro validation, and manual testing guidance for auto-recovery and repro workflows.

Changes

CLI coverage and validation

Layer / File(s) Summary
CLI harness and top-level dispatch
spec/integration/cli_spec.rb, src/main.m
The suite builds and invokes the macOS binary, verifies dispatch and version behavior, and checks documented usage output. CLI defaults isolation is added for reporting and preference writes.
Preference writes and recovery commands
spec/integration/cli_spec.rb, src/main.m
Tests validate verbosity, recovery, and auto arguments and isolated persistence, plus recover method validation and dry-run output.
Repro workflow validation and guidance
spec/integration/cli_spec.rb, spec/manual/TESTING.md
Tests validate repro arguments and dry-run cue ordering; manual checklists cover cursor recovery and maintainer repro runs.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested reviewers: copilot

Poem

A rabbit hops through CLI snow,
Checks each cue in tidy flow.
Defaults sleep in suites apart,
Recovery paths are mapped with heart.
Repro steps thump, then logs take flight.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the added CLI test coverage and defaults-isolation seam.
Description check ✅ Passed The description covers summary, changes, and verification, though it uses non-template headings and a narrative test section.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/cli-test-harness

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main.m`:
- Around line 38-46: Update the new comments in src/main.m to use en_US
spelling, replacing “signalling” with “signaling” and “signalled” with
“signaled” while leaving the implementation unchanged.
- Around line 47-55: Validate the environment override in cliSuiteName(),
rejecting invalid UTF-8 and the reserved kSuiteName value before returning it;
fall back to kSuiteName for rejected values. Update cliDefaultsIsolated() to
depend on whether cliSuiteName() yields a valid non-reserved override, so
isolation is not enabled for the real daemon suite.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: bd2b8964-0d0b-4632-b591-8d7f9df677aa

📥 Commits

Reviewing files that changed from the base of the PR and between 2fbab14 and 4434b46.

📒 Files selected for processing (3)
  • spec/integration/cli_spec.rb
  • spec/manual/TESTING.md
  • src/main.m

Comment thread src/main.m Outdated
Comment thread src/main.m Outdated
toobuntu and others added 2 commits July 20, 2026 12:10
Rename the isolation env var BLACKOUTD_DEFAULTS_SUITE ->
BLACKOUTD_TEST_DEFAULTS_SUITE to name it for its purpose (the
project's own test suite; not a supported interface), and validate it
once at startup in initCliDefaults(): an override equal to the real
"blackoutd" suite, or one that is not valid UTF-8, is now a hard error
(exit 2) printed before any subcommand runs — so it cannot write real
or global preferences while skipping the daemon signal, and the
rejection paths are safe to exercise from the test harness. cliSuiteName()
and cliDefaultsIsolated() read a single resolved result, so they can
never disagree.

Also corrects the seam comments to en_US spelling (signaling /
signaled) per the project convention.

Addresses PR #30 review (CodeRabbit): the =blackoutd and invalid-UTF-8
edge cases. Env unset ⇒ behavior identical to before.

Verified: valid override isolates; =blackoutd and non-UTF-8 abort with
exit 2 and no write; normal `status` unaffected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Fix the CI failure in "leaves the real blackoutd suite untouched":
compare `defaults read` stdout only. An absent key (the CI case) sends
a timestamped `defaults[pid]` diagnostic to stderr that differs
between the before/after calls; stdout is the value or empty and is
stable. The local machine had the key set, hiding the flake.

Rename the isolation env var to BLACKOUTD_TEST_DEFAULTS_SUITE and add
a "test-suite isolation guard" group: the real-suite name and a
non-UTF-8 value each abort with exit 2 and leave the real suite
untouched — now testable because the seam errors before any write
rather than falling back to the real suite. 34 examples, 0 failures.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@toobuntu
toobuntu merged commit bb26555 into main Jul 20, 2026
15 checks passed
@toobuntu
toobuntu deleted the feature/cli-test-harness branch July 20, 2026 16:13
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