Files
千川白浪andClaude Opus 5.5 565577589a refactor: give each VM action one window binding
Every VM action had two bindings: one by name and one by driver and name.
The window used only the second, so the first is gone and the WithDriver
suffix with it. Unused bindings and frontend exports are removed too.

Tests now reject bindings the window never calls, stale generated
bindings and unused frontend exports. TypeScript rejects unused locals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 21:16:28 -07:00

54 lines
1.7 KiB
Go

package app
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestSSHHostAlias(t *testing.T) {
if sshHostAlias("test.driver.linux", "dev") == sshHostAlias("", "dev") {
t.Fatal("same-name drivers share an SSH alias")
}
if got := sshHostAlias("", "macos-tahoe"); got != "reims-macos-tahoe" {
t.Fatalf("alias = %q", got)
}
if got := sshHostAlias("", "My Mac 26"); got != "reims-my-mac-26" {
t.Fatalf("alias = %q", got)
}
}
func TestUpsertSSHConfigBlockIdempotent(t *testing.T) {
cfg := filepath.Join(t.TempDir(), "config")
initial := "Host prod\n HostName 10.0.0.5\n"
if err := os.WriteFile(cfg, []byte(initial), 0o600); err != nil {
t.Fatal(err)
}
if err := upsertSSHConfigBlock(cfg, "macos-tahoe", "reims-macos-tahoe", "127.0.0.1", 2222, "alice"); err != nil {
t.Fatal(err)
}
b1, _ := os.ReadFile(cfg)
s1 := string(b1)
if !strings.Contains(s1, "Host prod") || !strings.Contains(s1, "Host reims-macos-tahoe") || !strings.Contains(s1, "Port 2222") || !strings.Contains(s1, "User alice") {
t.Fatalf("unexpected first config:\n%s", s1)
}
// Updating port and user must replace the block in place without duplicating it.
if err := upsertSSHConfigBlock(cfg, "macos-tahoe", "reims-macos-tahoe", "127.0.0.1", 2223, "bob"); err != nil {
t.Fatal(err)
}
b2, _ := os.ReadFile(cfg)
s2 := string(b2)
if strings.Count(s2, "Host reims-macos-tahoe") != 1 {
t.Fatalf("expected single block, got:\n%s", s2)
}
if !strings.Contains(s2, "Port 2223") || !strings.Contains(s2, "User bob") || strings.Contains(s2, "User alice") {
t.Fatalf("block not updated:\n%s", s2)
}
if !strings.Contains(s2, "Host prod") {
t.Fatalf("existing user config lost:\n%s", s2)
}
}