launch: backup configs for integrations automatically

This commit is contained in:
ParthSareen
2026-03-28 11:06:49 -07:00
parent 80d3744c5d
commit d94d683c32
4 changed files with 13 additions and 23 deletions

View File

@@ -443,18 +443,14 @@ func TestLaunchCmdHeadlessWithoutYes_ReturnsActionableConfirmError(t *testing.T)
cmd := LaunchCmd(func(cmd *cobra.Command, args []string) error { return nil }, func(cmd *cobra.Command) {})
cmd.SetArgs([]string{"stubeditor", "--model", "llama3.2"})
err := cmd.Execute()
if err == nil {
t.Fatal("expected launch command to fail without --yes in headless mode")
if err := cmd.Execute(); err != nil {
t.Fatalf("expected launch command to succeed without --yes, got %v", err)
}
if !strings.Contains(err.Error(), "re-run with --yes") {
t.Fatalf("expected actionable --yes guidance, got %v", err)
if diff := cmp.Diff([][]string{{"llama3.2"}}, stub.edited); diff != "" {
t.Fatalf("editor models mismatch (-want +got):\n%s", diff)
}
if len(stub.edited) != 0 {
t.Fatalf("expected no editor writes when confirmation is blocked, got %v", stub.edited)
}
if stub.ranModel != "" {
t.Fatalf("expected launch to abort before run, got %q", stub.ranModel)
if stub.ranModel != "llama3.2" {
t.Fatalf("expected launch to run with llama3.2, got %q", stub.ranModel)
}
}

View File

@@ -617,12 +617,9 @@ func TestLaunchIntegration_EditorForceConfigure(t *testing.T) {
return []string{"llama3.2", "qwen3:8b"}, nil
}
var proceedPrompt bool
DefaultConfirmPrompt = func(prompt string, options ConfirmOptions) (bool, error) {
if prompt == "Proceed?" {
proceedPrompt = true
}
return true, nil
t.Fatalf("unexpected confirmation prompt: %q", prompt)
return false, nil
}
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -650,9 +647,6 @@ func TestLaunchIntegration_EditorForceConfigure(t *testing.T) {
if !multiCalled {
t.Fatal("expected multi selector to be used for forced editor configure")
}
if !proceedPrompt {
t.Fatal("expected backup warning confirmation before edit")
}
if diff := compareStringSlices(editor.edited, [][]string{{"llama3.2", "qwen3:8b"}}); diff != "" {
t.Fatalf("unexpected edited models (-want +got):\n%s", diff)
}
@@ -1444,8 +1438,8 @@ func TestLaunchIntegration_ConfigureOnlyDoesNotRequireInstalledBinary(t *testing
if editor.ranModel != "" {
t.Fatalf("expected configure-only flow to skip launch, got %q", editor.ranModel)
}
if !slices.Contains(prompts, "Proceed?") {
t.Fatalf("expected editor warning prompt, got %v", prompts)
if slices.Contains(prompts, "Proceed?") {
t.Fatalf("expected editor write to skip Proceed prompt, got %v", prompts)
}
if !slices.Contains(prompts, "Launch LauncherEditor now?") {
t.Fatalf("expected configure-only launch prompt, got %v", prompts)

View File

@@ -256,7 +256,7 @@ func confirmEditorEdit(runner Runner, editor Editor) (bool, error) {
}
fmt.Fprintf(os.Stderr, "Backups will be saved to %s/\n\n", fileutil.BackupDir())
return ConfirmPrompt("Proceed?")
return true, nil
}
// buildModelList merges existing models with recommendations for selection UIs.

View File

@@ -66,8 +66,8 @@ func withLaunchConfirmPolicy(policy launchConfirmPolicy) func() {
}
}
// ConfirmPrompt is the shared confirmation gate for launch flows (integration
// edits, missing-model pulls, sign-in prompts, OpenClaw install/security, etc).
// ConfirmPrompt is the shared confirmation gate for launch flows (missing-model
// pulls, sign-in prompts, OpenClaw install/security, etc).
// Behavior is controlled by currentLaunchConfirmPolicy, typically scoped by
// withLaunchConfirmPolicy in LaunchCmd (e.g. auto-approve with --yes).
func ConfirmPrompt(prompt string) (bool, error) {