🐛 fix(scripts): repair windows script parsing

fix powershell here-strings and help alias conflicts\nadd windows script lint test and run it in CI
This commit is contained in:
csh
2026-01-22 17:30:15 +08:00
parent 26a35e0ccf
commit 5a2925f846
8 changed files with 83 additions and 24 deletions
+12 -1
View File
@@ -11,7 +11,8 @@ tests/
│ ├── test_sync_standards.bats # sync_standards.sh 测试
│ ├── test_sync_templates.bats # sync_templates.sh 测试
│ ├── test_vendor_playbook.bats # vendor_playbook.sh 测试
── test_install_codex_skills.bats # install_codex_skills.sh 测试
── test_install_codex_skills.bats # install_codex_skills.sh 测试
│ └── test_windows_script_lints.bats # Windows 脚本 lint 测试
├── templates/ # 模板验证测试
│ ├── validate_python_templates.sh # Python 模板验证
│ ├── validate_cpp_templates.sh # C++ 模板验证
@@ -153,6 +154,16 @@ sh check_doc_links.sh
- **幂等性**
- 多次安装结果一致
#### test_windows_script_lints.bats
测试 Windows 脚本的基础 lint 规则:
- **PowerShell**
- here-string 终止符不与管道同一行
- Help 参数别名不与参数名冲突
- **Batch**
- `:show_help` 标签不应阻断参数解析
### 2. 模板验证测试 (templates/)
验证项目模板文件的正确性和完整性。
@@ -0,0 +1,44 @@
#!/usr/bin/env bats
# Windows script lint tests (PowerShell/Batch)
setup() {
export PLAYBOOK_ROOT="$(cd "$BATS_TEST_DIRNAME/../.." && pwd)"
}
@test "sync_standards.ps1 - here-string terminator not piped" {
run grep -nE "^[[:space:]]*['\\\"]@\\s*\\|" "$PLAYBOOK_ROOT/scripts/sync_standards.ps1"
[ "$status" -ne 0 ]
}
@test "sync_standards.ps1 - Help alias does not shadow parameter name" {
run grep -niE "Alias\\([^)]*['\"]help['\"]" "$PLAYBOOK_ROOT/scripts/sync_standards.ps1"
[ "$status" -ne 0 ]
}
@test "install_codex_skills.ps1 - Help alias does not shadow parameter name" {
run grep -niE "Alias\\([^)]*['\"]help['\"]" "$PLAYBOOK_ROOT/scripts/install_codex_skills.ps1"
[ "$status" -ne 0 ]
}
@test "sync_templates.ps1 - Help alias does not shadow parameter name" {
run grep -niE "Alias\\([^)]*['\"]help['\"]" "$PLAYBOOK_ROOT/scripts/sync_templates.ps1"
[ "$status" -ne 0 ]
}
@test "vendor_playbook.ps1 - Help alias does not shadow parameter name" {
run grep -niE "Alias\\([^)]*['\"]help['\"]" "$PLAYBOOK_ROOT/scripts/vendor_playbook.ps1"
[ "$status" -ne 0 ]
}
@test "sync_standards.bat - show_help label follows parse_args" {
local file="$PLAYBOOK_ROOT/scripts/sync_standards.bat"
local show_line
local parse_line
show_line=$(grep -n "^:show_help" "$file" | head -n 1 | cut -d: -f1)
parse_line=$(grep -n "^:parse_args" "$file" | head -n 1 | cut -d: -f1)
[ -n "$show_line" ]
[ -n "$parse_line" ]
[ "$show_line" -gt "$parse_line" ]
}