保留模型目录失败细节

补充目录认证解析超时和清理错误正文

通过模型目录定向测试
This commit is contained in:
kdletters
2026-10-05 19:20:29 +08:00
parent 3ecff3f524
commit 9eabdacdfb
@@ -35,7 +35,7 @@ pub(super) fn source_for_credential(
return Ok(CatalogSource::Bundled);
};
let auth: Value = serde_json::from_slice(auth_json)
.map_err(|_| "model-catalog-auth-invalid: 认证桥接内容无效")?;
.map_err(|error| format!("model-catalog-auth-invalid: 认证桥接内容无效:{error}"))?;
// 与 SDK resolved_mode 一样,显式 auth_mode 优先;旧文件才根据 API Key 判定。
let api_key_mode = match auth.get("auth_mode").and_then(Value::as_str) {
Some(mode) => mode == "apikey",
@@ -176,7 +176,7 @@ async fn export_catalog(
tokio::select! {
biased;
_ = cancelled(cancel) => Err("model-catalog-cancelled".into()),
result = tokio::time::timeout(CAPTURE_TIMEOUT, collected) => result.unwrap_or_else(|_| Err("model-catalog-timeout".into())),
result = tokio::time::timeout(CAPTURE_TIMEOUT, collected) => result.unwrap_or_else(|_| Err(format!("model-catalog-timeout: exceeded {} ms", CAPTURE_TIMEOUT.as_millis()))),
}
} else {
Err("model-catalog-stdio-unavailable".into())
@@ -184,7 +184,7 @@ async fn export_catalog(
let proof = tree
.shutdown(&mut child)
.await
.map_err(|_| "model-catalog-process-exit-unconfirmed")?;
.map_err(|error| format!("model-catalog-process-exit-unconfirmed: {error}"))?;
if !proof.main_process_exited || !proof.observed_tree_empty {
return Err("model-catalog-process-exit-unconfirmed".into());
}
@@ -344,7 +344,7 @@ pub(super) async fn capture(
if source == CatalogSource::Authenticated
&& cache_path
.try_exists()
.map_err(|_| "model-catalog-source-unavailable")?
.map_err(|error| format!("model-catalog-source-unavailable: {error}"))?
{
return Err("model-catalog-source-not-fresh: 当前回合必须使用新隔离目录".into());
}
@@ -369,9 +369,11 @@ pub(super) async fn capture(
"模型目录来源",
MAX_CATALOG_BYTES as u64,
)
.map_err(|_| "model-catalog-source-unconfirmed: OAuth 目录未取得本回合有效远端来源")?;
let cache: Value =
serde_json::from_str(&cache_text).map_err(|_| "model-catalog-source-invalid")?;
.map_err(|error| {
format!("model-catalog-source-unconfirmed: OAuth 目录未取得本回合有效远端来源:{error}")
})?;
let cache: Value = serde_json::from_str(&cache_text)
.map_err(|error| format!("model-catalog-source-invalid: {error}"))?;
verify_authenticated_source(&cache, &original, &bundled, started_ms, now_ms())?;
let evidence = json!({"cacheSha256":format!("{:x}", Sha256::digest(cache_text.as_bytes())),
"fetchedAt":cache.get("fetched_at"),"etagSha256":cache.get("etag").and_then(Value::as_str).map(|etag|format!("{:x}",Sha256::digest(etag.as_bytes())))});
@@ -386,8 +388,10 @@ pub(super) async fn capture(
{
return Err("model-catalog-cancelled".into());
}
let original_bytes = serde_json::to_vec(&original).map_err(|_| "model-catalog-json-invalid")?;
let derived_bytes = serde_json::to_vec(&derived).map_err(|_| "model-catalog-json-invalid")?;
let original_bytes = serde_json::to_vec(&original)
.map_err(|error| format!("model-catalog-json-invalid: {error}"))?;
let derived_bytes = serde_json::to_vec(&derived)
.map_err(|error| format!("model-catalog-json-invalid: {error}"))?;
if derived_bytes.len() > MAX_CATALOG_BYTES {
return Err("model-catalog-output-limit".into());
}
@@ -401,7 +405,8 @@ pub(super) async fn capture(
"changedField":"apply_patch_tool_type","modelCount":derived["models"].as_array().unwrap().len(),"cache":cache_evidence});
crate::write_game_creator_private_file(
&isolated_home.join("direct-model-catalog-receipt.json"),
&serde_json::to_vec(&receipt).map_err(|_| "model-catalog-receipt-invalid")?,
&serde_json::to_vec(&receipt)
.map_err(|error| format!("model-catalog-receipt-invalid: {error}"))?,
"模型目录来源回执",
)
.map_err(|error| {