UNPKG

symref

Version:

Static code checker for AI code agents (Windsurf, Cline, etc.)

48 lines 2.33 kB
import { CallGraphAnalyzer, SymbolReferenceAnalyzer } from '../../analyzer/index.js'; import { TestPromptGenerator } from '../../generator/test-prompt-generator.js'; import { writeFileSync } from 'fs'; import { join } from 'path'; import { ensureDirSync } from 'fs-extra'; export class SuggestTestCommand { static register(program) { program .command('suggest-test <from>') .description('AIによる動的検証用テストコードの生成支援') .requiredOption('--to <symbol>', '追跡先のシンボル') .option('--test-framework <framework>', 'テストフレームワーク (jest/mocha)', 'jest') .option('--output <file>', '出力ファイルパス') .action(async (from, options) => { await this.execute(from, options); }); } static async execute(fromSymbol, options) { try { // 呼び出し経路の解析 const callGraph = await CallGraphAnalyzer.analyze(fromSymbol, options.to); // シンボル参照情報の解析 const symbolRefs = await SymbolReferenceAnalyzer.analyze(options.to); // テストプロンプトの生成 const generator = new TestPromptGenerator(); const prompt = generator.generate({ callGraph, symbolRefs, framework: options.testFramework || 'jest' }); // 出力処理 await this.writeOutput(prompt, fromSymbol, options.to, options.output); console.log('テスト生成支援情報を出力しました。'); } catch (error) { console.error('エラーが発生しました:', error); process.exit(1); } } static async writeOutput(content, fromSymbol, toSymbol, outputPath) { const timestamp = new Date().toISOString().replace(/[:.]/g, '_'); const defaultFileName = `suggest_test_${fromSymbol.replace(/\./g, '_')}_to_${toSymbol.replace(/\./g, '_')}_${timestamp}.md`; const outputFilePath = outputPath || join(process.cwd(), '.symbols', defaultFileName); ensureDirSync(join(process.cwd(), '.symbols')); writeFileSync(outputFilePath, content, 'utf-8'); } } //# sourceMappingURL=suggest-test.js.map