From 66018542d096c161e9d04f784275e37df2ca07f4 Mon Sep 17 00:00:00 2001 From: Joe Danziger Date: Sun, 11 May 2025 00:04:42 -0400 Subject: [PATCH] update roo tests --- tests/integration/roo-files-inclusion.test.js | 55 ++++++------ .../roo-init-functionality.test.js | 90 ++++++++----------- 2 files changed, 68 insertions(+), 77 deletions(-) diff --git a/tests/integration/roo-files-inclusion.test.js b/tests/integration/roo-files-inclusion.test.js index 153910fc..1230ac1d 100644 --- a/tests/integration/roo-files-inclusion.test.js +++ b/tests/integration/roo-files-inclusion.test.js @@ -16,35 +16,38 @@ describe('Roo Files Inclusion in Package', () => { expect(packageJson.files).toContain('assets/**'); }); - test('init.js creates Roo directories and copies files', () => { - // Read the init.js file - const initJsPath = path.join(process.cwd(), 'scripts', 'init.js'); - const initJsContent = fs.readFileSync(initJsPath, 'utf8'); + test('roo.js profile contains logic for Roo directory creation and file copying', () => { + // Read the roo.js profile file + const rooJsPath = path.join(process.cwd(), 'scripts', 'profiles', 'roo.js'); + const rooJsContent = fs.readFileSync(rooJsPath, 'utf8'); - // Check for Roo directory creation (using more flexible pattern matching) - const hasRooDir = initJsContent.includes( - "ensureDirectoryExists(path.join(targetDir, '.roo" - ); - expect(hasRooDir).toBe(true); + // Check for the main handler function + expect(rooJsContent.includes("onAddBrandRules(targetDir)")).toBe(true); - // Check for .roomodes file copying - const hasRoomodes = initJsContent.includes("copyTemplateFile('.roomodes'"); - expect(hasRoomodes).toBe(true); + // Check for general recursive copy of assets/roocode + 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); - // Check for mode-specific patterns (using more flexible pattern matching) - const hasArchitect = initJsContent.includes('architect'); - const hasAsk = initJsContent.includes('ask'); - const hasBoomerang = initJsContent.includes('boomerang'); - const hasCode = initJsContent.includes('code'); - const hasDebug = initJsContent.includes('debug'); - const hasTest = initJsContent.includes('test'); - - expect(hasArchitect).toBe(true); - expect(hasAsk).toBe(true); - expect(hasBoomerang).toBe(true); - expect(hasCode).toBe(true); - expect(hasDebug).toBe(true); - expect(hasTest).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); + + // Check for definition of rooModes array and all modes + const rooModesArrayRegex = /const rooModes\s*=\s*\[([^\]]+)\]\s*;?/; + const rooModesMatch = rooJsContent.match(rooModesArrayRegex); + expect(rooModesMatch).not.toBeNull(); + if (rooModesMatch) { + expect(rooModesMatch[1].includes('architect')).toBe(true); + expect(rooModesMatch[1].includes('ask')).toBe(true); + expect(rooModesMatch[1].includes('boomerang')).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', () => { diff --git a/tests/integration/roo-init-functionality.test.js b/tests/integration/roo-init-functionality.test.js index 86b08aa0..85e0ed8c 100644 --- a/tests/integration/roo-init-functionality.test.js +++ b/tests/integration/roo-init-functionality.test.js @@ -2,68 +2,56 @@ import { jest } from '@jest/globals'; import fs from 'fs'; import path from 'path'; -describe('Roo Initialization Functionality', () => { - let initJsContent; +describe('Roo Profile Initialization Functionality', () => { + let rooProfileContent; beforeAll(() => { - // Read the init.js file content once for all tests - const initJsPath = path.join(process.cwd(), 'scripts', 'init.js'); - initJsContent = fs.readFileSync(initJsPath, 'utf8'); + // Read the roo.js profile file content once for all tests + const rooJsPath = path.join(process.cwd(), 'scripts', 'profiles', 'roo.js'); + rooProfileContent = fs.readFileSync(rooJsPath, 'utf8'); }); - test('init.js creates Roo directories in createProjectStructure function', () => { - // Check if createProjectStructure function exists - expect(initJsContent).toContain('function createProjectStructure'); + test('roo.js profile ensures Roo directory structure via onAddBrandRules', () => { + // Check if onAddBrandRules function exists + expect(rooProfileContent).toContain('onAddBrandRules(targetDir)'); - // Check for the line that creates the .roo directory - const hasRooDir = initJsContent.includes( - "ensureDirectoryExists(path.join(targetDir, '.roo'))" + // Check for the general copy of assets/roocode which includes .roo base structure + expect(rooProfileContent).toContain( + '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 - const hasRooRulesDir = initJsContent.includes( - "ensureDirectoryExists(path.join(targetDir, '.roo', 'rules'))" - ); - expect(hasRooRulesDir).toBe(true); + // 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 - // 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', () => { - // Check for the .roomodes case in the copyTemplateFile function - const casesRoomodes = initJsContent.includes("case '.roomodes':"); - expect(casesRoomodes).toBe(true); - - // Check that assets/roocode appears somewhere in the file - const hasRoocodePath = initJsContent.includes("'assets', 'roocode'"); - expect(hasRoocodePath).toBe(true); - - // Check that roomodes file is copied - const copiesRoomodes = initJsContent.includes( - "copyTemplateFile('.roomodes'" - ); - expect(copiesRoomodes).toBe(true); + 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 }); - test('init.js has code to copy rule files for each mode', () => { - // Look for template copying for rule files - const hasModeRulesCopying = - initJsContent.includes('copyTemplateFile(') && - initJsContent.includes('rules-') && - initJsContent.includes('-rules'); - expect(hasModeRulesCopying).toBe(true); + test('roo.js profile copies mode-specific rule files via onAddBrandRules', () => { + expect(rooProfileContent).toContain('onAddBrandRules(targetDir)'); + expect(rooProfileContent).toContain('for (const mode of rooModes)'); + + // 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`);"); + // 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 }); });