fix(m197): 复审 r1 的 P1 + 三条 P2(描述对齐行为 / 内部编号下屏 / kind 守卫 / gh-proxy 可覆盖)
P1(阻断)`java.auto_install` 的描述与行为不一致——那句会进 AI 工具的 JSON Schema `description`,等于让助手对用户说一件实现刻意不做的事: - `crates/core/src/setting/keys.rs`:改成「缺 Java 时在 Java 页标出推荐版本并可一键安装; 不会自动下载」,去掉 `(D13 基准 JDK17)`。 - `SettingsJavaAutoInstallHint` 中英两侧各补一句显式否定(「不会自己开始下载 —— 点「安装」 才会下」/ "Nothing is downloaded on its own — you press Install."),标签从「自动准备」改成 「缺 JDK 时推荐一档」;金表同步。 - 新增守卫 `the_auto_install_description_says_it_never_downloads_by_itself`(描述必须含 「不会自动下载」、不含旧说法与内部编号)。 P2-1 内部决策编号印在界面上:`SettingsJavaDownloadBaseline` 的 `Baseline (D13)` / `基准版本(D13)` → `Recommended baseline` / `推荐基准版本`(金表同步)。另加两条目录级守卫 (`no_user_visible_string_mentions_an_internal_decision_id` / `no_user_visible_string_carries_markdown_backticks`);后者顺带清掉 M168 遗留的 `FontCjkStatusHint` 里的 `ui.font_cdn` 反引号——全仓最后一条。 P2-2 `ProgressEvent::SourceFailed.kind` 没有守卫:`engine_mock_test` - `reports_progress_events_and_errors_when_all_sources_fail` 的解构补 `kind`,断言 `ServerError`; - 新增 `a_404_is_classified_as_not_found_and_never_cools_the_source_down`(404 → `NotFound`, 与「源坏了」分开)。 P2-3 交付任务书那句「(默认值可改)」:新增 `download.gh_proxy`(空 = 跟随内置默认 / `off` = 关 / 其它 = 覆盖前缀),`engine_with` 是它的真消费者(改 `RegionProfile`,因为 `gh_proxy_candidates` 读的就是档案里的前缀);Java 页不画 UI(归 M193)。**内置默认值没动**。 schema minor 1.7.0 → 1.8.0(新键必须推 minor),三处硬编码 minor 的用例同步。 另:真下载用例改成 panic 也清理(复审顺带项 7④);`downloads/refusal.rs` 的「四档」改「五档」。
This commit is contained in:
1 parent
9a7b138d08
commit
a14b00aced
15 files changed
+387
-28
No files matched your search
@@ -55,6 +55,8 @@ pub mod update;
|
||||
/// `1.6.0` 登记 M161 的「自更新」两键(见 [`update`]):纯增量但带一步数据迁移
|
||||
/// (此前住在 `cache/update/prefs.json`,迁移见 [`super::update_prefs`])。
|
||||
/// `1.7.0` 登记 M168 的中文字体下载地址覆盖键(`ui.font_cdn`,见 [`font`]):纯增量、无迁移。
|
||||
/// `1.8.0` 登记 M197 的 gh-proxy 前缀覆盖键(`download.gh_proxy`):同样纯增量——出厂值是空串,
|
||||
/// 语义正是「老文件没有这个键」时的行为(跟随内置镜像表的默认前缀)。
|
||||
///
|
||||
/// **旧读新(方向相反,措辞必须精确)**:1.4.0 的客户端读 1.5.0 的文件时,
|
||||
/// [`super::schema::SchemaCompat::check_url`] 走 `found.minor > expected.minor` →
|
||||
@@ -64,7 +66,7 @@ pub mod update;
|
||||
/// 原因:回退到旧版本会出现「设置改不动」,而原因只在 `$schema` 那一行里,不看版本号无从排查。
|
||||
#[must_use]
|
||||
pub fn launcher_version() -> SchemaVersion {
|
||||
SchemaVersion::new(1, 7, 0)
|
||||
SchemaVersion::new(1, 8, 0)
|
||||
}
|
||||
|
||||
/// `config/launcher.json` 的 schema。
|
||||
@@ -144,6 +146,16 @@ pub fn launcher_schema() -> SettingSchema {
|
||||
AiPolicy::sensitive(),
|
||||
"manual 代理地址(如 http://127.0.0.1:7890)",
|
||||
))
|
||||
// M197:gh-proxy 前缀的用户覆盖。语义在 `core::download::region`:
|
||||
// 空串 = 跟随内置默认(镜像表里的 gh-proxy.com,且只有镜像优先/国内判定才启用);
|
||||
// `off` = 明确关掉;其余非空值 = 用这个前缀覆盖。
|
||||
.with(SettingSpec::text(
|
||||
"download.gh_proxy",
|
||||
"",
|
||||
256,
|
||||
AiPolicy::sensitive(),
|
||||
"GitHub 下载的加速前缀(gh-proxy)。留空 = 跟随内置默认(镜像表里的 gh-proxy.com,仅镜像优先/国内判定时启用);填 off 关闭;填一个 URL 前缀则覆盖它",
|
||||
))
|
||||
.with(SettingSpec::path(
|
||||
"java.selected_path",
|
||||
AiPolicy::sensitive(),
|
||||
@@ -153,7 +165,10 @@ pub fn launcher_schema() -> SettingSchema {
|
||||
"java.auto_install",
|
||||
true,
|
||||
AiPolicy::audited(),
|
||||
"缺 Java 时自动下载(D13 基准 JDK17)",
|
||||
// M197:这句会进 AI 工具的 JSON Schema `description`(`catalog.rs` 直接塞 `spec.doc`),
|
||||
// 所以必须写**实现真做的事**:缺 Java 时在 Java 页标出推荐版本并可一键安装,
|
||||
// 不会自己开始下载(是否下载由用户点「安装」决定)。
|
||||
"缺 Java 时在 Java 页标出推荐版本并可一键安装;不会自动下载",
|
||||
))
|
||||
// D23:托管 JDK 的落点三模式。语义在 `game::java::location`:
|
||||
// 未设置(空串)→ 按 `core.data_mode` 派生(Portable 数据根 / Standard 系统目录);
|
||||
|
||||
@@ -338,9 +338,19 @@ async fn reports_progress_events_and_errors_when_all_sources_fail() {
|
||||
started = true;
|
||||
assert!(candidates >= 1);
|
||||
}
|
||||
ProgressEvent::SourceFailed { will_retry, .. } => {
|
||||
ProgressEvent::SourceFailed {
|
||||
will_retry, kind, ..
|
||||
} => {
|
||||
failed_source = true;
|
||||
assert!(!will_retry, "单次尝试用尽后不应再声明重试");
|
||||
// M197:`kind` 是诊断字段,必须来自**真实**的失败分类(HTTP 500 → ServerError)。
|
||||
// 变异证明:把 `engine.rs` 的 `kind: err.kind` 写成常量
|
||||
// `DownloadErrorKind::Network` ⇒ 本断言红。
|
||||
assert_eq!(
|
||||
kind,
|
||||
DownloadErrorKind::ServerError,
|
||||
"HTTP 500 必须被分类成 ServerError(诊断字段不许是常量)"
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -348,3 +358,57 @@ async fn reports_progress_events_and_errors_when_all_sources_fail() {
|
||||
assert!(started && failed_source, "进度事件缺失");
|
||||
server.stop();
|
||||
}
|
||||
|
||||
/// `SourceFailed.kind` 的另一半:**404 不是「源坏了」**,是「该源没有这个文件」。
|
||||
///
|
||||
/// 这两档在引擎里的后果完全不同(`NotFound` 走 `record_missing`,不冷却源;`ServerError` 走
|
||||
/// `record_failure`)。把两者混成一个常量最贵的地方就在这里:院校镜像只留最新补丁,请求旧补丁
|
||||
/// 必然 404,判成「源坏了」会把唯一可用镜像冷却掉(M33/M34 实测)。
|
||||
///
|
||||
/// 变异证明:把 `engine.rs` / `bytes.rs` 两处 `kind: err.kind` 改成 `DownloadErrorKind::NotFound`
|
||||
/// 常量 ⇒ 上面那条 500 用例红;改成 `Network` ⇒ 本条红。
|
||||
#[tokio::test]
|
||||
async fn a_404_is_classified_as_not_found_and_never_cools_the_source_down() {
|
||||
let server = MockServer::start(vec![
|
||||
MockResponse::status(404),
|
||||
MockResponse::status(404),
|
||||
MockResponse::status(404),
|
||||
MockResponse::status(404),
|
||||
])
|
||||
.await;
|
||||
let url = server.url("/gone.jar");
|
||||
let dir = temp_dir("engine-404");
|
||||
let cache = Arc::new(ContentCache::open(dir.join("cache")));
|
||||
let (emitter, mut events) = ProgressEmitter::channel();
|
||||
let engine = DownloadEngine::new(
|
||||
fast_config(1),
|
||||
Arc::new(MirrorTable::builtin()),
|
||||
Arc::new(direct_region()),
|
||||
Arc::new(HealthRegistry::in_memory()),
|
||||
cache,
|
||||
)
|
||||
.with_progress(emitter);
|
||||
|
||||
let error = engine
|
||||
.download(DownloadRequest::new(
|
||||
ResourceKind::Library,
|
||||
url.as_str(),
|
||||
dir.join("gone.jar"),
|
||||
))
|
||||
.await
|
||||
.expect_err("只有 404 的源必须失败");
|
||||
assert_eq!(error.kind, DownloadErrorKind::AllSourcesFailed);
|
||||
|
||||
let mut seen: Vec<DownloadErrorKind> = Vec::new();
|
||||
while let Ok(event) = events.try_recv() {
|
||||
if let ProgressEvent::SourceFailed { kind, .. } = event {
|
||||
seen.push(kind);
|
||||
}
|
||||
}
|
||||
assert!(!seen.is_empty(), "至少要有一条 SourceFailed");
|
||||
assert!(
|
||||
seen.iter().all(|kind| *kind == DownloadErrorKind::NotFound),
|
||||
"404 必须分类成 NotFound,实际:{seen:?}"
|
||||
);
|
||||
server.stop();
|
||||
}
|
||||
@@ -131,8 +131,8 @@ fn appearance_keys_are_all_ai_writable_and_registered() {
|
||||
fn schema_registration_shape_is_right() {
|
||||
assert_eq!(
|
||||
launcher_version().minor,
|
||||
7,
|
||||
"1.7.0 登记 M168 的 ui.font_cdn(1.6.0 是 M161 的自更新两键)"
|
||||
8,
|
||||
"1.8.0 登记 M197 的 download.gh_proxy(1.7.0 是 M168 的 ui.font_cdn)"
|
||||
);
|
||||
let schema = launcher_schema();
|
||||
assert_eq!(
|
||||
|
||||
@@ -128,9 +128,10 @@ fn overrides_key_is_an_enum_whitelist() {
|
||||
|
||||
#[test]
|
||||
fn schema_versions_register_the_new_keys_without_migration() {
|
||||
// 1.7.0 登记 M168 的 `ui.font_cdn`(1.6.0 登记 M161 的自更新两键,1.5.0 = M116 窗口圆角,
|
||||
// 1.4.0 = M91 外观下层三键,1.3.0 = D17「外观(高级)」,1.2.0 = D23 的 JDK 落点/优先级键)。
|
||||
assert_eq!(launcher_version(), SchemaVersion::new(1, 7, 0));
|
||||
// 1.8.0 登记 M197 的 `download.gh_proxy`(1.7.0 = M168 的 `ui.font_cdn`,1.6.0 登记 M161 的
|
||||
// 自更新两键,1.5.0 = M116 窗口圆角,1.4.0 = M91 外观下层三键,1.3.0 = D17「外观(高级)」,
|
||||
// 1.2.0 = D23 的 JDK 落点/优先级键)。
|
||||
assert_eq!(launcher_version(), SchemaVersion::new(1, 8, 0));
|
||||
assert_eq!(instance_version(), SchemaVersion::new(1, 1, 0));
|
||||
assert_eq!(launcher_schema().id(), SchemaId::LAUNCHER);
|
||||
// major 仍是 1:迁移链(按 major 走)不需要新步骤,老文件缺键即默认值。
|
||||
|
||||
@@ -66,10 +66,10 @@ fn install_root_accepts_a_path_and_keeps_empty_as_unset() {
|
||||
|
||||
#[test]
|
||||
fn schema_version_bumps_minor_only_so_no_migration_step_is_needed() {
|
||||
// 1.7.0 = M168 的中文字体下载地址覆盖键(`ui.font_cdn`;此前 1.6.0 是 M161 的自更新两键,
|
||||
// 1.5.0 是 M116 窗口圆角)。每加一批键推一次 minor 是**纪律**,不是巧合:
|
||||
// 老版本读新文件会判 `ReadOnlyPreserveSchema`,所以版本号本身就是「新键存在」的对外声明。
|
||||
assert_eq!(launcher_version(), SchemaVersion::new(1, 7, 0));
|
||||
// 1.8.0 = M197 的 gh-proxy 覆盖键(`download.gh_proxy`;此前 1.7.0 是 M168 的 `ui.font_cdn`,
|
||||
// 1.6.0 是 M161 的自更新两键,1.5.0 是 M116 窗口圆角)。每加一批键推一次 minor 是**纪律**,
|
||||
// 不是巧合:老版本读新文件会判 `ReadOnlyPreserveSchema`,所以版本号本身就是「新键存在」的对外声明。
|
||||
assert_eq!(launcher_version(), SchemaVersion::new(1, 8, 0));
|
||||
assert_eq!(
|
||||
launcher_version().major,
|
||||
1,
|
||||
@@ -120,3 +120,31 @@ fn an_old_config_file_without_the_new_keys_still_loads() {
|
||||
);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// `java.auto_install` 的 schema 描述必须与实现一致:**不会**自动下载。
|
||||
///
|
||||
/// 这句会进 AI 工具的 JSON Schema `description`(`setting/catalog.rs` 把 `spec.doc` 原样塞进去),
|
||||
/// 所以它不是注释而是**对外文案**:写「缺 Java 时自动下载」等于让启动器自己的助手对用户说
|
||||
/// 一件实现刻意不做的事(M197 复审 r1 的 P1)。
|
||||
///
|
||||
/// 变异证明:把描述改回「缺 Java 时自动下载(D13 基准 JDK17)」⇒ 本用例红(三句断言都会红)。
|
||||
#[test]
|
||||
fn the_auto_install_description_says_it_never_downloads_by_itself() {
|
||||
let schema = launcher_schema();
|
||||
let doc = schema
|
||||
.spec("java.auto_install")
|
||||
.expect("java.auto_install 必须登记")
|
||||
.doc;
|
||||
assert!(
|
||||
doc.contains("不会自动下载"),
|
||||
"描述必须写明「不会自动下载」(AI 会照这句话告诉用户):{doc}"
|
||||
);
|
||||
assert!(
|
||||
!doc.contains("缺 Java 时自动下载"),
|
||||
"描述不许再写「缺 Java 时自动下载」:{doc}"
|
||||
);
|
||||
assert!(
|
||||
!doc.contains("D13"),
|
||||
"描述里不许出现内部决策编号(用户与助手都不知道 D13 是什么):{doc}"
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user