mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
tests/e2e/project_test.go and desktop_test.go port tests/e2e.sh's project and desktop sections, every check title word for word and in the same order, with the same macOS and Linux branches (130 checks on a Mac, 122 on Linux, with desktop's 16, its local proxy's two included). tests/e2e.sh drops both blocks and the helpers only they used (tty_run, mounts_of, host_port_kept, lima_serve, vm_say, lima_boot, ports_live, desktop_*, watch_*), their host-tool checks and cleanup lines, and lists them in go_sections. The project section sets the sandbox's Claude Code logins (which an earlier network run leaves in devvm's store) aside while its agent VMs run, as those VMs expect none, and puts them back after. The emptied CA's check looks for the CA in the VM's bundle with vmHas. Harness files: text_test.go (SaidLine, FirstLine, LastLine, Trim, FilesHave, Listed, Locked, Procs, Forwarders, DevvmIn, OwnVM), net_test.go (Reaches, ReachesWithin, Answer, Local, Local6, HostProgram, LimaServe, VMSay, LimaBoot, PortsLive, HostPortKept), tty_test.go (TTYRun, with Cmd's new Input), watch_test.go (WatchSees, WatchMisses), ssh_test.go (SSHAgent, StopPid, KeyComments, RfwdLinks), goe2e_test.go (ExecQuoting, ServeDesktop, Desktop's View and End). They use the shared s.Start, NewCA, WatchProcs, MountLine, HasLine, ExitStatus, gitTool, sshTool, devvmCmd, grepF, readText, vmHas, loopbackOnly and limaListens. testing.md lists them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
74 lines
2.4 KiB
Go
74 lines
2.4 KiB
Go
//go:build e2e
|
|
|
|
package e2e
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"regexp"
|
|
"strconv"
|
|
"strings"
|
|
"syscall"
|
|
)
|
|
|
|
// SSHAgent starts a throwaway ssh-agent on the socket sock, stopped at
|
|
// the run's end, and is its pid.
|
|
func SSHAgent(s *S, sock string) (int, error) {
|
|
r, err := s.Run(Cmd{Args: []string{"ssh-agent", "-a", sock}})
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
m := regexp.MustCompile(`SSH_AGENT_PID=([0-9]+);`).FindStringSubmatch(r.Stdout)
|
|
if m == nil {
|
|
return 0, errors.New("ssh-agent printed no pid")
|
|
}
|
|
pid, _ := strconv.Atoi(m[1])
|
|
s.Defer(func(context.Context) { StopPid(pid) })
|
|
return pid, nil
|
|
}
|
|
|
|
// StopPid sends the process TERM, once: a process the run started
|
|
// outside a command (an ssh-agent, which forks).
|
|
func StopPid(pid int) {
|
|
if pid > 0 {
|
|
_ = syscall.Kill(pid, syscall.SIGTERM)
|
|
}
|
|
}
|
|
|
|
// KeyComments is the third field of each of ssh-add -l's lines, the
|
|
// keys' comments, one a line ($(ssh-add -l | awk '{ print $3 }')).
|
|
func KeyComments(out string) string {
|
|
var cs []string
|
|
for l := range strings.SplitSeq(out, "\n") {
|
|
if f := strings.Fields(l); len(f) >= 3 {
|
|
cs = append(cs, f[2])
|
|
}
|
|
}
|
|
return strings.Join(cs, "\n")
|
|
}
|
|
|
|
// RfwdLinks checks that the VM's sshd, reached as host by the command
|
|
// ssh, binds a remote forward only on 127.77.0.0/16, the addresses of
|
|
// links: ssh's default (localhost), 127.0.0.1, 0.0.0.0, ::1, localhost
|
|
// and another range are refused, as is a remote socket forward (of
|
|
// sock, a socket here), and 127.77.0.250 binds (the control). A
|
|
// safeguard for an honest VM: the boundary is the host's ssh.
|
|
func RfwdLinks(s *S, host, sock string, ssh ...string) error {
|
|
p := strconv.Itoa(s.Port(47613))
|
|
for _, a := range []string{
|
|
"0:127.0.0.1:9", p + ":127.0.0.1:9", "127.0.0.1:" + p + ":127.0.0.1:9", "0.0.0.0:" + p + ":127.0.0.1:9",
|
|
"[::1]:" + p + ":127.0.0.1:9", "localhost:" + p + ":127.0.0.1:9", "127.78.0.2:" + p + ":127.0.0.1:9",
|
|
fmt.Sprintf("/tmp/devvm-e2e-%d.sock:%s", os.Getpid(), sock),
|
|
} {
|
|
if _, err := s.Run(Cmd{Args: append(append(ssh[:len(ssh):len(ssh)], "-o", "ExitOnForwardFailure=yes", "-R", a), host, "true")}); err == nil {
|
|
return errors.New("-R " + a + " bound")
|
|
}
|
|
}
|
|
if _, err := s.Run(Cmd{Args: append(append(ssh[:len(ssh):len(ssh)], "-o", "ExitOnForwardFailure=yes", "-R", "127.77.0.250:"+p+":127.0.0.1:9"), host, "true")}); err != nil {
|
|
return errors.New("-R 127.77.0.250 refused")
|
|
}
|
|
return nil
|
|
}
|