Skip to content

Refactor: Finish the goos parameterization and harden callLog - #1374

Merged
mrsabath merged 3 commits into
mainfrom
fix/goosref
Oct 14, 2026
Merged

mrsabath merged 3 commits into
mainfrom
fix/goosref

Conversation

@mrsabath

@mrsabath mrsabath commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Closes #1106. Two commits, one per checkbox, since the items are independent.

Correction to the issue's premise

The issue says both functions "already receive goos/runtime.GOOS as a parameter but still branch on it internally". Neither did. serviceIsCurrent(p servicePaths) and reportInstallSuccess(healthy bool, stdout io.Writer) took no goos at all and read runtime.GOOS directly — so this is the full parameterization rather than cleanup of residual branching. Line numbers had also moved (reportInstallSuccess was cited at :498, found at :552).

Item 1 — finish the goos refactor

Internal runtime.GOOS reads removed:

  • reportInstallSuccess — three: supervisorName(runtime.GOOS) in both output branches, plus if runtime.GOOS == "darwin" gating the crash-recovery note. That was its entire output, so on a Mac the systemd line was never asserted and on Linux CI the launchd line never was.
  • serviceIsCurrent — two: the darwin-only !strings.Contains(body, "--supervise") clause, and supervisorRunning(runtime.GOOS, p). The inner function already took goos, so it was testable while its caller pinned it to the host.

Follows #1080's established shape exactly — goos as the leading parameter, internal branches read it, callers pass runtime.GOOS — matching loadService / controlService / supervisorRunning / unloadService and renderUnitFor. setup_step_service.go passes the env.goos it already carries, consistent with the supervisorName(env.goos) on the next line.

