Also output resolved paths for symlinks#92
Merged
Merged
Conversation
Reviewer's GuideThis PR enhances link output by including resolved symlink paths in both runtime logging and test expectations by conditionally appending the original and resolved paths. Sequence diagram for enhanced symlink resolution in link loggingsequenceDiagram
participant "link()"
participant "filepath.EvalSymlinks"
participant "log.Default()"
"link()"->>"filepath.EvalSymlinks": Resolve sourcePath
"link()"->>"log.Default()": Print operation with original and resolved sourcePath if different
Sequence diagram for test output generation with resolved symlink pathssequenceDiagram
participant "generateOutput()"
participant "filepath.EvalSymlinks"
participant "TestCase"
"generateOutput()"->>"filepath.EvalSymlinks": Resolve lib path
"generateOutput()"->>"TestCase": Append lib (resolved) -> destination to ExpectedStdout
Class diagram for updated symlink and path resolution logicclassDiagram
class TestDetails {
+string Path
+bool Symlink
+BinDetails Bin
+string SnagTo
+string SnagAs
}
class BinDetails {
+ElfDetails Elf
+bool HasInterpreter
}
class ElfDetails {
+string Path
+string Interpreter
+[]string Dependencies
}
class TestCase {
+[]string ExpectedStdout
+map[string]string ExpectedFiles
+string Dest
}
TestDetails --> BinDetails
BinDetails --> ElfDetails
TestCase --> TestDetails
class Paths {
+const P_ld_linux
+var P_ld_linux_resolved
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #92 +/- ##
==========================================
- Coverage 73.39% 72.94% -0.45%
==========================================
Files 12 12
Lines 639 658 +19
==========================================
+ Hits 469 480 +11
- Misses 117 123 +6
- Partials 53 55 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `internal/paths.go:14` </location>
<code_context>
// Path to interpreter
const P_ld_linux = "/lib64/ld-linux-x86-64.so.2"
+var P_ld_linux_resolved, _ = filepath.EvalSymlinks(P_ld_linux)
+
// Paths to common libraries
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider handling errors from EvalSymlinks when initializing P_ld_linux_resolved.
Explicitly handling the EvalSymlinks error will help avoid silent failures and improve reliability. Consider logging the error or falling back to P_ld_linux if resolution fails.
Suggested implementation:
```golang
var P_ld_linux_resolved = resolveLdLinux()
func resolveLdLinux() string {
resolved, err := filepath.EvalSymlinks(P_ld_linux)
if err != nil {
// Log the error and fall back to the original path
fmt.Fprintf(os.Stderr, "Warning: failed to resolve symlink for %s: %v\n", P_ld_linux, err)
return P_ld_linux
}
return resolved
}
```
You will need to import the "fmt" and "os" packages at the top of the file if they are not already imported:
```go
import (
"fmt"
"os"
"path/filepath"
)
```
</issue_to_address>
### Comment 2
<location> `internal/testing/testiterator.go:227` </location>
<code_context>
func generateOutput(bin TestDetails, tc *TestCase, inplace bool) {
if !inplace {
snaggedBin := filepath.Join(tc.Dest, bin.SnagTo, bin.SnagAs)
</code_context>
<issue_to_address>
**issue (complexity):** Consider extracting the repeated mapping logic into a helper function to simplify generateOutput.
```go
// helper to reduce duplication in generateOutput
func formatMapping(src, hint, dest string) string {
if hint != "" && hint != src {
return fmt.Sprintf("%s (%s) -> %s", src, hint, dest)
}
return fmt.Sprintf("%s -> %s", src, dest)
}
func generateOutput(bin TestDetails, tc *TestCase, inplace bool) {
if !inplace {
snagged := filepath.Join(tc.Dest, bin.SnagTo, bin.SnagAs)
hint := ""
if bin.Symlink {
hint = bin.Bin.Elf.Path
}
tc.ExpectedStdout = append(tc.ExpectedStdout,
formatMapping(bin.Path, hint, snagged),
)
tc.ExpectedFiles[bin.Path] = snagged
}
if bin.Bin.HasInterpreter {
snagged := filepath.Join(tc.Dest, bin.Bin.Elf.Interpreter)
hint := P_ld_linux_resolved
if P_ld_linux == P_ld_linux_resolved {
hint = ""
}
tc.ExpectedStdout = append(tc.ExpectedStdout,
formatMapping(bin.Bin.Elf.Interpreter, hint, snagged),
)
tc.ExpectedFiles[bin.Bin.Elf.Interpreter] = snagged
}
for _, lib := range bin.Bin.Elf.Dependencies {
snagged := filepath.Join(tc.Dest, "lib64", filepath.Base(lib))
resolved, _ := filepath.EvalSymlinks(lib)
hint := resolved
if lib == resolved {
hint = ""
}
tc.ExpectedStdout = append(tc.ExpectedStdout,
formatMapping(lib, hint, snagged),
)
tc.ExpectedFiles[lib] = snagged
}
}
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
Summary by Sourcery
Display resolved filesystem paths for symlinks in output logs and test expectations.
Enhancements:
Chores: