Repository navigation
Refactor: Finish the goos parameterization and harden callLog - #1374
Conversation
…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]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
pdettori
left a comment
There was a problem hiding this comment.
Reviewed as pure parameterization plus test-harness hardening; nothing blocking.
- All
serviceIsCurrent/reportInstallSuccesscallers updated correctly:runtime.GOOSat bothcmd_service.gosites,env.goosinsetup_step_service.go— consistent with the adjacentsupervisorName(env.goos)and the #1080 pattern. - The cross-platform tests genuinely exercise both platforms' logic from either host, including the
--superviseclause asserted in both directions — the exact gap the issue described. - The
callLogargv: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.
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]>
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.GOOSas a parameter but still branch on it internally". Neither did.serviceIsCurrent(p servicePaths)andreportInstallSuccess(healthy bool, stdout io.Writer)took nogoosat all and readruntime.GOOSdirectly — so this is the full parameterization rather than cleanup of residual branching. Line numbers had also moved (reportInstallSuccesswas cited at:498, found at:552).Item 1 — finish the
goosrefactorInternal
runtime.GOOSreads removed:reportInstallSuccess— three:supervisorName(runtime.GOOS)in both output branches, plusif 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, andsupervisorRunning(runtime.GOOS, p). The inner function already tookgoos, so it was testable while its caller pinned it to the host.Follows #1080's established shape exactly —
goosas the leading parameter, internal branches read it, callers passruntime.GOOS— matchingloadService/controlService/supervisorRunning/unloadServiceandrenderUnitFor.setup_step_service.gopasses theenv.goosit already carries, consistent with thesupervisorName(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 ownrenderUnitFortext, matching stamp, that platform's supervisor CLI stubbed via #1080'sfakeLaunchctl/fakeSystemctlharness, livehttptesthealth endpoint). Verified running on macOS:The darwin not-running case shortens
serviceReadyTimeoutto 200ms (thesetup_rollback_test.goidiom) —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
callLogLines now carry a
callLogPrefix = "argv:", emitted as separateechowords (echo argv: "$@") so a zero-arg call logs exactlyargv:with no trailing space.readCallLogstrips it, so every existing assertion compares the same argument strings as before —TestLoadService_Linux,TestUnloadService_Linux,TestControlService_LinuxandTestLingerEnabledpass unchanged (independently re-verified).Zero-arg call →
[]string{""}(one entry, empty args); never-called →nil. Previously both werenil.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 nowt.Fatalfrather than silently filtered, since that would mean something other than acallLogfake wrote to the path.TestCallLogdrives 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:echo argv:writesargv:,echo argv: ""writesargv:, 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 in3cf867fc.)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.callLogconsumers pass unchanged.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
tuifailures plus 2 main-package ones; a later run of the same suite showed ~25, every one sharing the causeError 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 declaredtuifailures 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