Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(automations): keep existing bundle when editing a custom automation (#18649)

John-Mason P. Shackelford79abd32d856d
diff --git a/.pr/automation-edit-bundle/README.md b/.pr/automation-edit-bundle/README.md
new file mode 100644
index 0000000000..e47c4bcce7
--- /dev/null
+++ b/.pr/automation-edit-bundle/README.md
@@ -0,0 +1,4 @@
+Evidence for the edit-custom-automation fix.
+
+baseline-main-*: main at 2a0806d. fix-branch-*: this branch.
+Both: control-openhands launch, custom automation with an uploaded bundle and no setup_script_path, kebab Edit, Weekdays, Save.
diff --git a/.pr/automation-edit-bundle/baseline-main-after-save.png b/.pr/automation-edit-bundle/baseline-main-after-save.png
new file mode 100644
index 0000000000..d022bffdd1
Binary files /dev/null and b/.pr/automation-edit-bundle/baseline-main-after-save.png differ
diff --git a/.pr/automation-edit-bundle/baseline-main-before-save.png b/.pr/automation-edit-bundle/baseline-main-before-save.png
new file mode 100644
index 0000000000..bcad7462ca
Binary files /dev/null and b/.pr/automation-edit-bundle/baseline-main-before-save.png differ
diff --git a/.pr/automation-edit-bundle/baseline-main.gif b/.pr/automation-edit-bundle/baseline-main.gif
new file mode 100644
index 0000000000..485152ca26
Binary files /dev/null and b/.pr/automation-edit-bundle/baseline-main.gif differ
diff --git a/.pr/automation-edit-bundle/fix-branch-after-save.png b/.pr/automation-edit-bundle/fix-branch-after-save.png
new file mode 100644
index 0000000000..60e1011508
Binary files /dev/null and b/.pr/automation-edit-bundle/fix-branch-after-save.png differ
diff --git a/.pr/automation-edit-bundle/fix-branch-before-save.png b/.pr/automation-edit-bundle/fix-branch-before-save.png
new file mode 100644
index 0000000000..7ab46d50b9
Binary files /dev/null and b/.pr/automation-edit-bundle/fix-branch-before-save.png differ
diff --git a/.pr/automation-edit-bundle/fix-branch.gif b/.pr/automation-edit-bundle/fix-branch.gif
new file mode 100644
index 0000000000..01bb283967
Binary files /dev/null and b/.pr/automation-edit-bundle/fix-branch.gif differ
diff --git a/__tests__/api/automation-form-session.test.ts b/__tests__/api/automation-form-session.test.ts
new file mode 100644
index 0000000000..6a273534a2
--- /dev/null
+++ b/__tests__/api/automation-form-session.test.ts
@@ -0,0 +1,49 @@
+import { beforeEach, describe, expect, it } from "vitest";
+
+import {
+ getAutomationFormSession,
+ initializeAutomationFormSession,
+ patchAutomationFormSession,
+} from "#/api/automation-form-session";
+
+const BUNDLE_PATH =
+ "oh-internal://uploads/97b19046-c2fb-4846-af9b-f596218b100e";
+
+describe("automation form session", () => {
+ beforeEach(() => {
+ window.sessionStorage.clear();
+ });
+
+ it("keeps the existing custom bundle path when the draft is initialized", () => {
+ initializeAutomationFormSession("conv-1", {
+ prompt: "",
+ kind: "custom",
+ editingAutomationId: "automation-1",
+ existingCustomTarballPath: BUNDLE_PATH,
+ });
+
+ expect(getAutomationFormSession("conv-1")?.existingCustomTarballPath).toBe(
+ BUNDLE_PATH,
+ );
+ });
+
+ it("keeps the existing custom bundle path after a field is edited", () => {
+ initializeAutomationFormSession("conv-1", {
+ prompt: "",
+ kind: "custom",
+ editingAutomationId: "automation-1",
+ existingCustomTarballPath: BUNDLE_PATH,
+ form: { kind: "custom", entrypoint: "python3 main.py" },
+ });
+
+ patchAutomationFormSession(
+ "conv-1",
+ { customSchedule: "0 7 * * 1-5" },
+ { source: "user" },
+ );
+
+ expect(getAutomationFormSession("conv-1")?.existingCustomTarballPath).toBe(
+ BUNDLE_PATH,
+ );
+ });
+});
diff --git a/src/api/automation-form-session.ts b/src/api/automation-form-session.ts
index 82325a4bc6..3f992c79d2 100644
--- a/src/api/automation-form-session.ts
+++ b/src/api/automation-form-session.ts
@@ -169,6 +169,10 @@ function normalizeDraft(value: AutomationSetupDraft): AutomationSetupDraft {
typeof value.editingAutomationId === "string"
? value.editingAutomationId.trim()
: "";
+ const existingCustomTarballPath =
+ typeof value.existingCustomTarballPath === "string"
+ ? value.existingCustomTarballPath.trim()
+ : "";
const serverDraftId =
typeof value.serverDraftId === "string" ? value.serverDraftId.trim() : "";
const materializedAutomationId =
@@ -189,6 +193,7 @@ function normalizeDraft(value: AutomationSetupDraft): AutomationSetupDraft {
...(normalizedPlugins.length > 0 ? { plugins: normalizedPlugins } : {}),
form: normalizedForm,
...(editingAutomationId ? { editingAutomationId } : {}),
+ ...(existingCustomTarballPath ? { existingCustomTarballPath } : {}),
...(serverDraftId ? { serverDraftId } : {}),
...(materializedAutomationId ? { materializedAutomationId } : {}),
...(fieldMetadata ? { fieldMetadata } : {}),