1use crate::example::{Example, ExampleContext, ExampleMetadata, JudgeAssertion};
2use agent::{EditFileMode, EditFileToolInput};
3use agent_settings::AgentProfileId;
4use anyhow::Result;
5use async_trait::async_trait;
6
7pub struct CommentTranslation;
8
9#[async_trait(?Send)]
10impl Example for CommentTranslation {
11 fn meta(&self) -> ExampleMetadata {
12 ExampleMetadata {
13 name: "comment_translation".to_string(),
14 url: "https://github.com/servo/font-kit.git".to_string(),
15 revision: "504d084e29bce4f60614bc702e91af7f7d9e60ad".to_string(),
16 language_server: None,
17 max_assertions: Some(1),
18 profile_id: AgentProfileId::default(),
19 existing_thread_json: None,
20 max_turns: None,
21 }
22 }
23
24 async fn conversation(&self, cx: &mut ExampleContext) -> Result<()> {
25 let response = cx.prompt(
26 r#"
27 Edit the following files and translate all their comments to italian, in this exact order:
28
29 - font-kit/src/family.rs
30 - font-kit/src/canvas.rs
31 - font-kit/src/error.rs
32 "#
33 ).await?;
34
35 let mut create_or_overwrite_count = 0;
36 for tool_call in response.tool_calls() {
37 if tool_call.name == "edit_file" {
38 let input = tool_call.parse_input::<EditFileToolInput>()?;
39 if !matches!(input.mode, EditFileMode::Edit) {
40 create_or_overwrite_count += 1;
41 }
42 }
43 }
44
45 cx.assert_eq(create_or_overwrite_count, 0, "no_creation_or_overwrite")?;
46
47 Ok(())
48 }
49
50 fn diff_assertions(&self) -> Vec<JudgeAssertion> {
51 vec![JudgeAssertion {
52 id: "comments_translated".to_string(),
53 description: concat!(
54 "- Only `family.rs`, `canvas.rs` and `error.rs` should have changed.\n",
55 "- Their doc comments should have been all translated to Italian."
56 )
57 .into(),
58 }]
59 }
60}