Skip to content

Commit c144ee3

Browse files
authored
test: add regression coverage for .github/agents/ root-relative import path (#25636)
1 parent a8dedce commit c144ee3

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

pkg/parser/import_remote_nested_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,72 @@ func TestMultipleSiblingStylesFromSameDirectory(t *testing.T) {
872872
"server-c from shared/server-c.md root-relative import should be merged")
873873
}
874874

875+
// TestDotGithubAgentsImport verifies the documented import path format
876+
// ".github/agents/planner.md" resolves from the repository root
877+
// (not from .github/workflows/ as a base).
878+
//
879+
// This is the regression test for the bug where:
880+
// - importing ".github/agents/planner.md" failed with "import file not found"
881+
// - because the resolver was treating the path as relative to .github/workflows/
882+
//
883+
// The correct behaviour is described in the imports documentation:
884+
// paths starting with ".github/" are repo-root-relative.
885+
func TestDotGithubAgentsImport(t *testing.T) {
886+
tmpDir := t.TempDir()
887+
workflowsDir := filepath.Join(tmpDir, ".github", "workflows")
888+
agentsDir := filepath.Join(tmpDir, ".github", "agents")
889+
require.NoError(t, os.MkdirAll(workflowsDir, 0o755), "create .github/workflows dir")
890+
require.NoError(t, os.MkdirAll(agentsDir, 0o755), "create .github/agents dir")
891+
892+
// Agent file at .github/agents/planner.md (repo-root-relative path as documented)
893+
agentContent := "---\ndescription: Planner agent\n---\n\n# Planner\n\nHelp with planning."
894+
require.NoError(t, os.WriteFile(filepath.Join(agentsDir, "planner.md"), []byte(agentContent), 0o644),
895+
"write .github/agents/planner.md")
896+
897+
t.Run("root-relative .github/agents/ path resolves as agent file", func(t *testing.T) {
898+
frontmatter := map[string]any{
899+
"imports": []any{".github/agents/planner.md"},
900+
}
901+
yamlContent := "imports:\n - .github/agents/planner.md\n"
902+
cache := NewImportCache(tmpDir)
903+
result, err := ProcessImportsFromFrontmatterWithSource(
904+
frontmatter, workflowsDir, cache,
905+
filepath.Join(workflowsDir, "planner-test.md"), yamlContent,
906+
)
907+
908+
require.NoError(t, err, "'.github/agents/planner.md' import should resolve successfully")
909+
require.NotNil(t, result, "result should not be nil")
910+
911+
// The agent file should be detected and its path stored
912+
assert.Equal(t, ".github/agents/planner.md", result.AgentFile,
913+
"AgentFile should be set to the repo-root-relative path")
914+
915+
// The import path should be added for runtime-import macro generation
916+
assert.Contains(t, result.ImportPaths, ".github/agents/planner.md",
917+
"ImportPaths should contain the agent import path")
918+
})
919+
920+
t.Run("slash-prefixed /.github/agents/ path also resolves as agent file", func(t *testing.T) {
921+
frontmatter := map[string]any{
922+
"imports": []any{"/.github/agents/planner.md"},
923+
}
924+
yamlContent := "imports:\n - /.github/agents/planner.md\n"
925+
cache := NewImportCache(tmpDir)
926+
result, err := ProcessImportsFromFrontmatterWithSource(
927+
frontmatter, workflowsDir, cache,
928+
filepath.Join(workflowsDir, "planner-test.md"), yamlContent,
929+
)
930+
931+
require.NoError(t, err, "'/.github/agents/planner.md' import should resolve successfully")
932+
require.NotNil(t, result, "result should not be nil")
933+
934+
// The agent file should be detected
935+
assert.NotEmpty(t, result.AgentFile, "AgentFile should be set")
936+
assert.Contains(t, result.ImportPaths, result.AgentFile,
937+
"ImportPaths should contain the agent import path")
938+
})
939+
}
940+
875941
// writeFile is a test helper that writes content to a file in the given directory.
876942
func writeFile(t *testing.T, dir, name, content string) {
877943
t.Helper()

0 commit comments

Comments
 (0)