(t *testing.T)
| 96 | } |
| 97 | |
| 98 | func TestIsOwnedDaemonMatchesCommandLine(t *testing.T) { |
| 99 | if _, err := processCommandLine(os.Getpid()); shouldSkipProcessCommandError(err) { |
| 100 | t.Skipf("process command introspection not permitted in this environment: %v", err) |
| 101 | } |
| 102 | |
| 103 | root := t.TempDir() |
| 104 | codemapDir := filepath.Join(root, ".codemap") |
| 105 | if err := os.MkdirAll(codemapDir, 0o755); err != nil { |
| 106 | t.Fatal(err) |
| 107 | } |
| 108 | |
| 109 | cmd := exec.Command(os.Args[0], "-test.run=TestOwnedDaemonHelperProcess", "watch", "daemon", root) |
| 110 | cmd.Env = append(os.Environ(), "CODEMAP_WATCH_HELPER=1") |
| 111 | if err := cmd.Start(); err != nil { |
| 112 | t.Fatalf("start helper daemon: %v", err) |
| 113 | } |
| 114 | defer func() { |
| 115 | _ = cmd.Process.Kill() |
| 116 | _, _ = cmd.Process.Wait() |
| 117 | }() |
| 118 | |
| 119 | pidPath := filepath.Join(codemapDir, "watch.pid") |
| 120 | if err := os.WriteFile(pidPath, []byte(strconv.Itoa(cmd.Process.Pid)), 0o644); err != nil { |
| 121 | t.Fatal(err) |
| 122 | } |
| 123 | |
| 124 | deadline := time.Now().Add(2 * time.Second) |
| 125 | for !IsOwnedDaemon(root) { |
| 126 | if time.Now().After(deadline) { |
| 127 | t.Fatal("expected process command line to match owned daemon") |
| 128 | } |
| 129 | time.Sleep(25 * time.Millisecond) |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | func TestReadPIDInvalidContent(t *testing.T) { |
| 134 | root := t.TempDir() |
nothing calls this directly
no test coverage detected