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