M201 r2: 修视觉 r1 的两条 P2 + 代码复审的坏值提示 p2

视觉 r1(fix-then-merge):
- P2-1 分隔线贴字:downloaded 组的行间距从 0 改成 `Space::X3`(12dp)。实测
  说明末行→分隔线 1–3px → **12–13px**、分隔线→下一标题 4–5px → **12–17px**
  (同族页 9–18px;同一把尺子量演示回退卡 16–19px)。不动 `frame::divider` /
  `demo_card`;`spacing` 只作用于子节点之间,卡片首行顶距与末行底距仍是 20。
- P2-2 孤字「效」:`with_note` 把「原值 X 已按出厂 N 生效」从说明段落里挪到
  **独立一行**(`\n` 分隔,渲染器按行断)。浅/深/窄三张复验:无 <20px 窄行。
  两种措辞(出厂 8 / 已按 1)一字未改,presenter 侧新增 `ends_with("\n原值 …")`
  断言把「独占一行」钉住。

代码复审 p2(非整数坏值被静默丢掉):
- `raw_int`(`Value::as_i64`)→ `raw_text`:文件里显式写过的原值转**上屏文本**
  (字符串取原文不带 serde 引号、数字/布尔 `to_string`、`null` 当没写)。
  于是 `"auto"` / `8.5` / `true` / `-4` 都能进那句提示,不再「画着 8 却说不出
  用户写的 auto 被忽略」。
- 新用例 `every_bad_value_shape_says_what_the_raw_value_was`:负整数 / 字符串 /
  浮点 / 布尔 / null 五种形态。

验证:fmt --all --check / check -p unlucky-app-iced --all-targets /
test -p unlucky-app-iced(845+6) / test -p unlucky-presenter(316) /
test -p unlucky-i18n(36),全部 EXIT=0。
This commit is contained in:
AskaEth committed 2026-11-09 10:51:16 +08:00
1 parent ab573838f3
commit 5dda9ac31d
3 files changed
+151 -9

No files matched your search

@@ -70,6 +70,14 @@ fn an_out_of_range_file_value_shows_the_engine_value_and_names_the_raw_one() {
"文件值与生效值不一致时必须写明原值:{}",
concurrency.description
);
// r1 视觉复审 P2-2:那句结论必须**独占一行**(接在说明末尾时,最后一个「效」会被挤成孤字)。
assert!(
concurrency
.description
.ends_with("\n原值 9999 已按出厂 8 生效"),
"结论必须自成一行(`\\n` 分隔),否则 424 列的说明会把它折出单字孤行:{:?}",
concurrency.description
);
assert_eq!(
tuning_of(&env).max_concurrency,
8,
@@ -102,11 +110,106 @@ fn a_file_value_that_matches_the_engine_value_gets_no_note() {
"没有差异就不该有那句话:{}",
row.description
);
// 没有结论行 ⇒ 说明里也不该有换行(那会让页面多出一行空白)。
assert!(
!row.description.contains('\n'),
"没有差异就不该有第二段:{:?}",
row.description
);
}
std::fs::remove_dir_all(&dir).ok();
}
/// **每一种坏值形态都要说清原值**(r1 代码复审 p2:非整数坏值曾被静默丢掉)。
///
/// 任务书 P3-5 是无条件的「文件里的值与生效值不一致时,行上要写明原值 X 已按出厂 N 生效」,
/// 而「手改坏值」不止越界整数这一种。四种形态各验一遍:
///
/// | 文件里写的 | 生效值 | 行上必须出现 |
/// |---|---|---|
/// | `9999`(越界整数) | 8 | `原值 9999 已按出厂 8 生效`(上面那条用例) |
/// | `-4`(负整数) | 8 | `原值 -4 已按出厂 8 生效` |
/// | `"auto"`(类型不对) | 8 | `原值 auto 已按出厂 8 生效` ← **本用例补的洞** |
/// | `8.5` / `true`(类型不对) | 3 | `原值 8.5 / true 已按出厂 3 生效` |
/// | `0`(retry 特例) | 1 | `原值 0 已按 1 生效`(上面那条用例) |
///
/// 抓得住:① 原值退回 `Value::as_i64`(非整数 → `None` → `let raw = raw?` 短路 ⇒ 一个字都不说);
/// ② 字符串原值被 serde 加上引号(上屏成 `"auto"`);③ `null` 被当成「写过」(会冒出
/// `原值 null …`)。
/// 抓不住:别的键(region / mirror / proxy_mode)同族缺口——那三条不在 P3-5 点名范围,
/// 已由 tower 登记为另一个 follow-up。
#[test]
fn every_bad_value_shape_says_what_the_raw_value_was() {
// 负整数
let (dir, env) = env_with(
"bad-negative",
serde_json::json!({ "download": { "concurrency": -4 } }),
);
let group_view = group(&env);
let concurrency = row(&group_view, unlucky_core::download::config::KEY_CONCURRENCY);
assert_eq!(chosen(concurrency), "8", "-4 越界 ⇒ 生效值是出厂 8");
assert!(
concurrency.description.contains("原值 -4 已按出厂 8 生效"),
"负整数也要说清原值:{}",
concurrency.description
);
std::fs::remove_dir_all(&dir).ok();
// 类型不对:字符串 + 浮点(一次覆盖两个)
let (dir, env) = env_with(
"bad-types",
serde_json::json!({ "download": { "concurrency": "auto", "retry_limit": 8.5 } }),
);
let group_view = group(&env);
let concurrency = row(&group_view, unlucky_core::download::config::KEY_CONCURRENCY);
let retry = row(&group_view, unlucky_core::download::config::KEY_RETRY_LIMIT);
assert_eq!(
chosen(concurrency),
"8",
"\"auto\" 不是整数 ⇒ 生效值是出厂 8"
);
assert!(
concurrency
.description
.contains("原值 auto 已按出厂 8 生效"),
"字符串坏值必须原样上屏(不带引号)并说清它被忽略了:{}",
concurrency.description
);
assert!(
!concurrency.description.contains("\"auto\""),
"上屏的是用户写的那个词,不是 serde 的转义形式:{:?}",
concurrency.description
);
assert_eq!(chosen(retry), "3", "8.5 不是整数 ⇒ 生效值是出厂 3");
assert!(
retry.description.contains("原值 8.5 已按出厂 3 生效"),
"浮点坏值也要说清:{}",
retry.description
);
std::fs::remove_dir_all(&dir).ok();
// 布尔 / null:`true` 要说;`null` 等于没写(不该冒出「原值 null …」)
let (dir, env) = env_with(
"bad-bool-null",
serde_json::json!({ "download": { "retry_limit": true, "concurrency": null } }),
);
let group_view = group(&env);
let retry = row(&group_view, unlucky_core::download::config::KEY_RETRY_LIMIT);
let concurrency = row(&group_view, unlucky_core::download::config::KEY_CONCURRENCY);
assert!(
retry.description.contains("原值 true 已按出厂 3 生效"),
"布尔坏值也要说清:{}",
retry.description
);
assert!(
!concurrency.description.contains("原值"),
"`null` 等于没写,不该有提示:{}",
concurrency.description
);
std::fs::remove_dir_all(&dir).ok();
}
/// `retry_limit = 0`(旧版档位)落成「只试一次」:行上画 1,并说清原值是 0。
///
/// 抓得住:把 `0` 原样画上屏(那时引擎按 1 跑,界面说 0 —— 又一个「设置项说假话」);