package thin import ( "path/filepath" "strings" "testing" "amadan.net/oficina/equipo/internal/runner" "amadan.net/oficina/equipo/internal/runner/provider" ) // A Mac has no /proc/self/fd to bind a socket through, so a step's tool // socket path itself must fit sun_path (104 bytes with its NUL). It goes // under the scratch root's short t/, in a directory named only by // MkdirTemp's random number, as s: for a runner user whose home is as // long as macToolHomeName allows, the longest path still fits. The roots // are install_mac.go's (~/.local/share/equipo-runner). func TestToolSocketPathFits(t *testing.T) { cfg := func(name string) runner.Config { share := filepath.Join("/Users", name, ".local", "share", "equipo-runner") return runner.Config{StateDir: filepath.Join(share, "state"), ScratchRoot: filepath.Join(share, "scratch"), WorkspaceRoot: filepath.Join(share, "work")} } for _, name := range []string{"paulequipo", strings.Repeat("n", 32), strings.Repeat("n", macToolHomeName)} { c := cfg(name) root := macToolRoot(c) if root != filepath.Join(c.ScratchRoot, "t") { t.Fatalf("a Mac's tool sockets are under %s, not the scratch root's t/", root) } if got := macToolSocketLongest(root); len(got) > provider.MaxDarwinSocketPath { t.Fatalf("home of %d bytes: %s is %d bytes", len(name), got, len(got)) } } // One byte more no longer fits, and is refused, never cut short. if got := macToolSocketLongest(macToolRoot(cfg(strings.Repeat("n", macToolHomeName+1)))); len(got) <= provider.MaxDarwinSocketPath { t.Fatalf("macToolHomeName is not the longest name that fits: %s", got) } // The state directory, where Linux puts them, would not fit a long // name with the Linux names. if long := filepath.Join(cfg(strings.Repeat("n", 32)).StateDir, "coord-tool-4294967295", "equipo.sock"); len(long) <= provider.MaxDarwinSocketPath { t.Fatalf("the Linux layout fits after all: %s", long) } }