Skip to content

build: share the Go build cache across worktrees with -trimpath - #765

Closed
EricAndrechek wants to merge 4 commits into
lint/markdown-mdx-parserfrom
build/trimpath
Closed

EricAndrechek wants to merge 4 commits into
lint/markdown-mdx-parserfrom
build/trimpath

Conversation

@EricAndrechek

@EricAndrechek EricAndrechek commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Summary

Go keys this module's own packages in the build cache by absolute directory, so every worktree compiled and cached its own copy of each variant (normal, test, -race, -cover -coverpkg=./...), and Go only evicts entries unused for five days. -trimpath makes the entries path-independent.

  • Makefile. Exports GOFLAGS=-trimpath, keeping any GOFLAGS the caller passes (also when given on the make command line). A GOFLAGS that already names -trimpath is left alone, so sub-makes don't prepend it again and GOFLAGS=-trimpath=false make … opts out. CI runs the same targets and inherits it. No workflow or .goreleaser.yaml change: they have no direct go build/go test calls that matter here, and release-build paths are build: add -trimpath to release, container, and goreleaser builds #537.
  • Path anchors. natstest.repoFile walks up from the working directory to go.mod, because tests in several packages import it. The roles integration test builds the binary from two levels above its package directory, which is where go test runs it. Nothing else uses runtime.Caller; debug.Stack in internal/api/router.go only feeds a log field.
  • Debugging. make build's debug binary is exempt (scripts/build.sh passes -trimpath=false) and keeps absolute source paths for Delve. Other binaries are trimmed and need a source-path substitution; development.md has the dlv example.

Test plan

  • go test -trimpath -count=1 ./internal/mq/... passes.
  • go test -trimpath -tags integration -run TestRoles ./tests/integration/ passes (72s).
  • make test-unit passes under the new flags and writes its profile; the profile names files by import path, and gocover-cobertura over it emits repo-relative filenames that all exist.
  • make verify passes.
  • Cache sharing, counting compile steps of go test -c -x ./internal/api in a second checkout of the same commit: 0 with -trimpath, 23 without.
  • A recursive make probe shows GOFLAGS stable at depth 0, 1 and 2 with it unset, in the environment, on the command line, and set to -trimpath=false.
  • make build's binary has absolute source paths; make build-release's has none.
  • make ci (run before pushing).

Related Issues

Closes #763. Related: #537 (-trimpath for release builds). Stacked on #760 (base lint/markdown-mdx-parser); contains the whole stack below it and today's main. Part of #740.

🤖 Generated with Claude Code

EricAndrechek and others added 4 commits October 7, 2026 16:10
Go keys this module's own packages in the build cache by absolute
directory, so every worktree compiled and cached its own copy of each
variant (normal, test, -race, -cover). The Makefile now exports
GOFLAGS=-trimpath, keeping any GOFLAGS the caller passes; CI runs the
same targets and inherits it.

The two tests that located repository files with runtime.Caller, whose
path is module-relative under -trimpath, now find the root from the
working directory: natstest walks up to go.mod, and the roles test builds
from two levels above its package directory.

Closes #763. Part of #740.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Guard the Makefile prepend so recursive makes and callers that already
name -trimpath do not stack it, and -trimpath=false opts out. The debug
build passes -trimpath=false so debuggers find absolute source paths.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 262b1468-01b8-4cd1-afd9-c25f6dcc3883
📥 Commits

Reviewing files that changed from the base of the PR and between a31340d and 8b04490.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • Makefile
  • docs/src/content/docs/development.md
  • internal/mq/natstest/natstest.go
  • scripts/build.sh
  • tests/integration/roles_test.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📜 Recent review details
