(t *testing.T)
| 198 | } |
| 199 | |
| 200 | func TestGetRecentHandoffAndBranchDetection(t *testing.T) { |
| 201 | if _, err := exec.LookPath("git"); err != nil { |
| 202 | t.Skip("git not available") |
| 203 | } |
| 204 | |
| 205 | root := t.TempDir() |
| 206 | if got := getRecentHandoff(root); got != nil { |
| 207 | t.Fatalf("expected nil without handoff, got %+v", got) |
| 208 | } |
| 209 | |
| 210 | oldArtifact := &handoff.Artifact{ |
| 211 | SchemaVersion: handoff.SchemaVersion, |
| 212 | GeneratedAt: time.Now().Add(-25 * time.Hour), |
| 213 | Branch: "feature/old", |
| 214 | } |
| 215 | if err := handoff.WriteLatest(root, oldArtifact); err != nil { |
| 216 | t.Fatalf("WriteLatest old artifact: %v", err) |
| 217 | } |
| 218 | if got := getRecentHandoff(root); got != nil { |
| 219 | t.Fatalf("expected stale handoff to be ignored, got %+v", got) |
| 220 | } |
| 221 | |
| 222 | freshArtifact := &handoff.Artifact{ |
| 223 | SchemaVersion: handoff.SchemaVersion, |
| 224 | GeneratedAt: time.Now(), |
| 225 | Branch: "feature/fresh", |
| 226 | Delta: handoff.DeltaSnapshot{ |
| 227 | Changed: []handoff.FileStub{{Path: "main.go", Status: "modified"}}, |
| 228 | }, |
| 229 | } |
| 230 | if err := handoff.WriteLatest(root, freshArtifact); err != nil { |
| 231 | t.Fatalf("WriteLatest fresh artifact: %v", err) |
| 232 | } |
| 233 | if got := getRecentHandoff(root); got == nil || got.Branch != "feature/fresh" { |
| 234 | t.Fatalf("expected fresh handoff, got %+v", got) |
| 235 | } |
| 236 | |
| 237 | repo := makeRepoOnBranch(t, "feature/current") |
| 238 | branch, ok := gitCurrentBranch(repo) |
| 239 | if !ok || branch != "feature/current" { |
| 240 | t.Fatalf("gitCurrentBranch() = %q, %v", branch, ok) |
| 241 | } |
| 242 | if branch, ok := gitCurrentBranch(t.TempDir()); ok || branch != "" { |
| 243 | t.Fatalf("expected non-git root to have unknown branch, got %q, %v", branch, ok) |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | func TestShowDiffVsMainUsesLightweightPath(t *testing.T) { |
| 248 | if _, err := exec.LookPath("git"); err != nil { |
nothing calls this directly
no test coverage detected