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)
| 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 |
| 67 | func 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 := `--- |
| 73 | imports: |
| 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 := `--- |
| 83 | imports: |
| 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 := `--- |
| 93 | imports: |
| 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 := `--- |
| 103 | imports: |
| 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") |
nothing calls this directly
no test coverage detected