CloneCoW built reims.CreateOpts without SSHPort even though the field and the --ssh-port argument both exist, so every CoW clone came up with no host SSH forward. MCP temporary sessions and any other clone then failed every SSH-based guest tool (guest_exec, guest_wait_ready, test_run) with a port that nothing listened on. Pick the next free port after the source VM's forward and pass it to create; a source without forwarding still yields a clone without one. Add TestCloneSSHPort for the selection logic. model: deepseek/deepseek-v4.1-flash agent: lead (DeepSeek Harness)
26 lines
750 B
Go
26 lines
750 B
Go
package macosdriver
|
|
|
|
import "testing"
|
|
|
|
func TestCloneSSHPort(t *testing.T) {
|
|
never := func(int) bool { return false }
|
|
all := func(int) bool { return true }
|
|
for _, tt := range []struct {
|
|
name string
|
|
sourcePort int
|
|
inUse func(int) bool
|
|
want int
|
|
}{
|
|
{"source without forwarding stays off", 0, never, 0},
|
|
{"next free port after the source", 2222, never, 2223},
|
|
{"skips ports that are already bound", 2222, func(p int) bool { return p <= 2225 }, 2226},
|
|
{"falls back when the range is exhausted", 65533, all, 65534},
|
|
} {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := cloneSSHPort(tt.sourcePort, tt.inUse); got != tt.want {
|
|
t.Fatalf("cloneSSHPort(%d) = %d, want %d", tt.sourcePort, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|