UNPKG

symref

Version:

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

88 lines (81 loc) 2.91 kB
export class TestPromptGenerator { generate(context) { return ` 検証対象の呼び出し経路: ${this.formatCallPath(context.callGraph)} シンボル情報: ${this.formatSymbolInfo(context.symbolRefs)} テスト要件: 1. エントリーポイントからの呼び出しフローを検証 2. 各シンボルの呼び出しをspyで検証 3. 呼び出し順序の確認 推奨テスト構造: \`\`\`typescript ${this.generateTestStructure(context)} \`\`\` `; } formatCallPath(callGraph) { let result = ''; for (const node of callGraph.nodes) { const indent = ' '.repeat(node.depth); result += `${indent}${node.depth === 0 ? '- ' : '└─ '}${node.symbol}\n`; } return result; } formatSymbolInfo(refs) { return `- 定義: ${refs.definition} - 依存: ${refs.dependencies.join(', ')} - 呼び出し元: ${refs.callers.join(', ')}`; } generateTestStructure(context) { const { callGraph, framework } = context; const testTarget = callGraph.nodes[0].symbol; const finalTarget = callGraph.nodes[callGraph.nodes.length - 1].symbol; return `describe('${testTarget} to ${finalTarget}', () => { ${this.generateTestSetup(framework)} beforeEach(() => { // スパイとモックのリセット jest.clearAllMocks(); }); it('should call all dependencies in correct order', async () => { // テスト実装 ${this.generateTestImplementation(callGraph, framework)} }); });`; } generateTestSetup(framework) { if (framework === 'jest') { return `// スパイとモックの設定 const mockDependencies = jest.spyOn(Dependencies, 'method');`; } return `// スパイとモックの設定 const mockDependencies = sinon.spy(Dependencies, 'method');`; } generateTestImplementation(callGraph, framework) { const assertions = callGraph.nodes.map((node) => { if (framework === 'jest') { return `expect(${node.symbol}).toHaveBeenCalled();`; } return `expect(${node.symbol}.called).to.be.true;`; }).join('\n '); return `// 関数の実行 await ${callGraph.nodes[0].symbol}(); // 呼び出しの検証 ${assertions} // 呼び出し順序の検証 ${this.generateOrderAssertions(callGraph, framework)}`; } generateOrderAssertions(callGraph, framework) { if (framework === 'jest') { return callGraph.nodes.map((node, index) => { if (index === 0) return ''; return `expect(${node.symbol}).toHaveBeenCalledAfter(${callGraph.nodes[index - 1].symbol});`; }).filter(Boolean).join('\n '); } return `// Mochaでの順序検証 // カスタム順序検証ロジックが必要`; } } //# sourceMappingURL=test-prompt-generator.js.map