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

Function TestProcessIncludesWithWorkflowSpec_PathResolution

pkg/cli/imports_test.go:272–307  ·  view source on GitHub ↗

TestProcessIncludesWithWorkflowSpec_PathResolution tests that body-level {{#import}} paths are resolved relative to the workflow file's location, not the repo root. Regression test for: gh aw add rewrites {{#import shared/X.md}} with incorrect cross-repo path (resolves from repo root instead of .git

(t *testing.T)

Source from the content-addressed store, hash-verified

270// Regression test for: gh aw add rewrites {{#import shared/X.md}} with incorrect
271// cross-repo path (resolves from repo root instead of .github/workflows/).
272func TestProcessIncludesWithWorkflowSpec_PathResolution(t *testing.T) {
273 content := `---
274engine: copilot
275---
276
277# My Workflow
278
279{{#import shared/config.md}}
280`
281
282 workflow := &WorkflowSpec{
283 RepoSpec: RepoSpec{
284 RepoSlug: "github/source-repo",
285 },
286 WorkflowPath: ".github/workflows/my-workflow.md",
287 }
288
289 commitSHA := "abc123def456"
290
291 result, err := processIncludesWithWorkflowSpec(content, workflow, commitSHA, "", "", false)
292 if err != nil {
293 t.Fatalf("Expected no error, got: %v", err)
294 }
295
296 // Path should be resolved relative to .github/workflows/, not the repo root
297 expectedInclude := "{{#import github/source-repo/.github/workflows/shared/config.md@abc123def456}}"
298 if !strings.Contains(result, expectedInclude) {
299 t.Errorf("Expected result to contain '%s'\nGot:\n%s", expectedInclude, result)
300 }
301
302 // The old wrong form (resolving from repo root) must not appear
303 wrongPath := "{{#import github/source-repo/shared/config.md@abc123def456}}"
304 if strings.Contains(result, wrongPath) {
305 t.Errorf("Result must NOT contain repo-root-relative path '%s'\nGot:\n%s", wrongPath, result)
306 }
307}
308
309// TestProcessIncludesWithWorkflowSpec_PreservesLocalIncludes tests that body-level
310// {{#import}} directives are preserved as-is when the target file exists in the

Callers

nothing calls this directly

Calls 2

ErrorfMethod · 0.45

Tested by

no test coverage detected