@@ -97,17 +97,22 @@ export function activate(context: vscode.ExtensionContext): void {
9797 project_path : projectPath ,
9898 } ) ;
9999
100- const passRate = ( report . pass_rate * 100 ) . toFixed ( 0 ) ;
100+ const passRate = report . pass_rate . toFixed ( 0 ) ;
101101 const msg = `测试完成 | 通过率 ${ passRate } % | Bug ${ report . bug_count } 个` ;
102102
103103 if ( report . bug_count === 0 ) {
104104 vscode . window . showInformationMessage ( `✅ ${ msg } ` ) ;
105105 } else {
106106 const action = await vscode . window . showWarningMessage (
107107 `⚠️ ${ msg } ` ,
108+ "复制Bug给AI" ,
108109 "查看报告" ,
109110 ) ;
110- if ( action === "查看报告" ) {
111+ if ( action === "复制Bug给AI" ) {
112+ const bugSummary = formatBugSummaryForAI ( report ) ;
113+ await vscode . env . clipboard . writeText ( bugSummary ) ;
114+ vscode . window . showInformationMessage ( "Bug摘要已复制到剪贴板,粘贴到聊天窗口让AI修复" ) ;
115+ } else if ( action === "查看报告" ) {
111116 showReport ( report . report_markdown ) ;
112117 }
113118 }
@@ -157,14 +162,24 @@ export function activate(context: vscode.ExtensionContext): void {
157162 base_url : baseUrl || undefined ,
158163 } ) ;
159164
160- const passRate = ( report . pass_rate * 100 ) . toFixed ( 0 ) ;
165+ const passRate = report . pass_rate . toFixed ( 0 ) ;
161166 const msg = `蓝本测试完成 | 通过率 ${ passRate } % | Bug ${ report . bug_count } 个` ;
162167
163168 if ( report . bug_count === 0 ) {
164169 vscode . window . showInformationMessage ( `✅ ${ msg } ` ) ;
165170 } else {
166- const action = await vscode . window . showWarningMessage ( `⚠️ ${ msg } ` , "查看报告" ) ;
167- if ( action === "查看报告" ) { showReport ( report . report_markdown ) ; }
171+ const action = await vscode . window . showWarningMessage (
172+ `⚠️ ${ msg } ` ,
173+ "复制Bug给AI" ,
174+ "查看报告" ,
175+ ) ;
176+ if ( action === "复制Bug给AI" ) {
177+ const bugSummary = formatBugSummaryForAI ( report ) ;
178+ await vscode . env . clipboard . writeText ( bugSummary ) ;
179+ vscode . window . showInformationMessage ( "Bug摘要已复制到剪贴板,粘贴到聊天窗口让AI修复" ) ;
180+ } else if ( action === "查看报告" ) {
181+ showReport ( report . report_markdown ) ;
182+ }
168183 }
169184 outputChannel . appendLine ( "─" . repeat ( 40 ) ) ;
170185 outputChannel . appendLine ( report . report_markdown ) ;
@@ -273,7 +288,7 @@ export function activate(context: vscode.ExtensionContext): void {
273288 auto_repair : config . get < boolean > ( "autoRepair" , false ) ,
274289 project_path : folderPath ,
275290 } ) ;
276- const passRate = ( report . pass_rate * 100 ) . toFixed ( 0 ) ;
291+ const passRate = report . pass_rate . toFixed ( 0 ) ;
277292 vscode . window . showInformationMessage (
278293 `TestPilot AI 完成 | 通过率 ${ passRate } % | Bug ${ report . bug_count } 个` ,
279294 ) ;
@@ -312,6 +327,32 @@ export function deactivate(): void {
312327 outputChannel ?. appendLine ( "[TestPilot AI] 插件已停用" ) ;
313328}
314329
330+ /** 格式化Bug摘要,方便粘贴给编程AI修复 */
331+ function formatBugSummaryForAI ( report : { test_name : string ; url : string ; pass_rate : number ; bug_count : number ; bugs ?: Array < { severity : string ; title : string ; description : string ; step_number ?: number | null } > ; report_markdown : string } ) : string {
332+ const lines : string [ ] = [
333+ `TestPilot AI 发现 ${ report . bug_count } 个Bug,请修复:` ,
334+ `测试: ${ report . test_name } | URL: ${ report . url } | 通过率: ${ report . pass_rate . toFixed ( 0 ) } %` ,
335+ "" ,
336+ ] ;
337+
338+ const bugs = report . bugs || [ ] ;
339+ if ( bugs . length > 0 ) {
340+ bugs . forEach ( ( bug , i ) => {
341+ const step = bug . step_number ? ` (步骤#${ bug . step_number } )` : "" ;
342+ lines . push ( `${ i + 1 } . [${ bug . severity . toUpperCase ( ) } ] ${ bug . title } ${ step } ` ) ;
343+ if ( bug . description ) {
344+ const desc = bug . description . split ( "\n" ) [ 0 ] . substring ( 0 , 150 ) ;
345+ lines . push ( ` ${ desc } ` ) ;
346+ }
347+ } ) ;
348+ } else {
349+ lines . push ( report . report_markdown . substring ( 0 , 1000 ) ) ;
350+ }
351+
352+ lines . push ( "" , "修复后请调用 run_blueprint_test 重新测试。" ) ;
353+ return lines . join ( "\n" ) ;
354+ }
355+
315356/** 在新的编辑器标签页中显示 Markdown 报告 */
316357function showReport ( markdown : string ) : void {
317358 const doc = vscode . workspace . openTextDocument ( {
0 commit comments