beads/scripts/ci_blacksmith_runner_test.go
Julian Knutsen 84ce244857
ci: same-repo Linux/Windows PR jobs on Blacksmith with main-seeded warm build caches (F7b) (#7155)
* ci: move same-repo PR Linux/Windows/macOS legs to Blacksmith, shard preflight (F7b)

PR-path jobs for same-repo PRs/merge_group now run on Blacksmith instead
of GitHub-hosted runners, following F4/F7a's ternary-expression and
restore-only-cache patterns; forks/Dependabot are unaffected:

- scripts-go-checks, pr-lint-wrapper: same-repo Blacksmith 4vcpu Linux.
- check-doc-freshness-platforms, pr-preflight-platforms: restructured
  from a top-level matrix.os list to an include:-only "matrix marker"
  shape (runner: same-repo-linux/-windows/-macos) so each host can
  resolve an independent same-repo Blacksmith selection via one chained
  ternary runs-on expression.
- Six standalone Windows jobs (test-windows-liveness,
  worktree-remove-windows, test-windows-small,
  test-windows-liveness-prebuilt, worktree-remove-windows-prebuilt,
  windows-make-shell) move to same-repo Blacksmith Windows
  (blacksmith-{2,4}vcpu-windows-2025, public beta). CGO/mingw-w64 and
  Chocolatey preinstall are unconfirmed on that image; both risks are
  flagged with one-line rollback instructions at the call sites.
- pr-preflight-platforms' Windows leg is split into two shards (common
  steps on shard 1, the three Windows-only heavy steps on shard 2) to
  shorten its critical path; shard 2 downloads Go modules directly
  instead of sharing shard 1's runner/cache.

main.yml gains cache savers for the newly same-repo-Blacksmith PR
consumers, since Blacksmith and GitHub-hosted runners cannot see each
other's actions/cache entries even for identical keys:

- blacksmith-go-build-cache warms the Blacksmith-selection race/non-race
  GOCACHEs scripts-go-checks and pr-preflight-platforms/check-doc-
  freshness-platforms' ubuntu legs need, push-to-main only. Its non-race
  leg shares scripts/ci/warm-non-race-cache.sh with build-artifacts, and
  compiles tools/bazel/run_allowlisted_go_tests.py's allowlisted
  packages via its new --compile-only flag, so the two paths and the
  warm-up can never drift from what they actually run.
- pr-lint-wrapper, go-vet-cache, test-windows gain a venue: [blacksmith,
  github] matrix leg to seed both runner selections pr.yml's
  same-repo-Blacksmith-or-fork-hosted consumers can land on.

Updates the policy-test suite (ci_workflow_test.go,
ci_blacksmith_runner_test.go, pr_lanes_bazel_coverage_test.go) to cover
the new runner selections, matrix-marker shape, shard gating, and cache
topology, including a dedicated inventory/writer check for
blacksmith-go-build-cache.

Deferred follow-up (not done here): sharding check-doc-freshness-
platforms and the standalone Windows jobs, and moving/sharding macOS
legs beyond what check-doc-freshness-platforms'/pr-preflight-platforms'
matrix-marker form already covers.

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

* fix(ci): F7b review response -- msys2/Blacksmith-saver guards, macOS stays hosted (B1/B2/S3)

Addresses ~/beads-bazel-plan/f7b/review.md's two cache-safety blockers and
one follow-up gap found after F7b moved same-repo PR Linux/Windows/macOS
legs onto Blacksmith and added push-to-main Blacksmith cache seeders:

- B1: windows-make-shell's msys2/setup-msys2 step caches its installed
  packages by default, which implicitly SAVED a GitHub Actions cache entry
  from a same-repo PR the moment it ran on a Blacksmith runner (confirmed
  via a real cache-list entry from a refs/pull/.../merge ref). Disabled with
  a fail-closed `cache: ${{ runner.environment == 'github-hosted' }}`, and
  generalized the sweep (TestBlacksmithReachablePRJobsDisableDefaultCachingActions)
  to cover any default-caching setup-* action on a Blacksmith-reachable job,
  not just this one.

