fix: tests
This commit is contained in:
parent
2b97efe5c6
commit
81acb44601
1 changed files with 32 additions and 40 deletions
|
|
@ -1,55 +1,47 @@
|
|||
import { isRuleActive } from "./isRuleActive";
|
||||
|
||||
describe("isRuleActive", () => {
|
||||
it("evaluates glob patterns correctly", () => {
|
||||
const activePaths = ["src/foo.ts", "src/bar.tsx", "README.md"];
|
||||
it("should correctly evaluate combined contains and glob conditions", () => {
|
||||
const rule = {
|
||||
name: "My Rule",
|
||||
rule: "Do no harm",
|
||||
if: "${{ and(contains(current.model.model, 'claude-3-7-sonnet'), glob('*.tsx')) }}",
|
||||
};
|
||||
|
||||
// Should be false when activePaths is empty
|
||||
expect(
|
||||
isRuleActive({
|
||||
rule: {
|
||||
name: "Test Rule",
|
||||
rule: "Some rule",
|
||||
if: '${{ glob("src/*.ts") }}',
|
||||
},
|
||||
activePaths,
|
||||
rule,
|
||||
activePaths: [],
|
||||
currentModel: "claude-3-7-sonnet",
|
||||
}),
|
||||
).toBe(false);
|
||||
|
||||
// Should be false when no matching paths
|
||||
expect(
|
||||
isRuleActive({
|
||||
rule,
|
||||
activePaths: ["test.py", "main.js"],
|
||||
currentModel: "claude-3-7-sonnet",
|
||||
}),
|
||||
).toBe(false);
|
||||
|
||||
// Should be true when both conditions are met
|
||||
expect(
|
||||
isRuleActive({
|
||||
rule,
|
||||
activePaths: ["Component.tsx", "main.js"],
|
||||
currentModel: "claude-3-7-sonnet",
|
||||
}),
|
||||
).toBe(true);
|
||||
|
||||
// Should be false when only glob matches
|
||||
expect(
|
||||
isRuleActive({
|
||||
rule: {
|
||||
name: "Test Rule",
|
||||
rule: "Some rule",
|
||||
if: '${{ glob("*.md") }}',
|
||||
},
|
||||
activePaths,
|
||||
}),
|
||||
).toBe(true);
|
||||
|
||||
expect(
|
||||
isRuleActive({
|
||||
rule: {
|
||||
name: "Test Rule",
|
||||
rule: "Some rule",
|
||||
if: '${{ glob("*.py") }}',
|
||||
},
|
||||
activePaths,
|
||||
rule,
|
||||
activePaths: ["Component.tsx"],
|
||||
currentModel: "gpt-4",
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("evaluates combined conditions correctly", () => {
|
||||
const activePaths = ["src/foo.ts"];
|
||||
|
||||
expect(
|
||||
isRuleActive({
|
||||
rule: {
|
||||
name: "Test Rule",
|
||||
rule: "Some rule",
|
||||
if: '${{ glob("src/*.ts") && current.model === "gpt-4" }}',
|
||||
},
|
||||
activePaths,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue