@@ -594,6 +594,55 @@ This is test rule content from file.`;
594594 expect ( copilotRule . isRoot ( ) ) . toBe ( true ) ;
595595 } ) ;
596596
597+ it ( "should use relativeDirPath to distinguish non-root files named copilot-instructions.md" , async ( ) => {
598+ const instructionsDir = join ( testDir , ".github" , "instructions" ) ;
599+ await ensureDir ( instructionsDir ) ;
600+
601+ const fileContent = `---
602+ description: "Same filename as root"
603+ applyTo: "**/*.ts"
604+ ---
605+
606+ This should be treated as a non-root rule.` ;
607+ await writeFileContent ( join ( instructionsDir , "copilot-instructions.md" ) , fileContent ) ;
608+
609+ const copilotRule = await CopilotRule . fromFile ( {
610+ baseDir : testDir ,
611+ relativeDirPath : ".github/instructions" ,
612+ relativeFilePath : "copilot-instructions.md" ,
613+ validate : true ,
614+ } ) ;
615+
616+ expect ( copilotRule . isRoot ( ) ) . toBe ( false ) ;
617+ expect ( copilotRule . getRelativeDirPath ( ) ) . toBe ( ".github/instructions" ) ;
618+ expect ( copilotRule . getRelativeFilePath ( ) ) . toBe ( "copilot-instructions.instructions.md" ) ;
619+ expect ( copilotRule . getFrontmatter ( ) ) . toEqual ( {
620+ description : "Same filename as root" ,
621+ applyTo : "**/*.ts" ,
622+ } ) ;
623+ expect ( copilotRule . getBody ( ) ) . toBe ( "This should be treated as a non-root rule." ) ;
624+ } ) ;
625+
626+ it ( "should detect root only when both relativeDirPath and filename match" , async ( ) => {
627+ const githubDir = join ( testDir , ".github" ) ;
628+ await ensureDir ( githubDir ) ;
629+
630+ const rootContent = "Root detected with explicit directory." ;
631+ await writeFileContent ( join ( githubDir , "copilot-instructions.md" ) , rootContent ) ;
632+
633+ const copilotRule = await CopilotRule . fromFile ( {
634+ baseDir : testDir ,
635+ relativeDirPath : ".github" ,
636+ relativeFilePath : "copilot-instructions.md" ,
637+ validate : true ,
638+ } ) ;
639+
640+ expect ( copilotRule . isRoot ( ) ) . toBe ( true ) ;
641+ expect ( copilotRule . getRelativeDirPath ( ) ) . toBe ( ".github" ) ;
642+ expect ( copilotRule . getRelativeFilePath ( ) ) . toBe ( "copilot-instructions.md" ) ;
643+ expect ( copilotRule . getBody ( ) ) . toBe ( rootContent ) ;
644+ } ) ;
645+
597646 it ( "should load root file from .copilot/copilot-instructions.md when global=true" , async ( ) => {
598647 const copilotDir = join ( testDir , ".copilot" ) ;
599648 await ensureDir ( copilotDir ) ;
0 commit comments