@@ -484,6 +484,145 @@ pub fn generate_pipeline_path(output_path: &std::path::Path) -> String {
484484#[ cfg( test) ]
485485mod tests {
486486 use super :: * ;
487+ use crate :: compile:: types:: { McpConfig , McpOptions , Repository } ;
488+
489+ /// Helper: create a minimal FrontMatter by parsing YAML
490+ fn minimal_front_matter ( ) -> FrontMatter {
491+ let ( fm, _) = parse_markdown ( "---\n name: test-agent\n description: test\n ---\n " ) . unwrap ( ) ;
492+ fm
493+ }
494+
495+ // ─── compute_effective_workspace ─────────────────────────────────────────
496+
497+ #[ test]
498+ fn test_workspace_explicit_root ( ) {
499+ let ws = compute_effective_workspace ( & Some ( "root" . to_string ( ) ) , & [ ] , "agent" ) ;
500+ assert_eq ! ( ws, "root" ) ;
501+ }
502+
503+ #[ test]
504+ fn test_workspace_explicit_repo_with_checkouts ( ) {
505+ let checkouts = vec ! [ "other-repo" . to_string( ) ] ;
506+ let ws = compute_effective_workspace ( & Some ( "repo" . to_string ( ) ) , & checkouts, "agent" ) ;
507+ assert_eq ! ( ws, "repo" ) ;
508+ }
509+
510+ #[ test]
511+ fn test_workspace_implicit_root_no_checkouts ( ) {
512+ let ws = compute_effective_workspace ( & None , & [ ] , "agent" ) ;
513+ assert_eq ! ( ws, "root" ) ;
514+ }
515+
516+ #[ test]
517+ fn test_workspace_implicit_repo_with_checkouts ( ) {
518+ let checkouts = vec ! [ "other-repo" . to_string( ) ] ;
519+ let ws = compute_effective_workspace ( & None , & checkouts, "agent" ) ;
520+ assert_eq ! ( ws, "repo" ) ;
521+ }
522+
523+ #[ test]
524+ fn test_workspace_explicit_repo_no_checkouts_still_returns_repo ( ) {
525+ // Emits a warning but still returns "repo"
526+ let ws = compute_effective_workspace ( & Some ( "repo" . to_string ( ) ) , & [ ] , "agent" ) ;
527+ assert_eq ! ( ws, "repo" ) ;
528+ }
529+
530+ // ─── validate_checkout_list ───────────────────────────────────────────────
531+
532+ #[ test]
533+ fn test_validate_checkout_list_empty_is_ok ( ) {
534+ let result = validate_checkout_list ( & [ ] , & [ ] ) ;
535+ assert ! ( result. is_ok( ) ) ;
536+ }
537+
538+ #[ test]
539+ fn test_validate_checkout_list_valid_alias_passes ( ) {
540+ let repos = vec ! [ Repository {
541+ repository: "my-repo" . to_string( ) ,
542+ repo_type: "git" . to_string( ) ,
543+ name: "org/my-repo" . to_string( ) ,
544+ repo_ref: "refs/heads/main" . to_string( ) ,
545+ } ] ;
546+ let checkout = vec ! [ "my-repo" . to_string( ) ] ;
547+ let result = validate_checkout_list ( & repos, & checkout) ;
548+ assert ! ( result. is_ok( ) ) ;
549+ }
550+
551+ #[ test]
552+ fn test_validate_checkout_list_unknown_alias_fails ( ) {
553+ let repos = vec ! [ Repository {
554+ repository: "my-repo" . to_string( ) ,
555+ repo_type: "git" . to_string( ) ,
556+ name: "org/my-repo" . to_string( ) ,
557+ repo_ref: "refs/heads/main" . to_string( ) ,
558+ } ] ;
559+ let checkout = vec ! [ "unknown-alias" . to_string( ) ] ;
560+ let result = validate_checkout_list ( & repos, & checkout) ;
561+ assert ! ( result. is_err( ) ) ;
562+ assert ! ( result. unwrap_err( ) . to_string( ) . contains( "unknown-alias" ) ) ;
563+ }
564+
565+ #[ test]
566+ fn test_validate_checkout_list_empty_checkout_of_nonempty_repos_ok ( ) {
567+ let repos = vec ! [ Repository {
568+ repository: "my-repo" . to_string( ) ,
569+ repo_type: "git" . to_string( ) ,
570+ name: "org/my-repo" . to_string( ) ,
571+ repo_ref: "refs/heads/main" . to_string( ) ,
572+ } ] ;
573+ let result = validate_checkout_list ( & repos, & [ ] ) ;
574+ assert ! ( result. is_ok( ) ) ;
575+ }
576+
577+ // ─── generate_copilot_params ──────────────────────────────────────────────
578+
579+ #[ test]
580+ fn test_copilot_params_bash_wildcard ( ) {
581+ let mut fm = minimal_front_matter ( ) ;
582+ fm. tools = Some ( crate :: compile:: types:: ToolsConfig {
583+ bash : Some ( vec ! [ ":*" . to_string( ) ] ) ,
584+ edit : None ,
585+ } ) ;
586+ let params = generate_copilot_params ( & fm) ;
587+ assert ! ( params. contains( "--allow-tool \" shell(:*)\" " ) ) ;
588+ }
589+
590+ #[ test]
591+ fn test_copilot_params_bash_disabled ( ) {
592+ let mut fm = minimal_front_matter ( ) ;
593+ fm. tools = Some ( crate :: compile:: types:: ToolsConfig {
594+ bash : Some ( vec ! [ ] ) ,
595+ edit : None ,
596+ } ) ;
597+ let params = generate_copilot_params ( & fm) ;
598+ assert ! ( !params. contains( "shell(" ) ) ;
599+ }
600+
601+ #[ test]
602+ fn test_copilot_params_custom_mcp_not_added_with_mcp_flag ( ) {
603+ let mut fm = minimal_front_matter ( ) ;
604+ fm. mcp_servers . insert (
605+ "my-tool" . to_string ( ) ,
606+ McpConfig :: WithOptions ( McpOptions {
607+ command : Some ( "node" . to_string ( ) ) ,
608+ ..Default :: default ( )
609+ } ) ,
610+ ) ;
611+ let params = generate_copilot_params ( & fm) ;
612+ // Custom MCPs (with command) should NOT appear as --mcp flags
613+ assert ! ( !params. contains( "--mcp my-tool" ) ) ;
614+ }
615+
616+ #[ test]
617+ fn test_copilot_params_builtin_mcp_added_with_mcp_flag ( ) {
618+ let mut fm = minimal_front_matter ( ) ;
619+ fm. mcp_servers
620+ . insert ( "ado" . to_string ( ) , McpConfig :: Enabled ( true ) ) ;
621+ let params = generate_copilot_params ( & fm) ;
622+ assert ! ( params. contains( "--mcp ado" ) ) ;
623+ }
624+
625+ // ─── sanitize_filename ────────────────────────────────────────────────────
487626
488627 #[ test]
489628 fn test_sanitize_filename_basic ( ) {
0 commit comments