Files
OmniRoute/tests/unit/agentSkills-schemas.test.ts
Diego Rodrigues de Sa e Souza ecc89eef14 feat(providers): integrate audited free-tier gateways (#9210)
* feat(providers): add Zylo UnoRouter and Poolside registries

* feat(providers): integrate audited free-tier gateways

* feat: add wave2 free-tier provider registries

* feat(providers): add Mixlayer Speka and TokenReply registries

* feat: add wave 2 free-tier provider registries

* fix: align meganova provider slug

* feat(providers): integrate wave2 free-tier gateways

* feat(providers): add Wave 3-A free-tier registries

* feat(providers): add HelyxAI Auriko and Poixe registries

* feat(providers): add Naga AI and Chat Oripe registries

* feat(providers): integrate wave3 free-tier gateways

* feat(providers): add FreeInference registry

* feat(providers): add Free.ai registry

* feat(providers): integrate wave4 free-tier gateways

* docs: synchronize provider and free-tier inventories

* refactor(providers): split audited gateway catalog

* feat(providers): add audited Void AI and HelixMind gateways

* feat(providers): finalize audited free-tier integration

* test(providers): update APIKEY split count to 229 after rebase onto release/v3.8.50

The rebase merged the release catalog (201 APIKEY providers) with the PR's
28 free-tier additions, yielding 229 total. Correct the characterization
count so the partition assertion reflects the true merged state.

---------

Co-authored-by: diegosouzapw <diegosouzapw@users.noreply.github.com>
Co-authored-by: backryun <bakryun0718@proton.me>
2026-08-12 16:19:25 -03:00

269 lines
9.1 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
const { AgentSkillSchema, SkillCoverageSchema, ListQuerySchema, GenerateBodySchema } =
await import("../../src/lib/agentSkills/schemas.ts");
test("agent skills schemas module exposes runtime validators", async () => {
const schemas = await import("../../src/lib/agentSkills/schemas.ts");
for (const key of [
"AgentSkillSchema",
"GenerateBodySchema",
"ListQuerySchema",
"SkillCategorySchema",
"SkillCoverageSchema",
]) {
assert.equal(typeof schemas[key].safeParse, "function", `${key} should stay exported`);
}
});
// ─── 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: 23, total: 23 },
cli: { have: 21, total: 21 },
config: { have: 1, total: 1 },
totalSkills: 45,
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: 21, total: 21 },
config: { have: 1, total: 1 },
totalSkills: 44,
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: 23, total: 23 },
cli: { have: 20, total: 20 },
config: { have: 1, total: 1 },
totalSkills: 44,
generatedAt: new Date().toISOString(),
};
const result = SkillCoverageSchema.safeParse(input);
assert.equal(result.success, false);
});
test("SkillCoverageSchema — invalid datetime fails", () => {
const input = {
api: { have: 23, total: 23 },
cli: { have: 21, total: 21 },
config: { have: 1, total: 1 },
totalSkills: 45,
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: 23 },
cli: { have: 21, total: 21 },
config: { have: 1, total: 1 },
totalSkills: 45,
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 — config category parses successfully", () => {
const result = ListQuerySchema.safeParse({ category: "config" });
assert.equal(result.success, true);
if (result.success) {
assert.equal(result.data.category, "config");
}
});
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);
});