- B2: blacksmith-go-build-cache, pr-lint-wrapper, go-vet-cache and
  test-windows (main.yml) had no (or an incomplete) same-repo push-to-main
  guard, so a same-repo fork with push access to its own main could run --
  and save a cache entry from -- a paid Blacksmith job. Added the exact
  push-to-main/same-repo `if:` F7c's own blacksmith-setup-go-cache already
  uses, pinned by TestBlacksmithSaverJobsGuardedAgainstPullRequest.

- S3: the macOS leg of pr-preflight-platforms/check-doc-freshness-platforms
  resolved to Blacksmith for same-repo PRs; Blacksmith bills macOS at
  roughly 20x its Linux/Windows rate and no push-to-main Blacksmith-macOS
  saver exists, so that leg would pay the premium for a guaranteed cold
  cache. macOS now stays unconditionally on GitHub-hosted macos-latest.

Also pins S7 (blacksmith-go-build-cache/go-vet-cache/test-windows's cache
keys are bounded by go.sum+UTC-day, not github.sha) and S6/S8 (their
20-minute timeouts), both already in place but previously unpinned, and
replaces run_allowlisted_go_tests.py's fragile GO_TEST_FLAGS[-2:] slice with
an explicit BUILD_FLAGS constant (N1).

Re-ran the reviewer's 15 mutations (~/beads-bazel-plan/f7b/review/mutate.py):
all now killed or structurally moot (the Windows preflight shard split this
review asked to revert-unless-helpful was reverted, in an earlier commit on
this branch, removing the vulnerability surface 6 of them targeted).

scripts/BUILD.bazel: add the new ci_f7b_review_test.go to scripts_test's
srcs -- bazel test caught it missing (file existed on disk but was not
compiled into the Bazel-built test binary).

Verification: go vet/test/build, gofmt, bazel --nohome_rc test
//scripts:scripts_test, actionlint -shellcheck, shellcheck, make
ci-pr-policy, make bazel-sync-check all pass.

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

* test(ci): drop local review-doc path from comment

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-03 17:58:31 -07:00

469 lines
19 KiB
Go

