@@ -21,6 +21,7 @@ use labels::{
2121use serde:: { Deserialize , Serialize } ;
2222use serde_json:: Value ;
2323use std:: alloc:: { alloc as std_alloc, dealloc as std_dealloc, Layout } ;
24+ use std:: borrow:: Cow ;
2425use std:: slice;
2526use std:: sync:: Mutex ;
2627
@@ -257,9 +258,13 @@ struct LabelResponseOutput {
257258 items : Vec < LabeledItem > ,
258259}
259260
260- fn infer_scope_for_baseline ( tool_name : & str , tool_args : & Value , repo_id : & str ) -> String {
261+ fn infer_scope_for_baseline < ' a > (
262+ tool_name : & str ,
263+ tool_args : & Value ,
264+ repo_id : & ' a str ,
265+ ) -> Cow < ' a , str > {
261266 if !repo_id. is_empty ( ) {
262- return repo_id . to_string ( ) ;
267+ return Cow :: Borrowed ( repo_id ) ;
263268 }
264269
265270 match tool_name {
@@ -268,16 +273,16 @@ fn infer_scope_for_baseline(tool_name: &str, tool_args: &Value, repo_id: &str) -
268273 | "manage_notification_subscription"
269274 | "manage_repository_notification_subscription"
270275 | "create_repository"
271- | "fork_repository" => scope_names:: GITHUB . to_string ( ) ,
276+ | "fork_repository" => Cow :: Borrowed ( scope_names:: GITHUB ) ,
272277 "search_code" | "search_issues" | "search_pull_requests" => {
273278 let query = tool_args
274279 . get ( "query" )
275280 . and_then ( |v| v. as_str ( ) )
276281 . unwrap_or ( "" ) ;
277282 let ( _, _, repo_from_query) = extract_repo_info_from_search_query ( query) ;
278- repo_from_query
283+ Cow :: Owned ( repo_from_query)
279284 }
280- _ => String :: new ( ) ,
285+ _ => Cow :: Borrowed ( "" ) ,
281286 }
282287}
283288
@@ -1096,9 +1101,18 @@ mod tests {
10961101 let tool_args = json ! ( { "query" : "repo:lpcox/github-guard README" } ) ;
10971102
10981103 let inferred = infer_scope_for_baseline ( "search_code" , & tool_args, "" ) ;
1104+ assert ! ( matches!( inferred, Cow :: Owned ( _) ) ) ;
10991105 assert_eq ! ( inferred, "lpcox/github-guard" ) ;
11001106 }
11011107
1108+ #[ test]
1109+ fn infer_scope_for_baseline_borrows_repo_id_when_present ( ) {
1110+ let tool_args = json ! ( { } ) ;
1111+ let inferred = infer_scope_for_baseline ( "get_file_contents" , & tool_args, "octocat/hello-world" ) ;
1112+
1113+ assert ! ( matches!( inferred, Cow :: Borrowed ( "octocat/hello-world" ) ) ) ;
1114+ }
1115+
11021116 #[ test]
11031117 fn search_code_baseline_preserves_scoped_integrity ( ) {
11041118 let ctx = PolicyContext {
0 commit comments