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

Function TestImportCycleError_FormattedOutput

pkg/parser/import_cycle_test.go:203–255  ·  view source on GitHub ↗

TestImportCycleError_FormattedOutput tests the formatted error message

(t *testing.T)

Source from the content-addressed store, hash-verified

201
202// TestImportCycleError_FormattedOutput tests the formatted error message
203func TestImportCycleError_FormattedOutput(t *testing.T) {
204 tests := []struct {
205 name string
206 chain []string
207 expectedParts []string
208 }{
209 {
210 name: "simple 2-file cycle",
211 chain: []string{"a.md", "b.md", "a.md"},
212 expectedParts: []string{
213 "Import cycle detected",
214 "a.md (starting point)",
215 "imports b.md",
216 "cycles back to a.md",
217 "To fix this issue:",
218 },
219 },
220 {
221 name: "4-file cycle as per issue",
222 chain: []string{"b.md", "c.md", "d.md", "b.md"},
223 expectedParts: []string{
224 "Import cycle detected",
225 "b.md (starting point)",
226 "imports c.md",
227 "imports d.md",
228 "cycles back to b.md",
229 },
230 },
231 }
232
233 for _, tt := range tests {
234 t.Run(tt.name, func(t *testing.T) {
235 cycleErr := &parser.ImportCycleError{
236 Chain: tt.chain,
237 WorkflowFile: "test.md",
238 }
239
240 formatted := parser.FormatImportCycleError(cycleErr)
241 require.Error(t, formatted, "Formatted error should not be nil")
242
243 errMsg := formatted.Error()
244 for _, part := range tt.expectedParts {
245 assert.Contains(t, errMsg, part, "Error message should contain: %s", part)
246 }
247
248 // Verify multiline format
249 assert.Contains(t, errMsg, "\n", "Error should be multiline")
250
251 // Verify indentation is present (agent-friendly formatting)
252 assert.Contains(t, errMsg, " ↳", "Error should use indented arrows")
253 })
254 }
255}
256
257// TestImportCycleError_InvalidChain tests handling of invalid cycle chains
258func TestImportCycleError_InvalidChain(t *testing.T) {

Callers

nothing calls this directly

Calls 3

FormatImportCycleErrorFunction · 0.92
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected