(t *testing.T)
| 437 | } |
| 438 | |
| 439 | func TestSubscribeNestedGitRepos(t *testing.T) { |
| 440 | t.Parallel() |
| 441 | |
| 442 | // Create an outer repo. |
| 443 | outerDir := initTestRepo(t) |
| 444 | |
| 445 | // Create an inner repo nested inside the outer one. |
| 446 | innerDir := filepath.Join(outerDir, "subproject") |
| 447 | require.NoError(t, os.MkdirAll(innerDir, 0o700)) |
| 448 | |
| 449 | gitCmd(t, innerDir, "init") |
| 450 | gitCmd(t, innerDir, "config", "user.name", "Test") |
| 451 | gitCmd(t, innerDir, "config", "user.email", "test@test.com") |
| 452 | |
| 453 | // Commit a file in the inner repo so it has HEAD. |
| 454 | innerFile := filepath.Join(innerDir, "inner.go") |
| 455 | require.NoError(t, os.WriteFile(innerFile, []byte("package inner\n"), 0o600)) |
| 456 | gitCmd(t, innerDir, "add", "inner.go") |
| 457 | gitCmd(t, innerDir, "commit", "-m", "inner commit") |
| 458 | |
| 459 | // Now create a dirty file in the inner repo. |
| 460 | dirtyFile := filepath.Join(innerDir, "dirty.go") |
| 461 | require.NoError(t, os.WriteFile(dirtyFile, []byte("package inner\n"), 0o600)) |
| 462 | |
| 463 | logger := slogtest.Make(t, nil) |
| 464 | h := agentgit.NewHandler(logger) |
| 465 | |
| 466 | // Subscribe with the path inside the inner repo. |
| 467 | added := h.Subscribe([]string{dirtyFile}) |
| 468 | require.True(t, added) |
| 469 | |
| 470 | msg := h.Scan(context.Background()) |
| 471 | require.NotNil(t, msg) |
| 472 | require.Len(t, msg.Repositories, 1, "should track only one repo") |
| 473 | |
| 474 | // The tracked repo should be the inner repo, not the outer one. |
| 475 | require.Equal(t, innerDir, msg.Repositories[0].RepoRoot, |
| 476 | "should track the inner (nearest) repo, not the outer one") |
| 477 | } |
| 478 | |
| 479 | func TestScanDeletedRepoEmitsRemoved(t *testing.T) { |
| 480 | t.Parallel() |
nothing calls this directly
no test coverage detected