fix(settings): 备份主机状态不得由历史下发推断

为什么:host_configured=false 时页面宣称"定时计划不会执行",但平台只是没挂载
主机凭据,远端既有 cron 可能仍在跑;最后下发是历史记录,也不能证明当前计划。

怎么改:无凭据时改为"无法确认当前主机计划/远端 cron 可能仍在执行";最后下发标为
历史并注明不能代表当前状态;未探测与探测失败分开;"与设置是否一致"只在真正读回
主机计划后判定。

怎么验:新增无凭据 + 有效历史下发、已接线未探测两例回归,断言不出现"不会执行";
vitest 619 项、tsc、prettier 通过;本地页面夹具 C 面板核对文案。
This commit is contained in:
姚章浩
2026-11-19 23:45:15 +08:00
parent 6444814123
commit 9eacf6473e
3 changed files with 78 additions and 25 deletions
+43 -21
View File
@@ -254,10 +254,24 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
days !== schedule.retention_days ||
months !== schedule.retention_months
const hostLine = !schedule.host_configured
? '未接线(缺少主机凭据)'
? '平台未挂载主机凭据(远端状态未知)'
: schedule.host_reachable
? `${schedule.host_target} · 已连接`
: `${schedule.host_target} · 连接失败`
: schedule.host_checked_at || schedule.host_error
? `${schedule.host_target} · 连接失败`
: `${schedule.host_target} · 尚未探测`
// 未探测与探测失败必须分开:只读计划先返回时 reachable=false 不代表连不上。
const hostProbePending =
schedule.host_configured && !schedule.host_reachable && !schedule.host_checked_at && !schedule.host_error
const syncLine = !schedule.host_configured
? '无法比对(未读取主机计划)'
: hostProbePending
? '尚未比对'
: !schedule.host_reachable
? '无法比对(主机不可达)'
: schedule.in_sync
? '已一致'
: '待下发'
// 只有真的连上并读回主机状态时,才能说脚本在不在;连不上是"未知"。
const scriptLine = !schedule.host_reachable
? '未知(未连上主机,未执行主机侧脚本)'
@@ -295,7 +309,7 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
<div className="storage-block-heading">
<h3 id="storage-scope-heading">范围与读写方向</h3>
<span className={`storage-chip ${schedule.host_configured ? 'ok' : 'off'}`}>
{schedule.host_configured ? '主机已接线' : '主机未接线'}
{schedule.host_configured ? '平台已接主机凭据' : '平台未接主机凭据'}
</span>
</div>
<dl className="storage-facts">
@@ -475,14 +489,16 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
</div>
<p className="storage-plan">
{!schedule.host_configured
? '主机未接线:定时计划不会执行。'
: !schedule.host_reachable
? '主机连不上:以下"主机生效"状态未知,不能按设置推定。'
: schedule.host_schedule_enabled
? `主机生效:每天 ${schedule.host_schedule_time} · 保留 ${schedule.host_keep_days} 天 · 每月 ${schedule.host_keep_months} 份 · ${
schedule.in_sync ? '与设置已一致' : '与设置不一致(待下发)'
}`
: '主机生效:定时备份已关闭(已有备份保留)'}
? '平台未挂载主机凭据:无法读取当前主机计划,远端 cron 是否仍在执行未知(历史下发不能代替实时状态)。'
: hostProbePending
? '尚未探测当前主机计划:不能按设置或历史下发推定。'
: !schedule.host_reachable
? '主机连不上:以下"主机生效"状态未知,不能按设置推定。'
: schedule.host_schedule_enabled
? `主机生效:每天 ${schedule.host_schedule_time} · 保留 ${schedule.host_keep_days} 天 · 每月 ${schedule.host_keep_months} 份 · ${
schedule.in_sync ? '与设置已一致' : '与设置不一致(待下发)'
}`
: '主机生效:定时备份已关闭(已有备份保留)'}
{schedule.host_next_run ? ` · 下次 ${schedule.host_next_run}` : ' · 下一次实际执行未由主机返回'}
</p>
<p className="storage-plan">
@@ -656,7 +672,7 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
<p className="hint">
{schedule.last_run_error
? `最近一次结果读取失败:${schedule.last_run_error}`
: '还没有读到任何批次(主机未接线、连不上或尚未执行过);不能据此判断备份成功或失败。'}
: '还没有读到任何批次(平台未接主机凭据、主机连不上或尚未执行过);不能据此判断备份成功或失败。'}
</p>
)}
</section>
@@ -665,7 +681,11 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
<div className="storage-block-heading">
<h3 id="storage-host-heading">主机状态(读回)</h3>
<span className="hint">
{schedule.host_checked_at ? `读取于 ${formatBackupMoment(schedule.host_checked_at)}` : '尚未探测'}
{!schedule.host_configured
? '未探测(平台未挂载主机凭据)'
: schedule.host_checked_at
? `读取于 ${formatBackupMoment(schedule.host_checked_at)}`
: '尚未探测'}
</span>
</div>
<div className="storage-settings-grid">
@@ -683,10 +703,12 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
{schedule.host_next_run
? schedule.host_next_run
: !schedule.host_configured
? '未接通备份执行主机:当前计划不会执行'
: schedule.host_schedule_enabled
? `已配置每日 ${schedule.host_schedule_time};尚未核验下一次实际执行(不以历史下发时间推算)`
: '未启用定时或未从主机读到计划'}
? '无法确认当前主机计划:平台未挂载主机凭据,远端 cron 可能仍在执行(历史下发不能代替实时状态)'
: hostProbePending
? '尚未探测主机,无法确认下一次执行'
: schedule.host_schedule_enabled
? `已配置每日 ${schedule.host_schedule_time};尚未核验下一次实际执行(不以历史下发时间推算)`
: '未启用定时或未从主机读到计划'}
</dd>
</dl>
<dl>
@@ -705,12 +727,12 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
: '—'}
</dd>
<dt>与设置是否一致</dt>
<dd>{schedule.in_sync ? '已一致' : '待下发'}</dd>
<dt>最后下发</dt>
<dd>{syncLine}</dd>
<dt>最后下发(历史)</dt>
<dd>
{schedule.last_applied_at
? `${formatBackupMoment(schedule.last_applied_at)}${schedule.last_applied_summary ? ` · ${schedule.last_applied_summary}` : ''}`
: '—'}
? `${formatBackupMoment(schedule.last_applied_at)}${schedule.last_applied_summary ? ` · ${schedule.last_applied_summary}` : ''} · 只记录当时下发结果,不能代表当前主机计划或执行状态`
: '—(没有历史下发记录;不能据设置推定主机计划)'}
</dd>
</dl>
</div>