comment_translation.rs

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