fix(m161): 收更新键/按钮/矮窗口/启动错误/导入结果五笔债

① update.auto_check / update.channel 登记进 core setting schema(1.6.0)
   - 新增 setting/keys/update.rs(两键 + UPDATE_CHANNELS,只允许 stable);
     SettingSchema 加 with_all 供域键表批量登记。
   - 新增 setting/update_prefs.rs:cache/update/prefs.json → launcher.json 的一次性迁移。
     四条硬约束:源指纹闸门(幂等)、不丢 false、新值胜出、旧文件改名 .migrated 后不再被读;
     主配置不可写时不动旧文件。收据 config/update-prefs-migration.json。
   - presenter Runtime 建会话时迁一次并把结局留在 migration();prefs 字段换成
     auto_check + 每次派发从主配置读 channel(不再硬编码 Channel::Stable)。
     保留旧字段 auto_check 的真实来源(原有测试 cases 会断言)。
   - CLI config get/set/dump 先跑同一次迁移(幂等),输出里给 migration 段与收据路径。

② presenter/dto/events.rs 的「本次会话不再弹提示条」注释改成真实语义
   (记的是版本号:同版本压住、更高版本照弹、手动检查清掉)。

③ 检查/下载进行中按钮禁用:pages/update/busy.rs 的 busy/can_check/can_apply;
   设置页两颗按钮改画禁用(不是消失),app 层 on_update_action 再挡一道
   (忙碌时 CheckNow/Apply 不派发);新增两条用例(含「忙完恢回可点」)。

④ 内容库低高度:content_layout::MIN_BODY_HEIGHT=460 + BodyMode(按固定件+三整行算出来,
   用例守着算式);frame::body_height 从 Ui::metrics 算正文可用高,pages::Model 带 window_height。
   ≥460 列表自己滚;<460 主列整列一个滚动条、列表按自然高度铺开。

⑤ 启动错误文案本地化:presenter 删掉 launch_summary / 「启动失败:」前缀 / 五条中文阶段前缀,
   改发 LaunchFailureView{stage,detail};LaunchFinished 改带 exit_code/uptime_ms/failure,
   Toast 由 app 层按 i18n key 现求(与 install_cancelled 同构)。InstancesFailed 拆成
   InstancesFailedStage(列表单行)+ LaunchStageFailed(详情/Toast 全文)。

⑥ 导入结果块:ImportReportView 加 failure_stage(NotStarted/RolledBack/RollbackIncomplete,
   由 core 的 rollback 机器位推出);标题、图标、底色三处分档,预检失败不再说「已回滚」。

顺带:六处注释/文档漂移(update.rs 的分工表与偏好落点、pack 的「已整包回滚」、
build_request 的 Errors、settings/update 的按钮禁用说明等),
以及为守 400 行把 update/cli-config/core-keys/presenter-dto/presenter-launch/i18n-golden
里贴线或越线的文件按模块拆开(纯搬移,行为不变)。
This commit is contained in:
AskaEth committed 2026-11-07 15:02:13 +08:00
1 parent b2d9f3927f
commit 03741ecd2d
69 files changed
+2653 -707

No files matched your search

