Formatting fixes and remove trailing dash acceptance

This commit is contained in:
Devin Robison 2026-03-23 16:56:54 -06:00 committed by Peter Steinberger
parent 40071ea23e
commit a339d706c1
2 changed files with 36 additions and 7 deletions

View File

@ -101,7 +101,10 @@ describe("skills-clawhub", () => {
workspaceDir: "/tmp/workspace",
slug: "re\u0430ct",
});
expect(result).toMatchObject({ ok: false, error: expect.stringContaining("Invalid skill slug") });
expect(result).toMatchObject({
ok: false,
error: expect.stringContaining("Invalid skill slug"),
});
});
it("rejects Cyrillic homograph 'е' (U+0435) in slug", async () => {
@ -109,7 +112,10 @@ describe("skills-clawhub", () => {
workspaceDir: "/tmp/workspace",
slug: "r\u0435act",
});
expect(result).toMatchObject({ ok: false, error: expect.stringContaining("Invalid skill slug") });
expect(result).toMatchObject({
ok: false,
error: expect.stringContaining("Invalid skill slug"),
});
});
it("rejects Cyrillic homograph 'о' (U+043E) in slug", async () => {
@ -117,7 +123,10 @@ describe("skills-clawhub", () => {
workspaceDir: "/tmp/workspace",
slug: "t\u043Edo",
});
expect(result).toMatchObject({ ok: false, error: expect.stringContaining("Invalid skill slug") });
expect(result).toMatchObject({
ok: false,
error: expect.stringContaining("Invalid skill slug"),
});
});
it("rejects slug with mixed Unicode and ASCII", async () => {
@ -125,7 +134,10 @@ describe("skills-clawhub", () => {
workspaceDir: "/tmp/workspace",
slug: "cаlеndаr",
});
expect(result).toMatchObject({ ok: false, error: expect.stringContaining("Invalid skill slug") });
expect(result).toMatchObject({
ok: false,
error: expect.stringContaining("Invalid skill slug"),
});
});
it("rejects slug with non-Latin scripts", async () => {
@ -133,7 +145,10 @@ describe("skills-clawhub", () => {
workspaceDir: "/tmp/workspace",
slug: "技能",
});
expect(result).toMatchObject({ ok: false, error: expect.stringContaining("Invalid skill slug") });
expect(result).toMatchObject({
ok: false,
error: expect.stringContaining("Invalid skill slug"),
});
});
it("rejects slug starting with a hyphen", async () => {
@ -141,7 +156,21 @@ describe("skills-clawhub", () => {
workspaceDir: "/tmp/workspace",
slug: "-calendar",
});
expect(result).toMatchObject({ ok: false, error: expect.stringContaining("Invalid skill slug") });
expect(result).toMatchObject({
ok: false,
error: expect.stringContaining("Invalid skill slug"),
});
});
it("rejects slug ending with a hyphen", async () => {
const result = await installSkillFromClawHub({
workspaceDir: "/tmp/workspace",
slug: "calendar-",
});
expect(result).toMatchObject({
ok: false,
error: expect.stringContaining("Invalid skill slug"),
});
});
it("accepts valid ASCII slugs", async () => {

View File

@ -62,7 +62,7 @@ type Logger = {
info?: (message: string) => void;
};
const VALID_SLUG_PATTERN = /^[a-z0-9][a-z0-9-]*$/;
const VALID_SLUG_PATTERN = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/;
function normalizeSlug(raw: string): string {
const slug = raw.trim().toLowerCase();