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