Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

test(agent-skills): unit tests for schemas + SkillsConceptCard

diegosouzapwbf764dc529aa
diff --git a/tests/unit/SkillsConceptCard.test.tsx b/tests/unit/SkillsConceptCard.test.tsx
new file mode 100644
index 0000000000..010478126a
--- /dev/null
+++ b/tests/unit/SkillsConceptCard.test.tsx
@@ -0,0 +1,144 @@
+// @vitest-environment jsdom
+import React from "react";
+import { act } from "react";
+import { createRoot } from "react-dom/client";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+
+// Minimal next-intl stub — returns the translation key for inspection.
+vi.mock("next-intl", () => ({
+ useTranslations: () => (key: string) => key,
+}));
+
+// Minimal next/link stub — renders as a plain anchor element.
+vi.mock("next/link", () => ({
+ default: ({
+ href,
+ children,
+ className,
+ }: {
+ href: string;
+ children: React.ReactNode;
+ className?: string;
+ }) => (
+ <a href={href} className={className}>
+ {children}
+ </a>
+ ),
+}));
+
+const cleanupCallbacks: Array<() => void> = [];
+
+function makeContainer(): HTMLElement {
+ const container = document.createElement("div");
+ document.body.appendChild(container);
+ cleanupCallbacks.push(() => {
+ container.remove();
+ });
+ return container;
+}
+
+describe("SkillsConceptCard", () => {
+ beforeEach(() => {
+ (
+ globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean }
+ ).IS_REACT_ACT_ENVIRONMENT = true;
+ });
+
+ afterEach(() => {
+ while (cleanupCallbacks.length > 0) {
+ cleanupCallbacks.pop()?.();
+ }
+ document.body.innerHTML = "";
+ vi.clearAllMocks();
+ });
+
+ it("renders agent variant with correct i18n keys", async () => {
+ const { SkillsConceptCard } = await import(
+ "../../src/shared/components/SkillsConceptCard.tsx"
+ );
+ const container = makeContainer();
+ const root = createRoot(container);
+ await act(async () => {
+ root.render(<SkillsConceptCard variant="agent" />);
+ });
+
+ const text = container.textContent ?? "";
+ // The i18n mock returns the key itself, so these keys should appear.
+ expect(text).toContain("conceptCard.agent.title");
+ expect(text).toContain("conceptCard.agent.description");
+ expect(text).toContain("conceptCard.agent.crossLinkLabel");
+ });
+
+ it("renders omni variant with correct i18n keys", async () => {
+ const { SkillsConceptCard } = await import(
+ "../../src/shared/components/SkillsConceptCard.tsx"
+ );
+ const container = makeContainer();
+ const root = createRoot(container);
+ await act(async () => {
+ root.render(<SkillsConceptCard variant="omni" />);
+ });
+
+ const text = container.textContent ?? "";
+ expect(text).toContain("conceptCard.omni.title");
+ expect(text).toContain("conceptCard.omni.description");
+ expect(text).toContain("conceptCard.omni.crossLinkLabel");
+ });
+
+ it("agent variant cross-link points to /dashboard/omni-skills", async () => {
+ const { SkillsConceptCard } = await import(
+ "../../src/shared/components/SkillsConceptCard.tsx"
+ );
+ const container = makeContainer();
+ const root = createRoot(container);
+ await act(async () => {
+ root.render(<SkillsConceptCard variant="agent" />);
+ });
+
+ const link = container.querySelector("a");
+ expect(link).not.toBeNull();
+ expect(link?.getAttribute("href")).toBe("/dashboard/omni-skills");
+ });
+
+ it("omni variant cross-link points to /dashboard/agent-skills", async () => {
+ const { SkillsConceptCard } = await import(
+ "../../src/shared/components/SkillsConceptCard.tsx"
+ );
+ const container = makeContainer();
+ const root = createRoot(container);
+ await act(async () => {
+ root.render(<SkillsConceptCard variant="omni" />);
+ });
+
+ const link = container.querySelector("a");
+ expect(link).not.toBeNull();
+ expect(link?.getAttribute("href")).toBe("/dashboard/agent-skills");
+ });
+
+ it("accepts optional className prop", async () => {
+ const { SkillsConceptCard } = await import(
+ "../../src/shared/components/SkillsConceptCard.tsx"
+ );
+ const container = makeContainer();
+ const root = createRoot(container);
+ await act(async () => {
+ root.render(<SkillsConceptCard variant="agent" className="my-custom-class" />);
+ });
+
+ const el = container.firstElementChild as HTMLElement | null;
+ expect(el?.className).toContain("my-custom-class");
+ });
+
+ it("renders without crashing when className is omitted", async () => {
+ const { SkillsConceptCard } = await import(
+ "../../src/shared/components/SkillsConceptCard.tsx"
+ );
+ const container = makeContainer();
+ const root = createRoot(container);
+ await act(async () => {
+ root.render(<SkillsConceptCard variant="agent" />);
+ });
+
+ expect(container.children.length).toBeGreaterThan(0);
+ });
+});
diff --git a/tests/unit/agentSkills-schemas.test.ts b/tests/unit/agentSkills-schemas.test.ts
new file mode 100644
index 0000000000..7172f3e7aa
--- /dev/null
+++ b/tests/unit/agentSkills-schemas.test.ts
@@ -0,0 +1,233 @@
+import test from "node:test";
+import assert from "node:assert/strict";
+
+const { AgentSkillSchema, SkillCoverageSchema, ListQuerySchema, GenerateBodySchema } =
+ await import("../../src/lib/agentSkills/schemas.ts");
+
+// ─── AgentSkillSchema ─────────────────────────────────────────────────────────
+
+test("AgentSkillSchema — valid api skill parses successfully", () => {
+ const input = {
+ id: "omni-providers",
+ name: "Providers",
+ description: "Manage LLM providers",
+ category: "api" as const,
+ area: "providers",
+ endpoints: ["GET /api/providers", "POST /api/providers"],
+ rawUrl: "https://raw.githubusercontent.com/owner/repo/main/skills/omni-providers/SKILL.md",
+ githubUrl: "https://github.com/owner/repo/blob/main/skills/omni-providers/SKILL.md",
+ };
+ const result = AgentSkillSchema.safeParse(input);
+ assert.equal(result.success, true);
+ if (result.success) {
+ assert.equal(result.data.id, "omni-providers");
+ assert.equal(result.data.category, "api");
+ }
+});
+
+test("AgentSkillSchema — valid cli skill parses successfully", () => {
+ const input = {
+ id: "cli-serve",
+ name: "Serve",
+ description: "Start the OmniRoute server",
+ category: "cli" as const,
+ area: "cli-serve",
+ cliCommands: ["serve", "serve --port 8080"],
+ rawUrl: "https://raw.githubusercontent.com/owner/repo/main/skills/cli-serve/SKILL.md",
+ githubUrl: "https://github.com/owner/repo/blob/main/skills/cli-serve/SKILL.md",
+ };
+ const result = AgentSkillSchema.safeParse(input);
+ assert.equal(result.success, true);
+});
+
+test("AgentSkillSchema — invalid id (uppercase) fails", () => {
+ const input = {
+ id: "Omni-Providers",
+ name: "Providers",
+ description: "Manage LLM providers",
+ category: "api",
+ area: "providers",
+ rawUrl: "https://raw.githubusercontent.com/owner/repo/main/skills/omni-providers/SKILL.md",
+ githubUrl: "https://github.com/owner/repo/blob/main/skills/omni-providers/SKILL.md",
+ };
+ const result = AgentSkillSchema.safeParse(input);
+ assert.equal(result.success, false);
+});
+
+test("AgentSkillSchema — invalid category fails", () => {
+ const input = {
+ id: "omni-providers",
+ name: "Providers",
+ description: "Manage LLM providers",
+ category: "unknown",
+ area: "providers",
+ rawUrl: "https://raw.githubusercontent.com/owner/repo/main/skills/omni-providers/SKILL.md",
+ githubUrl: "https://github.com/owner/repo/blob/main/skills/omni-providers/SKILL.md",
+ };
+ const result = AgentSkillSchema.safeParse(input);
+ assert.equal(result.success, false);
+});
+
+test("AgentSkillSchema — non-url rawUrl fails", () => {
+ const input = {
+ id: "omni-providers",
+ name: "Providers",
+ description: "Manage LLM providers",
+ category: "api",
+ area: "providers",
+ rawUrl: "not-a-url",
+ githubUrl: "https://github.com/owner/repo/blob/main/skills/omni-providers/SKILL.md",
+ };
+ const result = AgentSkillSchema.safeParse(input);
+ assert.equal(result.success, false);
+});
+
+test("AgentSkillSchema — optional fields absent parses successfully", () => {
+ const input = {
+ id: "omni-providers",
+ name: "Providers",
+ description: "Manage LLM providers",
+ category: "api",
+ area: "providers",
+ rawUrl: "https://raw.githubusercontent.com/owner/repo/main/skills/omni-providers/SKILL.md",
+ githubUrl: "https://github.com/owner/repo/blob/main/skills/omni-providers/SKILL.md",
+ };
+ const result = AgentSkillSchema.safeParse(input);
+ assert.equal(result.success, true);
+ if (result.success) {
+ assert.equal(result.data.endpoints, undefined);
+ assert.equal(result.data.cliCommands, undefined);
+ assert.equal(result.data.icon, undefined);
+ assert.equal(result.data.isEntry, undefined);
+ assert.equal(result.data.isNew, undefined);
+ }
+});
+
+test("AgentSkillSchema — .parse throws on invalid input", () => {
+ assert.throws(() => {
+ AgentSkillSchema.parse({ id: "bad id", name: "", description: "", category: "api", area: "x", rawUrl: "x", githubUrl: "x" });
+ });
+});
+
+// ─── SkillCoverageSchema ──────────────────────────────────────────────────────
+
+test("SkillCoverageSchema — valid coverage parses successfully", () => {
+ const input = {
+ api: { have: 22, total: 22 },
+ cli: { have: 20, total: 20 },
+ totalSkills: 42,
+ generatedAt: new Date().toISOString(),
+ };
+ const result = SkillCoverageSchema.safeParse(input);
+ assert.equal(result.success, true);
+});
+
+test("SkillCoverageSchema — wrong total literal (api.total=21) fails", () => {
+ const input = {
+ api: { have: 21, total: 21 },
+ cli: { have: 20, total: 20 },
+ totalSkills: 41,
+ generatedAt: new Date().toISOString(),
+ };
+ const result = SkillCoverageSchema.safeParse(input);
+ assert.equal(result.success, false);
+});
+
+test("SkillCoverageSchema — wrong total literal (cli.total=19) fails", () => {
+ const input = {
+ api: { have: 22, total: 22 },
+ cli: { have: 19, total: 19 },
+ totalSkills: 41,
+ generatedAt: new Date().toISOString(),
+ };
+ const result = SkillCoverageSchema.safeParse(input);
+ assert.equal(result.success, false);
+});
+
+test("SkillCoverageSchema — invalid datetime fails", () => {
+ const input = {
+ api: { have: 22, total: 22 },
+ cli: { have: 20, total: 20 },
+ totalSkills: 42,
+ generatedAt: "not-a-date",
+ };
+ const result = SkillCoverageSchema.safeParse(input);
+ assert.equal(result.success, false);
+});
+
+test("SkillCoverageSchema — negative have value fails", () => {
+ const input = {
+ api: { have: -1, total: 22 },
+ cli: { have: 20, total: 20 },
+ totalSkills: 42,
+ generatedAt: new Date().toISOString(),
+ };
+ const result = SkillCoverageSchema.safeParse(input);
+ assert.equal(result.success, false);
+});
+
+// ─── ListQuerySchema ──────────────────────────────────────────────────────────
+
+test("ListQuerySchema — empty object parses successfully", () => {
+ const result = ListQuerySchema.safeParse({});
+ assert.equal(result.success, true);
+ if (result.success) {
+ assert.equal(result.data.category, undefined);
+ assert.equal(result.data.area, undefined);
+ }
+});
+
+test("ListQuerySchema — valid category parses successfully", () => {
+ const result = ListQuerySchema.safeParse({ category: "api" });
+ assert.equal(result.success, true);
+ if (result.success) {
+ assert.equal(result.data.category, "api");
+ }
+});
+
+test("ListQuerySchema — invalid category fails", () => {
+ const result = ListQuerySchema.safeParse({ category: "invalid" });
+ assert.equal(result.success, false);
+});
+
+test("ListQuerySchema — area filter parses successfully", () => {
+ const result = ListQuerySchema.safeParse({ category: "cli", area: "cli-serve" });
+ assert.equal(result.success, true);
+ if (result.success) {
+ assert.equal(result.data.area, "cli-serve");
+ }
+});
+
+// ─── GenerateBodySchema ───────────────────────────────────────────────────────
+
+test("GenerateBodySchema — empty object applies defaults", () => {
+ const result = GenerateBodySchema.safeParse({});
+ assert.equal(result.success, true);
+ if (result.success) {
+ assert.equal(result.data.dryRun, true);
+ assert.equal(result.data.prune, false);
+ assert.equal(result.data.onlyIds, undefined);
+ }
+});
+
+test("GenerateBodySchema — explicit dryRun=false parses", () => {
+ const result = GenerateBodySchema.safeParse({ dryRun: false, prune: true });
+ assert.equal(result.success, true);
+ if (result.success) {
+ assert.equal(result.data.dryRun, false);
+ assert.equal(result.data.prune, true);
+ }
+});
+
+test("GenerateBodySchema — onlyIds array parses", () => {
+ const result = GenerateBodySchema.safeParse({ onlyIds: ["omni-providers", "cli-serve"] });
+ assert.equal(result.success, true);
+ if (result.success) {
+ assert.deepEqual(result.data.onlyIds, ["omni-providers", "cli-serve"]);
+ }
+});
+
+test("GenerateBodySchema — non-boolean dryRun fails", () => {
+ const result = GenerateBodySchema.safeParse({ dryRun: "yes" });
+ assert.equal(result.success, false);
+});