Skip to content

fix(pre-commit): add go build gate for staged Go changes (#1770) - #2303

Merged
HongmingWang-Rabbit merged 1 commit into
stagingfrom
auto/issue-1770-pre-commit-go-build
Apr 29, 2026
Merged

HongmingWang-Rabbit merged 1 commit into
stagingfrom
auto/issue-1770-pre-commit-go-build

Conversation

@HongmingWang-Rabbit

Copy link
Copy Markdown
Contributor

Summary

Adds a go build ./... check to .githooks/pre-commit that runs whenever a .go file in workspace-server/ is staged. Rejects the commit if the build fails.

Why

Per #1770: bot agents have produced syntactically-broken Go that the patch tool applied (PR #1769 nested a function declaration inside another function's body). Staging Platform(Go) was red for hours; every Go PR targeting staging during that window failed CI through no fault of its own.

This is the pre-commit guard half of the three guards proposed in #1770. Skip-with-warning when go isn't installed (so CI runners and bots without go bypass cleanly).

Test plan

  • bash -n .githooks/pre-commit — shell syntax valid
  • cd workspace-server && go build ./... on current main — passes (no false positive)
  • Manual: introduce a syntax error to a staged Go file, attempt commit, confirm rejection
  • Manual: verify cost on a warm cache (~5-10s expected)

What this PR does NOT do

  • Branch-protection: make Platform (Go) a required check on staging — admin action, needs your settings change. Currently the job runs but isn't required, so a Lead override could still merge a red PR.
  • SHARED_RULES clarification — process change, lives in some other doc/repo.

These are tracked in #1770 as separate guards; this PR closes only the pre-commit guard half. The issue stays open for the other two.

🤖 Generated with Claude Code

Catches the bot-generated-structurally-invalid-Go class that took
staging Platform(Go) red for hours on 2026-04-22 (PR #1769 commit
66ea0b6 nested a function declaration inside another function's body).
The patch tool applied it; the Go parser rejected it; every Go PR
targeting staging during the window failed CI through no fault of its
own.

Hook now runs `cd workspace-server && go build ./...` when any .go
file in workspace-server/ is staged. If the build fails, commit is
rejected with the first 20 lines of build output. Skip-with-warning
when go isn't installed (CI runners + bots without go bypass cleanly).

Cost: ~5-10s per commit that touches Go on a warm cache. Acceptable
for the class of bug it catches — the alternative (catch at PR-time
via CI) is too late, the malformed commit is already shared.

This is one of the three guards proposed in #1770. The other two
(branch-protection on `Platform (Go)` as required check; SHARED_RULES
clarification on bot-PR overrides) are admin / process changes that
need your action.

Closes the pre-commit half of #1770. Branch-protection + SHARED_RULES
work tracks separately.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@HongmingWang-Rabbit
HongmingWang-Rabbit added this pull request to the merge queue Apr 29, 2026
Merged via the queue into staging with commit c219168 Apr 29, 2026
20 checks passed
@HongmingWang-Rabbit
HongmingWang-Rabbit deleted the auto/issue-1770-pre-commit-go-build branch April 29, 2026 18:06
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