MCPcopy Create free account
hub / github.com/JordanCoin/codemap / TestFindChildReposAndSessionStartVariants

Function TestFindChildReposAndSessionStartVariants

cmd/hooks_more_test.go:495–581  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

493}
494
495func 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{

Callers

nothing calls this directly

Calls 10

WritePIDFunction · 0.92
RemovePIDFunction · 0.92
WriteLatestFunction · 0.92
captureOutputFunction · 0.85
hookSessionStartFunction · 0.85
runGitTestCmdFunction · 0.85
findChildReposFunction · 0.85
makeRepoOnBranchFunction · 0.85
writeWatchStateFunction · 0.85
captureOutputAndErrorFunction · 0.85

Tested by

no test coverage detected