1use crate::example::{Example, ExampleContext, ExampleMetadata, JudgeAssertion};
2use agent_settings::AgentProfileId;
3use anyhow::Result;
4use assistant_tools::{EditFileMode, EditFileToolInput};
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 }
21 }
22
23 async fn conversation(&self, cx: &mut ExampleContext) -> Result<()> {
24 cx.push_user_message(r#"
25 Edit the following files and translate all their comments to italian, in this exact order:
26
27 - font-kit/src/family.rs
28 - font-kit/src/canvas.rs
29 - font-kit/src/error.rs
30 "#);
31 cx.run_to_end().await?;
32
33 let mut create_or_overwrite_count = 0;
34 cx.agent_thread().read_with(cx, |thread, cx| {
35 for message in thread.messages() {
36 for tool_use in thread.tool_uses_for_message(message.id, cx) {
37 if tool_use.name == "edit_file" {
38 let input: EditFileToolInput = serde_json::from_value(tool_use.input)?;
39 if !matches!(input.mode, EditFileMode::Edit) {
40 create_or_overwrite_count += 1;
41 }
42 }
43 }
44 }
45
46 anyhow::Ok(())
47 })??;
48 cx.assert_eq(create_or_overwrite_count, 0, "no_creation_or_overwrite")?;
49
50 Ok(())
51 }
52
53 fn diff_assertions(&self) -> Vec<JudgeAssertion> {
54 vec![JudgeAssertion {
55 id: "comments_translated".to_string(),
56 description: concat!(
57 "- Only `family.rs`, `canvas.rs` and `error.rs` should have changed.\n",
58 "- Their doc comments should have been all translated to Italian."
59 )
60 .into(),
61 }]
62 }
63}