fix(agent): slice-3 follow-ups — keep run-status on config fail, selftest usage, contract golden (v0.3.1)

- collect: a per-guest GuestConfig failure preserves the ListLXC run-status (only
  spec dropped); empty status normalized to "unknown". Test asserts preserved
  "running" + nil spec.
- main: --selftest usage error now reads (want read|task|hub).
- contract: testdata/host-report.golden.json + TestHostReport_ContractMatchesGolden
  (field-name key-set check vs golden; byte-identical with the hub copy).
- version 0.3.0 -> 0.3.1.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-08 18:29:05 +02:00
parent ab77fa3544
commit e68a7af4d3
7 changed files with 182 additions and 67 deletions
+8 -3
View File
@@ -105,13 +105,18 @@ func (c *Collector) collectGuests(ctx context.Context) []Guest {
guests := make([]Guest, 0, len(lxc))
for _, g := range lxc {
entry := Guest{VMID: g.VMID, Name: g.Name, Status: g.Status, ControllerVersion: ""}
// Normalize an empty run-status to "unknown" so the wire value is always one
// of running|stopped|unknown (matches the hub handler's empty→unknown default).
if entry.Status == "" {
entry.Status = "unknown"
}
// GuestConfig supplies cores; memory/disk come from the list entry (bytes).
// On failure, KEEP the known run-status from ListLXC — only the spec is lost.
cfg, err := c.px.GuestConfig(ctx, g.VMID)
if err != nil {
c.logger.Warn("hub: GuestConfig failed; guest degraded to unknown",
c.logger.Warn("hub: GuestConfig failed; spec omitted (run-status kept)",
"vmid", g.VMID, "err", err)
entry.Status = "unknown"
entry.Spec = nil // omitted
entry.Spec = nil
} else {
entry.Spec = &GuestSpec{
Cores: cfg.Cores,