(t *testing.T)
| 186 | } |
| 187 | |
| 188 | func TestScanRespectsGitignoreNestedNegation(t *testing.T) { |
| 189 | t.Parallel() |
| 190 | |
| 191 | repoDir := initTestRepo(t) |
| 192 | logger := slogtest.Make(t, nil) |
| 193 | |
| 194 | // Add a .gitignore that ignores node_modules/. |
| 195 | require.NoError(t, os.WriteFile(filepath.Join(repoDir, ".gitignore"), []byte("node_modules/\n"), 0o600)) |
| 196 | gitCmd(t, repoDir, "add", ".gitignore") |
| 197 | gitCmd(t, repoDir, "commit", "-m", "add gitignore") |
| 198 | |
| 199 | // Simulate the tailwindcss stubs directory which contains a nested |
| 200 | // .gitignore with "!*" (negation that un-ignores everything). |
| 201 | // Real git keeps the parent node_modules/ ignore rule, but go-git |
| 202 | // incorrectly lets the child negation override it. |
| 203 | stubsDir := filepath.Join(repoDir, "site", "node_modules", ".pnpm", |
| 204 | "tailwindcss@3.4.18", "node_modules", "tailwindcss", "stubs") |
| 205 | require.NoError(t, os.MkdirAll(stubsDir, 0o700)) |
| 206 | require.NoError(t, os.WriteFile(filepath.Join(stubsDir, ".gitignore"), []byte("!*\n"), 0o600)) |
| 207 | require.NoError(t, os.WriteFile(filepath.Join(stubsDir, "config.full.js"), []byte("module.exports = {}\n"), 0o600)) |
| 208 | require.NoError(t, os.WriteFile(filepath.Join(stubsDir, "tailwind.config.js"), []byte("// tw config\n"), 0o600)) |
| 209 | |
| 210 | // Also create a normal file outside node_modules. |
| 211 | require.NoError(t, os.WriteFile(filepath.Join(repoDir, "main.go"), []byte("package main\n"), 0o600)) |
| 212 | |
| 213 | h := agentgit.NewHandler(logger) |
| 214 | h.Subscribe([]string{filepath.Join(repoDir, "main.go")}) |
| 215 | |
| 216 | ctx := context.Background() |
| 217 | msg := h.Scan(ctx) |
| 218 | require.NotNil(t, msg) |
| 219 | require.Len(t, msg.Repositories, 1) |
| 220 | |
| 221 | diff := msg.Repositories[0].UnifiedDiff |
| 222 | |
| 223 | // The non-ignored file should appear in the diff. |
| 224 | assert.Contains(t, diff, "main.go") |
| 225 | // Files inside node_modules must not appear even though a nested |
| 226 | // .gitignore contains "!*". The parent node_modules/ rule takes |
| 227 | // precedence in real git. |
| 228 | assert.NotContains(t, diff, "config.full.js") |
| 229 | assert.NotContains(t, diff, "tailwind.config.js") |
| 230 | } |
| 231 | |
| 232 | func TestScanDeltaEmission(t *testing.T) { |
| 233 | t.Parallel() |
nothing calls this directly
no test coverage detected