fix(appearance): M91 r2 —— 真交叉断言 + unsafe 门禁跨行扫描 + α 上取整

P2-1「与 design 码值一致」的守门此前不存在
- 新增 crates/app-iced/src/platform/mod.rs::palette_source_codes_match_design_level_codes:
  三个格子对照 PaletteSource::as_str() 与 unlucky_design::palette::Level::code(),
  并覆盖反方向(from_key_value(level.code()) 必须还原同一档)与「码值在允许值表里」
- core 侧那条测试改名为 value_tables_are_self_consistent,注释改成事实:
  core 不依赖 design,只能钉自己的字面量;一致性由 app-iced 的那条对照断言守
- 实测:把 design 的 Level::Wallpaper 码值改成 "desktop" → 新断言红(design 自己 178 个测试仍全绿)

P2-2 unsafe-scope 门禁:行级正则 → 跨行扫描
- 去注释 + 按方括号闭合把续行并成逻辑行,再逐个属性组判断 allow(...unsafe_code)
- 抓得住原来两种绕过:多行属性 #![allow(\n unsafe_code\n)]、同行两属性 #[inline] #[allow(unsafe_code)]
- 门禁注释补全已知边界(不再声称「依赖 fmt job 兜底」——已不依赖)

O-1 α 量化方向:round → ceil
- 0.08×255=20.4,round 得 20 → 实际下发 20/255=0.0784,低于 D36 名义下限
- ceil 得 21 → 0.0824;新增 applied_alpha_is_never_below_the_floor 断言 下发字节/255 ≥ 0.08

O-7 契约测试补三个新键
- appearance_keys_are_all_ai_writable_and_registered 的 audited 清单加 window_opacity /
  titlebar_mode / palette_source
This commit is contained in:
AskaEth committed 2026-11-02 14:28:36 +08:00
1 parent 7406785325
commit fa2c6560fd
6 files changed
+108 -16

No files matched your search

+32
View File
@@ -111,4 +111,36 @@ mod tests {
assert_eq!(effective_window_alpha(Backend::Cpu, 0.5), Some(0.5));
assert_eq!(effective_window_alpha(Backend::Gpu, 0.5), Some(0.5));
}
/// `appearance.palette_source` 的码值必须与 `design` 的 `Level::code()` 逐字一致。
///
/// 为什么这条断言住在这里:`unlucky-core` 按分层纪律不依赖 `unlucky-design`,
/// 它的测试**看不到** design,所以 core 自己只能钉字面量。本 crate 同时依赖
/// `unlucky-design`(`Level`)与 `unlucky-presenter`(重导出 `PaletteSource`),
/// 是全仓唯一能真做这次对照的地方。
///
/// 抓得住:design 侧改任一档的稳定码(例如把 `wallpaper` 改成 `desktop`)、或有人改了
/// core 的字符串表——两个方向都红(下面往返那条覆盖「只改一侧」)。
/// 抓不住:档位的**语义**是否仍对齐(只保证字符串一致),以及 UI 是否真按这个码值取色。
#[test]
fn palette_source_codes_match_design_level_codes() {
use unlucky_design::palette::Level;
use unlucky_presenter::prefs::PaletteSource;
for (source, level) in [
(PaletteSource::BackgroundImage, Level::BackgroundImage),
(PaletteSource::Wallpaper, Level::Wallpaper),
(PaletteSource::Preset, Level::Preset),
] {
assert_eq!(
source.as_str(),
level.code(),
"core 的 {source:?} 码值与 design 的 {level:?} 不一致"
);
// 反方向:design 的码值喂回 core 必须还原成同一档(防「两个字符串互换了」)。
assert_eq!(PaletteSource::from_key_value(level.code()), source);
// 且必须真的在 core 的允许值表里(否则 schema 会拒绝写这个值)。
assert!(unlucky_presenter::prefs::PALETTE_SOURCES.contains(&level.code()));
}
}
}