fix(core,cli): M231 复审三条 P2 —— 恢复误删用例 / 收窄 --dry-run 文案 / 判定链去重
P2-1:`natives_cases.rs` 里 `missing_native_jar_becomes_missing_component` 是上一轮 批量截断时**误伤**掉的(我把「tree_snapshot 之后的所有内容」整段砍掉,连带这条与 dry-run 无关的用例),不是有意删。现已从 main 原样贴回,`MissingNativeJar` / natives 组件缺失这条用户可见失败路径恢复覆盖。 P2-2:help 的「也不写盘」是过度承诺 —— `commands/launch.rs` 的 `launcher_log::set_dir` /`record_start`/`record` 都在 `if args.dry_run` 之前,dry-run 仍会 append `<数据根>/logs/launcher.log`(连父目录 create_dir_all)。文案收窄成「不碰版本树 (不解压 natives、不建 natives 目录);启动器自身的运行日志照记」。core 的 `DryRun` 文档同步加了「本层承诺 / 调用方日志另算」的边界。 P2-3:`extract` 与 `preview` 的「无 jar / 戳记命中 / 重解」判定链合成 `inspect()` 一份, 返回 `DirStatus`(NoJars / Ready(files) / Stale)+ 源 jar 指纹;两个入口只在这里分叉。 另:`tree_snapshot_notices_a_transient_directory` 在全量并行跑时偶发红(本轮门禁抓到 1 次, 单跑 3 次全绿)——「建了立刻删」对父目录 mtime 的影响会被 NTFS 合并。换成确定性自检 `tree_snapshot_sees_new_nodes_and_mtime_changes`(新节点 + 同内容重写的 mtime 变化), 并把这条能力边界写进 `tree_snapshot` 的「抓不住」。
This commit is contained in:
1 parent
1fa30c4885
commit
c917bfa18f
5 files changed
+134
-50
No files matched your search
@@ -176,3 +176,46 @@ fn natives_extracted_event_carries_report_fields() {
|
||||
.expect("dir 是字符串")
|
||||
.ends_with("natives"));
|
||||
}
|
||||
|
||||
/// 缺 natives jar:适配层当成组件缺失(组装前显式失败),而不是等到 UnsatisfiedLinkError。
|
||||
#[test]
|
||||
fn missing_native_jar_becomes_missing_component() {
|
||||
let (mut request, ctx) = legacy_forge_request();
|
||||
request.natives = NativesPlan::new(vec![NativeJar::new(
|
||||
"C:/mc/libraries/missing-natives-windows.jar",
|
||||
"org.lwjgl:lwjgl:3.2.2:natives-windows",
|
||||
)]);
|
||||
// 直接验证适配层:给一个不存在的 natives jar,严格模式应产出 MissingNativeJar 告警。
|
||||
let libraries: Vec<LibraryInput> = request
|
||||
.classpath
|
||||
.iter()
|
||||
.map(|path| LibraryInput::new(path.clone(), "x"))
|
||||
.collect();
|
||||
let natives = request.natives.jars.clone();
|
||||
let snapshot = SnapshotInput {
|
||||
version_id: "1.16.5",
|
||||
main_class: Some("net.minecraft.client.main.Main"),
|
||||
libraries: &libraries,
|
||||
natives: &natives,
|
||||
..SnapshotInput::minimal("1.16.5", "net.minecraft.client.main.Main")
|
||||
};
|
||||
let options = AdapterOptions {
|
||||
java: JavaSelection::new("C:/java/bin/java.exe", 17, 64),
|
||||
..AdapterOptions::strict()
|
||||
};
|
||||
let output = build_request(&snapshot, options);
|
||||
assert!(
|
||||
output
|
||||
.warnings
|
||||
.iter()
|
||||
.any(|warning| matches!(warning, AdapterWarning::MissingNativeJar { .. })),
|
||||
"应有 MissingNativeJar 告警:{:?}",
|
||||
output.warnings
|
||||
);
|
||||
assert_eq!(output.request.natives.era, NativesEra::Legacy);
|
||||
// 组装按既有语义直接失败(missing_components 非空)。
|
||||
assert!(matches!(
|
||||
assemble(&output.request, &ctx).err(),
|
||||
Some(LaunchError::Assembly(AssemblyError::MissingComponents(_)))
|
||||
));
|
||||
}
|
||||
@@ -12,16 +12,16 @@ use crate::prelude::*;
|
||||
|
||||
/// 版本树的「节点类型 + mtime(纳秒)+ 相对路径」快照,用来逐字比较 dry-run 前后。
|
||||
///
|
||||
/// 抓得住:新增/删除任何节点(含 `natives/` 目录本身 —— 根节点的 mtime 就是父目录 mtime)、
|
||||
/// 任何已有节点被重写或 mtime 被更新。目录节点的 mtime 会因「建子目录」而变,所以
|
||||
/// 「建了又删」这种瞬时写入也会被记到根节点上(只要快照跨过了那次操作)。
|
||||
/// 抓不住:内容变了但 mtime 被回填成原值(本仓没有这种写法);时间戳分辨率粗于操作间隔的
|
||||
/// 文件系统(FAT/exFAT 的 2s 粒度)上「建了又删」可能落进同一格 —— 那种情况只剩
|
||||
/// 「`natives` 目录不存在」这条判据兜底,瞬时的建-删会漏。
|
||||
/// 抓得住:新增/删除任何节点(含 `natives/` 目录本身)、任何已有节点被重写或 mtime 被
|
||||
/// 更新;根节点(= 父目录 `versions/<id>/`)也在快照里,所以「建目录」会同时体现在
|
||||
/// 节点集合与父目录 mtime 上。
|
||||
/// 抓不住:①内容变了但 mtime 被回填成原值(本仓没有这种写法);②**建了立刻删**这类
|
||||
/// 瞬时写入只留父目录 mtime 一条线索,而 NTFS 会把该更新合并掉 —— 本仓实测:全量并行跑
|
||||
/// 测试时这条偶发看不见(单跑又看得见),所以瞬时建删只剩「`natives` 目录不存在」兜底。
|
||||
///
|
||||
/// 时间戳口径:NTFS / ext4 的 mtime 精度是 100ns 级,快照取纳秒整数比较,所以同一秒内的
|
||||
/// 多次操作(建目录 → 删目录)照样分辨得出来,不需要 `sleep` 把两次操作推到不同秒。
|
||||
/// 下面 `tree_snapshot_notices_a_transient_directory` 就是这条判据的自检(防假绿)。
|
||||
/// 时间戳口径:NTFS / ext4 的 mtime 精度是 100ns 级,快照取纳秒整数比较,同一秒内的
|
||||
/// 两次操作(写文件 → 再写一次)分辨得出来,不需要 `sleep` 把操作推到不同秒。
|
||||
/// 判据自检见 `tree_snapshot_sees_new_nodes_and_mtime_changes`(防假绿)。
|
||||
fn tree_snapshot(root: &Path) -> Vec<String> {
|
||||
fn line(meta: &std::fs::Metadata, relative: &str) -> String {
|
||||
let nanos = meta
|
||||
@@ -206,30 +206,40 @@ fn dry_run_after_real_extract_reports_ready_without_writing() {
|
||||
assert_eq!(report.skipped, 1, "{report:?}");
|
||||
}
|
||||
|
||||
/// 判据自检(防假绿):快照必须看得见「建一个子目录又立刻删掉」留下的父目录 mtime 变化,
|
||||
/// 判据自检(防假绿):快照必须看得见「新增节点」与「已有节点的 mtime 变化」,
|
||||
/// 否则上面几条「快照逐字相等」等于没断言。
|
||||
///
|
||||
/// 这里**不**用「建了立刻删」来探父目录 mtime:NTFS 会把瞬时建删对父目录 mtime 的影响
|
||||
/// 合并掉(本仓实测:全量并行跑时偶发看不见、单跑看得见),拿它当门禁就是引入 flaky。
|
||||
/// 改成两种确定性变化:新节点(结构维度)+ 同内容重写(时间维度,只有文件 mtime 变,
|
||||
/// 不依赖父目录时间戳的合并行为)。
|
||||
#[test]
|
||||
fn tree_snapshot_notices_a_transient_directory() {
|
||||
fn tree_snapshot_sees_new_nodes_and_mtime_changes() {
|
||||
let root = temp_dir("natives-snapshot-probe");
|
||||
let version_dir = root.join("versions/1.16.5");
|
||||
std::fs::create_dir_all(&version_dir).expect("建版本目录");
|
||||
std::fs::write(version_dir.join("1.16.5.json"), b"{}").expect("放清单占位");
|
||||
let before = tree_snapshot(&version_dir);
|
||||
let baseline = tree_snapshot(&version_dir);
|
||||
|
||||
// 模拟 `create_dir_all(natives)` 之后目录又被删掉:节点集合复原,只有父目录 mtime 变了。
|
||||
let transient = version_dir.join("natives");
|
||||
std::fs::create_dir(&transient).expect("建目录");
|
||||
std::fs::remove_dir(&transient).expect("删目录");
|
||||
assert!(!transient.exists(), "目录应已删掉");
|
||||
// 1) 结构维度:多一个目录节点(正是 `create_dir_all(natives)` 留下的痕迹)。
|
||||
std::fs::create_dir(version_dir.join("natives")).expect("建目录");
|
||||
let with_dir = tree_snapshot(&version_dir);
|
||||
assert!(
|
||||
with_dir.len() > baseline.len(),
|
||||
"快照必须看得见新目录:{baseline:?} vs {with_dir:?}"
|
||||
);
|
||||
assert_ne!(baseline, with_dir);
|
||||
|
||||
let after = tree_snapshot(&version_dir);
|
||||
// 2) 时间维度:同一份内容重写一遍,节点集合不变、文件 mtime 必须变。
|
||||
std::fs::write(version_dir.join("1.16.5.json"), b"{}").expect("重写清单占位");
|
||||
let rewritten = tree_snapshot(&version_dir);
|
||||
assert_eq!(
|
||||
before.len(),
|
||||
after.len(),
|
||||
"节点集合应恢复原样,差异只该在 mtime 上:{before:?} vs {after:?}"
|
||||
with_dir.len(),
|
||||
rewritten.len(),
|
||||
"节点集合没变,差异只该在 mtime 上"
|
||||
);
|
||||
assert_ne!(
|
||||
before, after,
|
||||
"快照必须看得见瞬时建删留下的父目录 mtime 变化,否则零落盘断言是假绿"
|
||||
with_dir, rewritten,
|
||||
"快照必须看得见已有文件的 mtime 变化,否则零落盘断言是假绿"
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user