A desktop coding agent with free access to frontier models.
TypeScript
import { describe, expect, test } from "bun:test";
import {
sanitizeCommandName,
validateCommandName,
validateMcpName,
validateSkillName,
validateMcpConfig,
validateUserMcpName,
} from "./validators.js";
describe("sanitizeCommandName", () => {
test("passes through valid names", () => {
expect(sanitizeCommandName("my-command")).toBe("my-command");
expect(sanitizeCommandName("deploy")).toBe("deploy");
});
test("trims whitespace", () => {
expect(sanitizeCommandName(" hello ")).toBe("hello");
});
test("strips leading slashes", () => {
expect(sanitizeCommandName("/deploy")).toBe("deploy");
expect(sanitizeCommandName("///deploy")).toBe("deploy");
});
});
describe("validateCommandName", () => {
test("accepts valid alphanumeric names", () => {
expect(() => validateCommandName("deploy")).not.toThrow();
expect(() => validateCommandName("my-cmd")).not.toThrow();
expect(() => validateCommandName("a_b_c")).not.toThrow();
expect(() => validateCommandName("Cmd123")).not.toThrow();
});
test("rejects empty string", () => {
expect(() => validateCommandName("")).toThrow();
});
test("rejects names with slashes", () => {
expect(() => validateCommandName("foo/bar")).toThrow();
expect(() => validateCommandName("foo\\bar")).toThrow();
});
test("rejects names with dots", () => {
expect(() => validateCommandName("foo.bar")).toThrow();
});
test("rejects names with spaces", () => {
expect(() => validateCommandName("foo bar")).toThrow();
});
});
describe("validateMcpName", () => {
test("accepts valid names", () => {
expect(() => validateMcpName("my-server")).not.toThrow();
expect(() => validateMcpName("notion")).not.toThrow();
expect(() => validateMcpName("a_b")).not.toThrow();
});
test("rejects empty strings", () => {
expect(() => validateMcpName("")).toThrow();
});
test("rejects names starting with dash", () => {
expect(() => validateMcpName("-bad")).toThrow();
});
test("rejects names with special characters", () => {
expect(() => validateMcpName("foo.bar")).toThrow();
expect(() => validateMcpName("foo bar")).toThrow();
expect(() => validateMcpName("foo/bar")).toThrow();
});
});
describe("validateUserMcpName", () => {
test("reserves the OmniRush.ai Connect runtime name", () => {
expect(() => validateUserMcpName("omnirush-cloud")).toThrow("reserved for OmniRush.ai Connect");
expect(() => validateUserMcpName("OMNIRUSH-CLOUD")).toThrow("reserved for OmniRush.ai Connect");
expect(() => validateUserMcpName("omnirush-connect-1234")).toThrow("reserved for OmniRush.ai Connect");
expect(() => validateUserMcpName("omnirush-direct-linear-1234")).toThrow("reserved for OmniRush.ai Connect");
});
test("allows ordinary workspace MCP names", () => {
expect(() => validateUserMcpName("bigquery")).not.toThrow();
});
});
describe("validateSkillName", () => {
test("accepts kebab-case names", () => {
expect(() => validateSkillName("my-skill")).not.toThrow();
expect(() => validateSkillName("skill123")).not.toThrow();
expect(() => validateSkillName("a")).not.toThrow();
});
test("rejects empty strings", () => {
expect(() => validateSkillName("")).toThrow();
});
test("rejects uppercase", () => {
expect(() => validateSkillName("MySkill")).toThrow();
});
test("rejects underscores", () => {
expect(() => validateSkillName("my_skill")).toThrow();
});
test("rejects names over 64 chars", () => {
expect(() => validateSkillName("a".repeat(65))).toThrow();
});
});
describe("validateMcpConfig", () => {
test("accepts valid remote config", () => {
expect(() =>
validateMcpConfig({ type: "remote", url: "https://example.com" }),
).not.toThrow();
expect(() =>
validateMcpConfig({ type: "remote", url: "http://localhost:8080/mcp" }),
).not.toThrow();
});
test("accepts valid local config", () => {
expect(() =>
validateMcpConfig({ type: "local", command: ["npx", "my-server"] }),
).not.toThrow();
});
test("rejects unknown type", () => {
expect(() => validateMcpConfig({ type: "unknown" })).toThrow();
});
test("rejects remote without url", () => {
expect(() => validateMcpConfig({ type: "remote" })).toThrow();
expect(() => validateMcpConfig({ type: "remote", url: "" })).toThrow();
expect(() => validateMcpConfig({ type: "remote", url: " " })).toThrow();
});
test("rejects remote with invalid or non-http url", () => {
expect(() => validateMcpConfig({ type: "remote", url: "notaurl" })).toThrow();
expect(() => validateMcpConfig({ type: "remote", url: "https:example.com" })).toThrow();
expect(() => validateMcpConfig({ type: "remote", url: " https://example.com" })).toThrow();
expect(() => validateMcpConfig({ type: "remote", url: "https://example.com " })).toThrow();
expect(() => validateMcpConfig({ type: "remote", url: "file:///tmp/mcp" })).toThrow();
expect(() => validateMcpConfig({ type: "remote", url: "javascript:alert(1)" })).toThrow();
});
test("rejects a registry launch of omnirush-ui-mcp with 400 unsafe_mcp_command", () => {
for (const command of [
["npx", "-y", "omnirush-ui-mcp"],
["bunx", "omnirush-ui-mcp@latest"],
["pnpm", "dlx", "omnirush-ui-mcp"],
["sh", "-c", "npx -y omnirush-ui-mcp"],
]) {
let error: unknown;
try {
validateMcpConfig({ type: "local", command, enabled: true });
} catch (caught) {
error = caught;
}
expect(error).toMatchObject({ status: 400, code: "unsafe_mcp_command" });
}
// The command is checked whatever the declared type.
expect(() => validateMcpConfig({ type: "remote", url: "https://example.com", command: ["npx", "-y", "omnirush-ui-mcp"] }))
.toThrow("not published on npm");
// The bundled launch runs the file by path and stays valid.
expect(() => validateMcpConfig({
type: "local",
command: [
"/Applications/OmniRush.ai.app/Contents/MacOS/OmniRush.ai",
"/Applications/OmniRush.ai.app/Contents/Resources/omnirush-ui-mcp/index.mjs",
],
environment: { ELECTRON_RUN_AS_NODE: "1" },
})).not.toThrow();
});
test("rejects local without command", () => {
expect(() => validateMcpConfig({ type: "local" })).toThrow();
expect(() => validateMcpConfig({ type: "local", command: [] })).toThrow();
expect(() => validateMcpConfig({ type: "local", command: ["", "foo"] })).toThrow();
expect(() => validateMcpConfig({ type: "local", command: ["npx", 12] })).toThrow();
});
});