Elffuss BraidHub

kikocis/continue public

main · 2.3 KiBRawPermalink
1import { describe, expect, it } from "vitest";
2import { RuleWithSource } from "../..";
3import { shouldApplyRule } from "./getSystemMessageWithRules";
4
5describe("File Path Protocol Matching", () => {
6 // Test rule with a file:// protocol in the path - simulating what happens in VSCode
7 const ruleWithFileProtocol: RuleWithSource = {
8 name: "Rule with file:// protocol",
9 rule: "This is a test rule",
10 source: "rules-block",
11 ruleFile: "file:///Users/user/project/nested-folder/rules.md",
12 };
13
14 it("should match relative paths with file:// protocol paths", () => {
15 // This is the key test case that would have failed before:
16 // A relative path should match with a file:// protocol directory path
17 const relativePaths = ["nested-folder/example.py"];
18
19 // Before the fix, this would have failed because the string comparison
20 // would be checking if 'nested-folder/example.py' starts with
21 // 'file:///Users/user/project/nested-folder/'
22 expect(shouldApplyRule(ruleWithFileProtocol, relativePaths)).toBe(true);
23 });
24
25 it("should match when directory name appears in the path", () => {
26 // Even with a more complex relative path, it should match as long as
27 // it contains the right directory structure
28 const nestedPaths = ["src/components/nested-folder/example.py"];
29 expect(shouldApplyRule(ruleWithFileProtocol, nestedPaths)).toBe(true);
30 });
31
32 it("should not match when directory name is not in the path", () => {
33 // Should not match when the path doesn't contain the directory name
34 const unrelatedPaths = ["src/components/other-folder/example.py"];
35 expect(shouldApplyRule(ruleWithFileProtocol, unrelatedPaths)).toBe(false);
36 });
37
38 it("should match absolute paths with the same protocol", () => {
39 // Should also work with absolute paths
40 const absolutePaths = [
41 "file:///Users/user/project/nested-folder/example.py",
42 ];
43 expect(shouldApplyRule(ruleWithFileProtocol, absolutePaths)).toBe(true);
44 });
45
46 it("should handle mixed path types in the same call", () => {
47 // Should handle a mix of relative and absolute paths
48 const mixedPaths = [
49 "nested-folder/example.py",
50 "file:///Users/user/project/nested-folder/other.py",
51 "src/unrelated/file.py",
52 ];
53 expect(shouldApplyRule(ruleWithFileProtocol, mixedPaths)).toBe(true);
54 });
55});