@@ -520,6 +520,121 @@ def test_command_with_aliases(self, project_dir, temp_dir):
520520 assert (claude_dir / "speckit.alias.cmd.md" ).exists ()
521521 assert (claude_dir / "speckit.shortcut.md" ).exists ()
522522
523+ def test_register_commands_for_copilot (self , extension_dir , project_dir ):
524+ """Test registering commands for Copilot agent with .agent.md extension."""
525+ # Create .github/agents directory (Copilot project)
526+ agents_dir = project_dir / ".github" / "agents"
527+ agents_dir .mkdir (parents = True )
528+
529+ manifest = ExtensionManifest (extension_dir / "extension.yml" )
530+
531+ registrar = CommandRegistrar ()
532+ registered = registrar .register_commands_for_agent (
533+ "copilot" , manifest , extension_dir , project_dir
534+ )
535+
536+ assert len (registered ) == 1
537+ assert "speckit.test.hello" in registered
538+
539+ # Verify command file uses .agent.md extension
540+ cmd_file = agents_dir / "speckit.test.hello.agent.md"
541+ assert cmd_file .exists ()
542+
543+ # Verify NO plain .md file was created
544+ plain_md_file = agents_dir / "speckit.test.hello.md"
545+ assert not plain_md_file .exists ()
546+
547+ content = cmd_file .read_text ()
548+ assert "description: Test hello command" in content
549+ assert "<!-- Extension: test-ext -->" in content
550+
551+ def test_copilot_companion_prompt_created (self , extension_dir , project_dir ):
552+ """Test that companion .prompt.md files are created in .github/prompts/."""
553+ agents_dir = project_dir / ".github" / "agents"
554+ agents_dir .mkdir (parents = True )
555+
556+ manifest = ExtensionManifest (extension_dir / "extension.yml" )
557+
558+ registrar = CommandRegistrar ()
559+ registrar .register_commands_for_agent (
560+ "copilot" , manifest , extension_dir , project_dir
561+ )
562+
563+ # Verify companion .prompt.md file exists
564+ prompt_file = project_dir / ".github" / "prompts" / "speckit.test.hello.prompt.md"
565+ assert prompt_file .exists ()
566+
567+ # Verify content has correct agent frontmatter
568+ content = prompt_file .read_text ()
569+ assert content == "---\n agent: speckit.test.hello\n ---\n "
570+
571+ def test_copilot_aliases_get_companion_prompts (self , project_dir , temp_dir ):
572+ """Test that aliases also get companion .prompt.md files for Copilot."""
573+ import yaml
574+
575+ ext_dir = temp_dir / "ext-alias-copilot"
576+ ext_dir .mkdir ()
577+
578+ manifest_data = {
579+ "schema_version" : "1.0" ,
580+ "extension" : {
581+ "id" : "ext-alias-copilot" ,
582+ "name" : "Extension with Alias" ,
583+ "version" : "1.0.0" ,
584+ "description" : "Test" ,
585+ },
586+ "requires" : {"speckit_version" : ">=0.1.0" },
587+ "provides" : {
588+ "commands" : [
589+ {
590+ "name" : "speckit.alias-copilot.cmd" ,
591+ "file" : "commands/cmd.md" ,
592+ "aliases" : ["speckit.shortcut-copilot" ],
593+ }
594+ ]
595+ },
596+ }
597+
598+ with open (ext_dir / "extension.yml" , "w" ) as f :
599+ yaml .dump (manifest_data , f )
600+
601+ (ext_dir / "commands" ).mkdir ()
602+ (ext_dir / "commands" / "cmd.md" ).write_text (
603+ "---\n description: Test\n ---\n \n Test"
604+ )
605+
606+ # Set up Copilot project
607+ (project_dir / ".github" / "agents" ).mkdir (parents = True )
608+
609+ manifest = ExtensionManifest (ext_dir / "extension.yml" )
610+ registrar = CommandRegistrar ()
611+ registered = registrar .register_commands_for_agent (
612+ "copilot" , manifest , ext_dir , project_dir
613+ )
614+
615+ assert len (registered ) == 2
616+
617+ # Both primary and alias get companion .prompt.md
618+ prompts_dir = project_dir / ".github" / "prompts"
619+ assert (prompts_dir / "speckit.alias-copilot.cmd.prompt.md" ).exists ()
620+ assert (prompts_dir / "speckit.shortcut-copilot.prompt.md" ).exists ()
621+
622+ def test_non_copilot_agent_no_companion_file (self , extension_dir , project_dir ):
623+ """Test that non-copilot agents do NOT create .prompt.md files."""
624+ claude_dir = project_dir / ".claude" / "commands"
625+ claude_dir .mkdir (parents = True )
626+
627+ manifest = ExtensionManifest (extension_dir / "extension.yml" )
628+
629+ registrar = CommandRegistrar ()
630+ registrar .register_commands_for_agent (
631+ "claude" , manifest , extension_dir , project_dir
632+ )
633+
634+ # No .github/prompts directory should exist
635+ prompts_dir = project_dir / ".github" / "prompts"
636+ assert not prompts_dir .exists ()
637+
523638
524639# ===== Utility Function Tests =====
525640
@@ -596,6 +711,31 @@ def test_full_install_and_remove_workflow(self, extension_dir, project_dir):
596711 assert not cmd_file .exists ()
597712 assert len (manager .list_installed ()) == 0
598713
714+ def test_copilot_cleanup_removes_prompt_files (self , extension_dir , project_dir ):
715+ """Test that removing a Copilot extension also removes .prompt.md files."""
716+ agents_dir = project_dir / ".github" / "agents"
717+ agents_dir .mkdir (parents = True )
718+
719+ manager = ExtensionManager (project_dir )
720+ manager .install_from_directory (extension_dir , "0.1.0" , register_commands = True )
721+
722+ # Verify copilot was detected and registered
723+ metadata = manager .registry .get ("test-ext" )
724+ assert "copilot" in metadata ["registered_commands" ]
725+
726+ # Verify files exist before cleanup
727+ agent_file = agents_dir / "speckit.test.hello.agent.md"
728+ prompt_file = project_dir / ".github" / "prompts" / "speckit.test.hello.prompt.md"
729+ assert agent_file .exists ()
730+ assert prompt_file .exists ()
731+
732+ # Use the extension manager to remove — exercises the copilot prompt cleanup code
733+ result = manager .remove ("test-ext" )
734+ assert result is True
735+
736+ assert not agent_file .exists ()
737+ assert not prompt_file .exists ()
738+
599739 def test_multiple_extensions (self , temp_dir , project_dir ):
600740 """Test installing multiple extensions."""
601741 import yaml
0 commit comments