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
@@ -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