(t *testing.T)
| 493 | } |
| 494 | |
| 495 | func TestFindChildReposAndSessionStartVariants(t *testing.T) { |
| 496 | if _, err := exec.LookPath("git"); err != nil { |
| 497 | t.Skip("git not available") |
| 498 | } |
| 499 | |
| 500 | t.Run("non git repo exits early", func(t *testing.T) { |
| 501 | var hookErr error |
| 502 | out := captureOutput(func() { hookErr = hookSessionStart(t.TempDir()) }) |
| 503 | if hookErr != nil { |
| 504 | t.Fatalf("hookSessionStart() error: %v", hookErr) |
| 505 | } |
| 506 | if !strings.Contains(out, "Not a git repository") { |
| 507 | t.Fatalf("expected non-git notice, got:\n%s", out) |
| 508 | } |
| 509 | }) |
| 510 | |
| 511 | t.Run("multi repo parent honors gitignore", func(t *testing.T) { |
| 512 | root := t.TempDir() |
| 513 | runGitTestCmd(t, root, "init") |
| 514 | if err := os.WriteFile(filepath.Join(root, ".gitignore"), []byte("ignored-child\n"), 0o644); err != nil { |
| 515 | t.Fatal(err) |
| 516 | } |
| 517 | for _, name := range []string{"svc-a", "svc-b", "ignored-child"} { |
| 518 | child := filepath.Join(root, name) |
| 519 | if err := os.MkdirAll(child, 0o755); err != nil { |
| 520 | t.Fatal(err) |
| 521 | } |
| 522 | runGitTestCmd(t, child, "init") |
| 523 | } |
| 524 | |
| 525 | repos := findChildRepos(root) |
| 526 | got := strings.Join(repos, ",") |
| 527 | if len(repos) != 2 || !strings.Contains(got, "svc-a") || !strings.Contains(got, "svc-b") || strings.Contains(got, "ignored-child") { |
| 528 | t.Fatalf("unexpected child repos: %v", repos) |
| 529 | } |
| 530 | }) |
| 531 | |
| 532 | t.Run("git repo shows hubs and recent handoff", func(t *testing.T) { |
| 533 | root := makeRepoOnBranch(t, "feature/session-start") |
| 534 | writeWatchState(t, root, watch.State{ |
| 535 | UpdatedAt: time.Now(), |
| 536 | FileCount: 5, |
| 537 | Hubs: []string{"pkg/types.go"}, |
| 538 | Importers: map[string][]string{ |
| 539 | "pkg/types.go": {"a.go", "b.go", "c.go"}, |
| 540 | }, |
| 541 | }) |
| 542 | if err := watch.WritePID(root); err != nil { |
| 543 | t.Fatal(err) |
| 544 | } |
| 545 | t.Cleanup(func() { watch.RemovePID(root) }) |
| 546 | |
| 547 | if err := handoff.WriteLatest(root, &handoff.Artifact{ |
| 548 | SchemaVersion: handoff.SchemaVersion, |
| 549 | GeneratedAt: time.Now(), |
| 550 | Branch: "feature/session-start", |
| 551 | BaseRef: "main", |
| 552 | Delta: handoff.DeltaSnapshot{ |
nothing calls this directly
no test coverage detected