P6-03 repo size trend + agent-update UI fix + dashboard polish #21
@@ -339,6 +339,10 @@ func dispatchAgentMessage(ctx context.Context, c *Conn, hostID string, env api.E
|
||||
} else {
|
||||
slog.Info("ws: repo stats refreshed", "host_id", hostID)
|
||||
}
|
||||
day := time.Now().UTC().Format("2006-01-02")
|
||||
if err := deps.Store.UpsertHostRepoStatsHistory(ctx, hostID, day, patch, time.Now().UTC()); err != nil {
|
||||
slog.Warn("ws: upsert host repo stats history", "host_id", hostID, "err", err)
|
||||
}
|
||||
|
||||
case api.MsgCommandResult:
|
||||
// TODO(P2): persist command.result acks for "did the agent
|
||||
|
||||
@@ -133,3 +133,42 @@ func TestRepoStatsReportPartialUpdate(t *testing.T) {
|
||||
t.Errorf("LastCheckStatus: got %q want ok", got.LastCheckStatus)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepoStatsReportWritesHistoryRow(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := openWSTestStore(t)
|
||||
ctx := context.Background()
|
||||
|
||||
const hostID = "h-stats-history"
|
||||
seedHostWS(t, s, hostID)
|
||||
|
||||
payload := api.RepoStatsPayload{
|
||||
TotalSizeBytes: int64ptrWS(12345),
|
||||
SnapshotCount: int64ptrWS(7),
|
||||
}
|
||||
env, err := api.Marshal(api.MsgRepoStats, "", payload)
|
||||
if err != nil {
|
||||
t.Fatalf("marshal: %v", err)
|
||||
}
|
||||
|
||||
deps := HandlerDeps{Store: s}
|
||||
dispatchAgentMessage(ctx, nil, hostID, env, deps)
|
||||
|
||||
pts, err := s.ListHostRepoStatsHistory(ctx, hostID, time.Time{})
|
||||
if err != nil {
|
||||
t.Fatalf("list history: %v", err)
|
||||
}
|
||||
if len(pts) != 1 {
|
||||
t.Fatalf("want 1 history row, got %d", len(pts))
|
||||
}
|
||||
wantDay := time.Now().UTC().Format("2006-01-02")
|
||||
if got := pts[0].Day.Format("2006-01-02"); got != wantDay {
|
||||
t.Errorf("day: want %s, got %s", wantDay, got)
|
||||
}
|
||||
if pts[0].TotalSizeBytes == nil || *pts[0].TotalSizeBytes != 12345 {
|
||||
t.Errorf("TotalSizeBytes: want 12345, got %v", pts[0].TotalSizeBytes)
|
||||
}
|
||||
if pts[0].SnapshotCount == nil || *pts[0].SnapshotCount != 7 {
|
||||
t.Errorf("SnapshotCount: want 7, got %v", pts[0].SnapshotCount)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user