beads/scripts/conformance_script_test.go
Julian Knutsen 9ecb33a5f9 feat(ci): add served HTTP conformance as Tier 3 of the conformance gate
The served tier (internal/httpclient's served_*_test.go corpus) never ran
in CI, so HIGH 2-5's regressions (and any future ones) would merge
undetected. Add it as Tier 3 of scripts/conformance.sh, the existing
required entrypoint conformance.yml already runs on every PR/push/merge_group
(not a new workflow, not wired through ci-gate.sh's aggregation -- this
repo's convention for this gate is a single standalone job):

  CGO_ENABLED=1 BEADS_TEST_EMBEDDED_DOLT=1 BEADS_HTTP_TEST_REQUIRED=1 \
    go test -timeout=40m ./internal/httpclient/

Left unsharded: Tier 1 and Tier 2 are themselves single unsharded
invocations, and Tier 3 is one Go package, not a multi-package corpus the
repo's existing package-sharding scripts apply to. No Bazel-lane addition:
bazel-coverage's embedded/dolt_server outputs only ever substitute for
main.yml/pr-risk.yml jobs, never for conformance.yml's own job, so there is
no existing Bazel-lane relationship for this gate to extend.

Bumped the job's timeout-minutes 45 -> 100 (30m + 10m + 40m budgeted
sub-timeouts plus checkout/setup-go overhead) and updated the three policy
tests that pin this script/workflow byte-for-byte
(TestConformanceScriptUsesExplicitTimeoutBudgets,
TestConformanceScriptPropagatesGoTestFailures,
TestConformanceWorkflowHasOuterTimeoutBudget), re-included
internal/httpclient/** in both path filters (push and pull_request, kept
identical) since served_*_test.go files are the suite itself and would
otherwise be excluded by the shared !**_test.go negation, and documented the
new filter entry in ci_f7c_advisory_test.go's own-entries map.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-06 09:45:16 +00:00

170 lines
4.6 KiB
Go

package scripts_test
import (
"errors"
"os"
"os/exec"
"path/filepath"
"reflect"
"runtime"
"strconv"
"strings"
"testing"
)
func TestConformanceScriptUsesExplicitTimeoutBudgets(t *testing.T) {
run := runConformanceScript(t, 0, 0)
if run.err != nil {
t.Fatalf("conformance.sh failed: %v\n%s", run.err, run.output)
}
want := [][]string{
{"test", "-tags", "gms_pure_go", "-v", "-timeout", "30m", "./internal/storage/embeddeddolt/", "-run", "TestConformance"},
{"test", "-tags", "gms_pure_go e2e", "-timeout", "10m", "./test/conformance/"},
{"test", "-timeout=40m", "./internal/httpclient/"},
}
if !reflect.DeepEqual(run.calls, want) {
t.Fatalf("go calls = %#v, want %#v", run.calls, want)
}
}
func TestConformanceScriptPropagatesGoTestFailures(t *testing.T) {
tests := []struct {
name string
failCall int
exitCode int
wantCalls int
}{
{name: "tier 1", failCall: 1, exitCode: 41, wantCalls: 1},
{name: "tier 2", failCall: 2, exitCode: 42, wantCalls: 2},
{name: "tier 3", failCall: 3, exitCode: 43, wantCalls: 3},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
run := runConformanceScript(t, test.failCall, test.exitCode)
if got := conformanceExitCode(run.err); got != test.exitCode {
t.Fatalf("exit = %d, want %d; error=%v\n%s", got, test.exitCode, run.err, run.output)
}
if len(run.calls) != test.wantCalls {
t.Fatalf("go call count = %d, want %d; calls=%#v", len(run.calls), test.wantCalls, run.calls)
}
})
}
}
func conformanceExitCode(err error) int {
if err == nil {
return 0
}
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
return exitErr.ExitCode()
}
return -1
}
func TestConformanceWorkflowHasOuterTimeoutBudget(t *testing.T) {
path := filepath.Join(sourceRepoRoot(t), ".github", "workflows", "conformance.yml")
data, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
text := strings.ReplaceAll(string(data), "\r\n", "\n")
want := " conformance:\n" +
" name: Storage backend conformance (embedded Dolt oracle)\n" +
" timeout-minutes: 100\n" +
" runs-on: " + sameRepoBlacksmith4vcpu + "\n"
if !strings.Contains(text, want) {
t.Fatalf("conformance job does not declare the maintained 100-minute outer budget:\n%s", text)
}
}
type conformanceRun struct {
output string
calls [][]string
err error
}
func runConformanceScript(t *testing.T, failCall, failExit int) conformanceRun {
t.Helper()
bash := requireHostTool(t, "bash")
bin := t.TempDir()
stateDir := t.TempDir()
callLog := filepath.Join(stateDir, "go-calls")
if err := os.WriteFile(callLog, nil, 0o600); err != nil {
t.Fatal(err)
}
writeExecutable(t, filepath.Join(bin, "go"), `#!/bin/sh
set -eu
count=0
if [ -s "$GO_CALL_COUNT" ]; then
count="$(cat "$GO_CALL_COUNT")"
fi
count=$((count + 1))
printf '%s\n' "$count" >"$GO_CALL_COUNT"
printf '%s\0' "$#" >>"$GO_CALL_LOG"
printf '%s\0' "$@" >>"$GO_CALL_LOG"
if [ "$count" = "$GO_FAIL_CALL" ]; then
exit "$GO_FAIL_EXIT"
fi
if [ "$count" = 1 ]; then
printf '%s\n' '--- PASS: TestConformance (0.01s)'
fi
`)
root := sourceRepoRoot(t)
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"
}
env := []string{
"PATH=" + os.Getenv("PATH"),
"BEADS_TEST_COMMAND_PATH=" + commandPath,
"HOME=" + statePath,
"LC_ALL=C",
"LANG=C",
"BASH_ENV=",
"ENV=",
"GO_CALL_LOG=" + statePath + "/go-calls",
"GO_CALL_COUNT=" + statePath + "/go-call-count",
"GO_FAIL_CALL=" + strconv.Itoa(failCall),
"GO_FAIL_EXIT=" + strconv.Itoa(failExit),
}
requireShellCommandPath(t, bash, root, env, "go", binPath+"/go")
cmd := bashScriptCommand(bash, "scripts/conformance.sh")
cmd.Dir = root
cmd.Env = env
output, runErr := cmd.CombinedOutput()
log, readErr := os.ReadFile(callLog)
if readErr != nil {
t.Fatal(readErr)
}
return conformanceRun{output: string(output), calls: parseArgvCalls(t, log), err: runErr}
}
func parseArgvCalls(t *testing.T, log []byte) [][]string {
t.Helper()
tokens := strings.Split(string(log), "\x00")
if len(tokens) == 0 || tokens[len(tokens)-1] != "" {
t.Fatalf("invalid NUL-delimited argv log: %q", log)
}
tokens = tokens[:len(tokens)-1]
var calls [][]string
for len(tokens) > 0 {
count, err := strconv.Atoi(tokens[0])
if err != nil || count < 0 || len(tokens) < count+1 {
t.Fatalf("invalid NUL-delimited argv log: %q", log)
}
calls = append(calls, append([]string(nil), tokens[1:count+1]...))
tokens = tokens[count+1:]
}
return calls
}