package scripts_test
import (
"fmt"
"strings"
"testing"
)
// This file is shared between F7a (ci/f7a-blacksmith-fold) and F7c
// (ci/f7c-advisory-workflows). F7a lands first; F7c should rebase onto it and
// delete its own copies of the pieces below rather than keep a second
// definition (two independent `sameRepoBlacksmith4vcpu` consts merge fine
// textually since the literal is identical, but two
// `TestSameRepoBlacksmithExpressionSemantics` functions in the same package
// do not - that was review SF-5/F7c-collision on the F7a review).
//
// Public surface F7c (or any later slice) should reuse:
// - sameRepoBlacksmith2vcpu / sameRepoBlacksmith4vcpu / sameRepoBlacksmith8vcpu
// - evalGHExpr(expr string, ctx map[string]string) (any, error)
// - mustEvalGHRunsOn(t *testing.T, expr string, ctx map[string]string) string
//
// F7c's own TestSameRepoBlacksmithExpressionSemantics (ci_f7c_advisory_test.go)
// and TestBlacksmithAdvisoryJobsReadNoSecrets should be folded into (or
// replaced by calls into) this file's test and
// TestBlacksmithJobsReadNoSecrets (ci_workflow_test.go) respectively, rather
// than kept as independent copies.
// F3: the same "same-repo PR, or merge_group" Blacksmith expression used by
// pr.yml's and pr-risk.yml's bazel-coverage/ci-gate/detect-ci-tier jobs - a
// package-level const so every test that needs it (TestSameRepoBlacksmithRunners,
// TestPRRiskBazelCoverageJob, ...) reads the one literal.
const sameRepoBlacksmith2vcpu = "${{ (github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}"
// F7a: the same same-repo expression at 4 vCPU and 8 vCPU, for jobs sized
// larger than the 2 vCPU default (check-doc-flags, pr-policy-wrapper,
// pr-risk.yml's test-nix at 4 vCPU; check-release-target-cross-compilation at
// 8 vCPU). F7c's advisory workflows also use the 4 vCPU size.
const sameRepoBlacksmith4vcpu = "${{ (github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) && 'blacksmith-4vcpu-ubuntu-2404' || 'ubuntu-latest' }}"
const sameRepoBlacksmith8vcpu = "${{ (github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) && 'blacksmith-8vcpu-ubuntu-2404' || 'ubuntu-latest' }}"
// F7b: same-repo Blacksmith Windows (blacksmith-*vcpu-windows-2025, public
// beta) and macOS (blacksmith-*vcpu-macos-latest) labels, same ternary shape
// as the Linux consts above - forks/Dependabot keep the current GitHub-hosted
// windows-latest/macos-latest label. windows-2025 is GitHub's windows-2025
// image minus the full Visual Studio IDE, EdgeDriver and WinAppDriver; VS
// Build Tools 2022 is present (cgo via MSVC/clang-cl or an installed
// mingw-w64 toolchain), but there is no Linux Docker. Jobs moved onto these
// labels that rely on a specific Windows toolchain detail already document
// that dependency at the call site.
const sameRepoBlacksmithWindows2vcpu = "${{ (github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) && 'blacksmith-2vcpu-windows-2025' || 'windows-latest' }}"
const sameRepoBlacksmithWindows4vcpu = "${{ (github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) && 'blacksmith-4vcpu-windows-2025' || 'windows-latest' }}"
const sameRepoBlacksmithWindows8vcpu = "${{ (github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) && 'blacksmith-8vcpu-windows-2025' || 'windows-latest' }}"
const sameRepoBlacksmithWindows16vcpu = "${{ (github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) && 'blacksmith-16vcpu-windows-2025' || 'windows-latest' }}"
const sameRepoBlacksmithMacOS6vcpu = "${{ (github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) && 'blacksmith-6vcpu-macos-latest' || 'macos-latest' }}"
const sameRepoBlacksmithMacOS12vcpu = "${{ (github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) && 'blacksmith-12vcpu-macos-latest' || 'macos-latest' }}"
// sameRepoPlatformsMatrixMarkerRunsOn is the "matrix marker" form (spec
// F7/F7b §2.1) used by mixed-OS matrix jobs (pr-preflight-platforms,
// check-doc-freshness-platforms): Actions does not expand `${{ }}` inside a
// matrix array/include value, so each OS leg's `include` entry instead sets a
// plain string marker field (`runner: same-repo-linux` etc.), and a single
// chained ternary in the job's `runs-on` tests which marker (if any) the
// current leg carries, falling back to `matrix.os` for legs with no marker or
// when the marker's own same-repo condition is false.
//
// F7b review fix (S3): the macOS branch is a plain 'macos-latest', never
// Blacksmith - Blacksmith macOS runners bill at roughly 20x Linux/Windows
// rates and no push-to-main Blacksmith-macOS cache saver exists. The
// `same-repo-macos` marker itself is kept (only its resolved value changed)
// so the job's matrix shape stays uniform across all three OSes.
const sameRepoPlatformsMatrixMarkerRunsOn = "${{ matrix.runner == 'same-repo-linux' && ((github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) && 'blacksmith-4vcpu-ubuntu-2404' || 'ubuntu-latest') || matrix.runner == 'same-repo-windows' && ((github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) && 'blacksmith-4vcpu-windows-2025' || 'windows-latest') || matrix.runner == 'same-repo-macos' && 'macos-latest' || matrix.os }}"
// --- a minimal GitHub Actions expression evaluator -------------------------
//
// Review SF-3 (2026-10-03) on the F7a review: the original
// TestSameRepoBlacksmithExpressionSemantics ran a hand-written Go
// re-implementation of the same-repo Blacksmith formula against its own
// truth table, then string-compared the pinned consts against a template
// built from the same pieces - a tautology that a change to both the
// template and the const (in the same wrong way) would still pass. This
// evaluator actually parses and evaluates the real `${{ ... }}` expression
// string, for the small subset of the GitHub Actions expression language
// this repo's same-repo Blacksmith ternaries use: string literals, dotted
// identifier lookups (resolved from a caller-supplied context map), ==, !=,
// &&, ||, !, and parentheses. It is not a general-purpose GHA expression
// engine - no functions, no numbers, no object/array literals.
//
// && and || use GitHub's own short-circuit-returns-operand semantics (not
// strict booleans: `false && 'x'` is `false`, not `false`'s boolean negation
// of something), which is exactly what lets a `cond && 'labelA' || 'labelB'`
// ternary evaluate to a string label rather than a bool.
type ghToken struct {
kind string // "ident", "string", "op", "lparen", "rparen", "bang"
val string
}
func ghTokenize(s string) ([]ghToken, error) {
var toks []ghToken
i := 0
isIdentByte := func(b byte) bool {
return b == '.' || b == '_' ||
(b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || (b >= '0' && b <= '9')
}
for i < len(s) {
c := s[i]
switch {
case c == ' ' || c == '\t' || c == '\n' || c == '\r':
i++
case c == '(':
toks = append(toks, ghToken{"lparen", "("})
i++
case c == ')':
toks = append(toks, ghToken{"rparen", ")"})
i++
case c == '\'':
j := i + 1
for j < len(s) && s[j] != '\'' {
j++
}
if j >= len(s) {
return nil, fmt.Errorf("unterminated string literal at byte %d in %q", i, s)
}
toks = append(toks, ghToken{"string", s[i+1 : j]})
i = j + 1
case strings.HasPrefix(s[i:], "=="):
toks = append(toks, ghToken{"op", "=="})
i += 2
case strings.HasPrefix(s[i:], "!="):
toks = append(toks, ghToken{"op", "!="})
i += 2
case strings.HasPrefix(s[i:], "&&"):
toks = append(toks, ghToken{"op", "&&"})
i += 2
case strings.HasPrefix(s[i:], "||"):
toks = append(toks, ghToken{"op", "||"})
i += 2
case c == '!':
toks = append(toks, ghToken{"bang", "!"})
i++
default:
j := i
for j < len(s) && isIdentByte(s[j]) {
j++
}
if j == i {
return nil, fmt.Errorf("unexpected character %q at byte %d in %q", c, i, s)
}
toks = append(toks, ghToken{"ident", s[i:j]})
i = j
}
}
return toks, nil
}
type ghParser struct {
toks []ghToken
pos int
ctx map[string]string
}
func (p *ghParser) peek() (ghToken, bool) {
if p.pos >= len(p.toks) {
return ghToken{}, false
}
return p.toks[p.pos], true
}
func (p *ghParser) next() (ghToken, bool) {
tok, ok := p.peek()
if ok {
p.pos++
}
return tok, ok
}
func (p *ghParser) parseExpr() (any, error) { return p.parseOr() }
func (p *ghParser) parseOr() (any, error) {
left, err := p.parseAnd()
if err != nil {
return nil, err
}
for {
tok, ok := p.peek()
if !ok || tok.kind != "op" || tok.val != "||" {
return left, nil
}
p.next()
right, err := p.parseAnd()
if err != nil {
return nil, err
}
if !ghTruthy(left) {
left = right
}
}
}
func (p *ghParser) parseAnd() (any, error) {
left, err := p.parseEquality()
if err != nil {
return nil, err
}
for {
tok, ok := p.peek()
if !ok || tok.kind != "op" || tok.val != "&&" {
return left, nil
}
p.next()
right, err := p.parseEquality()
if err != nil {
return nil, err
}
if ghTruthy(left) {
left = right
}
}
}
func (p *ghParser) parseEquality() (any, error) {
left, err := p.parseUnary()
if err != nil {
return nil, err
}
for {
tok, ok := p.peek()
if !ok || tok.kind != "op" || (tok.val != "==" && tok.val != "!=") {
return left, nil
}
p.next()
right, err := p.parseUnary()
if err != nil {
return nil, err
}
eq := ghEquals(left, right)
if tok.val == "!=" {
left = !eq
} else {
left = eq
}
}
}
func (p *ghParser) parseUnary() (any, error) {
if tok, ok := p.peek(); ok && tok.kind == "bang" {
p.next()
v, err := p.parseUnary()
if err != nil {
return nil, err
}
return !ghTruthy(v), nil
}
return p.parsePrimary()
}
func (p *ghParser) parsePrimary() (any, error) {
tok, ok := p.next()
if !ok {
return nil, fmt.Errorf("unexpected end of expression")
}
switch tok.kind {
case "lparen":
v, err := p.parseExpr()
if err != nil {
return nil, err
}
closing, ok := p.next()
if !ok || closing.kind != "rparen" {
return nil, fmt.Errorf("expected ) in expression")
}
return v, nil
case "string":
return tok.val, nil
case "ident":
v, ok := p.ctx[tok.val]
if !ok {
// An identifier the caller's context does not mention (for
// example a deleted fork's head.repo.full_name) is null in the
// real evaluator; treat it as the empty string, which compares
// unequal to every non-empty literal this repo's expressions use.
return "", nil
}
return v, nil
default:
return nil, fmt.Errorf("unexpected token %+v", tok)
}
}
func ghTruthy(v any) bool {
switch x := v.(type) {
case bool:
return x
case string:
return x != ""
case nil:
return false
default:
return true
}
}
func ghEquals(a, b any) bool {
return fmt.Sprint(a) == fmt.Sprint(b)
}
// evalGHExpr evaluates a GitHub Actions `${{ ... }}` expression (the wrapper
// is optional) against ctx, a map from dotted identifier (e.g.
// "github.event_name") to its string value. See the package comment above
// for the supported subset.
func evalGHExpr(expr string, ctx map[string]string) (any, error) {
expr = strings.TrimSpace(expr)
expr = strings.TrimPrefix(expr, "${{")
expr = strings.TrimSuffix(expr, "}}")
expr = strings.TrimSpace(expr)
toks, err := ghTokenize(expr)
if err != nil {
return nil, err
}
p := &ghParser{toks: toks, ctx: ctx}
v, err := p.parseExpr()
if err != nil {
return nil, err
}
if p.pos != len(p.toks) {
return nil, fmt.Errorf("trailing tokens after expression %q: %v", expr, p.toks[p.pos:])
}
return v, nil
}
// mustEvalGHRunsOn evaluates a `runs-on: ${{ ... }}`-style expression and
// returns the resulting runner-label string, failing the test if the
// expression does not evaluate to a string.
func mustEvalGHRunsOn(t *testing.T, expr string, ctx map[string]string) string {
t.Helper()
v, err := evalGHExpr(expr, ctx)
if err != nil {
t.Fatalf("evalGHExpr(%q): %v", expr, err)
}
s, ok := v.(string)
if !ok {
t.Fatalf("evalGHExpr(%q) = %#v (%T), want string", expr, v, v)
}
return s
}
// TestSameRepoBlacksmithExpressionSemantics runs the real, pinned
// sameRepoBlacksmith{2,4,8}vcpu expression strings through evalGHExpr (not a
// hand-written mirror of their logic) against every event shape the policy
// cares about: trusted same-repo PRs and merge_group get Blacksmith; forks,
// Dependabot, a deleted fork head, and any other event fall back to
// ubuntu-latest. Because this evaluates the actual expression text, a
// semantic typo in any of the three consts (a dropped `!`, a swapped `&&`/
// `||`, a wrong field name) fails this test even if a hand-rolled Go mirror
// would have been edited to match it.
func TestSameRepoBlacksmithExpressionSemantics(t *testing.T) {
const ownRepo = "steveyegge/beads"
type tc struct {
name string
event string
headRepo string // github.event.pull_request.head.repo.full_name; "" = fork or deleted fork head
actor string
wantRunner bool
}
cases := []tc{
{"same-repo PR, human actor", "pull_request", ownRepo, "alice", true},
{"merge_group always Blacksmith", "merge_group", "", "", true},
{"fork PR stays ubuntu-latest", "pull_request", "someone-else/beads", "alice", false},
{"deleted fork head stays ubuntu-latest", "pull_request", "", "alice", false},
{"same-repo PR, dependabot actor stays ubuntu-latest", "pull_request", ownRepo, "dependabot[bot]", false},
{"push stays ubuntu-latest", "push", "", "alice", false},
{"pull_request_target stays ubuntu-latest", "pull_request_target", ownRepo, "alice", false},
{"schedule stays ubuntu-latest", "schedule", "", "", false},
{"workflow_dispatch stays ubuntu-latest", "workflow_dispatch", "", "", false},
}
type constCase struct {
label string // the Blacksmith label the expression resolves to when wantRunner
fallback string // the GitHub-hosted label it falls back to otherwise
expr string
}
consts := []constCase{
{"blacksmith-2vcpu-ubuntu-2404", "ubuntu-latest", sameRepoBlacksmith2vcpu},
{"blacksmith-4vcpu-ubuntu-2404", "ubuntu-latest", sameRepoBlacksmith4vcpu},
{"blacksmith-8vcpu-ubuntu-2404", "ubuntu-latest", sameRepoBlacksmith8vcpu},
{"blacksmith-2vcpu-windows-2025", "windows-latest", sameRepoBlacksmithWindows2vcpu},
{"blacksmith-4vcpu-windows-2025", "windows-latest", sameRepoBlacksmithWindows4vcpu},
{"blacksmith-8vcpu-windows-2025", "windows-latest", sameRepoBlacksmithWindows8vcpu},
{"blacksmith-16vcpu-windows-2025", "windows-latest", sameRepoBlacksmithWindows16vcpu},
{"blacksmith-6vcpu-macos-latest", "macos-latest", sameRepoBlacksmithMacOS6vcpu},
{"blacksmith-12vcpu-macos-latest", "macos-latest", sameRepoBlacksmithMacOS12vcpu},
}
for _, c := range cases {
ctx := map[string]string{
"github.event_name": c.event,
"github.event.pull_request.head.repo.full_name": c.headRepo,
"github.repository": ownRepo,
"github.actor": c.actor,
}
for _, cst := range consts {
t.Run(c.name+"/"+cst.label, func(t *testing.T) {
got := mustEvalGHRunsOn(t, cst.expr, ctx)
want := cst.fallback
if c.wantRunner {
want = cst.label
}
if got != want {
t.Errorf("%s: real evaluator on %q = %q, want %q", c.name, cst.expr, got, want)
}
})
}
}
}
// TestSameRepoPlatformsMatrixMarkerRunsOnExpressionSemantics runs the real,
// pinned sameRepoPlatformsMatrixMarkerRunsOn chained-ternary expression
// (pr-preflight-platforms' and check-doc-freshness-platforms' runs-on, F7b
// §2.1) through evalGHExpr for every (marker, event) combination the policy
// cares about: the linux/windows `runner` markers resolve to that OS's
// Blacksmith label only on a trusted same-repo PR/merge_group, falling back
// to that OS's GitHub-hosted label otherwise; the macos marker always
// resolves to GitHub-hosted macos-latest regardless of trust (F7b review fix
// S3: Blacksmith macOS is ~20x the Linux/Windows rate and has no push-to-main
// cache saver); and a leg with no marker at all (there is none today, but the
// fallback must still be safe) falls back to matrix.os.
func TestSameRepoPlatformsMatrixMarkerRunsOnExpressionSemantics(t *testing.T) {
const ownRepo = "steveyegge/beads"
trustedCtx := map[string]string{
"github.event_name": "pull_request",
"github.event.pull_request.head.repo.full_name": ownRepo,
"github.repository": ownRepo,
"github.actor": "alice",
}
forkCtx := map[string]string{
"github.event_name": "pull_request",
"github.event.pull_request.head.repo.full_name": "someone-else/beads",
"github.repository": ownRepo,
"github.actor": "alice",
}
cases := []struct {
name string
marker string // matrix.runner
os string // matrix.os
ctx map[string]string
wantRunsOn string
}{
{"linux marker, trusted", "same-repo-linux", "ubuntu-latest", trustedCtx, "blacksmith-4vcpu-ubuntu-2404"},
{"linux marker, fork", "same-repo-linux", "ubuntu-latest", forkCtx, "ubuntu-latest"},
{"windows marker, trusted", "same-repo-windows", "windows-latest", trustedCtx, "blacksmith-4vcpu-windows-2025"},
{"windows marker, fork", "same-repo-windows", "windows-latest", forkCtx, "windows-latest"},
// F7b review fix (S3): macOS never resolves to Blacksmith, trusted or not.
{"macos marker, trusted", "same-repo-macos", "macos-latest", trustedCtx, "macos-latest"},
{"macos marker, fork", "same-repo-macos", "macos-latest", forkCtx, "macos-latest"},
{"no marker falls back to matrix.os", "", "some-other-os", trustedCtx, "some-other-os"},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
ctx := map[string]string{}
for k, v := range c.ctx {
ctx[k] = v
}
ctx["matrix.runner"] = c.marker
ctx["matrix.os"] = c.os
got := mustEvalGHRunsOn(t, sameRepoPlatformsMatrixMarkerRunsOn, ctx)
if got != c.wantRunsOn {
t.Errorf("%s: runs-on = %q, want %q", c.name, got, c.wantRunsOn)
}
})
}
}