From ef1f420b15c9be49b0cb79732b771efd70857d3d Mon Sep 17 00:00:00 2001 From: Sutu Sebastian Date: Mon, 16 Nov 2026 16:54:32 +0200 Subject: [PATCH 1/5] fix(action): pin the composite action to the v0.7.0 release --- .changeset/action-pin-v070.md | 5 + README.md | 2 +- action.yml | 2 +- docs/manual.md | 2 +- examples/verdict-review.yml | 2 +- internal/archtest/action_pin_test.go | 168 +++++++++++++++++++++++++++ 6 files changed, 177 insertions(+), 4 deletions(-) create mode 100644 .changeset/action-pin-v070.md create mode 100644 internal/archtest/action_pin_test.go diff --git a/.changeset/action-pin-v070.md b/.changeset/action-pin-v070.md new file mode 100644 index 000000000..b2e862879 --- /dev/null +++ b/.changeset/action-pin-v070.md @@ -0,0 +1,5 @@ +--- +"@stainless-code/verdict": patch +--- + +Pin the composite Action and its example workflow to the v0.7.0 release commit, so Action users get the hardened installers. An archtest now fails on an "as introduced" self-pin or a stale release comment. diff --git a/README.md b/README.md index 3b20c4ccb..7f31bb0ce 100644 --- a/README.md +++ b/README.md @@ -194,7 +194,7 @@ never proxies your key; the agent contacts its model provider directly. `version` is required and accepts only pinned stable releases. Set the repository variable `VERDICT_VERSION` to a release containing `run --agent` before enabling -the workflow — the `v0.6.1` tag predates that command. The Action +the workflow — the `v0.7.0` tag is the first release with that command. The Action reuses `setup-verdict` for checksum and signature verification and exports the installed `version`. Pin the Action to a full commit SHA, as the example does. The Action owns fetch → ready → run → post → report → gate; `run` makes no diff --git a/action.yml b/action.yml index cf8ee8da9..ab1ba68b2 100644 --- a/action.yml +++ b/action.yml @@ -48,7 +48,7 @@ runs: [[ -n "$TOKEN" ]] || exit 2 - name: Install verdict id: install - uses: stainless-code/verdict/setup-verdict@471d2985b29060caa90036fefac565e97a12bb2c # action as introduced; re-pin to a release commit + uses: stainless-code/verdict/setup-verdict@b4c36344f03375985a8edf859b9092ba7d59f077 # v0.7.0 with: version: ${{ inputs.version }} diff --git a/docs/manual.md b/docs/manual.md index 29ec74efa..0f705f6b9 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -4700,7 +4700,7 @@ never proxies your key; the agent contacts its model provider directly. `version` is required and accepts only pinned stable releases. Set the repository variable `VERDICT_VERSION` to a release containing `run --agent` before enabling -the workflow — the `v0.6.1` tag predates that command. The Action +the workflow — the `v0.7.0` tag is the first release with that command. The Action reuses `setup-verdict` for checksum and signature verification and exports the installed `version`. Pin the Action to a full commit SHA, as the example does. The Action owns fetch → ready → run → post → report → gate; `run` makes no diff --git a/examples/verdict-review.yml b/examples/verdict-review.yml index d147d2060..01b8c9a4d 100644 --- a/examples/verdict-review.yml +++ b/examples/verdict-review.yml @@ -39,7 +39,7 @@ jobs: persist-credentials: false - name: Review and gate - uses: stainless-code/verdict@307677c5acf73f7ffd6932d7b8bf1885360d33af # composite action + uses: stainless-code/verdict@b4c36344f03375985a8edf859b9092ba7d59f077 # v0.7.0 with: version: ${{ vars.VERDICT_VERSION }} repository: ${{ github.repository }} diff --git a/internal/archtest/action_pin_test.go b/internal/archtest/action_pin_test.go new file mode 100644 index 000000000..d4c14d81e --- /dev/null +++ b/internal/archtest/action_pin_test.go @@ -0,0 +1,168 @@ +package archtest + +import ( + "encoding/json" + "fmt" + "os" + "os/exec" + "path/filepath" + "regexp" + "slices" + "strings" + "testing" + "time" +) + +var selfPinSHA = regexp.MustCompile(`^[0-9a-f]{40}$`) + +var actionSelfPins = []struct { + path string + prefix string +}{ + {path: "action.yml", prefix: "stainless-code/verdict/setup-verdict@"}, + {path: "examples/verdict-review.yml", prefix: "stainless-code/verdict@"}, +} + +// TestActionPinsAtRelease keeps the composite Action and its copy-paste +// workflow on the release that package.json names, with no re-pin TODO left in +// the line. +func TestActionPinsAtRelease(t *testing.T) { + root := moduleRoot(t) + version := actionPackageVersion(t, root) + wantComment := "# v" + version + var shas []string + for _, target := range actionSelfPins { + src := readRepoFile(t, root, target.path) + sha, problems := pinProblems(src, target.prefix, wantComment) + for _, problem := range problems { + t.Errorf("%s: %s", target.path, problem) + } + shas = append(shas, sha) + } + if len(shas) == 2 && shas[0] != "" && shas[1] != "" && shas[0] != shas[1] { + t.Errorf("self-pins disagree: action.yml is %s, examples/verdict-review.yml is %s", shas[0], shas[1]) + } + t.Run("release tag points at the pin", func(t *testing.T) { + tags := tagsAt(t, root, shas[0]) + if len(tags) == 0 { + t.Skip("no tags in this checkout: the SHA-to-version check needs a tagged clone") + } + if !slices.Contains(tags, "v"+version) { + t.Errorf("self-pin %s has tags %v; want tag v%s at that commit", shas[0], tags, version) + } + }) +} + +func actionPackageVersion(t *testing.T, root string) string { + t.Helper() + raw, err := os.ReadFile(filepath.Join(root, "package.json")) + if err != nil { + t.Fatalf("read package.json: %v", err) + } + var pkg struct { + Version string `json:"version"` + } + if err := json.Unmarshal(raw, &pkg); err != nil { + t.Fatalf("decode package.json: %v", err) + } + if pkg.Version == "" { + t.Fatal("package.json has no version: the pin guard would pass on nothing") + } + return pkg.Version +} + +// A shallow CI checkout has no tags; the line checks still run there. +func tagsAt(t *testing.T, root, sha string) []string { + t.Helper() + if !selfPinSHA.MatchString(sha) { + return nil + } + if _, err := exec.LookPath("git"); err != nil { + return nil + } + cmd := exec.CommandContext(t.Context(), "git", "-C", root, "tag", "--points-at", sha) + cmd.WaitDelay = 2 * time.Second + out, err := cmd.Output() + if err != nil { + return nil + } + return strings.Fields(string(out)) +} + +func pinProblems(src, prefix, wantComment string) (string, []string) { + var problems []string + for _, line := range strings.Split(src, "\n") { + start := strings.Index(line, prefix) + if start < 0 { + continue + } + tail := strings.Fields(strings.TrimPrefix(line[start:], prefix)) + sha := "" + if len(tail) > 0 { + sha = tail[0] + } + if !selfPinSHA.MatchString(sha) { + problems = append(problems, fmt.Sprintf("self-pin %q is not a full 40-hex commit SHA", sha)) + } + gotComment := strings.Join(tail[min(len(tail), 1):], " ") + if gotComment != wantComment { + problems = append(problems, fmt.Sprintf("self-pin comment %q, want %q", gotComment, wantComment)) + } + for _, marker := range []string{"re-pin", "repin", "as introduced", "todo"} { + if strings.Contains(strings.ToLower(line), marker) { + problems = append(problems, "self-pin still carries an open re-pin TODO") + break + } + } + return sha, problems + } + return "", []string{"no " + prefix + " self-pin found"} +} + +func TestPinProblems(t *testing.T) { + t.Parallel() + const prefix = "stainless-code/verdict/setup-verdict@" + const release = "b4c36344f03375985a8edf859b9092ba7d59f077" + const introduced = "471d2985b29060caa90036fefac565e97a12bb2c" + tests := []struct { + name string + line string + want []string + }{ + { + name: "release pin", + line: " uses: " + prefix + release + " # v0.7.0", + }, + { + name: "introduction pin with an open TODO", + line: " uses: " + prefix + introduced + " # action as introduced; re-pin to a release commit", + want: []string{"open re-pin TODO", "comment"}, + }, + { + name: "release SHA with a stale version comment", + line: " uses: " + prefix + release + " # v0.6.1", + want: []string{"comment"}, + }, + { + name: "moving tag", + line: " uses: " + prefix + "latest # v0.7.0", + want: []string{"40-hex"}, + }, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + _, problems := pinProblems(tc.line, prefix, "# v0.7.0") + for _, expected := range tc.want { + if !slices.ContainsFunc(problems, func(problem string) bool { + return strings.Contains(problem, expected) + }) { + t.Errorf("pinProblems() = %v; want a problem containing %q", problems, expected) + } + } + if len(tc.want) == 0 && len(problems) != 0 { + t.Errorf("pinProblems() = %v; want no problems", problems) + } + }) + } +} From 3b7f98209df237bd7e1666555abb691b83ff2bac Mon Sep 17 00:00:00 2001 From: Sutu Sebastian Date: Mon, 16 Nov 2026 16:58:56 +0200 Subject: [PATCH 2/5] test(archtest): refuse stale action release pins --- internal/archtest/action_pin_test.go | 150 +++++++++++++++++---------- 1 file changed, 94 insertions(+), 56 deletions(-) diff --git a/internal/archtest/action_pin_test.go b/internal/archtest/action_pin_test.go index d4c14d81e..324b64b03 100644 --- a/internal/archtest/action_pin_test.go +++ b/internal/archtest/action_pin_test.go @@ -15,10 +15,12 @@ import ( var selfPinSHA = regexp.MustCompile(`^[0-9a-f]{40}$`) -var actionSelfPins = []struct { +type selfPinTarget struct { path string prefix string -}{ +} + +var actionSelfPins = []selfPinTarget{ {path: "action.yml", prefix: "stainless-code/verdict/setup-verdict@"}, {path: "examples/verdict-review.yml", prefix: "stainless-code/verdict@"}, } @@ -32,27 +34,48 @@ func TestActionPinsAtRelease(t *testing.T) { wantComment := "# v" + version var shas []string for _, target := range actionSelfPins { - src := readRepoFile(t, root, target.path) - sha, problems := pinProblems(src, target.prefix, wantComment) - for _, problem := range problems { - t.Errorf("%s: %s", target.path, problem) - } - shas = append(shas, sha) + shas = append(shas, checkActionPin(t, root, target, wantComment)) + } + checkReleaseTag(t, root, shas, version) +} + +func checkActionPin(t *testing.T, root string, target selfPinTarget, wantComment string) string { + t.Helper() + src := readRepoFile(t, root, target.path) + sha, problems := pinProblems(src, target.prefix, wantComment) + for _, problem := range problems { + t.Errorf("%s: %s", target.path, problem) + } + return sha +} + +func checkReleaseTag(t *testing.T, root string, shas []string, version string) { + t.Helper() + if len(shas) != 2 { + t.Fatalf("found %d self-pins; want 2", len(shas)) } - if len(shas) == 2 && shas[0] != "" && shas[1] != "" && shas[0] != shas[1] { + if shas[0] == "" || shas[1] == "" { + return + } + if shas[0] != shas[1] { t.Errorf("self-pins disagree: action.yml is %s, examples/verdict-review.yml is %s", shas[0], shas[1]) } t.Run("release tag points at the pin", func(t *testing.T) { - tags := tagsAt(t, root, shas[0]) - if len(tags) == 0 { - t.Skip("no tags in this checkout: the SHA-to-version check needs a tagged clone") - } - if !slices.Contains(tags, "v"+version) { - t.Errorf("self-pin %s has tags %v; want tag v%s at that commit", shas[0], tags, version) - } + checkTagAtPin(t, root, shas[0], version) }) } +func checkTagAtPin(t *testing.T, root, sha, version string) { + t.Helper() + tags := tagsAt(t, root, sha) + if len(tags) == 0 { + t.Skip("no tags in this checkout: the SHA-to-version check needs a tagged clone") + } + if !slices.Contains(tags, "v"+version) { + t.Errorf("self-pin %s has tags %v; want tag v%s at that commit", sha, tags, version) + } +} + func actionPackageVersion(t *testing.T, root string) string { t.Helper() raw, err := os.ReadFile(filepath.Join(root, "package.json")) @@ -90,45 +113,55 @@ func tagsAt(t *testing.T, root, sha string) []string { } func pinProblems(src, prefix, wantComment string) (string, []string) { - var problems []string - for _, line := range strings.Split(src, "\n") { - start := strings.Index(line, prefix) - if start < 0 { - continue - } - tail := strings.Fields(strings.TrimPrefix(line[start:], prefix)) - sha := "" - if len(tail) > 0 { - sha = tail[0] - } - if !selfPinSHA.MatchString(sha) { - problems = append(problems, fmt.Sprintf("self-pin %q is not a full 40-hex commit SHA", sha)) + for line := range strings.SplitSeq(src, "\n") { + if strings.Contains(line, prefix) { + return pinLineProblems(line, prefix, wantComment) } - gotComment := strings.Join(tail[min(len(tail), 1):], " ") - if gotComment != wantComment { - problems = append(problems, fmt.Sprintf("self-pin comment %q, want %q", gotComment, wantComment)) - } - for _, marker := range []string{"re-pin", "repin", "as introduced", "todo"} { - if strings.Contains(strings.ToLower(line), marker) { - problems = append(problems, "self-pin still carries an open re-pin TODO") - break - } - } - return sha, problems } return "", []string{"no " + prefix + " self-pin found"} } +func pinLineProblems(line, prefix, wantComment string) (string, []string) { + start := strings.Index(line, prefix) + tail := strings.Fields(line[start+len(prefix):]) + sha := "" + if len(tail) > 0 { + sha = tail[0] + } + var problems []string + if !selfPinSHA.MatchString(sha) { + problems = append(problems, fmt.Sprintf("self-pin %q is not a full 40-hex commit SHA", sha)) + } + gotComment := strings.Join(tail[min(len(tail), 1):], " ") + if gotComment != wantComment { + problems = append(problems, fmt.Sprintf("self-pin comment %q, want %q", gotComment, wantComment)) + } + if hasRepinMarker(line) { + problems = append(problems, "self-pin still carries an open re-pin TODO") + } + return sha, problems +} + +func hasRepinMarker(line string) bool { + lower := strings.ToLower(line) + markers := []string{"re-pin", "repin", "as introduced", "todo"} + return slices.ContainsFunc(markers, func(marker string) bool { + return strings.Contains(lower, marker) + }) +} + +type pinCase struct { + name string + line string + want []string +} + func TestPinProblems(t *testing.T) { t.Parallel() const prefix = "stainless-code/verdict/setup-verdict@" const release = "b4c36344f03375985a8edf859b9092ba7d59f077" const introduced = "471d2985b29060caa90036fefac565e97a12bb2c" - tests := []struct { - name string - line string - want []string - }{ + tests := []pinCase{ { name: "release pin", line: " uses: " + prefix + release + " # v0.7.0", @@ -152,17 +185,22 @@ func TestPinProblems(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { t.Parallel() - _, problems := pinProblems(tc.line, prefix, "# v0.7.0") - for _, expected := range tc.want { - if !slices.ContainsFunc(problems, func(problem string) bool { - return strings.Contains(problem, expected) - }) { - t.Errorf("pinProblems() = %v; want a problem containing %q", problems, expected) - } - } - if len(tc.want) == 0 && len(problems) != 0 { - t.Errorf("pinProblems() = %v; want no problems", problems) - } + checkPinCase(t, tc, prefix) }) } } + +func checkPinCase(t *testing.T, tc pinCase, prefix string) { + t.Helper() + _, problems := pinProblems(tc.line, prefix, "# v0.7.0") + if len(tc.want) == 0 && len(problems) != 0 { + t.Fatalf("pinProblems() = %v; want no problems", problems) + } + for _, expected := range tc.want { + if !slices.ContainsFunc(problems, func(problem string) bool { + return strings.Contains(problem, expected) + }) { + t.Errorf("pinProblems() = %v; want a problem containing %q", problems, expected) + } + } +} From ca87d35f5b0b30ccfb2322492e2ac0f6642b2c0a Mon Sep 17 00:00:00 2001 From: Sutu Sebastian Date: Mon, 16 Nov 2026 17:07:00 +0200 Subject: [PATCH 3/5] test(archtest): allow pins behind the package version --- .changeset/action-pin-v070.md | 2 +- internal/archtest/action_pin_test.go | 214 +++++++++++++++++++++------ 2 files changed, 172 insertions(+), 44 deletions(-) diff --git a/.changeset/action-pin-v070.md b/.changeset/action-pin-v070.md index b2e862879..f0f15c071 100644 --- a/.changeset/action-pin-v070.md +++ b/.changeset/action-pin-v070.md @@ -2,4 +2,4 @@ "@stainless-code/verdict": patch --- -Pin the composite Action and its example workflow to the v0.7.0 release commit, so Action users get the hardened installers. An archtest now fails on an "as introduced" self-pin or a stale release comment. +Pin the composite Action and its example workflow to the v0.7.0 release commit, so Action users get the hardened installers. An archtest now fails on an "as introduced" self-pin or a pin ahead of the release manifest. diff --git a/internal/archtest/action_pin_test.go b/internal/archtest/action_pin_test.go index 324b64b03..7dfbd6608 100644 --- a/internal/archtest/action_pin_test.go +++ b/internal/archtest/action_pin_test.go @@ -8,71 +8,81 @@ import ( "path/filepath" "regexp" "slices" + "strconv" "strings" "testing" "time" ) -var selfPinSHA = regexp.MustCompile(`^[0-9a-f]{40}$`) +var ( + selfPinSHA = regexp.MustCompile(`^[0-9a-f]{40}$`) + semverPattern = regexp.MustCompile(`^([0-9]+)\.([0-9]+)\.([0-9]+)$`) + pinCommentPattern = regexp.MustCompile(`^# v([0-9]+\.[0-9]+\.[0-9]+)$`) +) type selfPinTarget struct { path string prefix string } +type selfPin struct { + sha string + version string +} + var actionSelfPins = []selfPinTarget{ {path: "action.yml", prefix: "stainless-code/verdict/setup-verdict@"}, {path: "examples/verdict-review.yml", prefix: "stainless-code/verdict@"}, } -// TestActionPinsAtRelease keeps the composite Action and its copy-paste -// workflow on the release that package.json names, with no re-pin TODO left in -// the line. +// TestActionPinsAtRelease keeps both self-pins on the same tagged release at +// or before package.json: a Version PR bumps the manifest before the matching +// release commit exists, so equality would deadlock the next release. func TestActionPinsAtRelease(t *testing.T) { root := moduleRoot(t) version := actionPackageVersion(t, root) - wantComment := "# v" + version - var shas []string + var pins []selfPin for _, target := range actionSelfPins { - shas = append(shas, checkActionPin(t, root, target, wantComment)) + pins = append(pins, checkActionPin(t, root, target, version)) } - checkReleaseTag(t, root, shas, version) + checkReleaseTag(t, root, pins) } -func checkActionPin(t *testing.T, root string, target selfPinTarget, wantComment string) string { +func checkActionPin(t *testing.T, root string, target selfPinTarget, packageVersion string) selfPin { t.Helper() src := readRepoFile(t, root, target.path) - sha, problems := pinProblems(src, target.prefix, wantComment) + pin, problems := pinProblems(src, target.prefix, packageVersion) for _, problem := range problems { t.Errorf("%s: %s", target.path, problem) } - return sha + return pin } -func checkReleaseTag(t *testing.T, root string, shas []string, version string) { +func checkReleaseTag(t *testing.T, root string, pins []selfPin) { t.Helper() - if len(shas) != 2 { - t.Fatalf("found %d self-pins; want 2", len(shas)) + if len(pins) != 2 { + t.Fatalf("found %d self-pins; want 2", len(pins)) } - if shas[0] == "" || shas[1] == "" { + if pins[0].sha == "" || pins[1].sha == "" { return } - if shas[0] != shas[1] { - t.Errorf("self-pins disagree: action.yml is %s, examples/verdict-review.yml is %s", shas[0], shas[1]) + if pins[0] != pins[1] { + t.Errorf("self-pins disagree: action.yml is %s v%s, examples/verdict-review.yml is %s v%s", + pins[0].sha, pins[0].version, pins[1].sha, pins[1].version) } t.Run("release tag points at the pin", func(t *testing.T) { - checkTagAtPin(t, root, shas[0], version) + checkTagAtPin(t, root, pins[0].sha, pins[0].version) }) } -func checkTagAtPin(t *testing.T, root, sha, version string) { +func checkTagAtPin(t *testing.T, root, sha, pinVersion string) { t.Helper() tags := tagsAt(t, root, sha) if len(tags) == 0 { t.Skip("no tags in this checkout: the SHA-to-version check needs a tagged clone") } - if !slices.Contains(tags, "v"+version) { - t.Errorf("self-pin %s has tags %v; want tag v%s at that commit", sha, tags, version) + if !slices.Contains(tags, "v"+pinVersion) { + t.Errorf("self-pin %s has tags %v; want tag v%s at that commit", sha, tags, pinVersion) } } @@ -88,8 +98,8 @@ func actionPackageVersion(t *testing.T, root string) string { if err := json.Unmarshal(raw, &pkg); err != nil { t.Fatalf("decode package.json: %v", err) } - if pkg.Version == "" { - t.Fatal("package.json has no version: the pin guard would pass on nothing") + if !semverValid(pkg.Version) { + t.Fatalf("package.json version %q is not X.Y.Z", pkg.Version) } return pkg.Version } @@ -112,34 +122,98 @@ func tagsAt(t *testing.T, root, sha string) []string { return strings.Fields(string(out)) } -func pinProblems(src, prefix, wantComment string) (string, []string) { +func pinProblems(src, prefix, packageVersion string) (selfPin, []string) { for line := range strings.SplitSeq(src, "\n") { if strings.Contains(line, prefix) { - return pinLineProblems(line, prefix, wantComment) + return pinLineProblems(line, prefix, packageVersion) } } - return "", []string{"no " + prefix + " self-pin found"} + return selfPin{}, []string{"no " + prefix + " self-pin found"} } -func pinLineProblems(line, prefix, wantComment string) (string, []string) { +func pinLineProblems(line, prefix, packageVersion string) (selfPin, []string) { start := strings.Index(line, prefix) tail := strings.Fields(line[start+len(prefix):]) - sha := "" + var pin selfPin if len(tail) > 0 { - sha = tail[0] + pin.sha = tail[0] } var problems []string - if !selfPinSHA.MatchString(sha) { - problems = append(problems, fmt.Sprintf("self-pin %q is not a full 40-hex commit SHA", sha)) + if !selfPinSHA.MatchString(pin.sha) { + problems = append(problems, fmt.Sprintf("self-pin %q is not a full 40-hex commit SHA", pin.sha)) } - gotComment := strings.Join(tail[min(len(tail), 1):], " ") - if gotComment != wantComment { - problems = append(problems, fmt.Sprintf("self-pin comment %q, want %q", gotComment, wantComment)) + comment := strings.Join(tail[min(len(tail), 1):], " ") + pin.version = pinCommentVersion(comment) + if pin.version == "" { + problems = append(problems, fmt.Sprintf("self-pin comment %q, want `# vX.Y.Z`", comment)) } + problems = append(problems, versionProblems(pin.version, packageVersion)...) if hasRepinMarker(line) { problems = append(problems, "self-pin still carries an open re-pin TODO") } - return sha, problems + return pin, problems +} + +func pinCommentVersion(comment string) string { + match := pinCommentPattern.FindStringSubmatch(comment) + if match == nil { + return "" + } + return match[1] +} + +func versionProblems(pinVersion, packageVersion string) []string { + if !semverValid(packageVersion) { + return []string{fmt.Sprintf("package.json version %q is not X.Y.Z", packageVersion)} + } + if pinVersion == "" { + return nil + } + if !semverValid(pinVersion) { + return []string{fmt.Sprintf("self-pin version %q is not X.Y.Z", pinVersion)} + } + if semverGreater(pinVersion, packageVersion) { + return []string{fmt.Sprintf("self-pin v%s is newer than package.json version %s", pinVersion, packageVersion)} + } + return nil +} + +func semverValid(version string) bool { + _, ok := semverParts(version) + return ok +} + +func semverGreater(left, right string) bool { + a, aOK := semverParts(left) + b, bOK := semverParts(right) + if !aOK || !bOK { + return false + } + for i := range a { + if a[i] != b[i] { + return a[i] > b[i] + } + } + return false +} + +func semverParts(version string) ([3]int, bool) { + var parts [3]int + match := semverPattern.FindStringSubmatch(version) + if match == nil { + return parts, false + } + for i := range parts { + if len(match[i+1]) > 1 && match[i+1][0] == '0' { + return parts, false + } + number, err := strconv.Atoi(match[i+1]) + if err != nil { + return parts, false + } + parts[i] = number + } + return parts, true } func hasRepinMarker(line string) bool { @@ -151,9 +225,10 @@ func hasRepinMarker(line string) bool { } type pinCase struct { - name string - line string - want []string + name string + line string + pkgVersion string + want []string } func TestPinProblems(t *testing.T) { @@ -172,15 +247,35 @@ func TestPinProblems(t *testing.T) { want: []string{"open re-pin TODO", "comment"}, }, { - name: "release SHA with a stale version comment", + name: "older pinned release stays valid after a version bump", line: " uses: " + prefix + release + " # v0.6.1", - want: []string{"comment"}, + }, + { + name: "version PR: pin behind package.json", + line: " uses: " + prefix + release + " # v0.7.0", + pkgVersion: "0.7.1", + }, + { + name: "pin newer than package.json", + line: " uses: " + prefix + release + " # v0.7.2", + pkgVersion: "0.7.1", + want: []string{"newer than package.json version"}, }, { name: "moving tag", line: " uses: " + prefix + "latest # v0.7.0", want: []string{"40-hex"}, }, + { + name: "malformed version comment", + line: " uses: " + prefix + release + " # v0.7", + want: []string{"comment"}, + }, + { + name: "leading zero in pin version", + line: " uses: " + prefix + release + " # v0.07.0", + want: []string{"not X.Y.Z"}, + }, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { @@ -192,11 +287,20 @@ func TestPinProblems(t *testing.T) { func checkPinCase(t *testing.T, tc pinCase, prefix string) { t.Helper() - _, problems := pinProblems(tc.line, prefix, "# v0.7.0") - if len(tc.want) == 0 && len(problems) != 0 { + pkgVersion := tc.pkgVersion + if pkgVersion == "" { + pkgVersion = "0.7.0" + } + _, problems := pinProblems(tc.line, prefix, pkgVersion) + assertPinProblems(t, problems, tc.want) +} + +func assertPinProblems(t *testing.T, problems, want []string) { + t.Helper() + if len(want) == 0 && len(problems) != 0 { t.Fatalf("pinProblems() = %v; want no problems", problems) } - for _, expected := range tc.want { + for _, expected := range want { if !slices.ContainsFunc(problems, func(problem string) bool { return strings.Contains(problem, expected) }) { @@ -204,3 +308,27 @@ func checkPinCase(t *testing.T, tc pinCase, prefix string) { } } } + +func TestSemverGreater(t *testing.T) { + t.Parallel() + tests := []struct { + name string + left, right string + want bool + }{ + {name: "patch", left: "0.7.1", right: "0.7.0", want: true}, + {name: "older patch", left: "0.7.0", right: "0.7.1"}, + {name: "equal", left: "0.7.0", right: "0.7.0"}, + {name: "minor is numeric", left: "0.10.0", right: "0.9.9", want: true}, + {name: "major wins", left: "1.0.0", right: "0.99.99", want: true}, + {name: "leading zero is not semver", left: "0.07.0", right: "0.7.0"}, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + if got := semverGreater(tc.left, tc.right); got != tc.want { + t.Errorf("semverGreater(%q, %q) = %v; want %v", tc.left, tc.right, got, tc.want) + } + }) + } +} From d54cf316fd2831d128fe9b3922194bb5d9339359 Mon Sep 17 00:00:00 2001 From: Sutu Sebastian Date: Mon, 16 Nov 2026 17:12:46 +0200 Subject: [PATCH 4/5] chore: drop the action pin changeset; no shipped artifact changes --- .changeset/action-pin-v070.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .changeset/action-pin-v070.md diff --git a/.changeset/action-pin-v070.md b/.changeset/action-pin-v070.md deleted file mode 100644 index f0f15c071..000000000 --- a/.changeset/action-pin-v070.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@stainless-code/verdict": patch ---- - -Pin the composite Action and its example workflow to the v0.7.0 release commit, so Action users get the hardened installers. An archtest now fails on an "as introduced" self-pin or a pin ahead of the release manifest. From f88a2c08ed1e82e6e6724cb5af629a73d70297df Mon Sep 17 00:00:00 2001 From: Sutu Sebastian Date: Mon, 16 Nov 2026 17:19:50 +0200 Subject: [PATCH 5/5] fix(archtest): fail untagged pins and check every uses line --- internal/archtest/action_pin_test.go | 224 +++++++++++++++++++++++---- 1 file changed, 197 insertions(+), 27 deletions(-) diff --git a/internal/archtest/action_pin_test.go b/internal/archtest/action_pin_test.go index 7dfbd6608..c460c8cb6 100644 --- a/internal/archtest/action_pin_test.go +++ b/internal/archtest/action_pin_test.go @@ -35,54 +35,135 @@ var actionSelfPins = []selfPinTarget{ {path: "examples/verdict-review.yml", prefix: "stainless-code/verdict@"}, } -// TestActionPinsAtRelease keeps both self-pins on the same tagged release at -// or before package.json: a Version PR bumps the manifest before the matching -// release commit exists, so equality would deadlock the next release. +// TestActionPinsAtRelease allows pins behind package.json: Version PRs bump +// the manifest before the matching release commit exists. func TestActionPinsAtRelease(t *testing.T) { root := moduleRoot(t) version := actionPackageVersion(t, root) var pins []selfPin for _, target := range actionSelfPins { - pins = append(pins, checkActionPin(t, root, target, version)) + pins = append(pins, checkActionPin(t, root, target, version)...) } checkReleaseTag(t, root, pins) } -func checkActionPin(t *testing.T, root string, target selfPinTarget, packageVersion string) selfPin { +func checkActionPin(t *testing.T, root string, target selfPinTarget, packageVersion string) []selfPin { t.Helper() src := readRepoFile(t, root, target.path) - pin, problems := pinProblems(src, target.prefix, packageVersion) + pins, problems := pinProblems(src, target.prefix, packageVersion) for _, problem := range problems { t.Errorf("%s: %s", target.path, problem) } - return pin + return pins } func checkReleaseTag(t *testing.T, root string, pins []selfPin) { t.Helper() - if len(pins) != 2 { - t.Fatalf("found %d self-pins; want 2", len(pins)) + if len(pins) < 2 { + t.Fatalf("found %d self-pins; want at least 2, one per shipped workflow", len(pins)) } - if pins[0].sha == "" || pins[1].sha == "" { - return + for _, problem := range pinDisagreements(pins) { + t.Error(problem) } - if pins[0] != pins[1] { - t.Errorf("self-pins disagree: action.yml is %s v%s, examples/verdict-review.yml is %s v%s", - pins[0].sha, pins[0].version, pins[1].sha, pins[1].version) + if pins[0].sha == "" { + return } t.Run("release tag points at the pin", func(t *testing.T) { checkTagAtPin(t, root, pins[0].sha, pins[0].version) }) } +func pinDisagreements(pins []selfPin) []string { + var problems []string + for _, pin := range pins[1:] { + if pin != pins[0] { + problems = append(problems, fmt.Sprintf("self-pin %s v%s disagrees with %s v%s", + pin.sha, pin.version, pins[0].sha, pins[0].version)) + } + } + return problems +} + +type tagLookup func(sha string) []string + func checkTagAtPin(t *testing.T, root, sha, pinVersion string) { t.Helper() - tags := tagsAt(t, root, sha) - if len(tags) == 0 { + checkTagAtPinWith(t, repoTags(t, root), func(sha string) []string { + return tagsAt(t, root, sha) + }, sha, pinVersion) +} + +type tagOutcome int + +const ( + tagSkip tagOutcome = iota + tagOK + tagMismatch +) + +func (outcome tagOutcome) String() string { + switch outcome { + case tagSkip: + return "skip" + case tagOK: + return "ok" + default: + return "mismatch" + } +} + +func checkTagAtPinWith(t *testing.T, allTags []string, lookup tagLookup, sha, pinVersion string) { + t.Helper() + atPin := lookup(sha) + outcome := tagOutcomeFor(allTags, atPin, pinVersion) + if outcome == tagSkip { t.Skip("no tags in this checkout: the SHA-to-version check needs a tagged clone") } - if !slices.Contains(tags, "v"+pinVersion) { - t.Errorf("self-pin %s has tags %v; want tag v%s at that commit", sha, tags, pinVersion) + if outcome == tagMismatch { + t.Errorf("self-pin %s carries tags %v; want tag v%s at that commit", sha, atPin, pinVersion) + } +} + +func tagOutcomeFor(allTags, atPin []string, pinVersion string) tagOutcome { + if len(allTags) == 0 { + return tagSkip + } + if slices.Contains(atPin, "v"+pinVersion) { + return tagOK + } + return tagMismatch +} + +func TestTagOutcomeFor(t *testing.T) { + t.Parallel() + tests := []struct { + name string + allTags, atPin []string + want tagOutcome + }{ + { + name: "tagged checkout with an untagged pin", + allTags: []string{"v0.7.0"}, + want: tagMismatch, + }, + { + name: "tagged checkout with the pin's release tag", + allTags: []string{"v0.7.0", "v0.6.0"}, + atPin: []string{"v0.7.0"}, + want: tagOK, + }, + { + name: "checkout with no tags", + want: tagSkip, + }, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + if got := tagOutcomeFor(tc.allTags, tc.atPin, "0.7.0"); got != tc.want { + t.Errorf("tagOutcomeFor(%v, %v) = %v; want %v", tc.allTags, tc.atPin, got, tc.want) + } + }) } } @@ -104,16 +185,25 @@ func actionPackageVersion(t *testing.T, root string) string { return pkg.Version } -// A shallow CI checkout has no tags; the line checks still run there. +func repoTags(t *testing.T, root string) []string { + t.Helper() + return gitTags(t, root, "-l") +} + func tagsAt(t *testing.T, root, sha string) []string { t.Helper() if !selfPinSHA.MatchString(sha) { return nil } + return gitTags(t, root, "--points-at", sha) +} + +func gitTags(t *testing.T, root string, args ...string) []string { + t.Helper() if _, err := exec.LookPath("git"); err != nil { return nil } - cmd := exec.CommandContext(t.Context(), "git", "-C", root, "tag", "--points-at", sha) + cmd := exec.CommandContext(t.Context(), "git", append([]string{"-C", root, "tag"}, args...)...) cmd.WaitDelay = 2 * time.Second out, err := cmd.Output() if err != nil { @@ -122,13 +212,22 @@ func tagsAt(t *testing.T, root, sha string) []string { return strings.Fields(string(out)) } -func pinProblems(src, prefix, packageVersion string) (selfPin, []string) { +func pinProblems(src, prefix, packageVersion string) ([]selfPin, []string) { + var pins []selfPin + var problems []string for line := range strings.SplitSeq(src, "\n") { - if strings.Contains(line, prefix) { - return pinLineProblems(line, prefix, packageVersion) + trimmed := strings.TrimSpace(line) + if strings.HasPrefix(trimmed, "#") || !strings.Contains(trimmed, "uses:") || !strings.Contains(trimmed, prefix) { + continue } + pin, lineProblems := pinLineProblems(line, prefix, packageVersion) + pins = append(pins, pin) + problems = append(problems, lineProblems...) + } + if len(pins) == 0 { + problems = append(problems, "no "+prefix+" self-pin found") } - return selfPin{}, []string{"no " + prefix + " self-pin found"} + return pins, problems } func pinLineProblems(line, prefix, packageVersion string) (selfPin, []string) { @@ -229,6 +328,7 @@ type pinCase struct { line string pkgVersion string want []string + wantCount int } func TestPinProblems(t *testing.T) { @@ -276,25 +376,95 @@ func TestPinProblems(t *testing.T) { line: " uses: " + prefix + release + " # v0.07.0", want: []string{"not X.Y.Z"}, }, + { + name: "prefix in a comment before the real uses line", + line: " # uses: " + prefix + introduced + " # action as introduced; re-pin to a release commit\n" + + " uses: " + prefix + release + " # v0.7.0", + }, + { + name: "file with no self-pin", + line: " uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7", + wantCount: -1, + want: []string{"no " + prefix + " self-pin found"}, + }, + { + name: "every uses line is checked", + line: " uses: " + prefix + release + " # v0.7.0\n" + + " uses: " + prefix + release + " # v0.7.0", + wantCount: 2, + }, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { t.Parallel() - checkPinCase(t, tc, prefix) + checkPinCase(t, &tc, prefix) }) } } -func checkPinCase(t *testing.T, tc pinCase, prefix string) { +func checkPinCase(t *testing.T, tc *pinCase, prefix string) { t.Helper() pkgVersion := tc.pkgVersion if pkgVersion == "" { pkgVersion = "0.7.0" } - _, problems := pinProblems(tc.line, prefix, pkgVersion) + pins, problems := pinProblems(tc.line, prefix, pkgVersion) + wantPins := tc.wantCount + switch wantPins { + case -1: + wantPins = 0 + case 0: + wantPins = 1 + } + if len(pins) != wantPins { + t.Errorf("pinProblems() found %d pins; want %d", len(pins), wantPins) + } assertPinProblems(t, problems, tc.want) } +func TestPinDisagreements(t *testing.T) { + t.Parallel() + const release = "b4c36344f03375985a8edf859b9092ba7d59f077" + const introduced = "471d2985b29060caa90036fefac565e97a12bb2c" + tests := []struct { + name string + pins []selfPin + want int + }{ + { + name: "equal pins", + pins: []selfPin{ + {sha: release, version: "0.7.0"}, + {sha: release, version: "0.7.0"}, + }, + }, + { + name: "different commits", + pins: []selfPin{ + {sha: release, version: "0.7.0"}, + {sha: introduced, version: "0.7.0"}, + }, + want: 1, + }, + { + name: "different versions on one commit", + pins: []selfPin{ + {sha: release, version: "0.7.0"}, + {sha: release, version: "0.6.1"}, + }, + want: 1, + }, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + if got := len(pinDisagreements(tc.pins)); got != tc.want { + t.Errorf("pinDisagreements() = %d problems; want %d", got, tc.want) + } + }) + } +} + func assertPinProblems(t *testing.T, problems, want []string) { t.Helper() if len(want) == 0 && len(problems) != 0 {