feat: add contextual Target actions

This commit is contained in:
proxyctl coordinator
2026-07-17 23:14:57 +08:00
parent 2ca42bd4bd
commit 2ac088b388
16 changed files with 428 additions and 194 deletions
+35
View File
@@ -83,6 +83,24 @@ func TestCompleteModelOffersBothExplicitDriftResolutionIntents(t *testing.T) {
}
}
func TestCompleteModelRendersUnknownTargetStateAsStructurallyUnavailable(t *testing.T) {
const reason = "Target actions are unavailable because this Target state is unknown"
initial := completeTargetSnapshot("", app.TargetAction{DisabledReason: reason})
initial.Targets[0].PrimaryAction.Available = false
module := &targetModule{snapshot: initial}
model := resizedModel(t, module, themeModeNoColor, 120, 36)
view := model.View()
if !strings.Contains(view, "Action: Unavailable") || !strings.Contains(view, "Action unavailable:") || !strings.Contains(view, "state is unknown") || !strings.Contains(view, "Space: Unavailable disabled") {
t.Fatalf("unknown Target action was not structurally unavailable:\n%s", view)
}
updated, command := model.Update(tea.KeyMsg{Type: tea.KeySpace})
model = updated.(Model)
if command != nil || len(module.intents) != 0 || model.operation.status.Summary != reason {
t.Fatalf("unknown Target action dispatched: intents=%#v status=%q\n%s", module.intents, model.operation.status.Summary, model.View())
}
}
func TestCompleteModelUsesStructuredDisabledReasonWithoutInferringFromState(t *testing.T) {
initial := completeTargetSnapshot(target.Disabled, app.TargetAction{
Kind: app.EnableTargetAction, DisabledReason: "No Active Profile is selected; create or select one before enabling",
@@ -100,6 +118,23 @@ func TestCompleteModelUsesStructuredDisabledReasonWithoutInferringFromState(t *t
}
}
func TestCompleteModelPressingUnavailableTargetActionShowsExactReasonAndDispatchesNoIntent(t *testing.T) {
const reason = "GNOME settings schema is unavailable for the owning user"
initial := completeTargetSnapshot(target.External, app.TargetAction{
Kind: app.ApplyProfileTargetAction, Available: false, DisabledReason: reason,
})
initial.Targets[0].Available = false
module := &targetModule{snapshot: initial}
model := resizedModel(t, module, themeModeNoColor, 120, 36)
model = updateKey(model, "u")
updated, command := model.Update(tea.KeyMsg{Type: tea.KeySpace})
model = updated.(Model)
if command != nil || len(module.intents) != 0 || model.operation.status.Summary != reason {
t.Fatalf("unavailable action: command=%v intents=%#v status=%q", command != nil, module.intents, model.operation.status.Summary)
}
}
func TestCompleteModelRestoreOwnershipLossFailsTruthfully(t *testing.T) {
initial := completeTargetSnapshot(target.Drifted, app.TargetAction{Kind: app.ResolveDriftTargetAction, Available: true})
initial.Targets[0].DriftResolutionActions = []app.TargetAction{