TestFetchDispatchWorkflows_NoSourceConflict verifies that a file with no source field is treated as a conflict (unknown origin).
(t *testing.T)
| 1665 | // TestFetchDispatchWorkflows_NoSourceConflict verifies that a file with no source field |
| 1666 | // is treated as a conflict (unknown origin). |
| 1667 | func TestFetchDispatchWorkflows_NoSourceConflict(t *testing.T) { |
| 1668 | dir := t.TempDir() |
| 1669 | workflowsDir := dir |
| 1670 | |
| 1671 | // Pre-existing file with NO source field |
| 1672 | existingPath := filepath.Join(dir, "target-workflow.md") |
| 1673 | require.NoError(t, os.WriteFile(existingPath, []byte("# No source field\n"), 0644)) |
| 1674 | |
| 1675 | content := `--- |
| 1676 | safe-outputs: |
| 1677 | dispatch-workflow: |
| 1678 | workflows: |
| 1679 | - target-workflow |
| 1680 | --- |
| 1681 | # Main |
| 1682 | ` |
| 1683 | spec := &WorkflowSpec{ |
| 1684 | RepoSpec: RepoSpec{RepoSlug: "github/gh-aw", Version: "main"}, |
| 1685 | WorkflowPath: ".github/workflows/main.md", |
| 1686 | } |
| 1687 | |
| 1688 | err := fetchAndSaveRemoteDispatchWorkflows(context.Background(), content, spec, workflowsDir, false, false, nil) |
| 1689 | require.Error(t, err, "should error when existing file has no source field") |
| 1690 | assert.Contains(t, err.Error(), "target-workflow", "error should name the conflicting file") |
| 1691 | assert.Contains(t, err.Error(), "(no source field)", "error should show placeholder for missing source") |
| 1692 | } |
| 1693 | |
| 1694 | // TestFetchDispatchWorkflows_ForceOverwritesConflict verifies that --force bypasses conflict detection. |
| 1695 | func TestFetchDispatchWorkflows_ForceOverwritesConflict(t *testing.T) { |
nothing calls this directly
no test coverage detected