fix(download): M294 r1 —— JDK 下载页与 CLI 也接上源选择,文档同步

复审 p1:发布版 GUI 的「下载 JDK」页是第二处 DownloadEngine::new(要 with_progress
拿走引擎),此前只读了 gh_proxy,region / mirror_preference 到不了那里;报告却把 GUI
写成「已接」。复审 p2:CLI 四条命令同样不认这两个键 —— 同一份 launcher.json 在 GUI 与
CLI 上表现不同,等于把「设置项说假话」挪到 CLI 侧。

- app-iced downloads/engine.rs:新增 SourceSelection(只读键、不翻译)+
  engine_with(.., &SourceSelection),在 gh-proxy 三态之前叠
  DownloadTuning::with_source_selection(..).apply_source_selection(..)
- Request 加 source_selection 字段,构造点(app/update/settings/java/downloads.rs)
  用 SourceSelection::of_config(&config) 显式传值(不从缓存根反推配置路径:
  反推失败会静默按 auto 收场,正是本 mission 要消灭的形状)
- cli download.rs 的 tuning():链 .with_source_selection(..),四条命令共用这一处装配
- core 的 summary():把「地区 / 镜像偏好」两档印进 CLI 那行生效值(CLI 既然读了,
  少印两项就是新的半真话)
- shared.rs 注释说清「共享引擎」与本文件的第二处装配点;app-iced 模块头补对照表
- 新判据:JDK 下载页与 CLI 各一条断候选源顺序的用例,均配变异验证(换回裸
  EngineConfig::default() / 裸 tuning 即红);补一条 region=cn + gh_proxy=off 的
  叠加次序守卫(复审 P3-2)
- docs/download-settings.md:§1 表格两行、§5 拆「已接 / 未接」、新增 §3.1.1 覆盖面
  表、§6 补 M14-M16 三条变异、§7 补「镜像可达性没验」

连带(不加就编不过,已报备 tower):downloads/tests.rs 的 Request 字面量 +1 行、
downloads/tests/gh_proxy.rs 两处 engine_with 调用点补第四参。
This commit is contained in:
worker-mirrorwire committed 2026-11-13 09:00:00 +08:00
1 parent 0f64acbd05
commit 69e3e198bf
11 files changed
+395 -36

No files matched your search

+46
View File
@@ -343,3 +343,49 @@ fn the_timeout_settings_reach_the_engine_and_the_console_line() {
assert_eq!(super::tuning(&ctx), DownloadTuning::default());
assert!(super::announce(&super::tuning(&ctx)).is_none());
}
/// 一个 URL 在 CLI 装配出来的引擎里的**源名顺序**(`plan()` 是引擎真正的选源决策点)。
fn plan_sources(engine: &DownloadEngine) -> Vec<String> {
let url = "https://libraries.minecraft.net/com/google/guava/guava/32.0.0/guava-32.0.0.jar";
let dest = std::env::temp_dir().join("ull-cli-plan-guava.jar");
let request = DownloadRequest::new(ResourceKind::Library, url.to_string(), dest);
engine
.plan(&request, 0)
.into_iter()
.map(|c| c.source)
.collect()
}
/// **M294 r1(P2-1)**:两键进 CLI 四条命令的生产装配点,终端那行说明也含它们。
///
/// 判据是**候选顺序**:两段都让设置与探测结论相反,没接上时必红(变异:`download-settings.md` M15)。
#[test]
fn the_source_selection_settings_reach_the_cli_engine() {
use unlucky_core::download::region::{store_cached, RegionProfile};
let dir = TempDir::new("source-selection");
let ctx = ctx_at(&dir);
let cache = ctx.layout().cache();
std::fs::create_dir_all(&cache).expect("建缓存根");
let now = unlucky_core::download::cache::now_ms();
let region_json = cache.join("region.json");
// 探测=镜像优先 + 设置 official ⇒ 官方第一条(未接线时是 bmclapi)。
store_cached(&region_json, &RegionProfile::mirror_first(now)).expect("档案");
let mirror = json!({ "download": { "mirror_preference": "official" } });
write_launcher_config(&ctx, mirror);
let engine = crate::commands::install::build_engine(&ctx);
assert_eq!(plan_sources(&engine), ["official", "bmclapi"], "官方第一条");
let line = super::announce(&super::tuning(&ctx)).expect("该有一行");
assert!(line.contains("镜像偏好=official"), "{line}");
assert!(line.contains("地区=auto"), "{line}");
// 探测=直连 + 设置 cn ⇒ 镜像第一条(未接线时是 official)。
store_cached(&region_json, &RegionProfile::direct(now)).expect("档案");
write_launcher_config(&ctx, json!({ "download": { "region": "cn" } }));
let engine = crate::commands::install::build_engine(&ctx);
assert_eq!(plan_sources(&engine), ["bmclapi", "official"], "镜像第一条");
let line = super::announce(&super::tuning(&ctx)).expect("该有一行");
assert!(line.contains("地区=cn"), "{line}");
assert!(line.contains("镜像偏好=auto"), "{line}");
}