/ tests / verify-architect-fixes.js
verify-architect-fixes.js
  1  /**
  2   * Quick verification that Architect agent fixes work
  3   */
  4  
  5  import { ArchitectAgent } from '../src/agents/architect.js';
  6  import Database from 'better-sqlite3';
  7  import fs from 'fs/promises';
  8  
  9  const TEST_DB = './test-arch-verify.db';
 10  
 11  async function verifyFixes() {
 12    console.log('Setting up test database...');
 13  
 14    const db = new Database(TEST_DB);
 15    db.exec(`
 16      CREATE TABLE IF NOT EXISTS agent_tasks (
 17        id INTEGER PRIMARY KEY AUTOINCREMENT,
 18        task_type TEXT NOT NULL,
 19        assigned_to TEXT NOT NULL,
 20        status TEXT DEFAULT 'pending',
 21        context_json TEXT,
 22        result_json TEXT,
 23        created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
 24        started_at DATETIME,
 25        completed_at DATETIME
 26      );
 27  
 28      CREATE TABLE IF NOT EXISTS agent_logs (
 29        id INTEGER PRIMARY KEY AUTOINCREMENT,
 30        task_id INTEGER,
 31        agent_name TEXT NOT NULL,
 32        log_level TEXT,
 33        message TEXT NOT NULL,
 34        data_json TEXT,
 35        created_at DATETIME DEFAULT CURRENT_TIMESTAMP
 36      );
 37  
 38      CREATE TABLE IF NOT EXISTS agent_state (
 39        agent_name TEXT PRIMARY KEY,
 40        last_active DATETIME DEFAULT CURRENT_TIMESTAMP,
 41        current_task_id INTEGER,
 42        status TEXT DEFAULT 'idle'
 43      );
 44  
 45      INSERT OR IGNORE INTO agent_state (agent_name, status) VALUES ('architect', 'idle');
 46    `);
 47  
 48    process.env.DATABASE_PATH = TEST_DB;
 49  
 50    console.log('\n✓ Database setup complete\n');
 51  
 52    // Test 1: Null context_json handling
 53    console.log('Test 1: Null context_json handling...');
 54    const taskId1 = db
 55      .prepare(
 56        `
 57      INSERT INTO agent_tasks (task_type, assigned_to, status, context_json)
 58      VALUES (?, ?, ?, ?)
 59      RETURNING id
 60    `
 61      )
 62      .get('review_design', 'architect', 'running', null).id;
 63  
 64    const agent = new ArchitectAgent();
 65    await agent.initialize();
 66  
 67    const task1 = db.prepare('SELECT * FROM agent_tasks WHERE id = ?').get(taskId1);
 68    await agent.reviewDesign(task1);
 69  
 70    const result1 = db.prepare('SELECT status FROM agent_tasks WHERE id = ?').get(taskId1);
 71    if (result1.status === 'completed') {
 72      console.log('✓ Test 1 PASSED: Handles null context_json gracefully\n');
 73    } else {
 74      console.log(`✗ Test 1 FAILED: Status is ${result1.status}\n`);
 75    }
 76  
 77    // Test 2: parseDesignResponse
 78    console.log('Test 2: parseDesignResponse extracts fields correctly...');
 79    const designResponse = `**Summary**: Add user authentication
 80  
 81  **Approach**: JWT-based auth
 82  
 83  **Files Affected**:
 84  - \`src/auth/jwt.js\`
 85  - \`src/auth/middleware.js\`
 86  
 87  **Estimated Effort**: 6 hours
 88  
 89  **Breaking Changes**: None
 90  
 91  **Migration Required**: yes`;
 92  
 93    const proposal = agent.parseDesignResponse(designResponse, 'Add auth');
 94  
 95    if (
 96      proposal.summary.includes('authentication') &&
 97      proposal.files_affected.length === 2 &&
 98      proposal.estimated_effort === 6 &&
 99      proposal.requires_migration === true
100    ) {
101      console.log('✓ Test 2 PASSED: parseDesignResponse works correctly\n');
102    } else {
103      console.log('✗ Test 2 FAILED: parseDesignResponse parsing incorrect');
104      console.log('  Proposal:', JSON.stringify(proposal, null, 2), '\n');
105    }
106  
107    // Test 3: parseReviewResponse
108    console.log('Test 3: parseReviewResponse extracts issues...');
109    const reviewResponse = `**Issues**:
110  - [high] Test coverage missing
111  - [medium] File too large
112  - [low] Add comments`;
113  
114    const issues = agent.parseReviewResponse(reviewResponse);
115  
116    if (
117      issues.length === 3 &&
118      issues.filter(i => i.severity === 'high').length === 1 &&
119      issues.filter(i => i.severity === 'medium').length === 1
120    ) {
121      console.log('✓ Test 3 PASSED: parseReviewResponse works correctly\n');
122    } else {
123      console.log('✗ Test 3 FAILED: parseReviewResponse parsing incorrect');
124      console.log('  Issues:', JSON.stringify(issues, null, 2), '\n');
125    }
126  
127    // Test 4: identifyAffectedDocs
128    console.log('Test 4: identifyAffectedDocs detects doc changes...');
129    const affected = agent.identifyAffectedDocs(
130      ['db/migrations/050-test.sql', 'package.json', 'src/agents/developer.js'],
131      'new_feature'
132    );
133  
134    if (
135      affected.some(d => d.file === 'db/schema.sql') &&
136      affected.some(d => d.file === 'README.md') &&
137      affected.some(d => d.file === 'docs/06-automation/agent-system.md')
138    ) {
139      console.log('✓ Test 4 PASSED: identifyAffectedDocs works correctly\n');
140    } else {
141      console.log('✗ Test 4 FAILED: identifyAffectedDocs not detecting all docs');
142      console.log('  Affected:', JSON.stringify(affected, null, 2), '\n');
143    }
144  
145    // Cleanup
146    db.close();
147    await fs.unlink(TEST_DB);
148  
149    console.log('All tests complete! ✅\n');
150  }
151  
152  verifyFixes().catch(console.error);