diff --git a/src-tauri/src/commands/onboarding.rs b/src-tauri/src/commands/onboarding.rs index 4a6704a..fb36662 100644 --- a/src-tauri/src/commands/onboarding.rs +++ b/src-tauri/src/commands/onboarding.rs @@ -379,7 +379,13 @@ fn check_project_context( .get("schema_version") .and_then(|value| value.as_u64()); let project_id = context.get("project_id").and_then(|value| value.as_str()); - if version != Some(PROJECT_CONTEXT_SCHEMA_VERSION) { + if project_id != Some(expected_project_id) { + VerifyCheck::with_state( + "项目身份上下文", + VerifyState::Unavailable, + "`.lian-jing/context.json` 的 project_id 与炼境登记不一致——停止使用并重新 inject_mcp", + ) + } else if version != Some(PROJECT_CONTEXT_SCHEMA_VERSION) { VerifyCheck::with_state( "项目身份上下文", VerifyState::VersionMismatch, @@ -388,18 +394,12 @@ fn check_project_context( version, PROJECT_CONTEXT_SCHEMA_VERSION ), ) - } else if project_id == Some(expected_project_id) { + } else { VerifyCheck::with_state( "项目身份上下文", VerifyState::Ready, "`.lian-jing/context.json` 与已登记 project_id 一致", ) - } else { - VerifyCheck::with_state( - "项目身份上下文", - VerifyState::Unavailable, - "`.lian-jing/context.json` 的 project_id 与炼境登记不一致——停止使用并重新 inject_mcp", - ) } } None if legacy @@ -989,6 +989,14 @@ mod tests { ); assert_eq!(mismatch.state, VerifyState::VersionMismatch); + let identity_mismatch = check_project_context( + Some(r#"{"schema_version":0,"project_id":"another-project"}"#), + None, + "p1", + ); + assert_eq!(identity_mismatch.state, VerifyState::Unavailable); + assert!(identity_mismatch.detail.contains("停止使用")); + let missing = check_project_context(None, None, "p1"); assert_eq!(missing.state, VerifyState::Missing);