New tests exercise both platforms from either host, which is the entire value of the refactor. A currentServiceFixture(t, goos) helper builds the accept-state per platform (that platform's own renderUnitFor text, matching stamp, that platform's supervisor CLI stubbed via #1080's fakeLaunchctl/fakeSystemctl harness, live httptest health endpoint). Verified running on macOS:

--- PASS: TestServiceIsCurrent_BothPlatforms
    --- PASS: .../darwin:_a_freshly_written,_running,_healthy_service_is_current
    --- PASS: .../linux:_a_freshly_written,_running,_healthy_service_is_current
    --- PASS: .../darwin:_a_unit_that_lost_--supervise_is_not_current
    --- PASS: .../linux:_the_systemd_unit_is_current_without_--supervise
    --- PASS: .../darwin:_a_job_the_supervisor_does_not_report_running_is_not_current
    --- PASS: .../linux:_a_job_the_supervisor_does_not_report_running_is_not_current
--- PASS: TestReportInstallSuccess_BothPlatforms
    --- PASS: .../darwin/healthy=true    --- PASS: .../darwin/healthy=false
    --- PASS: .../linux/healthy=true     --- PASS: .../linux/healthy=false

The darwin not-running case shortens serviceReadyTimeout to 200ms (the setup_rollback_test.go idiom) — supervisorRunning's darwin branch otherwise polls the full 15s, and nothing in the fixture is transient.

No behavioral change on either platform. Pure parameterization.

Item 2 — harden callLog

Lines now carry a callLogPrefix = "argv:", emitted as separate echo words (echo argv: "$@") so a zero-arg call logs exactly argv: with no trailing space. readCallLog strips it, so every existing assertion compares the same argument strings as before — TestLoadService_Linux, TestUnloadService_Linux, TestControlService_Linux and TestLingerEnabled pass unchanged (independently re-verified).

Zero-arg call → []string{""} (one entry, empty args); never-called → nil. Previously both were nil.

Two further hardenings: the trailing-newline trim moved ahead of the loop, so "" can only come from a real zero-arg call and never from the file's own newline; and a line without the prefix is now t.Fatalf rather than silently filtered, since that would mean something other than a callLog fake wrote to the path.

TestCallLog drives a stub directly (no production caller reaches the case). Two of its five cases record what the format cannot represent, as known limits rather than bugs:

  • one empty argument vs no arguments at all are indistinguishable, in the text and in the entry count — echo argv: writes argv:, echo argv: "" writes argv: , and the decode collapses both to exactly one "". (An earlier revision of this description and of the test comment claimed they "differ in the count"; that was wrong, caught in review, and corrected in 3cf867fc.)
  • a space-containing argument is shell-joined and reads as two.

Neither matters for any current call site, and telling the first pair apart would need a per-argument format that would make every existing assertion in the file unreadable.

Verification

  • GOWORK=off go -C cmd/agentop vet ./... clean; gofmt -l cmd/agentop/ clean.
  • All new tests pass; all pre-existing callLog consumers pass unchanged.
  • No behavioral bug found in either function.

Caveat worth your attention

This sandbox degraded mid-session and could not produce one clean full-suite run on the final tree. An early run showed only the 3 known tui failures plus 2 main-package ones; a later run of the same suite showed ~25, every one sharing the cause Error opening /private/var/select/sh: Operation not permitted — the sandbox stopped permitting /bin/sh, which breaks every PATH-stub test.

Confirmed not caused by this change: re-running the identical selection against the pristine tree (git stash -u) gave byte-identical failures. The 3 declared tui failures reproduce as expected (they assert on an un-tilde-expanded temp path — also a sandbox-layout artefact). Still, a clean full-suite run outside the sandbox before merge would be worth having; CI will provide it.

Assisted-By: Claude (Anthropic AI) [email protected]

Summary by CodeRabbit

  • Bug Fixes
    • Service installation checks now apply the requirements and recovery guidance for the target operating system.
  • Tests
    • Expanded coverage for platform-specific service checks and installation messages, and improved verification of system service command logging.

…allSuccess

Second half of the refactor #1080 did for loadService, controlService,
supervisorRunning and unloadService: these two read runtime.GOOS internally,
so their darwin-only logic could only ever be exercised on a Mac and their
linux-only logic only on Linux.

serviceIsCurrent's --supervise clause is the clearest case. A macOS plist that
lost --supervise leaves crashes unrecovered, so the clause refuses to call such
a unit current; the systemd unit never carries the flag at all, because
Restart=on-failure is its recovery. Neither half was asserted from the other
host — the existing TestServiceIsCurrent skips its --supervise case off darwin
for exactly this reason — and nothing proved the requirement stays out of
Linux's way. Same shape for reportInstallSuccess: the supervisor name and the
darwin-only crash-recovery note are its entire output, and its existing test
puts both assertions behind runtime.GOOS, so each run verifies one platform and
takes the other on faith.

Following #1080's pattern exactly: goos as the leading parameter, callers pass
runtime.GOOS (setup_step_service.go passes the env.goos it already carries).
The internal branches then read goos instead.

cmd_service_goos_test.go adds the tests that make the refactor worth doing.
Both platforms' paths run on every host: serviceIsCurrent gets a per-platform
fixture (that platform's own unit text, a matching stamp, that platform's
supervisor CLI stubbed through the #1080 fakeLaunchctl/fakeSystemctl harness,
and a live health endpoint), then the --supervise clause is asserted in both
directions and the supervisor clause driven through each platform's own
vocabulary. reportInstallSuccess gets all four goos x healthy combinations.

No behavior change on either platform.

Refs #1106.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Mariusz Sabath <[email protected]>
…callLog

callLog's fake wrote `echo "$@"` to its log, so an invocation with no arguments
appended a blank line — which readCallLog filtered out as empty. A real but
bugged zero-argument call therefore read as the clean "never called" outcome,
and "the call log has zero entries" is precisely what several subtests in this
file assert deliberately to mean our code did NOT shell out. It is the same
invisible failure installStub's own reachability check exists to catch, one
layer in.

Latent only: no call site in the current code passes zero arguments, so nothing
exercises it today. Hardened before it silently matters.

Every logged line now carries an "argv:" prefix, so a zero-argument call writes
"argv:" — content, not a blank line. readCallLog strips the prefix, which keeps
every existing assertion comparing against the same argument strings as before,
and treats a line WITHOUT the prefix as a hard failure rather than filtering
it: that would mean something other than a callLog fake wrote to the path.
Trailing-newline handling moved ahead of the loop, so "" as an entry can now
only come from a zero-argument call.

TestCallLog proves the distinction holds, driving a stub directly since no
production caller can reach the case: zero arguments is one entry with empty
arguments, a never-invoked stub is nil, and a normal call still round-trips
verbatim. Two more cases pin what the format cannot represent — one empty
argument versus none differ in the entry count and not the text, and an
argument containing a space is joined by the shell and indistinguishable from
two — recorded as known limits rather than left for a reader to rediscover.

Closes #1106.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Mariusz Sabath <[email protected]>
@mrsabath
mrsabath requested a review from a team as a code owner October 13, 2026 19:16
@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3d4edeb2-0f13-4d2e-8c32-df454248271c
📥 Commits

Reviewing files that changed from the base of the PR and between c841538 and 3cf867f.

📒 Files selected for processing: 6
  • cmd/agentop/cmd_service.go
  • cmd/agentop/cmd_service_goos_test.go
  • cmd/agentop/cmd_service_recovery_test.go
  • cmd/agentop/cmd_service_restricted_test.go
  • cmd/agentop/cmd_service_systemd_test.go
  • cmd/agentop/setup_step_service.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

Service checks and install reports now use explicit operating-system inputs. Cross-platform tests cover Darwin and Linux behavior. The systemd test call log now distinguishes a zero-argument invocation from no invocation.

Changes: Service platform selection

Layer / File(s) Summary
Pass operating-system inputs through service checks
cmd/agentop/cmd_service.go, cmd/agentop/setup_step_service.go
serviceIsCurrent and reportInstallSuccess use an explicit OS value for platform-specific behavior. Callers pass runtime.GOOS or env.goos.
Test platform-specific service behavior
cmd/agentop/cmd_service_goos_test.go, cmd/agentop/cmd_service_recovery_test.go, cmd/agentop/cmd_service_restricted_test.go
New tests exercise Darwin and Linux currentness checks and install reports. Existing tests pass the runtime OS to the updated functions.

Systemd test call log

Layer / File(s) Summary
Record and parse call-log entries
cmd/agentop/cmd_service_systemd_test.go
The call-log writer prefixes entries with argv:. The reader validates and removes the prefix. Tests cover zero-argument calls and the format’s argument ambiguities.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Suggested reviewers: pdettori

Merge Risk: ⚪ Minimal · up to 3cf86

This change makes platform-specific service checks testable from either host and does not alter production behavior. The author recommends a full-suite run outside the sandbox, which is a normal pre-merge check.

Pre-merge checks: Passed 5
Passed Passed checks: 5 passed
Check name Status Explanation
Linked Issues check Passed Issue #1106 has two active coding requirements. cmd_service.go now passes goos to serviceIsCurrent and reportInstallSuccess, and both functions use that parameter for platform-specific logic. …
Out of Scope Changes check Passed The changes stay within issue #1106. Production changes parameterize the two named service functions and update their callers. Added tests verify the required cross-platform behavior. The call-log cha…
Docstring Coverage Passed Docstring coverage is 92.86% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 6 files.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly summarizes both primary changes: completing goos parameterization and hardening the callLog test helper.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@pdettori pdettori left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed as pure parameterization plus test-harness hardening; nothing blocking.

  • All serviceIsCurrent / reportInstallSuccess callers updated correctly: runtime.GOOS at both cmd_service.go sites, env.goos in setup_step_service.go — consistent with the adjacent supervisorName(env.goos) and the #1080 pattern.
  • The cross-platform tests genuinely exercise both platforms' logic from either host, including the --supervise clause asserted in both directions — the exact gap the issue described.
  • The callLog argv: prefix scheme round-trips every existing assertion unchanged (the green agentop CI run also covers the sandbox-degradation caveat in the description).

One suggestion inline on a comment inaccuracy in TestCallLog.

Comment thread cmd/agentop/cmd_service_systemd_test.go Resolved
Review feedback on #1106 (thanks @pdettori).

The comment on TestCallLog's "one empty argument" case claimed that one
empty argument and no arguments at all "differ in the count, which is
the thing the assertions key on, and not in the text". That is wrong in
both halves, and verified so: `echo argv:` writes "argv:" while
`echo argv: ""` writes "argv: ", and CutPrefix plus TrimPrefix(" ")
collapse BOTH to exactly one "" entry. Same text, same count — the two
cases are fully indistinguishable in this format, and both test cases
already assert the same []string{""}.

What the entry count does distinguish is called-at-all (one entry) from
never-called (nil), which is the zero-argument case's actual value and
the distinction every assertion in this file keys on. The comment now
says that, and files one-empty-arg-vs-zero-args as a known limit beside
the space-joining one directly below it, so a future reader does not go
looking for a difference that is not there.

Comment only — no behaviour or assertion changed.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Mariusz Sabath <[email protected]>
@mrsabath
mrsabath merged commit 910141d into main Oct 14, 2026
30 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Follow-up: finish the goos refactor and harden callLog's zero-arg case

2 participants