//go:build darwin package e2e import ( "bytes" "context" "crypto/sha256" "encoding/json" "encoding/xml" "fmt" "os" "os/exec" "path/filepath" "slices" "strconv" "strings" "syscall" "testing" "time" "albedo/cli/internal/localdaemon" ) // launchdHome is one private home whose launchctl is the stub. The stub keeps // the loaded plist at daemon-launchd-loaded.plist and the process it spawned in // daemon-service-stub.json; fault files beside them shape its replies. type launchdHome struct { t *testing.T home, path, loadedPath string env []string declared bool } func launchdFixture(t *testing.T) *launchdHome { t.Helper() home := filepath.Join(t.TempDir(), "home % $ &", ".albedo") userHome := t.TempDir() if err := os.MkdirAll(home, 0700); err != nil { t.Fatal(err) } digest := sha256.Sum256([]byte(home)) fixture := &launchdHome{ t: t, home: home, loadedPath: filepath.Join(home, "daemon-launchd-loaded.plist"), path: filepath.Join(userHome, "Library/LaunchAgents", fmt.Sprintf("systems.albedo.daemon-%x.plist", digest[:8])), env: append(slices.Clone(suite.env), "HOME="+userHome, "ALBEDO_HOME="+home, "ALBEDO_LAUNCHCTL="+filepath.Join(suite.root, "cli/test/e2e/login_service_stub.py")), } t.Cleanup(func() { for _, name := range []string{"launchd-disabled", "launchd-print.json", "launchd-retry.json", "print-hook.json", "fail-after-bootstrap", "fail-after-kickstart", "fail-after-bootout", "bootout-reply-gate"} { _ = os.Remove(filepath.Join(home, name)) } snapshot, _ := readDaemonSnapshot(home) if snapshot.Pid > 0 && syscall.Kill(snapshot.Pid, 0) == nil { if output, err := fixture.run("daemon", "--stop", "--kernels"); err != nil { t.Errorf("cleanup stop: %v %s", err, output) } } if fixture.declared { // These are this fixture's private stub files, never native registrations. if snapshot.Pid <= 0 || awaitExit(snapshot.Pid, 5*time.Second) { for _, path := range []string{fixture.path, fixture.loadedPath} { if err := os.Remove(path); err != nil && !os.IsNotExist(err) { t.Errorf("cleanup private declaration: %v", err) } } } } else if _, err := os.Lstat(fixture.path); err == nil { if output, err := fixture.run("daemon", "uninstall"); err != nil { t.Errorf("cleanup uninstall: %v %s", err, output) } } if snapshot.Pid > 0 && !awaitExit(snapshot.Pid, 5*time.Second) { t.Errorf("private daemon %d survived", snapshot.Pid) } }) return fixture } func (fixture *launchdHome) run(args ...string) (string, error) { ctx, cancel := context.WithTimeout(context.Background(), 90*time.Second) defer cancel() cmd := exec.CommandContext(ctx, suite.cli, args...) cmd.Env = fixture.env output, err := cmd.CombinedOutput() return string(output), err } func (fixture *launchdHome) must(args ...string) string { fixture.t.Helper() output, err := fixture.run(args...) if err != nil { fixture.t.Fatalf("%v: %v %s", args, err, output) } return output } func (fixture *launchdHome) refuses(args ...string) string { fixture.t.Helper() output, err := fixture.run(args...) if err == nil { fixture.t.Fatalf("%v succeeded: %s", args, output) } return output } func (fixture *launchdHome) status() localdaemon.ServiceStatus { fixture.t.Helper() var status localdaemon.ServiceStatus if err := json.Unmarshal([]byte(fixture.must("daemon", "status", "--json")), &status); err != nil { fixture.t.Fatal(err) } return status } func (fixture *launchdHome) writeJSON(name string, value any) { fixture.t.Helper() data, err := json.Marshal(value) if err != nil { fixture.t.Fatal(err) } fixture.writeFile(filepath.Join(fixture.home, name), data) } func (fixture *launchdHome) writeFile(path string, data []byte) { fixture.t.Helper() if err := os.WriteFile(path, data, 0600); err != nil { fixture.t.Fatal(err) } } func (fixture *launchdHome) read(path string) []byte { fixture.t.Helper() data, err := os.ReadFile(path) if err != nil { fixture.t.Fatal(err) } return data } func (fixture *launchdHome) exists(path string) bool { _, err := os.Lstat(path) return err == nil } // verbs counts the launchd mutations the stub received. func (fixture *launchdHome) verbs(verb string) int { fixture.t.Helper() data, err := os.ReadFile(filepath.Join(fixture.home, "service-stub.log")) if err != nil && !os.IsNotExist(err) { fixture.t.Fatal(err) } return strings.Count(string(data), `["`+verb+`",`) } // hookPrint arms print-hook.json for the call-th print from now on. func (fixture *launchdHome) hookPrint(hook map[string]any) { fixture.t.Helper() _ = os.Remove(filepath.Join(fixture.home, "print-count")) fixture.writeJSON("print-hook.json", hook) } func (fixture *launchdHome) retrying(runs int) { fixture.writeJSON("launchd-retry.json", map[string]any{"state": "spawn scheduled", "runs": runs, "history": "last exit code = 75: EX_TEMPFAIL"}) } func (fixture *launchdHome) startCLI(args ...string) (*exec.Cmd, *bytes.Buffer) { fixture.t.Helper() cmd := exec.Command(suite.cli, args...) cmd.Env = fixture.env var output bytes.Buffer cmd.Stdout, cmd.Stderr = &output, &output if err := cmd.Start(); err != nil { fixture.t.Fatal(err) } fixture.t.Cleanup(func() { if cmd.ProcessState == nil { _ = cmd.Process.Kill() _ = cmd.Wait() } }) return cmd, &output } func (fixture *launchdHome) await(what string, ready func() bool) { fixture.t.Helper() deadline := time.Now().Add(20 * time.Second) for !ready() { if time.Now().After(deadline) { fixture.t.Fatalf("timed out waiting for %s", what) } time.Sleep(10 * time.Millisecond) } } // startHolder runs the daemon directly, independent of the registration. func (fixture *launchdHome) startHolder() int { fixture.t.Helper() executable := "" for _, entry := range fixture.env { if value, ok := strings.CutPrefix(entry, "ALBEDO_DAEMON="); ok { executable = value } } holder := exec.Command(executable) holder.Env = append(slices.Clone(fixture.env), "ALBEDO_PARENT_PID="+strconv.Itoa(os.Getpid())) log, err := os.OpenFile(filepath.Join(fixture.home, "holder.log"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600) if err != nil { fixture.t.Fatal(err) } defer log.Close() holder.Stdout, holder.Stderr = log, log if err = holder.Start(); err != nil { fixture.t.Fatal(err) } go func() { _ = holder.Wait() }() fixture.t.Cleanup(func() { _ = holder.Process.Kill() }) fixture.await("independent daemon", func() bool { snapshot, _ := readDaemonSnapshot(fixture.home) return snapshot.Pid == holder.Process.Pid && fixture.status().Pid == holder.Process.Pid }) return holder.Process.Pid } func TestDaemonServiceDarwinRefreshDriftAndUnloaded(t *testing.T) { fixture := launchdFixture(t) fixture.must("daemon", "install") first := fixture.status() if first.Class != localdaemon.ManagedService || first.Manager != "launchd" || first.Pid == 0 || first.Pid != first.MainPID { t.Fatalf("install did not produce a managed daemon: %+v", first) } fixture.must("daemon", "install") if fixture.status().Pid != first.Pid { t.Fatal("refresh replaced daemon") } fixture.must("daemon", "--stop") if !awaitExit(first.Pid, 5*time.Second) { t.Fatal("ordinary stop left daemon alive") } if idle := fixture.status(); idle.Class != localdaemon.ServiceIdle || idle.Pid != 0 { t.Fatalf("stop did not leave the registration idle: %+v", idle) } fixture.must("daemon", "install") if fixture.status().Class != localdaemon.ServiceIdle { t.Fatal("idle refresh started daemon") } originalLoaded := fixture.read(fixture.loadedPath) drift := bytes.ReplaceAll(originalLoaded, []byte(suite.root), []byte(suite.root+"-drift")) if bytes.Equal(drift, originalLoaded) { t.Fatal("fixture did not change loaded definition") } fixture.writeFile(fixture.loadedPath, drift) if output := fixture.refuses("daemon"); !strings.Contains(output, "uninstall") { t.Fatalf("drift refusal gives no reconciliation: %s", output) } if !bytes.Equal(fixture.read(fixture.loadedPath), drift) || fixture.verbs("kickstart") != 0 || fixture.verbs("bootout") != 0 { t.Fatal("Connect acted on a drifted registration") } fixture.writeFile(fixture.loadedPath, originalLoaded) // An unloaded owned file is bootstrapped by an ordinary Connect. if err := os.Remove(fixture.loadedPath); err != nil { t.Fatal(err) } fixture.must("daemon") if managed := fixture.status(); managed.Class != localdaemon.ManagedService || fixture.verbs("bootstrap") != 2 { t.Fatalf("unloaded Connect did not bootstrap: %+v", managed) } fixture.must("daemon", "--stop", "--kernels") if err := os.Remove(fixture.loadedPath); err != nil { t.Fatal(err) } fixture.writeFile(filepath.Join(fixture.home, "launchd-disabled"), []byte{}) if output := fixture.refuses("daemon"); !strings.Contains(output, "launchctl enable") { t.Fatalf("disabled start refusal: %s", output) } fixture.must("daemon", "uninstall") if fixture.exists(fixture.path) || !fixture.exists(filepath.Join(fixture.home, "launchd-disabled")) { t.Fatal("disabled unloaded uninstall kept the file or changed the override") } fixture.refuses("daemon", "install") if fixture.exists(fixture.path) { t.Fatal("disabled install published file") } if fixture.verbs("bootout") != 0 || fixture.verbs("bootstrap") != 2 { t.Fatal("stop, disabled start or unloaded uninstall submitted a manager mutation") } } func TestDaemonServiceDarwinUninstallDrainsManagedDaemonAndBootsOutOnce(t *testing.T) { fixture := launchdFixture(t) fixture.must("daemon", "install") managed := fixture.status() fixture.must("daemon", "uninstall") if !awaitExit(managed.Pid, time.Second) { t.Fatal("uninstall left the managed daemon running") } if fixture.exists(fixture.path) || fixture.exists(fixture.loadedPath) || fixture.verbs("bootout") != 1 { t.Fatalf("uninstall left file=%v registration=%v after %d bootouts", fixture.exists(fixture.path), fixture.exists(fixture.loadedPath), fixture.verbs("bootout")) } } func TestDaemonServiceDarwinRetryYieldsToIndependentHolder(t *testing.T) { fixture := launchdFixture(t) fixture.must("daemon", "install") fixture.must("daemon", "--stop") fixture.retrying(3) if output := fixture.refuses("daemon", "--stop"); !strings.Contains(output, "launchd may retry") { t.Fatalf("retry stop: %s", output) } if status := fixture.status(); status.Class != localdaemon.ServiceRetrying || !strings.Contains(status.Note, "exit 75") { t.Fatalf("retry status: %+v", status) } fixture.must("daemon", "install") holder := fixture.startHolder() if status := fixture.status(); status.Class != localdaemon.StandaloneBeside || status.Pid != holder { t.Fatalf("holder did not take precedence over retry: %+v", status) } fixture.must("daemon") fixture.must("daemon", "uninstall") if syscall.Kill(holder, 0) != nil { t.Fatal("uninstall stopped the independent holder") } if fixture.exists(fixture.path) || fixture.exists(fixture.loadedPath) || fixture.verbs("bootout") != 1 || fixture.verbs("kickstart") != 0 { t.Fatal("uninstall did not remove only the retrying registration") } fixture.must("daemon", "--stop") if !awaitExit(holder, 10*time.Second) { t.Fatal("standalone stop failed after uninstall") } } func TestDaemonServiceDarwinRetryRecoveryAcceptsResetRunCount(t *testing.T) { fixture := launchdFixture(t) fixture.must("daemon", "install") fixture.must("daemon", "--stop") fixture.retrying(5) fixture.hookPrint(map[string]any{}) connect, output := fixture.startCLI("daemon") fixture.await("Connect observing the retry", func() bool { count, _ := os.ReadFile(filepath.Join(fixture.home, "print-count")) calls, _ := strconv.Atoi(string(count)) return calls >= 3 }) // Stand in for launchd's own retry after a re-registration reset its count. _ = os.Remove(filepath.Join(fixture.home, "launchd-retry.json")) fixture.writeJSON("daemon-service-stub.json", map[string]int{"pid": 0, "runs": 0}) recovery := exec.Command(filepath.Join(suite.root, "cli/test/e2e/login_service_stub.py"), "kickstart", fmt.Sprintf("gui/%d/%s", os.Getuid(), strings.TrimSuffix(filepath.Base(fixture.path), ".plist"))) recovery.Env = fixture.env if result, err := recovery.CombinedOutput(); err != nil { t.Fatalf("recovery: %v %s", err, result) } if err := connect.Wait(); err != nil { t.Fatalf("Connect refused a recovered daemon with a lower run count: %v %s", err, output) } if status := fixture.status(); status.Class != localdaemon.ManagedService || fixture.verbs("kickstart") != 1 { t.Fatalf("Connect started the retrying service itself or did not attach: %+v", status) } } func TestDaemonServiceDarwinWithoutGUIDomainOnlyFileFreeHomesRunStandalone(t *testing.T) { fixture := launchdFixture(t) fixture.writeJSON("launchd-print.json", map[string]any{"status": 112, "stderr": fmt.Sprintf("Bad request.\nCould not find domain for user gui: %d\n", os.Getuid())}) fixture.must("daemon") standalone := fixture.status() if standalone.Class != localdaemon.NoService || !strings.Contains(standalone.Note, "GUI domain absent") { t.Fatalf("no-GUI standalone status: %+v", standalone) } fixture.refuses("daemon", "install") if fixture.exists(fixture.path) { t.Fatal("install published without a GUI domain") } fixture.must("daemon", "--stop") if err := os.MkdirAll(filepath.Dir(fixture.path), 0700); err != nil { t.Fatal(err) } if err := os.WriteFile(fixture.path, []byte("foreign"), 0600); err != nil { t.Fatal(err) } fixture.refuses("daemon") if snapshot, _ := readDaemonSnapshot(fixture.home); snapshot.Pid > 0 && syscall.Kill(snapshot.Pid, 0) == nil { t.Fatal("daemon launched beside a service file without a GUI domain") } if err := os.Remove(fixture.path); err != nil { t.Fatal(err) } fixture.writeJSON("launchd-print.json", map[string]any{"status": 125, "stderr": "Could not print domain: 125: Domain does not support specified action\n"}) fixture.refuses("daemon") if snapshot, _ := readDaemonSnapshot(fixture.home); snapshot.Pid > 0 && syscall.Kill(snapshot.Pid, 0) == nil { t.Fatal("ambiguous manager failure permitted direct launch") } } func TestDaemonServiceDarwinFailedShutdownNeverFallsBackToBootout(t *testing.T) { fixture := launchdFixture(t) fixture.must("daemon", "install") // The daemon dies right after uninstall's identity bracket accepts it. fixture.hookPrint(map[string]any{"call": 3, "kill_after_reply": true}) fixture.refuses("daemon", "uninstall") if !fixture.exists(fixture.path) || !fixture.exists(fixture.loadedPath) || fixture.verbs("bootout") != 0 { t.Fatal("failed authenticated shutdown was followed by removal") } } func TestDaemonServiceDarwinChangesBeforeMutationAreRefused(t *testing.T) { fixture := launchdFixture(t) fixture.must("daemon", "install") fixture.must("daemon", "--stop") original := fixture.read(fixture.path) // A file replaced after install's first observation is never overwritten. fixture.hookPrint(map[string]any{"call": 2, "write": map[string]string{fixture.path: "replacement"}}) fixture.refuses("daemon", "install") if string(fixture.read(fixture.path)) != "replacement" { t.Fatal("install overwrote a replaced file") } fixture.writeFile(fixture.path, original) // A loaded definition changed after uninstall accepted it is not booted out. loaded := fixture.read(fixture.loadedPath) changed := bytes.ReplaceAll(loaded, []byte(suite.root), []byte(suite.root+"-replaced")) fixture.hookPrint(map[string]any{"call": 2, "write": map[string]string{fixture.loadedPath: string(changed)}}) fixture.refuses("daemon", "uninstall") if fixture.verbs("bootout") != 0 || !bytes.Equal(fixture.read(fixture.path), original) { t.Fatal("uninstall acted on a changed registration") } _ = os.Remove(filepath.Join(fixture.home, "print-hook.json")) fixture.writeFile(fixture.loadedPath, loaded) } func TestDaemonServiceDarwinStartPreservesReplacedFile(t *testing.T) { for _, loaded := range []bool{true, false} { t.Run(fmt.Sprintf("loaded=%v", loaded), func(t *testing.T) { fixture := launchdFixture(t) fixture.must("daemon", "install") fixture.must("daemon", "--stop") original := fixture.read(fixture.path) defer fixture.writeFile(fixture.path, original) if !loaded { if err := os.Remove(fixture.loadedPath); err != nil { t.Fatal(err) } } bootstraps, kickstarts := fixture.verbs("bootstrap"), fixture.verbs("kickstart") fixture.hookPrint(map[string]any{"call": 2, "write": map[string]string{fixture.path: "replacement"}}) fixture.refuses("daemon") if string(fixture.read(fixture.path)) != "replacement" || fixture.verbs("bootstrap") != bootstraps || fixture.verbs("kickstart") != kickstarts { t.Fatal("start submitted a mutation or changed the replacement file") } if snapshot, _ := readDaemonSnapshot(fixture.home); snapshot.Pid > 0 && syscall.Kill(snapshot.Pid, 0) == nil { t.Fatal("a process started after the file changed") } }) } } func TestDaemonServiceDarwinBootoutRaceAndCancellationKeepFile(t *testing.T) { for _, cancel := range []bool{false, true} { t.Run(map[bool]string{false: "file replaced", true: "cancelled"}[cancel], func(t *testing.T) { fixture := launchdFixture(t) fixture.must("daemon", "install") fixture.must("daemon", "--stop") gate := filepath.Join(fixture.home, "bootout-reply-gate") if err := syscall.Mkfifo(gate, 0600); err != nil { t.Fatal(err) } uninstall, output := fixture.startCLI("daemon", "uninstall") fixture.await("bootout submission", func() bool { return fixture.exists(filepath.Join(fixture.home, "bootout-submitted")) }) want := fixture.read(fixture.path) if cancel { if err := uninstall.Process.Signal(os.Interrupt); err != nil { t.Fatal(err) } } else { want = []byte("replacement") fixture.writeFile(fixture.path, want) release, err := os.OpenFile(gate, os.O_WRONLY, 0) if err != nil { t.Fatal(err) } _ = release.Close() } if err := uninstall.Wait(); err == nil { t.Fatalf("uninstall succeeded: %s", output) } if !bytes.Equal(fixture.read(fixture.path), want) || fixture.verbs("bootout") != 1 || fixture.exists(fixture.loadedPath) { t.Fatalf("bootout outcome: %s", output) } if cancel && !strings.Contains(output.String(), "may have taken effect") { t.Fatalf("cancellation did not report partial state: %s", output) } _ = os.Remove(gate) if !cancel { if err := os.Remove(fixture.path); err != nil { t.Fatal(err) } } }) } } func TestDaemonServiceDarwinFailedRepliesKeepSubmittedEffects(t *testing.T) { fixture := launchdFixture(t) fixture.writeFile(filepath.Join(fixture.home, "fail-after-bootstrap"), []byte{}) if output := fixture.refuses("daemon", "install"); !strings.Contains(output, "configuration left in place") { t.Fatalf("failed bootstrap reply: %s", output) } if !fixture.exists(fixture.path) || !fixture.exists(fixture.loadedPath) { t.Fatal("failed bootstrap reply lost the file or registration") } fixture.await("submitted daemon", func() bool { return fixture.status().Class == localdaemon.ManagedService }) _ = os.Remove(filepath.Join(fixture.home, "fail-after-bootstrap")) fixture.must("daemon", "--stop") fixture.writeFile(filepath.Join(fixture.home, "fail-after-kickstart"), []byte{}) if output := fixture.refuses("daemon"); !strings.Contains(output, "kickstart may have taken effect") { t.Fatalf("failed kickstart reply: %s", output) } fixture.await("kickstarted daemon", func() bool { return fixture.status().Class == localdaemon.ManagedService }) _ = os.Remove(filepath.Join(fixture.home, "fail-after-kickstart")) fixture.must("daemon", "--stop") fixture.writeFile(filepath.Join(fixture.home, "fail-after-bootout"), []byte{}) if output := fixture.refuses("daemon", "uninstall"); !strings.Contains(output, "bootout may have taken effect") { t.Fatalf("failed bootout reply: %s", output) } if !fixture.exists(fixture.path) || fixture.exists(fixture.loadedPath) || fixture.verbs("bootout") != 1 { t.Fatal("failed bootout reply removed the file or retried") } _ = os.Remove(filepath.Join(fixture.home, "fail-after-bootout")) } func TestDaemonServiceDarwinUnsafeObservationAllowsOnlyAttachment(t *testing.T) { fixture := launchdFixture(t) fixture.must("daemon", "install") original := fixture.read(fixture.path) managed := fixture.status() fixture.writeJSON("launchd-print.json", map[string]any{"stdout": "malformed manager output\n"}) for _, args := range [][]string{{"daemon", "--stop", "--kernels"}, {"daemon", "uninstall"}, {"daemon", "install"}} { fixture.refuses(args...) } if !bytes.Equal(fixture.read(fixture.path), original) || fixture.status().Pid != managed.Pid { t.Fatal("unsafe observation changed the file or daemon") } fixture.must("daemon") if !fixture.exists(fixture.loadedPath) || fixture.verbs("bootout") != 0 { t.Fatal("unsafe observation removed registration") } } // Direct form deliberately avoids wait4path and any dependency on a Nix store. func TestDaemonServiceDarwinDeclaredLifecycle(t *testing.T) { fixture := launchdFixture(t) fixture.must("daemon", "install") fixture.must("daemon", "--stop") original := fixture.read(fixture.path) var document struct { Arguments []string `xml:"dict>array>string"` } if err := xml.Unmarshal(original, &document); err != nil || len(document.Arguments) != 3 { t.Fatalf("installed arguments: %+v %v", document, err) } executable := filepath.Join(t.TempDir(), "bin", "albedo") if err := os.MkdirAll(filepath.Dir(executable), 0700); err != nil { t.Fatal(err) } if err := os.Symlink(suite.cli, executable); err != nil { t.Fatal(err) } var before, after bytes.Buffer if err := xml.EscapeText(&before, []byte(document.Arguments[0])); err != nil { t.Fatal(err) } if err := xml.EscapeText(&after, []byte(executable)); err != nil { t.Fatal(err) } declaration := bytes.Replace(original, []byte("\n"), nil, 1) declaration = bytes.Replace(declaration, before.Bytes(), after.Bytes(), 1) oldLabel := strings.TrimSuffix(filepath.Base(fixture.path), ".plist") declaration = bytes.ReplaceAll(declaration, []byte(oldLabel), []byte("systems.albedo.daemon")) if err := os.Remove(fixture.path); err != nil { t.Fatal(err) } userHome := filepath.Dir(fixture.home) for index, entry := range fixture.env { if strings.HasPrefix(entry, "HOME=") { fixture.env[index] = "HOME=" + userHome } } fixture.path = filepath.Join(userHome, "Library/LaunchAgents/systems.albedo.daemon.plist") if err := os.MkdirAll(filepath.Dir(fixture.path), 0700); err != nil { t.Fatal(err) } fixture.writeFile(fixture.path, declaration) fixture.writeFile(fixture.loadedPath, declaration) fixture.declared = true beforeInfo, err := os.Stat(fixture.path) if err != nil { t.Fatal(err) } bootstraps, bootouts := fixture.verbs("bootstrap"), fixture.verbs("bootout") fixture.must("daemon") first := fixture.status() if first.Class != localdaemon.ManagedService || !strings.Contains(first.Note, "externally managed") { t.Fatalf("declared daemon: %+v", first) } fixture.refuses("daemon", "install") fixture.refuses("daemon", "uninstall") if current := fixture.status(); current.Pid != first.Pid || current.Class != localdaemon.ManagedService { t.Fatalf("refusal changed daemon: %+v", current) } fixture.writeFile(filepath.Join(fixture.home, "launchd-disabled"), nil) fixture.must("daemon", "--stop") fixture.refuses("daemon") if err = os.Remove(filepath.Join(fixture.home, "launchd-disabled")); err != nil { t.Fatal(err) } fixture.must("daemon") if current := fixture.status(); current.Class != localdaemon.ManagedService || current.Pid == first.Pid { t.Fatalf("declared restart: %+v", current) } fixture.must("daemon", "--stop") afterInfo, err := os.Stat(fixture.path) if err != nil { t.Fatal(err) } if !os.SameFile(beforeInfo, afterInfo) || !bytes.Equal(fixture.read(fixture.path), declaration) || !bytes.Equal(fixture.read(fixture.loadedPath), declaration) || fixture.verbs("bootstrap") != bootstraps || fixture.verbs("bootout") != bootouts { t.Fatal("external lifecycle mutated declaration or registration") } if err := os.Remove(fixture.loadedPath); err != nil { t.Fatal(err) } fixture.refuses("daemon") if fixture.verbs("bootstrap") != bootstraps { t.Fatal("unloaded declaration was bootstrapped") } }