Files
vercel__vercel-plugin/tests/unified-ranker.test.ts
John Lindquist e9ee9f2966 feat(hooks): add unified skill ranker
Add a shared rankSkills utility that combines path, command, import, profiler, prompt, lexical, and priority signals into a single sortable score with per-signal breakdowns.

Add a focused Bun regression test covering weighted scoring, ordering, and default field behavior for sparse candidates.

Verified: bun test tests/unified-ranker.test.ts
How to test: bun test tests/unified-ranker.test.ts
Swarm-Agent: codex-unified-ranker
2026-03-09 19:04:01 -06:00

56 lines
1.5 KiB
TypeScript

import { describe, test, expect } from "bun:test";
import { rankSkills } from "../hooks/src/unified-ranker.mts";
describe("rankSkills", () => {
test("rankSkills computes weighted breakdown and sorts by finalScore when candidates mix signals", () => {
const ranked = rankSkills([
{ skill: "lexical-heavy", lexicalScore: 10, basePriority: 4 },
{
skill: "all-signals",
pathMatch: true,
commandMatch: true,
importMatch: true,
profilerBoost: 3,
promptScore: 6,
lexicalScore: 2,
basePriority: 8,
},
{ skill: "command-only", commandMatch: true },
]);
expect(ranked.map(({ skill }) => skill)).toEqual([
"all-signals",
"lexical-heavy",
"command-only",
]);
expect(ranked[0].finalScore).toBeCloseTo(49.7);
expect(ranked[0].breakdown).toEqual({
pathPoints: 10,
commandPoints: 10,
importPoints: 10,
profilerPoints: 3,
promptPoints: 6,
lexicalPoints: 2.7,
priorityPoints: 8,
});
});
test("rankSkills applies default signal values when optional fields are omitted", () => {
const [ranked] = rankSkills([{ skill: "baseline" }]);
expect(ranked).toEqual({
skill: "baseline",
finalScore: 5,
breakdown: {
pathPoints: 0,
commandPoints: 0,
importPoints: 0,
profilerPoints: 0,
promptPoints: 0,
lexicalPoints: 0,
priorityPoints: 5,
},
});
});
});