feat(official-sync): 配置校验与 server-info/marker 拉取接入错误码

catalog.refresh 真机 e2e 暴露的缺口:任务配置校验失败落 900001,而
输入域码表(100xxx)早已定义却无使用点。本次接入:

- 配置校验四处类型化(经 anyhow::Error::new 保留 DownloadError,
  task worker 现有 downcast 直接归类):
  缺少应用版本 → MISSING_APP_VERSION(100001)、
  缺少连接组 → MISSING_CONNECTION_GROUP(100002)、
  缺少服务器信息来源 → MISSING_SERVER_INFO_SOURCE(100003)、
  GameMainConfig 缺 ServerInfoDataUrl → LAUNCHER_RESPONSE_INVALID
  (600004,launcher 链内容缺陷)。
- fetch_bytes 改返回 DownloadError:非官方 URL → NON_OFFICIAL_URL、
  curl 失败保留准确网络域码。server-info / endpoint marker / 种子
  catalog 拉取(5 处调用)由 anyhow::Error::msg 改 Error::new 保留
  类型——发现阶段的网络失败此前全部落 internal,现携带 3xx 网络码。

测试:3 个配置校验错误码 downcast 断言 + fetch_bytes 双拒绝映射
(非官方 URL / 404)。真机 e2e:无 auto-discover 的 daemon 上
catalog.refresh → task.status 报 BAT-ERR-100001 missing_app_version
(domain=input),修复前为 900001。全量 fmt / clippy --workspace
--all-targets -D warnings / test --workspace 全绿。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-17 10:20:08 -07:00
co-authored by Claude Fable 5
parent 11b19683cf
commit eac1edd455
2 changed files with 122 additions and 18 deletions
+39 -3
View File
@@ -756,9 +756,12 @@ impl OfficialResourcePullService {
/// This is intended for small discovery inputs such as `server-info`,
/// `TableCatalog.bytes`, `BundlePackingInfo.bytes`, and
/// `MediaCatalog.bytes`.
pub fn fetch_bytes(&self, url: &str) -> Result<Vec<u8>, String> {
pub fn fetch_bytes(&self, url: &str) -> Result<Vec<u8>, DownloadError> {
if !is_official_yostar_jp_url(url) {
return Err(format!("拒绝拉取非官方 URL{url}"));
return Err(DownloadError::new(
bat_core::ErrorCode::NON_OFFICIAL_URL,
format!("拒绝拉取非官方 URL{url}"),
));
}
let output = run_curl_with_retry_with_proxy(
@@ -779,7 +782,13 @@ impl OfficialResourcePullService {
command
},
)
.map_err(|error| format!("curl 拉取失败 {url}{error}"))?;
.map_err(|error| {
// 保留 curl 失败的准确网络域码;进程类失败归 INTERNAL。
let code = error
.final_error_code()
.unwrap_or(bat_core::ErrorCode::INTERNAL);
DownloadError::new(code, format!("curl 拉取失败 {url}{error}"))
})?;
Ok(output.stdout)
}
@@ -1829,6 +1838,33 @@ mod tests {
use std::fs;
use tempfile::TempDir;
#[test]
fn fetch_bytes_maps_rejections_to_error_codes() {
// 非官方 URL:安全边界拒绝。
let service = OfficialResourcePullService::new("/tmp/unused");
let error = service
.fetch_bytes("https://evil.example/server_info.json")
.unwrap_err();
assert_eq!(error.code(), bat_core::ErrorCode::NON_OFFICIAL_URL);
// curl 404:保留网络域码。
let out_dir = TempDir::new().unwrap();
let bin_dir = TempDir::new().unwrap();
let curl_path = bin_dir.path().join("curl");
write_shell_script(
&curl_path,
r#"#!/bin/sh
printf 'curl: (22) The requested URL returned error: 404\n' >&2
exit 22
"#,
);
let service = OfficialResourcePullService::with_curl_command(out_dir.path(), &curl_path);
let error = service
.fetch_bytes("https://prod-clientpatch.bluearchiveyostar.com/r93_token/missing.bytes")
.unwrap_err();
assert_eq!(error.code(), bat_core::ErrorCode::HTTP_NOT_FOUND);
}
#[test]
fn read_download_manifest_at_handles_missing_and_bad_version() {
let temp = TempDir::new().unwrap();