-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate-selector.test.ts
More file actions
88 lines (80 loc) · 2.4 KB
/
Copy pathtemplate-selector.test.ts
File metadata and controls
88 lines (80 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { describe, expect, it } from "vitest";
import {
ApprovedTemplateSelector,
type ApprovedTemplateSource,
type PromptTemplateCandidate
} from "../src/refiners/template-selector.js";
describe("ApprovedTemplateSelector", () => {
const templates: PromptTemplateCandidate[] = [
{
id: "feature",
repoId: "repo",
category: "feature",
title: "Feature implementation",
templateText: "Implement [FEATURE] and verify it.",
usageNotes: "Use for new features.",
successScore: 90,
approved: 1
},
{
id: "bugfix",
repoId: "repo",
category: "bugfix",
title: "Bug fix",
templateText: "Reproduce and fix [BUG].",
successScore: 75,
approved: true
},
{
id: "pending",
repoId: "repo",
category: "feature",
title: "Pending",
templateText: "Do not select.",
successScore: 100,
approved: 0
},
{
id: "deprecated",
repoId: "repo",
category: "feature",
title: "Deprecated",
templateText: "Do not select.",
successScore: 100,
approved: 1,
deprecated: 1
}
];
const source: ApprovedTemplateSource = {
getTemplates: () => templates
};
it("retrieves only approved, active templates and ranks prompt relevance", async () => {
const selected = await new ApprovedTemplateSelector(source).select({
repoId: "repo",
prompt: "Implement a new login feature",
limit: 2
});
expect(selected.map(template => template.id)).toEqual(["feature", "bugfix"]);
expect(selected[0].selectionReasons).toContain("category:feature");
expect(selected.some(template => template.id === "pending")).toBe(false);
expect(selected.some(template => template.id === "deprecated")).toBe(false);
});
it("keeps repository boundaries", async () => {
const selected = await new ApprovedTemplateSelector(source).select({
repoId: "other",
prompt: "Implement a feature"
});
expect(selected).toEqual([]);
});
it("supports a disabled selection limit without querying the source", async () => {
let queried = false;
const selector = new ApprovedTemplateSelector({
getTemplates: () => {
queried = true;
return templates;
}
});
expect(await selector.select({ repoId: "repo", prompt: "Implement a feature", limit: 0 })).toEqual([]);
expect(queried).toBe(false);
});
});