fix: finalize TUI operation coordination
hermetic-ci / test (push) Canceled after 0s

This commit is contained in:
proxyctl coordinator
2026-07-18 02:56:33 +08:00
parent 652d7eba2b
commit e6fd3ffe73
8 changed files with 153 additions and 67 deletions
+10 -23
View File
@@ -58,9 +58,7 @@ func TestTargetPanelShowsOnlyAvailableTargetsAndAppliesAsynchronously(t *testing
if command == nil || !strings.Contains(model.View(), "Applying") || len(module.intents) != 1 {
t.Fatalf("operation did not expose applying state before effect:\n%s", model.View())
}
message := command()
updated, _ = model.Update(message)
model = updated.(Model)
model, _ = applyOperationCommand(t, model, command)
if len(module.intents) != 1 || module.intents[0].Kind != app.ApplyProfileToTarget || !strings.Contains(model.View(), "Enabled") {
t.Fatalf("completed toggle = %#v\n%s", module.intents, model.View())
}
@@ -72,8 +70,7 @@ func TestTargetRestartConfirmationCancelsWithoutConfirmedMutation(t *testing.T)
model := NewModel(module)
updated, command := model.Update(tea.KeyMsg{Type: tea.KeySpace})
model = updated.(Model)
updated, _ = model.Update(command())
model = updated.(Model)
model, _ = applyOperationCommand(t, model, command)
if !strings.Contains(model.View(), "restart immediately") || len(module.intents) != 1 || module.intents[0].Confirm {
t.Fatalf("warning = intents %#v\n%s", module.intents, model.View())
}
@@ -85,8 +82,7 @@ func TestTargetRestartConfirmationCancelsWithoutConfirmedMutation(t *testing.T)
updated, command = model.Update(tea.KeyMsg{Type: tea.KeySpace})
model = updated.(Model)
updated, _ = model.Update(command())
model = updated.(Model)
model, _ = applyOperationCommand(t, model, command)
module.result = app.Result{
Snapshot: app.Snapshot{ActiveProfile: "office", Targets: []app.TargetSnapshot{{ID: "docker-daemon", Description: target.Description{Name: "Docker daemon"}, Available: true, State: target.Enabled, PrimaryAction: app.TargetAction{Kind: app.DisableTargetAction, Available: true}}}},
Notice: "Docker daemon Target is now Enabled",
@@ -96,7 +92,6 @@ func TestTargetRestartConfirmationCancelsWithoutConfirmedMutation(t *testing.T)
if command == nil {
t.Fatal("confirmation did not start operation")
}
_ = command()
if len(module.intents) != 3 || !module.intents[2].Confirm {
t.Fatalf("confirmed intents = %#v", module.intents)
}
@@ -141,12 +136,10 @@ func TestRefreshKeyRunsAsynchronouslyAndRendersRefreshingThenCompleted(t *testin
if command == nil || len(module.intents) != 1 || !strings.Contains(model.View(), "Checking Target availability and state") {
t.Fatalf("refresh did not start asynchronously: intents %#v\n%s", module.intents, model.View())
}
message := command()
if len(module.intents) != 1 || module.intents[0].Kind != app.RefreshTargets {
t.Fatalf("refresh command intents = %#v", module.intents)
}
updated, command = model.Update(message)
model = updated.(Model)
model, command = applyOperationCommand(t, model, command)
if command != nil || !strings.Contains(model.View(), "External") || !strings.Contains(model.View(), "Refreshed Target availability and state") {
t.Fatalf("refresh completion:\n%s", model.View())
}
@@ -228,8 +221,7 @@ func TestRefreshClampsSelectionAfterMultipleTargetsDisappear(t *testing.T) {
model.selectedTargetID = "four"
updated, command := model.Update(keyMessage("r"))
model = updated.(Model)
updated, _ = model.Update(command())
model = updated.(Model)
model, _ = applyOperationCommand(t, model, command)
if model.selectedTargetID != "one" || !strings.Contains(model.View(), "> ? Unknown One") {
t.Fatalf("selection after multi-Target reduction = %q\n%s", model.selectedTargetID, model.View())
}
@@ -237,8 +229,7 @@ func TestRefreshClampsSelectionAfterMultipleTargetsDisappear(t *testing.T) {
module.result = app.Result{Snapshot: app.Snapshot{}}
updated, command = model.Update(keyMessage("r"))
model = updated.(Model)
updated, _ = model.Update(command())
model = updated.(Model)
model, _ = applyOperationCommand(t, model, command)
if model.selectedTargetID != "" {
t.Fatalf("selection with no Available Targets = %q, want empty", model.selectedTargetID)
}
@@ -323,18 +314,15 @@ func TestActiveProfileTransitionRendersPerTargetProgress(t *testing.T) {
if command == nil {
t.Fatal("Profile transition did not start progressive operation")
}
updated, command := model.Update(command())
model = updated.(Model)
model, command = applyOperationCommand(t, model, command)
if command == nil || !strings.Contains(model.View(), "Applying") || !strings.Contains(model.View(), "Active Profile: new") {
t.Fatalf("applying progress:\n%s", model.View())
}
updated, command = model.Update(command())
model = updated.(Model)
model, command = applyOperationCommand(t, model, command)
if command == nil || !strings.Contains(model.View(), "Enabled") || !strings.Contains(model.View(), "update completed") {
t.Fatalf("Target completion:\n%s", model.View())
}
updated, _ = model.Update(command())
model = updated.(Model)
model, _ = applyOperationCommand(t, model, command)
if !strings.Contains(model.View(), "Activated Profile new") {
t.Fatalf("final transition:\n%s", model.View())
}
@@ -379,8 +367,7 @@ func TestTargetFailurePreservesTruthfulStateAndRendersRedactedError(t *testing.T
model := NewModel(module)
updated, command := model.Update(tea.KeyMsg{Type: tea.KeySpace})
model = updated.(Model)
updated, _ = model.Update(command())
model = updated.(Model)
model, _ = applyOperationCommand(t, model, command)
model = updateKey(model, "e")
view := model.View()
if !strings.Contains(view, "Enabled") || !strings.Contains(view, "Current error:") || !strings.Contains(view, "REDACTED") {