Files
w3cjandClaude Opus 5.5 2545de19f3 test(e2e): the Go runner is the entry point, mise run e2e -- FLAGS, and tests/e2e.sh goes
TestE2E already set up the sandbox, slots, locks and flags itself, so the
898-line script only handed over. The run is now `mise run e2e -- FLAGS`
(go test -tags e2e from tests/e2e, CGO_ENABLED=0) with the same flags:
--only, --from, --clean, --every-feature, --slots, --slot, --newest-base,
--golden, plus --reuse.

- options: the flags named as the script's options; the hand-over flags
  (lock-holder, count, total, started, summary) and the ported/unported
  split are gone.
- e2eUbuntuRelease, a const in sandbox_test.go, holds the Ubuntu pin;
  scripts/bump.sh e2e-ubuntu moves it (get_const), and TestE2EUbuntuPins,
  bump.txtar and the E2E workflow read it there.
- From the script into Go: the OpenSSL-not-LibreSSL host check, and
  --newest-base's start line and its UPSTREAM DRIFT summary.
- The script's leftover bash helpers (perl vm_state, no_leak, ca_*,
  lima_listens, the retry list, its heartbeat) are gone with it.
- mise's e2e:go task merges into e2e; TestCommandLines drops its $D rule.
- Docs (contributing, testing, maintaining, internals) and AGENTS.md name
  mise run e2e; testing.md's "Porting a section" becomes "Adding a section".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-06 01:56:50 -07:00

100 lines
2.6 KiB
Go

//go:build e2e
// Package e2e is devvm's end-to-end tests: real VMs, in a sandbox, a
// section at a time. TestE2E is the run, and its flags (--only, --slots…)
// come after go test's -args. Each section is a file of its own, listed in
// sections. mise run e2e runs it from this folder, where go test streams
// its output:
//
// mise run e2e -- --only gc
// cd tests/e2e && go test -tags e2e -count=1 -timeout 0 -run '^TestE2E$' -args --only gc
package e2e
import (
"context"
"flag"
"os"
"os/signal"
"syscall"
"testing"
"time"
)
// TestMain registers the run's flags on the command line's flag set, so
// go test's -args reach them; TestE2E reads them back (readOptions).
func TestMain(m *testing.M) {
registerFlags(flag.CommandLine)
os.Exit(m.Run())
}
// TestE2E is the run: the chosen sections, in a slot's sandbox, or spread
// over --slots of them. It fails when a check fails or a section ends
// early.
func TestE2E(t *testing.T) {
if d := flag.Lookup("test.timeout").Value.String(); d != "0s" {
t.Fatalf("e2e: run it with -timeout 0 (go test's %s would end a long section mid-check)", d)
}
o, err := readOptions(flag.CommandLine, sections())
if err != nil {
t.Fatalf("e2e: %v", err)
}
ctx, stop := signal.NotifyContext(t.Context(), syscall.SIGINT, syscall.SIGTERM)
defer stop()
out := newOutput(os.Stdout)
var ok bool
if o.slots > 1 {
ok, err = runSlots(ctx, out, o)
} else {
ok, err = runSlot(ctx, out, o)
}
if err != nil {
out.line("e2e: %v", err)
ok = false
}
if ctx.Err() != nil && t.Context().Err() == nil {
out.line("e2e: interrupted")
ok = false
}
if !ok {
t.Fail()
}
}
// runSlot is one slot's run: its sandbox set up, the chosen sections run,
// then everything the run made deleted.
func runSlot(ctx context.Context, out *output, o options) (bool, error) {
sb, err := newSandbox(o)
if err != nil {
return false, err
}
if err := sb.checkTools(ctx, o.sel); err != nil {
return false, err
}
if err := sb.lock(); err != nil {
return false, err
}
defer sb.unlock()
// The cleanup outlives the run's context: an interrupted run still
// deletes what it made.
defer sb.cleanup(context.WithoutCancel(ctx), out)
if err := sb.setup(ctx, out); err != nil {
return false, err
}
if o.newest {
listed, err := listedRelease(ctx)
if err != nil {
return false, err
}
out.line("e2e: newest base: Ubuntu's cloud image %s (e2e pins %s) and the mirrors' newest packages, in %s", listed, e2eUbuntuRelease, sb.work)
}
r := newRunner(ctx, out, sb, o)
defer r.stop()
for _, sec := range sections() {
if !o.wants(sec.name) || ctx.Err() != nil {
continue
}
r.section(sec)
}
return r.finish(time.Now()), nil
}