CI / fmt (rustfmt --check) (push) Waiting to run
CI / clippy (ubuntu-latest) (push) Waiting to run
CI / clippy (windows-latest) (push) Waiting to run
CI / test (ubuntu-latest) (push) Waiting to run
CI / test (windows-latest) (push) Waiting to run
CI / build release (ubuntu-latest) (push) Waiting to run
CI / build release (windows-latest) (push) Waiting to run
CI / runtime smoke (ubuntu x64, xvfb) (push) Waiting to run
CI / runtime smoke (macos arm64, probe) (push) Skipped
CI / update-e2e (windows x64) (push) Waiting to run
GPU evidence / GPU 判据自测(不需 GPU;跳过 ≠ 已验证) (push) Waiting to run
GPU evidence / GPU 证据 — 探测可用产物与硬件适配器 (push) Waiting to run
Guards / core 零 UI 守门 (push) Waiting to run
Guards / presenter 零 UI 守门 (push) Waiting to run
Guards / design 零第三方依赖守门 (push) Waiting to run
Guards / unsafe 落点守门(集合必须恰好等于期望) (push) Waiting to run
Guards / 文件行数 ≤400 守门 (push) Waiting to run
Guards / 依赖许可与来源(cargo-deny) (push) Waiting to run
Release guard / 发布标记语义守门(push tag → 稳定版) (push) Waiting to run
Signing status(播报,不是门禁) / 判据自测(三行/退出码/变异重放/接线) (push) Waiting to run
Signing status(播报,不是门禁) / 签名就绪度(播报) (push) Waiting to run
Release / 选槽位(默认四个:Windows 两档 + Linux 两档) (push) Waiting to run
83 lines
2.9 KiB
Rust
83 lines
2.9 KiB
Rust
//! [`super`](rig 适配层)的用例(M174 r1 复审 P2-5 拆出来:结构化映射让 `rig.rs` 撞了 400 行)。
|
||
//!
|
||
//! 纯搬移。分类的端到端证据不在本文件:那要真 HTTP,用例在
|
||
//! `crates/cli/src/commands/agent/probe/tests.rs`(四类各一台假服务器)。
|
||
|
||
use super::*;
|
||
|
||
fn tool(id: &str, name: &str) -> super::super::chat::ToolCall {
|
||
super::super::chat::ToolCall {
|
||
id: id.to_string(),
|
||
name: name.to_string(),
|
||
arguments: serde_json::json!({ "path": "appearance.theme_mode" }),
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn disabled_config_is_rejected_before_touching_the_network() {
|
||
let Err(err) = RigProvider::new(ProviderConfig::disabled()) else {
|
||
panic!("禁用态应在构造阶段被拒");
|
||
};
|
||
assert!(err.to_string().contains("禁用"));
|
||
}
|
||
|
||
#[test]
|
||
fn anthropic_without_key_is_rejected() {
|
||
assert!(RigProvider::new(ProviderConfig::anthropic("claude-sonnet-4")).is_err());
|
||
assert!(
|
||
RigProvider::new(ProviderConfig::anthropic("claude-sonnet-4").with_api_key("sk-ant"))
|
||
.is_ok()
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn local_states_build_offline() {
|
||
assert!(RigProvider::new(ProviderConfig::llamacpp_local("qwen2.5-7b")).is_ok());
|
||
assert!(RigProvider::new(ProviderConfig::ollama("llama3.1")).is_ok());
|
||
}
|
||
|
||
#[test]
|
||
fn request_maps_messages_and_tools() {
|
||
let request = ChatRequest {
|
||
model: "mock".to_string(),
|
||
messages: vec![
|
||
ChatMessage::system("你是助手"),
|
||
ChatMessage::user("把主题换成浅色"),
|
||
ChatMessage::Assistant {
|
||
text: String::new(),
|
||
tool_calls: vec![tool("call_1", "set_config")],
|
||
},
|
||
ChatMessage::tool("call_1", "set_config", "{\"status\":\"written\"}"),
|
||
],
|
||
tools: vec![crate::registry::ToolDefinition {
|
||
name: "set_config".to_string(),
|
||
description: "改配置".to_string(),
|
||
input_schema: serde_json::json!({ "type": "object" }),
|
||
}],
|
||
temperature: Some(0.5),
|
||
max_tokens: Some(512),
|
||
};
|
||
let built = build_request(&request).expect("应能构造");
|
||
assert_eq!(built.chat_history.len(), 4);
|
||
assert_eq!(built.tools.len(), 1);
|
||
assert_eq!(built.tools[0].name.as_str(), "set_config");
|
||
assert_eq!(built.temperature, Some(0.5));
|
||
assert_eq!(built.max_tokens, Some(512));
|
||
// 工具结果在 rig 0.45 里是 user 角色的 ToolResult 内容块
|
||
let json = serde_json::to_string(&built.chat_history[3]).expect("可序列化");
|
||
assert!(json.contains("toolresult"), "{json}");
|
||
}
|
||
|
||
#[test]
|
||
fn empty_history_is_a_readable_error() {
|
||
let request = ChatRequest {
|
||
model: "m".to_string(),
|
||
messages: Vec::new(),
|
||
tools: Vec::new(),
|
||
temperature: None,
|
||
max_tokens: None,
|
||
};
|
||
let err = build_request(&request).unwrap_err();
|
||
assert!(err.to_string().contains("对话历史为空"));
|
||
}
|