Files
w3cjandClaude Opus 5.5 283d06e9a4 refactor(e2e): one owner for each of the Go e2e's text, launch, log, mount, process and leak helpers
The phase's review found helpers that the section ports copied:

- firstLine (tools) duplicated FirstLine: every caller uses FirstLine.
- tailLines moves beside FirstLine and LastLine (text_test.go), and
  LastLine and link's errorsOf are built on it.
- Launch and launchWith share one launch (S.launch), which records the
  VM through OwnVM, in place of two copies of OwnVM's body.
- Paths.RunLogs is the one reader of devvm's run-log folder:
  RunLogHas, NewestLog, the heartbeat, from's corpLog and network's two
  log reads use it, in place of six globs.
- MountsOf is built on MountLine, in place of a second limactl list
  --json reader.
- Procs reads the processes through psAll, as the process watch does,
  so the listing stays out of the check's log.
- network's dialable goes: its check uses ReachesWithin and Local.
- Res.Has is HasLine on its output; CA.Line is pemLine on its PEM;
  link's out is Trim; tools' lockSum is readText.
- FilesHave goes: the desktop password's and agent save's checks that a
  secret is in no file here use NoLeak, which also fails on a file it
  can't read and names the file, never the secret.
- project's tarList reads the export with exportFiles (Go's tar) in
  place of host tar -tzf.

Tests: TestHarnessNetReaders covers LastLine and Res.Has;
TestHarnessExport covers exportFiles and tarList. Contributing's
testing page lists RunLogs, MountsOf and tailLines, and drops FilesHave.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-06 04:33:39 -07:00

82 lines
2.3 KiB
Go

//go:build e2e
package e2e
import (
"runtime"
"slices"
"strings"
)
// SaidLine is whether one of out's lines is one of msg's lines (grep -qxF).
func SaidLine(out, msg string) bool {
for l := range strings.SplitSeq(msg, "\n") {
if l != "" && HasLine(out, l) {
return true
}
}
return false
}
// FirstLine and LastLine are a message's first and last lines (m … | head -1).
func FirstLine(msg string) string { l, _, _ := strings.Cut(msg, "\n"); return l }
func LastLine(msg string) string { return tailLines(msg, 1) }
// tailLines is text's last n lines (tail -n N).
func tailLines(text string, n int) string {
l := strings.Split(strings.TrimRight(text, "\n"), "\n")
return strings.Join(l[max(0, len(l)-n):], "\n")
}
// Trim is a command's output as $(…) has it: its trailing newlines gone.
func Trim(out string) string { return strings.TrimRight(out, "\n") }
// Listed is whether limactl lists the VM (limactl list -q).
func Listed(s *S, vm string) bool {
r, _ := s.Limactl("list", "-q")
return HasLine(r.Stdout, vm)
}
// Locked is whether the file has macOS's user immutable flag, as .git
// protection sets it (ls -lO shows uchg).
func Locked(s *S, f string) bool {
if runtime.GOOS != "darwin" {
return false
}
r, err := s.Run(Cmd{Args: []string{"ls", "-lOd", f}})
return err == nil && strings.Contains(r.Stdout, "uchg")
}
// Procs is every host process's command line, one a line (ps -axww),
// which stays out of the check's log, as the process watch's.
func Procs(s *S) []string {
b, _ := psAll(s.r.window().ctx)
return strings.Split(string(b), "\n")
}
// Forwarders is the command lines of the VM's port forwarders here
// (devvm _ports -vm VM).
func Forwarders(s *S, vm string) []string {
var out []string
for _, l := range Procs(s) {
if strings.Contains(l, "_ports -vm "+vm+" ") {
out = append(out, l)
}
}
return out
}
// DevvmIn runs devvm args in dir with input (none when empty), env on
// top of the sandbox's (devvmCmd's command).
func DevvmIn(s *S, dir, input string, env []string, args ...string) (Res, error) {
return s.Run(devvmCmd(s, dir, input, env, args...))
}
// OwnVM makes the VM this run's: deleted at its end.
func OwnVM(s *S, vm string) {
if vm != "" && !slices.Contains(s.sb.created, vm) {
s.sb.created = append(s.sb.created, vm)
}
}