Skip to content

Commit b848acc

Browse files
committed
beginning of userSubmitPrompt persistance test
1 parent 20a050b commit b848acc

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

crates/agent/tests/common/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ use serde::Serialize;
4747

4848
type MockResponseStreams = Vec<Vec<StreamResult>>;
4949

50-
#[derive(Default)]
5150
pub struct TestCaseBuilder {
51+
test_base: TestBase,
5252
test_name: Option<String>,
5353
agent_config: Option<AgentConfig>,
5454
files: Vec<Box<dyn TestFile>>,
@@ -58,6 +58,10 @@ pub struct TestCaseBuilder {
5858
}
5959

6060
impl TestCaseBuilder {
61+
pub async fn new() -> Self {
62+
Self { test_base: TestBase::new().await, test_name: Default::default(), agent_config: todo!(), files: todo!(), mock_responses: todo!(), trust_all_tools: todo!(), tool_use_approvals: todo!() }
63+
}
64+
6165
pub fn test_name<'a>(mut self, name: impl Into<Cow<'a, str>>) -> Self {
6266
self.test_name = Some(name.into().to_string());
6367
self
@@ -92,6 +96,10 @@ impl TestCaseBuilder {
9296
self
9397
}
9498

99+
pub fn with_test_perprompt_hook(mut self) -> Self {
100+
101+
}
102+
95103
pub async fn build(self) -> Result<TestCase> {
96104
let snapshot = AgentSnapshot::new_empty(self.agent_config.unwrap_or_default());
97105

@@ -102,7 +110,6 @@ impl TestCaseBuilder {
102110

103111
let mut agent = Agent::new(snapshot, Arc::new(model), McpManager::new().spawn()).await?;
104112

105-
let mut test_base = TestBase::new().await;
106113
for file in self.files {
107114
test_base = test_base.with_file(file).await;
108115
}

crates/agent/tests/test_hooks.rs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,54 @@ async fn test_user_prompt_hook_single() {
120120
let req = test.requests().first().expect("should have one request");
121121
let first_msg = req.messages().first().expect("first message should exist").text();
122122
assert_contains(&first_msg, "submitted!");
123-
}
123+
}
124+
125+
#[tokio::test]
126+
async fn test_user_prompt_hook_persistence() {
127+
let _ = tracing_subscriber::fmt::try_init();
128+
129+
let hooks = HashMap::from([
130+
(
131+
HookTrigger::UserPromptSubmit,
132+
vec![HookConfig::ShellCommand(CommandHook {
133+
command: "printf 'a' >> turns.txt; printf \"char count: $(wc -c < turns.txt | tr -d ' ')\"".to_string(),
134+
opts: BaseHookConfig {
135+
timeout_ms: 5000,
136+
max_output_size: 1024,
137+
cache_ttl_seconds: 0,
138+
matcher: None,
139+
},
140+
})],
141+
),
142+
]);
143+
144+
let agent_config = AgentConfig::V2025_08_22(AgentConfigV2025_08_22 {
145+
hooks,
146+
..Default::default()
147+
});
148+
let mut test: TestCase = TestCase::builder()
149+
.test_name("user prompt submit hook behavior for single shell command and one turn")
150+
.with_agent_config(agent_config)
151+
.with_test_perprompt_hook()
152+
.with_file(("turns.txt", ""))
153+
.with_responses(
154+
parse_response_streams(include_str!("./mock_responses/simple_two_turn.jsonl"))
155+
.await
156+
.unwrap(),
157+
)
158+
.build()
159+
.await
160+
.unwrap();
161+
162+
test.wait_until_agent_initializes(Duration::from_millis(100)).await;
163+
test.send_prompt("hello".to_string()).await;
164+
test.wait_until_agent_stop(Duration::from_millis(100)).await;
165+
test.send_prompt("bye".to_string()).await;
166+
test.wait_until_agent_stop(Duration::from_millis(100)).await;
167+
let req = test.requests().first().expect("first request should exist");
168+
let first_msg = req.messages().first().expect("first message should exist").text();
169+
assert_contains(&first_msg, "char count: 1");
170+
let req = test.requests().get(1).expect("second request should exist");
171+
let first_msg = req.messages().first().expect("first message should exist").text();
172+
assert_contains(&first_msg, "char count: 2");
173+
}

0 commit comments

Comments
 (0)