beads/scripts/conformance.sh
Eddie the Engineer b32798d1bb fix(httpclient): address #7247 relaunch review iteration 1
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>
2026-10-08 07:47:17 +00:00

71 lines
3.8 KiB
Bash
Executable file

#!/usr/bin/env bash
#
# Local conformance entrypoint, under plain go test:
#
# ./scripts/conformance.sh
#
# Three tiers exercise the storage conformance contract: the in-process
# storage corpus against the embedded-Dolt oracle, the real-binary CLI
# corpus, then the served HTTP client/role corpus against a real server.
# CI runs all three tiers as Bazel targets, remotely:
#
# bazel test --config=embedded //internal/storage/embeddeddolt:embeddeddolt_conformance_core_test \
# //internal/storage/embeddeddolt:embeddeddolt_conformance_audit_test
# bazel test --config=integration //test/conformance:conformance_test
# bazel test --config=embedded //internal/httpclient:httpclient_served_test
#
set -euo pipefail
cd "$(dirname "$0")/.."
TAGS="gms_pure_go"
# assert_conformance_passed LOGFILE LABEL
# Fail the gate unless the top-level TestConformance in LOGFILE ran and PASSED. The
# checks MUST anchor to column-0 result lines: `go test -v` indents subtest results, and
# RunAll legitimately skips backend-inapplicable subtests (e.g. Claim concurrency on the
# single-writer embedded-Dolt reference), so an unanchored `--- SKIP: TestConformance`
# grep would match an indented subtest and false-fail the gate even though the top-level
# suite passed. Deletes LOGFILE either way.
assert_conformance_passed() {
local log="$1" label="$2"
if grep -qE '^--- SKIP: TestConformance' "$log" || ! grep -qE '^--- PASS: TestConformance' "$log"; then
rm -f "$log"
echo "FATAL: $label conformance (top-level TestConformance) skipped or did not run; storage-parity gate is not enforced" >&2
exit 1
fi
rm -f "$log"
}
echo "==> Tier 1: in-process store conformance + wedge gates"
# The embedded-Dolt backend runs the full backend-agnostic suite (conformance.RunAll) as
# the reference oracle any future backend is compared against. BEADS_TEST_EMBEDDED_DOLT=1
# is REQUIRED, not optional: without it that suite self-skips
# (internal/storage/embeddeddolt/conformance_test.go), which would let this whole
# storage-parity gate report success while never running the oracle. Run it with -v and
# fail loudly if the top-level TestConformance skips or reports no pass, so the gate can
# never go green on a silent skip.
# (assert_conformance_passed explains why the skip/pass checks anchor to column-0 lines.)
embedded_dolt_log="$(mktemp)"
BEADS_TEST_EMBEDDED_DOLT=1 CGO_ENABLED=1 go test -tags "$TAGS" -v \
-timeout 30m ./internal/storage/embeddeddolt/ -run TestConformance | tee "$embedded_dolt_log"
assert_conformance_passed "$embedded_dolt_log" "embedded-Dolt reference (need BEADS_TEST_EMBEDDED_DOLT=1)"
echo "==> Tier 2: end-to-end 'bd init' + CLI conformance (reference round-trip)"
CGO_ENABLED=1 go test -tags "$TAGS e2e" -timeout 10m ./test/conformance/
echo "==> Tier 3: served HTTP client/role conformance (real server, real wire)"
# The httpclient package's served_*_test.go files are gated by the `cgo`
# build tag (set automatically when CGO_ENABLED=1; no -tags entry needed) and
# self-skip without BEADS_TEST_EMBEDDED_DOLT=1 + BEADS_HTTP_TEST_REQUIRED=1 --
# the latter is a fail-loud guard (not a silent skip) if it's set without the
# former, so a misconfigured env can't report a false green here either.
# Nor can a build with cgo off, which drops every served file: the package's
# untagged TestServedTierIsLinkedWhenRequired fails a required run then.
# Here the tier is one unsharded invocation, like Tier 1 and Tier 2 above;
# -timeout=40m matches the budget the review asked for. The embedded lane's
# httpclient_served_test runs the same package and env on the race build,
# split into shards (rules_go deals the tests out round-robin) so each fits
# the lane's 1200s action limit.
CGO_ENABLED=1 BEADS_TEST_EMBEDDED_DOLT=1 BEADS_HTTP_TEST_REQUIRED=1 \
go test -tags "$TAGS" -timeout=40m ./internal/httpclient/
echo "==> conformance OK"