Changesets · Branches · Tags · Compare
| Changeset | b6f6b229557f4a66c71a4e764b6bc7bd210bd78504b65e6319e7d8169dd59232 |
|---|---|
| Author | Tomasz Stefaniak <tomasz.p.stefaniak@gmail.com> · 2025-06-09 16:07 -07:00 |
| Committer | Tomasz Stefaniak <tomasz.p.stefaniak@gmail.com> · 2025-06-09 17:11 -07:00 |
| Parents | 456405ec0111 |
6 files changed
modified core/config/markdown/loadCodebaseRules.vitest.ts +93 −85
| @@ -1,153 +1,161 @@ | ||
| 1 | -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; | |
| 2 | -import { loadCodebaseRules } from './loadCodebaseRules'; | |
| 3 | -import { walkDirs } from '../../indexing/walkDir'; | |
| 4 | -import { IDE } from '../..'; | |
| 5 | -import { convertMarkdownRuleToContinueRule } from './parseMarkdownRule'; | |
| 1 | +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | |
| 2 | +import { IDE } from "../.."; | |
| 3 | +import { walkDirs } from "../../indexing/walkDir"; | |
| 4 | +import { loadCodebaseRules } from "./loadCodebaseRules"; | |
| 5 | +import { convertMarkdownRuleToContinueRule } from "./parseMarkdownRule"; | |
| 6 | 6 | |
| 7 | 7 | // Mock dependencies |
| 8 | -vi.mock('../../indexing/walkDir', () => ({ | |
| 8 | +vi.mock("../../indexing/walkDir", () => ({ | |
| 9 | 9 | walkDirs: vi.fn(), |
| 10 | 10 | })); |
| 11 | 11 | |
| 12 | -vi.mock('./parseMarkdownRule', () => ({ | |
| 12 | +vi.mock("./parseMarkdownRule", () => ({ | |
| 13 | 13 | convertMarkdownRuleToContinueRule: vi.fn(), |
| 14 | 14 | })); |
| 15 | 15 | |
| 16 | -describe('loadCodebaseRules', () => { | |
| 17 | - // Mock IDE | |
| 16 | +describe("loadCodebaseRules", () => { | |
| 17 | + // Mock IDE with properly typed mock functions | |
| 18 | 18 | const mockIde = { |
| 19 | - readFile: vi.fn(), | |
| 19 | + readFile: vi.fn() as unknown as IDE["readFile"] & { | |
| 20 | + mockImplementation: Function; | |
| 21 | + }, | |
| 20 | 22 | } as unknown as IDE; |
| 21 | 23 | |
| 22 | 24 | // Setup test files |
| 23 | 25 | const mockFiles = [ |
| 24 | - 'src/rules.md', | |
| 25 | - 'src/redux/rules.md', | |
| 26 | - 'src/components/rules.md', | |
| 27 | - 'src/utils/helper.ts', // Non-rules file | |
| 28 | - '.continue/rules.md', // This should also be loaded | |
| 26 | + "src/rules.md", | |
| 27 | + "src/redux/rules.md", | |
| 28 | + "src/components/rules.md", | |
| 29 | + "src/utils/helper.ts", // Non-rules file | |
| 30 | + ".continue/rules.md", // This should also be loaded | |
| 29 | 31 | ]; |
| 30 | 32 | |
| 31 | 33 | // Mock rule content |
| 32 | - const mockRuleContent = { | |
| 33 | - 'src/rules.md': '# General Rules\nFollow coding standards', | |
| 34 | - 'src/redux/rules.md': '---\nglobs: "**/*.{ts,tsx}"\n---\n# Redux Rules\nUse Redux Toolkit', | |
| 35 | - 'src/components/rules.md': '---\nglobs: ["**/*.tsx", "**/*.jsx"]\n---\n# Component Rules\nUse functional components', | |
| 36 | - '.continue/rules.md': '# Global Rules\nFollow project guidelines', | |
| 34 | + const mockRuleContent: Record<string, string> = { | |
| 35 | + "src/rules.md": "# General Rules\nFollow coding standards", | |
| 36 | + "src/redux/rules.md": | |
| 37 | + '---\nglobs: "**/*.{ts,tsx}"\n---\n# Redux Rules\nUse Redux Toolkit', | |
| 38 | + "src/components/rules.md": | |
| 39 | + '---\nglobs: ["**/*.tsx", "**/*.jsx"]\n---\n# Component Rules\nUse functional components', | |
| 40 | + ".continue/rules.md": "# Global Rules\nFollow project guidelines", | |
| 37 | 41 | }; |
| 38 | 42 | |
| 39 | 43 | // Mock converted rules |
| 40 | - const mockConvertedRules = { | |
| 41 | - 'src/rules.md': { | |
| 42 | - name: 'General Rules', | |
| 43 | - rule: 'Follow coding standards', | |
| 44 | - source: 'rules-block', | |
| 45 | - ruleFile: 'src/rules.md', | |
| 44 | + const mockConvertedRules: Record<string, any> = { | |
| 45 | + "src/rules.md": { | |
| 46 | + name: "General Rules", | |
| 47 | + rule: "Follow coding standards", | |
| 48 | + source: "rules-block", | |
| 49 | + ruleFile: "src/rules.md", | |
| 46 | 50 | }, |
| 47 | - 'src/redux/rules.md': { | |
| 48 | - name: 'Redux Rules', | |
| 49 | - rule: 'Use Redux Toolkit', | |
| 50 | - globs: '**/*.{ts,tsx}', | |
| 51 | - source: 'rules-block', | |
| 52 | - ruleFile: 'src/redux/rules.md', | |
| 51 | + "src/redux/rules.md": { | |
| 52 | + name: "Redux Rules", | |
| 53 | + rule: "Use Redux Toolkit", | |
| 54 | + globs: "**/*.{ts,tsx}", | |
| 55 | + source: "rules-block", | |
| 56 | + ruleFile: "src/redux/rules.md", | |
| 53 | 57 | }, |
| 54 | - 'src/components/rules.md': { | |
| 55 | - name: 'Component Rules', | |
| 56 | - rule: 'Use functional components', | |
| 57 | - globs: ['**/*.tsx', '**/*.jsx'], | |
| 58 | - source: 'rules-block', | |
| 59 | - ruleFile: 'src/components/rules.md', | |
| 58 | + "src/components/rules.md": { | |
| 59 | + name: "Component Rules", | |
| 60 | + rule: "Use functional components", | |
| 61 | + globs: ["**/*.tsx", "**/*.jsx"], | |
| 62 | + source: "rules-block", | |
| 63 | + ruleFile: "src/components/rules.md", | |
| 60 | 64 | }, |
| 61 | - '.continue/rules.md': { | |
| 62 | - name: 'Global Rules', | |
| 63 | - rule: 'Follow project guidelines', | |
| 64 | - source: 'rules-block', | |
| 65 | - ruleFile: '.continue/rules.md', | |
| 65 | + ".continue/rules.md": { | |
| 66 | + name: "Global Rules", | |
| 67 | + rule: "Follow project guidelines", | |
| 68 | + source: "rules-block", | |
| 69 | + ruleFile: ".continue/rules.md", | |
| 66 | 70 | }, |
| 67 | 71 | }; |
| 68 | 72 | |
| 69 | 73 | beforeEach(() => { |
| 70 | 74 | // Setup mocks |
| 71 | 75 | vi.resetAllMocks(); |
| 72 | - | |
| 76 | + | |
| 73 | 77 | // Mock walkDirs to return our test files |
| 74 | 78 | (walkDirs as any).mockResolvedValue(mockFiles); |
| 75 | - | |
| 79 | + | |
| 76 | 80 | // Mock readFile to return content based on path |
| 77 | - mockIde.readFile.mockImplementation((path: string) => { | |
| 78 | - return Promise.resolve(mockRuleContent[path] || ''); | |
| 81 | + (mockIde.readFile as any).mockImplementation((path: string) => { | |
| 82 | + return Promise.resolve(mockRuleContent[path] || ""); | |
| 79 | 83 | }); |
| 80 | - | |
| 84 | + | |
| 81 | 85 | // Mock convertMarkdownRuleToContinueRule to return converted rules |
| 82 | - (convertMarkdownRuleToContinueRule as any).mockImplementation((path: string, content: string) => { | |
| 83 | - return mockConvertedRules[path]; | |
| 84 | - }); | |
| 86 | + (convertMarkdownRuleToContinueRule as any).mockImplementation( | |
| 87 | + (path: string, content: string) => { | |
| 88 | + return mockConvertedRules[path]; | |
| 89 | + }, | |
| 90 | + ); | |
| 85 | 91 | }); |
| 86 | 92 | |
| 87 | 93 | afterEach(() => { |
| 88 | 94 | vi.resetAllMocks(); |
| 89 | 95 | }); |
| 90 | - | |
| 91 | - it('should load rules from all rules.md files in the workspace', async () => { | |
| 96 | + it("should load rules from all rules.md files in the workspace", async () => { | |
| 92 | 97 | const { rules, errors } = await loadCodebaseRules(mockIde); |
| 93 | - | |
| 98 | + | |
| 94 | 99 | // Should find all rules.md files |
| 95 | 100 | expect(walkDirs).toHaveBeenCalledWith(mockIde); |
| 96 | - | |
| 101 | + | |
| 97 | 102 | // Should read all rules.md files |
| 98 | 103 | expect(mockIde.readFile).toHaveBeenCalledTimes(4); |
| 99 | - expect(mockIde.readFile).toHaveBeenCalledWith('src/rules.md'); | |
| 100 | - expect(mockIde.readFile).toHaveBeenCalledWith('src/redux/rules.md'); | |
| 101 | - expect(mockIde.readFile).toHaveBeenCalledWith('src/components/rules.md'); | |
| 102 | - expect(mockIde.readFile).toHaveBeenCalledWith('.continue/rules.md'); | |
| 103 | - | |
| 104 | + expect(mockIde.readFile).toHaveBeenCalledWith("src/rules.md"); | |
| 105 | + expect(mockIde.readFile).toHaveBeenCalledWith("src/redux/rules.md"); | |
| 106 | + expect(mockIde.readFile).toHaveBeenCalledWith("src/components/rules.md"); | |
| 107 | + expect(mockIde.readFile).toHaveBeenCalledWith(".continue/rules.md"); | |
| 108 | + | |
| 104 | 109 | // Should convert all rules |
| 105 | 110 | expect(convertMarkdownRuleToContinueRule).toHaveBeenCalledTimes(4); |
| 106 | - | |
| 111 | + | |
| 107 | 112 | // Should return all rules |
| 108 | 113 | expect(rules).toHaveLength(4); |
| 109 | - expect(rules).toContainEqual(mockConvertedRules['src/rules.md']); | |
| 110 | - expect(rules).toContainEqual(mockConvertedRules['src/redux/rules.md']); | |
| 111 | - expect(rules).toContainEqual(mockConvertedRules['src/components/rules.md']); | |
| 112 | - expect(rules).toContainEqual(mockConvertedRules['.continue/rules.md']); | |
| 113 | - | |
| 114 | + expect(rules).toContainEqual(mockConvertedRules["src/rules.md"]); | |
| 115 | + expect(rules).toContainEqual(mockConvertedRules["src/redux/rules.md"]); | |
| 116 | + expect(rules).toContainEqual(mockConvertedRules["src/components/rules.md"]); | |
| 117 | + expect(rules).toContainEqual(mockConvertedRules[".continue/rules.md"]); | |
| 118 | + | |
| 114 | 119 | // Should not have errors |
| 115 | 120 | expect(errors).toHaveLength(0); |
| 116 | 121 | }); |
| 117 | 122 | |
| 118 | - it('should handle errors when reading a rule file', async () => { | |
| 123 | + it("should handle errors when reading a rule file", async () => { | |
| 119 | 124 | // Setup mock to throw for a specific file |
| 120 | - mockIde.readFile.mockImplementation((path: string) => { | |
| 121 | - if (path === 'src/redux/rules.md') { | |
| 122 | - return Promise.reject(new Error('Failed to read file')); | |
| 125 | + (mockIde.readFile as any).mockImplementation((path: string) => { | |
| 126 | + if (path === "src/redux/rules.md") { | |
| 127 | + return Promise.reject(new Error("Failed to read file")); | |
| 123 | 128 | } |
| 124 | - return Promise.resolve(mockRuleContent[path] || ''); | |
| 129 | + return Promise.resolve(mockRuleContent[path] || ""); | |
| 125 | 130 | }); |
| 126 | - | |
| 131 | + | |
| 127 | 132 | const { rules, errors } = await loadCodebaseRules(mockIde); |
| 128 | - | |
| 133 | + | |
| 129 | 134 | // Should still return other rules |
| 130 | 135 | expect(rules).toHaveLength(3); |
| 131 | - expect(rules).toContainEqual(mockConvertedRules['src/rules.md']); | |
| 132 | - expect(rules).toContainEqual(mockConvertedRules['src/components/rules.md']); | |
| 133 | - expect(rules).toContainEqual(mockConvertedRules['.continue/rules.md']); | |
| 134 | - | |
| 136 | + expect(rules).toContainEqual(mockConvertedRules["src/rules.md"]); | |
| 137 | + expect(rules).toContainEqual(mockConvertedRules["src/components/rules.md"]); | |
| 138 | + expect(rules).toContainEqual(mockConvertedRules[".continue/rules.md"]); | |
| 139 | + | |
| 135 | 140 | // Should have one error |
| 136 | 141 | expect(errors).toHaveLength(1); |
| 137 | - expect(errors[0].message).toContain('Failed to parse colocated rule file src/redux/rules.md'); | |
| 142 | + expect(errors[0].message).toContain( | |
| 143 | + "Failed to parse colocated rule file src/redux/rules.md", | |
| 144 | + ); | |
| 138 | 145 | }); |
| 139 | 146 | |
| 140 | - it('should handle errors when walkDirs fails', async () => { | |
| 147 | + it("should handle errors when walkDirs fails", async () => { | |
| 141 | 148 | // Setup mock to throw |
| 142 | - (walkDirs as any).mockRejectedValue(new Error('Failed to walk directories')); | |
| 143 | - | |
| 149 | + (walkDirs as any).mockRejectedValue( | |
| 150 | + new Error("Failed to walk directories"), | |
| 151 | + ); | |
| 144 | 152 | const { rules, errors } = await loadCodebaseRules(mockIde); |
| 145 | - | |
| 153 | + | |
| 146 | 154 | // Should return no rules |
| 147 | 155 | expect(rules).toHaveLength(0); |
| 148 | - | |
| 156 | + | |
| 149 | 157 | // Should have one error |
| 150 | 158 | expect(errors).toHaveLength(1); |
| 151 | - expect(errors[0].message).toContain('Error loading colocated rule files'); | |
| 159 | + expect(errors[0].message).toContain("Error loading colocated rule files"); | |
| 152 | 160 | }); |
| 153 | -}); | |
| No newline at the end of the file | ||
| 161 | +}); |
modified core/config/markdown/ruleCollocationApplication.vitest.ts +31 −27
| @@ -1,6 +1,12 @@ | ||
| 1 | 1 | import path from "path"; |
| 2 | 2 | import { beforeEach, describe, expect, it } from "vitest"; |
| 3 | -import { ContextItemWithId, RuleWithSource, UserChatMessage } from "../.."; | |
| 3 | +import { | |
| 4 | + ContextItemId, | |
| 5 | + ContextItemWithId, | |
| 6 | + RuleWithSource, | |
| 7 | + UserChatMessage, | |
| 8 | +} from "../.."; | |
| 9 | + | |
| 4 | 10 | import { getApplicableRules } from "../../llm/rules/getSystemMessageWithRules"; |
| 5 | 11 | |
| 6 | 12 | describe("Rule Colocation Application", () => { |
| @@ -68,86 +74,82 @@ | ||
| 68 | 74 | beforeEach(() => { |
| 69 | 75 | // Setup user messages with different code blocks |
| 70 | 76 | userMessageWithComponentFile = { |
| 71 | - id: "1", | |
| 72 | 77 | role: "user", |
| 73 | 78 | content: |
| 74 | 79 | "Can you help me with this component file?\n```tsx src/components/Button.tsx\nexport const Button = () => {...}\n```", |
| 75 | - createdAt: new Date().toISOString(), | |
| 76 | 80 | }; |
| 77 | 81 | |
| 78 | 82 | userMessageWithComponentJsxFile = { |
| 79 | - id: "1b", | |
| 80 | 83 | role: "user", |
| 81 | 84 | content: |
| 82 | 85 | "Can you help me with this JSX component file?\n```jsx src/components/OldButton.jsx\nexport const OldButton = () => {...}\n```", |
| 83 | - createdAt: new Date().toISOString(), | |
| 84 | 86 | }; |
| 85 | 87 | |
| 86 | 88 | userMessageWithReduxFile = { |
| 87 | - id: "2", | |
| 88 | 89 | role: "user", |
| 89 | 90 | content: |
| 90 | 91 | 'Can you help with this redux slice?\n```ts src/redux/userSlice.ts\nimport { createSlice } from "@reduxjs/toolkit";\n```', |
| 91 | - createdAt: new Date().toISOString(), | |
| 92 | 92 | }; |
| 93 | 93 | |
| 94 | 94 | userMessageWithRootFile = { |
| 95 | - id: "3", | |
| 96 | 95 | role: "user", |
| 97 | 96 | content: |
| 98 | 97 | "Can you help with this utility file?\n```ts src/utils/helpers.ts\nexport const formatDate = (date) => {...}\n```", |
| 99 | - createdAt: new Date().toISOString(), | |
| 100 | 98 | }; |
| 101 | 99 | |
| 102 | 100 | userMessageWithApiUtilFile = { |
| 103 | - id: "4", | |
| 104 | 101 | role: "user", |
| 105 | 102 | content: |
| 106 | 103 | "Can you help with this API utility file?\n```ts src/utils/api/requests.ts\nexport const fetchData = () => {...}\n```", |
| 107 | - createdAt: new Date().toISOString(), | |
| 108 | 104 | }; |
| 109 | 105 | |
| 110 | 106 | // Setup context items |
| 111 | 107 | componentTsxContextItem = { |
| 112 | - id: "context1", | |
| 108 | + id: { providerTitle: "file", itemId: "context1" } as ContextItemId, | |
| 113 | 109 | uri: { type: "file", value: "src/components/Button.tsx" }, |
| 114 | 110 | content: "export const Button = () => {...}", |
| 115 | - retrievedAt: new Date().toISOString(), | |
| 111 | + name: "Button.tsx", | |
| 112 | + description: "Component file", | |
| 116 | 113 | }; |
| 117 | 114 | |
| 118 | 115 | componentJsxContextItem = { |
| 119 | - id: "context1b", | |
| 116 | + id: { providerTitle: "file", itemId: "context1b" } as ContextItemId, | |
| 120 | 117 | uri: { type: "file", value: "src/components/OldButton.jsx" }, |
| 121 | 118 | content: "export const OldButton = () => {...}", |
| 122 | - retrievedAt: new Date().toISOString(), | |
| 119 | + name: "OldButton.jsx", | |
| 120 | + description: "Component file", | |
| 123 | 121 | }; |
| 124 | 122 | |
| 125 | 123 | reduxContextItem = { |
| 126 | - id: "context2", | |
| 124 | + id: { providerTitle: "file", itemId: "context2" } as ContextItemId, | |
| 127 | 125 | uri: { type: "file", value: "src/redux/userSlice.ts" }, |
| 128 | 126 | content: 'import { createSlice } from "@reduxjs/toolkit";', |
| 129 | - retrievedAt: new Date().toISOString(), | |
| 127 | + name: "userSlice.ts", | |
| 128 | + description: "Redux slice", | |
| 130 | 129 | }; |
| 131 | 130 | |
| 132 | 131 | rootContextItem = { |
| 133 | - id: "context3", | |
| 132 | + id: { providerTitle: "file", itemId: "context3" } as ContextItemId, | |
| 134 | 133 | uri: { type: "file", value: "src/utils/helpers.ts" }, |
| 135 | 134 | content: "export const formatDate = (date) => {...}", |
| 136 | - retrievedAt: new Date().toISOString(), | |
| 135 | + name: "helpers.ts", | |
| 136 | + description: "Utility file", | |
| 137 | 137 | }; |
| 138 | 138 | |
| 139 | 139 | apiUtilContextItem = { |
| 140 | - id: "context4", | |
| 140 | + id: { providerTitle: "file", itemId: "context4" } as ContextItemId, | |
| 141 | 141 | uri: { type: "file", value: "src/utils/api/requests.ts" }, |
| 142 | 142 | content: "export const fetchData = () => {...}", |
| 143 | - retrievedAt: new Date().toISOString(), | |
| 143 | + name: "requests.ts", | |
| 144 | + description: "API utility file", | |
| 144 | 145 | }; |
| 145 | 146 | |
| 146 | 147 | otherUtilContextItem = { |
| 147 | - id: "context5", | |
| 148 | + id: { providerTitle: "file", itemId: "context5" } as ContextItemId, | |
| 148 | 149 | uri: { type: "file", value: "src/utils/format.ts" }, |
| 149 | 150 | content: "export const formatCurrency = (amount) => {...}", |
| 150 | - retrievedAt: new Date().toISOString(), | |
| 151 | + name: "format.ts", | |
| 152 | + description: "Formatting utility", | |
| 151 | 153 | }; |
| 152 | 154 | }); |
| 153 | 155 | |
| @@ -338,17 +340,19 @@ | ||
| 338 | 340 | |
| 339 | 341 | // Create context items for different files |
| 340 | 342 | const modelFileContext: ContextItemWithId = { |
| 341 | - id: "models1", | |
| 343 | + id: { providerTitle: "file", itemId: "models1" } as ContextItemId, | |
| 342 | 344 | uri: { type: "file", value: "src/models/user.ts" }, |
| 343 | 345 | content: "export interface User {...}", |
| 344 | - retrievedAt: new Date().toISOString(), | |
| 346 | + name: "user.ts", | |
| 347 | + description: "User model", | |
| 345 | 348 | }; |
| 346 | 349 | |
| 347 | 350 | const serviceFileContext: ContextItemWithId = { |
| 348 | - id: "services1", | |
| 351 | + id: { providerTitle: "file", itemId: "services1" } as ContextItemId, | |
| 349 | 352 | uri: { type: "file", value: "src/services/auth.ts" }, |
| 350 | 353 | content: "export const login = () => {...}", |
| 351 | - retrievedAt: new Date().toISOString(), | |
| 354 | + name: "auth.ts", | |
| 355 | + description: "Auth service", | |
| 352 | 356 | }; |
| 353 | 357 | |
| 354 | 358 | // Test with model file - should apply only the models rule |
modified core/llm/rules/alwaysApplyRules.vitest.ts +69 −67
| @@ -1,137 +1,139 @@ | ||
| 1 | -import { describe, expect, it } from 'vitest'; | |
| 2 | -import { ContextItemWithId, RuleWithSource, UserChatMessage } from '../..'; | |
| 3 | -import { getApplicableRules } from './getSystemMessageWithRules'; | |
| 4 | - | |
| 5 | -describe('Rule application with alwaysApply', () => { | |
| 1 | +import { describe, expect, it } from "vitest"; | |
| 2 | +import { | |
| 3 | + ContextItemId, | |
| 4 | + ContextItemWithId, | |
| 5 | + RuleWithSource, | |
| 6 | + UserChatMessage, | |
| 7 | +} from "../.."; | |
| 8 | +import { getApplicableRules } from "./getSystemMessageWithRules"; | |
| 9 | + | |
| 10 | +describe("Rule application with alwaysApply", () => { | |
| 6 | 11 | // Create an always-apply rule |
| 7 | 12 | const alwaysApplyRule: RuleWithSource = { |
| 8 | - name: 'Always Apply Rule', | |
| 9 | - rule: 'This rule should always be applied', | |
| 13 | + name: "Always Apply Rule", | |
| 14 | + rule: "This rule should always be applied", | |
| 10 | 15 | alwaysApply: true, |
| 11 | - source: 'rules-block', | |
| 12 | - ruleFile: '.continue/always-apply.md', | |
| 16 | + source: "rules-block", | |
| 17 | + ruleFile: ".continue/always-apply.md", | |
| 13 | 18 | }; |
| 14 | - | |
| 19 | + | |
| 15 | 20 | // Create a colocated rule in a nested directory |
| 16 | 21 | const nestedDirRule: RuleWithSource = { |
| 17 | - name: 'Nested Directory Rule', | |
| 18 | - rule: 'This rule applies to files in the nested directory', | |
| 19 | - source: 'rules-block', | |
| 20 | - ruleFile: 'nested-folder/rules.md', | |
| 22 | + name: "Nested Directory Rule", | |
| 23 | + rule: "This rule applies to files in the nested directory", | |
| 24 | + source: "rules-block", | |
| 25 | + ruleFile: "nested-folder/rules.md", | |
| 21 | 26 | }; |
| 22 | 27 | |
| 23 | - it('should apply alwaysApply rules even with no file references', () => { | |
| 28 | + it("should apply alwaysApply rules even with no file references", () => { | |
| 24 | 29 | // Message with no code blocks or file references |
| 25 | 30 | const simpleMessage: UserChatMessage = { |
| 26 | - id: '1', | |
| 27 | - role: 'user', | |
| 28 | - content: 'Can you help me understand how this works?', | |
| 29 | - createdAt: new Date().toISOString(), | |
| 31 | + role: "user", | |
| 32 | + content: "Can you help me understand how this works?", | |
| 30 | 33 | }; |
| 31 | 34 | |
| 32 | 35 | // Apply rules with no context items |
| 33 | 36 | const applicableRules = getApplicableRules( |
| 34 | - simpleMessage, | |
| 37 | + simpleMessage, | |
| 35 | 38 | [alwaysApplyRule, nestedDirRule], |
| 36 | - [] | |
| 39 | + [], | |
| 37 | 40 | ); |
| 38 | 41 | |
| 39 | 42 | // The always apply rule should be included regardless of context |
| 40 | 43 | expect(applicableRules).toHaveLength(1); |
| 41 | - expect(applicableRules.map(r => r.name)).toContain('Always Apply Rule'); | |
| 42 | - expect(applicableRules.map(r => r.name)).not.toContain('Nested Directory Rule'); | |
| 44 | + expect(applicableRules.map((r) => r.name)).toContain("Always Apply Rule"); | |
| 45 | + expect(applicableRules.map((r) => r.name)).not.toContain( | |
| 46 | + "Nested Directory Rule", | |
| 47 | + ); | |
| 43 | 48 | }); |
| 44 | 49 | |
| 45 | - it('should apply nested directory rules to files in that directory', () => { | |
| 50 | + it("should apply nested directory rules to files in that directory", () => { | |
| 46 | 51 | // Context with a file in the nested directory |
| 47 | 52 | const nestedFileContext: ContextItemWithId = { |
| 48 | - id: 'context1', | |
| 49 | - uri: { type: 'file', value: 'nested-folder/example.ts' }, | |
| 50 | - content: 'export const example = () => {...}', | |
| 51 | - retrievedAt: new Date().toISOString(), | |
| 53 | + id: { providerTitle: "file", itemId: "context1" } as ContextItemId, | |
| 54 | + uri: { type: "file", value: "nested-folder/example.ts" }, | |
| 55 | + content: "export const example = () => {...}", | |
| 56 | + name: "example.ts", | |
| 57 | + description: "Example file", | |
| 52 | 58 | }; |
| 53 | 59 | |
| 54 | 60 | // Apply rules with file context in nested directory |
| 55 | 61 | const applicableRules = getApplicableRules( |
| 56 | 62 | undefined, // No message needed |
| 57 | 63 | [alwaysApplyRule, nestedDirRule], |
| 58 | - [nestedFileContext] | |
| 64 | + [nestedFileContext], | |
| 59 | 65 | ); |
| 60 | 66 | |
| 61 | 67 | // Both rules should apply |
| 62 | 68 | expect(applicableRules).toHaveLength(2); |
| 63 | - expect(applicableRules.map(r => r.name)).toContain('Always Apply Rule'); | |
| 64 | - expect(applicableRules.map(r => r.name)).toContain('Nested Directory Rule'); | |
| 69 | + expect(applicableRules.map((r) => r.name)).toContain("Always Apply Rule"); | |
| 70 | + expect(applicableRules.map((r) => r.name)).toContain( | |
| 71 | + "Nested Directory Rule", | |
| 72 | + ); | |
| 65 | 73 | }); |
| 66 | 74 | |
| 67 | - it('should NOT apply nested directory rules to files outside that directory', () => { | |
| 75 | + it("should NOT apply nested directory rules to files outside that directory", () => { | |
| 68 | 76 | // Context with a file outside the nested directory |
| 69 | 77 | const outsideFileContext: ContextItemWithId = { |
| 70 | - id: 'context2', | |
| 71 | - uri: { type: 'file', value: 'src/utils/helper.ts' }, | |
| 72 | - content: 'export const helper = () => {...}', | |
| 73 | - retrievedAt: new Date().toISOString(), | |
| 78 | + id: { providerTitle: "file", itemId: "context2" } as ContextItemId, | |
| 79 | + uri: { type: "file", value: "src/utils/helper.ts" }, | |
| 80 | + content: "export const helper = () => {...}", | |
| 81 | + name: "helper.ts", | |
| 82 | + description: "Helper utility", | |
| 74 | 83 | }; |
| 75 | 84 | |
| 76 | 85 | // Apply rules with file context outside nested directory |
| 77 | 86 | const applicableRules = getApplicableRules( |
| 78 | 87 | undefined, // No message needed |
| 79 | 88 | [alwaysApplyRule, nestedDirRule], |
| 80 | - [outsideFileContext] | |
| 89 | + [outsideFileContext], | |
| 81 | 90 | ); |
| 82 | 91 | |
| 83 | 92 | // Only the always apply rule should be included |
| 84 | 93 | expect(applicableRules).toHaveLength(1); |
| 85 | - expect(applicableRules.map(r => r.name)).toContain('Always Apply Rule'); | |
| 86 | - expect(applicableRules.map(r => r.name)).not.toContain('Nested Directory Rule'); | |
| 94 | + expect(applicableRules.map((r) => r.name)).toContain("Always Apply Rule"); | |
| 95 | + expect(applicableRules.map((r) => r.name)).not.toContain( | |
| 96 | + "Nested Directory Rule", | |
| 97 | + ); | |
| 87 | 98 | }); |
| 88 | 99 | |
| 89 | - it('should correctly apply rules when a file is mentioned in a message', () => { | |
| 100 | + it("should correctly apply rules when a file is mentioned in a message", () => { | |
| 90 | 101 | // Message with a file reference |
| 91 | 102 | const messageWithFile: UserChatMessage = { |
| 92 | - id: '3', | |
| 93 | - role: 'user', | |
| 94 | - content: 'Can you help with this file?\n```ts nested-folder/example.ts\nexport const example = () => {...}\n```', | |
| 95 | - createdAt: new Date().toISOString(), | |
| 103 | + role: "user", | |
| 104 | + content: | |
| 105 | + "Can you help with this file?\n```ts nested-folder/example.ts\nexport const example = () => {...}\n```", | |
| 96 | 106 | }; |
| 97 | 107 | |
| 98 | 108 | // Apply rules with a message containing a file reference |
| 99 | 109 | const applicableRules = getApplicableRules( |
| 100 | 110 | messageWithFile, |
| 101 | 111 | [alwaysApplyRule, nestedDirRule], |
| 102 | - [] | |
| 112 | + [], | |
| 103 | 113 | ); |
| 104 | 114 | |
| 105 | 115 | // Both rules should apply |
| 106 | 116 | expect(applicableRules).toHaveLength(2); |
| 107 | - expect(applicableRules.map(r => r.name)).toContain('Always Apply Rule'); | |
| 108 | - expect(applicableRules.map(r => r.name)).toContain('Nested Directory Rule'); | |
| 117 | + expect(applicableRules.map((r) => r.name)).toContain("Always Apply Rule"); | |
| 118 | + expect(applicableRules.map((r) => r.name)).toContain( | |
| 119 | + "Nested Directory Rule", | |
| 120 | + ); | |
| 109 | 121 | }); |
| 110 | 122 | |
| 111 | - it('should always apply rules with alwaysApply regardless of message or context', () => { | |
| 123 | + it("should always apply rules with alwaysApply regardless of message or context", () => { | |
| 112 | 124 | // Test with no message or context |
| 113 | - let applicableRules = getApplicableRules( | |
| 114 | - undefined, | |
| 115 | - [alwaysApplyRule], | |
| 116 | - [] | |
| 117 | - ); | |
| 125 | + let applicableRules = getApplicableRules(undefined, [alwaysApplyRule], []); | |
| 118 | 126 | expect(applicableRules).toHaveLength(1); |
| 119 | - expect(applicableRules.map(r => r.name)).toContain('Always Apply Rule'); | |
| 120 | - | |
| 127 | + expect(applicableRules.map((r) => r.name)).toContain("Always Apply Rule"); | |
| 128 | + | |
| 121 | 129 | // Test with message but no file references and no context |
| 122 | 130 | const simpleMessage: UserChatMessage = { |
| 123 | - id: '4', | |
| 124 | - role: 'user', | |
| 125 | - content: 'Hello, can you help me?', | |
| 126 | - createdAt: new Date().toISOString(), | |
| 131 | + role: "user", | |
| 132 | + content: "Hello, can you help me?", | |
| 127 | 133 | }; |
| 128 | - | |
| 129 | - applicableRules = getApplicableRules( | |
| 130 | - simpleMessage, | |
| 131 | - [alwaysApplyRule], | |
| 132 | - [] | |
| 133 | - ); | |
| 134 | + | |
| 135 | + applicableRules = getApplicableRules(simpleMessage, [alwaysApplyRule], []); | |
| 134 | 136 | expect(applicableRules).toHaveLength(1); |
| 135 | - expect(applicableRules.map(r => r.name)).toContain('Always Apply Rule'); | |
| 137 | + expect(applicableRules.map((r) => r.name)).toContain("Always Apply Rule"); | |
| 136 | 138 | }); |
| 137 | -}); | |
| No newline at the end of the file | ||
| 139 | +}); |
modified core/llm/rules/fileProtocolMatching.vitest.ts +25 −23
| @@ -1,53 +1,55 @@ | ||
| 1 | -import { describe, expect, it } from 'vitest'; | |
| 2 | -import { RuleWithSource } from '../..'; | |
| 3 | -import { shouldApplyRule } from './getSystemMessageWithRules'; | |
| 1 | +import { describe, expect, it } from "vitest"; | |
| 2 | +import { RuleWithSource } from "../.."; | |
| 3 | +import { shouldApplyRule } from "./getSystemMessageWithRules"; | |
| 4 | 4 | |
| 5 | -describe('File Path Protocol Matching', () => { | |
| 5 | +describe("File Path Protocol Matching", () => { | |
| 6 | 6 | // Test rule with a file:// protocol in the path - simulating what happens in VSCode |
| 7 | 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', | |
| 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 | 12 | }; |
| 13 | 13 | |
| 14 | - it('should match relative paths with file:// protocol paths', () => { | |
| 14 | + it("should match relative paths with file:// protocol paths", () => { | |
| 15 | 15 | // This is the key test case that would have failed before: |
| 16 | 16 | // A relative path should match with a file:// protocol directory path |
| 17 | - const relativePaths = ['nested-folder/example.py']; | |
| 18 | - | |
| 17 | + const relativePaths = ["nested-folder/example.py"]; | |
| 18 | + | |
| 19 | 19 | // Before the fix, this would have failed because the string comparison |
| 20 | - // would be checking if 'nested-folder/example.py' starts with | |
| 20 | + // would be checking if 'nested-folder/example.py' starts with | |
| 21 | 21 | // 'file:///Users/user/project/nested-folder/' |
| 22 | 22 | expect(shouldApplyRule(ruleWithFileProtocol, relativePaths)).toBe(true); |
| 23 | 23 | }); |
| 24 | 24 | |
| 25 | - it('should match when directory name appears in the path', () => { | |
| 25 | + it("should match when directory name appears in the path", () => { | |
| 26 | 26 | // Even with a more complex relative path, it should match as long as |
| 27 | 27 | // it contains the right directory structure |
| 28 | - const nestedPaths = ['src/components/nested-folder/example.py']; | |
| 28 | + const nestedPaths = ["src/components/nested-folder/example.py"]; | |
| 29 | 29 | expect(shouldApplyRule(ruleWithFileProtocol, nestedPaths)).toBe(true); |
| 30 | 30 | }); |
| 31 | 31 | |
| 32 | - it('should not match when directory name is not in the path', () => { | |
| 32 | + it("should not match when directory name is not in the path", () => { | |
| 33 | 33 | // Should not match when the path doesn't contain the directory name |
| 34 | - const unrelatedPaths = ['src/components/other-folder/example.py']; | |
| 34 | + const unrelatedPaths = ["src/components/other-folder/example.py"]; | |
| 35 | 35 | expect(shouldApplyRule(ruleWithFileProtocol, unrelatedPaths)).toBe(false); |
| 36 | 36 | }); |
| 37 | 37 | |
| 38 | - it('should match absolute paths with the same protocol', () => { | |
| 38 | + it("should match absolute paths with the same protocol", () => { | |
| 39 | 39 | // Should also work with absolute paths |
| 40 | - const absolutePaths = ['file:///Users/user/project/nested-folder/example.py']; | |
| 40 | + const absolutePaths = [ | |
| 41 | + "file:///Users/user/project/nested-folder/example.py", | |
| 42 | + ]; | |
| 41 | 43 | expect(shouldApplyRule(ruleWithFileProtocol, absolutePaths)).toBe(true); |
| 42 | 44 | }); |
| 43 | 45 | |
| 44 | - it('should handle mixed path types in the same call', () => { | |
| 46 | + it("should handle mixed path types in the same call", () => { | |
| 45 | 47 | // Should handle a mix of relative and absolute paths |
| 46 | 48 | const mixedPaths = [ |
| 47 | - 'nested-folder/example.py', | |
| 48 | - 'file:///Users/user/project/nested-folder/other.py', | |
| 49 | - 'src/unrelated/file.py' | |
| 49 | + "nested-folder/example.py", | |
| 50 | + "file:///Users/user/project/nested-folder/other.py", | |
| 51 | + "src/unrelated/file.py", | |
| 50 | 52 | ]; |
| 51 | 53 | expect(shouldApplyRule(ruleWithFileProtocol, mixedPaths)).toBe(true); |
| 52 | 54 | }); |
| 53 | -}); | |
| No newline at the end of the file | ||
| 55 | +}); |
modified core/llm/rules/implicitGlobalRules.vitest.ts +72 −65
| @@ -1,129 +1,136 @@ | ||
| 1 | -import { describe, expect, it } from 'vitest'; | |
| 2 | -import { ContextItemWithId, RuleWithSource, UserChatMessage } from '../..'; | |
| 3 | -import { getApplicableRules } from './getSystemMessageWithRules'; | |
| 4 | - | |
| 5 | -describe('Implicit global rules application', () => { | |
| 1 | +import { describe, expect, it } from "vitest"; | |
| 2 | +import { RuleWithSource, UserChatMessage } from "../.."; | |
| 3 | +import { getApplicableRules } from "./getSystemMessageWithRules"; | |
| 4 | + | |
| 5 | +describe("Implicit global rules application", () => { | |
| 6 | 6 | // Create a rule with no alwaysApply and no globs - should behave like a global rule |
| 7 | 7 | const implicitGlobalRule: RuleWithSource = { |
| 8 | - name: 'Implicit Global Rule', | |
| 9 | - rule: 'This rule should be applied to all messages (implicit global)', | |
| 10 | - source: 'rules-block', | |
| 11 | - ruleFile: '.continue/global-rule.md', | |
| 8 | + name: "Implicit Global Rule", | |
| 9 | + rule: "This rule should be applied to all messages (implicit global)", | |
| 10 | + source: "rules-block", | |
| 11 | + ruleFile: ".continue/global-rule.md", | |
| 12 | 12 | // No alwaysApply specified |
| 13 | 13 | // No globs specified |
| 14 | 14 | }; |
| 15 | - | |
| 15 | + | |
| 16 | 16 | // Create a rule with explicit alwaysApply: true for comparison |
| 17 | 17 | const explicitGlobalRule: RuleWithSource = { |
| 18 | - name: 'Explicit Global Rule', | |
| 19 | - rule: 'This rule should always be applied (explicit global)', | |
| 18 | + name: "Explicit Global Rule", | |
| 19 | + rule: "This rule should always be applied (explicit global)", | |
| 20 | 20 | alwaysApply: true, |
| 21 | - source: 'rules-block', | |
| 22 | - ruleFile: '.continue/explicit-global.md', | |
| 21 | + source: "rules-block", | |
| 22 | + ruleFile: ".continue/explicit-global.md", | |
| 23 | 23 | }; |
| 24 | - | |
| 24 | + | |
| 25 | 25 | // Create a colocated rule in a nested directory |
| 26 | 26 | const nestedDirRule: RuleWithSource = { |
| 27 | - name: 'Nested Directory Rule', | |
| 28 | - rule: 'This rule applies to files in the nested directory', | |
| 29 | - source: 'rules-block', | |
| 30 | - ruleFile: 'nested-folder/rules.md', | |
| 27 | + name: "Nested Directory Rule", | |
| 28 | + rule: "This rule applies to files in the nested directory", | |
| 29 | + source: "rules-block", | |
| 30 | + ruleFile: "nested-folder/rules.md", | |
| 31 | 31 | }; |
| 32 | 32 | |
| 33 | - it('should apply rules with no alwaysApply and no globs to all messages, even with no file references', () => { | |
| 33 | + it("should apply rules with no alwaysApply and no globs to all messages, even with no file references", () => { | |
| 34 | 34 | // Message with no code blocks or file references |
| 35 | 35 | const simpleMessage: UserChatMessage = { |
| 36 | - id: '1', | |
| 37 | - role: 'user', | |
| 38 | - content: 'Can you help me understand how this works?', | |
| 39 | - createdAt: new Date().toISOString(), | |
| 36 | + role: "user", | |
| 37 | + content: "Can you help me understand how this works?", | |
| 40 | 38 | }; |
| 41 | 39 | |
| 42 | 40 | // Apply rules with no context items |
| 43 | 41 | const applicableRules = getApplicableRules( |
| 44 | - simpleMessage, | |
| 42 | + simpleMessage, | |
| 45 | 43 | [implicitGlobalRule, explicitGlobalRule, nestedDirRule], |
| 46 | - [] | |
| 44 | + [], | |
| 47 | 45 | ); |
| 48 | 46 | |
| 49 | 47 | // Both global rules should be included regardless of context |
| 50 | 48 | expect(applicableRules).toHaveLength(2); |
| 51 | - expect(applicableRules.map(r => r.name)).toContain('Implicit Global Rule'); | |
| 52 | - expect(applicableRules.map(r => r.name)).toContain('Explicit Global Rule'); | |
| 53 | - expect(applicableRules.map(r => r.name)).not.toContain('Nested Directory Rule'); | |
| 49 | + expect(applicableRules.map((r) => r.name)).toContain( | |
| 50 | + "Implicit Global Rule", | |
| 51 | + ); | |
| 52 | + expect(applicableRules.map((r) => r.name)).toContain( | |
| 53 | + "Explicit Global Rule", | |
| 54 | + ); | |
| 55 | + expect(applicableRules.map((r) => r.name)).not.toContain( | |
| 56 | + "Nested Directory Rule", | |
| 57 | + ); | |
| 54 | 58 | }); |
| 55 | 59 | |
| 56 | - it('should treat root-level rules with no globs as global rules', () => { | |
| 60 | + it("should treat root-level rules with no globs as global rules", () => { | |
| 57 | 61 | // Root rule with no globs |
| 58 | 62 | const rootNoGlobsRule: RuleWithSource = { |
| 59 | - name: 'Root No Globs Rule', | |
| 60 | - rule: 'This is a root-level rule with no globs', | |
| 61 | - source: 'rules-block', | |
| 62 | - ruleFile: '.continue/rules.md', | |
| 63 | + name: "Root No Globs Rule", | |
| 64 | + rule: "This is a root-level rule with no globs", | |
| 65 | + source: "rules-block", | |
| 66 | + ruleFile: ".continue/rules.md", | |
| 63 | 67 | // No alwaysApply, no globs |
| 64 | 68 | }; |
| 65 | - | |
| 69 | + | |
| 66 | 70 | // Test with no file context |
| 67 | 71 | const applicableRules = getApplicableRules( |
| 68 | 72 | undefined, |
| 69 | 73 | [rootNoGlobsRule], |
| 70 | - [] | |
| 74 | + [], | |
| 71 | 75 | ); |
| 72 | - | |
| 76 | + | |
| 73 | 77 | // Should include the rule even with no context |
| 74 | 78 | expect(applicableRules).toHaveLength(1); |
| 75 | - expect(applicableRules[0].name).toBe('Root No Globs Rule'); | |
| 79 | + expect(applicableRules[0].name).toBe("Root No Globs Rule"); | |
| 76 | 80 | }); |
| 77 | 81 | |
| 78 | - it('should apply implicit global rules alongside file-specific rules', () => { | |
| 82 | + it("should apply implicit global rules alongside file-specific rules", () => { | |
| 79 | 83 | // File-specific message |
| 80 | 84 | const messageWithFile: UserChatMessage = { |
| 81 | - id: '2', | |
| 82 | - role: 'user', | |
| 83 | - content: 'Can you help with this file?\n```ts nested-folder/example.ts\nexport const example = () => {...}\n```', | |
| 84 | - createdAt: new Date().toISOString(), | |
| 85 | + role: "user", | |
| 86 | + content: | |
| 87 | + "Can you help with this file?\n```ts nested-folder/example.ts\nexport const example = () => {...}\n```", | |
| 85 | 88 | }; |
| 86 | - | |
| 89 | + | |
| 87 | 90 | // Apply all rule types together |
| 88 | 91 | const applicableRules = getApplicableRules( |
| 89 | 92 | messageWithFile, |
| 90 | 93 | [implicitGlobalRule, explicitGlobalRule, nestedDirRule], |
| 91 | - [] | |
| 94 | + [], | |
| 92 | 95 | ); |
| 93 | - | |
| 96 | + | |
| 94 | 97 | // Should include all rules |
| 95 | 98 | expect(applicableRules).toHaveLength(3); |
| 96 | - expect(applicableRules.map(r => r.name)).toContain('Implicit Global Rule'); | |
| 97 | - expect(applicableRules.map(r => r.name)).toContain('Explicit Global Rule'); | |
| 98 | - expect(applicableRules.map(r => r.name)).toContain('Nested Directory Rule'); | |
| 99 | + expect(applicableRules.map((r) => r.name)).toContain( | |
| 100 | + "Implicit Global Rule", | |
| 101 | + ); | |
| 102 | + expect(applicableRules.map((r) => r.name)).toContain( | |
| 103 | + "Explicit Global Rule", | |
| 104 | + ); | |
| 105 | + expect(applicableRules.map((r) => r.name)).toContain( | |
| 106 | + "Nested Directory Rule", | |
| 107 | + ); | |
| 99 | 108 | }); |
| 100 | - | |
| 101 | - it('should apply implicit global rules for first message without code', () => { | |
| 109 | + | |
| 110 | + it("should apply implicit global rules for first message without code", () => { | |
| 102 | 111 | // Simple first message |
| 103 | 112 | const firstMessage: UserChatMessage = { |
| 104 | - id: '3', | |
| 105 | - role: 'user', | |
| 106 | - content: 'Hello, can you help me?', | |
| 107 | - createdAt: new Date().toISOString(), | |
| 113 | + role: "user", | |
| 114 | + content: "Hello, can you help me?", | |
| 108 | 115 | }; |
| 109 | - | |
| 116 | + | |
| 110 | 117 | // Assistant rules that should always apply |
| 111 | 118 | const assistantRule: RuleWithSource = { |
| 112 | - name: 'Assistant Guidelines', | |
| 113 | - rule: 'SOLID Design Principles - Coding Assistant Guidelines', | |
| 114 | - source: 'rules-block', | |
| 115 | - ruleFile: '.continue/rules.md', | |
| 119 | + name: "Assistant Guidelines", | |
| 120 | + rule: "SOLID Design Principles - Coding Assistant Guidelines", | |
| 121 | + source: "rules-block", | |
| 122 | + ruleFile: ".continue/rules.md", | |
| 116 | 123 | // No alwaysApply, no globs - should still apply |
| 117 | 124 | }; |
| 118 | - | |
| 125 | + | |
| 119 | 126 | const applicableRules = getApplicableRules( |
| 120 | 127 | firstMessage, |
| 121 | 128 | [assistantRule], |
| 122 | - [] | |
| 129 | + [], | |
| 123 | 130 | ); |
| 124 | - | |
| 131 | + | |
| 125 | 132 | // Should include the assistant rule even though there's no code |
| 126 | 133 | expect(applicableRules).toHaveLength(1); |
| 127 | - expect(applicableRules[0].name).toBe('Assistant Guidelines'); | |
| 134 | + expect(applicableRules[0].name).toBe("Assistant Guidelines"); | |
| 128 | 135 | }); |
| 129 | -}); | |
| No newline at the end of the file | ||
| 136 | +}); |
modified core/llm/rules/nestedDirectoryRules.vitest.ts +21 −13
| @@ -1,5 +1,10 @@ | ||
| 1 | 1 | import { describe, expect, it } from "vitest"; |
| 2 | -import { ContextItemWithId, RuleWithSource, UserChatMessage } from "../.."; | |
| 2 | +import { | |
| 3 | + ContextItemId, | |
| 4 | + ContextItemWithId, | |
| 5 | + RuleWithSource, | |
| 6 | + UserChatMessage, | |
| 7 | +} from "../.."; | |
| 3 | 8 | import { getApplicableRules } from "./getSystemMessageWithRules"; |
| 4 | 9 | |
| 5 | 10 | describe("Nested directory rules application", () => { |
| @@ -23,13 +28,14 @@ | ||
| 23 | 28 | it("should apply nested directory rules to files in that directory", () => { |
| 24 | 29 | // Create a context with a file in the nested directory |
| 25 | 30 | const nestedFileContext: ContextItemWithId = { |
| 26 | - id: "nested1", | |
| 31 | + id: { providerTitle: "file", itemId: "nested1" } as ContextItemId, | |
| 27 | 32 | uri: { |
| 28 | 33 | type: "file", |
| 29 | 34 | value: "manual-testing-sandbox/nested-folder/hellonested.py", |
| 30 | 35 | }, |
| 31 | 36 | content: 'print("Hello nested")', |
| 32 | - retrievedAt: new Date().toISOString(), | |
| 37 | + name: "hellonested.py", | |
| 38 | + description: "Nested file", | |
| 33 | 39 | }; |
| 34 | 40 | |
| 35 | 41 | // Apply rules with the nested file context |
| @@ -48,11 +54,9 @@ | ||
| 48 | 54 | it("should also work with file references in messages", () => { |
| 49 | 55 | // Message with a file reference in the nested directory |
| 50 | 56 | const messageWithNestedFile: UserChatMessage = { |
| 51 | - id: "msg1", | |
| 52 | 57 | role: "user", |
| 53 | 58 | content: |
| 54 | 59 | 'Can you explain this file?\n```python manual-testing-sandbox/nested-folder/hellonested.py\nprint("Hello nested")\n```', |
| 55 | - createdAt: new Date().toISOString(), | |
| 56 | 60 | }; |
| 57 | 61 | |
| 58 | 62 | // Apply rules with the message containing a nested file reference |
| @@ -71,10 +75,11 @@ | ||
| 71 | 75 | it("should NOT apply nested directory rules to files outside that directory", () => { |
| 72 | 76 | // Context with a file outside the nested directory |
| 73 | 77 | const outsideFileContext: ContextItemWithId = { |
| 74 | - id: "outside1", | |
| 78 | + id: { providerTitle: "file", itemId: "outside1" } as ContextItemId, | |
| 75 | 79 | uri: { type: "file", value: "src/utils/helper.ts" }, |
| 76 | 80 | content: "export const helper = () => {...}", |
| 77 | - retrievedAt: new Date().toISOString(), | |
| 81 | + name: "helper.ts", | |
| 82 | + description: "Helper file", | |
| 78 | 83 | }; |
| 79 | 84 | |
| 80 | 85 | // Apply rules with file context outside nested directory |
| @@ -112,26 +117,29 @@ | ||
| 112 | 117 | |
| 113 | 118 | // A file in src/ |
| 114 | 119 | const srcPythonFileContext: ContextItemWithId = { |
| 115 | - id: "python1", | |
| 120 | + id: { providerTitle: "file", itemId: "python1" } as ContextItemId, | |
| 116 | 121 | uri: { type: "file", value: "src/pythonfile.py" }, |
| 117 | 122 | content: 'print("Hello")', |
| 118 | - retrievedAt: new Date().toISOString(), | |
| 123 | + name: "pythonfile.py", | |
| 124 | + description: "Python file in src", | |
| 119 | 125 | }; |
| 120 | 126 | |
| 121 | 127 | // A file in utils/ |
| 122 | 128 | const utilsPythonFileContext: ContextItemWithId = { |
| 123 | - id: "python2", | |
| 129 | + id: { providerTitle: "file", itemId: "python2" } as ContextItemId, | |
| 124 | 130 | uri: { type: "file", value: "utils/pythonfile.py" }, |
| 125 | 131 | content: 'print("Hello")', |
| 126 | - retrievedAt: new Date().toISOString(), | |
| 132 | + name: "pythonfile.py", | |
| 133 | + description: "Python file in utils", | |
| 127 | 134 | }; |
| 128 | 135 | |
| 129 | 136 | // A file in manual-testing-sandbox/ |
| 130 | 137 | const manualTestingPythonFileContext: ContextItemWithId = { |
| 131 | - id: "python3", | |
| 138 | + id: { providerTitle: "file", itemId: "python3" } as ContextItemId, | |
| 132 | 139 | uri: { type: "file", value: "manual-testing-sandbox/pythonfile.py" }, |
| 133 | 140 | content: 'print("Hello")', |
| 134 | - retrievedAt: new Date().toISOString(), | |
| 141 | + name: "pythonfile.py", | |
| 142 | + description: "Python file in manual-testing-sandbox", | |
| 135 | 143 | }; |
| 136 | 144 | |
| 137 | 145 | // Apply src rule to src file - should match |