(t *testing.T)
| 874 | } |
| 875 | |
| 876 | func TestGetRepoChangesStagedModifiedDeleted(t *testing.T) { |
| 877 | t.Parallel() |
| 878 | |
| 879 | repoDir := initTestRepo(t) |
| 880 | logger := slogtest.Make(t, nil) |
| 881 | |
| 882 | h := agentgit.NewHandler(logger) |
| 883 | |
| 884 | // Modify the committed file (worktree modified). |
| 885 | require.NoError(t, os.WriteFile(filepath.Join(repoDir, "README.md"), []byte("# Modified\n"), 0o600)) |
| 886 | |
| 887 | // Stage a new file. |
| 888 | require.NoError(t, os.WriteFile(filepath.Join(repoDir, "staged.go"), []byte("package staged\n"), 0o600)) |
| 889 | gitCmd(t, repoDir, "add", "staged.go") |
| 890 | |
| 891 | // Create an untracked file. |
| 892 | require.NoError(t, os.WriteFile(filepath.Join(repoDir, "untracked.txt"), []byte("hello\n"), 0o600)) |
| 893 | |
| 894 | h.Subscribe([]string{filepath.Join(repoDir, "README.md")}) |
| 895 | msg := h.Scan(context.Background()) |
| 896 | require.NotNil(t, msg) |
| 897 | require.Len(t, msg.Repositories, 1) |
| 898 | |
| 899 | diff := msg.Repositories[0].UnifiedDiff |
| 900 | |
| 901 | // README.md was committed then modified in worktree. |
| 902 | require.Contains(t, diff, "README.md") |
| 903 | require.Contains(t, diff, "--- a/README.md") |
| 904 | require.Contains(t, diff, "+++ b/README.md") |
| 905 | require.Contains(t, diff, "-# Test") |
| 906 | require.Contains(t, diff, "+# Modified") |
| 907 | |
| 908 | // staged.go was added to the staging area. |
| 909 | require.Contains(t, diff, "staged.go") |
| 910 | require.Contains(t, diff, "+package staged") |
| 911 | |
| 912 | // untracked.txt is untracked (shown via --no-index diff). |
| 913 | require.Contains(t, diff, "untracked.txt") |
| 914 | require.Contains(t, diff, "+hello") |
| 915 | } |
| 916 | |
| 917 | func TestFallbackPollTriggersScan(t *testing.T) { |
| 918 | t.Parallel() |
nothing calls this directly
no test coverage detected