From bc1dc868a1b040ca5d4feceed0c99fb307462d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Fri, 18 Sep 2026 14:07:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E5=B7=B2=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E9=99=84=E4=BB=B6=E7=9A=84=E9=A1=B9=E7=9B=AE=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit imported 附件必须携带有效非空的项目相对路径。 failed 附件仍允许无路径,并补充状态路径组合测试。 --- .../direct_codex_user_item/validation.rs | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/direct_codex_user_item/validation.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/direct_codex_user_item/validation.rs index 12bab6797..f0ff6e7be 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/direct_codex_user_item/validation.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/direct_codex_user_item/validation.rs @@ -50,11 +50,15 @@ pub(crate) fn validate_direct_codex_user_item( if reference.name.trim().is_empty() { return Err("附件缺少文件名".to_string()); } + let status = reference.status.trim(); + if status == "imported" && reference.local_path.trim().is_empty() { + return Err("已导入附件缺少项目路径".to_string()); + } if !reference.local_path.trim().is_empty() { sanitize_attachment_local_path(&reference.local_path) .ok_or_else(|| "附件项目路径无效".to_string())?; } - if !matches!(reference.status.trim(), "imported" | "failed") { + if !matches!(status, "imported" | "failed") { return Err("附件状态无效".to_string()); } } @@ -186,4 +190,28 @@ mod tests { .expect_err("too many inline attachments must be rejected"); assert!(error.contains("最多携带"), "{error}"); } + + #[test] + fn imported_attachment_requires_a_project_path() { + let root = tempfile::tempdir().expect("temp project"); + crate::init_local_game_project_at(root.path(), "validation-test", "校验测试") + .expect("init project"); + let item = serde_json::from_value(json!({ + "type": "message", + "role": "user", + "content": [{ + "type": "agc_attachment_reference", + "name": "attachment.txt", + "mediaType": "text/plain", + "size": 1, + "localPath": "", + "status": "imported" + }], + "id": "turn-1:user" + })) + .expect("deserialize user item"); + let error = validate_direct_codex_user_item(root.path(), &item) + .expect_err("imported attachment without a project path must fail"); + assert!(error.contains("缺少项目路径"), "{error}"); + } }