feat(tui): 主入口 Manage-Backup 与配置入口 Edit-Config(第一轮第六块·完成)
Manage-Backup.ps1:不带参数进 TUI 主菜单(备份 / 恢复 / 配置);带 -Action 直接做那个动作,可配 -Quiet 走无头。退出码原样传出(计划任务靠它);只有两种情况由它自己给码:进不了交互界面(2)与菜单里按 Esc(0)。 动作目前仍是**子进程**:一份编排、两个前端是终局目标(ADR-0012),但那要求先把编排从入口脚本下沉进模块。先让 TUI 能用起来,等下沉做完把子进程调用换成进程内直调,界面层不受影响。 -Quiet 与交互两条路的输出处理**故意不同**:-Quiet 时调用方要拿输出(管道 / 日志 / 计划任务),所以捕获并转发;交互时让子进程继承控制台,输出实时、顺序正确、还能接键盘。这套转发收进模块函数 Invoke-BakNRetEntryScript(垫片与主入口共用同一处逻辑)。 Edit-Config.ps1:把已做好的清单编辑器挂上(外科式改写 + 校验通过才落盘 + 时间戳备份);设置与名录两个界面明确报"还没做"并返回非零,而不是假装成功。 判据 7 条。过程中夹具又踩了"& 不传退出码"这个事实(我在垫片那层修过,却在测试夹具这一层又犯)—— 所以断言里改用 -File 调入口;输出检查走**文件重定向**而不是管道捕获(与 E2E 同一个理由:沙箱下给子进程建管道可能失败,写文件不会)。 验收:test.ps1 9/9 全绿(5.1 与 7);真实清单只读冒烟 4/4。
This commit is contained in:
1 parent
4e3c0461c0
commit
c2bae35506
6 files changed
+257
No files matched your search
@@ -1703,6 +1703,39 @@ Test-Case '源码里不得出现"左边空的赋值"(用脚本生成代码时
|
||||
Assert-Equal 0 $offenders.Count ('这些行看起来是赋值、左边却是空的:' + ($offenders -join ' / '))
|
||||
}
|
||||
|
||||
Test-Case '主入口:-Quiet 不画界面、菜单能渲染、进不去界面时明确失败(退出码 2)' {
|
||||
$repoRoot = Split-Path -Parent $PSScriptRoot
|
||||
$probe = Join-Path $env:TEMP ("bnr-entry-" + [guid]::NewGuid().ToString('N').Substring(0, 8))
|
||||
New-Item -ItemType Directory -Path $probe -Force | Out-Null
|
||||
try {
|
||||
# 输出检查走**文件重定向**(子 pwsh 自己把输出写文件),不走管道捕获 ——
|
||||
# 与 E2E 套件同一个理由:沙箱下给子进程建管道可能失败,而写文件不会。
|
||||
$quietOut = Join-Path $probe 'quiet.txt'
|
||||
& pwsh -NoProfile -File (Join-Path $repoRoot 'Manage-Backup.ps1') -Action Backup -Quiet -DryRun *> $quietOut
|
||||
Assert-Equal 0 $LASTEXITCODE '-Quiet 干跑应当退出 0'
|
||||
$quietText = Get-Content -LiteralPath $quietOut -Raw -Encoding UTF8
|
||||
Assert-True ($quietText -match '日志文件') '-Quiet 下子进程的输出应当被转发出来'
|
||||
Assert-True ($quietText -notmatch '↑↓') '-Quiet 下不该出现任何 TUI 提示'
|
||||
|
||||
# 菜单:给按键序列就能驱动(Esc 直接退出,退出码 0),并且真的画了界面
|
||||
$menuOut = Join-Path $probe 'menu.txt'
|
||||
& pwsh -NoProfile -File (Join-Path $repoRoot 'Manage-Backup.ps1') -InputScript Esc *> $menuOut
|
||||
Assert-Equal 0 $LASTEXITCODE '菜单按 Esc 应当退出 0'
|
||||
$menuText = Get-Content -LiteralPath $menuOut -Raw -Encoding UTF8
|
||||
Assert-True ($menuText -match '↑↓ 选择') '菜单应当渲染出提示行'
|
||||
Assert-True ($menuText -match '备份') '菜单应当列出动作'
|
||||
|
||||
# 没有控制台也没有按键序列:明确失败,绝不挂起
|
||||
$noConsoleOut = Join-Path $probe 'noconsole.txt'
|
||||
& pwsh -NoProfile -File (Join-Path $repoRoot 'Manage-Backup.ps1') *> $noConsoleOut
|
||||
Assert-Equal 2 $LASTEXITCODE '进不了交互界面应当退出 2'
|
||||
$ncText = Get-Content -LiteralPath $noConsoleOut -Raw -Encoding UTF8
|
||||
Assert-True ($ncText -match '-Action') '报错里应当告诉你怎么非交互执行'
|
||||
} finally {
|
||||
Remove-Item -LiteralPath $probe -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