Remove opencode package + vm acp command (dead code)

The `internal/opencode` package and the `opencodeCapability` that
consumed it were hard-wired to wait for opencode on guest port 4096
when an image shipped an initrd. After the prune commits (void /
alpine / customize.sh / image build all removed), nothing banger
produces today carries an initrd, so the capability's wait path was
unreachable: every startup short-circuited to the "direct-boot, skip
opencode" branch.

Same logic for `banger vm acp`: it SSHes to `opencode acp --cwd
<path>`, a binary the golden image no longer ships. Users who run
their own image with opencode can still invoke
`ssh vm -- opencode acp --cwd /root/repo` directly — no banger
scaffolding required.

Removed:
- internal/opencode/ (whole package, 255 LOC incl. tests)
- internal/daemon/opencode.go (opencodeCapability)
- cli `vm acp` command + its helpers (runVMACP, sshACPCommandArgs,
  vmACPRemoteCommand) + their tests
- The opencodeCapability{} entry in registeredCapabilities() plus
  the test that pinned its presence
- `wait_opencode` progress-stage label from the vm-create renderer
- Stale mentions in daemon/doc.go, README, and webui test fixtures

~480 lines gone, 12 added. `banger/internal` is now 25 packages
instead of 26.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Thales Maciel 2026-04-18 16:54:37 -03:00
parent 0933deaeb1
commit b5c13e3938
No known key found for this signature in database
GPG key ID: 33112E6833C34679
10 changed files with 12 additions and 482 deletions

View file

@ -268,21 +268,6 @@ 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"})
@ -516,8 +501,8 @@ func TestRunVMCreatePollsUntilDone(t *testing.T) {
return api.VMCreateStatusResult{
Operation: api.VMCreateOperation{
ID: "op-1",
Stage: "wait_opencode",
Detail: "waiting for opencode on guest port 4096",
Stage: "wait_vsock_agent",
Detail: "waiting for guest vsock agent",
},
}, nil
}
@ -555,7 +540,7 @@ func TestVMCreateProgressRendererSuppressesDuplicateLines(t *testing.T) {
renderer.render(api.VMCreateOperation{Stage: "prepare_work_disk", Detail: "cloning work seed"})
renderer.render(api.VMCreateOperation{Stage: "prepare_work_disk", Detail: "cloning work seed"})
renderer.render(api.VMCreateOperation{Stage: "wait_opencode", Detail: "waiting for opencode on guest port 4096"})
renderer.render(api.VMCreateOperation{Stage: "wait_vsock_agent", Detail: "waiting for guest vsock agent"})
lines := strings.Split(strings.TrimSpace(stderr.String()), "\n")
if len(lines) != 2 {
@ -564,7 +549,7 @@ func TestVMCreateProgressRendererSuppressesDuplicateLines(t *testing.T) {
if lines[0] != "[vm create] preparing work disk: cloning work seed" {
t.Fatalf("first line = %q", lines[0])
}
if lines[1] != "[vm create] waiting for opencode: waiting for opencode on guest port 4096" {
if lines[1] != "[vm create] waiting for vsock agent: waiting for guest vsock agent" {
t.Fatalf("second line = %q", lines[1])
}
}
@ -1017,98 +1002,6 @@ 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")