mirror of
https://github.com/vercel/vercel-plugin.git
synced 2026-09-14 15:39:47 +08:00
657e96a294
Add a MiniSearch-backed lexical index for retrieval frontmatter with synonym and contraction expansion so hooks can rank skills from short natural-language queries. Verified: bun test hooks/lexical-index.test.ts Verified: ./node_modules/.bin/tsc --noEmit --module NodeNext --moduleResolution NodeNext --target ES2022 --strict --skipLibCheck --types node hooks/src/lexical-index.mts Swarm-Agent: codex-lexical-index
77 lines
2.1 KiB
TypeScript
77 lines
2.1 KiB
TypeScript
import { afterEach, describe, expect, it } from "bun:test";
|
|
import { initializeLexicalIndex, searchSkills } from "./src/lexical-index.mts";
|
|
|
|
const originalMinScore = process.env.VERCEL_PLUGIN_LEXICAL_RESULT_MIN_SCORE;
|
|
|
|
function restoreMinScore(): void {
|
|
if (typeof originalMinScore === "string") {
|
|
process.env.VERCEL_PLUGIN_LEXICAL_RESULT_MIN_SCORE = originalMinScore;
|
|
return;
|
|
}
|
|
delete process.env.VERCEL_PLUGIN_LEXICAL_RESULT_MIN_SCORE;
|
|
}
|
|
|
|
afterEach(() => {
|
|
restoreMinScore();
|
|
initializeLexicalIndex(new Map());
|
|
});
|
|
|
|
describe("lexical index", () => {
|
|
it("test_searchSkills_matches_top_level_and_metadata_retrieval_with_query_expansion", () => {
|
|
process.env.VERCEL_PLUGIN_LEXICAL_RESULT_MIN_SCORE = "0";
|
|
initializeLexicalIndex(
|
|
new Map([
|
|
[
|
|
"deployments",
|
|
{
|
|
retrieval: {
|
|
aliases: ["deploy"],
|
|
intents: ["publish release"],
|
|
entities: ["environment secret"],
|
|
examples: ["push this app live"],
|
|
},
|
|
},
|
|
],
|
|
[
|
|
"auth",
|
|
{
|
|
metadata: {
|
|
retrieval: {
|
|
aliases: ["auth"],
|
|
intents: ["login"],
|
|
entities: ["session credentials"],
|
|
examples: ["cannot signin"],
|
|
},
|
|
},
|
|
},
|
|
],
|
|
]),
|
|
);
|
|
|
|
expect(searchSkills("ship my env config")[0]?.skill).toBe("deployments");
|
|
expect(searchSkills("cant signin with session credentials")[0]?.skill).toBe("auth");
|
|
});
|
|
|
|
it("test_searchSkills_filters_results_using_env_min_score", () => {
|
|
initializeLexicalIndex(
|
|
new Map([
|
|
[
|
|
"api-skill",
|
|
{
|
|
retrieval: {
|
|
aliases: ["api"],
|
|
intents: ["endpoint route"],
|
|
entities: ["graphql handler"],
|
|
examples: ["build a rest api"],
|
|
},
|
|
},
|
|
],
|
|
]),
|
|
);
|
|
|
|
process.env.VERCEL_PLUGIN_LEXICAL_RESULT_MIN_SCORE = "999";
|
|
|
|
expect(searchSkills("graphql api route")).toEqual([]);
|
|
});
|
|
});
|