/** * Monorepo Support Validation Tests * * Architecture after deduplication: * - Monorepo context logic lives ONLY in context-logic.js * - workflow.xml (src) uses {{monorepo_context_logic}} placeholder → injected at install time * - Individual source workflow files do NOT have inline checks (that's the deduplication!) * - Only code-review/instructions.xml, dev-story/instructions.xml, create-story/instructions.xml * and advanced-elicitation/workflow.xml are XML workflows checked; XML workflows that go through * workflow.xml no longer need inline checks. * * Verifies: * 1. The set-project workflow is correctly registered. * 2. No source workflow file has a stale inline "Monorepo Context Check" block. * 3. Only the canonical SINGLE source (context-logic.js) defines the check. * 4. set-project implementation still manages .current_project. */ const fs = require('fs-extra'); const path = require('node:path'); const { globSync } = require('glob'); // ANSI colors const colors = { reset: '\u001B[0m', green: '\u001B[32m', red: '\u001B[31m', yellow: '\u001B[33m', cyan: '\u001B[36m', dim: '\u001B[2m', }; let passed = 0; let failed = 0; function assert(condition, testName, errorMessage = '') { if (condition) { console.log(`${colors.green}✓${colors.reset} ${testName}`); passed++; } else { console.log(`${colors.red}✗${colors.reset} ${testName}`); if (errorMessage) { console.log(` ${colors.dim}${errorMessage}${colors.reset}`); } failed++; } } async function runTests() { console.log(`${colors.cyan}========================================`); console.log('Monorepo Support Validation Tests'); console.log(`========================================${colors.reset}\n`); const projectRoot = path.join(__dirname, '..'); // 1. Verify set-project registration console.log(`${colors.yellow}Test Suite 1: Workflow Registration${colors.reset}\n`); try { const csvPath = path.join(projectRoot, 'src/bmm/module-help.csv'); const content = await fs.readFile(csvPath, 'utf8'); assert(content.includes('set-project'), 'set-project workflow is registered in module-help.csv'); } catch (error) { assert(false, 'Registration check failed', error.message); } console.log(''); // 2. Verify NO stale inline "Monorepo Context Check" blocks in source workflow files // These are redundant since workflow.xml now handles context injection via context-logic.js console.log(`${colors.yellow}Test Suite 2: No Stale Inline Monorepo Context Checks${colors.reset}\n`); console.log(` ${colors.dim}(Inline checks were moved to workflow.xml via context-logic.js)${colors.reset}\n`); const workflowFiles = globSync('src/{core,bmm}/workflows/**/*.{md,xml}', { cwd: projectRoot }); const exceptions = [ 'context-logic.js', 'code-review/instructions.xml', 'create-story/instructions.xml', 'dev-story/instructions.xml', 'advanced-elicitation/workflow.xml', 'deep-dive-instructions.md', ]; for (const file of workflowFiles) { if (exceptions.some((e) => file.endsWith(e))) continue; const content = await fs.readFile(path.join(projectRoot, file), 'utf8'); const hasMarkdownCheck = content.includes('**Monorepo Context Check:**'); const hasXmlCheck = / { console.error(error); process.exit(1); });