From 193a6c65da8be7808722feff8dcc6f4cb4563939 Mon Sep 17 00:00:00 2001 From: nook24 Date: Fri, 20 Nov 2026 15:13:10 +0000 Subject: [PATCH] Test state change long output end to end The worker already carried long_output from the statechanges payload to the statehistory tables, but the fixture mirrored output and no test asserted the field. Give the fixture a distinct multi-line long output and check both the decode and the row columns, so a dropped or overwritten long_output fails. --- .claude/specs/statusngin_statechanges.json | 4 ++-- docs/openapi.yaml | 8 ++++++-- internal/queue/decode_test.go | 6 ++++++ internal/queue/statechange_test.go | 13 +++++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/.claude/specs/statusngin_statechanges.json b/.claude/specs/statusngin_statechanges.json index 7c2a36b..5a5d42d 100644 --- a/.claude/specs/statusngin_statechanges.json +++ b/.claude/specs/statusngin_statechanges.json @@ -10,7 +10,7 @@ "host_name": "localhost", "service_description": "Flapping", "output": "Your random value is: 158", - "long_output": "Your random value is: 158", + "long_output": "Your random value is: 158\nThis line only appears in the long output.", "statechange_type": 1, "state": 0, "state_type": 1, @@ -30,7 +30,7 @@ "host_name": "demo.statusengine.org", "service_description": "Flapping", "output": "Your random value is: 87", - "long_output": "Your random value is: 87", + "long_output": "Your random value is: 87\nThis line only appears in the long output.", "statechange_type": 1, "state": 0, "state_type": 0, diff --git a/docs/openapi.yaml b/docs/openapi.yaml index 462ee1c..ee70e0f 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -662,7 +662,11 @@ components: type: string description: Empty for a host state change (see statechange_type). output: { type: string } - long_output: { type: string } + long_output: + type: string + description: > + The object's long plugin output, not a copy of `output`. Empty + when the object has none, matching the host/service check queues. statechange_type: type: integer description: "0 = host state change, 1 = service state change." @@ -679,7 +683,7 @@ components: host_name: localhost last_hard_state: 1 last_state: 1 - long_output: "Your random value is: 158" + long_output: "Your random value is: 158\nThis line only appears in the long output." max_attempts: 4 output: "Your random value is: 158" service_description: Flapping diff --git a/internal/queue/decode_test.go b/internal/queue/decode_test.go index 22f68cb..b92cd2e 100644 --- a/internal/queue/decode_test.go +++ b/internal/queue/decode_test.go @@ -74,6 +74,12 @@ func TestDecodeBulkQueues(t *testing.T) { if len(events) != 2 || events[0].Timestamp != 1785470683 || events[0].ServiceDescription != "Flapping" { t.Fatalf("unexpected events: %+v", events) } + // The broker sends the real long output for state changes, not a copy + // of output. The fixture's value is deliberately different from its + // output, so a decoder that dropped the field would fail here. + if want := "Your random value is: 158\nThis line only appears in the long output."; events[0].LongOutput != want { + t.Fatalf("events[0].LongOutput = %q, want %q", events[0].LongOutput, want) + } }) t.Run("LogEntry", func(t *testing.T) { diff --git a/internal/queue/statechange_test.go b/internal/queue/statechange_test.go index a14b33d..7aba89b 100644 --- a/internal/queue/statechange_test.go +++ b/internal/queue/statechange_test.go @@ -79,6 +79,13 @@ func TestHostStateHistoryRowAndServiceStateHistoryRowColumns(t *testing.T) { } ev := items[0] + // The fixture's long_output differs from output on purpose: the broker + // sends the real long output now, and the row assertions below have to + // catch a dropped field rather than a value that merely mirrors output. + if ev.LongOutput == "" || ev.LongOutput == ev.Output { + t.Fatalf("fixture long_output = %q, want a distinct non-empty long output", ev.LongOutput) + } + hostRow := hostStateHistoryRow(ev, nil) if len(hostRow) != 12 { t.Fatalf("hostStateHistoryRow has %d values, want 12", len(hostRow)) @@ -87,6 +94,9 @@ func TestHostStateHistoryRowAndServiceStateHistoryRowColumns(t *testing.T) { t.Fatalf("hostStateHistoryRow[0:4] = %v, want [%v %v %v %v]", hostRow[0:4], ev.HostName, ev.Timestamp, ev.TimestampUsec, ev.StateChangeType) } + if hostRow[11] != ev.LongOutput { + t.Fatalf("hostStateHistoryRow[11] = %v, want LongOutput %q", hostRow[11], ev.LongOutput) + } serviceRow := serviceStateHistoryRow(ev, nil) if len(serviceRow) != 13 { @@ -98,4 +108,7 @@ func TestHostStateHistoryRowAndServiceStateHistoryRowColumns(t *testing.T) { if serviceRow[3] != ev.HostName || serviceRow[4] != ev.StateChangeType { t.Fatalf("serviceStateHistoryRow[3:5] = %v, want [%v %v]", serviceRow[3:5], ev.HostName, ev.StateChangeType) } + if serviceRow[12] != ev.LongOutput { + t.Fatalf("serviceStateHistoryRow[12] = %v, want LongOutput %q", serviceRow[12], ev.LongOutput) + } }