Repository navigation
Fix: Build agentop on Windows, and refuse what needs a Unix service #2048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -260,7 +260,7 @@ func TestServiceLifecycle_RealLaunchd(t *testing.T) { | |
| // pid is the supervisor's, and it stays the same while a new proxy takes over. | ||
| // syscall.Kill gets a pid from childPID, which never returns one below 2: kill(2) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: This comment still says |
||
| // reads 0 as this process's own group, which holds `go test` too. | ||
| if err := syscall.Kill(proxy, syscall.SIGKILL); err != nil { | ||
| if err := killPID(proxy, syscall.SIGKILL); err != nil { | ||
| t.Fatalf("kill -9 proxy %d: %v", proxy, err) | ||
| } | ||
| // The wait follows whatever supervisor launchd reports now, so that a broken | ||
|
|
@@ -293,7 +293,7 @@ func TestServiceLifecycle_RealLaunchd(t *testing.T) { | |
| t.Error("after stop the label is not disabled, so the next login would start Cortex again") | ||
| } | ||
| for _, pid := range []int{sup, newProxy} { | ||
| if !waitUntil(10*time.Second, func() bool { return syscall.Kill(pid, 0) != nil }) { | ||
| if !waitUntil(10*time.Second, func() bool { return killPID(pid, 0) != nil }) { | ||
| t.Errorf("process %d was still running 10s after stop", pid) | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| //go:build !windows | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "syscall" | ||
|
|
||
| "golang.org/x/sys/unix" | ||
| ) | ||
|
|
||
| // Process helpers for tests, for Unix. killpid_windows_test.go has the Windows half (#1520). | ||
|
|
||
| // killPID sends sig to pid (to the group led by -pid when pid is negative). | ||
| func killPID(pid int, sig syscall.Signal) error { return syscall.Kill(pid, sig) } | ||
|
|
||
| // groupAttr starts a child as the leader of a process group of its own. | ||
| func groupAttr() *syscall.SysProcAttr { return &syscall.SysProcAttr{Setpgid: true} } | ||
|
|
||
| // sessionAttr starts a child in a session of its own. | ||
| func sessionAttr() *syscall.SysProcAttr { return &syscall.SysProcAttr{Setsid: true} } | ||
|
|
||
| // mkfifo makes a named pipe at path. | ||
| func mkfifo(path string, mode uint32) error { return syscall.Mkfifo(path, mode) } | ||
|
|
||
| // getsid is pid's session id. | ||
| func getsid(pid int) (int, error) { return unix.Getsid(pid) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| //go:build windows | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "errors" | ||
| "syscall" | ||
| ) | ||
|
|
||
| // The Windows half of killpid_unix_test.go. Windows has no signals to send to another process, | ||
| // no process groups of the Unix kind and no sessions. The tests that use these need a Unix | ||
| // service or shell and do not run on Windows; these keep them compiling there (#1520). | ||
|
|
||
| var errNoUnixProcess = errors.New("not on Windows") | ||
|
|
||
| func killPID(int, syscall.Signal) error { return errNoUnixProcess } | ||
|
|
||
| func groupAttr() *syscall.SysProcAttr { return nil } | ||
|
|
||
| func sessionAttr() *syscall.SysProcAttr { return nil } | ||
|
|
||
| func getsid(int) (int, error) { return 0, errNoUnixProcess } | ||
|
|
||
| func mkfifo(string, uint32) error { return errNoUnixProcess } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io" | ||
| ) | ||
|
|
||
| // unsupportedOnWindows are the subcommands that install, run or replace Cortex as a service. | ||
| // On Windows they need a service backend, a way to stop the proxy without killing it, and a | ||
| // way to replace a running .exe, none of which exists yet (#1520). Everything else in agentop | ||
| // talks to a running proxy over HTTP, or edits a settings file, and works there. | ||
| var unsupportedOnWindows = map[string]bool{ | ||
| "service": true, | ||
| "setup": true, | ||
| "uninstall": true, | ||
| "update": true, | ||
| } | ||
|
|
||
| // refuseUnsupported reports whether subcommand cmd cannot run on goos, and says so on stderr. | ||
| // goos is a parameter so the rule is testable on every OS. | ||
| func refuseUnsupported(goos, cmd string, stderr io.Writer) bool { | ||
| if goos != "windows" || !unsupportedOnWindows[cmd] { | ||
| return false | ||
| } | ||
| fmt.Fprintf(stderr, "agentop: `agentop %s` is not supported on Windows yet (#1520).\n"+ | ||
| " Run the proxy in a terminal instead: cortex --local\n", cmd) | ||
| return true | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
go test -runwith a name that matches no test still exits 0. If someone renames one of these tests, Windows CI stops running it and nobody sees it. You can add-vand check that each name has a--- PASSline, or you can accept the risk.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Fixed in #2050: the step runs with
-v, and fails if any listed name has no--- PASS/--- SKIPline, so a renamed test can't drop out silently.Assisted-By: Claude (Anthropic AI) noreply@anthropic.com