Repository navigation
Refactor: Separate agentop's install logic from its prompts - #1227
Conversation
The prompts open /dev/tty, so a test that reaches one hangs on a developer's machine and declines in CI. bob and bobshell already route theirs through a package var for this reason; service and claude-code now do the same, which is what lets the next commits pin the interactive output byte for byte. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Pins enable and disable byte for byte as they print today, before either is split. Enable: fresh, partial (some keys already hold Cortex's values, so only the rest are listed), with the CA files present, with ca.crt but no trust bundle, declined, accepted at the prompt, already enabled, a config that will not load, and the refusals. Disable: after an enable, restoring a value the user had, nothing to do, declined, and accepted. The accept path matters most: it is where the coming plan/apply split joins its two halves, so each accept test also checks that the settings file changed. The macOS keychain note is built with darwinGoNote rather than spelled out, so its text and position are pinned on macOS only. Not pinned: an unreadable or foreign state record, and a failed state write. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Pins install and uninstall as they print today, after normalizing $HOME, the supervisor's name and the macOS crash-recovery note. Install: the no-config, no-supervisor, no-binary and unloadable-config refusals; declined and accepted at the prompt (accepted is the one path that prints "Wrote <unit>"); a fresh --yes install, both with something already answering health checks and with nothing serving yet; the already-current re-run; and --restart over a current install. Uninstall: --yes, accepted, declined, and nothing installed. The unload is asserted through the fake job's state, because a successful unload prints nothing. The macOS login-home warning is checked in raw stderr, since normalizing strips it. One scenario runs on darwin and linux: the fake supervisor stubs launchctl, systemctl, loginctl and lsof together, so CI covers systemd and a Mac covers launchd. Every stub goes through installStub, because the fakes answer for the real io.rossoctl.cortex label, and a test that fell through to the real launchctl would boot out the Cortex the machine is running. Not pinned: adopting a hand-started proxy (it needs a live process named cortex), a health-check timeout, the supervisor not reporting the job running, a failed load, migration failures, and loginctl enable-linger failing. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
planClaudeCodeEnable runs the checks that can refuse an enable, in the order enable made them, and touches nothing on disk. applyClaudeCodeEnable records the prior values and writes the settings. printTrustFileNotes keeps the CA-file notes in the command, out of both halves. agentop setup needs the halves separately: it shows the change on one consent screen alongside the rest of what it will do, then applies it without a prompt of its own. The two refusals that printed their own text now return it as errors, which the command prints through the same "agentop: %v" it uses for the others, so the bytes are unchanged. The characterization tests pass unchanged. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
The same split as enable, for the other direction: setup's rollback and agentop uninstall both need to undo the Claude Code wiring without the command's prompt and summary. planClaudeCodeDisable lists the managed keys that are present and touches nothing; applyClaudeCodeDisable restores what enable recorded, removes what it added, and deletes the record. Output is unchanged. The tests seed a stale Cortex HTTPS_PROXY that enable replaces, because a prior value equal to what enable writes cannot tell a restored value from a leftover one. The enable apply test now fails, rather than panicking, when no state record was written. Two doc comments added by the enable split are narrowed to what the code does today. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
runServiceInstall is install from the point of consent onward. Its body is the old one, left in place, with three kinds of edit. Each return now reports an installResult, so a caller can tell started-and-healthy, started-but-unprobed and already-current apart without parsing text. The --yes check that hid the unit path became an announceUnit parameter. And the hand-started proxy that the preview names is passed in as adopt, so the preview and the action agree on it. runServiceInstall still writes the command's own text to the writers it is given. removeService is uninstall's action without its preview and summary. One of its comments now names serviceUninstall's message instead of "the message below", since the two no longer share a function. Every string stays in cmd_service.go, where install_test.sh looks for the ones install.sh filters on, and the exit codes install.sh branches on are unchanged. The new tests pin each installResult outcome, including an install with no health URL to probe, and removeService's answer when the unit goes but the stamp will not. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
printTrustFileNotes's doc comment said a caller that applies and then starts the proxy has nothing to warn about because the files appear on that start; the trust bundle never appears on a host with no system root store, so the comment now says only that a caller applying before the start should check the files after it. The comment on TestRunServiceInstall_UnprobedInstallIsNotHealthy said only the result tells a healthy install from an unprobed one, but stdout differs too; it now says so short of parsing stdout. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 48 minutes. View limit detailsLimit details: You’ve used the included review currently available. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (7)
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. Comment |
pdettori
left a comment
There was a problem hiding this comment.
Verified the pure-refactor claim against the base files: exit codes (exitDeclined/exitNoSupervisor at the same points), output text and ordering (the \n-terminated Fprintf messages became fmt.Errorf wrapped by the unchanged agentop: %v\n — same bytes), --yes/announceUnit semantics, and the consent flow are all preserved. Plan functions are read-only (planClaudeCodeEnable never receives statePath, so it structurally cannot write the state file), and apply writes everything the old code wrote. Two suggestions (#1, #2) are best addressed before the setup PR builds on these seams. Test quality is genuinely strong — byte-exact stdout/stderr/exit-code pins plus disk-effect assertions that guard against vacuous passes.
Review summary
- Author: huang195 (MEMBER — maintainer)
- Areas reviewed: Go CLI refactor with line-by-line behavior-change audit, characterization tests
- Agent/IDE config (.claude/.vscode): none
- Commits: 7, all signed-off
- CI status: all green (CodeRabbit rate-limited, non-blocking)
| " Nothing to change. Use `agentop service restart` to restart it anyway.\n", | ||
| filepath.Base(p.binary), supervisorName(runtime.GOOS)) | ||
| return 0 | ||
| return installResult{alreadyCurrent: true} |
There was a problem hiding this comment.
suggestion: The already-current path prints "Already current: ... and healthy." but returns installResult{alreadyCurrent: true} with healthy: false. Fine for the CLI (.exit is 0 either way), but a latent trap for the follow-up setup PR: a caller that branches on healthy before alreadyCurrent will report an already-running, healthy service as not healthy. Either set healthy: true here — the message asserts it — or spell out the precedence in the struct comment.
| // applyClaudeCodeEnable records what the managed keys held, then writes the plan's | ||
| // values. Failing to record is a warning on stderr, as it always was: the write still | ||
| // happens, and disable then deletes the keys rather than restoring them. | ||
| func applyClaudeCodeEnable(pl claudeCodePlan, statePath string, stderr io.Writer) error { |
There was a problem hiding this comment.
suggestion: The plan carries the doc map read at plan time, and apply mutates and writes it. The old code had the same read-confirm-write window internally, so this is not a behavior change — but the split exports that window, and the setup PR will widen it (plan -> its own consent screen -> apply). Worth a comment here now, and possibly an mtime/size re-check in the follow-up PR, so apply doesn't silently clobber a settings.json the user or another tool edited in between.
| } | ||
|
|
||
| // caCertNote is the note enable prints while ca.crt does not exist yet. | ||
| func caCertNote(caDir string) string { |
There was a problem hiding this comment.
nit: caCertNote/bundleNote/enablePreviewOf mirror the implementation's format strings rather than being independent golden literals, so the claude-code characterization is partially self-referential — a wording change made alongside a helper update would pass unnoticed. The service-side tests use hardcoded literals and are stronger. The "tests pass before the code moves" commit ordering is the real guarantee here; fine to keep, just noting the asymmetry.
| // while the fake job is loaded, so newServiceSceneServing can follow it. | ||
| // | ||
| // The four stubs go through installStub, whose reachability check is load-bearing here: | ||
| // the label is the REAL io.rossoctl.cortex, so a test that fell through to the real |
There was a problem hiding this comment.
nit: The fakeSupervisor stub uses the real io.rossoctl.cortex label, so if installStub ever fails to install its fake (PATH or permission problem), the test falls through to the real launchctl and boots out the Cortex running on the dev machine. Consider having installStub fail the test hard on any installation error.
Summary
Splits
agentop service install|uninstallandagentop configure claude-code enable|disable, so that the next PR'sagentop setupcan run them behind its own consent screen and read the outcome without parsing text. There is no behaviour change.claude-code enable/disable:planClaudeCodeEnableandapplyClaudeCodeEnable, plusprintTrustFileNotes;planClaudeCodeDisableandapplyClaudeCodeDisable.The plan functions only read; the apply functions write.
service install/uninstall:runServiceInstallruns install from the point of consent onward and returnsinstallResult{exit, alreadyCurrent, healthy}.removeServiceis uninstall's action.runServiceInstallstill writes the command's own text to the writers it is given.Prompt seams:
serviceConfirmandclaudeCodeConfirmfollow thebobConfirmpattern, so tests can answer a prompt without/dev/tty.This is the first of four PRs toward
agentop setup: one consent screen, a checklist, and rollback for the laptop install.How "no behaviour change" is shown
Characterization tests land first, in their own commits, and pass on the code before any of it moves. They pin stdout, stderr, the exit code and the effects on disk exactly.
configure claude-code enable:configure claude-code disable:service install:--restartover a current install.service uninstall:--yes, accepted, declined;Also pinned: the macOS login-home warning.
Not pinned:
loginctl enable-lingerfailing;The code for those paths moves unchanged apart from its
returnstatements, andgit diff --color-movedoncmd_service.goshows that.One scenario runs on both platforms: the fake supervisor stubs both
launchctlandsystemctl. The macOS-only output (where the Go keychain note appears, and the login-home warning) was checked on macOS only, because CI runs on Ubuntu.The strings
scripts/install.shfilters on stay incmd_service.go, which is the fileinstall_test.shchecks for them.Test plan
go test -race ./...incmd/agentopsh scripts/install_test.shgit diff --color-movedoncmd_service.goandcmd_claudecode.goAssisted-By: Claude Code