From 6d27ac6777ba3a1992ff6753eee955ca7064d49e Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Thu, 3 Apr 2025 14:05:53 -0700 Subject: [PATCH] test: rules --- core/llm/rules/isRuleActive.test.ts | 32 ++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/core/llm/rules/isRuleActive.test.ts b/core/llm/rules/isRuleActive.test.ts index db7dc1f5c..6d7bd0d04 100644 --- a/core/llm/rules/isRuleActive.test.ts +++ b/core/llm/rules/isRuleActive.test.ts @@ -1,14 +1,13 @@ import { isRuleActive } from "./isRuleActive"; describe("isRuleActive", () => { - 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')) }}", - }; + const rule = { + name: "My Rule", + rule: "Do no harm", + if: "${{ and(contains(current.model.model, 'claude-3-7-sonnet') and glob('*.tsx')) }}", + }; - // Should be false when activePaths is empty + it("should return false when activePaths is empty", () => { expect( isRuleActive({ rule, @@ -16,8 +15,9 @@ describe("isRuleActive", () => { currentModel: "claude-3-7-sonnet", }), ).toBe(false); + }); - // Should be false when no matching paths + it("should return false when no matching paths exist", () => { expect( isRuleActive({ rule, @@ -25,8 +25,9 @@ describe("isRuleActive", () => { currentModel: "claude-3-7-sonnet", }), ).toBe(false); + }); - // Should be true when both conditions are met + it("should return true when both conditions are met", () => { expect( isRuleActive({ rule, @@ -34,8 +35,9 @@ describe("isRuleActive", () => { currentModel: "claude-3-7-sonnet", }), ).toBe(true); + }); - // Should be false when only glob matches + it("should return false when only glob matches but model doesn't", () => { expect( isRuleActive({ rule, @@ -44,4 +46,14 @@ describe("isRuleActive", () => { }), ).toBe(false); }); + + it("should return false when model matches but glob doesn't", () => { + expect( + isRuleActive({ + rule, + activePaths: ["Component.ts"], + currentModel: "claude-3-7-sonnet", + }), + ).toBe(false); + }); });