* feat(httpclient): lift the HTTP client store and roles from bd-enterprise (MIT contribution)
Contributed by gascity from bd-enterprise (github.com/gascity/bd-enterprise,
internal/enterprise/httpstore @ 49d1df2f6) to OSS beads under the MIT
license, with the owner's explicit approval. Every lifted file carries a
provenance header naming its source path.
Lifted into internal/httpclient: the Store (DoltStorage over the wire), the
dial/register glue, the read roles (reader, querier, counters, edges,
relations, graph, tree, cycles, stats, config, memories, journal), the write
roles (lifecycle, claimer, releaser, deleter, dependency editor, metadata
CAS, commenter, batch closer/creator/applier, ready claimer, sweeper), and
their tests. The store transport seam (WireClient/WireDialer) and the
store-dependent tests deferred from the S2 lift are restored here.
Not lifted: the hosted gateway (httpgw/gwauth), box-login, storage profiles
and gasworks. dial.go only mentions the gateway in comments.
This commit is the mechanical lift and does NOT build yet. It references
enterprise-only APIs absent from OSS: issueops.ReadyLister,
journalops.Watcher, storage.ServerEnforcedPolicy, the
NonCommitGraphBackend/RemoteWorkspaceBackend markers, DoltStorage
differences, and BatchCloseRequest.claim_next. The following commits
reconcile it with OSS (S3/S4/S5).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(httpclient): reconcile the bd-enterprise lift's compile-time API surface against OSS
The mechanical lift (02a9dad17) carried several bd-enterprise-only shapes
that do not exist in OSS beads:
- ReadyLister, journalops.Watcher/StreamWire, and ServerEnforcedPolicy have
no OSS wire counterpart; drop the role, its served/journal-watch tests,
and the policy enforcement path entirely rather than leave dead code that
cannot compile against OSS's apigen types.
- claim_hook_gate_test.go exercised a hook surface OSS does not publish.
- recordingWire/fakeWire no longer embed a StreamWire double now that no
read role can reach a watch stream; testTarget's two conflicting
package-scope declarations (store_test.go and helpers_test.go) are split
apart as pinnedProjectTarget vs. the generic helper.
- unsupported_gen.go is regenerated from scratch against OSS's actual
storage.DoltStorage via a new, from-scratch reflection-based generator
(internal/storage/unsupportedgen) rather than hand-copied from
bd-enterprise's generated output; completeness_test.go's
legitimatelyUnsupported map grows the handful of OSS-only or
previously-missed methods (AddRemoteWithRef, RenameLabel, etc.) this
regeneration surfaces.
- write_ledger_test.go and the divergence ledger doc gain the
force_notes_overwrite and claim pending rows OSS's apigen.UpdateRequest
and SweepRequest actually carry, and drop the Remaining/LiveDependent
assertions SweepResult/SweepSkips have no wire member to ever populate.
go build ./... and go vet ./... are clean after this change. No behavior
beyond the removed surfaces changes here; read-role and write-role
reconciliation land in follow-up commits.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(httpclient): stop sending listIssues a reverse/sort vocabulary OSS does not publish
The bd-enterprise lift's sortedPage pushdown assumed GET /v0/beads/issues
(listIssues) shared the same sort vocabulary and a reverse parameter with
GET /v0/beads/issues:query (handleQueryIssues) -- a different operation.
OSS's openapi.v0.yaml publishes listIssues a CLOSED two-value `sort` enum
(created, priority; deliberately smaller than the nine values :query
takes) and no `reverse` parameter at all. Sending either would earn an
unknown-parameter or invalid_value refusal from the real server, not a
silently-wrong answer -- which is why this only surfaces against a served
backend, not a Go-side unit test of the request builder.
Add listSortPushdownEligible to gate the pushdown fast path to the two
keyset orders listIssues can actually page, unconditionally refusing any
reversed request (listIssues has no parameter that names a reversed
direction, so a reversed request of any order walks and sorts
client-side). Drop the unconditional `reverse` send from sortedPage.
served_list_test.go's three affected cases encoded the wrong,
enterprise-only wire shape (expecting reverse=false on the fallback path,
expecting a reversed order to push down with sort+reverse, and expecting a
Go-side/SQL-side mix in listIssues' sort enum); corrected to match OSS's
actual, provable wire contract rather than left red. list_sort_test.go's
publishedParamEnum helper now reads the OpenAPI document via the
go:embed'd spec.OpenAPIV0() accessor instead of a relative os.ReadFile, so
it no longer depends on the test's working directory (this also fixes the
same test failing under Bazel's sandbox, which does not expose arbitrary
relative-path files).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(httpclient): reconcile write-role tests against OSS's BatchClose/Update shapes
OSS's apigen.BatchCloseRequest and BatchCloseResponse publish no
claim_next/claimed_next member at all (ledger row
W-CloseBatchRequest.ClaimNext) -- bd-enterprise's claim-folded-into-close
shape has no OSS wire counterpart. Replace the three tests that exercised
decoding a served claim (TestBatchCloseRefusesAServedClaimCarryingNoIssue,
TestBatchCloseRefusesAServedClaimTheRequestNeverEarned,
TestBatchCloseKeepsTheClaimItEarned) with
TestBatchCloseRefusesClaimNextUnconditionally, which pins the actual OSS
behavior: a CloseBatchRequest naming ClaimNext refuses before any dial, on
both the unserved and served legs, regardless of what a server would
otherwise answer. Drop the now-dead "claim-next" case and helper claim
variable from TestBatchCloseServesTheSingleItemShapeAndRefusesTheRest.
Also:
- Add the ForceNotesOverwrite case to
TestUpdateRefusesEveryMemberTheWireExcludes's hand-maintained member
map -- a ledgered-pending UpdateRequest member (see
W-UpdateRequest.ForceNotesOverwrite) the lift's test left uncovered.
- Remove write_roles_test.go's duplicate `ptr[T]` generic helper, which
redeclared the one already in helpers_test.go and never compiled.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* test(conformance): pin post-write RowVersion propagation across Update/Close/Reopen
types.Issue.RowVersion is json:"-", so an implementation that forgot to
populate it on the way back from storage would still compile and still
pass every existing content assertion in lifecycle_close_reopen_contract.go
-- none of them read RowVersion. Add
RunLifecycleResultsCarryThePostWriteRowVersion, which chains each write's
result token into the next write's ExpectedVersion (Update -> Close ->
Reopen) with no intervening read, so a dropped or stale token fails closed
on the next write's optimistic-concurrency guard rather than passing
silently.
Register it in role_bundle_cases.go's roleContractCases dispatch table at
its declaration-order position -- TestRoleContractCasesCoverEveryContractCase
was failing because the function existed with no dispatcher entry.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* chore(bazel): sync BUILD files via gazelle for the S3 reconciliation
bazel run //:gazelle after the compile/read-role/write-role reconciliation
commits:
- internal/httpclient/BUILD.bazel: regenerate srcs/deps for the files
added, removed and newly imported above (drops the deleted
policy/journal-watch/readylister files, adds the spec dep for
list_sort_test.go's embedded OpenAPI read). Manually add
`data = glob(["*.go"])` to the go_test rule, matching the idiom already
used by //internal/httpclient/encode: completeness_test.go and
divergence_citation_gate_test.go read their own package's .go sources at
runtime (a regex scan of unsupported_gen.go and an AST walk of the
package directory), and Bazel's go_test sandbox only copies in files a
rule declares as `data` -- `srcs` are compiled away, not left readable.
A `# keep` directive protects the attribute across future gazelle runs
(confirmed gazelle does not manage `data` on this rule).
- internal/storage/BUILD.bazel,
internal/storage/unsupportedgen/BUILD.bazel: pick up the new
from-scratch unsupportedgen generator package.
bazel test //internal/httpclient/... //backend/conformance/... now passes
all 4 targets (previously 4 of the package's tests failed only under
Bazel's sandbox: TestInterfaceCompleteness,
TestTheCountGroupVocabularyMatchesTheSharedOne,
TestFlaglessListSortIsTheSameOrderNamed,
TestDivergenceParkCitationsResolveToLiveLedgerRows).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(conformance): close two pre-existing leg-wiring gaps found while registering http
- RunLifecycleResultsCarryThePostWriteRowVersion (added in 536561124) was
never wired into dolt/embeddeddolt/uow's own lifecycle_close_reopen test
tables, only into the http leg's. TestEveryLegWiresEveryRoleContract
catches this once a fourth leg forces the test to actually run again;
wire the missing t.Run into all three.
- The three StatsReporter "suppressed rows" cases (GateIssues/TemplateIssues
breakdown) were never added to served_graph_aux_test.go even though the
wire already carries both fields end-to-end (types.Statistics is shared
verbatim by apigen.StatsResponse and the client's decode). Wire them; all
three pass over HTTP with no server or client change needed.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* feat(conformance): register the http leg in the role-contract lock
Registers "http" (wiringRoot internal/httpclient) in contractLegRegistry.
The served-surface harness (served_harness_test.go + 16 served_*_test.go
files) already wired 495 of 576 role-contract entrypoints from the
bd-enterprise lift; this change:
- Waives the 3 RunCycleDetectorIncludeTracks* cases: issueops.
DetectCyclesRequest.IncludeTracks has no plumbing on either side of the
wire today (cycles.go always calls DetectCycles with a zero-value
request; the client's DetectCycles ignores its request parameter). No
slice through S13 adds one, so the waiver says a new slice is needed
rather than pointing at an existing one.
- Sets adoptionCeiling: 75 for the remaining, not-yet-wired write-role and
internal-plumbing entrypoints (lifecycle writes, DependencyEditor,
MetadataCAS, Lease, Sweeper, VersionReconciler, Bootstrapper/
InitVerifier, cross-record invariants) that S4 and later write slices
pick up and ratchet down.
- Adds //internal/httpclient:go_srcs to storage_test's data: the leg's
wiring root lives outside internal/storage, and the Bazel sandbox has no
other reason to materialize those sources for a test that reads them at
runtime.
TestEveryLegWiresEveryRoleContract, TestEveryRoleMethodHasAContractCase,
and RunUnsupportedContract (already wired pre-lift in
internal/httpclient/completeness_test.go) all pass for the http leg.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(httpclient): close review's HIGH 2-5 gaps and reconcile their test doubles
HIGH 2 (BatchCloser), HIGH 3 (created_by stamping, absent-parent 404/400,
force_notes_overwrite carriage) and HIGH 4 (CapabilityError now unwraps to a
typed *storage.ErrUnsupported with Capability) were implemented in prior
commits on this branch; this change finishes HIGH 5 and the verification the
review asked for:
- role_reader.go's Reader.Get and bridge.go's raw GetIssue both now stitch
Revision back onto Issue.RowVersion via parseRevision, so a guarded write
built off either read carries the row's real token instead of a decoded
zero. Both are pinned by round-trip served tests that guard a write with
the read's token and require a stale-token replay to refuse.
- Fixed create_test.go's stale assertion that created_by must stay empty
(contradicted the HIGH 3 stamping fix it predated).
- Fixed recordingWire's canned IssueDetails{} response (roles_test.go): it
omitted Revision, which is a required field on every getIssue response
per the OpenAPI spec, and the HIGH 5 stitch now reads it unconditionally.
- Synced internal/httpclient/wire/BUILD.bazel via gazelle: handshake_test.go's
new internal/storage import had no corresponding dep.
- gofmt'd write_roles_test.go's stubWire struct tags.
Verified: served HTTP conformance tier (BEADS_TEST_EMBEDDED_DOLT=1
BEADS_HTTP_TEST_REQUIRED=1 go test ./internal/httpclient/, -timeout=40m)
600 PASS / 0 FAIL / 72 SKIP (all ledgered known-divergence waivers). One
TLS-handshake-timing test failed in that run and passed 3/3 in isolation
(unrelated file, pre-existing flake under machine load, not reproducible).
Also green: default go test (minus the pre-existing, unrelated
TestEngdocsAndRootMarkdownLinks doc-link drift and the environmental
internal/storage/uow dolt-server-spawn hang), bazel build/test for the
touched packages, make api-check, and gofmt/vet.
Live-mutated and reverted 3 guards to confirm their tests are load-bearing:
role_reader.go's RowVersion stitch, bridge.go's RowVersion stitch, and
lifecycle.go's force_notes_overwrite wiring.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* 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>
* fix(httpclient): root-cause and fix the Happy-Eyeballs TLS flake in store_dependent_test.go
TestTransportForSucceedsWithEnvCAFile (and 3 Handshake-based siblings that
assert on a successful dial through a configured CA: SidecarCAFile,
CAFileEnvAgreeingWithSidecarSucceeds, DialWithNilTransportHTTPClientGetsCAInjectedOnACopy)
flaked once with "tls: first record does not look like a TLS handshake".
Root cause: our code, same class S2 already fixed for TransportFor's direct
callers (forceIPv4Loopback in ca_test.go/ca_wrong_ca_test.go). Every server
these tests dial is addressed by hostname "localhost" (ca.startServer
rewrites it there deliberately, so SNI is actually sent), which Go's
default dialer races a tcp6 dial to ::1:<port> against the real tcp4 dial to
127.0.0.1:<port> for (RFC 6555). An unrelated local process already bound to
a colliding ephemeral port on ::1 can occasionally win that race before the
real dial completes, and the client speaks TLS to that unrelated process
instead -- the misleading handshake error, not a real hang or a product bug.
These four tests go through Handshake with DialOptions{} (HTTPClient left
nil deliberately, since that is itself the nil-HTTPClient branch of DialWith
under test), so they never get a *http.Transport back to mutate the way
forceIPv4Loopback's existing callers do. Fixed via warmIPv4OnlyCATransport:
pre-build the target's CA-scoped transport through the same public
TransportFor the product code itself calls (so it lands in the exact
(path, content)-keyed cache transportForFile's cache hit returns), force
tcp4-only on that cached pointer, and let Handshake's own DialWith run
unchanged -- same branch under test, same cached transport, no sleeps, no
retries. Verified with -race -count=50 on all four: 200/200 pass.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(httpclient): refuse DetectCycles(IncludeTracks=true) instead of silently ignoring it
roles_graph.go's httpCycleDetector.DetectCycles took its request as `_`,
forwarding nothing: a caller asking for the widened (tracks-following) walk
silently got the narrower default walk back with no error. listDependencyCycles
has no include_tracks wire parameter at all, so there is no way to honor the
field — only to refuse it loudly or drop it silently. Switch to the typed,
ledger-cited refusal (encode.RefusedError via refuse(), citing new row
"L-cycles-tracks") that CountEdges' own wire bound already uses, add the
ledger row and its Op, regenerate the auto-generated ledger doc, and pin the
behavior with a unit test (no served-tier case needed: the refusal is
pre-dial by design, same reasoning as the existing edge-count bound pin).
Also fix leg_contract_wiring_test.go's cycleTracksWireGapWaiverReason, which
had gone stale: it described the http leg as silently forwarding nothing for
this field, which was true before this change and is not after. The waiver
itself (the three RunCycleDetectorIncludeTracks* contract cases stay unwired
for the http leg) is unaffected — they were never wired, and still are not —
only the reason text needed updating to describe a typed refusal instead of a
silent ignore.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(storage): name the http leg's permanent contract gaps instead of budgeting them
The http leg's role-contract adoption ceiling (internal/storage/contract_leg_registry_test.go)
sat at a flat 75, with a prose "adopting" note that bundled every skip into
one vague bucket — including MetadataCAS, which is in fact fully wired (0
missing cases), a false claim left over from an earlier wiring pass.
Twenty-six of the 75 skips are not S4-and-later work at all: they are
PERMANENT gaps that no future slice closes, because the contract itself has
no publicops role for an HTTP client to route through:
- Importer (4 cases): uow is Importer's one accessor, same precedent the
dolt and embeddeddolt legs already carry (importerOneAccessorWaiverReason).
- RetentionFixture/EpochFixture (15 cases) and CrossRecordInvariantFixture
(7 cases): both fixtures carry raw storage hooks (Resolve, Erase, Mint,
CurrentEpoch, GuardedWrite, EnforceCrossRecordInvariant, ...) with no
publicops field at all. dolt, embeddeddolt and uow wire these because
they ARE the storage engine this address/epoch/retention and
cross-record transaction bookkeeping belongs to; the http leg is a
remote client with none of its own to report. There is no wire surface
for this to ever route through short of a new role being designed from
scratch — a new slice, not a missing test line.
These 26 are now named, reasoned waivers in unwiredContractEntrypoints
(two new reason constants: retentionEpochNoRoleWaiverReason and
crossRecordInvariantNoRoleWaiverReason), and the ceiling drops from 75 to 49
to match. The "adopting" note is rewritten to correctly name every remaining
category under budget (lifecycle writes, DependencyEditor, DualWrite,
Sweeper, VersionReconciler, Bootstrapper/InitVerifier, ExpectedRevision/
Refusal) and to drop the false MetadataCAS claim.
Also documents, at conformanceEntrypointsWiredBy, why a leg wiring a
conformance.RunX reference with every hook left nil would read as "adopted"
by this lock's static source grep while actually running as a skip —
matching the loophole internal/httpclient's divergence_citation_gate_test.go
already closes for skipKnownDivergence call sites. No leg currently does
this (verified by inspection); the note sets the review expectation for
future wiring rather than papering over the gap with no record of the policy.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(licensing): scrub internal program/org naming and a leaked private ID from OSS-visible text
MEDIUM 8 of the S3 ship review: remove licensing-hygiene leaks found by a
read-only repo-wide survey, while leaving every legitimate "Contributed by
gascity from bd-enterprise ... to OSS beads under the MIT license." provenance
header and every genuine public gascity/gastownhall self-reference (the real
OSS org, beads.gascity.com docs domain, RBE infra) untouched:
- Delete release-gates/ga-7psli2-3-1-baseline-cmd-bd-fix-gate.md: the only
file in release-gates/ keyed by a private `ga-` tracker ID instead of the
directory's established public `be-` convention (30 other files), and the
only one leaking internal filesystem paths (/home/jaword/...,
gc-management/.gc/artifacts) and internal routing terms (mayor/mpr,
"deployer session"). Not referenced from anywhere else in the tree.
- .golangci.yml: drop two private `ga-2ltro.12`/`ga-26w10` history citations
used as nolint-comment justifications; reworded to the same explanatory
content without naming a private tracker ID.
- Reword 19 "gc native-program" occurrences (14 files, comments and one
design doc) to drop the internal program name while keeping the "S3
reconciliation (2026-10)" dating they were attached to.
- cmd/bd/if_revision.go, if_revision_test.go, update.go,
update_proxied_server.go: drop literal citations of gascity's private
bdstore_conditional.go classifier (including a test function name,
TestIfRevisionEnvelopeGascityContract -> ...DownstreamContract) while
keeping the substantive explanation of why this envelope's shape is
load-bearing for a downstream consumer.
- internal/httpclient/lifecycle.go: drop a citation of gascity's private
internal/beads/bdstore.go.
- internal/httpclient/dial.go: drop the internal/enterprise/httpgw package
path, keeping "a gateway dialer outside this repo".
- internal/httpclient/register.go: reword away from naming "the enterprise
distribution" while keeping the build-tag-opt-in behavior it documents.
Verified: go build ./..., go vet ./internal/httpclient/... ./cmd/bd/...,
go test ./internal/httpclient/... and ./cmd/bd/... -run TestIfRevision all
pass; TestDivergenceLedgerDocMatchesLedger still passes (ledger.go and its
doc were edited in lockstep). gofmt -l reports no diffs on any touched file.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(httpclient/wire): correct the CapExternalDependencies doc's implied false claim
MEDIUM 9 of the S3 ship review. The old comment on CapExternalDependencies
said this client "has no external-dependency policy layer to gate" and that
"OSS publishes no storage.ExternalDependencyQueryStore-backed client policy
... to compose" immediately after naming bd-enterprise's removed policy.go --
easily misread as "OSS has no external-dependency decorator at all." It does:
internal/storage/externaldeps's decorator is unconditional (no build tag) and
is wired into every local storage chain by cmd/bd/storage_chain.go.
Reworded to say precisely what is and is not true: the decorator exists and
runs for local backends; what this http client lacks is a client-side
composition of that decorator around a remote store, which is moot anyway
because a server advertising this capability already applies the policy
itself before answering. (Rolled in the same "gc native-program" wording
removal from the MEDIUM 8 commit, since both edits touch this comment block.)
A second claim from the same review item -- that OSS is said somewhere not to
serve events:watch -- could not be located despite an exhaustive repo-wide
search (this file, engdocs/, docs/reference/events-journal.md,
SERVE_RUNBOOK.md, the divergence ledger, CHANGELOG.md, and a dedicated
read-only research pass). internal/httpapi/events_watch.go,
routes.go's events.watch route entry, and internal/httpclient/wire/stream.go
all confirm OSS serves it unconditionally (gated only per-workspace by the
events journal setting, not by build/distribution). No corresponding false
claim exists in this worktree to fix; noting this rather than editing
something that already reads correctly.
Verified: go build ./internal/httpclient/..., go vet, go test
./internal/httpclient/wire/... pass. gofmt -l clean.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* test(unsupportedgen): add a freshness check for the generated shell
LOW item from the S3 ship review: internal/storage/unsupportedgen had no
tests of its own, so the generator could drift from the checked-in
internal/httpclient/unsupported_gen.go (a storage.DoltStorage interface
change, or a hand-written method added/removed on Store) with nothing to
catch it short of a human noticing the diff. TestInterfaceCompleteness
(completeness_test.go) already pins which methods belong in the shell by
name, but not whether the checked-in bytes match what the generator would
produce today.
TestGeneratedShellIsFresh runs the same scan-then-generate pipeline main()
runs for the registered DoltStorage/httpclient/Store consumer and diffs the
result against the checked-in file -- mirrors the existing
TestDivergenceLedgerDocMatchesLedger pattern in
internal/httpclient/encode/ledger_render_test.go. Added
TestScanHandWrittenMethodsExcludesOwnOutput alongside it to pin the
correctness property the freshness check depends on (scanning must not see
the generator's own prior output as hand-written).
BUILD.bazel: added the go_test rule by hand (gazelle cannot infer the
cross-package `data` dependency a relative-path os.ReadFile needs under the
Bazel sandbox) with data = ["//internal/httpclient:go_srcs"], following the
existing cross-package data pattern in
internal/httpclient/encode/BUILD.bazel. Placed go_test before the
go_srcs.py-managed filegroup block, which `make bazel-sync-check` requires.
Verified: `bazel run //:gazelle` leaves the rule untouched, `bazel test
//internal/storage/unsupportedgen:unsupportedgen_test` passes, `make
bazel-sync-check` is clean, go build/vet/test ./... all pass.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(httpclient/encode): scrub a private tracker-ID cluster from the shipped divergence-ledger doc
Follow-up to the MEDIUM 8 licensing scrub: internal/httpclient/encode's
ledger_render.go header and ledger.go's comments/pinnedElsewhere constant/two
Why strings cited "ga-b8ddd.12/.19/.23/.30" by name. These feed directly into
engdocs/design/http-divergence-ledger.md -- a shipped, generated OSS design
doc, the most visible surface this private ID cluster reached (Fork A's
MEDIUM 8 survey found ~40 occurrences of "ga-b8ddd" across the httpclient
package; this commit addresses the subset inside package encode that is
checked-in prose/doc text, not test-fixture or assertion values). Reworded to
keep the same substantive explanation (what closed, what's still deferred,
which dual run resolved L17) without naming the private ID.
The remaining ~30 occurrences of "ga-b8ddd" outside package encode
(offrole.go, metadata.go, store.go, roles_test.go, wire/*_test.go,
served_*_test.go) are left for a follow-up pass: scrubbing them individually
needs the same per-file verification this commit did, and is a larger,
separate blast radius than was practical in this pass.
Regenerated engdocs/design/http-divergence-ledger.md via
`go test ./internal/httpclient/encode -run TestDivergenceLedgerDocMatchesLedger
-update-ledger-doc`; diff confirmed only the ga-b8ddd text changed. go build
./..., go vet ./internal/httpclient/..., and go test ./internal/httpclient/...
all pass.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* docs(httpclient): drop a private host reference from a test comment
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* revert(licensing): keep the scrub to the contributed client code
The previous scrub also edited upstream files this PR doesn't otherwise
touch (.golangci.yml, cmd/bd --if-revision files from #7203) and deleted an
upstream release-gate record. Restore them; the provenance scrub applies only
to the code contributed from bd-enterprise.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* feat(httpclient): wire S8 count-scope fields on the client
Encode ParentID/NoParent/ExcludeTypes/ExcludeStatus onto countIssues
(table.go + encode.go), add issues.count.scope to the client capability
table (wire/handshake.go, wire/vocabulary_test.go), and refuse locally
before dialing when the server hasn't advertised the token and any scope
field is set (counter.go's refuseUnservedScope), returning a typed
*storage.ErrUnsupported{Capability:"issues.count.scope"} rather than
dropping fields or taking a guaranteed-400 round trip.
Adds encoding-parity coverage (counts_test.go), a masked-token skew test
proving the pre-dial refusal and zero dials (counts_test.go), roundtrip
and skew-table fixes for the newly-encoded fields (encode/roundtrip_test.go,
encode/skew.go), and wires S8's nine shared Counter conformance cases into
the served http leg (served_counter_test.go), including AddDependency so
the wisp/compose cases run instead of skipping. List stays nil on this
fixture since listTable() has pre-existing, unrelated permanent refusals
for ListRequest.NoParent/ExcludeTypes, so the three *MatchesListCardinality
cases skip here by design.
internal/storage's TestEveryLegWiresEveryRoleContract/http ceiling check
remains red (53 skipped vs ceiling 49) after this change, but strictly
improved: before this change the inherited baseline was 62 skipped (13
over ceiling), all nine of S8's new entrypoints unwired. This change wires
all nine, closing exactly that gap; the remaining 4-over are named
RunBootstrapper*/RunDependencyEditor* cases unrelated to count-scope,
pre-existing debt from other already-merged slices whose ceiling was
never bumped for them. Left the ceiling constant alone rather than
raising it to paper over debt this change doesn't own.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(storage): close the http leg's role-contract ceiling regression
TestEveryLegWiresEveryRoleContract/http went red after the rebase (62
skipped, 13 past its ceiling of 49) before any work in this session; the
prior commit closed 9 of those (S8's Counter cases). The remaining 4-over
were RunBootstrapper* (9 entries) and RunDependencyEditor* (2 entries),
both newly-merged contracts this leg had never classified.
RunBootstrapper*: internal/httpclient/accessors.go already names
Bootstrapper PERMANENTLY UNSERVABLE over http (bd init resolves its
substrate identity entirely client-side, before any server exists to
dial) — add a new named waiver, bootstrapperPermanentlyUnservableWaiverReason,
covering all nine entrypoints. VersionReconciler and InitVerifier are
named permanently unservable by the same accessors.go comment but are
left under the ceiling for their own reviewed change, out of scope here.
RunDependencyEditor*: the OSS server already serves add/remove and the
http leg already wires nearly all of DependencyEditor's contract. The two
missing cases (SameTypeReAddWithChangedMetadataMintsOneVersion,
SameTypeReAddWithIdenticalMetadataIsANoOp) only needed
SetVersionedHistoryEnabled wired onto the fixture, the same way
SetJournalEnabled already is — wired it for real; both pass served.
With Bootstrapper waived and DependencyEditor fully wired, the leg's
unwaived-missing count drops from 53 to 42, so adoptionCeiling moves
from 49 to 42 to keep the ratchet exact, with the adopting prose updated
to match.
TestEveryLegWiresEveryRoleContract is green. Served tier (real, CGO +
embedded dolt): 611 PASS, 0 FAIL, 72 SKIP (up from 609). bazel build/test
and make api-check pass for the touched targets.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* build(bazel): auto-sync BUILD files
Applied from the bazel-sync-patch artifact of https://github.com/gastownhall/beads/actions/runs/37307836753
(`make bazel-sync`: gazelle, tools/bazel/go_srcs.py, bazel mod tidy).
Only BUILD.bazel, MODULE.bazel and MODULE.bazel.lock are ever pushed; see
scripts/bazel-autofix-push.sh.
* fix(conformance): pass -tags gms_pure_go to Tier 3's served httpclient run
scripts/conformance.sh:61 ran a bare `go test -timeout=40m ./internal/httpclient/`
for Tier 3 (served HTTP client/role conformance), which `make ci-pr-policy`'s
build-tag policy check refuses ("bare go test without -tags=gms_pure_go").
Pass the same -tags Tier 1 already does, and update
TestConformanceScriptUsesExplicitTimeoutBudgets' pinned argv to match.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(bazel): give //internal/httpclient:httpclient_test room to run
The package takes ~350s under --config=ci (BEADS_TEST_SKIP=dolt, no
BEADS_TEST_EMBEDDED_DOLT) — mostly wall-clock wait on the CA tests'
dialer/keep-alive timeouts, not CPU — but the go_test had no size/timeout
override, so it inherited the medium default's 300s and timed out
intermittently under Bazel (and took "Go test equivalence" down with it).
Set size = "large", timeout = "long", matching
//internal/storage/embeddeddolt's go_test.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(httpclient): fix data race in caContextHandler test helper
TestTransportForRaisesMaxIdleConnsPerHostForBursts drives caContextHandler
with 8 concurrent requests; handler() wrote requestSeen/host/sni from every
server goroutine with no synchronization, and the other nine callers (all
single-request) never exercised the race. go test -race reproduced it as
3x DATA RACE across repeated runs.
Guard the fields with a mutex and expose them only through accessor methods
(sawRequest/seenHost/seenSNI), updating every call site in
store_dependent_test.go accordingly.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(unsupportedgen): canonicalize reflect-visible stdlib aliases
TestGeneratedShellIsFresh fails on Go >= 1.27: encoding/json.RawMessage
became an alias of encoding/json/jsontext.Value, and reflect only ever sees
an alias's underlying type, so formatType rendered
storage.DoltStorage.MergeMetadata's signature with the new, non-portable
name even though the signature itself did not change. A contributor on
1.27 following the freshness test's own advice ("go generate
./internal/httpclient") would commit a shell that does not compile on the
1.26.7 SDK this repo pins.
Add reflectAliasCanonical, a table mapping a reflect-visible alias target
back to the name a human wrote in source, consulted by namedType. Add an
entry here for any future stdlib alias this generator's output needs to
stay stable across.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(httpclient): claimOnlyUpdate propagates the claim's RowVersion
bridge.go's GetIssue already stitches details.Revision onto
hydrated.RowVersion when claimOnlyUpdate rehydrates labels/CreatedBy onto
the claim response, but the claim response itself (issueops.Claimer's
bare-row contract) carries no revision at all, and the copy-back only
touched Labels and CreatedBy. So Lifecycle.Update({Actor, IssueID, Claim:
true}) — `bd update X --claim` — handed back Issue.RowVersion == 0 over
http where the local leg returns the real token, and feeding that into the
next write's ExpectedVersion got a spurious mismatch instead of none.
Copy RowVersion back too. Extend
RunLifecycleResultsCarryThePostWriteRowVersion (shared lifecycle/close/reopen
conformance contract) with a claim-shaped first link in the chain: claim,
then guard the next write with the claim result's own token, proving the
claim-only path populates the real version rather than a nonzero constant.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(httpclient): stitch RowVersion on SearchIssues' exact-id fast path
resolve.go's getIssuesByExactID decodes the same IssueDetails shape
bridge.go's GetIssue does, but never parsed details.Revision the way
GetIssue's own stitch does, so SearchIssues(ctx, "<exact id>") answered
RowVersion 0 — a one-line gap: Issue.RowVersion is json:"-", so the decode
left it at zero, and only the explicit parseRevision stitch recovers it from
the response's own Revision string member.
Add TestSearchIssuesExactIDPopulatesRowVersionForAGuardedWrite, pinning the
same guarded-write round trip TestBridgeGetIssuePopulatesRowVersionForAGuardedWrite
already pins for the plain GetIssue path.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(httpclient): route every write role's refusals through inexpressible
Review finding 7: write-side refusals were not uniformly *ErrUnsupported.
Read roles already wrap encoder refusals through Store.inexpressible, which
reaches both encode.RefusedError and encode.CapabilityError; the write side's
refuse() returned a bare *encode.RefusedError instead, so a caller doing
errors.As(err, &unsupported) caught the count-scope refusal but missed
Sweeper.Sweep(Limit), DetectCycles(IncludeTracks), ReadyClaimer.ClaimNext,
BatchApplier.ApplyBatch, BatchCloser.CloseBatch, Deleter.Delete,
DependencyEditor.AddDependencies, and BatchCreator.CreateBatch.
Give InexpressibleError a detail field that preserves the original error's
composite text (an "items[%d]..." or "Issue.%s:" prefix a deeper encoder
helper already adds) instead of collapsing the message to the bare ledger
row text, and wrap every remaining write role's exported method in a single
named-return defer calling store.inexpressible, matching the pattern
lifecycle.go's Create/Update/Reopen already use.
Add TestWriteRoleRefusalsMatchTheReadShape, pinning three write-side
refusals (Sweeper.Sweep Limit, CycleDetector.DetectCycles IncludeTracks,
ReadyClaimer.ClaimNext) now classify via errors.As(*storage.ErrUnsupported)
the same way a read-side refusal does.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(cmd/bd): stop spelling out Status: StatusOpen on a markdown batch create
Review nit 8: batchcreator.go's refuseUnwirableIssue refuses a populated
Status (apigen.BatchCreateItem has no wire slot for it), and
buildMarkdownBatchRequest always set Status: types.StatusOpen explicitly, so
`bd create --file` refused on every call against an http-backed store.
PreparePublicCreateRequest already defaults an empty Status to StatusOpen on
every backend, including the http client store's own server, so the explicit
assignment here was never a different outcome - only a populated member the
wire can't carry. Leave it unset; the created issue is identical on every
backend, and the http leg's role-level accounting for why Status and
CreatedBy are excluded from its allowlists is documented on
batchCreateCarriedIssueMembers (internal/httpclient/batchcreator.go).
CreatedBy is left as-is: that member genuinely has no wire slot AND the
server does not yet stamp it from Actor (a gap already tracked in this PR's
Follow-ups), so its refusal is correct, not a bug to route around.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* docs(httpapi): correct create.go's CreatedBy comment to caller-asserted
Review nit 8: the comment claimed CreatedBy is stamped from the
"authenticated actor," but actor is parsed straight from the request body
(s.bodyActor) and never authenticated - exactly as this file's own doc
comment states a few lines above. Reword to "caller-asserted actor" and
cross-reference that doc comment so the two stay consistent. No behavior
change: the stamp itself and its test coverage were already correct.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(httpclient): raise MaxIdleConnsPerHost for a supplied client's nil Transport
Review nit 8: DialWith's doc comment promises the raised MaxIdleConnsPerHost
ceiling on every dial, "whether or not a CA is configured," but the
opts.HTTPClient.Transport == nil arm only injected a transport when the
target's CA was configured (resolved.configured()). A caller-supplied
*http.Client with a nil Transport and no CA fell through untouched, so it
defaulted to http.DefaultTransport's own ceiling of 2 at request time instead
- silently exempting this one shape from the doc's promise and forcing a
fresh TLS handshake on most of a concurrent burst even once the pool is warm.
Route this arm through the same dialTransport helper the opts.HTTPClient ==
nil arm above already uses (the CA-scoped transport when a CA is configured,
the shared baseline otherwise), injected onto a copy so the caller's own
*http.Client fields (Timeout, CheckRedirect, Jar) stay untouched.
Add TestDialWithSuppliedClientNilTransportNoCARaisesMaxIdleConnsPerHost: an
end-to-end burst through wire.Client.Do, traced with httptrace, asserting the
connection pool settles into reuse at a burst size the default ceiling of 2
cannot sustain.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* docs(httpclient): stop citing nonexistent design docs from new source files
Review nit 8: several comments added by this lift cited
engdocs/design/http-client-backend.md, "D8 row N", and beads-design/slices.json
- none of which exist in this repository (the design lived in the
bd-enterprise-internal source this code was lifted from).
Point each citation at what actually ships in-repo instead:
engdocs/design/http-divergence-ledger.md (the generated, human-readable
rendering of the divergence ledger in encode/ledger.go) for the D7/D8/D9
discipline citations in encode.go, ledger.go, bijection_test.go,
write_ledger_test.go, wire/credential.go and store.go's package doc; and a
direct description of the wire-gap it records, rather than a slices.json
scope reference, in leg_contract_wiring_test.go's cycle-tracks waiver
rationale. Regenerate http-divergence-ledger.md from ledger_render.go (which
had the same stale citation) via
`go test ./internal/httpclient/encode -run TestDivergenceLedgerDocMatchesLedger -update-ledger-doc`
so the shipped doc and its generator agree.
No behavior change; comment and generated-doc text only.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* feat(httpclient): implement issueops.BatchGetter for the HTTP client leg
The rebase onto origin/main (item 9 of PR #7247's review) brought in
upstream #7248's new issueops.BatchGetter role on storage.DoltStorage,
breaking the HTTP client leg's interface satisfaction. This wires it up
as a read role (no actor, no version guard, writes nothing — dialed as
a POST only because MaxGetManyIDs ids cannot ride a GET query string),
mirroring Counter/Querier rather than the WriteWire-wrapped roles.
- wire/paths.go: add PathIssuesBatchGet ("/v0/beads/issues:batchGet").
- batchgetter.go: httpBatchGetter.GetMany dials the server and stitches
each resolved issue's RowVersion from apigen.BatchGetIssue.Revision
(the role's only wire spelling of the row token, since RowVersion is
json:"-"). checkGetManyIDs pre-validates the cap and blank-id rules,
in the same order internal/storage/issueops.ValidateGetManyRequest
applies them, because batch_get.go's failBatchGetErr collapses every
validation failure into one generic, code-less InvalidArgument the
client could never decode back into *issueops.TooManyIDsError.
- accessors.go: add the BatchGetter() accessor (26th wire-backed role).
- unsupported_gen.go: regenerated, dropping the now-implemented stub.
- completeness_test.go: move BatchGetter into wireBackedAccessors and
bump the asserted accessor-matrix total from 28 to 29.
- served_test.go / served_harness_test.go: both package-local "by hand"
httpapi.Config builders (serveRoles, serveConfig) now wire
cfg.BatchGetter, fixing ~56 served-tier tests that broke once
BatchGetter joined httpapi.Listen's required role set.
- served_batch_getter_test.go: wire the HTTP leg into all 14
backend/conformance.RunBatchGetterXxx cases, following
served_graph_counter_test.go's pattern. This surfaced a real bug:
GetMany built Missing via append([]string(nil), body.Missing...),
which stays nil when the server reports no misses, violating the
role's "Missing is never nil on success" contract — fixed to build
via make([]string, len(body.Missing)) + copy.
Verified: go build/vet clean; internal/httpclient suite green
(including the embedded-dolt served tier); TestEveryLegWiresEveryRoleContract
holds the http leg's adoption ceiling at exactly 42 with no change needed;
TestInterfaceCompleteness and TestAccessorMatrixMatchesDesign pass.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* build(bazel): auto-sync BUILD files
Applied from the bazel-sync-patch artifact of https://github.com/gastownhall/beads/actions/runs/37450731721
(`make bazel-sync`: gazelle, tools/bazel/go_srcs.py, bazel mod tidy).
Only BUILD.bazel, MODULE.bazel and MODULE.bazel.lock are ever pushed; see
scripts/bazel-autofix-push.sh.
* test(httpclient): lock contextServer.seen against concurrent handler goroutines
TestDialWithSuppliedClientNilTransportNoCARaisesMaxIdleConnsPerHost drives
the stub with bursts of 8 concurrent requests; the handler appended to
seen without a lock. Readers only look at seen after their requests return.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* build(bazel): sync go_srcs managed blocks for unsupportedgen after the main merge
The PR adds internal/storage/unsupportedgen on a base that predates #7320,
which gave every Bazel package a managed repo_files filegroup. On the merge,
`python3 tools/bazel/go_srcs.py --check` (TestBazelGoSrcsBlocksCurrent) found
3 stale blocks: the package's own repo_files block, its entry in the root
BUILD.bazel repo_files list, and its entry in tools/bazel/BUILD.bazel.
`make bazel-sync` regenerated exactly those; gazelle changed nothing else.
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>
* fix(httpclient): refuse DepAddItem.HasSpawner and ThreadID on applyBatch after the main merge
Main's #7209 gave issueops.DepAddItem two members, HasSpawner and
ThreadID, and a conformance case, RunBatchApplyStampsSpawnerIDOnlyWhenNamed.
ApplyDepAddItem on the v0 wire publishes source, target, type and
metadata only, so on the merge the http leg dropped both silently and
two of the PR's gates went red:
- TestEveryWireExcludedWriteMemberCarriesALedgerRow: the reflective
census found two wire-excluded DepAddItem members with no ledger row.
- TestEveryLegWiresEveryRoleContract/http: the new case left the leg
at 43 unwired cases against its exact ceiling of 42.
applyDepAddItemBody now refuses each member where the role would store
something the wire cannot say, under two new KindRefuse rows,
W-DepAddItem.HasSpawner and W-DepAddItem.ThreadID. The spawner flag
refuses only on a waits-for edge, because the role ignores it on every
other type and stores the same row either way. The ledger doc is
regenerated (264 rows).
The served tier wires the new case as a park on W-DepAddItem.HasSpawner,
owned by the family's existing bead, which brings the http leg back to
its ceiling. With the skip removed the case fails on the client's
refusal; with the refusal also removed it fails on the drop the row
names: spawner_id "" where the role stamps the resolved target.
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>
* 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>
---------
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Eddie the Engineer <adopt-pr@gascity.com>
1396 lines
60 KiB
Go
1396 lines
60 KiB
Go
package scripts_test
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"reflect"
|
|
"regexp"
|
|
"sort"
|
|
"strconv"
|
|
"strings"
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
// ga-96smfk.22: the Linux Go test tiers run only as pr.yml's Bazel lanes
|
|
// (bazel.yml). PR Risk's legacy embedded, proxied and server-Dolt jobs and
|
|
// pr.yml's PR Core, build-artifacts and pure-Go/js-wasm jobs are gone, with
|
|
// the bazel-coverage decision and the BAZEL_RETIRES_LEGACY_* /
|
|
// BAZEL_COVERS_FORKS flags that chose between them and the lanes. So on
|
|
// every pull_request and merge group pr.yml's gate requires the lanes to
|
|
// have run remotely on rbe-west (BAZEL_REMOTE) and passed: no execution mode
|
|
// can leave the gate green with a tier unrun.
|
|
|
|
const (
|
|
prRiskWorkflowName = "pr-risk.yml"
|
|
prRiskPullRequestValue = "${{ github.event_name == 'pull_request' }}"
|
|
// The decision's Dependabot test: Dependabot runs get no Actions
|
|
// secrets, so bazel.yml's rbe job sends them to rbe-fork like forks.
|
|
prRiskDependabotValue = "${{ github.actor == 'dependabot[bot]' }}"
|
|
// pr.yml's gate id for "the Bazel lanes ran remotely".
|
|
bazelRemoteGateID = "BAZEL_REMOTE"
|
|
)
|
|
|
|
// rbeFacts: what GitHub evaluates bazel.yml's rbe step's env expressions on.
|
|
type rbeFacts struct {
|
|
event string // github.event_name
|
|
rbeVar string // vars.RBE_WEST_WORKERS ("" = unset)
|
|
secret string // secrets.RBE_WEST_EXECUTOR ("" = unavailable: fork, Dependabot, unset)
|
|
fork bool // github.event.pull_request.head.repo.fork
|
|
// github.actor is dependabot[bot] (fixed for a PR's runs and re-runs).
|
|
dependabot bool
|
|
// What rbe-fork-mint's /v1/status answers this run (bazelTestMintEnv;
|
|
// "" = unreachable). Only fork and Dependabot pull_request runs ask.
|
|
mint string
|
|
}
|
|
|
|
func (f rbeFacts) String() string {
|
|
return fmt.Sprintf("event=%s var=%q secret=%v fork=%v dependabot=%v mint=%q",
|
|
f.event, f.rbeVar, f.secret != "", f.fork, f.dependabot, f.mint)
|
|
}
|
|
|
|
// forkPR: a run that asks rbe-fork-mint (bazel.yml's rbe job).
|
|
func (f rbeFacts) forkPR() bool { return f.event == "pull_request" && (f.fork || f.dependabot) }
|
|
|
|
// rbeMintAnswers: the mint states every forkPR fact is tried with.
|
|
var rbeMintAnswers = []string{"", "closed", "ro", "rw"}
|
|
|
|
var (
|
|
// The events pr.yml's gate runs on.
|
|
rbeGateEvents = []string{"pull_request", "merge_group"}
|
|
rbeVarValues = []string{"", "true", "True", "TRUE", "false", "1", "yes"}
|
|
rbeSecrets = []string{"", "grpcs://rbe.example:443"}
|
|
)
|
|
|
|
// rbeGateFactsMatrix: every combination of the facts bazel.yml's rbe step
|
|
// reads, for the events pr.yml's gate runs on; the mint answers only matter
|
|
// to forkPR facts.
|
|
func rbeGateFactsMatrix() []rbeFacts {
|
|
var out []rbeFacts
|
|
for _, event := range rbeGateEvents {
|
|
for _, v := range rbeVarValues {
|
|
for _, secret := range rbeSecrets {
|
|
for _, fork := range []bool{false, true} {
|
|
for _, dependabot := range []bool{false, true} {
|
|
f := rbeFacts{event, v, secret, fork, dependabot, ""}
|
|
if !f.forkPR() {
|
|
out = append(out, f)
|
|
continue
|
|
}
|
|
for _, m := range rbeMintAnswers {
|
|
f.mint = m
|
|
out = append(out, f)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
// evalRBEExpr evaluates the env expressions the decision steps may use, for
|
|
// a bazel.yml call with these inputs (with: the caller's `with:`; unset
|
|
// inputs take their defaults). GitHub's == on strings is case-insensitive.
|
|
// Any other expression fails the test, so the simulation cannot silently
|
|
// drift from the workflows.
|
|
func evalRBEExpr(t *testing.T, expr string, f rbeFacts, with map[string]string) string {
|
|
t.Helper()
|
|
input := func(name, def string) string {
|
|
if v, ok := with[name]; ok {
|
|
return v
|
|
}
|
|
return def
|
|
}
|
|
switch expr {
|
|
case "${{ github.event.pull_request.number }}":
|
|
if f.event == "pull_request" || f.event == "pull_request_target" {
|
|
return "7123"
|
|
}
|
|
return ""
|
|
case prRiskPullRequestValue:
|
|
return strconv.FormatBool(f.event == "pull_request")
|
|
case prRiskDependabotValue:
|
|
return strconv.FormatBool(f.dependabot)
|
|
case "${{ vars.RBE_WEST_WORKERS == 'true' }}":
|
|
return strconv.FormatBool(strings.EqualFold(f.rbeVar, "true"))
|
|
case "${{ inputs.rbe == 'off' }}":
|
|
return strconv.FormatBool(strings.EqualFold(input("rbe", "on"), "off"))
|
|
case "${{ inputs.rbe == 'cache' }}":
|
|
return strconv.FormatBool(strings.EqualFold(input("rbe", "on"), "cache"))
|
|
case "${{ github.event.pull_request.head.repo.fork == true }}":
|
|
return strconv.FormatBool(f.fork)
|
|
case bazelForkFarmValue:
|
|
return strconv.FormatBool(strings.EqualFold(input("fork-farm", "off"), "authorized") &&
|
|
f.event == "pull_request_target" && input("checkout-sha", "") != "")
|
|
case bazelRBESecretValue:
|
|
return strconv.FormatBool(f.secret != "")
|
|
}
|
|
t.Fatalf("decision env expression %q: teach evalRBEExpr how GitHub evaluates it", expr)
|
|
return ""
|
|
}
|
|
|
|
// runDecisionStep runs a decision step's script under GitHub's bash flags
|
|
// with its env evaluated for f, and returns its $GITHUB_OUTPUT.
|
|
func runDecisionStep(t *testing.T, step ciWorkflowStep, f rbeFacts, with map[string]string) (map[string]string, error) {
|
|
t.Helper()
|
|
env := map[string]string{bazelTestMintEnv: f.mint}
|
|
for k, v := range step.Env {
|
|
env[k] = evalRBEExpr(t, v, f, with)
|
|
}
|
|
return runBazelRBEDecision(t, step.Run, env)
|
|
}
|
|
|
|
// prGateFor: pr.yml's ci-gate scenario for one run whose Bazel call took
|
|
// this mode with every lane that runs in it passing.
|
|
func prGateFor(t *testing.T, lanes map[string]map[string]bool, event, mode string) bazelGateScenario {
|
|
t.Helper()
|
|
outputs := map[string]string{}
|
|
for lane, modes := range lanes {
|
|
if modes[mode] {
|
|
outputs[lane] = "success"
|
|
}
|
|
}
|
|
return bazelGateScenario{
|
|
name: fmt.Sprintf("%s mode %s", event, mode), event: event,
|
|
mode: mode, enabled: bazelModeEnabled(mode), call: "success",
|
|
outputs: outputs,
|
|
}
|
|
}
|
|
|
|
// bazelPRCallLanes: the modes each bazel.yml lane runs in under pr.yml's call.
|
|
func bazelPRCallLanes(t *testing.T, with map[string]string) map[string]map[string]bool {
|
|
t.Helper()
|
|
lanes := map[string]map[string]bool{}
|
|
for name, job := range readCIWorkflow(t, bazelWorkflowName).Jobs {
|
|
if name != bazelRBEJobName {
|
|
lanes[name] = bazelLaneRunModes(t, name, job.If, with)
|
|
}
|
|
}
|
|
return lanes
|
|
}
|
|
|
|
// Never a green gate with the Linux Go test tiers unrun: for every fact
|
|
// bazel.yml's rbe step reads on a pull_request or merge group (the farm
|
|
// variable, the executor secret, fork, Dependabot, what rbe-fork's mint
|
|
// answers), pr.yml's actual gate step, with every lane that runs in the
|
|
// decided mode passing, is green exactly when that mode executed the lanes
|
|
// on rbe-west, and a red one names BAZEL_REMOTE. A lane that failed, was
|
|
// cancelled or did not report reds the gate in a remote mode too.
|
|
func TestPRGateRequiresRemoteBazelLanes(t *testing.T) {
|
|
requireHostTool(t, "bash")
|
|
pr := readCIWorkflow(t, "pr.yml")
|
|
call := pr.job(t, "bazel")
|
|
if call.Uses != "./.github/workflows/"+bazelWorkflowName {
|
|
t.Fatalf("pr.yml bazel job uses %q, want the local %s", call.Uses, bazelWorkflowName)
|
|
}
|
|
rbeStep := readCIWorkflow(t, bazelWorkflowName).job(t, bazelRBEJobName).Steps[0]
|
|
gateStep := pr.job(t, "ci-gate").step(t, "Evaluate CI gate")
|
|
lanes := bazelPRCallLanes(t, call.With)
|
|
|
|
required := strings.Fields(gateStep.Env["CI_GATE_REQUIRED"])
|
|
if !contains(required, bazelRemoteGateID) {
|
|
t.Errorf("pr.yml's ci-gate does not require %s", bazelRemoteGateID)
|
|
}
|
|
if _, ok := gateStep.Env[bazelRemoteGateID]; ok {
|
|
t.Errorf("pr.yml's ci-gate env sets %s; only its run script may", bazelRemoteGateID)
|
|
}
|
|
for lane, id := range bazelLaneGateIDs {
|
|
if !lanes[lane]["remote"] {
|
|
t.Errorf("gated lane %s does not run in mode remote", lane)
|
|
}
|
|
if !contains(required, id) && !bazelPackageJobs[lane] {
|
|
t.Errorf("pr.yml's ci-gate does not require %s", id)
|
|
}
|
|
}
|
|
|
|
gateMemo := map[string]bool{}
|
|
saw := map[string]bool{}
|
|
for _, f := range rbeGateFactsMatrix() {
|
|
out, err := runDecisionStep(t, rbeStep, f, call.With)
|
|
if err != nil {
|
|
t.Fatalf("%v: bazel.yml rbe step: %v", f, err)
|
|
}
|
|
mode := out["mode"]
|
|
saw[mode] = true
|
|
key := f.event + "/" + mode
|
|
pass, ok := gateMemo[key]
|
|
if !ok {
|
|
var log string
|
|
pass, log = runPRGateStep(t, gateStep, prGateFor(t, lanes, f.event, mode))
|
|
gateMemo[key] = pass
|
|
if !pass && !regexp.MustCompile(`::error::`+bazelRemoteGateID+`\b`).MatchString(log) {
|
|
t.Errorf("%v (mode %s): red gate does not name %s:\n%s", f, mode, bazelRemoteGateID, log)
|
|
}
|
|
}
|
|
if pass != bazelRemoteModes[mode] {
|
|
t.Errorf("%v: mode %s, every lane that runs in it passed: gate pass = %v, want %v", f, mode, pass, bazelRemoteModes[mode])
|
|
}
|
|
}
|
|
for _, mode := range []string{"remote", "fork-ro", "fork-rw", "cache", "skip"} {
|
|
if !saw[mode] {
|
|
t.Errorf("the fact matrix never reached mode %s: %v", mode, saw)
|
|
}
|
|
}
|
|
|
|
// Named cases, for the record.
|
|
for _, c := range []struct {
|
|
name string
|
|
f rbeFacts
|
|
mode string
|
|
pass bool
|
|
}{
|
|
{"same-repo PR, farm on", rbeFacts{"pull_request", "true", "x", false, false, ""}, "remote", true},
|
|
{"same-repo PR, kill switch (var unset)", rbeFacts{"pull_request", "", "x", false, false, ""}, "skip", false},
|
|
{"same-repo PR, executor secret missing", rbeFacts{"pull_request", "true", "", false, false, ""}, "cache", false},
|
|
{"fork PR, rbe-fork ro", rbeFacts{"pull_request", "true", "", true, false, "ro"}, "fork-ro", true},
|
|
{"fork PR, rbe-fork rw", rbeFacts{"pull_request", "", "", true, false, "rw"}, "fork-rw", true},
|
|
{"fork PR, rbe-fork closed", rbeFacts{"pull_request", "true", "", true, false, "closed"}, "cache", false},
|
|
{"fork PR, mint unreachable", rbeFacts{"pull_request", "true", "", true, false, ""}, "cache", false},
|
|
{"Dependabot PR, rbe-fork ro", rbeFacts{"pull_request", "true", "", false, true, "ro"}, "fork-ro", true},
|
|
{"Dependabot PR, rbe-fork closed", rbeFacts{"pull_request", "", "", false, true, "closed"}, "cache", false},
|
|
{"merge_group", rbeFacts{"merge_group", "true", "x", false, false, ""}, "remote", true},
|
|
{"merge_group, kill switch (var unset)", rbeFacts{"merge_group", "", "x", false, false, ""}, "skip", false},
|
|
{"merge_group, executor secret missing", rbeFacts{"merge_group", "true", "", false, false, ""}, "cache", false},
|
|
} {
|
|
out, err := runDecisionStep(t, rbeStep, c.f, call.With)
|
|
if err != nil {
|
|
t.Fatalf("%s: bazel.yml rbe step: %v", c.name, err)
|
|
}
|
|
if out["mode"] != c.mode {
|
|
t.Errorf("%s: mode = %q, want %s", c.name, out["mode"], c.mode)
|
|
}
|
|
if pass, log := runPRGateStep(t, gateStep, prGateFor(t, lanes, c.f.event, out["mode"])); pass != c.pass {
|
|
t.Errorf("%s: pr.yml gate pass = %v, want %v\n%s", c.name, pass, c.pass, log)
|
|
}
|
|
}
|
|
|
|
// Remote, but one gated lane failed, was cancelled or reported nothing:
|
|
// red, naming that lane.
|
|
for lane, id := range bazelLaneGateIDs {
|
|
for _, mode := range []string{"remote", "fork-ro"} {
|
|
for _, res := range []string{"failure", "cancelled", ""} {
|
|
sc := prGateFor(t, lanes, "pull_request", mode)
|
|
sc.outputs[lane] = res
|
|
if pass, log := runPRGateStep(t, gateStep, sc); pass || !regexp.MustCompile(`::error::`+id+`\b`).MatchString(log) {
|
|
t.Errorf("mode %s, lane %s %q: gate pass = %v, want red naming %s\n%s", mode, lane, res, pass, id, log)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// A mode that executed nothing remotely is red even if every lane
|
|
// somehow reported success.
|
|
for _, mode := range []string{"skip", "local", "cache"} {
|
|
sc := prGateFor(t, lanes, "pull_request", mode)
|
|
for lane := range bazelLaneGateIDs {
|
|
sc.outputs[lane] = "success"
|
|
}
|
|
if pass, log := runPRGateStep(t, gateStep, sc); pass || !strings.Contains(log, "::error::"+bazelRemoteGateID) {
|
|
t.Errorf("mode %s, every lane reported success: gate pass = %v, want red naming %s\n%s", mode, pass, bazelRemoteGateID, log)
|
|
}
|
|
}
|
|
}
|
|
|
|
func copyMap(m map[string]string) map[string]string {
|
|
out := make(map[string]string, len(m))
|
|
for k, v := range m {
|
|
out[k] = v
|
|
}
|
|
return out
|
|
}
|
|
|
|
// Review F5: each manifest-sharded Bazel lane (embedded, proxied, server
|
|
// storage) checks, after the run, that every Bazel shard of its
|
|
// manifest-sharded targets ran exactly the tests its shard script lists, for
|
|
// the targets' own BUILD.bazel shard counts, and that its unsharded targets
|
|
// did not only skip. These lanes are the tiers' only run since PR Risk's
|
|
// legacy jobs were retired (ga-96smfk.22), so the check is what stands
|
|
// between a manifest drift and a test silently never running.
|
|
func TestBazelRetiredLanesCheckListedTestsRan(t *testing.T) {
|
|
type suite struct {
|
|
job, step, label, script string
|
|
// shardCount: -1 reads the label's own shard_count live from its
|
|
// BUILD.bazel rule, via the liveShardCount dispatch table below;
|
|
// only a label present in that table may use it (enforced below).
|
|
shardCount int
|
|
}
|
|
// liveShardCount dispatches a suite's -1 shardCount to the accessor that
|
|
// reads its target's own shard_count from its BUILD.bazel rule — the
|
|
// single source of truth for a lane's shard split. See
|
|
// bazelProxiedShardCount's doc comment (scripts/ci_workflow_test.go) for
|
|
// the shared rationale.
|
|
liveShardCount := map[string]func(*testing.T) int{
|
|
"//cmd/bd:bd_proxied_test": bazelProxiedShardCount,
|
|
"//cmd/bd:bd_embedded_test": bazelEmbeddedCmdShardCount,
|
|
"//internal/storage/embeddeddolt:embeddeddolt_embedded_test": bazelEmbeddedStorageShardCount,
|
|
"//internal/storage/dolt:dolt_server_full_test": bazelServerFullShardCount,
|
|
}
|
|
for _, c := range []struct {
|
|
lane, config string
|
|
suites []suite
|
|
whole []string
|
|
}{
|
|
{bazelEmbedJobName, "embedded", []suite{
|
|
// bazel-embedded runs its own duration-balanced manifest blocks
|
|
// (scripts/ci/embedded_{cmd,storage}_test_durations.json), not
|
|
// PR Risk's frozen 20- and 5-shard blocks (slice F1): neither is
|
|
// a drop-in retirement of its legacy job's shard count, just its
|
|
// tests. bazelEmbeddedCmdShardCount/bazelEmbeddedStorageShardCount
|
|
// read the real counts from BUILD.bazel, making these suites'
|
|
// `want` (below) genuine cross-file pins against bazel.yml's own
|
|
// check_shard_coverage.py arguments, not independently
|
|
// hard-coded literals that could drift from BUILD.bazel
|
|
// unnoticed (S1).
|
|
{"test-embedded-cmd", "Test", "//cmd/bd:bd_embedded_test", ".github/scripts/embedded-test-shard.sh", -1},
|
|
{"test-embedded-storage", "Test", "//internal/storage/embeddeddolt:embeddeddolt_embedded_test", ".github/scripts/embedded-storage-test-shard.sh", -1},
|
|
}, []string{"//internal/storage/embeddeddolt:embeddeddolt_conformance_core_test", "//internal/storage/embeddeddolt:embeddeddolt_conformance_audit_test"}},
|
|
{bazelProxiedJobName, "doltserver-proxied", []suite{
|
|
// bazel-proxied runs its own duration-balanced manifest block
|
|
// (scripts/ci/proxied_test_durations.json), not PR Risk's frozen
|
|
// 15-shard bd-init-cost-proxy block: it is not a drop-in
|
|
// retirement of test-proxied-cmd's shard count, just its tests.
|
|
// bazelProxiedShardCount reads the real count from
|
|
// cmd/bd/BUILD.bazel, making this suite's `want` (below) a
|
|
// genuine cross-file pin against bazel.yml's own
|
|
// check_shard_coverage.py argument, not an independently
|
|
// hard-coded literal that could drift from BUILD.bazel unnoticed
|
|
// (S1).
|
|
{"test-proxied-cmd", "Test proxied-server cmd shard", "//cmd/bd:bd_proxied_test", ".github/scripts/proxied-test-shard.sh", -1},
|
|
}, nil},
|
|
{bazelServerJobName, "doltserver-integration", []suite{
|
|
{"test-server-storage-full", "Test", "//internal/storage/dolt:dolt_server_full_test", ".github/scripts/server-storage-test-shard.sh", -1},
|
|
}, []string{"//internal/storage/dolt:dolt_server_conformance_test"}},
|
|
} {
|
|
job := readCIWorkflow(t, bazelWorkflowName).job(t, c.lane)
|
|
step := job.step(t, "Every listed test ran in its shard")
|
|
want := []string{"python3 tools/bazel/check_shard_coverage.py", `--bep "$RUNNER_TEMP/bazel-bep.json"`}
|
|
for _, s := range c.suites {
|
|
shards := s.shardCount
|
|
if shards < 0 {
|
|
fn, ok := liveShardCount[s.label]
|
|
if !ok {
|
|
t.Fatalf("%s: shardCount<0 (read live from BUILD.bazel) is not configured for %s", s.job, s.label)
|
|
}
|
|
shards = fn(t)
|
|
}
|
|
want = append(want, fmt.Sprintf("--suite %s %s %d", s.label, s.script, shards))
|
|
}
|
|
for _, w := range c.whole {
|
|
want = append(want, "--whole "+w)
|
|
}
|
|
if got := strings.Join(strings.Fields(step.Run), " "); got != strings.Join(want, " ") {
|
|
t.Errorf("%s coverage step runs %q, want %q", c.lane, got, strings.Join(want, " "))
|
|
}
|
|
if step.If != "${{ always() && steps.test.outcome != 'skipped' }}" || step.ContinueOnError != nil {
|
|
t.Errorf("%s coverage step: if %q, continue-on-error %v; want always() after the test step and no continue-on-error", c.lane, step.If, step.ContinueOnError)
|
|
}
|
|
if !(job.stepIndex(t, "bazel test //... --config="+c.config) < job.stepIndex(t, step.Name) &&
|
|
job.stepIndex(t, step.Name) < job.stepIndex(t, "Record job result")) {
|
|
t.Errorf("%s coverage step must run after the test step and before the result recorder", c.lane)
|
|
}
|
|
}
|
|
}
|
|
|
|
// check_shard_coverage.py itself, on a synthetic BEP, test.xml files and
|
|
// shard script.
|
|
func TestCheckShardCoverageScript(t *testing.T) {
|
|
requireHostTool(t, "bash")
|
|
python := requireHostTool(t, "python3")
|
|
script := filepath.Join(sourceRepoRoot(t), "tools", "bazel", "check_shard_coverage.py")
|
|
dir := t.TempDir()
|
|
shard := filepath.Join(dir, "shard.sh")
|
|
// Shard 1 lists TestA and TestB, shard 2 TestC; list-only mode only.
|
|
if err := os.WriteFile(shard, []byte(`#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
[ "${BEADS_TEST_SHARD_LIST_ONLY:-}" = 1 ] || { echo "not list-only" >&2; exit 3; }
|
|
[ "$2" = 2 ] || { echo "bad total $2" >&2; exit 1; }
|
|
echo "Shard $1/$2: running"
|
|
echo " manifest: 1, fallback: 0"
|
|
case "$1" in
|
|
1) printf ' %s\n' TestA TestB TestMain ;; # TestMain: never a testcase
|
|
2) printf ' %s\n' TestC ;;
|
|
*) exit 1 ;;
|
|
esac
|
|
[ -z "${FAKE_SHARD_FAIL:-}" ] || exit 1
|
|
`), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
const label = "//pkg:t"
|
|
writeBEP := func(shards int) string {
|
|
lines := []string{`{"id":{"targetConfigured":{"label":"` + label + `"}},"configured":{"targetKind":"sh_test rule"}}`}
|
|
for k := 1; k <= shards; k++ {
|
|
lines = append(lines, fmt.Sprintf(`{"id":{"testResult":{"label":"%s","shard":%d,"run":1,"attempt":1}}}`, label, k))
|
|
}
|
|
path := filepath.Join(dir, fmt.Sprintf("bep%d.json", shards))
|
|
if err := os.WriteFile(path, []byte(strings.Join(lines, "\n")+"\n"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return path
|
|
}
|
|
// A name ending in "~" is written as a skipped testcase.
|
|
writeXML := func(logs string, k int, names ...string) {
|
|
d := filepath.Join(logs, "pkg", "t", fmt.Sprintf("shard_%d_of_2", k))
|
|
if err := os.MkdirAll(d, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var b strings.Builder
|
|
b.WriteString(`<testsuites><testsuite name="pkg">`)
|
|
for _, n := range names {
|
|
if skipped, ok := strings.CutSuffix(n, "~"); ok {
|
|
fmt.Fprintf(&b, `<testcase classname="pkg" name="%s"><skipped message="skip"></skipped></testcase>`, skipped)
|
|
continue
|
|
}
|
|
fmt.Fprintf(&b, `<testcase classname="pkg" name="%s"></testcase>`, n)
|
|
}
|
|
b.WriteString(`</testsuite></testsuites>`)
|
|
if err := os.WriteFile(filepath.Join(d, "test.xml"), []byte(b.String()), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
run := func(bep, logs string) (bool, string) {
|
|
cmd := exec.Command(python, script, "--bep", bep, "--testlogs", logs, "--suite", label, shard, "2")
|
|
out, err := cmd.CombinedOutput()
|
|
return err == nil, string(out)
|
|
}
|
|
cases := []struct {
|
|
name string
|
|
bepShard int
|
|
s1, s2 []string
|
|
pass bool
|
|
mention string
|
|
}{
|
|
{"exact", 2, []string{"TestA", "TestB", "TestA/sub"}, []string{"TestC"}, true, ""},
|
|
{"listed test missing from the binary", 2, []string{"TestA"}, []string{"TestC"}, false, "TestB is listed"},
|
|
{"test in the wrong shard", 2, []string{"TestA", "TestB", "TestC"}, []string{}, false, "TestC"},
|
|
{"unlisted test ran", 2, []string{"TestA", "TestB", "TestZ"}, []string{"TestC"}, false, "TestZ ran"},
|
|
{"shard count differs", 1, []string{"TestA", "TestB"}, []string{"TestC"}, false, "want 2"},
|
|
{"missing test.xml", 2, []string{"TestA", "TestB"}, nil, false, "missing"},
|
|
// Review G5: a shard whose test.xml has no top-level test at all
|
|
// still reports every listed test missing (check_testcases.py also
|
|
// rejects it, but this check must not depend on that).
|
|
{"shard ran zero tests", 2, []string{}, []string{"TestC"}, false, "TestA is listed"},
|
|
{"zero tests, only subtests", 2, []string{"TestA/sub"}, []string{"TestC"}, false, "TestB is listed"},
|
|
// Review G3: some skips are fine; a shard of only skips is not.
|
|
{"some skipped", 2, []string{"TestA~", "TestB"}, []string{"TestC"}, true, ""},
|
|
{"shard all skipped", 2, []string{"TestA~", "TestB~"}, []string{"TestC"}, false, "shard 1/2: every top-level test (2) was skipped"},
|
|
}
|
|
for i, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
logs := filepath.Join(dir, fmt.Sprintf("logs%d", i))
|
|
writeXML(logs, 1, c.s1...)
|
|
if c.s2 != nil {
|
|
writeXML(logs, 2, c.s2...)
|
|
}
|
|
pass, out := run(writeBEP(c.bepShard), logs)
|
|
if pass != c.pass || (c.mention != "" && !strings.Contains(out, c.mention)) {
|
|
t.Errorf("pass = %v, want %v (mention %q):\n%s", pass, c.pass, c.mention, out)
|
|
}
|
|
})
|
|
}
|
|
// --whole: an unsharded target must list a test and not only skips.
|
|
for i, c := range []struct {
|
|
names []string
|
|
pass bool
|
|
mention string
|
|
}{
|
|
{[]string{"TestConformance"}, true, ""},
|
|
{[]string{"TestConformance~"}, false, "was skipped"},
|
|
{[]string{}, false, "lists no tests"},
|
|
} {
|
|
logs := filepath.Join(dir, fmt.Sprintf("whole%d", i))
|
|
d := filepath.Join(logs, "pkg", "w")
|
|
if err := os.MkdirAll(d, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
xml := `<testsuites><testsuite name="pkg">`
|
|
for _, n := range c.names {
|
|
if skipped, ok := strings.CutSuffix(n, "~"); ok {
|
|
xml += `<testcase name="` + skipped + `"><skipped></skipped></testcase>`
|
|
} else {
|
|
xml += `<testcase name="` + n + `"></testcase>`
|
|
}
|
|
}
|
|
xml += `</testsuite></testsuites>`
|
|
if err := os.WriteFile(filepath.Join(d, "test.xml"), []byte(xml), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
bep := filepath.Join(dir, fmt.Sprintf("whole%d.json", i))
|
|
if err := os.WriteFile(bep, []byte(`{"id":{"targetConfigured":{"label":"//pkg:w"}},"configured":{"targetKind":"sh_test rule"}}
|
|
{"id":{"testResult":{"label":"//pkg:w","run":1,"attempt":1}}}
|
|
{"id":{"targetConfigured":{"label":"`+label+`"}},"configured":{"targetKind":"sh_test rule"}}
|
|
{"id":{"testResult":{"label":"`+label+`","shard":1}}}
|
|
{"id":{"testResult":{"label":"`+label+`","shard":2}}}
|
|
`), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
writeXML(logs, 1, "TestA", "TestB")
|
|
writeXML(logs, 2, "TestC")
|
|
out, err := exec.Command(python, script, "--bep", bep, "--testlogs", logs, "--suite", label, shard, "2", "--whole", "//pkg:w").CombinedOutput()
|
|
if (err == nil) != c.pass || (c.mention != "" && !strings.Contains(string(out), c.mention)) {
|
|
t.Errorf("--whole %v: pass = %v, want %v (mention %q):\n%s", c.names, err == nil, c.pass, c.mention, out)
|
|
}
|
|
}
|
|
if out, err := exec.Command(python, script, "--bep", writeBEP(2), "--testlogs", filepath.Join(dir, "logs0"), "--suite", label, shard, "2", "--whole", "//pkg:absent").CombinedOutput(); err == nil {
|
|
t.Errorf("--whole for a target the BEP lacks passed:\n%s", out)
|
|
}
|
|
|
|
// A failing shard script fails the check, even if what it listed
|
|
// matches; so does a missing one.
|
|
logs := filepath.Join(dir, "logs-bad")
|
|
writeXML(logs, 1, "TestA", "TestB")
|
|
writeXML(logs, 2, "TestC")
|
|
for _, c := range []struct {
|
|
script string
|
|
env []string
|
|
}{{shard, []string{"FAKE_SHARD_FAIL=1"}}, {"/nonexistent/shard.sh", nil}} {
|
|
cmd := exec.Command(python, script, "--bep", writeBEP(2), "--testlogs", logs, "--suite", label, c.script, "2")
|
|
cmd.Env = append(os.Environ(), c.env...)
|
|
if out, err := cmd.CombinedOutput(); err == nil || !strings.Contains(string(out), "failed") {
|
|
t.Errorf("shard script %s %v: check passed or did not say it failed:\n%s", c.script, c.env, out)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Review G1: the checker's input is the real shard scripts' list-only
|
|
// output (every retired lane's: the embedded, proxied and server suites). Every name they list, for every shard, must be a test go test
|
|
// runs (declared `func Name(t *testing.T)` in the package's _test.go files),
|
|
// or one check_shard_coverage.py drops as NOT_TESTS; and each NOT_TESTS name
|
|
// must really not be a test (TestMain takes *testing.M). Otherwise the
|
|
// checker reports a listed test that "did not run" on every real run.
|
|
func TestShardScriptsListOnlyRealTests(t *testing.T) {
|
|
// The CI shard scripts use bash 4 associative arrays (Linux runners only).
|
|
requireAutofixBash(t)
|
|
root := sourceRepoRoot(t)
|
|
m := regexp.MustCompile(`(?m)^NOT_TESTS = frozenset\(\{([^}]*)\}\)`).FindStringSubmatch(readPolicyFile(t, root, "tools/bazel/check_shard_coverage.py"))
|
|
if m == nil {
|
|
t.Fatal("tools/bazel/check_shard_coverage.py has no NOT_TESTS = frozenset({...})")
|
|
}
|
|
notTests := map[string]bool{}
|
|
for _, q := range regexp.MustCompile(`"([^"]+)"`).FindAllStringSubmatch(m[1], -1) {
|
|
notTests[q[1]] = true
|
|
}
|
|
for _, c := range []struct{ job, script, pkg string }{
|
|
{"test-embedded-cmd", ".github/scripts/embedded-test-shard.sh", "cmd/bd"},
|
|
{"test-embedded-storage", ".github/scripts/embedded-storage-test-shard.sh", "internal/storage/embeddeddolt"},
|
|
// D2 step 2: the proxied and server lanes' suites.
|
|
{"test-proxied-cmd", ".github/scripts/proxied-test-shard.sh", "cmd/bd"},
|
|
{"test-server-storage-full", ".github/scripts/server-storage-test-shard.sh", "internal/storage/dolt"},
|
|
} {
|
|
var src strings.Builder
|
|
files, err := filepath.Glob(filepath.Join(root, c.pkg, "*_test.go"))
|
|
if err != nil || len(files) == 0 {
|
|
t.Fatalf("%s: no _test.go files (%v)", c.pkg, err)
|
|
}
|
|
for _, f := range files {
|
|
data, err := os.ReadFile(f)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
src.Write(data)
|
|
src.WriteString("\n")
|
|
}
|
|
declared := map[string]bool{}
|
|
for _, d := range regexp.MustCompile(`(?m)^func (Test\w*)\(\w+ \*testing\.T\) \{`).FindAllStringSubmatch(src.String(), -1) {
|
|
declared[d[1]] = true
|
|
}
|
|
|
|
// B1: validate every total this script's committed manifest holds a
|
|
// block for, plus this job's own PR Risk matrix size and (for
|
|
// test-proxied-cmd) the Bazel lane's own shard_count — not just
|
|
// whichever total happens to equal this PR Risk job's matrix. Before
|
|
// F2 those always coincided; now the Bazel-only bazel-proxied lane
|
|
// reads a manifest block (30) that no PR-Risk-matrix-only check ever
|
|
// exercises, so a fork PR (which never runs bazel-proxied) could
|
|
// corrupt that block and still merge green. Looping over every
|
|
// distinct total in the manifest closes that gap for this script and
|
|
// any other script that later grows a second block the same way.
|
|
mm := shardManifestDefault.FindStringSubmatch(readPolicyFile(t, root, c.script))
|
|
if mm == nil {
|
|
t.Fatalf("%s has no ${BEADS_TEST_SHARD_MANIFEST:-...} default manifest", c.script)
|
|
}
|
|
totalsSet := map[int]bool{}
|
|
for _, line := range strings.Split(readPolicyFile(t, root, mm[1]), "\n") {
|
|
line, _, _ = strings.Cut(line, "#")
|
|
fields := strings.Fields(line)
|
|
if len(fields) == 0 {
|
|
continue
|
|
}
|
|
if n, err := strconv.Atoi(fields[0]); err == nil {
|
|
totalsSet[n] = true
|
|
}
|
|
}
|
|
switch c.script {
|
|
case ".github/scripts/proxied-test-shard.sh":
|
|
totalsSet[bazelProxiedShardCount(t)] = true
|
|
case ".github/scripts/embedded-test-shard.sh":
|
|
// F1: the Bazel-only bazel-embedded lane reads a 50-shard cmd
|
|
// block that no PR-Risk-matrix-only (20-shard) check exercises;
|
|
// without this, "BUILD.bazel's shard_count and bazel.yml's
|
|
// check_shard_coverage.py arg both drift to a new total with no
|
|
// manifest block" passes every policy test (see review S3) --
|
|
// the lane then silently goes 100% hash fallback and loses its
|
|
// duration balancing.
|
|
totalsSet[bazelEmbeddedCmdShardCount(t)] = true
|
|
case ".github/scripts/embedded-storage-test-shard.sh":
|
|
// F1: mirrors the cmd case above for the 15-shard storage block.
|
|
totalsSet[bazelEmbeddedStorageShardCount(t)] = true
|
|
case ".github/scripts/server-storage-test-shard.sh":
|
|
totalsSet[bazelServerFullShardCount(t)] = true
|
|
}
|
|
totals := make([]int, 0, len(totalsSet))
|
|
for n := range totalsSet {
|
|
totals = append(totals, n)
|
|
}
|
|
sort.Ints(totals)
|
|
|
|
for _, shards := range totals {
|
|
// The scripts' hash fallback forks per test (seconds per shard
|
|
// for the server suite): list the shards concurrently.
|
|
outs, errs := make([][]byte, shards+1), make([]error, shards+1)
|
|
var wg sync.WaitGroup
|
|
for k := 1; k <= shards; k++ {
|
|
wg.Add(1)
|
|
go func(k int) {
|
|
defer wg.Done()
|
|
cmd := exec.Command("bash", c.script, strconv.Itoa(k), strconv.Itoa(shards))
|
|
cmd.Dir = root
|
|
cmd.Env = append(os.Environ(), "BEADS_TEST_SHARD_LIST_ONLY=1")
|
|
outs[k], errs[k] = cmd.Output()
|
|
}(k)
|
|
}
|
|
wg.Wait()
|
|
listed, manifestSum := 0, 0
|
|
for k := 1; k <= shards; k++ {
|
|
if errs[k] != nil {
|
|
// The script itself exits 1 on a duplicate manifest entry
|
|
// or a manifest entry that names no discovered test
|
|
// (rename/typo/stale-after-delete), for the requested
|
|
// total only: this is what catches a corrupted block
|
|
// that a PR-Risk-matrix-only check at a different total
|
|
// would never see.
|
|
t.Fatalf("%s %d %d: %v\n%s", c.script, k, shards, errs[k], outs[k])
|
|
}
|
|
for _, line := range strings.Split(string(outs[k]), "\n") {
|
|
if mc := regexp.MustCompile(`^ manifest: (\d+), fallback: \d+$`).FindStringSubmatch(line); mc != nil {
|
|
n, _ := strconv.Atoi(mc[1])
|
|
manifestSum += n
|
|
continue
|
|
}
|
|
name, ok := strings.CutPrefix(line, " ")
|
|
if !ok || !strings.HasPrefix(name, "Test") || strings.ContainsAny(name, " :") {
|
|
continue
|
|
}
|
|
listed++
|
|
isTest := declared[name]
|
|
switch {
|
|
case notTests[name] && isTest:
|
|
t.Errorf("%s shard %d/%d lists %s, which check_shard_coverage.py drops, but it is a real test", c.script, k, shards, name)
|
|
case !notTests[name] && !isTest:
|
|
t.Errorf("%s shard %d/%d lists %s, which is not a `func %s(t *testing.T)` test in %s: check_shard_coverage.py would report it missing on every run (add it to NOT_TESTS only if go test never runs it)",
|
|
c.script, k, shards, name, name, c.pkg)
|
|
}
|
|
}
|
|
}
|
|
if listed < 50 {
|
|
t.Errorf("%s at %d shards listed only %d tests; did the list-only output format change?", c.script, shards, listed)
|
|
}
|
|
// S1: a total that is supposed to have a committed manifest
|
|
// block (every total this loop considers does: it is either a
|
|
// live job's matrix size or a total this script's own manifest
|
|
// already names) must not have silently gone 100% hash fallback,
|
|
// which is what "the whole block was deleted" looks like from
|
|
// here: check_shard_coverage.py would still pass (it rebuilds
|
|
// its expectation from this same script), so nothing else
|
|
// catches it.
|
|
if manifestSum == 0 {
|
|
t.Errorf("%s at %d shards: manifest entries for this total sum to 0 across all shards (100%% hash fallback); its committed block in %s may have been deleted", c.script, shards, mm[1])
|
|
}
|
|
}
|
|
}
|
|
for name := range notTests {
|
|
if name != "TestMain" {
|
|
t.Errorf("NOT_TESTS has %s; only TestMain is never a test", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
// S3: the Bazel-only 30-shard block is not frozen like the legacy 15-shard
|
|
// block (TestShardScriptsListOnlyRealTests's B1 fix catches outright
|
|
// corruption, but not a committed block that has drifted from the currently
|
|
// discovered TestProxiedServer*/TestServerMode* test set, e.g. a test added,
|
|
// renamed, or removed without anyone running --write). gen_proxied_shard_
|
|
// manifest.py --check verifies only that the committed block names every
|
|
// discovered test exactly once -- not that its shard *assignments* match a
|
|
// fresh LPT pack -- and fails with the exact command to fix it when a name
|
|
// is missing, stale, or duplicated. It deliberately does NOT fail merely
|
|
// because proxied_test_durations.json's weights changed and the existing
|
|
// packing is now suboptimal: two PRs each adding one proxied test would
|
|
// otherwise force a full repack and conflict on unrelated shard lines (see
|
|
// --repack below for the explicit opt-in to that). Run --check here so a
|
|
// block with missing/stale/duplicate names fails go test ./scripts/...
|
|
// (//scripts:scripts_test under Bazel) instead of only
|
|
// surfacing as a test silently never running in any shard. The legacy
|
|
// 15-shard block is deliberately excluded: its header documents that it is
|
|
// frozen and must not be regenerated (see
|
|
// .github/scripts/proxied-cmd-test-shards.txt and engdocs/TESTING.md), so a
|
|
// --check against it would always fail by design.
|
|
func TestProxiedShardManifestGeneratorNotStale(t *testing.T) {
|
|
python := requireHostTool(t, "python3")
|
|
root := sourceRepoRoot(t)
|
|
cmd := exec.Command(python, "scripts/ci/gen_proxied_shard_manifest.py", "30", "--weights=duration", "--check")
|
|
cmd.Dir = root
|
|
if out, err := cmd.CombinedOutput(); err != nil {
|
|
t.Errorf("gen_proxied_shard_manifest.py 30 --weights=duration --check: %v\n%s", err, out)
|
|
}
|
|
}
|
|
|
|
// walkBazelFiles visits every BUILD.bazel and BUILD file under root (and,
|
|
// with bzl, every .bzl file), skipping .git, node_modules and .beads. A
|
|
// symlink to a regular file is visited: under `bazel test` on a local
|
|
// executor the runfiles tree is a symlink forest, and a walk that skipped
|
|
// symlinks read no BUILD file there and reported every lane's targets gone
|
|
// (#7350). A symlink to a directory is never followed.
|
|
func walkBazelFiles(root string, bzl bool, visit func(path string, d os.DirEntry) error) error {
|
|
return filepath.WalkDir(root, func(path string, d os.DirEntry, err error) error {
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if d.IsDir() {
|
|
switch d.Name() {
|
|
case ".git", "node_modules", ".beads":
|
|
return filepath.SkipDir
|
|
}
|
|
return nil
|
|
}
|
|
name := d.Name()
|
|
if name != "BUILD.bazel" && name != "BUILD" && !(bzl && strings.HasSuffix(name, ".bzl")) {
|
|
return nil
|
|
}
|
|
if !isFileOrFileLink(path, d) {
|
|
return nil
|
|
}
|
|
return visit(path, d)
|
|
})
|
|
}
|
|
|
|
// A local Bazel executor hands the test a runfiles tree in which every file
|
|
// is a symlink into the sandbox's inputs (#7350: scripts_test ran there on an
|
|
// unauthorized fork's PR, read no BUILD file and failed every lane's pin with
|
|
// `got map[]`). The walk must see the same Bazel files through such a forest
|
|
// as in the checkout, and must not follow a symlinked directory or trip on a
|
|
// dangling link.
|
|
func TestBazelFileWalkFollowsFileSymlinks(t *testing.T) {
|
|
root := sourceRepoRoot(t)
|
|
collect := func(root string) []string {
|
|
var rels []string
|
|
err := walkBazelFiles(root, true, func(path string, _ os.DirEntry) error {
|
|
rel, err := filepath.Rel(root, path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
rels = append(rels, filepath.ToSlash(rel))
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("walk %s: %v", root, err)
|
|
}
|
|
sort.Strings(rels)
|
|
return rels
|
|
}
|
|
checkout := collect(root)
|
|
if len(checkout) < 10 {
|
|
t.Fatalf("found only %d Bazel files under %s; the checkout walk is broken", len(checkout), root)
|
|
}
|
|
|
|
forest := filepath.Join(t.TempDir(), "_main")
|
|
for _, rel := range checkout {
|
|
dst := filepath.Join(forest, filepath.FromSlash(rel))
|
|
if err := os.MkdirAll(filepath.Dir(dst), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.Symlink(filepath.Join(root, filepath.FromSlash(rel)), dst); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
// Hazards a runfiles tree or a checkout can hold: Bazel's bazel-* links to
|
|
// directories, and a link whose target is gone.
|
|
if err := os.Symlink(filepath.Join(root, "scripts"), filepath.Join(forest, "bazel-bin")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.Symlink(filepath.Join(forest, "missing", "BUILD.bazel"), filepath.Join(forest, "BUILD")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if got := collect(forest); !reflect.DeepEqual(got, checkout) {
|
|
t.Errorf("the symlink forest yields different Bazel files than the checkout:\nforest %d: %v\ncheckout %d: %v", len(got), got, len(checkout), checkout)
|
|
}
|
|
}
|
|
|
|
// Review G3: since D2 the retired tiers' Bazel lanes (embedded, proxied,
|
|
// server-storage) are those tiers' only pre-merge run on same-repo PRs, so
|
|
// nothing that reaches them may narrow them (select fewer tests, or turn
|
|
// them into skips) without a reviewed edit of this test.
|
|
// TestBazelEmbeddedJobRunsEmbeddedTier and TestBazelRetiredLanesArePinned
|
|
// pin the command lines and each lane config's lines; this covers
|
|
// everything else that applies to the lanes: every other .bazelrc line of a
|
|
// config a lane uses (the unconfigured ones, remote-exec and fork-cache,
|
|
// which setup-bazel's rc enables, and any config those pull in), rc files
|
|
// that would be try-imported, the tools/bazel scripts every test runs under
|
|
// or through, the whole setup-bazel action, and the lanes' targets' args and
|
|
// env. At run time, check_shard_coverage.py also fails a shard of only
|
|
// skips.
|
|
func TestBazelRetiredLanesCannotBeNarrowed(t *testing.T) {
|
|
root := sourceRepoRoot(t)
|
|
rcNarrow := regexp.MustCompile(`test_filter|test_arg|-test\.|_filters\b|test_env=(BEADS_TEST|GO_TEST|TESTBRIDGE)|--config=|cache_test_results|eviction_retries|run_under|flaky|runs_per_test|test_sharding_strategy|build_tests_only`)
|
|
const runUnder = "test --run_under=//tools/bazel:test_env"
|
|
wantImports := []string{"try-import %workspace%/.bazelrc.local", "try-import %workspace%/user.bazelrc"}
|
|
|
|
type rcLine struct{ cmd, config, text string }
|
|
var lines []rcLine
|
|
var imports []string
|
|
sawRunUnder := false
|
|
for _, raw := range strings.Split(readPolicyFile(t, root, ".bazelrc"), "\n") {
|
|
line := strings.TrimSpace(raw)
|
|
if line == "" || strings.HasPrefix(line, "#") {
|
|
continue
|
|
}
|
|
head, _, _ := strings.Cut(line, " ")
|
|
if head == "import" || head == "try-import" {
|
|
imports = append(imports, line)
|
|
continue
|
|
}
|
|
cmd, config, _ := strings.Cut(head, ":")
|
|
lines = append(lines, rcLine{cmd, config, line})
|
|
}
|
|
if !reflect.DeepEqual(imports, wantImports) {
|
|
t.Errorf(".bazelrc imports %v, want exactly %v (an import can carry any flag into the lanes)", imports, wantImports)
|
|
}
|
|
// The configs the lanes use: their own (pinned), the configs
|
|
// setup-bazel's generated rc enables for every command (remote-exec,
|
|
// and fork-cache in mode cache, where the remote-only lanes are skipped
|
|
// but the rc still applies), the unconfigured lines, and anything they
|
|
// reference (which the check below then forbids anyway).
|
|
laneConfigs := map[string][]string{"embedded": bazelEmbeddedRCLines}
|
|
for config, want := range bazelDoltServerRCLines {
|
|
laneConfigs[config] = want
|
|
}
|
|
// D2 step 3's lanes (PR-core, dolt-server, pure-Go/js-wasm, sole-run).
|
|
for config, want := range bazelPRLaneRCLines {
|
|
laneConfigs[config] = want
|
|
}
|
|
rcEnabled := map[string]bool{"remote-exec": true, "fork-cache": true}
|
|
inUse := map[string]bool{"": true}
|
|
for c := range laneConfigs {
|
|
inUse[c] = true
|
|
}
|
|
for c := range rcEnabled {
|
|
inUse[c] = true
|
|
}
|
|
for changed := true; changed; {
|
|
changed = false
|
|
for _, l := range lines {
|
|
if !inUse[l.config] {
|
|
continue
|
|
}
|
|
for _, m := range regexp.MustCompile(`--config=([A-Za-z0-9_-]+)`).FindAllStringSubmatch(l.text, -1) {
|
|
if !inUse[m[1]] {
|
|
inUse[m[1]], changed = true, true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
pinned := map[string]bool{}
|
|
for _, want := range laneConfigs {
|
|
for _, l := range want {
|
|
pinned[l] = true
|
|
}
|
|
}
|
|
for _, l := range lines {
|
|
if !inUse[l.config] || pinned[l.text] {
|
|
continue
|
|
}
|
|
if _, lane := laneConfigs[l.config]; lane {
|
|
t.Errorf(".bazelrc %q: not one of the pinned --config=%s lines", l.text, l.config)
|
|
continue
|
|
}
|
|
if l.text == runUnder {
|
|
sawRunUnder = true
|
|
continue
|
|
}
|
|
if rcNarrow.MatchString(l.text) {
|
|
t.Errorf(".bazelrc %q applies to the retired tiers' lanes (config %q) and selects, narrows or re-runs tests", l.text, l.config)
|
|
}
|
|
}
|
|
if !sawRunUnder {
|
|
t.Errorf(".bazelrc lacks %q (the wrapper the narrowing checks below cover)", runUnder)
|
|
}
|
|
|
|
// Committed rc files: only .bazelrc. .bazelrc.local and user.bazelrc are
|
|
// developer-local (gitignored) and would be try-imported into CI runs.
|
|
for _, f := range repoFiles(t, root) {
|
|
base := filepath.Base(f)
|
|
if strings.Contains(base, "bazelrc") && f != ".bazelrc" && f != setupBazelActionDir+"/write-bazelrc.sh" {
|
|
t.Errorf("committed rc file %s: .bazelrc's try-import would load it into every CI run", f)
|
|
}
|
|
}
|
|
|
|
// The scripts every lane's test runs under or through, and the whole
|
|
// setup-bazel action (its generated rc applies to every command).
|
|
scriptNarrow := regexp.MustCompile(`-test\.(short|run|skip|list|bench)|BEADS_TEST_SKIP|BEADS_TEST_EMBEDDED_DOLT|BEADS_TEST_PROXIED_SERVER|BEADS_TEST_ENV_RUN_DOLT|BEADS_TEST_REQUIRE_DOLT_CONTAINER|BEADS_TEST_DOLT_SERVER\b|TESTBRIDGE_TEST_ONLY|test_filter|test_arg|_filters\b|cache_test_results|eviction_retries|flaky|runs_per_test|test_sharding_strategy`)
|
|
files, _ := filepath.Glob(filepath.Join(root, "tools", "bazel", "*.sh"))
|
|
action, _ := filepath.Glob(filepath.Join(root, setupBazelActionDir, "*"))
|
|
files = append(files, action...)
|
|
if len(files) < 5 {
|
|
t.Fatalf("found only %v", files)
|
|
}
|
|
for _, f := range files {
|
|
rel, _ := filepath.Rel(root, f)
|
|
data, err := os.ReadFile(f)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for i, line := range strings.Split(string(data), "\n") {
|
|
code := strings.TrimSpace(line)
|
|
if strings.HasPrefix(code, "#") {
|
|
continue
|
|
}
|
|
if scriptNarrow.MatchString(code) {
|
|
t.Errorf("%s:%d %q can select, skip or re-run the retired tiers' lanes' tests", rel, i+1, code)
|
|
}
|
|
for _, m := range regexp.MustCompile(`--config=([A-Za-z0-9_-]+)`).FindAllStringSubmatch(code, -1) {
|
|
if !rcEnabled[m[1]] {
|
|
t.Errorf("%s:%d enables --config=%s for every command", rel, i+1, m[1])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Review F2 (step 2): the shard scripts the sharded targets run (the
|
|
// legacy jobs run the same scripts, so they are not changed here): the
|
|
// command that runs the selected tests is pinned exactly, and nothing
|
|
// else in them may select, skip, export a tier switch or run tests.
|
|
for _, c := range bazelShardScripts {
|
|
for _, e := range shardScriptNarrowing(c, readPolicyFile(t, root, c.script)) {
|
|
t.Error(e)
|
|
}
|
|
}
|
|
|
|
// The lanes' targets (tagged embedded, dolt-server-proxied or
|
|
// dolt-server-integration): exactly these, with exactly these args and
|
|
// env (the legacy jobs' flags; the shard scripts add the rest).
|
|
type target struct {
|
|
args []string
|
|
env map[string]string
|
|
}
|
|
want := map[string]target{
|
|
"//cmd/bd:bd_embedded_test": {
|
|
[]string{"$(rootpath //:.github/scripts/embedded-test-shard.sh)", "BEADS_TEST_CMD_BINARY", "$(rootpath :bd_test)", "-test.timeout=19m"},
|
|
map[string]string{"BEADS_TEST_BD_BINARY": "$(rlocationpath :bd)", "BEADS_TEST_EMBEDDED_DOLT": "1", "BEADS_TEST_GOFMT": "$(rlocationpath @go_sdk//:bin/gofmt)"},
|
|
},
|
|
"//internal/storage/embeddeddolt:embeddeddolt_embedded_test": {
|
|
[]string{"$(rootpath //:.github/scripts/embedded-storage-test-shard.sh)", "BEADS_TEST_EMBEDDED_TEST_BINARY", "$(rootpath :embeddeddolt_test)", "-test.timeout=19m"},
|
|
map[string]string{"BEADS_TEST_EMBEDDED_DOLT": "1"},
|
|
},
|
|
"//internal/storage/embeddeddolt:embeddeddolt_conformance_core_test": {
|
|
[]string{"$(rootpath :embeddeddolt_test)", "-test.v", "-test.count=1", "-test.timeout=19m", "-test.run=^TestConformance$$", "-test.skip=^TestConformance$$/^Audit$$"},
|
|
map[string]string{"BEADS_TEST_EMBEDDED_DOLT": "1"},
|
|
},
|
|
"//internal/storage/embeddeddolt:embeddeddolt_conformance_audit_test": {
|
|
[]string{"$(rootpath :embeddeddolt_test)", "-test.v", "-test.count=1", "-test.timeout=19m", "-test.run=^TestConformance$$/^Audit$$"},
|
|
map[string]string{"BEADS_TEST_EMBEDDED_DOLT": "1"},
|
|
},
|
|
// nightly.yml's retired non-race embedded batch-apply step: the large
|
|
// shapes every race lane shrinks or skips (raceEnabled).
|
|
"//internal/storage/embeddeddolt:embeddeddolt_batch_apply_nonrace_test": {
|
|
[]string{"$(rootpath :embeddeddolt_race_off)", "-test.v", "-test.count=1", "-test.timeout=19m", "-test.run=^(TestBatchApplyContract|TestLargeBatchApplyWallClock_Embedded|TestLargeBatchApplyStatementCounts712_Embedded|TestCreateBatchFastPathsMatchPerRowLarge_Embedded)$$"},
|
|
map[string]string{"BEADS_TEST_EMBEDDED_DOLT": "1"},
|
|
},
|
|
// scripts/conformance.sh's Tier 3, the served HTTP corpus, with the
|
|
// script's switches: required, so a missing engine fails each served
|
|
// case instead of skipping it.
|
|
"//internal/httpclient:httpclient_served_test": {
|
|
[]string{"$(rootpath :httpclient_test)", "-test.v", "-test.count=1", "-test.timeout=19m"},
|
|
map[string]string{"BEADS_HTTP_TEST_REQUIRED": "1", "BEADS_TEST_EMBEDDED_DOLT": "1"},
|
|
},
|
|
"//cmd/bd:bd_proxied_test": {
|
|
[]string{"$(rootpath //:.github/scripts/proxied-test-shard.sh)", "BEADS_TEST_CMD_BINARY", "$(rootpath :bd_test)"},
|
|
map[string]string{
|
|
"BEADS_TEST_BD_BINARY": "$(rlocationpath :bd_for_tests)", "BEADS_TEST_DOLT_SERVER": "local", "BEADS_TEST_GIT_IDENTITY": "1",
|
|
"BEADS_TEST_GOFMT": "$(rlocationpath @go_sdk//:bin/gofmt)", "BEADS_TEST_PROXIED_SERVER": "1",
|
|
"BEADS_TEST_REQUIRE_DOLT_CONTAINER": "1", "BEADS_TEST_REQUIRE_SOCAT": "1", "GOMAXPROCS": "4",
|
|
},
|
|
},
|
|
"//cmd/bd:bd_managed_local_test": {
|
|
[]string{"$(rootpath :bd_test)", "-test.run=^TestManagedLocalProxied", "-test.timeout=15m"},
|
|
map[string]string{
|
|
"BEADS_TEST_BD_BINARY": "$(rlocationpath :bd_for_tests)", "BEADS_TEST_DOLT_SERVER": "local",
|
|
"BEADS_TEST_GOFMT": "$(rlocationpath @go_sdk//:bin/gofmt)", "BEADS_TEST_PREFLIGHT_GO": "$(rlocationpath :preflight_go_fixture)",
|
|
"BEADS_TEST_PROXIED_LOCAL": "1", "BEADS_TEST_REQUIRE_DOLT_CONTAINER": "1", "BEADS_TEST_SKIP": "dolt",
|
|
},
|
|
},
|
|
"//internal/storage/dolt:dolt_server_conformance_test": {
|
|
[]string{"$(rootpath :dolt_race_off)", "-test.v", "-test.count=1", "-test.timeout=15m", "-test.run=^TestConformance$$"},
|
|
map[string]string{"BEADS_TEST_DOLT_SERVER": "local", "BEADS_TEST_GIT_IDENTITY": "1", "BEADS_TEST_REQUIRE_DOLT_CONTAINER": "1", "GOMAXPROCS": "4"},
|
|
},
|
|
"//internal/storage/dolt:dolt_server_full_test": {
|
|
[]string{"$(rootpath //:.github/scripts/server-storage-test-shard.sh)", "BEADS_TEST_SERVER_TEST_BINARY", "$(rootpath :dolt_race_off)"},
|
|
map[string]string{
|
|
"BEADS_TEST_DOLT_SERVER": "local", "BEADS_TEST_ENV_RUN_DOLT": "1", "BEADS_TEST_GIT_IDENTITY": "1",
|
|
"BEADS_TEST_REQUIRE_DOLT_CONTAINER": "1", "BEADS_TEST_SUBPROCESS_BINARY": "$(rlocationpath :dolt_race_off)", "GOMAXPROCS": "4",
|
|
},
|
|
},
|
|
}
|
|
laneTags := regexp.MustCompile(`"(embedded|dolt-server-proxied|dolt-server-integration)"`)
|
|
quoted := regexp.MustCompile(`"([^"]*)"`)
|
|
envPair := regexp.MustCompile(`"([^"]*)":\s*"([^"]*)"`)
|
|
nameRe := regexp.MustCompile(`(?m)^ name = "([^"]+)",$`)
|
|
tagsRe := regexp.MustCompile(`(?ms)^ tags = \[(.*?)\],$`)
|
|
envRe := regexp.MustCompile(`(?ms)^ env = \{(.*?)\},$`)
|
|
got := map[string]target{}
|
|
err := walkBazelFiles(root, false, func(path string, d os.DirEntry) error {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
pkg, _ := filepath.Rel(root, filepath.Dir(path))
|
|
for _, rule := range bazelTopRules(string(data)) {
|
|
tags := tagsRe.FindStringSubmatch(rule)
|
|
if tags == nil || !laneTags.MatchString(tags[1]) {
|
|
continue
|
|
}
|
|
name := nameRe.FindStringSubmatch(rule)
|
|
if name == nil {
|
|
t.Errorf("%s: a retired lane's rule without a literal name:\n%s", pkg, rule)
|
|
continue
|
|
}
|
|
var tg target
|
|
for _, q := range quoted.FindAllStringSubmatch(bazelAttrBlock(rule, "args"), -1) {
|
|
tg.args = append(tg.args, q[1])
|
|
}
|
|
tg.env = map[string]string{}
|
|
if e := envRe.FindStringSubmatch(rule); e != nil {
|
|
for _, p := range envPair.FindAllStringSubmatch(e[1], -1) {
|
|
tg.env[p[1]] = p[2]
|
|
}
|
|
}
|
|
if strings.Contains(rule, "args = select") || strings.Contains(rule, "env = select") || strings.Contains(rule, "env_inherit") {
|
|
t.Errorf("//%s:%s sets args/env indirectly; keep them literal so this check sees them", pkg, name[1])
|
|
}
|
|
got["//"+filepath.ToSlash(pkg)+":"+name[1]] = tg
|
|
}
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Errorf("the retired lanes' targets' args/env changed:\ngot %v\nwant %v", got, want)
|
|
}
|
|
|
|
// D2 step 3: the PR-core, dolt-server and pure lanes run (nearly) every
|
|
// other test target, too many to pin one by one: no rule outside the
|
|
// pinned ones above, and no .bzl macro, may select, skip or switch off
|
|
// tests through its args, env or anything else.
|
|
ruleNarrow := regexp.MustCompile(`-test\.(short|run|skip|list|bench)|BEADS_TEST_SKIP|BEADS_TEST_EMBEDDED_DOLT|TESTBRIDGE_TEST_ONLY|test_filter|flaky\s*=\s*(True|1|[A-Za-z_])`)
|
|
// Second runs over tests another target already runs in full: the
|
|
// selection is the point (a required-suite contract that checks it), and
|
|
// nothing leaves the lanes. Pinned to exactly these args.
|
|
extraRunVariants := map[string][]string{
|
|
// The doc-freshness suite (also run by //scripts:scripts_test) under
|
|
// -required-suite, as pr.yml's former Linux doc-freshness leg ran it.
|
|
"//scripts:doc_freshness_required_test": {
|
|
"-test.count=1",
|
|
"-test.run=^(TestDocFreshness.*|TestRequiredSuiteContract)$$",
|
|
"-required-suite=doc-freshness",
|
|
},
|
|
}
|
|
err = walkBazelFiles(root, true, func(path string, d os.DirEntry) error {
|
|
isBzl := strings.HasSuffix(d.Name(), ".bzl")
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
rel, _ := filepath.Rel(root, path)
|
|
pkg := filepath.ToSlash(filepath.Dir(rel))
|
|
var units []string
|
|
if isBzl {
|
|
units = []string{string(data)}
|
|
} else {
|
|
units = bazelTopRules(string(data))
|
|
}
|
|
for _, unit := range units {
|
|
if !isBzl {
|
|
if name := nameRe.FindStringSubmatch(unit); name != nil {
|
|
label := "//" + pkg + ":" + name[1]
|
|
if _, pinned := want[label]; pinned {
|
|
continue
|
|
}
|
|
if wantArgs, ok := extraRunVariants[label]; ok {
|
|
var args []string
|
|
for _, q := range quoted.FindAllStringSubmatch(bazelAttrBlock(unit, "args"), -1) {
|
|
args = append(args, q[1])
|
|
}
|
|
if !reflect.DeepEqual(args, wantArgs) {
|
|
t.Errorf("%s args = %q, want exactly %q", label, args, wantArgs)
|
|
}
|
|
continue
|
|
}
|
|
}
|
|
}
|
|
for _, line := range strings.Split(unit, "\n") {
|
|
code, _, _ := strings.Cut(line, "#")
|
|
if ruleNarrow.MatchString(code) && !strings.Contains(code, "flaky = False") {
|
|
t.Errorf("%s: %q can select, skip or retry tests of the gated lanes", rel, strings.TrimSpace(line))
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
// Review G4: each retired tier's lane asks Bazel which test targets are
|
|
// flaky (a grep of BUILD files misses `flaky = _VAR` or a macro default)
|
|
// before it runs the tier, and fails on any.
|
|
func TestBazelRetiredLanesQueryFlakyTargets(t *testing.T) {
|
|
const want = `flaky="$(bazel query 'attr(flaky, 1, tests(//...))')"
|
|
if [ -n "$flaky" ]; then
|
|
echo "::error::flaky = True on ${flaky//$'\n'/ }: the gated lanes run each test once"
|
|
exit 1
|
|
fi`
|
|
for lane, config := range bazelRetiredLaneConfigs {
|
|
job := readCIWorkflow(t, bazelWorkflowName).job(t, lane)
|
|
step := job.step(t, "No test target is marked flaky")
|
|
if strings.TrimSpace(step.Run) != want || step.If != "" || step.ContinueOnError != nil {
|
|
t.Errorf("%s flaky query step: if %q, continue-on-error %v, run:\n%s\nwant run:\n%s", lane, step.If, step.ContinueOnError, step.Run, want)
|
|
}
|
|
if !(job.stepIndex(t, "Set up Bazel") < job.stepIndex(t, step.Name) && job.stepIndex(t, step.Name) < job.stepIndex(t, "bazel test //... --config="+config)) {
|
|
t.Errorf("%s flaky query step must run after setup-bazel and before the tier", lane)
|
|
}
|
|
}
|
|
}
|
|
|
|
// The retired tiers' Bazel lanes and the config each runs.
|
|
var bazelRetiredLaneConfigs = map[string]string{
|
|
bazelEmbedJobName: "embedded",
|
|
bazelProxiedJobName: "doltserver-proxied",
|
|
bazelServerJobName: "doltserver-integration",
|
|
}
|
|
|
|
// bazelTierTestRun: a retired lane's test step, exactly (review F4).
|
|
func bazelTierTestRun(config string) string {
|
|
return strings.ReplaceAll(bazelEmbeddedTestRun, "--config=embedded", "--config="+config)
|
|
}
|
|
|
|
// .bazelrc's --config=doltserver-proxied and --config=doltserver-integration,
|
|
// exactly and in order (D2 step 2, as review F4 for embedded): no
|
|
// --test_filter, no -test.short/-test.run/-test.skip, no retries (results
|
|
// are cached like every lane's; nightly's --config=fresh re-executes). Their targets' own args (the conformance target's -test.run, the
|
|
// legacy job's) are pinned by TestBazelRetiredLanesCannotBeNarrowed.
|
|
var bazelDoltServerRCLines = map[string][]string{
|
|
"doltserver-proxied": {
|
|
"test:doltserver-proxied --@rules_go//go/config:race",
|
|
"test:doltserver-proxied --test_tag_filters=dolt-server-proxied",
|
|
"test:doltserver-proxied --build_tests_only",
|
|
"test:doltserver-proxied --keep_going",
|
|
"test:doltserver-proxied --test_summary=terse",
|
|
"test:doltserver-proxied --test_timeout=-1,-1,-1,1200",
|
|
"test:doltserver-proxied --test_env=GO_TEST_WRAP_TESTV=1",
|
|
"test:doltserver-proxied --test_arg=-test.parallel=4",
|
|
"test:doltserver-proxied --local_test_jobs=4",
|
|
"test:doltserver-proxied --remote_download_regex=.*/test\\.(log|xml)$",
|
|
"test:doltserver-proxied --experimental_remote_cache_eviction_retries=0",
|
|
},
|
|
"doltserver-integration": {
|
|
"build:doltserver-integration --@rules_go//go/config:tags=gms_pure_go,integration",
|
|
"test:doltserver-integration --@rules_go//go/config:race",
|
|
"test:doltserver-integration --test_tag_filters=dolt-server-integration",
|
|
"test:doltserver-integration --build_tests_only",
|
|
"test:doltserver-integration --keep_going",
|
|
"test:doltserver-integration --test_summary=terse",
|
|
"test:doltserver-integration --test_timeout=-1,-1,-1,1200",
|
|
"test:doltserver-integration --test_env=GO_TEST_WRAP_TESTV=1",
|
|
"test:doltserver-integration --test_arg=-test.parallel=4",
|
|
"test:doltserver-integration --local_test_jobs=4",
|
|
"test:doltserver-integration --remote_download_regex=.*/test\\.(log|xml)$",
|
|
"test:doltserver-integration --experimental_remote_cache_eviction_retries=0",
|
|
},
|
|
}
|
|
|
|
// D2 step 2, as review F2/F4 for embedded: the proxied and server lanes run
|
|
// exactly `bazel test //... --config=<config>` (plus nightly's BAZEL_FRESH)
|
|
// with a BEP and nothing else, their configs are exactly the pinned lines,
|
|
// and only test:fresh sets result caching.
|
|
func TestBazelRetiredLanesArePinned(t *testing.T) {
|
|
workflow := readCIWorkflow(t, bazelWorkflowName)
|
|
for lane, config := range bazelRetiredLaneConfigs {
|
|
test := workflow.job(t, lane).step(t, "bazel test //... --config="+config)
|
|
if strings.TrimSpace(test.Run) != bazelTierTestRun(config) {
|
|
t.Errorf("%s test step run changed; want exactly:\n%s\ngot:\n%s", lane, bazelTierTestRun(config), test.Run)
|
|
}
|
|
}
|
|
rc := readPolicyFile(t, bazelPolicyRoot(t), ".bazelrc")
|
|
for config, want := range bazelDoltServerRCLines {
|
|
var got []string
|
|
for _, line := range strings.Split(rc, "\n") {
|
|
line = strings.TrimSpace(line)
|
|
head, _, _ := strings.Cut(line, " ")
|
|
if strings.HasSuffix(head, ":"+config) {
|
|
got = append(got, line)
|
|
}
|
|
}
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Errorf(".bazelrc --config=%s lines changed; want exactly:\n%s\ngot:\n%s", config, strings.Join(want, "\n"), strings.Join(got, "\n"))
|
|
}
|
|
// Results are cached like every lane's; only nightly's
|
|
// --config=fresh re-executes them (ci_merge_queue_test.go).
|
|
}
|
|
// Review F1 (step 2): no whole-invocation retry after a remote cache
|
|
// eviction in any retired lane (it would re-run, and could turn green,
|
|
// a test that failed in the first attempt), and nothing else in
|
|
// .bazelrc sets the retry count (a later value would win).
|
|
evictionAllowed := map[string]bool{bazelSoleRunEvictionLine: true}
|
|
for _, config := range bazelRetiredLaneConfigs {
|
|
want := "test:" + config + " --experimental_remote_cache_eviction_retries=0"
|
|
lines := bazelEmbeddedRCLines
|
|
if config != "embedded" {
|
|
lines = bazelDoltServerRCLines[config]
|
|
}
|
|
if !contains(lines, want) {
|
|
t.Errorf("pinned --config=%s lacks %q", config, want)
|
|
}
|
|
evictionAllowed[want] = true
|
|
}
|
|
for _, line := range strings.Split(rc, "\n") {
|
|
line = strings.TrimSpace(line)
|
|
if !strings.HasPrefix(line, "#") && strings.Contains(line, "remote_cache_eviction_retries") && !evictionAllowed[line] {
|
|
t.Errorf(".bazelrc %q: only the retired tiers' configs set the eviction retry count (to 0)", line)
|
|
}
|
|
}
|
|
// A later --cache_test_results (any config the lanes use) would win.
|
|
// Only nightly's --config=fresh (appended only when the caller asks,
|
|
// ci_merge_queue_test.go) turns result caching off.
|
|
allowed := map[string]bool{bazelFreshRCLine: true}
|
|
for _, line := range strings.Split(rc, "\n") {
|
|
line = strings.TrimSpace(line)
|
|
if !strings.HasPrefix(line, "#") && strings.Contains(line, "cache_test_results") && !allowed[line] {
|
|
t.Errorf(".bazelrc %q: only test:fresh sets test result caching", line)
|
|
}
|
|
}
|
|
}
|
|
|
|
// bazelShardScript: a manifest shard script a retired lane's sharded target
|
|
// runs, and how it runs the selected tests.
|
|
type bazelShardScript struct {
|
|
script, binVar, timeout, goTags string
|
|
race bool
|
|
pkg, cd string // cd: the directory the prebuilt binary runs in ("" = none)
|
|
}
|
|
|
|
var bazelShardScripts = []bazelShardScript{
|
|
{".github/scripts/embedded-test-shard.sh", "CMD_BINARY", "20m", "gms_pure_go", true, "./cmd/bd/", ""},
|
|
{".github/scripts/embedded-storage-test-shard.sh", "STORAGE_BINARY", "20m", "gms_pure_go", true, "./internal/storage/embeddeddolt/", ""},
|
|
{".github/scripts/proxied-test-shard.sh", "CMD_BINARY", "15m", "gms_pure_go", false, "./cmd/bd/", ""},
|
|
{".github/scripts/server-storage-test-shard.sh", "STORAGE_BINARY", "15m", "integration,gms_pure_go", false, "./internal/storage/dolt/", "internal/storage/dolt"},
|
|
}
|
|
|
|
// tail: the script's code lines (comments and blank lines dropped) from the
|
|
// prebuilt-binary branch to the end of the file, exactly.
|
|
func (c bazelShardScript) tail() []string {
|
|
race := ""
|
|
if c.race {
|
|
race = "-race "
|
|
}
|
|
out := []string{`if [ -x "$` + c.binVar + `" ]; then`}
|
|
if c.cd != "" {
|
|
out = append(out, "cd "+c.cd)
|
|
}
|
|
return append(out,
|
|
`exec "$`+c.binVar+`" -test.v -test.count=1 -test.timeout=`+c.timeout+` \`,
|
|
`-test.run "$RUN_REGEX" \`,
|
|
`"$@"`,
|
|
"else",
|
|
`echo "Warning: pre-built test binary not found at $`+c.binVar+`, falling back to go test"`,
|
|
`exec go test -tags=`+c.goTags+` -v `+race+`-count=1 -timeout `+c.timeout+` \`,
|
|
`-run "$RUN_REGEX" \`,
|
|
`"$@" \`,
|
|
c.pkg,
|
|
"fi",
|
|
)
|
|
}
|
|
|
|
const bazelShardRunRegex = `RUN_REGEX="^($(IFS='|'; echo "${SHARD_TESTS[*]}"))$"`
|
|
|
|
// shardScriptNarrowing: why src does not run exactly c.tail() as its last code
|
|
// lines, builds RUN_REGEX from the selection exactly once, and outside the
|
|
// tail neither runs tests nor selects, skips or switches them.
|
|
func shardScriptNarrowing(c bazelShardScript, src string) []string {
|
|
var errs []string
|
|
var code []string
|
|
for _, line := range strings.Split(src, "\n") {
|
|
line = strings.TrimSpace(line)
|
|
if line != "" && !strings.HasPrefix(line, "#") {
|
|
code = append(code, line)
|
|
}
|
|
}
|
|
want := c.tail()
|
|
if len(code) < len(want) || !reflect.DeepEqual(code[len(code)-len(want):], want) {
|
|
got := code
|
|
if len(code) > len(want) {
|
|
got = code[len(code)-len(want):]
|
|
}
|
|
return append(errs, fmt.Sprintf("%s: the command that runs the shard changed; want exactly:\n%s\ngot:\n%s", c.script, strings.Join(want, "\n"), strings.Join(got, "\n")))
|
|
}
|
|
narrow := regexp.MustCompile(`-test\.|(^|\s)-(short|run|skip|count|list|bench)\b|\bexec\b|\bgo (test|run)\b|"\$@"|\$\*|\beval\b|BEADS_TEST_(SKIP|EMBEDDED_DOLT|PROXIED_SERVER|ENV_RUN_DOLT|REQUIRE_DOLT_CONTAINER|DOLT_SERVER\b)|GOFLAGS|TESTBRIDGE|RUN_REGEX`)
|
|
runRegex := 0
|
|
for _, line := range code[:len(code)-len(want)] {
|
|
if line == bazelShardRunRegex {
|
|
runRegex++
|
|
continue
|
|
}
|
|
if narrow.MatchString(line) {
|
|
errs = append(errs, fmt.Sprintf("%s: %q can run, select, skip or switch the shard's tests outside its pinned command", c.script, line))
|
|
}
|
|
}
|
|
if runRegex != 1 {
|
|
errs = append(errs, fmt.Sprintf("%s: want exactly one %s, got %d", c.script, bazelShardRunRegex, runRegex))
|
|
}
|
|
return errs
|
|
}
|
|
|
|
// The shard script check itself, on the real scripts and on narrowing edits
|
|
// of one (review F2 mutations m2 and m3).
|
|
func TestShardScriptNarrowingCheck(t *testing.T) {
|
|
root := sourceRepoRoot(t)
|
|
scripts := map[string]bool{}
|
|
for _, c := range bazelShardScripts {
|
|
scripts[c.script] = true
|
|
}
|
|
// Every retired lane's sharded target runs one of these scripts.
|
|
for _, c := range []string{"embedded-test-shard.sh", "embedded-storage-test-shard.sh", "proxied-test-shard.sh", "server-storage-test-shard.sh"} {
|
|
if !scripts[".github/scripts/"+c] {
|
|
t.Errorf("bazelShardScripts lacks %s", c)
|
|
}
|
|
}
|
|
c := bazelShardScripts[3]
|
|
src := readPolicyFile(t, root, c.script)
|
|
for name, edit := range map[string][2]string{
|
|
"exec -test.short": {`-test.timeout=15m \`, `-test.timeout=15m -test.short \`},
|
|
"export BEADS_TEST_SKIP": {"set -euo pipefail\n", "set -euo pipefail\nexport BEADS_TEST_SKIP=dolt\n"},
|
|
"GOFLAGS": {"set -euo pipefail\n", "set -euo pipefail\nexport GOFLAGS=-short\n"},
|
|
"second exec": {"set -euo pipefail\n", "set -euo pipefail\n[ -n \"${X:-}\" ] && exec true\n"},
|
|
"narrowed regex": {bazelShardRunRegex, `RUN_REGEX="^(${SHARD_TESTS[0]})$"`},
|
|
"go test fallback -short": {`-v -count=1 -timeout 15m \`, `-v -short -count=1 -timeout 15m \`},
|
|
} {
|
|
if strings.Count(src, edit[0]) == 0 {
|
|
t.Fatalf("%s: mutation %q no longer applies", c.script, name)
|
|
}
|
|
if len(shardScriptNarrowing(c, strings.Replace(src, edit[0], edit[1], 1))) == 0 {
|
|
t.Errorf("%s: mutation %q passes the shard script check", c.script, name)
|
|
}
|
|
}
|
|
}
|