Elffuss BraidHub

kikocis/continue public

update tests
Changesetde41b37de6c35fa44d1929e77ef8539a19675f64ec63f004ccc54e1aec137cd7
AuthorPatrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-05-22 10:17 -07:00
CommitterPatrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-05-22 10:17 -07:00
Parents4d749ae79aba

Browse the files at this changeset

2 files changed

modified core/tools/implementations/createRuleBlock.test.ts +12 −58
@@ -1,4 +1,4 @@
1-import * as YAML from "yaml";
1+import { parseMarkdownRule } from "../../config/markdown/parseMarkdownRule";
22 import { createRuleBlockImpl } from "./createRuleBlock";
33
44 // Mock the extras parameter with necessary functions
@@ -17,36 +17,6 @@
1717 jest.clearAllMocks();
1818 });
1919
20- it("should create a basic rule with name and rule content", async () => {
21- const args = {
22- name: "Test Rule",
23- rule: "Always write tests",
24- };
25-
26- const result = await createRuleBlockImpl(args, mockExtras as any);
27-
28- // Verify that writeFile was called
29- expect(mockIde.writeFile).toHaveBeenCalled();
30-
31- // Verify the file name
32- const fileUri = mockIde.writeFile.mock.calls[0][0];
33- expect(fileUri).toContain("test-rule.md");
34-
35- // Get the content
36- const fileContent = mockIde.writeFile.mock.calls[0][1];
37-
38- // Verify the content structure
39- expect(fileContent).toContain("---");
40- expect(fileContent).toContain("# Test Rule");
41- expect(fileContent).toContain("Always write tests");
42-
43- // Should have empty frontmatter - it will be "{}" not "" due to how YAML.stringify works with empty objects
44- const parts = fileContent.split(/^---\s*$/m);
45- expect(parts.length).toBeGreaterThanOrEqual(3);
46- const frontmatterStr = parts[1].trim();
47- expect(frontmatterStr === "" || frontmatterStr === "{}").toBeTruthy();
48- });
49-
5020 it("should create a rule with glob pattern", async () => {
5121 const args = {
5222 name: "TypeScript Rule",
@@ -56,22 +26,16 @@
5626
5727 await createRuleBlockImpl(args, mockExtras as any);
5828
59- // Get the content
6029 const fileContent = mockIde.writeFile.mock.calls[0][1];
6130
62- // Parse the frontmatter
63- const parts = fileContent.split(/^---\s*$/m);
64- const frontmatterStr = parts[1].trim();
65- const frontmatter = YAML.parse(frontmatterStr);
31+ const { frontmatter, markdown } = parseMarkdownRule(fileContent);
6632
67- // Verify the frontmatter contains globs
6833 expect(frontmatter).toEqual({
6934 globs: "**/*.{ts,tsx}",
7035 });
7136
72- // Verify the content has the rule
73- expect(fileContent).toContain("# TypeScript Rule");
74- expect(fileContent).toContain("Use interfaces for object shapes");
37+ expect(markdown).toContain("# TypeScript Rule");
38+ expect(markdown).toContain("Use interfaces for object shapes");
7539 });
7640
7741 it("should create a filename based on sanitized rule name", async () => {
@@ -82,12 +46,11 @@
8246
8347 await createRuleBlockImpl(args, mockExtras as any);
8448
85- // Check that the filename is sanitized
8649 const fileUri = mockIde.writeFile.mock.calls[0][0];
8750 expect(fileUri).toContain("special-chracters-spaces.md");
8851 });
8952
90- it("should include description in frontmatter and content", async () => {
53+ it("should create a rule with description pattern", async () => {
9154 const args = {
9255 name: "Description Test",
9356 rule: "This is the rule content",
@@ -96,23 +59,16 @@
9659
9760 await createRuleBlockImpl(args, mockExtras as any);
9861
99- // Get the content
10062 const fileContent = mockIde.writeFile.mock.calls[0][1];
10163
102- // Parse the frontmatter
103- const parts = fileContent.split(/^---\s*$/m);
104- const frontmatterStr = parts[1].trim();
105- const frontmatter = YAML.parse(frontmatterStr);
64+ const { frontmatter, markdown } = parseMarkdownRule(fileContent);
10665
107- // Verify the frontmatter contains description
10866 expect(frontmatter).toEqual({
10967 description: "This is a detailed explanation of the rule",
11068 });
11169
112- // Verify the content structure includes description before rule
113- expect(fileContent).toContain("# Description Test");
114- expect(fileContent).toContain("This is a detailed explanation of the rule");
115- expect(fileContent).toContain("This is the rule content");
70+ expect(markdown).toContain("# Description Test");
71+ expect(markdown).toContain("This is the rule content");
11672 });
11773
11874 it("should include both globs and description in frontmatter", async () => {
@@ -125,18 +81,16 @@
12581
12682 await createRuleBlockImpl(args, mockExtras as any);
12783
128- // Get the content
12984 const fileContent = mockIde.writeFile.mock.calls[0][1];
13085
131- // Parse the frontmatter
132- const parts = fileContent.split(/^---\s*$/m);
133- const frontmatterStr = parts[1].trim();
134- const frontmatter = YAML.parse(frontmatterStr);
86+ const { frontmatter, markdown } = parseMarkdownRule(fileContent);
13587
136- // Verify the frontmatter contains both description and globs
13788 expect(frontmatter).toEqual({
13889 description: "This rule enforces our team standards",
13990 globs: "**/*.js",
14091 });
92+
93+ expect(markdown).toContain("# Complete Rule");
94+ expect(markdown).toContain("Follow this standard");
14195 });
14296 });
modified core/tools/implementations/createRuleBlock.ts +1 −1
@@ -5,8 +5,8 @@
55 export interface CreateRuleBlockArgs {
66 name: string;
77 rule: string;
8+ description: string;
89 globs?: string;
9- description?: string;
1010 }
1111
1212 export const createRuleBlockImpl: ToolImpl = async (