feat: 运行结尾输出分类详细的结果汇总(成功/跳过/失败/安全/孤儿)
原先结尾只有一行计数加一个失败清单。计数回答有几个,而人真正要读的是哪几个、为什么——尤其当失败或跳过发生在你没盯着屏幕的时候(计划任务)。 新的 Write-BakNRetRunSummary 按动作分组逐条列出:成功组带归档名/体积/耗时/sha256 前 12 位、以及有文件没打进归档的警告标记;跳过组带具体原因(源未更新/源不存在/路径无效);失败组带退出码与原因原文,并且再单列一遍。另有安全描述符与孤儿归档两段,空分组不打印,末尾给耗时。 数据来源是 manifest 里本次运行写下的记录(按 finishedAt 落在运行窗口内筛),而不是让调用方另维护一份清单。 搬的过程里翻车一次并被自己的断言拦住:Get-RecField 只用 PSObject.Properties.Name 判字段存在,而那是 PSCustomObject 的形态;本进程新造的记录是 [ordered] 字典,于是字段一律读成 $null,现象是"本次运行没有写下任何条目记录"(记录明明在)。现在两种形态都认。 一个已知没做的:排除规则只在内联逐条打印,没进汇总——我没定位到那个打印点,不愿意凭猜往条目循环里插桩。 断言:零依赖套件新增一条,用真日志文件验收汇总内容,并断言空分组不出现。验收:test.ps1 9/9 全绿(7 与 5.1)。
This commit is contained in:
1 parent
e8f0a5ae19
commit
187549e2af
6 files changed
+186
-25
No files matched your search
@@ -1384,6 +1384,42 @@ Test-Case '条目记录的字段名与顺序是 manifest 的 schema(顺序变
|
||||
Assert-True ($record.attemptedAt -ne $again.attemptedAt) '两条记录的 attemptedAt 不该相同'
|
||||
}
|
||||
|
||||
Test-Case '结果汇总:分类列出成功/跳过/失败,带原因与失败明细,空分组不打印' {
|
||||
$dir = Join-Path $env:TEMP ("bnr-summary-" + [guid]::NewGuid().ToString('N').Substring(0, 8))
|
||||
New-Item -ItemType Directory -Path $dir -Force | Out-Null
|
||||
$manifest = @{ items = [ordered]@{} }
|
||||
$started = (Get-Date).AddSeconds(-30)
|
||||
$specs = @(
|
||||
@{ N = 'GoodApp'; A = 'backed-up'; R = $null; X = @{ archive = 'GoodApp.7z'; sha256 = 'abcdef1234567890'; sourceBytes = 1048576 } },
|
||||
@{ N = 'OldApp'; A = 'skip-unchanged'; R = '源最新修改时间不晚于归档时间'; X = @{} },
|
||||
@{ N = 'BadApp'; A = 'failed'; R = '压缩失败(退出码 2)'; X = @{} }
|
||||
)
|
||||
foreach ($spec in $specs) {
|
||||
$rec = New-BakNRetItemRecord -BaseName $spec.N -Source 'x' -ResolvedSource 'y' -Phase 'backup'
|
||||
$rec.action = $spec.A
|
||||
$rec.reason = $spec.R
|
||||
foreach ($k in $spec.X.Keys) { $rec[$k] = $spec.X[$k] }
|
||||
$rec.finishedAt = (Get-Date).ToString('o')
|
||||
$manifest.items[$spec.N] = $rec
|
||||
}
|
||||
try {
|
||||
Start-BakNRetLog -Directory $dir -Prefix 'summary' | Out-Null
|
||||
Write-BakNRetRunSummary -Mode 'backup' -Manifest $manifest -StartedAt $started -Failures @('BadApp:压缩失败(退出码 2)') -Counters @{ 失败 = 1 }
|
||||
$logPath = Get-BakNRetLogPath
|
||||
Stop-BakNRetLog
|
||||
$text = Get-Content -Encoding UTF8 -LiteralPath $logPath -Raw
|
||||
Assert-True ($text -match '结果汇总') '应当打印汇总标题'
|
||||
Assert-True ($text -match 'GoodApp') '应当列出成功的条目'
|
||||
Assert-True ($text -match '源未更新') '应当有跳过分组'
|
||||
Assert-True ($text -match '压缩失败(退出码 2)') '应当带上失败原因原文'
|
||||
Assert-True ($text -match '失败明细') '应当单列失败明细'
|
||||
Assert-True ($text -notmatch 'missing-source') '空分组不该出现'
|
||||
} finally {
|
||||
if (Get-BakNRetLogPath) { Stop-BakNRetLog }
|
||||
Remove-Item -LiteralPath $dir -Recurse -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
Remove-Item -LiteralPath $sandbox -Recurse -Force -ErrorAction SilentlyContinue
|
||||
Remove-Item -LiteralPath $itemSandbox -Recurse -Force -ErrorAction SilentlyContinue
|
||||
|
||||
Reference in new issue
Block a user