Also snag interpreter#52
Merged
Merged
Conversation
Reviewer's GuideThis PR extends Snaggle’s behavior to link ELF interpreters, updates tests to account for interpreter linking, refines CI triggers, and introduces a Docker-based workflow for integration testing. Class diagram for updated Snaggle linking logicclassDiagram
class File {
+string Interpreter
+[]string Dependencies
}
class Snaggle {
+Snaggle(path string, root string) error
}
class errgroup_Group {
+Go(func() error)
}
File <.. Snaggle : uses
errgroup_Group <.. Snaggle : uses
Snaggle o-- File : reads
Snaggle o-- errgroup_Group : manages link tasks
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- Rather than inlining interpreter linking in two places, move that logic into your test case definitions to avoid duplication and make the tests cleaner.
- Before merging, address the “make linking interpreter safer” TODO by adding proper validation or abstraction around interpreter path handling.
- The new CI and docker workflows introduce a lot of duplication—consider consolidating build steps or merging them into a single workflow for maintainability.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Rather than inlining interpreter linking in two places, move that logic into your test case definitions to avoid duplication and make the tests cleaner.
- Before merging, address the “make linking interpreter safer” TODO by adding proper validation or abstraction around interpreter path handling.
- The new CI and docker workflows introduce a lot of duplication—consider consolidating build steps or merging them into a single workflow for maintainability.
## Individual Comments
### Comment 1
<location> `snaggle/cli_test.go:73-74` </location>
<code_context>
expectedOut := make([]string, 0, 1+len(tc.ExpectedElf.Dependencies))
expectedOut = append(expectedOut, tc.ExpectedElf.Path+" -> "+binPath)
+ // ugly - should be in the tc - needs a tidy
+ if tc.ExpectedElf.IsDyn() && !tc.ExpectedElf.IsLib() {
+ expectedOut = append(expectedOut, tc.ExpectedElf.Interpreter+" -> "+filepath.Join(tmp, P_ld_linux))
+ }
var libCopies []string
</code_context>
<issue_to_address>
**suggestion (testing):** No test for error conditions when interpreter linking fails.
Add a test case with an invalid interpreter path or failed linking to verify proper error handling.
Suggested implementation:
```golang
binPath := filepath.Join(tmp, "bin", filepath.Base(tc.ExpectedElf.Name))
expectedOut := make([]string, 0, 1+len(tc.ExpectedElf.Dependencies))
expectedOut = append(expectedOut, tc.ExpectedElf.Path+" -> "+binPath)
// ugly - should be in the tc - needs a tidy
if tc.ExpectedElf.IsDyn() && !tc.ExpectedElf.IsLib() {
expectedOut = append(expectedOut, tc.ExpectedElf.Interpreter+" -> "+filepath.Join(tmp, P_ld_linux))
}
var libCopies []string
for _, lib := range tc.ExpectedElf.Dependencies {
copy := filepath.Join(tmp, "lib64", filepath.Base(lib))
}
// Test error condition: interpreter linking fails
t.Run("interpreter linking fails", func(t *testing.T) {
invalidElf := tc.ExpectedElf
invalidElf.Interpreter = "/invalid/interpreter/path"
invalidElfDyn := invalidElf.IsDyn() && !invalidElf.IsLib()
if invalidElfDyn {
// Simulate the linking function, expecting an error
err := linkInterpreter(invalidElf.Interpreter, filepath.Join(tmp, P_ld_linux))
if err == nil {
t.Errorf("expected error when linking invalid interpreter, got nil")
}
}
})
```
- You must implement or mock the `linkInterpreter` function to simulate interpreter linking and error return for invalid paths.
- If your test table (`tc`) is outside this snippet, you may want to add a dedicated test case to it for more coverage.
- Adjust the error check to match your actual error handling logic if it differs.
</issue_to_address>
### Comment 2
<location> `snaggle_test.go:36-37` </location>
<code_context>
expectedOut := make([]string, 0, 1+len(tc.ExpectedElf.Dependencies))
expectedOut = append(expectedOut, tc.ExpectedElf.Path+" -> "+binPath)
+ // ugly - should be in the tc - needs a tidy
+ if tc.ExpectedElf.IsDyn() && !tc.ExpectedElf.IsLib() {
+ expectedOut = append(expectedOut, tc.ExpectedElf.Interpreter+" -> "+filepath.Join(tmp, P_ld_linux))
+ }
var libCopies []string
</code_context>
<issue_to_address>
**suggestion (testing):** Missing test for interpreter linking error scenarios.
Add a test case for scenarios where the interpreter is missing or fails to link, ensuring errors are handled and reported correctly.
Suggested implementation:
```golang
binPath := filepath.Join(tmp, "bin", filepath.Base(tc.ExpectedElf.Name))
expectedOut := make([]string, 0, 1+len(tc.ExpectedElf.Dependencies))
expectedOut = append(expectedOut, tc.ExpectedElf.Path+" -> "+binPath)
// TODO: #51 ugly - should be in the tc - needs a tidy
if tc.ExpectedElf.IsDyn() && !tc.ExpectedElf.IsLib() {
expectedOut = append(expectedOut, tc.ExpectedElf.Interpreter+" -> "+filepath.Join(tmp, P_ld_linux))
}
// Test interpreter missing/failure scenario
if tc.ExpectedElf.Interpreter == "" || tc.ExpectedElf.Interpreter == "missing" {
expectedErr := "interpreter missing or failed to link"
if err == nil || !strings.Contains(err.Error(), expectedErr) {
t.Errorf("expected error for missing interpreter, got: %v", err)
}
}
var libCopies []string
for _, lib := range tc.ExpectedElf.Dependencies {
copy := filepath.Join(tmp, "lib64", filepath.Base(lib))
```
You will also need to:
1. Add a test case to your test table (where `tc` is defined) with `ExpectedElf.Interpreter` set to `""` or `"missing"` to trigger this scenario.
2. Ensure that the test setup simulates the missing interpreter (e.g., by not creating the interpreter file or by setting the field appropriately).
3. Make sure the test logic sets `err` when the interpreter is missing, so the error assertion works.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #52 +/- ##
==========================================
+ Coverage 74.00% 74.13% +0.12%
==========================================
Files 5 5
Lines 404 406 +2
==========================================
+ Hits 299 301 +2
Misses 71 71
Partials 34 34 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #49
Summary by Sourcery
Enable snaggle to include the interpreter binary when present, adjust tests to verify interpreter linking, and enhance CI with targeted triggers and a Docker-based test workflow
New Features:
Enhancements:
CI:
Tests: