From e26e69441ed0bb82d68ce8853c8d5c30516804ea Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Wed, 22 Apr 2026 21:51:58 +0300 Subject: [PATCH] chore(script_deployer): basic support for backend notes --- apps/script-deployer/src/deploy.spec.ts | 37 +++++++++++++++++++++++++ apps/script-deployer/src/deploy.ts | 9 +++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/apps/script-deployer/src/deploy.spec.ts b/apps/script-deployer/src/deploy.spec.ts index 2773c2bd56..2f8e4f265a 100644 --- a/apps/script-deployer/src/deploy.spec.ts +++ b/apps/script-deployer/src/deploy.spec.ts @@ -300,4 +300,41 @@ describe("deployScript", () => { }); }); }); + + describe("backend script", () => { + const meta = { id: "hello-world", type: "backend", run: "backendStartup", title: "Hello World" }; + const content = `api.log("Hello from script-deployer!");`; + const mime = "application/javascript;env=backend"; + + it("creates a code note with #run label", () => { + deployScript(meta, content, mime, becca, notesService); + + const codeId = codeNoteId(meta.id); + const codeNote = becca.notes[codeId]; + + expect(codeNote).toBeDefined(); + expect(codeNote.type).toBe("code"); + + const runLabel = codeNote.getLabels().find((a) => a.name === "run"); + expect(runLabel).toBeDefined(); + expect(runLabel!.value).toBe("backendStartup"); + }); + + it("places the code note under scripts folder, no render note", () => { + deployScript(meta, content, mime, becca, notesService); + + const codeId = codeNoteId(meta.id); + const codeNote = becca.notes[codeId]; + expect(codeNote.getParentBranches().some((b) => b.parentNoteId === SCRIPTS_NOTE_ID)).toBe(true); + expect(becca.notes[renderNoteId(meta.id)]).toBeUndefined(); + }); + + it("does not set #run when run field is absent", () => { + const metaNoRun = { id: "no-run", type: "backend", title: "No Run" }; + deployScript(metaNoRun, content, mime, becca, notesService); + + const codeNote = becca.notes[codeNoteId(metaNoRun.id)]; + expect(codeNote.getLabels().find((a) => a.name === "run")).toBeUndefined(); + }); + }); }); diff --git a/apps/script-deployer/src/deploy.ts b/apps/script-deployer/src/deploy.ts index 94856c85cf..1797cb0045 100644 --- a/apps/script-deployer/src/deploy.ts +++ b/apps/script-deployer/src/deploy.ts @@ -133,6 +133,7 @@ export interface BeccaLike { save(): void; setContent(content: string): void; setRelation(name: string, targetNoteId: string): void; + setLabel(name: string, value?: string): void; }>; } @@ -196,7 +197,7 @@ export function deployScript( return { action: "created", codeNoteId: codeId, renderNoteId: renderId, title: meta.title, type: meta.type }; } - // Plain code note. + // Plain code note (backend script, widget, etc.) notesService.createNewNote({ noteId: codeId, parentNoteId, @@ -206,5 +207,11 @@ export function deployScript( content, }); + // Backend scripts need a #run label to be executed by the scheduler. + if (meta.type === "backend" && meta.run) { + const codeNote = becca.notes[codeId]; + codeNote.setLabel("run", meta.run); + } + return { action: "created", codeNoteId: codeId, title: meta.title, type: meta.type }; }