beads/scripts/pull_dolt_image_test.go
Julian Knutsen 0588af25d1
ci: retire pr.yml's legacy PR Core, build, pure-Go, domain+uow and contract jobs where the gated Bazel lanes run them (D2 step 3) (#7097)
* ci: retire pr.yml's legacy PR Core, build, pure-Go, domain+uow and contract jobs where the gated Bazel lanes run them (D2 step 3)

On same-repo, non-Dependabot pull_requests while the committed
BAZEL_RETIRES_LEGACY_PR_LANES flag is "true" (bazel-coverage's new
pr_lanes output; the job stays identical in pr.yml and pr-risk.yml),
pr.yml's build-artifacts, pr-core-wrapper, check-cmd-bd-puregeo-tests,
test-domain-uow and contract-corpus stand down. ci-gate accepts those
skips only then, and BAZEL_PR_LANES_RETIRED requires the same run's
Bazel test, pure-Go/js-wasm and dolt-server lanes to have run remotely
and passed. Revert: commit the flag "false" in both workflows.

What the retired jobs did besides their tests keeps running on every PR:
- the package gates take bazel-ci-build-artifacts (bazel-test's bd, same
  layout) where build-artifacts stands down;
- the Dolt server fingerprint moves to its own required job;
- the Go tests Bazel does not run or skips (equivalence allowlist) run
  under go test in pr-preflight-platforms' Linux leg, each required to
  pass (tools/bazel/run_allowlisted_go_tests.py).

In mode remote the three lanes' bazel test invocations add
--config=sole-run (no cached test results, no whole-invocation retry on
remote cache eviction), as steps 1 and 2 do for their lanes.

Policy tests: decision matrix and named cases extended to the third
flag, gate simulation for the pr.yml tier, artifact consumers, pinned
lane steps and rc lines, a repo-wide narrowing scan of BUILD rules and
.bzl files, and the allowlisted-test runner.

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

* docs(ci): record the retired pr.yml PR Core, build, pure-Go, domain+uow and contract jobs in the check topology

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

* test(ci): only pr.yml's workflow env sets a BAZEL_RETIRES_* flag, and only the decision step reads one

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

* ci(pr): keep go test ./scripts/..., go test's vet and the Bazel-skipped tests on every PR (D2 step 3 review F1, F1b, F3, L2)

Review of D2 step 3: retiring PR Core removed the only required pre-merge
`go test` of the scripts packages, whose policy tests (the D2 guards
among them) check part or all of their rules under go test only, and
go test's implicit vet for every package (rules_go's go_test runs none).

New required job scripts-go-checks (SCRIPTS_GO_CHECKS), on every PR, in
PR Core's environment (dolt, git and dolt identity, test-env):
- scripts/ci/scripts-go-test.sh: `go test ./scripts/...` with PR Core's
  flags;
- scripts/ci/go-test-vet.sh: `go vet` with cmd/go's defaultVetFlags over
  ./..., policy-tested equal to the running toolchain's list;
- scripts/ci/allowlisted-go-tests.sh, moved here from
  pr-preflight-platforms.

TestBazelOnlySkipsAreAllowlisted also requires every test that runs part
of its checks under go test only (a Bazel-guarded return/continue, or a
go-test-only block that reports failures) to live under ./scripts, the
only packages go test still runs on every PR; and step 3's
TestRunAllowlistedGoTestsScript gets its allowlist entry.

Package gates on a covered PR whose Bazel call did not run remotely (the
farm switch off) now fail in their own step naming
BAZEL_PR_LANES_RETIRED instead of on a missing artifact (L2).

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

* docs(ci): record scripts-go-checks, the skip-allowlist check and the re-run-safe uploads for D2 step 3

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 Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-02 06:08:52 -07:00

200 lines
5.4 KiB
Go