@@ -0,0 +1,70 @@
//! M159 的遗留更新偏好 → 主配置(`update.auto_check`)的迁移(M161)。
//!
//! 从 `commands/config.rs` 拆出:那边贴着 400 行硬线,而这块是**独立的一件事**
//! (遗留文件的桥接),与 get/set 的排版逻辑无关。
use serde_json::{json, Value};
use unlucky_core::setting::update_prefs::{self, Migration};
use crate::context::Ctx;
/// M159 的遗留更新偏好 → 主配置的迁移结果(只在**有话说**时返回)。
pub(super) struct PrefsNote {
/// 人读一行(`config get/set` 的人类可读输出里追加)
pub(super) human: String,
/// 同一件事的机器可读形状(`--json` 信封里追加)
pub(super) data: Value,
}
/// 把 `<数据根>/cache/update/prefs.json` 迁进 `launcher.json`(M161)。
///
/// 为什么 `config` 这个**读命令**也会写盘:那份遗留文件对 CLI 本来就不可见——用户在手头没 GUI
/// 的机器上 `config get update.auto_check`,旧实现永远回默认 `true`,而他的开关可能是关的。
/// 迁移是**幂等**的(源指纹闸门 + 旧文件改名 `.migrated`),有收据,且在写不进去时什么都不动
/// (见 [`unlucky_core::setting::update_prefs`])。没有旧文件时这里只是一次 `stat`。
pub(super) fn migrate_update_prefs(ctx: &Ctx) -> Option<PrefsNote> {
let layout = ctx.layout();
let paths = update_prefs::Targets {
launcher: &ctx.launcher_config(),
legacy: &layout.cache().join("update").join("prefs.json"),
receipt: &layout.config().join(update_prefs::RECEIPT_FILE),
};
let now = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|elapsed| u64::try_from(elapsed.as_millis()).unwrap_or(u64::MAX))
.unwrap_or(0);
let migration = update_prefs::migrate(paths, now);
let (human, detail) = match &migration {
Migration::Nothing => return None,
Migration::Migrated { auto_check, .. } => (
format!(
"已把旧更新偏好迁入主配置:update.auto_check = {auto_check}(收据 {})",
paths.receipt.display()
),
format!("update.auto_check = {auto_check} 已迁移"),
),
Migration::NewValueWins { auto_check, .. } => (
format!(
"旧更新偏好文件已退役(主配置里已有 update.auto_check = {auto_check},新值胜出;收据 {})",
paths.receipt.display()
),
"旧文件已退役,主配置的值未改动".to_string(),
),
Migration::Unreadable { path, reason } => (
format!("旧更新偏好读不出来({}):{reason}", path.display()),
"旧文件坏,未迁移".to_string(),
),
Migration::Refused { reason } => (
format!("旧更新偏好未迁移:{reason}"),
"主配置不可写,未迁移".to_string(),
),
};
Some(PrefsNote {
human,
data: json!({
"id": migration.as_str(),
"receipt": migration.receipt().map(|path| path.display().to_string()),
"detail": detail,
}),
})
}
+64
View File
@@ -254,3 +254,67 @@ fn unknown_schema_prefix_warns_and_still_shows_file_values() {
report.human
);
}
/// M161:`ull config get update.auto_check` 读的是**主配置**,而且会把 M159 遗留的
/// `cache/update/prefs.json` 先迁进来(迁移收据在 `migration` 里可查)。
///
/// 这条是 mission「`ull config get update.auto_check` 真能读到」的端到端证明:
/// 旧文件里 `false` → 迁移 → 主配置 → CLI 输出 `false`(**不是**默认的 `true`)。
#[test]
fn the_update_switch_is_migrated_and_readable_from_the_cli() {
let temp = TempDir::new("update-prefs");
let exe = temp.path().join("exe");
let ctx = ctx_with(Globals::default(), &exe);
// 旧域内文件(M159 的落点):开关是关的。
let legacy = ctx.layout().cache().join("update").join("prefs.json");
write_json(&legacy, &json!({ "auto_check": false }));
let report = get(&ctx, Some("update.auto_check"), false).expect("读 update.auto_check");
assert_eq!(
report.data["value"],
json!(false),
"旧文件里的 false 必须读到(默认值是 true,读成默认就是丢值)"
);
assert_eq!(
report.data["path"],
json!(ctx.launcher_config().display().to_string()),
"落点必须是主配置(schema API),不是更新域自己的文件"
);
assert_eq!(
report.data["migration"]["id"],
json!("migrated"),
"迁移要走一遍并如实报出来:{report:?}"
);
let receipt = report.data["migration"]["receipt"]
.as_str()
.expect("收据路径")
.to_string();
assert!(Path::new(&receipt).is_file(), "收据可查:{receipt}");
assert!(!legacy.exists(), "旧文件必须退役");
assert!(
report
.human
.iter()
.any(|line| line.contains("已把旧更新偏好迁入主配置")),
"{:?}",
report.human
);
// 第二遍:什么都不做(幂等),值仍是 false。
let again = get(&ctx, Some("update.auto_check"), false).expect("再读一遍");
assert_eq!(again.data["value"], json!(false));
assert!(
again.data.get("migration").is_none(),
"第二遍不该再报迁移:{again:?}"
);
// `channels` 里只有 stable 时,写 beta 要当面被拒(而不是静默写成「设了没生效」)。
let error = set(&ctx, "update.channel", "beta").expect_err("beta 不在允许值里");
assert!(error.to_string().contains("beta"), "{error}");
// 允许值写得进去,且读得回来。
set(&ctx, "update.channel", "stable").expect("写 stable");
let channel = get(&ctx, Some("update.channel"), false).expect("读 update.channel");
assert_eq!(channel.data["value"], json!("stable"));
}