Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pkg/cli/frontmatter_formatting_test.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@ import (

// TestFormattingPreservation tests that frontmatter operations preserve comments, blank lines, and formatting
func TestFormattingPreservation(t *testing.T) {
t.Parallel()
originalContent := `---
on:
workflow_dispatch:
Expand All@@ -30,6 +31,7 @@ engine: claude
This is test content.`

t.Run("RemoveFieldFromOnTrigger preserves formatting", func(t *testing.T) {
t.Parallel()
result, err := RemoveFieldFromOnTrigger(originalContent, "stop-after")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
Expand DownExpand Up@@ -68,6 +70,7 @@ This is test content.`
})

t.Run("SetFieldInOnTrigger preserves formatting", func(t *testing.T) {
t.Parallel()
result, err := SetFieldInOnTrigger(originalContent, "stop-after", "+72h")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
Expand DownExpand Up@@ -106,6 +109,7 @@ This is test content.`
})

t.Run("UpdateFieldInFrontmatter preserves formatting", func(t *testing.T) {
t.Parallel()
result, err := UpdateFieldInFrontmatter(originalContent, "source", "test/repo@v1.0.0")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
Expand DownExpand Up@@ -147,7 +151,9 @@ This is test content.`
//
// was updated to engine: copilot but the child " id: claude" line remained, producing invalid YAML.
func TestUpdateFieldInFrontmatterBlockMapping(t *testing.T) {
t.Parallel()
t.Run("replace block-mapped engine with scalar value removes child lines", func(t *testing.T) {
t.Parallel()
content := `---
engine:
id: claude
Expand DownExpand Up@@ -182,6 +188,7 @@ permissions:
})

t.Run("replace block-mapped engine with deeper nesting removes all child lines", func(t *testing.T) {
t.Parallel()
content := `---
engine:
id: claude
Expand DownExpand Up@@ -211,6 +218,7 @@ source: owner/repo/workflow.md@main
})

t.Run("replace scalar engine still works correctly", func(t *testing.T) {
t.Parallel()
content := `---
engine: claude
permissions:
Expand All@@ -236,6 +244,7 @@ permissions:
})

t.Run("update preserves nested fields with same name", func(t *testing.T) {
t.Parallel()
content := `---
steps:
- name: test
Expand DownExpand Up@@ -265,7 +274,9 @@ source: owner/repo/workflow.md@old

// TestRemoveFieldFromOnTriggerEdgeCases tests edge cases for field removal
func TestRemoveFieldFromOnTriggerEdgeCases(t *testing.T) {
t.Parallel()
t.Run("remove field that doesn't exist", func(t *testing.T) {
t.Parallel()
content := `---
on:
issues:
Expand All@@ -286,6 +297,7 @@ permissions:
})

t.Run("remove field from workflow without on block", func(t *testing.T) {
t.Parallel()
content := `---
permissions:
contents: read
Expand All@@ -303,6 +315,7 @@ permissions:
})

t.Run("field with similar prefix should not match", func(t *testing.T) {
t.Parallel()
content := `---
on:
workflow_dispatch:
Expand All@@ -326,6 +339,7 @@ on:
})

t.Run("on with inline value should not be treated as block", func(t *testing.T) {
t.Parallel()
content := `---
on: push
permissions:
Expand All@@ -344,6 +358,7 @@ permissions:
})

t.Run("multiline field value should be fully removed", func(t *testing.T) {
t.Parallel()
content := `---
on:
workflow_dispatch:
Expand DownExpand Up@@ -373,6 +388,7 @@ on:
})

t.Run("inline comment with multiple colons should be preserved", func(t *testing.T) {
t.Parallel()
content := `---
on:
workflow_dispatch:
Expand Down
7 changes: 7 additions & 0 deletions pkg/cli/grant_test.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@ import (
)

func TestGrantDisplayFindings_NilOutput(t *testing.T) {
t.Parallel()
count, err := grantDisplayFindings("test-image:latest", nil)
if err != nil {
t.Fatalf("Expected no error for nil output, got: %v", err)
Expand All@@ -22,6 +23,7 @@ func TestGrantDisplayFindings_NilOutput(t *testing.T) {
}

func TestGrantDisplayFindings_WithDeniedPackages(t *testing.T) {
t.Parallel()
output := &grantOutput{}
output.Run.Targets = []grantTargetResult{
{
Expand DownExpand Up@@ -62,13 +64,15 @@ func TestGrantDisplayFindings_WithDeniedPackages(t *testing.T) {
}

func TestRunGrantOnLockFiles_NoLockFiles(t *testing.T) {
t.Parallel()
err := runGrantOnLockFiles([]string{}, false, false)
if err != nil {
t.Errorf("Expected no error for empty lock file list, got: %v", err)
}
}

func TestGrantPolicyFile(t *testing.T) {
t.Parallel()
policyFile, err := grantPolicyFile()
if err != nil {
t.Fatalf("Expected grant policy file, got: %v", err)
Expand All@@ -79,6 +83,7 @@ func TestGrantPolicyFile(t *testing.T) {
}

func TestGrantRunOnImageRejectsInvalidImageRef(t *testing.T) {
t.Parallel()
tmpDir := t.TempDir()
policyFile := filepath.Join(tmpDir, "policy.yaml")
require.NoError(t, os.WriteFile(policyFile, []byte("policy: true\n"), 0o644))
Expand All@@ -97,6 +102,7 @@ func TestGrantRunOnImageRejectsInvalidImageRef(t *testing.T) {

for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
_, err := grantRunOnImage(tt.imageRef, policyFile, false)
require.Error(t, err)
require.ErrorContains(t, err, tt.want)
Expand All@@ -105,6 +111,7 @@ func TestGrantRunOnImageRejectsInvalidImageRef(t *testing.T) {
}

func TestGrantRunOnImageVerboseCommandEscapesImageRef(t *testing.T) {
t.Parallel()
tmpDir := t.TempDir()
policyFile := filepath.Join(tmpDir, "policy file.yaml")
require.NoError(t, os.WriteFile(policyFile, []byte("policy: true\n"), 0o644))
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/help_text_test.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,6 +8,7 @@ import (
)

func TestWorkflowIDExplanation(t *testing.T) {
t.Parallel()
// Test that the constant is not empty
if WorkflowIDExplanation == "" {
t.Error("WorkflowIDExplanation should not be empty")
Expand Down
3 changes: 3 additions & 0 deletions pkg/cli/helpers_json_test.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,14 +10,17 @@ import (
)

func TestMarshalIndentJSONOrWrap(t *testing.T) {
t.Parallel()
t.Run("marshals value as indented JSON", func(t *testing.T) {
t.Parallel()
data, err := marshalIndentJSONOrWrap(map[string]string{"a": "b"}, "test value")
require.NoError(t, err)
assert.JSONEq(t, `{"a":"b"}`, string(data))
assert.Contains(t, string(data), "\n \"a\"", "output should be indented with two spaces")
})

t.Run("wraps error with context", func(t *testing.T) {
t.Parallel()
_, err := marshalIndentJSONOrWrap(make(chan int), "test value")
require.Error(t, err)
assert.Contains(t, err.Error(), "failed to marshal test value to JSON")
Expand Down
4 changes: 4 additions & 0 deletions pkg/cli/importpath_test.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,6 +15,7 @@ import (
// workflowspec paths are returned unchanged, "/" prefix paths become repo-relative
// strings, and relative paths are cleaned and forward-slash normalised.
func TestResolveImportPath_ImportsOpts(t *testing.T) {
t.Parallel()
tmpDir := t.TempDir()
workflowDir := filepath.ToSlash(filepath.Join(tmpDir, "workflows"))

Expand DownExpand Up@@ -58,6 +59,7 @@ func TestResolveImportPath_ImportsOpts(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
result := resolveImportPath(tt.importPath, workflowDir, opts)
assert.Equal(t, tt.expected, result,
"resolveImportPath(%q, %q, importsOpts) = %q", tt.importPath, workflowDir, result)
Expand All@@ -69,6 +71,7 @@ func TestResolveImportPath_ImportsOpts(t *testing.T) {
// section refs are stripped, workflowspec paths return "", and relative paths are
// joined with baseDir.
func TestResolveImportPath_RunPushOpts(t *testing.T) {
t.Parallel()
tmpDir := t.TempDir()
baseDir := filepath.Join(tmpDir, "workflows")
require.NoError(t, os.MkdirAll(baseDir, 0755))
Expand DownExpand Up@@ -107,6 +110,7 @@ func TestResolveImportPath_RunPushOpts(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
result := resolveImportPath(tt.importPath, baseDir, opts)
assert.Equal(t, tt.expected, result,
"resolveImportPath(%q, %q, runPushOpts) = %q", tt.importPath, baseDir, result)
Expand Down
Loading