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

Function TestImportCycleDetection_FourFiles

pkg/parser/import_cycle_test.go:67–146  ·  view source on GitHub ↗

TestImportCycleDetection_FourFiles tests that a 4-file cycle (A→B→C→D→B) is detected This is the exact scenario from the issue requirements

(t *testing.T)

Source from the content-addressed store, hash-verified

65// TestImportCycleDetection_FourFiles tests that a 4-file cycle (A→B→C→D→B) is detected
66// This is the exact scenario from the issue requirements
67func TestImportCycleDetection_FourFiles(t *testing.T) {
68 tempDir := testutil.TempDir(t, "test-*")
69
70 // Create workflow A that imports B
71 fileA := filepath.Join(tempDir, "a.md")
72 fileAContent := `---
73imports:
74 - b.md
75---
76# Workflow A
77`
78 require.NoError(t, os.WriteFile(fileA, []byte(fileAContent), 0644), "Failed to write file A")
79
80 // Create file B that imports C
81 fileB := filepath.Join(tempDir, "b.md")
82 fileBContent := `---
83imports:
84 - c.md
85---
86# File B
87`
88 require.NoError(t, os.WriteFile(fileB, []byte(fileBContent), 0644), "Failed to write file B")
89
90 // Create file C that imports D
91 fileC := filepath.Join(tempDir, "c.md")
92 fileCContent := `---
93imports:
94 - d.md
95---
96# File C
97`
98 require.NoError(t, os.WriteFile(fileC, []byte(fileCContent), 0644), "Failed to write file C")
99
100 // Create file D that imports B (creating cycle back to B)
101 fileD := filepath.Join(tempDir, "d.md")
102 fileDContent := `---
103imports:
104 - b.md
105---
106# File D
107`
108 require.NoError(t, os.WriteFile(fileD, []byte(fileDContent), 0644), "Failed to write file D")
109
110 // Process imports from file A - should detect cycle B→C→D→B
111 frontmatter := map[string]any{
112 "imports": []string{"b.md"},
113 }
114
115 _, err := parser.ProcessImportsFromFrontmatterWithSource(frontmatter, tempDir, nil, fileA, fileAContent)
116 require.Error(t, err, "Should detect import cycle")
117
118 // Verify error is an ImportCycleError
119 var cycleErr *parser.ImportCycleError
120 require.ErrorAs(t, err, &cycleErr, "Error should be ImportCycleError")
121
122 if cycleErr != nil {
123 // Verify the full chain is present
124 assert.NotEmpty(t, cycleErr.Chain, "Cycle chain should not be empty")

Callers

nothing calls this directly

Calls 4

TempDirFunction · 0.92
FormatImportCycleErrorFunction · 0.92
ErrorMethod · 0.45

Tested by

no test coverage detected