Fix vm run guest repo path and add vm acp bridge
Normalize repo-backed guest checkouts to /root/repo so vm run, attach, and follow-on guest tooling stop depending on the source repository name. Add `banger vm acp [--cwd] <vm>` as an SSH stdio bridge to guest `opencode acp`, defaulting to /root/repo when that checkout exists and falling back to /root. Update the README and CLI coverage around the fixed guest path and ACP command. Validation: go test ./internal/cli, go test ./..., make build.
This commit is contained in:
parent
dbc70643c3
commit
5f89c07fc0
3 changed files with 210 additions and 12 deletions
|
|
@ -233,6 +233,21 @@ func TestVMRunFlagsExist(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestVMACPFlagsExist(t *testing.T) {
|
||||
root := NewBangerCommand()
|
||||
vm, _, err := root.Find([]string{"vm"})
|
||||
if err != nil {
|
||||
t.Fatalf("find vm: %v", err)
|
||||
}
|
||||
acp, _, err := vm.Find([]string{"acp"})
|
||||
if err != nil {
|
||||
t.Fatalf("find acp: %v", err)
|
||||
}
|
||||
if acp.Flags().Lookup("cwd") == nil {
|
||||
t.Fatal("missing flag \"cwd\"")
|
||||
}
|
||||
}
|
||||
|
||||
func TestVMCreateFlagsShowStaticDefaults(t *testing.T) {
|
||||
root := NewBangerCommand()
|
||||
vm, _, err := root.Find([]string{"vm"})
|
||||
|
|
@ -967,6 +982,98 @@ func TestSSHCommandArgs(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestRunVMACPBridgesOverSSH(t *testing.T) {
|
||||
origVMSSH := vmSSHFunc
|
||||
origSSHExec := sshExecFunc
|
||||
t.Cleanup(func() {
|
||||
vmSSHFunc = origVMSSH
|
||||
sshExecFunc = origSSHExec
|
||||
})
|
||||
|
||||
vmSSHFunc = func(ctx context.Context, socketPath, idOrName string) (api.VMSSHResult, error) {
|
||||
if socketPath != "/tmp/bangerd.sock" {
|
||||
t.Fatalf("socketPath = %q, want /tmp/bangerd.sock", socketPath)
|
||||
}
|
||||
if idOrName != "devbox" {
|
||||
t.Fatalf("idOrName = %q, want devbox", idOrName)
|
||||
}
|
||||
return api.VMSSHResult{Name: "devbox", GuestIP: "172.16.0.2"}, nil
|
||||
}
|
||||
|
||||
var gotArgs []string
|
||||
var gotStdin string
|
||||
sshExecFunc = func(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, args []string) error {
|
||||
gotArgs = append([]string(nil), args...)
|
||||
data, err := io.ReadAll(stdin)
|
||||
if err != nil {
|
||||
t.Fatalf("ReadAll(stdin): %v", err)
|
||||
}
|
||||
gotStdin = string(data)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := runVMACP(
|
||||
context.Background(),
|
||||
"/tmp/bangerd.sock",
|
||||
model.DaemonConfig{SSHKeyPath: "/tmp/id_ed25519"},
|
||||
strings.NewReader("client stream"),
|
||||
&bytes.Buffer{},
|
||||
&bytes.Buffer{},
|
||||
"devbox",
|
||||
"",
|
||||
); err != nil {
|
||||
t.Fatalf("runVMACP: %v", err)
|
||||
}
|
||||
|
||||
if gotStdin != "client stream" {
|
||||
t.Fatalf("stdin = %q, want client stream", gotStdin)
|
||||
}
|
||||
joined := strings.Join(gotArgs, " ")
|
||||
for _, want := range []string{
|
||||
"-T",
|
||||
"-F /dev/null",
|
||||
"-i /tmp/id_ed25519",
|
||||
"-o LogLevel=ERROR",
|
||||
"root@172.16.0.2",
|
||||
"bash -lc",
|
||||
} {
|
||||
if !strings.Contains(joined, want) {
|
||||
t.Fatalf("ssh args = %q, want %q", joined, want)
|
||||
}
|
||||
}
|
||||
remoteCommand := gotArgs[len(gotArgs)-1]
|
||||
if !strings.Contains(remoteCommand, `exec opencode acp --cwd "$DIR"`) {
|
||||
t.Fatalf("remote command = %q, want ACP exec", remoteCommand)
|
||||
}
|
||||
if !strings.Contains(remoteCommand, "REPO_DIR='/root/repo'") {
|
||||
t.Fatalf("remote command = %q, want repo fallback", remoteCommand)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVMACPRemoteCommandDefaultsToRepoThenRoot(t *testing.T) {
|
||||
got := vmACPRemoteCommand("")
|
||||
for _, want := range []string{
|
||||
"REPO_DIR='/root/repo'",
|
||||
"DEFAULT_DIR='/root'",
|
||||
`if [ -d "$REPO_DIR" ]; then DIR="$REPO_DIR"; else DIR="$DEFAULT_DIR"; fi`,
|
||||
`exec opencode acp --cwd "$DIR"`,
|
||||
} {
|
||||
if !strings.Contains(got, want) {
|
||||
t.Fatalf("vmACPRemoteCommand() = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestVMACPRemoteCommandUsesExplicitCWD(t *testing.T) {
|
||||
got := vmACPRemoteCommand("/workspace/project")
|
||||
if !strings.Contains(got, "DIR='/workspace/project'") {
|
||||
t.Fatalf("vmACPRemoteCommand() = %q, want explicit cwd", got)
|
||||
}
|
||||
if strings.Contains(got, "REPO_DIR=") {
|
||||
t.Fatalf("vmACPRemoteCommand() = %q, want no repo fallback", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateSSHPrereqs(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
keyPath := filepath.Join(dir, "id_ed25519")
|
||||
|
|
@ -1156,6 +1263,7 @@ func TestRunVMRunCreatesImportsAndAttaches(t *testing.T) {
|
|||
Runtime: model.VMRuntime{
|
||||
State: model.VMStateRunning,
|
||||
GuestIP: "172.16.0.2",
|
||||
DNSName: "devbox.vm",
|
||||
},
|
||||
}
|
||||
vmCreateBeginFunc = func(context.Context, string, api.VMCreateParams) (api.VMCreateBeginResult, error) {
|
||||
|
|
@ -1716,6 +1824,12 @@ func TestVMRunCheckoutScriptSkipsRepoGitIdentityWhenIncomplete(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestVMRunGuestDirIsFixed(t *testing.T) {
|
||||
if got := vmRunGuestDir(); got != "/root/repo" {
|
||||
t.Fatalf("vmRunGuestDir() = %q, want /root/repo", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewBangerdCommandRejectsArgs(t *testing.T) {
|
||||
cmd := NewBangerdCommand()
|
||||
cmd.SetArgs([]string{"extra"})
|
||||
|
|
@ -1951,12 +2065,14 @@ func (c *testVMRunGuestClient) StreamTar(ctx context.Context, sourceDir, remoteC
|
|||
|
||||
func (c *testVMRunGuestClient) RunScript(ctx context.Context, script string, logWriter io.Writer) error {
|
||||
c.runScriptCalls++
|
||||
if c.runScriptCalls == 1 {
|
||||
switch c.runScriptCalls {
|
||||
case 1:
|
||||
c.script = script
|
||||
return c.checkoutErr
|
||||
default:
|
||||
c.launchScript = script
|
||||
return c.launchErr
|
||||
}
|
||||
c.launchScript = script
|
||||
return c.launchErr
|
||||
}
|
||||
|
||||
func (c *testVMRunGuestClient) StreamTarEntries(ctx context.Context, sourceDir string, entries []string, remoteCommand string, logWriter io.Writer) error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue