refactor: 公共面补 BakNRet 前缀,产品名大小写全仓统一
16 个没有前缀的公共函数补上 BakNRet(Write-Log → Write-BakNRetLog、Resolve-BackupEntry → Resolve-BakNRetBackupEntry、Find-ChildDirectoryByName → Find-BakNRetChildDirectoryByName 等), 另外把全仓的 Baknret 统一成 BakNRet(47 个文件、940 处、65 个定义文件重命名)。 这不是审美问题:静态分析直接拓出一条实据 —— Write-Log 与本机某个已装模块导出的命令 **重名**(PSAvoidOverwritingBuiltInCmdlets),而重名的后果是导入两个模块时有一方的命令被 静默遮蔽。补前缀正是这条规则的解法,改名后它归零。 为什么敢做这个规模:PowerShell 的函数名解析大小写不敏感,所以 Baknret → BakNRet 在功能 上是零风险;真正要验证的是 16 个补前缀的调用点,而 276 个断言几乎覆盖了每个函数。另外 "名字与文件名一致"这条不变式有断言盯着(加载器点源的文件集合 vs 磁盘)。 踩到并记下的坑:Windows 文件系统大小写不敏感,所以**只改大小写**的重命名会被 Move-Item 当成同一个文件而静默跳过 —— 同一批里同时改了名字的那 16 个文件却成功了,于是"看起来能跑"。 最后用"先移到临时名、再移到目标名"的两步走解决,判断与替换全部改用显式大小写敏感的形式 (-creplace / -cmatch)。 顺带把名录指纹缓存从 MD5 换成 SHA256(PSAvoidUsingBrokenHashAlgorithms):它只是缓存键, 没有兼容负担。 验收:test.ps1 9/9 全绿(7 与 5.1)、100 个文件两版解析零错、276 个断言全过、 构建工具仍能合回单文件(3300 行)。
This commit is contained in:
1 parent
187d2759fd
commit
42f02d0eca
84 files changed
+1043
-1043
No files matched your search
@@ -58,13 +58,13 @@ if (-not (Test-Path -LiteralPath $manifestPath)) {
|
||||
exit 0
|
||||
}
|
||||
|
||||
$config = Get-BaknretConfig -Path $configPath
|
||||
$catalogPath = Resolve-CatalogPath -Configured $config.SoftwareCatalog -Root $projectRoot
|
||||
$config = Get-BakNRetConfig -Path $configPath
|
||||
$catalogPath = Resolve-BakNRetCatalogPath -Configured $config.SoftwareCatalog -Root $projectRoot
|
||||
$listLines = @(Get-Content -Encoding UTF8 -LiteralPath $listPath)
|
||||
|
||||
# 用 cmd 批次文件把子进程输出落盘再读回。为什么不用 `& pwsh ... 2>&1` 直接捕获:
|
||||
# 那会给子进程建管道,在受限环境 / 沙箱里会被直接拒绝(见 tests\BakNRet.Tests.ps1 里的同款注释)。
|
||||
function Invoke-BaknretCaptured {
|
||||
function Invoke-BakNRetCaptured {
|
||||
param([string]$Script, [string[]]$Arguments)
|
||||
|
||||
$hostExe = if ($PSVersionTable.PSEdition -eq 'Core') { 'pwsh' } else { 'powershell' }
|
||||
@@ -130,7 +130,7 @@ Test-Case '真实清单里每个条目都能解析出方向,且软件名都能
|
||||
if ($item.Direction -eq 'backup') { $backupOnly++ }
|
||||
if ($item.Direction -eq 'restore') { $restoreOnly++ }
|
||||
|
||||
$resolved = Resolve-BackupEntry -Entry $item -CatalogPath $catalogPath -MaxDepth $config.CatalogMaxDepth
|
||||
$resolved = Resolve-BakNRetBackupEntry -Entry $item -CatalogPath $catalogPath -MaxDepth $config.CatalogMaxDepth
|
||||
if ($resolved.Error -and $resolved.Error -like '*名录里没有*') { $catalogMiss += $resolved.Error }
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ Write-Host "`n== 只读模式不写一个字节 ==" -ForegroundColor Cyan
|
||||
Test-Case 'Backup.ps1 -DryRun 退出 0、不再有"名录里没有"告警、manifest 不变' {
|
||||
$before = Get-ManifestHash
|
||||
$arguments = @('-BackupListPath', $listPath, '-DryRun', '-QuietTool', '-Only') + $SampleEntries
|
||||
$run = Invoke-BaknretCaptured -Script $backupScript -Arguments $arguments
|
||||
$run = Invoke-BakNRetCaptured -Script $backupScript -Arguments $arguments
|
||||
|
||||
Assert-Equal 0 $run.ExitCode ("DryRun 退出码不是 0;输出尾部:" + ($run.Output -split "`n" | Select-Object -Last 4 | Out-String))
|
||||
Assert-False ($run.Output -match "名录里没有 '") "DryRun 仍然把某些条目当成查不到的软件名"
|
||||
@@ -153,7 +153,7 @@ Test-Case 'Backup.ps1 -DryRun 退出 0、不再有"名录里没有"告警、mani
|
||||
|
||||
Test-Case 'Restore.ps1 -VerifyOnly 退出 0、把行首 + 识别成"仅备份"、manifest 不变' {
|
||||
$before = Get-ManifestHash
|
||||
$run = Invoke-BaknretCaptured -Script $restoreScript -Arguments @(
|
||||
$run = Invoke-BakNRetCaptured -Script $restoreScript -Arguments @(
|
||||
'-BackupListPath', $listPath, '-VerifyOnly', '-Only', $RestoreSample, '-Verbose')
|
||||
|
||||
Assert-Equal 0 $run.ExitCode ("VerifyOnly 退出码不是 0;输出尾部:" + ($run.Output -split "`n" | Select-Object -Last 4 | Out-String))
|
||||
|
||||
Reference in new issue
Block a user