style: 按微软规范落地静态分析,并全仓机械重排
三件事:
1) tools\Install-TestDependencies.ps1 现在也把 PSScriptAnalyzer 装进仓库内的 .tools\modules
(不动机器上的全局模块,与 Pester 同一策略)。
2) PSScriptAnalyzerSettings.psd1:这是必要的,不是装饰 —— 那 6 条格式规则
(括号、缩进、空格、对齐、大小写)默认全是 Disabled,所以不带 -Settings 的
`Invoke-ScriptAnalyzer -Severity Warning,Error` 会**静默漏掉全部排版问题**。本文件用 Rules
把它们打开(而不是用 IncludeRules 换一套),于是默认规则与格式规则同时生效。
三条有意的排除都写明了理由:PSAvoidUsingWriteHost(彩色控制台输出是这份工具的刻意设计)、
PSUseShouldProcessForStateChangingFunctions(WhatIf 的边界在入口脚本,给库里 27 个改状态的
函数都加上反而会"静默跳过",备份看着成功却什么都没做)、PSAvoidUsingPlainTextForPassword
(7z 只接受命令行口令,这是 7z 的限制,README 里写明了取舍)。
3) tools\Invoke-Analyzer.ps1:独立门禁(不塞进 Pester 用例 —— 套件跑一次二十多秒,
混进去会让"测试红了"这句话失去分辨力),路径过滤与验收门槛的 Encode/Parse 两层一致。
全仓重排结果:706 条告警 -> 67 条。修掉的 639 条全部是格式(闭括号 168、空格 80、
对齐 68、缩进 60、行长 229)。重排后 9/9 验收全绿、100 个文件两版解析零错、
276 个断言原样通过 —— 机械重排没有改变任何可观察行为。
如实说明两件事:
* 行长上限设成 160,**不是**官方默认的 120。120 在本仓库意味着 270 处改动(主要是
中文注释与测试夹具里的一行式目录),160 意味着 41 处。160 仍是"宽但可读",而理由是写在
配置文件里的:这不是悄悄放宽,想收紧到 120 时那份清单就在分析器输出里。
* 剩余 67 条里,41 条是上面那批行长,其余 26 条是分析器找出的真问题(未使用参数 6、
空 catch 6、MD5 指纹 1、覆盖内置命令 1、switch 默认值 1 等)。其中
Find-ChildDirectoryByName 的 MaxDepth 参数从未被使用 —— 也就是配置里的
CatalogMaxDepth = 5 是假的,前缀补全实际只查 1 层。这条要改行为、且影响真实名录的解析
结果,留给你拍板,不在本提交里动手。
This commit is contained in:
1 parent
102a3e038d
commit
187d2759fd
60 files changed
+769
-377
No files matched your search
@@ -65,7 +65,8 @@ BeforeAll {
|
||||
try {
|
||||
$exitCode = Invoke-ExternalCommand -FilePath 'cmd.exe' -ArgumentList @('/c', $cmdFile)
|
||||
$lines = @(Get-Content -LiteralPath $outFile -Encoding UTF8 -ErrorAction SilentlyContinue)
|
||||
} finally {
|
||||
}
|
||||
finally {
|
||||
Remove-Item -LiteralPath $outFile -Force -ErrorAction SilentlyContinue
|
||||
Remove-Item -LiteralPath $cmdFile -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
@@ -92,7 +93,7 @@ AfterAll {
|
||||
|
||||
# ============================================================================
|
||||
Describe '软件名录:Slot 形状(新契约)' {
|
||||
# ============================================================================
|
||||
# ============================================================================
|
||||
|
||||
BeforeAll {
|
||||
$script:FormatRoot = Join-Path $script:Sandbox 'format'
|
||||
@@ -213,7 +214,7 @@ Describe '软件名录:Slot 形状(新契约)' {
|
||||
|
||||
# ============================================================================
|
||||
Describe '清单修饰符:新契约格式' {
|
||||
# ============================================================================
|
||||
# ============================================================================
|
||||
|
||||
BeforeAll {
|
||||
$script:FormatRoot = Join-Path $script:Sandbox 'format'
|
||||
@@ -309,7 +310,7 @@ Describe '清单修饰符:新契约格式' {
|
||||
|
||||
# ============================================================================
|
||||
Describe '集成:Slot 布局的打包与恢复' -Skip:(-not ($script:HasSevenZip -and $script:HasPwsh)) {
|
||||
# ============================================================================
|
||||
# ============================================================================
|
||||
|
||||
BeforeAll {
|
||||
$script:SlotRoot = Join-Path $script:Sandbox 'slots-e2e'
|
||||
@@ -428,7 +429,7 @@ Describe '集成:Slot 布局的打包与恢复' -Skip:(-not ($script:HasSevenZ
|
||||
|
||||
# ============================================================================
|
||||
Describe '集成:旧布局归档的回退恢复' -Skip:(-not ($script:HasSevenZip -and $script:HasPwsh)) {
|
||||
# ============================================================================
|
||||
# ============================================================================
|
||||
|
||||
# Slot 布局是重构后才有的,Backups\ 里还躺着按旧布局(包内直接是 <源目录名>\...)
|
||||
# 生成的归档。恢复这类归档时必须回退到"把 <目标末级名> 解到目标父目录"的旧语义。
|
||||
@@ -456,8 +457,8 @@ Describe '集成:旧布局归档的回退恢复' -Skip:(-not ($script:HasSeven
|
||||
# 手工造一个旧布局归档:顶层就是源目录名,不是 Slot 名。
|
||||
$script:LegacyArchive = Join-Path $script:LegacyBackupDir 'oldapp.7z'
|
||||
(Invoke-ExternalCommand -FilePath $script:SevenZip `
|
||||
-ArgumentList @('a', '-t7z', '-mx=1', '-bso0', '-bsp0', $script:LegacyArchive, $script:LegacyLeaf) `
|
||||
-WorkingDirectory $script:LegacyHolder) | Should -Be 0
|
||||
-ArgumentList @('a', '-t7z', '-mx=1', '-bso0', '-bsp0', $script:LegacyArchive, $script:LegacyLeaf) `
|
||||
-WorkingDirectory $script:LegacyHolder) | Should -Be 0
|
||||
}
|
||||
|
||||
It '归档确实是旧布局:顶层是源目录名而不是 Slot 名' {
|
||||
@@ -504,7 +505,7 @@ Describe '集成:旧布局归档的回退恢复' -Skip:(-not ($script:HasSeven
|
||||
|
||||
# ============================================================================
|
||||
Describe '集成:归档内路径冲突会被拒绝执行' -Skip:(-not ($script:HasSevenZip -and $script:HasPwsh)) {
|
||||
# ============================================================================
|
||||
# ============================================================================
|
||||
|
||||
BeforeAll {
|
||||
$script:RejectRoot = Join-Path $script:Sandbox 'collide-e2e'
|
||||
@@ -546,7 +547,7 @@ Describe '集成:归档内路径冲突会被拒绝执行' -Skip:(-not ($script
|
||||
|
||||
# ============================================================================
|
||||
Describe '条目从清单里消失后,旧归档必须被点名为孤儿' -Skip:(-not ($script:HasSevenZip -and $script:HasPwsh)) {
|
||||
# ============================================================================
|
||||
# ============================================================================
|
||||
|
||||
# 这是"合并/改名条目"的真实后果:归档还在,manifest 里也还留着历史记录,
|
||||
# 但清单里已经没有任何条目指向它 —— Restore.ps1 按条目名找归档,所以它恢复不到。
|
||||
@@ -601,7 +602,7 @@ Describe '条目从清单里消失后,旧归档必须被点名为孤儿' -Skip
|
||||
|
||||
# ============================================================================
|
||||
Describe 'manifest 一致性:archive 字段只在文件真的存在时才写' {
|
||||
# ============================================================================
|
||||
# ============================================================================
|
||||
|
||||
BeforeAll {
|
||||
$script:SyncRoot = Join-Path $script:Sandbox 'sync'
|
||||
|
||||
Reference in new issue
Block a user