update roo tests

This commit is contained in:
Joe Danziger
2025-05-11 00:04:42 -04:00
parent 157e8850a1
commit 66018542d0
2 changed files with 68 additions and 77 deletions

View File

@@ -16,35 +16,38 @@ describe('Roo Files Inclusion in Package', () => {
expect(packageJson.files).toContain('assets/**'); expect(packageJson.files).toContain('assets/**');
}); });
test('init.js creates Roo directories and copies files', () => { test('roo.js profile contains logic for Roo directory creation and file copying', () => {
// Read the init.js file // Read the roo.js profile file
const initJsPath = path.join(process.cwd(), 'scripts', 'init.js'); const rooJsPath = path.join(process.cwd(), 'scripts', 'profiles', 'roo.js');
const initJsContent = fs.readFileSync(initJsPath, 'utf8'); const rooJsContent = fs.readFileSync(rooJsPath, 'utf8');
// Check for Roo directory creation (using more flexible pattern matching) // Check for the main handler function
const hasRooDir = initJsContent.includes( expect(rooJsContent.includes("onAddBrandRules(targetDir)")).toBe(true);
"ensureDirectoryExists(path.join(targetDir, '.roo"
);
expect(hasRooDir).toBe(true);
// Check for .roomodes file copying // Check for general recursive copy of assets/roocode
const hasRoomodes = initJsContent.includes("copyTemplateFile('.roomodes'"); expect(rooJsContent.includes("copyRecursiveSync(sourceDir, targetDir)")).toBe(true);
expect(hasRoomodes).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);
// Check for mode-specific patterns (using more flexible pattern matching) // Check for mode-specific rule file copying logic
const hasArchitect = initJsContent.includes('architect'); expect(rooJsContent.includes("for (const mode of rooModes)")).toBe(true);
const hasAsk = initJsContent.includes('ask'); expect(rooJsContent.includes("path.join(rooModesDir, `rules-${mode}`, `${mode}-rules`)")).toBe(true);
const hasBoomerang = initJsContent.includes('boomerang'); expect(rooJsContent.includes("path.join(targetDir, '.roo', `rules-${mode}`, `${mode}-rules`)")).toBe(true);
const hasCode = initJsContent.includes('code');
const hasDebug = initJsContent.includes('debug'); // Check for definition of rooModes array and all modes
const hasTest = initJsContent.includes('test'); const rooModesArrayRegex = /const rooModes\s*=\s*\[([^\]]+)\]\s*;?/;
const rooModesMatch = rooJsContent.match(rooModesArrayRegex);
expect(hasArchitect).toBe(true); expect(rooModesMatch).not.toBeNull();
expect(hasAsk).toBe(true); if (rooModesMatch) {
expect(hasBoomerang).toBe(true); expect(rooModesMatch[1].includes('architect')).toBe(true);
expect(hasCode).toBe(true); expect(rooModesMatch[1].includes('ask')).toBe(true);
expect(hasDebug).toBe(true); expect(rooModesMatch[1].includes('boomerang')).toBe(true);
expect(hasTest).toBe(true); expect(rooModesMatch[1].includes('code')).toBe(true);
expect(rooModesMatch[1].includes('debug')).toBe(true);
expect(rooModesMatch[1].includes('test')).toBe(true);
}
}); });
test('source Roo files exist in assets directory', () => { test('source Roo files exist in assets directory', () => {

View File

@@ -2,68 +2,56 @@ import { jest } from '@jest/globals';
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
describe('Roo Initialization Functionality', () => { describe('Roo Profile Initialization Functionality', () => {
let initJsContent; let rooProfileContent;
beforeAll(() => { beforeAll(() => {
// Read the init.js file content once for all tests // Read the roo.js profile file content once for all tests
const initJsPath = path.join(process.cwd(), 'scripts', 'init.js'); const rooJsPath = path.join(process.cwd(), 'scripts', 'profiles', 'roo.js');
initJsContent = fs.readFileSync(initJsPath, 'utf8'); rooProfileContent = fs.readFileSync(rooJsPath, 'utf8');
}); });
test('init.js creates Roo directories in createProjectStructure function', () => { test('roo.js profile ensures Roo directory structure via onAddBrandRules', () => {
// Check if createProjectStructure function exists // Check if onAddBrandRules function exists
expect(initJsContent).toContain('function createProjectStructure'); expect(rooProfileContent).toContain('onAddBrandRules(targetDir)');
// Check for the line that creates the .roo directory // Check for the general copy of assets/roocode which includes .roo base structure
const hasRooDir = initJsContent.includes( expect(rooProfileContent).toContain(
"ensureDirectoryExists(path.join(targetDir, '.roo'))" 'copyRecursiveSync(sourceDir, targetDir)'
); );
expect(hasRooDir).toBe(true); expect(rooProfileContent).toContain("path.resolve(__dirname, '../../assets/roocode')"); // Verifies sourceDir definition
// Check for the line that creates .roo/rules directory // Check for the loop that processes rooModes
const hasRooRulesDir = initJsContent.includes( expect(rooProfileContent).toContain('for (const mode of rooModes)');
"ensureDirectoryExists(path.join(targetDir, '.roo', 'rules'))"
); // Check for creation of mode-specific rule directories (e.g., .roo/rules-architect)
expect(hasRooRulesDir).toBe(true); // 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
// Check for the for loop that creates mode-specific directories
const hasRooModeLoop =
initJsContent.includes(
"for (const mode of ['architect', 'ask', 'boomerang', 'code', 'debug', 'test'])"
) ||
(initJsContent.includes('for (const mode of [') &&
initJsContent.includes('architect') &&
initJsContent.includes('ask') &&
initJsContent.includes('boomerang') &&
initJsContent.includes('code') &&
initJsContent.includes('debug') &&
initJsContent.includes('test'));
expect(hasRooModeLoop).toBe(true);
}); });
test('init.js copies Roo files from assets/roocode directory', () => { test('roo.js profile copies .roomodes file via onAddBrandRules', () => {
// Check for the .roomodes case in the copyTemplateFile function expect(rooProfileContent).toContain('onAddBrandRules(targetDir)');
const casesRoomodes = initJsContent.includes("case '.roomodes':");
expect(casesRoomodes).toBe(true); // Check for the specific .roomodes copy logic
expect(rooProfileContent).toContain('fs.copyFileSync(roomodesSrc, roomodesDest);');
// Check that assets/roocode appears somewhere in the file expect(rooProfileContent).toContain("const roomodesSrc = path.join(sourceDir, '.roomodes');");
const hasRoocodePath = initJsContent.includes("'assets', 'roocode'"); expect(rooProfileContent).toContain("const roomodesDest = path.join(targetDir, '.roomodes');");
expect(hasRoocodePath).toBe(true); expect(rooProfileContent).toContain("path.resolve(__dirname, '../../assets/roocode')"); // sourceDir for roomodesSrc
// Check that roomodes file is copied
const copiesRoomodes = initJsContent.includes(
"copyTemplateFile('.roomodes'"
);
expect(copiesRoomodes).toBe(true);
}); });
test('init.js has code to copy rule files for each mode', () => { test('roo.js profile copies mode-specific rule files via onAddBrandRules', () => {
// Look for template copying for rule files expect(rooProfileContent).toContain('onAddBrandRules(targetDir)');
const hasModeRulesCopying = expect(rooProfileContent).toContain('for (const mode of rooModes)');
initJsContent.includes('copyTemplateFile(') &&
initJsContent.includes('rules-') && // Check for the specific mode rule file copy logic
initJsContent.includes('-rules'); expect(rooProfileContent).toContain('fs.copyFileSync(src, dest);');
expect(hasModeRulesCopying).toBe(true);
// Check source path construction for 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
}); });
}); });