Cuts the daemon-managed guest-session machinery (start/list/show/
logs/stop/kill/attach/send). The feature shipped aimed at agent-
orchestration workflows (programmatic stdin piping into a long-lived
guest process) that aren't driving any concrete user today, and the
~2.3K LOC of daemon surface area — attach bridge, FIFO keepalive,
controller registry, sessionstream framing, SQLite persistence — was
locking in an API we'd have to keep through v0.1.0.
Anything session-flavoured that people actually need today can be
done with `vm ssh + tmux` or `vm run -- cmd`.
Deleted:
- internal/cli/commands_vm_session.go
- internal/daemon/{guest_sessions,session_lifecycle,session_attach,session_stream,session_controller}.go
- internal/daemon/session/ (guest-session helpers package)
- internal/sessionstream/ (framing package)
- internal/daemon/guest_sessions_test.go
- internal/store/guest_session_test.go
- GuestSession* types from internal/{api,model}
- Store UpsertGuestSession/GetGuestSession/ListGuestSessionsByVM/DeleteGuestSession + scanner helpers
- guest.session.* RPC dispatch entries
- 5 CLI session tests, 2 completion tests, 2 printer tests
Extracted:
- ShellQuote + FormatStepError lifted to internal/daemon/workspace/util.go
(only non-session consumer); workspace package now self-contained
- internal/daemon/guest_ssh.go keeps guestSSHClient + dialGuest +
waitForGuestSSH — still used by workspace prepare/export
- internal/daemon/fake_firecracker_test.go preserves the test helper
that used to live in guest_sessions_test.go
Store schema: CREATE TABLE guest_sessions and its column migrations
removed. Existing dev DBs keep an orphan table (harmless, pre-v0.1.0).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
102 lines
2.2 KiB
Go
102 lines
2.2 KiB
Go
package cli
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// findSubcommand walks cmd's subtree along path and returns the
|
|
// matching command, or nil.
|
|
func findSubcommand(root *cobra.Command, path ...string) *cobra.Command {
|
|
cur := root
|
|
for _, name := range path {
|
|
var next *cobra.Command
|
|
for _, sub := range cur.Commands() {
|
|
if sub.Name() == name {
|
|
next = sub
|
|
break
|
|
}
|
|
}
|
|
if next == nil {
|
|
return nil
|
|
}
|
|
cur = next
|
|
}
|
|
return cur
|
|
}
|
|
|
|
func assertHasAlias(t *testing.T, cmd *cobra.Command, alias string) {
|
|
t.Helper()
|
|
if cmd == nil {
|
|
t.Fatal("command is nil")
|
|
}
|
|
for _, a := range cmd.Aliases {
|
|
if a == alias {
|
|
return
|
|
}
|
|
}
|
|
t.Errorf("%q missing alias %q; have %v", cmd.Name(), alias, cmd.Aliases)
|
|
}
|
|
|
|
func TestListCommandsHaveLsAlias(t *testing.T) {
|
|
root := NewBangerCommand()
|
|
|
|
cases := [][]string{
|
|
{"vm", "list"},
|
|
{"image", "list"},
|
|
{"kernel", "list"},
|
|
}
|
|
for _, path := range cases {
|
|
t.Run(path[len(path)-1], func(t *testing.T) {
|
|
cmd := findSubcommand(root, path...)
|
|
if cmd == nil {
|
|
t.Fatalf("missing command: %v", path)
|
|
}
|
|
assertHasAlias(t, cmd, "ls")
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestDeleteCommandsHaveRmAlias(t *testing.T) {
|
|
root := NewBangerCommand()
|
|
|
|
cases := [][]string{
|
|
{"vm", "delete"},
|
|
{"image", "delete"},
|
|
}
|
|
for _, path := range cases {
|
|
t.Run(path[len(path)-1], func(t *testing.T) {
|
|
cmd := findSubcommand(root, path...)
|
|
if cmd == nil {
|
|
t.Fatalf("missing command: %v", path)
|
|
}
|
|
assertHasAlias(t, cmd, "rm")
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestVMCommandRegistersPrune(t *testing.T) {
|
|
root := NewBangerCommand()
|
|
cmd := findSubcommand(root, "vm", "prune")
|
|
if cmd == nil {
|
|
t.Fatal("vm prune not registered")
|
|
}
|
|
if flag := cmd.Flags().Lookup("force"); flag == nil {
|
|
t.Error("vm prune missing --force flag")
|
|
}
|
|
if flag := cmd.Flags().ShorthandLookup("f"); flag == nil {
|
|
t.Error("vm prune missing -f shorthand")
|
|
}
|
|
}
|
|
|
|
func TestKernelRmHasDeleteAlias(t *testing.T) {
|
|
// This already existed prior to this feature — guard against regressions.
|
|
root := NewBangerCommand()
|
|
cmd := findSubcommand(root, "kernel", "rm")
|
|
if cmd == nil {
|
|
t.Fatal("kernel rm missing")
|
|
}
|
|
assertHasAlias(t, cmd, "delete")
|
|
assertHasAlias(t, cmd, "remove")
|
|
}
|