From afe025b886ffbc45dab086d4b167030263fd39b5 Mon Sep 17 00:00:00 2001 From: Diego Imbert Date: Fri, 3 Jul 2026 18:00:54 +0200 Subject: [PATCH] fix: run DDL migration guard on the script editor Test button Co-Authored-By: Claude Opus 4.8 (1M context) --- frontend/src/lib/components/Editor.svelte | 13 +++++++++++-- frontend/src/lib/components/ScriptEditor.svelte | 15 +++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/frontend/src/lib/components/Editor.svelte b/frontend/src/lib/components/Editor.svelte index d56e834422..2054dc8cf1 100644 --- a/frontend/src/lib/components/Editor.svelte +++ b/frontend/src/lib/components/Editor.svelte @@ -223,12 +223,21 @@ ) let ddlGuard = $state(undefined) - async function runCmdEnterWithDdlGuard() { + // Run the DDL migration guard against the current code. Returns false when the + // user cancels (the run must be aborted); may rewrite the code (migrated + // statements stripped). Exported so run paths that bypass the Monaco + // Cmd+Enter binding (e.g. the Test button) can guard too. + export async function guardDdlBeforeRun(): Promise { if (datatableForMigrations && ddlGuard) { const res = await ddlGuard.guard(getCode()) - if (!res.proceed) return + if (!res.proceed) return false if (res.code !== getCode()) setCode(res.code) } + return true + } + + async function runCmdEnterWithDdlGuard() { + if (!(await guardDdlBeforeRun())) return cmdEnterAction?.() } diff --git a/frontend/src/lib/components/ScriptEditor.svelte b/frontend/src/lib/components/ScriptEditor.svelte index f1944c73cc..575c303b06 100644 --- a/frontend/src/lib/components/ScriptEditor.svelte +++ b/frontend/src/lib/components/ScriptEditor.svelte @@ -743,7 +743,17 @@ args = nargs } - export async function runTest(opts?: { cascade?: boolean }) { + export async function runTest(opts?: { cascade?: boolean; skipDdlGuard?: boolean }) { + // Intercept DDL statements (offer to turn them into data table migrations) + // on every run path, not just the editor's Cmd+Enter. `skipDdlGuard` is set + // by the Cmd+Enter action, which already guarded before calling us. + if (!opts?.skipDdlGuard) { + if ((await editor?.guardDdlBeforeRun()) === false) return + // The guard may have rewritten the code (migrated statements stripped); + // `editorCode` is kept in sync by the editor binding, so mirror the + // on:change handler and pull it into `code` before we run. + if (activeModuleTab === null) code = editorCode + } // When the caller forces a cascade choice (e.g. the canvas runnable // menu's "Run + trigger N downstream"), also flip the persistent // `cascadeDownstream` state so the split button's label/icon reflect @@ -2626,7 +2636,8 @@ } else { await inferModuleSchema() } - runTest() + // The Editor already ran the DDL guard before invoking this action. + runTest({ skipDdlGuard: true }) }} formatAction={async () => { if (activeModuleTab === null) {