test(m262): 三条平台/时序依赖的测试改成确定性判据
① prefs.rs:custom 落点不再写死 D:/JDKs(Linux 上它是相对路径,会被拼到数据根后, 同一条断言在两个平台上验的是两件事)。改由临时目录给绝对路径;另加一条相对路径 必须按数据根解析的断言,把上一版抓不住的那一半补上。 ② fonts/tests.rs:install::status() 读的是进程级静态槽,同 binary 的 page_messages 用例切 zh_cn 会真的发起下载并把它写成 Downloading ⇒ 前后快照比较与谁并行谁赢。 改成用 current_exe() 在**只有本用例的进程**里量,并断言前后逐值相等(任何写槽都算越界)。 ③ fixture_cases.rs:目录 mtime 不再赌「写文件恰好落在另一个 tick」,改为显式钉 mtime (t0/t1 整秒,对任何 filetime 粒度无余数)并逐 ns 比对。 三条都补了「抓得住什么 / 抓不住什么」。
This commit is contained in:
1 parent
98eb4c14c1
commit
d4959fd3d3
3 files changed
+259
-13
No files matched your search
@@ -179,12 +179,59 @@ fn type_roles_pick_the_display_stack_for_big_text() {
|
||||
/// 用 `resolve_with_faces` 而不是 `resolve_with`:`system_faces()` 不可注入,拿不到「一台没有
|
||||
/// 中文字体的机器」。这里给一张只有拉丁族的脸表 ⇒ 中文环境判出 `NeedsDownload`。
|
||||
///
|
||||
/// 抓得住:把 `install::after_probe(cjk_report.strategy)` 加回求值路径(那正是 r2 判为 bug 的写法)
|
||||
/// ——状态槽会从 `NotNeeded`/`Unknown` 变成 `Downloading`,下面那条断言当场红。
|
||||
/// 复审 r3 实测:加回去整套 `unlucky-app-iced --lib` **687 passed / 0 failed**(当时没有这条)。
|
||||
/// 抓不住:`App` 构造之后 `log_cjk` 那一拍会不会触发(那是 `cjk_for` 的职责,且它本来就该触发)。
|
||||
/// ## 为什么这条现在要在**自己的进程**里量(M262,ubuntu CI 真红)
|
||||
///
|
||||
/// `install::status()` 读的是**进程级**的静态槽:`install.rs:146` 的
|
||||
/// `static STATE: OnceLock<Mutex<CjkInstall>>`。而同一个 test binary(`unlucky-app-iced --lib`)
|
||||
/// 里还有别的用例会**写**它,路径如下:
|
||||
///
|
||||
/// ```text
|
||||
/// app/update/page_messages.rs:206 the_language_message_switches_the_catalog_and_rebuilds_the_view
|
||||
/// → App::update(Message::Language(Fixed(ZhCn)))
|
||||
/// → app/update/page_messages.rs:146 set_language → ui/lang.rs:135 log_cjk
|
||||
/// → fonts.rs:266 cjk_for(Some("zh_cn")) → install.rs:311 after_probe
|
||||
/// → install.rs:317-318 Step::Start → install/worker.rs:74 update(Downloading{bytes})
|
||||
/// ```
|
||||
///
|
||||
/// 触发条件:那个用例用 `Options::default()`(`screenshot: None` ⇒ `construct.rs:106`
|
||||
/// `set_offline(false)`)构造 App,而机器上**没有**中文字体时 `zh_cn` 判出 `NeedsDownload`。
|
||||
/// ubuntu runner 正是这一档(Windows 开发机装了中文字体,策略停在 `System`,所以本地看不出来)。
|
||||
/// 之后那条后台线程会真去拉 16.9 MiB(`install/worker.rs:88`),槽在下载期间一直是
|
||||
/// `Downloading`。它和本用例**并行**跑(默认多线程 harness),于是本用例读到的 `after`
|
||||
/// 完全可能是**别人**在飞的那条下载。
|
||||
///
|
||||
/// 上一版直接比 `install::status()` 的前后快照 = 拿一把全进程共享的尺子量,谁并行谁赢。
|
||||
/// 修法不是放宽断言,而是**把尺子放进只有本用例的进程**:`current_exe()` + `--exact`
|
||||
/// 重新起一次本 test binary、只跑这一条(`ULL_FONT_PURITY_CHILD=1` 防递归)。子进程里槽的初值
|
||||
/// 就是 `Unknown`,没有谁跟它抢,判据因此是确定性的。
|
||||
///
|
||||
/// 抓得住:
|
||||
/// - 把 `install::after_probe(cjk_report.strategy)` 加回求值路径(r2 判为 bug 的写法)——
|
||||
/// 子进程里槽从 `Unknown` 变成 `Downloading { bytes: 17772300 }`,`!after.is_downloading()`
|
||||
/// 当场红(实测,见报告「变异证明」);
|
||||
/// - 更宽的回归:求值路径**任何**写槽的动作(连 `Unknown → NotNeeded` 这种「无害改写」也算),
|
||||
/// 由「前后必须逐值相等」那条守;
|
||||
/// - 判据本身失效(这张脸表不再判出 `NeedsDownload`)—— 单独一条断言,免得上面两条变成假绿。
|
||||
///
|
||||
/// 抓不住:
|
||||
/// - 别的用例会不会写槽(本用例主动换进程,**不再**替全进程背书);
|
||||
/// - `App` 构造之后 `log_cjk` 那一拍会不会触发(那是 `cjk_for` 的职责,且它本来就该触发);
|
||||
/// - 起进程本身失败(`current_exe` 拿不到、禁 fork 的环境)——那时是**红**,不是软过;
|
||||
/// - 子进程里跑了「几条」这件事只由 stdout 的 `1 passed` 兜着(改名会让它红,而不是变 0 条假绿)。
|
||||
#[test]
|
||||
fn resolving_fonts_never_starts_a_download() {
|
||||
if std::env::var_os(CHILD_ENV).is_some() {
|
||||
evaluation_starts_no_download();
|
||||
return;
|
||||
}
|
||||
rerun_in_own_process();
|
||||
}
|
||||
|
||||
/// 子进程标记(防递归:父进程起子进程,子进程直接跑判据)。
|
||||
const CHILD_ENV: &str = "ULL_FONT_PURITY_CHILD";
|
||||
|
||||
/// 判据本体(只在**没有别的用例抢全局槽**的进程里跑)。
|
||||
fn evaluation_starts_no_download() {
|
||||
use unlucky_i18n::font::Strategy;
|
||||
|
||||
use crate::fonts::install;
|
||||
@@ -202,13 +249,48 @@ fn resolving_fonts_never_starts_a_download() {
|
||||
let resolved = resolve_with_faces(Some("zh_cn"), Some(&latin));
|
||||
let after = install::status();
|
||||
|
||||
assert_eq!(
|
||||
before,
|
||||
install::CjkInstall::Unknown,
|
||||
"隔离失效:这个进程里槽的初值已被谁改过({before:?}),下面的前后比较就没有意义"
|
||||
);
|
||||
assert_eq!(
|
||||
resolved.cjk.strategy,
|
||||
Strategy::NeedsDownload(&unlucky_i18n::font::NOTO_SANS_SC),
|
||||
"这张脸表必须判出「需要下载」,否则下面的断言证明不了什么"
|
||||
"这张脸表必须判出「需要下载」,否则后面的断言证明不了什么"
|
||||
);
|
||||
assert!(
|
||||
!after.is_downloading(),
|
||||
"求值字体**不许**发起下载(状态从 {before:?} 变成了 {after:?})"
|
||||
);
|
||||
assert_eq!(
|
||||
after, before,
|
||||
"求值字体一次都不许写状态槽(比「不再是下载中」更强:任何改写都算越界)"
|
||||
);
|
||||
}
|
||||
|
||||
/// 用 `current_exe()` 把本 test binary 再起一次,只跑 [`resolving_fonts_never_starts_a_download`]。
|
||||
fn rerun_in_own_process() {
|
||||
let exe = std::env::current_exe().expect("取本 test binary 的路径");
|
||||
let name = "fonts::tests::resolving_fonts_never_starts_a_download";
|
||||
let output = std::process::Command::new(&exe)
|
||||
.args(["--exact", "--nocapture", "--test-threads=1", name])
|
||||
.env(CHILD_ENV, "1")
|
||||
// 截图通道的钉子会直接替换 `status()` 的返回值(`install.rs:157` 先看它),
|
||||
// 留着就等于把尺子换成别人的常数。
|
||||
.env_remove(crate::fonts::install::CAPTURE_ENV)
|
||||
.output()
|
||||
.unwrap_or_else(|error| panic!("起不了隔离子进程 {}:{error}", exe.display()));
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"隔离子进程里的判据红了(退出码 {:?})\n--- stdout ---\n{stdout}\n--- stderr ---\n{}",
|
||||
output.status.code(),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
assert!(
|
||||
stdout.contains("1 passed"),
|
||||
"子进程里必须**真**跑了一条用例(`--exact` 名字对不上会 0 passed 退出 0,那是假绿):\n{stdout}"
|
||||
);
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
//! | 顺序层级 | [`an_empty_priority_follows_the_region`] | 让 `order_layer` 恒为 `Region` |
|
||||
//! | 超长路径不写盘 | [`an_overlong_install_root_is_refused_before_writing`] | 删掉 `Prefs::validate` 的长度判据 |
|
||||
|
||||
use std::path::Path;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use unlucky_core::setting::keys::launcher_schema;
|
||||
use unlucky_core::setting::store::SettingStore;
|
||||
@@ -65,7 +65,30 @@ fn the_three_keys_are_written_and_read_back() {
|
||||
|
||||
/// `java.installRoot` 留空 ⇒ 生效落点来自 `core.data_mode`;填了 ⇒ 来自设置键。
|
||||
///
|
||||
/// 变异证明:把 `prefs_store::effective` 里 `override_root` 那段删掉(当作永远没设)⇒ 后半段红。
|
||||
/// ## 为什么不再写死 `D:/JDKs`(M262)
|
||||
///
|
||||
/// `D:/JDKs` 在 Windows 上是**绝对路径**、在 Linux 上是**相对路径**(`D:` 只是个普通目录名),
|
||||
/// 而 `JavaInstallRoot::resolve`(`crates/core/src/game/java/location.rs:128`)对两者的处理是
|
||||
/// 两件事:绝对路径原样用,相对路径拼到数据根后面。于是同一条 `assert_eq!(root, "D:/JDKs")`
|
||||
/// 在两个平台上验的是**两个不同的语义**:Windows 上验「设了就不拼数据根」(对),Linux 上验
|
||||
/// 「绝对路径被当成相对路径拼了」——ubuntu CI 因此必红。落点现在由临时目录给出,两个平台上都是
|
||||
/// 绝对路径,断言回到它本来的意思。
|
||||
///
|
||||
/// 抓得住:
|
||||
/// - `effective` 忽略 `java.installRoot`(整段红:落点会变成数据根下的 `java-managed`,
|
||||
/// `root_layer` 也退回 `DataMode`。实测:把 `override_root` 恒置空 ⇒ 红在 `root_layer`);
|
||||
/// - 「设了却仍按数据根下的 `java-managed` 来」(实测:让 `JavaInstallRoot::resolve` 的 custom 分支
|
||||
/// 返回 `launcher.java_managed()` ⇒ 红在 `root` 那句,错误的落点被打出来);
|
||||
/// - 相对路径的落点规则(第二段:相对路径**必须**拼数据根)。
|
||||
///
|
||||
/// 抓不住:
|
||||
/// - **「绝对路径被当成相对路径拼」**:`Path::join` 对一个绝对路径返回的就是它自己,于是
|
||||
/// `is_absolute()` 那一支在两个平台上都**观测不到**——实测把那一支删成恒 `home().join(root)`,
|
||||
/// 本用例仍然全绿。上一版写死 `D:/JDKs` 之所以在 Windows 上绿而在 Linux 上红,靠的不是
|
||||
/// 「拼不拼」这条分支,而是 `D:/JDKs` 在两个平台上**根本不是一类路径**。要让这一支有守卫,
|
||||
/// 得换成一个「绝对路径 join 之后会变」的平台(没有),或者直接断言 `is_absolute` 的判据本身;
|
||||
/// - 路径归一化(`D:/JDKs` → `D:\JDKs` 这类)与分隔符风格;
|
||||
/// - Standard 数据模式下拿不到系统标准目录的那一臂(`root_unresolved`,本用例钉的是 portable)。
|
||||
#[test]
|
||||
fn an_empty_install_root_follows_the_data_mode() {
|
||||
let dir = root("prefs-root");
|
||||
@@ -87,15 +110,66 @@ fn an_empty_install_root_follows_the_data_mode() {
|
||||
effective.root
|
||||
);
|
||||
|
||||
let custom_root = custom_install_root();
|
||||
assert!(
|
||||
!custom_root.starts_with(&dir),
|
||||
"custom 落点必须不在数据根里(否则「拼了数据根」这条也能过):{} vs {}",
|
||||
custom_root.display(),
|
||||
dir.display()
|
||||
);
|
||||
|
||||
let custom = Prefs {
|
||||
install_root: "D:/JDKs".to_string(),
|
||||
saved_install_root: "D:/JDKs".to_string(),
|
||||
install_root: custom_root.display().to_string(),
|
||||
saved_install_root: custom_root.display().to_string(),
|
||||
..Prefs::default()
|
||||
};
|
||||
let effective = prefs_store::effective(&file, &custom);
|
||||
assert_eq!(effective.root_layer, RootLayer::Setting);
|
||||
assert_eq!(effective.root_mode, "custom");
|
||||
assert_eq!(effective.root, "D:/JDKs", "设了就按它来,不再拼数据根");
|
||||
assert_eq!(
|
||||
effective.root,
|
||||
custom_root.display().to_string(),
|
||||
"设了就按它来,不再拼数据根"
|
||||
);
|
||||
assert!(
|
||||
!effective.root_unresolved,
|
||||
"custom 落点不该是「解析失败」:{effective:?}"
|
||||
);
|
||||
|
||||
// 相对路径那一档(上一版写死的 `D:/JDKs` 在 Linux 上就落进这里):按数据根解析,
|
||||
// 但来源层仍是设置键。两个平台上语义相同——这正是上一版抓不住的那一半。
|
||||
let relative = Prefs {
|
||||
install_root: "jdks-relative".to_string(),
|
||||
saved_install_root: "jdks-relative".to_string(),
|
||||
..Prefs::default()
|
||||
};
|
||||
let effective = prefs_store::effective(&file, &relative);
|
||||
assert_eq!(effective.root_layer, RootLayer::Setting);
|
||||
assert_eq!(effective.root_mode, "custom");
|
||||
assert_eq!(
|
||||
effective.root,
|
||||
dir.join("jdks-relative").display().to_string(),
|
||||
"相对路径按数据根解析(绝对路径才原样用)"
|
||||
);
|
||||
|
||||
let _ = std::fs::remove_dir_all(&custom_root);
|
||||
}
|
||||
|
||||
/// 一个**平台无关的绝对路径**(且不在数据根里):custom 落点的替身。
|
||||
///
|
||||
/// 不能写死 `D:/JDKs` / `/opt/jdks`:前者在 Linux 上是相对路径,后者在 Windows 上是相对路径
|
||||
/// (见 [`an_empty_install_root_follows_the_data_mode`] 的文档)。临时目录两边都是绝对路径。
|
||||
fn custom_install_root() -> PathBuf {
|
||||
let dir = std::env::temp_dir().join(format!(
|
||||
"ull-java-custom-{}-{}",
|
||||
std::process::id(),
|
||||
std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.map_or(0, |d| d.as_nanos())
|
||||
));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).expect("建 custom 落点");
|
||||
dir
|
||||
}
|
||||
|
||||
/// `java.vendorPriority` 留空 ⇒ 地区默认序;排过 ⇒ 顺序与来源层都变。
|
||||
|
||||
Reference in new issue
Block a user