Files
skill-lib/tests/common/mod.rs
木炎 6aad2ce48e feat: restore zhihu browser skills
Reconnect the recovered Zhihu skill flows to the live browser runtime and resolve their resources relative to the executable so they work outside the repo root.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-27 14:29:38 +08:00

40 lines
1013 B
Rust

use std::collections::VecDeque;
use std::sync::Mutex;
use std::time::Duration;
use sgclaw::pipe::{AgentMessage, BrowserMessage, PipeError, Transport};
pub struct MockTransport {
incoming: Mutex<VecDeque<BrowserMessage>>,
sent: Mutex<Vec<AgentMessage>>,
}
impl MockTransport {
pub fn new(messages: Vec<BrowserMessage>) -> Self {
Self {
incoming: Mutex::new(VecDeque::from(messages)),
sent: Mutex::new(Vec::new()),
}
}
#[allow(dead_code)]
pub fn sent_messages(&self) -> Vec<AgentMessage> {
self.sent.lock().unwrap().clone()
}
}
impl Transport for MockTransport {
fn send(&self, message: &AgentMessage) -> Result<(), PipeError> {
self.sent.lock().unwrap().push(message.clone());
Ok(())
}
fn recv_timeout(&self, _timeout: Duration) -> Result<BrowserMessage, PipeError> {
self.incoming
.lock()
.unwrap()
.pop_front()
.ok_or(PipeError::Timeout)
}
}