fix: reconcile stale detection streams

This commit is contained in:
proxyctl coordinator
2026-07-17 21:30:46 +08:00
parent fdc59b1400
commit c4214ab8b2
2 changed files with 28 additions and 1 deletions
@@ -99,6 +99,28 @@ func TestCompleteModelStreamsStartupAndRefreshByTargetWithoutMovingSelection(t *
}
}
func TestCompleteModelReconcilesAuthoritativeSnapshotWhenDetectionGenerationClosesStale(t *testing.T) {
startup := make(chan app.TargetDetectionUpdate)
module := &progressiveDetectionModule{
snapshot: app.Snapshot{Targets: []app.TargetSnapshot{{
ID: "shell", Description: target.Description{Name: "Shell", Summary: "Shell description"},
}}},
streams: []chan app.TargetDetectionUpdate{startup},
}
model := resizedModel(t, module, themeModeNoColor, 80, 24)
assertUsableFrame(t, model.View(), 80, 24, "> … Checking Shell")
// A newer Application generation has already established the authoritative
// result, so the stale stream closes without publishing a completion update.
_ = module.detectionUpdate("shell", app.TargetReady, true, target.Enabled, "shell enabled", nil)
close(startup)
model, next := applyDetectionCommand(t, model, model.Init())
if next != nil || model.refreshing {
t.Fatalf("stale closure left detection active: next=%v refreshing=%v", next != nil, model.refreshing)
}
assertUsableFrame(t, model.View(), 80, 24, "> ● Enabled Shell", "Evidence: shell enabled")
}
func (m *progressiveDetectionModule) detectionUpdate(id string, phase app.TargetDetectionPhase, available bool, state target.State, evidence string, err error) app.TargetDetectionUpdate {
for i := range m.snapshot.Targets {
if m.snapshot.Targets[i].ID != id {