🧰 Additional context used
📚 Code guidelines (3)
AGENTS.md — auto-discovered
docs/src/content/docs/development.md — auto-discovered
CONTRIBUTING.md — auto-discovered
📓 Path-based instructions (8)
Source excerpt: **Never hand-write `®` or `™` in prose.**

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • docs/src/content/docs/development.md
Source excerpt: **Integration test needing Docker** → add a subtest under `tests/integration/` (e.g.

📄 CodeRabbit inference engine (docs/src/content/docs/development.md)

Files:

  • tests/integration/roles_test.go
Source excerpt: Create `*_test.go` files in the same package as the code under test.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • tests/integration/roles_test.go
Source excerpt: Create the package under `internal/`.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • internal/mq/natstest/natstest.go
Source excerpt: **WH001 applies to every tracked Markdown file, with no carve-out** — `AGENTS.md`, `CHANGELOG.md`, `.github/` CI docs and `.claude/` agent prompts included.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • docs/src/content/docs/development.md
  • CHANGELOG.md
Source excerpt: **Strict Go formatting**: Use `gofumpt` (a stricter superset of `gofmt`, enforced by CI).

📄 CodeRabbit inference engine (docs/src/content/docs/development.md)

Files:

  • tests/integration/roles_test.go
  • internal/mq/natstest/natstest.go
Source excerpt: **Docs prose**: never hard-wrap Markdown — one paragraph is one line.

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Files:

  • docs/src/content/docs/development.md
  • CHANGELOG.md
Source excerpt: Run `make fix` to apply them.

📄 CodeRabbit inference engine (docs/src/content/docs/development.md)

Files:

  • docs/src/content/docs/development.md
  • CHANGELOG.md
🪛 LanguageTool
CHANGELOG.md

[typographical] ~54-~54: Consider using an em dash in dialogues and enumerations.
Context: - Worktrees share the Go build cache ...

(DASH_RULE)


[style] ~54-~54: Since ownership is already implied, this phrasing may be redundant.
Context: ...ory, so every worktree built and cached its own copy of each variant (normal, test, `-r...

(PRP_OWN)


📝 Summary

Summary by CodeRabbit

  • Changed
    • Go builds now share cached packages across worktrees when built from the same source and variant, which can reduce repeated build time.
    • Debug builds retain absolute source paths for easier debugging. You can disable path trimming for other builds with GOFLAGS=-trimpath=false.
  • Documentation
    • Updated the development guide with build-cache behavior, debugging details, and guidance for working with repository files.

Walkthrough

The Makefile now enables -trimpath by default while preserving supplied GOFLAGS. Test helpers locate repository files from the working directory. Debug builds disable trimming, and the development guide documents the behavior and configuration.

Changes

Go build path handling

Layer / File(s) Summary
Default trimming configuration
Makefile, CHANGELOG.md
The Makefile adds -trimpath unless supplied flags already contain it. The changelog records the change.
Working-directory repository paths
internal/mq/natstest/natstest.go, tests/integration/roles_test.go
The test helpers use the working directory to locate repository files instead of runtime.Caller paths.
Debug build path override
scripts/build.sh, docs/src/content/docs/development.md
Debug builds pass -trimpath=false. The development guide describes trimming, opt-out configuration, debugger path substitution, and repository file access.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Other · Severity of issue fixed: Medium

Suggested reviewers: taitelee

Merge Risk: ⚪ Minimal · up to 8b044

The reviewed build and test path changes show no concrete issue that should block merging.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR implements the coding requirements in #763. Makefile exports GOFLAGS with -trimpath while preserving caller flags and allowing -trimpath=false. internal/mq/natstest/natstest.go finds …
Out of Scope Changes check ✅ Passed The changes stay within #763. The Makefile and build-script changes apply the cache-sharing default and preserve debugger behavior. The two test changes remove compile-time path dependence. The docume…
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (3 skipped: 3 …
Title check ✅ Passed The title clearly and concisely describes the main change: sharing the Go build cache across worktrees by using -trimpath.
Description check ✅ Passed The description directly explains the -trimpath change, affected tests and build behavior, debugging considerations, and validation results.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
✨ Simplify code
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added documentation Improvements or additions to documentation go Pull requests that update go code area/docs Documentation, site/, README area/infra CI, build, deploy, Docker, release labels Oct 7, 2026
@EricAndrechek

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@EricAndrechek

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@EricAndrechek

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@EricAndrechek

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@EricAndrechek

Copy link
Copy Markdown
Member Author

Superseded by #793: the same change (identical diff, which CodeRabbit approved here) rebuilt directly on main so it no longer waits on #760.


— Posted by Claude Code on behalf of @EricAndrechek

EricAndrechek added a commit that referenced this pull request Oct 9, 2026
Go keys this module's own packages in the build cache by absolute
directory, so every worktree compiled and cached its own copy of each
variant (normal, test, `-race`, `-cover -coverpkg=./...`), and Go only
evicts entries unused for five days. `-trimpath` makes the entries
path-independent.

- **Makefile.** Exports `GOFLAGS=-trimpath`, keeping any `GOFLAGS` the
caller passes (also when given on the `make` command line). A `GOFLAGS`
that already names `-trimpath` is left alone, so sub-makes don't prepend
it again and `GOFLAGS=-trimpath=false make …` opts out. CI runs the same
targets and inherits it. No workflow or `.goreleaser.yaml` change: they
have no direct `go build`/`go test` calls that matter here, and
release-build paths are #537.
- **Path anchors.** `natstest.repoFile` walks up from the working
directory to `go.mod`, because tests in several packages import it. The
roles integration test builds the binary from two levels above its
package directory, which is where `go test` runs it. Nothing else uses
`runtime.Caller`; `debug.Stack` in `internal/api/router.go` only feeds a
log field.
- **Debugging.** `make build`'s debug binary is exempt
(`scripts/build.sh` passes `-trimpath=false`) and keeps absolute source
paths for Delve. Other binaries are trimmed and need a source-path
substitution; `development.md` has the `dlv` example.

## Test plan

This branch's diff is identical to #765's (same 6 files, +40/−11,
compared line by line), which CodeRabbit approved. Re-run here against
`main`: the pre-commit `make verify` and a full `make ci` (unit suite,
integration suite including `TestRoles`, and the builds). The three
measurement items below were measured on #765 and not repeated.

- [x] `go test -trimpath -count=1 ./internal/mq/...` passes (inside
`make ci`'s unit suite).
- [x] `go test -trimpath -tags integration -run TestRoles
./tests/integration/` passes (inside `make ci`'s integration suite).
- [x] `make test-unit` passes under the new flags (inside `make ci`).
The profile naming files by import path, and `gocover-cobertura`
emitting repo-relative filenames that all exist, were measured on #765.
- [x] `make verify` passes.
- [ ] (measured on #765) Cache sharing, counting `compile` steps of `go
test -c -x ./internal/api` in a second checkout of the same commit: 0
with `-trimpath`, 23 without.
- [ ] (measured on #765) A recursive make probe shows `GOFLAGS` stable
at depth 0, 1 and 2 with it unset, in the environment, on the command
line, and set to `-trimpath=false`.
- [ ] (measured on #765) `make build`'s binary has absolute source
paths; `make build-release`'s has none.
- [x] `make ci` passes.

## Related Issues

Closes #763. Related: #537 (`-trimpath` for release builds). Part of
#740. Supersedes #765 (rebuilt on `main`, no longer stacked on #760).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01Wjv2nu841pxTMdUWSAPmDH

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docs Documentation, site/, README area/infra CI, build, deploy, Docker, release documentation Improvements or additions to documentation go Pull requests that update go code

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant