Skip to content

prefix stdout with link/copy#86

Merged
MusicalNinjaDad merged 6 commits into
mainfrom
44_stdout
Nov 1, 2025
Merged

prefix stdout with link/copy#86
MusicalNinjaDad merged 6 commits into
mainfrom
44_stdout

Conversation

@MusicalNinjaDad

@MusicalNinjaDad MusicalNinjaDad commented Nov 1, 2025

Copy link
Copy Markdown
Owner

Summary by Sourcery

Prefix stdout messages of file operations with operation type and update tests to assert on these prefixes using a new AssertStdout helper.

New Features:

  • Add AssertStdout helper to verify operation prefixes in test output

Enhancements:

  • Prefix file operation logs with "link" or "copy" to indicate the action taken

Tests:

  • Replace raw stdout assertions with AssertStdout across unit tests
  • Add assertion in TestCommonBinaries to ensure linked files are prefixed with "link"

@MusicalNinjaDad MusicalNinjaDad linked an issue Nov 1, 2025 that may be closed by this pull request
@sourcery-ai

sourcery-ai Bot commented Nov 1, 2025

Copy link
Copy Markdown

Reviewer's Guide

This PR adds explicit operation prefixes (“link” or “copy”) to both test assertions and runtime log output by introducing a new AssertStdout helper, updating existing tests to use it and enforce prefix expectations, and modifying the link function to emit the correct operation in its log messages.

Class diagram for new AssertStdout helper and link function changes

classDiagram
    class AssertStdout {
        +AssertStdout(t *testing.T, expected []string, actual []string)
    }
    class Link {
        +link(sourcePath string, targetDir string) error
        -op string
    }
    AssertStdout <.. TestCases : used by
    Link <.. log.Default : logs operation
    Link <.. internal.Copy : calls
    Link <.. internal.SameFile : calls
Loading

File-Level Changes

Change Details Files
Introduce AssertStdout helper in test utilities
  • Add AssertStdout function to validate and strip “link”/“copy” prefixes
  • Iterate over actual output lines, assert prefix presence, and strip first 5 characters
  • Compare stripped lines against expected values
internal/testing/testdata.go
Update snaggle tests to use AssertStdout and enforce link prefix
  • Replace Assert.ElementsMatch calls with AssertStdout
  • Add loop to assert any line containing tc.Elf.Path starts with “link ”
snaggle_test.go
Adopt AssertStdout in CLI test suite
  • Replace Assert.ElementsMatch with AssertStdout in cli tests
cmd/snaggle/cli_test.go
Prefix log output with actual operation type
  • Introduce op variable initialized to “link”
  • Set op to “copy” when falling back on copy
  • Prepend op to log.Default().Println output
snaggle.go

Assessment against linked issues

Issue Objective Addressed Explanation
#44 Show in stdout when source is a symlink: originalSource (actualPath) -> target The PR does not add logic to display the actual path when the source is a symlink; it only prefixes stdout with 'link' or 'copy'.
#44 When target is relative, show absolute path or prefix with '.' The PR does not modify stdout to show absolute paths or prefix with '.' when the target is relative.
#44 Let user know whether linking or copying each file in stdout

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • The AssertStdout helper slices the first 5 characters to strip the prefix but only checks HasPrefix("copy") or HasPrefix("link"); it should validate "copy " and "link " (with the space) and adjust the slice accordingly to avoid off-by-one errors.
  • The assertion error message references "line" instead of "link"—update it to mention the correct prefix.
  • Consider defining constants for the "copy " and "link " prefixes to avoid hardcoding the length and make future changes safer.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The AssertStdout helper slices the first 5 characters to strip the prefix but only checks HasPrefix("copy") or HasPrefix("link"); it should validate "copy " and "link " (with the space) and adjust the slice accordingly to avoid off-by-one errors.
- The assertion error message references "line" instead of "link"—update it to mention the correct prefix.
- Consider defining constants for the "copy " and "link " prefixes to avoid hardcoding the length and make future changes safer.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov

codecov Bot commented Nov 1, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.56%. Comparing base (aac398e) to head (6d7202f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #86      +/-   ##
==========================================
+ Coverage   74.02%   74.56%   +0.53%     
==========================================
  Files          11       11              
  Lines         566      578      +12     
==========================================
+ Hits          419      431      +12     
  Misses        104      104              
  Partials       43       43              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MusicalNinjaDad MusicalNinjaDad linked an issue Nov 1, 2025 that may be closed by this pull request
@MusicalNinjaDad MusicalNinjaDad enabled auto-merge (squash) November 1, 2025 10:54
@MusicalNinjaDad MusicalNinjaDad merged commit 7027441 into main Nov 1, 2025
11 checks passed
@MusicalNinjaDad MusicalNinjaDad deleted the 44_stdout branch November 1, 2025 10:55
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.

let user know whether linking or copying each

1 participant