package scripts_test
import (
"errors"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
"testing"
)
const doltSQLServerImage = "dolthub/dolt-sql-server:2.2.0"
func TestPullDoltImageRetriesTransientFailures(t *testing.T) {
tests := []struct {
name string
failures int
wantExit int
wantPulls int
wantSleeps int
}{
{name: "immediate success", failures: 0, wantExit: 0, wantPulls: 1, wantSleeps: 0},
{name: "eventual success", failures: 2, wantExit: 0, wantPulls: 3, wantSleeps: 2},
{name: "exhausted retries", failures: 3, wantExit: 42, wantPulls: 3, wantSleeps: 2},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
run := runPullDoltImage(t, test.failures)
if got := pullDoltExitCode(run.err); got != test.wantExit {
t.Fatalf("exit = %d, want %d; error=%v\n%s", got, test.wantExit, run.err, run.output)
}
if len(run.dockerCalls) != test.wantPulls {
t.Fatalf("docker pull count = %d, want %d; calls=%q\n%s", len(run.dockerCalls), test.wantPulls, run.dockerCalls, run.output)
}
for _, call := range run.dockerCalls {
if call != "pull "+doltSQLServerImage {
t.Fatalf("docker call = %q, want %q", call, "pull "+doltSQLServerImage)
}
}
if len(run.sleepCalls) != test.wantSleeps {
t.Fatalf("sleep count = %d, want %d; calls=%q\n%s", len(run.sleepCalls), test.wantSleeps, run.sleepCalls, run.output)
}
for _, call := range run.sleepCalls {
if call != "5" {
t.Fatalf("sleep call = %q, want 5", call)
}
}
})
}
}
func TestDoltImagePullWorkflowsUseRetryHelper(t *testing.T) {
wantCalls := map[string]int{
"main.yml": 2,
"pr.yml": 3, // test-domain-uow, contract-corpus, test-dolt-server-fingerprint
"pr-risk.yml": 3,
"regression.yml": 1,
}
workflowsDir := filepath.Join(sourceRepoRoot(t), ".github", "workflows")
for name, want := range wantCalls {
data, err := os.ReadFile(filepath.Join(workflowsDir, name))
if err != nil {
t.Fatal(err)
}
text := string(data)
if got := strings.Count(text, "run: ./scripts/ci/pull-dolt-image.sh"); got != want {
t.Errorf("%s retry-helper calls = %d, want %d", name, got, want)
}
}
workflowPaths, err := filepath.Glob(filepath.Join(workflowsDir, "*.y*ml"))
if err != nil {
t.Fatal(err)
}
for _, path := range workflowPaths {
data, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
if strings.Contains(string(data), "docker pull "+doltSQLServerImage) {
t.Errorf("%s still pulls the Dolt image without retries", filepath.Base(path))
}
}
}
func TestPullDoltImageHelperIsExecutable(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Windows does not preserve Unix executable bits")
}
path := filepath.Join(sourceRepoRoot(t), "scripts", "ci", "pull-dolt-image.sh")
info, err := os.Stat(path)
if err != nil {
t.Fatal(err)
}
if info.Mode().Perm()&0o111 == 0 {
t.Fatalf("%s is not executable", path)
}
}
type pullDoltRun struct {
output string
dockerCalls []string
sleepCalls []string
err error
}
func runPullDoltImage(t *testing.T, failures int) pullDoltRun {
t.Helper()
bash := requireHostTool(t, "bash")
bin := t.TempDir()
stateDir := t.TempDir()
dockerLog := filepath.Join(stateDir, "docker-calls")
sleepLog := filepath.Join(stateDir, "sleep-calls")
for _, path := range []string{dockerLog, sleepLog} {
if err := os.WriteFile(path, nil, 0o600); err != nil {
t.Fatal(err)
}
}
writeExecutable(t, filepath.Join(bin, "docker"), `#!/bin/sh
set -eu
count=0
if [ -s "$DOLT_PULL_CALL_COUNT" ]; then
IFS= read -r count <"$DOLT_PULL_CALL_COUNT"
fi
count=$((count + 1))
printf '%s\n' "$count" >"$DOLT_PULL_CALL_COUNT"
printf '%s\n' "$*" >>"$DOLT_PULL_DOCKER_LOG"
if [ "$count" -le "$DOLT_PULL_FAILURES" ]; then
exit 42
fi
`)
writeExecutable(t, filepath.Join(bin, "sleep"), `#!/bin/sh
set -eu
printf '%s\n' "$*" >>"$DOLT_PULL_SLEEP_LOG"
`)
pathEnv := shellPathEnv()
binPath := shellPathUnderEnv(t, bash, bin, pathEnv)
statePath := shellPathUnderEnv(t, bash, stateDir, pathEnv)
commandPath := binPath + ":" + os.Getenv("PATH") + ":/usr/bin:/bin"
if runtime.GOOS == "windows" {
commandPath = binPath + ":/usr/bin:/bin"
}
root := sourceRepoRoot(t)
env := []string{
"PATH=" + os.Getenv("PATH"),
"BEADS_TEST_COMMAND_PATH=" + commandPath,
"LC_ALL=C",
"LANG=C",
"BASH_ENV=",
"ENV=",
"DOLT_PULL_CALL_COUNT=" + statePath + "/docker-call-count",
"DOLT_PULL_DOCKER_LOG=" + statePath + "/docker-calls",
"DOLT_PULL_SLEEP_LOG=" + statePath + "/sleep-calls",
"DOLT_PULL_FAILURES=" + strconv.Itoa(failures),
}
requireShellCommandPath(t, bash, root, env, "docker", binPath+"/docker")
requireShellCommandPath(t, bash, root, env, "sleep", binPath+"/sleep")
cmd := bashScriptCommand(bash, "scripts/ci/pull-dolt-image.sh")
cmd.Dir = root
cmd.Env = env
output, runErr := cmd.CombinedOutput()
dockerCalls := readCallLines(t, dockerLog)
sleepCalls := readCallLines(t, sleepLog)
return pullDoltRun{output: string(output), dockerCalls: dockerCalls, sleepCalls: sleepCalls, err: runErr}
}
func readCallLines(t *testing.T, path string) []string {
t.Helper()
data, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
text := strings.TrimSpace(string(data))
if text == "" {
return nil
}
return strings.Split(text, "\n")
}
func pullDoltExitCode(err error) int {
if err == nil {
return 0
}
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
return exitErr.ExitCode()
}
return -1
}