Skip to content

feat: Implement GitHub Action outputs and golden tests#12

Merged
pfrederiksen merged 2 commits intomainfrom
feat/pr-review-fixes
Jan 17, 2026
Merged

feat: Implement GitHub Action outputs and golden tests#12
pfrederiksen merged 2 commits intomainfrom
feat/pr-review-fixes

Conversation

@pfrederiksen
Copy link
Copy Markdown
Owner

Summary

This PR addresses the remaining issues from PR #11 review:

  • Issue 3: Fully implement GitHub Action outputs (has-changes, diff-output)
  • Issue 4: Add golden tests for new output formats (stat, side-by-side, git-diff)

Changes

GitHub Actions Integration

  • Added writeGitHubOutputs() function to write outputs in GitHub Actions format
  • Detects GITHUB_OUTPUT environment variable automatically
  • Outputs has-changes as boolean (true/false)
  • Outputs diff-output using heredoc format for multiline content
  • Added comprehensive tests including append behavior verification

Golden Tests

  • Converted TestGenerateStat to use golden files (4 test cases)
  • Converted TestGenerateSideBySide to use golden files (5 test cases)
  • Converted TestGenerateGitDiff to use golden files (5 test cases)
  • All golden files generated in testdata/report/
  • Tests support -update flag to regenerate golden files

Bug Fixes

  • Fixed variable redeclaration error in compareFiles()

Test Results

All tests passing with good coverage:

  • cmd/configdiff: 67.7% coverage
  • report: 90.9% coverage

Related

Addresses review comments from #11 before merging and releasing v0.3.0.

🤖 Generated with Claude Code

Add GitHub Actions integration with has-changes and diff-output outputs.
Convert output format tests to use golden files for better maintainability.

Changes:
- Add writeGitHubOutputs() to write GitHub Actions outputs
- Detect GITHUB_OUTPUT env var and write outputs in correct format
- Convert TestGenerateStat to golden file tests (4 test cases)
- Convert TestGenerateSideBySide to golden file tests (5 test cases)
- Convert TestGenerateGitDiff to golden file tests (5 test cases)
- Add comprehensive tests for GitHub Actions output functionality
- Fix variable redeclaration in compareFiles()

Addresses PR review comments from #11:
- Issue 3: GitHub Action outputs now fully implemented
- Issue 4: Golden tests added for all new output formats

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@claude
Copy link
Copy Markdown

claude bot commented Jan 17, 2026

Code Review

I found 1 issue that should be addressed:

Heredoc Delimiter Injection Vulnerability in GitHub Actions Output

File: cmd/configdiff/compare.go:283-285

The heredoc format uses a fixed EOF delimiter which creates a potential injection vulnerability. If diffOutput contains a line with just EOF (which is plausible since config files can contain arbitrary string values), the heredoc will terminate prematurely, causing:

  1. Output corruption: The rest of the diff content would be interpreted as GitHub Actions workflow commands
  2. Output injection: A malicious config file could inject arbitrary outputs affecting subsequent workflow steps

For example, a config file containing:

value: |
  Some text
  EOF
  injected-output=malicious

Recommended fix: Use a randomized delimiter that cannot appear in the content:

delimiter := fmt.Sprintf("ghadelimiter_%d", rand.Int63())
if _, err := fmt.Fprintf(f, "diff-output<<%s\n%s\n%s\n", delimiter, diffOutput, delimiter); err \!= nil {
    return err
}

See GitHub's documentation on multiline strings for more details.


Reference:

// Write diff-output using heredoc format
if _, err := fmt.Fprintf(f, "diff-output<<EOF\n%s\nEOF\n", diffOutput); err != nil {
return err
}

Fix heredoc delimiter injection vulnerability by using a cryptographically
random delimiter instead of fixed "EOF" string.

Security issue: A config file containing "EOF" on its own line could
prematurely terminate the heredoc and potentially inject arbitrary
GitHub Actions workflow commands.

Changes:
- Generate random 16-byte delimiter prefixed with "ghadelimiter_"
- Update tests to verify random delimiter format
- Add test case specifically for EOF injection attack
- Add reference to GitHub Actions multiline string documentation

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@pfrederiksen pfrederiksen merged commit d51f8f0 into main Jan 17, 2026
6 checks passed
@pfrederiksen pfrederiksen deleted the feat/pr-review-fixes branch January 17, 2026 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant