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:
@@ -58,7 +58,7 @@ func TestCollect_HostAndGuests(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCollect_GuestConfigFailureDegradesButStillReports(t *testing.T) {
|
||||
func TestCollect_GuestConfigFailureKeepsStatusOmitsSpec(t *testing.T) {
|
||||
px := &fakePx{
|
||||
node: "demo-felhom",
|
||||
ns: newTestNodeStatus(),
|
||||
@@ -69,7 +69,7 @@ func TestCollect_GuestConfigFailureDegradesButStillReports(t *testing.T) {
|
||||
cfg: map[int]proxmox.GuestConfig{100: {Cores: 2}},
|
||||
cfgErr: map[int]error{200: errors.New("config read failed")},
|
||||
}
|
||||
c := NewCollector(px, fakeProber{status: "active"}, "h", "0.3.0", quietLogger())
|
||||
c := NewCollector(px, fakeProber{status: "active"}, "h", "0.3.1", quietLogger())
|
||||
r, err := c.Collect(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("a per-guest failure must NOT fail the whole report: %v", err)
|
||||
@@ -77,9 +77,14 @@ func TestCollect_GuestConfigFailureDegradesButStillReports(t *testing.T) {
|
||||
if len(r.Guests) != 2 {
|
||||
t.Fatalf("guests = %d", len(r.Guests))
|
||||
}
|
||||
// GuestConfig failed for vmid 200, but its run-status (from ListLXC) is known and
|
||||
// must be PRESERVED — only the spec is dropped.
|
||||
bad := r.Guests[1]
|
||||
if bad.Status != "unknown" || bad.Spec != nil {
|
||||
t.Errorf("degraded guest = %+v (want status=unknown, spec=nil)", bad)
|
||||
if bad.Status != "running" {
|
||||
t.Errorf("status = %q, want preserved \"running\" (not forced to unknown)", bad.Status)
|
||||
}
|
||||
if bad.Spec != nil {
|
||||
t.Errorf("spec = %+v, want nil (omitted on config failure)", bad.Spec)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user