-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest_popup.ps1
More file actions
574 lines (497 loc) · 19.4 KB
/
test_popup.ps1
File metadata and controls
574 lines (497 loc) · 19.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
# 三术弹窗测试脚本 (PowerShell 版本)
# 使用 target\release 或 target\debug 中的 CLI 工具测试弹窗功能
param()
# 确保脚本在项目根目录执行,避免相对路径导致资源找不到
Set-Location -Path $PSScriptRoot
$ErrorActionPreference = "Stop"
$script:ProjectRoot = $PSScriptRoot
$script:CliType = "local" # local 或 global
$script:BuildType = "release"
$script:SanshuExeName = "三术.exe"
$script:DengExeName = "等一下.exe"
$script:CliPath = Join-Path -Path $script:ProjectRoot -ChildPath "target\$($script:BuildType)"
$script:SimplePopupFile = Join-Path -Path $script:ProjectRoot -ChildPath "test_simple_popup.json"
$script:MarkdownPopupFile = Join-Path -Path $script:ProjectRoot -ChildPath "test_markdown_popup.json"
function Test-Command {
param([string]$Command)
try {
Get-Command $Command -ErrorAction Stop | Out-Null
return $true
}
catch {
return $false
}
}
function Resolve-CommandPath {
param([string]$Command)
$cmd = Get-Command $Command -ErrorAction Stop
if ($cmd.Path) { return $cmd.Path }
if ($cmd.Source) { return $cmd.Source }
return $cmd.Name
}
function Write-Utf8NoBom {
param(
[string]$Path,
[string]$Content
)
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
[System.IO.File]::WriteAllText($Path, $Content, $utf8NoBom)
}
function Update-CliPath {
$script:CliPath = Join-Path -Path $script:ProjectRoot -ChildPath "target\$($script:BuildType)"
}
function Select-BuildType {
if ($script:CliType -ne "local") {
return
}
Write-Host "🔧 选择构建类型:" -ForegroundColor Yellow
Write-Host " 1. Release (推荐,性能最佳)" -ForegroundColor Green
Write-Host " 2. Debug (包含调试信息)" -ForegroundColor Green
Write-Host ""
$selected = $false
while (-not $selected) {
$buildChoice = Read-Host "请选择构建类型 (1-2)"
switch ($buildChoice) {
"1" {
$script:BuildType = "release"
Update-CliPath
Write-Host "✅ 已选择 Release 构建" -ForegroundColor Green
$selected = $true
}
"2" {
$script:BuildType = "debug"
Update-CliPath
Write-Host "✅ 已选择 Debug 构建" -ForegroundColor Green
$selected = $true
}
default {
Write-Host "❌ 无效选项,请选择 1 或 2" -ForegroundColor Red
}
}
}
Write-Host ""
}
function Check-GlobalCli {
Write-Host "🔍 检查全局CLI工具..." -ForegroundColor Yellow
$sanshuFound = $false
$dengFound = $false
if (Test-Command $script:SanshuExeName) {
$path = Resolve-CommandPath $script:SanshuExeName
Write-Host "✅ 找到全局 三术 CLI: $path" -ForegroundColor Green
$sanshuFound = $true
}
else {
Write-Host "❌ 未找到全局 三术 CLI" -ForegroundColor Red
}
if (Test-Command $script:DengExeName) {
$path = Resolve-CommandPath $script:DengExeName
Write-Host "✅ 找到全局 等一下 CLI: $path" -ForegroundColor Green
$dengFound = $true
}
else {
Write-Host "❌ 未找到全局 等一下 CLI" -ForegroundColor Red
}
if (-not $sanshuFound -or -not $dengFound) {
Write-Host "💡 全局CLI工具未完全安装,安装方法:" -ForegroundColor Yellow
Write-Host " cargo install --path . --bins" -ForegroundColor Cyan
Write-Host " 或者选择使用本地编译版本" -ForegroundColor Yellow
Write-Host ""
Write-Host "🔄 是否切换到本地编译版本? (y/n)" -ForegroundColor Cyan
$switchChoice = Read-Host "请选择"
if ($switchChoice -match '^[Yy]$') {
$script:CliType = "local"
Select-BuildType
return
}
else {
Write-Host "❌ 无法继续,请先安装全局CLI工具" -ForegroundColor Red
exit 1
}
}
$script:CliPath = "" # 全局CLI不需要路径前缀
Write-Host "✅ 全局CLI工具检查完成" -ForegroundColor Green
Write-Host ""
}
function Select-CliType {
Write-Host "🔧 选择CLI类型:" -ForegroundColor Yellow
Write-Host " 1. 本地编译版本 (从项目target目录)" -ForegroundColor Green
Write-Host " 2. 全局安装版本 (系统PATH中)" -ForegroundColor Green
Write-Host ""
$selected = $false
while (-not $selected) {
$cliChoice = Read-Host "请选择CLI类型 (1-2)"
switch ($cliChoice) {
"1" {
$script:CliType = "local"
Write-Host "✅ 已选择本地编译版本" -ForegroundColor Green
Select-BuildType
$selected = $true
}
"2" {
$script:CliType = "global"
Write-Host "✅ 已选择全局安装版本" -ForegroundColor Green
Check-GlobalCli
$selected = $true
}
default {
Write-Host "❌ 无效选项,请选择 1 或 2" -ForegroundColor Red
}
}
}
Write-Host ""
}
function Compile-Project {
if ($script:CliType -eq "global") {
Write-Host "⚠️ 使用全局CLI,跳过编译步骤" -ForegroundColor Yellow
return
}
Write-Host "🔨 开始编译项目..." -ForegroundColor Yellow
$cargoToml = Join-Path -Path $script:ProjectRoot -ChildPath "Cargo.toml"
if (-not (Test-Path $cargoToml)) {
Write-Host "❌ 未找到 Cargo.toml 文件" -ForegroundColor Red
Write-Host "💡 请确保在Rust项目根目录中运行此脚本" -ForegroundColor Yellow
exit 1
}
if (-not (Test-Command "cargo")) {
Write-Host "❌ 未找到 cargo 命令" -ForegroundColor Red
Write-Host "💡 请先安装 Rust: https://rustup.rs/" -ForegroundColor Yellow
exit 1
}
if ($script:BuildType -eq "release") {
Write-Host "📦 编译 Release 版本..." -ForegroundColor Cyan
& cargo build --release
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ Release 编译完成" -ForegroundColor Green
}
else {
Write-Host "❌ Release 编译失败" -ForegroundColor Red
exit 1
}
}
else {
Write-Host "📦 编译 Debug 版本..." -ForegroundColor Cyan
& cargo build
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ Debug 编译完成" -ForegroundColor Green
}
else {
Write-Host "❌ Debug 编译失败" -ForegroundColor Red
exit 1
}
}
Write-Host ""
}
function Check-CliTools {
if ($script:CliType -eq "global") {
Write-Host "📋 检查全局CLI工具..." -ForegroundColor Yellow
Check-GlobalCli
return
}
Write-Host "📋 检查本地CLI工具 ($($script:BuildType))..." -ForegroundColor Yellow
$sanshuPath = Join-Path -Path $script:CliPath -ChildPath $script:SanshuExeName
if (-not (Test-Path $sanshuPath)) {
Write-Host "❌ 未找到 三术 CLI工具" -ForegroundColor Red
if ($script:BuildType -eq "release") {
Write-Host "💡 请先编译项目: cargo build --release" -ForegroundColor Yellow
}
else {
Write-Host "💡 请先编译项目: cargo build" -ForegroundColor Yellow
}
Write-Host "🔨 是否现在编译项目? (y/n)" -ForegroundColor Cyan
$compileChoice = Read-Host "请选择"
if ($compileChoice -match '^[Yy]$') {
Compile-Project
}
else {
exit 1
}
}
$dengPath = Join-Path -Path $script:CliPath -ChildPath $script:DengExeName
if (-not (Test-Path $dengPath)) {
Write-Host "❌ 未找到 等一下 CLI工具" -ForegroundColor Red
if ($script:BuildType -eq "release") {
Write-Host "💡 请先编译项目: cargo build --release" -ForegroundColor Yellow
}
else {
Write-Host "💡 请先编译项目: cargo build" -ForegroundColor Yellow
}
Write-Host "🔨 是否现在编译项目? (y/n)" -ForegroundColor Cyan
$compileChoice = Read-Host "请选择"
if ($compileChoice -match '^[Yy]$') {
Compile-Project
}
else {
exit 1
}
}
Write-Host "✅ 本地CLI工具检查完成 ($($script:BuildType))" -ForegroundColor Green
Write-Host " 构建类型: $($script:BuildType)"
Write-Host " 三术: $sanshuPath"
Write-Host " 等一下: $dengPath"
}
function Check-TestFiles {
Write-Host "📋 检查测试文件..." -ForegroundColor Yellow
if (-not (Test-Path $script:SimplePopupFile)) {
Write-Host "❌ 未找到 test_simple_popup.json" -ForegroundColor Red
exit 1
}
if (-not (Test-Path $script:MarkdownPopupFile)) {
Write-Host "❌ 未找到 test_markdown_popup.json" -ForegroundColor Red
exit 1
}
Write-Host "✅ 测试文件检查完成" -ForegroundColor Green
}
function Show-TestOptions {
Write-Host "🎨 可用的测试选项:" -ForegroundColor Cyan
if ($script:CliType -eq "global") {
Write-Host "当前CLI类型: 全局安装版本" -ForegroundColor Yellow
}
else {
Write-Host "当前CLI类型: 本地编译版本 ($($script:BuildType))" -ForegroundColor Yellow
}
Write-Host ""
Write-Host " 1. 测试简单弹窗 (test_simple_popup.json)" -ForegroundColor Green
Write-Host " 2. 测试Markdown弹窗 (test_markdown_popup.json)" -ForegroundColor Green
Write-Host " 3. 测试自定义弹窗" -ForegroundColor Green
Write-Host " 4. 启动前端测试环境" -ForegroundColor Green
Write-Host " 5. 查看CLI工具帮助" -ForegroundColor Green
Write-Host " 6. 切换CLI类型" -ForegroundColor Green
Write-Host " 7. 安装/重新编译" -ForegroundColor Green
Write-Host " q. 退出" -ForegroundColor Green
Write-Host ""
}
function Show-JsonContent {
param([string]$FilePath)
if (Test-Command "jq") {
& jq "." $FilePath
}
else {
Write-Host "JSON内容:"
Get-Content -Path $FilePath
}
}
function Get-CliCommand {
param([string]$CliName)
if ($script:CliType -eq "global") {
return $CliName
}
return (Join-Path -Path $script:CliPath -ChildPath $CliName)
}
function Test-SimplePopup {
Write-Host "🚀 启动简单弹窗测试..." -ForegroundColor Yellow
Write-Host "使用文件: test_simple_popup.json" -ForegroundColor Cyan
Write-Host "📄 文件内容:" -ForegroundColor Yellow
Show-JsonContent -FilePath $script:SimplePopupFile
Write-Host ""
$cliCmd = Get-CliCommand $script:DengExeName
Write-Host "🎯 启动弹窗..." -ForegroundColor Green
Write-Host "执行命令: $cliCmd --mcp-request test_simple_popup.json" -ForegroundColor Cyan
& $cliCmd --mcp-request $script:SimplePopupFile
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ 弹窗测试完成" -ForegroundColor Green
}
else {
Write-Host "❌ 弹窗测试失败" -ForegroundColor Red
Write-Host "💡 请检查CLI工具是否正常工作" -ForegroundColor Yellow
}
}
function Test-MarkdownPopup {
Write-Host "🚀 启动Markdown弹窗测试..." -ForegroundColor Yellow
Write-Host "使用文件: test_markdown_popup.json" -ForegroundColor Cyan
Write-Host "📄 文件内容:" -ForegroundColor Yellow
Show-JsonContent -FilePath $script:MarkdownPopupFile
Write-Host ""
$cliCmd = Get-CliCommand $script:DengExeName
Write-Host "🎯 启动弹窗..." -ForegroundColor Green
Write-Host "执行命令: $cliCmd --mcp-request test_markdown_popup.json" -ForegroundColor Cyan
& $cliCmd --mcp-request $script:MarkdownPopupFile
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ Markdown弹窗测试完成" -ForegroundColor Green
}
else {
Write-Host "❌ Markdown弹窗测试失败" -ForegroundColor Red
Write-Host "💡 请检查CLI工具是否正常工作" -ForegroundColor Yellow
}
}
function Test-CustomPopup {
Write-Host "🚀 创建自定义弹窗测试..." -ForegroundColor Yellow
$tempFile = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath "custom_popup_test.json"
$jsonContent = @'
{
"id": "custom-test-001",
"message": "# 🎨 自定义弹窗测试\n\n这是一个自定义的弹窗测试,用于验证弹窗功能的完整性。\n\n## ✨ 测试功能\n- 头部固定显示\n- 工具栏固定显示\n- 图片组件渲染\n- 输入框组件\n- 禁止选中非内容区域\n- Markdown紧凑渲染\n\n## 🔧 操作说明\n1. 测试主题切换按钮\n2. 测试打开主界面按钮\n3. 测试预定义选项选择\n4. 测试文本输入功能\n5. 测试图片粘贴功能\n\n```typescript\n// 示例代码\ninterface PopupTest {\n header: 'fixed'\n toolbar: 'fixed'\n content: 'scrollable'\n images: 'component-rendered'\n input: 'component-based'\n}\n```\n\n> **注意**: 请测试所有交互功能以确保弹窗工作正常。",
"predefined_options": [
"🎨 测试主题切换",
"🏠 测试主界面按钮",
"📝 测试文本输入",
"🖼️ 测试图片功能",
"⚡ 测试快捷键",
"✅ 测试完成",
"❌ 发现问题"
],
"is_markdown": true
}
'@
Write-Utf8NoBom -Path $tempFile -Content $jsonContent
Write-Host "📄 自定义测试内容:" -ForegroundColor Yellow
Show-JsonContent -FilePath $tempFile
Write-Host ""
$cliCmd = Get-CliCommand $script:DengExeName
Write-Host "🎯 启动自定义弹窗..." -ForegroundColor Green
Write-Host "执行命令: $cliCmd --mcp-request $tempFile" -ForegroundColor Cyan
& $cliCmd --mcp-request $tempFile
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ 自定义弹窗测试完成" -ForegroundColor Green
}
else {
Write-Host "❌ 自定义弹窗测试失败" -ForegroundColor Red
Write-Host "💡 请检查CLI工具是否正常工作" -ForegroundColor Yellow
}
Remove-Item -Path $tempFile -Force -ErrorAction SilentlyContinue
}
function Start-FrontendTest {
Write-Host "🚀 启动前端测试环境..." -ForegroundColor Yellow
Write-Host "测试环境将在 http://localhost:5174 启动" -ForegroundColor Cyan
Write-Host "💡 按 Ctrl+C 停止测试环境" -ForegroundColor Yellow
Write-Host ""
if (-not (Test-Command "pnpm")) {
Write-Host "❌ 未找到 pnpm 命令" -ForegroundColor Red
Write-Host "💡 请先安装 pnpm: npm install -g pnpm" -ForegroundColor Yellow
return
}
$packageJson = Join-Path -Path $script:ProjectRoot -ChildPath "package.json"
if (-not (Test-Path $packageJson)) {
Write-Host "❌ 未找到 package.json 文件" -ForegroundColor Red
return
}
Push-Location -Path $script:ProjectRoot
try {
& pnpm "test:ui"
}
finally {
Pop-Location
}
}
function Show-CliHelp {
Write-Host "📖 CLI工具帮助信息:" -ForegroundColor Yellow
Write-Host ""
$sanshuCmd = Get-CliCommand $script:SanshuExeName
$dengCmd = Get-CliCommand $script:DengExeName
Write-Host "三术 CLI:" -ForegroundColor Cyan
Write-Host "命令: $sanshuCmd" -ForegroundColor Cyan
& $sanshuCmd --help 2>$null
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ 帮助信息显示完成" -ForegroundColor Green
}
else {
Write-Host "⚠️ 三术 CLI 无帮助信息或不支持 --help 参数" -ForegroundColor Yellow
Write-Host "尝试直接运行: $sanshuCmd" -ForegroundColor Cyan
}
Write-Host ""
Write-Host "等一下 CLI:" -ForegroundColor Cyan
Write-Host "命令: $dengCmd" -ForegroundColor Cyan
& $dengCmd --help 2>$null
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ 帮助信息显示完成" -ForegroundColor Green
}
else {
Write-Host "⚠️ 等一下 CLI 无帮助信息或不支持 --help 参数" -ForegroundColor Yellow
Write-Host "尝试直接运行: $dengCmd" -ForegroundColor Cyan
Write-Host "MCP请求参数: $dengCmd --mcp-request <json_file>" -ForegroundColor Cyan
}
}
function Switch-CliType {
Write-Host "🔄 切换CLI类型" -ForegroundColor Yellow
if ($script:CliType -eq "global") {
Write-Host "当前CLI类型: 全局安装版本"
}
else {
Write-Host "当前CLI类型: 本地编译版本 ($($script:BuildType))"
}
Write-Host ""
if ($script:CliType -eq "global") {
$script:CliType = "local"
Write-Host "✅ 已切换到本地编译版本" -ForegroundColor Green
Select-BuildType
}
else {
$script:CliType = "global"
Write-Host "✅ 已切换到全局安装版本" -ForegroundColor Green
Check-GlobalCli
}
Write-Host ""
}
function Install-OrCompile {
if ($script:CliType -eq "global") {
Write-Host "🔨 安装全局CLI工具..." -ForegroundColor Yellow
Write-Host "执行命令: cargo install --path . --bins" -ForegroundColor Cyan
if (-not (Test-Command "cargo")) {
Write-Host "❌ 未找到 cargo 命令" -ForegroundColor Red
Write-Host "💡 请先安装 Rust: https://rustup.rs/" -ForegroundColor Yellow
return
}
& cargo install --path . --bins
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ 全局CLI工具安装完成" -ForegroundColor Green
Check-GlobalCli
}
else {
Write-Host "❌ 全局CLI工具安装失败" -ForegroundColor Red
}
}
else {
Write-Host "🔨 重新编译本地项目 ($($script:BuildType))..." -ForegroundColor Yellow
Compile-Project
Check-CliTools
}
}
function Main {
Write-Host "🎯 三术弹窗测试脚本" -ForegroundColor Cyan
Write-Host "================================" -ForegroundColor Cyan
Select-CliType
Check-CliTools
Check-TestFiles
Write-Host ""
while ($true) {
Show-TestOptions
$choice = Read-Host "请选择测试选项 (1-7, q)"
Write-Host ""
switch ($choice) {
"1" { Test-SimplePopup }
"2" { Test-MarkdownPopup }
"3" { Test-CustomPopup }
"4" { Start-FrontendTest }
"5" { Show-CliHelp }
"6" { Switch-CliType }
"7" { Install-OrCompile }
"q" { Write-Host "👋 测试结束,再见!" -ForegroundColor Green; exit 0 }
"Q" { Write-Host "👋 测试结束,再见!" -ForegroundColor Green; exit 0 }
default { Write-Host "❌ 无效选项,请重新选择" -ForegroundColor Red }
}
Write-Host ""
Write-Host "按回车键继续..." -ForegroundColor Yellow
[void](Read-Host)
Write-Host ""
}
}
# 检查依赖工具
Write-Host "🔍 检查依赖工具..." -ForegroundColor Cyan
if (-not (Test-Command "jq")) {
Write-Host "⚠️ 建议安装 jq 以获得更好的JSON显示效果" -ForegroundColor Yellow
Write-Host " Windows: winget install jqlang.jq 或 choco install jq" -ForegroundColor Yellow
Write-Host ""
}
else {
Write-Host "✅ jq 已安装" -ForegroundColor Green
}
if (-not (Test-Command "pnpm")) {
Write-Host "⚠️ 建议安装 pnpm 以使用前端测试环境" -ForegroundColor Yellow
Write-Host " 安装命令: npm install -g pnpm" -ForegroundColor Yellow
Write-Host ""
}
else {
Write-Host "✅ pnpm 已安装" -ForegroundColor Green
}
Write-Host ""
# 运行主函数
Main