Skip to content

Commit 56769a5

Browse files
TMHSDigitalclaude
andcommitted
fix(tui): re-arm the event listener for unknown event kinds (#165)
listenForEvents returned nil for an event kind it did not know, and the scan view only re-arms the listener for known messages, so a new engine event kind would have stopped the TUI reading the channel and the scan would never finish. Return an ignoredEventMsg instead and re-arm on it. Adds a test over every EventKind plus an unknown one. The zero-value Kind/EventKind change is left for a pre-1.0 API pass. Fixes #165 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LpkeXSPwrzd7ZCuX3no7gD
1 parent e018e60 commit 56769a5

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

‎internal/tui/model.go‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func (m Model) updateScan(msg tea.Msg) (tea.Model, tea.Cmd) {
259259
m.out.ResultWithHint(msg.domain, msg.records, msg.takeover)
260260
}
261261
return m, tea.Batch(svCmd, listenForEvents(m.events))
262-
case progressMsg, wildcardMsg, errorMsg:
262+
case progressMsg, wildcardMsg, errorMsg, ignoredEventMsg:
263263
return m, tea.Batch(svCmd, listenForEvents(m.events))
264264
case doneMsg:
265265
// Successful completion (including user abort, which still drains and
@@ -376,6 +376,11 @@ func listenForEvents(events <-chan scan.Event) tea.Cmd {
376376
}
377377
return doneMsg{processed: ev.Processed, total: ev.Total, found: ev.Found, stats: ev.Stats}
378378
}
379-
return nil
379+
// A kind this view does not know yet must not stall the scan: the
380+
// listener is re-armed for it like any other event (#165).
381+
return ignoredEventMsg{}
380382
}
381383
}
384+
385+
// ignoredEventMsg stands for an engine event the TUI does not display.
386+
type ignoredEventMsg struct{}

‎internal/tui/model_test.go‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,35 @@ import (
1111

1212
"github.com/TMHSDigital/subenum/internal/dns"
1313
"github.com/TMHSDigital/subenum/internal/output"
14+
"github.com/TMHSDigital/subenum/internal/scan"
1415
)
1516

17+
// TestListenForEventsHandlesEveryKind covers #165: every engine event kind,
18+
// and one the TUI does not know, becomes a message, and an unknown kind
19+
// re-arms the listener instead of stalling the scan.
20+
func TestListenForEventsHandlesEveryKind(t *testing.T) {
21+
unknown := scan.EventDone + 1
22+
for k := scan.EventResult; k <= unknown; k++ {
23+
events := make(chan scan.Event, 1)
24+
events <- scan.Event{Kind: k}
25+
if msg := listenForEvents(events)(); msg == nil {
26+
t.Errorf("event kind %d produced no message", k)
27+
}
28+
}
29+
30+
events := make(chan scan.Event, 2)
31+
events <- scan.Event{Kind: unknown}
32+
events <- scan.Event{Kind: scan.EventDone}
33+
m := Model{state: stateScan, events: events, scanView: newScanViewModel(80, 24, false)}
34+
_, cmd := m.Update(listenForEvents(events)())
35+
if cmd == nil {
36+
t.Fatal("an unknown event kind did not re-arm the listener")
37+
}
38+
if len(events) != 1 {
39+
t.Fatalf("%d events left, want the EventDone still queued", len(events))
40+
}
41+
}
42+
1643
// TestFinalizeOutputGatesStructuredOutput locks in the TUI's replication of the
1744
// CLI contract: structured output is finalized only on the success path
1845
// (doneMsg -> finalizeOutput(true)). The early-error path

0 commit comments

Comments
 (0)