TestScanHeartbeatOnCleanRepo pins the heartbeat contract: while any repo is subscribed, every scan emits a non-nil message with a fresh ScannedAt, even when no repo produced a delta. The UI's "checked Ns ago" label depends on this so an idle clean repo does not drift while the agent is still polling
(t *testing.T)
| 275 | // "checked Ns ago" label depends on this so an idle clean repo does |
| 276 | // not drift while the agent is still polling. |
| 277 | func TestScanHeartbeatOnCleanRepo(t *testing.T) { |
| 278 | t.Parallel() |
| 279 | |
| 280 | repoDir := initTestRepo(t) |
| 281 | logger := slogtest.Make(t, nil) |
| 282 | |
| 283 | h := agentgit.NewHandler(logger) |
| 284 | require.True(t, h.Subscribe([]string{repoDir})) |
| 285 | ctx := context.Background() |
| 286 | |
| 287 | // First scan on a clean repo captures branch/remote/empty-diff. |
| 288 | msg1 := h.Scan(ctx) |
| 289 | require.NotNil(t, msg1) |
| 290 | require.NotNil(t, msg1.ScannedAt) |
| 291 | require.Len(t, msg1.Repositories, 1) |
| 292 | require.Empty(t, msg1.Repositories[0].UnifiedDiff) |
| 293 | firstScanAt := *msg1.ScannedAt |
| 294 | |
| 295 | // Second scan: no delta, but heartbeat must still advance |
| 296 | // ScannedAt so clients can render an honest "checked Ns ago". |
| 297 | msg2 := h.Scan(ctx) |
| 298 | require.NotNil(t, msg2, "heartbeat should fire on a no-delta scan") |
| 299 | require.NotNil(t, msg2.ScannedAt) |
| 300 | require.Empty(t, msg2.Repositories, "heartbeat carries no per-repo changes") |
| 301 | require.False(t, msg2.ScannedAt.Before(firstScanAt), |
| 302 | "heartbeat ScannedAt must not go backwards") |
| 303 | |
| 304 | // Third scan: also a heartbeat. Still non-nil, still empty. |
| 305 | msg3 := h.Scan(ctx) |
| 306 | require.NotNil(t, msg3) |
| 307 | require.Empty(t, msg3.Repositories) |
| 308 | } |
| 309 | |
| 310 | // TestScanNoHeartbeatWithoutSubscribedRoots pins that the heartbeat |
| 311 | // only fires when there is at least one subscribed repo. Before any |
nothing calls this directly
no test coverage detected