test(kernel,growth): Phase 1 缝测试安全网 — 3条核心链路 19 测试全部通过
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
对话链路: 4 缝测试 (Tauri→Kernel / Kernel→LLM / LLM→UI / 流式生命周期) Hands链路: 3 缝测试 (工具路由 / 执行回调 / 通用工具) 记忆链路: 3 缝测试 (FTS5存储 / 模式检索 / 去重) 冒烟测试: 3 Rust + 8 TypeScript 全量 PASS - Kernel::boot_with_driver() 测试辅助方法 - 全量 cargo test 0 回归 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
59
crates/zclaw-kernel/tests/smoke_chat.rs
Normal file
59
crates/zclaw-kernel/tests/smoke_chat.rs
Normal file
@@ -0,0 +1,59 @@
|
||||
//! Chat smoke test — full lifecycle: send → stream → persist
|
||||
//!
|
||||
//! Uses MockLlmDriver to verify the complete chat pipeline without a real LLM.
|
||||
|
||||
use std::sync::Arc;
|
||||
use zclaw_kernel::{Kernel, KernelConfig};
|
||||
use zclaw_runtime::test_util::MockLlmDriver;
|
||||
use zclaw_runtime::{LoopEvent, LlmDriver};
|
||||
use zclaw_types::AgentConfig;
|
||||
|
||||
#[tokio::test]
|
||||
async fn smoke_chat_full_lifecycle() {
|
||||
let mock = MockLlmDriver::new().with_text_response("Hello! I am the mock assistant.");
|
||||
let config = KernelConfig::default();
|
||||
let kernel = Kernel::boot_with_driver(config, Arc::new(mock) as Arc<dyn LlmDriver>)
|
||||
.await
|
||||
.expect("kernel boot");
|
||||
|
||||
let agent = AgentConfig::new("smoke-agent")
|
||||
.with_system_prompt("You are a test assistant.");
|
||||
let id = agent.id;
|
||||
kernel.spawn_agent(agent).await.expect("spawn agent");
|
||||
|
||||
// 1. Non-streaming: send and get response
|
||||
let resp = kernel.send_message(&id, "Hello".to_string()).await.expect("send");
|
||||
assert!(!resp.content.is_empty());
|
||||
assert!(resp.output_tokens > 0);
|
||||
|
||||
// 2. Streaming: send and collect all events
|
||||
let mut rx = kernel
|
||||
.send_message_stream(&id, "Tell me more".to_string())
|
||||
.await
|
||||
.expect("stream");
|
||||
|
||||
let mut delta_count = 0;
|
||||
let mut complete_result = None;
|
||||
while let Some(event) = rx.recv().await {
|
||||
match event {
|
||||
LoopEvent::Delta(text) => {
|
||||
delta_count += 1;
|
||||
assert!(!text.is_empty(), "delta should have content");
|
||||
}
|
||||
LoopEvent::Complete(result) => {
|
||||
complete_result = Some(result);
|
||||
break;
|
||||
}
|
||||
LoopEvent::Error(msg) => panic!("unexpected error: {}", msg),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
assert!(delta_count > 0, "should receive at least one delta");
|
||||
let result = complete_result.expect("should receive complete");
|
||||
assert!(result.output_tokens > 0);
|
||||
|
||||
// 3. Verify session persistence — messages were saved
|
||||
let agent_info = kernel.get_agent(&id).expect("agent should exist");
|
||||
assert!(agent_info.message_count >= 2, "at least 2 messages should be tracked");
|
||||
}
|
||||
Reference in New Issue
Block a user