MCPcopy Create free account
hub / github.com/github/gh-aw / TestResolveIncludePath

Function TestResolveIncludePath

pkg/parser/frontmatter_utils_test.go:120–237  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

118}
119
120func TestResolveIncludePath(t *testing.T) {
121 // Create temporary directory structure
122 tempDir, err := os.MkdirTemp("", "test_resolve")
123 require.NoError(t, err, "should create temp dir")
124 defer os.RemoveAll(tempDir)
125
126 // Create regular test file in temp dir
127 regularFile := filepath.Join(tempDir, "regular.md")
128 err = os.WriteFile(regularFile, []byte("test"), 0644)
129 require.NoError(t, err, "should write regular file")
130
131 // Create a repo-like structure: <repoRoot>/.github/workflows/, .github/agents/ and .agents/
132 repoRoot := filepath.Join(tempDir, "repo")
133 workflowsDir := filepath.Join(repoRoot, ".github", "workflows")
134 agentsDir := filepath.Join(repoRoot, ".github", "agents")
135 dotAgentsDir := filepath.Join(repoRoot, ".agents")
136 err = os.MkdirAll(workflowsDir, 0755)
137 require.NoError(t, err, "should create workflows dir")
138 err = os.MkdirAll(agentsDir, 0755)
139 require.NoError(t, err, "should create agents dir")
140 err = os.MkdirAll(dotAgentsDir, 0755)
141 require.NoError(t, err, "should create .agents dir")
142
143 workflowFile := filepath.Join(workflowsDir, "workflow.md")
144 err = os.WriteFile(workflowFile, []byte("test"), 0644)
145 require.NoError(t, err, "should write workflow file")
146
147 agentFile := filepath.Join(agentsDir, "planner.md")
148 err = os.WriteFile(agentFile, []byte("test"), 0644)
149 require.NoError(t, err, "should write agent file")
150
151 dotAgentFile := filepath.Join(dotAgentsDir, "agent.md")
152 err = os.WriteFile(dotAgentFile, []byte("test"), 0644)
153 require.NoError(t, err, "should write .agents file")
154
155 tests := []struct {
156 name string
157 filePath string
158 baseDir string
159 expected string
160 wantErr bool
161 }{
162 {
163 name: "regular relative path",
164 filePath: "regular.md",
165 baseDir: tempDir,
166 expected: regularFile,
167 },
168 {
169 name: "regular file not found",
170 filePath: "nonexistent.md",
171 baseDir: tempDir,
172 wantErr: true,
173 },
174 {
175 name: "absolute path outside base dir is rejected for security",
176 filePath: "/etc/passwd",
177 baseDir: tempDir,

Callers

nothing calls this directly

Calls 3

ResolveIncludePathFunction · 0.70
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected