fix formatting

This commit is contained in:
Joe Danziger
2025-05-11 13:32:42 -04:00
parent d28170ee03
commit 7169296c24
12 changed files with 279 additions and 133 deletions

View File

@@ -2,32 +2,37 @@ import fs from 'fs';
import path from 'path';
describe('Cursor Profile Initialization Functionality', () => {
let cursorProfileContent;
let cursorProfileContent;
beforeAll(() => {
const cursorJsPath = path.join(process.cwd(), 'scripts', 'profiles', 'cursor.js');
cursorProfileContent = fs.readFileSync(cursorJsPath, 'utf8');
});
beforeAll(() => {
const cursorJsPath = path.join(
process.cwd(),
'scripts',
'profiles',
'cursor.js'
);
cursorProfileContent = fs.readFileSync(cursorJsPath, 'utf8');
});
test('cursor.js exports correct brandName and rulesDir', () => {
expect(cursorProfileContent).toContain("const brandName = 'Cursor'");
expect(cursorProfileContent).toContain("const rulesDir = '.cursor/rules'");
});
test('cursor.js exports correct brandName and rulesDir', () => {
expect(cursorProfileContent).toContain("const brandName = 'Cursor'");
expect(cursorProfileContent).toContain("const rulesDir = '.cursor/rules'");
});
test('cursor.js preserves .mdc filenames in fileMap', () => {
expect(cursorProfileContent).toContain('fileMap = {');
// Should NOT contain any .md mapping
expect(cursorProfileContent).not.toMatch(/\.md'/);
});
test('cursor.js preserves .mdc filenames in fileMap', () => {
expect(cursorProfileContent).toContain('fileMap = {');
// Should NOT contain any .md mapping
expect(cursorProfileContent).not.toMatch(/\.md'/);
});
test('cursor.js contains tool naming logic and global replacements', () => {
expect(cursorProfileContent).toContain('edit_file');
expect(cursorProfileContent).toContain('search tool');
expect(cursorProfileContent).not.toContain('apply_diff');
expect(cursorProfileContent).not.toContain('search_files tool');
});
test('cursor.js contains tool naming logic and global replacements', () => {
expect(cursorProfileContent).toContain('edit_file');
expect(cursorProfileContent).toContain('search tool');
expect(cursorProfileContent).not.toContain('apply_diff');
expect(cursorProfileContent).not.toContain('search_files tool');
});
test('cursor.js contains correct documentation URL logic', () => {
expect(cursorProfileContent).toContain('docs.cursor.com');
});
test('cursor.js contains correct documentation URL logic', () => {
expect(cursorProfileContent).toContain('docs.cursor.com');
});
});

View File

@@ -0,0 +1,76 @@
// Integration tests for rules transformer functions in MCP server context
import { jest } from '@jest/globals';
import {
convertAllRulesToBrandRules,
removeBrandRules
} from '../../../scripts/modules/rule-transformer.js';
import * as windsurfProfile from '../../../scripts/profiles/windsurf.js';
// Mock fs functions as in direct-functions.test.js
const mockExistsSync = jest.fn();
const mockWriteFileSync = jest.fn();
const mockReadFileSync = jest.fn();
const mockUnlinkSync = jest.fn();
const mockMkdirSync = jest.fn();
const mockRmSync = jest.fn();
const mockReaddirSync = jest.fn();
jest.mock('fs', () => ({
existsSync: mockExistsSync,
writeFileSync: mockWriteFileSync,
readFileSync: mockReadFileSync,
unlinkSync: mockUnlinkSync,
mkdirSync: mockMkdirSync,
rmSync: mockRmSync,
readdirSync: mockReaddirSync
}));
describe('rules transformer', () => {
const mockProjectDir = '/mock/project/root';
beforeEach(() => {
jest.clearAllMocks();
});
test('should convert all Cursor rules to windsurf brand rules', () => {
// Arrange
mockExistsSync.mockImplementation((p) => {
// Simulate that the cursor rules directory exists
if (p === '/mock/project/root/assets/rules') return true;
// Simulate that the brand rules directory does not exist initially
if (p === '/mock/project/root/.windsurf/rules') return false;
return false;
});
mockReadFileSync.mockImplementation((p) => 'mock rule content');
mockReaddirSync.mockImplementation((dir) => ['sample-rule.mdc']);
mockWriteFileSync.mockImplementation(() => {});
mockMkdirSync.mockImplementation(() => {});
// Act
const result = convertAllRulesToBrandRules(mockProjectDir, windsurfProfile);
// Assert
expect(result.success).toBeGreaterThanOrEqual(0);
expect(mockWriteFileSync).toHaveBeenCalled();
expect(mockMkdirSync).toHaveBeenCalled();
});
test('should remove windsurf brand rules', () => {
// Arrange
mockExistsSync.mockImplementation((p) => {
// Simulate that the brand rules directory exists
if (p === '/mock/project/root/.windsurf/rules') return true;
return false;
});
mockRmSync.mockImplementation(() => {});
mockUnlinkSync.mockImplementation(() => {});
mockReaddirSync.mockImplementation((dir) => []);
// Act
const removed = removeBrandRules(mockProjectDir, windsurfProfile);
// Assert
expect(removed).toBe(true);
expect(mockRmSync).toHaveBeenCalled();
});
});

View File

@@ -22,20 +22,34 @@ describe('Roo Files Inclusion in Package', () => {
const rooJsContent = fs.readFileSync(rooJsPath, 'utf8');
// Check for the main handler function
expect(rooJsContent.includes("onAddBrandRules(targetDir)")).toBe(true);
expect(rooJsContent.includes('onAddBrandRules(targetDir)')).toBe(true);
// Check for general recursive copy of assets/roocode
expect(rooJsContent.includes("copyRecursiveSync(sourceDir, targetDir)")).toBe(true);
expect(
rooJsContent.includes('copyRecursiveSync(sourceDir, targetDir)')
).toBe(true);
// Check for .roomodes file copying logic (source and destination paths)
expect(rooJsContent.includes("path.join(sourceDir, '.roomodes')")).toBe(true);
expect(rooJsContent.includes("path.join(targetDir, '.roomodes')")).toBe(true);
expect(rooJsContent.includes("path.join(sourceDir, '.roomodes')")).toBe(
true
);
expect(rooJsContent.includes("path.join(targetDir, '.roomodes')")).toBe(
true
);
// Check for mode-specific rule file copying logic
expect(rooJsContent.includes("for (const mode of rooModes)")).toBe(true);
expect(rooJsContent.includes("path.join(rooModesDir, `rules-${mode}`, `${mode}-rules`)")).toBe(true);
expect(rooJsContent.includes("path.join(targetDir, '.roo', `rules-${mode}`, `${mode}-rules`)")).toBe(true);
expect(rooJsContent.includes('for (const mode of rooModes)')).toBe(true);
expect(
rooJsContent.includes(
'path.join(rooModesDir, `rules-${mode}`, `${mode}-rules`)'
)
).toBe(true);
expect(
rooJsContent.includes(
"path.join(targetDir, '.roo', `rules-${mode}`, `${mode}-rules`)"
)
).toBe(true);
// Check for definition of rooModes array and all modes
const rooModesArrayRegex = /const rooModes\s*=\s*\[([^\]]+)\]\s*;?/;
const rooModesMatch = rooJsContent.match(rooModesArrayRegex);

View File

@@ -19,26 +19,37 @@ describe('Roo Profile Initialization Functionality', () => {
expect(rooProfileContent).toContain(
'copyRecursiveSync(sourceDir, targetDir)'
);
expect(rooProfileContent).toContain("path.resolve(__dirname, '../../assets/roocode')"); // Verifies sourceDir definition
expect(rooProfileContent).toContain(
"path.resolve(__dirname, '../../assets/roocode')"
); // Verifies sourceDir definition
// Check for the loop that processes rooModes
expect(rooProfileContent).toContain('for (const mode of rooModes)');
// Check for creation of mode-specific rule directories (e.g., .roo/rules-architect)
// This is the line: if (!fs.existsSync(destDir)) fs.mkdirSync(destDir, { recursive: true });
expect(rooProfileContent).toContain("fs.mkdirSync(destDir, { recursive: true });");
expect(rooProfileContent).toContain("const destDir = path.dirname(dest);"); // part of the same logic block
expect(rooProfileContent).toContain(
'fs.mkdirSync(destDir, { recursive: true });'
);
expect(rooProfileContent).toContain('const destDir = path.dirname(dest);'); // part of the same logic block
});
test('roo.js profile copies .roomodes file via onAddBrandRules', () => {
expect(rooProfileContent).toContain('onAddBrandRules(targetDir)');
// Check for the specific .roomodes copy logic
expect(rooProfileContent).toContain('fs.copyFileSync(roomodesSrc, roomodesDest);');
expect(rooProfileContent).toContain("const roomodesSrc = path.join(sourceDir, '.roomodes');");
expect(rooProfileContent).toContain("const roomodesDest = path.join(targetDir, '.roomodes');");
expect(rooProfileContent).toContain("path.resolve(__dirname, '../../assets/roocode')"); // sourceDir for roomodesSrc
expect(rooProfileContent).toContain(
'fs.copyFileSync(roomodesSrc, roomodesDest);'
);
expect(rooProfileContent).toContain(
"const roomodesSrc = path.join(sourceDir, '.roomodes');"
);
expect(rooProfileContent).toContain(
"const roomodesDest = path.join(targetDir, '.roomodes');"
);
expect(rooProfileContent).toContain(
"path.resolve(__dirname, '../../assets/roocode')"
); // sourceDir for roomodesSrc
});
test('roo.js profile copies mode-specific rule files via onAddBrandRules', () => {
@@ -47,11 +58,17 @@ describe('Roo Profile Initialization Functionality', () => {
// Check for the specific mode rule file copy logic
expect(rooProfileContent).toContain('fs.copyFileSync(src, dest);');
// Check source path construction for mode rules
expect(rooProfileContent).toContain("const src = path.join(rooModesDir, `rules-${mode}`, `${mode}-rules`);");
expect(rooProfileContent).toContain(
'const src = path.join(rooModesDir, `rules-${mode}`, `${mode}-rules`);'
);
// Check destination path construction for mode rules
expect(rooProfileContent).toContain("const dest = path.join(targetDir, '.roo', `rules-${mode}`, `${mode}-rules`);");
expect(rooProfileContent).toContain("const rooModesDir = path.join(sourceDir, '.roo');"); // part of src path
expect(rooProfileContent).toContain(
"const dest = path.join(targetDir, '.roo', `rules-${mode}`, `${mode}-rules`);"
);
expect(rooProfileContent).toContain(
"const rooModesDir = path.join(sourceDir, '.roo');"
); // part of src path
});
});

View File

@@ -2,41 +2,41 @@ import fs from 'fs';
import path from 'path';
describe('Rules Files Inclusion in Package', () => {
test('package.json includes assets/** in the "files" array for rules files', () => {
const packageJsonPath = path.join(process.cwd(), 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
expect(packageJson.files).toContain('assets/**');
});
test('package.json includes assets/** in the "files" array for rules files', () => {
const packageJsonPath = path.join(process.cwd(), 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
expect(packageJson.files).toContain('assets/**');
});
test('all rules files exist in assets/rules directory', () => {
const rulesDir = path.join(process.cwd(), 'assets', 'rules');
const expectedFiles = [
'ai_providers.mdc',
'ai_services.mdc',
'architecture.mdc',
'changeset.mdc',
'commands.mdc',
'cursor_rules.mdc',
'dependencies.mdc',
'dev_workflow.mdc',
'glossary.mdc',
'mcp.mdc',
'new_features.mdc',
'self_improve.mdc',
'taskmaster.mdc',
'tasks.mdc',
'tests.mdc',
'ui.mdc',
'utilities.mdc',
];
for (const file of expectedFiles) {
expect(fs.existsSync(path.join(rulesDir, file))).toBe(true);
}
});
test('all rules files exist in assets/rules directory', () => {
const rulesDir = path.join(process.cwd(), 'assets', 'rules');
const expectedFiles = [
'ai_providers.mdc',
'ai_services.mdc',
'architecture.mdc',
'changeset.mdc',
'commands.mdc',
'cursor_rules.mdc',
'dependencies.mdc',
'dev_workflow.mdc',
'glossary.mdc',
'mcp.mdc',
'new_features.mdc',
'self_improve.mdc',
'taskmaster.mdc',
'tasks.mdc',
'tests.mdc',
'ui.mdc',
'utilities.mdc'
];
for (const file of expectedFiles) {
expect(fs.existsSync(path.join(rulesDir, file))).toBe(true);
}
});
test('assets/rules directory is not empty', () => {
const rulesDir = path.join(process.cwd(), 'assets', 'rules');
const files = fs.readdirSync(rulesDir).filter(f => !f.startsWith('.'));
expect(files.length).toBeGreaterThan(0);
});
test('assets/rules directory is not empty', () => {
const rulesDir = path.join(process.cwd(), 'assets', 'rules');
const files = fs.readdirSync(rulesDir).filter((f) => !f.startsWith('.'));
expect(files.length).toBeGreaterThan(0);
});
});

View File

@@ -2,35 +2,42 @@ import fs from 'fs';
import path from 'path';
describe('Windsurf Profile Initialization Functionality', () => {
let windsurfProfileContent;
let windsurfProfileContent;
beforeAll(() => {
const windsurfJsPath = path.join(process.cwd(), 'scripts', 'profiles', 'windsurf.js');
windsurfProfileContent = fs.readFileSync(windsurfJsPath, 'utf8');
});
beforeAll(() => {
const windsurfJsPath = path.join(
process.cwd(),
'scripts',
'profiles',
'windsurf.js'
);
windsurfProfileContent = fs.readFileSync(windsurfJsPath, 'utf8');
});
test('windsurf.js exports correct brandName and rulesDir', () => {
expect(windsurfProfileContent).toContain("const brandName = 'Windsurf'");
expect(windsurfProfileContent).toContain("const rulesDir = '.windsurf/rules'");
});
test('windsurf.js exports correct brandName and rulesDir', () => {
expect(windsurfProfileContent).toContain("const brandName = 'Windsurf'");
expect(windsurfProfileContent).toContain(
"const rulesDir = '.windsurf/rules'"
);
});
test('windsurf.js contains fileMap for .mdc to .md mapping', () => {
expect(windsurfProfileContent).toContain("fileMap = {");
expect(windsurfProfileContent).toContain(".mdc'");
expect(windsurfProfileContent).toContain(".md'");
});
test('windsurf.js contains fileMap for .mdc to .md mapping', () => {
expect(windsurfProfileContent).toContain('fileMap = {');
expect(windsurfProfileContent).toContain(".mdc'");
expect(windsurfProfileContent).toContain(".md'");
});
test('windsurf.js contains tool renaming and extension logic', () => {
expect(windsurfProfileContent).toContain("edit_file");
expect(windsurfProfileContent).toContain("apply_diff");
expect(windsurfProfileContent).toContain("search tool");
expect(windsurfProfileContent).toContain("search_files tool");
expect(windsurfProfileContent).toContain(".mdc");
expect(windsurfProfileContent).toContain(".md");
});
test('windsurf.js contains tool renaming and extension logic', () => {
expect(windsurfProfileContent).toContain('edit_file');
expect(windsurfProfileContent).toContain('apply_diff');
expect(windsurfProfileContent).toContain('search tool');
expect(windsurfProfileContent).toContain('search_files tool');
expect(windsurfProfileContent).toContain('.mdc');
expect(windsurfProfileContent).toContain('.md');
});
test('windsurf.js contains correct documentation URL transformation', () => {
expect(windsurfProfileContent).toContain('docs.cursor.com');
expect(windsurfProfileContent).toContain('docs.windsurf.com');
});
test('windsurf.js contains correct documentation URL transformation', () => {
expect(windsurfProfileContent).toContain('docs.cursor.com');
expect(windsurfProfileContent).toContain('docs.windsurf.com');
});
});