diff --git a/apps/web/src/lib/projectScriptKeybindings.test.ts b/apps/web/src/lib/projectScriptKeybindings.test.ts index 69e4d77afe08..ea4e8fa6073b 100644 --- a/apps/web/src/lib/projectScriptKeybindings.test.ts +++ b/apps/web/src/lib/projectScriptKeybindings.test.ts @@ -43,7 +43,7 @@ describe("projectScriptKeybindings", () => { expect(() => decodeProjectScriptKeybindingRule({ keybinding: "mod+k", - command: "script.BAD.run" as KeybindingCommand, + command: "script..run" as KeybindingCommand, }), ).toThrowError(PROJECT_SCRIPT_KEYBINDING_INVALID_MESSAGE); }); diff --git a/apps/web/src/projectScripts.test.ts b/apps/web/src/projectScripts.test.ts index 54de739daa5f..f2ceeb0d7770 100644 --- a/apps/web/src/projectScripts.test.ts +++ b/apps/web/src/projectScripts.test.ts @@ -61,6 +61,13 @@ describe("projectScripts helpers", () => { const command = commandForProjectScript("lint"); expect(command).toBe("script.lint.run"); expect(projectScriptIdFromCommand(command)).toBe("lint"); + + const externalId = "123e4567-e89b-42d3-a456-426614174000"; + const externalCommand = commandForProjectScript(externalId); + expect(externalCommand).toBe(`script.${externalId}.run`); + expect(projectScriptIdFromCommand(externalCommand)).toBe(externalId); + + expect(projectScriptIdFromCommand("script. lint .run")).toBeNull(); expect(projectScriptIdFromCommand("terminal.toggle")).toBeNull(); }); diff --git a/packages/contracts/src/keybindings.test.ts b/packages/contracts/src/keybindings.test.ts index e04f311dc0b6..7c214167580b 100644 --- a/packages/contracts/src/keybindings.test.ts +++ b/packages/contracts/src/keybindings.test.ts @@ -118,13 +118,15 @@ it.effect("parses keybinding rules", () => it.effect("rejects invalid command values", () => Effect.gen(function* () { - const result = yield* Effect.exit( - decode(KeybindingRule, { - key: "mod+j", - command: "script.Test.run", - }), - ); - assert.strictEqual(result._tag, "Failure"); + for (const command of ["script..run", "script. setup .run"]) { + const result = yield* Effect.exit( + decode(KeybindingRule, { + key: "mod+j", + command, + }), + ); + assert.strictEqual(result._tag, "Failure"); + } }), ); @@ -135,6 +137,12 @@ it.effect("accepts dynamic script run commands", () => command: "script.setup.run", }); assert.strictEqual(parsed.command, "script.setup.run"); + + const parsedExternalId = yield* decode(KeybindingRule, { + key: "mod+r", + command: "script.123e4567-e89b-42d3-a456-426614174000.run", + }); + assert.strictEqual(parsedExternalId.command, "script.123e4567-e89b-42d3-a456-426614174000.run"); }), ); diff --git a/packages/contracts/src/keybindings.ts b/packages/contracts/src/keybindings.ts index 62aa69db9df6..d26756ac0c89 100644 --- a/packages/contracts/src/keybindings.ts +++ b/packages/contracts/src/keybindings.ts @@ -78,10 +78,7 @@ export const STATIC_KEYBINDING_COMMANDS = [ export const SCRIPT_RUN_COMMAND_PATTERN = Schema.TemplateLiteral([ Schema.Literal("script."), - Schema.NonEmptyString.check( - Schema.isMaxLength(MAX_SCRIPT_ID_LENGTH), - Schema.isPattern(/^[a-z0-9][a-z0-9-]*$/), - ), + Schema.String.check(Schema.isTrimmed(), Schema.isNonEmpty()), Schema.Literal(".run"), ]);