Review iteration 1 of the relaunched adoption raised six majors. This commit fixes all six. Five are the majors the first adoption's iteration 1 raised. Its fixup, 696803f250 (tag adopt-pr/bd-f5illd/stranded-fixup-696803f250), fixed them but never reached the branch. That fix is ported here onto the contributor's current head, with its reasoning unchanged; the sixth is new. Creates refused what the CLI sends. Every `bd create` carries CreatedBy, a workspace whose config.yaml names a prefix also carries IDPrefix, and the client refused both. - The server stamps created_by from the actor on all three create shapes: batch_create.go and batch_apply.go now match create.go. - The client sends a CreatedBy that names the actor and refuses any other value, which the server's stamp would silently replace. createIssue and the apply create item share refuseUnwirableIssueMembers. - IDPrefix refuses only where the role would act on it: an explicit, unforced id. - `bd create --file` stays refused over http. Dropping its Status was safe but not enough: the batch create still refuses its Provenance and Owner. The markdown.go and batchcreator.go comments that called it servable now say so. keysetFilter ignored AfterPriority. It now compares priority first, mirroring sqlbuild's KeysetPriorityCreatedAtIDPredicate, and a new served case resumes a priority keyset position. AfterID or AfterPriority without AfterCreatedAt no longer reads as a zero-instant position that discarded every row (the AfterID minor). Claim with a patch was refused on a false ledger claim. `claim`, `force_assignee_transfer` and `force_close_policy` now ride updateBody like `force_notes_overwrite`, so a claim with a patch or a version guard is one updateIssue call. A claim ALONE sent to a server that predates the member (#6890) falls back to claimIssue. The three ledger rows are retired, and the served cases parked on them now run. OpenReadOnly returns a writable store. It stays writable, as a documented exception: backends.Backend.OpenReadOnly also serves the root pre-run's classified reads, and `bd ready --claim` writes through that store. The exception is named in the backends.Backend contract, the store_factory invariant and the store doc, and TestReadOnlyOpenServesTheClaimBdReadyMakes pins it. An OpenNonMutating backend hook is the follow-up. Security surface. - http_target.json is in the doctor gitignore template and its required patterns. - BEADS_HTTP_TOKEN and BEADS_HTTP_TOKEN_COMMAND are host-scoped with BEADS_HTTP_CA_FILE's "host[:port]=value" syntax. A value scoped to another server falls through to the next rung, and a command scoped elsewhere never runs. - LoadTarget and SaveTarget refuse a url that carries userinfo, and Target.String drops userinfo. The served Tier 3 had no CI home. The new target //internal/httpclient:httpclient_served_test is an `embedded`-tagged sh_test. It reruns httpclient_test's binary through tools/bazel/go_test_variant.sh with the script's BEADS_TEST_EMBEDDED_DOLT=1 and BEADS_HTTP_TEST_REQUIRED=1, in 24 shards on the embedded lane's race build. bazel.yml's bazel-embedded job already runs `bazel test //... --config=embedded`, so no workflow changes. - -test.timeout=19m, not the script's 40m: Go's own timeout then fires, and dumps every goroutine, before the action's 1200s limit. - TestBazelRetiredLanesCannotBeNarrowed pins its args and env. The new TestConformanceServedTierRunsUnderBazel ties the script's Tier 3 switches to the rule. - The new untagged TestServedTierIsLinkedWhenRequired fails a required run built without cgo, which drops every served file (the sentinel minor). - A first 12-shard run found two test defects; both are fixed. TestServedBatchApplyBoundsTheItemCount's 1000-item apply outlasts the client's 60s per-request timeout under -race, so a race_detector_{on,off}_test.go pair scales its "at bound" half to 150 there, as embeddeddolt's TestBatchApplyContract does. And TestTheCompositionCatchesAWrongParameter's dropped-filter case leaned on rows earlier tests had seeded: run alone, or first in its shard, it failed. It now seeds its own row outside the scope. - conformance.sh, its script test and engdocs/CI_REQUIRED_CHECK_TOPOLOGY.md name the target. Deviations from the review's suggested fixes: - A bare BEADS_HTTP_TOKEN(_COMMAND) fails closed rather than falling back, and the error does not echo the value: a bare token split at an "=" would put token text into the pattern half. Dropping the bare syntax is safe today: the backend has no Register call site and no docs/ page names the variables. - Target.String drops userinfo instead of using url.URL.Redacted, which masks only the password, so a token used as the username would print. - The pre-#6890 claimIssue fallback leaves RowVersion unset instead of borrowing the follow-up read's token. That read is a second snapshot, so its token could postdate a write this claim never saw and arm a guard that should miss; a guard built from the unset token fails closed. Against a current server the claim rides updateIssue, whose `revision` is stitched as for any update. Also fixed: the nit about the completeness failure message, which now says to regenerate the shell, and the offrole.go tombstone comment that named a skip list which no longer exists. Left for follow-up (all latent, since httpclient.Register has no production caller): vocabOnce latching a failed fetch, snapshot holding s.mu across the handshake dial, unchunked graph anchors, private tracker IDs in park owners, and the bounded journal limit above 10000. Validation: - git diff --check; gofmt -l; go vet over internal/httpclient/... and scripts - go test -tags gms_pure_go over internal/httpapi/..., internal/httpclient/..., internal/storage/backends/... and backend/conformance/...; the doctor gitignore tests; the cmd/bd events-journal construction guard; ./scripts - bazel test --config=embedded //internal/httpclient:httpclient_served_test on the lane's remote executors: 24 shards, 702 top-level tests, 632 pass, 70 skip (69 ledgered KNOWN DIVERGENCE, plus TestCAFileHygieneRefusesGroupWritableFile, which finds no supplementary group on the executor), 0 fail, 0 data races; slowest shard 283s. tools/bazel/check_testcases.py --bep passes. - each of the 702 tests run alone (go test -run '^Name$', without -race): 0 fail - the whole tier under go test without -race, with the script's switches and -timeout=40m, before the two test fixes: 633 pass, 69 skip, 0 fail - removing BEADS_HTTP_TEST_REQUIRED from the rule fails both policy tests - bazel test --config=ci over //internal/httpclient/..., //internal/httpapi/..., //scripts/..., //test/docsync/..., //internal/storage/backends/..., //backend/conformance/... and //cmd/bd/doctor/...: 32 tests pass - make ci-pr-lint: nogo native plus windows/darwin, passes Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
224 lines
7.3 KiB
Go
224 lines
7.3 KiB
Go
package scripts_test
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"reflect"
|
|
"regexp"
|
|
"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", "-tags", "gms_pure_go", "-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
|
|
}
|
|
|
|
// The conformance tiers CI runs are Bazel targets, not this script: Tier 1
|
|
// is the embedded lane's embeddeddolt_conformance_{core,audit}_test
|
|
// (TestBazelEmbeddedJobRunsEmbeddedTier pins their flags), Tier 2 the
|
|
// integration lane's //test/conformance:conformance_test, pinned here to the
|
|
// script's tier: both harness files, built under the e2e or integration tag,
|
|
// against the injected non-race bd. Tier 3 is the embedded lane's
|
|
// //internal/httpclient:httpclient_served_test
|
|
// (TestConformanceServedTierRunsUnderBazel). conformance.yml, which ran the
|
|
// script on a GitHub runner, is gone.
|
|
func TestConformanceE2ETierRunsUnderBazel(t *testing.T) {
|
|
root := sourceRepoRoot(t)
|
|
rule := bazelRuleBlock(readPolicyFile(t, root, "test/conformance/BUILD.bazel"), "conformance_test")
|
|
if rule == "" {
|
|
t.Fatal("test/conformance/BUILD.bazel has no conformance_test")
|
|
}
|
|
for _, want := range []string{
|
|
`"e2e_test.go",`,
|
|
`"roundtrip_test.go",`,
|
|
`data = ["//cmd/bd:bd_for_tests"],`,
|
|
`env = {"BEADS_TEST_BD_BINARY": "$(rlocationpath //cmd/bd:bd_for_tests)"},`,
|
|
`tags = ["integration-only"],`,
|
|
} {
|
|
if !strings.Contains(rule, want) {
|
|
t.Errorf("//test/conformance:conformance_test lacks %q:\n%s", want, rule)
|
|
}
|
|
}
|
|
for _, file := range []string{"e2e_test.go", "roundtrip_test.go"} {
|
|
src := readPolicyFile(t, root, "test/conformance/"+file)
|
|
if !strings.HasPrefix(src, "//go:build e2e || integration\n") {
|
|
t.Errorf("test/conformance/%s must build under e2e (scripts/conformance.sh) and integration (the Bazel lane)", file)
|
|
}
|
|
}
|
|
if _, err := os.Stat(filepath.Join(root, ".github", "workflows", "conformance.yml")); err == nil {
|
|
t.Error(".github/workflows/conformance.yml is back; its tiers run under Bazel")
|
|
}
|
|
}
|
|
|
|
// Tier 3's Bazel target runs the script's Tier 3 package, the httpclient
|
|
// go_test binary, with every BEADS_* switch the script sets for it: the one
|
|
// that stands the served corpus up and the one that makes it required. A
|
|
// switch the script gains that the target lacks fails here;
|
|
// TestBazelRetiredLanesCannotBeNarrowed pins the target's args and env
|
|
// exactly.
|
|
func TestConformanceServedTierRunsUnderBazel(t *testing.T) {
|
|
root := sourceRepoRoot(t)
|
|
tier := regexp.MustCompile(`(?m)^((?:[A-Z_]+=\S+ )+)\\\n\s+go test -tags "\$TAGS" -timeout=40m \./internal/httpclient/$`).
|
|
FindStringSubmatch(readPolicyFile(t, root, "scripts/conformance.sh"))
|
|
if tier == nil {
|
|
t.Fatal("scripts/conformance.sh has no Tier 3 `... go test -tags \"$TAGS\" -timeout=40m ./internal/httpclient/` invocation")
|
|
}
|
|
switches := regexp.MustCompile(`\b(BEADS_[A-Z_]+)=(\S+)`).FindAllStringSubmatch(tier[1], -1)
|
|
if len(switches) < 2 {
|
|
t.Fatalf("parsed only %v from Tier 3's env %q", switches, tier[1])
|
|
}
|
|
rule := bazelRuleBlock(readPolicyFile(t, root, "internal/httpclient/BUILD.bazel"), "httpclient_served_test")
|
|
if rule == "" {
|
|
t.Fatal("internal/httpclient/BUILD.bazel has no httpclient_served_test")
|
|
}
|
|
want := []string{`"$(rootpath :httpclient_test)",`, `data = [":httpclient_test"],`, `tags = ["embedded"],`}
|
|
for _, sw := range switches {
|
|
want = append(want, `"`+sw[1]+`": "`+sw[2]+`",`)
|
|
}
|
|
for _, w := range want {
|
|
if !strings.Contains(rule, w) {
|
|
t.Errorf("//internal/httpclient:httpclient_served_test lacks %q:\n%s", w, rule)
|
|
}
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|