Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(skill-burger): preserve app ID references in workflow edits

Afloat0799d8685431
diff --git a/server/skill-burger/edit-id-references.test.ts b/server/skill-burger/edit-id-references.test.ts
new file mode 100644
index 0000000000..1a35e80387
--- /dev/null
+++ b/server/skill-burger/edit-id-references.test.ts
@@ -0,0 +1,75 @@
+import { mkdtempSync, readFileSync, rmSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { afterEach, expect, it } from "vitest";
+
+import { workflowSchema, type Workflow, type WorkflowStep } from "../../shared/skill-burger/format.ts";
+import { applyEdit, editSchema, insertFix } from "./edit.ts";
+import { createExecutors } from "./executors.ts";
+import { startRun } from "./runner.ts";
+import { readWorkflowSkill, saveWorkflowSkill } from "./store.ts";
+
+const roots: string[] = [];
+afterEach(() => roots.splice(0).forEach((root) => rmSync(root, { recursive: true, force: true })));
+
+const recordId = "recFresh1234567890";
+const literalId = "recFixed1234567890";
+const table = { baseId: "appTest12345678901", tableIdOrName: "Tasks" };
+const pathSteps: WorkflowStep[] = [
+ { id: "s1", kind: "app", app: "airtable", tool: "AIRTABLE_LIST_RECORDS", label: "Find current record", args: { ...table, view: "Current" } },
+ {
+ id: "s2", kind: "app", app: "airtable", tool: "AIRTABLE_UPDATE_MULTIPLE_RECORDS", label: "Review records",
+ args: { ...table, records: [
+ { id: { $step: "s1", path: "records.0.id" }, fields: { Reviewed: true, id: "s1" } },
+ { id: literalId, fields: { Reviewed: true } },
+ ] },
+ },
+];
+
+it.each(["add_case", "keep_fix"] as const)("%s keeps references under app record IDs pointing at the added steps", async (mode) => {
+ const root = mkdtempSync(join(tmpdir(), "burger-edit-ids-"));
+ roots.push(root);
+ const original: Workflow = workflowSchema.parse({
+ version: 1, summary: "Review current records", args: {}, steps: [
+ { id: "s1", kind: "app", app: "airtable", tool: "AIRTABLE_LIST_RECORDS", label: "Read archived records", args: { ...table, view: "Archived" } },
+ ...(mode === "add_case" ? [{
+ id: "d1", kind: "decide", label: "Review records", cases: ["review"],
+ rules: [{ $step: "s1", path: "records.0.id", op: "exists", case: "review" }],
+ }] : []),
+ { id: "s2", kind: "file", label: "Write receipt", path: "receipt.txt", content: "reviewed" },
+ ],
+ });
+ const before = structuredClone(pathSteps);
+ const changed = mode === "add_case"
+ ? applyEdit(original, editSchema.parse({ action: "add_case", decide: { id: "d1" }, case: "review", steps: pathSteps }))
+ : insertFix(original, "s2", pathSteps);
+ if ("error" in changed) throw new Error(changed.error);
+ const saved = saveWorkflowSkill({ workflow: changed, name: "review-records", botIds: [], root });
+ if ("error" in saved) throw new Error(saved.error);
+ const loaded = readWorkflowSkill(saved.name, root)!;
+ const calls: Array<{ tool: string; args: Record<string, unknown> }> = [];
+ const exec = createExecutors({
+ botId: "b", cwd: root,
+ async internal(kind, path, body) {
+ expect([kind, path]).toEqual(["connectors", "/api/internal/connectors/mcp"]);
+ const frame = body as { params: { arguments: { tools: Array<{ tool_slug: string; arguments: Record<string, unknown> }> } } };
+ const sent = frame.params.arguments.tools[0]!;
+ calls.push({ tool: sent.tool_slug, args: sent.arguments });
+ const data = sent.tool_slug === "AIRTABLE_LIST_RECORDS"
+ ? { records: [{ id: sent.arguments.view === "Current" ? recordId : "recOlder1234567890" }] }
+ : { updated: true };
+ return { ok: true, body: { result: { content: [{ type: "text", text: JSON.stringify({ successful: true, data: { results: [{ tool_slug: sent.tool_slug, response: { successful: true, data } }] } }) }] } } };
+ },
+ });
+ const result = await startRun({ name: saved.name, botId: "b", threadId: "t", sha256: saved.sha256, workflow: loaded.workflow }, {
+ exec, events: { started() {}, ended() {} }, save() {},
+ });
+ expect(result).toMatchObject({ ok: true, status: "ok" });
+ expect(calls.map((call) => call.tool)).toEqual(["AIRTABLE_LIST_RECORDS", "AIRTABLE_LIST_RECORDS", "AIRTABLE_UPDATE_MULTIPLE_RECORDS"]);
+ expect(calls[2]!.args).toEqual({ ...table, records: [
+ { id: recordId, fields: { Reviewed: true, id: "s1" } },
+ { id: literalId, fields: { Reviewed: true } },
+ ] });
+ expect(readFileSync(join(root, "receipt.txt"), "utf8")).toBe("reviewed");
+ expect(pathSteps).toEqual(before);
+});
diff --git a/server/skill-burger/edit.ts b/server/skill-burger/edit.ts
index 8f5314bf4e..803c7641c7 100644
--- a/server/skill-burger/edit.ts
+++ b/server/skill-burger/edit.ts
@@ -38,7 +38,7 @@ function rewriteRefs(node: unknown, renamed: ReadonlyMap<string, string>): unkno
if (!node || typeof node !== "object") return node;
const record = node as Record<string, unknown>;
if (typeof record.$step === "string" && renamed.has(record.$step)) return { ...record, $step: renamed.get(record.$step) };
- return Object.fromEntries(Object.entries(record).map(([key, value]) => [key, key === "id" ? value : rewriteRefs(value, renamed)]));
+ return Object.fromEntries(Object.entries(record).map(([key, value]) => [key, rewriteRefs(value, renamed)]));
}
/** The workflow with `edit` made, or what is wrong with it. */
diff --git a/shared/skill-burger/draft-view.test.ts b/shared/skill-burger/draft-view.test.ts
index 8deb8e3c68..9ee5039efb 100644
--- a/shared/skill-burger/draft-view.test.ts
+++ b/shared/skill-burger/draft-view.test.ts
@@ -54,3 +54,23 @@ describe("the person's choices", () => {
expect(applyChoices(workflow, { inputs: { url: { name: "9x" } } })).toMatchObject({ error: expect.stringContaining("can't be an input's name") });
});
});
+
+describe("dependencies inside app record IDs", () => {
+ const workflow = wf([
+ { id: "s1", kind: "app", app: "airtable", tool: "AIRTABLE_LIST_RECORDS", label: "Find records", args: {} },
+ { id: "s2", kind: "app", app: "airtable", tool: "AIRTABLE_UPDATE_MULTIPLE_RECORDS", label: "Update records", args: { records: [{ id: { $step: "s1", path: "records.0.id" }, fields: { Reviewed: true } }] } },
+ { id: "s3", kind: "file", label: "Write receipt", path: "receipt.txt", content: { $step: "s2" } },
+ { id: "s4", kind: "file", label: "Keep notes", path: "notes.txt", content: "Notes" },
+ ], {});
+
+ it("connects the card's dependent steps through a reference under id", () => {
+ const view = draftView(workflow, [], []);
+ expect(view.steps[1]!.needs).toEqual(["s1"]);
+ expect(dependents(view.steps, "s1")).toEqual(["s2", "s3"]);
+ });
+
+ it("refuses an update without its lookup, and allows leaving the entire dependent chain out", () => {
+ expect(applyChoices(workflow, { skip: ["s1"] })).toEqual({ error: '"Update records" uses what "Find records" returns; leave both out or keep both.' });
+ expect(applyChoices(workflow, { skip: ["s1", "s2", "s3"] })).toMatchObject({ steps: [{ id: "s4" }] });
+ });
+});
diff --git a/shared/skill-burger/draft-view.ts b/shared/skill-burger/draft-view.ts
index f89548d1c4..40dd8583d5 100644
--- a/shared/skill-burger/draft-view.ts
+++ b/shared/skill-burger/draft-view.ts
@@ -58,7 +58,7 @@ function refsIn(node: unknown, into = new Set<string>()): Set<string> {
else if (node && typeof node === "object") {
const record = node as Record<string, unknown>;
if (typeof record.$step === "string") into.add(record.$step);
- for (const [key, value] of Object.entries(record)) if (key !== "id") refsIn(value, into);
+ for (const value of Object.values(record)) refsIn(value, into);
}
return into;
}