Skip to content

fix approved file lookup under -trimpath - #89

Draft
hownowstephen wants to merge 3 commits into
mainfrom
trimpath
Draft

hownowstephen wants to merge 3 commits into
mainfrom
trimpath

Conversation

@hownowstephen

@hownowstephen hownowstephen commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Under -trimpath, stack frame file paths are module-relative (github.com/org/mod/pkg/x_test.go), so approved files resolve to <pkg>/github.com/org/mod/pkg/.... Every approval misses, and received files are written there instead. This repo's own suite fails ~60 tests with GOFLAGS=-trimpath.

When the frame path isn't absolute, fall back to the working directory, since go test runs each package's tests from its source directory.

CI now also runs go test -trimpath ./... on stable Go for each OS. Older toolchains hit unrelated linker issues on current runners (macOS LC_UUID, Windows cgo with -race).

Known limitation: if a t.Run callback is defined in a helper package, approvals under -trimpath go to the calling test's package rather than next to the helper.

Summary by Sourcery

Ensure approval files resolve correctly under -trimpath and continuously verify this behavior in CI.

Bug Fixes:

  • Fix approved file lookup when tests run with Go's -trimpath option by resolving non-absolute stack frame paths from the package working directory.

CI:

  • Run the test suite with -trimpath on the stable Go version in CI.

@sourcery-ai

sourcery-ai Bot commented Oct 29, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The PR fixes approved-file lookup for -trimpath by resolving non-absolute frame paths against the package test working directory, and adds CI coverage to prevent regressions across the repository.

Sequence diagram for trimpath approval file resolution

sequenceDiagram
    participant Test as Go test
    participant Runtime as runtime.Callers
    participant Resolver as findFileName
    participant OS as os.Getwd
    participant Path as filepath.Join

    Test->>Runtime: capture stack frame
    Runtime-->>Resolver: lastFrame.File
    alt filepath.IsAbs(lastFrame.File)
        Resolver-->>Test: absolute frame path
    else non-absolute frame path
        Resolver->>OS: os.Getwd()
        OS-->>Resolver: package working directory
        Resolver->>Path: filepath.Base(lastFrame.File)
        Path-->>Resolver: base filename
        Resolver-->>Test: filepath.Join(wd, base filename)
    end
Loading

File-Level Changes

Change Details Files
Resolve non-absolute stack frame paths from the current package working directory under -trimpath.
  • Detect module-relative frame paths with filepath.IsAbs.
  • Use os.Getwd and join it with the frame basename before looking up approved files.
  • Propagate working-directory lookup errors.
stack_trace_namer.go
Add CI coverage for tests executed with -trimpath.
  • Run go test -trimpath ./... as a matrix test step.
.github/workflows/test.yml

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

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