fix: harden operations and configuration recovery

This commit is contained in:
proxyctl coordinator
2026-08-30 11:13:45 +08:00
parent e34bf7d989
commit 8928986830
27 changed files with 542 additions and 125 deletions
+20 -21
View File
@@ -145,13 +145,24 @@ func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) {
m.operation.unexpectedClose()
return m, m.operation.deferredQuit()
}
completedIntent := m.operation.intent
m.snapshot = progress.update.Snapshot
m.retainTargetSelection()
m.retainProfileSelection(m.selectedProfileName, m.selected)
decoded := progress.update.Decode()
if firstFailed := m.operation.apply(progress.update); firstFailed != "" {
m.selectedTargetID = firstFailed
m.detailsOffset = 0
}
if decoded.IsTerminal() && isProfileMutation(completedIntent.Kind) {
if decoded.Kind == app.OperationSucceeded {
m.page = profilesPage
m.form = formState{}
m.status = decoded.Status.Summary
} else if decoded.Err != nil {
m.status = "Error: " + decoded.Err.Error()
}
}
if m.operation.confirmation != nil {
m.page = mainPage
if m.help.open {
@@ -399,7 +410,7 @@ func (m Model) updateProfiles(key tea.KeyMsg) (tea.Model, tea.Cmd) {
case confirmationAccepted:
name := m.profileDelete.name
m.profileDelete = nil
m.applyProfileMutation(app.Intent{Kind: app.DeleteProfile, Name: name, Confirm: true}, "")
return m, m.startOperation(app.Intent{Kind: app.DeleteProfile, Name: name, Confirm: true})
case confirmationCancelled:
m.profileDelete = nil
}
@@ -519,13 +530,8 @@ func (m Model) updateForm(key tea.KeyMsg) (tea.Model, tea.Cmd) {
}
normalized := m.form.validation.Normalized
intent := app.Intent{Kind: kind, Name: m.form.originalName, Profile: normalized}
result := m.applyProfileMutation(intent, normalized.Name)
if result.Err != nil {
return m, nil
}
m.page = profilesPage
m.form = formState{}
return m, nil
m.selectedProfileName = normalized.Name
return m, m.startOperation(intent)
case tea.KeyCtrlD:
address, token, started := m.form.startProbe()
if !started {
@@ -556,20 +562,13 @@ func (m Model) beginProfileActivation(intent app.Intent) (tea.Model, tea.Cmd) {
return m, m.startOperation(intent)
}
func (m *Model) applyProfileMutation(intent app.Intent, preferredName string) app.Result {
formerName, formerIndex := m.selectedProfileName, m.selected
result := m.application.Dispatch(intent)
m.snapshot = result.Snapshot
if preferredName == "" {
preferredName = formerName
func isProfileMutation(kind app.IntentKind) bool {
switch kind {
case app.CreateProfile, app.UpdateProfile, app.DeleteProfile:
return true
default:
return false
}
m.retainProfileSelection(preferredName, formerIndex)
if result.Err != nil {
m.status = "Error: " + result.Err.Error()
} else {
m.status = result.Notice
}
return result
}
func (m Model) selectedProfile() (profile.Profile, bool) {