(t *testing.T)
| 230 | } |
| 231 | |
| 232 | func TestScanDeltaEmission(t *testing.T) { |
| 233 | t.Parallel() |
| 234 | |
| 235 | repoDir := initTestRepo(t) |
| 236 | logger := slogtest.Make(t, nil) |
| 237 | |
| 238 | h := agentgit.NewHandler(logger) |
| 239 | |
| 240 | // Create a dirty file. |
| 241 | dirtyFile := filepath.Join(repoDir, "dirty.go") |
| 242 | require.NoError(t, os.WriteFile(dirtyFile, []byte("package dirty\n"), 0o600)) |
| 243 | |
| 244 | h.Subscribe([]string{dirtyFile}) |
| 245 | ctx := context.Background() |
| 246 | |
| 247 | // First scan — returns all files (no previous snapshot). |
| 248 | msg1 := h.Scan(ctx) |
| 249 | require.NotNil(t, msg1) |
| 250 | require.Len(t, msg1.Repositories, 1) |
| 251 | |
| 252 | // Second scan with no changes. Should emit a heartbeat with a |
| 253 | // fresh ScannedAt but no repositories. This lets the UI's |
| 254 | // "checked Ns ago" label stay honest on an idle clean repo. |
| 255 | msg2 := h.Scan(ctx) |
| 256 | require.NotNil(t, msg2, "heartbeat should fire even with no delta") |
| 257 | require.NotNil(t, msg2.ScannedAt) |
| 258 | require.Empty(t, msg2.Repositories, "heartbeat must not report per-repo changes") |
| 259 | |
| 260 | // Revert the dirty file (make repo clean). |
| 261 | require.NoError(t, os.Remove(dirtyFile)) |
| 262 | |
| 263 | // Third scan — should emit a "clean" delta for dirty.go. |
| 264 | msg3 := h.Scan(ctx) |
| 265 | require.NotNil(t, msg3) |
| 266 | require.Len(t, msg3.Repositories, 1) |
| 267 | |
| 268 | // The file was reverted, so it should no longer appear in the diff. |
| 269 | require.NotContains(t, msg3.Repositories[0].UnifiedDiff, "dirty.go") |
| 270 | } |
| 271 | |
| 272 | // TestScanHeartbeatOnCleanRepo pins the heartbeat contract: while any |
| 273 | // repo is subscribed, every scan emits a non-nil message with a fresh |
nothing calls this directly
no test coverage detected