Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix: guard PR field assignment on ref shape, not just event name

Cursor Agent5c8c9b6c9b46
diff --git a/cli/beacon/internal/ci/session.go b/cli/beacon/internal/ci/session.go
index 45157458..04e9e98c 100644
--- a/cli/beacon/internal/ci/session.go
+++ b/cli/beacon/internal/ci/session.go
@@ -316,12 +316,15 @@ func detectRunInfo() *schema.RunInfo {
} else {
info.Branch = os.Getenv("GITHUB_REF_NAME")
}
- // GITHUB_REF is a non-PR ref (e.g. refs/heads/main) on push events, so
- // only record PR fields when the trigger is actually a pull request.
+ // Only populate PR fields when the ref is actually a pull-request ref.
+ // pull_request_target sets GITHUB_REF to the base branch, not the
+ // merge ref, so we guard on the ref shape rather than just the event.
if isPullRequestEvent(eventName) {
ref := os.Getenv("GITHUB_REF")
- info.PR = ref
- info.PRNumber = parsePRNumber(ref)
+ if strings.HasPrefix(ref, "refs/pull/") {
+ info.PR = ref
+ info.PRNumber = parsePRNumber(ref)
+ }
}
return info
}
diff --git a/cli/beacon/internal/ci/session_test.go b/cli/beacon/internal/ci/session_test.go
index 405b84b5..bfbd7eca 100644
--- a/cli/beacon/internal/ci/session_test.go
+++ b/cli/beacon/internal/ci/session_test.go
@@ -171,6 +171,26 @@ func TestDetectRunInfoPullRequest(t *testing.T) {
}
}
+func TestDetectRunInfoPullRequestTargetOmitsPR(t *testing.T) {
+ t.Setenv("CI", "true")
+ t.Setenv("GITHUB_ACTIONS", "true")
+ t.Setenv("GITHUB_EVENT_NAME", "pull_request_target")
+ t.Setenv("GITHUB_HEAD_REF", "feature/telemetry")
+ t.Setenv("GITHUB_REF_NAME", "main")
+ t.Setenv("GITHUB_REF", "refs/heads/main")
+
+ info := detectRunInfo()
+ if info == nil {
+ t.Fatal("detectRunInfo returned nil in GitHub Actions")
+ }
+ if info.Branch != "feature/telemetry" {
+ t.Fatalf("Branch = %q, want PR head ref", info.Branch)
+ }
+ if info.PR != "" || info.PRNumber != "" {
+ t.Fatalf("pull_request_target with base-branch ref should not record PR fields: PR=%q PRNumber=%q", info.PR, info.PRNumber)
+ }
+}
+
func TestDetectRunInfoPushOmitsPR(t *testing.T) {
t.Setenv("CI", "true")
t.Setenv("GITHUB_ACTIONS", "true")