Compare commits

..

5 commits

Author SHA1 Message Date
Eddie the Engineer
7d8d858427 fix(ci,serve): fit the 1000-item cap's tests in the storage shard budget
Review fixes for the relaunched #7051, iteration 1.

Raising issueops.MaxApplyBatchItems from 100 to 1000 made the base-owned
TestBatchApplyContract take 604s under -race, against 97s at the old cap
(main run 35862663577). It hashed onto the legacy test-embedded-storage
shard 2/5, beside ~5m of other tests, and that shard hit its 15m budget
twice (PR Risk run 36807191489). PR Risk no longer runs the legacy tier
on same-repo PRs (#7071), but Main's push run and fork PRs still do, so
the merge would have carried the timeout to Main.

Raising the jobs' timeout-minutes alone would not fix it: the shard
script passes the binary its own -test.timeout=15m. So:

- embedded-storage-test-shard.sh passes -test.timeout=20m (and its go
  test fallback -timeout 20m), as embedded-test-shard.sh does for
  cmd/bd.
- test-embedded-storage in main.yml and pr-risk.yml: timeout-minutes 15
  -> 25, the script's 20m plus setup.
- embeddeddolt_embedded_test appends -test.timeout=19m, as
  bd_embedded_test does, so Go's timeout, which dumps every goroutine,
  fires before rbe-west's 1200s action kill, which does not.
  TestBazelEmbeddedJobMirrorsEmbeddedTier now checks the override on
  both sharded targets instead of only cmd/bd's, and the PR Risk
  coverage test pins the storage target's new args.
- embedded-storage-test-shards.txt places TestBatchApplyContract on
  shard 4, which has ~3m of other tests, and the PR's two large-batch
  tests, TestLargeBatchApplyStatementCounts_Embedded (247s) and
  TestLargeBatchApplyWallClock_Embedded (261s), on shards 2 and 5. From
  the PR run's per-test times, the heaviest shard projects to ~13m, down
  from shard 2's 15m-plus.

Also correct the stop-grace guidance. For an in-flight large apply,
Serve's drain waits out the apply's remaining deadline plus drainGrace
(5s), so the orchestrator's stop grace must be at least
--large-apply-ceiling plus 5s, as Serve's own doc says. The runbook, the
flag help, the LargeApplyCeiling field doc and the CHANGELOG entry asked
for the ceiling alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 12:37:41 +00:00
Gas City Adopt-PR
c3fa831888 fix(uow): stop a doomed large-apply retry before ctx cuts it off
retryTxBudget sizes maxElapsed once at ApplyBatch entry, but says nothing
about how long an individual attempt takes. A slow first attempt (e.g.
157s of a large apply's commit) left little of the budget for a retry,
which then got killed mid-transaction by ctx's own deadline instead of
finishing and reporting its own outcome -- surfacing as
context.DeadlineExceeded (isUnavailable excludes it -> a generic 500)
instead of the exhausted-write-conflict result this loop already reports
correctly (-> 503 + Retry-After).

RunTxResultWithin now tracks the previous attempt's duration and, before
starting a new one, stops early with the last real serialization error
when time left on ctx is less than that duration plus a fixed headroom --
but only when publicops.HasExtendedRetryBudget(ctx) is set (the same
marker retryTxBudget itself checks). Applying the look-ahead
unconditionally regressed TestApplyBatchHonorsAnExtendedRetryBudgetFromContext's
unmarked case: ordinary requests have cheap attempts and are meant to run
until their own ctx deadline ends the loop, and the large-apply-sized 5s
headroom was tripping that for any short-ctx caller with a near-instant
failing attempt.

Adds TestRunTxResultWithin_SlowAttemptStopsBeforeADoomedRetry (a 1.2s
commit against a 2s marked ctx must stop after one attempt with its own
serialization error, never DeadlineExceeded, and never touch a second
unit of work) and its control, TestRunTxResultWithin_ShortAttemptStillRetries
(a 50ms attempt against the same shape must still retry and succeed).
Both mutation-checked against the look-ahead condition and its gate.

Also updates the stale "items accepts at most 100 entries" prose on the
applyBatch endpoint description (openapi.v0.yaml) to the large-envelope
wording already used elsewhere in the spec: 1000-item cap behind the
issues.batchApplyLarge capability, large-apply-ceiling deadline extension,
<=100 unaffected. dependencies:count's own "at most 100" lines are
unrelated and untouched.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-01 12:37:40 +00:00
Eddie the Engineer
20c198f76d fix(httpapi,serve): wire the large-apply retry budget; repair stale pins
Review fixes for the large batchApply envelope, on top of the test
repairs the PR needed against main.

The extended commit-retry budget was never switched on.
internal/storage/uow's retryTxBudget lets a large apply keep retrying a
commit-time conflict past the ordinary 15s ceiling only when its context
carries issueops.WithExtendedRetryBudget's marker, and the docs on both
sides say admitLargeApply sets it, but nothing did: the marker's only
callers were the uow tests, which mark their contexts by hand. A
1000-item apply that hit a conflict still gave up after 15s with most of
its 5-minute ceiling unused. admitLargeApply now marks the run context
it builds, and TestApplyBatchMarksOnlyALargeApplyForTheExtendedRetryBudget
pins the seam over HTTP: marked at 101 and 1000 items, unmarked at 100.
Removing the mark fails the 101 and 1000 cases; marking every request in
handleApplyBatch fails the 100 case.

Smaller fixes from the same review:

- `bd serve --large-apply-ceiling` repeated the 5m default as a literal
  of its own, and since bd serve always passes a positive ceiling, that
  literal, not httpapi's, was the default every deployment ran. Export
  httpapi.DefaultLargeApplyCeiling, default the flag to it, and pin the
  flag's 5m0s default in TestServeFlags.
- admitLargeApply's release cancels the run context before clearing
  s.largeApplyDeadline, the order acquireLargeApply's doc states; it
  cleared the deadline first.
- Drop the batchfixtures test's dead t.Skipf, which waited for the cap
  to reach 1000, and correct a graph-counter comment that still cited
  the 100-item cap and the TestServeFlags doc line that called the
  no-argument server unchanged.

The PR raises issueops.MaxApplyBatchItems from 100 to 1000 and adds
`bd serve --large-apply-ceiling`, but two base-owned tests still pinned
the old surface and went red on every lane that runs them (Bazel / test,
Test (macos-latest)):

- TestServeFlags pins the exact `bd serve` flag list; add
  large-apply-ceiling.
- TestPlanApplyBatchRefusesAnUnusableRequest/too_many_items built 101
  items and expected "at most 100 items", a request the 1000 cap now
  plans successfully. Size the over-cap request and its message from
  issueops.MaxApplyBatchItems, as TestPlanApplyBatchAcceptsTheBoundary
  already does for the other side of the cap; the cap's value stays
  pinned by TestCapBatchApplyLargeTiesAllThreeLimits.

The PR's own TestLargeApplyBurstNeverStarvesSmallRequestsForSemTimeout
also went red in PR Core (-race, -p 4 on a 4-vCPU runner): all eight
small requests took 160-165ms against a 100ms bound. The stall it
guards against lasts semTimeout (5s), while a small request can still
queue briefly behind the refused large requests, each holding a general
sem slot while its body decodes. Bound it at a second, the "want well
under a second" its sibling TestLargeApplyQueueDoesNotStarveOrdinaryRequests
already uses. Pinned to four cores beside 24 busy loops, small requests
measured 183ms mean and 338ms max, and the 1s bound passed 80/80 runs;
with the one-waiter gate in acquireLargeApply disabled the test still
fails 3/3, on its 2s never-completed check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 12:37:40 +00:00
Gas City Adopt-PR
fe54ac09ef feat(httpapi,issueops): raise batchApply envelope to 1000 items with bounded large-apply handling
POST /v0/beads/issues:batchApply now accepts up to 1000 items (up from 100);
issueops.MaxApplyBatchItems moves accordingly and the request body cap rises
to 16 MiB. The whole plan still applies in exactly ONE transaction. A request
over 100 items runs under a separate, flat, operator-configured whole-run
budget (`bd serve --large-apply-ceiling`, 5 minutes by default) instead of
the ordinary 60s request deadline; a request at or under 100 items is
unaffected and keeps exactly the 60s deadline and 15s commit-retry ceiling it
always had.

Concurrency and shutdown are bounded, not just documented:
- Oversized requests serialize through a dedicated one-wide semaphore, and at
  most one caller may wait for that semaphore at a time (a CAS-guarded single
  waiter) — a burst of oversized requests is shed with 503 rather than
  queuing and starving ordinary traffic behind the general semaphore.
- The run deadline is stamped only once the slot is actually acquired, not
  at the time the request arrived.
- Graceful shutdown closes new admissions before computing its drain budget,
  then waits out an in-flight large apply up to its own remaining deadline
  (plus a few seconds' grace for the response to write); any large apply
  still queued for the semaphore when shutdown begins is refused rather than
  extending the drain further. A queued caller that disconnects gets a clean
  503, never a misclassified context error. `bd serve`'s orchestrator stop
  grace must be at least `--large-apply-ceiling` — see
  engdocs/SERVE_RUNBOOK.md.
- ApplyBatch's commit-retry budget only extends past the ordinary 15s ceiling
  on this explicit large-apply path (via a context marker), with headroom
  reserved so the final retry attempt can't be killed mid-commit by the
  context's own expiry.

A new `issues.batchApplyLarge` capability token on `GET /v0/beads/context`
lets a client learn whether a given server accepts the raised envelope.

Wall-clock measurement (embedded Dolt, whole-transaction build+commit) backs
the 5-minute ceiling default: 356 items ~12.6s (23.8x headroom), 1000 items
~57.5s (5.2x headroom).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-01 12:37:40 +00:00
Gas City Adopt-PR
d7f974d6f8 test(storage): measure ApplyBatchInTx SQL statement counts (B0)
Adds a driver.Connector-level counting/latency-injecting wrapper
(internal/storage/sqlcount) plus shared plan-request fixtures
(internal/storage/batchfixtures: mol-normalized 356/712-item shapes and a
40-item classic shape) and backend-specific pinning tests + benchmarks
(internal/storage/embeddeddolt, internal/storage/dolt) that measure the
ACTUAL number of SQL statements issueops.ApplyBatchInTx issues for each
shape, on both the embedded and Dolt (TCP) backends.

Measured totals (Prepare+Exec+Query+StmtExec+StmtQuery inside one
transaction): 356 items ~7008-7009, 712 items 14014-14015, 40 items 846,
identical on both backends (expected: statement issuance is driven by Go
application logic, not backend-specific SQL planning). Pinned with a small
(+/-2) tolerance to absorb an observed, host-contention-driven +/-1 Query
drift (Exec is deterministic on every run). This is the regression baseline
slice B2 (a later, lighter fast path) must demonstrably lower.

batchfixtures.UncappedPlan bypasses issueops.MaxApplyBatchItems so this
measurement does not depend on slice B1's cap raise.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-01 12:37:40 +00:00
1946 changed files with 23519 additions and 288774 deletions

View file

@ -1,7 +1,9 @@
npm-package/node_modules
examples/library-usage
examples/bd-example-extension-go
npm-package
website
node_modules
.claude/worktrees
.claude
.worktrees
.beads
.dolt

348
.bazelrc
View file

@ -1,27 +1,8 @@
# Bazel configuration for beads. Bazel is beads' build and test system: CI
# gates on the `bazel test` lanes in .github/workflows/bazel.yml, and
# `make test`/`make check` run the same commands (engdocs/TESTING.md
# "Building and Testing"). Plain `go build`/`go test` still work as an
# inner-loop convenience but are not what CI enforces. Where actions run is
# per machine, never committed here: contributors read the anonymous,
# read-only cache with --config=fork-cache (defined below); maintainers with
# an rbe-west client certificate execute remotely with --config=remote-exec.
# Make either the default with a `build --config=...` line in the gitignored
# .bazelrc.local. Bzlmod only; Bazel version is pinned in .bazelversion.
# Bazel configuration for beads (side-by-side with the Go toolchain; `go build`
# and `go test` are unaffected). Bzlmod only; Bazel version is pinned in
# .bazelversion.
common --enable_bzlmod
common --color=no
# C/C++ (and so cgo, -race and the Go stdlib) builds only with MODULE.bazel's
# pinned LLVM toolchain: no host-detected local_config_cc to fall back to,
# which would key actions to the client's gcc and lld and fail remote links
# on workers without lld (scripts/bazel_hermetic_cc_test.go).
common --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
# The pinned remote-worker host in every action key: //platforms:rbe_worker's
# worker-env exec property is the sha256 of tools/rbe/worker-env.txt, and
# rbe-west's schedulers run an action only on a worker that measured that
# host (platforms/BUILD.bazel). Key-affecting, so unconditional: local,
# fork-cache and remote runs hash alike.
build --extra_execution_platforms=//platforms:rbe_worker
# ICU policy (engdocs/ICU-POLICY.md): build go-mysql-server with its pure-Go
# regex backend so no target links libicu. MODULE.bazel carries the matching
@ -56,7 +37,7 @@ test:prcore --test_env=BEADS_TEST_REQUIRE_EXCLUDE_PERMISSION=1
# Every tag that belongs to another lane (scripts/bazel_policy_test.go
# bazelPRCoreExcludedTags). integration-only targets run zero tests outside
# --config=integration.
test:prcore --test_tag_filters=-dolt-server,-dolt-server-proxied,-dolt-server-integration,-dolt-server-cmd,-embedded,-manual,-integration-only
test:prcore --test_tag_filters=-requires-docker,-dolt-server,-dolt-server-proxied,-dolt-server-integration,-embedded,-manual,-integration-only
test:ci --config=prcore
test:ci --keep_going --test_summary=terse
@ -69,6 +50,29 @@ test:ci --remote_download_regex=.*/test\.xml$
# bazel.yml publishes the non-race bd as pr.yml's ci-build-artifacts.
test:ci --remote_download_regex=.*/bin/cmd/bd/bd_for_tests/bd$
# Docker lane: only the requires-docker targets (pr.yml's container-backed
# jobs "Test (storage domain + uow)" and "Contract corpus"), on a host with a
# docker daemon. Race like the domain+uow job (//cmd/bd/protocol's variant
# opts out, like the non-race Contract corpus job), but no -short and no
# BEADS_TEST_SKIP=dolt, which would keep the containers from starting. Those
# targets are also tagged no-remote-exec, so they run on the host even with
# --config=remote-exec; their builds may still run remotely. -test.v in
# test.xml, as in test:ci, lets equivalence.py see which tests ran.
test:docker --@rules_go//go/config:race
test:docker --test_tag_filters=requires-docker
test:docker --build_tests_only
test:docker --keep_going
test:docker --test_env=GO_TEST_WRAP_TESTV=1
# Those jobs pass no -p/-parallel, so go test uses GOMAXPROCS, ubuntu-latest's
# 4 vCPUs, for both. Match that on any host: 4 test processes (hence at most
# 4 dolt containers starting at once) and -test.parallel=4.
test:docker --local_test_jobs=4
test:docker --test_arg=-test.parallel=4
# The variants depend on host state no action key sees (the docker daemon,
# the pulled dolt image, the network), so a cached result proves nothing about
# this host: always run them, like the jobs' `go test -count=1`.
test:docker --nocache_test_results
# Embedded-Dolt tier: PR Risk's embedded jobs ("Test (Embedded Dolt Cmd
# N/20)", "Test (Embedded Dolt Storage N/5)", "Test (Embedded Dolt
# Conformance - core/audit)"), as the `embedded`-tagged variants of bd_test
@ -95,64 +99,45 @@ test:embedded --test_arg=-test.parallel=4
test:embedded --test_env=GO_TEST_WRAP_TESTV=1
test:embedded --remote_download_regex=.*/test\.xml$
# Since D2 step 1 this lane is the tier's only pre-merge run on same-repo PRs
# (pr-risk.yml's legacy jobs stand down). Its results are cached like every
# lane's: an unchanged test reuses its recorded PASS, and nightly re-executes
# everything (--config=fresh below).
# No whole-invocation retry on a remote cache eviction ("Lost inputs"):
# Bazel would re-run every test, and a test that failed in the first
# attempt but passes in the retry would report green, unlike the legacy
# jobs, which never retried. Evicted inputs fail the step instead; a
# visible "Re-run failed jobs" retries it.
test:embedded --experimental_remote_cache_eviction_retries=0
# The race configuration's nogo validations run once, in bazel.yml's `test`
# lane (`bazel test //... --config=ci`), which is a strict superset of every
# race-group lane's RunNogo/ValidateNogo keys. --norun_validations is a
# build-request option, not a configuration flag: it changes no action key
# (compile, link and nogo actions are shared with `test` through the action
# cache; test results are not, since each lane's test actions carry its own
# test env and args) and discards no analysis; it only skips re-running nogo's
# validation actions that the owner lane already runs on this configuration.
# scripts/nogo_lint_policy_test.go's TestNogoConfigurationsHaveOneValidatingLane
# pins `test` as this configuration's sole validating lane.
test:embedded --norun_validations
# (pr-risk.yml's legacy jobs stand down), and the legacy jobs ran every test
# every time (-test.count=1). A cached PASS would let a stale or poisoned
# farm action-cache entry, or an unreproduced -race finding, stand in for a
# run: always execute, at farm (not runner) cost.
test:embedded --nocache_test_results
# Dolt-server lane: what pr.yml's retired container-backed jobs ("Test
# (storage domain + uow)" and "Contract corpus") ran, but every dolt
# sql-server is a child of the test process, started from the pinned dolt in
# the test wrapper's runfiles (BEADS_TEST_DOLT_SERVER=local, set by each
# dolt-server target), so the targets run on remote workers and need no
# docker. As those jobs: race (//cmd/bd/protocol's variant opts out, like its
# job), no -short, no BEADS_TEST_SKIP=dolt, -test.parallel=4, and the
# no--short twins of the job's other packages. Results are cacheable: every
# input (test binary, dolt, env) is in the action key, and a server that
# cannot start fails the target (BEADS_TEST_REQUIRE_DOLT_CONTAINER=1) instead
# of skipping. test.xml is downloaded for tools/bazel/equivalence.py --job,
# test.log for bazel.yml's failure artifact.
# Dolt-server lane: the same jobs as the docker lane ("Test (storage domain +
# uow)" and "Contract corpus"), but every dolt sql-server is a child of the
# test process, started from the pinned dolt in the test wrapper's runfiles
# (BEADS_TEST_DOLT_SERVER=local, set by each dolt-server target), so the
# targets run on remote workers and need no docker. Same selection rules as
# test:docker: race (//cmd/bd/protocol's variant opts out, like its job), no
# -short, no BEADS_TEST_SKIP=dolt, -test.parallel=4, and the no--short twins
# of the job's other packages. Results are cacheable: every input (test
# binary, dolt, env) is in the action key, and a server that cannot start
# fails the target (BEADS_TEST_REQUIRE_DOLT_CONTAINER=1) instead of skipping.
# --config=docker stays as the A/B control. test.xml is downloaded for
# tools/bazel/equivalence.py --job, test.log for bazel.yml's failure artifact.
test:doltserver --@rules_go//go/config:race
test:doltserver --test_tag_filters=dolt-server
test:doltserver --build_tests_only
test:doltserver --keep_going
test:doltserver --test_env=GO_TEST_WRAP_TESTV=1
test:doltserver --test_arg=-test.parallel=4
# Locally (rbe=off, no executor): at most 4 test processes, the jobs' 4-vCPU
# runner shape; remote workers are not limited by it.
# Locally (fork PRs, rbe=off, no executor): at most 4 test processes, as in
# test:docker; remote workers are not limited by it.
test:doltserver --local_test_jobs=4
test:doltserver --remote_download_regex=.*/test\.(log|xml)$
# Race-group nogo is owned by the `test` lane; see test:embedded's comment
# above.
test:doltserver --norun_validations
# Proxied-server tier: PR Risk's "Test (Proxied Dolt Cmd N/15)" jobs, as
# //cmd/bd:bd_proxied_test and //cmd/bd:bd_managed_local_test (the
# managed-local lifecycle in a loopback-only network namespace) (the
# dolt-server-proxied tag). Kept out of
# //cmd/bd:bd_proxied_test (dolt-server-proxied tag). Kept out of
# --config=doltserver because bazel.yml runs that lane locally too (forks,
# rbe=off), where 30 concurrent shards, each with a dolt sql-server busy on
# ~4 cores, do not fit regardless of any single shard's wall time; bazel.yml
# runs this one only with remote execution, in a job of its own
# (bazel-proxied). The build is
# --config=doltserver's: race, like PR Risk's /tmp/bd-cmd-test; the
# subprocess bd is the non-race bd_for_tests, like the jobs'. Each shard runs its job's
# rbe=off), where 15 shards of ~10 minutes, each with a dolt sql-server busy
# on ~4 cores, do not fit; bazel.yml runs this one only with remote
# execution, in a job of its own (bazel-proxied). The build is
# --config=doltserver's: race, like PR Risk's /tmp/bd-cmd-test (main.yml's
# twin job runs build-artifacts' non-race bd-cmd-test, so this is the
# stricter of the two); the subprocess bd is the non-race bd_for_tests, like
# the jobs'. Each shard runs its job's
# shard script, whose -test.timeout=15m is past "long": the target is
# eternal, which rbe-west caps at 1200s.
test:doltserver-proxied --@rules_go//go/config:race
@ -166,48 +151,6 @@ 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)$
# Since D2 step 2 this lane is the tier's only pre-merge run on same-repo
# PRs. Results are cached like every lane's (nightly: --config=fresh).
# No whole-invocation retry on a remote cache eviction ("Lost inputs"):
# Bazel would re-run every test, and a test that failed in the first
# attempt but passes in the retry would report green, unlike the legacy
# jobs, which never retried. Evicted inputs fail the step instead; a
# visible "Re-run failed jobs" retries it.
test:doltserver-proxied --experimental_remote_cache_eviction_retries=0
# Race-group nogo is owned by the `test` lane; see test:embedded's comment
# above.
test:doltserver-proxied --norun_validations
# dolt-server + proxied union (item 5): bazel.yml's bazel-dolt-race job runs
# both tiers in one invocation in mode remote, in place of the bazel-doltserver
# and bazel-proxied lanes, which still run --config=doltserver and
# --config=doltserver-proxied in every other mode. Exactly the union of the two
# member configs' lines, with one tag filter naming both tiers
# (scripts/bazel_dolt_race_test.go). Every other flag is the same in both
# members or outside any action key for the other: the race build,
# -test.parallel=4 and GO_TEST_WRAP_TESTV=1 are common; the eternal timeout
# applies to no dolt-server target; the eviction retry count is what
# doltserver gets from --config=sole-run wherever it executes remotely;
# test_summary, local_test_jobs and remote_download_regex are not in any action
# key. So each member target's test action is unchanged (aquery: all 62
# TestRunner actions byte-identical), and whichever arm the mode picks shares
# cached results with the other. The member configs stay for those modes, make
# and developers.
test:dolt-race --@rules_go//go/config:race
test:dolt-race --test_tag_filters=dolt-server,dolt-server-proxied
test:dolt-race --build_tests_only
test:dolt-race --keep_going
test:dolt-race --test_summary=terse
test:dolt-race --test_timeout=-1,-1,-1,1200
test:dolt-race --test_env=GO_TEST_WRAP_TESTV=1
test:dolt-race --test_arg=-test.parallel=4
test:dolt-race --local_test_jobs=4
test:dolt-race --remote_download_regex=.*/test\.(log|xml)$
test:dolt-race --experimental_remote_cache_eviction_retries=0
# The union carries its members' --norun_validations line
# (TestBazelDoltRaceConfigIsMemberUnion needs no change: both members and the
# union carry the same line).
test:dolt-race --norun_validations
# Server-Dolt storage tier: PR Risk's "Test (Server Dolt Conformance)" and
# "Test (Server Dolt Full Suite N/16)" jobs, as
@ -235,117 +178,10 @@ 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)$
# F5 S2 Variant A: this configuration (integration, doltserver-integration,
# doltserver-cmd -- the same fingerprint, race=true plus
# tags=gms_pure_go,integration) has no full-lane owner. Its nogo runs once,
# narrowly, in bazel.yml's bazel-integration job: a `bazel build
# --output_groups=nogo_fix` step over //internal/testutil/integration only
# (the configuration's non-test library; the 56 integration-tagged _test.go
# files this loses vet/lint coverage on are listed in
# tools/nogo/unvalidated_integration_tests.txt, f5-spec.md §3/§5 S2).
# --norun_validations is a build-request option, not a configuration flag:
# it changes no action key and discards no analysis; it only skips
# re-running nogo's validation actions, which bazel-integration's nogo-only
# step already runs for this configuration's library files.
# scripts/nogo_lint_policy_test.go's TestNogoConfigurationsHaveOneValidatingLane
# pins the nogo-only step as this configuration's sole validating lane.
test:doltserver-integration --norun_validations
# Since D2 step 2 this lane is the tier's only pre-merge run on same-repo
# PRs. Results are cached like every lane's (nightly: --config=fresh).
# No whole-invocation retry on a remote cache eviction ("Lost inputs"):
# Bazel would re-run every test, and a test that failed in the first
# attempt but passes in the retry would report green, unlike the legacy
# jobs, which never retried. Evicted inputs fail the step instead; a
# visible "Re-run failed jobs" retries it.
test:doltserver-integration --experimental_remote_cache_eviction_retries=0
# cmd/bd Dolt-server tier: //cmd/bd:bd_dolt_server_test (dolt-server-cmd
# tag), the whole integration-tagged cmd/bd suite against a hermetic dolt
# sql-server, i.e. the Dolt-gated cmd/bd tests every other lane skips
# (BEADS_TEST_SKIP=dolt in --config=prcore/ci and --config=integration), and //tests/regression:regression_test
# (the differential regression suite, formerly regression.yml, against the
# catalog-pinned baseline in @bd_releases). The build flags are exactly
# --config=integration's, so it compiles nothing bazel-integration does not
# (shared through the remote cache). bazel.yml runs it where it runs the
# integration lane (remote, or with the read-only cache in mode cache), in a
# job of its own (bazel-cmd-dolt), advisory until pr.yml's
# BAZEL_CMD_DOLT_REQUIRED says otherwise. No BEADS_TEST_SKIP, no -short.
# Results are cacheable, as in --config=doltserver: every input is in the
# action key, and a server that cannot start fails the target.
build:doltserver-cmd --@rules_go//go/config:tags=gms_pure_go,integration
test:doltserver-cmd --@rules_go//go/config:race
test:doltserver-cmd --test_tag_filters=dolt-server-cmd
test:doltserver-cmd --build_tests_only
test:doltserver-cmd --keep_going
test:doltserver-cmd --test_summary=terse
test:doltserver-cmd --test_timeout=-1,-1,-1,1200
# As in --config=integration: Go's own timeout fires first and dumps every
# goroutine to test.log, which Bazel's kill at 1200s does not. Item 5 A2: the
# -test.timeout=19m arg and the BEADS_TEST_REQUIRE_EXCLUDE_PERMISSION env moved
# onto //cmd/bd:bd_dolt_server_test's and //tests/regression:regression_test's
# own args/env (the rules), so --config=dolt-int below does not need them:
# without the move, server-storage's 15m Go timeout would become 19m under
# the union, and the env would leak into server-storage's targets. The final
# argv and environment Bazel assembles (target args, then -test.timeout=19m,
# then this config's own -test.parallel=4 test_arg; same env map either way)
# are unchanged, so the remote action digest -- what RBE's cache keys on --
# is unaffected and cached results should carry over. This IS a local
# actionKey change for these two targets' 46 actions: --test_env is part of
# the build configuration's own fingerprint, picked up by every target
# analyzed under that configuration, unlike a target's own env attribute,
# which only the target carries. To be confirmed in practice by the first
# merge group's tests_cached == tests_total in ci-analytics, not claimed here
# as already observed.
test:doltserver-cmd --test_arg=-test.parallel=4
test:doltserver-cmd --test_env=GO_TEST_WRAP_TESTV=1
test:doltserver-cmd --local_test_jobs=4
test:doltserver-cmd --remote_download_regex=.*/test\.(log|xml)$
# F5 S2 Variant A: same configuration as --config=integration /
# doltserver-integration above; see that block's comment for the owner
# (bazel-integration's nogo-only step over //internal/testutil/integration).
test:doltserver-cmd --norun_validations
# server-storage + cmd-dolt union (item 5 A2): bazel.yml's bazel-dolt-int job
# runs both tiers in one invocation in mode remote, in place of the
# bazel-server-storage and bazel-cmd-dolt jobs, which still run
# --config=doltserver-integration and --config=doltserver-cmd in every other
# mode (fork-ro, fork-rw, cache, local): there one client does both tiers'
# work with no in-flight deduplication, so a union would cost the sum of the
# tiers instead of the max. Exactly the union of the two member configs'
# lines above, with one tag filter naming both members' tags
# (scripts/bazel_dolt_int_test.go). Every other flag is the same in both
# members: the race build, tags=gms_pure_go,integration, keep_going,
# test_summary, the eternal 1200s timeout, GO_TEST_WRAP_TESTV=1,
# -test.parallel=4, local_test_jobs, remote_download_regex and
# norun_validations. So each member target's test action is unchanged in the
# sense that matters for caching (aquery: all 63 TestRunner actions' remote
# action digests are byte-identical, the key RBE's cache lookups use), though
# each action's local actionKey differs since these flags now reach the
# target via its own env/args rather than the member's build configuration.
# Cached results carry over both ways regardless.
# New for cmd-dolt here: --experimental_remote_cache_eviction_retries=0.
# server-storage already has it (above); cmd-dolt did not (it has no
# --config=sole-run of its own, unlike doltserver). Adding it to the union is
# stricter for cmd-dolt (no whole-invocation retry on a remote cache
# eviction) and policy-conformant with sole-run semantics; the eviction
# allowlist in pr_risk_bazel_coverage_test.go records the new line.
build:dolt-int --@rules_go//go/config:tags=gms_pure_go,integration
test:dolt-int --@rules_go//go/config:race
test:dolt-int --test_tag_filters=dolt-server-integration,dolt-server-cmd
test:dolt-int --build_tests_only
test:dolt-int --keep_going
test:dolt-int --test_summary=terse
test:dolt-int --test_timeout=-1,-1,-1,1200
test:dolt-int --test_env=GO_TEST_WRAP_TESTV=1
test:dolt-int --test_arg=-test.parallel=4
test:dolt-int --local_test_jobs=4
test:dolt-int --remote_download_regex=.*/test\.(log|xml)$
test:dolt-int --norun_validations
test:dolt-int --experimental_remote_cache_eviction_retries=0
# Integration lane: the `go test` main.yml's former "Main Linux integration"
# jobs ran on push (this lane replaced them, and nightly.yml's retired Full
# Test Suite, which ran the same `go test` over ./... in one job): every package
# Integration lane: main.yml's "Main Linux integration packages (N/6)" and
# "Main Linux integration cmd/bd (N/8)" jobs (and nightly.yml's Full Test
# Suite, which runs the same `go test` over ./... in one job): every package
# built with -tags=integration,gms_pure_go, race, no -short, no -skip,
# BEADS_TEST_SKIP=dolt. The tag is set for the whole build, as `go test -tags`
# does, not per target: gazelle generates srcs/deps with integration files
@ -361,9 +197,7 @@ test:integration --test_env=BEADS_TEST_SKIP=dolt
# keeps every container- or server-backed test skipped, which is what the
# untagged base targets already do. scripts/bazel_policy_test.go derives the
# required exclusions from the PR-core list, so a new lane tag lands here too.
# pr-core-only targets (the historical-release suites: shell tests against
# the release-shaped bd, which the PR-core lane already runs) stay out too.
test:integration --test_tag_filters=-dolt-server,-dolt-server-proxied,-dolt-server-integration,-dolt-server-cmd,-embedded,-manual,-pr-core-only
test:integration --test_tag_filters=-requires-docker,-dolt-server,-dolt-server-proxied,-dolt-server-integration,-embedded,-manual
test:integration --build_tests_only
test:integration --keep_going
test:integration --test_summary=terse
@ -386,13 +220,6 @@ test:integration --test_env=GO_TEST_WRAP_TESTV=1
# equivalence.py / check_testcases.py right after each lane's own
# `bazel test`, before the other lane runs (or give the lanes separate jobs).
test:integration --remote_download_regex=.*/test\.xml$
# F5 S2 Variant A: same configuration as --config=doltserver-integration /
# doltserver-cmd above; see that block's comment for the owner
# (bazel-integration's nogo-only step over //internal/testutil/integration).
# The 56 integration-tagged _test.go files this configuration no longer
# validates in any full lane are the accepted loss, listed in
# tools/nogo/unvalidated_integration_tests.txt.
test:integration --norun_validations
# Pure-Go lane: pr.yml's "Check pure-Go and js/wasm boundaries
# (CGO_ENABLED=0)" job. CGO is off for every Go target (rules_go drops
@ -418,60 +245,6 @@ build:js-wasm --platforms=@rules_go//go/toolchain:js_wasm
build:js-wasm --use_target_platform_for_tests
build:js-wasm --remote_download_outputs=toplevel
# nogo (//tools/nogo: go test's vet checks plus the golangci-lint linters
# .golangci.yml enables) runs beside every Go compile, so `bazel build`/
# `bazel test` fails on a finding -- in bazel.yml's one validating (owner)
# lane per configuration (since F5 S1: a race-group non-owner lane reuses
# its owner's nogo results instead of re-running them; see
# scripts/nogo_lint_policy_test.go's nogoConfigurations table).
# --config=nogo asks for the analysis alone (the nogo_fix output group;
# nothing is linked), in the race configuration bazel.yml's unit lane
# (test:ci) builds, so a local run reuses CI's remote cache. make lint,
# scripts/pr-lint and the pre-commit hook use it.
build:nogo --@rules_go//go/config:race
build:nogo --keep_going
build:nogo --output_groups=nogo_fix
# The same analyzers over the files only other platforms compile
# (//go:build windows, darwin, !linux ...): scripts/pr-lint builds
# //tools/bazel:release_cross, every go_library and go_binary split-transitioned
# to rules_go's non-cgo platforms, for its windows/amd64 and darwin/arm64
# passes (golangci-lint's former GOOS=windows/darwin legs). bazel.yml's pure
# lane builds the same target for every release platform, which validates
# nogo there too.
build:nogo-cross --keep_going
build:nogo-cross --output_groups=nogo_fix
# D2 step 3: bazel.yml's bazel-test, bazel-pure and bazel-doltserver lanes
# add this in the remote modes, where (on same-repo PRs and merge groups)
# they are the only pre-merge run of pr.yml's legacy PR Core,
# pure-Go/js-wasm, domain+uow and contract corpus jobs, which never retried.
# Like the retired PR Risk tiers' configs: no whole-invocation retry after
# a remote cache eviction ("Lost inputs"), whose exit code outranks a test
# failure, so a test that failed in the first attempt and passed in the
# retry would report green.
test:sole-run --experimental_remote_cache_eviction_retries=0
# Test result caching. Every lane caches its test results (read and write;
# Bazel's default): a test whose action key (test binary, runfiles, test env,
# platform) is unchanged reuses the PASS the farm recorded for it, on a PR
# (any attempt), a merge group or a push to main, so only what a change
# touched runs. Why that is safe:
# - Identical key, identical test: these targets are hermetic (dolt and
# every input are runfiles).
# - A cached failure is never reused: Bazel treats a failed cached action
# as a miss, so whatever failed re-runs.
# - Only rbe-west's workers write the action cache (clients' writes are
# refused), so a cached PASS is a real remote execution, not a client
# upload.
# - What is given up is re-sampling a nondeterministic (-race, timing)
# test on unchanged inputs. nightly.yml passes fresh-test-results: true,
# so bazel.yml appends this config last to every `bazel test` and the
# whole suite re-executes once a night.
# - No retries: --experimental_remote_cache_eviction_retries=0 (the
# retired tiers' configs and sole-run) and no flaky attempts anywhere.
# Policy: scripts/ci_merge_queue_test.go.
test:fresh --nocache_test_results
# Read-only anonymous cache for fork PRs: rbe-west's rbe-cache endpoint serves
# action-cache and CAS reads only (writes and Execute are refused by the farm)
# and needs no credentials, so it is committed (scripts/bazel_policy_test.go
@ -502,9 +275,6 @@ build:fork-cache --remote_retries=2
build:fork-cache --experimental_circuit_breaker_strategy=failure
# The farm admits 16 connections per source IP.
build:fork-cache --remote_max_connections=8
# No --remote_cache_compression here: setup-bazel's write-bazelrc.sh adds it
# for fork-cache while rbe-cache advertises zstd (cache-zstd-probe.sh), so the
# server decides and rollback needs no change here.
# Remote execution against any REAPI-compatible service. Only generic tuning
# lives here; the executor endpoint and TLS credentials are never committed.
@ -515,7 +285,7 @@ build:remote-exec --remote_download_minimal
build:remote-exec --remote_timeout=600
build:remote-exec --remote_retries=3
# Upload only remotely executed results. A locally executed action (a
# no-remote-exec test, whose result depends on the host) must not seed the
# no-remote-exec test, a host-dependent docker-lane result) must not seed the
# shared cache that CI and every other developer read.
build:remote-exec --noremote_upload_local_results

View file

@ -1 +1 @@
9.3.0
9.2.0

View file

@ -201,8 +201,7 @@ document what the pinned release does, never main-only features. See
## 9. Verify before you call it done
Run the gates in [references/verification.md](references/verification.md).
The short list: `bazel test //test/docsync:docsync_test --config=ci`
(nav↔file sync + link conventions),
The short list: `go test ./test/docsync` (nav↔file sync + link conventions),
`./scripts/generate-cli-docs.sh --check` (generated docs fresh),
`./scripts/check-doc-freshness.sh` (Last reviewed markers), and a live
preview with `make docs-dev` (or `./mint.sh dev`) at `localhost:3000`.

View file

@ -39,9 +39,8 @@ don't measure that work by the word delta.
*not* simplifying — it buries the real change in the diff.
4. **Loss-check** (below).
5. **Fact-check** (below).
6. **Gates:** `bazel test //test/docsync:docsync_test --config=ci`, every
fence parses, no body H1, no HTML comments (MDX), preview with
`make docs-dev`.
6. **Gates:** `go test ./test/docsync`, every fence parses, no body H1, no
HTML comments (MDX), preview with `make docs-dev`.
7. **Preview, then commit on approval** — one page or section per batch, so
the reviewer can steer before a cut compounds across the section.

View file

@ -8,7 +8,7 @@ the binary still prints, the docs now lie.
## The discipline
1. **Survey first.** Count occurrences in `docs/`, `engdocs/`, `README.md`,
every `AGENTS.md` (root and nested), and `*.go`. Read enough to tell
`AGENTS.md`, `AGENT_INSTRUCTIONS.md`, and `*.go`. Read enough to tell
*prose* (the concept) from *literals*.
2. **Rename prose only**, with judgment per occurrence — fix articles and
grammar so it reads naturally.

View file

@ -8,7 +8,7 @@ Run these before considering docs work complete. Ordered cheapest-first.
# 1. Docs sync: docs.json nav <-> file consistency, link conventions
# (root-relative extensionless in docs/, exact paths in engdocs/ and
# curated root files), orphan detection (only CLI_REFERENCE.md is exempt).
bazel test //test/docsync:docsync_test --config=ci
go test ./test/docsync
# 2. Generated CLI docs freshness: regenerates from the live command tree
# and diffs docs/CLI_REFERENCE.md, docs/cli-reference/, and the CLI
@ -55,7 +55,7 @@ all of:
1. **Redirect** — add an entry to the `redirects` array in `docs/docs.json`
from the old route to the new one.
2. **Rewrite inbound links** — grep the whole repo, not just `docs/`:
README.md, every AGENTS.md (root and nested), engdocs/, examples/,
README.md, AGENTS.md, AGENT_INSTRUCTIONS.md, engdocs/, examples/,
npm-package/, plugins/, integrations/, scripts, and Go comments.
3. **Check bd's printed output** — if `bd` prints the old path (grep `cmd/`
and `internal/templates/` for it), fix the Go source to print the new

103
.claude/test-strategy.md Normal file
View file

@ -0,0 +1,103 @@
# Test Running Strategy for Claude Code
## Critical Rules
1. **ALWAYS use `./scripts/test.sh` instead of `go test` directly**
- It automatically skips broken tests from `.test-skip`
- Uses appropriate timeouts (3m default)
- Consistent with human developers and CI/CD
2. **Use `-run` to target specific tests when developing features**
```bash
# Good: When working on feature X
./scripts/test.sh -run TestFeatureX ./cmd/bd/...
# Avoid: Running full suite unnecessarily
./scripts/test.sh ./...
```
3. **Understand the bottleneck: COMPILATION not EXECUTION**
- 180s compilation time vs 3.8s actual test execution (cmd/bd)
- Running subset of tests doesn't save much time (still recompiles)
- But use `-run` anyway to avoid seeing unrelated failures
## Common Commands
```bash
# Full test suite (what 'make test' runs)
./scripts/test.sh
# Test specific package
./scripts/test.sh ./cmd/bd/...
./scripts/test.sh ./internal/storage/embeddeddolt/...
# Test specific feature
./scripts/test.sh -run TestCreate ./cmd/bd/...
./scripts/test.sh -run TestImport
# Verbose output (when debugging)
./scripts/test.sh -v -run TestSpecificTest
```
## When Tests Fail
1. **Check if it's a known broken test:**
```bash
cat .test-skip
```
2. **If it's new, investigate:**
- Read the test failure message
- Run with `-v` for more detail
- Check if recent code changes broke it
3. **If unfixable now:**
- File GitHub issue with details
- Add to `.test-skip` with issue reference
- Document in commit message
## Package Size Context
The `cmd/bd` package is LARGE:
- 41,696 lines of code
- 205 files (82 test files)
- 313 individual tests
- Compilation takes ~180 seconds
This is why:
- Compilation is slow
- Test script uses 3-minute timeout
- Targeting specific tests is important
## Environment Variables
Use these when needed:
```bash
# Custom timeout
TEST_TIMEOUT=5m ./scripts/test.sh
# Verbose by default
TEST_VERBOSE=1 ./scripts/test.sh
# Run pattern
TEST_RUN=TestSomething ./scripts/test.sh
```
## Quick Reference
| Task | Command |
|------|---------|
| Run all tests | `make test` or `./scripts/test.sh` |
| Test one package | `./scripts/test.sh ./cmd/bd/...` |
| Test one function | `./scripts/test.sh -run TestName` |
| Verbose output | `./scripts/test.sh -v` |
| Custom timeout | `./scripts/test.sh -timeout 10m` |
| Skip additional test | `./scripts/test.sh -skip TestFoo` |
## Remember
- The test script is in `.gitignore` path: `scripts/test.sh`
- Skip list is in repo root: `.test-skip`
- Full documentation: `engdocs/TESTING.md`
- Current broken tests: See GH issues #355, #356

View file

@ -1,5 +1,5 @@
#!/usr/bin/env bash
# Pre-commit hook: auto-format with gofmt, then lint and vet with nogo.
# Pre-commit hook: auto-format with gofmt and lint with golangci-lint.
# Installed via: git config core.hooksPath .githooks
# See also: make install (sets hooksPath automatically)
@ -9,6 +9,24 @@ set -euo pipefail
# the beads section at the bottom must run for non-Go commits too.
staged_go_files=$(git diff --cached --name-only --diff-filter=ACM -- '*.go')
if [ -n "$staged_go_files" ]; then
# Build golangci-lint from source so it is never a stale global binary, and
# pin the version to the one CI uses (.github/workflows/{pr,main}.yml).
GOLANGCI_LINT="go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.10.1"
# Build it with the repo's own Go, the way CI does. In CI, actions/setup-go
# installs the go.mod version and exports GOTOOLCHAIN=local. Locally
# GOTOOLCHAIN defaults to "auto", and for a pkg@version build that honours
# golangci-lint's own toolchain directive instead: it downgrades to
# go1.25.12, which then refuses this repo's newer go directive at config
# load ("the Go language version (go1.25) used to build golangci-lint is
# lower than the targeted Go version") and fails every Go commit. Pinning to
# the go directive reproduces CI's resolution on any host toolchain.
go_toolchain="go$(awk '$1 == "go" { print $2; exit }' go.mod)"
if [ "$go_toolchain" = "go" ]; then
echo >&2 "pre-commit: no go directive in go.mod; cannot pin the lint toolchain"
exit 1
fi
# Auto-format and re-stage, through the go.mod-pinned gofmt. A bare PATH
# gofmt belongs to the host toolchain, and on a host newer than the go
# directive it rewrites and re-stages files into a form CI's gofmt rejects
@ -17,13 +35,13 @@ if [ -n "$staged_go_files" ]; then
echo "$staged_go_files" | xargs "$gofmt_bin" -w
echo "$staged_go_files" | xargs git add
# Lint and vet: nogo (//tools/nogo) over the staged files' Bazel packages,
# the analyzers bazel.yml gates on (go test's vet checks plus the
# golangci-lint linters .golangci.yml enables). Findings fail the commit;
# nogo prints a `patch -p1` command for the ones with suggested fixes.
# Needs bazel (or bazelisk) on PATH; the windows/darwin passes run in CI
# and in `make lint`.
make lint-changed LINT_CHANGED_SCOPE=staged || exit 1
# Lint changed code with auto-fix; block on remaining issues.
# CGO_ENABLED=0 avoids typecheck failures from CGO-only dependencies
# (e.g., dolthub/go-icu-regex) that require system headers not always present.
CGO_ENABLED=0 GOTOOLCHAIN="$go_toolchain" $GOLANGCI_LINT run --new-from-rev=HEAD --fix || exit 1
# Re-stage any auto-fixes from the linter
echo "$staged_go_files" | xargs git add
fi
# --- BEGIN BEADS INTEGRATION v1.3.0 ---

View file

@ -1,10 +1,8 @@
#!/usr/bin/env bash
# Pre-push hook: run the Bazel test suite for branch pushes that change Go or
# Bazel inputs (scripts/pre-push-suite.sh), and when pushing a release tag
# (refs/tags/v*), refuse the push if version constants disagree. The version
# check stops a release from being tagged/published with drifted versions (the
# failure mode that left main red after the 1.0.5 release) before it ever
# reaches CI.
# Pre-push hook: when pushing a release tag (refs/tags/v*), refuse the push if
# version constants disagree. This stops a release from being tagged/published
# with drifted versions (the failure mode that left main red after the 1.0.5
# release) before it ever reaches CI.
#
# Installed via: git config core.hooksPath .githooks
# See also: make install (sets hooksPath automatically)
@ -28,68 +26,17 @@ if [ "$pushing_version_tag" -eq 1 ]; then
repo_root="$(git rev-parse --show-toplevel)"
# Skip on older checkouts without the consistency check; do not block.
if [ -x "$repo_root/scripts/check-versions.sh" ]; then
while read -r local_ref _local_sha _remote_ref _remote_sha; do
case "$local_ref" in
refs/tags/v[0-9]*)
tag_version="${local_ref#refs/tags/v}"
echo "Release tag v$tag_version push detected — verifying version consistency..."
checker_status=0
(cd "$repo_root" && ./scripts/check-versions.sh --expect "$tag_version") || checker_status=$?
if [ "$checker_status" -ne 0 ]; then
echo ""
if [ "$checker_status" -eq 1 ]; then
echo "❌ Refusing to push release tag v$tag_version: versions are inconsistent." >&2
echo " See the checker output above for what is inconsistent and how to fix it." >&2
elif [ "$checker_status" -eq 3 ]; then
echo "❌ Refusing to push release tag v$tag_version: the tag does not match this checkout's release version." >&2
echo " The release surfaces agree with each other, so do NOT re-run update-versions.sh." >&2
echo " Push only the tag matching this checkout (see CONTRIBUTING.md)." >&2
else
echo "❌ Refusing to push release tag v$tag_version: version checker unavailable or failed (exit $checker_status)." >&2
echo " Check the Go toolchain and checker diagnostics above." >&2
fi
echo " Override with --no-verify only if you know what you are doing." >&2
exit 1
fi
;;
esac
done <<< "$push_refs"
echo "Release tag push detected — verifying version consistency..."
if ! (cd "$repo_root" && ./scripts/check-versions.sh); then
echo ""
echo "❌ Refusing to push release tag: versions are inconsistent." >&2
echo " Fix with: scripts/update-versions.sh <version>" >&2
echo " Override with --no-verify only if you know what you are doing." >&2
exit 1
fi
fi
fi
# The push-time test suite (scripts/pre-push-suite.sh): bazel.yml's test lane,
# `bazel test //... --config=ci`, for branch pushes whose new commits change
# Go or Bazel inputs. A tag push, a deletion, or a docs-only push skips it.
# BD_PREPUSH_SUITE=go runs plain go test instead, under a banner.
#
# The decision keys on the remote ref and the shas, never on the local ref's
# shape: for `git push origin HEAD` and `HEAD:refs/heads/x` git passes the
# literal local ref `HEAD`, which a `refs/heads/*` match would skip (#7351).
zero_sha=0000000000000000000000000000000000000000
suite_needed=0
while read -r _local_ref local_sha remote_ref remote_sha; do
case "$remote_ref" in
refs/tags/*) continue ;;
esac
if [ "$local_sha" = "$zero_sha" ] || ! git cat-file -e "$local_sha^{commit}" 2>/dev/null; then
continue
fi
base="$remote_sha"
if [ "$base" = "$zero_sha" ] || ! git cat-file -e "$base^{commit}" 2>/dev/null; then
# A new remote branch: compare against main's merge-base.
base="$(git merge-base "$local_sha" origin/main 2>/dev/null || true)"
fi
if [ -z "$base" ] || git diff --name-only "$base" "$local_sha" -- \
'*.go' 'go.mod' 'go.sum' '*.bazel' '*.bzl' '.bazelrc' '.bazelversion' 'MODULE.bazel.lock' | grep -q .; then
suite_needed=1
fi
done <<< "$push_refs"
if [ "$suite_needed" -eq 1 ]; then
repo_root="$(git rev-parse --show-toplevel)"
"$repo_root/scripts/pre-push-suite.sh" </dev/null
fi
exec < <(printf '%s\n' "$push_refs")
# --- BEGIN BEADS INTEGRATION v1.3.0 ---

View file

@ -1,94 +0,0 @@
name: Bug report
description: Report broken behavior in bd.
title: "bug: "
body:
- type: markdown
attributes:
value: |
Thanks for the report. This issue is the record a fix PR links to, so the more evidence here, the better. You can open a fix PR right away; no approval is needed first.
**Agents filling in this form:** answer each question only from evidence you have. If you cannot answer a question from the evidence, write exactly `NOT_ENOUGH_INFO` instead of guessing.
- type: checkboxes
id: checks
attributes:
label: Before you continue
options:
- label: I searched existing issues and did not find a duplicate.
required: true
- label: I reproduced this with stock `bd`, without an orchestrator or agent framework in the loop.
required: false
- type: textarea
id: summary
attributes:
label: Summary
description: What is broken, in one or two sentences.
validations:
required: true
- type: textarea
id: repro
attributes:
label: Steps to reproduce
description: Exact commands, starting from a fresh directory where possible.
render: shell
validations:
required: true
- type: textarea
id: expected
attributes:
label: Expected behavior
validations:
required: true
- type: textarea
id: actual
attributes:
label: Actual behavior
description: Include the full error output.
validations:
required: true
- type: input
id: version
attributes:
label: bd version
description: Output of `bd version`.
validations:
required: true
- type: dropdown
id: mode
attributes:
label: Storage mode
options:
- Embedded (default `bd init`)
- Server mode (`bd init --server`)
- Proxied server
- Not sure
validations:
required: true
- type: input
id: os
attributes:
label: Operating system
placeholder: "macOS 15.5 (arm64), Ubuntu 24.04, Windows 11, ..."
validations:
required: true
- type: textarea
id: impact
attributes:
label: Impact
description: Who is affected, how severe it is (data loss, blocked, workaround exists), and how often it happens.
validations:
required: true
- type: textarea
id: context
attributes:
label: Additional context
description: Logs, `bd doctor` output, root-cause notes, or a proposed fix.

View file

@ -1,11 +0,0 @@
blank_issues_enabled: false
contact_links:
- name: Documentation
url: https://beads.gascity.com/
about: Installation, concepts, CLI reference, and troubleshooting.
- name: Questions and ideas
url: https://github.com/gastownhall/beads/discussions
about: Ask usage questions or float an idea before it is ready to be an issue.
- name: Security vulnerability
url: https://github.com/gastownhall/beads/security/policy
about: Report security issues privately, never in a public issue.

View file

@ -1,108 +0,0 @@
name: Feature request
description: Propose a change to bd, with the information needed to accept it.
title: "feat: "
body:
- type: markdown
attributes:
value: |
This form collects the context reviewers and future readers need for a change worth discussing. You can open your PR right after filing; no approval is needed first. Small, self-explanatory changes can skip the issue and go straight to a PR. Read the [project charter](https://github.com/gastownhall/beads/blob/main/engdocs/PROJECT_CHARTER.md) first — beads owns issue-tracking primitives, not orchestration policy or storage-engine behavior.
**Agents filling in this form:** answer each question only from evidence you have. If you cannot answer a question from the evidence, write exactly `NOT_ENOUGH_INFO` instead of guessing.
- type: checkboxes
id: checks
attributes:
label: Before you continue
options:
- label: I searched existing issues and pull requests and did not find a duplicate.
required: true
- type: textarea
id: motivation
attributes:
label: Motivation
description: The problem, and who has it. Describe the pain, not the implementation you prefer.
validations:
required: true
- type: textarea
id: proposal
attributes:
label: Proposed change
description: The behavior, command, flag, or API you want.
validations:
required: true
- type: textarea
id: impact
attributes:
label: Impact
description: Who is affected and how — users, agents, integrations, downstream consumers of the `--json` output.
validations:
required: true
- type: textarea
id: risk
attributes:
label: Risk and compatibility
description: Schema or migration changes, wire or `--json` output changes, behavior changes for existing workspaces, and how to roll back.
validations:
required: true
- type: textarea
id: verification
attributes:
label: Verification plan
description: How we will know it works end to end, beyond unit tests.
validations:
required: true
- type: textarea
id: alternatives
attributes:
label: Alternatives considered
description: Current workarounds, issue metadata, an integration or plugin, or other designs.
- type: dropdown
id: size
attributes:
label: Estimated size
options:
- XS (under 50 lines)
- S (under 200 lines)
- M (under 500 lines)
- L (under 1,000 lines)
- XL (more than 1,000 lines; likely needs splitting)
- Not sure
validations:
required: true
- type: dropdown
id: intent
attributes:
label: Intent
options:
- I am opening or will open a PR
- I'm reporting the need; someone else would implement it
validations:
required: true
- type: dropdown
id: ai
attributes:
label: AI assistance
description: Was an AI agent used to draft this issue?
options:
- "No"
- Yes, partly
- Yes, mostly
validations:
required: true
- type: checkboxes
id: accountability
attributes:
label: Accountability
options:
- label: A human has read this issue and stands behind it.
required: true

View file

@ -1,24 +1,16 @@
<!--
Link an issue when there is one (`Closes #123`); it is recommended for
user-visible bugs and changes worth discussing, and optional for small,
self-explanatory fixes. Either way, say why the change is needed below. See
CONTRIBUTING.md#issues-and-pull-requests.
This is a starting scaffold to help reviewers (human and agent) parse intent before diff.
Replace, expand, or delete sections freely. CONTRIBUTING.md has the full hygiene rules.
-->
Closes #
## What
## What changed
<!-- One or two plain-language sentences: what does this change do? -->
<!-- One or two plain-language sentences. -->
## Why
## Evidence it works
<!-- The problem this solves, the motivation, or a link to the issue: e.g. "Fixes #123" -->
<!-- Commands a reviewer can run and what they show, end to end.
"Unit tests pass" alone is not evidence. -->
## Verification
## Checklist
- [ ] The why is documented: in a linked issue (reproduction or motivation, impact, risk) or in this description.
- [ ] `make test` (the Bazel test lane, nogo lint included) and any other lane `engdocs/TESTING.md` selects pass locally.
- [ ] User-facing behavior changes are reflected in `docs/` or the generated CLI reference.
- [ ] If an invariant or rule changed, the owning `AGENTS.md` is updated.
<!-- How you tested. Commands a reviewer can run to confirm. -->

View file

@ -8,15 +8,9 @@ description: >
BAZEL_REMOTE_EXECUTOR, RBE_TLS_CERT and RBE_TLS_KEY in the step env, that rc
enables --config=remote-exec for every bazel command; with none of them the
job runs locally; with BAZEL_FORK_CACHE=true (and no secrets) it enables
the read-only fork cache (--config=fork-cache), and with BAZEL_RRC_READ=true
too (the remote repo contents cache readers) Bazel's remote repo contents
cache through rbe-cache while it answers; with BAZEL_FORK_REMOTE=true
(fork and Dependabot PRs, bazel.yml modes fork-ro/fork-rw; needs
RBE_FORK_PR and RBE_FORK_TIER) it gets a short-lived certificate from
rbe-fork-mint (fork-credential.sh, proving the run with a CSR artifact) and
enables remote execution on rbe-fork; a partial set, or two of these
together, fails. `bazel` on PATH is a wrapper that always passes the
generated rc.
the read-only fork cache (--config=fork-cache, fork PRs); a partial set,
or the fork cache together with the secrets, fails. `bazel` on PATH is a
wrapper that always passes the generated rc.
outputs:
remote:
description: '"true" when remote execution is configured'
@ -41,18 +35,15 @@ runs:
# unverified repo contents cache is off (write-bazelrc.sh) and the Bazel
# binary is not cached, so a poisoned entry (a cache written by an
# untrusted run) cannot change what executes. v3: v2 also held Bazelisk's
# download and the contents cache. v4: MODULE.bazel joins the key because
# the lock does not record non-registry repository rules (llvm_dist), so
# v3 kept restoring the 1.94 GB LLVM .tar.xz after the switch to the
# 149 MB slice.
# download and the contents cache.
- name: Restore Bazel runner cache
id: restore
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ runner.temp }}/bazel-ci-cache
key: bazel-repo-v4-${{ runner.os }}-${{ hashFiles('.bazelversion', 'MODULE.bazel', 'MODULE.bazel.lock') }}
key: bazel-repo-v3-${{ runner.os }}-${{ hashFiles('.bazelversion', 'MODULE.bazel.lock') }}
restore-keys: |
bazel-repo-v4-${{ runner.os }}-
bazel-repo-v3-${{ runner.os }}-
- name: Install Bazelisk
shell: bash
@ -78,8 +69,6 @@ runs:
case "$bazel_version/$arch" in
9.2.0/amd64) bazel_sha=7668a95db1250f12c40407251e4e203b4ec8bf39bc495d2f485b2d8c99048694 ;;
9.2.0/arm64) bazel_sha=049dd21f40ad979db11c3ee68c96a42ce75f1185e69ac61ab20de1501427a410 ;;
9.3.0/amd64) bazel_sha=d302d22ed77ee5658b87857249baa579db84300ecebe0a1e9a357b5b20f80eb8 ;;
9.3.0/arm64) bazel_sha=615cc2509819047e4930fe6643c5f01ebd705ccadf75e8f0b85f9b83cc6a6ca0 ;;
*) echo "setup-bazel: no pinned sha256 for Bazel '$bazel_version' ($arch); add it from the release's .sha256 file" >&2; exit 1 ;;
esac
{
@ -88,49 +77,12 @@ runs:
echo "BAZEL_CI_BAZEL_SHA256=$bazel_sha"
} >> "$GITHUB_ENV"
# Fork and Dependabot runs (no secrets, no OIDC): a key and a CSR, the CSR
# as an artifact of this run (the mint's proof that the request comes
# from a running job of it), then the certificate. The key stays in the
# secret dir; the CSR and the certificate are public.
# fork-credential.sh key does nothing (no outputs) unless the caller set
# BAZEL_FORK_REMOTE=true; the next two steps follow its csr output.
- name: rbe-fork key and CSR
id: fork-key
shell: bash
env:
BAZEL_CI_SECRET_DIR: ${{ runner.temp }}/bazel-ci-secret
run: bash "$GITHUB_ACTION_PATH/fork-credential.sh" key
- name: rbe-fork CSR artifact (proof of this run)
id: fork-csr
if: steps.fork-key.outputs.csr != ''
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: ${{ steps.fork-key.outputs.artifact-name }}
path: ${{ steps.fork-key.outputs.csr }}
retention-days: 1
if-no-files-found: error
compression-level: 0
- name: rbe-fork certificate (rbe-fork-mint)
id: fork-cert
if: steps.fork-key.outputs.csr != ''
shell: bash
env:
BAZEL_CI_SECRET_DIR: ${{ runner.temp }}/bazel-ci-secret
ARTIFACT_ID: ${{ steps.fork-csr.outputs.artifact-id }}
run: bash "$GITHUB_ACTION_PATH/fork-credential.sh" cert
- name: Write CI bazelrc
id: rc
shell: bash
env:
BAZEL_CI_CACHE_DIR: ${{ runner.temp }}/bazel-ci-cache
BAZEL_CI_SECRET_DIR: ${{ runner.temp }}/bazel-ci-secret
RBE_FORK_CERT_FILE: ${{ steps.fork-cert.outputs.cert }}
RBE_FORK_KEY_FILE: ${{ steps.fork-cert.outputs.key }}
RBE_FORK_ENDPOINT: ${{ steps.fork-cert.outputs.endpoint }}
RBE_FORK_INSTANCE: ${{ steps.fork-cert.outputs.instance }}
run: bash "$GITHUB_ACTION_PATH/write-bazelrc.sh"
- name: Install bazel wrapper

View file

@ -1,151 +0,0 @@
#!/usr/bin/env bash
# May this fork-cache lane read Bazel's remote repo contents cache through
# rbe-west's anonymous read-only cache (rbe-cache :8443, .bazelrc's
# fork-cache) right now? Exits 0 only when the kill switch below is on,
# rbe-cache answers a REAPI GetCapabilities for instance oss with gRPC status
# 0 and a ServerCapabilities that has cache_capabilities, and then answers a
# GetActionResult for a key no action has, and a ByteStream Read for a blob
# the CAS does not hold, each with NOT_FOUND (gRPC 5): the whole read chain
# (Caddy, nativelink-anon, the action cache and the CAS) is up. Anything else
# exits nonzero: switched off, an HTTP or gRPC error, a refused connection,
# a timeout, an answer that does not parse, no curl or python3. The caller
# then writes no repo contents cache lines, and never fails on it. The
# verdict carries the GetCapabilities TCP connect time without the DNS
# lookup (about one round trip to rbe-cache), for the lane's step summary.
#
# Why a probe: with the startup flag set and the cache unreachable (closed
# by rbe-west's kill switch, or down), Bazel retries every repository
# against it before fetching it itself (engdocs/design/
# bazel-remote-repo-contents-cache.md, R6), which costs far more than the
# cache saves. Fork pull_request runs see no repository variables, so the
# opt-out is the committed line below and the server's own answer.
#
# Three gRPC calls over curl's HTTP/2, the first answer decoded by
# python3's standard library: no grpcurl, no new action. Nothing goes to
# stdout (callers write their rc from it); one verdict line goes to stderr. A copy lives in gascity
# (tools/rbe/) and beads (.github/actions/setup-bazel/); keep in sync, except
# the kill switch, which is each repository's own.
#
# Tests only: RBE_CACHE_PROBE_URL (a stand-in server) and
# RBE_CACHE_PROBE_MAX_TIME (seconds).
set -uo pipefail
# Kill switch: off stops this repository's fork-cache lanes reading the
# remote repo contents cache (they fetch external repositories themselves),
# with a one-line pull request; on lets rbe-cache's answer decide. To stop
# every reader of rbe-cache, set it off in both copies (gascity and beads).
# It reaches a lane when the lane's checkout carries it.
fork_rrc_read=on
url=${RBE_CACHE_PROBE_URL:-https://rbe-cache.ops.gascity.com:8443}
max_time=${RBE_CACHE_PROBE_MAX_TIME:-5}
rtt=
no() {
echo "rbe-cache rrc probe: $*${rtt:+ ($rtt)}; this lane fetches external repositories itself" >&2
exit 1
}
[ "$fork_rrc_read" = on ] || no "switched off (fork_rrc_read=$fork_rrc_read in $(basename "$0"))"
command -v curl >/dev/null 2>&1 || no "no curl"
command -v python3 >/dev/null 2>&1 || no "no python3"
tmp=$(mktemp -d) || no "no temp dir"
trap 'rm -rf "$tmp"' EXIT
# call WHAT METHOD REQ: one gRPC call (METHOD: service/method); the answer's
# messages go to $tmp/body, its grpc-status to $st, and the TCP connect time
# without the DNS lookup to $tc. Fails the probe (prefixed with WHAT) on a
# transport error or a non-200 answer.
call() {
local what=$1 out code dns
out=$(curl -sS --http2 --connect-timeout 3 --max-time "$max_time" \
-H 'content-type: application/grpc' -H 'te: trailers' \
--data-binary @"$3" -D "$tmp/head" -o "$tmp/body" -w '%{http_code} %{time_namelookup} %{time_connect}' \
"$url/$2" 2>"$tmp/err") ||
no "$what$(tr '\n' ' ' <"$tmp/err")"
read -r code dns tc <<<"$out"
tc=$(awk -v d="$dns" -v c="$tc" 'BEGIN { if (c > d) printf "%.6f", c - d }' 2>/dev/null) || tc=
[ "$code" = 200 ] || no "${what}HTTP $code"
# grpc-status is a trailer; curl writes trailers after the headers.
st=$(tr -d '\r' <"$tmp/head" | sed -n 's/^grpc-status: *//Ip' | tail -1)
}
# GetCapabilitiesRequest{instance_name: "oss"} (fork-cache's
# --remote_instance_name) as one uncompressed gRPC message.
printf '\000\000\000\000\005\012\003oss' >"$tmp/req" || no "cannot write the request"
call "" build.bazel.remote.execution.v2.Capabilities/GetCapabilities "$tmp/req"
rtt=$(awk -v s="$tc" 'BEGIN { if (s > 0) printf "tcp connect %.1f ms", s * 1000 }' 2>/dev/null) || rtt=
[ "$st" = 0 ] || no "gRPC status ${st:-missing}"
why=$(python3 -I - "$tmp/body" <<'PY'
import sys
def varint(b, i):
v = s = 0
while True:
if i >= len(b) or s > 63:
raise ValueError("truncated varint")
c = b[i]
i += 1
v |= (c & 0x7F) << s
s += 7
if c < 0x80:
return v, i
def fields(b):
i = 0
while i < len(b):
key, i = varint(b, i)
num, wire = key >> 3, key & 7
if wire == 0:
v, i = varint(b, i)
elif wire == 1:
v, i = b[i:i + 8], i + 8
elif wire == 2:
n, i = varint(b, i)
v, i = b[i:i + n], i + n
elif wire == 5:
v, i = b[i:i + 4], i + 4
else:
raise ValueError("wire type %d" % wire)
if i > len(b):
raise ValueError("truncated field %d" % num)
yield num, wire, v
try:
body = open(sys.argv[1], "rb").read()
if len(body) < 5 or body[0] != 0:
raise ValueError("not an uncompressed gRPC message")
n = int.from_bytes(body[1:5], "big")
if len(body) != 5 + n:
raise ValueError("gRPC length %d, %d bytes" % (n, len(body) - 5))
# ServerCapabilities.cache_capabilities
cache = [v for num, wire, v in fields(body[5:]) if num == 1 and wire == 2]
except (OSError, ValueError) as e:
print("unreadable answer (%s)" % e)
sys.exit(2)
if not cache:
print("no cache_capabilities in the answer")
sys.exit(1)
PY
) || no "${why:-python3 failed}"
# GetActionResultRequest{instance_name: "oss", action_digest: {hash:
# sha256("cache-rrc-probe: no action has this key"), size_bytes: 1}}: a key
# no action has, so the action cache behind rbe-cache must say NOT_FOUND.
key=ad12d7a2f1dec188fc1f2c4f5535a4a65eb630fa2f309eca423695e6ec7abee7
printf '\000\000\000\000\113\012\003oss\022\104\012\100%s\020\001' "$key" >"$tmp/req" ||
no "cannot write the request"
call "GetActionResult: " build.bazel.remote.execution.v2.ActionCache/GetActionResult "$tmp/req"
[ "$st" = 5 ] || no "GetActionResult: gRPC status ${st:-missing}, want 5 (NOT_FOUND)"
# ReadRequest{resource_name: "oss/blobs/<the same hash>/1"}: a blob the CAS
# does not hold (its content would have to hash to that key), so the CAS
# behind rbe-cache must say NOT_FOUND.
printf '\000\000\000\000\116\012\114oss/blobs/%s/1' "$key" >"$tmp/req" ||
no "cannot write the request"
call "ByteStream Read: " google.bytestream.ByteStream/Read "$tmp/req"
[ "$st" = 5 ] || no "ByteStream Read: gRPC status ${st:-missing}, want 5 (NOT_FOUND)"
echo "rbe-cache rrc probe: rbe-cache answers GetCapabilities, GetActionResult and ByteStream Read${rtt:+ ($rtt)}; this lane reads the remote repo contents cache" >&2

View file

@ -1,119 +0,0 @@
#!/usr/bin/env bash
# Does rbe-west's anonymous read-only cache (rbe-cache :8443, .bazelrc's
# fork-cache) advertise zstd right now? Exits 0 only when its REAPI
# GetCapabilities answer lists ZSTD in cache_capabilities.supported_compressors,
# the field Bazel checks before it accepts --remote_cache_compression (it
# refuses a remote that does not list it). Anything else exits nonzero: not
# listed, an HTTP or gRPC error, a refused connection, a timeout, an answer
# that does not parse, no curl or python3. The caller then leaves the flag
# off, and never fails on it.
#
# So the server decides, at run time: when rbe-west turns zstd on, fork-cache
# runs use it; when it turns it off (rollback), they stop. No repository
# variable (fork pull_request runs see none) and no revert.
#
# One unary gRPC call over curl's HTTP/2, decoded by python3's standard
# library: no grpcurl, no new action. Nothing goes to stdout (callers write
# their rc from it); one verdict line goes to stderr. A byte copy lives in
# gascity (tools/rbe/) and beads (.github/actions/setup-bazel/); keep in sync.
#
# Tests only: RBE_CACHE_PROBE_URL (a stand-in server) and
# RBE_CACHE_PROBE_MAX_TIME (seconds).
set -uo pipefail
url=${RBE_CACHE_PROBE_URL:-https://rbe-cache.ops.gascity.com:8443}
max_time=${RBE_CACHE_PROBE_MAX_TIME:-5}
no() {
echo "rbe-cache zstd probe: $*; the fork cache stays identity" >&2
exit 1
}
command -v curl >/dev/null 2>&1 || no "no curl"
command -v python3 >/dev/null 2>&1 || no "no python3"
tmp=$(mktemp -d) || no "no temp dir"
trap 'rm -rf "$tmp"' EXIT
# GetCapabilitiesRequest{instance_name: "oss"} (fork-cache's
# --remote_instance_name) as one uncompressed gRPC message.
printf '\000\000\000\000\005\012\003oss' >"$tmp/req" || no "cannot write the request"
code=$(curl -sS --http2 --connect-timeout 3 --max-time "$max_time" \
-H 'content-type: application/grpc' -H 'te: trailers' \
--data-binary @"$tmp/req" -D "$tmp/head" -o "$tmp/body" -w '%{http_code}' \
"$url/build.bazel.remote.execution.v2.Capabilities/GetCapabilities" 2>"$tmp/err") ||
no "$(tr '\n' ' ' <"$tmp/err")"
[ "$code" = 200 ] || no "HTTP $code"
# grpc-status is a trailer; curl writes trailers after the headers.
st=$(tr -d '\r' <"$tmp/head" | sed -n 's/^grpc-status: *//Ip' | tail -1)
[ "$st" = 0 ] || no "gRPC status ${st:-missing}"
why=$(python3 -I - "$tmp/body" <<'PY'
import sys
ZSTD = 1 # build.bazel.remote.execution.v2.Compressor.Value.ZSTD
def varint(b, i):
v = s = 0
while True:
if i >= len(b) or s > 63:
raise ValueError("truncated varint")
c = b[i]
i += 1
v |= (c & 0x7F) << s
s += 7
if c < 0x80:
return v, i
def fields(b):
i = 0
while i < len(b):
key, i = varint(b, i)
num, wire = key >> 3, key & 7
if wire == 0:
v, i = varint(b, i)
elif wire == 1:
v, i = b[i:i + 8], i + 8
elif wire == 2:
n, i = varint(b, i)
v, i = b[i:i + n], i + n
elif wire == 5:
v, i = b[i:i + 4], i + 4
else:
raise ValueError("wire type %d" % wire)
if i > len(b):
raise ValueError("truncated field %d" % num)
yield num, wire, v
try:
body = open(sys.argv[1], "rb").read()
if len(body) < 5 or body[0] != 0:
raise ValueError("not an uncompressed gRPC message")
n = int.from_bytes(body[1:5], "big")
if len(body) != 5 + n:
raise ValueError("gRPC length %d, %d bytes" % (n, len(body) - 5))
compressors = []
for num, wire, v in fields(body[5:]):
if num != 1 or wire != 2: # ServerCapabilities.cache_capabilities
continue
for cnum, cwire, cv in fields(v):
if cnum != 6: # CacheCapabilities.supported_compressors
continue
if cwire == 0:
compressors.append(cv)
elif cwire == 2: # packed
j = 0
while j < len(cv):
x, j = varint(cv, j)
compressors.append(x)
except (OSError, ValueError) as e:
print("unreadable answer (%s)" % e)
sys.exit(2)
if ZSTD in compressors:
print("advertises zstd")
sys.exit(0)
print("zstd not advertised (supported_compressors %s)" % compressors)
sys.exit(1)
PY
) || no "${why:-python3 failed}"
echo "rbe-cache zstd probe: $why; the fork cache uses zstd" >&2

View file

@ -1,91 +0,0 @@
#!/usr/bin/env bash
# setup-bazel: a short-lived rbe-west client certificate for fork and
# Dependabot pull_request runs, which get no secrets and no OIDC token
# (infra nativelink-cas/west README "rbe-fork"). Two steps around the CSR
# artifact upload (action.yml):
#
# fork-credential.sh key an EC P-256 key in BAZEL_CI_SECRET_DIR (outside the
# workspace; PKCS#8: Bazel's Netty TLS refuses a
# SEC1 "EC PRIVATE KEY"), and a CSR for the upload.
# Outputs: csr (path), artifact-name.
# fork-credential.sh cert asks rbe-fork-mint for a certificate naming the
# uploaded artifact (ARTIFACT_ID). Outputs: cert,
# key, endpoint, instance, tier.
#
# The mint signs only for an in-progress pull_request run of this repository
# whose artifact holds this CSR (only code running in the run can upload one),
# at the head of RBE_FORK_PR. It decides the tier from the PR's author and the
# run's triggering actor; RBE_FORK_TIER is what the rbe job's status probe
# said, and a different answer fails the job (re-run all jobs). The key never
# leaves the runner; the certificate is public. Nothing here is secret enough
# to mask, but the key file is 0600 like the CI key.
set -euo pipefail
MINT=${RBE_FORK_MINT:-https://rbe-mint.ops.gascity.com:8444}
ENDPOINT_RE=${RBE_FORK_ENDPOINT_RE:-'^grpcs://rbe-fork\.ops\.gascity\.com:8444$'}
dir=${BAZEL_CI_SECRET_DIR:?BAZEL_CI_SECRET_DIR is required}
out=${GITHUB_OUTPUT:-/dev/stdout}
case "${1:-}" in
key)
# Only fork and Dependabot runs (bazel.yml modes fork-ro/fork-rw).
[ "${BAZEL_FORK_REMOTE:-}" = true ] || exit 0
install -d -m 0700 "$dir"
csr_dir="${RUNNER_TEMP:?}/rbe-csr"
rm -rf "$csr_dir" && install -d -m 0700 "$csr_dir"
umask 077
openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out "$dir/fork.key" 2>/dev/null
openssl req -new -key "$dir/fork.key" -subj "/CN=rbe-fork-request" -out "$csr_dir/csr.pem"
job=${GITHUB_JOB:?}
[[ $job =~ ^[a-z0-9][a-z0-9_-]{0,39}$ ]] || { echo "setup-bazel: job id '$job' does not fit the mint's job pattern" >&2; exit 1; }
{
echo "csr=$csr_dir/csr.pem"
echo "artifact-name=rbe-csr-$job-${GITHUB_RUN_ATTEMPT:?}-$(openssl rand -hex 8)"
} >>"$out"
;;
cert)
: "${ARTIFACT_ID:?}" "${RBE_FORK_PR:?}" "${RBE_FORK_TIER:?}" "${GITHUB_REPOSITORY:?}" "${GITHUB_RUN_ID:?}"
body=$(jq -cn --arg repo "${GITHUB_REPOSITORY#*/}" --argjson run "$GITHUB_RUN_ID" \
--argjson attempt "${GITHUB_RUN_ATTEMPT:?}" --argjson pr "$RBE_FORK_PR" --arg job "${GITHUB_JOB:?}" \
--argjson artifact "$ARTIFACT_ID" \
'{repo: $repo, run_id: $run, run_attempt: $attempt, pr: $pr, job: $job, artifact_id: $artifact}')
reply="$dir/mint.json"
code=000
for attempt in 1 2 3 4; do
# --connect-timeout: a closed gate drops the SYN; fail fast, not in 60 s.
code=$(curl -sS -o "$reply" -w '%{http_code}' --connect-timeout 5 --max-time 60 \
-H 'content-type: application/json' --data "$body" "$MINT/v1/cert") || code=000
# Retry what may pass on its own: a rate or live-certificate limit (429;
# the rates are per minute, the backoff sums to one), the mint could not
# reach GitHub (502), or the network (000). Everything else is an answer.
case "$code" in 429 | 502 | 000) ;; *) break ;; esac
[ "$attempt" -eq 4 ] || sleep $((attempt * 10))
done
if [ "$code" != 200 ]; then
echo "::error title=rbe-fork mint refused (HTTP $code)::$(jq -r '.error // empty' "$reply" 2>/dev/null || true)"
exit 1
fi
endpoint=$(jq -r .endpoint "$reply")
instance=$(jq -r .instance "$reply")
tier=$(jq -r .tier "$reply")
[[ $endpoint =~ $ENDPOINT_RE ]] || { echo "::error::rbe-fork mint returned endpoint '$endpoint'" >&2; exit 1; }
case "$tier/$instance" in ro/oss-fork | rw/oss) ;; *) echo "::error::rbe-fork mint returned tier '$tier' instance '$instance'" >&2; exit 1 ;; esac
if [ "$tier" != "$RBE_FORK_TIER" ]; then
echo "::error title=rbe-fork tier changed::the mint says '$tier', this run's mode says '$RBE_FORK_TIER' (allowlist changed?); re-run all jobs"
exit 1
fi
umask 077
jq -r .cert_pem "$reply" >"$dir/fork.crt"
openssl x509 -in "$dir/fork.crt" -noout -subject -enddate
{
echo "cert=$dir/fork.crt"
echo "key=$dir/fork.key"
echo "endpoint=$endpoint"
echo "instance=$instance"
echo "tier=$tier"
} >>"$out"
;;
*)
echo "usage: $0 key|cert" >&2
exit 2
;;
esac

View file

@ -25,27 +25,9 @@
# cert path) and outside BAZEL_CI_CACHE_DIR (the runner cache must never store
# credentials). The endpoint is masked in the job log.
#
# BAZEL_FORK_CACHE=true (bazel.yml mode "cache": rbe=cache dispatches, and
# fork/Dependabot runs while rbe-fork is closed) appends --config=fork-cache:
# .bazelrc's credential-free, read-only rbe-west cache. While that cache
# advertises zstd (cache-zstd-probe.sh asks its GetCapabilities; any failure
# means no) it also asks for zstd transfers (--remote_cache_compression). A
# probe, not a repository variable: fork pull_request runs see no vars. No
# other mode ever asks, because only the anonymous cache can advertise zstd,
# and Bazel refuses a remote that does not. With BAZEL_RRC_READ=true too
# (bazel.yml's remote repo contents cache readers alone: the jobs whose
# configs rrc-lane-commands.txt seeds), and while rbe-cache answers
# (cache-rrc-probe.sh, which also holds the committed kill switch), it reads
# Bazel's remote repo contents cache, as those jobs' trusted readers do: the
# trees rrc-seed wrote on main pushes, through rbe-cache's anonymous AC and
# CAS reads. The job's step summary says whether it reads, and why.
#
# RBE_FORK_CERT_FILE + RBE_FORK_KEY_FILE + RBE_FORK_ENDPOINT + RBE_FORK_INSTANCE
# (bazel.yml modes fork-ro/fork-rw: fork-credential.sh's outputs, a
# short-lived rbe-fork-mint certificate) enable --config=remote-exec against
# rbe-fork: instance oss-fork (the fork pool, nothing cached) or oss
# (allowlisted authors: the OSS pool, results cached by the workers). The
# three modes are mutually exclusive.
# BAZEL_FORK_CACHE=true (bazel.yml mode "cache": fork PRs and rbe=cache
# dispatches) appends --config=fork-cache: .bazelrc's credential-free,
# read-only rbe-west cache. It is mutually exclusive with the RBE secrets.
#
# Outputs (to $GITHUB_OUTPUT when set, else stdout): rc=<path>,
# remote=true|false, cache=true|false.
@ -100,22 +82,6 @@ key="${RBE_TLS_KEY:-}"
ca="${RBE_TLS_CA:-}"
instance="${RBE_INSTANCE:-}"
fork_cache="${BAZEL_FORK_CACHE:-}"
rrc_reader="${BAZEL_RRC_READ:-}"
fork_cert="${RBE_FORK_CERT_FILE:-}"
fork_key="${RBE_FORK_KEY_FILE:-}"
fork_endpoint="${RBE_FORK_ENDPOINT:-}"
fork_instance="${RBE_FORK_INSTANCE:-}"
fork_fields=0
for v in "$fork_cert" "$fork_key" "$fork_endpoint" "$fork_instance"; do
[[ -n "$v" ]] && fork_fields=$((fork_fields + 1))
done
case "$fork_fields/$fork_instance" in
0/ | 4/oss | 4/oss-fork) ;;
*)
echo "setup-bazel: RBE_FORK_CERT_FILE, RBE_FORK_KEY_FILE, RBE_FORK_ENDPOINT and RBE_FORK_INSTANCE (oss or oss-fork) go together" >&2
exit 1
;;
esac
case "$fork_cache" in
"" | true) ;;
*)
@ -123,13 +89,6 @@ case "$fork_cache" in
exit 1
;;
esac
case "$rrc_reader" in
"" | true) ;;
*)
echo "setup-bazel: BAZEL_RRC_READ must be \"true\" or empty, got \"$rrc_reader\"" >&2
exit 1
;;
esac
rc="$secret_dir/ci.bazelrc"
umask 077
@ -139,23 +98,6 @@ umask 077
# The repo contents cache (default: under the repository cache, so in
# the runner cache) holds extracted repos Bazel never re-verifies; off.
echo "common --repo_contents_cache="
# Every mode fetches external repositories on the runner. gazelle's
# go_repository fetches Go modules with the go command (fetch_repo), not
# Bazel's downloader, and the go command never retries: one TLS
# handshake timeout against proxy.golang.org failed a whole lane. With
# "|" the go command moves to the next entry on any error (a ","
# list only on 404/410): the proxy twice, then the module's origin.
# fetch_repo checks every module against its go.sum hash whatever the
# source. Key neutral: repository fetching only, no action reads it.
echo "common --repo_env=GOPROXY=https://proxy.golang.org|https://proxy.golang.org|direct"
# Bazel's own downloader (the Go SDK, http_archive) already retries;
# give slow TLS handshakes and reads twice the default timeouts.
echo "common --http_timeout_scaling=2.0"
# The client's JVM heap. Bazel's default caps it at 25% of RAM, about
# 2 GB on the 8 GB 2 vCPU runners every remote lane uses; //... analysis
# fits today, with little headroom. A startup option: key neutral, it only
# restarts the server. Each lane reports peak-heap-size to size this.
echo "startup --host_jvm_args=-Xmx4g"
} >"$rc"
# write_pem DEST VALUE: decode base64 (or accept raw PEM) and check it is PEM.
@ -188,25 +130,7 @@ done
remote=false
cache=false
if [[ "$fork_fields" -eq 4 ]]; then
if [[ "$set_fields" -ne 0 || "$fork_cache" == true ]]; then
echo "setup-bazel: the rbe-fork certificate, the remote execution secrets and BAZEL_FORK_CACHE are mutually exclusive" >&2
exit 1
fi
{
echo "build:remote-exec --remote_executor=$fork_endpoint"
echo "build:remote-exec --tls_client_certificate=$fork_cert"
echo "build:remote-exec --tls_client_key=$fork_key"
echo "build:remote-exec --remote_instance_name=$fork_instance"
echo "build:remote-exec --noremote_upload_local_results"
# The farm admits 128 connections per source IP (Blacksmith runners
# share addresses). Key-neutral, like everything in this rc.
echo "build:remote-exec --remote_max_connections=8"
echo "build --config=remote-exec"
} >>"$rc"
remote=true
echo "setup-bazel: remote execution on rbe-fork (instance $fork_instance, short-lived certificate)"
elif [[ "$set_fields" -eq 3 ]]; then
if [[ "$set_fields" -eq 3 ]]; then
if [[ "$fork_cache" == true ]]; then
echo "setup-bazel: BAZEL_FORK_CACHE and the remote execution secrets are mutually exclusive" >&2
exit 1
@ -241,39 +165,7 @@ elif [[ "$set_fields" -ne 0 ]]; then
echo "setup-bazel: remote execution is partially configured; BAZEL_REMOTE_EXECUTOR, RBE_TLS_CERT and RBE_TLS_KEY must be set together (or none, for local execution)" >&2
exit 1
elif [[ "$fork_cache" == true ]]; then
# The remote repo contents cache, read-only, for the jobs that opt in
# (BAZEL_RRC_READ: only their configs are seeded), while rbe-cache
# answers and the probe's kill switch (fork_rrc_read) is on. With the
# startup flag set and the cache unreachable, every repository first
# fails a lookup (gascity engdocs/design/bazel-remote-repo-contents-cache.md,
# R6), so a closed or down rbe-cache gets no lines, and a notice says
# why. That holds at probe time only: after loading, Bazel fetches the
# files lazily, and losing rbe-cache then fails the command (R4). Both
# lines are key neutral, as for the trusted readers; fork-cache uploads
# nothing, and rbe-cache refuses every write.
rrc_read=false
if [[ "$rrc_reader" != true ]]; then
why="not a remote repo contents cache reader (no BAZEL_RRC_READ)"
elif why=$(bash "$(dirname "${BASH_SOURCE[0]}")/cache-rrc-probe.sh" 2>&1); then
rrc_read=true
echo "$why"
else
echo "::notice title=No remote repo contents cache::$why"
fi
echo "Fork cache remote repo contents cache read: **$([[ "$rrc_read" == true ]] && echo on || echo off)** (${why#rbe-cache rrc probe: })" >>"${GITHUB_STEP_SUMMARY:-/dev/null}"
# zstd for the anonymous cache's transfers while it advertises zstd:
# transport only, so action keys are unchanged. The probes never fail
# this script; they only decide the lines.
{
echo "build --config=fork-cache"
if bash "$(dirname "${BASH_SOURCE[0]}")/cache-zstd-probe.sh"; then
echo "build:fork-cache --remote_cache_compression"
fi
if [[ "$rrc_read" == true ]]; then
echo "startup --experimental_remote_repo_contents_cache"
echo "common --loading_phase_threads=64"
fi
} >>"$rc"
echo "build --config=fork-cache" >>"$rc"
cache=true
echo "setup-bazel: read-only remote cache (rbe-cache); executing locally"
else

View file

@ -1,17 +0,0 @@
{
"github_owned_allowed": true,
"verified_allowed": false,
"patterns_allowed": [
"DeterminateSystems/determinate-nix-action@*",
"DeterminateSystems/nix-installer-action@*",
"anchore/sbom-action@*",
"codecov/codecov-action@*",
"cygwin/cygwin-install-action@*",
"docker/setup-buildx-action@*",
"dorny/paths-filter@*",
"goreleaser/goreleaser-action@*",
"msys2/setup-msys2@*",
"ossf/scorecard-action@*",
"peter-evans/create-pull-request@*"
]
}

View file

@ -10,11 +10,6 @@
# must be listed, and the PR must come from the author's own fork. A listed
# user gets same-repo-PR-level trust: its PR code runs with the RBE client
# certificate. Same people as gascity's .github/blacksmith-allowlist.txt.
# rbe-west's rbe-fork-mint reads this file too, from the default branch, by
# the same rules: a listed author's own-fork PR, triggered by a listed user,
# gets rbe-fork tier rw (bazel.yml mode fork-rw: the trusted OSS pool) when
# the farm has rw switched on; everyone else gets tier ro (fork pool). A
# line that is not a numeric id makes the mint treat the list as empty.
8082291 # julianknutsen
91582 # quad341
36544495 # sjarmak

View file

@ -1,15 +1,138 @@
# GitHub Copilot instructions for beads
# GitHub Copilot Instructions for Beads
The canonical contributor instructions for this repository are in
[AGENTS.md](../AGENTS.md); area-specific rules are in the nested `AGENTS.md`
files listed in its routing table. Read those, not this file, for workflow,
build, test, and scope rules.
## Project Overview
The rules most often missed in review:
**beads** (command: `bd`) is a Dolt-powered issue tracker designed for AI-supervised coding workflows. Git integration is optional. We dogfood our own tool for all task tracking.
- A PR must close a documented GitHub issue (filed before or alongside it).
- Build with `make install`, never `go build -o bd ./cmd/bd` or `go install ./cmd/bd`.
- `make ci-pr-lint` must pass with zero issues; choose tests with
[engdocs/TESTING.md](../engdocs/TESTING.md).
- Never create test issues in a production database; use `t.TempDir()`.
- CLI output uses small Unicode status symbols, never emoji icons.
**Key Features:**
- Dependency-aware issue tracking
- Auto-sync via Dolt-native replication
- AI-optimized CLI with JSON output
- Dolt server mode for background operations
- MCP server integration for Claude and other AI assistants
## Tech Stack
- **Language**: Go 1.21+
- **Storage**: Dolt (version-controlled SQL database)
- **CLI Framework**: Cobra
- **Testing**: Go standard testing + table-driven tests
- **CI/CD**: GitHub Actions
- **MCP Server**: Python (integrations/beads-mcp/)
## Coding Guidelines
### Testing
- Always write tests for new features
- Use `t.TempDir() in Go tests` to avoid polluting production database
- Run `go test -short ./...` before committing
- Never create test issues in production DB (use temporary DB)
### Code Style
- Run `make ci-pr-lint` before committing changes to Go or lint-controlled files
- Follow existing patterns in `cmd/bd/` for new commands
- Add `--json` flag to all commands for programmatic use
- Update docs when changing behavior
### Git Workflow
- Install git hooks: `bd hooks install`
- Use `bd dolt push` / `bd dolt pull` for remote sync
- Before implementing related work, opening a PR, or merging/closing a PR, run:
`scripts/pr-preflight.sh --search "<topic>" --repo gastownhall/beads` or
`scripts/pr-preflight.sh <pr-number> --repo gastownhall/beads`
- External contributor PRs have priority: build on them when possible, preserve
tests and attribution, and never close or replace them silently.
## Issue Tracking with bd
**CRITICAL**: This project uses **bd** for ALL task tracking. Do NOT create markdown TODO lists.
### Essential Commands
```bash
# Find work
bd ready --json # Unblocked issues
bd stale --days 30 --json # Forgotten issues
# Create and manage (ALWAYS include --description)
bd create "Title" --description="Detailed context" -t bug|feature|task -p 0-4 --json
bd update <id> --claim --json
bd close <id> --reason "Done" --json
# Search
bd list --status open --priority 1 --json
bd show <id> --json
# Sync (if remote configured)
bd dolt push # Push to Dolt remote
bd dolt pull # Pull from Dolt remote
```
### Workflow
1. **Check ready work**: `bd ready --json`
2. **Claim task**: `bd update <id> --claim`
3. **Work on it**: Implement, test, document
4. **Discover new work?** `bd create "Found bug" --description="What was found and why" -p 1 --deps discovered-from:<parent-id> --json`
5. **Complete**: `bd close <id> --reason "Done" --json`
6. **Sync**: `bd dolt push` (push to Dolt remote if configured)
**IMPORTANT**: Always include `--description` when creating issues. Issues without descriptions lack context for future work.
### Priorities
- `0` - Critical (security, data loss, broken builds)
- `1` - High (major features, important bugs)
- `2` - Medium (default, nice-to-have)
- `3` - Low (polish, optimization)
- `4` - Backlog (future ideas)
## Project Structure
```
beads/
├── cmd/bd/ # CLI commands (add new commands here)
├── internal/
│ ├── types/ # Core data types
│ └── storage/ # Storage layer
│ └── dolt/ # Dolt implementation
├── integrations/
│ └── beads-mcp/ # MCP server (Python)
├── examples/ # Integration examples
├── docs/ # Documentation
└── .beads/
└── dolt/ # Dolt database (source of truth)
```
## Available Resources
### MCP Server (Recommended)
Use the beads MCP server for native function calls instead of shell commands:
- Install: `pip install beads-mcp`
- Functions: `mcp__beads__ready()`, `mcp__beads__create()`, etc.
- See `integrations/beads-mcp/README.md`
### Scripts
- `./scripts/bump-version.sh <version> --commit` - Update all version files atomically
- `./scripts/release.sh <version>` - Complete release workflow
- `./scripts/update-homebrew.sh <version>` - Update Homebrew formula
### Key Documentation
- **AGENTS.md** - Comprehensive AI agent guide (detailed workflows, advanced features)
- **AGENT_INSTRUCTIONS.md** - Development procedures, testing, releases
- **README.md** - User-facing documentation
- **docs/CLI_REFERENCE.md** - Complete command reference
## Important Rules
- ✅ Use bd for ALL task tracking
- ✅ Always use `--json` flag for programmatic use
- ✅ Use `bd dolt push` / `bd dolt pull` for remote sync
- ✅ Test with `t.TempDir() in Go tests`
- ❌ Do NOT create markdown TODO lists
- ❌ Do NOT create test issues in production DB
- ❌ Do NOT manually modify `.beads/dolt/`
---
**For detailed workflows and advanced features, see [AGENTS.md](../AGENTS.md)**

View file

@ -7,14 +7,10 @@
# bazel-gate.sh skips the Bazel gate ids whose job is skipped by design
# in this mode, for CI_GATE_SKIPPED_OK:
# skip: every lane and the aggregate (BAZEL)
# local: the remote-only BAZEL_EMBEDDED,
# BAZEL_PROXIED, BAZEL_SERVER_STORAGE,
# BAZEL_INTEGRATION and BAZEL_CMD_DOLT
# cache: BAZEL_EMBEDDED, BAZEL_PROXIED,
# BAZEL_SERVER_STORAGE (integration
# and cmd-dolt run with the read-only
# cache)
# remote, fork-ro, fork-rw: none
# local, cache: the remote-only BAZEL_EMBEDDED,
# BAZEL_INTEGRATION, BAZEL_PROXIED,
# BAZEL_SERVER_STORAGE
# remote: none
# bazel-gate.sh aggregate the value to gate on for BAZEL: the call's
# aggregate result, or, when the mode is missing
# or invalid (the rbe job failed, the call never
@ -33,7 +29,7 @@ mode="${BAZEL_RBE_MODE:-}"
enabled="${BAZEL_RBE_ENABLED:-}"
valid=false
case "$mode/$enabled" in
remote/true | fork-ro/true | fork-rw/true | local/false | cache/false | skip/false) valid=true ;;
remote/true | local/false | cache/false | skip/false) valid=true ;;
esac
case "${1:-}" in
@ -41,9 +37,8 @@ case "${1:-}" in
skips=()
if [[ "$valid" == true ]]; then
case "$mode" in
skip) skips+=(BAZEL BAZEL_TEST BAZEL_PURE BAZEL_RELEASE_CROSS BAZEL_EMBEDDED BAZEL_INTEGRATION BAZEL_DOLTSERVER BAZEL_PROXIED BAZEL_SERVER_STORAGE BAZEL_CMD_DOLT) ;;
local) skips+=(BAZEL_EMBEDDED BAZEL_INTEGRATION BAZEL_PROXIED BAZEL_SERVER_STORAGE BAZEL_CMD_DOLT) ;;
cache) skips+=(BAZEL_EMBEDDED BAZEL_PROXIED BAZEL_SERVER_STORAGE) ;;
skip) skips+=(BAZEL BAZEL_TEST BAZEL_PURE BAZEL_EMBEDDED BAZEL_INTEGRATION BAZEL_DOLTSERVER BAZEL_PROXIED BAZEL_SERVER_STORAGE) ;;
local | cache) skips+=(BAZEL_EMBEDDED BAZEL_INTEGRATION BAZEL_PROXIED BAZEL_SERVER_STORAGE) ;;
esac
fi
echo "${skips[*]-}"

163
.github/scripts/ci-capability-selector.sh vendored Executable file
View file

@ -0,0 +1,163 @@
#!/usr/bin/env bash
# Report candidate PR Risk capabilities without changing the current gates.
set -euo pipefail
embedded_cli=false
proxied_cli=false
embedded_storage=false
embedded_conformance=false
server_conformance=false
full=false
reason=""
diff_file=""
cleanup() {
if [[ -n "$diff_file" ]]; then
rm -f "$diff_file"
fi
}
trap cleanup EXIT
set_full() {
embedded_cli=true
proxied_cli=true
embedded_storage=true
embedded_conformance=true
server_conformance=true
full=true
reason="$1"
}
emit() {
local lines=(
"embedded_cli=$embedded_cli"
"proxied_cli=$proxied_cli"
"embedded_storage=$embedded_storage"
"embedded_conformance=$embedded_conformance"
"server_conformance=$server_conformance"
"full=$full"
"reason=$reason"
)
printf '%s\n' "${lines[@]}"
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
printf '%s\n' "${lines[@]}" >> "$GITHUB_OUTPUT"
fi
}
event_name="${GITHUB_EVENT_NAME:-}"
base_sha="${PR_BASE_SHA:-}"
head_sha="${PR_HEAD_SHA:-}"
case "$event_name" in
pull_request) ;;
push) set_full "push"; emit; exit 0 ;;
merge_group) set_full "merge_group"; emit; exit 0 ;;
*) set_full "unsupported_event"; emit; exit 0 ;;
esac
if [[ -z "$base_sha" || -z "$head_sha" ]]; then
set_full "missing_bounds"
emit
exit 0
fi
diff_file=$(mktemp)
if ! git diff --no-ext-diff --find-renames --name-status -z "$base_sha" "$head_sha" -- > "$diff_file"; then
set_full "diff_failed"
emit
exit 0
fi
saw_path=false
saw_cmd=false
saw_embedded=false
saw_server=false
saw_conformance=false
while :; do
status=""
if ! IFS= read -r -d '' status <&3; then
if [[ -n "$status" ]]; then
set_full "malformed_record"
fi
break
fi
if [[ "$status" != "A" && "$status" != "M" ]]; then
set_full "unsafe_status"
break
fi
path=""
if ! IFS= read -r -d '' path <&3; then
set_full "malformed_record"
break
fi
saw_path=true
if [[ -z "$path" || "$path" == /* || "/$path/" == *"/../"* || "$path" == . || "$path" == .. || "$path" == ./* ]]; then
set_full "unsafe_path"
break
fi
case "$path" in
.github/workflows/*|.github/scripts/*)
set_full "unsafe_control"
break
;;
.buildflags|go.mod|go.sum|Makefile|default.nix|flake.nix|flake.lock|overlay.nix|packages.nix)
set_full "build_input"
break
;;
cmd/bd/*)
embedded_cli=true
proxied_cli=true
saw_cmd=true
;;
internal/storage/embeddeddolt/*)
embedded_cli=true
embedded_storage=true
embedded_conformance=true
saw_embedded=true
;;
internal/storage/dolt/*)
proxied_cli=true
server_conformance=true
saw_server=true
;;
backend/conformance/*|test/conformance/*)
embedded_conformance=true
server_conformance=true
saw_conformance=true
;;
internal/storage/*|backend/*|schema/*)
set_full "cross_cutting_storage"
break
;;
docs/*.md|docs/*.mdx|docs/*.png|docs/*.jpg|docs/*.jpeg|docs/*.gif|docs/*.svg|docs/*.webp|docs/*.avif|engdocs/*.md|engdocs/*.mdx|engdocs/*.png|engdocs/*.jpg|engdocs/*.jpeg|engdocs/*.gif|engdocs/*.svg|engdocs/*.webp|engdocs/*.avif|README.md|CHANGELOG.md|ARTICLES.md|BENCHMARKS.md|NEWSLETTER.md)
;;
*)
set_full "unowned_path"
break
;;
esac
done 3< "$diff_file"
if [[ "$full" != true ]]; then
if [[ "$embedded_cli" == true && "$proxied_cli" == true && "$embedded_storage" == true && "$embedded_conformance" == true && "$server_conformance" == true ]]; then
full=true
reason="full"
elif [[ "$saw_path" != true ]]; then
reason="empty_diff"
elif [[ "$saw_cmd" == true && "$saw_embedded" != true && "$saw_server" != true && "$saw_conformance" != true ]]; then
reason="cmd_bd"
elif [[ "$saw_embedded" == true && "$saw_cmd" != true && "$saw_server" != true && "$saw_conformance" != true ]]; then
reason="embedded_storage"
elif [[ "$saw_server" == true && "$saw_cmd" != true && "$saw_embedded" != true && "$saw_conformance" != true ]]; then
reason="server_storage"
elif [[ "$saw_conformance" == true && "$saw_cmd" != true && "$saw_embedded" != true && "$saw_server" != true ]]; then
reason="shared_conformance"
elif [[ "$saw_cmd" == false && "$saw_embedded" == false && "$saw_server" == false && "$saw_conformance" == false ]]; then
reason="docs_only"
else
reason="mixed"
fi
fi
emit

103
.github/scripts/ci-embedded-tier.sh vendored Executable file
View file

@ -0,0 +1,103 @@
#!/usr/bin/env bash
# Decide whether CI should run the full embedded Dolt build/storage/cmd matrix.
set -euo pipefail
event_name="${GITHUB_EVENT_NAME:-}"
base_sha="${PR_BASE_SHA:-}"
head_sha="${PR_HEAD_SHA:-}"
full_embedded=false
reason=""
changed_files=""
write_outputs() {
if [ -n "${GITHUB_OUTPUT:-}" ]; then
{
echo "full_embedded=$full_embedded"
echo "reason=$reason"
} >> "$GITHUB_OUTPUT"
fi
}
case "$event_name" in
push)
full_embedded=true
reason="push to main runs full embedded Dolt coverage"
write_outputs
echo "$reason"
exit 0
;;
merge_group)
full_embedded=true
reason="merge queue runs full embedded Dolt coverage"
write_outputs
echo "$reason"
exit 0
;;
esac
if [ "$event_name" != "pull_request" ]; then
full_embedded=true
reason="non-PR event runs full embedded Dolt coverage"
write_outputs
echo "$reason"
exit 0
fi
if [ -z "$base_sha" ] || [ -z "$head_sha" ]; then
full_embedded=true
reason="PR diff bounds unavailable; defaulting to full embedded Dolt coverage"
write_outputs
echo "$reason"
exit 0
fi
if ! changed_files="$(git diff --name-only "$base_sha" "$head_sha")"; then
full_embedded=true
reason="PR diff failed; defaulting to full embedded Dolt coverage"
write_outputs
echo "$reason"
exit 0
fi
if [ -z "$changed_files" ]; then
reason="no changed files detected; skipping embedded Dolt matrix"
write_outputs
echo "$reason"
exit 0
fi
while IFS= read -r path; do
case "$path" in
cmd/*|internal/*|tests/*|scripts/*|.github/scripts/*|.github/workflows/*)
full_embedded=true
reason="changed $path"
break
;;
*.go|go.mod|go.sum|Makefile|default.nix|flake.nix|flake.lock|packages.nix)
full_embedded=true
reason="changed $path"
break
;;
AGENTS.md|AGENT_INSTRUCTIONS.md|CONTRIBUTING.md|RELEASING.md)
full_embedded=true
reason="changed $path"
break
;;
esac
done <<< "$changed_files"
if [ "$full_embedded" = true ]; then
reason="risk path detected: $reason; running full embedded Dolt coverage"
else
reason="docs/metadata-only PR; skipping embedded Dolt storage/cmd matrix"
fi
write_outputs
echo "$reason"
echo "Changed files:"
while IFS= read -r path; do
printf ' %s\n' "$path"
done <<< "$changed_files"

View file

@ -1,545 +1,154 @@
# Embedded-Dolt cmd/bd test shard manifest.
# Embedded cmd test shard manifest.
#
# Format: <total_shards> <shard_number> <top_level_test_name>
#
# 100-shard split for the Bazel-only embedded-Dolt cmd tier
# (bazel-embedded in .github/workflows/bazel.yml), bin-packed
# longest-first by measured wall-time from
# scripts/ci/embedded_cmd_test_durations.json (see that file for provenance
# and its "relative weight, not absolute SLA" caveat) onto the shard
# whose estimated wall time grows least: serial tests (no top-level
# t.Parallel) add up, parallel ones share -test.parallel=4.
# Regenerate with scripts/ci/gen_embedded_cmd_shard_manifest.py 100
# --weights=duration --write after adding, splitting or removing
# TestEmbedded* functions in cmd/bd/*_test.go. --write is
# incremental: it keeps every already-assigned test on its current shard
# and only places newly-discovered names, onto whichever shard is
# currently lightest, so two unrelated PRs that each add one test do not
# textually conflict or silently invalidate each other's packing. Pass
# --repack to force a full from-scratch rebalance instead (a deliberate,
# separate change — expect a large diff). --check only verifies every
# discovered name is listed here exactly once (no stale or duplicate
# entries); it does NOT verify the packing is still well-balanced.
#
# This file is generated: notes added here are erased by the next
# regeneration. Add them to the generator or the durations file instead.
100 1 TestEmbeddedUpdateConcurrent
100 2 TestEmbeddedShowConcurrent
100 3 TestEmbeddedCloseConcurrent
100 4 TestEmbeddedEpicConcurrent
100 5 TestEmbeddedConfigConcurrent
100 6 TestEmbeddedListFilteringBasicAndLabels
100 7 TestEmbeddedDepConcurrent
100 8 TestEmbeddedMaxRowsListLimitInteraction
100 9 TestEmbeddedChildrenConcurrent
100 10 TestEmbeddedCreateScalarAndRelationships
100 11 TestEmbeddedKVConcurrent
100 12 TestEmbeddedGatedRendering
100 13 TestEmbeddedListFilteringStatusAndHierarchy
100 14 TestEmbeddedReopenConcurrent
100 15 TestEmbeddedPurgeWispsPlaneRetention
100 16 TestEmbeddedMemoryConcurrent
100 17 TestEmbeddedReopen
100 18 TestEmbeddedLabelPropagateRename
100 18 TestEmbeddedPrune_protectsBeadCitedByCustomStatusBead
100 19 TestEmbeddedLabelConcurrent
100 19 TestEmbeddedNewDoltStore_StrictReadOnlyRefusesWritesOnFreshDatabase
100 20 TestEmbeddedInitRoleRoutingRetainedFork
100 20 TestEmbeddedMigrateSchema_IdentityMismatchRefusesBeforeApplying
100 21 TestEmbeddedMaxRowsReady
100 21 TestEmbeddedMigratePersonal_movesIssues
100 22 TestEmbeddedCount
100 22 TestEmbeddedIfRevisionCloseReplaysMoleculeAutoClose
100 23 TestEmbeddedCountConcurrent
100 23 TestEmbeddedExportExcludeOwner_flag
100 24 TestEmbeddedEventsTailFollowReportsTruncationOnTheStream
100 24 TestEmbeddedUndeferConcurrent
100 24 TestEmbeddedWispGCProtectsActiveWisps
100 25 TestEmbeddedDoltRemoteAdd_LocalOnly_FiresBeforeGuard
100 25 TestEmbeddedMaxRowsListBasic
100 25 TestEmbeddedRemovedBackendHealRejectionPerBackend
100 26 TestEmbeddedDoltRemoteAdd_JSON_AllowGitOrigin_WarningOnStderr
100 26 TestEmbeddedExternalMutationPolicy
100 26 TestEmbeddedPersistentPreRunLogsAndSkipsIdentityCheckForFreshEmbeddedWorkspace
100 27 TestEmbeddedDoltRemoteAdd_GitOriginCollision_RefusalMessageCopy
100 27 TestEmbeddedNewDoltStoreFromConfig_DottedDBName
100 27 TestEmbeddedShipConcurrent
100 28 TestEmbeddedDoltLocalOnly_RemoteAdd_RefusesExitOne
100 28 TestEmbeddedHistoryConcurrent
100 28 TestEmbeddedImportChunkedRealStoreResumeConverges
100 29 TestEmbeddedDoltLocalOnly_RemoteAdd_ErrorOnStderr
100 29 TestEmbeddedEpicCloseEligibleReasonFlag
100 29 TestEmbeddedImportChunkedNoReadyWindowWithReadinessEdgeIntoCycle
100 30 TestEmbeddedCloseGuardsAndEpics
100 30 TestEmbeddedDoltLocalOnly_Push_ExitsZeroWithMessage
100 30 TestEmbeddedImportChunkedCrossBucketBlocksEdgesResumeBackfills
100 31 TestEmbeddedDoltLocalOnly_ConfigRoundTrip
100 31 TestEmbeddedIfRevisionCloseWarnsOnForcedOpenChildren
100 31 TestEmbeddedInitSelectedExcludeRoutingForkInvalidQuiet
100 32 TestEmbeddedDoctorUnsupportedJSON
100 32 TestEmbeddedIfRevisionAdvertisedOnFourVerbs
100 32 TestEmbeddedListSearchAndOutputFormats
100 33 TestEmbeddedBootstrapJSONLAndGitOrigin
100 33 TestEmbeddedDeleteJournalsTheRequestingActor
100 33 TestEmbeddedExportExcludeOwner_verbose
100 34 TestEmbeddedCopyIssueRelations_preservesCommentWithTimestamp
100 34 TestEmbeddedEventsTailReportsTruncationToTheCLI
100 34 TestEmbeddedUnclaimBatchAndRefusals
100 34 TestEmbeddedWispGCPurgeClosedDoesNotCascadeIntoLiveSteps
100 35 TestEmbeddedAutoPruneRespectsBdConfigSet
100 35 TestEmbeddedEventsReadNoticesADisabledJournal
100 35 TestEmbeddedGateCreateBeadRename
100 35 TestEmbeddedVersionedHistoryEnvIsProcessWideAndOnlyTurnsRecordingOn
100 36 TestEmbeddedAutoPruneLeavesAnUnboundedJournalAlone
100 36 TestEmbeddedDoltRemoteResetData_UnknownRemote
100 36 TestEmbeddedGateConcurrent
100 36 TestEmbeddedUnclaimIfAssigneeCLIDifferentSpelling
100 37 TestEmbeddedAutoPruneBoundsTheJournalAfterAMutatingCommand
100 37 TestEmbeddedDoltRemoteResetData_CloudRemoteRefused
100 37 TestEmbeddedMaxRowsDepTreeAndDuplicates
100 37 TestEmbeddedSpawnMolecule_SubstitutesTemplatedStepFields
100 38 TestEmbeddedGraphConcurrent
100 38 TestEmbeddedRoutedCreateJournalsIntoTheTargetWorkspace
100 38 TestEmbeddedUnclaimIfAssigneeFlagValidation
100 39 TestEmbeddedIfRevisionRejectsLabelAndParentEdits
100 39 TestEmbeddedMaxRowsGraph
100 39 TestEmbeddedNewDoltStoreFromConfig_NoMetadata
100 40 TestEmbeddedIfRevisionOutranksReassignFenceCLI
100 40 TestEmbeddedNewDoltStoreFromConfig_HyphenatedDBName
100 40 TestEmbeddedUpdateLifecycleClaimParentCommit
100 41 TestEmbeddedDuplicateConcurrent
100 41 TestEmbeddedVersionedHistoryFollowsTheStoreItWritesInto
100 42 TestEmbeddedInitAForkAutoContributor
100 42 TestEmbeddedUpdateIfGuardsFlagValidation
100 43 TestEmbeddedIfRevisionMultiIDRejected
100 43 TestEmbeddedInitExplicitBeadsDirIsAuthoritative
100 44 TestEmbeddedIfRevisionComposesWithIfAssigneeIfStatus
100 44 TestEmbeddedStaleConcurrent
100 45 TestEmbeddedGraph
100 45 TestEmbeddedUpdateIfGuardsCLI
100 46 TestEmbeddedCloseAlreadyClosedClaimNextAndMolecule
100 46 TestEmbeddedIfRevisionMatchAndMismatch
100 47 TestEmbeddedListSearchAndOutputSearchAndSort
100 47 TestEmbeddedRevisionRemintMatrix
100 48 TestEmbeddedDeferConcurrent
100 48 TestEmbeddedReassignFenceCLI
100 49 TestEmbeddedBackupRestoreStrictReadonly
100 49 TestEmbeddedInitAPushConsentAndRemoteBootstrap
100 49 TestEmbeddedMigratePersonal_abortOnNoConfirm
100 50 TestEmbeddedDiffConcurrent
100 50 TestEmbeddedDoltRemoteAdd_AllowGitOrigin_WarningOnStderr
100 50 TestEmbeddedImportChunkedWaitsForChildImportedLaterStaysBlocked
100 50 TestEmbeddedVersionOutputShape
100 51 TestEmbeddedDoltRemoteAdd_AllowGitOrigin_Exits0
100 51 TestEmbeddedHistoryAndShowAsOfReadDoltCommits
100 51 TestEmbeddedImportChunkedStaleRejectedRowKeepsDeferredDepsOut
100 51 TestEmbeddedInitGitBootstrapRoutingFreshQuiet
100 52 TestEmbeddedConfigSetOtherKeysSkipTheVersionedHistoryScan
100 52 TestEmbeddedDoltLocalOnly_Push_LocalStoreCopy
100 52 TestEmbeddedImportChunkedNoReadyWindowAtAnyFreezePoint
100 52 TestEmbeddedSwarmConcurrent
100 53 TestEmbeddedDoltLocalOnly_Push_JSON_DisabledStatus
100 53 TestEmbeddedIfRevisionOrdinaryCAS
100 53 TestEmbeddedImportChunkedMixedRegularWispCrossBucketEdgesWired
100 53 TestEmbeddedInitSelectedExcludeRoutingStealthDecoyQuiet
100 54 TestEmbeddedDiscoveryPinsEnvFileReadonly
100 54 TestEmbeddedFormatJSONAliasMatchesJSON
100 54 TestEmbeddedGraphModeDependencyWorkspaceUnaffected
100 54 TestEmbeddedInitAgentArtifactsGolden
100 54 TestEmbeddedSearchConcurrent
100 54 TestEmbeddedShowAsOfFailureExitCodes
100 55 TestEmbeddedDoltLocalOnly_Pull_JSON_DisabledStatus
100 55 TestEmbeddedImportChunkedConcurrentUpdateKeepsDeferredDeps
100 55 TestEmbeddedUndefer
100 55 TestEmbeddedVersionedHistorySwitchScansEveryRowNotOnePage
100 56 TestEmbeddedDepNoCycleCheck
100 56 TestEmbeddedDoltLocalOnly_Pull_ExitsZeroWithMessage
100 56 TestEmbeddedImportChunkedConcurrentUpdateKeepsBlockingDeps
100 56 TestEmbeddedVersionedHistorySwitchRoundTrip
100 57 TestEmbeddedDoltLocalOnly_DoltStatus_ShowsDisabled
100 57 TestEmbeddedIfRevisionDeletePreflightGoneIsPreconditionFailed
100 57 TestEmbeddedQueryConcurrent
100 57 TestEmbeddedVersionedHistorySwitchRefusesUnversionableMetadata
100 58 TestEmbeddedDepAAddRejectionsAndBulk
100 58 TestEmbeddedDoctorUnsupportedProse
100 58 TestEmbeddedIfRevisionCascadeDelete
100 58 TestEmbeddedVersionedHistorySwitchRefusesAnUnrecordableGateTimeout
100 59 TestEmbeddedDeferAutoWake
100 59 TestEmbeddedDoctorSupportedChecks
100 59 TestEmbeddedIdentityGateRendersSchemaSkewFromForwardDriftedWorkspace
100 59 TestEmbeddedVersionedHistorySetManyRefusesUnversionableMetadata
100 60 TestEmbeddedCommentsCLI
100 60 TestEmbeddedCorruptMetadataFailsLoudUntilRestored
100 60 TestEmbeddedExportExcludeOwner_config
100 60 TestEmbeddedRoutedWriteMissDoesNotCreateTargetDatabase
100 60 TestEmbeddedWispGCPurgeClosedStillPurgesFullyClosedMolecules
100 61 TestEmbeddedBootstrapCloneFailureScrubsCredentials
100 61 TestEmbeddedContributorRoutedWritesCommitInPlanning
100 61 TestEmbeddedEventsPruneHonorsRetainRowsFloorFromConfig
100 61 TestEmbeddedUpdateRoutedStoreCommitsTargetHead
100 61 TestEmbeddedVersionedHistoryConfigSetWritesTheStoreRow
100 62 TestEmbeddedAutoPruneDoesNotRunForReadOnlyCommands
100 62 TestEmbeddedDoltRemoteResetData_GitBacked
100 62 TestEmbeddedGateCheckSkipsTemplateGates
100 62 TestEmbeddedReadyBlockersAndLabels
100 62 TestEmbeddedUnclaimIfAssigneeCLI
100 63 TestEmbeddedDepAndLinkBatchAutoCommitDoesNotAdvanceHead
100 63 TestEmbeddedGateCheckLimitCountsOnlyLiveGates
100 63 TestEmbeddedIfRevisionDeletePreflightGoneParentIsPreconditionFailed
100 63 TestEmbeddedListPageEdges
100 64 TestEmbeddedAutoExportExcludeOwner_config
100 64 TestEmbeddedDoltRemoteAdd_NoGitOrigin_ProceedsNormally
100 64 TestEmbeddedGateWaiterCheckLifecycle
100 64 TestEmbeddedPromoteMovesAWispParent
100 64 TestEmbeddedSpawnMolecule_PreservesStepLabels
100 65 TestEmbeddedIfRevisionPreflightGoneIsPreconditionFailedOnEveryVerb
100 65 TestEmbeddedRemovedBackendHealRoundTrip
100 65 TestEmbeddedSupersede
100 66 TestEmbeddedCloseBasicIsolatedStores
100 66 TestEmbeddedShowCommentsTail
100 67 TestEmbeddedAdminCompactReadOnlyAllowed
100 67 TestEmbeddedAutoImportFallback_ConflictSkip_DoesNotClobber
100 67 TestEmbeddedBootstrapConcurrent
100 67 TestEmbeddedCountIncludeInfra
100 67 TestEmbeddedCreateCommitPending
100 67 TestEmbeddedCreateDryRunRepoDoesNotInitializeTarget
100 67 TestEmbeddedCreateRepoFromNonBeadsCwd
100 67 TestEmbeddedCreateRepoRelativeUninitRefused
100 67 TestEmbeddedHooks
100 67 TestEmbeddedOnboard
100 67 TestEmbeddedPrime
100 67 TestEmbeddedPromote
100 67 TestEmbeddedQuickstart
100 67 TestEmbeddedQuickstartConcurrent
100 67 TestEmbeddedWhere
100 67 TestEmbeddedWhereConcurrent
100 68 TestEmbeddedAutoImportFallback_ConflictSkip_EmptyDBImportsAll
100 68 TestEmbeddedBlocked
100 68 TestEmbeddedCompactConcurrent
100 68 TestEmbeddedContext
100 68 TestEmbeddedCreateJSONEchoesSubSecondTimestamps
100 68 TestEmbeddedDoltBlockedAndCommit
100 68 TestEmbeddedDoltConcurrent
100 68 TestEmbeddedInfo
100 68 TestEmbeddedInfoSuppressGitHooks
100 68 TestEmbeddedOrphans
100 68 TestEmbeddedRoutedMutatingSiblingDeleteCloseDelete
100 68 TestEmbeddedSetupConcurrent
100 68 TestEmbeddedTodoConcurrent
100 68 TestEmbeddedTypes
100 69 TestEmbeddedCompact
100 69 TestEmbeddedConfigValidateJSONNoWorkspaceWritesStdout
100 69 TestEmbeddedCreateConcurrent
100 69 TestEmbeddedDepBulkNoCycleCheckKeepsWholeGraphGate
100 69 TestEmbeddedDuplicatesSharedFixture
100 69 TestEmbeddedGateListScoped
100 69 TestEmbeddedGetDependencies
100 69 TestEmbeddedInfoConcurrent
100 69 TestEmbeddedRenamePrefixConcurrent
100 69 TestEmbeddedRoutedSiblingWritesCommitTargetHeadNote
100 69 TestEmbeddedTypesConcurrent
100 69 TestEmbeddedUpdateBatchAutoCommitDoesNotAdvanceHead
100 70 TestEmbeddedExportConcurrent
100 70 TestEmbeddedFlattenConcurrent
100 70 TestEmbeddedGCDryRunAndSkips
100 70 TestEmbeddedImportConcurrent
100 70 TestEmbeddedImportUpsertAndPrefixSync
100 70 TestEmbeddedLabelAddRemoveMultiAndDuplicate
100 70 TestEmbeddedMemory
100 70 TestEmbeddedMigrateConcurrent
100 70 TestEmbeddedPurgeConcurrent
100 70 TestEmbeddedRoutedMutatingSiblingAssignTagDepTag
100 71 TestEmbeddedCloseJSONReportsMoleculeAutoClose
100 71 TestEmbeddedInitRoleRoutingExplicitDefault
100 71 TestEmbeddedPrimeChangeDirRedirectNoticeFollowsTarget
100 71 TestEmbeddedRoutedCreateHonorsTheEnvOverrideOverTheTargetsConfig
100 71 TestEmbeddedSearchRoutesAgree
100 72 TestEmbeddedContributorCreateMultiple
100 72 TestEmbeddedCreateWithGitRemote
100 72 TestEmbeddedFederationConcurrent
100 72 TestEmbeddedGateCreateRepoErrorsList
100 72 TestEmbeddedHumanConcurrent
100 72 TestEmbeddedImportPromotedWispRoundtrip
100 72 TestEmbeddedPrimeChangeDirPrimesTarget
100 72 TestEmbeddedRoutedMutatingSiblingDeleteCloseClose
100 72 TestEmbeddedRoutedSiblingWritesCommitTargetHeadReopen
100 72 TestEmbeddedUpdateFieldsMappingAndRefs
100 73 TestEmbeddedCompactMisdatedChild
100 73 TestEmbeddedExportFlags
100 73 TestEmbeddedFederationPeers
100 73 TestEmbeddedGateCreateFlags
100 73 TestEmbeddedGateCreateReady
100 73 TestEmbeddedPrimeChangeDirDefaultTemplateMatchesTarget
100 73 TestEmbeddedQuickConcurrent
100 73 TestEmbeddedRenamePrefixBasic
100 73 TestEmbeddedRoutedMutatingSiblingAssignTagDepDepAdd
100 74 TestEmbeddedBlockedConcurrent
100 74 TestEmbeddedBranch
100 74 TestEmbeddedCountIncludeEphemeral
100 74 TestEmbeddedDepAddWispSource
100 74 TestEmbeddedMigrate
100 74 TestEmbeddedPrimeConcurrent
100 74 TestEmbeddedRestore
100 74 TestEmbeddedVCConcurrent
100 75 TestEmbeddedCommentsCLIConcurrent
100 75 TestEmbeddedContextConcurrent
100 75 TestEmbeddedFlatten
100 75 TestEmbeddedInitC
100 75 TestEmbeddedListComments
100 75 TestEmbeddedOpen_EmptyDatabaseRejected
100 75 TestEmbeddedReclaimRunsTheLeaseReclaimerRole
100 75 TestEmbeddedRoutedSiblingWritesCommitTargetHeadComment
100 75 TestEmbeddedVCStatusAndCommit
100 76 TestEmbeddedCloseAlreadyClosedContinue
100 76 TestEmbeddedCloseAlreadyClosedMultipleIDs
100 76 TestEmbeddedExportFormats
100 76 TestEmbeddedGCForceWithDecay
100 76 TestEmbeddedGCFullAndNoForcePrompts
100 76 TestEmbeddedInitAGitOriginRemote
100 76 TestEmbeddedLabelAddRemoveRemove
100 76 TestEmbeddedOnboardConcurrent
100 77 TestEmbeddedClaimPools
100 77 TestEmbeddedConfigNoWorkspaceStoreFreeCommands
100 77 TestEmbeddedCreateStorageClassConflicts
100 77 TestEmbeddedExternalCapabilityReadyAfterShip
100 77 TestEmbeddedHumanListStatsRespondDismiss
100 77 TestEmbeddedMemoryCorpusBudget
100 77 TestEmbeddedOrphansConcurrent
100 77 TestEmbeddedStatus
100 78 TestEmbeddedBranchConcurrent
100 78 TestEmbeddedComments
100 78 TestEmbeddedDepBRemove
100 78 TestEmbeddedLabelAddRemoveAdd
100 78 TestEmbeddedShip
100 78 TestEmbeddedUpdateFieldsNotesOverwrite
100 78 TestEmbeddedVCCommitVariantsAndMerge
100 78 TestEmbeddedVersionConcurrent
100 79 TestEmbeddedCreateCrossRepoUninit
100 79 TestEmbeddedDeleteJSONDependencyErrorContract
100 79 TestEmbeddedEpicCloseEligibleNotEligible
100 79 TestEmbeddedInitABasic
100 79 TestEmbeddedInitBRemoteSchemaAndCloneFailure
100 79 TestEmbeddedRenamePrefixEdgeCases
100 79 TestEmbeddedUpdateFieldsNotesClearAndDefer
100 80 TestEmbeddedCreateCrossRepoWithParent
100 80 TestEmbeddedCreateFormCommitsLabelOnlyCreate
100 80 TestEmbeddedCreateStorageClassBasic
100 80 TestEmbeddedRoutedMutatingSiblingAssignTagDepAssign
100 80 TestEmbeddedStatusConcurrent
100 80 TestEmbeddedSwarmCreate
100 80 TestEmbeddedSwarmValidate
100 81 TestEmbeddedAdminCompactTier2Honesty
100 81 TestEmbeddedBackup
100 81 TestEmbeddedDeleteForceAndBatch
100 81 TestEmbeddedGateCreateBeadCheck
100 81 TestEmbeddedGateList
100 81 TestEmbeddedRestoreConcurrent
100 81 TestEmbeddedStaleLabelFilters
100 81 TestEmbeddedStateConcurrent
100 82 TestEmbeddedCreateCrossRepoDryRunWithParent
100 82 TestEmbeddedDeleteBasic
100 82 TestEmbeddedDepBTreeAndCycles
100 82 TestEmbeddedDirectCommitPathsBatchAutoCommitDoesNotAdvanceHead
100 82 TestEmbeddedHooksConcurrent
100 82 TestEmbeddedImportFromSources
100 82 TestEmbeddedStale
100 83 TestEmbeddedAdminBlocked
100 83 TestEmbeddedAutoImportJSONLConcurrentWriter
100 83 TestEmbeddedInitBAutoCommitAndJSONLRemote
100 83 TestEmbeddedLabelEditReportsPrefix
100 83 TestEmbeddedMaxRowsDoctorAndConfig
100 83 TestEmbeddedPurgeFiltered
100 83 TestEmbeddedReadyConcurrent
100 84 TestEmbeddedDoltRemoteAdd_GitOriginCollision_Exits1
100 84 TestEmbeddedInitGitBootstrapRoutingDecoyInvalid
100 84 TestEmbeddedInitSelectedExcludeRoutingStealthInvalid
100 84 TestEmbeddedMigratePersonal_preservesComments
100 85 TestEmbeddedBootstrapExistingDryRunInit
100 85 TestEmbeddedChildrenBasicAndEmpty
100 85 TestEmbeddedCreateGraphAndBulk
100 85 TestEmbeddedCreateRepoRelativeExistingWorkspaceUnaffected
100 85 TestEmbeddedIfRevisionReopenGuardDirect
100 85 TestEmbeddedInitArtifactRouting
100 86 TestEmbeddedDoltRemoteAdd_DifferentURL_ProceedsNormally
100 86 TestEmbeddedExplicitHierarchicalParentEdges
100 86 TestEmbeddedInitHooksRouting
100 86 TestEmbeddedMigratePersonal_noopWhenEmpty
100 87 TestEmbeddedCreateRepoProxiedTargetError
100 87 TestEmbeddedGateInheritsDownParentChain
100 87 TestEmbeddedReadyClaimConcurrent
100 87 TestEmbeddedState
100 87 TestEmbeddedSupersedeConcurrent
100 87 TestEmbeddedSwarmCreateForceAndErrors
100 88 TestEmbeddedChangeDirOverridesInheritedBeadsDir
100 88 TestEmbeddedDepAAddAndList
100 88 TestEmbeddedKV
100 88 TestEmbeddedMaxRowsReadyMerge
100 88 TestEmbeddedPromoteCLI
100 88 TestEmbeddedUnclaimSuccess
100 89 TestEmbeddedBackupConcurrent
100 89 TestEmbeddedCreateDryRunDoesNotMigrate
100 89 TestEmbeddedGateShowResolve
100 89 TestEmbeddedInitBStealthAndForceReinit
100 89 TestEmbeddedLabelEditReportsNoop
100 89 TestEmbeddedShowBasicsAndJSON
100 90 TestEmbeddedAutoImportJSONLSkipsNonEmpty
100 90 TestEmbeddedConfig
100 90 TestEmbeddedFindDuplicatesConcurrent
100 90 TestEmbeddedLabelEditReportsListAndTemplate
100 90 TestEmbeddedLintConcurrent
100 90 TestEmbeddedUpdateLifecycleDefer
100 90 TestEmbeddedVersion
100 91 TestEmbeddedDuplicate
100 91 TestEmbeddedPreviewDoesNotConsumeVersionMarker
100 91 TestEmbeddedPruneDryRunAndFilters
100 91 TestEmbeddedReadOnlyCommandsSpawnNoGit
100 91 TestEmbeddedShowUnresolvableDeps
100 91 TestEmbeddedTypesAgreeWithCreate
100 92 TestEmbeddedAutoImportJSONLNoExplicitCommit
100 92 TestEmbeddedDefer
100 92 TestEmbeddedDepAAddTypesAndFlags
100 92 TestEmbeddedEpicCloseEligibleClosesEpics
100 92 TestEmbeddedSetup
100 92 TestEmbeddedSwarmStatusList
100 93 TestEmbeddedCreateStorageClassBatchAndMisc
100 93 TestEmbeddedDeletePreviewAndGuards
100 93 TestEmbeddedDepBRemoveOutputAndRelatesTo
100 93 TestEmbeddedListConcurrent
100 93 TestEmbeddedPruneSafetyAndScope
100 93 TestEmbeddedShowDetailAndCurrentFlags
100 94 TestEmbeddedCreateDryRunCrossRepoDoesNotMigrateTarget
100 94 TestEmbeddedDepListSingleIDWarnsOnDroppedExternalEdge
100 94 TestEmbeddedEpicCloseEligibleReasonOutput
100 94 TestEmbeddedFederationStatus
100 94 TestEmbeddedGCConcurrent
100 94 TestEmbeddedReadyDefaultJSONAndFlags
100 95 TestEmbeddedChildrenJSONAndAllStatuses
100 95 TestEmbeddedFindDuplicates
100 95 TestEmbeddedImportClosedChildWhoseParentWasDeleted
100 95 TestEmbeddedInitConcurrent
100 95 TestEmbeddedQuick
100 96 TestEmbeddedDiff
100 96 TestEmbeddedDuplicatesConcurrent
100 96 TestEmbeddedHistory
100 96 TestEmbeddedShowDetailAndCurrentHistoryAndCurrent
100 96 TestEmbeddedSquashWispMoleculeClearsRootEphemeral
100 97 TestEmbeddedDuplicatesOwnWorkspaces
100 97 TestEmbeddedHumanPositionalFileAndGuards
100 97 TestEmbeddedPurgeBasics
100 97 TestEmbeddedQuietFlagSuppressesSuccessOutput
100 97 TestEmbeddedSearchStatusLimitSortDatesMetadata
100 98 TestEmbeddedCloseBasicSharedStore
100 98 TestEmbeddedContributorCreateRoutesToPlanning
100 98 TestEmbeddedGCConditionalMatcherDecode
100 98 TestEmbeddedQuery
100 98 TestEmbeddedTodo
100 99 TestEmbeddedBlockedLabelFilters
100 99 TestEmbeddedDoltRemoteAndPush
100 99 TestEmbeddedEpicStatus
100 99 TestEmbeddedInitSelectedExcludeRoutingForkDecoyAuto
100 99 TestEmbeddedSearchQueryStatusAssigneeLabels
100 100 TestEmbeddedContributorCreateShowReadsRouted
100 100 TestEmbeddedCreateCrossRepo
100 100 TestEmbeddedInitGitBootstrapRoutingExistingExplicit
100 100 TestEmbeddedLint
100 100 TestEmbeddedPromoteCLIConcurrent
# There is no committed recent duration artifact for these tests. This manifest
# pins a conservative even split for the 20-shard CI matrix while
# embedded-test-shard.sh continues to hash-distribute newly-added tests that are
# not listed here.
20 1 TestEmbeddedBackup
20 2 TestEmbeddedBackupConcurrent
20 3 TestEmbeddedBlocked
20 4 TestEmbeddedBlockedConcurrent
20 5 TestEmbeddedBootstrap
20 6 TestEmbeddedBootstrapConcurrent
20 7 TestEmbeddedBranch
20 8 TestEmbeddedBranchConcurrent
20 9 TestEmbeddedChildren
20 10 TestEmbeddedChildrenConcurrent
20 11 TestEmbeddedClose
20 12 TestEmbeddedCloseConcurrent
20 13 TestEmbeddedComments
20 14 TestEmbeddedCommentsCLI
20 15 TestEmbeddedCommentsCLIConcurrent
20 16 TestEmbeddedCompact
20 17 TestEmbeddedCompactConcurrent
20 18 TestEmbeddedConfig
20 19 TestEmbeddedConfigConcurrent
20 20 TestEmbeddedConfigNoWorkspaceStoreFreeCommands
20 1 TestEmbeddedConfigValidateJSONNoWorkspaceWritesStdout
20 2 TestEmbeddedContext
20 3 TestEmbeddedContextConcurrent
20 4 TestEmbeddedContributorCreate
20 5 TestEmbeddedCount
20 6 TestEmbeddedCountConcurrent
20 7 TestEmbeddedCreate
20 8 TestEmbeddedCreateCommitPending
20 9 TestEmbeddedCreateConcurrent
20 10 TestEmbeddedCreateCrossRepo
20 11 TestEmbeddedCreateCrossRepoUninit
20 12 TestEmbeddedCreateCrossRepoWithParent
20 13 TestEmbeddedCreateWithGitRemote
20 14 TestEmbeddedDefer
20 15 TestEmbeddedDeferConcurrent
20 16 TestEmbeddedDelete
20 17 TestEmbeddedDep
20 18 TestEmbeddedDepConcurrent
20 19 TestEmbeddedDiff
20 20 TestEmbeddedDiffConcurrent
20 1 TestEmbeddedDolt
20 2 TestEmbeddedDoltConcurrent
20 3 TestEmbeddedDuplicate
20 4 TestEmbeddedDuplicateConcurrent
20 5 TestEmbeddedDuplicates
20 6 TestEmbeddedDuplicatesConcurrent
20 7 TestEmbeddedEpic
20 8 TestEmbeddedEpicConcurrent
20 9 TestEmbeddedExport
20 10 TestEmbeddedExportConcurrent
20 11 TestEmbeddedFederation
20 12 TestEmbeddedFederationConcurrent
20 13 TestEmbeddedFindDuplicates
20 14 TestEmbeddedFindDuplicatesConcurrent
20 15 TestEmbeddedFlatten
20 16 TestEmbeddedFlattenConcurrent
20 17 TestEmbeddedGC
20 18 TestEmbeddedGCConcurrent
20 19 TestEmbeddedGate
20 20 TestEmbeddedGateConcurrent
20 1 TestEmbeddedGateCreate
20 2 TestEmbeddedGetDependencies
20 3 TestEmbeddedGraph
20 4 TestEmbeddedGraphConcurrent
20 5 TestEmbeddedHistory
20 6 TestEmbeddedHistoryConcurrent
20 7 TestEmbeddedHooks
20 8 TestEmbeddedHooksConcurrent
20 9 TestEmbeddedHuman
20 10 TestEmbeddedHumanConcurrent
20 11 TestEmbeddedImport
20 12 TestEmbeddedImportConcurrent
20 13 TestEmbeddedInfo
20 14 TestEmbeddedInfoConcurrent
20 15 TestEmbeddedInit
20 16 TestEmbeddedInitConcurrent
20 17 TestEmbeddedKV
20 18 TestEmbeddedKVConcurrent
20 19 TestEmbeddedLabel
20 20 TestEmbeddedLabelConcurrent
20 1 TestEmbeddedLint
20 2 TestEmbeddedLintConcurrent
20 3 TestEmbeddedList
20 4 TestEmbeddedListConcurrent
20 5 TestEmbeddedMemory
20 6 TestEmbeddedMemoryConcurrent
20 7 TestEmbeddedMigrate
20 8 TestEmbeddedMigrateConcurrent
20 9 TestEmbeddedOnboard
20 10 TestEmbeddedOnboardConcurrent
20 11 TestEmbeddedOrphans
20 12 TestEmbeddedOrphansConcurrent
20 13 TestEmbeddedPrime
20 14 TestEmbeddedPrimeConcurrent
20 15 TestEmbeddedPromote
20 16 TestEmbeddedPromoteCLI
20 17 TestEmbeddedPromoteCLIConcurrent
20 18 TestEmbeddedPrune
20 19 TestEmbeddedPurge
20 20 TestEmbeddedPurgeConcurrent
20 1 TestEmbeddedQuery
20 2 TestEmbeddedQueryConcurrent
20 3 TestEmbeddedQuick
20 4 TestEmbeddedQuickConcurrent
20 5 TestEmbeddedQuickstart
20 6 TestEmbeddedQuickstartConcurrent
20 7 TestEmbeddedReady
20 8 TestEmbeddedReadyConcurrent
20 9 TestEmbeddedRenamePrefix
20 10 TestEmbeddedRenamePrefixConcurrent
20 11 TestEmbeddedReopen
20 12 TestEmbeddedReopenConcurrent
20 13 TestEmbeddedRestore
20 14 TestEmbeddedRestoreConcurrent
20 15 TestEmbeddedSearch
20 16 TestEmbeddedSearchConcurrent
20 17 TestEmbeddedSetup
20 18 TestEmbeddedSetupConcurrent
20 19 TestEmbeddedShip
20 20 TestEmbeddedShipConcurrent
20 1 TestEmbeddedShow
20 2 TestEmbeddedShowConcurrent
20 3 TestEmbeddedStale
20 4 TestEmbeddedStaleConcurrent
20 5 TestEmbeddedState
20 6 TestEmbeddedStateConcurrent
20 7 TestEmbeddedStatus
20 8 TestEmbeddedStatusConcurrent
20 9 TestEmbeddedSupersede
20 10 TestEmbeddedSupersedeConcurrent
20 11 TestEmbeddedSwarm
20 12 TestEmbeddedSwarmConcurrent
20 13 TestEmbeddedTodo
20 14 TestEmbeddedTodoConcurrent
20 15 TestEmbeddedTypes
20 16 TestEmbeddedTypesConcurrent
20 17 TestEmbeddedUndefer
20 18 TestEmbeddedUndeferConcurrent
20 19 TestEmbeddedUpdate
20 20 TestEmbeddedUpdateConcurrent
20 1 TestEmbeddedVC
20 2 TestEmbeddedVCConcurrent
20 3 TestEmbeddedVersion
20 4 TestEmbeddedVersionConcurrent
20 5 TestEmbeddedWhere
20 6 TestEmbeddedWhereConcurrent

View file

@ -16,21 +16,14 @@
# shards by sub-test path (core/audit), not by top-level function name, and
# is a different mechanism from this manifest.
#
# Several tests are placed by measured -race duration instead (PR Risk run
# Three tests are placed by measured -race duration instead (PR Risk run
# 36807191489, at the 1000-item issueops.MaxApplyBatchItems cap):
# TestBatchApplyContract (604s) on shard 4, which has ~3m of other tests,
# and TestLargeBatchApplyWallClock_Embedded (261s) on shard 5. Hashed,
# and TestLargeBatchApplyStatementCounts_Embedded (247s) and
# TestLargeBatchApplyWallClock_Embedded (261s) on shards 2 and 5. Hashed,
# TestBatchApplyContract shared shard 2 with ~5m of other tests and ran it
# past the job's old 15m timeout; placed so, the heaviest shard projects to
# ~13m.
#
# TestLargeBatchApplyStatementCounts_Embedded (247s in that same run) was
# later split into TestLargeBatchApplyStatementCounts356_Embedded,
# TestLargeBatchApplyStatementCounts712_Embedded and
# TestLargeBatchApplyStatementCountsClassic40_Embedded (slice F1, CI shard
# balance; see internal/storage/embeddeddolt/large_batch_apply_measure_test.go).
# All 3 are kept on shard 2, where the single test used to live, rather than
# rebalanced across this frozen 5-shard block.
5 1 TestActiveDatabaseSizeFailsForMissingEmbeddedDatabase
5 2 TestActiveDatabaseSizeScopesToActiveEmbeddedDatabase
5 3 TestAddDependency
@ -90,9 +83,7 @@
5 1 TestHistory_NullTextColumns
5 2 TestHookFiringStoreCreateIssuesFiresDependencyUpdatesFromEmbeddedStore
5 3 TestIsBlockedBatchEmbedded
5 2 TestLargeBatchApplyStatementCounts356_Embedded
5 2 TestLargeBatchApplyStatementCounts712_Embedded
5 2 TestLargeBatchApplyStatementCountsClassic40_Embedded
5 2 TestLargeBatchApplyStatementCounts_Embedded
5 5 TestLargeBatchApplyWallClock_Embedded
5 4 TestLeaseLifecycleEmbedded
5 5 TestListWisps
@ -109,500 +100,3 @@
5 1 TestUpdateIssueType
5 2 TestUpdateMergeOps_DoltEngine
5 3 TestUpdateMergeOps_DoltEngine_TwoIssues
# Embedded-Dolt storage test shard manifest.
#
# Format: <total_shards> <shard_number> <top_level_test_name>
#
# 40-shard split for the Bazel-only embedded-Dolt storage tier
# (bazel-embedded in .github/workflows/bazel.yml), bin-packed
# longest-processing-time-first by measured wall-time from
# scripts/ci/embedded_storage_test_durations.json (see that file for provenance
# and its "relative weight, not absolute SLA" caveat).
# Regenerate with scripts/ci/gen_embedded_storage_shard_manifest.py 40
# --weights=duration --write after adding or removing Test* functions in
# internal/storage/embeddeddolt/*_test.go. --write is incremental: it
# keeps every already-assigned test on its current shard and only places
# newly-discovered names, onto whichever shard is currently lightest, so
# two unrelated PRs that each add one test do not textually conflict or
# silently invalidate each other's packing. Pass --repack to force a full
# from-scratch rebalance instead (a deliberate, separate change — expect a
# large diff). --check only verifies every discovered name is listed here
# exactly once (no stale or duplicate entries); it does NOT verify the
# packing is still well-balanced.
#
# This file is generated: notes added here are erased by the next
# regeneration. Add them to the generator or the durations file instead.
40 1 TestLifecycleCloseReopenContract
40 2 TestBatchApplyContract
40 3 TestActiveDatabaseSizeFailsForMissingEmbeddedDatabase
40 3 TestActiveDatabaseSizeScopesToActiveEmbeddedDatabase
40 3 TestBuildDSN_NoDatabase
40 3 TestBuildDSN_SpacesInPath
40 3 TestBuildDSN_WithDatabase
40 3 TestCleanGitRemoteCacheGarbage
40 3 TestCleanGitRemoteCacheGarbage_NoCacheDir
40 3 TestCleanGitRemoteCacheGarbage_Throttled
40 3 TestCommitAllOutOfBandChangeAndHonestNoOp
40 3 TestCreateBatchEquivalencePartsCoverEveryScenario
40 3 TestCreateBatchFastPathsMatchPerRowLarge_Embedded
40 3 TestCrossRecordInvariantContract
40 3 TestDepRekeyMarkerStillInIgnoredSeries
40 3 TestDoltCommitResponseLossIsIndeterminate
40 3 TestEmbeddedDependencyEditorRefusesADottedChildGatedOnItsOwnParent
40 3 TestEmbeddedDoltStoreIssueLifecycleBuildsOperations
40 3 TestEmbeddedDoltStoreIssueLifecycleRejectsNilStore
40 3 TestEmbeddedOpenReadOnly_FreshDatabaseNoWrites
40 3 TestEmbeddedSQLCommitResponseLossIsIndeterminate
40 3 TestEpochContract
40 3 TestExpectedRevisionContract
40 3 TestGitRefPinsMatchDolt
40 3 TestHasRepository
40 3 TestHelperProcess
40 3 TestLargeBatchApplyStatementCounts712_Embedded
40 3 TestLargeGraphCreateTiming_Embedded
40 3 TestLenientGateWarningBody_BluntRefusalKeepsSharedGuidance
40 3 TestLenientGateWarningBody_ShapedDecisions
40 3 TestLenientGateWarning_ComposedOutput
40 3 TestMain
40 3 TestPushCommitsPendingChangesFirst
40 3 TestRemoteEntryPointsUseVersionControlOps
40 3 TestRetentionContract
40 3 TestStageAndCommitAfterSQLCommitResponseLossIsIndeterminateAndNotReplayed
40 3 TestTransactionCleanupAfterSQLCommitIsIndeterminate
40 3 TestTransactionCleanupBeforeSQLCommitRemainsDefinite
40 3 TestUnknownProvenanceLeaseStaysReclaimable
40 4 TestBlockedListerContract
40 4 TestCreateBatchFastPathsMatchPerRowSmallDepAdd_Embedded
40 4 TestEmbeddedIssueOperationsUpdateLabelPatchOrdering
40 4 TestEmbeddedReaderGetMissIsNotFoundAndBackendFailureDoesNotDecay
40 4 TestEmbeddedReaderListFilterFamiliesNarrowToTheirRows
40 4 TestMergeAndSettleWithStrategy_EmptyStrategyMatchesMergeAndSettle
40 5 TestEmbeddedClaimerRefusesIncompleteRequestsAndAnAbsentIDWithoutTouchingState
40 5 TestEmbeddedIssueOperationsCloseAndReopenAWisp
40 5 TestEmbeddedReaderListKeysetPositionResumesTheCreatedDescIDAscOrder
40 5 TestRecordVersionKeepsSubSecondChangeAt
40 5 TestWithPeerAuth
40 6 TestCreateBatchFastPathsMatchPerRowApplyWaitsFor_Embedded
40 6 TestEmbeddedMergeAndSettleFKCascadeRepair
40 6 TestEmbeddedMergeAndSettleSkipsNonMemoryConfigConflict
40 6 TestEmbeddedReaderListKeysetPositionNarrowsWithoutReplacingTheOtherPredicates
40 6 TestEmbeddedRelationsAnswersAWispTargetInTheOutDirection
40 6 TestPromoteStillWorksWithCollisionGuard
40 6 TestSearchWithMissingWispPlaneTables
40 6 TestVersionedHistoryKeepsNumbersTheStoreDistinguishesApart
40 7 TestConcurrencyMultiProcess
40 7 TestEmbeddedBatchCloserRecordsOneHistoryEntryForWhatLanded
40 7 TestEmbeddedDependencyEditorAcceptsAnExternalTarget
40 7 TestEmbeddedDependencyEditorRelatesToAddLeavesItsSourceUnblocked
40 7 TestEmbeddedIssueOperationsUpdateMetadataReplaceClearsAndValidates
40 7 TestEmbeddedLenientOpenWarning_DataBehind
40 7 TestEmbeddedRelationsLeavesTheCallersRequestAlone
40 7 TestLoseVersionLeavesTheEpochTablesCommitted
40 7 TestMergeAndSettleWithStrategy_ResolvesDeclinedConflict
40 8 TestDeleterContract
40 8 TestEmbeddedDependencyEditorRoutesWispSourcedRemovalToTheWispPlane
40 8 TestEmbeddedMergeAndSettleDirtyWorkingSetSurvivesRefusedMerge
40 8 TestEmbeddedMintLeavesUpdatedAtWhereHistoryOffDoes
40 8 TestEmbeddedReaderGetBriefDepsProjectsTheDependencyRows
40 8 TestEmbeddedRelationsOrdersNeighborsFromBothPlanesTogether
40 8 TestEmbeddedReopenIssueCategorySemantics
40 8 TestGetIssueCommentsPageEmbedded
40 8 TestListWisps
40 9 TestBumpEpochCarryingNeitherCarriesNorServesARowFromAFutureEpoch
40 9 TestEmbeddedDependencyEditorRefusesCrossPlaneCycle
40 9 TestEmbeddedDependencyEditorSameTypeReAddIsIdempotent
40 9 TestEmbeddedDependencyEditorSnapshotsTheRequest
40 9 TestEmbeddedMigration0058AddsOnlyMissingConstraintInMixedPopulation
40 9 TestEmbeddedReaderReadyPageWiderThanTheHydrationBatchIsStillThatPrefix
40 9 TestEmbeddedReadyClaimerHydratesOnlyItsBlocksEdgesIntoTheCardinalities
40 9 TestGetReadyWorkIncludeEphemeralExcludesNonReadyWisps
40 9 TestPristineEmbeddedDoltFixtureRelocatesPrefixes
40 9 TestUpdateMergeOps_DoltEngine
40 10 TestEmbeddedClaimerStampsStartedAtOnceAcrossTheTwoWritesItChoosesBetween
40 10 TestEmbeddedDependencyEditorRemoveIsIdempotent
40 10 TestEmbeddedIssueOperationsUpdateClaimCASAndTransferMatrix
40 10 TestEmbeddedReaderGetResolvesTheExactIDAcrossBothPlanes
40 10 TestEmbeddedReaderReadyEphemeralPageKeepsBothPlanesCountsAtItsBoundary
40 10 TestGraphCounterContract
40 10 TestIgnoredCursorHealRespectsOperatorOverride
40 10 TestRunInTransactionPostCommitStageFailureIsIndeterminate
40 10 TestVersionedHistoryOffMatchesPreStackGolden_Embedded
40 10 TestWithPeerAuth_WarnsWhenStoredPeerSuppressesAmbientPasswordAmbient
40 11 TestABumpUnderOneStoreIDMovesTheEpochSeenThroughEveryStoreID
40 11 TestEmbeddedBatchCreateFirstVersionCarriesCreationTimeEdges
40 11 TestEmbeddedClaimerRefusalMessagesCarryTheirFragments
40 11 TestEmbeddedGuardedUpdateMintsOnceAfterItsPatches
40 11 TestEmbeddedMergeAndSettleRefusesUnknownTable
40 11 TestEmbeddedReaderListMaxRowsBoundaryIsLimitPlusOffset
40 11 TestEmbeddedReadyClaimerRecordsOneHistoryEntryForAWin
40 11 TestEventsJournal_ActorMatrixOnEmbedded
40 11 TestMemoriesContract
40 11 TestWithPeerAuth_WarnsWhenStoredPeerSuppressesAmbientPasswordStored
40 12 TestCounterExcludeStatusAcceptsAWorkspaceCustomStatusWithoutIncludeInfra
40 12 TestEmbeddedClaimerAcceptsAConfiguredActiveStatusAndRefusesAConfiguredWipOne
40 12 TestEmbeddedClaimerRefusesAWispIDAsNotFound
40 12 TestEmbeddedDependencyEditorVersionsOnlyARealAddOrRemove
40 12 TestEmbeddedIgnoredMigration0023RepairsForkLineageJournalShape
40 12 TestEmbeddedIssueOperationsCreateUnderAParentMintsTheNextChildID
40 12 TestEmbeddedReadyClaimerAnswersTheQuestionReaderReadyLists
40 12 TestHistoryPresenceContract
40 12 TestLifecycleUpdateContract
40 12 TestReaderListExcludeStatusAcceptsAWorkspaceCustomStatus
40 13 TestEmbeddedDepRekeyConvergesRenameChain
40 13 TestEmbeddedDependencyEditorAppliesParentChildBeforeBlockingEdges
40 13 TestEmbeddedDependencyEditorRefusesAGhostSource
40 13 TestEmbeddedIssueOperationsCreateParentChildRecomputesWaitsForClosure
40 13 TestEmbeddedIssueOperationsUpdateClaimPatchAppliesAfterClaim
40 13 TestEmbeddedIssueOperationsUpdateFoldsMetadataIntoOneEvent
40 13 TestEmbeddedPre0058RepairMarchesDriftedWispDependenciesToFinalShape
40 13 TestEmbeddedRelationsDirectionSelectsTheInverseGraph
40 13 TestGraphWalkPlansHonorJoinHints
40 14 TestBatchCreatorContract
40 14 TestBlockingAnnotatorContract
40 14 TestCountsIncludeWispDependencies
40 14 TestEmbeddedIssueOperationsPersistenceRollbackWispAndDetachedResults
40 14 TestEmbeddedOpenForRemoteSync_DataBehind
40 14 TestEmbeddedReaderOffsetSkipsTheRowsBeforeThePage
40 14 TestEmbeddedReaderReadyDefaultTypeExclusionsYieldToAnExplicitType
40 14 TestEmbeddedReadyClaimerClaimsTheFrontRowAndReturnsThePostClaimState
40 14 TestEmbeddedReadyClaimerDoesNotMutateTheCallerRequest
40 14 TestHeartbeatIssueCommitsARefusalOnlyWhenItReadTheIssueEmbedded
40 14 TestHistory_NullTextColumns
40 15 TestCreateIssuesRejectStaleUpserts
40 15 TestDecryptPassword_ShortCiphertextClassifiesAsKeyMismatch
40 15 TestEmbeddedGetMergeBlockersOnAQuietStore
40 15 TestEmbeddedIgnoredMigration0023NoopsWithoutItsTables
40 15 TestEmbeddedIssueOperationsRequestValuesAreNotMutated
40 15 TestEmbeddedReaderReadyBriefDropsTheFreeFormTextAndNothingElse
40 15 TestEmbeddedRelationsFiltersByAnOpenTypeVocabulary
40 15 TestGetIssue
40 15 TestLegacyTrackedIgnoredCursorHealsOnOpen
40 15 TestMoleculeContract
40 15 TestReadyWorkPageTotalFilterMatrix
40 16 TestDescendantWalkReachesEveryTargetKindAndStopsOnCycles
40 16 TestEmbeddedDependencyEditorAddedEchoesTheRequestOrder
40 16 TestEmbeddedDependencyEditorRemovesOnlyTheNamedEdge
40 16 TestEmbeddedReaderDoesNotMutateTheCallerRequest
40 16 TestEmbeddedReaderListLimitBoundaryUnderASortTheDatabaseCanExpress
40 16 TestEmbeddedRenameKeepsDependencyIDsDeterministic
40 16 TestExternalCapabilityBlocksEmbeddedReadyAndAppearsInTree
40 16 TestGetReadyWorkIncludeEphemeralAppliesWispFilters
40 16 TestMergeWithStrategy_OursKeepsLocal
40 16 TestWithPeerAuth_DivergedRemoteURLFailsClosed
40 17 TestAddDependency
40 17 TestEmbeddedBatchCloserWispItemClosesAndEarnsTheClaim
40 17 TestEmbeddedDependencyEditorSameTypeReAddWithChangedThreadMintsOneVersion
40 17 TestEmbeddedIssueOperationsUpdateIssuePlaneOnlyRefusesWisps
40 17 TestEmbeddedIssueOperationsUpdateStatusCrossingSettlesAConditionalBlocksDepender
40 17 TestEmbeddedReaderListRejectsATypeOutsideTheWorkspaceVocabulary
40 17 TestEmbeddedReadyClaimerLeasesADurableWinButNotAnEphemeralOne
40 17 TestHeartbeatMatchesActorAcrossSpellingEmbedded
40 17 TestStatsReporterContract
40 17 TestVersionReconcilerContract
40 18 TestCreateBatchParticipationGeneration
40 18 TestEmbeddedBatchCloserIdempotentRecloseIsAPerItemSuccess
40 18 TestEmbeddedDependencyEditorMixedBatchWritesBothPlanes
40 18 TestEmbeddedIssueOperationsUpdateRawMetadataTakesTheFunnelsValueShapes
40 18 TestEmbeddedMergeAndSettleMemoryConfigConflict
40 18 TestEmbeddedReaderListIncludeEphemeralMergesThePlanesIntoOneOrder
40 18 TestEmbeddedReaderListParentReachesEveryDescendantAndOnlyItsOwn
40 18 TestMetadataCASContract
40 18 TestOpenDifferentDirsReturnsDifferentStores
40 18 TestPromoteClearsNoHistory
40 18 TestRemoteVerbPlainRemoteWithoutAuthPresentsNone
40 19 TestEmbeddedDependencyEditorRetypeRefusalLeavesTheOriginalEdge
40 19 TestEmbeddedIssueOperationsUpdateInvalidIssueTypePreservesValidationSentinel
40 19 TestEmbeddedMigration0062FlipsEventsToIgnoredPlane
40 19 TestEmbeddedReaderListMaxRowsIsHonored
40 19 TestEmbeddedRelationsAnswersInThePinnedOrder
40 19 TestIgnoredCursorHealConvergesFromEveryCrashState
40 19 TestOpenAfterCloseCreatesNewStore
40 19 TestOpenReturnsCachedStore
40 19 TestParticipationGenerationFixtureKitIsWired
40 19 TestRemoteVerbsPresentStoredPeerCredentials
40 19 TestRenameLabelMintsOneVersionPerTouchedBead
40 20 TestBumpEpochCarryingCarriesOnlyTheLineageHoldingTheNewestRow
40 20 TestCreateIssue
40 20 TestEmbeddedCheckedWrappersRouteTheirPreconditions
40 20 TestEmbeddedIssueOperationsCreateRoutesInfraTypesToWisps
40 20 TestEmbeddedMigrateStepCommitLeavesUntouchedUserDirt_4566
40 20 TestEmbeddedOpenReadOnly_SkipsGateAndMigrations
40 20 TestEmbeddedReadyClaimerClaimsAnEphemeralRowTheFilterAdmits
40 20 TestEventsJournalRestartAndRetentionBoundary
40 20 TestForeignSkipDetailIsBounded
40 20 TestHeartbeatRejectsWispEmbedded
40 20 TestIgnoredCursorHealNeverResurrectsRolledBackVersions
40 21 TestBumpEpochCarryingCarriesTheLiveRowsOfEveryStoreInTheDatabase
40 21 TestCreateRejectsCrossTableIDCollision
40 21 TestEmbeddedBatchCloserItemsAnswerToTheCloseGuards
40 21 TestEmbeddedDependencyEditorAcceptsATypeOutsideTheConstants
40 21 TestEmbeddedIssueOperationsUpdateParentStagesBlockedStateAndRollsBackFailure
40 21 TestEmbeddedMigration0047DelegatesToSplitTargetRepairAndConvergesThroughIgnoredChain
40 21 TestEmbeddedRelationsLeavesAnExternalTargetOutOfTheAnswer
40 21 TestEmbeddedRemoteMigrateGate_BlocksReopen
40 21 TestEmbeddedRoleFixtureKitCountHistoryMovesWithACommit
40 21 TestEmbeddedTransactionStandaloneWispLifecyclePersistsWithoutDoltCommit
40 21 TestLargeBatchApplyWallClock_Embedded
40 22 TestEdgeReaderContract
40 22 TestEmbeddedDepRekeyAbortLeavesMarkerUnrecorded
40 22 TestEmbeddedDepRekeyRefusesToWriteIntoDirtyDependencies
40 22 TestEmbeddedDependencyEditorRefusesSelfDependencyWithTheProbeSkipped
40 22 TestEmbeddedReaderListStatusAcceptsACommaSeparatedORSet
40 22 TestEmbeddedReaderReadyLimitBoundary
40 22 TestEventsAutoPruneKeepsAnUnboundedJournalUnbounded
40 22 TestEventsJournalPruneNeverSplitsASkewedPair
40 22 TestLargeBatchApplyStatementCounts356_Embedded
40 22 TestLeaseLifecycleEmbedded
40 22 TestPolicyBlockingAnnotatorForeignOpensAreSublinear
40 23 TestAsOfReadContract
40 23 TestEmbeddedBatchCloserBackendFailureReturnsNoOutcomes
40 23 TestEmbeddedBatchCloserClaimNextHydratesWhenSomethingClosed
40 23 TestEmbeddedDependencyEditorAcceptsBlockingAcrossIssueTypes
40 23 TestEmbeddedDependencyEditorRecordsNoHistoryForAnAllEphemeralRequest
40 23 TestEmbeddedMigrateConvergesUnderConcurrentInterruptedRetries_4566
40 23 TestEmbeddedReaderListEmptyPageIsWellFormed
40 23 TestEmbeddedReadyClaimerFencesTheClaimByEveryLabelSetAndTheParentItWasGiven
40 23 TestEmbeddedRoleFixtureKitHooksAreUsable
40 23 TestEventsAutoPruneBoundsTheJournalToTheFloors
40 23 TestJournalContract
40 24 TestBootstrapperContract
40 24 TestEmbeddedBatchCloserOutcomesMirrorItemsIndexForIndex
40 24 TestEmbeddedClaimerReclaimsAcrossSpellingWithoutWriting
40 24 TestEmbeddedConfigCommitStagesConfig
40 24 TestEmbeddedIgnoredSeriesConvergesWithFreshInitShape
40 24 TestEmbeddedIssueOperationsCreateWithDependenciesSettlesInTheCreatingTransaction
40 24 TestEmbeddedMigrateSelfHealsAfterMidPassFault_4566
40 24 TestEmbeddedReaderListQueryMatchesTheTitleOrTheID
40 24 TestEmbeddedReaderListWispTypeNarrowsTheAdmittedPlaneRatherThanAdmittingIt
40 24 TestIgnoredCursorHealResumeRespectsOperatorOverride
40 24 TestLargeBatchApplyStatementCountsClassic40_Embedded
40 24 TestReopenIssue
40 25 TestBatchGetterContract
40 25 TestDatabases
40 25 TestDualWriteFixtureKitIsWired
40 25 TestEmbeddedBatchCloserClaimNextIsNilWhenNothingClosed
40 25 TestEmbeddedIssueOperationsUpdateClaimHonorsConfiguredActiveStatuses
40 25 TestEmbeddedReadyClaimerLeavesEphemeralRowsOutOfTheDefaultReadySet
40 25 TestEmbeddedReadyClaimerRejectsLimitOffsetBriefAndEmptyActor
40 25 TestGetDependentRecordsForIssuesEmbedded
40 25 TestHeartbeaterContract
40 25 TestIgnoredCursorHealIsIdempotent
40 25 TestIsBlockedBatchEmbedded
40 25 TestReadyWorkPageTotal
40 25 TestWithPeerAuth_RestoresAbsentEnv
40 26 TestEmbeddedIssueOperationsCreateClosedDerivesTheClosedStamp
40 26 TestEmbeddedMigration0058CleansOrphanedAndInvalidWispDependenciesRowsBeforeAddingConstraints
40 26 TestEmbeddedOpenForReadOnlyCommand_LenientGate
40 26 TestEmbeddedReaderListReadyFlagCarriesTheAssigneeAndPriorityFilters
40 26 TestEmbeddedReaderReadyParentScopesToItsTransitiveDescendants
40 26 TestEmbeddedReadyClaimerSkipsIneligibleFrontRows
40 26 TestEmbeddedRecomputeAllBlockedDirtyGraphIsTyped
40 26 TestEmbeddedRelationsRefusesTheZeroDirection
40 26 TestHookFiringStoreCreateIssuesFiresDependencyUpdatesFromEmbeddedStore
40 26 TestReclaimAnyReplicaOverride
40 26 TestWithPeerAuth_EnvFallbackDoesNotObservePeerCredentials
40 27 TestEmbeddedBatchCloserDurableHistoryNeverNamesAWisp
40 27 TestEmbeddedBatchCloserRequestValidationReturnsZeroResultAndChangesNothing
40 27 TestEmbeddedDependencyEditorAcceptsADiamond
40 27 TestEmbeddedDependencyEditorAddMarksItsSourceInTheSameVerb
40 27 TestEmbeddedMigration0058HealsAlreadyAffectedDatabase
40 27 TestEmbeddedReaderGetOptionalRowListsAreOffByDefault
40 27 TestEmbeddedRelationsRefusesATypeFilterOverTheColumnLength
40 27 TestEventsJournalReadRefusesAnInteriorHole
40 27 TestPartitionWispIDs
40 27 TestRemoteGitDataRefOnEngine
40 27 TestSweeperContract
40 28 TestBumpEpochCarryingDoesNotCarryALostLineage
40 28 TestEmbeddedBatchCloserForceBypassesOnlyClosePolicy
40 28 TestEmbeddedBatchCloserSettlesTheDependersOfWhatItClosed
40 28 TestEmbeddedClaimerClaimsAnUnassignedOpenIssueAndAnswersTheBareRow
40 28 TestEmbeddedClaimerReclaimsItsOwnInProgressIssueWithoutWriting
40 28 TestEmbeddedClaimerTakesAPoolAssignedIssueButRefusesAForeignHolder
40 28 TestEmbeddedIssueOperationsUpdateLabelPatchValueRules
40 28 TestEmbeddedIssueOperationsUpdateRefusesATypeOutsideTheWorkspaceVocabulary
40 28 TestEmbeddedReaderListReadyFlagAnswersTheBlockerAwareSet
40 28 TestRenameLabel
40 28 TestUpdateIssueType
40 28 TestWithPeerAuth_RestoresEnvWhenCallbackFails
40 29 TestEmbeddedBatchCloserClaimFilterValueFailureIsARequestValidationFailure
40 29 TestEmbeddedBatchCloserClaimNextIsNilWhenTheFrontIsEmpty
40 29 TestEmbeddedDepRekeyMergesFreshDuplicateEdges
40 29 TestEmbeddedDependencyEditorRecordsOneHistoryEntryPerLandedRequest
40 29 TestEmbeddedMergeAndSettleMetadataConflict
40 29 TestEmbeddedReaderListDefaultExclusionsAndTheirOverrides
40 29 TestEmbeddedReaderListTimeBoundsAreStrictAndWholeSecond
40 29 TestEmbeddedReaderReadySetOwnsItsStatusPinnedAndTemplateDecisions
40 29 TestEmbeddedTransactionSameStatusDoesNotPublishUnrelatedDurableChanges
40 29 TestEventsJournalAccessor
40 29 TestLeaseReclaimerContract
40 29 TestLifecycleCreateContract
40 30 TestCounterContract
40 30 TestCycleDetectorContract
40 30 TestEmbeddedClaimerTakesAnOpenIssueTheActorAlreadyHolds
40 30 TestEmbeddedCommitToleratesNothingToCommit
40 30 TestEmbeddedEveryAcceptedLifecycleMutationMintsOneVersion
40 30 TestEmbeddedIssueOperationsUpdateClaimConflictCarriesTheLosingState
40 30 TestEmbeddedIssueOperationsUpdateStampsStartedAtOnceOnTheFirstInProgress
40 30 TestEmbeddedReaderReadySortPoliciesOrderTheSameRows
40 30 TestEmbeddedTransactionStandaloneWispMutationDoesNotPublishUnrelatedDurableChanges
40 30 TestLegacyTrackedIgnoredCursorUnwedgesPull
40 30 TestUpdateMergeOps_DoltEngine_TwoIssues
40 31 TestBumpEpochCarryingWritesOneCarryRowPerLiveIDNamingTheLineageRoot
40 31 TestDualWriteContract
40 31 TestEmbeddedDependencyEditorAcceptsAForeignRepoTarget
40 31 TestEmbeddedDependencyEditorMaintainsBlockedStateAcrossPlanes
40 31 TestEmbeddedDependencyEditorWritesTheTargetIntoItsTypedColumn
40 31 TestEmbeddedMigrateConsent_BehindAndDirtyWorkingSetReconcileRecovers
40 31 TestEmbeddedReaderListPriorityKeysetWalkOverAnOversizedEqualKeyRunLosesNothingAndRepeatsNothing
40 31 TestEmbeddedTransactionWispLifecyclePersistsDurableDependent
40 31 TestEventsSinceEmbedded
40 31 TestGetLabels
40 31 TestReadyCounterContract
40 31 TestWithPeerAuth_KeyMismatchFailsClosed
40 32 TestCurrentAddressForNeverReseedsAnAbsentStoreEpochRow
40 32 TestEmbeddedClaimerGrantsALiveLeaseOnTheRowItWonAndLeavesARefusedOneAlone
40 32 TestEmbeddedDependencyEditorRefusesAMissingLocalTarget
40 32 TestEmbeddedDirtyTablesGate_BlocksReopenThenWorkingSetReconcileRecovers
40 32 TestEmbeddedIgnoredMigration0019CreatesEventsForFreshClones
40 32 TestEmbeddedIssueOperationsCreateReverseNonBlockingStagesConcreteTables
40 32 TestEmbeddedReadyClaimerEmptyFrontIsNormal
40 32 TestEmbeddedRecomputeAllBlockedWiring
40 32 TestEventsJournal_EmbeddedConcurrentGaplessNoDup
40 32 TestGetNextChildID
40 32 TestRemoteVerbPlainRemoteKeepsAmbientEnv
40 32 TestWithPeerAuth_MissingRemoteFailsClosed
40 33 TestEmbeddedBatchCloserDuplicateItemRecloseAtItsOwnIndex
40 33 TestEmbeddedDependencyEditorClosedChildAddSatisfiesAnAnyChildrenGate
40 33 TestEmbeddedDependencyEditorValidationRefusalsWriteNothing
40 33 TestEmbeddedIgnoredMigration0023NoopsOnHealthyWorkspace
40 33 TestEmbeddedMoveIssuePersistenceEphemeralNoHistorySmoke
40 33 TestEmbeddedRelationsResolvesTheAnchorIDExactly
40 33 TestEmbeddedSyncCommitsConfigBeforeMerge
40 33 TestEventsAutoPruneThrottleSkipsTheSecondPass
40 33 TestFirstMintLeavesTheEpochTablesCommitted
40 33 TestGetDependentRecordsEmbedded
40 33 TestPruneEventsBatchDeletesTheLowestSeqsOnly
40 33 TestTreeWalkerContract
40 34 TestAddLabel
40 34 TestBumpEpochCarryingLeavesTheEpochTablesCommitted
40 34 TestDecryptPassword_KeyMismatchNamesTheLocalKey
40 34 TestEmbeddedBlockedRecheckRecordsUnblockingWrites
40 34 TestEmbeddedDependencyEditorAttributesItsEventsToTheActor
40 34 TestEmbeddedDependencyEditorSameTypeReAddWithIdenticalMetadataIsANoOp
40 34 TestEmbeddedIssueOperationsCreateAggregatesRelations
40 34 TestEmbeddedReaderReadyDeferredAndEphemeralGates
40 34 TestEmbeddedReaderReadyPageIsThePrefixOfTheUnboundedAnswerCountsIncluded
40 34 TestMergeWithStrategy_TheirsResolvesAndCommits
40 34 TestQuerierContract
40 34 TestReadyWorkStatementBudget
40 35 TestEmbeddedBatchCloserAllIdempotentBatchLandsNothing
40 35 TestEmbeddedClaimIssueWrapperClaimsTheWispPlane
40 35 TestEmbeddedDependencyEditorGateScopeFollowsTheEdgeType
40 35 TestEmbeddedDependencyEditorRefusesASamePlaneEdgeClosingACrossPlaneCycle
40 35 TestEmbeddedDependencyEditorRepeatsWithinOneRequestCollapse
40 35 TestEmbeddedIssueOperationsUpdateAllScalarAndPointerFieldsReportChanged
40 35 TestEmbeddedIssueOperationsUpdateWritesEveryScalarPatchField
40 35 TestMerge_NoStrategyStillErrorsWithEscapeHatchHint
40 35 TestReadEventsAutoPruneStateResolvesBothHalvesInOneQuery
40 35 TestReadyWorkWithMissingDeferredParentTables
40 35 TestReclaimExpiredLeaseSurvivesRestartEmbedded
40 36 TestBumpEpochCarryingFailsAndRollsBackWhenARowAlreadyExistsAtTheNewEpoch
40 36 TestCommenterContract
40 36 TestConcurrentOpenReturnsCached
40 36 TestEmbeddedBatchCloserAllRefusedBatchRecordsNoHistory
40 36 TestEmbeddedDependencyEditorRefusalWritesNothing
40 36 TestEmbeddedDependencyEditorSkipPerEdgeCycleCheckDropsOnlyTheProbe
40 36 TestEmbeddedMigration0057ConvertsTextEventsColumnsToLongtext
40 36 TestEmbeddedReaderListReadyFlagRefusesAFilterItCannotCarry
40 36 TestEmbeddedRelationsRefusesAnUnusableTypeFilter
40 36 TestGetReadyWorkMoleculeFilter
40 36 TestReleaserContract
40 36 TestSchemaAfterInit
40 37 TestEmbeddedBatchCloserClaimNextSeesAnUnblockingFromItsOwnBatch
40 37 TestEmbeddedBatchCloserOutcomeSnapshotIsTheDocumentedShape
40 37 TestEmbeddedDependencyEditorRecordsOneHistoryEntryForAMixedPlaneRequest
40 37 TestEmbeddedDependencyEditorRefusesACycleThroughAParentChildHop
40 37 TestEmbeddedDependencyEditorRemoveUnmarksItsSourceAndDescendants
40 37 TestEmbeddedIssueOperationsCreateEmptyIDPreservesParentAndReverseDependencies
40 37 TestEmbeddedLenientOpenWarning_OtherRefusalsKeepBluntGuidance
40 37 TestEmbeddedMergeAndSettleReportsOperatorConflicts
40 37 TestEmbeddedReaderListBriefDropsTheFreeFormTextAndNothingElse
40 37 TestEmbeddedReaderListNaturalNumericIDSortTrimsAfterTheFetch
40 37 TestEpochWritesReportAnUnpublishedCommitAsIndeterminate
40 37 TestIgnoredCursorHealRespectsOverrideUnderBroaderPattern
40 38 TestCreateIssues
40 38 TestEmbeddedClaimerRefusesABuiltInIneligibleStatusWithTheStateThatRefusedIt
40 38 TestEmbeddedDependencyEditorRefusesBlockingEdgeAcrossItsOwnHierarchy
40 38 TestEmbeddedIssueOperationsUpdateClosedFieldsMatchClose
40 38 TestEmbeddedIssueOperationsUpdateNotesConflictPreservesValidationSentinel
40 38 TestEmbeddedReaderGetDetailShapeMatchesTheSeededIssue
40 38 TestEmbeddedReaderListCountsAreBlocksOnlyWhereGetCountsEveryEdge
40 38 TestEmbeddedReaderListKeysetWalkOverAnOversizedGroupLosesNothingAndRepeatsNothing
40 38 TestEmbeddedTempRebuildIntermediatesNeverReachHistory
40 38 TestEventsJournalPruneWhenEveryRowIsOlderThanTheCutoff
40 38 TestPolicyBlockingAnnotatorBatchEqualsPerItem
40 38 TestWithPeerAuth_ConcurrentPeersDoNotMixCredentials
40 39 TestDualWriteContractFlagOff
40 39 TestEmbeddedBatchCloserPerItemRefusalIsAResultAndSurvivorsCommit
40 39 TestEmbeddedBlockedRecheckFailureKeepsTheWrite
40 39 TestEmbeddedDependencyEditorMixedBatchRefusalRollsBackBothPlanes
40 39 TestEmbeddedIssueOperationsClaimLeavesBlockedStateAlone
40 39 TestEmbeddedMigrateRepairedDependenciesIDColumnCommitsAtomicallyWithVersion53_4690
40 39 TestEmbeddedReaderListSkipCountsDropsTheCardinalitiesAndNothingElse
40 39 TestEmbeddedRelationsResolvesAWispAnchor
40 39 TestParticipationGenerationFence
40 39 TestPreviewStoreRefusesLocalMetadataWrite
40 39 TestReclaimRefusesForeignReplicaLease
40 39 TestWorkspaceConfigContract
40 40 TestCountsWithMissingWispPlaneTables
40 40 TestEmbeddedBatchCloserDoesNotMutateTheCallerRequest
40 40 TestEmbeddedBlockedRecheckSettlesWhatTheWriteRecorded
40 40 TestEmbeddedDepRekeyRepairsHalfRekeyedDuplicateEdge
40 40 TestEmbeddedDependencyEditorRefusesBlockingEdgeAcrossAWispHierarchy
40 40 TestEmbeddedDependencyEditorRoutesWispSourcedEdgeToTheWispPlane
40 40 TestEmbeddedDependencyEditorSameTypeReAddWithChangedMetadataMintsOneVersion
40 40 TestEmbeddedIssueOperationsUpdateStatusCrossingSettlesDependers
40 40 TestEmbeddedOpenForRemoteSync_OtherRefusalsStayFatal
40 40 TestEmbeddedRelationsSeparatesNoNeighborsFromNoSuchIssue
40 40 TestEmbeddedReopenCustomDoneFallsBackWhenNormalizedTableMissing

View file

@ -3,7 +3,7 @@
#
# Usage: embedded-test-shard.sh <shard_number> <total_shards>
#
# Discovers all TestEmbedded* top-level functions in cmd/bd/*_test.go.
# Discovers all TestEmbedded* top-level functions from cmd/bd/*_embedded_test.go.
# Tests listed in embedded-cmd-test-shards.txt for the requested shard count use
# that committed assignment; newly-added tests fall back to hash(name) % total.
# Runs the matching subset using the pre-built test binary at
@ -33,12 +33,8 @@ fi
SHARD_INDEX=$(( SHARD_NUMBER - 1 ))
MANIFEST="${BEADS_TEST_SHARD_MANIFEST:-.github/scripts/embedded-cmd-test-shards.txt}"
# Discover all top-level TestEmbedded* functions across every cmd/bd test
# file, by name rather than by file glob (as proxied-test-shard.sh does): a
# test gated on BEADS_TEST_EMBEDDED_DOLT runs in this lane or in none, wherever
# it lives. scripts/embedded_lane_coverage_test.go fails on a gated test this
# selection misses.
ALL_TESTS=$(grep -rh '^func TestEmbedded' cmd/bd/*_test.go \
# Discover all top-level TestEmbedded* functions.
ALL_TESTS=$(grep -rh '^func TestEmbedded' cmd/bd/*_embedded_test.go \
| sed 's/func \(TestEmbedded[A-Za-z0-9_]*\).*/\1/' \
| sort -u)

View file

@ -2,287 +2,189 @@
#
# Format: <total_shards> <shard_number> <top_level_test_name>
#
# 34-shard split for the Bazel-only proxied-server tier
# (bazel-proxied in .github/workflows/bazel.yml), bin-packed
# longest-processing-time-first by measured wall-time from
# scripts/ci/proxied_test_durations.json (see that file for
# provenance and its "relative weight, not absolute SLA" caveat).
# Regenerate with scripts/ci/gen_proxied_shard_manifest.py 34
# --weights=duration --write after adding or removing
# TestProxiedServer*/TestServerMode* functions. --write is incremental:
# it keeps every already-assigned test on its current shard and only
# places newly-discovered names, onto whichever shard is currently
# lightest, so two unrelated PRs that each add one test do not textually
# conflict or silently invalidate each other's packing. Pass --repack to
# force a full from-scratch rebalance instead (a deliberate, separate
# change — expect a large diff). --check only verifies every discovered
# name is listed here exactly once (no stale or duplicate entries); it
# does NOT verify the packing is still well-balanced, so a reweighted
# proxied_test_durations.json does not by itself fail --check — rerun
# with --repack periodically (or whenever shard loads look uneven in CI)
# to rebalance on purpose. Newly-added tests not listed here
# hash-distribute via proxied-test-shard.sh: cksum(name) % total,
# unrelated to proxied_test_durations.json (that file only feeds this
# generator's own cost estimate for a test it has not measured yet).
# 15-shard split, bin-packed longest-processing-time-first by
# estimated cost (bd-init count; per-init migration chains dominate).
# Regenerate with scripts/ci/gen_proxied_shard_manifest.py after adding,
# splitting, or reweighting TestProxiedServer*/TestServerMode*
# functions. Newly-added tests not listed here hash-distribute via
# proxied-test-shard.sh.
#
# This file is generated: notes added here are erased by the next
# regeneration. Add them to the generator or the durations file
# instead.
# regeneration. Add them to the generator instead. Known blind spots
# of the cost proxy (it counts inits, not the work done per init):
#
# TestProxiedServerListSortRetiresTheWalk is the most expensive
# entry and one of the cheapest-looking: off a single init it seeds
# 1400 rows and walks the listing three ways. It is the measurement
# behind the claim that sort=priority retires the client-side walk,
# so it has to run on PRs.
#
# TestProxiedServerServeReadParity is the CLI/HTTP read parity
# oracle, the behavioural half of the anti-drift claim. It being in
# this lane, and this lane being required by the PR Risk CI gate,
# is what makes that claim enforced on PRs rather than asserted in
# a doc comment.
34 1 TestProxiedServerDep2
34 1 TestProxiedServerMolProgress
34 1 TestProxiedServerReadyClaimConcurrent
34 1 TestProxiedServerServeActivatesTheEventsJournal
34 1 TestProxiedServerServeRelease
15 1 TestProxiedServerBlocked
15 1 TestProxiedServerCompactDolt
15 1 TestProxiedServerCreate
15 1 TestProxiedServerDep2
15 1 TestProxiedServerDepConcurrent
15 1 TestProxiedServerListSortRetiresTheWalk
15 1 TestProxiedServerMolLastActivity
15 1 TestProxiedServerReopenConcurrent
15 1 TestProxiedServerServeReadParity
15 1 TestProxiedServerUpdateConcurrentClaim
34 2 TestProxiedServerDepListSingleIDWarnsOnDroppedExternalEdge
34 2 TestProxiedServerGateList
34 2 TestProxiedServerList
34 2 TestProxiedServerServeRemoveDependency
34 2 TestProxiedServerUpdateC
15 2 TestProxiedServerCompactHistory
15 2 TestProxiedServerCreate2
15 2 TestProxiedServerDepListSingleIDWarnsOnDroppedExternalEdge
15 2 TestProxiedServerFindDuplicates
15 2 TestProxiedServerListWatchCountsTheOffsetIntoMaxRows
15 2 TestProxiedServerReady2
15 2 TestProxiedServerSQL
15 2 TestProxiedServerServeReadRevision
15 2 TestProxiedServerUpdateConcurrentMetadata
15 2 TestProxiedServerUpdateIfGuards
34 3 TestProxiedServerAutoPrune
34 3 TestProxiedServerClose2B
34 3 TestProxiedServerEventsJournalOffByDefault
34 3 TestProxiedServerIfRevisionCloseMismatchRefuses
34 3 TestProxiedServerMolLastActivity
34 3 TestProxiedServerPurgeWispsPlaneRetention
34 3 TestProxiedServerServeLifecycle
34 3 TestProxiedServerStatuses
15 3 TestProxiedServerCascadeParity
15 3 TestProxiedServerDoltLifecycle
15 3 TestProxiedServerMolBurn
15 3 TestProxiedServerMolStale
15 3 TestProxiedServerMoleculeFrontDoorDirectServerProxyParity
15 3 TestProxiedServerSQLDatabaseFlag
15 3 TestProxiedServerServeRelatedIssues
15 3 TestProxiedServerTag
15 3 TestProxiedServerUpdate
15 3 TestProxiedServerWispCreateRejectsEnumViolatingVar
34 4 TestProxiedServerMolStale
34 4 TestProxiedServerReadyConcurrent
34 4 TestProxiedServerServeRelatedIssues
34 4 TestProxiedServerServeSettingsWrites
34 4 TestProxiedServerShow2
34 4 TestServerModeServeSkipsPostRunMaintenance
15 4 TestProxiedServerCreateInfraTypeRoutesToWisps
15 4 TestProxiedServerEdit
15 4 TestProxiedServerMoleculeFrontDoorWriteParity
15 4 TestProxiedServerPour
15 4 TestProxiedServerReassignFence
15 4 TestProxiedServerServeAddComment
15 4 TestProxiedServerServeRelease
15 4 TestProxiedServerUpdate2
15 4 TestProxiedServerUpdateHooks
34 5 TestProxiedServerHistoryRemoteRefusalFrontDoorMatrix
34 5 TestProxiedServerInfo
34 5 TestProxiedServerNote
34 5 TestProxiedServerOutageReconnectAcceptanceMatrix
34 5 TestProxiedServerUpdate3
34 5 TestServerModeDeferAutoWake
15 5 TestProxiedServerClose
15 5 TestProxiedServerConfigConcurrent
15 5 TestProxiedServerExport
15 5 TestProxiedServerGateLifecycle
15 5 TestProxiedServerMolReadyGated
15 5 TestProxiedServerMultiStatementSQL
15 5 TestProxiedServerServeAddDependencies
15 5 TestProxiedServerServeRemoveDependency
15 5 TestProxiedServerWispCreate
34 6 TestProxiedServerPing
34 6 TestProxiedServerQuick
34 6 TestProxiedServerServeReadsTheJournalItJustWrote
34 6 TestProxiedServerSwarm
34 6 TestProxiedServerUpdate2B
34 6 TestProxiedServerVersionedHistorySwitchRefusesAnUnrecordableGateTimeout
34 6 TestProxiedServerWispList
15 6 TestProxiedServerClose2
15 6 TestProxiedServerContext
15 6 TestProxiedServerExternalCreate
15 6 TestProxiedServerLink
15 6 TestProxiedServerNote
15 6 TestProxiedServerRelate
15 6 TestProxiedServerServeBatchClose
15 6 TestProxiedServerServeSettingsWrites
15 6 TestProxiedServerWispList
34 7 TestProxiedServerCloseConcurrent
34 7 TestProxiedServerCreateInfraTypeRoutesToWisps
34 7 TestProxiedServerDeleteIfRevisionSingleWinner
34 7 TestProxiedServerExternalCreate
34 7 TestProxiedServerIfRevisionGuardDelete
34 7 TestProxiedServerIfRevisionTargetGoneIsPreconditionFailed
34 7 TestProxiedServerLabelC
34 7 TestProxiedServerMoleculeLifecycleAgreesOnEveryRoute
34 7 TestProxiedServerTypesAgreeWithCreate
15 7 TestProxiedServerAssign
15 7 TestProxiedServerBackupRefusedOnExternalTopology
15 7 TestProxiedServerCount
15 7 TestProxiedServerGC
15 7 TestProxiedServerList
15 7 TestProxiedServerOrphans
15 7 TestProxiedServerReady
15 7 TestProxiedServerServeClaim
15 7 TestProxiedServerServeUpdate
15 7 TestProxiedServerState
34 8 TestProxiedServerClose2
34 8 TestProxiedServerDeleteWisp
34 8 TestProxiedServerExport
34 8 TestProxiedServerFindDuplicates
34 8 TestProxiedServerGateCheck
34 8 TestProxiedServerServeReadParity
15 8 TestProxiedServerBatchParity
15 8 TestProxiedServerCountIncludeInfra
15 8 TestProxiedServerDoltRemoteRemove
15 8 TestProxiedServerGateCreateInheritsRepoMetadata
15 8 TestProxiedServerLabel
15 8 TestProxiedServerMolBond
15 8 TestProxiedServerPathHelpers
15 8 TestProxiedServerRecomputeBlocked
15 8 TestProxiedServerServeClaimNext
15 8 TestProxiedServerSetState
34 9 TestProxiedServerCloseSiblingBlockersFanIn
34 9 TestProxiedServerGateLifecycle
34 9 TestProxiedServerHistoryRemoteSupportedFrontDoorParity
34 9 TestProxiedServerIfRevisionGuardReopen
34 9 TestProxiedServerIfRevisionOutranksReassignFence
34 9 TestProxiedServerServeRefusesTheJournalWhenItIsDisabled
34 9 TestProxiedServerUpdate
34 9 TestServerModeServe
15 9 TestProxiedServerChildren
15 9 TestProxiedServerComment
15 9 TestProxiedServerDeferAutoWake
15 9 TestProxiedServerGateFrontDoorDirectServerProxyParity
15 9 TestProxiedServerMemory
15 9 TestProxiedServerPing
15 9 TestProxiedServerPrune
15 9 TestProxiedServerReopen
15 9 TestProxiedServerServeClose
15 9 TestProxiedServerStale
34 10 TestProxiedServerContext
34 10 TestProxiedServerCreate2B
34 10 TestProxiedServerGateCheckB
34 10 TestProxiedServerServeRefusesAStreamOnADisabledJournal
34 10 TestProxiedServerTypes
34 10 TestProxiedServerUpdate2C
15 10 TestProxiedServerCleanDatabases
15 10 TestProxiedServerDeferUndefer
15 10 TestProxiedServerDuplicates
15 10 TestProxiedServerGraph
15 10 TestProxiedServerPourRejectsEnumViolatingVar
15 10 TestProxiedServerSearch
15 10 TestProxiedServerServeCount
15 10 TestProxiedServerShow
15 10 TestProxiedServerStatuses
15 10 TestProxiedServerUpdateWisp
34 11 TestProxiedServerBatchParity
34 11 TestProxiedServerCompactHistory
34 11 TestProxiedServerPour
34 11 TestProxiedServerQuery
34 11 TestProxiedServerReady
34 11 TestProxiedServerServeAddDependencies
15 11 TestProxiedServerDelete
15 11 TestProxiedServerDep
15 11 TestProxiedServerGateCheck
15 11 TestProxiedServerGateList
15 11 TestProxiedServerHeartbeat
15 11 TestProxiedServerMolProgress
15 11 TestProxiedServerPriority
15 11 TestProxiedServerPromote
15 11 TestProxiedServerServeCreate
15 11 TestProxiedServerSwarm
34 12 TestProxiedServerBlocked
34 12 TestProxiedServerChildren
34 12 TestProxiedServerCleanDatabases
34 12 TestProxiedServerReadyB
34 12 TestProxiedServerReadyWisp
34 12 TestProxiedServerReclaim
34 12 TestProxiedServerShowCommentsTail
34 12 TestProxiedServerUnclaim
15 12 TestProxiedServerDeleteBlockedJSONSingleDoc
15 12 TestProxiedServerHistory
15 12 TestProxiedServerKV
15 12 TestProxiedServerMolShow
15 12 TestProxiedServerQuery
15 12 TestProxiedServerQuick
15 12 TestProxiedServerServeDelete
15 12 TestProxiedServerShow2
15 12 TestProxiedServerTypes
15 12 TestProxiedServerUpdateClosePolicy
34 13 TestProxiedServerCompactDolt
34 13 TestProxiedServerCreate2
34 13 TestProxiedServerGraph
34 13 TestProxiedServerHistoryRemoteSupportedDirectParity
34 13 TestProxiedServerMolSquash
34 13 TestProxiedServerPromote
34 13 TestProxiedServerServeRefusesAStaleCheckpointWithGone
15 13 TestProxiedServerDeleteConcurrent
15 13 TestProxiedServerInfo
15 13 TestProxiedServerMolSquash
15 13 TestProxiedServerReadyClaimConcurrent
15 13 TestProxiedServerReadyWisp
15 13 TestProxiedServerServeEdgeCounts
15 13 TestProxiedServerShow3
15 13 TestProxiedServerStatus
15 13 TestProxiedServerUnclaim
15 13 TestProxiedServerWispGC
34 14 TestProxiedServerAssign
34 14 TestProxiedServerCloseB
34 14 TestProxiedServerDuplicates
34 14 TestProxiedServerHeartbeat
34 14 TestProxiedServerIfRevisionCloseReplaysMoleculeAutoClose
34 14 TestProxiedServerInitIfMissing
34 14 TestProxiedServerMolReadyGated
15 14 TestProxiedServerCleanDatabasesPurgeDropped
15 14 TestProxiedServerConfig
15 14 TestProxiedServerConfigSetMany
15 14 TestProxiedServerDeleteForceOrphans
15 14 TestProxiedServerImport
15 14 TestProxiedServerInitIfMissing
15 14 TestProxiedServerMolDistill
15 14 TestProxiedServerPrime
15 14 TestProxiedServerReadyConcurrent
15 14 TestProxiedServerServeLifecycle
15 14 TestProxiedServerUnclaimIfAssigneeParity
34 15 TestProxiedServerDepConcurrent
34 15 TestProxiedServerImport
34 15 TestProxiedServerMoleculeFrontDoorWriteParity
34 15 TestProxiedServerReopenConcurrent
34 15 TestProxiedServerSQL
34 16 TestProxiedServerBackupRefusedOnExternalTopology
34 16 TestProxiedServerCascadeParity
34 16 TestProxiedServerConfigSetMany
34 16 TestProxiedServerKV
34 16 TestProxiedServerServeCount
34 16 TestProxiedServerServeCreate
34 16 TestProxiedServerUpdateHooks
34 17 TestProxiedServerDep
34 17 TestProxiedServerMultiStatementSQL
34 17 TestProxiedServerOrphans
34 17 TestProxiedServerPrime
34 17 TestProxiedServerSQLDatabaseFlag
34 17 TestProxiedServerServeModeGate
34 17 TestServerModeServeIgnoresGraphModeDependency
34 18 TestProxiedServerClose3
34 18 TestProxiedServerCount
34 18 TestProxiedServerCountIncludeInfra
34 18 TestProxiedServerDoltRemoteRemove
34 18 TestProxiedServerMolShow
34 18 TestProxiedServerWispCreateRejectsEnumViolatingVar
34 19 TestProxiedServerCreate
34 19 TestProxiedServerMolCurrent
34 19 TestProxiedServerServeBatchClose
34 19 TestProxiedServerShow3
34 19 TestServerModeTypesAgreeWithCreate
34 20 TestProxiedServerDelete
34 20 TestProxiedServerLint
34 20 TestProxiedServerPriority
34 20 TestProxiedServerShow2B
34 20 TestProxiedServerWispGC
34 20 TestServerModeSharedServeGlobalReportsTheServedDatabase
34 21 TestProxiedServerBatchDepAddRefusesADottedChildGatedOnItsParent
34 21 TestProxiedServerConfig
34 21 TestProxiedServerExternalPolicyDirectParity
34 21 TestProxiedServerMoleculeFrontDoorDirectServerProxyParity
34 21 TestProxiedServerPathHelpers
34 21 TestProxiedServerPrune
34 21 TestProxiedServerServeClose
34 21 TestProxiedServerUnclaimIfAssigneeParity
34 22 TestProxiedServerGateCreateInheritsRepoMetadata
34 22 TestProxiedServerRecomputeBlocked
34 22 TestProxiedServerServeEdgeCounts
34 22 TestProxiedServerTag
34 22 TestProxiedServerUpdateB
34 22 TestProxiedServerUpdateConcurrentMetadata
34 23 TestProxiedServerDep2B
34 23 TestProxiedServerIfRevisionGuardUpdate
34 23 TestProxiedServerListWatchCountsTheOffsetIntoMaxRows
34 23 TestProxiedServerMolBurn
34 23 TestProxiedServerSearchRoutesAgree
34 23 TestProxiedServerServeUpdate
34 23 TestProxiedServerUpdateConcurrentClaim
34 23 TestProxiedServerUpdateWisp
34 24 TestProxiedServerDeleteBlockedJSONSingleDoc
34 24 TestProxiedServerDeleteForceOrphans
34 24 TestProxiedServerHuman
34 24 TestProxiedServerIfRevisionDeleteMatchAndMismatch
34 24 TestProxiedServerIfRevisionGuardAssign
34 24 TestProxiedServerListComments
34 24 TestProxiedServerListSortRetiresTheWalk
34 24 TestProxiedServerShowWatch
34 24 TestProxiedServerUpdateIfGuards
34 25 TestProxiedServerInitExplicitBeadsDirIsAuthoritative
34 25 TestProxiedServerSetState
34 25 TestProxiedServerShow
34 25 TestProxiedServerShowB
34 25 TestProxiedServerStale
34 25 TestProxiedServerWispCreate
34 26 TestProxiedServerDeferAutoWake
34 26 TestProxiedServerExternalMutationPolicy
34 26 TestProxiedServerReopenB
34 26 TestProxiedServerSearch
34 26 TestProxiedServerServeClaim
34 26 TestProxiedServerShow3B
34 27 TestProxiedServerDeferUndefer
34 27 TestProxiedServerGatedRendering
34 27 TestProxiedServerHistory
34 27 TestProxiedServerLabel
34 27 TestProxiedServerLabelB
34 27 TestProxiedServerUpdateClosePolicy
34 28 TestProxiedServerDep2C
34 28 TestProxiedServerDoltLifecycle
34 28 TestProxiedServerIfRevisionCloseWarnsOnForcedOpenChildren
34 28 TestProxiedServerReady2
34 28 TestProxiedServerReassignFence
34 28 TestProxiedServerSQLStatementRouting
34 28 TestProxiedServerServeClaimNext
34 28 TestProxiedServerUpdateConcurrentAppendNotes
34 29 TestProxiedServerGateFrontDoorDirectServerProxyParity
34 29 TestProxiedServerMolDistill
34 29 TestProxiedServerReopen
34 29 TestProxiedServerServeDelete
34 29 TestProxiedServerState
34 30 TestProxiedServerDeleteConcurrent
34 30 TestProxiedServerReadyC
34 30 TestProxiedServerServeAddComment
34 30 TestProxiedServerStatus
34 30 TestProxiedServerTodo
34 30 TestProxiedServerUpdate2
34 30 TestProxiedServerVersionedHistoryServeActivatesTheProviderFromItsOwnRow
34 31 TestProxiedServerCloseBeadGate
34 31 TestProxiedServerComment
34 31 TestProxiedServerConfigB
34 31 TestProxiedServerEventsJournal
34 31 TestProxiedServerGateAddWaiterConvoy
34 31 TestProxiedServerIfRevisionGuardClose
34 31 TestProxiedServerMolBond
34 32 TestProxiedServerCleanDatabasesPurgeDropped
34 32 TestProxiedServerConfigConcurrent
34 32 TestProxiedServerDepB
34 32 TestProxiedServerServeStreamsTheJournalItIsWriting
34 32 TestProxiedServerServeUpdateClaim
34 32 TestProxiedServerStorageClass
34 33 TestProxiedServerBatchDefersThenDoltCommitAdvancesHeadOnce
34 33 TestProxiedServerClose
34 33 TestProxiedServerGC
34 33 TestProxiedServerMemory
34 33 TestProxiedServerPourRejectsEnumViolatingVar
34 33 TestProxiedServerRelate
34 34 TestProxiedServerClose4
34 34 TestProxiedServerCreate2C
34 34 TestProxiedServerEdit
34 34 TestProxiedServerEpic
34 34 TestProxiedServerLink
34 34 TestProxiedServerServeReadRevision
15 15 TestProxiedServerCloseConcurrent
15 15 TestProxiedServerDeleteWisp
15 15 TestProxiedServerEpic
15 15 TestProxiedServerHuman
15 15 TestProxiedServerLint
15 15 TestProxiedServerMolCurrent
15 15 TestProxiedServerReclaim
15 15 TestProxiedServerServeModeGate
15 15 TestProxiedServerTodo
15 15 TestProxiedServerUpdate3
15 15 TestProxiedServerUpdateConcurrentAppendNotes

View file

@ -1,17 +0,0 @@
# Every bazel.yml lane's loading and analysis, for the remote repo contents
# cache: rrc-seed runs each line with --nobuild on a push to main (uploading
# the repositories it fetches) and rrc-verify runs each cold every night.
# One `bazel` command per line (no shell quoting); # starts a comment.
# scripts/bazel_rrc_test.go checks that every --config a reading lane's
# bazel command uses appears here.
test //... --config=ci
test //... --config=embedded
test //... --config=integration
test //... --config=doltserver
test //... --config=doltserver-proxied
test //... --config=dolt-race
test //... --config=doltserver-integration
test //... --config=doltserver-cmd
test //... --config=dolt-int
build --config=pure //cmd/bd:bd //cmd/bd:bd_test //internal/storage/embeddeddolt:embeddeddolt_test //internal/tracker:tracker_test
build --config=js-wasm //internal/hooks:hooks_test

View file

@ -1,51 +0,0 @@
#!/usr/bin/env bash
# Loading and analysis of every bazel.yml lane, for the remote repo contents
# cache (bazel.yml's rrc-seed and rrc-verify jobs).
#
# Usage: rrc-run-lanes.sh [STARTUP_FLAG...] -- [COMMAND_FLAG...]
#
# Runs `bazel STARTUP_FLAG... <line> --nobuild COMMAND_FLAG...` for each
# command line in .github/scripts/rrc-lane-commands.txt (or RRC_LANE_COMMANDS),
# in order, stopping at the first failure. --nobuild: repository rules,
# loading and analysis only, never a build or test action.
#
# Bazel exits 1 after `test --nobuild` even when loading and analysis succeed
# ("Couldn't start the build. Unable to run tests"). A command passes when it
# exits 0, or exits non-zero having printed "Build completed successfully"
# and no ERROR line but that one.
set -euo pipefail
startup=()
while [ $# -gt 0 ] && [ "$1" != -- ]; do
startup+=("$1")
shift
done
[ $# -gt 0 ] || {
echo "usage: rrc-run-lanes.sh [STARTUP_FLAG...] -- [COMMAND_FLAG...]" >&2
exit 2
}
shift
flags=("$@")
file=${RRC_LANE_COMMANDS:-$(dirname "${BASH_SOURCE[0]}")/rrc-lane-commands.txt}
mapfile -t cmds < <(sed -e 's/#.*//' -e 's/[[:space:]]*$//' "$file" | grep -v '^[[:space:]]*$' || true)
if [ "${#cmds[@]}" -eq 0 ]; then
echo "::error::no lane commands in $file"
exit 1
fi
log=$(mktemp)
trap 'rm -f "$log"' EXIT
summary=${GITHUB_STEP_SUMMARY:-/dev/null}
for cmd in "${cmds[@]}"; do
read -r -a args <<<"$cmd"
start=$(date +%s)
rc=0
bazel ${startup[@]+"${startup[@]}"} "${args[@]}" --nobuild ${flags[@]+"${flags[@]}"} </dev/null 2>&1 | tee "$log" || rc=$?
if [ "$rc" -ne 0 ] && grep -q '^INFO: Build completed successfully' "$log" &&
! grep '^ERROR:' "$log" | grep -qv "^ERROR: Couldn't start the build. Unable to run tests$"; then
rc=0
fi
echo "rrc: \`bazel $cmd\`: exit $rc, $(($(date +%s) - start))s" | tee -a "$summary"
[ "$rc" -eq 0 ] || exit "$rc"
done

View file

@ -1,113 +0,0 @@
#!/usr/bin/env bash
# A 30-minute rbe-west client certificate for the remote repo contents cache
# writer (bazel.yml's rrc-seed job; engdocs/design/bazel-remote-repo-contents-cache.md).
#
# The job trades its GitHub Actions OIDC token (audience rbe-rrc-writer) for a
# certificate CN=rbe-rrc-writer from rbe-west's mint. The mint signs only for
# this repository's bazel.yml on a push to main (repository, ref, event_name
# and job_workflow_ref claims); pull_request, fork and Dependabot runs cannot
# get one (no OIDC token, or a refs/pull/N/merge one). On rbe-west that
# certificate reaches only GetCapabilities, the CAS and an action cache front
# (rrc-gate) that admits repo-contents entries and refuses everything else, so
# it can never write an execution result or execute anything.
#
# The key is an EC P-256 key (PKCS#8: Bazel's Netty TLS refuses a SEC1 "EC
# PRIVATE KEY") generated here in BAZEL_CI_SECRET_DIR, outside the workspace;
# it never leaves the runner. The OIDC token is masked. Outputs (to
# $GITHUB_OUTPUT when set, else stdout): cert, key, endpoint, instance; none
# when the mint answers 503 or cannot be reached (seeding switched off on
# rbe-west: infra nativelink-cas/west/README.md "Client contract"), which
# exits 0 with a warning.
#
# Tests only: RBE_RRC_MINT (a stand-in mint) and RBE_RRC_ENDPOINT_RE.
set -euo pipefail
MINT=${RBE_RRC_MINT:-https://rbe-mint.ops.gascity.com:8444}
ENDPOINT_RE=${RBE_RRC_ENDPOINT_RE:-'^grpcs://rbe-west\.ops\.gascity\.com(:443)?$'}
AUDIENCE=rbe-rrc-writer
dir=${BAZEL_CI_SECRET_DIR:?BAZEL_CI_SECRET_DIR is required}
out=${GITHUB_OUTPUT:-/dev/stdout}
if [ -z "${ACTIONS_ID_TOKEN_REQUEST_URL:-}" ] || [ -z "${ACTIONS_ID_TOKEN_REQUEST_TOKEN:-}" ]; then
echo "::error title=rrc writer::no OIDC token request URL; the job needs permissions: id-token: write" >&2
exit 1
fi
install -d -m 0700 "$dir"
umask 077
oidc=$(curl -sS --fail --connect-timeout 5 --max-time 30 --retry 3 --retry-all-errors \
-H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
"$ACTIONS_ID_TOKEN_REQUEST_URL&audience=$AUDIENCE" | jq -r '.value // empty')
if [ -z "$oidc" ]; then
echo "::error title=rrc writer::GitHub returned no OIDC token" >&2
exit 1
fi
printf '::add-mask::%s\n' "$oidc"
openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out "$dir/rrc-writer.key" 2>/dev/null
csr=$(openssl req -new -key "$dir/rrc-writer.key" -subj "/CN=rbe-rrc-writer-request")
body=$(jq -cn --arg csr "$csr" '{csr_pem: $csr}')
reply="$dir/rrc-mint.json"
code=000
for attempt in 1 2 3 4; do
# --connect-timeout: a closed gate drops the SYN; fail fast, not in 60 s.
code=$(curl -sS -o "$reply" -w '%{http_code}' --connect-timeout 5 --max-time 60 \
-H "Authorization: Bearer $oidc" -H 'content-type: application/json' \
--data "$body" "$MINT/v1/rrc-writer/cert") || code=000
# Retry what may pass on its own: a rate limit (429), the mint could not
# reach GitHub's JWKS (502), or the network (000). Everything else is an
# answer.
case "$code" in 429 | 502 | 000) ;; *) break ;; esac
[ "$attempt" -eq 4 ] || sleep $((attempt * 10))
done
case "$code" in
200) ;;
503 | 000)
# The mint's switch is off, its CA is not installed, or rbe-west's fork
# edge is closed: seeding is off, not broken. No outputs, so the seed
# step skips; the push to main never fails on it.
echo "::warning title=rrc writer: seeding off (HTTP $code)::$(jq -r '.error // empty' "$reply" 2>/dev/null || true)"
exit 0
;;
*)
echo "::error title=rrc writer mint refused (HTTP $code)::$(jq -r '.error // empty' "$reply" 2>/dev/null || true)"
exit 1
;;
esac
endpoint=$(jq -r '.endpoint // empty' "$reply")
instance=$(jq -r '.instance // empty' "$reply")
[[ $endpoint =~ $ENDPOINT_RE ]] || {
echo "::error::rrc writer mint returned endpoint '$endpoint'" >&2
exit 1
}
[ "$instance" = oss ] || {
echo "::error::rrc writer mint returned instance '$instance', want oss" >&2
exit 1
}
jq -r '.cert_pem // empty' "$reply" >"$dir/rrc-writer.crt"
subject=$(openssl x509 -in "$dir/rrc-writer.crt" -noout -subject -nameopt RFC2253) || {
echo "::error::rrc writer mint returned no certificate" >&2
exit 1
}
rdns=$(tr ',' '\n' <<<"${subject#subject=}")
cn=$(sed -n 's/^CN=//p' <<<"$rdns")
org=$(sed -n 's/^O=//p' <<<"$rdns")
if ! [[ $cn =~ ^rbe-rrc-writer(-[a-z0-9]+)?$ ]] || [ "$org" != gascity ]; then
echo "::error::rrc writer mint returned a certificate for '$subject'" >&2
exit 1
fi
# The certificate must belong to the key generated above.
if [ "$(openssl x509 -in "$dir/rrc-writer.crt" -noout -pubkey | openssl sha256)" != "$(openssl pkey -in "$dir/rrc-writer.key" -pubout | openssl sha256)" ]; then
echo "::error::rrc writer mint returned a certificate for another key" >&2
exit 1
fi
openssl x509 -in "$dir/rrc-writer.crt" -noout -subject -enddate
rm -f "$reply"
{
echo "cert=$dir/rrc-writer.crt"
echo "key=$dir/rrc-writer.key"
echo "endpoint=$endpoint"
echo "instance=$instance"
} >>"$out"

View file

@ -40,20 +40,15 @@
# the disk) and re-checked once staged (scripts/bazel-autofix-push.sh), so a
# hostile patch can at most rewrite BUILD.bazel / MODULE.bazel /
# MODULE.bazel.lock on its own PR branch. Pushes are leased to the run's head
# SHA and skipped for heads that are protected or under a ruleset. The App
# private key is a secret of the `autofix` environment, whose deployment-
# branch policy allows only `main`, so only a job running on main can read
# it; the minted token itself is scoped to this one repo with contents:write
# only, so even a hostile patch gains nothing beyond what the job already
# had.
# SHA and skipped for heads that are protected or under a ruleset.
#
# TOKEN NOTE: pushes made with the default GITHUB_TOKEN do not retrigger PR
# checks. On same-repo PRs the push step mints a short-lived installation
# token for the gastownhall-autofix GitHub App (contents:write, scoped to
# this repo only) and uses that instead. Fork PRs always get the apply-recipe
# comment - no token we hold can push to a fork, so the mint step is skipped
# for them. workflow_run always runs this file from the default branch, so
# edits take effect only after they merge.
# checks. This reuses the DOCS_AUTOFIX_TOKEN repo secret (fine-grained PAT or
# GitHub App token with contents:write on this repo) rather than adding a
# second one; without it the pushed fix still lands but checks need a manual
# re-run. Fork PRs always get the apply-recipe comment - no token we hold can
# push to a fork. workflow_run always runs this file from the default branch,
# so edits take effect only after they merge.
name: Bazel Autofix
@ -75,10 +70,6 @@ jobs:
github.event.workflow_run.conclusion == 'failure'
runs-on: ubuntu-latest
timeout-minutes: 10
# Grants the job read access to this environment's secrets; its
# deployment-branch policy restricts that to jobs running on main
# (workflow_run always does), not to any PR branch.
environment: autofix
# Shared with docs-autofix.yml; queue, never cancel (see header).
concurrency:
group: autofix-${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}
@ -123,22 +114,6 @@ jobs:
fi
echo "found=true" >> "$GITHUB_OUTPUT"
# Same-repo PRs only: no token we hold can push to a fork, and a fork's
# head_repository can even be absent (deleted fork), so this mints
# nothing for it and the push script falls back to the apply-recipe
# comment. app-token outputs are empty (not failed) when the step is
# skipped, which is what the fallback below relies on.
- name: Mint autofix app token
id: app-token
if: github.event.workflow_run.head_repository.full_name == github.repository
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3
with:
app-id: ${{ secrets.AUTOFIX_APP_ID }}
private-key: ${{ secrets.AUTOFIX_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: ${{ github.event.repository.name }}
permission-contents: write
- name: Push sync commit or leave apply recipe
if: steps.patch.outputs.found == 'true'
env:
@ -152,9 +127,9 @@ jobs:
RUN_URL: ${{ github.event.workflow_run.html_url }}
# Split tokens: gh api calls (PR lookup, comments) always use the
# workflow token, which carries this job's pull-requests:write; the
# App token is used ONLY for the git push, so it needs no more
# optional PAT is used ONLY for the git push, so it needs no more
# than contents:write.
GH_TOKEN: ${{ github.token }}
PUSH_TOKEN: ${{ steps.app-token.outputs.token || github.token }}
AUTOFIX_TOKEN_KIND: ${{ steps.app-token.outputs.token && 'app' || 'default' }}
PUSH_TOKEN: ${{ secrets.DOCS_AUTOFIX_TOKEN || github.token }}
AUTOFIX_TOKEN_KIND: ${{ secrets.DOCS_AUTOFIX_TOKEN && 'pat' || 'default' }}
run: ./scripts/bazel-autofix-push.sh

View file

@ -1,9 +1,8 @@
# Bazel lanes on the remote-execution farm for fork PRs by trusted authors.
#
# Fork PRs get no Actions secrets, so pr.yml's Bazel call runs them locally
# with rbe-west's anonymous read-only cache (mode cache: no embedded,
# proxied-server or server-storage tier). This workflow gives the farm to
# fork PRs whose
# with rbe-west's anonymous read-only cache (mode cache, no remote-only
# lanes). This workflow gives the farm to fork PRs whose
# author AND triggering user are on .github/bazel-farm-allowlist.txt (by
# numeric user id), by calling bazel.yml from pull_request_target, which has
# the secrets.
@ -11,8 +10,8 @@
# ADVISORY. pr.yml is unchanged: every fork PR, listed or not, still runs the
# cache-mode Bazel lanes (local execution, read-only cache) inside the
# enforced `CI Gate / Required`. This run adds a fast remote signal,
# including the remote-only embedded, proxied-server and server-storage
# tiers, that no required check and no privileged workflow
# including the remote-only embedded, integration, proxied-server and
# server-storage tiers, that no required check and no privileged workflow
# reads. Making it authoritative needs a trusted reporter; see
# engdocs/CI_REQUIRED_CHECK_TOPOLOGY.md, "Trusted-author fork PRs".
#
@ -120,27 +119,9 @@ jobs:
name: Bazel Farm
needs: authorize
if: ${{ needs.authorize.outputs.allowed == 'true' }}
# A called workflow's job gets at most this call's token permissions, and
# GitHub checks them when the run starts, even for a job whose if: skips
# it (startup_failure otherwise; gascity #7478): bazel.yml's rrc-seed asks
# id-token: write (push to main only) and rrc-verify issues: write
# (schedule and dispatch only). Neither runs for this event, every other
# bazel.yml job keeps contents: read, and rbe-west's mint refuses any OIDC
# token but a main-push bazel.yml one
# (scripts/bazel_rrc_test.go, TestBazelWorkflowCallersGrantEveryRequestedPermission).
permissions:
contents: read
id-token: write
issues: write
uses: ./.github/workflows/bazel.yml
# Exactly the four RBE secrets: never the rbe-prewarm app private key
# (B1, security review of bdef342d5). This pull_request_target run is
# the one caller whose code under test is an untrusted fork's, so it
# must never carry the credential that mints gastownhall/gascity
# Actions tokens; pre-warming is accepted as a same-repo-only benefit
# (bazel.yml's rbe-prewarm job also gates on mode remote only, which a
# fork-authorized farm run never reaches). See "rbe-west Pre-warm",
# engdocs/CI_REQUIRED_CHECK_TOPOLOGY.md.
secrets:
RBE_WEST_EXECUTOR: ${{ secrets.RBE_WEST_EXECUTOR }}
RBE_TLS_CERT: ${{ secrets.RBE_TLS_CERT }}

File diff suppressed because it is too large Load diff

765
.github/workflows/ci-measurements.yml vendored Normal file
View file

@ -0,0 +1,765 @@
name: CI Measurements
on:
workflow_call:
inputs:
suite:
description: "Suite to measure"
required: true
type: string
smoke_version:
description: "Optional previous release for cross-version-smoke"
required: false
type: string
default: ""
workflow_dispatch:
inputs:
suite:
description: "Suite to measure"
required: true
type: choice
default: pr-linux
options:
- pr-linux
- macos-short
- macos-candidates
- linux-integration
- linux-integration-sharded
- linux-integration-hybrid-sharded
- linux-integration-hybrid-16-sharded
- linux-integration-hybrid-prebuilt-sharded
- linux-integration-coverage
- cross-version-smoke
- nix
- mcp-package
- npm-package
smoke_version:
description: "Optional previous release for cross-version-smoke"
required: false
default: ""
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.suite }}
cancel-in-progress: false
env:
BD_DISABLE_METRICS: "1"
BD_DISABLE_EVENT_FLUSH: "1"
jobs:
pr-linux:
name: Measure PR Linux commands
if: ${{ inputs.suite == 'pr-linux' }}
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
- name: Install Dolt
run: ./scripts/ci/install-dolt.sh
- name: Configure Git and Dolt identity
run: |
git config --global user.name "CI Bot"
git config --global user.email "ci@beads.test"
dolt config --global --add user.name "CI Bot"
dolt config --global --add user.email "ci@beads.test"
- name: Measure commands
run: |
set -euo pipefail
mkdir -p artifacts
source scripts/ci/lib/timing.sh
source ./.buildflags
ci_time "install gotestsum" -- go install gotest.tools/gotestsum@v1.13.0
ci_time "install golangci-lint" -- go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.10.1
status=0
ci_time "pr-policy wrapper" -- make ci-pr-policy || status=$?
# -timeout=30m keeps this in step with the lane it measures
# (scripts/ci/pr-core.sh). Without it ./cmd/bd can die on `go test`'s
# 10m default and the measurement reports a panic instead of a duration.
ci_time "pr-core gotestsum" -- gotestsum --junitfile artifacts/pr-core-junit.xml --format testdox -- -race -short -timeout=30m -skip '^TestEmbedded' ./... || status=$?
ci_time "pr-lint wrapper" -- make ci-pr-lint || status=$?
exit "$status"
- name: Upload measurement artifacts
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: ci-measure-pr-linux
path: artifacts/
retention-days: 7
if-no-files-found: ignore
macos-short:
name: Measure macOS short Go tests
if: ${{ inputs.suite == 'macos-short' }}
runs-on: macos-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
- name: Install Dolt
run: ./scripts/ci/install-dolt.sh
- name: Configure Git and Dolt identity
run: |
git config --global user.name "CI Bot"
git config --global user.email "ci@beads.test"
dolt config --global --add user.name "CI Bot"
dolt config --global --add user.email "ci@beads.test"
- name: Measure commands
run: |
set -euo pipefail
source scripts/ci/lib/timing.sh
source ./.buildflags
# -timeout=30m matches the macOS lanes this measures (pr.yml, main.yml).
# This is the job that produced the ./cmd/bd duration distribution, and
# at 10m it clips its own longest samples into timeout panics.
ci_time "macos short go test" -- go test -tags=gms_pure_go -v -race -short -timeout=30m -skip '^TestEmbedded' ./...
macos-candidates:
name: Measure macOS no-short candidates
if: ${{ inputs.suite == 'macos-candidates' }}
runs-on: macos-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
- name: Install Dolt
run: ./scripts/ci/install-dolt.sh
- name: Configure Git and Dolt identity
run: |
git config --global user.name "CI Bot"
git config --global user.email "ci@beads.test"
dolt config --global --add user.name "CI Bot"
dolt config --global --add user.email "ci@beads.test"
- name: Measure commands
run: |
set -euo pipefail
source scripts/ci/lib/timing.sh
status=0
ci_time "macos no-short go test" -- go test -tags=gms_pure_go -v -race -timeout=30m -skip '^TestEmbedded' ./... || status=$?
ci_time "macos integration go test" -- go test -tags=integration,gms_pure_go -v -race -timeout=30m -skip '^TestEmbedded' ./... || status=$?
exit "$status"
linux-integration:
name: Measure Linux integration tests
if: ${{ inputs.suite == 'linux-integration' }}
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
- name: Install Dolt
run: ./scripts/ci/install-dolt.sh
- name: Configure Git and Dolt identity
run: |
git config --global user.name "CI Bot"
git config --global user.email "ci@beads.test"
dolt config --global --add user.name "CI Bot"
dolt config --global --add user.email "ci@beads.test"
- name: Measure commands
run: |
set -euo pipefail
mkdir -p artifacts
source scripts/ci/lib/timing.sh
ci_time "install gotestsum" -- go install gotest.tools/gotestsum@v1.13.0
ci_time "linux integration go test" -- env BEADS_TEST_SKIP=dolt gotestsum --junitfile artifacts/linux-integration-junit.xml --format testdox -- -v -race -tags=integration,gms_pure_go -timeout=30m ./...
- name: Upload measurement artifacts
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: ci-measure-linux-integration
path: artifacts/
retention-days: 7
if-no-files-found: ignore
linux-integration-sharded:
name: Measure Linux integration shard ${{ matrix.shard }}/6
if: ${{ inputs.suite == 'linux-integration-sharded' }}
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3, 4, 5, 6]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
- name: Install Dolt
run: ./scripts/ci/install-dolt.sh
- name: Configure Git and Dolt identity
run: |
git config --global user.name "CI Bot"
git config --global user.email "ci@beads.test"
dolt config --global --add user.name "CI Bot"
dolt config --global --add user.email "ci@beads.test"
- name: Measure shard
env:
SHARD: ${{ matrix.shard }}
TOTAL_SHARDS: 6
run: |
set -euo pipefail
mkdir -p artifacts
source scripts/ci/lib/timing.sh
ci_time "install gotestsum" -- go install gotest.tools/gotestsum@v1.13.0
mapfile -t packages < <(
GO_TEST_SHARD_TAGS=integration,gms_pure_go \
scripts/ci/go-test-shard-packages.sh "$SHARD" "$TOTAL_SHARDS"
)
package_manifest="artifacts/linux-integration-packages-${SHARD}-of-${TOTAL_SHARDS}.txt"
printf '%s\n' "${packages[@]}" | tee "$package_manifest"
if [[ "${#packages[@]}" -eq 0 ]]; then
echo "No packages assigned to shard ${SHARD}/${TOTAL_SHARDS}; skipping go test"
exit 0
fi
ci_time "linux integration shard ${SHARD}/${TOTAL_SHARDS} go test" -- \
env BEADS_TEST_SKIP=dolt gotestsum \
--junitfile "artifacts/linux-integration-shard-${SHARD}-of-${TOTAL_SHARDS}.xml" \
--format testdox \
-- -v -race -tags=integration,gms_pure_go -timeout=30m "${packages[@]}"
- name: Upload measurement artifacts
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: ci-measure-linux-integration-shard-${{ matrix.shard }}-of-6
path: artifacts/
retention-days: 7
if-no-files-found: ignore
linux-integration-hybrid-packages:
name: Measure Linux integration package shard ${{ matrix.shard }}/6 (no cmd/bd)
if: ${{ inputs.suite == 'linux-integration-hybrid-sharded' || inputs.suite == 'linux-integration-hybrid-16-sharded' || inputs.suite == 'linux-integration-hybrid-prebuilt-sharded' }}
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3, 4, 5, 6]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
- name: Install Dolt
run: ./scripts/ci/install-dolt.sh
- name: Configure Git and Dolt identity
run: |
git config --global user.name "CI Bot"
git config --global user.email "ci@beads.test"
dolt config --global --add user.name "CI Bot"
dolt config --global --add user.email "ci@beads.test"
- name: Measure shard
env:
SHARD: ${{ matrix.shard }}
TOTAL_SHARDS: 6
run: |
set -euo pipefail
mkdir -p artifacts
source scripts/ci/lib/timing.sh
ci_time "install gotestsum" -- go install gotest.tools/gotestsum@v1.13.0
package_manifest="artifacts/linux-integration-hybrid-packages-${SHARD}-of-${TOTAL_SHARDS}.txt"
write_package_manifest() {
GO_TEST_SHARD_TAGS=integration,gms_pure_go \
GO_TEST_SHARD_EXCLUDE_REGEX="^github.com/steveyegge/beads/cmd/bd$" \
scripts/ci/go-test-shard-packages.sh "$SHARD" "$TOTAL_SHARDS" > "$package_manifest"
}
ci_time "list integration package shard ${SHARD}/${TOTAL_SHARDS}" -- write_package_manifest
cat "$package_manifest"
mapfile -t packages < "$package_manifest"
if [[ "${#packages[@]}" -eq 0 ]]; then
echo "No packages assigned to shard ${SHARD}/${TOTAL_SHARDS}; skipping go test"
exit 0
fi
ci_time "linux integration package shard ${SHARD}/${TOTAL_SHARDS} go test" -- \
env BEADS_TEST_SKIP=dolt gotestsum \
--junitfile "artifacts/linux-integration-hybrid-packages-${SHARD}-of-${TOTAL_SHARDS}.xml" \
--format testdox \
-- -v -race -tags=integration,gms_pure_go -timeout=30m "${packages[@]}"
- name: Upload measurement artifacts
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: ci-measure-linux-integration-hybrid-packages-${{ matrix.shard }}-of-6
path: artifacts/
retention-days: 7
if-no-files-found: ignore
linux-integration-hybrid-cmd-bd:
name: Measure Linux integration cmd/bd shard ${{ matrix.shard }}/8
if: ${{ inputs.suite == 'linux-integration-hybrid-sharded' }}
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3, 4, 5, 6, 7, 8]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
- name: Install Dolt
run: ./scripts/ci/install-dolt.sh
- name: Configure Git and Dolt identity
run: |
git config --global user.name "CI Bot"
git config --global user.email "ci@beads.test"
dolt config --global --add user.name "CI Bot"
dolt config --global --add user.email "ci@beads.test"
- name: Measure shard
env:
SHARD: ${{ matrix.shard }}
TOTAL_SHARDS: 8
run: |
set -euo pipefail
mkdir -p artifacts
source scripts/ci/lib/timing.sh
ci_time "install gotestsum" -- go install gotest.tools/gotestsum@v1.13.0
test_manifest="artifacts/linux-integration-cmd-bd-tests-${SHARD}-of-${TOTAL_SHARDS}.txt"
write_test_manifest() {
GO_TEST_SHARD_TAGS=integration,gms_pure_go \
scripts/ci/go-test-shard-names.sh "$SHARD" "$TOTAL_SHARDS" ./cmd/bd > "$test_manifest"
}
ci_time "list cmd/bd test shard ${SHARD}/${TOTAL_SHARDS}" -- write_test_manifest
cat "$test_manifest"
mapfile -t tests < "$test_manifest"
if [[ "${#tests[@]}" -eq 0 ]]; then
echo "No tests assigned to shard ${SHARD}/${TOTAL_SHARDS}; skipping go test"
exit 0
fi
run_regex="^($(IFS='|'; echo "${tests[*]}"))$"
ci_time "linux integration cmd/bd shard ${SHARD}/${TOTAL_SHARDS} go test" -- \
env BEADS_TEST_SKIP=dolt gotestsum \
--junitfile "artifacts/linux-integration-cmd-bd-${SHARD}-of-${TOTAL_SHARDS}.xml" \
--format testdox \
-- -v -race -tags=integration,gms_pure_go -timeout=30m -run "$run_regex" ./cmd/bd
- name: Upload measurement artifacts
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: ci-measure-linux-integration-cmd-bd-${{ matrix.shard }}-of-8
path: artifacts/
retention-days: 7
if-no-files-found: ignore
linux-integration-hybrid-16-cmd-bd:
name: Measure Linux integration cmd/bd shard ${{ matrix.shard }}/16
if: ${{ inputs.suite == 'linux-integration-hybrid-16-sharded' }}
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
- name: Install Dolt
run: ./scripts/ci/install-dolt.sh
- name: Configure Git and Dolt identity
run: |
git config --global user.name "CI Bot"
git config --global user.email "ci@beads.test"
dolt config --global --add user.name "CI Bot"
dolt config --global --add user.email "ci@beads.test"
- name: Measure shard
env:
SHARD: ${{ matrix.shard }}
TOTAL_SHARDS: 16
run: |
set -euo pipefail
mkdir -p artifacts
source scripts/ci/lib/timing.sh
ci_time "install gotestsum" -- go install gotest.tools/gotestsum@v1.13.0
test_manifest="artifacts/linux-integration-cmd-bd-tests-${SHARD}-of-${TOTAL_SHARDS}.txt"
write_test_manifest() {
GO_TEST_SHARD_TAGS=integration,gms_pure_go \
scripts/ci/go-test-shard-names.sh "$SHARD" "$TOTAL_SHARDS" ./cmd/bd > "$test_manifest"
}
ci_time "list cmd/bd test shard ${SHARD}/${TOTAL_SHARDS}" -- write_test_manifest
cat "$test_manifest"
mapfile -t tests < "$test_manifest"
if [[ "${#tests[@]}" -eq 0 ]]; then
echo "No tests assigned to shard ${SHARD}/${TOTAL_SHARDS}; skipping go test"
exit 0
fi
run_regex="^($(IFS='|'; echo "${tests[*]}"))$"
ci_time "linux integration cmd/bd shard ${SHARD}/${TOTAL_SHARDS} go test" -- \
env BEADS_TEST_SKIP=dolt gotestsum \
--junitfile "artifacts/linux-integration-cmd-bd-${SHARD}-of-${TOTAL_SHARDS}.xml" \
--format testdox \
-- -v -race -tags=integration,gms_pure_go -timeout=30m -run "$run_regex" ./cmd/bd
- name: Upload measurement artifacts
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: ci-measure-linux-integration-cmd-bd-${{ matrix.shard }}-of-16
path: artifacts/
retention-days: 7
if-no-files-found: ignore
linux-integration-hybrid-prebuilt-bd:
name: Measure Linux integration prebuild cmd/bd binary
if: ${{ inputs.suite == 'linux-integration-hybrid-prebuilt-sharded' }}
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
- name: Measure build
run: |
set -euo pipefail
mkdir -p artifacts
source scripts/ci/lib/timing.sh
source ./.buildflags
ci_time "build cmd/bd subprocess binary" -- go build -tags gms_pure_go -o artifacts/bd ./cmd/bd
- name: Upload prebuilt bd
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: ci-measure-linux-integration-prebuilt-bd
path: artifacts/bd
retention-days: 7
if-no-files-found: error
linux-integration-hybrid-prebuilt-cmd-bd:
name: Measure Linux integration prebuilt cmd/bd shard ${{ matrix.shard }}/8
if: ${{ inputs.suite == 'linux-integration-hybrid-prebuilt-sharded' }}
needs: linux-integration-hybrid-prebuilt-bd
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3, 4, 5, 6, 7, 8]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
- name: Download prebuilt bd
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: ci-measure-linux-integration-prebuilt-bd
path: prebuilt-bd
- name: Install Dolt
run: ./scripts/ci/install-dolt.sh
- name: Configure Git and Dolt identity
run: |
git config --global user.name "CI Bot"
git config --global user.email "ci@beads.test"
dolt config --global --add user.name "CI Bot"
dolt config --global --add user.email "ci@beads.test"
- name: Measure shard
env:
SHARD: ${{ matrix.shard }}
TOTAL_SHARDS: 8
BEADS_TEST_BD_BINARY: ${{ github.workspace }}/prebuilt-bd/bd
run: |
set -euo pipefail
mkdir -p artifacts
chmod +x "$BEADS_TEST_BD_BINARY"
source scripts/ci/lib/timing.sh
ci_time "install gotestsum" -- go install gotest.tools/gotestsum@v1.13.0
test_manifest="artifacts/linux-integration-cmd-bd-tests-${SHARD}-of-${TOTAL_SHARDS}.txt"
write_test_manifest() {
GO_TEST_SHARD_TAGS=integration,gms_pure_go \
scripts/ci/go-test-shard-names.sh "$SHARD" "$TOTAL_SHARDS" ./cmd/bd > "$test_manifest"
}
ci_time "list cmd/bd test shard ${SHARD}/${TOTAL_SHARDS}" -- write_test_manifest
cat "$test_manifest"
mapfile -t tests < "$test_manifest"
if [[ "${#tests[@]}" -eq 0 ]]; then
echo "No tests assigned to shard ${SHARD}/${TOTAL_SHARDS}; skipping go test"
exit 0
fi
run_regex="^($(IFS='|'; echo "${tests[*]}"))$"
ci_time "linux integration prebuilt cmd/bd shard ${SHARD}/${TOTAL_SHARDS} go test" -- \
env BEADS_TEST_SKIP=dolt gotestsum \
--junitfile "artifacts/linux-integration-prebuilt-cmd-bd-${SHARD}-of-${TOTAL_SHARDS}.xml" \
--format testdox \
-- -v -race -tags=integration,gms_pure_go -timeout=30m -run "$run_regex" ./cmd/bd
- name: Upload measurement artifacts
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: ci-measure-linux-integration-prebuilt-cmd-bd-${{ matrix.shard }}-of-8
path: artifacts/
retention-days: 7
if-no-files-found: ignore
linux-integration-coverage:
name: Measure Linux integration coverage
if: ${{ inputs.suite == 'linux-integration-coverage' }}
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
- name: Install Dolt
run: ./scripts/ci/install-dolt.sh
- name: Configure Git and Dolt identity
run: |
git config --global user.name "CI Bot"
git config --global user.email "ci@beads.test"
dolt config --global --add user.name "CI Bot"
dolt config --global --add user.email "ci@beads.test"
- name: Measure commands
run: |
set -euo pipefail
mkdir -p artifacts
source scripts/ci/lib/timing.sh
ci_time "install gotestsum" -- go install gotest.tools/gotestsum@v1.13.0
status=0
ci_time "linux integration coverage go test" -- env BEADS_TEST_SKIP=dolt gotestsum --junitfile artifacts/linux-integration-coverage-junit.xml --format testdox -- -v -race -tags=integration,gms_pure_go -coverprofile=artifacts/coverage.out -timeout=30m ./... || status=$?
if [[ -f artifacts/coverage.out ]]; then
ci_time "coverage summary" -- go tool cover -func=artifacts/coverage.out || status=$?
else
echo "coverage.out was not generated; skipping coverage summary"
fi
exit "$status"
- name: Upload measurement artifacts
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: ci-measure-linux-integration-coverage
path: artifacts/
retention-days: 7
if-no-files-found: ignore
cross-version-smoke:
name: Measure cross-version smoke
if: ${{ inputs.suite == 'cross-version-smoke' }}
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
- name: Configure Git
run: |
git config --global user.name "CI Bot"
git config --global user.email "ci@beads.test"
- name: Cache previous release binaries
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v5
with:
path: ~/.cache/beads-regression
key: smoke-binaries-measure-${{ runner.os }}
- name: Measure commands
env:
GH_TOKEN: ${{ github.token }}
SMOKE_VERSION: ${{ inputs.smoke_version }}
run: |
set -euo pipefail
source scripts/ci/lib/timing.sh
source ./.buildflags
ci_time "build candidate binary" -- go build -tags gms_pure_go -o /tmp/bd-candidate ./cmd/bd
export CANDIDATE_BIN=/tmp/bd-candidate
if [[ -z "$SMOKE_VERSION" ]]; then
SMOKE_VERSION="$(gh release list --repo "$GITHUB_REPOSITORY" --limit 1 --json tagName --jq '.[0].tagName')"
fi
if [[ -z "$SMOKE_VERSION" ]]; then
echo "Could not resolve a previous release tag for cross-version smoke"
exit 1
fi
ci_time "upgrade smoke ${SMOKE_VERSION}" -- ./scripts/upgrade-smoke-test.sh "$SMOKE_VERSION"
nix:
name: Measure nix build
if: ${{ inputs.suite == 'nix' }}
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Install Nix
uses: DeterminateSystems/determinate-nix-action@527f17dd63d2d60d3e5552934bc84b9a33a14d11 # v3
- name: Measure commands
run: |
set -euo pipefail
source scripts/ci/lib/timing.sh
ci_time "nix build .#default" -- nix build .#default --print-build-logs
mcp-package:
name: Measure MCP package checks
if: ${{ inputs.suite == 'mcp-package' }}
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: '3.14'
- name: Measure commands
run: |
set -euo pipefail
source scripts/ci/lib/timing.sh
ci_time "install uv" -- pip install uv==0.11.16
ci_time "mcp package gate" -- make ci-package-mcp
- name: Upload measurement artifacts
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: ci-measure-mcp-package
path: integrations/beads-mcp/dist/
retention-days: 7
if-no-files-found: ignore
npm-package:
name: Measure npm package checks
if: ${{ inputs.suite == 'npm-package' }}
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
- name: Set up Node.js
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v6
with:
node-version: '24'
- name: Measure commands
run: |
set -euo pipefail
source scripts/ci/lib/timing.sh
ci_time "npm package gate" -- make ci-package-npm
- name: Upload measurement artifacts
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: ci-measure-npm-package
path: artifacts/
retention-days: 7
if-no-files-found: ignore

33
.github/workflows/conformance.yml vendored Normal file
View file

@ -0,0 +1,33 @@
name: Conformance
# Runs the same two-tier storage conformance suite developers run locally:
# the in-process store corpus and the real-binary CLI harness.
on:
pull_request:
branches: [ main, 'release/**' ]
merge_group:
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
BD_DISABLE_METRICS: "1"
BD_DISABLE_EVENT_FLUSH: "1"
jobs:
conformance:
name: Storage backend conformance (embedded Dolt oracle)
timeout-minutes: 45
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
- name: Run conformance (embedded Dolt oracle)
run: ./scripts/conformance.sh

View file

@ -0,0 +1,90 @@
name: Cross-Version Smoke Tests
on:
# On tag push (release gate): test the last 30 releases for broad regression coverage
push:
tags:
- 'v*'
# On PR to main or a release branch: test only the last 5 releases for fast
# feedback. Release-targeted PRs are exactly the ones where cross-version
# upgrade breakage is most expensive to discover at tag time.
pull_request:
branches: [ main, 'release/**' ]
# Allow manual trigger with custom version count
workflow_dispatch:
inputs:
version_count:
description: 'Number of previous releases to test against'
required: false
default: '5'
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
BD_DISABLE_METRICS: "1"
BD_DISABLE_EVENT_FLUSH: "1"
jobs:
smoke:
name: Upgrade smoke (${{ matrix.prev_version }} → candidate)
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
prev_version: ${{ fromJson(needs.versions.outputs.matrix) }}
needs: versions
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
- name: Configure Git
run: |
git config --global user.name "CI Bot"
git config --global user.email "ci@beads.test"
- name: Cache previous release binaries
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v5
with:
path: ~/.cache/beads-regression
key: smoke-binaries-${{ matrix.prev_version }}-${{ runner.os }}
- name: Build candidate binary
run: go build -tags gms_pure_go -o /tmp/bd-candidate ./cmd/bd
- name: Run upgrade smoke tests
env:
CANDIDATE_BIN: /tmp/bd-candidate
run: ./scripts/upgrade-smoke-test.sh ${{ matrix.prev_version }}
versions:
name: Resolve versions to test
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.resolve.outputs.matrix }}
steps:
- name: Resolve release versions
id: resolve
env:
GH_TOKEN: ${{ github.token }}
# Tag push and manual dispatch test more versions; PRs test fewer for speed
VERSION_COUNT: ${{ (github.event_name == 'push' && '30') || (github.event_name == 'workflow_dispatch' && inputs.version_count) || '5' }}
run: |
VERSIONS=$(gh release list \
--repo gastownhall/beads \
--limit "$VERSION_COUNT" \
--json tagName \
--jq '[.[].tagName]')
echo "matrix=$VERSIONS" >> "$GITHUB_OUTPUT"
echo "Testing versions: $VERSIONS"

View file

@ -15,23 +15,18 @@
# patch is applied to an index in a bare clone and re-checked once staged
# (scripts/docs-autofix-push.sh), so a hostile patch can at most rewrite
# generated doc files on its own PR branch. Pushes are leased to the run's
# head SHA and skipped for heads that are protected or under a ruleset. The
# App private key is a secret of the `autofix` environment, whose deployment-
# branch policy allows only `main`, so only a job running on main can read
# it; the minted token itself is scoped to this one repo with contents:write
# only, so even a hostile patch gains nothing beyond what the job already
# had.
# head SHA and skipped for heads that are protected or under a ruleset.
#
# CONCURRENCY: job-level, shared with bazel-autofix.yml per head branch and
# without cancel-in-progress, so the two bots queue instead of racing on one
# branch (see bazel-autofix.yml).
#
# TOKEN NOTE: pushes made with the default GITHUB_TOKEN do not retrigger PR
# checks. On same-repo PRs the push step mints a short-lived installation
# token for the gastownhall-autofix GitHub App (contents:write, scoped to
# this repo only) and uses that instead. Fork PRs always get the apply-recipe
# comment - no token we hold can push to a fork, so the mint step is skipped
# for them.
# checks. Configure a DOCS_AUTOFIX_TOKEN repo secret (fine-grained PAT or
# GitHub App token with contents:write on this repo) for fully hands-off
# operation on same-repo PRs; without it the pushed fix still lands but
# checks need a manual re-run. Fork PRs always get the apply-recipe comment -
# no token we hold can push to a fork.
name: Docs Autofix
@ -54,10 +49,6 @@ jobs:
runs-on: ubuntu-latest
# Bounded: a hung run would hold the shared group for the default 6h.
timeout-minutes: 10
# Grants the job read access to this environment's secrets; its
# deployment-branch policy restricts that to jobs running on main
# (workflow_run always does), not to any PR branch.
environment: autofix
# Shared with bazel-autofix.yml; queue, never cancel.
concurrency:
group: autofix-${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}
@ -101,22 +92,6 @@ jobs:
fi
echo "found=true" >> "$GITHUB_OUTPUT"
# Same-repo PRs only: no token we hold can push to a fork, and a fork's
# head_repository can even be absent (deleted fork), so this mints
# nothing for it and the push script falls back to the apply-recipe
# comment. app-token outputs are empty (not failed) when the step is
# skipped, which is what the fallback below relies on.
- name: Mint autofix app token
id: app-token
if: github.event.workflow_run.head_repository.full_name == github.repository
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3
with:
app-id: ${{ secrets.AUTOFIX_APP_ID }}
private-key: ${{ secrets.AUTOFIX_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: ${{ github.event.repository.name }}
permission-contents: write
- name: Push regen commit or leave apply recipe
if: steps.patch.outputs.found == 'true'
env:
@ -129,9 +104,9 @@ jobs:
RUN_URL: ${{ github.event.workflow_run.html_url }}
# Split tokens: gh api calls (PR lookup, comments) always use the
# workflow token, which carries this job's pull-requests:write; the
# App token is used ONLY for the git push, so it needs no more
# optional PAT is used ONLY for the git push, so it needs no more
# than contents:write.
GH_TOKEN: ${{ github.token }}
PUSH_TOKEN: ${{ steps.app-token.outputs.token || github.token }}
AUTOFIX_TOKEN_KIND: ${{ steps.app-token.outputs.token && 'app' || 'default' }}
PUSH_TOKEN: ${{ secrets.DOCS_AUTOFIX_TOKEN || github.token }}
AUTOFIX_TOKEN_KIND: ${{ secrets.DOCS_AUTOFIX_TOKEN && 'pat' || 'default' }}
run: ./scripts/docs-autofix-push.sh

View file

@ -3,15 +3,22 @@ name: Docs (Mintlify) checks
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
# The Mintlify site and the check itself. The docsync guard (docs nav,
# links and agent-instruction routing over docs/, engdocs/ and the root
# markdown) is //test/docsync:docsync_test, which bazel.yml's --config=ci
# lane runs on every PR; this workflow keeps only Mintlify's own
# broken-link check, which needs the network (npx mint) and the base
# branch's history.
paths:
# The docsync guard also validates engdocs/** and the curated root
# markdown files (rootDocFiles in test/docsync/docsync_test.go) — keep
# this filter in sync with that list, or a docs-breaking PR merges
# green and turns main red at the full test run.
- 'docs/**'
- 'engdocs/**'
- 'test/docsync/**'
- 'mint.sh'
- 'README.md'
- 'AGENTS.md'
- 'AGENT_INSTRUCTIONS.md'
- 'CONTRIBUTING.md'
- 'CLAUDE.md'
- 'RELEASING.md'
- 'PR_MAINTAINER_GUIDELINES.md'
- '.github/scripts/docs-render-check.sh'
- '.github/workflows/docs-mintlify.yml'
@ -23,10 +30,24 @@ concurrency:
cancel-in-progress: true
jobs:
docsync:
name: Docs nav/link sync (docsync guard)
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
- name: Run docsync guard
run: go test -tags=gms_pure_go ./test/docsync
broken-links:
name: Mintlify broken-links (baseline-aware)
runs-on: ${{ (github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}
timeout-minutes: 10
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6

File diff suppressed because it is too large Load diff

150
.github/workflows/migration-test.yml vendored Normal file
View file

@ -0,0 +1,150 @@
name: Migration Test Harness
on:
pull_request:
paths-ignore:
- '**/*.md'
- 'docs/**'
- 'website/**'
push:
tags: ['v*']
workflow_dispatch:
permissions:
contents: read
env:
BD_DISABLE_METRICS: "1"
BD_DISABLE_EVENT_FLUSH: "1"
DOLT_TEST_RUNTIME_VERSION: v2.1.8
DOLT_TEST_RUNTIME_SHA256: f66318f08ed66e409fc39363ae0fff8ce6fbf6dba9f5bac632b91527b9632a74
jobs:
historical-upgrades:
name: Historical ${{ matrix.version }} → candidate
# v0.55.4 is dynamically linked against the ICU version shipped here.
# Pin the image so a runner alias update cannot invalidate the fixture.
runs-on: ubuntu-24.04
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
include:
- version: v0.9.1
cache-identity: v0.9.1-source-e3c8554fa2c3e4b9caf7e296e9c8abbe24211a72-go1.25.0-cgo1
- version: v0.17.0
cache-identity: v0.17.0-d4d08617a324c85b45c9628bc519d659a9ff9c7c37da67aa48727e0af7f19a75
- version: v0.49.6
cache-identity: v0.49.6-8546dc9a47e11dc31ac2bc9a0224a9c690975e91850932cbb62623053fbb7db8
- version: v0.50.3
cache-identity: v0.50.3-e94b09e0b6a9324bbc0e81ea36bccaaa42172a926bfedfb389e9a26dedb63184
- version: v0.55.4
cache-identity: v0.55.4-e0fa25456dd82890230eef17653448a0bf995104c78864be91c5ed84426a5f49
- version: v0.56.1
cache-identity: v0.56.1-4f9f6cc44465a11613ff529009901eaaf841c6b1f91c15e002b0ecda2015a15c
- version: v0.57.0
cache-identity: v0.57.0-f8629d5627bed7d25f06f92334addc171d679f9aed9d08c5d42a9684205dc04b
- version: v0.62.0
cache-identity: v0.62.0-4cca7265b22e5c3ca8d62ab0b9752bec31f68b7f5fa636282a4c7e5454c35535
- version: v0.63.3
cache-identity: v0.63.3-5f4efd2e010209b3f381dbcd783b2a3a652f50ea72f40ef04c8ba434d408bf9e
- version: v1.0.0
cache-identity: v1.0.0-7057db1e92428fcf5c08d5dc6b07ead57e588b262cba78b9a26893d55bd29fdb
- version: v1.0.1
cache-identity: v1.0.1-1d2364d5d7083a4634a9e734ca87822fb79c2b6625988f9f791e3376313b1b77
- version: v1.1.0
cache-identity: v1.1.0-b0f3dd607c3fb989ee08d0a6854fba80d0402971eb108f9af6170bc14d491a34
- version: v1.1.2
cache-identity: v1.1.2-a72d71ed374955dc9f83a0f90b54bd7b6a0016709dd1676ae2e368651ed401c2
# The v1.1.2 tree re-tagged by the recovery release, so it adds no new
# storage regime — but it is the tag field upgrades actually start
# from, and it was never in this corpus.
- version: v1.2.2
cache-identity: v1.2.2-8140098a51d3b81d5548d1c5e6db1a2d9930e5d141efe2a4bff7d079c4d321e8
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
- name: Install test dependencies
# Backstop for a hang that escapes the inner `timeout` calls, so it has
# to sit ABOVE what those calls can legitimately consume: 3 update
# attempts x 120s + 2 backoffs x 10s + 180s install = 560s worst case.
# 11m leaves ~100s of headroom and stays under the job's 15m budget, so
# a stuck step fails as a step instead of cancelling the whole job.
timeout-minutes: 11
run: |
updated=""
for attempt in 1 2 3; do
if sudo timeout 120 apt-get \
-o Acquire::Retries=3 \
-o Acquire::http::Timeout=30 \
-o Acquire::https::Timeout=30 \
update; then
updated=yes
break
fi
echo "::warning::apt-get update attempt $attempt failed or timed out"
# No backoff after the final attempt - there is nothing left to wait for.
if [ "$attempt" -lt 3 ]; then
sleep 10
fi
done
# Deliberate best-effort: a stale index still installs these packages
# from the runner image cache far more often than not, and failing the
# job here would turn a transient mirror outage into a red build. The
# warning is what makes the degraded path visible in the job log.
if [ -z "$updated" ]; then
echo "::warning::apt-get update failed after 3 attempts; proceeding with cached index"
fi
sudo timeout 180 apt-get install -y jq libicu74
- name: Install Dolt test runtime
# v0.55.4-v0.62.0 host their fixture on this server; v1.0.1-v1.1.2 use
# the same pinned binary as a read-only oracle over the wisp plane,
# which has no `bd dolt sql` equivalent.
if: contains(fromJSON('["v0.55.4","v0.56.1","v0.57.0","v0.62.0","v1.0.1","v1.1.0","v1.1.2","v1.2.2"]'), matrix.version)
run: |
archive="$RUNNER_TEMP/dolt-linux-amd64.tar.gz"
runtime="$RUNNER_TEMP/dolt-runtime"
install_root="$GITHUB_WORKSPACE/.tools/dolt"
curl -fsSL --retry 3 --retry-all-errors --retry-delay 2 \
"https://github.com/dolthub/dolt/releases/download/${DOLT_TEST_RUNTIME_VERSION}/dolt-linux-amd64.tar.gz" \
-o "$archive"
echo "${DOLT_TEST_RUNTIME_SHA256} $archive" | sha256sum -c -
mkdir -p "$runtime" "$install_root/bin"
tar -xzf "$archive" -C "$runtime"
install -m 0755 "$runtime/dolt-linux-amd64/bin/dolt" "$install_root/bin/dolt"
"$install_root/bin/dolt" version
- name: Configure Git
run: |
git config --global user.name "CI Bot"
git config --global user.email "ci@beads.test"
- name: Cache pinned historical release
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.cache/beads-regression
key: historical-dolt-${{ matrix.cache-identity }}-${{ runner.os }}-${{ runner.arch }}
- name: Build candidate
run: make build
- name: Set up Go 1.25 for v0.9.1 source build
if: matrix.version == 'v0.9.1'
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: '1.25.0'
- name: Verify explicit historical upgrade
env:
CANDIDATE_BIN: ./bd
GIT_CONFIG_NOSYSTEM: "1"
DOLT_BIN: ${{ github.workspace }}/.tools/dolt/bin/dolt
HISTORICAL_VERSION: ${{ matrix.version }}
run: |
./scripts/migration-test/run.sh --version "$HISTORICAL_VERSION"

View file

@ -1,91 +1,173 @@
name: Nightly
name: Nightly Full Tests
# Every nightly test runs under Bazel on rbe-west: the `bazel` call below is
# the full suite with no cached test results. Nothing here runs go test on a
# runner (ga-96smfk.22).
on:
schedule:
# Run at 2am UTC daily
- cron: '0 2 * * *'
workflow_dispatch:
permissions:
contents: read
inputs:
suite:
description: "Nightly suite or measurement suite"
required: true
type: choice
default: full-test
options:
- full-test
- pr-linux
- macos-short
- macos-candidates
- linux-integration
- linux-integration-sharded
- linux-integration-hybrid-sharded
- linux-integration-hybrid-16-sharded
- linux-integration-hybrid-prebuilt-sharded
- linux-integration-coverage
- cross-version-smoke
- nix
- mcp-package
- npm-package
- bazel
smoke_version:
description: "Optional previous release for cross-version-smoke"
required: false
default: ""
env:
BD_DISABLE_METRICS: "1"
BD_DISABLE_EVENT_FLUSH: "1"
jobs:
# Bazel lane with the full equivalence listing (package and test-name sets;
# PRs gate on it through pr.yml). Remote execution when the repo secrets
# are present; bazel.yml gets the four RBE secrets plus rbe-prewarm's
# bazel-allocator app private key (same-repo/scheduled trigger only, so
# pre-warming is safe here - see bazel.yml's "rbe-west Pre-warm" header and
# engdocs/CI_REQUIRED_CHECK_TOPOLOGY.md).
measure:
name: Measure selected CI suite
if: ${{ github.event_name == 'workflow_dispatch' && inputs.suite != 'full-test' && inputs.suite != 'bazel' }}
uses: ./.github/workflows/ci-measurements.yml
with:
suite: ${{ inputs.suite }}
smoke_version: ${{ inputs.smoke_version }}
# PR Core's go test (scripts/ci/pr-core.sh) with -json output, so the Bazel
# job below can compare per-test status: a test that passes here and skips
# under Bazel fails the equivalence check unless allowlisted.
bazel-go-test-json:
name: Bazel equivalence (go-test side)
if: ${{ github.event_name == 'schedule' || inputs.suite == 'bazel' }}
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Go
id: setup-go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
cache: false
- name: Restore Go module cache
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/go/pkg/mod
key: beads-go-mod-v2-${{ runner.os }}-${{ runner.arch }}-go-${{ steps.setup-go.outputs.go-version }}-${{ hashFiles('go.mod', 'go.sum') }}
restore-keys: beads-go-mod-v2-${{ runner.os }}-${{ runner.arch }}-go-${{ steps.setup-go.outputs.go-version }}-
- name: Install Dolt
run: ./scripts/ci/install-dolt.sh
- name: Configure Git and Dolt identity
run: |
git config --global user.name "CI Bot"
git config --global user.email "ci@beads.test"
dolt config --global --add user.name "CI Bot"
dolt config --global --add user.email "ci@beads.test"
- name: Run PR core go-test (JSON)
env:
BEADS_PR_CORE_GO_TEST_JSON: ${{ runner.temp }}/go-test.json
run: make ci-pr-core
# Uploaded even when tests fail: the status comparison still applies.
- name: Upload go-test results
if: ${{ always() }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: bazel-equivalence-go-test-json
path: ${{ runner.temp }}/go-test.json
if-no-files-found: error
retention-days: 7
# Bazel lane with the full go test equivalence listing and the skip-parity
# check (reported here; PRs gate on it through pr.yml). Remote execution
# when the repo secrets are present; bazel.yml gets those four and nothing
# else.
bazel:
name: Bazel (fresh, full detail)
# A called workflow's job gets at most this call's token permissions, and
# GitHub checks them when the run starts, even for a job whose if: skips
# it (startup_failure otherwise; gascity #7478): bazel.yml's rrc-seed asks
# id-token: write (push to main only) and rrc-verify issues: write
# (schedule and dispatch only). rrc-verify runs here (its alert issue);
# rrc-seed never does, every other bazel.yml job keeps contents: read,
# and rbe-west's mint refuses any OIDC token but a main-push bazel.yml one
# (scripts/bazel_rrc_test.go, TestBazelWorkflowCallersGrantEveryRequestedPermission).
permissions:
contents: read
id-token: write
issues: write
name: Bazel equivalence (full detail)
needs: bazel-go-test-json
if: ${{ !cancelled() && (github.event_name == 'schedule' || inputs.suite == 'bazel') }}
uses: ./.github/workflows/bazel.yml
secrets:
RBE_WEST_EXECUTOR: ${{ secrets.RBE_WEST_EXECUTOR }}
RBE_TLS_CERT: ${{ secrets.RBE_TLS_CERT }}
RBE_TLS_KEY: ${{ secrets.RBE_TLS_KEY }}
RBE_TLS_CA: ${{ secrets.RBE_TLS_CA }}
RBE_POOL_APP_PRIVATE_KEY: ${{ secrets.RBE_POOL_APP_PRIVATE_KEY }}
with:
details: true
# The one run that re-executes every test (no cached test results):
# PRs, merge groups and pushes to main reuse unchanged tests' PASSes,
# so this keeps sampling flaky and -race failures every night.
fresh-test-results: true
go-test-json-artifact: bazel-equivalence-go-test-json
# rbe-west's pool workers are gascity's and advertise the sha256 of
# gascity's worker-env manifest; beads' tools/rbe/worker-env.txt is a
# byte-for-byte copy and platforms/BUILD.bazel carries the same pin. A copy
# that falls behind queues every remote action (bazel.yml's rbe job runs
# the same check before each remote run and fails it fast), so check every
# night and, out of step, open or update a ci/infra issue with the diff and
# the pin to commit (tools/rbe/worker-env-sync-issue). The only job here
# with issues: write, and only its last step uses the token. gascity
# unreachable (exit 2) fails the job without an issue.
rbe-worker-env-sync:
name: rbe worker-env in step with gascity
full-test:
name: Full Test Suite
if: ${{ github.event_name == 'schedule' || inputs.suite == 'full-test' }}
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
issues: write
timeout-minutes: 45
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
persist-credentials: false
go-version-file: 'go.mod'
- name: Compare the worker-env manifest and pin with gascity's main
id: sync
env:
WORKER_ENV_SYNC_REPORT: ${{ runner.temp }}/worker-env-sync.md
- name: Install Dolt
run: |
rc=0
tools/rbe/worker-env-sync main || rc=$?
echo "rc=$rc" >> "$GITHUB_OUTPUT"
exit "$rc"
./scripts/ci/install-dolt.sh
- name: Open or update the out-of-step issue
if: ${{ failure() && steps.sync.outputs.rc == '1' }}
- name: Configure Git and Dolt identity
run: |
git config --global user.name "CI Bot"
git config --global user.email "ci@beads.test"
dolt config --global --add user.name "CI Bot"
dolt config --global --add user.email "ci@beads.test"
- name: Build
run: go build -v -tags gms_pure_go ./cmd/bd
- name: Full Test Suite (including integration tests)
env:
GH_TOKEN: ${{ github.token }}
REPORT: ${{ runner.temp }}/worker-env-sync.md
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: tools/rbe/worker-env-sync-issue "$REPORT" "$RUN_URL"
# Skip Docker-based Dolt testcontainer tests — they hang in
# GitHub Actions (known issue, see scripts/repro-dolt-hang/).
# Non-Docker integration tests still run via the installed dolt binary.
BEADS_TEST_SKIP: dolt
run: go test -v -race -tags=integration,gms_pure_go -coverprofile=coverage.out -timeout=30m ./...
- name: Check coverage threshold
run: |
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//')
echo "Coverage: $COVERAGE%"
# Threshold is lower (30%) because Docker-based Dolt integration
# tests are skipped in CI (BEADS_TEST_SKIP=dolt). With Docker
# tests included, coverage would be ~50%+.
if (( $(echo "$COVERAGE < 30" | bc -l) )); then
echo "❌ Coverage is below 30% threshold"
exit 1
elif (( $(echo "$COVERAGE < 40" | bc -l) )); then
echo "⚠️ Coverage is below 40% (warning threshold)"
else
echo "✅ Coverage meets threshold"
fi
- name: Upload coverage
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v6
if: success()
continue-on-error: true
with:
file: ./coverage.out
fail_ci_if_error: false

View file

@ -1,12 +1,15 @@
name: nix build
on:
# No pull_request trigger: pr-risk.yml's required `test-nix` job already
# runs `nix run .#default` plus `nix flake check -L` on every PR, a strict
# superset of the `nix build .#default` this workflow exercises here. This
# workflow still runs on push to main (and workflow_dispatch) so the plain
# `nix build` path itself stays covered without duplicating a PR-blocking
# job that never adds coverage pr-risk.yml doesn't already have.
pull_request:
paths:
- 'go.mod'
- 'go.sum'
- 'default.nix'
- 'flake.nix'
- 'flake.lock'
- 'overlay.nix'
- 'packages.nix'
push:
branches: [main]
paths:

View file

@ -2,16 +2,8 @@ name: PR Risk
on:
pull_request:
branches: [ main, 'release/**', 'hotfix/**' ]
# Merge queue (engdocs/CI_REQUIRED_CHECK_TOPOLOGY.md, "Merge Queue"):
# the ruleset's required gate must also report on each queue entry's
# merge-group commit, or a queued PR waits until the queue times it out.
# checks_requested is the queue asking for those checks; pinned
# explicitly (scripts/ci_merge_queue_test.go). The concurrency group
# below keys a merge group on its own gh-readonly-queue/* ref, so queue
# runs never cancel each other or a PR's own runs.
branches: [ main, 'release/**' ]
merge_group:
types: [ checks_requested ]
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }}
@ -20,23 +12,483 @@ concurrency:
env:
BD_DISABLE_METRICS: "1"
BD_DISABLE_EVENT_FLUSH: "1"
# The legacy Go test tiers this workflow used to run (embedded Dolt storage,
# conformance and cmd shards; proxied-server cmd shards; server-Dolt storage
# and full suite) are pr.yml's Bazel lanes on rbe-west now: `embedded Dolt
# tier`, `proxied-server tier` (`dolt-race`, with the dolt-server lane, in
# mode remote) and `server-Dolt storage tier` (bazel.yml), which pr.yml's `CI Gate / Required` requires to have run remotely and
# passed on every pull_request and merge group, fork and Dependabot PRs
# included (ga-96smfk.22). What remains is the Nix packaging check, which no
# Bazel target can stand in for: it builds the package Nix users install.
# D2 step 1: "true" retires PR Risk's legacy embedded-Dolt test jobs on
# same-repo, non-Dependabot pull_requests; pr.yml's
# gated Bazel lane is then the tier's only pre-merge run, and pr.yml's
# gate goes red unless that lane ran remotely and passed. Committed, not a
# repo variable, so a re-run can never change it; must equal pr.yml's /
# pr-risk.yml's copy (scripts/pr_risk_bazel_coverage_test.go). Revert:
# commit "false" in both workflows (in-flight PRs pick it up on their next
# push or merge of main).
BAZEL_RETIRES_LEGACY_EMBEDDED: "true"
jobs:
detect-ci-tier:
name: Detect CI tier
runs-on: ubuntu-latest
outputs:
full_embedded: ${{ steps.tier.outputs.full_embedded }}
reason: ${{ steps.tier.outputs.reason }}
shadow_embedded_cli: ${{ steps.shadow-selector.outputs.embedded_cli }}
shadow_proxied_cli: ${{ steps.shadow-selector.outputs.proxied_cli }}
shadow_embedded_storage: ${{ steps.shadow-selector.outputs.embedded_storage }}
shadow_embedded_conformance: ${{ steps.shadow-selector.outputs.embedded_conformance }}
shadow_server_conformance: ${{ steps.shadow-selector.outputs.server_conformance }}
shadow_full: ${{ steps.shadow-selector.outputs.full }}
shadow_reason: ${{ steps.shadow-selector.outputs.reason }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
with:
fetch-depth: 0
- name: Decide embedded Dolt coverage
id: tier
env:
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: bash .github/scripts/ci-embedded-tier.sh
- name: Shadow CI capability selector
id: shadow-selector
continue-on-error: true
env:
GITHUB_EVENT_NAME: ${{ github.event_name }}
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
set -o pipefail
selection="$(bash .github/scripts/ci-capability-selector.sh)"
printf '%s\n' "$selection"
{
echo '### Shadow CI capability selector'
printf '%s\n' "$selection" | sed 's/^/- `/' | sed 's/$/`/'
} >> "$GITHUB_STEP_SUMMARY"
# D2 step 1: whether the legacy test-embedded-* jobs below stand down
# because pr.yml's gated Bazel `embedded Dolt tier` lane is this PR's run of
# the tier. True only with BAZEL_RETIRES_LEGACY_EMBEDDED, on a same-repo (not
# fork) pull_request whose actor is not Dependabot. pr.yml runs this same
# job (policy-tested identical) and its gate goes red unless the lane then
# ran remotely and passed, so neither the kill switch (mode skip) nor a
# missing executor secret (mode cache) can silently drop the tier. Forks
# and Dependabot (no secrets), merge_group and every other event keep the
# legacy tier. The step reads no secret or variable and runs no repository
# code.
bazel-embedded-coverage:
name: Bazel embedded coverage
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
covered: ${{ steps.decide.outputs.covered }}
steps:
# GitHub's == is case-insensitive. FORK is bazel.yml's rbe job's
# expression, verbatim. Nothing mutable is read: not RBE_WEST_WORKERS
# and not the executor secret (either, evaluated per run, would let one
# workflow's re-run disagree with the other's). A same-repo PR whose run
# lacks the secret is covered anyway, so pr.yml's gate goes red (mode
# cache) instead of the tier silently moving back. Dependabot runs get
# no Actions secrets by design and keep the legacy tier; github.actor
# (unlike triggering_actor) stays the PR's actor on a re-run.
- name: Decide whether the Bazel lane covers the embedded tier
id: decide
env:
RETIRED: ${{ env.BAZEL_RETIRES_LEGACY_EMBEDDED == 'true' }}
PULL_REQUEST: ${{ github.event_name == 'pull_request' }}
FORK: ${{ github.event.pull_request.head.repo.fork == true }}
DEPENDABOT: ${{ github.actor == 'dependabot[bot]' }}
run: |
for v in RETIRED PULL_REQUEST FORK DEPENDABOT; do
case "${!v}" in
true|false) ;;
*) echo "::error::$v is '${!v}', want true or false"; exit 1 ;;
esac
done
covered=false
if [ "$RETIRED" = true ] && [ "$PULL_REQUEST" = true ] && [ "$FORK" = false ] && [ "$DEPENDABOT" = false ]; then
covered=true
fi
echo "covered=$covered" >> "$GITHUB_OUTPUT"
echo "Legacy embedded Dolt tier retired in favour of the Bazel lane: **$covered** (retired: $RETIRED, pull_request: $PULL_REQUEST, fork: $FORK, dependabot: $DEPENDABOT)" | tee -a "$GITHUB_STEP_SUMMARY"
# End-to-end coverage for proxied-server CLI subcommands, sharded across the
# CI matrix. Each sub-test drives the bd CLI subprocess against a real dolt
# sql-server started via testcontainers by the shared proxied harness
# (cmd/bd/*_proxied_integration_test.go).
#
# Reuses the cmd/bd test binary compiled once by build-embedded: the proxied
# tests live in the same package and are gated at runtime by
# BEADS_TEST_PROXIED_SERVER=1, so no separate build is needed. Shard
# assignment is committed in .github/scripts/proxied-cmd-test-shards.txt;
# newly-added TestProxiedServer*/TestServerMode* tests hash-distribute until
# listed there.
test-proxied-cmd:
name: Test (Proxied Dolt Cmd ${{ matrix.shard }}/${{ strategy.job-total }})
needs: [detect-ci-tier, build-embedded]
if: needs.detect-ci-tier.outputs.full_embedded == 'true'
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Download binaries
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: embedded-test-binaries
path: /tmp/
- name: Fix permissions
run: chmod +x /tmp/bd-proxied /tmp/bd-cmd-test
- name: Install Dolt CLI
# TestProxiedServerExternalCreate needs the dolt binary on PATH; the
# shared harness itself uses the dolt sql-server container image.
run: ./scripts/ci/install-dolt.sh
- name: Configure Git and Dolt identity
run: |
git config --global user.name "CI Bot"
git config --global user.email "ci@beads.test"
dolt config --global --add user.name "CI Bot"
dolt config --global --add user.email "ci@beads.test"
- name: Pull Dolt sql-server image
# The shared proxied harness requires the image cached locally
# (isDoltImageCached); without it every proxied test self-skips. Keep the
# tag in sync with internal/testutil/testdoltcommon.go:DoltDockerImage.
run: ./scripts/ci/pull-dolt-image.sh
- name: Test proxied-server cmd shard
timeout-minutes: 16
env:
BEADS_TEST_PROXIED_SERVER: "1"
BEADS_TEST_BD_BINARY: /tmp/bd-proxied
BEADS_TEST_CMD_BINARY: /tmp/bd-cmd-test
run: bash .github/scripts/proxied-test-shard.sh ${{ matrix.shard }} 15
# Embedded Dolt tests - test the in-process Dolt engine (no server required)
#
# Split into: build → storage tests + parallel cmd test shards.
# cmd/bd embedded tests use a committed shard manifest; newly-added tests
# still auto-distribute via hash fallback until the manifest is updated.
#
# The storage, conformance and cmd test jobs stand down when
# bazel-embedded-coverage says pr.yml's gated Bazel `embedded Dolt tier`
# lane runs them instead; build-embedded keeps running, because its
# artifact also feeds the proxied and server Dolt jobs.
build-embedded:
name: Build (Embedded Dolt)
needs: detect-ci-tier
if: needs.detect-ci-tier.outputs.full_embedded == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Go
id: setup-go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
cache: false
- name: Restore Go module cache
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/go/pkg/mod
key: beads-go-mod-v2-${{ runner.os }}-${{ runner.arch }}-go-${{ steps.setup-go.outputs.go-version }}-${{ hashFiles('go.mod', 'go.sum') }}
restore-keys: beads-go-mod-v2-${{ runner.os }}-${{ runner.arch }}-go-${{ steps.setup-go.outputs.go-version }}-
- name: Restore race Go build cache
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ runner.temp }}/go-cache/race
key: beads-go-build-v2-${{ runner.os }}-${{ runner.arch }}-go-${{ steps.setup-go.outputs.go-version }}-base-gms_pure_go-race-${{ github.sha }}
restore-keys: beads-go-build-v2-${{ runner.os }}-${{ runner.arch }}-go-${{ steps.setup-go.outputs.go-version }}-base-gms_pure_go-race-
- name: Restore non-race Go build cache
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ runner.temp }}/go-cache/non-race
key: beads-go-build-v2-${{ runner.os }}-${{ runner.arch }}-go-${{ steps.setup-go.outputs.go-version }}-base-gms_pure_go-non-race-${{ github.sha }}
restore-keys: beads-go-build-v2-${{ runner.os }}-${{ runner.arch }}-go-${{ steps.setup-go.outputs.go-version }}-base-gms_pure_go-non-race-
- name: Build embedded bd binary
env:
GOCACHE: ${{ runner.temp }}/go-cache/race
run: go build -tags gms_pure_go -race -o /tmp/bd-embedded-test ./cmd/bd/
- name: Build embedded storage test binary
env:
GOCACHE: ${{ runner.temp }}/go-cache/race
run: go test -tags gms_pure_go -race -c -o /tmp/embeddeddolt-test ./internal/storage/embeddeddolt/
- name: Build embedded cmd test binary
env:
GOCACHE: ${{ runner.temp }}/go-cache/race
run: go test -tags gms_pure_go -race -c -o /tmp/bd-cmd-test ./cmd/bd/
# Non-race bd used as the proxied-server test subprocess. The proxied
# tests spawn bd many times per sub-test; a -race subprocess would slow
# every invocation, so build a plain binary for BEADS_TEST_BD_BINARY.
- name: Build proxied bd subprocess binary
env:
GOCACHE: ${{ runner.temp }}/go-cache/non-race
run: go build -tags gms_pure_go -o /tmp/bd-proxied ./cmd/bd/
# Server-Dolt conformance binary. No -race: the Dolt server runs
# out-of-process in a container, and omitting it keeps the run inside the
# job's timeout. The dolt package self-skips without the docker image, so
# the binary is harmless if its job is gated off.
- name: Build server Dolt conformance test binary
env:
GOCACHE: ${{ runner.temp }}/go-cache/non-race
run: go test -tags=integration,gms_pure_go -c -o /tmp/dolt-conformance-test ./internal/storage/dolt/
- name: Upload binaries
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: embedded-test-binaries
path: |
/tmp/bd-embedded-test
/tmp/embeddeddolt-test
/tmp/bd-cmd-test
/tmp/bd-proxied
/tmp/dolt-conformance-test
retention-days: 1
test-embedded-storage:
name: Test (Embedded Dolt Storage ${{ matrix.shard }}/${{ strategy.job-total }})
needs: [detect-ci-tier, bazel-embedded-coverage, build-embedded]
if: needs.detect-ci-tier.outputs.full_embedded == 'true' && needs.bazel-embedded-coverage.outputs.covered != 'true'
runs-on: ubuntu-latest
# The shard script's -test.timeout=20m plus setup. At 15m the 1000-item
# batch-apply cap cancelled shard 2/5: TestBatchApplyContract took 604s
# under -race (97s at the 100-item cap, main run 35862663577) and the
# shard hit 15m twice (run 36807191489). The manifest now pins the heavy
# tests apart; the heaviest shard projects to ~13m.
timeout-minutes: 25
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3, 4, 5]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Download binaries
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: embedded-test-binaries
path: /tmp/
- name: Fix permissions
run: chmod +x /tmp/embeddeddolt-test
- name: Configure Git
run: |
git config --global user.name "CI Bot"
git config --global user.email "ci@beads.test"
- name: Test
env:
BEADS_TEST_EMBEDDED_DOLT: "1"
BEADS_TEST_EMBEDDED_TEST_BINARY: /tmp/embeddeddolt-test
# Manifest-driven shard of the storage suite (mirrors test-embedded-cmd
# / embedded-test-shard.sh). Conformance runs separately in the
# dedicated test-embedded-conformance job; embedded-storage-test-shard.sh
# excludes TestConformance from discovery, so it never lands in one of
# these shards.
run: bash .github/scripts/embedded-storage-test-shard.sh ${{ matrix.shard }} 5
test-embedded-conformance:
name: Test (Embedded Dolt Conformance - ${{ matrix.partition }})
needs: [detect-ci-tier, bazel-embedded-coverage, build-embedded]
if: needs.detect-ci-tier.outputs.full_embedded == 'true' && needs.bazel-embedded-coverage.outputs.covered != 'true'
runs-on: ubuntu-latest
timeout-minutes: 35
strategy:
fail-fast: false
matrix:
partition: [core, audit]
env:
BEADS_TEST_EMBEDDED_DOLT: "1"
BEADS_TEST_EMBEDDED_TEST_BINARY: /tmp/embeddeddolt-test
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Download binaries
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: embedded-test-binaries
path: /tmp/
- name: Fix permissions
run: chmod +x /tmp/embeddeddolt-test
- name: Configure Git
run: |
git config --global user.name "CI Bot"
git config --global user.email "ci@beads.test"
- name: Test core conformance
if: matrix.partition == 'core'
# RunAll has a natural Audit seam. Run everything except Audit in the
# core shard and Audit alone in the other shard. The combined suite has
# exceeded 30m under runner variance; each half currently takes ~15m.
# Keep the Go timeout below the job timeout so a real stall still emits
# a diagnostic goroutine dump before Actions stops the job.
run: /tmp/embeddeddolt-test -test.v -test.count=1 -test.timeout=30m -test.run '^TestConformance$' -test.skip '^TestConformance$/^Audit$'
- name: Test audit conformance
if: matrix.partition == 'audit'
run: /tmp/embeddeddolt-test -test.v -test.count=1 -test.timeout=30m -test.run '^TestConformance$/^Audit$'
test-server-storage:
name: Test (Server Dolt Conformance)
needs: [detect-ci-tier, build-embedded]
if: needs.detect-ci-tier.outputs.full_embedded == 'true'
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Download binaries
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: embedded-test-binaries
path: /tmp/
- name: Fix permissions
run: chmod +x /tmp/dolt-conformance-test
- name: Configure Git
run: |
git config --global user.name "CI Bot"
git config --global user.email "ci@beads.test"
- name: Install Dolt
run: ./scripts/ci/install-dolt.sh
- name: Configure Dolt
run: |
dolt config --global --add user.name "CI Bot"
dolt config --global --add user.email "ci@beads.test"
dolt version
- name: Pull Dolt sql-server image
# Presence of this image flips isDoltImageCached() true, so the suite
# exercises server Dolt instead of self-skipping. Keep the tag in sync
# with internal/testutil/testdoltcommon.go:DoltDockerImage.
run: ./scripts/ci/pull-dolt-image.sh
- name: Test
# Server twin of test-embedded-conformance: same conformance.RunAll, but
# against the container-backed server-mode Dolt backend. No -short / no
# BEADS_TEST_SKIP=dolt, so TestMain starts the shared server and the
# suite runs instead of self-skipping.
run: /tmp/dolt-conformance-test -test.v -test.count=1 -test.timeout=15m -test.run '^TestConformance$'
test-server-storage-full:
name: Test (Server Dolt Full Suite ${{ matrix.shard }}/${{ strategy.job-total }})
needs: [detect-ci-tier, build-embedded]
if: needs.detect-ci-tier.outputs.full_embedded == 'true'
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Download binaries
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: embedded-test-binaries
path: /tmp/
- name: Fix permissions
run: chmod +x /tmp/dolt-conformance-test
- name: Configure Git
run: |
git config --global user.name "CI Bot"
git config --global user.email "ci@beads.test"
- name: Install Dolt
run: ./scripts/ci/install-dolt.sh
- name: Configure Dolt
run: |
dolt config --global --add user.name "CI Bot"
dolt config --global --add user.email "ci@beads.test"
dolt version
- name: Pull Dolt sql-server image
# Presence of this image flips isDoltImageCached() true, so the suite
# exercises server Dolt instead of self-skipping. Keep the tag in sync
# with internal/testutil/testdoltcommon.go:DoltDockerImage.
run: ./scripts/ci/pull-dolt-image.sh
- name: Test
# build-embedded's dolt-conformance-test binary compiles every
# top-level test in internal/storage/dolt, not just conformance --
# test-server-storage above only ever runs the ^TestConformance$
# subset. Everything else in that binary (TestCreateGuard_*,
# federation/create-guard/concurrent suites, and diff-owned tests such
# as TestBenchDBPurgeDoesNotLeak on PR #5792) was reached by no
# PR-triggered lane and silently SKIPped for lack of a live server.
# This sibling job reuses the same artifact and server setup and runs
# everything else instead, so a SKIP there gets a real PASS/FAIL.
#
# Manifest-driven shard of the full suite (mirrors test-embedded-storage
# / server-storage-test-shard.sh): 1126 tests in one 15m-Go-timeout job
# never finished (job 95616282508 died at 256/1126 tests, 15m28s in,
# zero failures -- it just ran out of time). server-storage-test-shard.sh
# excludes TestConformance from discovery, so it never lands in one of
# these shards.
env:
BEADS_TEST_ENV_RUN_DOLT: "1"
run: bash .github/scripts/server-storage-test-shard.sh ${{ matrix.shard }} 16
test-embedded-cmd:
name: Test (Embedded Dolt Cmd ${{ matrix.shard }}/${{ strategy.job-total }})
needs: [detect-ci-tier, bazel-embedded-coverage, build-embedded]
if: needs.detect-ci-tier.outputs.full_embedded == 'true' && needs.bazel-embedded-coverage.outputs.covered != 'true'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Download binaries
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: embedded-test-binaries
path: /tmp/
- name: Fix permissions
run: chmod +x /tmp/bd-embedded-test /tmp/embeddeddolt-test /tmp/bd-cmd-test
- name: Configure Git
run: |
git config --global user.name "CI Bot"
git config --global user.email "ci@beads.test"
- name: Test
env:
BEADS_TEST_EMBEDDED_DOLT: "1"
BEADS_TEST_BD_BINARY: /tmp/bd-embedded-test
run: bash .github/scripts/embedded-test-shard.sh ${{ matrix.shard }} 20
test-nix:
name: Test Nix Flake
# F7a: cache-free (no GitHub-saved cache restored/saved here) same-repo
# job moved onto Blacksmith at 4 vCPU; forks, Dependabot and any other
# event stay GitHub-hosted. Must match TestSameRepoBlacksmithRunners.
runs-on: ${{ (github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) && 'blacksmith-4vcpu-ubuntu-2404' || 'ubuntu-latest' }}
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
@ -45,11 +497,10 @@ jobs:
id: nix_help
run: |
nix run .#default -- --help > help.txt
# A packaging check, not a test: evaluates every flake output (packages,
# apps, devShells, overlay) for every system the flake declares. The
# flake has no `checks`: its one check, hook-timeout-backends, runs
# under Bazel as //tests/hook_timeout_backends:hook_timeout_backends_test
# in bazel.yml's PR-core lane.
# Every flake check for the runner's own system (today: hook-timeout-
# backends, checks.nix). `nix flake check` rather than a spelled-out
# `.#checks.x86_64-linux.<name>`: no hardcoded system, and a check added
# to checks.nix is run without a workflow edit.
- name: Run the flake checks
run: |
nix flake check -L
@ -68,17 +519,17 @@ jobs:
ci-gate:
name: PR Risk Gate / Required
# F3: same-repo PRs and merge_group get the org's Blacksmith pool; forks,
# Dependabot and any other event stay GitHub-hosted. This job restores no
# GitHub-saved cache. Must match the TestSameRepoBlacksmithRunners pin;
# the gate's NAME must never change (ruleset requires exactly "PR Risk
# Gate / Required").
runs-on: ${{ (github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}
# F3: now on Blacksmith for same-repo PRs; a hang used to burn only the
# default 360 minutes of a free GitHub-hosted runner, now Blacksmith
# minutes too.
timeout-minutes: 10
runs-on: ubuntu-latest
needs:
- detect-ci-tier
- bazel-embedded-coverage
- build-embedded
- test-embedded-storage
- test-embedded-conformance
- test-server-storage
- test-server-storage-full
- test-embedded-cmd
- test-proxied-cmd
- test-nix
if: ${{ always() }}
steps:
@ -88,6 +539,38 @@ jobs:
env:
CI_GATE_NAME: PR risk gate
CI_GATE_REQUIRED: >-
DETECT_CI_TIER
BAZEL_EMBEDDED_COVERAGE
BUILD_EMBEDDED
TEST_EMBEDDED_STORAGE
TEST_EMBEDDED_CONFORMANCE
TEST_SERVER_STORAGE
TEST_SERVER_STORAGE_FULL
TEST_EMBEDDED_CMD
TEST_PROXIED_CMD
TEST_NIX
FULL_EMBEDDED: ${{ needs.detect-ci-tier.outputs.full_embedded }}
BAZEL_COVERS_EMBEDDED: ${{ needs.bazel-embedded-coverage.outputs.covered }}
DETECT_CI_TIER: ${{ needs.detect-ci-tier.result }}
BAZEL_EMBEDDED_COVERAGE: ${{ needs.bazel-embedded-coverage.result }}
BUILD_EMBEDDED: ${{ needs.build-embedded.result }}
TEST_EMBEDDED_STORAGE: ${{ needs.test-embedded-storage.result }}
TEST_EMBEDDED_CONFORMANCE: ${{ needs.test-embedded-conformance.result }}
TEST_SERVER_STORAGE: ${{ needs.test-server-storage.result }}
TEST_SERVER_STORAGE_FULL: ${{ needs.test-server-storage-full.result }}
TEST_EMBEDDED_CMD: ${{ needs.test-embedded-cmd.result }}
TEST_PROXIED_CMD: ${{ needs.test-proxied-cmd.result }}
TEST_NIX: ${{ needs.test-nix.result }}
run: bash .github/scripts/ci-gate.sh
run: |
skipped_ok=""
if [[ "$FULL_EMBEDDED" != "true" ]]; then
skipped_ok="BUILD_EMBEDDED TEST_EMBEDDED_STORAGE TEST_EMBEDDED_CONFORMANCE TEST_SERVER_STORAGE TEST_SERVER_STORAGE_FULL TEST_EMBEDDED_CMD TEST_PROXIED_CMD"
fi
# The legacy embedded test jobs stand down only where pr.yml's gated
# Bazel lane runs the tier (bazel-embedded-coverage); any other skip
# of them, or a failed or missing decision, fails the gate.
if [[ "$BAZEL_COVERS_EMBEDDED" == "true" ]]; then
skipped_ok="$skipped_ok TEST_EMBEDDED_STORAGE TEST_EMBEDDED_CONFORMANCE TEST_EMBEDDED_CMD"
fi
export CI_GATE_SKIPPED_OK="$skipped_ok"
bash .github/scripts/ci-gate.sh

1691
.github/workflows/pr.yml vendored

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,164 @@
# Managed-local proxied lifecycle lane.
#
# The proxied shards in main.yml exercise command behavior against an
# EXTERNALLY managed Dolt testcontainer. This lane covers the production
# local-first path those shards cannot: bd launches its own loopback proxy,
# the proxy launches a locally installed `dolt sql-server`, and the whole
# lifecycle (create/read, loopback-only listeners, idle shutdown,
# transparent restart with persistence), identity failures, orphan recovery,
# and start/stop convergence run INSIDE a network namespace with only
# loopback up — proving no outbound network is needed once the binaries are
# installed. Linux first; the test lane defines Windows/macOS parity but does
# not implement those OS-specific observation helpers yet.
name: Proxied Local Lifecycle
on:
workflow_dispatch:
merge_group:
push:
branches: [main]
paths:
- 'cmd/bd/proxied_local_*'
- 'cmd/bd/proxied_server*.go'
- 'cmd/bd/dolt*.go'
- 'cmd/bd/*_proxied_server.go'
- 'cmd/bd/backup*.go'
- 'cmd/bd/purge*.go'
- 'cmd/bd/*managed_local*'
- 'cmd/bd/proxied_outage_reconnect_integration_test.go'
- 'cmd/bd/db_proxy_child.go'
- 'cmd/bd/init*.go'
- 'cmd/bd/proxied_integration_helpers_test.go'
- 'cmd/bd/store_factory*.go'
- 'cmd/bd/test_dolt_server_cgo_test.go'
- 'cmd/bd/tracker_proxy_uow_conformance_integration_test.go'
- 'cmd/bd/uow_factory.go'
- 'internal/configfile/**'
- 'internal/doltserver/**'
- 'internal/storage/dbproxy/**'
- 'internal/storage/uow/**'
- 'internal/tracker/conformance/**'
- 'internal/tracker/uow_store.go'
- 'internal/tracker/engine.go'
- 'internal/tracker/store.go'
- 'go.mod'
- 'go.sum'
- '.github/workflows/proxied-local-smoke.yml'
pull_request:
paths:
- 'cmd/bd/proxied_local_*'
- 'cmd/bd/proxied_server*.go'
- 'cmd/bd/dolt*.go'
- 'cmd/bd/*_proxied_server.go'
- 'cmd/bd/backup*.go'
- 'cmd/bd/purge*.go'
- 'cmd/bd/*managed_local*'
- 'cmd/bd/proxied_outage_reconnect_integration_test.go'
- 'cmd/bd/db_proxy_child.go'
- 'cmd/bd/init*.go'
- 'cmd/bd/proxied_integration_helpers_test.go'
- 'cmd/bd/store_factory*.go'
- 'cmd/bd/test_dolt_server_cgo_test.go'
- 'cmd/bd/tracker_proxy_uow_conformance_integration_test.go'
- 'cmd/bd/uow_factory.go'
- 'internal/configfile/**'
- 'internal/doltserver/**'
- 'internal/storage/dbproxy/**'
- 'internal/storage/uow/**'
- 'internal/tracker/conformance/**'
- 'internal/tracker/uow_store.go'
- 'internal/tracker/engine.go'
- 'internal/tracker/store.go'
- 'go.mod'
- 'go.sum'
- '.github/workflows/proxied-local-smoke.yml'
permissions:
contents: read
jobs:
managed-local-smoke:
name: Managed-local proxied lifecycle (Linux, offline)
runs-on: ubuntu-latest
timeout-minutes: 25
env:
CGO_ENABLED: "1"
# Pinned so the lane tests a known dolt CLI, not whatever the installer
# resolves on a given day. Bump deliberately, and only in lockstep with
# the measured pin in scripts/ci/install-dolt.sh (see "Which Dolt
# version to install" in docs/architecture/dolt.md).
DOLT_VERSION: 2.2.0
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
- name: Install pinned Dolt CLI
run: |
curl -fsSL "https://github.com/dolthub/dolt/releases/download/v${DOLT_VERSION}/dolt-linux-amd64.tar.gz" -o /tmp/dolt.tar.gz
tar -xzf /tmp/dolt.tar.gz -C /tmp
sudo install /tmp/dolt-linux-amd64/bin/dolt /usr/local/bin/dolt
dolt version
- name: Build bd and compile the test binary (online)
run: |
go build -tags gms_pure_go -o /tmp/bd-under-test ./cmd/bd
go test -tags gms_pure_go -c -o /tmp/proxied-local-smoke.test ./cmd/bd
- name: Assert the managed-local lifecycle tests are compiled in
run: |
listed="$(
BEADS_TEST_PROXIED_LOCAL=1 \
BEADS_TEST_SKIP=dolt \
/tmp/proxied-local-smoke.test \
-test.list '^TestManagedLocalProxied'
)"
for test_name in \
TestManagedLocalProxiedLifecycleSmoke \
TestManagedLocalProxiedForeignListenerNotAdopted \
TestManagedLocalProxiedReusedPidNeverKilled \
TestManagedLocalProxiedLegacyRecordFailClosed \
TestManagedLocalProxiedOrphanBackendReaped \
TestManagedLocalProxiedNProcessColdStartConvergence \
TestManagedLocalProxiedStopStartInterleave \
TestManagedLocalProxiedDoltStatusReportsLiveTopology \
TestManagedLocalProxiedDoltStartRefusesOverLiveProxy \
TestManagedLocalProxiedDoltStartRefusesWithProxyDown \
TestManagedLocalProxiedDoltLifecycleLeavesOtherTopologiesAlone \
TestManagedLocalProxiedTrackerUOWConformance \
TestManagedLocalProxiedBackupRoundTrip \
TestManagedLocalProxiedAutoBackup \
TestManagedLocalProxiedBackupRestoreRefusedWhileAttached \
TestManagedLocalProxiedPurgeWispsPlaneRetention \
TestManagedLocalProxiedBackendCleanExitRetiresProxy
do
if ! grep -qx "$test_name" <<<"$listed"; then
echo "managed-local lifecycle test $test_name is missing; got: '$listed'" >&2
exit 1
fi
done
- name: Run managed-local lifecycle lane offline (loopback-only netns)
run: |
sudo env \
"PATH=$PATH" \
BEADS_TEST_PROXIED_LOCAL=1 \
BEADS_TEST_SKIP=dolt \
BEADS_TEST_BD_BINARY=/tmp/bd-under-test \
unshare --net -- bash -euxc '
ip link set lo up
# Prove the namespace really has no outbound network before
# trusting anything the test reports.
if timeout 3 bash -c "exec 3<>/dev/tcp/1.1.1.1/443" 2>/dev/null; then
echo "outbound network unexpectedly available inside the netns" >&2
exit 1
fi
cd cmd/bd
/tmp/proxied-local-smoke.test \
-test.run "^TestManagedLocalProxied" \
-test.v -test.timeout 15m
'

133
.github/workflows/regression.yml vendored Normal file
View file

@ -0,0 +1,133 @@
name: Regression Tests
on:
# Run on merges to main
push:
branches: [main]
pull_request:
branches: [main, 'release/**']
# Allow manual trigger
workflow_dispatch:
env:
BD_DISABLE_METRICS: "1"
BD_DISABLE_EVENT_FLUSH: "1"
jobs:
detect-regression-need:
name: Detect regression need
runs-on: ubuntu-latest
outputs:
run_regression: ${{ steps.detect.outputs.run_regression }}
reason: ${{ steps.detect.outputs.reason }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
with:
fetch-depth: 0
- name: Decide whether to run differential regression tests
id: detect
env:
EVENT_NAME: ${{ github.event_name }}
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
set -euo pipefail
if [[ "$EVENT_NAME" != "pull_request" ]]; then
echo "run_regression=true" >> "$GITHUB_OUTPUT"
echo "reason=$EVENT_NAME event always runs regression tests" >> "$GITHUB_OUTPUT"
exit 0
fi
labels="$(jq -r '.pull_request.labels[].name // empty' "$GITHUB_EVENT_PATH")"
if grep -Fxq "run-regression" <<<"$labels"; then
echo "run_regression=true" >> "$GITHUB_OUTPUT"
echo "reason=run-regression label present" >> "$GITHUB_OUTPUT"
exit 0
fi
if grep -Fxq "skip-regression" <<<"$labels"; then
echo "run_regression=false" >> "$GITHUB_OUTPUT"
echo "reason=skip-regression label present" >> "$GITHUB_OUTPUT"
exit 0
fi
changed="$(git diff --name-only "$PR_BASE_SHA" "$PR_HEAD_SHA")"
echo "Changed files:"
printf '%s\n' "$changed"
regression_candidates="$(
printf '%s\n' "$changed" |
grep -Ev '^(cmd/bd|internal/storage|internal/types)/.*_test\.go$' ||
true
)"
risky_pattern='^(\.github/workflows/regression\.yml|Makefile|go\.(mod|sum)|cmd/bd/|internal/storage/|internal/types/|tests/regression/)'
if grep -Eq "$risky_pattern" <<<"$regression_candidates"; then
echo "run_regression=true" >> "$GITHUB_OUTPUT"
echo "reason=PR changes CLI, storage, types, regression, or build inputs" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "run_regression=false" >> "$GITHUB_OUTPUT"
echo "reason=PR does not touch regression-sensitive paths" >> "$GITHUB_OUTPUT"
regression:
name: Differential Regression (v0.49.6 baseline)
needs: detect-regression-need
if: needs.detect-regression-need.outputs.run_regression == 'true'
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- name: Show regression trigger reason
run: echo "${{ needs.detect-regression-need.outputs.reason }}"
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
- name: Configure Git
run: |
git config --global user.name "CI Bot"
git config --global user.email "ci@beads.test"
- name: Install Dolt
run: ./scripts/ci/install-dolt.sh
- name: Configure Dolt
run: |
dolt config --global --add user.name "CI Bot"
dolt config --global --add user.email "ci@beads.test"
dolt version
- name: Pull Dolt sql-server image
# Without this, isDoltImageCached() returns false in TestMain and the
# regression suite falls back to embedded Dolt with HOME=<tmpdir>, which
# has a known cleanup race (see beads issue: TestCreateWithParentFlag
# TempDir RemoveAll "directory not empty" flake). Keep the tag in sync
# with internal/testutil/testdoltcommon.go:DoltDockerImage.
run: ./scripts/ci/pull-dolt-image.sh
- name: Cache baseline binary
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v5
with:
path: ~/.cache/beads-regression
key: regression-baseline-${{ hashFiles('tests/regression/BASELINE_VERSION') }}
# Passing-side wall time already overlapped the go deadline below, so
# ordinary GitHub-runner speed variance -- not a real hang -- was
# tripping this step. Measured over the 100 most recent Regression
# Tests runs (2026-09-03/04, ~29.5h): p50 593s (~10m), max passing
# 1189s (~19.8m) against the prior 1200s (20m) cap, and 5 runs in that
# window hit the identical `panic: test timed out after 20m0s` with
# zero `--- FAIL` lines -- a budget defect, not a regression. Match
# main.yml's Test job fix for the same failure mode: raise the go
# deadline to cover the observed slowdown and keep it inside a larger
# finite job budget (see timeout-minutes above), so the go deadline
# fires first and prints goroutine stacks -- a REAL hang stays
# diagnosable instead of being cut off by a bare job kill.
- name: Run regression tests
run: go test -tags=regression,gms_pure_go -timeout=40m -v ./tests/regression/...

View file

@ -35,14 +35,18 @@ jobs:
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
cache: false
- name: Verify tag matches version.go
run: |
tag_version="${GITHUB_REF_NAME#v}"
code_version="$(grep 'Version = ' cmd/bd/version.go | sed 's/.*"\(.*\)".*/\1/')"
if [ "$tag_version" != "$code_version" ]; then
echo "ERROR: tag v$tag_version does not match cmd/bd/version.go ($code_version)" >&2
exit 1
fi
echo "OK: tag and version.go agree on $code_version"
- name: Verify tag and released versions
run: ./scripts/check-versions.sh --expect "${GITHUB_REF_NAME#v}"
- name: Check version consistency
run: ./scripts/check-versions.sh
release-package-mcp:
name: Release Package Gate (MCP)

View file

@ -1,13 +1,10 @@
name: Update vendorHash for dependabot Go bumps
# Dependabot bumps to go.mod/go.sum invalidate the proxyVendor FOD hash in
# default.nix, which fails the required PR Risk `test-nix` gate (F7c,
# spec-f7.md §2.4: nix-build.yml itself no longer runs on pull_request, since
# test-nix's `nix run .#default` plus `nix flake check -L`, which evaluates
# every flake output, is a superset of plain `nix build .#default`). This workflow detects the drift, computes the
# new hash via scripts/update-nix-vendorhash.sh, and pushes the update back to
# the dependabot branch so the gate goes green without a maintainer
# round-trip.
# default.nix, which fails the nix-build CI gate. This workflow detects the
# drift, computes the new hash via scripts/update-nix-vendorhash.sh, and
# pushes the update back to the dependabot branch so the gate goes green
# without a maintainer round-trip.
#
# Tracked under beads-bz5.
#
@ -31,9 +28,9 @@ name: Update vendorHash for dependabot Go bumps
#
# Caveat:
# GitHub does not retrigger pull_request workflow runs for commits
# authored by GITHUB_TOKEN. After this workflow pushes, the existing PR Risk
# `test-nix` check on this PR will remain stuck on the pre-fix commit.
# Maintainers either re-run test-nix manually, or this workflow's own
# authored by GITHUB_TOKEN. After this workflow pushes, the existing
# nix-build.yml check on this PR will remain stuck on the pre-fix commit.
# Maintainers either re-run nix-build manually, or this workflow's own
# success acts as the green signal that the hash is correct.
on:
@ -82,14 +79,6 @@ jobs:
- name: Update vendorHash
run: ./scripts/update-nix-vendorhash.sh
- name: Verify the build independently of the script's exit status
# update-nix-vendorhash.sh's own verification build (its step 5) is
# internal to the script; this step re-derives the same signal from
# a source the workflow doesn't have to trust: a plain `nix build`
# that this job step fails on if it fails, regardless of what the
# script itself reported.
run: nix build .#default
- name: Detect whether hash changed
id: changed
run: |

View file

@ -1,196 +0,0 @@
# Keep beads' rbe worker-env pin in step with gastownhall/gascity main
# without the ~100-minute wait #7419 fixed by hand.
#
# rbe-west's OSS pool is gascity's: its workers advertise the sha256 of the
# toolchain manifest gascity's tools/rbe/worker-env measures, and the
# schedulers match //platforms:rbe_worker's worker-env exec property
# exactly. beads' tools/rbe/worker-env.txt and the platforms/BUILD.bazel pin
# are a byte-for-byte copy of gascity main's; when gascity moves the pin (a
# Go, dolt, or OS/library bump -- #7387 was a Go security release), every
# beads remote-execution run stops in bazel.yml's rbe-job preflight
# (tools/rbe/worker-env-sync) until the copy catches up. nightly.yml's
# rbe-worker-env-sync job already opens a ci/infra issue for a human to fix;
# this instead opens the fix itself, every 15 minutes, so the gap is
# minutes, not until someone reads the issue.
#
# tools/rbe/worker-env-sync only detects the mismatch (exit 1) or that it
# could not compare with gascity (exit 2, e.g. GitHub is briefly
# unreachable; the next run retries). The write half, tools/rbe/worker-env-
# sync-copy, runs only after that exit-1 detection, on a checkout already in
# hand -- so a transient gascity outage can turn "in step" into "unknown",
# never into an unwanted write.
#
# TWO TOKENS, ONE JOB EACH: GitHub never runs checks on a PR a plain
# GITHUB_TOKEN opens (its loop-prevention rule), so this needs a GitHub App
# token to open the PR. The gastownhall-autofix App (contents:write only on
# this repo) mints push-token and does the git push of the fixed branch
# (bot/worker-env-sync); it cannot open, label or merge a PR. The separate
# gascity-autofix App (pull-requests:write only, no contents) mints pr-token
# and does everything PR-shaped: create/update, the status/needs-review-auto
# label, and arming auto-merge. Splitting them means a bug in the PR-shaped
# half can never push a commit, and a bug in the push half can never touch a
# PR; neither token can do the other's job even by accident. Both Apps'
# credentials are secrets of the same `autofix` environment.
#
# peter-evans/create-pull-request takes one token for the whole push+PR
# flow, so it cannot honor this split; this uses plain git for the push and
# gh for the PR instead. Every `${{ }}` is resolved into a step's `env:`,
# never written inside a `run:` script, so a value that happened to look
# like shell (a title or body containing `` ` `` or `$`) is data to the
# shell, not something GitHub's expression syntax or the shell re-parses.
#
# SECURITY: schedule and workflow_dispatch are never fork events (no
# pull_request trigger here at all), so neither App's private key -- secrets
# of the `autofix` environment, whose deployment-branch policy allows only
# main -- is ever readable by a fork. The guard on github.repository is
# defense in depth for a fork of this repo, where the secrets would not
# exist anyway. Both mint steps run only once worker-env-sync has already
# found a real mismatch, so a run that is in step or can't compare asks
# neither App for a token. gh pr merge --auto only arms GitHub's native
# auto-merge (it still waits for every required check and the branch
# protection rule); it does not merge anything itself.
name: rbe worker-env autosync
on:
schedule:
- cron: "*/15 * * * *"
workflow_dispatch:
permissions:
contents: read
jobs:
autosync:
name: Sync worker-env pin with gascity main
if: github.repository == 'gastownhall/beads'
runs-on: ubuntu-latest
timeout-minutes: 10
# Grants the job read access to this environment's secrets (both Apps'
# id and private key); its deployment-branch policy restricts that to
# jobs running on main, which schedule and workflow_dispatch on this
# repo always are.
environment: autofix
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
with:
persist-credentials: false
# Never fails the step itself: rc is the signal every later step
# gates on (1, a real mismatch; 2, gascity unreachable -- the next
# scheduled run retries; 0, in step). A run every 15 minutes failing
# red for however long a mismatch takes to review and merge would be
# noise, not signal.
- name: Compare the worker-env manifest and pin with gascity's main
id: sync
run: |
rc=0
tools/rbe/worker-env-sync main || rc=$?
echo "rc=$rc" >> "$GITHUB_OUTPUT"
- name: Copy gascity main's worker-env manifest and pin
if: steps.sync.outputs.rc == '1'
run: tools/rbe/worker-env-sync-copy main
- name: Confirm only the worker-env files moved
if: steps.sync.outputs.rc == '1'
run: |
changed="$(git diff --name-only)"
untracked="$(git ls-files --others --exclude-standard)"
want=$'platforms/BUILD.bazel\ntools/rbe/worker-env.txt'
if [ -n "$untracked" ] || [ "$(printf '%s\n' "$changed" | sort)" != "$(printf '%s\n' "$want" | sort)" ]; then
echo "::error::worker-env-sync-copy touched more than platforms/BUILD.bazel and tools/rbe/worker-env.txt:"
printf '%s\n' "$changed" "$untracked"
exit 1
fi
# contents:write only, on this repo alone: all it can do is push
# bot/worker-env-sync. Minted only once a real mismatch needs a push.
- name: Mint push token (gastownhall-autofix)
id: push-token
if: steps.sync.outputs.rc == '1'
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3
with:
app-id: ${{ secrets.AUTOFIX_APP_ID }}
private-key: ${{ secrets.AUTOFIX_APP_PRIVATE_KEY }}
owner: gastownhall
repositories: beads
permission-contents: write
# pull-requests:write only, on this repo alone: all it can do is
# open, label and arm auto-merge on a PR -- never push a commit.
- name: Mint PR token (gascity-autofix)
id: pr-token
if: steps.sync.outputs.rc == '1'
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3
with:
app-id: ${{ secrets.GASCITY_AUTOFIX_APP_ID }}
private-key: ${{ secrets.GASCITY_AUTOFIX_APP_PRIVATE_KEY }}
owner: gastownhall
repositories: beads
permission-pull-requests: write
# push-token alone; it cannot see a PR exists, let alone touch one.
# Leased to the branch: a force-with-lease scoped to refs/heads/
# bot/worker-env-sync only, so a push can never move any other ref.
- name: Commit and push the sync branch
if: steps.sync.outputs.rc == '1'
env:
PUSH_TOKEN: ${{ steps.push-token.outputs.token }}
REPO: ${{ github.repository }}
BRANCH: bot/worker-env-sync
COMMIT_SUBJECT: "build(rbe): sync worker-env pin with gascity main"
GIT_AUTHOR_NAME: gastownhall-autofix[bot]
GIT_AUTHOR_EMAIL: gastownhall-autofix[bot]@users.noreply.github.com
GIT_COMMITTER_NAME: gastownhall-autofix[bot]
GIT_COMMITTER_EMAIL: gastownhall-autofix[bot]@users.noreply.github.com
run: |
git checkout -B "$BRANCH"
git add platforms/BUILD.bazel tools/rbe/worker-env.txt
git commit -m "$COMMIT_SUBJECT"
git push "https://x-access-token:${PUSH_TOKEN}@github.com/${REPO}.git" \
"HEAD:refs/heads/$BRANCH" "--force-with-lease=refs/heads/$BRANCH"
# pr-token alone; it cannot push a commit, only act on the PR the
# step above already pushed.
- name: Open or update the sync PR
id: pr
if: steps.sync.outputs.rc == '1'
env:
GH_TOKEN: ${{ steps.pr-token.outputs.token }}
REPO: ${{ github.repository }}
BRANCH: bot/worker-env-sync
TITLE: "build(rbe): sync worker-env pin with gascity main"
LABEL: status/needs-review-auto
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
body="$(cat <<BODY
rbe-west's pool workers advertise gastownhall/gascity main's worker-env
pin; beads' copy (\`tools/rbe/worker-env.txt\` and the
\`platforms/BUILD.bazel\` pin) had fallen out of step, so beads' remote
actions were queueing on a pin no worker serves
(\`tools/rbe/worker-env-sync main\`, run $RUN_URL).
This copies gascity main's manifest and pin byte for byte, same as
#7419. Auto-merge is armed: it lands once the automated review and the
rest of the required checks are green.
BODY
)"
number="$(gh pr list --repo "$REPO" --head "$BRANCH" --base main --state open --json number --jq '.[0].number')"
if [ -n "$number" ]; then
gh pr edit "$number" --repo "$REPO" --title "$TITLE" --body "$body"
else
gh pr create --repo "$REPO" --base main --head "$BRANCH" --title "$TITLE" --body "$body"
number="$(gh pr list --repo "$REPO" --head "$BRANCH" --base main --state open --json number --jq '.[0].number')"
fi
gh pr edit "$number" --repo "$REPO" --add-label "$LABEL"
echo "number=$number" >> "$GITHUB_OUTPUT"
- name: Enable auto-merge
if: steps.sync.outputs.rc == '1' && steps.pr.outputs.number
env:
GH_TOKEN: ${{ steps.pr-token.outputs.token }}
REPO: ${{ github.repository }}
PR_NUMBER: ${{ steps.pr.outputs.number }}
run: gh pr merge --auto --squash --repo "$REPO" "$PR_NUMBER"

View file

@ -1,9 +1,3 @@
# Lint policy for nogo (//tools/nogo), which runs these linters beside every
# Bazel Go compile: tools/nogo/internal/golangci embeds this file and applies
# it as golangci-lint v2.10.1 would (enabled linters, settings, run.tests,
# generated files, exclusion rules). Decoding is strict, so a key the nogo
# wrappers do not implement fails the build. golangci-lint itself still reads
# it (editors, ad-hoc runs), but CI gates on nogo; see engdocs/LINTING.md.
version: "2"
run:
@ -467,28 +461,12 @@ linters:
# tests: false` means forbidigo never analyzes a test file at all, so that
# entry asserts nothing either way and scoping it would be the churn this
# comment just refused to write.
#
# `search` LEFT this list when all three of its routes moved onto
# issueops.Reader.List with issueops.SearchListRequest (cmd/bd/search.go);
# it builds no filter any more.
#
# `gate` LEFT it when `bd gate check` joined `bd gate list` on
# issueops.ListGates over the route's Querier: cmd/bd/gate.go and
# cmd/bd/gate_proxied_server.go name no filter type any more.
# `gate_discover` keeps its own hole below, since findPendingGates still
# asks SearchIssues for its gates.
- path: '^cmd/bd/(close|duplicates|find_duplicates|gc|graph|info|label|orphans|purge|todo|wisp|human)(_proxied_server)?\.go$'
- path: '^cmd/bd/(close|duplicates|find_duplicates|gate|gc|graph|info|label|orphans|purge|search|todo|wisp|human)(_proxied_server)?\.go$'
text: 'do not write a filter here'
linters:
- forbidigo
# Molecule reporting: each selects the members of one molecule.
#
# `mol current` and `mol progress` LEFT this list when their in_progress
# and hooked listings moved onto issueops.Reader.List (cmd/bd/mol_roles.go)
# so a remote backend answers them. The proxied route's in-transaction
# port still searches through the unit of work, and that filter lives in
# mol_port.go beside the port.
- path: '^cmd/bd/mol_(port|ready_gated|stale)\.go$'
- path: '^cmd/bd/mol_(current|port|progress|ready_gated|stale)\.go$'
text: 'do not write a filter here'
linters:
- forbidigo

View file

@ -1,15 +1,9 @@
repos:
# Lint and vet: nogo (//tools/nogo) over the changed files' Bazel packages,
# the analyzers CI gates on (go test's vet checks plus the golangci-lint
# linters .golangci.yml enables). Needs bazel or bazelisk on PATH.
- repo: local
- repo: https://github.com/golangci/golangci-lint
rev: v2.10.1
hooks:
- id: nogo
name: nogo (bazel)
entry: make lint-changed LINT_CHANGED_SCOPE=staged
language: system
types: [go]
pass_filenames: false
- id: golangci-lint
args: [--timeout=5m]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0

455
AGENTS.md
View file

@ -1,227 +1,290 @@
# Beads — Contributor Agent Instructions
# Agent Instructions
This file is for agents and humans **developing beads** (`bd`). If you are
using `bd` to track work in your own project, read the user docs instead:
[docs site](https://beads.gascity.com/) and
[IDE and agent setup](docs/getting-started/ide-setup.md).
<!-- bd-doctor-divergence: ok -->
<!-- Contributor-only file. Do not run `bd setup` or `bd init` against this
checkout: they would inject the end-user beads integration block here. -->
See [AGENT_INSTRUCTIONS.md](AGENT_INSTRUCTIONS.md) for full instructions.
Nested `AGENTS.md` files hold area-specific rules; the routing table at the
end lists them. `CLAUDE.md` files are symlinks to their sibling `AGENTS.md`.
This file exists for compatibility with tools that look for AGENTS.md.
## How work flows here
The marker above tells `bd doctor` that the intentional divergence between
this file and `CLAUDE.md` (different audiences, different reading orders) is
expected and should not be flagged.
GitHub Issues is the public tracker. Use an issue when it adds context
reviewers need: a user-visible bug, a behavior or design change worth
discussing, or work that spans several PRs. The issue carries the
reproduction, impact, and evidence for a bug, or the motivation, impact, risk,
and verification plan for a change. Small, self-explanatory changes (typos,
flaky tests, refactors, CI or docs tweaks) can go straight to a PR whose body
explains the why.
## Key Sections
1. If the change warrants an issue, find or file one with the bug or feature
form. It does not need maintainer approval first; file it before or
alongside the PR.
2. Work on a branch, open a PR against `main` (its body says
`Closes #<issue>` when there is one), and let CI and review run.
3. Maintainers triage issues with `status/needs-triage`, `status/needs-info`,
`status/needs-repro`, `status/needs-design`, and `status/accepted`
(confirmed); see [CONTRIBUTING.md](CONTRIBUTING.md).
- **Issue Tracking** - How to use bd for work management
- **Development Guidelines** - Code standards and testing
- **Project Scope** - Read [engdocs/PROJECT_CHARTER.md](engdocs/PROJECT_CHARTER.md) before adding new feature surface area
- **Visual Design System** - Status icons, colors, and semantic styling for CLI output
- **Contributor Protection** - Read [CONTRIBUTING.md](CONTRIBUTING.md) before handling external PRs
- **Maintainer PR Guidelines** - Read [PR_MAINTAINER_GUIDELINES.md](PR_MAINTAINER_GUIDELINES.md) before triaging, landing, or closing PRs
Maintainers also keep an internal bd ledger. It is optional for contributors
and not a substitute for the GitHub issue.
## Project Scope
## Agent contribution policy
Before adding new feature surface area, read
[engdocs/PROJECT_CHARTER.md](engdocs/PROJECT_CHARTER.md). Beads owns issue tracking
primitives and should not encode orchestration-layer policy, become a storage
engine, or casually expand the database schema when metadata would work.
- File an issue when the change warrants one (see above). When you do, use
the bug or feature form fields, fill each from evidence, and answer
`NOT_ENOUGH_INFO` where the evidence runs out.
- A human reviews and stands behind every issue and PR an agent drafts.
Evidence that the change works end-to-end is required; "unit tests pass"
alone is not evidence.
- Before implementing work, opening a PR, or merging/closing a PR, run the PR
preflight:
```bash
scripts/pr-preflight.sh --search "<topic keywords>" --repo gastownhall/beads
scripts/pr-preflight.sh <pr-number> --repo gastownhall/beads
```
The preflight is the agent gate for PR handling; do not rely on
auto-discovery of CONTRIBUTING.md.
- Use `gh` for GitHub issues and PRs, not browser tools. Write PR, issue,
comment, and review bodies to a file, run `scripts/gh-body-lint <body-file>`,
and pass the file with `gh ... --body-file`. Sign agent-written GitHub
comments and reviews per [engdocs/AGENT_SIGNING.md](engdocs/AGENT_SIGNING.md).
## PR Safety for Agents
## Contributor protection
External contributor PRs have priority. Read [CONTRIBUTING.md](CONTRIBUTING.md)
— it contains promises we've made to contributors — and, before triaging,
reviewing, landing, closing, or otherwise maintaining PRs,
Before triaging, reviewing, landing, closing, or otherwise maintaining PRs, read
[PR_MAINTAINER_GUIDELINES.md](PR_MAINTAINER_GUIDELINES.md). The maintainer
policy is to maximize community throughput: find useful contributor value,
absorb or transform it locally when practical, preserve attribution, and use
request-changes only as a last resort.
Before implementing any feature or fix, check for existing open PRs on the
same topic. If one exists:
1. **Review it first** — read the diff, understand the approach.
2. **Build on their work, don't rewrite it** — check out their branch,
fix/adapt as needed.
3. **Preserve their tests** — keep them unless they're wrong.
4. **Attribute properly** — `Co-authored-by:` in commits, reference their PR.
5. **Never close or supersede their PR silently.** If a rewrite is
unavoidable, explain why on the original PR and credit their design/tests.
## Scope: where a change belongs
Read [engdocs/PROJECT_CHARTER.md](engdocs/PROJECT_CHARTER.md) before adding
feature surface area. Beads owns issue tracking primitives and should not
encode orchestration-layer policy, become a storage engine, or casually expand
the database schema when metadata would work. Prefer, in order: issue
metadata over new fields, a flag on an existing command over a new command,
an integration or plugin over core, and leave orchestration policy to the
orchestration layer.
**Storage boundary.** Beads talks to storage through a driver interface
(`dolthub/driver` for Dolt). Do not add beads-side flocks, engine
introspection, storage-specific retry or crash-recovery logic, or public SDK
return types that leak driver internals. If the boundary is too narrow, widen
the interface or route the issue to the driver instead of patching around it
in beads. `bd doctor` support for embedded mode is enabled one subcommand at a
time, each human-vetted (GH#3794): do not lift the embedded-mode gate in
`cmd/bd/doctor.go` wholesale, and keep database-layer checks and fixes
server-gated until the driver interface covers them.
**Layering.** Schema → `internal/storage/issueops` → `cmd/bd`. Add new
primitives at the lowest layer first, one layer per PR, stacked when a fix
spans layers. See
[CONTRIBUTING_PR_GUIDELINES.md](CONTRIBUTING_PR_GUIDELINES.md).
## Build, test, lint
Bazel is the build and test system: CI gates on the `bazel test` lanes in
`.github/workflows/bazel.yml`, and nogo (lint + vet), gofmt and the repository
guards exist only as Bazel targets. Install
[Bazelisk](https://github.com/bazelbuild/bazelisk) as `bazel`; the pre-commit
and pre-push hooks need it.
Before implementing work, opening a PR, or merging/closing a PR, run the PR
preflight:
```bash
make test # bazel test //... --config=ci: the CI test lane (nogo, gofmt, guards, unit tests)
make check # testing.Short policy + make ci-pr-lint + make test
make ci-pr-lint # nogo lint + vet gate, native plus windows/darwin
make check-docs # bazel docsync + doc freshness, then the CLI flag check
make bazel-sync # after adding/removing/renaming Go files or changing imports/go.mod
make install # build and install bd to ~/.local/bin (canonical)
scripts/pr-preflight.sh --search "<topic keywords>" --repo gastownhall/beads
scripts/pr-preflight.sh <pr-number> --repo gastownhall/beads
```
- Each other tier has its own lane (`--config=integration`, `doltserver`,
`embedded`, ...); [engdocs/TESTING.md](engdocs/TESTING.md) lists the exact
command per lane and is the canonical source for test selection, design,
and PR-readiness gates.
- Where actions run: contributors add `--config=fork-cache` (rbe-west's
anonymous read-only cache; nothing is uploaded), maintainers with an rbe-west
certificate `--config=remote-exec`, agent hosts whose `~/.bazelrc` names the
executor neither. Make yours the default with a `build --config=...` line in
the gitignored `.bazelrc.local`, or pass `BAZEL_FLAGS=...` to make.
- Agents run tests only with `bazel test`, also while iterating on one
behavior:
External contributor PRs have priority. Review and build on their branch when
possible, preserve their tests and attribution, and never close or supersede
their PR silently. If a rewrite is unavoidable, explain why on the original PR
and credit their design/tests.
```bash
bazel test //cmd/bd:bd_test --config=ci --test_filter='^TestName$' --test_output=all
```
## Visual Design Anti-Patterns
A target also passes when the test never ran (a filter that matches
nothing, a skip, a file the configuration does not compile), so count a run
only when its log shows `--- PASS: TestName` and no `--- SKIP` for the test
or a `TestName/...` subtest: Go prints `--- PASS` for a test whose every
subtest skipped. "Check That the Test Ran" in
[engdocs/TESTING.md](engdocs/TESTING.md) names the tests `--config=ci` does
not run (Dolt-backed, `-short`-gated, integration-tagged, `TestEmbedded*`
and embedded-Dolt, files `BUILD.bazel` does not list) and the way into
each. An unchanged target returns its cached result, which is the same
evidence. Finish with `make test`.
- Agents do not run `go test` (`./scripts/test.sh`, `make test-go`): CI does
not enforce it, it skips nogo, gofmt and the guards, and agent hosts may
refuse it. It stays a convenience for humans working offline. The exception
is regenerating golden files (`make corpus-regen`, `make githooks-regen`,
`BD_UPDATE_GOLDEN=1`), which Bazel cannot do: see "Regenerating Golden
Files" in [engdocs/TESTING.md](engdocs/TESTING.md).
- **Do NOT** use `go build -o bd ./cmd/bd`, `go install ./cmd/bd`, or raw
`go run ./cmd/bd ...`: they bypass the canonical build path, leave stale
binaries, and raw `go run` misses the `gms_pure_go` tag. Use `make install`,
`./bd`, or `go run -tags gms_pure_go ./cmd/bd ...`.
- All new features need tests.
- **Never pollute a production database with test issues.** Use `t.TempDir()`
in Go tests and a disposable working directory for manual `bd` experiments.
- `make ci-pr-lint` must pass with zero issues; see
[engdocs/LINTING.md](engdocs/LINTING.md).
- If BUILD files are out of sync and you cannot run `make bazel-sync`, CI
syncs them: on same-repo PRs the bazel-autofix workflow pushes the fix to
your branch (pull before pushing again); fork PRs get a comment with an
apply recipe.
- If you changed behavior, update the user docs (`docs/`, via the
`beads-docs` skill) or README in the same PR.
**NEVER use emoji-style icons** (🔴🟠🟡🔵⚪) in CLI output. They cause cognitive overload.
## Commits and PRs
**ALWAYS use small Unicode symbols** with semantic colors (status uses symbols; priority uses labels):
- Status: `○ ◐ ● ✓ ❄`
- Priority: `P0`–`P4` label with color (no status glyph)
- Conventional Commits: `type(scope): summary` (`fix`, `feat`, `docs`,
`test`, `refactor`, `chore`, `ci`, `perf`).
- For agent-prepared commits, include the `Agent-Signature:` trailer described
in [engdocs/AGENT_SIGNING.md](engdocs/AGENT_SIGNING.md). Use
`unknown-model` or `unknown-reasoning` when reliable runtime metadata is
unavailable.
- Maintainers working from the internal ledger may also end the subject with
the bead ID, e.g. `(bd-abc)`, so `bd doctor` can detect orphaned issues.
- Work on a feature branch and open a PR against `main`; direct pushes to
`main` are reserved for releases and narrow operational fixes.
- When the user asks to bump the version, use `./scripts/bump-version.sh`; the
full release process is in [RELEASING.md](RELEASING.md).
See [AGENT_INSTRUCTIONS.md](AGENT_INSTRUCTIONS.md) for full development guidelines.
## Ending a session
## Storage Boundary
Do not push to `main`. Before handing off:
The canonical storage boundary is in
[engdocs/PROJECT_CHARTER.md](engdocs/PROJECT_CHARTER.md#storage-boundary). In short:
Beads talks to storage through a driver interface (`dolthub/driver` for Dolt).
Do not add beads-side flocks, engine introspection, storage-specific retry or
crash-recovery logic, or public SDK return types that leak driver internals.
If the boundary is too narrow, widen the interface or route the issue to the
driver instead of patching around it in beads.
1. Run the quality gates your change needs (`make test`, `make ci-pr-lint`,
and the other Bazel lanes [engdocs/TESTING.md](engdocs/TESTING.md)
selects). If gates are broken on `main`, report it as a P0 issue.
2. Record follow-up work as GitHub issues (or ledger beads, for maintainers).
3. Commit, push, or open a PR only when the person you are working for asked
you to. Report changed files, validation run, and anything left open.
A live application of this rule: `bd doctor` support for embedded mode is
enabled one subcommand at a time, each human-vetted (GH#3794). Do not lift the
embedded-mode gate in `cmd/bd/doctor.go` wholesale, and keep database-layer
checks and fixes server-gated until the driver interface covers them.
## CLI output
## Agent Warning: Interactive Commands
**NEVER use emoji-style icons** (🔴🟠🟡🔵⚪) in CLI output. **ALWAYS use small
Unicode symbols** with semantic colors: status `○ ◐ ● ✓ ❄`; priority as a
`P0`–`P4` label with color (no status glyph). The full visual design system
and CLI design principles are in
[engdocs/UI_PHILOSOPHY.md](engdocs/UI_PHILOSOPHY.md).
**DO NOT use `bd edit`** - it opens an interactive editor ($EDITOR) which AI agents cannot use.
## Non-interactive shell commands
Use `bd update` with flags instead:
```bash
bd update <id> --description "new description"
bd update <id> --title "new title"
bd update <id> --design "design notes"
bd update <id> --append-notes "additional notes" # --notes replaces existing notes and requires --force once notes are set
bd update <id> --acceptance "acceptance criteria"
Agents cannot answer prompts. Use `cp -f`, `mv -f`, `rm -f`, `rm -rf`,
`cp -rf` (these may be aliased to `-i`); `scp`/`ssh -o BatchMode=yes`;
`apt-get -y`; `HOMEBREW_NO_AUTO_UPDATE=1 brew`. **DO NOT use `bd edit`** — it
opens `$EDITOR`; use `bd update <id> --title/--description/--design/--acceptance/--append-notes`
(pipe text with special characters via `--description=-`).
# Use stdin for descriptions with special characters (backticks, !, nested quotes)
echo 'Description with `backticks` and "quotes"' | bd create "Title" --description=-
echo 'Updated text' | bd update <id> --description=-
```
## Routing table
## Testing
| When you are touching… | Read first |
|---|---|
| `cmd/bd/` (commands, output, proxied-server routes) | [cmd/bd/AGENTS.md](cmd/bd/AGENTS.md) |
| `engdocs/` (contributor and internals docs) | [engdocs/AGENTS.md](engdocs/AGENTS.md) |
| `docs/` (the published user docs) | `.claude/skills/beads-docs/SKILL.md` |
| Any Go test | [engdocs/TESTING.md](engdocs/TESTING.md) |
| Lint failures or `.golangci.yml` | [engdocs/LINTING.md](engdocs/LINTING.md) |
| A new storage operation or issueops role | [engdocs/ADDING_AN_ISSUEOPS_ROLE.md](engdocs/ADDING_AN_ISSUEOPS_ROLE.md) |
| Schema migrations | [internal/storage/schema/migrations/README.md](internal/storage/schema/migrations/README.md) |
| Dolt concurrency, server vs embedded mode | [engdocs/design/dolt-concurrency.md](engdocs/design/dolt-concurrency.md) |
| Errors returned to users | [engdocs/ERROR_HANDLING.md](engdocs/ERROR_HANDLING.md) |
| The `bd serve` HTTP surface | [engdocs/SERVE_RUNBOOK.md](engdocs/SERVE_RUNBOOK.md) |
| A new example under `examples/` | `examples/README.md` — give the example its own README and link it there |
| Releases and version bumps | [RELEASING.md](RELEASING.md) |
| Scope questions | [engdocs/PROJECT_CHARTER.md](engdocs/PROJECT_CHARTER.md) |
| Planned work and priorities | [ROADMAP.md](ROADMAP.md) |
Use [engdocs/TESTING.md](engdocs/TESTING.md) for the canonical commands,
test-design guidance, and PR-readiness gates.
## Non-Interactive Shell Commands
**ALWAYS use non-interactive flags** with file operations to avoid hanging on confirmation prompts.
Shell commands like `cp`, `mv`, and `rm` may be aliased to include `-i` (interactive) mode on some systems, causing the agent to hang indefinitely waiting for y/n input.
**Use these forms instead:**
```bash
# Force overwrite without prompting
cp -f source dest # NOT: cp source dest
mv -f source dest # NOT: mv source dest
rm -f file # NOT: rm file
# For recursive operations
rm -rf directory # NOT: rm -r directory
cp -rf source dest # NOT: cp -r source dest
```
**Other commands that may prompt:**
- `scp` - use `-o BatchMode=yes` for non-interactive
- `ssh` - use `-o BatchMode=yes` to fail instead of prompting
- `apt-get` - use `-y` flag
- `brew` - use `HOMEBREW_NO_AUTO_UPDATE=1` env var
## Landing the Plane (Session Completion)
**When ending a work session** (or when the user says "let's land the
plane"), you MUST complete ALL steps below. Work is NOT complete until
`git push` succeeds.
**MANDATORY WORKFLOW:**
1. **File issues for remaining work** - Create issues for anything that needs follow-up
2. **Run quality gates** (if code changed):
- `make ci-pr-lint` (required zero-finding formatting and lint wrapper)
- `make test` (and `make test-icu-path` only if you intentionally need the ICU regex path)
- File a P0 issue if quality gates are broken
3. **Update issue status** - Close finished work, update in-progress items
4. **PUSH TO REMOTE** - This is MANDATORY:
```bash
git pull --rebase
git push
git status # MUST show "up to date with origin"
```
5. **Clean up**:
```bash
git stash clear # Remove old stashes
git remote prune origin # Clean up deleted remote branches
```
6. **Verify** - All changes committed AND pushed, no untracked files remain
7. **Hand off** - Choose a follow-up issue and give the user a prompt for
the next session, e.g. "Continue work on bd-X: [issue title]. [Brief
context about what's been done and what's next]"
**CRITICAL RULES:**
- Work is NOT complete until `git push` succeeds
- NEVER stop before pushing - that leaves work stranded locally
- NEVER say "ready to push when you are" - YOU must push
- If push fails, resolve and retry until it succeeds
Close with a summary for the user: what was completed this session, issues
filed for follow-up, quality-gate status, confirmation everything is pushed,
and the recommended prompt for the next session.
<!-- BEGIN BEADS INTEGRATION v:1 profile:full hash:bacef91e -->
## Issue Tracking with bd (beads)
**IMPORTANT**: This project uses **bd (beads)** for ALL issue tracking. Do NOT use markdown TODOs, task lists, or other tracking methods.
### Why bd?
- Dependency-aware: Track blockers and relationships between issues
- Git-friendly: Dolt-powered version control with native sync
- Agent-optimized: JSON output, ready work detection, discovered-from links
- Prevents duplicate tracking systems and confusion
### Quick Start
**Check for ready work:**
```bash
bd ready --json
```
**Create new issues:**
```bash
bd create "Issue title" --description="Detailed context" -t bug|feature|task -p 0-4 --json
bd create "Issue title" --description="What this issue is about" -p 1 --deps discovered-from:bd-123 --json
```
**Claim and update:**
```bash
bd update <id> --claim --json
bd update bd-42 --priority 1 --json
```
**Complete work:**
```bash
bd close bd-42 --reason "Completed" --json
```
### Issue Types
- `bug` - Something broken
- `feature` - New functionality
- `task` - Work item (tests, docs, refactoring)
- `epic` - Large feature with subtasks
- `chore` - Maintenance (dependencies, tooling)
### Priorities
- `0` - Critical (security, data loss, broken builds)
- `1` - High (major features, important bugs)
- `2` - Medium (default, nice-to-have)
- `3` - Low (polish, optimization)
- `4` - Backlog (future ideas)
### Workflow for AI Agents
1. **Check ready work**: `bd ready` shows unblocked issues
2. **Claim your task atomically**: `bd update <id> --claim`
3. **Work on it**: Implement, test, document
4. **Discover new work?** Create linked issue:
- `bd create "Found bug" --description="Details about what was found" -p 1 --deps discovered-from:<parent-id>`
5. **Complete**: `bd close <id> --reason "Done"`
### Quality
- Use `--acceptance` and `--design` fields when creating issues
- Use `--validate` to check description completeness
### Lifecycle
- `bd defer <id>` / `bd supersede <id>` for issue management
- `bd stale` / `bd orphans` / `bd lint` for hygiene
- `bd human <id>` to flag for human decisions
- `bd formula list` / `bd mol pour <name>` for structured workflows
### Sync
bd stores issue history in Dolt:
- Each write auto-commits to Dolt history
- Use `bd dolt push`/`bd dolt pull` for remote sync
- Do not treat `.beads/issues.jsonl` as the sync protocol
**Architecture in one line:** issues live in a local Dolt DB; sync uses `refs/dolt/data` on your git remote; `.beads/issues.jsonl` is a passive export. See https://github.com/gastownhall/beads/blob/main/docs/core-concepts/sync-concepts.md for details and anti-patterns.
### Important Rules
- ✅ Use bd for ALL task tracking
- ✅ Always use `--json` flag for programmatic use
- ✅ Link discovered work with `discovered-from` dependencies
- ✅ Check `bd ready` before asking "what should I work on?"
- ❌ Do NOT create markdown TODO lists
- ❌ Do NOT use external issue trackers
- ❌ Do NOT duplicate tracking systems
For more details, see README.md and https://github.com/gastownhall/beads/blob/main/docs/getting-started/quickstart.md.
## Agent Context Profiles
The managed Beads block is task-tracking guidance, not permission to override repository, user, or orchestrator instructions.
- **Conservative (default)**: Use `bd` for task tracking. Do not run git commits, git pushes, or Dolt remote sync unless explicitly asked. At handoff, report changed files, validation, and suggested next commands.
- **Minimal**: Keep tool instruction files as pointers to `bd prime`; use the same conservative git policy unless active instructions say otherwise.
- **Team-maintainer**: Only when the repository explicitly opts in, agents may close beads, run quality gates, commit, and push as part of session close. A current "do not commit" or "do not push" instruction still wins.
## Session Completion
This protocol applies when ending a Beads implementation workflow. It is subordinate to explicit user, repository, and orchestrator instructions.
1. **File issues for remaining work** - Create beads for anything that needs follow-up
2. **Run quality gates** (if code changed) - Tests, linters, builds
3. **Update issue status** - Close finished work, update in-progress items
4. **Handle git/sync by active profile**:
```bash
# Conservative/minimal/default: report status and proposed commands; wait for approval.
git status
# Team-maintainer opt-in only, unless current instructions forbid it:
git pull --rebase
bd dolt push
git push
git status
```
5. **Hand off** - Summarize changes, validation, issue status, and any blocked sync/commit/push step
**Critical rules:**
- Explicit user or orchestrator instructions override this Beads block.
- Do not commit or push without clear authority from the active profile or the current user request.
- If a required sync or push is blocked, stop and report the exact command and error.
<!-- END BEADS INTEGRATION -->

View file

@ -1,9 +1,537 @@
# Agent Instructions
# Detailed Agent Instructions for Beads Development
Contributor instructions for agents developing beads live in
[AGENTS.md](AGENTS.md). Area-specific rules live in nested `AGENTS.md` files
listed in its routing table.
**For project overview and quick start, see [AGENTS.md](AGENTS.md)**
If you are using `bd` to track work in your own project, see the user docs:
[IDE and agent setup](docs/getting-started/ide-setup.md) and
[https://beads.gascity.com/](https://beads.gascity.com/).
This document contains detailed operational instructions for AI agents working on beads development, testing, and releases.
## Development Guidelines
### Code Standards
- **Go version**: see `go.mod` for the required version (currently 1.26+)
- **Linting**: `make ci-pr-lint` must pass with zero issues; see
[engdocs/LINTING.md](engdocs/LINTING.md)
- **Testing**: All new features need tests; use [engdocs/TESTING.md](engdocs/TESTING.md) for command selection, test design, and PR readiness.
- **Documentation**: Update relevant .md files
### File Organization
```
beads/
├── cmd/bd/ # CLI commands
├── internal/
│ ├── types/ # Core data types
│ └── storage/ # Storage layer
│ └── dolt/ # Dolt implementation
├── examples/ # Integration examples
└── *.md # Documentation
```
### Testing Workflow
**IMPORTANT:** Never pollute the production database with test issues!
For test commands, tier selection, and test-design guidance, use the canonical
[engdocs/TESTING.md](engdocs/TESTING.md).
**For manual testing**, keep initialization and all experiments in a disposable
working directory. This safety example supplements the canonical testing guide:
```bash
beads_manual_dir="$(mktemp -d)"
(
set -e
cd "$beads_manual_dir"
bd init --quiet --prefix test --skip-hooks --skip-agents
bd create "Test issue" -p 1
)
rm -rf -- "$beads_manual_dir"
```
`BEADS_DB` alone does not redirect `bd init` workspace setup. Do not run manual
initialization from a production workspace even when selecting another database.
**For automated tests**, use `t.TempDir()` in Go tests:
```go
func TestMyFeature(t *testing.T) {
tmpDir := t.TempDir()
testDB := filepath.Join(tmpDir, ".beads", "beads.db")
s := newTestStore(t, testDB)
// ... test code
}
```
**Git test isolation:** For tests that create temporary git repos, force repo-local hooks:
```bash
git config core.hooksPath .git/hooks
```
Do not rely on the developer's global git config. Global `core.hooksPath` can leak
into temp repos and produce flaky test behavior.
**Warning:** bd will warn you when creating issues with a "Test" prefix in the
production database. The disposable working directory is the isolation
boundary for manual initialization and experiments.
**Tmpfs hosts:** the `cmd/bd` test suite creates an isolated `$HOME` and several
test binaries under `$TMPDIR`. They are normally cleaned by the test process,
but a SIGKILLed or OOMed run can leave orphans behind. On hosts where `/tmp`
is tmpfs (e.g. Fedora Atomic / Bluefin), run `make clean-test-tmp` between
test runs if `du -sh /tmp/beads-* /tmp/bd-*` shows accumulation. See bd-3q2u.
### Before Committing
1. **Run tests**: follow [engdocs/TESTING.md](engdocs/TESTING.md).
2. **Run the required lint contract when its code surface changed**:
`make ci-pr-lint`
3. **Update docs**: If you changed behavior, update README.md or other docs
4. **Sync Bazel BUILD files** if you added, removed or renamed Go files, or
changed imports or `go.mod`: `make bazel-sync` (needs Bazel), then commit
the BUILD.bazel / MODULE.bazel changes. Without Bazel, let CI do it: on
same-repo PRs the bazel-autofix workflow pushes the fix for the packages
your PR changed to your branch (pull before pushing again); fork PRs get
a comment with an apply recipe.
5. **Commit**: With git hooks installed (`bd hooks install`), Dolt changes are auto-committed
### Commit Message Convention
When committing work for an issue, include the issue ID in parentheses at the end:
```bash
git commit -m "Fix auth validation bug (bd-abc)"
git commit -m "Add retry logic for database locks (bd-xyz)"
```
This enables `bd doctor` to detect **orphaned issues** - work that was committed but the issue wasn't closed. The doctor check cross-references open issues against git history to find these orphans.
For agent-prepared commits, also include the
`Agent-Signature:` trailer described in
[engdocs/AGENT_SIGNING.md](engdocs/AGENT_SIGNING.md). Use `unknown-model` or
`unknown-reasoning` when reliable runtime metadata is unavailable.
### Git Workflow
bd uses **Dolt** as its primary database. Changes are committed to Dolt history automatically (one Dolt commit per write command).
**Install git hooks** for commit integration and legacy fallback behavior:
```bash
bd hooks install
```
### Git Integration
**Dolt sync**: Dolt handles sync natively via `bd dolt push` / `bd dolt pull`. No export/import round-trip needed for normal sync.
**Protected branches**: Dolt stores data under `refs/dolt/data`, separate from standard Git refs. See [docs/reference/protected-branches.md](docs/reference/protected-branches.md).
**Git worktrees**: Work directly with Dolt — no special flags needed. See [docs/reference/advanced.md](docs/reference/advanced.md).
**Merge conflicts**: Rare with hash IDs. Dolt uses cell-level 3-way merge for conflict resolution.
## Git Workflow: PR by Default
Crew workers use a PR-based workflow. Beads is a dependency of a downstream consumer, so we
defer to the standard PR flow to keep changes reviewable.
- Work on a feature branch, push the branch, open a PR against `main`
- `gh pr create` is the normal path to land work
- Direct push to main is reserved for releases (tag + release commit) and
narrow operational fixes; prefer a PR when unsure
- When handling external contributor PRs, use fix-merge: checkout the PR
branch locally, fix/rebase onto main, merge via PR, then close the PR
### Maintainer PR Guidelines
Before triaging, reviewing, landing, closing, or otherwise maintaining PRs,
read [PR_MAINTAINER_GUIDELINES.md](PR_MAINTAINER_GUIDELINES.md). The
maintainer policy is to maximize community throughput: find useful contributor
value, absorb or transform it locally when practical, preserve attribution, and
use request-changes only as a last resort.
Sign agent-written GitHub comments and reviews using
[engdocs/AGENT_SIGNING.md](engdocs/AGENT_SIGNING.md).
### External Contributor PRs: Check Before You Build
**Read [CONTRIBUTING.md](CONTRIBUTING.md)** — it contains promises we've made to contributors. Violating them damages trust and community.
Run the read-only preflight before implementing related work, opening a PR, or
merging/closing a PR:
```bash
scripts/pr-preflight.sh --search "<topic keywords>" --repo gastownhall/beads
scripts/pr-preflight.sh <pr-number> --repo gastownhall/beads
```
**Before implementing any feature or fix, check for existing open PRs on the same topic:**
```bash
gh pr list --repo gastownhall/beads --state open --search "<topic keywords>" --json number,title,author,headRefName
```
**Contributor work gets priority.** If an external PR already exists:
1. **Review it first** — read the diff, understand the approach
2. **Build on their work, don't rewrite it** — checkout their branch, fix/adapt as needed
3. **Preserve their tests** — contributor tests are signal; keep them unless they're wrong
4. **Attribute properly** — use `Co-authored-by:` in commits, reference their PR number
5. **Never auto-close a contributor PR** by merging a rewrite — that discards their contribution silently
If you must rewrite (e.g., fundamentally different approach needed), explain why on the original PR and credit the contributor's design/tests in your commits.
Do not rely on auto-discovery of CONTRIBUTING.md; the preflight is the agent
gate for PR handling.
## Landing the Plane
See [AGENTS.md](AGENTS.md#landing-the-plane-session-completion) for the
canonical session-completion protocol (quality gates, mandatory `git push`,
cleanup, and next-session hand-off).
## Agent Session Workflow
**WARNING: DO NOT use `bd edit`** - it opens an interactive editor ($EDITOR) which AI agents cannot use. Use `bd update` with flags instead:
```bash
bd update <id> --description "new description"
bd update <id> --title "new title"
bd update <id> --design "design notes"
bd update <id> --append-notes "additional notes" # --notes replaces existing notes and requires --force once notes are set
bd update <id> --acceptance "acceptance criteria"
```
**Read execution metadata before prose.** When enacting a bd issue, inspect the
structured metadata before using description or notes to choose execution mode,
delegation, model, reasoning level, or parallel group:
```bash
bd show <id> --json | jq '.[0] | {id,title,metadata,description,notes}'
```
The execution metadata keys are:
- `execution_agent_type`
- `execution_suggested_model`
- `execution_reasoning_effort`
- `execution_mode`
- `execution_parallel_group`
When these keys are present, treat them as the authoritative execution hints.
Use `description` for the work scope and `notes` for rationale or fallback
context. Parent/orchestrator agents must read these fields before spawning
subagents because a running subagent cannot change its model or reasoning effort
after launch.
**Use stdin for descriptions with special characters** (backticks, `!`, nested quotes):
```bash
# Pipe via stdin to avoid shell escaping issues
echo 'Description with `backticks` and "quotes"' | bd create "Title" --stdin
echo 'Updated description with $variables' | bd update <id> --description=-
# Or use --body-file for longer content
bd create "Title" --body-file=description.md
```
**GitHub body hygiene.** For GitHub PR, issue, comment, and review bodies,
write Markdown to a file and pass it with `gh ... --body-file`. Run
`scripts/gh-body-lint <body-file>` first to catch literal `\n` sequences and
non-linking `GH#123` references.
**Example agent session:**
```bash
# Make changes (each write auto-commits to Dolt)
bd create "Fix bug" -p 1
bd create "Add tests" -p 1
bd update bd-42 --claim
bd close bd-40 --reason "Completed"
# Push Dolt data to remote if configured
bd dolt push
# Now safe to end session
```
This installs:
- **pre-commit** — Commits pending Dolt changes
- **post-merge** — Runs chained hooks and a legacy JSONL import fallback only when no Dolt remote is configured
**Note:** Hooks are embedded in the bd binary and work for all bd users (not just source repo users).
## Common Development Tasks
### Visual Design System
When adding CLI output features, follow these design principles for consistent,
cognitively friendly visuals.
#### No Emoji-Style Icons
Do not use large colored emoji icons like red/orange/yellow/blue/white circles
for priorities or status. They cause cognitive overload and break visual
consistency.
Use small Unicode symbols with semantic colors applied via lipgloss:
- Status: `○ ◐ ● ✓ ❄`
- Priority: `P0`–`P4` label with color (no status glyph)
#### Status Icons
Use these symbols consistently across all commands:
```text
○ open - Available to work (white/default)
◐ in_progress - Currently being worked (yellow)
● blocked - Waiting on dependencies (red)
✓ closed - Completed (muted gray)
❄ deferred - Scheduled for later (blue/muted)
```
#### Priority Labels and Colors
Format priority as the P-label with color only (no status glyph — `●` is blocked status):
- `P0`: Red + bold (critical)
- `P1`: Orange (high)
- `P2`: Amber (elevated)
- `P3`–`P4`: Default text
#### Issue Type Colors
- `bug`: Red (problems need attention)
- `epic`: Purple (larger scope)
- Others: Default text
#### Design Principles
1. Small Unicode symbols only; avoid emoji blobs.
2. Semantic colors only for actionable items; do not color everything.
3. Closed items fade using muted gray.
4. Prefer icons over text labels for scanability.
5. Keep icons consistent across list, graph, show, and related commands.
6. Use tree connectors (`├──`, `└──`, `│`) for hierarchies.
7. Reduce cognitive noise; do not show `needs:1` when it is just the parent epic.
#### Semantic Styles
Use exported styles from `internal/ui/styles.go`:
```go
// Status styles
ui.StatusInProgressStyle // Yellow - active work
ui.StatusBlockedStyle // Red - needs attention
ui.StatusClosedStyle // Muted gray - done
// Priority styles
ui.PriorityP0Style // Red + bold
ui.PriorityP1Style // Orange
// Type styles
ui.TypeBugStyle // Red
ui.TypeEpicStyle // Purple
// General styles
ui.PassStyle, ui.WarnStyle, ui.FailStyle
ui.MutedStyle, ui.AccentStyle
ui.RenderMuted(text), ui.RenderAccent(text)
```
Example:
```go
switch issue.Status {
case types.StatusOpen:
icon = "○"
case types.StatusInProgress:
icon = ui.StatusInProgressStyle.Render("◐")
case types.StatusBlocked:
icon = ui.StatusBlockedStyle.Render("●")
case types.StatusClosed:
icon = ui.StatusClosedStyle.Render("✓")
}
```
### CLI Design Principles
**Minimize cognitive overload.** Every new command, flag, or option adds cognitive burden for users. Before adding anything:
1. **Recovery/fix operations → `bd doctor --fix`**: Don't create separate commands like `bd recover` or `bd repair`. Doctor already detects problems - let `--fix` handle remediation. This keeps all health-related operations in one discoverable place.
For git hook marker migration specifically: use `bd migrate hooks --dry-run` to preview operations, and `bd doctor --fix` for the standard apply path.
2. **Prefer flags on existing commands**: Before creating a new command, ask: "Can this be a flag on an existing command?" Example: `bd list --stale` instead of `bd stale`.
3. **Consolidate related operations**: Related operations should live together. Version control uses `bd vc {log,diff,commit}`, not separate top-level commands.
4. **Count the commands**: Run `bd --help` and count. If we're approaching 30+ commands, we have a discoverability problem. Consider subcommand grouping.
5. **New commands need strong justification**: A new command should represent a fundamentally different operation, not just a convenience wrapper.
### Adding a New Command
1. Create file in `cmd/bd/`
2. Add to root command in `cmd/bd/main.go`
3. Implement with Cobra framework
4. Add `--json` flag for agent use
5. Add tests in `cmd/bd/*_test.go`
6. Document in README.md
### Adding Storage Features
1. Add Dolt SQL schema changes in `internal/storage/dolt/`
2. Add migration if needed
3. Update `internal/types/types.go` if new types
4. Implement in `internal/storage/dolt/` (queries, issues, etc.)
5. Add tests
6. Update export/import in `cmd/bd/export.go` and `cmd/bd/import.go`
### Adding Examples
1. Create directory in `examples/`
2. Add README.md explaining the example
3. Include working code
4. Link from `examples/README.md`
5. Mention in main README.md
## Building
```bash
# Build and install bd to ~/.local/bin (the canonical location)
make install
# Verify installed binary
bd init --prefix test
bd create "Test issue" -p 1
bd ready
```
For testing commands, test design, and PR-readiness gates, use
[engdocs/TESTING.md](engdocs/TESTING.md).
> **WARNING**: Do NOT use `go build -o bd ./cmd/bd`, `go install ./cmd/bd`,
> or raw `go run ./cmd/bd ...`.
> These bypass the canonical build path, can create stale binaries in the
> working directory or `~/go/bin/`, and raw `go run` may miss the required
> `gms_pure_go` build tag. Always use `make install`, `./bd`, or
> `go run -tags gms_pure_go ./cmd/bd ...` when you explicitly need `go run`.
## Version Management
**IMPORTANT**: When the user asks to "bump the version" or mentions a new version number (e.g., "bump to 0.9.3"), use the version bump script:
```bash
# Preview changes (shows diff, doesn't commit)
./scripts/bump-version.sh 0.9.3
# Auto-commit the version bump
./scripts/bump-version.sh 0.9.3 --commit
git push origin main
```
**What it does:**
- Updates ALL version files (CLI, plugin, MCP server, docs) in one command
- Validates semantic versioning format
- Shows diff preview
- Verifies all versions match after update
- Creates standardized commit message
**User will typically say:**
- "Bump to 0.9.3"
- "Update version to 1.0.0"
- "Rev the project to 0.9.4"
- "Increment the version"
**You should:**
1. Run `./scripts/bump-version.sh <version> --commit`
2. Push to GitHub
3. Confirm all versions updated correctly
**Files updated automatically:**
- `cmd/bd/version.go` - CLI version
- `plugins/beads/.claude-plugin/plugin.json` - Claude plugin version
- `plugins/beads/.codex-plugin/plugin.json` - Codex plugin version
- `.claude-plugin/marketplace.json` - Claude marketplace version
- `integrations/beads-mcp/pyproject.toml` - MCP server version
- `README.md` - Documentation version
- `PLUGIN.md` - Version requirements
**Why this matters:** We had version mismatches (bd-66) when only `version.go` was updated. This script prevents that by updating all components atomically.
See `scripts/README.md` for more details.
## Release Process (Maintainers)
See [RELEASING.md](RELEASING.md) for the complete release process, including
the automated `./scripts/release.sh <version>` script and the manual,
step-by-step channel-by-channel instructions.
## Checking GitHub Issues and PRs
**IMPORTANT**: When asked to check GitHub issues or PRs, use command-line tools like `gh` instead of browser/playwright tools.
**Preferred approach:**
```bash
# List open issues with details
gh issue list --limit 30
# List open PRs
gh pr list --limit 30
# View specific issue
gh issue view 201
```
**Then provide an in-conversation summary** highlighting:
- Urgent/critical issues (regressions, bugs, broken builds)
- Common themes or patterns
- Feature requests with high engagement
- Items that need immediate attention
**Why this matters:**
- Browser tools consume more tokens and are slower
- CLI summaries are easier to scan and discuss
- Keeps the conversation focused and efficient
- Better for quick triage and prioritization
**Do NOT use:** `browser_navigate`, `browser_snapshot`, or other playwright tools for GitHub PR/issue reviews unless specifically requested by the user.
## Telemetry
`bd` collects anonymous command-usage metrics. Each event is a `cli_command`
record carrying only the command name; each batch also carries the bd version
and OS platform, keyed by a machine-derived, HMAC-protected distinct ID. No
email, repo path, remote URL, issue content, or user-supplied strings are
collected. Events are written under `~/.beads/eventsData` and POSTed to
`https://gastownhall-eventsapi.com/mp/collect`.
Metrics are enabled by default (opt-out). The friendliest way to see or change
them is `bd metrics` (`bd metrics on` / `bd metrics off` / `bd metrics example`),
which takes effect on the next command with no restart. `BD_DISABLE_METRICS=1`
still works as a one-off, shell-scoped override. The cross-tool
[`DO_NOT_TRACK`](https://donottrack.sh/) standard is honored as a disable-only
opt-out: `DO_NOT_TRACK=1` opts out, while a falsey or empty value
(`DO_NOT_TRACK=0`, `false`, or unset-but-present) falls through to your saved
`bd metrics` preference instead of forcing metrics back on. `BD_DISABLE_METRICS`
is the bidirectional override and takes precedence when both are set.
## Questions?
- Check existing issues: `bd list`
- Look at recent commits: `git log --oneline -20`
- Read the docs: README.md, ADVANCED.md, docs/reference/configuration.md
- Create an issue if unsure: `bd create "Question: ..." -t task -p 2`
## Important Files
- **README.md** - Main documentation (keep this updated!)
- **ADVANCED.md** - Advanced features (rename, merge, compaction)
- **CONTRIBUTING.md** - Contribution guidelines
- **SECURITY.md** - Security policy

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1 +0,0 @@
AGENTS.md

23
CLAUDE.md Normal file
View file

@ -0,0 +1,23 @@
# Claude Code Entry Point for Beads
This file is intentionally short. Do not copy workflow, build, storage, or UI
rules here; those details drift quickly when repeated across agent entrypoints.
## Read First
- **Workflow and safety**: [AGENTS.md](AGENTS.md)
- **Detailed agent operations**: [AGENT_INSTRUCTIONS.md](AGENT_INSTRUCTIONS.md)
- **Architecture orientation**: [engdocs/CLAUDE.md](engdocs/CLAUDE.md)
- **PR maintenance policy**: [PR_MAINTAINER_GUIDELINES.md](PR_MAINTAINER_GUIDELINES.md)
## Current Ground Rules
- Run `bd prime` before doing tracked work.
- Follow `go.mod` and [AGENT_INSTRUCTIONS.md](AGENT_INSTRUCTIONS.md) for build
and test commands; do not hard-code toolchain versions here.
- Beads uses Dolt as the issue database. Use `bd dolt push` / `bd dolt pull`
for issue data sync; do not use export/import as a routine git workflow.
- The CLI Visual Design System lives in
[AGENT_INSTRUCTIONS.md](AGENT_INSTRUCTIONS.md#visual-design-system).
- If this file conflicts with a linked source, trust the linked source and fix
this file by removing the duplicate.

View file

@ -2,65 +2,14 @@
Thank you for your interest in contributing to bd! This document provides guidelines and instructions for contributing.
## Issues and pull requests
GitHub Issues is the public tracker. Use an issue when it adds context
reviewers need: a user-visible bug, a behavior or design change worth
discussing first, or work that spans several pull requests. The issue holds
why the change is needed, what it affects, and how we will know it works; file
it with the bug or feature form before or alongside your pull request, and it
does not need maintainer approval first. Small, self-explanatory changes
(typos, flaky tests, refactors, CI or docs tweaks) can go straight to a pull
request whose description explains the why.
### Triage labels
| Label | Meaning | Applied by |
|---|---|---|
| `status/needs-triage` | Awaiting initial triage. | Automation, on every new issue |
| `status/needs-info` | Waiting on essential information from the reporter. | Maintainers |
| `status/needs-repro` | Needs a reproducible bug report. | Maintainers |
| `status/needs-design` | The direction needs a design decision before work starts. | Maintainers |
| `status/accepted` | Confirmed and on our radar. | Maintainers |
Issues left in `status/needs-info` or `status/needs-repro` are closed after 14
days without a reply to the request; reply with the details and a
maintainer will reopen them.
Priority (`priority/p0`–`priority/p3`) and kind (`kind/bug`, `kind/feature`,
`kind/docs`, `kind/chore`) labels are set during triage.
### Pull request pipeline labels
These labels drive the maintainers' automated review and merge workflow. They
are applied by maintainers and automation; contributors don't need to set
them.
| Label | Meaning |
|---|---|
| `status/needs-review` | Request the PR review workflow. |
| `status/needs-review-auto` | Request the automated PR review workflow. |
| `status/reviewing` | The PR review workflow is running. |
| `status/review-failed` | The PR review workflow failed before merge-ready. |
| `status/merge-ready` | The PR is ready for the merge workflow. |
| `status/merge-queued` | Queued for deterministic PR-review merge. |
| `status/merge-failed` | The merge queue needs operator attention. |
| `status/needs-bugflow` | Request the bugflow investigation workflow. |
The current priorities are on the [roadmap](ROADMAP.md); work in a priority
area is reviewed first.
## Development Setup
### Prerequisites
- [Bazelisk](https://github.com/bazelbuild/bazelisk), installed as `bazel`
(it reads `.bazelversion`). **Required:** Bazel is the build and test system
CI gates on, and the pre-commit (nogo lint) and pre-push (test suite) hooks
run it.
- Go (see `go.mod` for the required version; currently 1.26+), for `make
install` and the `go test` inner loop
- Go (see `go.mod` for the required version; currently 1.26+)
- Git
- A C compiler (CGO is required for the embedded Dolt database)
- golangci-lint v2.10.1 for the required local lint gate
- ICU headers are **not required** for building -- see [engdocs/ICU-POLICY.md](engdocs/ICU-POLICY.md)
### Getting Started
@ -70,44 +19,16 @@ area is reviewed first.
git clone https://github.com/gastownhall/beads
cd beads
# Read rbe-west's anonymous, read-only cache: everything CI already built and
# tested is a cache hit, and nothing you build is uploaded.
echo 'build --config=fork-cache' >> .bazelrc.local
# Build the project (uses gms_pure_go tag via Makefile)
make build
# Run the test suite CI gates on (bazel test //... --config=ci)
# Run tests (uses correct build tags automatically)
make test
# Build and install bd to ~/.local/bin (also enables the git hooks)
# Build and install locally to ~/.local/bin
make install
```
### Building and Testing
Bazel is the gate: `.github/workflows/bazel.yml` runs every pull request's
tests as `bazel test` lanes, and nogo (lint + vet), gofmt and the repository
guards exist only as Bazel targets. The make targets run the same commands:
| Command | Runs |
|---|---|
| `make test` | `bazel test //... --config=ci`: the test lane (unit tests, nogo, gofmt, repository guards) |
| `make check` | the testing.Short policy, `make ci-pr-lint` and `make test` |
| `make ci-pr-lint` | nogo natively plus the windows/amd64 and darwin/arm64 passes |
| `make check-docs` | the Bazel docsync and doc-freshness tests, then the CLI flag check |
| `bazel test //... --config=integration` | the integration lane; [engdocs/TESTING.md](engdocs/TESTING.md) lists every other lane's command |
Where actions run is your choice, set in the gitignored `.bazelrc.local` (or
per command with `make test BAZEL_FLAGS=--config=...`):
- `--config=fork-cache` (contributors): reads the anonymous cache, runs misses
on your machine, uploads nothing.
- `--config=remote-exec` (maintainers with an rbe-west client certificate):
executes remotely; the executor and TLS lines stay in your `user.bazelrc` or
`.bazelrc.local`.
`go test` (`./scripts/test.sh`, or `make test-go` / `make check-go` /
`make check-docs-go`) still works as an inner-loop convenience, but CI does not
enforce it and it skips nogo, gofmt and the guards. Finish with `make test`.
## Project Structure
```
@ -117,7 +38,7 @@ beads/
│ ├── types/ # Core data types (Issue, Dependency, etc.)
│ └── storage/ # Storage interface and implementations
│ └── dolt/ # Dolt database backend
├── .golangci.yml # Linter configuration (applied by nogo, tools/nogo)
├── .golangci.yml # Linter configuration
└── .github/workflows/ # CI/CD pipelines
```
@ -140,24 +61,23 @@ We follow standard Go conventions:
### Linting
Lint and vet run as nogo under Bazel: go test's vet checks plus the
golangci-lint linters `.golangci.yml` enables, the same analyzers CI gates on.
Use the same pinned golangci-lint version and repository-owned wrapper as CI:
```bash
# Run the required lint and vet gate (native, windows and darwin)
make ci-pr-lint
# Install the version pinned by CI
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.10.1
# Faster: only the Bazel packages of your changed Go files
make lint-changed
# Run the required formatting and lint contract
make ci-pr-lint
```
`make ci-pr-lint` must pass with zero issues. It analyzes the repository's
normal `gms_pure_go` build and cross-checks the Windows- and macOS-only
non-cgo code. Accepted intentional patterns are encoded narrowly in
`.golangci.yml`; do not ignore a failing baseline. See
[engdocs/LINTING.md](engdocs/LINTING.md) for the full policy.
`make ci-pr-lint` must pass with zero issues. It checks formatting, lints the
repository's normal `gms_pure_go` build, and cross-lints Windows-only non-CGO
code. Accepted intentional patterns are encoded narrowly in `.golangci.yml`;
do not ignore a failing baseline. See [engdocs/LINTING.md](engdocs/LINTING.md)
for the full policy.
CI runs the same analyzers on all pull requests, in the Bazel test lane.
CI runs the same required wrapper on all pull requests.
## Making Changes
@ -170,23 +90,21 @@ engine, or expand the database schema when issue metadata is sufficient.
### Workflow
1. If the change warrants one, find or file an issue (see [Issues and pull requests](#issues-and-pull-requests))
2. Fork the repository and create a feature branch (`git checkout -b feature/my-feature`)
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/my-feature`)
3. Make your changes
4. Add tests for new functionality
5. Run tests and linter locally
6. Commit your changes with clear messages
7. Push to your fork
8. Open a pull request that explains the change and says `Closes #<issue>` when there is one
8. Open a pull request
### Commit Messages
Use [Conventional Commits](https://www.conventionalcommits.org/):
`type(scope): summary`, where type is one of `fix`, `feat`, `docs`, `test`,
`refactor`, `chore`, `ci`, or `perf`.
Write clear, concise commit messages:
```
feat(dep): add cycle detection for dependency graphs
Add cycle detection for dependency graphs
- Implement recursive CTE-based cycle detection
- Add tests for simple and complex cycles
@ -197,10 +115,6 @@ feat(dep): add cycle detection for dependency graphs
**One issue per PR, and one PR per issue.** No piggybacking or riders — each PR should address exactly one thing.
Read [CONTRIBUTING_PR_GUIDELINES.md](CONTRIBUTING_PR_GUIDELINES.md) for the
layering rules (schema → storage/issueops → cmd/bd, one layer per PR) and the
repro and benchmark evidence reviewers expect.
- Keep PRs focused on a single feature or fix
- Do not include unrelated changes, cleanup, or "while I'm here" improvements
- Do not include `.beads/` data (database, JSONL) in your PR
@ -224,8 +138,7 @@ For test commands, test design, and PR-readiness gates, see the canonical
- Follow the proportional validation budget in
[engdocs/TESTING.md](engdocs/TESTING.md): docs-only changes use docs checks;
Go changes use focused and affected-package tests plus one final `make test`
(the Bazel test lane).
Go changes use focused and affected-package tests plus one final `make test`.
- If you hit a test failure unrelated to your change, don't silently skip
it -- check `.test-skip` and file an issue if it's not already tracked
(see [engdocs/TESTING.md](engdocs/TESTING.md#failures-skips-and-review)).
@ -265,12 +178,22 @@ round-trip paths should pattern-match on those tests.
## Feature Requests and Bug Reports
Use the issue forms: [bug report](https://github.com/gastownhall/beads/issues/new?template=bug_report.yml)
or [feature request](https://github.com/gastownhall/beads/issues/new?template=feature_request.yml).
The feature form asks for the motivation, impact, risk and compatibility,
and verification plan up front, so a maintainer can accept the issue without
a round trip. Questions go to
[Discussions](https://github.com/gastownhall/beads/discussions).
### Reporting Bugs
Include in your bug report:
- Steps to reproduce
- Expected behavior
- Actual behavior
- Version of bd (`bd version` if implemented)
- Operating system and Go version
### Feature Requests
When proposing new features:
- Explain the use case
- Describe the proposed solution
- Consider backwards compatibility
- Discuss alternatives you've considered
## Your PR Will Not Be Overwritten
@ -368,7 +291,7 @@ docker run --rm -v $(pwd):/workspace -w /workspace nixos/nix \
If the build fails with a `vendorHash` mismatch, run `./scripts/update-nix-vendorhash.sh` to recompute and update `default.nix`, or update it manually with the `got:` hash from the error message and rebuild.
On a PR, this is covered by PR Risk's required `test-nix` job (`.github/workflows/pr-risk.yml`), which runs `nix run .#default -- --help` plus `nix flake check -L` (an evaluation of every flake output; the flake has no test checks) on every PR touching `go.mod`, `go.sum`, `default.nix`, `flake.nix`, or `flake.lock` -- a superset of plain `nix build .#default`. `.github/workflows/nix-build.yml` dropped its own `pull_request` trigger as redundant (F7c, spec-f7.md §2.4) and now only runs `nix build .#default` on push to `main` and on `workflow_dispatch`, so dependabot bumps that invalidate `vendorHash` still fail loudly post-merge instead of silently breaking Nix users on main. For dependabot Go-module bumps specifically, `.github/workflows/update-vendor-hash.yml` runs the same `update-nix-vendorhash.sh` script and pushes the hash bump back to the dependabot branch automatically (note: GitHub does not retrigger `pull_request` workflows for `GITHUB_TOKEN`-authored commits, so a maintainer may need to re-run PR Risk's `test-nix` once after the auto-fix push to mark the gate green).
The `nix build` CI job (`.github/workflows/nix-build.yml`) runs on any PR that touches `go.mod`, `go.sum`, `default.nix`, `flake.nix`, or `flake.lock`, so dependabot bumps that invalidate `vendorHash` fail loudly instead of silently breaking Nix users on main. For dependabot Go-module bumps specifically, `.github/workflows/update-vendor-hash.yml` runs the same `update-nix-vendorhash.sh` script and pushes the hash bump back to the dependabot branch automatically (note: GitHub does not retrigger `pull_request` workflows for `GITHUB_TOKEN`-authored commits, so a maintainer may need to re-run `nix build .#default` once after the auto-fix push to mark the gate green).
### Debugging
@ -386,15 +309,11 @@ dlv debug ./cmd/bd -- create "Test issue"
(For maintainers)
Follow [RELEASING.md](RELEASING.md); it is the canonical release process.
The pre-push version gate requires Go and validates each `v*` release tag
against the checkout's canonical version. A batch containing different release
versions is refused; push only the tag matching this checkout.
`bd preflight` finds the nearest Beads source module by walking ancestor
directories, checking both source markers and the module identity. Its version
check runs directly in Go; `scripts/check-versions.sh` remains a Bash entrypoint.
1. Update version in code
2. Update CHANGELOG.md
3. Tag release: `git tag v0.x.0`
4. Push tag: `git push origin v0.x.0`
5. GitHub Actions will build and publish
## Questions?

View file

@ -5,194 +5,8 @@ module(
bazel_dep(name = "platforms", version = "1.1.0")
bazel_dep(name = "rules_go", version = "0.63.0")
# nogo honors //nolint directives through ast.CommentMap ranges, which differ
# from golangci-lint's (a comment trailing `func f(...) {` attaches to the
# body's first statement). This tree's directives were written against
# golangci-lint, so the patch adds golangci-lint's ranges as well.
single_version_override(
module_name = "rules_go",
patch_strip = 1,
patches = ["//third_party/patches:rules_go_nogo_golangci_nolint.patch"],
version = "0.63.0",
)
bazel_dep(name = "gazelle", version = "0.53.0")
bazel_dep(name = "rules_shell", version = "0.6.1")
bazel_dep(name = "toolchains_llvm", version = "1.11.0")
# Loaded by @llvm_dist_linux_x86_64's BUILD file (toolchains_llvm's template).
bazel_dep(name = "rules_cc", version = "0.2.17")
# Hermetic C/C++ toolchain, ported from gastownhall/gascity. rules_go builds
# the Go stdlib under -race and every cgo package (mattn/go-sqlite3, gozstd,
# ...) with the registered C toolchain, and every Go compile depends on the
# stdlib, so a host-detected toolchain (local_config_cc: CC=/usr/bin/gcc,
# -fuse-ld=lld only where the CLIENT has lld, gcc-version-specific generated
# inputs) keys those actions to the machine that ran the analysis and fails
# remotely on workers without lld. Instead: LLVM pinned by sha256, plus a
# sysroot of pinned Ubuntu 24.04 packages (the RBE workers' release, so
# binaries load the same glibc and libstdc++ there), byte-identical on every
# Linux x86_64 host. No ICU: beads builds go-mysql-server with its pure-Go
# regex backend (engdocs/ICU-POLICY.md), so nothing may link libicu. .bazelrc
# turns host detection off so nothing falls back to the host compiler;
# scripts/bazel_hermetic_cc_test.go guards both.
deb_sysroot = use_repo_rule("//third_party/cc_toolchain:deb_sysroot.bzl", "deb_sysroot")
# Where every pinned Ubuntu 24.04 package below comes from, tried in order
# (the sha256 pins, not the source, decide what is accepted):
# - gascity's content-addressed mirror, a release holding each pinned
# .deb as <sha256>.deb (gascity's tools/cc_toolchain/mirror_debs.sh
# publishes it; gascity pins the same packages), so a cold fetch does not
# depend on Canonical's servers;
# - the snapshot these packages were pinned from (immutable, but a single
# host that returns 503 for minutes at a time);
# - Launchpad's librarian, which keeps every file ever published to the
# primary archive, superseded versions included;
# - archive.ubuntu.com, which drops superseded versions.
NOBLE_DEB_URLS = [
"https://github.com/gastownhall/gascity/releases/download/toolchain-noble-debs-20261001/{sha256}.deb",
"https://snapshot.ubuntu.com/ubuntu/20261001T000000Z/{path}",
"https://launchpad.net/ubuntu/+archive/primary/+files/{file}",
"https://archive.ubuntu.com/ubuntu/{path}",
]
deb_sysroot(
name = "cc_sysroot_noble_amd64",
packages = {
"pool/main/g/gcc-13/libgcc-13-dev_13.3.0-6ubuntu2~24.04.1_amd64.deb": "cd689db2691edaa10f37329307292796bb599e722e0505c79e14caaa1fe9a93a",
"pool/main/g/gcc-13/libstdc++-13-dev_13.3.0-6ubuntu2~24.04.1_amd64.deb": "ee5633e863e19c3381ed97842ce35ed32ede96a3d1ae4e94c051d3036fe21347",
"pool/main/g/gcc-14/libgcc-s1_14.2.0-4ubuntu2~24.04.1_amd64.deb": "aa7fadbe33b78bcf99885318040601c550c208929565b179891d9a3cc2aa68cd",
"pool/main/g/gcc-14/libstdc++6_14.2.0-4ubuntu2~24.04.1_amd64.deb": "a51f8de7829211db961a31f02158058ad1a95f92ac6d0a5dff6350e2821c54c0",
"pool/main/g/glibc/libc6-dev_2.39-0ubuntu8.9_amd64.deb": "e13d5fcc1b2a86f75bca8e0026a8e39f24fe97ca86e92be79991f8697eb1306f",
"pool/main/g/glibc/libc6_2.39-0ubuntu8.9_amd64.deb": "ff5557d99b51f761c4b7c92368b9cc45565eda17df9bf9eb4b134d09825008be",
"pool/main/l/linux/linux-libc-dev_6.8.0-146.146_amd64.deb": "1a7bb04132d01cd14bea3d615e5861096ca1f70c4659902eb14b36c21993cadc",
},
remove = [
"etc",
"usr/bin",
"usr/sbin",
"usr/share",
"usr/lib/x86_64-linux-gnu/gconv",
"usr/lib/gcc/x86_64-linux-gnu/13/crtoffload*",
"usr/lib/gcc/x86_64-linux-gnu/13/lib*san*",
"usr/lib/gcc/x86_64-linux-gnu/13/libatomic*",
"usr/lib/gcc/x86_64-linux-gnu/13/libbacktrace*",
"usr/lib/gcc/x86_64-linux-gnu/13/libgcov*",
"usr/lib/gcc/x86_64-linux-gnu/13/libgomp*",
"usr/lib/gcc/x86_64-linux-gnu/13/libitm*",
"usr/lib/gcc/x86_64-linux-gnu/13/libquadmath*",
"usr/lib/gcc/x86_64-linux-gnu/13/libstdc++*.a",
],
urls = NOBLE_DEB_URLS,
)
LLVM_VERSION = "22.1.8"
llvm_dist = use_repo_rule("//third_party/cc_toolchain:llvm_dist.bzl", "llvm_dist")
llvm_dist(
name = "llvm_dist_linux_x86_64",
llvm_version = LLVM_VERSION,
members = [
"bin/clang",
"bin/clang++",
"bin/clang-22",
"bin/clang-cpp",
"bin/ld.lld",
"bin/ld64.lld",
"bin/lld",
"bin/llvm-ar",
"bin/llvm-as",
"bin/llvm-cov",
"bin/llvm-install-name-tool",
"bin/llvm-nm",
"bin/llvm-objcopy",
"bin/llvm-objdump",
"bin/llvm-profdata",
"bin/llvm-ranlib",
"bin/llvm-readelf",
"bin/llvm-readobj",
"bin/llvm-strip",
"bin/llvm-symbolizer",
"bin/wasm-ld",
"include/c++",
"include/x86_64-unknown-linux-gnu",
"lib/clang/22/include",
"lib/clang/22/lib/x86_64-unknown-linux-gnu/clang_rt.crtbegin.o",
"lib/clang/22/lib/x86_64-unknown-linux-gnu/clang_rt.crtend.o",
"lib/clang/22/lib/x86_64-unknown-linux-gnu/libclang_rt.builtins.a",
# `bazel coverage` links cgo binaries with -fprofile-instr-generate,
# which pulls in compiler-rt's profile runtime (~170KB).
"lib/clang/22/lib/x86_64-unknown-linux-gnu/libclang_rt.profile.a",
],
# LLVM-22.1.8-Linux-X64.tar.xz (sha256 df0e1ecf...0006384), sliced to the
# members above by tools/cc_toolchain/repack_llvm.sh: 149 MB instead of
# 1.94 GB, and no single-threaded xz pass on every cold runner. The files
# are byte-identical to the release's, so no action key changes.
# tools/cc_toolchain/llvm_members.txt must list the same members.
sha256 = "de6147773999137b70ef3d7bd8ecb1e5b91f2a161d02fd09aec591b84516bec5",
sliced = True,
stub_tools = [
"clang-format",
"clang-tidy",
"clangd",
"llvm-dwp",
],
# The sha256 pin, not the host, guarantees the bytes. gascity's release
# asset for now; a beads mirror of the same bytes can be listed first.
urls = [
"https://github.com/gastownhall/gascity/releases/download/toolchain-llvm-22.1.8-slice-1/LLVM-22.1.8-Linux-X64-slice.tar.zst",
],
)
# Every other host (macOS arm64, Linux arm64) runs toolchains_llvm's stock
# LLVM_VERSION release for its platform, pinned by sha256 in toolchains_llvm's
# distribution table and fetched only there. Once any toolchain_root is set,
# toolchains_llvm creates no stock distribution of its own and fails every
# build on a host no root covers. Not hermetic there: no sysroot, so cgo
# uses the host's headers and libraries, as before.
llvm_host_dist = use_repo_rule("@toolchains_llvm//toolchain:rules.bzl", "llvm")
llvm_host_dist(
name = "llvm_dist_host",
llvm_version = LLVM_VERSION,
# The bare rule reads the per-host dict; llvm_toolchain's macro would
# fill it in from llvm_version.
llvm_versions = {"": LLVM_VERSION},
)
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
llvm.toolchain(
name = "llvm_toolchain",
# Pair Darwin's host SDK with its native linker. LLVM 22.1.8's ld64.lld
# cannot parse the arm64e.x1 TAPI targets in the macOS 27 SDK. Keep the
# pinned Clang compiler; Linux keeps the bundled LLD and pinned sysroot.
linker = {
"darwin-aarch64": "auto",
"darwin-x86_64": "auto",
},
llvm_version = LLVM_VERSION,
# The sysroot's libstdc++, linked dynamically as host-gcc builds did.
stdlib = {"linux-x86_64": "dynamic-stdc++"},
)
llvm.toolchain_root(
name = "llvm_toolchain",
label = "@llvm_dist_linux_x86_64//:BUILD.bazel",
targets = ["linux-x86_64"],
)
llvm.toolchain_root(
name = "llvm_toolchain",
label = "@llvm_dist_host//:BUILD.bazel",
)
llvm.sysroot(
name = "llvm_toolchain",
label = "@cc_sysroot_noble_amd64//:sysroot",
targets = ["linux-x86_64"],
)
use_repo(llvm, "llvm_toolchain")
register_toolchains("@llvm_toolchain//:all")
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(
@ -201,36 +15,8 @@ go_sdk.download(
)
use_repo(go_sdk, "go_sdk")
# nogo: //tools/nogo's analyzers (go test's vet checks plus the golangci-lint
# linters .golangci.yml enables) run beside every first-party Go compile, so
# a finding fails `bazel build`/`bazel test` wherever it executes (RBE
# included). External repos only feed analyzer facts; they are not validated.
go_sdk.nogo(
includes = ["//:__subpackages__"],
nogo = "//tools/nogo",
)
# gazelle compiles fetch_repo and gazelle, which every go_deps repository
# runs, with `go build` in a repository rule before any go_deps fetch can
# start (18-24 s of every CI lane's loading). This substitute serves those
# reproducible binaries from the repository cache by pinned sha256 and builds
# them from source on a miss (tools/bazel/go_repository_tools.bzl).
gazelle_non_module_deps = use_extension("@gazelle//internal/bzlmod:non_module_deps.bzl", "non_module_deps")
go_repository_tools = use_repo_rule("//tools/bazel:go_repository_tools.bzl", "go_repository_tools")
go_repository_tools(name = "gazelle_go_repository_tools")
override_repo(
gazelle_non_module_deps,
bazel_gazelle_go_repository_tools = "gazelle_go_repository_tools",
)
# gazelle.go.work joins the beads module and the nogo analyzers' module
# (tools/nogo/go.mod) into one dependency graph for Bazel only; `go build` in
# the repository root never reads it (it is not named go.work).
go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_work = "//:gazelle.go.work")
go_deps.from_file(go_mod = "//:go.mod")
# beads builds go-mysql-server with its stdlib-regex backend (ICU policy):
# gazelle must see gms_pure_go as satisfied so it selects regex_pure.go and
@ -242,23 +28,6 @@ go_deps.gazelle_override(
],
path = "github.com/dolthub/go-mysql-server",
)
# protoc-gen-validate ships validate/validate.pb.go, so its Go library can
# compile from the checked-in code. Its own validate/BUILD instead makes the
# Go library a go_proto_library, so every lane built protoc from source just
# to regenerate that file: about 4.5k C++ compile, link and archive actions,
# each carrying the LLVM toolchain as inputs. The module reaches the graph
# only through grpc xds and the cloud SDKs. Gazelle regenerates its BUILD
# files with proto rules off; build_file_name makes it write BUILD.bazel (which
# Bazel prefers) rather than merge into the upstream BUILD files.
go_deps.gazelle_override(
build_file_generation = "on",
directives = [
"gazelle:build_file_name BUILD.bazel",
"gazelle:proto disable",
],
path = "github.com/envoyproxy/protoc-gen-validate",
)
go_deps.module_override(
patch_strip = 1,
patches = ["//third_party/patches:eventsapi_schema_build.patch"],
@ -281,17 +50,7 @@ go_deps.module_override(
patches = ["//third_party/patches:gozstd_nocgo.patch"],
path = "github.com/dolthub/gozstd",
)
# nogo does not analyze the standard library, so ctrlflow has no noReturn
# facts for t.Fatal, log.Fatal, os.Exit, ...; buildssa (unparam) and the vet
# passes then treat them as returning, unlike golangci-lint and go vet. The
# patch makes ctrlflow know those standard-library functions intrinsically.
go_deps.module_override(
patch_strip = 1,
patches = ["//third_party/patches:x_tools_ctrlflow_stdlib_noreturn.patch"],
path = "golang.org/x/tools",
)
use_repo(go_deps, "cc_mvdan_unparam", "com_github_anthropics_anthropic_sdk_go", "com_github_ashanbrown_forbidigo_v2", "com_github_burntsushi_toml", "com_github_cenkalti_backoff_v4", "com_github_charmbracelet_x_ansi", "com_github_creack_pty", "com_github_data_dog_go_sqlmock", "com_github_dolthub_dolt_go", "com_github_dolthub_driver_v2", "com_github_dolthub_eventkit", "com_github_dolthub_go_mysql_server", "com_github_dolthub_vitess", "com_github_go_sql_driver_mysql", "com_github_golangci_misspell", "com_github_golangci_unconvert", "com_github_google_uuid", "com_github_gowebpki_jcs", "com_github_invopop_jsonschema", "com_github_johanneskaufmann_html_to_markdown_v2", "com_github_kisielk_errcheck", "com_github_mattn_go_sqlite3", "com_github_microcosm_cc_bluemonday", "com_github_oapi_codegen_oapi_codegen_v2", "com_github_olebedev_when", "com_github_openpeedeep_depguard_v2", "com_github_securego_gosec_v2", "com_github_spf13_cobra", "com_github_spf13_pflag", "com_github_spf13_viper", "com_github_stretchr_testify", "com_github_subosito_gotenv", "com_github_testcontainers_testcontainers_go", "com_github_testcontainers_testcontainers_go_modules_dolt", "com_github_yuin_goldmark", "in_gopkg_yaml_v3", "io_opentelemetry_go_otel", "io_opentelemetry_go_otel_exporters_otlp_otlpmetric_otlpmetrichttp", "io_opentelemetry_go_otel_exporters_stdout_stdoutmetric", "io_opentelemetry_go_otel_exporters_stdout_stdouttrace", "io_opentelemetry_go_otel_metric", "io_opentelemetry_go_otel_sdk", "io_opentelemetry_go_otel_sdk_metric", "io_opentelemetry_go_otel_trace", "io_rsc_script", "land_charm_glamour_v2", "land_charm_huh_v2", "land_charm_lipgloss_v2", "org_go_simpler_sloglint", "org_golang_x_mod", "org_golang_x_net", "org_golang_x_sync", "org_golang_x_sys", "org_golang_x_term", "org_golang_x_tools")
use_repo(go_deps, "com_github_anthropics_anthropic_sdk_go", "com_github_burntsushi_toml", "com_github_cenkalti_backoff_v4", "com_github_charmbracelet_x_ansi", "com_github_data_dog_go_sqlmock", "com_github_dolthub_dolt_go", "com_github_dolthub_driver_v2", "com_github_dolthub_eventkit", "com_github_dolthub_go_mysql_server", "com_github_dolthub_vitess", "com_github_go_sql_driver_mysql", "com_github_google_uuid", "com_github_gowebpki_jcs", "com_github_invopop_jsonschema", "com_github_johanneskaufmann_html_to_markdown_v2", "com_github_mattn_go_sqlite3", "com_github_microcosm_cc_bluemonday", "com_github_oapi_codegen_oapi_codegen_v2", "com_github_olebedev_when", "com_github_spf13_cobra", "com_github_spf13_pflag", "com_github_spf13_viper", "com_github_stretchr_testify", "com_github_subosito_gotenv", "com_github_testcontainers_testcontainers_go", "com_github_testcontainers_testcontainers_go_modules_dolt", "com_github_yuin_goldmark", "in_gopkg_yaml_v3", "io_opentelemetry_go_otel", "io_opentelemetry_go_otel_exporters_otlp_otlpmetric_otlpmetrichttp", "io_opentelemetry_go_otel_exporters_stdout_stdoutmetric", "io_opentelemetry_go_otel_exporters_stdout_stdouttrace", "io_opentelemetry_go_otel_metric", "io_opentelemetry_go_otel_sdk", "io_opentelemetry_go_otel_sdk_metric", "io_opentelemetry_go_otel_trace", "io_rsc_script", "land_charm_glamour_v2", "land_charm_huh_v2", "land_charm_lipgloss_v2", "org_golang_x_mod", "org_golang_x_net", "org_golang_x_sync", "org_golang_x_sys", "org_golang_x_term")
# Hermetic Dolt CLI for tests (tools/bazel/dolt.bzl pins the release to
# scripts/ci/install-dolt.sh). //tools/bazel:dolt selects the repository for
@ -317,101 +76,3 @@ dolt_release(
name = "dolt_darwin_arm64",
platform = "darwin-arm64",
)
# The migration corpus's external Dolt runtime (scripts/migration-test/lib/
# versions.sh DOLT_TEST_RUNTIME_VERSION): an older release than DOLT_VERSION,
# deliberately, as the historical server-Dolt fixtures' host.
dolt_release(
name = "dolt_test_runtime_linux_amd64",
platform = "linux-amd64",
version = "2.1.8",
)
# The tracked release formula, for //scripts:shell_scripts_test and the
# whole-checkout guard //scripts/repochecks:go_install_guidance_test. .beads/
# also holds live bd data and is in .bazelignore, so no main-repo target can
# declare the formula; this local repository exposes only .beads/formulas.
new_local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository")
new_local_repository(
name = "beads_formulas",
build_file_content = """exports_files(
glob(["*.formula.toml"]),
visibility = [
"@@//scripts:__pkg__",
"@@//scripts/repochecks:__pkg__",
],
)
""",
path = ".beads/formulas",
)
# Historical bd releases for the regression, migration and cross-version
# suites (tools/bazel/bd_releases.bzl): one repository per release in the
# release catalog that records a linux_amd64 asset digest, behind the
# @bd_releases hub. Adding a release is a catalog change only.
bd_releases = use_extension("//tools/bazel:bd_releases.bzl", "bd_releases")
bd_releases.catalog(path = "//scripts:migration-test/release-catalog.json")
use_repo(bd_releases, "bd_releases")
# The source-tag SQLite release (v0.9.1) has no release asset: the migration
# corpus builds it from its module source with the Go release it was
# qualified on, offline (//tests/migration:bd_source_tag). The proxy files
# are pinned in tests/migration/source_tag_modules.json, the toolchain here.
go_module_proxy = use_repo_rule("//tools/bazel:go_module_proxy.bzl", "go_module_proxy")
go_module_proxy(
name = "bd_source_tag_goproxy",
lock = "//tests/migration:source_tag_modules.json",
)
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "go_1_25_0_linux_amd64",
build_file_content = """exports_files(
["go/bin/go"],
visibility = ["//visibility:public"],
)
filegroup(
name = "sdk",
srcs = glob(["go/**"]),
visibility = ["//visibility:public"],
)
""",
sha256 = "2852af0cb20a13139b3448992e69b868e50ed0f8a1e5940ee1de9e19a123b613",
urls = ["https://go.dev/dl/go1.25.0.linux-amd64.tar.gz"],
)
# The timeout implementations //tests/hook_timeout_backends runs the tracked
# git hook shims against (formerly checks.nix's hook-timeout-backends, which
# took them from nixpkgs): static x86_64 builds, so the test needs nothing
# from the executor beyond a shell, perl and GNU coreutils.
http_file = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
http_file(
name = "busybox_static",
executable = True,
sha256 = "6e123e7f3202a8c1e9b1f94d8941580a25135382b99e8d3e34fb858bba311348",
urls = ["https://busybox.net/downloads/binaries/1.35.0-x86_64-linux-musl/busybox"],
)
http_file(
name = "toybox_static",
executable = True,
sha256 = "38e03ffd8aead8ca26833e1e5c90a9ea7250f3719c29d779ebff7aa55c9d2dac",
urls = ["https://landley.net/toybox/downloads/binaries/0.8.15/toybox-x86_64"],
)
http_archive(
name = "uutils_coreutils",
build_file_content = """exports_files(
["coreutils"],
visibility = ["//visibility:public"],
)
""",
sha256 = "9b555b01457279bcc3e46753f0ef324fd3d02a0535111200a4632d1297263b54",
strip_prefix = "coreutils-0.12.0-x86_64-unknown-linux-musl",
urls = ["https://github.com/uutils/coreutils/releases/download/0.12.0/coreutils-0.12.0-x86_64-unknown-linux-musl.tar.gz"],
)

69
MODULE.bazel.lock generated
View file

@ -18,12 +18,9 @@
"https://bcr.bazel.build/modules/apple_support/1.15.1/MODULE.bazel": "a0556fefca0b1bb2de8567b8827518f94db6a6e7e7d632b4c48dc5f865bc7c85",
"https://bcr.bazel.build/modules/apple_support/1.21.0/MODULE.bazel": "ac1824ed5edf17dee2fdd4927ada30c9f8c3b520be1b5fd02a5da15bc10bff3e",
"https://bcr.bazel.build/modules/apple_support/1.21.1/MODULE.bazel": "5809fa3efab15d1f3c3c635af6974044bac8a4919c62238cce06acee8a8c11f1",
"https://bcr.bazel.build/modules/apple_support/2.5.2/MODULE.bazel": "bb1b7081e390a8d3885f642cb0073dfcf8e7a36525e079fa8f5835af7079c0fe",
"https://bcr.bazel.build/modules/apple_support/2.5.2/source.json": "dd51ee925a550e92b55eb41c4c809a967da311a2d2520241252a238a48b39c4c",
"https://bcr.bazel.build/modules/aspect_bazel_lib/2.14.0/MODULE.bazel": "2b31ffcc9bdc8295b2167e07a757dbbc9ac8906e7028e5170a3708cecaac119f",
"https://bcr.bazel.build/modules/aspect_bazel_lib/2.19.3/MODULE.bazel": "253d739ba126f62a5767d832765b12b59e9f8d2bc88cc1572f4a73e46eb298ca",
"https://bcr.bazel.build/modules/aspect_bazel_lib/2.19.3/source.json": "ffab9254c65ba945f8369297ad97ca0dec213d3adc6e07877e23a48624a8b456",
"https://bcr.bazel.build/modules/aspect_bazel_lib/2.8.1/MODULE.bazel": "812d2dd42f65dca362152101fbec418029cc8fd34cbad1a2fde905383d705838",
"https://bcr.bazel.build/modules/apple_support/1.24.2/MODULE.bazel": "0e62471818affb9f0b26f128831d5c40b074d32e6dda5a0d3852847215a41ca4",
"https://bcr.bazel.build/modules/apple_support/1.24.2/source.json": "2c22c9827093250406c5568da6c54e6fdf0ef06238def3d99c71b12feb057a8d",
"https://bcr.bazel.build/modules/bazel_features/1.1.0/MODULE.bazel": "cfd42ff3b815a5f39554d97182657f8c4b9719568eb7fded2b9135f084bf760b",
"https://bcr.bazel.build/modules/bazel_features/1.1.1/MODULE.bazel": "27b8c79ef57efe08efccbd9dd6ef70d61b4798320b8d3c134fd571f78963dbcd",
"https://bcr.bazel.build/modules/bazel_features/1.10.0/MODULE.bazel": "f75e8807570484a99be90abcd52b5e1f390362c258bcb73106f4544957a48101",
"https://bcr.bazel.build/modules/bazel_features/1.11.0/MODULE.bazel": "f9382337dd5a474c3b7d334c2f83e50b6eaedc284253334cf823044a26de03e8",
@ -38,13 +35,10 @@
"https://bcr.bazel.build/modules/bazel_features/1.3.0/MODULE.bazel": "cdcafe83ec318cda34e02948e81d790aab8df7a929cec6f6969f13a489ccecd9",
"https://bcr.bazel.build/modules/bazel_features/1.30.0/MODULE.bazel": "a14b62d05969a293b80257e72e597c2da7f717e1e69fa8b339703ed6731bec87",
"https://bcr.bazel.build/modules/bazel_features/1.33.0/MODULE.bazel": "8b8dc9d2a4c88609409c3191165bccec0e4cb044cd7a72ccbe826583303459f6",
"https://bcr.bazel.build/modules/bazel_features/1.34.0/MODULE.bazel": "e8475ad7c8965542e0c7aac8af68eb48c4af904be3d614b6aa6274c092c2ea1e",
"https://bcr.bazel.build/modules/bazel_features/1.36.0/MODULE.bazel": "596cb62090b039caf1cad1d52a8bc35cf188ca9a4e279a828005e7ee49a1bec3",
"https://bcr.bazel.build/modules/bazel_features/1.38.0/MODULE.bazel": "f9b8a9c890ebd216b4049fd12a31d3c2602e3403c7af636b04fbbd7453edc9c9",
"https://bcr.bazel.build/modules/bazel_features/1.4.1/MODULE.bazel": "e45b6bb2350aff3e442ae1111c555e27eac1d915e77775f6fdc4b351b758b5d7",
"https://bcr.bazel.build/modules/bazel_features/1.42.1/MODULE.bazel": "275a59b5406ff18c01739860aa70ad7ccb3cfb474579411decca11c93b951080",
"https://bcr.bazel.build/modules/bazel_features/1.42.1/source.json": "fcd4396b2df85f64f2b3bb436ad870793ecf39180f1d796f913cc9276d355309",
"https://bcr.bazel.build/modules/bazel_features/1.9.0/MODULE.bazel": "885151d58d90d8d9c811eb75e3288c11f850e1d6b481a8c9f766adee4712358b",
"https://bcr.bazel.build/modules/bazel_features/1.9.1/MODULE.bazel": "8f679097876a9b609ad1f60249c49d68bfab783dd9be012faf9d82547b14815a",
"https://bcr.bazel.build/modules/bazel_skylib/1.0.3/MODULE.bazel": "bcb0fd896384802d1ad283b4e4eb4d718eebd8cb820b0a2c3a347fb971afd9d8",
"https://bcr.bazel.build/modules/bazel_skylib/1.1.1/MODULE.bazel": "1add3e7d93ff2e6998f9e118022c84d163917d912f5afafb3058e3d2f1545b5e",
@ -62,8 +56,10 @@
"https://bcr.bazel.build/modules/bazel_skylib/1.8.2/source.json": "34a3c8bcf233b835eb74be9d628899bb32999d3e0eadef1947a0a562a2b16ffb",
"https://bcr.bazel.build/modules/buildozer/8.5.1/MODULE.bazel": "a35d9561b3fc5b18797c330793e99e3b834a473d5fbd3d7d7634aafc9bdb6f8f",
"https://bcr.bazel.build/modules/buildozer/8.5.1/source.json": "e3386e6ff4529f2442800dee47ad28d3e6487f36a1f75ae39ae56c70f0cd2fbd",
"https://bcr.bazel.build/modules/gawk/5.3.2.bcr.1/MODULE.bazel": "cdf8cbe5ee750db04b78878c9633cc76e80dcf4416cbe982ac3a9222f80713c8",
"https://bcr.bazel.build/modules/gawk/5.3.2.bcr.1/source.json": "fa7b512dfcb5eafd90ce3959cf42a2a6fe96144ebbb4b3b3928054895f2afac2",
"https://bcr.bazel.build/modules/gazelle/0.32.0/MODULE.bazel": "b499f58a5d0d3537f3cf5b76d8ada18242f64ec474d8391247438bf04f58c7b8",
"https://bcr.bazel.build/modules/gazelle/0.33.0/MODULE.bazel": "a13a0f279b462b784fb8dd52a4074526c4a2afe70e114c7d09066097a46b3350",
"https://bcr.bazel.build/modules/gazelle/0.34.0/MODULE.bazel": "abdd8ce4d70978933209db92e436deb3a8b737859e9354fb5fd11fb5c2004c8a",
"https://bcr.bazel.build/modules/gazelle/0.36.0/MODULE.bazel": "e375d5d6e9a6ca59b0cb38b0540bc9a05b6aa926d322f2de268ad267a2ee74c0",
"https://bcr.bazel.build/modules/gazelle/0.51.3/MODULE.bazel": "618a729142f66de1e2cb776d026413763be5b80d5e3d29ffb9d3d90c5defde90",
"https://bcr.bazel.build/modules/gazelle/0.53.0/MODULE.bazel": "76158efbaf12e35ae17af02f4a715bc6e7b3b410c693d34f422922ff4a56a925",
"https://bcr.bazel.build/modules/gazelle/0.53.0/source.json": "1f5a4dd0399e5a20e0daeaa3ba1f42391a1b909bc3d337f7a62d3216ddbdfad0",
@ -74,17 +70,12 @@
"https://bcr.bazel.build/modules/googletest/1.15.2/MODULE.bazel": "6de1edc1d26cafb0ea1a6ab3f4d4192d91a312fd2d360b63adaa213cd00b2108",
"https://bcr.bazel.build/modules/googletest/1.17.0/MODULE.bazel": "dbec758171594a705933a29fcf69293d2468c49ec1f2ebca65c36f504d72df46",
"https://bcr.bazel.build/modules/googletest/1.17.0/source.json": "38e4454b25fc30f15439c0378e57909ab1fd0a443158aa35aec685da727cd713",
"https://bcr.bazel.build/modules/jq.bzl/0.1.0/MODULE.bazel": "2ce69b1af49952cd4121a9c3055faa679e748ce774c7f1fda9657f936cae902f",
"https://bcr.bazel.build/modules/jq.bzl/0.1.0/source.json": "746bf13cac0860f091df5e4911d0c593971cd8796b5ad4e809b2f8e133eee3d5",
"https://bcr.bazel.build/modules/jsoncpp/1.9.5/MODULE.bazel": "31271aedc59e815656f5736f282bb7509a97c7ecb43e927ac1a37966e0578075",
"https://bcr.bazel.build/modules/jsoncpp/1.9.6/MODULE.bazel": "2f8d20d3b7d54143213c4dfc3d98225c42de7d666011528dc8fe91591e2e17b0",
"https://bcr.bazel.build/modules/jsoncpp/1.9.6/source.json": "a04756d367a2126c3541682864ecec52f92cdee80a35735a3cb249ce015ca000",
"https://bcr.bazel.build/modules/libpfm/4.11.0/MODULE.bazel": "45061ff025b301940f1e30d2c16bea596c25b176c8b6b3087e92615adbd52902",
"https://bcr.bazel.build/modules/mboworks_bzl/0.5.1/MODULE.bazel": "20c921aded4f4e00a6128dad47a843371c196ba8987474c11c8ba7b9da8c16f1",
"https://bcr.bazel.build/modules/mboworks_bzl/0.5.1/source.json": "3d9086bb203475113a16afb0ca0c9b97fdb37fc6e5a62b604b60ffc2450dc8c5",
"https://bcr.bazel.build/modules/nlohmann_json/3.6.1/MODULE.bazel": "6f7b417dcc794d9add9e556673ad25cb3ba835224290f4f848f8e2db1e1fca74",
"https://bcr.bazel.build/modules/nlohmann_json/3.6.1/source.json": "f448c6e8963fdfa7eb831457df83ad63d3d6355018f6574fb017e8169deb43a9",
"https://bcr.bazel.build/modules/package_metadata/0.0.2/MODULE.bazel": "fb8d25550742674d63d7b250063d4580ca530499f045d70748b1b142081ebb92",
"https://bcr.bazel.build/modules/package_metadata/0.0.3/MODULE.bazel": "77890552ecea9e284b5424c9de827a58099348763a4359e975c359a83d4faa83",
"https://bcr.bazel.build/modules/package_metadata/0.0.5/MODULE.bazel": "ef4f9439e3270fdd6b9fd4dbc3d2f29d13888e44c529a1b243f7a31dfbc2e8e4",
"https://bcr.bazel.build/modules/package_metadata/0.0.5/source.json": "2326db2f6592578177751c3e1f74786b79382cd6008834c9d01ec865b9126a85",
@ -102,11 +93,13 @@
"https://bcr.bazel.build/modules/protobuf/21.7/MODULE.bazel": "a5a29bb89544f9b97edce05642fac225a808b5b7be74038ea3640fae2f8e66a7",
"https://bcr.bazel.build/modules/protobuf/27.0/MODULE.bazel": "7873b60be88844a0a1d8f80b9d5d20cfbd8495a689b8763e76c6372998d3f64c",
"https://bcr.bazel.build/modules/protobuf/27.1/MODULE.bazel": "703a7b614728bb06647f965264967a8ef1c39e09e8f167b3ca0bb1fd80449c0d",
"https://bcr.bazel.build/modules/protobuf/29.0-rc2.bcr.1/MODULE.bazel": "52f4126f63a2f0bbf36b99c2a87648f08467a4eaf92ba726bc7d6a500bbf770c",
"https://bcr.bazel.build/modules/protobuf/29.0-rc2/MODULE.bazel": "6241d35983510143049943fc0d57937937122baf1b287862f9dc8590fc4c37df",
"https://bcr.bazel.build/modules/protobuf/29.0-rc3/MODULE.bazel": "33c2dfa286578573afc55a7acaea3cada4122b9631007c594bf0729f41c8de92",
"https://bcr.bazel.build/modules/protobuf/29.0/MODULE.bazel": "319dc8bf4c679ff87e71b1ccfb5a6e90a6dbc4693501d471f48662ac46d04e4e",
"https://bcr.bazel.build/modules/protobuf/29.1/MODULE.bazel": "557c3457560ff49e122ed76c0bc3397a64af9574691cb8201b4e46d4ab2ecb95",
"https://bcr.bazel.build/modules/protobuf/3.19.0/MODULE.bazel": "6b5fbb433f760a99a22b18b6850ed5784ef0e9928a72668b66e4d7ccd47db9b0",
"https://bcr.bazel.build/modules/protobuf/3.19.2/MODULE.bazel": "532ffe5f2186b69fdde039efe6df13ba726ff338c6bc82275ad433013fa10573",
"https://bcr.bazel.build/modules/protobuf/3.19.6/MODULE.bazel": "9233edc5e1f2ee276a60de3eaa47ac4132302ef9643238f23128fea53ea12858",
"https://bcr.bazel.build/modules/protobuf/32.1/MODULE.bazel": "89cd2866a9cb07fee9ff74c41ceace11554f32e0d849de4e23ac55515cfada4d",
"https://bcr.bazel.build/modules/protobuf/33.4/MODULE.bazel": "114775b816b38b6d0ca620450d6b02550c60ceedfdc8d9a229833b34a223dc42",
@ -138,16 +131,19 @@
"https://bcr.bazel.build/modules/rules_cc/0.1.5/MODULE.bazel": "88dfc9361e8b5ae1008ac38f7cdfd45ad738e4fa676a3ad67d19204f045a1fd8",
"https://bcr.bazel.build/modules/rules_cc/0.2.0/MODULE.bazel": "b5c17f90458caae90d2ccd114c81970062946f49f355610ed89bebf954f5783c",
"https://bcr.bazel.build/modules/rules_cc/0.2.13/MODULE.bazel": "eecdd666eda6be16a8d9dc15e44b5c75133405e820f620a234acc4b1fdc5aa37",
"https://bcr.bazel.build/modules/rules_cc/0.2.15/MODULE.bazel": "6a0a4a75a57aa6dc888300d848053a58c6b12a29f89d4304e1c41448514ec6e8",
"https://bcr.bazel.build/modules/rules_cc/0.2.17/MODULE.bazel": "1849602c86cb60da8613d2de887f9566a6d354a6df6d7009f9d04a14402f9a84",
"https://bcr.bazel.build/modules/rules_cc/0.2.17/source.json": "3832f45d145354049137c0090df04629d9c2b5493dc5c2bf46f1834040133a07",
"https://bcr.bazel.build/modules/rules_cc/0.2.8/MODULE.bazel": "f1df20f0bf22c28192a794f29b501ee2018fa37a3862a1a2132ae2940a23a642",
"https://bcr.bazel.build/modules/rules_foreign_cc/0.9.0/MODULE.bazel": "c9e8c682bf75b0e7c704166d79b599f93b72cfca5ad7477df596947891feeef6",
"https://bcr.bazel.build/modules/rules_fuzzing/0.5.2/MODULE.bazel": "40c97d1144356f52905566c55811f13b299453a14ac7769dfba2ac38192337a8",
"https://bcr.bazel.build/modules/rules_go/0.41.0/MODULE.bazel": "55861d8e8bb0e62cbd2896f60ff303f62ffcb0eddb74ecb0e5c0cbe36fc292c8",
"https://bcr.bazel.build/modules/rules_go/0.42.0/MODULE.bazel": "8cfa875b9aa8c6fce2b2e5925e73c1388173ea3c32a0db4d2b4804b453c14270",
"https://bcr.bazel.build/modules/rules_go/0.46.0/MODULE.bazel": "3477df8bdcc49e698b9d25f734c4f3a9f5931ff34ee48a2c662be168f5f2d3fd",
"https://bcr.bazel.build/modules/rules_go/0.59.0/MODULE.bazel": "b7e43e7414a3139a7547d1b4909b29085fbe5182b6c58cbe1ed4c6272815aeae",
"https://bcr.bazel.build/modules/rules_go/0.63.0/MODULE.bazel": "a2079e783a5d2715a90e6e2970ec8ffd717a487ff2aecb5f553e3975c5294a21",
"https://bcr.bazel.build/modules/rules_go/0.63.0/source.json": "5bf37b45c440ac03abad0cbfa8b8b8dd89cc4e82bc8305f468b8436fa58bae78",
"https://bcr.bazel.build/modules/rules_java/4.0.0/MODULE.bazel": "5a78a7ae82cd1a33cef56dc578c7d2a46ed0dca12643ee45edbb8417899e6f74",
"https://bcr.bazel.build/modules/rules_java/5.3.5/MODULE.bazel": "a4ec4f2db570171e3e5eb753276ee4b389bae16b96207e9d3230895c99644b86",
"https://bcr.bazel.build/modules/rules_java/6.3.0/MODULE.bazel": "a97c7678c19f236a956ad260d59c86e10a463badb7eb2eda787490f4c969b963",
"https://bcr.bazel.build/modules/rules_java/6.5.2/MODULE.bazel": "1d440d262d0e08453fa0c4d8f699ba81609ed0e9a9a0f02cd10b3e7942e61e31",
"https://bcr.bazel.build/modules/rules_java/7.10.0/MODULE.bazel": "530c3beb3067e870561739f1144329a21c851ff771cd752a49e06e3dc9c2e71a",
"https://bcr.bazel.build/modules/rules_java/7.12.2/MODULE.bazel": "579c505165ee757a4280ef83cda0150eea193eed3bef50b1004ba88b99da6de6",
@ -194,7 +190,6 @@
"https://bcr.bazel.build/modules/rules_python/1.7.0/source.json": "028a084b65dcf8f4dc4f82f8778dbe65df133f234b316828a82e060d81bdce32",
"https://bcr.bazel.build/modules/rules_shell/0.2.0/MODULE.bazel": "fda8a652ab3c7d8fee214de05e7a9916d8b28082234e8d2c0094505c5268ed3c",
"https://bcr.bazel.build/modules/rules_shell/0.3.0/MODULE.bazel": "de4402cd12f4cc8fda2354fce179fdb068c0b9ca1ec2d2b17b3e21b24c1a937b",
"https://bcr.bazel.build/modules/rules_shell/0.4.1/MODULE.bazel": "00e501db01bbf4e3e1dd1595959092c2fadf2087b2852d3f553b5370f5633592",
"https://bcr.bazel.build/modules/rules_shell/0.6.1/MODULE.bazel": "72e76b0eea4e81611ef5452aa82b3da34caca0c8b7b5c0c9584338aa93bae26b",
"https://bcr.bazel.build/modules/rules_shell/0.6.1/source.json": "20ec05cd5e592055e214b2da8ccb283c7f2a421ea0dc2acbf1aa792e11c03d0c",
"https://bcr.bazel.build/modules/rules_swift/1.16.0/MODULE.bazel": "4a09f199545a60d09895e8281362b1ff3bb08bbde69c6fc87aff5b92fcc916ca",
@ -204,21 +199,13 @@
"https://bcr.bazel.build/modules/rules_swift/3.1.2/source.json": "e85761f3098a6faf40b8187695e3de6d97944e98abd0d8ce579cb2daf6319a66",
"https://bcr.bazel.build/modules/stardoc/0.5.1/MODULE.bazel": "1a05d92974d0c122f5ccf09291442580317cdd859f07a8655f1db9a60374f9f8",
"https://bcr.bazel.build/modules/stardoc/0.5.3/MODULE.bazel": "c7f6948dae6999bf0db32c1858ae345f112cacf98f174c7a8bb707e41b974f1c",
"https://bcr.bazel.build/modules/stardoc/0.6.2/MODULE.bazel": "7060193196395f5dd668eda046ccbeacebfd98efc77fed418dbe2b82ffaa39fd",
"https://bcr.bazel.build/modules/stardoc/0.7.0/MODULE.bazel": "05e3d6d30c099b6770e97da986c53bd31844d7f13d41412480ea265ac9e8079c",
"https://bcr.bazel.build/modules/stardoc/0.7.2/MODULE.bazel": "fc152419aa2ea0f51c29583fab1e8c99ddefd5b3778421845606ee628629e0e5",
"https://bcr.bazel.build/modules/stardoc/0.7.2/source.json": "58b029e5e901d6802967754adf0a9056747e8176f017cfe3607c0851f4d42216",
"https://bcr.bazel.build/modules/swift_argument_parser/1.3.1.1/MODULE.bazel": "5e463fbfba7b1701d957555ed45097d7f984211330106ccd1352c6e0af0dcf91",
"https://bcr.bazel.build/modules/swift_argument_parser/1.3.1.2/MODULE.bazel": "75aab2373a4bbe2a1260b9bf2a1ebbdbf872d3bd36f80bff058dccd82e89422f",
"https://bcr.bazel.build/modules/swift_argument_parser/1.3.1.2/source.json": "5fba48bbe0ba48761f9e9f75f92876cafb5d07c0ce059cc7a8027416de94a05b",
"https://bcr.bazel.build/modules/tar.bzl/0.2.1/MODULE.bazel": "52d1c00a80a8cc67acbd01649e83d8dd6a9dc426a6c0b754a04fe8c219c76468",
"https://bcr.bazel.build/modules/tar.bzl/0.6.0/MODULE.bazel": "a3584b4edcfafcabd9b0ef9819808f05b372957bbdff41601429d5fd0aac2e7c",
"https://bcr.bazel.build/modules/tar.bzl/0.6.0/source.json": "4a620381df075a16cb3a7ed57bd1d05f7480222394c64a20fa51bdb636fda658",
"https://bcr.bazel.build/modules/toolchains_llvm/1.11.0/MODULE.bazel": "c0b9c103deeaf0fc103934ff0a189273b4f9b82cc1622c59b67e1c3a83d6b5e6",
"https://bcr.bazel.build/modules/toolchains_llvm/1.11.0/source.json": "d06e53520101c3890a094e5849b0ff16dde3a6f6531f25c997f340ebff34d569",
"https://bcr.bazel.build/modules/upb/0.0.0-20220923-a547704/MODULE.bazel": "7298990c00040a0e2f121f6c32544bab27d4452f80d9ce51349b1a28f3005c43",
"https://bcr.bazel.build/modules/yq.bzl/0.1.1/MODULE.bazel": "9039681f9bcb8958ee2c87ffc74bdafba9f4369096a2b5634b88abc0eaefa072",
"https://bcr.bazel.build/modules/yq.bzl/0.1.1/source.json": "2d2bad780a9f2b9195a4a370314d2c17ae95eaa745cefc2e12fbc49759b15aa3",
"https://bcr.bazel.build/modules/zlib/1.2.11/MODULE.bazel": "07b389abc85fdbca459b69e2ec656ae5622873af3f845e1c9d80fe179f3effa0",
"https://bcr.bazel.build/modules/zlib/1.2.12/MODULE.bazel": "3b1a8834ada2a883674be8cbd36ede1b6ec481477ada359cd2d3ddc562340b27",
"https://bcr.bazel.build/modules/zlib/1.3.1.bcr.5/MODULE.bazel": "eec517b5bbe5492629466e11dae908d043364302283de25581e3eb944326c4ca",
@ -229,7 +216,7 @@
"moduleExtensions": {
"@@pybind11_bazel+//:internal_configure.bzl%internal_configure_extension": {
"general": {
"bzlTransitiveDigest": "BsgERqYptkJeeC8wFaLj251IoTZTSy/58WA6kVp0q8I=",
"bzlTransitiveDigest": "NRXra7941UfmNUyIxnLt82V5hULluVGL2nBsijTl4j4=",
"usagesDigest": "D1r3lfzMuUBFxgG8V6o0bQTLMk3GkaGOaPzw53wrwyw=",
"recordedInputs": [
"REPO_MAPPING:pybind11_bazel+,bazel_tools bazel_tools",
@ -251,7 +238,7 @@
},
"@@rules_kotlin+//src/main/starlark/core/repositories:bzlmod_setup.bzl%rules_kotlin_extensions": {
"general": {
"bzlTransitiveDigest": "WDuVCwqV73DvcHB5Of+02lhUZgPxr9MqtpvMRyUi0eQ=",
"bzlTransitiveDigest": "+Kp6j204mBZ3mxlIDDR0gBoP45BZ4jYRhRAcB8sU0qc=",
"usagesDigest": "QI2z8ZUR+mqtbwsf2fLqYdJAkPOHdOV+tF2yVAUgRzw=",
"recordedInputs": [
"REPO_MAPPING:rules_kotlin+,bazel_tools bazel_tools"
@ -308,7 +295,7 @@
},
"@@rules_python+//python/extensions:config.bzl%config": {
"general": {
"bzlTransitiveDigest": "L+2ZCpb7GIJqvWaXpzkfk/80d916sIFVmSPzrSm6of8=",
"bzlTransitiveDigest": "dzD8Q2YmrP3fz8saWLHPmlwPLO91ImtTmP/c9JKTStM=",
"usagesDigest": "ZVSXMAGpD+xzVNPuvF1IoLBkty7TROO0+akMapt1pAg=",
"recordedInputs": [
"REPO_MAPPING:rules_python+,bazel_tools bazel_tools",
@ -476,7 +463,7 @@
},
"@@rules_python+//python/uv:uv.bzl%uv": {
"general": {
"bzlTransitiveDigest": "IgkgxNrtlAec7OnaFrWoCC5NQhHcY/aIz4jsqcNMm8Y=",
"bzlTransitiveDigest": "ijW9KS7qsIY+yBVvJ+Nr1mzwQox09j13DnE3iIwaeTM=",
"usagesDigest": "H8dQoNZcoqP+Mu0tHZTi4KHATzvNkM5ePuEqoQdklIU=",
"recordedInputs": [
"REPO_MAPPING:rules_python+,bazel_tools bazel_tools",
@ -503,26 +490,6 @@
}
}
}
},
"@@toolchains_llvm+//toolchain/extensions:distributions.bzl%llvm_distributions": {
"general": {
"bzlTransitiveDigest": "RfYsFLwRh0rVY8ReiYgbOEyr84zuBs7mbcHq3dPY3jI=",
"usagesDigest": "vl2VXD2E16aV3RG06i5tx7yyYASHiQFjvsiNZSDzQIg=",
"recordedInputs": [],
"generatedRepoSpecs": {
"llvm_distributions_data": {
"repoRuleId": "@@toolchains_llvm+//toolchain/internal:distributions_repo.bzl%llvm_distributions_repo",
"attributes": {
"srcs": [
"@@toolchains_llvm+//toolchain/distributions:pre_github.jsonc",
"@@toolchains_llvm+//toolchain/distributions:github_legacy.jsonc",
"@@toolchains_llvm+//toolchain/distributions:github.jsonc",
"@@toolchains_llvm+//toolchain/distributions:extra.jsonc"
]
}
}
}
}
}
},
"facts": {

123
Makefile
View file

@ -44,32 +44,13 @@ endif
endif
.PHONY: all build doctor-build test test-icu-path test-full-cgo test-regression test-upgrade test-cross-version test-migration corpus-regen githooks-regen bench bench-quick clean clean-test-tmp install install-force help check-up-to-date fmt fmt-check check-testing-short
.PHONY: lint lint-changed vet
.PHONY: check check-go test-go check-docs-go
.PHONY: ci-pr-core ci-pr-lint ci-complexity ci-complexity-diff ci-complexity-check ci-package-mcp ci-package-npm nogo-ownership
.PHONY: ci-pr-core ci-pr-policy ci-pr-lint ci-complexity ci-complexity-diff ci-complexity-check ci-package-mcp ci-package-npm
.PHONY: api-gen api-check
.PHONY: bazel-sync bazel-sync-check
# Default target
all: build
# Build and test engine. Bazel is what CI gates on: .github/workflows/bazel.yml
# runs `bazel test` lanes on rbe-west, and nogo (lint + vet), formatting and
# the repository guards are Bazel targets there. The primary targets (test,
# check, check-docs) run the same `bazel test` commands as those lanes, so a
# local run shares CI's action keys and its remote cache (engdocs/TESTING.md
# "Building and testing"). Each keeps a plain go twin under an explicit -go
# name (test-go, check-go, check-docs-go) for offline work and hosts Bazel does
# not serve; that twin is an inner-loop convenience, not what CI enforces.
# GitHub Actions jobs that still run Go-native suites call the -go names.
BAZEL ?= bazel
# Extra flags for every `bazel test` below: --config=fork-cache (contributors:
# the anonymous read-only cache) or --config=remote-exec (maintainers with an
# rbe-west client certificate). Hosts whose ~/.bazelrc names the executor need
# neither. Better: put `build --config=...` in the gitignored .bazelrc.local.
BAZEL_FLAGS ?=
BAZEL_TEST = $(BAZEL) test $(BAZEL_FLAGS)
BUILD_DIR := .
BD_BUILD_OUTPUT := $(BUILD_DIR)/bd$(if $(filter Windows_NT,$(OS)),.exe)
GIT_BUILD := $(shell git rev-parse --short HEAD)
@ -192,27 +173,11 @@ doctor-build:
echo " CGO_ENABLED=1 go build -tags gms_pure_go ./cmd/bd" ;; \
esac
# bazel.yml's test lane (`bazel test //... --config=ci`): every untagged
# go_test with PR Core's selection (race, -short, skips), plus nogo lint/vet,
# formatting and the repository guards. The other lanes' commands are in
# engdocs/TESTING.md "Building and testing".
# Run all tests (skips known broken tests listed in .test-skip)
test:
$(BAZEL_TEST) //... --config=ci
# Plain go test (skips known broken tests listed in .test-skip): an inner-loop
# convenience without Bazel; CI does not run it.
test-go:
@echo "Running tests..."
@TEST_COVER=1 ./scripts/test.sh
# Fast quality gates: the testing.Short policy, the full nogo lint gate
# (native plus the windows/darwin passes) and `make test`.
check: check-testing-short ci-pr-lint test
# The same gates without Bazel where they have a Go form: gofmt and go test.
# nogo has no go twin, so this is a convenience CI does not enforce.
check-go: fmt-check check-testing-short test-go
# Run the opt-in ICU regex path test suite (no skip list).
# This is a local developer workflow for intentionally exercising the leftover
# ICU path; it is not part of normal validation.
@ -229,59 +194,12 @@ test-full-cgo:
ci-pr-core:
@./scripts/ci/pr-core.sh
# Lint and vet are nogo (//tools/nogo): go test's vet checks plus the
# golangci-lint linters .golangci.yml enables, validated beside every Go
# compile, so any `bazel build`/`bazel test` (local or on rbe-west) fails on a
# finding. These targets ask Bazel for the analysis alone (.bazelrc's
# --config=nogo; nothing is linked).
ci-pr-policy:
@./scripts/ci/pr-policy.sh
ci-pr-lint:
@./scripts/ci/pr-lint.sh
# nogo-ownership is a dynamic, advisory cross-check (not part of the required
# //scripts static suite, which cannot shell out to Bazel): it asks real
# `bazel aquery` whether the nogo owner lane for each configuration group
# (today: race, bazel-test/--config=ci) really does validate every file a
# non-owner lane (embedded, doltserver, doltserver-proxied, dolt-race, which
# pass --norun_validations) compiles. See tools/bazel/nogo_ownership.py and
# scripts/nogo_lint_policy_test.go's nogoConfigurations table.
nogo-ownership:
@python3 tools/bazel/nogo_ownership.py
# The CI lint gate: native, plus //tools/bazel:release_cross for windows/amd64
# and darwin/arm64 (BD_LINT_TARGETS selects; scripts/pr-lint).
lint: ci-pr-lint
# go test's vet checks run inside nogo; same as lint.
vet: lint
# nogo over the Bazel packages of changed Go files, natively (the pre-commit
# hook's lint). LINT_CHANGED_SCOPE: staged, or worktree (changed against
# LINT_CHANGED_REF, staged, and untracked).
LINT_CHANGED_SCOPE ?= worktree
LINT_CHANGED_REF ?= HEAD
lint-changed:
@case "$(LINT_CHANGED_SCOPE)" in \
staged) files="$$(git diff --cached --name-only --diff-filter=ACMRT -- '*.go')" ;; \
worktree) files="$$( \
git diff --name-only --diff-filter=ACMRT "$(LINT_CHANGED_REF)" -- '*.go'; \
git diff --cached --name-only --diff-filter=ACMRT -- '*.go'; \
git ls-files --others --exclude-standard -- '*.go')" ;; \
*) echo "unknown LINT_CHANGED_SCOPE=$(LINT_CHANGED_SCOPE); expected staged or worktree" >&2; exit 2 ;; \
esac; \
packages=""; missing=""; \
for file in $$files; do \
dir="$$(dirname "$$file")"; \
case "/$$dir/" in */testdata/*) continue ;; esac; \
if [ -f "$$dir/BUILD.bazel" ]; then packages="$$packages //$${dir#.}:all"; else missing="$$missing $$dir"; fi; \
done; \
if [ -n "$$missing" ]; then \
echo "lint-changed: no BUILD.bazel in$$missing; run 'make bazel-sync'" >&2; exit 1; \
fi; \
packages="$$(printf '%s\n' $$packages | sort -u | sed 's#^///#//#; s#^//\.:#//:#')"; \
if [ -z "$$packages" ]; then echo "lint-changed: no changed Go packages"; exit 0; fi; \
echo "lint-changed:" $$packages; \
$(BAZEL) build --config=nogo -- $$packages
# Opt-in architecture experiment. Install gocyclo v0.6.0 first;
# report is advisory while check exercises the local baseline guard.
ci-complexity:
@ -302,8 +220,9 @@ api-gen:
go generate -tags "$(BUILD_TAGS)" ./internal/httpapi/apigen
# Two-part spec drift gate: regenerate and fail if regeneration CHANGED
# anything, then run the spec tests. CI runs the drift half as
# //scripts/repochecks:types_gen_drift_test.
# anything, then run the spec tests. Runs in the PR workflow's policy job
# (scripts/ci/pr-policy.sh), on every pull request, never only on
# push-to-main.
#
# The drift question is "do the checked-out types already match the checked-out
# spec", so the comparison is before-vs-after regeneration rather than
@ -461,15 +380,8 @@ fmt:
fmt-check:
@./scripts/ci/fmt-check.sh
# Docs checks: docsync and doc freshness as bazel.yml's test lane runs them,
# then the CLI flag check, which validates against bd built from the release in
# docs/cli-docs.pin (so it stays a script, like pr.yml's check-doc-flags job).
# Validate documentation references against actual CLI flags
check-docs:
$(BAZEL_TEST) //test/docsync:docsync_test //scripts/repochecks:doc_freshness_test --config=ci
@./scripts/check-doc-flags.sh
# The same docs checks with plain go test and a go-built bd.
check-docs-go:
@echo "Building bd for docs checks..."
@CGO_ENABLED=0 go build -tags "$(BUILD_TAGS)" -ldflags="-X main.Build=$(GIT_BUILD)" -o "$(BUILD_DIR)/bd" ./cmd/bd
@./scripts/check-doc-flags.sh "$(BUILD_DIR)/bd"
@ -504,10 +416,12 @@ diagrams-excalidraw:
docs-dev:
./mint.sh dev
# Regenerate BUILD.bazel files with gazelle and refresh the MODULE.bazel
# Bazel (side-by-side with the Go toolchain; `go build`/`go test` do not need
# it). Regenerate BUILD.bazel files with gazelle and refresh the MODULE.bazel
# use_repo list + MODULE.bazel.lock, then refresh the go_srcs filegroups that
# source-scanning tests declare as data (tools/bazel/go_srcs.py). Run after
# changing Go imports, go.mod, or packages.
BAZEL ?= bazel
bazel-sync:
$(BAZEL) run //:gazelle
python3 tools/bazel/go_srcs.py
@ -543,16 +457,12 @@ help:
@echo "Beads Makefile targets:"
@echo " make build - Build the bd binary"
@echo " make doctor-build - Diagnose build env (GOFLAGS/CGO/CC) for the ICU build trap"
@echo " make test - bazel test //... --config=ci (bazel.yml's test lane; BAZEL_FLAGS adds flags)"
@echo " make test-go - Plain go test via scripts/test.sh (inner loop; not what CI enforces)"
@echo " make check - testing.Short policy + nogo lint gate + make test"
@echo " make check-go - gofmt + testing.Short policy + make test-go (no Bazel)"
@echo " make test - Run all tests"
@echo " make test-icu-path - Run opt-in ICU regex path tests (maintainer-only)"
@echo " make test-full-cgo - Deprecated alias for make test-icu-path"
@echo " make ci-pr-core - Run required PR core Go test wrapper"
@echo " make ci-pr-lint - Run the required lint gate: nogo (vet + golangci-lint's linters) under Bazel, native + windows/darwin"
@echo " make lint - Same as ci-pr-lint (make vet too)"
@echo " make lint-changed - nogo over the Bazel packages of changed Go files (LINT_CHANGED_SCOPE=staged|worktree)"
@echo " make ci-pr-policy - Run required PR policy wrapper"
@echo " make ci-pr-lint - Run required PR formatting and lint wrapper"
@echo " make ci-complexity - Report production cyclomatic complexity (advisory)"
@echo " make ci-complexity-diff - Compare complexity with COMPLEXITY_BASE_REF"
@echo " make ci-complexity-check - Check complexity against the local baseline"
@ -568,8 +478,7 @@ help:
@echo " make install-force - Install bd, skipping the origin/main update check"
@echo " make fmt - Format all Go files with gofmt"
@echo " make fmt-check - Check Go formatting (for CI)"
@echo " make check-docs - Bazel docsync + doc freshness tests, then the CLI flag check"
@echo " make check-docs-go - The same docs checks with plain go test"
@echo " make check-docs - Validate docs against CLI flags"
@echo " make api-gen - Regenerate HTTP API types from the OpenAPI spec"
@echo " make api-check - OpenAPI drift gate (regenerate, diff-or-fail, spec tests)"
@echo " make bazel-sync - Regenerate Bazel BUILD files and tidy MODULE.bazel (gazelle + mod tidy)"

156
README.md
View file

@ -42,7 +42,7 @@ bd setup factory # Factory.ai Droid - creates/updates AGENTS.md
**Note:** Beads is a CLI tool you install once and use everywhere. You don't need to clone this repository into your project.
`bd init` creates or updates `AGENTS.md` by default so agents can discover the beads workflow, and also installs the project Claude Code, Codex, and Cursor integrations unless you pass `--skip-agents` or `--stealth`. Use `bd setup --list` to see supported integrations, including `bd setup codex`, `bd setup factory`, `bd setup claude`, `bd setup mux`, `bd setup cursor`, and more. See [Agent and IDE setup](docs/getting-started/ide-setup.md).
`bd init` creates or updates `AGENTS.md` by default so agents can discover the beads workflow, and also installs project Claude/Codex integrations unless you pass `--skip-agents` or `--stealth`. Use `bd setup --list` to see supported integrations, including `bd setup codex`, `bd setup factory`, `bd setup claude`, `bd setup mux`, `bd setup cursor`, and more. See [Agent and IDE setup](docs/getting-started/ide-setup.md).
Manual copy-paste is only for unsupported agents, existing projects where you cannot rerun `bd init`/`bd setup`, or custom instruction files. In those cases, run `bd onboard` and paste the printed snippet into the file your agent reads.
@ -109,8 +109,8 @@ version: sync remote-backed databases with your current `bd`, back up with
`bd export --all`, upgrade the binary, then run `bd info --whats-new`,
`bd hooks install`, and `bd version`. If the upgrade crosses a schema
migration on a remote-backed database, exactly one designated clone runs
`bd migrate schema` and `bd dolt push`; other clones install the new
binary and run `bd bootstrap`. See the full
`bd migrate` and `bd dolt push`; other clones install the new binary
and run `bd bootstrap`. See the full
[upgrade guide](https://beads.gascity.com/getting-started/upgrading)
or [docs/getting-started/installation.md](docs/getting-started/installation.md#updating-bd).
@ -175,153 +175,6 @@ are unaffected.
the guard with a warning on stderr. Use this only if you know the forward
migrations are additive and safe for your specific workload.
## 🔌 HTTP Backend (experimental)
A workspace can also talk to a remote `bd serve` over HTTP instead of opening
a local Dolt database — useful for a thin client against a shared server, or
for embedding beads in another program as a library.
```bash
# Point this workspace at a server (verifies the server first; writes nothing on failure)
bd connect https://bd.example.com --expect-project-id my-project
# The everyday commands work the same way: create, show, list, update, close,
# dependencies (including `bd dep tree`), comments, ready/count queries, and
# batch apply all round-trip over the wire with the same semantics as a local
# database. So does `bd ready --claim`, except against an older server or while
# any issue holds an unsatisfied external ref: then it lists and claims in two
# steps rather than one transaction (ledger row L14, linked below).
bd create "Fix auth bug" -p 1 -t bug
bd ready --json
bd close bd-a1b2 "Fixed"
# Loopback needs no TLS
bd connect http://127.0.0.1:8080
# Forget the server and restore this workspace's previous backend selection
bd connect --clear
```
HTTP mode is not a byte-for-byte mirror of local mode, though: some
operations are knowingly refused (the wire has no way to express them) or
degrade to a different-but-not-misreadable behavior (for example, a few
unbounded listing shapes lose single-query snapshot isolation and instead
walk the server page by page). Every one of these is a deliberate, tested
row, never a silent gap — see
[`engdocs/design/http-divergence-ledger.md`](engdocs/design/http-divergence-ledger.md)
for the full, generated list of what differs and why before depending on an
HTTP-backed workspace for a workflow you haven't checked against it. One
refusal to know up front: `bd close --claim-next` closes nothing over HTTP,
because the wire's batch close cannot carry the claim. Close without it, then
run `bd ready --claim`.
[Cross-repo dependencies](docs/core-concepts/dependencies.md#cross-repo-dependencies)
keep their policy over HTTP. The client resolves each `external:` reference
against its own `external_projects` configuration. `bd dep tree` shows the
reference as a leaf, and while it is unsatisfied the issue stays out of
`bd ready` and `bd ready --claim`, and `bd close` refuses it without
`--force`. A server that advertises enforcing that policy itself is trusted
to do so instead.
Three CLI-level differences are worth knowing up front:
- IDs resolve exactly: an abbreviated id is not expanded (the wire has no
substring search), and a missing id is reported as not found after one
lookup.
- `bd update -s closed` does not record `closed_by_session` (from `--session`
or `CLAUDE_SESSION_ID`), because the wire's update cannot carry it; the
close itself happens as usual. `bd close` does record the session. `bd
reopen`'s history entry carries the server's own label.
- Contributor auto-routing (`routing.*` settings) is read from local
`config.yaml` / environment only, never from the server's settings: its
targets are local paths.
`bd connect` writes two things on success: `.beads/metadata.json` gets
`"backend": "http"`, and a per-user, never-git-tracked sidecar
(`.beads/http_target.json`) records the server URL and pinned project id. It
never writes a credential to disk. A bearer credential, if the server
requires one, comes from `BEADS_HTTP_TOKEN=host[:port]=<token>`, then
`BEADS_HTTP_TOKEN_COMMAND=host[:port]=<command>` (a helper that prints a
token), then the credentials file, then no credential at all. Both variables
must name the server they are for (a pattern without a port matches that
host on any port); a bare value is refused, because it would be sent to
whatever server the workspace's `http_target.json` names. Connecting to a
non-loopback server over plain `http://` is refused by default (a bearer
credential would cross the network unencrypted) — pass `--allow-plaintext` to
override, or use `https://`. Switching a workspace that already selects a
different backend needs `--force`.
Each read (a GET, or the POST batch get) gives its first attempt 15s, from
when the request is sent, to get the server's response headers
(`BEADS_HTTP_RESPONSE_HEADER_TIMEOUT`: a duration such as `30s`, a number of
seconds, or `off`). A read whose headers do not arrive in time, or whose
connection is reset, is retried once on another connection, and each retry
is logged to stderr with its count. The retry has no header timer, but it
runs on what is left of the 60s bound on the whole request, counted from
when the first attempt was sent: a slow but healthy read still finishes if
the retry's headers and body together fit in that remainder (about 45s after
a header timeout), and one that needs longer now fails at 60s. The header
timer never cuts off a body that is still streaming; the 60s bound still
does. The events:watch stream's connect gets neither the header timer nor
the retry. On Windows a reset connection is retried only when it surfaces as
an early EOF, because the check matches the Unix reset error (`ECONNRESET`),
which a Windows reset (`WSAECONNRESET`) is not. A write gets no
header timer (the server answers a write only after it commits, so a large
one can be slow and healthy) and is never retried; if the 60s bound expires
after it was sent but before its headers, it fails with an error naming the
server's host, because it may or may not have been applied. A batch apply of
more than 100 items (a large `bd create --graph` plan, say) gets 6 minutes
instead of 60s, because `bd serve` gives such a request its
`--large-apply-ceiling` (5 minutes by default) and finishes it even after the
client has given up. A server whose ceiling is raised past about 5m15s can
still outlast the client. A dial or TLS timeout stays a plain connection
error, since the server never saw the request, and a connect that fails says
so: it names the address that refused the connection (nothing listening) or
never answered (a filtered port or a down host, after the dialer's 30s), or
the host name that did not resolve. `off` turns off only the
header timer: a reset read is still retried, and a write's timeout is still
reported as above.
Whether the server applies bd's external-dependency policy itself (the
`policy.external_dependencies` capability) is remembered for 5 minutes per
server URL and pinned project, in `beads/http-policy/` under the user cache
directory, so `bd ready` does not fetch the server's context before every
listing just to learn it. `BEADS_HTTP_POLICY_CACHE_TTL` sets that window (a
duration such as `1m`, a number of seconds, or `off`); a server restarted
with a different composition is seen once it passes. Claims and closes never
use the cached answer: they ask the server, since a stale one could skip the
client-side refusal of externally blocked work. A workspace connected without
a project pin is not cached.
`bd search`, `bd show --current` and `bd recompute-blocked` work over HTTP
too, each in its own way. `bd search` asks the server's listing with its text (`q`, behind the `issues.list.search` capability) and
refuses before dialing against a server that does not advertise it. `bd list
--no-assignee`, `--title` and `--id` likewise ride the listing's
`no_assignee`, `title` and repeatable `id`, each behind its own capability
(`issues.list.noAssignee`, `issues.list.title`, `issues.list.ids`), and the
rest of `bd list`'s filters (`--updated-*`, `--closed-*`, `--defer-*`,
`--due-*`, `--priority*`, the text and external-ref matches, `--spec`,
`--label-pattern`/`--label-regex`, `--exclude-type`, `--no-parent`,
`--no-labels`, `--empty-description`, `--pinned`/`--no-pinned`,
`--deferred`, `--overdue`, `--mol-type`, `--wisp-type`) ride it behind one
capability, `issues.list.filters`. Time bounds are resolved on the client as
they are locally; `--overdue` compares against the server's clock. The
default `--parent` tree view does not carry those filters yet and refuses one
rather than drop it; `--flat` or `--json` applies them to the parent's direct
children (not its whole subtree).
`bd show --current` finds the actor's in-progress or hooked issue through the
server's boolean query. `bd recompute-blocked` is a no-op that exits 0: the
server maintains `is_blocked` on every write, and repairing a stale flag is
done in the server's own workspace (`--json` reports
`{"rows_corrected": 0, "maintained_by": "server"}`).
An embedding program that links beads as a library rather than running
`cmd/bd` registers this backend itself through the public
[`backend/http`](backend/http) package (`bdhttp.Register`), and can open a
workspace with a credential scoped to one caller via
`beads.OpenBestAvailableWith` — see that package's doc comment for the
multi-tenant case. This surface is EXPERIMENTAL: pin an exact beads version.
## 🌐 Community Tools
See [docs/community-tools.md](docs/community-tools.md) for a curated list of community-built UIs, extensions, and integrations—including terminal interfaces, web UIs, editor extensions, and native apps.
@ -358,6 +211,5 @@ This is useful for:
## 📝 Documentation
* [Documentation site](https://beads.gascity.com/) | [Installing](docs/getting-started/installation.md) | [Sync Concepts](docs/core-concepts/sync-concepts.md) | [Agent Setup](docs/getting-started/ide-setup.md) | [Copilot CLI Setup](docs/integrations/copilot-cli.md) | [Copilot VS Code MCP](docs/integrations/github-copilot.md) | [Articles](ARTICLES.md) | [Sync Branch Mode](docs/reference/protected-branches.md) | [Troubleshooting](docs/reference/troubleshooting.md) | [FAQ](docs/reference/faq.md)
* Contributing: [CONTRIBUTING.md](CONTRIBUTING.md) (Bazel builds and tests beads: install [Bazelisk](https://github.com/bazelbuild/bazelisk), then `make test`) | [Roadmap](ROADMAP.md) | [Contributor agent instructions](AGENTS.md)
* [Documentation site](https://beads.gascity.com/) | [Installing](docs/getting-started/installation.md) | [Sync Concepts](docs/core-concepts/sync-concepts.md) | [Agent Workflow](AGENT_INSTRUCTIONS.md) | [Copilot CLI Setup](docs/integrations/copilot-cli.md) | [Copilot VS Code MCP](docs/integrations/github-copilot.md) | [Articles](ARTICLES.md) | [Sync Branch Mode](docs/reference/protected-branches.md) | [Troubleshooting](docs/reference/troubleshooting.md) | [FAQ](docs/reference/faq.md)
* [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/gastownhall/beads)

View file

@ -94,19 +94,15 @@ release-critical gates do not all run on every PR, so "tag the tip of main"
means tagging a SHA nobody has fully tested. A burned tag is never reused
(the v1.1.1 and v1.2.0 precedents), so that gamble is expensive.
**Cut the branch from a SHA that is green on `Bazel`, `Main` and
`Nightly`.** The `Bazel` workflow (every Linux test lane, on rbe-west) and
the `Main` workflow (the macOS and Windows jobs) run on push to `main`, and
the `Nightly` workflow (the full Bazel suite with no cached test results)
runs on a 2am UTC schedule, so the newest SHA with all three is usually a
few hours behind the tip:
**Cut the branch from a SHA that is green on both `Main` and
`Nightly Full Tests`.** The `Main` workflow runs on push to `main` and the
`Nightly Full Tests` workflow runs on a 2am UTC schedule, so the newest SHA
with both is usually a few hours behind the tip:
```bash
gh run list --workflow Bazel --branch main --event push --status success --limit 5 \
--json headSha,conclusion,createdAt
gh run list --workflow Main --branch main --status success --limit 5 \
--json headSha,conclusion,createdAt
gh run list --workflow Nightly --status success --limit 3 \
gh run list --workflow "Nightly Full Tests" --status success --limit 3 \
--json headSha,conclusion,createdAt
git fetch origin
@ -140,17 +136,16 @@ git log --oneline main..release/1.3.0
Before starting a release:
- [ ] `release/x.y.z` branch cut from a SHA green on `Bazel`, `Main` **and**
`Nightly` (see [Release Branches](#release-branches))
- [ ] All tests passing (`make test`, the Bazel test lane)
- [ ] `release/x.y.z` branch cut from a SHA green on `Main` **and**
`Nightly Full Tests` (see [Release Branches](#release-branches))
- [ ] All tests passing (`go test ./...`)
- [ ] npm package tests passing (`cd npm-package && npm run test:all`)
- [ ] **Upgrade smoke tests pass** (`make test-upgrade`) — see [Release Stability Gate](engdocs/RELEASE-STABILITY-GATE.md)
- [ ] **Regression tests pass**
(`bazel test //tests/regression:regression_test --config=doltserver-cmd`)
- [ ] **Regression tests pass** (`make test-regression`)
- [ ] **Every release target cross-compiles** — see
[Cross-compile before tagging](#cross-compile-before-tagging). PR CI
builds them only with cgo off, and a target that fails at tag time
burns the tag.
[Cross-compile before tagging](#cross-compile-before-tagging). PR CI does
not build them ([#5662](https://github.com/gastownhall/beads/issues/5662)),
and a target that fails at tag time burns the tag.
- [ ] **CHANGELOG.md updated with release notes** (see format below)
- [ ] **CHANGELOG rollup checked** — nothing left under `[Unreleased]` that
belongs in this release, and nothing filed under a *previous* release's
@ -168,15 +163,12 @@ Before starting a release:
### Cross-compile before tagging
`.goreleaser.yml` builds darwin, linux, windows **and freebsd**; the v1.2.0
tag burned on a freebsd compilation failure no pre-tag gate caught
([#5661](https://github.com/gastownhall/beads/pull/5661),
[#5662](https://github.com/gastownhall/beads/issues/5662)). PR CI now builds
the whole tree for every target in `scripts/ci/release-targets.txt` with Bazel
(`scripts/ci/bazel-release-cross-compile.sh`, in bazel.yml's pure-Go lane),
but with cgo off, while linux/amd64, linux/arm64, windows/amd64 and the darwin
pair ship with `CGO_ENABLED=1`. Build the real release configuration by hand
before tagging:
`.goreleaser.yml` builds darwin, linux, windows **and freebsd**, but PR CI
builds none of the cross targets — the v1.2.0 tag burned on a freebsd
compilation failure that no pre-tag gate could have caught
([#5661](https://github.com/gastownhall/beads/pull/5661) fixed the break,
[#5662](https://github.com/gastownhall/beads/issues/5662) tracks the CI gap).
Until that gap is closed, build them by hand before tagging:
```bash
goreleaser build --snapshot --clean

View file

@ -1,71 +0,0 @@
# Beads Roadmap
Last updated: 2026-10-05 · Owner: [@julianknutsen](https://github.com/julianknutsen)
This page lists the areas the maintainers are prioritizing. It reflects
current thinking, not commitments or dates: priorities change as we learn,
and the live state of each item is its tracking issue on GitHub.
## How this roadmap is used
- **Priority areas get expedited review.** Issues and PRs that advance a
priority area below are triaged and reviewed first.
- **Propose work with an issue when it warrants discussion.** For work
inside or outside a priority area that needs context or a design decision,
open an issue with the feature form, before or alongside your PR; small,
self-explanatory changes can go straight to a PR. See
[CONTRIBUTING.md](CONTRIBUTING.md#issues-and-pull-requests).
- **Scope.** Proposals must fit the product boundary in
[engdocs/PROJECT_CHARTER.md](engdocs/PROJECT_CHARTER.md).
- **Updates.** The owner rewrites this page at each minor release; the date
above says when it was last reviewed.
## Priority areas for 1.4
### Versioned beads and history
- **Goal:** every change to a bead is recorded as a version. Users can read
a bead's history and past versions, and writers can use `expectedRevision`
compare-and-swap to avoid lost updates. Everything ships behind a flag, off
by default, until the conformance suite and a production-corpus soak say
otherwise.
- **This period:** all six phases, enabled from the CLI by the end of the
period: conformance suite
([#6133](https://github.com/gastownhall/beads/issues/6133)), additive
schema ([#6134](https://github.com/gastownhall/beads/issues/6134)),
dual-write history behind a flag
([#6135](https://github.com/gastownhall/beads/issues/6135)), versioned
reads and CAS ([#6136](https://github.com/gastownhall/beads/issues/6136)),
production-corpus validation
([#6137](https://github.com/gastownhall/beads/issues/6137)), and CLI
surfacing and enablement
([#6138](https://github.com/gastownhall/beads/issues/6138)).
- **Tracking issue:** [#6132](https://github.com/gastownhall/beads/issues/6132);
design discussion stays on
[#5898](https://github.com/gastownhall/beads/issues/5898).
### Beads Graph Preview 2
- **Goal:** ship Beads Graph Preview 2, the next public checkpoint for the
generic Bead-and-Link graph model: a coherent daily-use CLI journey in
graph mode that behaves like ordinary `bd`, backed by a complete,
reviewable CLI specification.
- **This period:** the reviewed graph CLI specification, a complete
daily-use Issue journey proven through the installed CLI on embedded and
shared-server Dolt, and editing around that Issue (labels, notes, Memory
and Link edits).
- **Tracking issue:** [#7170](https://github.com/gastownhall/beads/issues/7170)
### Contributor onboarding
- **Goal:** a new contributor, human or agent, finds the rules for the code
they are changing next to that code, understands its intent and
invariants, and lands a well-explained PR, backed by an issue when the
change warrants one.
- **This period:** contributor-only agent instructions and documented-issue
intake ([#7223](https://github.com/gastownhall/beads/pull/7223));
per-package `AGENTS.md` files for the storage packages, naming their
guard tests and lint rules; a package-doc linter and package docs for the
packages that have none; and a curated set of `help wanted` starter
issues.
- **Tracking issue:** [#7228](https://github.com/gastownhall/beads/issues/7228)

View file

@ -19,7 +19,7 @@ Row numbers are the historical table's. Line numbers in this table are against t
| # | Path | Version seam at this head | Disposition | Mechanism |
|---|---|---|---|---|
| 13 | any of rows 1-8 whose target row is a wisp **or a promoted no-history bead** | no | NO-OP (a flagged issues-table create is stamped, not versioned) | The table that holds the row decides its plane, not its flags. A row in the wisps table mints and stamps nothing, whatever its flags say (FR-8). An update-shaped call on a flagged wisp returns on `IsWisp`, which is `Ephemeral \|\| NoHistory` (helpers.go:36-41). Every other wisps-table row is excluded by the seam's read of `participation_generation` from the issues table, which finds no row and returns: a flagged wisp's create-shaped call, and an unflagged row (bd mol squash's in-place flag clear, import's `wisp_plane` marker), which passes `IsWisp`. An issues-table row carrying `NoHistory` (a promoted no-history bead, bd-r9uce) is never versioned while it says so, because no-history means no history: an update-shaped call returns on `IsWisp`. A create-shaped call on such a row, with the flag on, still stamps `participation_generation` and mints nothing, so the row is not legacy once `bd update --persistent` repairs the flag in place. |
| 13 | any of rows 1-8 whose target row is a wisp **or a promoted no-history bead** | no | NO-OP | `RecordVersionInTx` returns on `IsWisp`, which is `Ephemeral \|\| NoHistory` (helpers.go:36-41): wisps per FR-8, and a promoted no-history bead — a durable issues-plane row with `NoHistory=true` — because no-history means no history. Wording only; the code did not change. |
| 14 | dependencies.go:`addDependencyInTx` via `AddDependencyInTx` from the store verbs, `ApplyParentPatch`, `applyBatchRun.applyDepAdd` | yes | VERSIONED | mint moved into `addDependencyInTx` (`mintDependencyVersion`, dependencies.go:393), gated on the row insert rather than on `eventWritten`; the publicops editor's own mint call was removed so no leg double-mints |
| 15 | domain/db/dependency.go:`dependencySQLRepositoryImpl.Insert` (uow `AddDependencies`, create-time edges) | yes | VERSIONED | seam at dependency.go:228 and :240 after the insert |
| 16 | dependencies.go:`removeDependencyInTx` via `RemoveDependencyInTx` and domain/db/dependency.go:`Delete` | yes | VERSIONED | gated on the row delete; dependency.go:409 on the uow leg |

View file

@ -43,64 +43,3 @@ filegroup(
)
# --- end go_srcs ---
# --- begin repo_files (managed by tools/bazel/go_srcs.py; run `make bazel-sync`) ---
filegroup(
name = "repo_doc_files",
srcs = glob(
[
"**/*.md",
"**/*.mdx",
],
allow_empty = True,
exclude = ["**/node_modules/**"],
),
visibility = ["//:__subpackages__"],
)
filegroup(
name = "repo_go_srcs",
srcs = glob(
["**/*.go"],
allow_empty = True,
exclude = [
"**/*_test.go",
"**/node_modules/**",
],
),
visibility = ["//:__subpackages__"],
)
filegroup(
name = "repo_go_test_srcs",
srcs = glob(
["**/*_test.go"],
allow_empty = True,
exclude = ["**/node_modules/**"],
),
visibility = ["//:__subpackages__"],
)
filegroup(
name = "repo_other_files",
srcs = glob(
["**"],
exclude = [
"**/*.db",
"**/*.exe",
"**/*.go",
"**/*.md",
"**/*.mdx",
"**/*.out",
"**/*.prof",
"**/*.pyc",
"**/*.test",
"**/__pycache__/**",
"**/node_modules/**",
],
),
visibility = ["//:__subpackages__"],
)
# --- end repo_files ---

View file

@ -140,37 +140,6 @@ type VCStatus = storage.Status
// store. See the field docs on the aliased struct.
type Backend = backends.Backend
// OpenOptions carries per-open injections (Credential, HTTPClient,
// UserAgent) that Backend.OpenWith may use. See the field docs on the
// aliased struct.
type OpenOptions = backends.OpenOptions
// Credential is the opaque per-open credential marker OpenOptions.Credential
// carries. A backend that needs one declares its own narrower interface and
// type-asserts the value its OpenWith receives. See the aliased type's docs.
type Credential = backends.Credential
// ErrCredentialWithoutOpenWith is returned by Backend.OpenWithOptions when
// OpenOptions.Credential is set but the backend has no OpenWith to honor it.
var ErrCredentialWithoutOpenWith = backends.ErrCredentialWithoutOpenWith
// ErrHTTPClientWithoutOpenWith is returned by Backend.OpenWithOptions when
// OpenOptions.HTTPClient is set but the backend has no OpenWith to honor it.
// Same fail-closed family as ErrCredentialWithoutOpenWith.
var ErrHTTPClientWithoutOpenWith = backends.ErrHTTPClientWithoutOpenWith
// ErrUserAgentWithoutOpenWith is returned by Backend.OpenWithOptions when
// OpenOptions.UserAgent is set but the backend has no OpenWith to honor it.
// Same fail-closed family as ErrCredentialWithoutOpenWith.
var ErrUserAgentWithoutOpenWith = backends.ErrUserAgentWithoutOpenWith
// ErrUnsupportedCredential is the typed refusal an OpenWith implementation
// MUST return (directly or wrapped, so errors.Is still matches) when it
// receives a non-nil Credential that does not type-assert to the narrower
// credential interface that backend's OpenWith expects. See the aliased
// error's docs in internal/storage/backends for the full contract.
var ErrUnsupportedCredential = backends.ErrUnsupportedCredential
// Register adds a backend under name. It is process-start wiring: call it
// once during initialization (typically from a registrant package's init that
// the embedding binary blank-imports), before any concurrent store access.
@ -202,12 +171,6 @@ func WorkspaceIsBeadsDir(name string) bool {
return backends.WorkspaceIsBeadsDir(name)
}
// IsRemote reports whether name is a registered backend that is a pure
// network client of a bd serve with no local database (see Backend.Remote).
func IsRemote(name string) bool {
return backends.IsRemote(name)
}
// Iter is the streaming-read cursor returned by the Iter* methods.
type Iter[T any] = storage.Iter[T]

View file

@ -11,11 +11,8 @@ go_library(
"audit_molecule_wisp_batch_iter.go",
"audit_search-counts-stats.go",
"batch_apply_contract.go",
"batch_apply_gate_contract.go",
"batch_closer_contract.go",
"batch_creator_contract.go",
"batch_getter_contract.go",
"blocked_lister_contract.go",
"blocked_state.go",
"blocking_annotator_contract.go",
"bootstrapper_contract.go",
@ -29,25 +26,19 @@ go_library(
"deleter_contract.go",
"dependency_editor_contract.go",
"dualwrite_history_contract.go",
"dualwrite_participation_generation_contract.go",
"edge_reader_contract.go",
"expected_revision_contract.go",
"graph_counter_contract.go",
"heartbeater_contract.go",
"history_matching.go",
"importer_contract.go",
"issue_operations_contract.go",
"issue_operations_staging.go",
"journal_contract.go",
"lease_reclaimer_contract.go",
"lifecycle_close_reopen_contract.go",
"lifecycle_create_contract.go",
"lifecycle_create_gate_contract.go",
"lifecycle_update_contract.go",
"lifecycle_update_gate_contract.go",
"memories_contract.go",
"metadata_cas_contract.go",
"molecule_contract.go",
"portable.go",
"querier_contract.go",
"reader_contract.go",
@ -65,13 +56,11 @@ go_library(
"transaction_parity.go",
"tree_walker_contract.go",
"version_reconciler_contract.go",
"versioned_read_contract.go",
"workspaceconfig_contract.go",
],
importpath = "github.com/steveyegge/beads/backend/conformance",
visibility = ["//visibility:public"],
deps = [
"//internal/hooks",
"//internal/storage",
"//internal/storage/issueops",
"//internal/storage/kvkeys",
@ -121,64 +110,3 @@ filegroup(
)
# --- end go_srcs ---
# --- begin repo_files (managed by tools/bazel/go_srcs.py; run `make bazel-sync`) ---
filegroup(
name = "repo_doc_files",
srcs = glob(
[
"**/*.md",
"**/*.mdx",
],
allow_empty = True,
exclude = ["**/node_modules/**"],
),
visibility = ["//:__subpackages__"],
)
filegroup(
name = "repo_go_srcs",
srcs = glob(
["**/*.go"],
allow_empty = True,
exclude = [
"**/*_test.go",
"**/node_modules/**",
],
),
visibility = ["//:__subpackages__"],
)
filegroup(
name = "repo_go_test_srcs",
srcs = glob(
["**/*_test.go"],
allow_empty = True,
exclude = ["**/node_modules/**"],
),
visibility = ["//:__subpackages__"],
)
filegroup(
name = "repo_other_files",
srcs = glob(
["**"],
exclude = [
"**/*.db",
"**/*.exe",
"**/*.go",
"**/*.md",
"**/*.mdx",
"**/*.out",
"**/*.prof",
"**/*.pyc",
"**/*.test",
"**/__pycache__/**",
"**/node_modules/**",
],
),
visibility = ["//:__subpackages__"],
)
# --- end repo_files ---

View file

@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"reflect"
"strings"
"testing"
"github.com/steveyegge/beads/internal/types"
@ -171,12 +170,6 @@ func RunBatchApplyAppliesEveryItemInDeclarationOrder(t *testing.T, ctx context.C
if got := batchApplyColumn(t, ctx, fixture, "status", blocked); got == string(types.StatusClosed) {
t.Errorf("%s was closed by a request that only asked to close %s", blocked, blocker)
}
// Neither create item names a creator, so each defaults to the request's actor.
for _, id := range []string{blocked, blocker} {
if got := batchApplyColumn(t, ctx, fixture, "created_by", id); got != "apply-writer" {
t.Errorf("%s created_by = %q, want the request's actor %q", id, got, "apply-writer")
}
}
}
// RunBatchApplyBindsEachNamedKeyToItsMintedID pins ApplyBatchResult.Keys: it is
@ -888,12 +881,9 @@ func RunBatchApplyEvaluatesExpectedAssigneeAsModified(t *testing.T, ctx context.
// close it. The refusal is the assertion; the rollback of the parent it created
// is what says the refusal took the request with it.
//
// POSITIVE HALF: the identical request with Force lands, and that is the proof
// the refusal was the policy rather than the shape. Force "bypasses blocker and
// open-child close policy, the pin and the assignee fence, and never the
// template guard" (batchapplier.go), and the parent trips no guard — the
// unforced half reached the policy, which the guards run before — so the
// policy is the only refusal Force had to waive.
// POSITIVE HALF: the identical request with Force lands, which is the whole of
// what Force does ("bypasses blocker and open-child close policy, and nothing
// else") and the proof that the refusal was the policy rather than the shape.
func RunBatchApplyClosePolicyEvaluatesAtTheCloseItem(t *testing.T, ctx context.Context, fixture BatchApplyFixture) {
t.Helper()
parent := fixture.IssuePrefix + "-closepolicy-parent"
@ -933,7 +923,7 @@ func RunBatchApplyClosePolicyEvaluatesAtTheCloseItem(t *testing.T, ctx context.C
t.Errorf("%s status = %q under Force, want %q", parent, got, types.StatusClosed)
}
if got := batchApplyColumn(t, ctx, fixture, "status", child); got != string(types.StatusOpen) {
t.Errorf("%s status = %q, want %q: Force waives the parent's close policy, it does not close the child", child, got, types.StatusOpen)
t.Errorf("%s status = %q, want %q: Force bypasses the close policy and nothing else", child, got, types.StatusOpen)
}
assertBatchApplyTypedEdgeCount(t, ctx, fixture, child, parent, string(publicops.DepParentChild), 1)
}
@ -1531,215 +1521,6 @@ func RunBatchApplyNormalizesTheWaitsForGate(t *testing.T, ctx context.Context, f
})
}
// RunBatchApplyStampsSpawnerIDOnlyWhenNamed is the S11 review fix-up
// regression for HIGH-2: a waits-for DepAddItem must only acquire
// metadata.spawner_id when the caller explicitly named a spawner
// (HasSpawner=true, which bd create --graph sets when the plan declares
// edges[].spawner_key/spawner_id, as does an embedder lowering such a plan
// onto this role). An edge with no named spawner must keep its gate-only
// metadata untouched — stamping it unconditionally from the resolved target
// caused unnecessary rewrite/version churn when gc re-applies the same edge
// (see CHANGELOG.md).
func RunBatchApplyStampsSpawnerIDOnlyWhenNamed(t *testing.T, ctx context.Context, fixture BatchApplyFixture) {
t.Helper()
spawner := fixture.IssuePrefix + "-spawner-named"
waiter := fixture.IssuePrefix + "-waiter-named"
batchApplySeedIssue(t, ctx, fixture, spawner, types.StatusOpen)
batchApplySeedIssue(t, ctx, fixture, waiter, types.StatusOpen)
batchApplyMust(t, ctx, fixture, publicops.ApplyBatchRequest{
Actor: "apply-writer",
Items: []publicops.ApplyItem{
{Kind: publicops.ItemDepAdd, DepAdd: &publicops.DepAddItem{
Source: publicops.Ref{ID: waiter},
Target: publicops.Ref{ID: spawner},
Type: publicops.DepWaitsFor,
Metadata: `{"gate":"any-children"}`,
HasSpawner: true,
}},
},
})
stored := batchApplyEdgeMetadata(t, ctx, fixture, waiter, spawner)
var meta types.WaitsForMeta
if err := json.Unmarshal([]byte(stored), &meta); err != nil {
t.Fatalf("stored named-spawner metadata %q: %v", stored, err)
}
if meta.SpawnerID != spawner {
t.Errorf("named-spawner edge spawner_id = %q, want %q (metadata %q)", meta.SpawnerID, spawner, stored)
}
spawner2 := fixture.IssuePrefix + "-spawner-unnamed"
waiter2 := fixture.IssuePrefix + "-waiter-unnamed"
batchApplySeedIssue(t, ctx, fixture, spawner2, types.StatusOpen)
batchApplySeedIssue(t, ctx, fixture, waiter2, types.StatusOpen)
batchApplyMust(t, ctx, fixture, publicops.ApplyBatchRequest{
Actor: "apply-writer",
Items: []publicops.ApplyItem{
batchApplyDepAdd(publicops.Ref{ID: waiter2}, publicops.Ref{ID: spawner2}, publicops.DepWaitsFor, `{"gate":"any-children"}`),
},
})
stored2 := batchApplyEdgeMetadata(t, ctx, fixture, waiter2, spawner2)
var meta2 types.WaitsForMeta
if err := json.Unmarshal([]byte(stored2), &meta2); err != nil {
t.Fatalf("stored unnamed-spawner metadata %q: %v", stored2, err)
}
if meta2.SpawnerID != "" {
t.Errorf("unnamed-spawner edge must not stamp spawner_id, got %q (metadata %q)", meta2.SpawnerID, stored2)
}
}
// RunBatchApplyCarriesThreadIDOntoTheStoredEdge pins DepAddItem.ThreadID
// (the 2026-10 Opus-review HIGH-2 finding): a conversation-threading id named
// on a dep_add item must land on the stored dependency row's own thread_id
// column, and an item that names none must store none. ThreadID is a plain
// column read independently of HasSpawner/Metadata, so this is its own case
// rather than a clause folded onto the spawner one above.
//
// Wired onto the http leg this exercises BOTH halves of the wire at once: the
// client's applyDepAddItemBody encode (batchapplier.go) and the server's
// applyDepAddItemMembers decode (internal/httpapi/batch_apply.go) must each
// carry the field, because either one silently dropping it leaves the stored
// column blank and fails the assertion below.
func RunBatchApplyCarriesThreadIDOntoTheStoredEdge(t *testing.T, ctx context.Context, fixture BatchApplyFixture) {
t.Helper()
source := fixture.IssuePrefix + "-thread-source"
target := fixture.IssuePrefix + "-thread-target"
batchApplySeedIssue(t, ctx, fixture, source, types.StatusOpen)
batchApplySeedIssue(t, ctx, fixture, target, types.StatusOpen)
const thread = "thread-conv-1"
batchApplyMust(t, ctx, fixture, publicops.ApplyBatchRequest{
Actor: "apply-writer",
Items: []publicops.ApplyItem{
{Kind: publicops.ItemDepAdd, DepAdd: &publicops.DepAddItem{
Source: publicops.Ref{ID: source}, Target: publicops.Ref{ID: target},
Type: publicops.DepBlocks, ThreadID: thread,
}},
},
})
if got := batchApplyEdgeThreadID(t, ctx, fixture, source, target); got != thread {
t.Errorf("stored edge thread_id = %q, want %q", got, thread)
}
source2 := fixture.IssuePrefix + "-thread-none-source"
target2 := fixture.IssuePrefix + "-thread-none-target"
batchApplySeedIssue(t, ctx, fixture, source2, types.StatusOpen)
batchApplySeedIssue(t, ctx, fixture, target2, types.StatusOpen)
batchApplyMust(t, ctx, fixture, publicops.ApplyBatchRequest{
Actor: "apply-writer",
Items: []publicops.ApplyItem{
batchApplyDepAdd(publicops.Ref{ID: source2}, publicops.Ref{ID: target2}, publicops.DepBlocks, ""),
},
})
if got := batchApplyEdgeThreadID(t, ctx, fixture, source2, target2); got != "" {
t.Errorf("an edge naming no thread must not stamp thread_id, got %q", got)
}
}
// RunBatchApplyCarriesThreadIDOntoAnExistingEdge pins DepAddItem.ThreadID on
// the re-add arm: a dep_add naming an edge that already exists with the same
// type is the idempotent re-add, and a thread it names still has to reach the
// stored row. That arm once compared and rewrote metadata alone, so a
// thread-only re-add was a silent no-op and a re-add moving both landed the
// metadata and dropped the thread — on the very path gc re-applies its plans
// through.
//
// The steps run on ONE edge, each from the state the step before it left: a
// thread-only re-add puts a thread on an edge that had none, a re-add moving
// the gate and the thread lands both, and a re-add naming no thread keeps the
// stored one, because an empty ThreadID names no thread rather than asking for
// none.
func RunBatchApplyCarriesThreadIDOntoAnExistingEdge(t *testing.T, ctx context.Context, fixture BatchApplyFixture) {
t.Helper()
source := fixture.IssuePrefix + "-rethread-source"
spawner := fixture.IssuePrefix + "-rethread-spawner"
batchApplySeedIssue(t, ctx, fixture, source, types.StatusOpen)
batchApplySeedIssue(t, ctx, fixture, spawner, types.StatusOpen)
add := func(gate, thread string) {
t.Helper()
batchApplyMust(t, ctx, fixture, publicops.ApplyBatchRequest{
Actor: "apply-writer",
Items: []publicops.ApplyItem{
{Kind: publicops.ItemDepAdd, DepAdd: &publicops.DepAddItem{
Source: publicops.Ref{ID: source}, Target: publicops.Ref{ID: spawner},
Type: publicops.DepWaitsFor, Metadata: `{"gate":"` + gate + `"}`, ThreadID: thread,
}},
},
})
}
assertEdge := func(step, wantGate, wantThread string) {
t.Helper()
assertBatchApplyEdgeCount(t, ctx, fixture, source, spawner, 1)
stored := batchApplyEdgeMetadata(t, ctx, fixture, source, spawner)
var meta types.WaitsForMeta
if err := json.Unmarshal([]byte(stored), &meta); err != nil {
t.Fatalf("%s: stored waits-for metadata %q is not a gate object: %v", step, stored, err)
}
if meta.Gate != wantGate {
t.Errorf("%s: stored gate = %q (metadata %q), want %q", step, meta.Gate, stored, wantGate)
}
if got := batchApplyEdgeThreadID(t, ctx, fixture, source, spawner); got != wantThread {
t.Errorf("%s: stored edge thread_id = %q, want %q", step, got, wantThread)
}
}
add(types.WaitsForAllChildren, "")
assertEdge("the first add, naming no thread", types.WaitsForAllChildren, "")
add(types.WaitsForAllChildren, "thread-conv-1")
assertEdge("a re-add moving the thread alone", types.WaitsForAllChildren, "thread-conv-1")
add(types.WaitsForAnyChildren, "thread-conv-2")
assertEdge("a re-add moving the gate and the thread", types.WaitsForAnyChildren, "thread-conv-2")
add(types.WaitsForAnyChildren, "")
assertEdge("a re-add naming no thread", types.WaitsForAnyChildren, "thread-conv-2")
}
// RunBatchApplyRefusesAThreadIDLongerThanItsColumn pins the bound on
// DepAddItem.ThreadID: one longer than the thread_id column holds is
// ErrValidation and writes no edge, on every leg alike. The http leg's decode
// refused it as a typed 400 while the local legs carried it to the write, where
// it failed as whatever storage error the column raised, mid-transaction — two
// error classes for one request. The shared plan bounds it now, before any
// database work.
//
// The positive half is the same edge with a thread exactly at the bound, which
// lands whole; without it, a role refusing every thread id satisfies the
// refusal.
func RunBatchApplyRefusesAThreadIDLongerThanItsColumn(t *testing.T, ctx context.Context, fixture BatchApplyFixture) {
t.Helper()
source := fixture.IssuePrefix + "-longthread-source"
target := fixture.IssuePrefix + "-longthread-target"
batchApplySeedIssue(t, ctx, fixture, source, types.StatusOpen)
batchApplySeedIssue(t, ctx, fixture, target, types.StatusOpen)
request := func(thread string) publicops.ApplyBatchRequest {
return publicops.ApplyBatchRequest{
Actor: "apply-writer",
Items: []publicops.ApplyItem{
{Kind: publicops.ItemDepAdd, DepAdd: &publicops.DepAddItem{
Source: publicops.Ref{ID: source}, Target: publicops.Ref{ID: target},
Type: publicops.DepBlocks, ThreadID: thread,
}},
},
}
}
tooLong := strings.Repeat("t", types.MaxFieldLen+1)
if _, err := fixture.BatchApplier.ApplyBatch(ctx, request(tooLong)); !errors.Is(err, publicops.ErrValidation) {
t.Fatalf("a %d-character thread_id: error = %v, want ErrValidation", len(tooLong), err)
}
assertBatchApplyEdgeCount(t, ctx, fixture, source, target, 0)
atBound := strings.Repeat("t", types.MaxFieldLen)
batchApplyMust(t, ctx, fixture, request(atBound))
if got := batchApplyEdgeThreadID(t, ctx, fixture, source, target); got != atBound {
t.Errorf("a %d-character thread_id stored as %d characters, want it whole", len(atBound), len(got))
}
}
// RunBatchApplySplicesAForwardMetadataRef pins the one exception to the
// backward-only rule (CreateItem.MetadataRefs): "IT IS THE ONE PLACE A KEY MAY
// REACH FORWARD … Every id is minted before any splice is applied, so the
@ -2001,56 +1782,21 @@ func RunBatchApplyLandsAnIdempotencyRecordWithItsWork(t *testing.T, ctx context.
// alone is satisfied by a bound one step away.
func RunBatchApplyBoundsTheItemCount(t *testing.T, ctx context.Context, fixture BatchApplyFixture) {
t.Helper()
RunBatchApplyBoundsTheItemCountAtScale(t, ctx, fixture, publicops.MaxApplyBatchItems)
}
// RunBatchApplyBoundsTheItemCountAtScale is RunBatchApplyBoundsTheItemCount
// with the "at bound" half's REAL applied count overridable to fewer than
// issueops.MaxApplyBatchItems, for a backend whose real engine makes
// applying a full MaxApplyBatchItems batch prohibitively slow in one CI
// configuration (embedded-dolt under the race detector: this subtest alone
// measured 903-945s there, because the in-process Dolt engine's own
// goroutine/lock machinery runs inside the instrumented binary).
//
// This does NOT weaken the boundary this contract pins. The production
// bound itself — exactly issueops.MaxApplyBatchItems accepted, one more
// refused — is independent of atBoundItems and is NOT re-derived from a
// real apply here: every backend's ApplyBatch calls the SAME
// storage.PlanApplyBatch to decide accept-vs-refuse, before touching
// storage at all (batch_applier.go: "VALIDATION HAPPENS BEFORE THE
// TRANSACTION"), and that shared function's own boundary is independently
// pinned, for real, pure and sub-millisecond, by
// TestPlanApplyBatchAcceptsTheBoundary and its "too many items" sibling in
// internal/storage/batch_apply_test.go — run on every `go test`, every
// backend, every PR, unaffected by atBoundItems. The refusing half below is
// UNCHANGED regardless of atBoundItems: it still sends the true
// MaxApplyBatchItems+1 count, because that half is already O(1) (the same
// pre-transaction length check, no backend ever reaches a write). Only the
// "at bound" half's REAL applied count is adjustable, to prove a backend's
// own write body does not drop, double or truncate a large accepted batch
// without paying for the full MaxApplyBatchItems every time one backend's
// real engine makes that unusually expensive.
func RunBatchApplyBoundsTheItemCountAtScale(t *testing.T, ctx context.Context, fixture BatchApplyFixture, atBoundItems int) {
t.Helper()
if atBoundItems < 1 || atBoundItems > publicops.MaxApplyBatchItems {
t.Fatalf("atBoundItems = %d, want 1..%d (the production bound this contract pins)", atBoundItems, publicops.MaxApplyBatchItems)
}
const accepted = "batch apply at the item bound"
const refused = "batch apply over the item bound"
atBound := make([]publicops.ApplyItem, atBoundItems)
atBound := make([]publicops.ApplyItem, publicops.MaxApplyBatchItems)
for i := range atBound {
atBound[i] = batchApplyCreate("", batchApplyMintedIssue(accepted))
}
result := batchApplyMust(t, ctx, fixture, publicops.ApplyBatchRequest{Actor: "apply-writer", Items: atBound})
if len(result.Items) != atBoundItems {
t.Fatalf("a request of %d items returned %d item results, want %d", atBoundItems, len(result.Items), atBoundItems)
if len(result.Items) != publicops.MaxApplyBatchItems {
t.Fatalf("a request of exactly MaxApplyBatchItems returned %d item results, want %d", len(result.Items), publicops.MaxApplyBatchItems)
}
if got := batchApplyCount(t, ctx, fixture, "SELECT COUNT(*) FROM issues WHERE title = ?", []any{accepted}); got != atBoundItems {
t.Errorf("%d row(s) landed for a request of %d items, want %d", got, atBoundItems, atBoundItems)
if got := batchApplyCount(t, ctx, fixture, "SELECT COUNT(*) FROM issues WHERE title = ?", []any{accepted}); got != publicops.MaxApplyBatchItems {
t.Errorf("%d row(s) landed for a request of exactly MaxApplyBatchItems, want %d", got, publicops.MaxApplyBatchItems)
}
// Unchanged: the true production bound, regardless of atBoundItems.
overBound := make([]publicops.ApplyItem, publicops.MaxApplyBatchItems+1)
for i := range overBound {
overBound[i] = batchApplyCreate("", batchApplyMintedIssue(refused))
@ -2403,20 +2149,6 @@ func batchApplyEdgeMetadata(t *testing.T, ctx context.Context, fixture BatchAppl
return blob
}
// batchApplyEdgeThreadID reads the stored thread_id column of one edge, which
// is where DepAddItem.ThreadID has to be visible — a plain column, independent
// of the type-specific Metadata blob batchApplyEdgeMetadata reads.
func batchApplyEdgeThreadID(t *testing.T, ctx context.Context, fixture BatchApplyFixture, source, target string) string {
t.Helper()
var value string
const query = "SELECT COALESCE(thread_id, '') FROM dependencies WHERE issue_id = ?" +
" AND COALESCE(depends_on_issue_id, depends_on_wisp_id, depends_on_external) = ?"
if err := fixture.QueryScalar(ctx, query, []any{source, target}, &value); err != nil {
t.Fatalf("reading edge thread_id for %s -> %s: %v", source, target, err)
}
return value
}
// batchApplyMetadataKey reads the WHOLE metadata blob off a row and reports one
// key's raw bytes. The whole blob is read rather than a JSON path extract,
// because that is what lets a case see an absent key and a null one as the
@ -2501,287 +2233,3 @@ func batchApplyHistoryMatching(t *testing.T, ctx context.Context, fixture BatchA
}
return count
}
// RunBatchApplyUpdateItemsRefuseATemplate pins that an update item answers to
// Lifecycle.Update's template guard: an item targeting a template refuses with
// an *ItemError carrying *TemplateReadOnlyError, whatever force flags it
// carries, and the request is all or nothing, so the create ahead of it does
// not land and the template is untouched.
func RunBatchApplyUpdateItemsRefuseATemplate(t *testing.T, ctx context.Context, fixture BatchApplyFixture) {
t.Helper()
template := fixture.IssuePrefix + "-tmplupd-template"
bystander := fixture.IssuePrefix + "-tmplupd-bystander"
seeded := batchApplyIssue(template, "a template")
seeded.IsTemplate = true
if err := fixture.CreateIssue(ctx, seeded, "seed"); err != nil {
t.Fatalf("seed %s: %v", template, err)
}
update := batchApplyUpdate(publicops.Ref{ID: template}, publicops.IssuePatch{
Title: publicops.Field[string]{Set: true, Value: "edited"},
Status: publicops.Field[publicops.Status]{Set: true, Value: types.StatusClosed},
})
update.Update.ForceClosePolicy = true
_, err := fixture.BatchApplier.ApplyBatch(ctx, publicops.ApplyBatchRequest{
Actor: "apply-writer",
ForceIDPrefix: true,
Items: []publicops.ApplyItem{
batchApplyCreate("bystander", batchApplyIssue(bystander, "must not land beside a refusal")),
update,
},
})
var itemErr *publicops.ItemError
if !errors.As(err, &itemErr) {
t.Fatalf("an update item on template %s: error = %v, want an *ItemError", template, err)
}
if itemErr.Kind != publicops.ItemUpdate || itemErr.Index != 1 {
t.Errorf("ItemError = %#v, want the update item at index 1", itemErr)
}
var refusal *publicops.TemplateReadOnlyError
if !errors.As(err, &refusal) || refusal.IssueID != template {
t.Errorf("update item on template = %v, want *TemplateReadOnlyError naming %s", err, template)
}
assertBatchApplyRowCount(t, ctx, fixture, "issues", bystander, 0)
if got := batchApplyColumn(t, ctx, fixture, "title", template); got != "a template" {
t.Errorf("%s title after the refusal = %q, want it untouched", template, got)
}
if got := batchApplyColumn(t, ctx, fixture, "status", template); got != string(types.StatusOpen) {
t.Errorf("%s status after the refusal = %q, want it untouched", template, got)
}
}
// RunBatchApplySplicesTheMetadataOfATemplateItCreates is the template guard's
// boundary: the one write a template legitimately takes inside a batch is a
// CREATE item that makes it and asks for a metadata splice. The splice runs as
// an update of the row the request itself is creating, after every id exists,
// and it must land — the template is being written, not modified — so a guard
// placed where the splice reaches it would refuse a template's own creation.
func RunBatchApplySplicesTheMetadataOfATemplateItCreates(t *testing.T, ctx context.Context, fixture BatchApplyFixture) {
t.Helper()
created := fixture.IssuePrefix + "-tmplsplice-created"
fresh := batchApplyIssue(created, "a template this request creates")
fresh.IsTemplate = true
item := batchApplyCreate("created", fresh)
item.Create.MetadataRefs = map[string]publicops.Ref{"gc.self": {Key: "created"}}
batchApplyMust(t, ctx, fixture, publicops.ApplyBatchRequest{
Actor: "apply-writer", ForceIDPrefix: true, Items: []publicops.ApplyItem{item},
})
if _, ok := batchApplyMetadataKey(t, ctx, fixture, created, "gc.self"); !ok {
t.Errorf("%s carries no gc.self key: the splice that finishes a template's own create must land", created)
}
}
// RunBatchApplyCloseItemsAnswerToTheCloseGuards pins that a close item answers
// to the close guards Lifecycle.Close states, under CloseRequest's rules: a
// template refuses forced or not, a pin and another actor's bead refuse unless
// the item's Force is set. A refusal is the item's *ItemError carrying the
// guard's typed error, and the request is all or nothing, so the create item
// ahead of it does not land.
//
// The assignee case is AS-MODIFIED: the holder is set by an update item of the
// same request, so a guard that read the row before the request began — or not
// at all — closes it.
func RunBatchApplyCloseItemsAnswerToTheCloseGuards(t *testing.T, ctx context.Context, fixture BatchApplyFixture) {
t.Helper()
template := fixture.IssuePrefix + "-closeguard-template"
pinned := fixture.IssuePrefix + "-closeguard-pinned"
held := fixture.IssuePrefix + "-closeguard-held"
bystander := fixture.IssuePrefix + "-closeguard-bystander"
for _, issue := range []*types.Issue{
{ID: template, IsTemplate: true},
{ID: pinned, Pinned: true},
{ID: held},
} {
issue.Title, issue.Status, issue.Priority, issue.IssueType = issue.ID, types.StatusOpen, 2, types.TypeTask
if err := fixture.CreateIssue(ctx, issue, "seed"); err != nil {
t.Fatalf("seed %s: %v", issue.ID, err)
}
}
plan := func(target string, force bool, extra ...publicops.ApplyItem) publicops.ApplyBatchRequest {
closeItem := batchApplyClose(publicops.Ref{ID: target})
closeItem.Close.Force = force
items := []publicops.ApplyItem{batchApplyCreate("bystander", batchApplyIssue(bystander, "must not land beside a refusal"))}
items = append(items, extra...)
return publicops.ApplyBatchRequest{Actor: "apply-closer", ForceIDPrefix: true, Items: append(items, closeItem)}
}
refused := func(label string, request publicops.ApplyBatchRequest, check func(error)) {
t.Helper()
_, err := fixture.BatchApplier.ApplyBatch(ctx, request)
var itemErr *publicops.ItemError
if !errors.As(err, &itemErr) {
t.Fatalf("%s: error = %v, want an *ItemError", label, err)
}
if itemErr.Kind != publicops.ItemClose || itemErr.Index != len(request.Items)-1 {
t.Errorf("%s: ItemError = %#v, want the close item at index %d", label, itemErr, len(request.Items)-1)
}
check(err)
assertBatchApplyRowCount(t, ctx, fixture, "issues", bystander, 0)
}
for _, force := range []bool{false, true} {
refused("template close item", plan(template, force), func(err error) {
var refusal *publicops.TemplateReadOnlyError
if !errors.As(err, &refusal) || refusal.IssueID != template {
t.Errorf("template close item (force=%v) = %v, want *TemplateReadOnlyError naming %s", force, err, template)
}
})
}
refused("pinned close item", plan(pinned, false), func(err error) {
var refusal *publicops.PinnedError
if !errors.As(err, &refusal) || refusal.IssueID != pinned {
t.Errorf("pinned close item = %v, want *PinnedError naming %s", err, pinned)
}
})
assign := batchApplyUpdate(publicops.Ref{ID: held}, publicops.IssuePatch{Assignee: publicops.Field[string]{Set: true, Value: "holder"}})
refused("held close item", plan(held, false, assign), func(err error) {
var refusal *publicops.CloseNotAssigneeError
if !errors.As(err, &refusal) {
t.Errorf("close item on a bead an earlier item assigned away = %v, want *CloseNotAssigneeError", err)
return
}
if refusal.IssueID != held || refusal.Assignee != "holder" || refusal.Actor != "apply-closer" {
t.Errorf("assignee refusal = %#v, want IssueID %q, Assignee holder, Actor apply-closer", refusal, held)
}
})
for _, id := range []string{template, pinned, held} {
if got := batchApplyColumn(t, ctx, fixture, "status", id); got != string(types.StatusOpen) {
t.Errorf("%s status after the refusals = %q, want it still open", id, got)
}
}
// The item's Force waives the pin and the assignee fence.
forcedPin := plan(pinned, true)
forcedPin.Items = forcedPin.Items[1:]
batchApplyMust(t, ctx, fixture, forcedPin)
forcedHeld := plan(held, true, assign)
forcedHeld.Items = forcedHeld.Items[1:]
batchApplyMust(t, ctx, fixture, forcedHeld)
for _, id := range []string{pinned, held} {
if got := batchApplyColumn(t, ctx, fixture, "status", id); got != string(types.StatusClosed) {
t.Errorf("%s status under the item's Force = %q, want %q", id, got, types.StatusClosed)
}
}
}
// RunBatchApplyRefusesADottedChildGatedOnItsOwnParent pins the dotted-id
// hierarchy rule (publicops.CheckDottedChildDependency) on a dep_add item: an
// edge from a dotted-id child to its own ancestor is refused with an
// *ItemError naming the edge, and the whole request rolls back. The rule is
// applied to the RESOLVED ids, so a key bound to a dotted child this request
// creates — the `bd create --graph` shape — is refused like a stored id.
//
// POSITIVE HALF: the parent-child edge to the immediate dotted parent lands.
//
// WITH THE HIERARCHY STORED: once that edge exists (the shape `bd create
// --parent` leaves), a blocking edge on the same pair is still this validation
// refusal, not the hierarchy conflict the stored edge would raise (which does
// not match ErrValidation) — the rule reads only the resolved ids, so it
// answers first — and the stored edge survives.
func RunBatchApplyRefusesADottedChildGatedOnItsOwnParent(t *testing.T, ctx context.Context, fixture BatchApplyFixture) {
t.Helper()
parent := fixture.IssuePrefix + "-dotted"
child := parent + ".1"
minted := parent + ".2"
batchApplySeedIssue(t, ctx, fixture, parent, types.StatusOpen)
batchApplySeedIssue(t, ctx, fixture, child, types.StatusOpen)
for _, refused := range []struct {
name string
items []publicops.ApplyItem
index int
}{
{"a stored child blocking on its parent", []publicops.ApplyItem{
batchApplyDepAdd(publicops.Ref{ID: child}, publicops.Ref{ID: parent}, publicops.DepBlocks, ""),
}, 0},
{"a child this request creates blocking on its parent", []publicops.ApplyItem{
batchApplyCreate("child", batchApplyIssue(minted, "the new child")),
batchApplyDepAdd(publicops.Ref{Key: "child"}, publicops.Ref{ID: parent}, publicops.DepBlocks, ""),
}, 1},
} {
_, err := fixture.BatchApplier.ApplyBatch(ctx, publicops.ApplyBatchRequest{
Actor: "apply-writer",
ForceIDPrefix: true,
Items: refused.items,
})
if !errors.Is(err, publicops.ErrValidation) {
t.Errorf("%s: error = %v, want ErrValidation", refused.name, err)
continue
}
var itemErr *publicops.ItemError
if !errors.As(err, &itemErr) {
t.Errorf("%s: error = %v, want an *ItemError naming the edge item", refused.name, err)
continue
}
if itemErr.Index != refused.index || itemErr.Kind != publicops.ItemDepAdd {
t.Errorf("%s: ItemError = %#v, want Index %d and Kind %q", refused.name, itemErr, refused.index, publicops.ItemDepAdd)
}
}
assertBatchApplyEdgeCount(t, ctx, fixture, child, parent, 0)
assertBatchApplyRowCount(t, ctx, fixture, "issues", minted, 0)
batchApplyMust(t, ctx, fixture, publicops.ApplyBatchRequest{
Actor: "apply-writer",
Items: []publicops.ApplyItem{
batchApplyDepAdd(publicops.Ref{ID: child}, publicops.Ref{ID: parent}, publicops.DepParentChild, ""),
},
})
assertBatchApplyEdgeCount(t, ctx, fixture, child, parent, 1)
_, err := fixture.BatchApplier.ApplyBatch(ctx, publicops.ApplyBatchRequest{
Actor: "apply-writer",
Items: []publicops.ApplyItem{
batchApplyDepAdd(publicops.Ref{ID: child}, publicops.Ref{ID: parent}, publicops.DepBlocks, ""),
},
})
var itemErr *publicops.ItemError
if !errors.Is(err, publicops.ErrValidation) || !errors.As(err, &itemErr) {
t.Errorf("blocks on a parent whose parent-child edge is stored: error = %v, want an *ItemError matching ErrValidation", err)
}
assertBatchApplyEdgeCount(t, ctx, fixture, child, parent, 1)
}
// RunBatchApplyAppliesTheDefaultPriority pins CreateItem.DefaultPriority: a
// create item that asks for the default stores publicops.DefaultCreatePriority,
// and one naming priority 0 stores P0. `bd create --graph` sends a node without
// a priority this way, and so does an HTTP batch apply create item without one.
// A create item asking for the default while naming a priority is
// ErrValidation and writes nothing, as it is for Lifecycle.Create.
func RunBatchApplyAppliesTheDefaultPriority(t *testing.T, ctx context.Context, fixture BatchApplyFixture) {
t.Helper()
unset := batchApplyMintedIssue("defaulted")
unset.Priority = 0
zero := batchApplyMintedIssue("critical")
zero.Priority = 0
result := batchApplyMust(t, ctx, fixture, publicops.ApplyBatchRequest{
Actor: "apply-writer",
Items: []publicops.ApplyItem{
{Kind: publicops.ItemCreate, Create: &publicops.CreateItem{Key: "d", Issue: unset, DefaultPriority: true}},
{Kind: publicops.ItemCreate, Create: &publicops.CreateItem{Key: "z", Issue: zero}},
},
})
for key, want := range map[string]int{"d": publicops.DefaultCreatePriority, "z": 0} {
id := result.Keys[key]
if id == "" {
t.Fatalf("key %q bound no id: %v", key, result.Keys)
}
if got := batchApplyCount(t, ctx, fixture, "SELECT priority FROM issues WHERE id = ?", []any{id}); got != want {
t.Errorf("stored priority of %s (%s) = %d, want %d", key, id, got, want)
}
}
conflict := fixture.IssuePrefix + "-prio-conflict"
clash := batchApplyIssue(conflict, conflict)
clash.Priority = 3
_, err := fixture.BatchApplier.ApplyBatch(ctx, publicops.ApplyBatchRequest{
Actor: "apply-writer",
ForceIDPrefix: true,
Items: []publicops.ApplyItem{
{Kind: publicops.ItemCreate, Create: &publicops.CreateItem{Key: "c", Issue: clash, DefaultPriority: true}},
},
})
if !errors.Is(err, publicops.ErrValidation) {
t.Fatalf("DefaultPriority with priority 3: err = %v, want ErrValidation", err)
}
assertBatchApplyRowCount(t, ctx, fixture, "issues", conflict, 0)
}

View file

@ -1,145 +0,0 @@
package conformance
import (
"context"
"encoding/json"
"errors"
"slices"
"testing"
"time"
"github.com/steveyegge/beads/internal/types"
publicops "github.com/steveyegge/beads/issueops"
)
// The BatchApplier half of the gate-member clauses; see
// lifecycle_create_gate_contract.go.
// RunBatchApplyCarriesTheGateMembers pins the gate members through
// BatchApplier: a create item stores all four, an update item replaces the
// waiter list of an existing row whole, a clear through an update item stores
// the empty list `[]`, and a create or update item past a bound refuses the
// WHOLE request as ErrValidation naming its member (on its *ItemError for the
// update item), so the earlier item rolls back with it.
func RunBatchApplyCarriesTheGateMembers(t *testing.T, ctx context.Context, fixture BatchApplyFixture) {
t.Helper()
gate := fixture.IssuePrefix + "-bag-gate"
existing := fixture.IssuePrefix + "-bag-existing"
batchApplySeedIssue(t, ctx, fixture, existing, types.StatusOpen)
issue := batchApplyIssue(gate, "a gate made by a plan")
issue.IssueType = types.TypeGate
issue.AwaitType = "timer"
issue.AwaitID = "await-plan"
issue.Timeout = 2 * time.Hour
issue.Waiters = []string{"a", "a", "b"}
batchApplyMust(t, ctx, fixture, publicops.ApplyBatchRequest{
Actor: "apply-writer",
ForceIDPrefix: true,
Items: []publicops.ApplyItem{
batchApplyCreate("gate", issue),
batchApplyUpdate(publicops.Ref{ID: existing}, publicops.IssuePatch{
AwaitID: publicops.Field[string]{Set: true, Value: "bead:" + gate},
Waiters: publicops.Field[[]string]{Set: true, Value: []string{"x", "y"}},
}),
},
})
assertBatchApplyGateColumns(t, ctx, fixture, gate, "timer", "await-plan", 2*time.Hour, []string{"a", "a", "b"})
assertBatchApplyGateColumns(t, ctx, fixture, existing, "", "bead:"+gate, 0, []string{"x", "y"})
// A clear through an update item stores the empty JSON list, not NULL and
// not the JSON null: the column is read raw here because every reader
// above treats the three alike.
batchApplyMust(t, ctx, fixture, publicops.ApplyBatchRequest{
Actor: "apply-writer",
Items: []publicops.ApplyItem{
batchApplyUpdate(publicops.Ref{ID: existing}, publicops.IssuePatch{
AwaitID: publicops.Field[string]{Set: true},
Waiters: publicops.Field[[]string]{Set: true},
}),
},
})
assertBatchApplyGateColumns(t, ctx, fixture, existing, "", "", 0, nil)
var clearedWaiters string
if err := fixture.QueryScalar(ctx, "SELECT COALESCE(waiters, '<NULL>') FROM issues WHERE id = ?", []any{existing}, &clearedWaiters); err != nil {
t.Fatalf("read the waiters column of %s: %v", existing, err)
}
if clearedWaiters != "[]" {
t.Errorf("%s waiters column after a clear = %q, want the stored empty list %q", existing, clearedWaiters, "[]")
}
first := fixture.IssuePrefix + "-bag-rolledback"
refused := batchApplyIssue(fixture.IssuePrefix+"-bag-refused", "past the bound")
refused.AwaitType = gateFieldAtBoundAwaitType + "x"
_, err := fixture.BatchApplier.ApplyBatch(ctx, publicops.ApplyBatchRequest{
Actor: "apply-writer",
ForceIDPrefix: true,
Items: []publicops.ApplyItem{
batchApplyCreate("first", batchApplyIssue(first, "rolls back with the refusal")),
batchApplyCreate("refused", refused),
},
})
assertGateFieldError(t, err, "a create item with await_type past its bound", publicops.GateFieldAwaitType)
assertBatchApplyRowCount(t, ctx, fixture, "issues", first, 0)
// An update item past a bound refuses the same way, named on its own
// item: the earlier create rolls back, and the target keeps its columns.
firstOfUpdate := fixture.IssuePrefix + "-bag-rolledback-upd"
_, err = fixture.BatchApplier.ApplyBatch(ctx, publicops.ApplyBatchRequest{
Actor: "apply-writer",
ForceIDPrefix: true,
Items: []publicops.ApplyItem{
batchApplyCreate("first", batchApplyIssue(firstOfUpdate, "rolls back with the refusal")),
batchApplyUpdate(publicops.Ref{ID: gate}, publicops.IssuePatch{
Title: publicops.Field[string]{Set: true, Value: "must not land"},
AwaitID: publicops.Field[string]{Set: true, Value: gateFieldAtBoundAwaitID + "x"},
}),
},
})
assertGateFieldError(t, err, "an update item with await_id past its bound", publicops.GateFieldAwaitID)
var itemErr *publicops.ItemError
if !errors.As(err, &itemErr) {
t.Fatalf("an update item with await_id past its bound: error = %v, want an *ItemError naming the item", err)
}
if itemErr.Index != 1 || itemErr.Kind != publicops.ItemUpdate {
t.Errorf("ItemError = %#v, want Index 1 and Kind %q", itemErr, publicops.ItemUpdate)
}
assertBatchApplyRowCount(t, ctx, fixture, "issues", firstOfUpdate, 0)
assertBatchApplyGateColumns(t, ctx, fixture, gate, "timer", "await-plan", 2*time.Hour, []string{"a", "a", "b"})
if got := batchApplyColumn(t, ctx, fixture, "title", gate); got != "a gate made by a plan" {
t.Errorf("%s title = %q, want the created title: a refused item writes nothing", gate, got)
}
}
// assertBatchApplyGateColumns reads the four gate columns of one durable row
// raw, so neither side of the comparison comes from the role.
func assertBatchApplyGateColumns(t *testing.T, ctx context.Context, fixture BatchApplyFixture, id, awaitType, awaitID string, timeout time.Duration, waiters []string) {
t.Helper()
var gotType, gotID, gotWaiters string
var gotTimeout int64
if err := fixture.QueryScalar(ctx,
"SELECT COALESCE(await_type, ''), COALESCE(await_id, ''), COALESCE(timeout_ns, 0), COALESCE(waiters, '') FROM issues WHERE id = ?",
[]any{id}, &gotType, &gotID, &gotTimeout, &gotWaiters); err != nil {
t.Fatalf("read the gate columns of %s: %v", id, err)
}
if gotType != awaitType || gotID != awaitID || time.Duration(gotTimeout) != timeout {
t.Errorf("%s gate columns = (%q, %q, %s), want (%q, %q, %s)", id, gotType, gotID, time.Duration(gotTimeout), awaitType, awaitID, timeout)
}
if stored := parseGateWaiters(gotWaiters); !slices.Equal(stored, waiters) {
t.Errorf("%s waiters column = %q (%q), want %q", id, gotWaiters, stored, waiters)
}
}
// parseGateWaiters reads the waiters TEXT column's JSON array, treating the
// empty string, `null` and `[]` as the one empty list they all mean.
func parseGateWaiters(raw string) []string {
if raw == "" || raw == "null" || raw == "[]" {
return nil
}
var out []string
if err := json.Unmarshal([]byte(raw), &out); err != nil {
return []string{"<unparseable: " + err.Error() + ">"}
}
return out
}

View file

@ -39,10 +39,9 @@ import (
// still reports OpenChildren (batchcloser.go:81-86); a duplicated id is one
// of those at its own index, and the first occurrence's reason is what the
// row keeps (batchcloser.go:28-33).
// - Force is request-wide and bypasses blocker and open-child policy, the
// pin and the assignee fence, never the template guard; the per-item
// precondition its clause also names is a category the request type keeps
// EMPTY (batchcloser.go:43-55).
// - Force is request-wide and bypasses only blocker and open-child policy;
// the per-item precondition its clause also names is a category the request
// type keeps EMPTY (batchcloser.go:43-53).
// - ClaimNext runs after the closes, inside the same transaction, and only
// when at least one item closed (batchcloser.go:55-70, 100-103, 143-146).
// - LANDED means CHANGED: an all-idempotent batch earns no claim and records
@ -1398,96 +1397,3 @@ func requireBatchCloserWisps(t *testing.T, fixture BatchCloserFixture) {
t.Skipf("fixture has no CreateWisp: this backend cannot seed the ephemeral plane, so the ephemeral rules are UNPINNED here")
}
}
// RunBatchCloserItemsAnswerToTheCloseGuards pins that every item of a batch
// answers to the close guards Lifecycle.Close states — template, pin, assignee
// — as a PER-ITEM refusal carrying the same typed error, while the survivors
// still commit; and that the request-wide Force waives the pin and the
// assignee fence and never the template.
//
// The guarded items sit between two plain ones, so an implementation that
// aborted the batch on a guard, or skipped the guard for items after the
// first, fails here rather than in `bd close a b c`.
func RunBatchCloserItemsAnswerToTheCloseGuards(t *testing.T, ctx context.Context, fixture BatchCloserFixture) {
t.Helper()
first := fixture.IssuePrefix + "-guard-first"
template := fixture.IssuePrefix + "-guard-template"
pinned := fixture.IssuePrefix + "-guard-pinned"
held := fixture.IssuePrefix + "-guard-held"
last := fixture.IssuePrefix + "-guard-last"
seedBatchCloserIssue(t, ctx, fixture, first)
seedBatchCloserIssue(t, ctx, fixture, last)
for _, issue := range []*types.Issue{
{ID: template, IsTemplate: true},
{ID: pinned, Status: types.StatusPinned},
{ID: held, Assignee: "holder"},
} {
issue.Title, issue.Priority, issue.IssueType = issue.ID, 2, types.TypeTask
if issue.Status == "" {
issue.Status = types.StatusOpen
}
if err := fixture.CreateIssue(ctx, issue, "seed"); err != nil {
t.Fatalf("seed %s: %v", issue.ID, err)
}
}
result, err := fixture.Closer.CloseBatch(ctx, publicops.CloseBatchRequest{
Actor: "closer",
Items: []publicops.BatchCloseItem{{IssueID: first}, {IssueID: template}, {IssueID: pinned}, {IssueID: held}, {IssueID: last}},
})
if err != nil {
t.Fatalf("CloseBatch over guarded items: %v, want per-item refusals", err)
}
if len(result.Outcomes) != 5 {
t.Fatalf("outcomes = %d, want 5", len(result.Outcomes))
}
for _, i := range []int{0, 4} {
if result.Outcomes[i].Err != nil || !result.Outcomes[i].Changed {
t.Errorf("outcome %d (%s) = %+v, want the plain item to land", i, result.Outcomes[i].IssueID, result.Outcomes[i])
}
}
var templateRefusal *publicops.TemplateReadOnlyError
if !errors.As(result.Outcomes[1].Err, &templateRefusal) || templateRefusal.IssueID != template {
t.Errorf("template item = %v, want *TemplateReadOnlyError naming %s", result.Outcomes[1].Err, template)
}
var pinRefusal *publicops.PinnedError
if !errors.As(result.Outcomes[2].Err, &pinRefusal) || pinRefusal.IssueID != pinned {
t.Errorf("pinned item = %v, want *PinnedError naming %s", result.Outcomes[2].Err, pinned)
}
var assigneeRefusal *publicops.CloseNotAssigneeError
if !errors.As(result.Outcomes[3].Err, &assigneeRefusal) {
t.Errorf("held item = %v, want *CloseNotAssigneeError", result.Outcomes[3].Err)
} else if assigneeRefusal.IssueID != held || assigneeRefusal.Assignee != "holder" || assigneeRefusal.Actor != "closer" {
t.Errorf("held item refusal = %#v, want IssueID %q, Assignee holder, Actor closer", assigneeRefusal, held)
}
for _, i := range []int{1, 2, 3} {
if result.Outcomes[i].Issue != nil {
t.Errorf("refused outcome %d carries an Issue snapshot, want nil beside Err", i)
}
}
assertBatchCloserStatus(t, ctx, fixture, first, types.StatusClosed)
assertBatchCloserStatus(t, ctx, fixture, last, types.StatusClosed)
assertBatchCloserStatus(t, ctx, fixture, template, types.StatusOpen)
assertBatchCloserStatus(t, ctx, fixture, pinned, types.StatusPinned)
assertBatchCloserStatus(t, ctx, fixture, held, types.StatusOpen)
forced, err := fixture.Closer.CloseBatch(ctx, publicops.CloseBatchRequest{
Actor: "closer",
Items: []publicops.BatchCloseItem{{IssueID: template}, {IssueID: pinned}, {IssueID: held}},
Force: true,
})
if err != nil {
t.Fatalf("forced CloseBatch over guarded items: %v", err)
}
if !errors.Is(forced.Outcomes[0].Err, publicops.ErrTemplateReadOnly) {
t.Errorf("forced template item = %v, want ErrTemplateReadOnly: force never waives read-only", forced.Outcomes[0].Err)
}
for _, i := range []int{1, 2} {
if forced.Outcomes[i].Err != nil || !forced.Outcomes[i].Changed {
t.Errorf("forced outcome %d (%s) = %+v, want force to bypass the guard", i, forced.Outcomes[i].IssueID, forced.Outcomes[i])
}
}
assertBatchCloserStatus(t, ctx, fixture, template, types.StatusOpen)
assertBatchCloserStatus(t, ctx, fixture, pinned, types.StatusClosed)
assertBatchCloserStatus(t, ctx, fixture, held, types.StatusClosed)
}

View file

@ -97,14 +97,6 @@ func RunBatchCreatorCreatesEveryItemAsOneAct(t *testing.T, ctx context.Context,
}
seen[issue.ID] = true
assertBatchCreatorRowCount(t, ctx, fixture, "issues", issue.ID, 1)
// No item names a creator, so each defaults to the batch's actor.
var createdBy string
if err := fixture.QueryScalar(ctx, "SELECT COALESCE(created_by, '') FROM issues WHERE id = ?", []any{issue.ID}, &createdBy); err != nil {
t.Fatalf("read created_by for %s: %v", issue.ID, err)
}
if createdBy != request.Actor || issue.CreatedBy != request.Actor {
t.Errorf("item %d created_by = %q (result %q), want the request's actor %q", i, createdBy, issue.CreatedBy, request.Actor)
}
}
if labels := result.Issues[0].Labels; len(labels) != 1 || labels[0] != "alpha" {
t.Errorf("result issue 0 labels = %v, want [alpha]: the snapshot is promised hydrated with labels", labels)
@ -697,63 +689,3 @@ func batchCreatorHistoryCount(t *testing.T, ctx context.Context, fixture BatchCr
}
return entries
}
// RunBatchCreatorAppliesTheDefaultPriority pins BatchCreateItem.DefaultPriority:
// an item that asks for the default stores publicops.DefaultCreatePriority, and
// an item naming priority 0 stores P0 in the same batch. The default is
// Lifecycle.Create's, applied in the shared preparation, so an HTTP
// batchCreate without `priority` and a `bd create --file` template without one
// land the same row. An item asking for the default while naming a priority is
// ErrValidation and writes nothing, as it is for Lifecycle.Create.
func RunBatchCreatorAppliesTheDefaultPriority(t *testing.T, ctx context.Context, fixture BatchCreatorFixture) {
t.Helper()
// Minted ids and an unset status, so the case asks nothing of the items
// but their priority — the http wire's batch item has no id or status slot.
unset := &types.Issue{Title: fixture.IssuePrefix + " defaulted", IssueType: types.TypeTask}
zero := &types.Issue{Title: fixture.IssuePrefix + " critical", IssueType: types.TypeTask}
result, err := fixture.BatchCreator.CreateBatch(ctx, publicops.CreateBatchRequest{
Actor: "batch-writer",
Items: []publicops.BatchCreateItem{
{Issue: unset, DefaultPriority: true},
{Issue: zero},
},
})
if err != nil {
t.Fatalf("CreateBatch: %v", err)
}
if len(result.Issues) != 2 || result.Issues[0] == nil || result.Issues[1] == nil {
t.Fatalf("result = %v, want two created issues", result.Issues)
}
for i, want := range []int{publicops.DefaultCreatePriority, 0} {
created := result.Issues[i]
if created.Priority != want {
t.Errorf("item %d result priority = %d, want %d", i, created.Priority, want)
}
var got int
if err := fixture.QueryScalar(ctx, "SELECT priority FROM issues WHERE id = ?", []any{created.ID}, &got); err != nil {
t.Fatalf("read priority of %s: %v", created.ID, err)
}
if got != want {
t.Errorf("item %d stored priority = %d, want %d", i, got, want)
}
}
conflict := fixture.IssuePrefix + " conflicting"
_, err = fixture.BatchCreator.CreateBatch(ctx, publicops.CreateBatchRequest{
Actor: "batch-writer",
Items: []publicops.BatchCreateItem{
{Issue: &types.Issue{Title: conflict, Priority: 3, IssueType: types.TypeTask}, DefaultPriority: true},
},
})
if !errors.Is(err, storage.ErrValidation) {
t.Fatalf("DefaultPriority with priority 3: err = %v, want ErrValidation", err)
}
var stored int
if err := fixture.QueryScalar(ctx, "SELECT COUNT(*) FROM issues WHERE title = ?", []any{conflict}, &stored); err != nil {
t.Fatalf("count issues titled %q: %v", conflict, err)
}
if stored != 0 {
t.Errorf("issues titled %q after the conflicting priority batch = %d, want 0", conflict, stored)
}
}

View file

@ -1,443 +0,0 @@
package conformance
import (
"context"
"errors"
"fmt"
"testing"
"github.com/steveyegge/beads/internal/types"
publicops "github.com/steveyegge/beads/issueops"
)
// This file holds the contract every implementation of publicops.BatchGetter
// must satisfy. Each case asserts what issueops/batchgetter.go PROMISES, cited
// by symbol; a backend that disagrees is parked at its own wiring site with
// skipKnownDivergence so the case still runs on the ones that agree.
//
// THREE LEGS, ONE BODY, GraphCounterFixture's reason: all three reach the same
// storage/issueops.ExecuteGetMany, which itself reaches GetIssuesByIDsInTx for
// the actual read. The two stores wrap it in their own read transaction, and
// the unit-of-work provider reaches it through the domain repository, whose
// runner publishes exactly the DBTX method set that function takes. So a
// three-leg run here is ONE READING plus two engine checks and three wrapper
// checks, and the cases are written for that: they assert the result's shape
// and order rather than message text, so a wrapper that loses the request,
// drops ordering or breaks errors.Is is what a per-leg failure would actually
// be.
//
// EVERY CASE NAMES THE EXACT IDS IT SEEDED, GraphCounterFixture's reason: the
// three fixtures share one database per suite and the two store fixtures share
// it with every other role's cases.
type BatchGetterFixture struct {
// IssuePrefix namespaces the ids each assertion seeds, so several of them
// can share one database.
IssuePrefix string
BatchGetter publicops.BatchGetter
// CreateIssue seeds a durable issue in the issues plane.
CreateIssue func(context.Context, *types.Issue, string) error
// CreateIssues seeds many durable issues in one call. Optional: only
// RunBatchGetterAcceptsExactlyTheCap uses it, to seed its MaxGetManyIDs
// issues in one write instead of MaxGetManyIDs single-row commits (about
// 200s of the embedded suites' race runs); nil falls back to CreateIssue
// per row. The seeded rows are the same either way, and the case asserts
// only on the GetMany read.
CreateIssues func(context.Context, []*types.Issue, string) error
// CreateWisp seeds an ephemeral issue in the wisps plane. It is a separate
// field rather than an Ephemeral flag on CreateIssue because the three
// adapters reach the two planes through different verbs.
CreateWisp func(context.Context, *types.Issue, string) error
// CountHistory reports how many history entries the fixture's branch has.
// A nil hook means "this backend cannot observe history", and the case that
// needs it SKIPS rather than passing quietly.
CountHistory func(context.Context) (int, error)
}
// RunBatchGetterFindsRequestedIssues pins the found half of GetManyResult: an
// id a GetManyRequest names and the store holds comes back hydrated, with the
// id that resolved it.
func RunBatchGetterFindsRequestedIssues(t *testing.T, ctx context.Context, fixture BatchGetterFixture) {
t.Helper()
first := fixture.IssuePrefix + "-found-a"
second := fixture.IssuePrefix + "-found-b"
seedBatchGetterIssues(t, ctx, fixture, first, second)
result := getMany(t, ctx, fixture, publicops.GetManyRequest{IDs: []string{first, second}})
assertBatchGetterIssueIDs(t, result, first, second)
assertBatchGetterMissingIDs(t, result)
}
// RunBatchGetterReportsMissingIDs pins GetManyResult.Missing: an id naming no
// stored row is reported there, beside whatever else resolved, rather than
// refusing the whole call. The ghost sits BETWEEN two real ids, the same
// placement RunGraphCounterDistinguishesNoEdgesFromNoAnchor uses, so a body
// that short-circuited on the first miss cannot pass by accident.
func RunBatchGetterReportsMissingIDs(t *testing.T, ctx context.Context, fixture BatchGetterFixture) {
t.Helper()
first := fixture.IssuePrefix + "-missing-real1"
ghost := fixture.IssuePrefix + "-missing-ghost"
second := fixture.IssuePrefix + "-missing-real2"
seedBatchGetterIssues(t, ctx, fixture, first, second)
result := getMany(t, ctx, fixture, publicops.GetManyRequest{IDs: []string{first, ghost, second}})
assertBatchGetterIssueIDs(t, result, first, second)
assertBatchGetterMissingIDs(t, result, ghost)
}
// RunBatchGetterCollapsesRepeatedIDs pins GetManyRequest.IDs's repeats clause:
// an id named twice is one entry, at the position of its first mention. The
// repeat is placed AFTER a different id, RunGraphCounterCollapsesRepeatedAnchors'
// reason: a body that de-duplicated by sorting rather than by first mention
// would answer b, a instead of a, b.
func RunBatchGetterCollapsesRepeatedIDs(t *testing.T, ctx context.Context, fixture BatchGetterFixture) {
t.Helper()
first := fixture.IssuePrefix + "-dup-b"
second := fixture.IssuePrefix + "-dup-a"
seedBatchGetterIssues(t, ctx, fixture, first, second)
result := getMany(t, ctx, fixture, publicops.GetManyRequest{
IDs: []string{first, second, first, second, first},
})
assertBatchGetterIssueIDs(t, result, first, second)
}
// RunBatchGetterAnswersInRequestOrder pins GetManyResult.Issues' ordering
// clause: the answer comes back in the REQUEST's order, never the storage
// engine's natural order. The ids are seeded in the opposite order from the one
// requested, so a body that forwarded the storage engine's order would fail.
func RunBatchGetterAnswersInRequestOrder(t *testing.T, ctx context.Context, fixture BatchGetterFixture) {
t.Helper()
first := fixture.IssuePrefix + "-order-c"
second := fixture.IssuePrefix + "-order-b"
third := fixture.IssuePrefix + "-order-a"
// Seeded in storage order third, second, first — the reverse of the
// request below — so a body that forwarded insertion order would fail.
seedBatchGetterIssues(t, ctx, fixture, third, second, first)
result := getMany(t, ctx, fixture, publicops.GetManyRequest{IDs: []string{first, second, third}})
assertBatchGetterIssueIDs(t, result, first, second, third)
}
// RunBatchGetterResolvesIDsExactly pins the exactness GetManyRequest.IDs
// documents: a prefix of a real id and a real id padded with whitespace are
// both reported Missing rather than resolved, the same exactness
// RunGraphCounterResolvesIDsExactly pins for EdgeCountRequest.IDs.
func RunBatchGetterResolvesIDsExactly(t *testing.T, ctx context.Context, fixture BatchGetterFixture) {
t.Helper()
real := fixture.IssuePrefix + "-exact-real"
seedBatchGetterIssues(t, ctx, fixture, real)
prefix := real[:len(real)-2]
spaced := " " + real + " "
result := getMany(t, ctx, fixture, publicops.GetManyRequest{IDs: []string{real, prefix, spaced}})
assertBatchGetterIssueIDs(t, result, real)
assertBatchGetterMissingIDs(t, result, prefix, spaced)
}
// RunBatchGetterAnswersAnEmptyRequest pins GetManyRequest.IDs's empty-slice
// clause: no ids is not an error, it is an answer with no issues — and both
// slices are never nil, so a front door that marshals them emits [] rather
// than null.
func RunBatchGetterAnswersAnEmptyRequest(t *testing.T, ctx context.Context, fixture BatchGetterFixture) {
t.Helper()
result, err := fixture.BatchGetter.GetMany(ctx, publicops.GetManyRequest{})
if err != nil {
t.Fatalf("GetMany with no ids = %v, want an empty answer", err)
}
if len(result.Issues) != 0 {
t.Fatalf("GetMany with no ids returned %d issues, want none", len(result.Issues))
}
if result.Issues == nil {
t.Error("Issues is nil; the contract promises it is never nil for a successful call")
}
if result.Missing == nil {
t.Error("Missing is nil; the contract promises it is never nil for a successful call")
}
}
// RunBatchGetterRefusesAnUnusableRequest pins the request vocabulary
// ValidateGetManyRequest applies: an empty-string id is refused with
// ErrValidation.
func RunBatchGetterRefusesAnUnusableRequest(t *testing.T, ctx context.Context, fixture BatchGetterFixture) {
t.Helper()
real := fixture.IssuePrefix + "-refuse-real"
seedBatchGetterIssues(t, ctx, fixture, real)
_, err := fixture.BatchGetter.GetMany(ctx, publicops.GetManyRequest{IDs: []string{real, ""}})
if !errors.Is(err, publicops.ErrValidation) {
t.Errorf("GetMany with an empty id beside a real one = %v, want ErrValidation", err)
}
}
// RunBatchGetterRefusesOverTheCap pins MaxGetManyIDs: a request naming more
// ids than the cap is refused with a *publicops.TooManyIDsError that wraps
// ErrValidation, counted on the request as sent, BEFORE deduplication — the
// request below repeats one id past the cap, so a body that checked the
// deduplicated count would wrongly let it through.
func RunBatchGetterRefusesOverTheCap(t *testing.T, ctx context.Context, fixture BatchGetterFixture) {
t.Helper()
real := fixture.IssuePrefix + "-cap-real"
seedBatchGetterIssues(t, ctx, fixture, real)
ids := make([]string, publicops.MaxGetManyIDs+1)
for i := range ids {
ids[i] = real
}
_, err := fixture.BatchGetter.GetMany(ctx, publicops.GetManyRequest{IDs: ids})
var tooMany *publicops.TooManyIDsError
if !errors.As(err, &tooMany) {
t.Fatalf("GetMany over the cap = %v, want *publicops.TooManyIDsError", err)
}
if tooMany.Requested != len(ids) {
t.Errorf("TooManyIDsError.Requested = %d, want %d (the count before deduplication)", tooMany.Requested, len(ids))
}
if tooMany.Cap != publicops.MaxGetManyIDs {
t.Errorf("TooManyIDsError.Cap = %d, want %d", tooMany.Cap, publicops.MaxGetManyIDs)
}
if !errors.Is(err, publicops.ErrValidation) {
t.Errorf("GetMany over the cap = %v, want it to also match ErrValidation", err)
}
}
// RunBatchGetterAcceptsExactlyTheCap pins the boundary MaxGetManyIDs draws:
// a request naming EXACTLY the cap's worth of distinct ids is accepted and
// answered in full, not refused. RunBatchGetterRefusesOverTheCap pins the
// cap+1 side of this line; without this case a `>` to `>=` mutation on the
// comparison would still refuse a one-over request (cap+1 is still > cap-1)
// and pass that case while silently refusing every legitimate cap-sized
// request.
func RunBatchGetterAcceptsExactlyTheCap(t *testing.T, ctx context.Context, fixture BatchGetterFixture) {
t.Helper()
ids := make([]string, publicops.MaxGetManyIDs)
for i := range ids {
ids[i] = fmt.Sprintf("%s-atcap-%d", fixture.IssuePrefix, i)
}
seedBatchGetterIssuesInBulk(t, ctx, fixture, ids...)
result := getMany(t, ctx, fixture, publicops.GetManyRequest{IDs: ids})
if len(result.Issues) != publicops.MaxGetManyIDs {
t.Fatalf("GetMany with exactly MaxGetManyIDs (%d) ids returned %d issues, want %d",
publicops.MaxGetManyIDs, len(result.Issues), publicops.MaxGetManyIDs)
}
assertBatchGetterMissingIDs(t, result)
}
// RunBatchGetterHydratesLabels pins that a resolved issue's Labels come back
// populated: hydration for this role is LABELS ONLY (no dependencies,
// dependents or comments — issueops.GetManyResult.Issues documents the
// scope), so Labels is the one piece of relational data a regression here
// could silently drop without any other case noticing.
func RunBatchGetterHydratesLabels(t *testing.T, ctx context.Context, fixture BatchGetterFixture) {
t.Helper()
id := fixture.IssuePrefix + "-labels-a"
seed := batchGetterSeed(id, false)
seed.Labels = []string{"alpha", "beta"}
if err := fixture.CreateIssue(ctx, seed, "batch-getter-seed"); err != nil {
t.Fatalf("seed issue %s: %v", id, err)
}
result := getMany(t, ctx, fixture, publicops.GetManyRequest{IDs: []string{id}})
assertBatchGetterIssueIDs(t, result, id)
got := result.Issues[0].Labels
want := []string{"alpha", "beta"}
if len(got) != len(want) {
t.Fatalf("GetMany(%s).Labels = %v, want %v", id, got, want)
}
seen := make(map[string]bool, len(got))
for _, l := range got {
seen[l] = true
}
for _, l := range want {
if !seen[l] {
t.Errorf("GetMany(%s).Labels = %v, want it to include %q", id, got, l)
}
}
}
// RunBatchGetterLeavesTheRequestAlone pins the no-mutation clause on
// BatchGetter: IDs is the one member a body could write through to the caller
// — de-duplication is exactly the step that would — and the contract says a
// body de-duplicates into its own copy.
func RunBatchGetterLeavesTheRequestAlone(t *testing.T, ctx context.Context, fixture BatchGetterFixture) {
t.Helper()
first := fixture.IssuePrefix + "-immutable-a"
second := fixture.IssuePrefix + "-immutable-b"
seedBatchGetterIssues(t, ctx, fixture, first, second)
ids := []string{first, first, second}
getMany(t, ctx, fixture, publicops.GetManyRequest{IDs: ids})
if len(ids) != 3 || ids[0] != first || ids[1] != first || ids[2] != second {
t.Errorf("the request's IDs slice is now %v; the contract says a body de-duplicates into its own copy", ids)
}
}
// RunBatchGetterSharesOneReadStructurally pins the STRUCTURAL half of the
// one-snapshot clause on BatchGetter.GetMany: the existence check and the
// hydration are one call answering one found id and one missing id together
// against a STATIC fixture, which is consistent with — but does not by
// itself PROVE — the two sharing one transaction under a concurrent writer.
// A body that split the probe from the hydration into two round trips could
// still pass this case against a fixture nothing else is mutating, so it
// checks both halves of one GetManyResult instead of asserting on two
// separate calls the way RunBatchGetterFindsRequestedIssues and
// RunBatchGetterReportsMissingIDs do, but it is NOT a concurrency test: no
// writer races the read here.
//
// Renamed from RunBatchGetterReadsOneSnapshot, which overclaimed an
// atomicity guarantee this case alone does not empirically demonstrate. A
// real interleaving test — a concurrent writer racing GetMany's transaction
// so the case can show a found id and a racing create or delete resolve
// consistently with ONE snapshot boundary — needs a synchronization hook
// (e.g. "pause this leg's read transaction after its query, before it
// returns, so a second goroutine can write and commit") that roleFixtureKit
// does not expose today; that kit is FROZEN (see role_fixture_kit_test.go)
// and a role slice does not edit it. Adding the hook is tracked as follow-up
// work rather than done here, so this case stays honestly structural.
func RunBatchGetterSharesOneReadStructurally(t *testing.T, ctx context.Context, fixture BatchGetterFixture) {
t.Helper()
present := fixture.IssuePrefix + "-snapshot-present"
ghost := fixture.IssuePrefix + "-snapshot-ghost"
seedBatchGetterIssues(t, ctx, fixture, present)
result := getMany(t, ctx, fixture, publicops.GetManyRequest{IDs: []string{present, ghost}})
if len(result.Issues) != 1 || len(result.Missing) != 1 {
t.Fatalf("GetMany([%s, %s]) = %d issues, %d missing; want exactly one of each from the same read",
present, ghost, len(result.Issues), len(result.Missing))
}
assertBatchGetterIssueIDs(t, result, present)
assertBatchGetterMissingIDs(t, result, ghost)
}
// RunBatchGetterCrossesBothPlanes pins that GetMany resolves ids regardless of
// which dependency plane stores them: a durable issue and an ephemeral wisp
// named in the same request both come back hydrated.
func RunBatchGetterCrossesBothPlanes(t *testing.T, ctx context.Context, fixture BatchGetterFixture) {
t.Helper()
issue := fixture.IssuePrefix + "-plane-issue"
wisp := fixture.IssuePrefix + "-plane-wisp"
seedBatchGetterIssues(t, ctx, fixture, issue)
seedBatchGetterWisp(t, ctx, fixture, wisp)
result := getMany(t, ctx, fixture, publicops.GetManyRequest{IDs: []string{issue, wisp}})
assertBatchGetterIssueIDs(t, result, issue, wisp)
}
// RunBatchGetterWritesNothing pins BatchGetter's read clause: a GetMany
// records no history entry. The delta is taken around the calls rather than as
// an absolute count, RunGraphCounterWritesNothing's reason: the seeds above it
// are versioned writes of their own.
func RunBatchGetterWritesNothing(t *testing.T, ctx context.Context, fixture BatchGetterFixture) {
t.Helper()
if fixture.CountHistory == nil {
t.Skip("this backend cannot observe history, so the writes-nothing clause cannot be checked here")
}
real := fixture.IssuePrefix + "-quiet-real"
ghost := fixture.IssuePrefix + "-quiet-ghost"
seedBatchGetterIssues(t, ctx, fixture, real)
before, err := fixture.CountHistory(ctx)
if err != nil {
t.Fatalf("CountHistory before: %v", err)
}
getMany(t, ctx, fixture, publicops.GetManyRequest{IDs: []string{real, ghost}})
// A refusal changes nothing either, so the same delta covers both.
_, _ = fixture.BatchGetter.GetMany(ctx, publicops.GetManyRequest{IDs: []string{""}})
after, err := fixture.CountHistory(ctx)
if err != nil {
t.Fatalf("CountHistory after: %v", err)
}
if after != before {
t.Fatalf("history entries went %d -> %d across two GetMany calls, want no change", before, after)
}
}
func getMany(t *testing.T, ctx context.Context, fixture BatchGetterFixture, request publicops.GetManyRequest) publicops.GetManyResult {
t.Helper()
result, err := fixture.BatchGetter.GetMany(ctx, request)
if err != nil {
t.Fatalf("GetMany(%v): %v", request.IDs, err)
}
return result
}
func seedBatchGetterIssues(t *testing.T, ctx context.Context, fixture BatchGetterFixture, ids ...string) {
t.Helper()
for _, id := range ids {
if err := fixture.CreateIssue(ctx, batchGetterSeed(id, false), "batch-getter-seed"); err != nil {
t.Fatalf("seed issue %s: %v", id, err)
}
}
}
// seedBatchGetterIssuesInBulk seeds the same rows as seedBatchGetterIssues,
// through the fixture's CreateIssues hook when it has one.
func seedBatchGetterIssuesInBulk(t *testing.T, ctx context.Context, fixture BatchGetterFixture, ids ...string) {
t.Helper()
if fixture.CreateIssues == nil {
seedBatchGetterIssues(t, ctx, fixture, ids...)
return
}
issues := make([]*types.Issue, len(ids))
for i, id := range ids {
issues[i] = batchGetterSeed(id, false)
}
if err := fixture.CreateIssues(ctx, issues, "batch-getter-seed"); err != nil {
t.Fatalf("seed %d issues: %v", len(issues), err)
}
}
func seedBatchGetterWisp(t *testing.T, ctx context.Context, fixture BatchGetterFixture, id string) {
t.Helper()
if err := fixture.CreateWisp(ctx, batchGetterSeed(id, true), "batch-getter-seed"); err != nil {
t.Fatalf("seed wisp %s: %v", id, err)
}
}
func batchGetterSeed(id string, ephemeral bool) *types.Issue {
return &types.Issue{
ID: id,
Title: id,
Status: types.StatusOpen,
Priority: 2,
IssueType: types.TypeTask,
Ephemeral: ephemeral,
}
}
func batchGetterIssueIDs(result publicops.GetManyResult) []string {
out := make([]string, 0, len(result.Issues))
for _, issue := range result.Issues {
out = append(out, issue.ID)
}
return out
}
func assertBatchGetterIssueIDs(t *testing.T, result publicops.GetManyResult, want ...string) {
t.Helper()
got := batchGetterIssueIDs(result)
if len(got) != len(want) {
t.Fatalf("issues = %v, want %v", got, want)
}
for i := range want {
if got[i] != want[i] {
t.Fatalf("issues = %v, want %v", got, want)
}
}
}
func assertBatchGetterMissingIDs(t *testing.T, result publicops.GetManyResult, want ...string) {
t.Helper()
got := result.Missing
if len(got) != len(want) {
t.Fatalf("missing = %v, want %v", got, want)
}
for i := range want {
if got[i] != want[i] {
t.Fatalf("missing = %v, want %v", got, want)
}
}
if got == nil {
t.Error("Missing is nil; the contract promises it is never nil for a successful call")
}
}

View file

@ -1,426 +0,0 @@
package conformance
import (
"context"
"fmt"
"reflect"
"slices"
"testing"
"time"
"github.com/steveyegge/beads/internal/types"
publicops "github.com/steveyegge/beads/issueops"
)
// This file holds the semantic contract every implementation of
// publicops.BlockedLister must satisfy: what issueops/blockedlister.go
// promises, asserted on every leg (dolt, embedded dolt, unit of work, and the
// served HTTP client) so `bd blocked` answers one listing whichever route it
// takes.
//
// EVERY CASE IS SCOPED BY A LABEL: the blocked set is a property of the whole
// database, not of an id prefix, so a row seeded by one case is inside the
// next one's answer unless each asks through Labels.
// BlockedListerFixture supplies adapter-specific storage access for the
// blocked-listing assertions.
type BlockedListerFixture struct {
// IssuePrefix namespaces the ids each case seeds, so several cases can
// share one database.
IssuePrefix string
// BlockedLister is the surface under test.
BlockedLister publicops.BlockedLister
// CreateIssue seeds a durable issue in the issues plane.
CreateIssue func(context.Context, *types.Issue, string) error
// CreateWisp seeds an ephemeral issue in the wisps plane.
CreateWisp func(context.Context, *types.Issue, string) error
// AddDependency seeds ONE edge, recomputing the stored blocked flag the
// way every dependency write does.
AddDependency func(context.Context, *types.Dependency, string) error
// MarkBlocked sets the stored is_blocked flag on one durable issue
// directly, without the edge that would justify it: the stale flag `bd
// recompute-blocked` exists to repair. It must fail unless exactly one row
// changed. A nil hook means this leg cannot write the column, and the case
// that needs it skips with that reason.
MarkBlocked func(context.Context, string) error
}
// RunBlockedLister runs every blocked-listing case as a subtest of t.
func RunBlockedLister(t *testing.T, ctx context.Context, fixture BlockedListerFixture) {
t.Helper()
t.Run("NamesADirectBlocker", func(t *testing.T) { runBlockedNamesADirectBlocker(t, ctx, fixture) })
t.Run("AttributesAChildToItsBlockedParent", func(t *testing.T) { runBlockedAttributesAChildToItsParent(t, ctx, fixture) })
t.Run("ClosedBlockerDoesNotBlock", func(t *testing.T) { runBlockedClosedBlockerDoesNotBlock(t, ctx, fixture) })
t.Run("IncludesTheWispPlane", func(t *testing.T) { runBlockedIncludesTheWispPlane(t, ctx, fixture) })
t.Run("ExcludesThePinnedStatus", func(t *testing.T) { runBlockedExcludesThePinnedStatus(t, ctx, fixture) })
t.Run("ParentFilter", func(t *testing.T) { runBlockedParentFilter(t, ctx, fixture) })
t.Run("LabelFilters", func(t *testing.T) { runBlockedLabelFilters(t, ctx, fixture) })
t.Run("Order", func(t *testing.T) { runBlockedOrder(t, ctx, fixture) })
t.Run("NamesWaitsForAndConditionalBlockers", func(t *testing.T) { runBlockedNamesWaitsForAndConditionalBlockers(t, ctx, fixture) })
t.Run("OmitsAStaleFlagWithNoNameableBlocker", func(t *testing.T) { runBlockedOmitsAStaleFlag(t, ctx, fixture) })
t.Run("HasNoTypeExclusions", func(t *testing.T) { runBlockedHasNoTypeExclusions(t, ctx, fixture) })
t.Run("EmptyIsAnEmptySlice", func(t *testing.T) { runBlockedEmptyIsAnEmptySlice(t, ctx, fixture) })
t.Run("DoesNotMutateTheCallerRequest", func(t *testing.T) { runBlockedDoesNotMutateTheRequest(t, ctx, fixture) })
}
// runBlockedNamesADirectBlocker: an issue with an open `blocks` target is
// listed with that target as its one blocker; the target itself is not.
func runBlockedNamesADirectBlocker(t *testing.T, ctx context.Context, f BlockedListerFixture) {
label := f.IssuePrefix + "-bl-direct"
blocked, blocker := blListerID(f, "direct-src"), blListerID(f, "direct-dst")
blListerSeedIssue(t, ctx, f, blListerIssue(blocked, 1, label))
blListerSeedIssue(t, ctx, f, blListerIssue(blocker, 1, label))
blListerSeedEdge(t, ctx, f, blocked, blocker, types.DepBlocks)
items := blListerList(t, ctx, f, publicops.BlockedRequest{Labels: []string{label}})
blListerAssertRows(t, items, map[string][]string{blocked: {blocker}})
}
// runBlockedAttributesAChildToItsParent: a child of a blocked parent, with no
// blocker of its own, is listed with its parent named as the blocker.
func runBlockedAttributesAChildToItsParent(t *testing.T, ctx context.Context, f BlockedListerFixture) {
label := f.IssuePrefix + "-bl-child"
parent, child, blocker := blListerID(f, "child-parent"), blListerID(f, "child-child"), blListerID(f, "child-blocker")
blListerSeedIssue(t, ctx, f, blListerIssue(parent, 1, label))
blListerSeedIssue(t, ctx, f, blListerIssue(blocker, 1, label+"-other"))
blListerSeedIssue(t, ctx, f, blListerIssue(child, 1, label))
blListerSeedEdge(t, ctx, f, child, parent, types.DepParentChild)
blListerSeedEdge(t, ctx, f, parent, blocker, types.DepBlocks)
items := blListerList(t, ctx, f, publicops.BlockedRequest{Labels: []string{label}})
blListerAssertRows(t, items, map[string][]string{parent: {blocker}, child: {parent}})
}
// runBlockedClosedBlockerDoesNotBlock: a `blocks` edge onto a closed target
// names no blocker, so the source is not listed.
func runBlockedClosedBlockerDoesNotBlock(t *testing.T, ctx context.Context, f BlockedListerFixture) {
label := f.IssuePrefix + "-bl-closed"
src, dst := blListerID(f, "closed-src"), blListerID(f, "closed-dst")
blListerSeedIssue(t, ctx, f, blListerIssue(src, 1, label))
closed := blListerIssue(dst, 1, label)
closed.Status = types.StatusClosed
blListerSeedIssue(t, ctx, f, closed)
blListerSeedEdge(t, ctx, f, src, dst, types.DepBlocks)
items := blListerList(t, ctx, f, publicops.BlockedRequest{Labels: []string{label}})
blListerAssertRows(t, items, map[string][]string{})
}
// runBlockedIncludesTheWispPlane: a blocked wisp is listed beside the issues.
func runBlockedIncludesTheWispPlane(t *testing.T, ctx context.Context, f BlockedListerFixture) {
label := f.IssuePrefix + "-bl-wisp"
wisp, blocker := blListerID(f, "wisp-src"), blListerID(f, "wisp-dst")
w := blListerIssue(wisp, 1, label)
w.Ephemeral = true
if err := f.CreateWisp(ctx, w, "seed"); err != nil {
t.Fatalf("seed wisp %s: %v", wisp, err)
}
b := blListerIssue(blocker, 1, label)
b.Ephemeral = true
if err := f.CreateWisp(ctx, b, "seed"); err != nil {
t.Fatalf("seed wisp %s: %v", blocker, err)
}
blListerSeedEdge(t, ctx, f, wisp, blocker, types.DepBlocks)
items := blListerList(t, ctx, f, publicops.BlockedRequest{Labels: []string{label}})
blListerAssertRows(t, items, map[string][]string{wisp: {blocker}})
}
// runBlockedExcludesThePinnedStatus: a row whose status is pinned is never
// listed, whatever blocks it.
func runBlockedExcludesThePinnedStatus(t *testing.T, ctx context.Context, f BlockedListerFixture) {
label := f.IssuePrefix + "-bl-pinned"
pinned, open, blocker := blListerID(f, "pinned-src"), blListerID(f, "pinned-open"), blListerID(f, "pinned-dst")
p := blListerIssue(pinned, 1, label)
p.Status = types.StatusPinned
blListerSeedIssue(t, ctx, f, p)
blListerSeedIssue(t, ctx, f, blListerIssue(open, 1, label))
blListerSeedIssue(t, ctx, f, blListerIssue(blocker, 1, label+"-other"))
blListerSeedEdge(t, ctx, f, pinned, blocker, types.DepBlocks)
blListerSeedEdge(t, ctx, f, open, blocker, types.DepBlocks)
items := blListerList(t, ctx, f, publicops.BlockedRequest{Labels: []string{label}})
blListerAssertRows(t, items, map[string][]string{open: {blocker}})
}
// runBlockedParentFilter: ParentID narrows to the parent's direct children.
func runBlockedParentFilter(t *testing.T, ctx context.Context, f BlockedListerFixture) {
label := f.IssuePrefix + "-bl-parent"
parent, kid, stranger, blocker := blListerID(f, "pf-parent"), blListerID(f, "pf-kid"), blListerID(f, "pf-stranger"), blListerID(f, "pf-blocker")
blListerSeedIssue(t, ctx, f, blListerIssue(parent, 1, label+"-other"))
blListerSeedIssue(t, ctx, f, blListerIssue(blocker, 1, label+"-other"))
blListerSeedIssue(t, ctx, f, blListerIssue(kid, 1, label))
blListerSeedIssue(t, ctx, f, blListerIssue(stranger, 1, label))
blListerSeedEdge(t, ctx, f, kid, parent, types.DepParentChild)
blListerSeedEdge(t, ctx, f, kid, blocker, types.DepBlocks)
blListerSeedEdge(t, ctx, f, stranger, blocker, types.DepBlocks)
all := blListerList(t, ctx, f, publicops.BlockedRequest{Labels: []string{label}})
blListerAssertRows(t, all, map[string][]string{kid: {blocker}, stranger: {blocker}})
narrowed := blListerList(t, ctx, f, publicops.BlockedRequest{ParentID: parent, Labels: []string{label}})
blListerAssertRows(t, narrowed, map[string][]string{kid: {blocker}})
}
// runBlockedLabelFilters: Labels is AND, LabelsAny is OR, ExcludeLabels
// removes, and every value is trimmed with blanks dropped.
func runBlockedLabelFilters(t *testing.T, ctx context.Context, f BlockedListerFixture) {
base := f.IssuePrefix + "-bl-lab"
red, blue := base+"-red", base+"-blue"
both, onlyRed, onlyBlue, blocker := blListerID(f, "lab-both"), blListerID(f, "lab-red"), blListerID(f, "lab-blue"), blListerID(f, "lab-blocker")
blListerSeedIssue(t, ctx, f, blListerIssue(both, 1, base, red, blue))
blListerSeedIssue(t, ctx, f, blListerIssue(onlyRed, 1, base, red))
blListerSeedIssue(t, ctx, f, blListerIssue(onlyBlue, 1, base, blue))
blListerSeedIssue(t, ctx, f, blListerIssue(blocker, 1, base+"-other"))
for _, id := range []string{both, onlyRed, onlyBlue} {
blListerSeedEdge(t, ctx, f, id, blocker, types.DepBlocks)
}
want := func(ids ...string) map[string][]string {
m := map[string][]string{}
for _, id := range ids {
m[id] = []string{blocker}
}
return m
}
blListerAssertRows(t, blListerList(t, ctx, f, publicops.BlockedRequest{Labels: []string{" " + red + " ", "", blue}}), want(both))
blListerAssertRows(t, blListerList(t, ctx, f, publicops.BlockedRequest{Labels: []string{base}, LabelsAny: []string{red, blue}}), want(both, onlyRed, onlyBlue))
blListerAssertRows(t, blListerList(t, ctx, f, publicops.BlockedRequest{Labels: []string{base}, ExcludeLabels: []string{" " + blue}}), want(onlyRed))
}
// runBlockedOrder: priority ascending, then created_at descending, then id.
//
// The created_at values are seeded explicitly, so every key decides at least
// one pair: two rows share a priority and differ in created_at (newest first),
// and five share both priority and created_at (the id breaks the tie). The
// expected order is written out rather than recomputed from the answer.
func runBlockedOrder(t *testing.T, ctx context.Context, f BlockedListerFixture) {
label := f.IssuePrefix + "-bl-order"
blocker := blListerID(f, "order-blocker")
blListerSeedIssue(t, ctx, f, blListerIssue(blocker, 1, label+"-other"))
older := time.Date(2026, 1, 1, 10, 0, 0, 0, time.UTC)
newer := older.Add(time.Hour)
// Two of the five tied rows are wisps. The store body assembles rows
// issues-plane first, each plane in id order, so the ids alone would put
// the tied run in the wrong order (b, d, e, then a, c); only the id
// tiebreak puts it right.
rows := []struct {
name string
priority int
created time.Time
wisp bool
}{
{"order-p3", 3, newer, false},
{"order-p0-older", 0, older, false},
{"order-p0-newer-e", 0, newer, false},
{"order-p0-newer-c", 0, newer, true},
{"order-p0-newer-a", 0, newer, true},
{"order-p0-newer-d", 0, newer, false},
{"order-p0-newer-b", 0, newer, false},
{"order-p1", 1, older, false},
}
for _, row := range rows {
issue := blListerIssue(blListerID(f, row.name), row.priority, label)
issue.CreatedAt = row.created
issue.UpdatedAt = row.created
if row.wisp {
issue.Ephemeral = true
if err := f.CreateWisp(ctx, issue, "seed"); err != nil {
t.Fatalf("seed wisp %s: %v", issue.ID, err)
}
} else {
blListerSeedIssue(t, ctx, f, issue)
}
blListerSeedEdge(t, ctx, f, issue.ID, blocker, types.DepBlocks)
}
want := []string{
blListerID(f, "order-p0-newer-a"),
blListerID(f, "order-p0-newer-b"),
blListerID(f, "order-p0-newer-c"),
blListerID(f, "order-p0-newer-d"),
blListerID(f, "order-p0-newer-e"),
blListerID(f, "order-p0-older"),
blListerID(f, "order-p1"),
blListerID(f, "order-p3"),
}
got := blListerIDs(blListerList(t, ctx, f, publicops.BlockedRequest{Labels: []string{label}}))
if !slices.Equal(got, want) {
t.Errorf("listing order = %v, want %v (priority ascending, created_at descending, id)", got, want)
}
}
// runBlockedNamesWaitsForAndConditionalBlockers: a waits-for onto a spawner
// whose child is still open, and a conditional-blocks onto an open target,
// each name their target, as a blocks edge does.
func runBlockedNamesWaitsForAndConditionalBlockers(t *testing.T, ctx context.Context, f BlockedListerFixture) {
label := f.IssuePrefix + "-bl-wf"
spawner, spawned := blListerID(f, "wf-spawner"), blListerID(f, "wf-spawned")
waiter := blListerID(f, "wf-waiter")
target, conditional := blListerID(f, "cb-target"), blListerID(f, "cb-src")
blListerSeedIssue(t, ctx, f, blListerIssue(spawner, 1, label+"-other"))
blListerSeedIssue(t, ctx, f, blListerIssue(spawned, 1, label+"-other"))
blListerSeedIssue(t, ctx, f, blListerIssue(target, 1, label+"-other"))
blListerSeedIssue(t, ctx, f, blListerIssue(waiter, 1, label))
blListerSeedIssue(t, ctx, f, blListerIssue(conditional, 1, label))
blListerSeedEdge(t, ctx, f, spawned, spawner, types.DepParentChild)
blListerSeedEdge(t, ctx, f, waiter, spawner, types.DepWaitsFor)
blListerSeedEdge(t, ctx, f, conditional, target, types.DepConditionalBlocks)
items := blListerList(t, ctx, f, publicops.BlockedRequest{Labels: []string{label}})
blListerAssertRows(t, items, map[string][]string{waiter: {spawner}, conditional: {target}})
}
// runBlockedOmitsAStaleFlag: a row whose stored flag says blocked but which
// has no active blocker and no parent names no blocker, so it is not listed.
// This is the narrowing gc's readiness projection documents relying on.
func runBlockedOmitsAStaleFlag(t *testing.T, ctx context.Context, f BlockedListerFixture) {
if f.MarkBlocked == nil {
t.Skip("this leg cannot write the stored is_blocked flag directly")
}
label := f.IssuePrefix + "-bl-stale"
stale, real, blocker := blListerID(f, "stale-src"), blListerID(f, "stale-real"), blListerID(f, "stale-blocker")
blListerSeedIssue(t, ctx, f, blListerIssue(stale, 1, label))
blListerSeedIssue(t, ctx, f, blListerIssue(real, 1, label))
blListerSeedIssue(t, ctx, f, blListerIssue(blocker, 1, label+"-other"))
blListerSeedEdge(t, ctx, f, real, blocker, types.DepBlocks)
if err := f.MarkBlocked(ctx, stale); err != nil {
t.Fatalf("mark %s blocked: %v", stale, err)
}
items := blListerList(t, ctx, f, publicops.BlockedRequest{Labels: []string{label}})
blListerAssertRows(t, items, map[string][]string{real: {blocker}})
}
// runBlockedHasNoTypeExclusions: a gate is listed like any other row; the
// blocked door excludes no issue type (unlike the ready front).
func runBlockedHasNoTypeExclusions(t *testing.T, ctx context.Context, f BlockedListerFixture) {
label := f.IssuePrefix + "-bl-type"
gate, epic, blocker := blListerID(f, "type-gate"), blListerID(f, "type-epic"), blListerID(f, "type-blocker")
g := blListerIssue(gate, 1, label)
g.IssueType = types.TypeGate
g.AwaitType = "human"
blListerSeedIssue(t, ctx, f, g)
e := blListerIssue(epic, 1, label)
e.IssueType = types.TypeEpic
blListerSeedIssue(t, ctx, f, e)
blListerSeedIssue(t, ctx, f, blListerIssue(blocker, 1, label+"-other"))
blListerSeedEdge(t, ctx, f, gate, blocker, types.DepBlocks)
blListerSeedEdge(t, ctx, f, epic, blocker, types.DepBlocks)
items := blListerList(t, ctx, f, publicops.BlockedRequest{Labels: []string{label}})
blListerAssertRows(t, items, map[string][]string{gate: {blocker}, epic: {blocker}})
}
// runBlockedEmptyIsAnEmptySlice: nothing blocked is an empty, non-nil slice
// and a nil error.
func runBlockedEmptyIsAnEmptySlice(t *testing.T, ctx context.Context, f BlockedListerFixture) {
result, err := f.BlockedLister.ListBlocked(ctx, publicops.BlockedRequest{Labels: []string{f.IssuePrefix + "-bl-nothing"}})
if err != nil {
t.Fatalf("ListBlocked: %v", err)
}
if result.Items == nil || len(result.Items) != 0 {
t.Fatalf("Items = %#v, want an empty non-nil slice", result.Items)
}
}
// runBlockedDoesNotMutateTheRequest: the caller's label slices come back as
// they were sent, normalization notwithstanding.
func runBlockedDoesNotMutateTheRequest(t *testing.T, ctx context.Context, f BlockedListerFixture) {
req := publicops.BlockedRequest{
ParentID: " ",
Labels: []string{" a ", "", "a"},
LabelsAny: []string{" b"},
ExcludeLabels: []string{"c "},
}
before := publicops.BlockedRequest{
ParentID: req.ParentID,
Labels: slices.Clone(req.Labels),
LabelsAny: slices.Clone(req.LabelsAny),
ExcludeLabels: slices.Clone(req.ExcludeLabels),
}
if _, err := f.BlockedLister.ListBlocked(ctx, req); err != nil {
t.Fatalf("ListBlocked: %v", err)
}
if !reflect.DeepEqual(req, before) {
t.Errorf("request after = %#v, before = %#v", req, before)
}
}
func blListerID(f BlockedListerFixture, name string) string {
return fmt.Sprintf("%s-%s", f.IssuePrefix, name)
}
func blListerIssue(id string, priority int, labels ...string) *types.Issue {
return &types.Issue{
ID: id,
Title: id,
Status: types.StatusOpen,
Priority: priority,
IssueType: types.TypeTask,
Labels: labels,
}
}
func blListerSeedIssue(t *testing.T, ctx context.Context, f BlockedListerFixture, issue *types.Issue) {
t.Helper()
if err := f.CreateIssue(ctx, issue, "seed"); err != nil {
t.Fatalf("seed issue %s: %v", issue.ID, err)
}
}
func blListerSeedEdge(t *testing.T, ctx context.Context, f BlockedListerFixture, from, to string, kind types.DependencyType) {
t.Helper()
if err := f.AddDependency(ctx, &types.Dependency{IssueID: from, DependsOnID: to, Type: kind}, "seed"); err != nil {
t.Fatalf("seed %s edge %s -> %s: %v", kind, from, to, err)
}
}
func blListerList(t *testing.T, ctx context.Context, f BlockedListerFixture, req publicops.BlockedRequest) []*types.BlockedIssue {
t.Helper()
result, err := f.BlockedLister.ListBlocked(ctx, req)
if err != nil {
t.Fatalf("ListBlocked(%+v): %v", req, err)
}
if result.Items == nil {
t.Fatalf("ListBlocked(%+v) Items is nil; the role promises a non-nil slice", req)
}
return result.Items
}
func blListerIDs(items []*types.BlockedIssue) []string {
ids := make([]string, 0, len(items))
for _, item := range items {
ids = append(ids, item.ID)
}
return ids
}
// assertBlockedRows requires the listing to be exactly want: the same ids,
// each naming exactly the blockers want gives it (in any order), with
// BlockedByCount equal to their number.
func blListerAssertRows(t *testing.T, items []*types.BlockedIssue, want map[string][]string) {
t.Helper()
got := map[string][]string{}
for _, item := range items {
if item == nil {
t.Fatalf("listing carries a nil row")
}
if _, dup := got[item.ID]; dup {
t.Errorf("row %s listed twice", item.ID)
}
blockers := slices.Clone(item.BlockedBy)
slices.Sort(blockers)
got[item.ID] = blockers
if item.BlockedByCount != len(item.BlockedBy) {
t.Errorf("row %s: BlockedByCount = %d, len(BlockedBy) = %d", item.ID, item.BlockedByCount, len(item.BlockedBy))
}
}
normalized := map[string][]string{}
for id, blockers := range want {
b := slices.Clone(blockers)
slices.Sort(b)
normalized[id] = b
}
if !reflect.DeepEqual(got, normalized) {
t.Errorf("listing = %v, want %v", got, normalized)
}
}

View file

@ -546,65 +546,3 @@ func assertParent(t *testing.T, result publicops.BlockingResult, id, want string
t.Errorf("entry %s parent = %q, want %q", id, got, want)
}
}
// RunBlockingAnnotatorReportsTheTransitiveBlockedFlag pins
// BlockingRequest.IncludeIsBlocked and IssueBlocking.IsBlocked: asked, each id
// with a row carries its STORED TRANSITIVE is_blocked flag — a child of a
// blocked parent is blocked with no blocking edge of its own, which BlockedBy
// alone would read as free — and an id naming no row carries none. Unasked,
// no item carries a flag. This is the read issueops.BlockedFlags (storage's
// IsBlockedBatch on a role-served backend) is built on.
func RunBlockingAnnotatorReportsTheTransitiveBlockedFlag(t *testing.T, ctx context.Context, fixture BlockingAnnotatorFixture) {
t.Helper()
blocker := fixture.IssuePrefix + "-flag-blocker"
blocked := fixture.IssuePrefix + "-flag-blocked"
child := fixture.IssuePrefix + "-flag-child"
free := fixture.IssuePrefix + "-flag-free"
ghost := fixture.IssuePrefix + "-flag-ghost"
seedBlockingIssues(t, ctx, fixture, blocker, blocked, child, free)
seedBlockingEdge(t, ctx, fixture, child, blocked, types.DepParentChild)
seedBlockingEdge(t, ctx, fixture, blocked, blocker, types.DepBlocks)
ids := []string{blocked, child, free, ghost}
unasked := annotateBlocking(t, ctx, fixture, publicops.BlockingRequest{IDs: ids})
for _, item := range unasked.Items {
if item.IsBlocked != nil {
t.Errorf("unasked: %s carries IsBlocked=%v, want no flag", item.ID, *item.IsBlocked)
}
}
asked := annotateBlocking(t, ctx, fixture, publicops.BlockingRequest{IDs: ids, IncludeIsBlocked: true})
want := map[string]*bool{blocked: new(true), child: new(true), free: new(false), ghost: nil}
if len(asked.Items) != len(ids) {
t.Fatalf("asked: %d items, want %d", len(asked.Items), len(ids))
}
for _, item := range asked.Items {
w, ok := want[item.ID]
if !ok {
t.Errorf("asked: unexpected item %s", item.ID)
continue
}
switch {
case w == nil && item.IsBlocked != nil:
t.Errorf("asked: %s (no row) IsBlocked=%v, want no flag", item.ID, *item.IsBlocked)
case w != nil && item.IsBlocked == nil:
t.Errorf("asked: %s IsBlocked absent, want %v", item.ID, *w)
case w != nil && *item.IsBlocked != *w:
t.Errorf("asked: %s IsBlocked=%v, want %v", item.ID, *item.IsBlocked, *w)
}
}
flags, err := publicops.BlockedFlags(ctx, fixture.Annotator, append(ids, blocked, ""))
if err != nil {
t.Fatalf("BlockedFlags: %v", err)
}
wantFlags := map[string]bool{blocked: true, child: true, free: false}
if len(flags) != len(wantFlags) {
t.Errorf("BlockedFlags = %v, want %v (no entry for the ghost or the blank id)", flags, wantFlags)
}
for id, w := range wantFlags {
if got, ok := flags[id]; !ok || got != w {
t.Errorf("BlockedFlags[%s] = %v (present %v), want %v", id, got, ok, w)
}
}
}

View file

@ -57,19 +57,6 @@ type CounterFixture struct {
// A nil hook means "this backend cannot observe history", and the case
// that needs it SKIPS rather than passing quietly.
CountHistory func(context.Context) (int, error)
// AddDependency seeds one dependency edge, the same hook
// ReaderFixture/DependencyEditorFixture take it from (role_fixture_kit's
// shared AddDependency). It exists here only for the ParentID/NoParent
// scope cases (S8): NoParent excludes by PARENT-CHILD EDGE alone
// (sqlbuild/filter.go), unlike ParentID's dotted-id-prefix fallback, so
// pinning it needs a real edge and not just a naming convention.
AddDependency func(context.Context, *types.Dependency, string) error
// List runs the List role's query directly (the store's IssueReader), so
// the storage-level parity cases below (S8 review, follow-up #5) can
// compare Count's answer against len(List's rows) for the same scope
// without going through a second builder. A nil hook skips those cases
// rather than failing: not every backend wiring has a Reader to hand.
List func(context.Context, publicops.ListRequest) (publicops.IssuePage, error)
}
// RunCounterCountsTheDurablePlaneByDefault pins counter.go:123-126 from the
@ -189,323 +176,6 @@ func RunCounterAnUnknownStatusMatchesNothing(t *testing.T, ctx context.Context,
assertCounterTotal(t, ctx, fixture, scope, 0)
}
// RunCounterParentIDScopesToChildren pins CountRequest.ParentID (counter.go,
// S8): restricted to ONE issue's children, reached two ways at once, exactly
// as ListRequest.ParentID is (sqlbuild/filter.go) — a parent-child dependency
// edge, OR (for a row with no such edge) a dotted-id prefix match. The parent
// itself, an unrelated row and a same-prefix DECOY (sibling id with no
// separator, e.g. "parent2") are all seeded so neither arm can pass by
// over-matching.
func RunCounterParentIDScopesToChildren(t *testing.T, ctx context.Context, fixture CounterFixture) {
t.Helper()
parent := fixture.IssuePrefix + "-parentid-parent"
byEdge := fixture.IssuePrefix + "-parentid-byedge"
byDotted := parent + ".1"
decoy := parent + "x"
unrelated := fixture.IssuePrefix + "-parentid-unrelated"
for _, id := range []string{parent, byEdge, byDotted, decoy, unrelated} {
seedCounterIssue(t, ctx, fixture, counterSeed(id))
}
requireCounterAddDependency(t, fixture)
if err := fixture.AddDependency(ctx, &types.Dependency{
IssueID: byEdge, DependsOnID: parent, Type: types.DepParentChild,
}, "seed"); err != nil {
t.Fatalf("seed edge %s -> %s: %v", byEdge, parent, err)
}
scope := counterScope(parent, byEdge, byDotted, decoy, unrelated)
scope.ParentID = parent
// Both children count; the parent, the decoy and the unrelated row do not.
assertCounterTotal(t, ctx, fixture, scope, 2)
}
// RunCounterNoParentExcludesChildren pins CountRequest.NoParent
// (counter.go, S8): restricted to rows with NO parent-child edge.
//
// Unlike ParentID, NoParent's SQL clause (sqlbuild/filter.go) checks ONLY the
// parent-child dependency table, not the dotted-id convention — a row that is
// a dotted-id child with no edge at all still passes NoParent. That asymmetry
// is exactly what the "byDotted" row below pins: it is excluded from
// ParentID's answer by nothing (RunCounterParentIDScopesToChildren already
// admits it), but NoParent admits it too, because it carries no edge.
func RunCounterNoParentExcludesChildren(t *testing.T, ctx context.Context, fixture CounterFixture) {
t.Helper()
parent := fixture.IssuePrefix + "-noparent-parent"
child := fixture.IssuePrefix + "-noparent-child"
byDotted := parent + ".1"
for _, id := range []string{parent, child, byDotted} {
seedCounterIssue(t, ctx, fixture, counterSeed(id))
}
requireCounterAddDependency(t, fixture)
if err := fixture.AddDependency(ctx, &types.Dependency{
IssueID: child, DependsOnID: parent, Type: types.DepParentChild,
}, "seed"); err != nil {
t.Fatalf("seed edge %s -> %s: %v", child, parent, err)
}
scope := counterScope(parent, child, byDotted)
assertCounterTotal(t, ctx, fixture, scope, 3)
scope.NoParent = true
// child is excluded (has an edge); parent and byDotted remain (neither
// carries a parent-child edge, and NoParent does not consult the dotted
// naming convention at all).
assertCounterTotal(t, ctx, fixture, scope, 2)
}
// RunCounterExcludeTypesNarrowsThePredicate pins CountRequest.ExcludeTypes
// (counter.go, S8): named types are excluded from the count, composing with
// (rather than replacing) IncludeInfra's own "gate" exclusion.
func RunCounterExcludeTypesNarrowsThePredicate(t *testing.T, ctx context.Context, fixture CounterFixture) {
t.Helper()
task := fixture.IssuePrefix + "-extype-task"
chore := fixture.IssuePrefix + "-extype-chore"
gate := fixture.IssuePrefix + "-extype-gate"
seedCounterIssue(t, ctx, fixture, counterSeed(task))
choreSeed := counterSeed(chore)
choreSeed.IssueType = types.TypeChore
seedCounterIssue(t, ctx, fixture, choreSeed)
gateSeed := counterSeed(gate)
gateSeed.IssueType = types.IssueType("gate")
seedCounterIssue(t, ctx, fixture, gateSeed)
scope := counterScope(task, chore, gate)
assertCounterTotal(t, ctx, fixture, scope, 3)
scope.ExcludeTypes = []string{"chore"}
assertCounterTotal(t, ctx, fixture, scope, 2)
// Composes with IncludeInfra's own default gate exclusion: both the
// explicit chore exclusion and the include-infra gate exclusion apply at
// once, leaving only task.
scope.IncludeInfra = true
assertCounterTotal(t, ctx, fixture, scope, 1)
}
// RunCounterExcludeStatusNarrowsThePredicate pins CountRequest.ExcludeStatus
// (counter.go, S8): a Count-only field with no List counterpart. Named
// statuses are excluded, and — UNLIKE Status — an unrecognized name is
// refused as ErrValidation rather than excluding nothing, because a typo
// would silently overcount (counter.go).
func RunCounterExcludeStatusNarrowsThePredicate(t *testing.T, ctx context.Context, fixture CounterFixture) {
t.Helper()
open := fixture.IssuePrefix + "-exstatus-open"
closed := fixture.IssuePrefix + "-exstatus-closed"
seedCounterIssue(t, ctx, fixture, counterSeed(open))
closedSeed := counterSeed(closed)
closedSeed.Status = types.StatusClosed
seedCounterIssue(t, ctx, fixture, closedSeed)
scope := counterScope(open, closed)
assertCounterTotal(t, ctx, fixture, scope, 2)
scope.ExcludeStatus = []string{"closed"}
assertCounterTotal(t, ctx, fixture, scope, 1)
// Unlike Status and IssueType, ExcludeStatus IS validated (S8 review,
// follow-up #3): a misspelled entry would silently exclude nothing and
// OVERCOUNT, so an unrecognized name is refused as ErrValidation instead
// of treated as a no-op.
scope.ExcludeStatus = []string{"no-such-status"}
if _, err := fixture.Counter.Count(ctx, scope); !errors.Is(err, publicops.ErrValidation) {
t.Errorf("Count with an unrecognized exclude-status = %v, want ErrValidation", err)
}
}
// requireCounterAddDependency skips a case that needs a real parent-child
// edge when the fixture offers no way to create one, rather than failing with
// a nil-pointer call — mirroring counterHistoryCount's optional-hook pattern.
func requireCounterAddDependency(t *testing.T, fixture CounterFixture) {
t.Helper()
if fixture.AddDependency == nil {
t.Skip("fixture cannot seed a dependency edge: AddDependency is nil")
}
}
// requireCounterList skips a case that needs the List role when the fixture
// offers no way to reach it, mirroring requireCounterAddDependency.
func requireCounterList(t *testing.T, fixture CounterFixture) {
t.Helper()
if fixture.List == nil {
t.Skip("fixture cannot run the List role: List is nil")
}
}
// assertCounterMatchesList compares Count's Total against len(List's rows)
// for the same scope, with List's AllFlag and IncludeAllTypes both set so
// List's own default exclusions (status, pinned, template, gate, infra-plane)
// are lifted exactly as far as Count's own default lifts none of them
// (workapi.BuildCountFilter's doc, count.go) — the one combination that
// makes the two cardinalities comparable at all for an arbitrary scope.
//
// This is a DIFFERENT check than
// TestBuildCountFilterParentFieldsMatchListFilter
// (internal/workapi/count_test.go), which compares the two FILTERS a shared
// request builds without touching a store; this one runs both roles against
// a real backend and compares what they actually return (S8 review, follow-up
// #5).
func assertCounterMatchesList(t *testing.T, ctx context.Context, fixture CounterFixture, idFilter, parentID string, noParent bool, excludeTypes []string) {
t.Helper()
countReq := publicops.CountRequest{
IDFilter: idFilter,
ParentID: parentID,
NoParent: noParent,
ExcludeTypes: excludeTypes,
}
total := counterTotal(t, ctx, fixture, countReq)
listReq := publicops.ListRequest{
IDFilter: idFilter,
ParentID: parentID,
NoParent: noParent,
ExcludeTypes: excludeTypes,
AllFlag: true,
IncludeAllTypes: true,
}
page, err := fixture.List(ctx, listReq)
if err != nil {
t.Fatalf("List(%+v): %v", listReq, err)
}
if got := int64(len(page.Items)); got != total {
t.Errorf("Count(%+v) = %d, len(List(%+v).Items) = %d, want equal", countReq, total, listReq, got)
}
}
// RunCounterParentIDMatchesListCardinality pins the storage-level half of
// CountRequest.ParentID's promise (S8 review, follow-up #5a): for one scope,
// Count's Total equals len(List's rows) for the equivalent ParentID scope.
func RunCounterParentIDMatchesListCardinality(t *testing.T, ctx context.Context, fixture CounterFixture) {
t.Helper()
requireCounterList(t, fixture)
requireCounterAddDependency(t, fixture)
parent := fixture.IssuePrefix + "-parity-parentid-parent"
byEdge := fixture.IssuePrefix + "-parity-parentid-byedge"
byDotted := parent + ".1"
unrelated := fixture.IssuePrefix + "-parity-parentid-unrelated"
for _, id := range []string{parent, byEdge, byDotted, unrelated} {
seedCounterIssue(t, ctx, fixture, counterSeed(id))
}
if err := fixture.AddDependency(ctx, &types.Dependency{
IssueID: byEdge, DependsOnID: parent, Type: types.DepParentChild,
}, "seed"); err != nil {
t.Fatalf("seed edge %s -> %s: %v", byEdge, parent, err)
}
idFilter := counterScope(parent, byEdge, byDotted, unrelated).IDFilter
assertCounterMatchesList(t, ctx, fixture, idFilter, parent, false, nil)
}
// RunCounterNoParentMatchesListCardinality pins the storage-level half of
// CountRequest.NoParent's promise (S8 review, follow-up #5a).
func RunCounterNoParentMatchesListCardinality(t *testing.T, ctx context.Context, fixture CounterFixture) {
t.Helper()
requireCounterList(t, fixture)
requireCounterAddDependency(t, fixture)
parent := fixture.IssuePrefix + "-parity-noparent-parent"
child := fixture.IssuePrefix + "-parity-noparent-child"
byDotted := parent + ".1"
for _, id := range []string{parent, child, byDotted} {
seedCounterIssue(t, ctx, fixture, counterSeed(id))
}
if err := fixture.AddDependency(ctx, &types.Dependency{
IssueID: child, DependsOnID: parent, Type: types.DepParentChild,
}, "seed"); err != nil {
t.Fatalf("seed edge %s -> %s: %v", child, parent, err)
}
idFilter := counterScope(parent, child, byDotted).IDFilter
assertCounterMatchesList(t, ctx, fixture, idFilter, "", true, nil)
}
// RunCounterExcludeTypesMatchesListCardinality pins the storage-level half of
// CountRequest.ExcludeTypes' promise (S8 review, follow-up #5a). ExcludeStatus
// has no List counterpart (counter.go) so it is not part of this parity
// family; RunCounterExcludeStatusNarrowsThePredicate above is its only
// coverage.
func RunCounterExcludeTypesMatchesListCardinality(t *testing.T, ctx context.Context, fixture CounterFixture) {
t.Helper()
requireCounterList(t, fixture)
task := fixture.IssuePrefix + "-parity-extype-task"
chore := fixture.IssuePrefix + "-parity-extype-chore"
seedCounterIssue(t, ctx, fixture, counterSeed(task))
choreSeed := counterSeed(chore)
choreSeed.IssueType = types.TypeChore
seedCounterIssue(t, ctx, fixture, choreSeed)
idFilter := counterScope(task, chore).IDFilter
assertCounterMatchesList(t, ctx, fixture, idFilter, "", false, []string{"chore"})
}
// RunCounterParentIDIncludesAWispChild pins that ParentID's edge match reaches
// into the wisp tier exactly as IncludeInfra's merge does (S8 review,
// follow-up #5b): a child seeded in the ephemeral/wisp tier, linked to its
// parent by the same parent-child edge ParentID matches on, is invisible to
// Count's durable-only default and counted once IncludeInfra merges the wisps
// table in.
func RunCounterParentIDIncludesAWispChild(t *testing.T, ctx context.Context, fixture CounterFixture) {
t.Helper()
requireCounterAddDependency(t, fixture)
parent := fixture.IssuePrefix + "-wispchild-parent"
wispChild := fixture.IssuePrefix + "-wispchild-child"
seedCounterIssue(t, ctx, fixture, counterSeed(parent))
seedCounterWisp(t, ctx, fixture, counterSeed(wispChild))
if err := fixture.AddDependency(ctx, &types.Dependency{
IssueID: wispChild, DependsOnID: parent, Type: types.DepParentChild,
}, "seed"); err != nil {
t.Fatalf("seed edge %s -> %s: %v", wispChild, parent, err)
}
scope := counterScope(parent, wispChild)
scope.ParentID = parent
// Durable-only default (counter.go, RunCounterCountsTheDurablePlaneByDefault):
// the wisp child is invisible without IncludeInfra.
assertCounterTotal(t, ctx, fixture, scope, 0)
scope.IncludeInfra = true
assertCounterTotal(t, ctx, fixture, scope, 1)
}
// RunCounterParentIDAndExcludeStatusComposeOnAClosedChild pins that ParentID
// and ExcludeStatus apply as a conjunction, not alternatives (S8 review,
// follow-up #5b): a closed child under its parent is counted by ParentID
// alone (Count hides nothing by default), and excluded once ExcludeStatus
// names its status, leaving only the open child.
func RunCounterParentIDAndExcludeStatusComposeOnAClosedChild(t *testing.T, ctx context.Context, fixture CounterFixture) {
t.Helper()
requireCounterAddDependency(t, fixture)
parent := fixture.IssuePrefix + "-closedchild-parent"
openChild := fixture.IssuePrefix + "-closedchild-open"
closedChild := fixture.IssuePrefix + "-closedchild-closed"
seedCounterIssue(t, ctx, fixture, counterSeed(parent))
seedCounterIssue(t, ctx, fixture, counterSeed(openChild))
closedSeed := counterSeed(closedChild)
closedSeed.Status = types.StatusClosed
seedCounterIssue(t, ctx, fixture, closedSeed)
for _, child := range []string{openChild, closedChild} {
if err := fixture.AddDependency(ctx, &types.Dependency{
IssueID: child, DependsOnID: parent, Type: types.DepParentChild,
}, "seed"); err != nil {
t.Fatalf("seed edge %s -> %s: %v", child, parent, err)
}
}
scope := counterScope(parent, openChild, closedChild)
scope.ParentID = parent
assertCounterTotal(t, ctx, fixture, scope, 2)
scope.ExcludeStatus = []string{"closed"}
assertCounterTotal(t, ctx, fixture, scope, 1)
}
// RunCounterGroupsPartitionTheScalarSet pins counter.go:168-169 and :244-245
// for a dimension whose buckets do NOT overlap: the grouped Total is the same
// number a scalar Count returns, and the buckets partition it exactly.

View file

@ -531,96 +531,6 @@ func RunDependencyEditorSameTypeReAddWithIdenticalMetadataIsANoOp(t *testing.T,
}
}
// RunDependencyEditorSameTypeReAddWithChangedThreadMintsOneVersion is the
// thread_id twin of
// RunDependencyEditorSameTypeReAddWithChangedMetadataMintsOneVersion. The row
// carries a thread as well as metadata, and the source issue's version snapshot
// carries each edge's thread_id, so a same-type re-add naming a thread the row
// does not carry is a real mutation on the same terms as a metadata change:
// the leaf updates the row in place, journals the replacement edge, and mints
// EXACTLY ONE version (#5898 leg 2). The re-add arm once compared metadata
// alone, which read that re-add as change-free and dropped the thread.
//
// The metadata is identical across every write, so the thread is the only
// thing that moves. A last re-add names no thread, and is the change-free
// no-op: an empty thread names none rather than asking for none, which is
// what keeps the callers that never carry a thread from erasing one.
//
// It drives the writes through fixture.AddDependency for the reason the
// metadata case gives: publicops.DependencyEdge carries no thread either.
func RunDependencyEditorSameTypeReAddWithChangedThreadMintsOneVersion(t *testing.T, ctx context.Context, fixture DependencyEditorFixture) {
t.Helper()
if fixture.AddDependency == nil {
t.Skip("fixture has no AddDependency hook: a thread is not settable through publicops.DependencyEdge")
}
fixture.SetJournalEnabled(true)
t.Cleanup(func() { fixture.SetJournalEnabled(false) })
fixture.SetVersionedHistoryEnabled(true)
t.Cleanup(func() { fixture.SetVersionedHistoryEnabled(false) })
source := fixture.IssuePrefix + "-idemthread-source"
target := fixture.IssuePrefix + "-idemthread-target"
seedDependencyEditorIssue(t, ctx, fixture, source)
seedDependencyEditorIssue(t, ctx, fixture, target)
const metadata = `{"note":"v1"}`
add := func(thread, refusal string) {
t.Helper()
dep := &types.Dependency{IssueID: source, DependsOnID: target, Type: types.DepBlocks, Metadata: metadata, ThreadID: thread}
if err := fixture.AddDependency(ctx, dep, "writer"); err != nil {
t.Fatalf("%s: %v", refusal, err)
}
assertDependencyEdgeTypedCount(t, ctx, fixture, "dependencies", source, target, string(types.DepBlocks), 1)
assertDependencyEditorEventCount(t, ctx, fixture, "events", source, types.EventDependencyAdded, 1)
}
storedThread := func() string {
t.Helper()
var thread string
if err := fixture.QueryScalar(ctx,
"SELECT COALESCE(thread_id, '') FROM dependencies WHERE issue_id = ? AND COALESCE(depends_on_issue_id, depends_on_wisp_id, depends_on_external) = ?",
[]any{source, target}, &thread); err != nil {
t.Fatalf("read stored thread_id for %s -> %s: %v", source, target, err)
}
return thread
}
journalCount := func() int {
t.Helper()
var count int
if err := fixture.QueryScalar(ctx,
"SELECT COUNT(*) FROM bd_events_journal WHERE issue_id = ? AND op = ?",
[]any{source, string(storeops.EventDepAdd)}, &count); err != nil {
t.Fatalf("count bd_events_journal dep_add rows for %s: %v", source, err)
}
return count
}
add("", "AddDependency first")
assertDependencyEditorJournalCountIsOne(t, ctx, fixture, source, string(storeops.EventDepAdd))
versionsBefore := countDependencyEditorIssueVersions(t, ctx, fixture, source)
add("thread-conv-1", "re-adding the same edge with a new thread refused")
if got := storedThread(); got != "thread-conv-1" {
t.Errorf("stored thread_id = %q, want %q: the re-add must persist the new thread, not keep the old", got, "thread-conv-1")
}
if got := journalCount(); got != 2 {
t.Errorf("bd_events_journal dep_add rows for %s = %d, want 2: the thread-changed re-add must journal its own replacement-edge entry", source, got)
}
if delta := countDependencyEditorIssueVersions(t, ctx, fixture, source) - versionsBefore; delta != 1 {
t.Errorf("issue_versions rows for %s went %d -> %d (delta %d), want a delta of 1: the thread genuinely changed, so the re-add is a real mutation of the source issue and must mint exactly one version (#5898 leg 2)", source, versionsBefore, versionsBefore+delta, delta)
}
versionsBefore = countDependencyEditorIssueVersions(t, ctx, fixture, source)
add("", "re-adding the same edge naming no thread refused")
if got := storedThread(); got != "thread-conv-1" {
t.Errorf("stored thread_id after a re-add naming no thread = %q, want %q kept", got, "thread-conv-1")
}
if got := journalCount(); got != 2 {
t.Errorf("bd_events_journal dep_add rows for %s = %d after a change-free re-add, want 2 still", source, got)
}
if delta := countDependencyEditorIssueVersions(t, ctx, fixture, source) - versionsBefore; delta != 0 {
t.Errorf("issue_versions rows for %s went %d -> %d (delta %d) on a re-add naming no thread, want a delta of 0: it keeps the stored thread, so nothing changed (#5898 R3)", source, versionsBefore, versionsBefore+delta, delta)
}
}
// RunDependencyEditorRepeatsWithinOneRequestCollapse pins the clause that
// answers a request naming ONE PAIR TWICE. The same-type re-add rule is stated
// for the pair rather than for the call, so the second occurrence inside a
@ -2631,82 +2541,3 @@ func dependencyEditorHistoryProbe(t *testing.T, ctx context.Context, fixture Dep
assertDependencyEditorHistoryDelta(t, ctx, fixture, before, want, why)
}
}
// RunDependencyEditorRefusesADottedChildGatedOnItsOwnParent pins
// publicops.CheckDottedChildDependency on the role: an explicit edge from a
// dotted-id child to its own ancestor is refused as a
// *DottedChildDependencyError (ErrValidation) on every leg, and nothing is
// written. (It is decided before any per-edge probe, so the probe-skipped
// spelling, which the wire does not publish, adds nothing here.) It used to be
// enforced only by the CLI ahead of the role, so an HTTP or embedded caller
// could gate bd-abc.1 on bd-abc.
//
// POSITIVE HALF: the hierarchy itself — a parent-child edge to the IMMEDIATE
// dotted parent — is allowed, and so is an edge between siblings. A body that
// refused every edge touching a dotted id would satisfy the refusals alone.
//
// WITH THE HIERARCHY STORED: once that parent-child edge exists (the shape
// `bd create --parent` leaves), a blocking edge on the same pair is still this
// refusal, not the type or hierarchy conflict the stored edge would raise — the
// rule reads nothing, so it answers first — and the stored edge survives.
func RunDependencyEditorRefusesADottedChildGatedOnItsOwnParent(t *testing.T, ctx context.Context, fixture DependencyEditorFixture) {
t.Helper()
parent := fixture.IssuePrefix + "-dotted"
child := parent + ".1"
grandchild := child + ".2"
sibling := parent + ".3"
for _, id := range []string{parent, child, grandchild, sibling} {
seedDependencyEditorIssue(t, ctx, fixture, id)
}
for _, refused := range []struct {
name string
edge publicops.DependencyEdge
}{
{"child blocks on its parent", publicops.DependencyEdge{IssueID: child, DependsOnID: parent, Type: publicops.DepBlocks}},
{"grandchild blocks on its grandparent", publicops.DependencyEdge{IssueID: grandchild, DependsOnID: parent, Type: publicops.DepBlocks}},
{"grandchild parent-child to its grandparent", publicops.DependencyEdge{IssueID: grandchild, DependsOnID: parent, Type: publicops.DepParentChild}},
{"child relates to its parent", publicops.DependencyEdge{IssueID: child, DependsOnID: parent, Type: publicops.DepRelated}},
} {
_, err := fixture.Editor.AddDependencies(ctx, publicops.AddDependenciesRequest{
Actor: "writer",
Edges: []publicops.DependencyEdge{refused.edge},
})
var dotted *publicops.DottedChildDependencyError
if !errors.As(err, &dotted) {
t.Errorf("%s: error = %v, want *DottedChildDependencyError", refused.name, err)
continue
}
if !errors.Is(err, publicops.ErrValidation) {
t.Errorf("%s: error = %v, want it to match ErrValidation", refused.name, err)
}
if dotted.IssueID != refused.edge.IssueID || dotted.DependsOnID != refused.edge.DependsOnID {
t.Errorf("%s: refusal names %s -> %s, want %s -> %s", refused.name,
dotted.IssueID, dotted.DependsOnID, refused.edge.IssueID, refused.edge.DependsOnID)
}
}
assertDependencyEditorNoEdgesFrom(t, ctx, fixture, child, grandchild)
if _, err := fixture.Editor.AddDependencies(ctx, publicops.AddDependenciesRequest{
Actor: "writer",
Edges: []publicops.DependencyEdge{
{IssueID: grandchild, DependsOnID: child, Type: publicops.DepParentChild},
{IssueID: sibling, DependsOnID: child, Type: publicops.DepBlocks},
},
}); err != nil {
t.Fatalf("the immediate parent-child edge and a sibling edge: %v", err)
}
assertDependencyEdgeTypedCount(t, ctx, fixture, "dependencies", grandchild, child, string(publicops.DepParentChild), 1)
assertDependencyEdgeCount(t, ctx, fixture, "dependencies", sibling, child, 1)
_, err := fixture.Editor.AddDependencies(ctx, publicops.AddDependenciesRequest{
Actor: "writer",
Edges: []publicops.DependencyEdge{{IssueID: grandchild, DependsOnID: child, Type: publicops.DepBlocks}},
})
var dotted *publicops.DottedChildDependencyError
if !errors.As(err, &dotted) || !errors.Is(err, publicops.ErrValidation) {
t.Errorf("blocks on a parent whose parent-child edge is stored: error = %v, want *DottedChildDependencyError matching ErrValidation", err)
}
assertDependencyEdgeTypedCount(t, ctx, fixture, "dependencies", grandchild, child, string(publicops.DepParentChild), 1)
assertDependencyEdgeCount(t, ctx, fixture, "dependencies", grandchild, child, 1)
}

View file

@ -71,13 +71,11 @@ import (
// - PARTICIPATION-GENERATION GATING (design §16.2b). Whether an
// update-shaped mutation on a legacy (participation_generation IS NULL)
// row is correctly skipped is Phase 2 behavior this bead also owns, but
// it depends on migration 0070's participation_generation column, which
// does not exist when this contract is first written (0070 lands last in
// this bead's build order, by the mayor's explicit sequencing — steps 4-5
// of design §16.3 moved to their own migration slot when 0068 shipped as
// attribution_status-only, see that migration's header). It gets its own
// dedicated cases once 0070 lands, beside this file rather than inside
// it.
// it depends on migration 0068's participation_generation column, which
// does not exist when this contract is first written (0068 lands last in
// this bead's build order, by the mayor's explicit sequencing). It gets
// its own dedicated cases once 0068 lands, beside this file rather than
// inside it.
// - CONCURRENT WRITERS. Every case here is one writer, one issue, one
// mutation at a time — the same restriction journal_contract.go states
// for the same reason: a single-threaded case cannot exercise what only

View file

@ -1,644 +0,0 @@
package conformance
import (
"context"
"testing"
)
// This file holds the write-fence cases dualwrite_history_contract.go's own
// "WHAT THIS CONTRACT DELIBERATELY DOES NOT PIN" section explicitly deferred:
// "PARTICIPATION-GENERATION GATING (design §16.2b)... It gets its own
// dedicated cases once 0070 lands, beside this file rather than inside it."
// Migration 0070 now carries participation_generation on both issues and
// wisps (design §16.3 steps 4-5, be-dt74u amendment, be-h89oq), so this is
// that file.
//
// Design §16.2b, verbatim substance: the flag-on writer does not increment
// current_revision or mint an issue_versions row for an UPDATE-shaped
// mutation against a record whose participation_generation is NULL — a skip,
// not a refusal (FR-2's zero-rows no-op shape). A CREATE-shaped mutation is
// different: a brand-new row has no prior legacy state to preserve, so if the
// flag is already on at creation time, the writer stamps
// participation_generation as part of the same insert that begins its
// history. A create with the flag off leaves the column NULL, indistinguishable
// from a true legacy row (FR-7's byte-identical requirement).
//
// WHY A SEPARATE FIXTURE RATHER THAN THREE MORE DualWriteFixture CLOSURES.
// DualWriteFixture's Mutate/MutateAsNoOp pair is deliberately flag-fixed-at-
// construction (see that file's SEEDING DISCIPLINE note and each leg's
// newXxxDualWriteFixture, which calls SetVersionedHistoryEnabled exactly
// once). The legacy-record case here is inherently "created while the flag
// was OFF, then mutated after the flag turns ON" — a fixture built once with
// one flag state cannot express that sequence, so SetFlag here is a toggle
// callable more than once per fixture, not a one-time constructor argument.
//
// THE FIXTURE'S CLOSURES ARE THE OBSERVABLE SURFACE, NOT THE SCHEMA — same
// discipline as DualWriteFixture: Mutate/MutateExisting drive CreateIssue and
// UpdateIssue (or their unit-of-work equivalents), never issue_versions or
// store_epoch directly.
//
// WHAT THIS CONTRACT DELIBERATELY DOES NOT PIN:
// - THE EXACT STAMPED VALUE. That a create-shaped mutation with the flag on
// stamps SOME non-NULL participation_generation is pinned here; that the
// value equals the current store_epoch.epoch is not — reaching
// store_epoch is the same one-column, two-of-three-legs-need-white-box-
// access problem dualwrite_history_contract.go's FR-6 note describes, and
// the same resolution applies: pinned per leg, dolt-only, alongside
// TestDualWriteStampsTheCurrentStoreEpochOnEachVersionRow.
// - wisps.participation_generation. FR-8 (carried by dualwrite_history_contract.go's
// exclusion list) applies here too: this fixture's Mutate front door is
// CreateIssue against the issues table, the wisp-arrival cases read only
// the issues row a wisp becomes, and no phase reads or writes the wisps
// column regardless.
type ParticipationGenerationFixture struct {
// IssuePrefix namespaces the id each case mints, the same discipline
// DualWriteFixture uses and for the same reason.
IssuePrefix string
// SetFlag toggles versioned history for every subsequent call through
// this fixture, and may be called more than once per case — unlike
// DualWriteFixture, whose flag is fixed at construction.
SetFlag func(ctx context.Context, enabled bool) error
// Mutate creates a new issue with the given id: a CREATE-shaped mutation
// in design §16.2b's sense.
Mutate func(ctx context.Context, id string) error
// MutateExisting applies a real (non-no-op) UPDATE-shaped mutation to an
// already-existing issue — a different value than Mutate gave it, so a
// vacuous no-op skip can never be mistaken for the fence.
MutateExisting func(ctx context.Context, id string) error
// CreateWisp creates a new wisp-plane (ephemeral) issue with the given
// id: the starting point for the two ways a record reaches the issues
// plane without being created there. A wisp is never versioned (FR-8)
// and never carries a participation declaration, in either flag state.
CreateWisp func(ctx context.Context, id string) error
// PromoteWisp promotes the wisp id onto the issues plane
// (PromoteFromEphemeral, or the unit-of-work leg's PromoteWisp).
PromoteWisp func(ctx context.Context, id string) error
// MovePersistent moves the wisp id onto the issues plane through a
// persistence-mode update (bd update --persistent). It is its own
// closure rather than a second spelling of PromoteWisp because it mints at
// a different site on every leg: the guarded update's one end-of-update
// mint on dolt and embeddeddolt, MoveIssuePersistenceInTx's own on uow.
// On an issues-plane row whose flags disagree with it (see
// CreateNoHistoryIssue) the same update repairs the flags in place, a
// same-plane normalize, rather than moving the row.
MovePersistent func(ctx context.Context, id string) error
// ClearWispFlag clears the wisp id's ephemeral flag IN PLACE: the untyped
// UpdateIssue of {"wisp": false} bd mol squash makes on a squashed root
// (UpdateWisp on the unit-of-work leg, the way its molecule writer routes
// it). The row stays in the wisps table, now carrying neither Ephemeral
// nor NoHistory.
ClearWispFlag func(ctx context.Context, id string) error
// SquashWispRoot closes the wisp id and then clears its flag as
// ClearWispFlag does, both in ONE transaction: the shape bd mol squash's
// root auto-close takes, where an error from either write aborts both.
SquashWispRoot func(ctx context.Context, id string) error
// CreateUnflaggedWisp creates id in the wisps table with neither
// Ephemeral nor NoHistory set: import's "wisp_plane" marker, which pins
// the plane whatever the flags say (WispPlaneOverride = &true, through
// the batch create import runs), or on the unit-of-work leg CreateWisp,
// which routes by the call rather than by the flags.
CreateUnflaggedWisp func(ctx context.Context, id string) error
// CreateNoHistoryIssue creates id in the ISSUES table carrying
// NoHistory=true: import's promoted-no-history shape (bd-r9uce), a
// durable row whose stray flag is preserved while WispPlaneOverride =
// &false pins its plane, through the batch create import runs; or on the
// unit-of-work leg CreateIssue, which routes by the call.
CreateNoHistoryIssue func(ctx context.Context, id string) error
// CurrentRevision reads issues.current_revision for id.
CurrentRevision func(ctx context.Context, id string) (int64, error)
// VersionRowCount reads how many issue_versions rows exist for id.
VersionRowCount func(ctx context.Context, id string) (int, error)
// ParticipationGeneration reads issues.participation_generation for id,
// returning nil for SQL NULL.
ParticipationGeneration func(ctx context.Context, id string) (*int64, error)
// InWispsTable reports whether the wisps table holds a row for id: the
// precondition the wisps-table cases check, so they cannot pass on a row
// that a step moved to the issues table.
InWispsTable func(ctx context.Context, id string) (bool, error)
}
// RunParticipationGenerationCreateWithFlagOnStampsAValue pins design
// §16.2(a)/(b): a create-shaped mutation with the flag already on stamps a
// non-NULL participation_generation on the new row, as part of the same
// insert that begins its history — a brand-new row has no legacy state to
// preserve, so there is nothing to skip.
func RunParticipationGenerationCreateWithFlagOnStampsAValue(t *testing.T, ctx context.Context, fixture ParticipationGenerationFixture) {
t.Helper()
if err := fixture.SetFlag(ctx, true); err != nil {
t.Fatalf("enabling versioned history: %v", err)
}
id := fixture.IssuePrefix + "-create-stamps"
if err := fixture.Mutate(ctx, id); err != nil {
t.Fatalf("mutating %s: %v", id, err)
}
gen, err := fixture.ParticipationGeneration(ctx, id)
if err != nil {
t.Fatalf("reading participation_generation for %s: %v", id, err)
}
if gen == nil {
t.Errorf("participation_generation for %s is NULL immediately after a create-shaped mutation with "+
"the flag on, want a stamped non-NULL value: design §16.2b requires the writer to declare "+
"participation at insert time, since a brand-new row has no prior legacy state to preserve", id)
}
}
// RunParticipationGenerationCreateWithFlagOffLeavesLegacyNull pins the other
// half of design §16.2(b): a create-shaped mutation with the flag off leaves
// participation_generation NULL, indistinguishable from a true legacy row —
// flag-off must stay byte-identical to pre-Phase-2 behavior (FR-7).
func RunParticipationGenerationCreateWithFlagOffLeavesLegacyNull(t *testing.T, ctx context.Context, fixture ParticipationGenerationFixture) {
t.Helper()
if err := fixture.SetFlag(ctx, false); err != nil {
t.Fatalf("disabling versioned history: %v", err)
}
id := fixture.IssuePrefix + "-create-flag-off"
if err := fixture.Mutate(ctx, id); err != nil {
t.Fatalf("mutating %s: %v", id, err)
}
gen, err := fixture.ParticipationGeneration(ctx, id)
if err != nil {
t.Fatalf("reading participation_generation for %s: %v", id, err)
}
if gen != nil {
t.Errorf("participation_generation for %s = %d with the flag off at creation, want NULL: a "+
"flag-off create must remain indistinguishable from a true legacy row (design §16.2b)", id, *gen)
}
}
// RunParticipationGenerationSkipsUpdateOnLegacyRecord pins the write fence's
// central claim, design §16.2(b): the flag-on writer does not increment
// current_revision or mint an issue_versions row for an update-shaped
// mutation against a record whose participation_generation is NULL. The
// record must be a REAL legacy record — created while the flag was off, not
// merely one the fixture asserts is NULL — so this also re-confirms that
// precondition before trusting the rest of the case.
func RunParticipationGenerationSkipsUpdateOnLegacyRecord(t *testing.T, ctx context.Context, fixture ParticipationGenerationFixture) {
t.Helper()
if err := fixture.SetFlag(ctx, false); err != nil {
t.Fatalf("disabling versioned history: %v", err)
}
id := fixture.IssuePrefix + "-legacy-skip"
if err := fixture.Mutate(ctx, id); err != nil {
t.Fatalf("mutating %s: %v", id, err)
}
if gen, err := fixture.ParticipationGeneration(ctx, id); err != nil {
t.Fatalf("reading participation_generation for %s: %v", id, err)
} else if gen != nil {
t.Fatalf("participation_generation for %s = %d before the flag was ever turned on, want NULL — "+
"this case cannot test the legacy-record fence against a record that was never actually legacy",
id, *gen)
}
if err := fixture.SetFlag(ctx, true); err != nil {
t.Fatalf("enabling versioned history: %v", err)
}
beforeRevision, err := fixture.CurrentRevision(ctx, id)
if err != nil {
t.Fatalf("reading current_revision for %s: %v", id, err)
}
beforeCount, err := fixture.VersionRowCount(ctx, id)
if err != nil {
t.Fatalf("counting version rows for %s: %v", id, err)
}
if err := fixture.MutateExisting(ctx, id); err != nil {
t.Fatalf("mutating existing %s: %v", id, err)
}
afterRevision, err := fixture.CurrentRevision(ctx, id)
if err != nil {
t.Fatalf("reading current_revision for %s: %v", id, err)
}
afterCount, err := fixture.VersionRowCount(ctx, id)
if err != nil {
t.Fatalf("counting version rows for %s: %v", id, err)
}
if afterCount != beforeCount {
t.Errorf("version row count for %s went from %d to %d across an update-shaped mutation on a "+
"legacy (participation_generation IS NULL) record with the flag now on, want unchanged: "+
"design §16.2b requires the writer to skip minting for a record it has not positively "+
"promoted", id, beforeCount, afterCount)
}
if afterRevision != beforeRevision {
t.Errorf("current_revision for %s went from %d to %d across the same skipped mutation, want "+
"unchanged: a skip means neither half of RecordVersionInTx's write runs, not just the "+
"version-row half", id, beforeRevision, afterRevision)
}
}
// RunParticipationGenerationProceedsForPromotedRecord is the fence's
// not-vacuous check: an update-shaped mutation against a record whose
// participation_generation is ALREADY stamped (created with the flag on,
// i.e. positively declared, not legacy) must mint normally. Without this
// case, an implementation that skips every update unconditionally would
// still pass RunParticipationGenerationSkipsUpdateOnLegacyRecord.
func RunParticipationGenerationProceedsForPromotedRecord(t *testing.T, ctx context.Context, fixture ParticipationGenerationFixture) {
t.Helper()
if err := fixture.SetFlag(ctx, true); err != nil {
t.Fatalf("enabling versioned history: %v", err)
}
id := fixture.IssuePrefix + "-promoted-proceeds"
if err := fixture.Mutate(ctx, id); err != nil {
t.Fatalf("mutating %s: %v", id, err)
}
if gen, err := fixture.ParticipationGeneration(ctx, id); err != nil {
t.Fatalf("reading participation_generation for %s: %v", id, err)
} else if gen == nil {
t.Fatalf("participation_generation for %s is NULL immediately after a create with the flag on — "+
"this case cannot test the promoted-record path against a record that was never actually "+
"promoted", id)
}
beforeCount, err := fixture.VersionRowCount(ctx, id)
if err != nil {
t.Fatalf("counting version rows for %s: %v", id, err)
}
if err := fixture.MutateExisting(ctx, id); err != nil {
t.Fatalf("mutating existing %s: %v", id, err)
}
afterCount, err := fixture.VersionRowCount(ctx, id)
if err != nil {
t.Fatalf("counting version rows for %s: %v", id, err)
}
if afterCount != beforeCount+1 {
t.Errorf("version row count for %s went from %d to %d across an update-shaped mutation on an "+
"already-promoted record, want exactly +1: the fence must skip only a legacy (NULL) record, "+
"not every update (design §16.2b)", id, beforeCount, afterCount)
}
}
// RunParticipationGenerationFlagOffSkipsUpdateOnParticipatingRecord pins the
// switch's off half for a record the fence would let through: created with
// the flag on (so participation_generation is stamped), then updated after
// the flag is turned back off, it must mint nothing. ProceedsForPromotedRecord
// shows the fence passes such a record, so only the flag stands between this
// update and a mint. No other case can see a writer that ignores the flag on
// updates: every other flag-off record is legacy, and the fence stops those
// first.
func RunParticipationGenerationFlagOffSkipsUpdateOnParticipatingRecord(t *testing.T, ctx context.Context, fixture ParticipationGenerationFixture) {
t.Helper()
if err := fixture.SetFlag(ctx, true); err != nil {
t.Fatalf("enabling versioned history: %v", err)
}
id := fixture.IssuePrefix + "-flag-off-skip"
if err := fixture.Mutate(ctx, id); err != nil {
t.Fatalf("mutating %s: %v", id, err)
}
if gen, err := fixture.ParticipationGeneration(ctx, id); err != nil {
t.Fatalf("reading participation_generation for %s: %v", id, err)
} else if gen == nil {
t.Fatalf("participation_generation for %s is NULL immediately after a create with the flag on — "+
"this case cannot test the flag against a record the fence would have stopped anyway", id)
}
if err := fixture.SetFlag(ctx, false); err != nil {
t.Fatalf("disabling versioned history: %v", err)
}
beforeRevision, err := fixture.CurrentRevision(ctx, id)
if err != nil {
t.Fatalf("reading current_revision for %s: %v", id, err)
}
beforeCount, err := fixture.VersionRowCount(ctx, id)
if err != nil {
t.Fatalf("counting version rows for %s: %v", id, err)
}
if err := fixture.MutateExisting(ctx, id); err != nil {
t.Fatalf("mutating existing %s: %v", id, err)
}
afterRevision, err := fixture.CurrentRevision(ctx, id)
if err != nil {
t.Fatalf("reading current_revision for %s: %v", id, err)
}
afterCount, err := fixture.VersionRowCount(ctx, id)
if err != nil {
t.Fatalf("counting version rows for %s: %v", id, err)
}
if afterCount != beforeCount {
t.Errorf("version row count for %s went from %d to %d across an update-shaped mutation with the "+
"flag off, want unchanged: turning versioned history off stops minting for every record, "+
"including one that already participates", id, beforeCount, afterCount)
}
if afterRevision != beforeRevision {
t.Errorf("current_revision for %s went from %d to %d across the same update with the flag off, "+
"want unchanged", id, beforeRevision, afterRevision)
}
}
// RunParticipationGenerationWispPromotionBeginsHistory pins that promoting a
// wisp onto the issues plane is CREATE-shaped in design §16.2b's sense. (This
// is wisp promotion, PromoteFromEphemeral: not R2.3's promotion of a legacy
// record, which is what ProceedsForPromotedRecord's name refers to.) The
// issues row a promotion inserts is brand new on that plane, and the wisp
// behind it was never versioned and never declared participation (FR-8), so
// there is no legacy state to preserve: with the flag on, the promotion stamps
// participation_generation and mints the record's first version, as a create
// there would. Treated as UPDATE-shaped, the fence finds the new row NULL and
// skips, and because nothing stamps the column afterwards every later update
// skips too, so a record created with the flag on is never versioned at all.
func RunParticipationGenerationWispPromotionBeginsHistory(t *testing.T, ctx context.Context, fixture ParticipationGenerationFixture) {
t.Helper()
runWispArrivalBeginsHistory(t, ctx, fixture, "promote", fixture.PromoteWisp)
}
// RunParticipationGenerationWispPersistenceMoveBeginsHistory is
// RunParticipationGenerationWispPromotionBeginsHistory for the other way a
// wisp reaches the issues plane, a persistence-mode update (bd update
// --persistent). It needs its own case because it reaches a different mint
// site than promotion on every leg (see MovePersistent).
func RunParticipationGenerationWispPersistenceMoveBeginsHistory(t *testing.T, ctx context.Context, fixture ParticipationGenerationFixture) {
t.Helper()
runWispArrivalBeginsHistory(t, ctx, fixture, "move-persistent", fixture.MovePersistent)
}
// runWispArrivalBeginsHistory is the body the two wisp-arrival cases share:
// with the flag on, a wisp that arrives on the issues plane through arrive
// carries a stamped participation_generation and exactly one version row,
// and the next update-shaped mutation mints normally.
func runWispArrivalBeginsHistory(t *testing.T, ctx context.Context, fixture ParticipationGenerationFixture, how string, arrive func(context.Context, string) error) {
t.Helper()
if err := fixture.SetFlag(ctx, true); err != nil {
t.Fatalf("enabling versioned history: %v", err)
}
id := fixture.IssuePrefix + "-" + how
if err := fixture.CreateWisp(ctx, id); err != nil {
t.Fatalf("creating wisp %s: %v", id, err)
}
if err := arrive(ctx, id); err != nil {
t.Fatalf("moving wisp %s onto the issues plane (%s): %v", id, how, err)
}
gen, err := fixture.ParticipationGeneration(ctx, id)
if err != nil {
t.Fatalf("reading participation_generation for %s: %v", id, err)
}
if gen == nil {
t.Errorf("participation_generation for %s is NULL after the wisp reached the issues plane (%s) with "+
"the flag on, want a stamped value: the issues row is new, so the arrival is create-shaped "+
"(design §16.2b), and a NULL here leaves the record fenced as legacy for good", id, how)
}
arrivedCount, err := fixture.VersionRowCount(ctx, id)
if err != nil {
t.Fatalf("counting version rows for %s: %v", id, err)
}
if arrivedCount != 1 {
t.Errorf("version row count for %s = %d after the wisp reached the issues plane (%s) with the flag "+
"on, want 1: a wisp is never versioned (FR-8), so the arrival mints the record's first version",
id, arrivedCount, how)
}
if err := fixture.MutateExisting(ctx, id); err != nil {
t.Fatalf("mutating existing %s: %v", id, err)
}
afterCount, err := fixture.VersionRowCount(ctx, id)
if err != nil {
t.Fatalf("counting version rows for %s: %v", id, err)
}
if afterCount != arrivedCount+1 {
t.Errorf("version row count for %s went from %d to %d across an update-shaped mutation after the "+
"wisp reached the issues plane (%s), want exactly +1: a record that arrived with the flag on is "+
"not legacy, so the fence must let its updates mint", id, arrivedCount, afterCount, how)
}
}
// RunParticipationGenerationWispFlagClearMintsNothing pins that the fence
// decides a row's plane by the TABLE that holds it, not by the row's flags.
// bd mol squash clears a wisp root's ephemeral flag in place, so the row
// stays in the wisps table carrying neither Ephemeral nor NoHistory, and a
// plane test read off those flags takes it for an issues-plane row. It is
// not one: a wisps-table row is never versioned (FR-8) and has no issues row
// whose participation_generation the fence could read. So the update must
// succeed and mint nothing. Read off the flags, the fence either aborts the
// whole update looking for an issues row that is not there, or, without the
// fence, mints a stray version for a wisp.
func RunParticipationGenerationWispFlagClearMintsNothing(t *testing.T, ctx context.Context, fixture ParticipationGenerationFixture) {
t.Helper()
runWispTableRowMintsNothing(t, ctx, fixture, "flag-clear", fixture.CreateWisp, fixture.ClearWispFlag)
}
// RunParticipationGenerationWispRootSquashMintsNothing is
// RunParticipationGenerationWispFlagClearMintsNothing in the shape bd mol
// squash actually runs it: the root's close and its flag clear in one
// transaction, so a mint that fails on the cleared row takes the close down
// with it and the squash cannot complete.
func RunParticipationGenerationWispRootSquashMintsNothing(t *testing.T, ctx context.Context, fixture ParticipationGenerationFixture) {
t.Helper()
runWispTableRowMintsNothing(t, ctx, fixture, "squash", fixture.CreateWisp, fixture.SquashWispRoot)
}
// RunParticipationGenerationUnflaggedWispCreateMintsNothing pins the
// create-shaped half of the same rule: a row CREATED in the wisps table
// without either flag (import's "wisp_plane" marker) reaches the
// create-shaped mint, and must come out of it with no error and no version,
// exactly as a flagged wisp does.
func RunParticipationGenerationUnflaggedWispCreateMintsNothing(t *testing.T, ctx context.Context, fixture ParticipationGenerationFixture) {
t.Helper()
runWispTableRowMintsNothing(t, ctx, fixture, "unflagged-create", fixture.CreateUnflaggedWisp)
}
// runWispTableRowMintsNothing is the body the three wisps-table cases share:
// with the flag on, every step succeeds on id, the wisps table still holds id
// afterwards, and id ends with no issue_versions row.
func runWispTableRowMintsNothing(t *testing.T, ctx context.Context, fixture ParticipationGenerationFixture, how string, steps ...func(context.Context, string) error) {
t.Helper()
if err := fixture.SetFlag(ctx, true); err != nil {
t.Fatalf("enabling versioned history: %v", err)
}
id := fixture.IssuePrefix + "-" + how
for i, step := range steps {
if err := step(ctx, id); err != nil {
t.Fatalf("step %d of %s on wisps-table row %s with the flag on: %v — a row the wisps table "+
"holds is never versioned (FR-8), so its mint must be a no-op, not an error that aborts "+
"the mutation", i+1, how, id, err)
}
}
// The precondition, checked after the steps rather than assumed: a step
// that moved the row to the issues table would leave a NULL
// participation_generation there, the update-shaped mint would be fenced
// as legacy, and the zero count below would hold without saying anything
// about a wisps-table row.
if inWisps, err := fixture.InWispsTable(ctx, id); err != nil {
t.Fatalf("checking whether the wisps table holds %s: %v", id, err)
} else if !inWisps {
t.Fatalf("%s is not in the wisps table after %s — this case pins that a wisps-table row mints "+
"nothing, and cannot say so about a row a step moved out of that table", id, how)
}
count, err := fixture.VersionRowCount(ctx, id)
if err != nil {
t.Fatalf("counting version rows for %s: %v", id, err)
}
if count != 0 {
t.Errorf("version row count for wisps-table row %s = %d after %s with the flag on, want 0: a "+
"wisp is never versioned (FR-8), whatever its flags say", id, count, how)
}
}
// RunParticipationGenerationNoHistoryIssueCreateDeclaresParticipation pins
// that a create declares participation for every ISSUES-table row it makes
// with the flag on, a row carrying NoHistory included. Import keeps a
// promoted no-history wisp's durable row on the issues plane with its stray
// no_history=true (bd-r9uce). While the row says no-history it is not
// versioned, so the create mints nothing. But it was created with history
// on, so it is not legacy: once bd update --persistent repairs the flag in
// place (a same-plane normalize, update-shaped by design), the repair and
// every update after it must mint. Left NULL by the create, the column reads
// as legacy to the fence, and the row is never versioned at all.
func RunParticipationGenerationNoHistoryIssueCreateDeclaresParticipation(t *testing.T, ctx context.Context, fixture ParticipationGenerationFixture) {
t.Helper()
if err := fixture.SetFlag(ctx, true); err != nil {
t.Fatalf("enabling versioned history: %v", err)
}
id := fixture.IssuePrefix + "-no-history-create"
if err := fixture.CreateNoHistoryIssue(ctx, id); err != nil {
t.Fatalf("creating no-history issues-plane row %s: %v", id, err)
}
gen, err := fixture.ParticipationGeneration(ctx, id)
if err != nil {
t.Fatalf("reading participation_generation for %s: %v", id, err)
}
if gen == nil {
t.Errorf("participation_generation for %s is NULL after a create with the flag on, want a stamped "+
"value: the row is new on the issues plane, so the create declares participation (design "+
"§16.2b) even though its NoHistory flag keeps it unversioned for now", id)
}
if count, err := fixture.VersionRowCount(ctx, id); err != nil {
t.Fatalf("counting version rows for %s: %v", id, err)
} else if count != 0 {
t.Errorf("version row count for %s = %d after a create carrying NoHistory, want 0: a no-history "+
"row is not versioned while it says so", id, count)
}
if err := fixture.MovePersistent(ctx, id); err != nil {
t.Fatalf("repairing %s to persistent: %v", id, err)
}
repairedCount, err := fixture.VersionRowCount(ctx, id)
if err != nil {
t.Fatalf("counting version rows for %s: %v", id, err)
}
if repairedCount != 1 {
t.Errorf("version row count for %s = %d after the persistent repair, want 1: the row was created "+
"with the flag on, so the fence must let the repair's update-shaped mint through", id, repairedCount)
}
if err := fixture.MutateExisting(ctx, id); err != nil {
t.Fatalf("mutating existing %s: %v", id, err)
}
afterCount, err := fixture.VersionRowCount(ctx, id)
if err != nil {
t.Fatalf("counting version rows for %s: %v", id, err)
}
if afterCount != repairedCount+1 {
t.Errorf("version row count for %s went from %d to %d across an update-shaped mutation after the "+
"repair, want exactly +1", id, repairedCount, afterCount)
}
}
// RunParticipationGenerationLegacyNoHistoryIssueStaysLegacy is
// RunParticipationGenerationNoHistoryIssueCreateDeclaresParticipation's
// negative twin, and pins R2.3: an ordinary write never promotes a legacy
// record. The same no-history issues-table row, created while the flag was
// OFF, is legacy. Only a create-shaped call stamps a flagged row, so once the
// flag is on, an update-shaped mutation must leave participation_generation
// NULL and mint nothing. So must the bd update --persistent repair that then
// clears the flag in place: that repair is update-shaped too (a same-plane
// normalize), so the row it leaves is an ordinary legacy row, still fenced.
func RunParticipationGenerationLegacyNoHistoryIssueStaysLegacy(t *testing.T, ctx context.Context, fixture ParticipationGenerationFixture) {
t.Helper()
if err := fixture.SetFlag(ctx, false); err != nil {
t.Fatalf("disabling versioned history: %v", err)
}
id := fixture.IssuePrefix + "-no-history-legacy"
if err := fixture.CreateNoHistoryIssue(ctx, id); err != nil {
t.Fatalf("creating no-history issues-plane row %s with the flag off: %v", id, err)
}
if gen, err := fixture.ParticipationGeneration(ctx, id); err != nil {
t.Fatalf("reading participation_generation for %s: %v", id, err)
} else if gen != nil {
t.Fatalf("participation_generation for %s = %d before the flag was ever turned on, want NULL — "+
"this case cannot test that a legacy no-history row stays legacy against a row that was never "+
"legacy", id, *gen)
}
if err := fixture.SetFlag(ctx, true); err != nil {
t.Fatalf("enabling versioned history: %v", err)
}
beforeRevision, err := fixture.CurrentRevision(ctx, id)
if err != nil {
t.Fatalf("reading current_revision for %s: %v", id, err)
}
assertStillLegacy := func(after string) {
t.Helper()
if gen, err := fixture.ParticipationGeneration(ctx, id); err != nil {
t.Fatalf("reading participation_generation for %s: %v", id, err)
} else if gen != nil {
t.Errorf("participation_generation for %s = %d after %s with the flag on, want NULL: the row "+
"was created with the flag off, and an update-shaped write must not promote a legacy "+
"record (R2.3), whatever its no-history flag says", id, *gen, after)
}
if count, err := fixture.VersionRowCount(ctx, id); err != nil {
t.Fatalf("counting version rows for %s: %v", id, err)
} else if count != 0 {
t.Errorf("version row count for %s = %d after %s with the flag on, want 0: a legacy row's "+
"update-shaped mint is fenced (design §16.2b)", id, count, after)
}
if revision, err := fixture.CurrentRevision(ctx, id); err != nil {
t.Fatalf("reading current_revision for %s: %v", id, err)
} else if revision != beforeRevision {
t.Errorf("current_revision for %s went from %d to %d after %s, want unchanged: a fenced "+
"mint runs neither half of the seam's write", id, beforeRevision, revision, after)
}
}
if err := fixture.MutateExisting(ctx, id); err != nil {
t.Fatalf("mutating existing %s: %v", id, err)
}
assertStillLegacy("an update-shaped mutation")
if err := fixture.MovePersistent(ctx, id); err != nil {
t.Fatalf("repairing %s to persistent: %v", id, err)
}
assertStillLegacy("the persistent repair")
}
// RunParticipationGenerationFenceIgnoresSchemaSkewHatch pins design §16.2(c):
// BD_IGNORE_SCHEMA_SKEW=1 downgrades CheckForwardDrift's refusal to a warning
// (internal/storage/schema/schema.go), but it must have no effect on this
// fence — the fence keys on the participation_generation column's real data,
// not on the migration cursor the hatch is about, so a write admitted through
// that hatch is still, correctly, skipped when the record is legacy.
func RunParticipationGenerationFenceIgnoresSchemaSkewHatch(t *testing.T, ctx context.Context, fixture ParticipationGenerationFixture) {
t.Helper()
t.Setenv("BD_IGNORE_SCHEMA_SKEW", "1")
if err := fixture.SetFlag(ctx, false); err != nil {
t.Fatalf("disabling versioned history: %v", err)
}
id := fixture.IssuePrefix + "-schema-skew-hatch"
if err := fixture.Mutate(ctx, id); err != nil {
t.Fatalf("mutating %s: %v", id, err)
}
if err := fixture.SetFlag(ctx, true); err != nil {
t.Fatalf("enabling versioned history: %v", err)
}
beforeCount, err := fixture.VersionRowCount(ctx, id)
if err != nil {
t.Fatalf("counting version rows for %s: %v", id, err)
}
if err := fixture.MutateExisting(ctx, id); err != nil {
t.Fatalf("mutating existing %s: %v", id, err)
}
afterCount, err := fixture.VersionRowCount(ctx, id)
if err != nil {
t.Fatalf("counting version rows for %s: %v", id, err)
}
if afterCount != beforeCount {
t.Errorf("version row count for %s went from %d to %d with BD_IGNORE_SCHEMA_SKEW=1 set, want "+
"unchanged: the schema-skew hatch must not bypass the participation_generation fence — they "+
"key on different planes (migration cursor vs. real column data) — so a write admitted "+
"through the hatch against a legacy record must still be skipped", id, beforeCount, afterCount)
}
}

View file

@ -1,837 +0,0 @@
package conformance
import (
"context"
"errors"
"strings"
"testing"
"time"
storeops "github.com/steveyegge/beads/internal/storage/issueops"
"github.com/steveyegge/beads/internal/types"
publicops "github.com/steveyegge/beads/issueops"
)
// This file holds the contract every implementation of publicops.Heartbeater
// must satisfy. Each case asserts what issueops/heartbeater.go PROMISES, cited
// by symbol.
//
// THREE LEGS, ONE BODY. dolt, embedded dolt and the unit-of-work provider all
// reach internal/storage/issueops.ExecuteHeartbeatInTx, so a per-leg failure
// here is a wrapper's failure: a commit the leg added, a hook it fired, a
// refusal that stopped matching errors.Is.
//
// THE QUIET CASE IS THE POINT. A heartbeat is the hottest write in a fleet and
// it is cheap because it writes the lease row and nothing else. Most of what
// RunHeartbeaterChangesNothingOnTheRow asserts is an ABSENCE — no revision, no
// version, no updated_at, no event, no journal entry, no history entry, no
// hook — and each absence is something a plausible wrapper would add.
//
// THE LIVE-CLAIM FENCE IS AN INVARIANT AND A PREDICATE. The RefusesAfter*
// cases hold the invariant: each ends a claim one way and asserts both that
// the lease row is gone and that the holder's next heartbeat is refused. The
// RefusesAnOrphanedLease* cases hold the predicate: a lease row that survives
// on an issue that is no longer claimed by its holder (what a re-arm racing a
// release or close can leave on Dolt) is refused AND deleted, never refreshed.
type HeartbeaterFixture struct {
// IssuePrefix namespaces the ids each assertion seeds, so several of them
// can share one database.
IssuePrefix string
// Heartbeater is the surface under test.
Heartbeater publicops.Heartbeater
// CreateIssue seeds a durable issue in the issues plane.
CreateIssue func(context.Context, *types.Issue, string) error
// CreateWisp seeds an ephemeral issue in the wisps plane. A nil CreateWisp
// SKIPS the wisp case loudly.
CreateWisp func(context.Context, *types.Issue, string) error
// Claimer takes the claim, and with it the lease row, a heartbeat
// refreshes.
Claimer publicops.Claimer
// Lifecycle ends or moves a claim (close, a status move, a hand-doled
// claim) and performs the guarded write the revision case lands.
Lifecycle publicops.Lifecycle
// Releaser gives a claim up for the release case. Nil SKIPS that case.
Releaser publicops.Releaser
// LeaseReclaimer reverts an aged claim for the reclaim case. Nil, or a nil
// Exec, SKIPS that case.
LeaseReclaimer publicops.LeaseReclaimer
// Exec runs raw statements against the backing database: the cases use it
// to age a lease.
Exec func(ctx context.Context, statements []SQLStatement) error
// ExecUncommitted runs raw statements as ANOTHER writer that leaves its
// change uncommitted in the version-controlled working set (a batch-mode
// edit): SQL-committed, no version-control commit. Nil means Exec already
// behaves so.
ExecUncommitted func(ctx context.Context, statements []SQLStatement) error
// QueryScalar runs a single-row query and scans it, so the post-state is
// read RAW rather than through the role being tested.
QueryScalar func(context.Context, string, []any, ...any) error
// CountHistory reports how many version-control entries the fixture's
// branch has. Nil SKIPS that one assertion, loudly, in the quiet case.
CountHistory func(context.Context) (int, error)
// SetJournalEnabled turns on durable journaling, so the quiet case can
// observe that a heartbeat records nothing in bd_events_journal. Nil SKIPS
// that one assertion, loudly.
SetJournalEnabled func(enabled bool)
// SetVersionedHistoryEnabled turns on dual-write issue-version history, so
// the quiet case can observe that a heartbeat records no issue_versions
// row. Nil SKIPS that one assertion, loudly.
SetVersionedHistoryEnabled func(enabled bool)
// HookedHeartbeater is the same role taken off the leg's HOOK-FIRING chain
// (storage.HookFiringStore on the store legs, uow.NewNotifyingProvider on
// the unit-of-work leg), built over the runner FiredUpdates reads. Nil,
// with FiredUpdates, SKIPS the no-hook assertion loudly.
HookedHeartbeater publicops.Heartbeater
// FiredUpdates reports, in firing order, the issue id of every on_update
// the hooked chain ran so far.
FiredUpdates func(context.Context) ([]string, error)
}
const (
heartbeaterHolder = "hb-holder"
heartbeaterIntruder = "hb-intruder"
heartbeaterReaper = "hb-reaper"
)
// RunHeartbeaterRefreshesTheHoldersLease pins the refresh itself
// (Heartbeater: "pushes the lease the caller holds forward by the store's
// TTL") and every member of the HeartbeatResult, against the row READ RAW.
func RunHeartbeaterRefreshesTheHoldersLease(t *testing.T, ctx context.Context, fixture HeartbeaterFixture) {
t.Helper()
requireHeartbeaterExec(t, fixture)
id := fixture.IssuePrefix + "-refresh"
heartbeaterSeedClaimed(t, ctx, fixture, id)
aged := time.Now().UTC().Add(-time.Minute).Truncate(time.Second)
if err := fixture.Exec(ctx, []SQLStatement{{
Query: "UPDATE leases SET lease_expires_at = ?, heartbeat_at = ? WHERE issue_id = ?",
Args: []any{aged, aged, id},
}}); err != nil {
t.Fatalf("age the lease on %s: %v", id, err)
}
before := time.Now().UTC().Add(-time.Second)
result := heartbeat(t, ctx, fixture.Heartbeater, publicops.HeartbeatRequest{Actor: heartbeaterHolder, IssueID: id})
after := time.Now().UTC().Add(time.Second)
if result.IssueID != id || result.Holder != heartbeaterHolder || result.Rearmed {
t.Fatalf("result = %+v, want {IssueID:%s Holder:%s Rearmed:false}", result, id, heartbeaterHolder)
}
if result.HeartbeatAt.Before(before) || result.HeartbeatAt.After(after) {
t.Fatalf("HeartbeatAt = %v, want the server clock at the call (between %v and %v)", result.HeartbeatAt, before, after)
}
if ttl := result.LeaseExpiresAt.Sub(result.HeartbeatAt); heartbeaterAbs(ttl-storeops.DefaultLeaseTTL) > time.Second {
t.Fatalf("LeaseExpiresAt - HeartbeatAt = %v, want the store's lease TTL %v", ttl, storeops.DefaultLeaseTTL)
}
if moved := heartbeaterScalar[int](t, ctx, fixture,
"SELECT COUNT(*) FROM leases WHERE issue_id = ? AND holder = ? AND lease_expires_at > ? AND heartbeat_at > ?",
id, heartbeaterHolder, aged, aged); moved != 1 {
t.Fatal("the lease row's lease_expires_at and heartbeat_at did not move forward")
}
heartbeaterRequireStoredMatches(t, ctx, fixture, id, result, before, after)
}
// RunHeartbeaterASameSecondHeartbeatIsNotARearm pins HeartbeatResult.Rearmed
// against the refresh that changes no value: a heartbeat landing in the same
// second as the claim or the previous heartbeat writes values identical to the
// row's (the lease columns hold whole seconds), which some engines report as
// zero rows affected. It is still a refresh of the caller's own row: Rearmed
// is false, and the lease's granted_at and granted_node do not move.
func RunHeartbeaterASameSecondHeartbeatIsNotARearm(t *testing.T, ctx context.Context, fixture HeartbeaterFixture) {
t.Helper()
requireHeartbeaterExec(t, fixture)
for i := 0; i < 3; i++ {
id := fixture.IssuePrefix + "-samesec-" + string(rune('a'+i))
heartbeaterSeedClaimed(t, ctx, fixture, id)
granted := heartbeaterScalar[string](t, ctx, fixture,
"SELECT CONCAT(CAST(granted_at AS CHAR), '|', COALESCE(granted_node, '')) FROM leases WHERE issue_id = ?", id)
for beat := 0; beat < 2; beat++ {
result := heartbeat(t, ctx, fixture.Heartbeater, publicops.HeartbeatRequest{Actor: heartbeaterHolder, IssueID: id})
if result.Rearmed {
t.Fatalf("heartbeat %d on %s right after the claim = %+v, want Rearmed:false: the holder's lease row existed", beat+1, id, result)
}
}
if got := heartbeaterScalar[string](t, ctx, fixture,
"SELECT CONCAT(CAST(granted_at AS CHAR), '|', COALESCE(granted_node, '')) FROM leases WHERE issue_id = ?", id); got != granted {
t.Fatalf("granted_at|granted_node on %s moved from %s to %s across refreshes; a refresh never re-grants", id, granted, got)
}
}
}
// RunHeartbeaterChangesNothingOnTheRow pins the role's quiet promise
// (Heartbeater: "A REFRESH WRITES ONLY THE LEASE ROW"): the issue row's revision
// (row_lock), its current_revision, its updated_at, its events, the events
// journal, issue_versions, the version-control history and the hooks are all
// exactly where the claim left them.
func RunHeartbeaterChangesNothingOnTheRow(t *testing.T, ctx context.Context, fixture HeartbeaterFixture) {
t.Helper()
requireHeartbeaterExec(t, fixture)
if fixture.SetJournalEnabled != nil {
fixture.SetJournalEnabled(true)
defer fixture.SetJournalEnabled(false)
} else {
t.Log("HeartbeaterFixture.SetJournalEnabled is nil: the journal assertion is skipped on this backend")
}
if fixture.SetVersionedHistoryEnabled != nil {
fixture.SetVersionedHistoryEnabled(true)
defer fixture.SetVersionedHistoryEnabled(false)
} else {
t.Log("HeartbeaterFixture.SetVersionedHistoryEnabled is nil: the issue_versions assertion is skipped on this backend")
}
id := fixture.IssuePrefix + "-quiet"
heartbeaterSeedClaimed(t, ctx, fixture, id)
// updated_at is stored at second precision on some backends; step past
// the claim's second so a stamp the heartbeat added cannot hide in it.
time.Sleep(1100 * time.Millisecond)
snapshot := func() heartbeaterRowSnapshot {
return heartbeaterSnapshot(t, ctx, fixture, id)
}
before := snapshot()
fired := heartbeaterFired(t, ctx, fixture, id)
surface := fixture.Heartbeater
if fixture.HookedHeartbeater != nil && fixture.FiredUpdates != nil {
surface = fixture.HookedHeartbeater
} else {
t.Log("HeartbeaterFixture.HookedHeartbeater/FiredUpdates is nil: the no-hook assertion is skipped on this backend")
}
heartbeat(t, ctx, surface, publicops.HeartbeatRequest{Actor: heartbeaterHolder, IssueID: id})
after := snapshot()
if before != after {
t.Fatalf("a heartbeat changed the issue's durable state:\nbefore %+v\nafter %+v", before, after)
}
if got := heartbeaterFired(t, ctx, fixture, id); got != fired {
t.Fatalf("on_update fired %d time(s) for %s across a refresh, want 0: a refresh fires no hook", got-fired, id)
}
}
// RunHeartbeaterAGuardedWriteWithThePreHeartbeatRevisionStillWins is the
// reason the quiet case matters to a caller: the holder's revision token
// survives its own heartbeats, so a guarded write it composed from the claim
// still lands.
func RunHeartbeaterAGuardedWriteWithThePreHeartbeatRevisionStillWins(t *testing.T, ctx context.Context, fixture HeartbeaterFixture) {
t.Helper()
if fixture.Lifecycle == nil {
t.Skip("HeartbeaterFixture.Lifecycle is nil: this backend cannot land a guarded write")
}
id := fixture.IssuePrefix + "-guarded"
revision := heartbeaterSeedClaimed(t, ctx, fixture, id)
heartbeat(t, ctx, fixture.Heartbeater, publicops.HeartbeatRequest{Actor: heartbeaterHolder, IssueID: id})
heartbeat(t, ctx, fixture.Heartbeater, publicops.HeartbeatRequest{Actor: heartbeaterHolder, IssueID: id})
if _, err := fixture.Lifecycle.Update(ctx, publicops.UpdateRequest{
Actor: heartbeaterHolder, IssueID: id, ExpectedVersion: &revision,
Patch: publicops.IssuePatch{Notes: publicops.Field[string]{Set: true, Value: "after two heartbeats"}},
}); err != nil {
t.Fatalf("guarded write with the claim's revision after heartbeats = %v, want it to land", err)
}
}
// RunHeartbeaterRefusesAForeignHolder pins the fence (Heartbeater REFUSALS:
// "an issue another actor holds: a *LeaseConflictError naming the Holder,
// wrapping ErrAlreadyClaimed"), and that the refusal writes nothing.
func RunHeartbeaterRefusesAForeignHolder(t *testing.T, ctx context.Context, fixture HeartbeaterFixture) {
t.Helper()
requireHeartbeaterExec(t, fixture)
id := fixture.IssuePrefix + "-foreign"
heartbeaterSeedClaimed(t, ctx, fixture, id)
// Age the holder's lease first, so a heartbeat that ignored the holder
// fence would really CHANGE the row (some engines count only changed rows,
// and the columns hold whole seconds: an unaged row refreshed in the
// claim's second changes nothing and would hide the missing fence).
aged := time.Now().UTC().Add(-time.Minute).Truncate(time.Second)
if err := fixture.Exec(ctx, []SQLStatement{{
Query: "UPDATE leases SET lease_expires_at = ?, heartbeat_at = ? WHERE issue_id = ?",
Args: []any{aged, aged, id},
}}); err != nil {
t.Fatalf("age the lease on %s: %v", id, err)
}
lease := heartbeaterScalar[string](t, ctx, fixture, "SELECT CONCAT(CAST(lease_expires_at AS CHAR), '|', CAST(heartbeat_at AS CHAR), '|', holder) FROM leases WHERE issue_id = ?", id)
_, err := fixture.Heartbeater.Heartbeat(ctx, publicops.HeartbeatRequest{Actor: heartbeaterIntruder, IssueID: id})
if !errors.Is(err, publicops.ErrAlreadyClaimed) {
t.Fatalf("heartbeat by a non-holder = %v, want ErrAlreadyClaimed", err)
}
if errors.Is(err, publicops.ErrLeaseNotHeld) {
t.Fatalf("heartbeat by a non-holder = %v also matches ErrLeaseNotHeld; the two refusals must stay distinct", err)
}
conflict := heartbeaterConflict(t, err)
if conflict.IssueID != id || conflict.Holder != heartbeaterHolder || conflict.Status != types.StatusInProgress {
t.Fatalf("LeaseConflictError = %+v, want {IssueID:%s Holder:%s Status:%s}", conflict, id, heartbeaterHolder, types.StatusInProgress)
}
if got := heartbeaterScalar[string](t, ctx, fixture, "SELECT CONCAT(CAST(lease_expires_at AS CHAR), '|', CAST(heartbeat_at AS CHAR), '|', holder) FROM leases WHERE issue_id = ?", id); got != lease {
t.Fatalf("a refused heartbeat moved the holder's lease from %s to %s", lease, got)
}
}
// RunHeartbeaterCommitsOnlyItsOwnTables pins the commit discipline against a
// DIRTY working set (Heartbeater: "A REFRESH WRITES ONLY THE LEASE ROW"; "A
// RE-ARM IS RECORDED AS A MUTATION"): another writer has left an uncommitted
// versioned change (a batch-mode edit, here a config row). A refresh and a
// refusal make no version-control commit and leave that change uncommitted;
// a re-arm makes exactly one commit, of its own tables, and still leaves the
// other writer's change uncommitted rather than sweeping it in under the
// heartbeat's message.
func RunHeartbeaterCommitsOnlyItsOwnTables(t *testing.T, ctx context.Context, fixture HeartbeaterFixture) {
t.Helper()
requireHeartbeaterExec(t, fixture)
if fixture.CountHistory == nil || fixture.Lifecycle == nil {
t.Skip("HeartbeaterFixture.CountHistory/Lifecycle is nil: this backend has no version-control history to observe")
}
refreshed := fixture.IssuePrefix + "-dirty-refresh"
heartbeaterSeedClaimed(t, ctx, fixture, refreshed)
refused := fixture.IssuePrefix + "-dirty-refused"
heartbeaterSeed(t, ctx, fixture, refused)
rearmed := fixture.IssuePrefix + "-dirty-rearm"
heartbeaterSeed(t, ctx, fixture, rearmed)
if _, err := fixture.Lifecycle.Update(ctx, publicops.UpdateRequest{
Actor: heartbeaterHolder, IssueID: rearmed,
Patch: publicops.IssuePatch{
Status: publicops.Field[publicops.Status]{Set: true, Value: types.StatusInProgress},
Assignee: publicops.Field[string]{Set: true, Value: heartbeaterHolder},
},
}); err != nil {
t.Fatalf("hand-dole %s: %v", rearmed, err)
}
probe := "heartbeat.dirty-probe." + fixture.IssuePrefix
dirty := fixture.Exec
if fixture.ExecUncommitted != nil {
dirty = fixture.ExecUncommitted
}
if err := dirty(ctx, []SQLStatement{{
Query: "REPLACE INTO config (`key`, value) VALUES (?, ?)", Args: []any{probe, "uncommitted"},
}}); err != nil {
t.Fatalf("dirty the working set: %v", err)
}
defer func() {
_ = dirty(ctx, []SQLStatement{{Query: "DELETE FROM config WHERE `key` = ?", Args: []any{probe}}})
}()
foreignDirty := func(when string) {
t.Helper()
if n := heartbeaterScalar[int](t, ctx, fixture,
"SELECT COUNT(*) FROM dolt_status WHERE table_name = 'config'"); n == 0 {
t.Fatalf("%s: the other writer's uncommitted config change was committed; a heartbeat commits only its own tables", when)
}
}
history := func() int {
t.Helper()
n, err := fixture.CountHistory(ctx)
if err != nil {
t.Fatalf("CountHistory: %v", err)
}
return n
}
foreignDirty("before any heartbeat")
before := history()
heartbeat(t, ctx, fixture.Heartbeater, publicops.HeartbeatRequest{Actor: heartbeaterHolder, IssueID: refreshed})
if got := history(); got != before {
t.Fatalf("a refresh moved the version-control history %d -> %d; a refresh makes no commit", before, got)
}
foreignDirty("after a refresh")
if _, err := fixture.Heartbeater.Heartbeat(ctx, publicops.HeartbeatRequest{Actor: heartbeaterHolder, IssueID: refused}); err == nil {
t.Fatalf("heartbeat on unclaimed %s succeeded, want a refusal", refused)
}
if got := history(); got != before {
t.Fatalf("a refusal moved the version-control history %d -> %d; a refusal makes no commit", before, got)
}
foreignDirty("after a refusal")
if result := heartbeat(t, ctx, fixture.Heartbeater, publicops.HeartbeatRequest{Actor: heartbeaterHolder, IssueID: rearmed}); !result.Rearmed {
t.Fatalf("heartbeat on hand-doled %s = %+v, want Rearmed", rearmed, result)
}
if got := history(); got != before+1 {
t.Fatalf("a re-arm moved the version-control history %d -> %d, want exactly one commit", before, got)
}
foreignDirty("after a re-arm")
}
// RunHeartbeaterRefusesAnOrphanedLeaseOnAReleasedIssue and
// ...OnAClosedIssue and ...OnAnIssueSomeoneElseHolds pin the live-claim
// predicate (Heartbeater: "THE LIVE-CLAIM FENCE IS A PREDICATE"): a lease row
// that names the caller but survives on an issue that is open, closed, or
// in_progress under another assignee is refused, never refreshed, and the
// refusal deletes it (Heartbeater: the one write a refusal makes). The row
// is planted raw: it is the state a re-arm racing a release or close leaves.
func RunHeartbeaterRefusesAnOrphanedLeaseOnAReleasedIssue(t *testing.T, ctx context.Context, fixture HeartbeaterFixture) {
t.Helper()
requireHeartbeaterExec(t, fixture)
id := fixture.IssuePrefix + "-orphan-open"
heartbeaterSeed(t, ctx, fixture, id)
heartbeaterRefusesAnOrphan(t, ctx, fixture, id, types.StatusOpen, "")
}
func RunHeartbeaterRefusesAnOrphanedLeaseOnAClosedIssue(t *testing.T, ctx context.Context, fixture HeartbeaterFixture) {
t.Helper()
requireHeartbeaterExec(t, fixture)
if fixture.Lifecycle == nil {
t.Skip("HeartbeaterFixture.Lifecycle is nil: this backend cannot close the claim")
}
id := fixture.IssuePrefix + "-orphan-closed"
heartbeaterSeedClaimed(t, ctx, fixture, id)
if _, err := fixture.Lifecycle.Close(ctx, publicops.CloseRequest{Actor: heartbeaterHolder, IssueID: id, Reason: "done"}); err != nil {
t.Fatalf("close %s: %v", id, err)
}
heartbeaterRefusesAnOrphan(t, ctx, fixture, id, types.StatusClosed, "")
}
func RunHeartbeaterRefusesAnOrphanedLeaseOnAnIssueSomeoneElseHolds(t *testing.T, ctx context.Context, fixture HeartbeaterFixture) {
t.Helper()
requireHeartbeaterExec(t, fixture)
if fixture.Lifecycle == nil {
t.Skip("HeartbeaterFixture.Lifecycle is nil: this backend cannot hand-dole a claim")
}
id := fixture.IssuePrefix + "-orphan-moved"
heartbeaterSeed(t, ctx, fixture, id)
if _, err := fixture.Lifecycle.Update(ctx, publicops.UpdateRequest{
Actor: heartbeaterIntruder, IssueID: id,
Patch: publicops.IssuePatch{
Status: publicops.Field[publicops.Status]{Set: true, Value: types.StatusInProgress},
Assignee: publicops.Field[string]{Set: true, Value: heartbeaterIntruder},
},
}); err != nil {
t.Fatalf("hand-dole %s to %s: %v", id, heartbeaterIntruder, err)
}
heartbeaterRefusesAnOrphan(t, ctx, fixture, id, types.StatusInProgress, heartbeaterIntruder)
}
// heartbeaterRefusesAnOrphan plants a lease row for heartbeaterHolder on id
// (which the holder does not hold), heartbeats as the holder, and asserts the
// refusal and that the row is gone.
func heartbeaterRefusesAnOrphan(t *testing.T, ctx context.Context, fixture HeartbeaterFixture, id string, status types.Status, foreign string) {
t.Helper()
now := time.Now().UTC().Truncate(time.Second)
if err := fixture.Exec(ctx, []SQLStatement{
{Query: "DELETE FROM leases WHERE issue_id = ?", Args: []any{id}},
{
Query: "INSERT INTO leases (issue_id, holder, granted_at, lease_expires_at, heartbeat_at, granted_node) VALUES (?, ?, ?, ?, ?, '')",
Args: []any{id, heartbeaterHolder, now.Add(-time.Minute), now.Add(time.Hour), now.Add(-time.Minute)},
},
}); err != nil {
t.Fatalf("plant an orphaned lease on %s: %v", id, err)
}
_, err := fixture.Heartbeater.Heartbeat(ctx, publicops.HeartbeatRequest{Actor: heartbeaterHolder, IssueID: id})
conflict := heartbeaterConflict(t, err)
if foreign != "" {
if !errors.Is(err, publicops.ErrAlreadyClaimed) || conflict.Holder != foreign {
t.Fatalf("heartbeat over an orphaned lease on an issue %s holds = %v (%+v), want ErrAlreadyClaimed naming %s", foreign, err, conflict, foreign)
}
} else if !errors.Is(err, publicops.ErrLeaseNotHeld) || conflict.Holder != "" {
t.Fatalf("heartbeat over an orphaned lease on a %s issue = %v (%+v), want ErrLeaseNotHeld", status, err, conflict)
}
if conflict.IssueID != id || conflict.Status != status || conflict.Ephemeral {
t.Fatalf("LeaseConflictError = %+v, want {IssueID:%s Status:%s Ephemeral:false}", conflict, id, status)
}
if n := heartbeaterScalar[int](t, ctx, fixture, "SELECT COUNT(*) FROM leases WHERE issue_id = ?", id); n != 0 {
t.Fatalf("lease rows on %s after the refusal = %d, want 0: a refusal deletes the caller's orphaned lease", id, n)
}
// And it stays refused: the next heartbeat finds no row to refresh.
if _, err := fixture.Heartbeater.Heartbeat(ctx, publicops.HeartbeatRequest{Actor: heartbeaterHolder, IssueID: id}); err == nil {
t.Fatalf("a second heartbeat on %s succeeded after the orphan was refused", id)
}
}
// heartbeaterRequireStoredMatches pins the reported times to the stored row
// (LeaseRenewal: "exactly what the lease row now holds"): lease_expires_at and
// heartbeat_at as stored are the result's, within the columns' one-second
// precision, and the stored expiry is the call's clock plus the store's TTL.
func heartbeaterRequireStoredMatches(t *testing.T, ctx context.Context, fixture HeartbeaterFixture, id string, result publicops.HeartbeatResult, before, after time.Time) {
t.Helper()
window := func(at time.Time) (time.Time, time.Time) { return at.Add(-time.Second), at.Add(time.Second) }
hbLo, hbHi := window(result.HeartbeatAt)
exLo, exHi := window(result.LeaseExpiresAt)
if n := heartbeaterScalar[int](t, ctx, fixture,
"SELECT COUNT(*) FROM leases WHERE issue_id = ? AND holder = ? AND heartbeat_at BETWEEN ? AND ? AND lease_expires_at BETWEEN ? AND ?",
id, result.Holder, hbLo, hbHi, exLo, exHi); n != 1 {
t.Fatalf("the stored lease row on %s does not hold the reported heartbeat_at %v and lease_expires_at %v (within 1s)",
id, result.HeartbeatAt, result.LeaseExpiresAt)
}
ttlLo, ttlHi := before.Add(storeops.DefaultLeaseTTL), after.Add(storeops.DefaultLeaseTTL)
if n := heartbeaterScalar[int](t, ctx, fixture,
"SELECT COUNT(*) FROM leases WHERE issue_id = ? AND lease_expires_at BETWEEN ? AND ?",
id, ttlLo, ttlHi); n != 1 {
t.Fatalf("the stored lease_expires_at on %s is not the call's clock plus the lease TTL %v", id, storeops.DefaultLeaseTTL)
}
if !result.HeartbeatAt.Equal(result.HeartbeatAt.Truncate(time.Second)) || !result.LeaseExpiresAt.Equal(result.LeaseExpiresAt.Truncate(time.Second)) {
t.Fatalf("result times %v / %v carry sub-second digits the lease columns cannot hold", result.HeartbeatAt, result.LeaseExpiresAt)
}
}
// RunHeartbeaterRefusesAfterClose, ...AfterRelease, ...AfterReclaim and
// ...AfterStatusMovedOffInProgress pin the in_progress fence through the
// lease-row invariant (Heartbeater: "a lease row exists only while its issue
// is in_progress with that holder as assignee"): each ends the claim one way,
// asserts the lease row went with it, and that the former holder's heartbeat
// is refused with ErrLeaseNotHeld, which also matches ErrNotClaimable.
func RunHeartbeaterRefusesAfterClose(t *testing.T, ctx context.Context, fixture HeartbeaterFixture) {
t.Helper()
if fixture.Lifecycle == nil {
t.Skip("HeartbeaterFixture.Lifecycle is nil: this backend cannot close the claim")
}
heartbeaterRefusesAfter(t, ctx, fixture, "closed", types.StatusClosed, func(id string) error {
_, err := fixture.Lifecycle.Close(ctx, publicops.CloseRequest{Actor: heartbeaterHolder, IssueID: id, Reason: "done"})
return err
})
}
func RunHeartbeaterRefusesAfterRelease(t *testing.T, ctx context.Context, fixture HeartbeaterFixture) {
t.Helper()
if fixture.Releaser == nil {
t.Skip("HeartbeaterFixture.Releaser is nil: this backend cannot release the claim")
}
heartbeaterRefusesAfter(t, ctx, fixture, "released", types.StatusOpen, func(id string) error {
_, err := fixture.Releaser.Release(ctx, publicops.ReleaseRequest{Actor: heartbeaterHolder, IssueID: id})
return err
})
}
func RunHeartbeaterRefusesAfterReclaim(t *testing.T, ctx context.Context, fixture HeartbeaterFixture) {
t.Helper()
if fixture.LeaseReclaimer == nil || fixture.Exec == nil {
t.Skip("HeartbeaterFixture.LeaseReclaimer/Exec is nil: this backend cannot reclaim the claim")
}
heartbeaterRefusesAfter(t, ctx, fixture, "reclaimed", types.StatusOpen, func(id string) error {
if err := fixture.Exec(ctx, []SQLStatement{{
Query: "UPDATE leases SET lease_expires_at = ? WHERE issue_id = ?",
Args: []any{time.Now().UTC().Add(-time.Hour), id},
}}); err != nil {
return err
}
result, err := fixture.LeaseReclaimer.Reclaim(ctx, publicops.ReclaimRequest{
Actor: heartbeaterReaper, Filter: publicops.ReclaimFilter{IDs: []string{id}},
})
if err == nil && len(result.Reclaimed) != 1 {
t.Fatalf("Reclaimed = %+v, want exactly %s", result.Reclaimed, id)
}
return err
})
}
func RunHeartbeaterRefusesAfterStatusMovedOffInProgress(t *testing.T, ctx context.Context, fixture HeartbeaterFixture) {
t.Helper()
if fixture.Lifecycle == nil {
t.Skip("HeartbeaterFixture.Lifecycle is nil: this backend cannot move the status")
}
heartbeaterRefusesAfter(t, ctx, fixture, "blocked", types.StatusBlocked, func(id string) error {
_, err := fixture.Lifecycle.Update(ctx, publicops.UpdateRequest{
Actor: heartbeaterHolder, IssueID: id,
Patch: publicops.IssuePatch{Status: publicops.Field[publicops.Status]{Set: true, Value: types.StatusBlocked}},
})
return err
})
}
// RunHeartbeaterRefusesAWisp pins the plane rule (Heartbeater REFUSALS: "a
// wisp ... ErrLeaseNotHeld"): wisps are never leased, so even a wisp the
// caller holds in_progress is refused, and no lease row appears for it.
func RunHeartbeaterRefusesAWisp(t *testing.T, ctx context.Context, fixture HeartbeaterFixture) {
t.Helper()
if fixture.CreateWisp == nil || fixture.QueryScalar == nil {
t.Skip("HeartbeaterFixture.CreateWisp/QueryScalar is nil: this backend cannot seed a wisp")
}
id := fixture.IssuePrefix + "-wisp"
if err := fixture.CreateWisp(ctx, &types.Issue{
ID: id, Title: id, Status: types.StatusInProgress, Assignee: heartbeaterHolder,
Priority: 2, IssueType: types.TypeTask, Ephemeral: true,
}, "seed"); err != nil {
t.Fatalf("seed wisp %s: %v", id, err)
}
_, err := fixture.Heartbeater.Heartbeat(ctx, publicops.HeartbeatRequest{Actor: heartbeaterHolder, IssueID: id})
if !errors.Is(err, publicops.ErrLeaseNotHeld) || !errors.Is(err, publicops.ErrNotClaimable) {
t.Fatalf("heartbeat on a wisp = %v, want ErrLeaseNotHeld matching ErrNotClaimable", err)
}
if !strings.Contains(err.Error(), "ephemeral") {
t.Fatalf("heartbeat on a wisp = %q, want the refusal to say the issue is ephemeral", err)
}
if conflict := heartbeaterConflict(t, err); conflict.IssueID != id || conflict.Holder != "" {
t.Fatalf("LeaseConflictError = %+v, want {IssueID:%s Holder:\"\"}", conflict, id)
}
if n := heartbeaterScalar[int](t, ctx, fixture, "SELECT COUNT(*) FROM leases WHERE issue_id = ?", id); n != 0 {
t.Fatalf("lease rows for wisp %s = %d, want 0: wisps are never leased", id, n)
}
}
// RunHeartbeaterRearmsAHandDoledClaim pins the self-heal (HeartbeatResult.
// Rearmed): an issue put in_progress with the caller as assignee by a generic
// update holds no lease row, and the holder's heartbeat grants one rather than
// refusing. The re-arm is recorded as a mutation (Heartbeater: "A RE-ARM IS
// RECORDED AS A MUTATION"): it remints the revision, which is what makes it
// collide with a racing release or close, and records a lease_rearmed event;
// the refresh after it does neither.
func RunHeartbeaterRearmsAHandDoledClaim(t *testing.T, ctx context.Context, fixture HeartbeaterFixture) {
t.Helper()
if fixture.Lifecycle == nil || fixture.QueryScalar == nil {
t.Skip("HeartbeaterFixture.Lifecycle/QueryScalar is nil: this backend cannot hand-dole a claim")
}
id := fixture.IssuePrefix + "-doled"
heartbeaterSeed(t, ctx, fixture, id)
if _, err := fixture.Lifecycle.Update(ctx, publicops.UpdateRequest{
Actor: heartbeaterHolder, IssueID: id,
Patch: publicops.IssuePatch{
Status: publicops.Field[publicops.Status]{Set: true, Value: types.StatusInProgress},
Assignee: publicops.Field[string]{Set: true, Value: heartbeaterHolder},
},
}); err != nil {
t.Fatalf("hand-dole %s: %v", id, err)
}
if n := heartbeaterScalar[int](t, ctx, fixture, "SELECT COUNT(*) FROM leases WHERE issue_id = ?", id); n != 0 {
t.Fatalf("lease rows after a generic update = %d, want 0: the case needs a claim with no lease", n)
}
revision := heartbeaterScalar[int64](t, ctx, fixture, "SELECT row_lock FROM issues WHERE id = ?", id)
before := time.Now().UTC().Add(-time.Second)
result := heartbeat(t, ctx, fixture.Heartbeater, publicops.HeartbeatRequest{Actor: heartbeaterHolder, IssueID: id})
after := time.Now().UTC().Add(time.Second)
if !result.Rearmed || result.Holder != heartbeaterHolder {
t.Fatalf("result = %+v, want Rearmed:true Holder:%s", result, heartbeaterHolder)
}
heartbeaterRequireStoredMatches(t, ctx, fixture, id, result, before, after)
if n := heartbeaterScalar[int](t, ctx, fixture,
"SELECT COUNT(*) FROM leases WHERE issue_id = ? AND holder = ? AND lease_expires_at > ?",
id, heartbeaterHolder, time.Now().UTC()); n != 1 {
t.Fatal("the re-armed heartbeat left no live lease row for the holder")
}
rearmed := heartbeaterScalar[int64](t, ctx, fixture, "SELECT row_lock FROM issues WHERE id = ?", id)
if rearmed == revision {
t.Fatalf("row_lock stayed %d across a re-arming heartbeat; a re-arm remints it so a racing release or close collides with it", revision)
}
rearmEvents := func() int {
return heartbeaterScalar[int](t, ctx, fixture,
"SELECT COUNT(*) FROM events WHERE issue_id = ? AND event_type = ?", id, string(types.EventLeaseRearmed))
}
if n := rearmEvents(); n != 1 {
t.Fatalf("lease_rearmed events on %s after a re-arm = %d, want 1: a re-arm is recorded as a mutation", id, n)
}
// The next heartbeat refreshes the lease it just granted: no re-arm, and
// no revision change.
if again := heartbeat(t, ctx, fixture.Heartbeater, publicops.HeartbeatRequest{Actor: heartbeaterHolder, IssueID: id}); again.Rearmed {
t.Fatalf("second heartbeat after the re-arm = %+v, want Rearmed:false", again)
}
if got := heartbeaterScalar[int64](t, ctx, fixture, "SELECT row_lock FROM issues WHERE id = ?", id); got != rearmed {
t.Fatalf("row_lock moved from %d to %d across a refresh after the re-arm", rearmed, got)
}
if n := rearmEvents(); n != 1 {
t.Fatalf("lease_rearmed events on %s after a refresh = %d, want still 1: a refresh records nothing", id, n)
}
}
// RunHeartbeaterAnswersNotFoundForAnAbsentID pins Heartbeater REFUSALS: "an
// IssueID that names no row on either plane: ErrNotFound".
func RunHeartbeaterAnswersNotFoundForAnAbsentID(t *testing.T, ctx context.Context, fixture HeartbeaterFixture) {
t.Helper()
_, err := fixture.Heartbeater.Heartbeat(ctx, publicops.HeartbeatRequest{
Actor: heartbeaterHolder, IssueID: fixture.IssuePrefix + "-absent",
})
if !errors.Is(err, publicops.ErrNotFound) {
t.Fatalf("heartbeat on an absent id = %v, want ErrNotFound", err)
}
}
// RunHeartbeaterRefusesABlankOrOverLongActor pins the request rules
// (HeartbeatRequest.Actor, Heartbeater REFUSALS): each is a
// *HeartbeatFieldError naming its field, matching ErrValidation.
func RunHeartbeaterRefusesABlankOrOverLongActor(t *testing.T, ctx context.Context, fixture HeartbeaterFixture) {
t.Helper()
id := fixture.IssuePrefix + "-refusals"
for _, test := range []struct {
name string
request publicops.HeartbeatRequest
field string
}{
{"an empty actor", publicops.HeartbeatRequest{IssueID: id}, publicops.HeartbeatFieldActor},
{"a blank actor", publicops.HeartbeatRequest{Actor: " \t", IssueID: id}, publicops.HeartbeatFieldActor},
{"an over-long actor", publicops.HeartbeatRequest{Actor: strings.Repeat("a", types.MaxFieldLen+1), IssueID: id}, publicops.HeartbeatFieldActor},
{"an empty id", publicops.HeartbeatRequest{Actor: heartbeaterHolder}, publicops.HeartbeatFieldIssueID},
} {
t.Run(test.name, func(t *testing.T) {
_, err := fixture.Heartbeater.Heartbeat(ctx, test.request)
if !errors.Is(err, publicops.ErrValidation) {
t.Fatalf("Heartbeat(%s) = %v, want ErrValidation", test.name, err)
}
var field *publicops.HeartbeatFieldError
if !errors.As(err, &field) || field.Field != test.field {
t.Fatalf("Heartbeat(%s) = %v, want a *HeartbeatFieldError naming %q", test.name, err, test.field)
}
})
}
}
// RunHeartbeaterDoesNotMutateTheRequest pins the role's "never mutate
// caller-owned request values".
func RunHeartbeaterDoesNotMutateTheRequest(t *testing.T, ctx context.Context, fixture HeartbeaterFixture) {
t.Helper()
id := fixture.IssuePrefix + "-nomutate"
heartbeaterSeedClaimed(t, ctx, fixture, id)
request := publicops.HeartbeatRequest{Actor: heartbeaterHolder, IssueID: id}
want := request
heartbeat(t, ctx, fixture.Heartbeater, request)
if request != want {
t.Fatalf("request after Heartbeat = %+v, want %+v", request, want)
}
}
// heartbeaterRefusesAfter seeds and claims one issue, ends the claim with end,
// and asserts the invariant and the refusal.
func heartbeaterRefusesAfter(t *testing.T, ctx context.Context, fixture HeartbeaterFixture, suffix string, status types.Status, end func(id string) error) {
t.Helper()
if fixture.QueryScalar == nil {
t.Skip("HeartbeaterFixture.QueryScalar is nil: this backend cannot read the lease row")
}
id := fixture.IssuePrefix + "-after-" + suffix
heartbeaterSeedClaimed(t, ctx, fixture, id)
if n := heartbeaterScalar[int](t, ctx, fixture, "SELECT COUNT(*) FROM leases WHERE issue_id = ?", id); n != 1 {
t.Fatalf("lease rows for claimed %s = %d, want 1", id, n)
}
if err := end(id); err != nil {
t.Fatalf("end the claim on %s (%s): %v", id, suffix, err)
}
if n := heartbeaterScalar[int](t, ctx, fixture, "SELECT COUNT(*) FROM leases WHERE issue_id = ?", id); n != 0 {
t.Fatalf("lease rows for %s %s = %d, want 0: the path that ended the claim left its lease row", suffix, id, n)
}
_, err := fixture.Heartbeater.Heartbeat(ctx, publicops.HeartbeatRequest{Actor: heartbeaterHolder, IssueID: id})
if !errors.Is(err, publicops.ErrLeaseNotHeld) || !errors.Is(err, publicops.ErrNotClaimable) {
t.Fatalf("heartbeat after the claim was %s = %v, want ErrLeaseNotHeld matching ErrNotClaimable", suffix, err)
}
if errors.Is(err, publicops.ErrAlreadyClaimed) {
t.Fatalf("heartbeat after the claim was %s = %v also matches ErrAlreadyClaimed", suffix, err)
}
conflict := heartbeaterConflict(t, err)
if conflict.IssueID != id || conflict.Holder != "" || conflict.Status != status {
t.Fatalf("LeaseConflictError = %+v, want {IssueID:%s Holder:\"\" Status:%s}", conflict, id, status)
}
if n := heartbeaterScalar[int](t, ctx, fixture, "SELECT COUNT(*) FROM leases WHERE issue_id = ?", id); n != 0 {
t.Fatalf("a refused heartbeat left %d lease row(s) for %s", n, id)
}
}
// heartbeaterRowSnapshot is every durable trace a heartbeat must not leave.
// A field the backend cannot observe holds -1.
type heartbeaterRowSnapshot struct {
RowLock int64
CurrentRevision int64
UpdatedAt string
Events int
JournalMaxSeq int64
IssueVersions int
History int
}
func heartbeaterSnapshot(t *testing.T, ctx context.Context, fixture HeartbeaterFixture, id string) heartbeaterRowSnapshot {
t.Helper()
snap := heartbeaterRowSnapshot{
RowLock: heartbeaterScalar[int64](t, ctx, fixture, "SELECT row_lock FROM issues WHERE id = ?", id),
CurrentRevision: heartbeaterScalar[int64](t, ctx, fixture, "SELECT current_revision FROM issues WHERE id = ?", id),
UpdatedAt: heartbeaterScalar[string](t, ctx, fixture, "SELECT CAST(updated_at AS CHAR) FROM issues WHERE id = ?", id),
Events: heartbeaterScalar[int](t, ctx, fixture, "SELECT COUNT(*) FROM events WHERE issue_id = ?", id),
JournalMaxSeq: -1,
IssueVersions: -1,
History: -1,
}
if fixture.SetJournalEnabled != nil {
snap.JournalMaxSeq = heartbeaterScalar[int64](t, ctx, fixture, "SELECT COALESCE(MAX(seq), 0) FROM bd_events_journal")
}
if fixture.SetVersionedHistoryEnabled != nil {
snap.IssueVersions = heartbeaterScalar[int](t, ctx, fixture, "SELECT COUNT(*) FROM issue_versions WHERE issue_id = ?", id)
}
if fixture.CountHistory != nil {
n, err := fixture.CountHistory(ctx)
if err != nil {
t.Fatalf("CountHistory: %v", err)
}
snap.History = n
}
return snap
}
func heartbeaterFired(t *testing.T, ctx context.Context, fixture HeartbeaterFixture, id string) int {
t.Helper()
if fixture.HookedHeartbeater == nil || fixture.FiredUpdates == nil {
return 0
}
ids, err := fixture.FiredUpdates(ctx)
if err != nil {
t.Fatalf("FiredUpdates: %v", err)
}
n := 0
for _, fired := range ids {
if fired == id {
n++
}
}
return n
}
func requireHeartbeaterExec(t *testing.T, fixture HeartbeaterFixture) {
t.Helper()
if fixture.Exec == nil || fixture.QueryScalar == nil {
t.Skip("HeartbeaterFixture.Exec/QueryScalar is nil: this backend cannot read or age a lease row")
}
}
func heartbeaterSeed(t *testing.T, ctx context.Context, fixture HeartbeaterFixture, id string) {
t.Helper()
if err := fixture.CreateIssue(ctx, &types.Issue{
ID: id, Title: id, Status: types.StatusOpen, Priority: 2, IssueType: types.TypeTask,
}, "seed"); err != nil {
t.Fatalf("seed %s: %v", id, err)
}
}
// heartbeaterSeedClaimed creates id and claims it as heartbeaterHolder through
// the leg's Claimer, answering the claim's row version.
func heartbeaterSeedClaimed(t *testing.T, ctx context.Context, fixture HeartbeaterFixture, id string) int64 {
t.Helper()
if fixture.Claimer == nil {
t.Skip("HeartbeaterFixture.Claimer is nil: this backend cannot take the claim a heartbeat refreshes")
}
heartbeaterSeed(t, ctx, fixture, id)
claimed, err := fixture.Claimer.Claim(ctx, publicops.ClaimRequest{Actor: heartbeaterHolder, IssueID: id})
if err != nil {
t.Fatalf("claim %s as %s: %v", id, heartbeaterHolder, err)
}
if claimed.Issue == nil {
t.Fatalf("claim %s answered no issue", id)
}
return claimed.Issue.RowVersion
}
func heartbeat(t *testing.T, ctx context.Context, surface publicops.Heartbeater, request publicops.HeartbeatRequest) publicops.HeartbeatResult {
t.Helper()
result, err := surface.Heartbeat(ctx, request)
if err != nil {
t.Fatalf("Heartbeat(%+v): %v", request, err)
}
return result
}
func heartbeaterConflict(t *testing.T, err error) *publicops.LeaseConflictError {
t.Helper()
var conflict *publicops.LeaseConflictError
if !errors.As(err, &conflict) {
t.Fatalf("refusal %v (%T) is not a *LeaseConflictError", err, err)
}
return conflict
}
func heartbeaterScalar[T any](t *testing.T, ctx context.Context, fixture HeartbeaterFixture, query string, args ...any) T {
t.Helper()
var value T
if err := fixture.QueryScalar(ctx, query, args, &value); err != nil {
t.Fatalf("%s %v: %v", query, args, err)
}
return value
}
func heartbeaterAbs(d time.Duration) time.Duration {
if d < 0 {
return -d
}
return d
}

View file

@ -1,625 +0,0 @@
package conformance
import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
"runtime"
"slices"
"sort"
"strings"
"testing"
"time"
"github.com/steveyegge/beads/internal/hooks"
"github.com/steveyegge/beads/internal/types"
publicops "github.com/steveyegge/beads/issueops"
)
// This file holds the contract every implementation of publicops.LeaseReclaimer
// must satisfy. Each case asserts what issueops/leasereclaimer.go PROMISES,
// cited by symbol.
//
// FOUR LEGS, ONE BODY. dolt, embedded dolt and the unit-of-work provider all
// reach internal/storage/issueops.ExecuteReclaimInTx, and the http leg reaches
// the same body on the far side of POST /v0/beads/issues:reclaim. So a per-leg
// failure here is a wrapper's failure — a lost scope, a revision that never
// reached the caller, a refusal that stopped matching errors.Is — and the
// cases are written to catch exactly those.
//
// EVERY SWEEP HERE IS SCOPED. The legs share one database per suite with every
// other role's cases, and an UNSCOPED reclaim would revert whatever stale lease
// another case left behind. Every call below names its ids, or an assignee or
// label this case alone uses, so a case can never reach outside what it seeded.
// The workspace-wide form is the same SQL with the scope clause absent, which
// sqlbuild.ReclaimScopeSQL's own tests pin.
//
// STALENESS IS MANUFACTURED, NOT WAITED FOR. The role refuses a negative
// OlderThan (the raw method's -time.Hour trick is exactly what it rules out),
// so a case claims through the leg's real Claimer — which writes the lease row
// every reclaim reads — and then moves that row's lease_expires_at into the
// past through Exec.
type LeaseReclaimerFixture struct {
// IssuePrefix namespaces the ids each assertion seeds, so several of them
// can share one database.
IssuePrefix string
// LeaseReclaimer is the surface under test.
LeaseReclaimer publicops.LeaseReclaimer
// CreateIssue seeds a durable issue in the issues plane.
CreateIssue func(context.Context, *types.Issue, string) error
// Claimer takes the claim, and with it the lease row, a reclaim reverts. It
// is the leg's own role rather than a raw insert so the lease is the shape
// a real claim leaves, granted_node included.
Claimer publicops.Claimer
// Lifecycle performs the guarded write the revision case races against the
// reclaim. A nil Lifecycle SKIPS that case loudly.
Lifecycle publicops.Lifecycle
// Exec runs raw statements against the backing database: the cases use it
// to age a lease and to attach labels. A nil Exec SKIPS every case that
// needs a stale lease, which is nearly all of them, so every leg supplies
// one.
Exec func(ctx context.Context, statements []SQLStatement) error
// QueryScalar runs a single-row query and scans it, so the post-state is
// read RAW rather than through the role being tested.
QueryScalar func(context.Context, string, []any, ...any) error
// HookedLeaseReclaimer is the same role taken off the leg's HOOK-FIRING
// chain (storage.HookFiringStore on the store legs and the http leg,
// uow.NewNotifyingProvider on the unit-of-work leg), built over the runner
// FiredUpdates reads. Nil, with FiredUpdates, SKIPS the hook case loudly.
HookedLeaseReclaimer publicops.LeaseReclaimer
// FiredUpdates reports, in firing order, the issue id of every on_update
// the hooked chain ran so far. It must not return before the hooks it is
// asked about have finished.
FiredUpdates func(context.Context) ([]string, error)
}
const (
leaseReclaimerReaper = "reaper"
leaseReclaimerHolder = "lr-holder"
)
// RunLeaseReclaimerRevertsAStaleLease pins the post-state the role names
// (issueops/leasereclaimer.go, LeaseReclaimer: "each reclaimed row moves
// in_progress -> open and the assignee is cleared") and the three members of
// the ReclaimedLease it reports, each READ RAW.
func RunLeaseReclaimerRevertsAStaleLease(t *testing.T, ctx context.Context, fixture LeaseReclaimerFixture) {
t.Helper()
requireLeaseReclaimerExec(t, fixture)
id := fixture.IssuePrefix + "-revert"
leaseReclaimerSeedStale(t, ctx, fixture, leaseReclaimerHolder, id)
result := leaseReclaim(t, ctx, fixture, publicops.ReclaimRequest{
Actor: leaseReclaimerReaper,
Filter: publicops.ReclaimFilter{IDs: []string{id}},
})
if len(result.Reclaimed) != 1 {
t.Fatalf("Reclaimed = %+v, want exactly %s", result.Reclaimed, id)
}
got := result.Reclaimed[0]
if got.ID != id || got.PreviousOwner != leaseReclaimerHolder {
t.Fatalf("Reclaimed[0] = %+v, want {ID:%s PreviousOwner:%s}", got, id, leaseReclaimerHolder)
}
if status := leaseReclaimerScalar[string](t, ctx, fixture, "SELECT status FROM issues WHERE id = ?", id); status != string(types.StatusOpen) {
t.Fatalf("status after reclaim = %q, want %q", status, types.StatusOpen)
}
if held := leaseReclaimerScalar[int](t, ctx, fixture,
"SELECT COUNT(*) FROM issues WHERE id = ? AND (COALESCE(assignee, '') <> '' OR started_at IS NOT NULL)", id); held != 0 {
t.Fatal("reclaim left the assignee or started_at set; the row is still held by a dead worker")
}
if leases := leaseReclaimerScalar[int](t, ctx, fixture, "SELECT COUNT(*) FROM leases WHERE issue_id = ?", id); leases != 0 {
t.Fatalf("lease rows after reclaim = %d, want 0", leases)
}
stored := leaseReclaimerScalar[int64](t, ctx, fixture, "SELECT row_lock FROM issues WHERE id = ?", id)
if got.Revision != types.RevisionToken(stored) {
t.Fatalf("Reclaimed[0].Revision = %q, want the row's own token %q", got.Revision, types.RevisionToken(stored))
}
}
// RunLeaseReclaimerMintsARevisionThatFencesTheFormerHolder is the reason the
// revision is minted at all (LeaseReclaimer: "a racing holder's guarded write
// fails with ErrVersionMismatch"). A worker that lost its lease and wakes up
// holding the token its claim handed it must NOT be able to land a guarded
// write over the issue another worker may already have taken; the token the
// reclaim reported, and only it, lands.
func RunLeaseReclaimerMintsARevisionThatFencesTheFormerHolder(t *testing.T, ctx context.Context, fixture LeaseReclaimerFixture) {
t.Helper()
requireLeaseReclaimerExec(t, fixture)
if fixture.Lifecycle == nil {
t.Skip("LeaseReclaimerFixture.Lifecycle is nil: this backend cannot race a guarded write against the reclaim")
}
id := fixture.IssuePrefix + "-fence"
claimed := leaseReclaimerSeedStale(t, ctx, fixture, leaseReclaimerHolder, id)[id]
result := leaseReclaim(t, ctx, fixture, publicops.ReclaimRequest{
Actor: leaseReclaimerReaper,
Filter: publicops.ReclaimFilter{IDs: []string{id}},
})
if len(result.Reclaimed) != 1 {
t.Fatalf("Reclaimed = %+v, want exactly %s", result.Reclaimed, id)
}
minted, err := types.ParseRevisionToken(result.Reclaimed[0].Revision)
if err != nil {
t.Fatalf("Reclaimed[0].Revision %q is not a revision token: %v", result.Reclaimed[0].Revision, err)
}
if minted == claimed {
t.Fatalf("reclaim reported revision %d, the claim's own token: nothing was minted", minted)
}
stale := claimed
_, err = fixture.Lifecycle.Update(ctx, publicops.UpdateRequest{
Actor: leaseReclaimerHolder, IssueID: id, ExpectedVersion: &stale,
Patch: publicops.IssuePatch{Notes: publicops.Field[string]{Set: true, Value: "late write"}},
})
if !errors.Is(err, publicops.ErrVersionMismatch) {
t.Fatalf("guarded write with the pre-reclaim token = %v, want ErrVersionMismatch", err)
}
fresh := minted
if _, err := fixture.Lifecycle.Update(ctx, publicops.UpdateRequest{
Actor: leaseReclaimerReaper, IssueID: id, ExpectedVersion: &fresh,
Patch: publicops.IssuePatch{Notes: publicops.Field[string]{Set: true, Value: "after reclaim"}},
}); err != nil {
t.Fatalf("guarded write with the token the reclaim reported = %v, want it to land", err)
}
}
// RunLeaseReclaimerLeavesALiveLeaseAlone pins staleness as the gate: a lease
// that has not expired is not eligible, even when its id is named, and naming
// it is not an error (ReclaimRequest.Filter: "FILTER.IDS IS NOT AN ERROR WHEN
// IT NAMES A NON-STALE OR UNKNOWN ISSUE").
func RunLeaseReclaimerLeavesALiveLeaseAlone(t *testing.T, ctx context.Context, fixture LeaseReclaimerFixture) {
t.Helper()
requireLeaseReclaimerExec(t, fixture)
id := fixture.IssuePrefix + "-live"
leaseReclaimerSeedClaimed(t, ctx, fixture, leaseReclaimerHolder, id)
result := leaseReclaim(t, ctx, fixture, publicops.ReclaimRequest{
Actor: leaseReclaimerReaper,
Filter: publicops.ReclaimFilter{IDs: []string{id}},
})
if len(result.Reclaimed) != 0 {
t.Fatalf("Reclaimed = %+v, want nothing: the lease has not expired", result.Reclaimed)
}
leaseReclaimerRequireHeld(t, ctx, fixture, id)
}
// RunLeaseReclaimerHonorsTheGraceWindow pins ReclaimRequest.OlderThan: a lease
// expired less than OlderThan ago is left alone, and the same lease is
// reclaimed once the window is narrower than its age.
func RunLeaseReclaimerHonorsTheGraceWindow(t *testing.T, ctx context.Context, fixture LeaseReclaimerFixture) {
t.Helper()
requireLeaseReclaimerExec(t, fixture)
id := fixture.IssuePrefix + "-grace"
leaseReclaimerSeedClaimed(t, ctx, fixture, leaseReclaimerHolder, id)
leaseReclaimerAge(t, ctx, fixture, 10*time.Minute, id)
request := publicops.ReclaimRequest{
Actor: leaseReclaimerReaper,
OlderThan: time.Hour,
Filter: publicops.ReclaimFilter{IDs: []string{id}},
}
if result := leaseReclaim(t, ctx, fixture, request); len(result.Reclaimed) != 0 {
t.Fatalf("OlderThan 1h over a lease 10m stale: Reclaimed = %+v, want nothing", result.Reclaimed)
}
leaseReclaimerRequireHeld(t, ctx, fixture, id)
request.OlderThan = time.Minute
if got := leaseReclaimerIDs(leaseReclaim(t, ctx, fixture, request)); !slices.Equal(got, []string{id}) {
t.Fatalf("OlderThan 1m over a lease 10m stale: Reclaimed = %v, want [%s]", got, id)
}
}
// RunLeaseReclaimerScopesToTheNamedIDs pins the IDs scope from both sides: an
// id that is not named is never reverted though it is stale, and an id that is
// named but absent or live is simply missing from Reclaimed — the call does
// not fail and does not report it.
func RunLeaseReclaimerScopesToTheNamedIDs(t *testing.T, ctx context.Context, fixture LeaseReclaimerFixture) {
t.Helper()
requireLeaseReclaimerExec(t, fixture)
named := fixture.IssuePrefix + "-scope-named"
unnamed := fixture.IssuePrefix + "-scope-unnamed"
live := fixture.IssuePrefix + "-scope-live"
ghost := fixture.IssuePrefix + "-scope-ghost"
leaseReclaimerSeedStale(t, ctx, fixture, leaseReclaimerHolder, named, unnamed)
leaseReclaimerSeedClaimed(t, ctx, fixture, leaseReclaimerHolder, live)
result := leaseReclaim(t, ctx, fixture, publicops.ReclaimRequest{
Actor: leaseReclaimerReaper,
Filter: publicops.ReclaimFilter{IDs: []string{ghost, live, named}},
})
if got := leaseReclaimerIDs(result); !slices.Equal(got, []string{named}) {
t.Fatalf("Reclaimed = %v, want [%s]: only the named stale lease", got, named)
}
leaseReclaimerRequireHeld(t, ctx, fixture, unnamed)
leaseReclaimerRequireHeld(t, ctx, fixture, live)
}
// RunLeaseReclaimerAnswersAnAbsentIDWithAnEmptyResult pins the empty answer:
// a sweep scoped only to ids that name no row is not a refusal, and its
// Reclaimed is empty and NON-NIL (ReclaimResult.Reclaimed: "Never nil for a
// successful call").
func RunLeaseReclaimerAnswersAnAbsentIDWithAnEmptyResult(t *testing.T, ctx context.Context, fixture LeaseReclaimerFixture) {
t.Helper()
result, err := fixture.LeaseReclaimer.Reclaim(ctx, publicops.ReclaimRequest{
Actor: leaseReclaimerReaper,
Filter: publicops.ReclaimFilter{IDs: []string{fixture.IssuePrefix + "-absent-a", fixture.IssuePrefix + "-absent-b"}},
})
if err != nil {
t.Fatalf("Reclaim scoped to absent ids = %v, want an empty answer", err)
}
if result.Reclaimed == nil {
t.Fatal("Reclaimed is nil; the role promises an empty, non-nil slice")
}
if len(result.Reclaimed) != 0 {
t.Fatalf("Reclaimed = %+v, want nothing", result.Reclaimed)
}
}
// RunLeaseReclaimerScopesToAssigneesAndLabels re-homes the raw method's scope
// cases (testReclaimScoped) onto the role: assignee, label (AND), label-any
// (OR) and exclude-label each narrow the sweep and never widen it.
func RunLeaseReclaimerScopesToAssigneesAndLabels(t *testing.T, ctx context.Context, fixture LeaseReclaimerFixture) {
t.Helper()
requireLeaseReclaimerExec(t, fixture)
p := fixture.IssuePrefix
a1, a2, b1, c1 := p+"-lbl-a1", p+"-lbl-a2", p+"-lbl-b1", p+"-lbl-c1"
laneA, laneB, opus := p+"-lane-a", p+"-lane-b", p+"-tier-opus"
workerA, workerB, workerC := p+"-wa", p+"-wb", p+"-wc"
leaseReclaimerSeedStale(t, ctx, fixture, workerA, a1, a2)
leaseReclaimerSeedStale(t, ctx, fixture, workerB, b1)
leaseReclaimerSeedStale(t, ctx, fixture, workerC, c1)
leaseReclaimerLabel(t, ctx, fixture, a1, laneA)
leaseReclaimerLabel(t, ctx, fixture, a2, laneA)
leaseReclaimerLabel(t, ctx, fixture, a2, opus)
leaseReclaimerLabel(t, ctx, fixture, b1, laneB)
reclaim := func(filter publicops.ReclaimFilter) []string {
t.Helper()
return leaseReclaimerIDs(leaseReclaim(t, ctx, fixture, publicops.ReclaimRequest{Actor: leaseReclaimerReaper, Filter: filter}))
}
if got := reclaim(publicops.ReclaimFilter{Labels: []string{laneB}}); !slices.Equal(got, []string{b1}) {
t.Fatalf("reclaim(labels %s) = %v, want [%s]", laneB, got, b1)
}
if got := reclaim(publicops.ReclaimFilter{Assignees: []string{workerC}}); !slices.Equal(got, []string{c1}) {
t.Fatalf("reclaim(assignees %s) = %v, want [%s]", workerC, got, c1)
}
if got := reclaim(publicops.ReclaimFilter{Labels: []string{laneA}, ExcludeLabels: []string{opus}}); !slices.Equal(got, []string{a1}) {
t.Fatalf("reclaim(labels %s, exclude %s) = %v, want [%s]", laneA, opus, got, a1)
}
leaseReclaimerRequireHeld(t, ctx, fixture, a2)
if got := reclaim(publicops.ReclaimFilter{LabelsAny: []string{p + "-lane-z", opus}}); !slices.Equal(got, []string{a2}) {
t.Fatalf("reclaim(labels-any lane-z,%s) = %v, want [%s]", opus, got, a2)
}
}
// RunLeaseReclaimerAttributesTheRecoveryEvent pins ReclaimRequest.Actor: the
// recovery event each reverted row records names the actor who ran the sweep,
// with the lease's former holder beside it.
func RunLeaseReclaimerAttributesTheRecoveryEvent(t *testing.T, ctx context.Context, fixture LeaseReclaimerFixture) {
t.Helper()
requireLeaseReclaimerExec(t, fixture)
id := fixture.IssuePrefix + "-event"
leaseReclaimerSeedStale(t, ctx, fixture, leaseReclaimerHolder, id)
leaseReclaim(t, ctx, fixture, publicops.ReclaimRequest{
Actor: leaseReclaimerReaper,
Filter: publicops.ReclaimFilter{IDs: []string{id}},
})
if n := leaseReclaimerScalar[int](t, ctx, fixture,
"SELECT COUNT(*) FROM events WHERE issue_id = ? AND event_type = ? AND actor = ? AND old_value = ?",
id, string(types.EventLeaseReclaimed), leaseReclaimerReaper, leaseReclaimerHolder); n != 1 {
t.Fatalf("lease_reclaimed events by %s naming %s = %d, want 1", leaseReclaimerReaper, leaseReclaimerHolder, n)
}
}
// RunLeaseReclaimerFiresOnUpdateOncePerReclaimedRow pins the hook the role
// names (LeaseReclaimer: "ITS HOOK IS on_update, once per reverted row"): each
// reverted row fires on_update exactly once, and a row the sweep did not
// revert — named but live — fires nothing.
func RunLeaseReclaimerFiresOnUpdateOncePerReclaimedRow(t *testing.T, ctx context.Context, fixture LeaseReclaimerFixture) {
t.Helper()
requireLeaseReclaimerExec(t, fixture)
if fixture.HookedLeaseReclaimer == nil || fixture.FiredUpdates == nil {
t.Skip("LeaseReclaimerFixture.HookedLeaseReclaimer/FiredUpdates is nil: this backend cannot observe its hooks")
}
first := fixture.IssuePrefix + "-hook-a"
second := fixture.IssuePrefix + "-hook-b"
live := fixture.IssuePrefix + "-hook-live"
leaseReclaimerSeedStale(t, ctx, fixture, leaseReclaimerHolder, first, second)
leaseReclaimerSeedClaimed(t, ctx, fixture, leaseReclaimerHolder, live)
before, err := fixture.FiredUpdates(ctx)
if err != nil {
t.Fatalf("FiredUpdates before: %v", err)
}
result, err := fixture.HookedLeaseReclaimer.Reclaim(ctx, publicops.ReclaimRequest{
Actor: leaseReclaimerReaper,
Filter: publicops.ReclaimFilter{IDs: []string{first, second, live}},
})
if err != nil {
t.Fatalf("hooked Reclaim: %v", err)
}
if got := leaseReclaimerIDs(result); !slices.Equal(got, []string{first, second}) {
t.Fatalf("Reclaimed = %v, want [%s %s]", got, first, second)
}
after, err := fixture.FiredUpdates(ctx)
if err != nil {
t.Fatalf("FiredUpdates after: %v", err)
}
fired := map[string]int{}
for _, id := range after[len(before):] {
fired[id]++
}
for _, id := range []string{first, second} {
if fired[id] != 1 {
t.Fatalf("on_update fired %d time(s) for %s, want exactly 1 (fired: %v)", fired[id], id, after[len(before):])
}
}
if fired[live] != 0 {
t.Fatalf("on_update fired for %s, which the sweep did not revert", live)
}
}
// RunLeaseReclaimerRefusesAMalformedRequest pins every refusal the role lists,
// each as ErrValidation (the cap as *TooManyReclaimIDsError), and that a
// refusal changes nothing: the stale lease every request names survives all of
// them.
func RunLeaseReclaimerRefusesAMalformedRequest(t *testing.T, ctx context.Context, fixture LeaseReclaimerFixture) {
t.Helper()
requireLeaseReclaimerExec(t, fixture)
id := fixture.IssuePrefix + "-malformed"
leaseReclaimerSeedStale(t, ctx, fixture, leaseReclaimerHolder, id)
tooMany := make([]string, publicops.MaxReclaimIDs+1)
for i := range tooMany {
tooMany[i] = id
}
for _, test := range []struct {
name string
request publicops.ReclaimRequest
tooMany bool
}{
{"an empty actor", publicops.ReclaimRequest{Filter: publicops.ReclaimFilter{IDs: []string{id}}}, false},
// One past the column every reverted row's recovery event records it
// in: a typed refusal before the sweep, never the backend's own error
// from the first row it would have reverted.
{"an over-long actor", publicops.ReclaimRequest{Actor: strings.Repeat("r", types.MaxFieldLen+1),
Filter: publicops.ReclaimFilter{IDs: []string{id}}}, false},
{"a negative grace window", publicops.ReclaimRequest{Actor: leaseReclaimerReaper, OlderThan: -time.Second,
Filter: publicops.ReclaimFilter{IDs: []string{id}}}, false},
{"a blank scoped id", publicops.ReclaimRequest{Actor: leaseReclaimerReaper,
Filter: publicops.ReclaimFilter{IDs: []string{id, ""}}}, false},
{"more ids than the cap", publicops.ReclaimRequest{Actor: leaseReclaimerReaper,
Filter: publicops.ReclaimFilter{IDs: tooMany}}, true},
} {
_, err := fixture.LeaseReclaimer.Reclaim(ctx, test.request)
if !errors.Is(err, publicops.ErrValidation) {
t.Fatalf("%s: Reclaim error = %v, want ErrValidation", test.name, err)
}
if test.tooMany {
var capErr *publicops.TooManyReclaimIDsError
if !errors.As(err, &capErr) || capErr.Requested != len(tooMany) || capErr.Cap != publicops.MaxReclaimIDs {
t.Fatalf("%s: Reclaim error = %v, want *TooManyReclaimIDsError{Requested:%d Cap:%d}",
test.name, err, len(tooMany), publicops.MaxReclaimIDs)
}
}
leaseReclaimerRequireHeld(t, ctx, fixture, id)
}
}
// RunLeaseReclaimerRefusesABlankScopeEntry pins the blank-entry refusal on
// the scopes that are not ids: an empty or all-blank assignee or label is
// ErrValidation as a *ReclaimFieldError naming its field, and changes
// nothing — the stale lease every request names survives.
func RunLeaseReclaimerRefusesABlankScopeEntry(t *testing.T, ctx context.Context, fixture LeaseReclaimerFixture) {
t.Helper()
requireLeaseReclaimerExec(t, fixture)
id := fixture.IssuePrefix + "-blankscope"
leaseReclaimerSeedStale(t, ctx, fixture, leaseReclaimerHolder, id)
for _, test := range []struct {
field string
filter publicops.ReclaimFilter
}{
{publicops.ReclaimFieldAssignees, publicops.ReclaimFilter{IDs: []string{id}, Assignees: []string{leaseReclaimerHolder, " "}}},
{publicops.ReclaimFieldLabels, publicops.ReclaimFilter{IDs: []string{id}, Labels: []string{""}}},
{publicops.ReclaimFieldLabelsAny, publicops.ReclaimFilter{IDs: []string{id}, LabelsAny: []string{"\t"}}},
{publicops.ReclaimFieldExcludeLabels, publicops.ReclaimFilter{IDs: []string{id}, ExcludeLabels: []string{"x", " "}}},
} {
_, err := fixture.LeaseReclaimer.Reclaim(ctx, publicops.ReclaimRequest{Actor: leaseReclaimerReaper, Filter: test.filter})
var fieldErr *publicops.ReclaimFieldError
if !errors.Is(err, publicops.ErrValidation) || !errors.As(err, &fieldErr) || fieldErr.Field != test.field {
t.Fatalf("blank %s entry: Reclaim error = %v, want a *ReclaimFieldError naming %s", test.field, err, test.field)
}
leaseReclaimerRequireHeld(t, ctx, fixture, id)
}
}
// RunLeaseReclaimerAcceptsExactlyTheCap pins the cap's boundary: MaxReclaimIDs
// entries is a request, one more is a refusal (the case above).
func RunLeaseReclaimerAcceptsExactlyTheCap(t *testing.T, ctx context.Context, fixture LeaseReclaimerFixture) {
t.Helper()
ids := make([]string, publicops.MaxReclaimIDs)
for i := range ids {
ids[i] = fmt.Sprintf("%s-cap-%04d", fixture.IssuePrefix, i)
}
result, err := fixture.LeaseReclaimer.Reclaim(ctx, publicops.ReclaimRequest{
Actor: leaseReclaimerReaper, Filter: publicops.ReclaimFilter{IDs: ids},
})
if err != nil {
t.Fatalf("Reclaim with exactly MaxReclaimIDs ids = %v, want an answer", err)
}
if len(result.Reclaimed) != 0 {
t.Fatalf("Reclaimed = %+v, want nothing: none of the ids exist", result.Reclaimed)
}
}
// RunLeaseReclaimerDoesNotMutateTheCallerRequest pins the role's "never mutate
// caller-owned request values": the scope slices come back as they were sent.
func RunLeaseReclaimerDoesNotMutateTheCallerRequest(t *testing.T, ctx context.Context, fixture LeaseReclaimerFixture) {
t.Helper()
requireLeaseReclaimerExec(t, fixture)
id := fixture.IssuePrefix + "-nomut"
leaseReclaimerSeedStale(t, ctx, fixture, leaseReclaimerHolder, id)
ids := []string{fixture.IssuePrefix + "-nomut-ghost", id}
assignees := []string{leaseReclaimerHolder}
request := publicops.ReclaimRequest{
Actor: leaseReclaimerReaper,
Filter: publicops.ReclaimFilter{IDs: ids, Assignees: assignees},
}
leaseReclaim(t, ctx, fixture, request)
if !slices.Equal(ids, []string{fixture.IssuePrefix + "-nomut-ghost", id}) || !slices.Equal(assignees, []string{leaseReclaimerHolder}) {
t.Fatalf("Reclaim rewrote the caller's scope: ids=%v assignees=%v", ids, assignees)
}
}
// NewUpdateHookLog plants an on_update script that appends the id of every
// issue it fires for, and returns the runner a hook-firing chain is built over
// plus a reader for LeaseReclaimerFixture.FiredUpdates. The reader waits for
// in-flight hooks before reading, so it answers for every hook already fired.
//
// It answers (nil, nil) where a shell hook cannot run, so a fixture built from
// it leaves the hook case to skip rather than fail.
func NewUpdateHookLog(t *testing.T) (*hooks.Runner, func(context.Context) ([]string, error)) {
t.Helper()
if runtime.GOOS == "windows" {
return nil, nil
}
dir := t.TempDir()
log := filepath.Join(t.TempDir(), "on_update.log")
script := "#!/bin/sh\necho \"$1\" >> " + log + "\n"
if err := os.WriteFile(filepath.Join(dir, "on_update"), []byte(script), 0o755); err != nil { //nolint:gosec // G306: a hook must be executable to run at all
t.Fatalf("plant the on_update hook: %v", err)
}
runner := hooks.NewRunner(dir)
return runner, func(context.Context) ([]string, error) {
if !runner.Wait(30 * time.Second) {
return nil, errors.New("on_update hooks still running after 30s")
}
data, err := os.ReadFile(log) // #nosec G304 -- this helper's own temp file
if errors.Is(err, os.ErrNotExist) {
return []string{}, nil
}
if err != nil {
return nil, err
}
var ids []string
for _, line := range strings.Split(strings.TrimSpace(string(data)), "\n") {
if line = strings.TrimSpace(line); line != "" {
ids = append(ids, line)
}
}
return ids, nil
}
}
func requireLeaseReclaimerExec(t *testing.T, fixture LeaseReclaimerFixture) {
t.Helper()
if fixture.Exec == nil || fixture.Claimer == nil || fixture.QueryScalar == nil {
t.Skip("LeaseReclaimerFixture.Exec/Claimer/QueryScalar is nil: this backend cannot manufacture a stale lease")
}
}
// leaseReclaimerSeedClaimed creates each id and claims it as holder through the
// leg's Claimer, answering each claim's row version.
func leaseReclaimerSeedClaimed(t *testing.T, ctx context.Context, fixture LeaseReclaimerFixture, holder string, ids ...string) map[string]int64 {
t.Helper()
versions := map[string]int64{}
for _, id := range ids {
if err := fixture.CreateIssue(ctx, &types.Issue{
ID: id, Title: id, Status: types.StatusOpen, Priority: 2, IssueType: types.TypeTask,
}, "seed"); err != nil {
t.Fatalf("seed %s: %v", id, err)
}
claimed, err := fixture.Claimer.Claim(ctx, publicops.ClaimRequest{Actor: holder, IssueID: id})
if err != nil {
t.Fatalf("claim %s as %s: %v", id, holder, err)
}
if claimed.Issue == nil {
t.Fatalf("claim %s answered no issue", id)
}
versions[id] = claimed.Issue.RowVersion
}
return versions
}
// leaseReclaimerSeedStale claims each id and ages its lease an hour past
// expiry, far beyond any grace window a case below uses by default.
func leaseReclaimerSeedStale(t *testing.T, ctx context.Context, fixture LeaseReclaimerFixture, holder string, ids ...string) map[string]int64 {
t.Helper()
versions := leaseReclaimerSeedClaimed(t, ctx, fixture, holder, ids...)
leaseReclaimerAge(t, ctx, fixture, time.Hour, ids...)
return versions
}
// leaseReclaimerAge moves each id's lease expiry to age in the past.
func leaseReclaimerAge(t *testing.T, ctx context.Context, fixture LeaseReclaimerFixture, age time.Duration, ids ...string) {
t.Helper()
expired := time.Now().UTC().Add(-age)
statements := make([]SQLStatement, 0, len(ids))
for _, id := range ids {
statements = append(statements, SQLStatement{
Query: "UPDATE leases SET lease_expires_at = ? WHERE issue_id = ?",
Args: []any{expired, id},
})
}
if err := fixture.Exec(ctx, statements); err != nil {
t.Fatalf("age leases %v: %v", ids, err)
}
for _, id := range ids {
if n := leaseReclaimerScalar[int](t, ctx, fixture, "SELECT COUNT(*) FROM leases WHERE issue_id = ?", id); n != 1 {
t.Fatalf("lease rows for %s = %d, want 1: the claim wrote no lease to reclaim", id, n)
}
}
}
func leaseReclaimerLabel(t *testing.T, ctx context.Context, fixture LeaseReclaimerFixture, id, label string) {
t.Helper()
if err := fixture.Exec(ctx, []SQLStatement{{
Query: "INSERT INTO labels (issue_id, label) VALUES (?, ?)",
Args: []any{id, label},
}}); err != nil {
t.Fatalf("label %s %s: %v", id, label, err)
}
}
func leaseReclaimerRequireHeld(t *testing.T, ctx context.Context, fixture LeaseReclaimerFixture, id string) {
t.Helper()
if status := leaseReclaimerScalar[string](t, ctx, fixture, "SELECT status FROM issues WHERE id = ?", id); status != string(types.StatusInProgress) {
t.Fatalf("%s status = %q, want it still %q", id, status, types.StatusInProgress)
}
}
func leaseReclaim(t *testing.T, ctx context.Context, fixture LeaseReclaimerFixture, request publicops.ReclaimRequest) publicops.ReclaimResult {
t.Helper()
result, err := fixture.LeaseReclaimer.Reclaim(ctx, request)
if err != nil {
t.Fatalf("Reclaim(%+v): %v", request.Filter, err)
}
if result.Reclaimed == nil {
t.Fatal("Reclaimed is nil; the role promises a non-nil slice for a successful call")
}
return result
}
func leaseReclaimerIDs(result publicops.ReclaimResult) []string {
ids := make([]string, 0, len(result.Reclaimed))
for _, r := range result.Reclaimed {
ids = append(ids, r.ID)
}
sort.Strings(ids)
return ids
}
func leaseReclaimerScalar[T any](t *testing.T, ctx context.Context, fixture LeaseReclaimerFixture, query string, args ...any) T {
t.Helper()
var value T
if err := fixture.QueryScalar(ctx, query, args, &value); err != nil {
t.Fatalf("%s %v: %v", query, args, err)
}
return value
}

View file

@ -846,12 +846,11 @@ func RunLifecycleCloseAndReopenSpanTheConfiguredDoneCategory(t *testing.T, ctx c
// RunLifecycleExpectedVersionIsCheckedBeforeTheNoOps pins the ORDERING clause
// both requests spell out. CloseRequest.ExpectedVersion "requires the current
// row version to match, and is checked BEFORE the idempotent close"
// (issueops/issueops.go:362-373); ReopenRequest.ExpectedVersion is "checked
// before a non-done no-op" (:390-391); and Close's own doc adds "ExpectedVersion
// row version to match and is checked before an idempotent close"
// (issueops/issueops.go:295-300); ReopenRequest.ExpectedVersion is "checked
// before a non-done no-op" (:272-275); and Close's own doc adds "ExpectedVersion
// is checked first, including for an idempotent close", with Force bypassing
// "the pin, the assignee fence, and blocker and open-child policy" and nothing
// else (:485-498).
// "blocker and open-child policy" and nothing else (:364-365).
//
// The dangerous shape is not a stale version on a live mutation — it is a stale
// version on the request that would have done nothing anyway. An implementation
@ -1093,87 +1092,6 @@ func RunLifecycleResultsAreHydratedPostStateSnapshots(t *testing.T, ctx context.
lifecycleCloseReopenAssertSnapshot(t, "reopen result", reopened.Issue, peer)
}
// RunLifecycleResultsCarryThePostWriteRowVersion pins that every write this
// role owns — Update, Close and Reopen — hands back a result whose
// Issue.RowVersion is the row's REAL post-write optimistic-concurrency token,
// not a zero value. types.Issue.RowVersion is `json:"-"`: an implementation
// that forgot to populate it on the way back from its own storage would still
// compile and would still pass every content assertion elsewhere in this
// file, because none of them read RowVersion.
//
// The assertion is a CHAIN rather than three independent zero-checks, because
// a zero-check alone cannot tell a dropped token from a WRONG one (an
// implementation could answer a nonzero constant, or the PRE-write version,
// and still clear it). Each step feeds the token the previous write answered
// with straight into the next write's ExpectedVersion, with no intervening
// read: the claim's token guards the Notes update, Update's token guards
// Close, and Close's token guards Reopen. A guard only passes if the token it
// was given equals the row's actual current version at the instant the next
// write runs, so a wrong or stale token fails closed — the next write
// refuses with ErrVersionMismatch — rather than silently succeeding. Any one
// dropped member breaks the chain at that link.
//
// The chain's first link is a CLAIM-ONLY request (Claim: true, no Patch),
// deliberately unguarded (UpdateRequest.Claim forbids combining Claim with
// ExpectedVersion — see issueops.UpdateRequest's doc): a backend that answers
// Lifecycle.Update's generic patch wire but special-cases a bare claim onto a
// different internal path (the http leg once dialed the Claimer role directly
// for one; it now folds the claim into updateIssue, keeping claimIssue only as
// the fallback for a server that predates updateIssue's `claim` member) could
// easily populate RowVersion on one path and not the other; this exercises
// the claim-only shape specifically, not just the Patch shape the rest of the
// chain already covered.
func RunLifecycleResultsCarryThePostWriteRowVersion(t *testing.T, ctx context.Context, fixture LifecycleCloseReopenFixture) {
t.Helper()
id := fixture.IssuePrefix + "-lcr-rowversion"
lifecycleCloseReopenSeedIssue(t, ctx, fixture, id, types.StatusOpen, nil)
claimed, err := fixture.Lifecycle.Update(ctx, publicops.UpdateRequest{
Actor: "writer", IssueID: id, Claim: true,
})
if err != nil {
t.Fatalf("claim %s: %v", id, err)
}
if claimed.Issue == nil || claimed.Issue.RowVersion == 0 {
t.Fatalf("claim result RowVersion = %+v, want a nonzero post-write token", claimed.Issue)
}
claimVersion := claimed.Issue.RowVersion
updated, err := fixture.Lifecycle.Update(ctx, publicops.UpdateRequest{
Actor: "writer", IssueID: id, ExpectedVersion: &claimVersion,
Patch: publicops.IssuePatch{Notes: publicops.Field[string]{Set: true, Value: "rowversion chain"}},
})
if err != nil {
t.Fatalf("update %s guarded by the claim's own token: %v — the claim result's RowVersion was not the row's real current version", id, err)
}
if updated.Issue == nil || updated.Issue.RowVersion == 0 {
t.Fatalf("update result RowVersion = %+v, want a nonzero post-write token", updated.Issue)
}
updateVersion := updated.Issue.RowVersion
closed, err := fixture.Lifecycle.Close(ctx, publicops.CloseRequest{
Actor: "writer", IssueID: id, ExpectedVersion: &updateVersion,
})
if err != nil {
t.Fatalf("close %s guarded by the update's own token: %v — the update result's RowVersion was not the row's real current version", id, err)
}
if closed.Issue == nil || closed.Issue.RowVersion == 0 {
t.Fatalf("close result RowVersion = %+v, want a nonzero post-write token", closed.Issue)
}
closeVersion := closed.Issue.RowVersion
reopened, err := fixture.Lifecycle.Reopen(ctx, publicops.ReopenRequest{
Actor: "writer", IssueID: id, ExpectedVersion: &closeVersion,
})
if err != nil {
t.Fatalf("reopen %s guarded by the close's own token: %v — the close result's RowVersion was not the row's real current version", id, err)
}
if reopened.Issue == nil || reopened.Issue.RowVersion == 0 {
t.Fatalf("reopen result RowVersion = %+v, want a nonzero post-write token", reopened.Issue)
}
}
// RunLifecycleCloseAndReopenRequireActorAndIssueID pins the deterministic
// validation floor both verbs sit on. The Lifecycle doc states "Deterministic
// request validation failures match ErrValidation" and "Refusals and
@ -1384,14 +1302,13 @@ func RunLifecycleCloseSettlesItsTransitiveAndCrossPlaneDependers(t *testing.T, c
// RunLifecycleCloseAdmitsATransitivelyBlockedTarget uses clears the first and
// not the second, and closing the child to clear the second would take the
// second subject with it, since a closed row cannot be blocked and so has
// nothing left to flip. Force waives close policy, the pin and the assignee
// fence, and nothing else — CloseRequest.Force "bypasses blocker and
// open-child close policy and the two close guards a force has always waived
// in bd" and "never bypasses the template guard, validation, ExpectedVersion,
// or lifecycle rules" (issueops/issueops.go:357-360) — so it is the shape that
// keeps both subjects observable, and it is not exotic: it is the same forced
// close of a blocked issue that
// RunLifecycleCloseIsIdempotentOnAClosedRowThatStillLooksBlocked is built on.
// nothing left to flip. Force waives close policy and nothing else —
// CloseRequest.Force "bypasses only blocker and open-child close policy" and
// "never bypasses validation, ExpectedVersion, or lifecycle rules"
// (issueops/issueops.go:310-311) — so it is the shape that keeps both subjects
// observable, and it is not exotic: it is the same forced close of a
// blocked issue that RunLifecycleCloseIsIdempotentOnAClosedRowThatStillLooksBlocked
// is built on.
//
// All three legs reach ONE body here (internal/storage/issueops.closeIssueInTx),
// so this is a wrapper and engine check rather than a third vote, exactly as
@ -1824,175 +1741,3 @@ func (c *lifecycleCloseReopenEventCounter) assertNoneAdded(t *testing.T, label s
}
c.total = total
}
// RunLifecycleCloseEnforcesTheCloseGuards pins the three close guards
// issueops.Lifecycle.Close states before close policy — template read-only,
// the pin, and the assignee authority fence (be-035) — on the role itself, so
// every caller of it is held to them and not only `bd close`, which used to
// apply them as a CLI pre-read the served and library routes skipped.
//
// Each refusal is asserted at the level a caller acts on: the typed error with
// its fields, its sentinel, and the sentence bd prints — read off the typed
// error, because a served refusal wraps it in the problem envelope — plus the
// row and the event stream left untouched. Force is asserted as the bypass for
// exactly the two guards it has always waived, and NOT for the template.
//
// The controls are load-bearing too: an unassigned issue and one held by the
// closing actor under a different spelling both close unforced, so a guard
// that refused every assigned row, or compared verbatim, fails here. A wisp
// case proves the guard reads the plane the close writes. A pinned issue with
// an open child reads the PIN's refusal, pinning the order (guards before
// policy). And a forced close of a boolean-pinned issue leaves the pin set, so
// the plain retry must stay the idempotent no-op (ga-ktn9pe.4.8) rather than
// refuse on the residue.
func RunLifecycleCloseEnforcesTheCloseGuards(t *testing.T, ctx context.Context, fixture LifecycleCloseReopenFixture) {
t.Helper()
template := fixture.IssuePrefix + "-lcg-template"
statusPinned := fixture.IssuePrefix + "-lcg-status-pinned"
flagPinned := fixture.IssuePrefix + "-lcg-flag-pinned"
held := fixture.IssuePrefix + "-lcg-held"
respelled := fixture.IssuePrefix + "-lcg-respelled"
unassigned := fixture.IssuePrefix + "-lcg-unassigned"
pinnedParent := fixture.IssuePrefix + "-lcg-pinned-parent"
pinnedChild := fixture.IssuePrefix + "-lcg-pinned-child"
wisp := fixture.IssuePrefix + "-lcg-wisp-held"
seed := func(issue *types.Issue) {
t.Helper()
issue.Title, issue.Priority, issue.IssueType = issue.ID, 2, types.TypeTask
if issue.Status == "" {
issue.Status = types.StatusOpen
}
if err := fixture.CreateIssue(ctx, issue, "seed"); err != nil {
t.Fatalf("seed %s: %v", issue.ID, err)
}
}
seed(&types.Issue{ID: template, IsTemplate: true})
seed(&types.Issue{ID: statusPinned, Status: types.StatusPinned})
seed(&types.Issue{ID: flagPinned, Pinned: true})
seed(&types.Issue{ID: held, Assignee: "holder"})
seed(&types.Issue{ID: respelled, Assignee: "gastown.closer"})
seed(&types.Issue{ID: unassigned})
seed(&types.Issue{ID: pinnedParent, Pinned: true})
seed(&types.Issue{ID: pinnedChild})
lifecycleCloseReopenSeedEdge(t, ctx, fixture, pinnedChild, pinnedParent, types.DepParentChild)
refuses := func(id string, force bool, label string, check func(error)) {
t.Helper()
before := lifecycleCloseReopenReadRow(t, ctx, fixture, id)
events := newLifecycleCloseReopenEventCounter(t, ctx, fixture, id)
_, err := fixture.Lifecycle.Close(ctx, publicops.CloseRequest{Actor: "closer", IssueID: id, Force: force})
check(err)
lifecycleCloseReopenAssertRow(t, ctx, fixture, id, "after the "+label+" refusal", before)
events.assertNoneAdded(t, label+" refusal")
}
// The template refuses, forced or not: no flag waives read-only.
for _, force := range []bool{false, true} {
refuses(template, force, "template", func(err error) {
var refusal *publicops.TemplateReadOnlyError
if !errors.As(err, &refusal) {
t.Fatalf("close of template %s (force=%v): err = %v, want *TemplateReadOnlyError", template, force, err)
}
if refusal.IssueID != template || !errors.Is(err, publicops.ErrTemplateReadOnly) {
t.Errorf("template refusal = %#v (%v), want IssueID %q matching ErrTemplateReadOnly", refusal, err, template)
}
want := "cannot modify template " + template + ": templates are read-only; use 'bd mol pour' to create a work item"
if refusal.Error() != want {
t.Errorf("template refusal reads %q, want %q", refusal.Error(), want)
}
})
}
// Both pin spellings refuse unforced (ga-z3vht).
for _, id := range []string{statusPinned, flagPinned} {
refuses(id, false, "pin", func(err error) {
var refusal *publicops.PinnedError
if !errors.As(err, &refusal) {
t.Fatalf("unforced close of pinned %s: err = %v, want *PinnedError", id, err)
}
if refusal.IssueID != id || !errors.Is(err, publicops.ErrPinned) {
t.Errorf("pin refusal = %#v (%v), want IssueID %q matching ErrPinned", refusal, err, id)
}
if want := "cannot modify pinned issue " + id + " (use --force to override)"; refusal.Error() != want {
t.Errorf("pin refusal reads %q, want %q", refusal.Error(), want)
}
})
}
// Another actor's bead refuses unforced, naming holder and actor.
refuses(held, false, "assignee", func(err error) {
var refusal *publicops.CloseNotAssigneeError
if !errors.As(err, &refusal) {
t.Fatalf("unforced close of %s held by another actor: err = %v, want *CloseNotAssigneeError", held, err)
}
if refusal.IssueID != held || refusal.Assignee != "holder" || refusal.Actor != "closer" {
t.Errorf("assignee refusal = %#v, want IssueID %q, Assignee holder, Actor closer", refusal, held)
}
if !errors.Is(err, publicops.ErrNotOwner) {
t.Errorf("assignee refusal %v does not match ErrNotOwner", err)
}
if want := `cannot close ` + held + `: assignee is "holder", actor is "closer"; reclaim or use --force to override`; refusal.Error() != want {
t.Errorf("assignee refusal reads %q, want %q", refusal.Error(), want)
}
})
// The guard runs before close policy: a pinned parent with an open child
// reads the pin, not the open children.
refuses(pinnedParent, false, "pin-before-policy", func(err error) {
if !errors.Is(err, publicops.ErrPinned) {
t.Fatalf("unforced close of pinned parent %s with an open child: err = %v, want ErrPinned first", pinnedParent, err)
}
})
// The controls: an unassigned bead and the actor's own bead under another
// spelling of its identity close unforced.
for _, tc := range []struct{ id, actor string }{{unassigned, "closer"}, {respelled, "gastown_closer"}} {
result, err := fixture.Lifecycle.Close(ctx, publicops.CloseRequest{Actor: tc.actor, IssueID: tc.id})
if err != nil {
t.Fatalf("unforced close of %s by %s: %v, want it to land", tc.id, tc.actor, err)
}
if !result.Changed || result.Issue.Status != types.StatusClosed {
t.Errorf("unforced close of %s = %#v, want a committed close", tc.id, result)
}
}
// Force bypasses the pin and the assignee fence.
for _, id := range []string{statusPinned, flagPinned, held} {
result, err := fixture.Lifecycle.Close(ctx, publicops.CloseRequest{Actor: "closer", IssueID: id, Force: true})
if err != nil {
t.Fatalf("forced close of %s: %v, want force to bypass the guard", id, err)
}
if !result.Changed || result.Issue.Status != types.StatusClosed {
t.Errorf("forced close of %s = %#v, want a committed close", id, result)
}
}
// The forced close left pinned=true on the flag-pinned row; the plain retry
// is the idempotent re-close, not a pin refusal.
retry, err := fixture.Lifecycle.Close(ctx, publicops.CloseRequest{Actor: "closer", IssueID: flagPinned})
if err != nil {
t.Fatalf("plain re-close of the already-closed, still-pinned %s: %v, want the idempotent no-op", flagPinned, err)
}
if retry.Changed {
t.Errorf("plain re-close of %s reported Changed = true, want the no-op", flagPinned)
}
// The guard reads the plane the close writes.
if err := fixture.CreateWisp(ctx, &types.Issue{
ID: wisp, Title: wisp, Status: types.StatusOpen, Priority: 2, IssueType: types.TypeTask, Assignee: "holder", Ephemeral: true,
}, "seed"); err != nil {
t.Fatalf("seed wisp %s: %v", wisp, err)
}
if _, err := fixture.Lifecycle.Close(ctx, publicops.CloseRequest{Actor: "closer", IssueID: wisp}); !errors.As(err, new(*publicops.CloseNotAssigneeError)) {
t.Fatalf("unforced close of wisp %s held by another actor: err = %v, want *CloseNotAssigneeError", wisp, err)
}
var status string
if err := fixture.QueryScalar(ctx, "SELECT status FROM wisps WHERE id = ?", []any{wisp}, &status); err != nil {
t.Fatalf("read wisp %s status: %v", wisp, err)
}
if types.Status(status) != types.StatusOpen {
t.Errorf("wisp %s status after the refusal = %q, want it still open", wisp, status)
}
}

View file

@ -490,12 +490,6 @@ func RunLifecycleCreateWritesEveryScalarField(t *testing.T, ctx context.Context,
t.Errorf("%s created_at = %v after a create that named none, want a stamp between %v and %v — a bare non-empty check would accept the zero time",
stamped, autoStamp, lower, upper)
}
// And no created_by: the request's actor is the creator (CreateRequest.Issue),
// stamped by the role itself, so a library caller and every front door store
// the same value for the same request.
if got := lifecycleCreateRow(t, ctx, fixture, stamped).CreatedBy; got != "writer" {
t.Errorf("%s created_by = %q after a create that named none, want the request's actor %q", stamped, got, "writer")
}
want := []lifecycleCreateMember{
{"title", "created title"},
@ -810,54 +804,3 @@ func lifecycleCreatePlaneName(ephemeral bool) string {
}
return "durable"
}
// RunLifecycleCreateAppliesTheDefaultPriority pins
// CreateRequest.DefaultPriority: a create that asks for the default stores
// publicops.DefaultCreatePriority, and one that names priority 0 stores P0 —
// the zero value is a real priority, never "absent". Asking for the default
// while naming a priority is ErrValidation and writes nothing.
//
// It is the one place the default lives: `bd create` without --priority and an
// HTTP create without `priority` both reach it through this flag, so a backend
// that dropped it would store P0 (critical) for every such create.
func RunLifecycleCreateAppliesTheDefaultPriority(t *testing.T, ctx context.Context, fixture LifecycleCreateFixture) {
t.Helper()
defaulted := fixture.IssuePrefix + "-prio-default"
critical := fixture.IssuePrefix + "-prio-zero"
conflict := fixture.IssuePrefix + "-prio-conflict"
for _, tc := range []struct {
id string
priority int
useDefault bool
want int
}{
{id: defaulted, useDefault: true, want: publicops.DefaultCreatePriority},
{id: critical, priority: 0, want: 0},
} {
created, err := fixture.Lifecycle.Create(ctx, publicops.CreateRequest{
Actor: "writer",
DefaultPriority: tc.useDefault,
Issue: &types.Issue{ID: tc.id, Title: tc.id, Priority: tc.priority, IssueType: types.TypeTask},
})
if err != nil {
t.Fatalf("create %s: %v", tc.id, err)
}
if created.Issue.Priority != tc.want {
t.Errorf("create %s result priority = %d, want %d", tc.id, created.Issue.Priority, tc.want)
}
if got := lifecycleCreateRow(t, ctx, fixture, tc.id).Priority; got != tc.want {
t.Errorf("stored %s priority = %d, want %d", tc.id, got, tc.want)
}
}
_, err := fixture.Lifecycle.Create(ctx, publicops.CreateRequest{
Actor: "writer",
DefaultPriority: true,
Issue: &types.Issue{ID: conflict, Title: conflict, Priority: 3, IssueType: types.TypeTask},
})
if !errors.Is(err, storage.ErrValidation) {
t.Fatalf("DefaultPriority with priority 3: err = %v, want ErrValidation", err)
}
assertLifecycleCreateAbsent(t, ctx, fixture, conflict, "after the conflicting priority create")
}

View file

@ -1,170 +0,0 @@
package conformance
import (
"context"
"errors"
"fmt"
"strings"
"testing"
"time"
"github.com/steveyegge/beads/internal/types"
publicops "github.com/steveyegge/beads/issueops"
)
// This file and its two siblings (lifecycle_update_gate_contract.go,
// batch_apply_gate_contract.go) hold the gate-member clauses of Lifecycle.Create,
// Lifecycle.Update and BatchApplier: await_type, await_id, timeout and waiters
// on a create, await_id and waiters on a patch, and the one set of bounds every
// route refuses with a *publicops.GateFieldError.
//
// THE BOUNDS ARE THE COLUMNS', and the boundary is asserted from both sides: a
// value AT the bound lands whole, a value one past it is refused naming its
// member and writes nothing. await_type is VARCHAR(32) and await_id
// VARCHAR(255), both counted in characters, so each at-bound value is
// multi-byte — a byte count would refuse it. waiters is a TEXT column holding
// a JSON array, bounded in BYTES. A negative timeout is the one refusal that is
// not a width.
//
// NOTHING ELSE IS A RULE, and two cases say so: a gate member lands on an
// issue of any type (local `bd update --await-id` has always worked on any
// row), and waiters are stored as given, duplicates included (deduplication is
// the CLI's). A backend that grew a stricter rule fails here.
// gateFieldAtBoundAwaitType is a 32-character, 64-byte await_type.
var gateFieldAtBoundAwaitType = strings.Repeat("é", 32)
// gateFieldAtBoundAwaitID is a 255-character, 510-byte await_id.
var gateFieldAtBoundAwaitID = strings.Repeat("é", types.MaxFieldLen)
// gateFieldAtBoundWaiters is one waiter whose JSON array encoding is exactly
// types.MaxTextBytes bytes: the entry plus `["` and `"]`.
func gateFieldAtBoundWaiters() []string {
return []string{strings.Repeat("w", types.MaxTextBytes-4)}
}
// gateFieldOverBoundWaiters encodes to one byte past the TEXT column.
func gateFieldOverBoundWaiters() []string {
return []string{strings.Repeat("w", types.MaxTextBytes-3)}
}
// assertGateFieldError checks err is ErrValidation carried by a
// *publicops.GateFieldError naming field.
func assertGateFieldError(t *testing.T, err error, label, field string) {
t.Helper()
if !errors.Is(err, publicops.ErrValidation) {
t.Fatalf("%s: error = %v, want ErrValidation", label, err)
}
var fieldErr *publicops.GateFieldError
if !errors.As(err, &fieldErr) {
t.Fatalf("%s: error = %v, want a *GateFieldError naming %s", label, err, field)
}
if fieldErr.Field != field {
t.Errorf("%s: GateFieldError.Field = %q, want %q", label, fieldErr.Field, field)
}
}
// gateMembers renders the four gate members off an issue for comparison.
func gateMembers(issue *types.Issue) string {
waiters := issue.Waiters
if len(waiters) == 0 {
waiters = nil
}
return fmt.Sprintf("await_type=%q await_id=%q timeout=%s waiters=%q", issue.AwaitType, issue.AwaitID, issue.Timeout, waiters)
}
func assertGateMembers(t *testing.T, id, label string, issue *types.Issue, awaitType, awaitID string, timeout time.Duration, waiters []string) {
t.Helper()
if issue == nil {
t.Fatalf("%s %s: no issue to read the gate members off", id, label)
}
if len(waiters) == 0 {
waiters = nil
}
want := fmt.Sprintf("await_type=%q await_id=%q timeout=%s waiters=%q", awaitType, awaitID, timeout, waiters)
if got := gateMembers(issue); got != want {
// The at-bound values are long; report sizes rather than the values.
if len(got)+len(want) > 2000 {
t.Errorf("%s %s gate members differ (got %d bytes, want %d bytes; await_type %d/%d runes, await_id %d/%d runes, waiters %d/%d entries)",
id, label, len(got), len(want),
len([]rune(issue.AwaitType)), len([]rune(awaitType)), len([]rune(issue.AwaitID)), len([]rune(awaitID)),
len(issue.Waiters), len(waiters))
return
}
t.Errorf("%s %s gate members = %s, want %s", id, label, got, want)
}
}
// RunLifecycleCreateWritesTheGateMembers pins that Lifecycle.Create stores all
// four gate members (CreateRequest.Issue's "gate" fields) on the row and
// answers them on the result, with the waiter list stored as given, duplicate
// included, and on an issue that is not of the gate type.
func RunLifecycleCreateWritesTheGateMembers(t *testing.T, ctx context.Context, fixture LifecycleCreateFixture) {
t.Helper()
gate := fixture.IssuePrefix + "-lcg-gate"
issue := lifecycleCreateIssue(gate)
issue.IssueType = types.TypeGate
issue.AwaitType = "gh:run"
issue.AwaitID = "12345"
issue.Timeout = 90 * time.Minute
issue.Waiters = []string{"rig/workers/a", "rig/workers/b", "rig/workers/a"}
created, err := fixture.Lifecycle.Create(ctx, publicops.CreateRequest{Actor: "writer", ForceIDPrefix: true, Issue: issue})
if err != nil {
t.Fatalf("create gate %s: %v", gate, err)
}
want := []string{"rig/workers/a", "rig/workers/b", "rig/workers/a"}
assertGateMembers(t, gate, "in the create result", created.Issue, "gh:run", "12345", 90*time.Minute, want)
assertGateMembers(t, gate, "in the stored row", lifecycleCreateRow(t, ctx, fixture, gate), "gh:run", "12345", 90*time.Minute, want)
// Any type carries them: no gate-type-only rule.
task := fixture.IssuePrefix + "-lcg-task"
carrier := lifecycleCreateIssue(task)
carrier.AwaitType = "formula-defined"
carrier.AwaitID = "bead:" + gate
carrier.Waiters = []string{"mail:someone"}
if _, err := fixture.Lifecycle.Create(ctx, publicops.CreateRequest{Actor: "writer", ForceIDPrefix: true, Issue: carrier}); err != nil {
t.Fatalf("create task %s carrying gate members: %v", task, err)
}
assertGateMembers(t, task, "in the stored row", lifecycleCreateRow(t, ctx, fixture, task), "formula-defined", "bead:"+gate, 0, []string{"mail:someone"})
}
// RunLifecycleCreateBoundsTheGateMembers pins the four GateFieldError bounds
// on create from both sides: each at-bound value lands whole, each value one
// past it is refused as ErrValidation naming its member, and the refused
// create leaves no row.
func RunLifecycleCreateBoundsTheGateMembers(t *testing.T, ctx context.Context, fixture LifecycleCreateFixture) {
t.Helper()
atBound := fixture.IssuePrefix + "-lcg-atbound"
issue := lifecycleCreateIssue(atBound)
issue.IssueType = types.TypeGate
issue.AwaitType = gateFieldAtBoundAwaitType
issue.AwaitID = gateFieldAtBoundAwaitID
issue.Timeout = 0
issue.Waiters = gateFieldAtBoundWaiters()
if _, err := fixture.Lifecycle.Create(ctx, publicops.CreateRequest{Actor: "writer", ForceIDPrefix: true, Issue: issue}); err != nil {
t.Fatalf("create %s with every gate member at its bound: %v", atBound, err)
}
assertGateMembers(t, atBound, "in the stored row", lifecycleCreateRow(t, ctx, fixture, atBound),
gateFieldAtBoundAwaitType, gateFieldAtBoundAwaitID, 0, gateFieldAtBoundWaiters())
for _, test := range []struct {
name string
field string
mutate func(*types.Issue)
}{
{"await_type", publicops.GateFieldAwaitType, func(i *types.Issue) { i.AwaitType = gateFieldAtBoundAwaitType + "x" }},
{"await_id", publicops.GateFieldAwaitID, func(i *types.Issue) { i.AwaitID = gateFieldAtBoundAwaitID + "x" }},
{"timeout", publicops.GateFieldTimeout, func(i *types.Issue) { i.Timeout = -time.Nanosecond }},
{"waiters", publicops.GateFieldWaiters, func(i *types.Issue) { i.Waiters = gateFieldOverBoundWaiters() }},
} {
id := fixture.IssuePrefix + "-lcg-over-" + strings.ReplaceAll(test.name, "_", "")
refused := lifecycleCreateIssue(id)
refused.IssueType = types.TypeGate
test.mutate(refused)
_, err := fixture.Lifecycle.Create(ctx, publicops.CreateRequest{Actor: "writer", ForceIDPrefix: true, Issue: refused})
assertGateFieldError(t, err, "create with "+test.name+" past its bound", test.field)
assertLifecycleCreateAbsent(t, ctx, fixture, id, "after the refused "+test.name)
}
}

View file

@ -4,11 +4,8 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"reflect"
"slices"
"sort"
"sync"
"testing"
"time"
@ -908,385 +905,6 @@ func RunLifecycleUpdateConditionalGuardsGateOrdinaryEdits(t *testing.T, ctx cont
maskedEvents.assert(t, "guard masked by the one before it", 0)
}
// RunLifecycleUpdateExpectedVersionSingleWinnerUnderConcurrency pins A8's
// (gastownhall/beads#4682) headline claim about Lifecycle.Update's
// ExpectedVersion guard, for `bd update/close/assign/delete --if-revision`:
// the compare and the write are ONE atomic operation, not a read-then-write a
// concurrent writer can slip between (T4.4, BEADS-JOURNAL-PLAN.md Item 4). N
// goroutines race the SAME token — the row's version as of before any of them
// run — against the same row; exactly one may apply it, every other goroutine
// must see ErrVersionMismatch (never a second silent success), and the row
// that is left behind must be exactly the single winner's content, never a
// torn write belonging to neither the seed nor any one racer.
//
// THIS IS A GENUINE CONCURRENCY TEST, not N sequential attempts dressed up as
// parallel ones. cmd/bd's embedded-mode backend admits only one `bd` process
// at a time (an exclusive flock — see acquireEmbeddedLock in
// cmd/bd/store_factory.go), which would make "exactly one winner" trivially
// true even of a buggy read-then-write implementation with no atomicity at
// all, because no second process could ever observe the first one's
// in-flight state. That is why the CLI-level --if-revision tests
// (cmd/bd/if_revision_embedded_test.go) assert the match/mismatch CONTRACT
// sequentially and leave the race to this fixture: goroutines sharing one
// already-open Lifecycle are the one shape in this suite that can actually
// interleave at the transaction level, independent of whatever process-level
// serialization a given CLI backend layers on top.
func RunLifecycleUpdateExpectedVersionSingleWinnerUnderConcurrency(t *testing.T, ctx context.Context, fixture LifecycleUpdateFixture) {
t.Helper()
const racers = 16
id := fixture.IssuePrefix + "-lup-singlewinner"
seedLifecycleUpdateIssue(t, ctx, fixture, lifecycleUpdateIssue(id))
seed := lifecycleUpdateRow(t, ctx, fixture, id)
racedToken := seed.RowVersion
// Priority is a small enum (0-4, see validation.ValidatePriority); each
// racer's own index would overflow it past four racers, so the index rides
// in Notes instead (free-text, nothing else writes it in this test) and
// priority merely alternates, giving the final-state check two independent
// columns that must agree on which one racer actually landed.
var wg sync.WaitGroup
won := make([]bool, racers)
errs := make([]error, racers)
wg.Add(racers)
for i := 0; i < racers; i++ {
i := i
go func() {
defer wg.Done()
version := racedToken
result, err := fixture.Lifecycle.Update(ctx, publicops.UpdateRequest{
Actor: "racer",
IssueID: id,
Patch: publicops.IssuePatch{
Priority: publicops.Field[int]{Set: true, Value: i % 5},
Notes: publicops.Field[string]{Set: true, Value: fmt.Sprintf("racer-%d", i)},
},
ExpectedVersion: &version,
})
errs[i] = err
won[i] = err == nil && result.Changed
}()
}
wg.Wait()
winners := 0
winner := -1
for i, win := range won {
if win {
winners++
winner = i
continue
}
if !errors.Is(errs[i], storage.ErrVersionMismatch) {
t.Errorf("racer %d: err = %v, want nil (won) or ErrVersionMismatch (lost the race)", i, errs[i])
}
}
if winners != 1 {
t.Fatalf("%d racers shared one --if-revision token %d; got %d winners, want exactly 1 (errs=%v)",
racers, racedToken, winners, errs)
}
final := lifecycleUpdateRow(t, ctx, fixture, id)
wantNotes := fmt.Sprintf("racer-%d", winner)
if final.Notes != wantNotes {
t.Errorf("final notes = %q, want the single winner's %q — a torn or lost write", final.Notes, wantNotes)
}
if final.Priority != winner%5 {
t.Errorf("final priority = %d, want the single winner's %d — a torn or lost write", final.Priority, winner%5)
}
if final.RowVersion == racedToken {
t.Errorf("final row version = %d, want it to have advanced past the raced token %d", final.RowVersion, racedToken)
}
}
// RunLifecycleUpdateExpectedVersionSingleWinnerWithDisjointColumnsUnderConcurrency
// is RunLifecycleUpdateExpectedVersionSingleWinnerUnderConcurrency's sibling,
// and the reason that one is not enough on its own (mc-zndi7.76, gap 1).
//
// Every racer there writes the SAME two cells (Priority and Notes), so a
// backend whose storage layer auto-merges disjoint-cell changes from a common
// base — Dolt's native behavior — could pass that test on native cell-level
// conflict detection ALONE, with the ExpectedVersion/row_lock compare-and-swap
// doing nothing at all: sixteen racers colliding on one cell look identical to
// sixteen racers colliding on one ROW VERSION. A hand-applied mutant that
// reminted row_lock to an unconditional fresh random value on every write
// (rather than deriving it from, and checking it against, ExpectedVersion)
// still passed the shared-cell test on this suite's in-tree backends 3 of 3
// runs each, and only showed its true colors — 3 to 7 winners per round — on a
// real Dolt server CLI race with disjoint-column patches, which is the shape
// this case restores.
//
// Each racer here writes a column NO OTHER RACER TOUCHES, so Dolt's per-cell
// auto-merge cannot provide false mutual exclusion for any pair of them:
// whatever excludes all but one racer here has to be the row_lock/
// ExpectedVersion compare-and-swap itself, not an accident of which cells
// collide.
func RunLifecycleUpdateExpectedVersionSingleWinnerWithDisjointColumnsUnderConcurrency(t *testing.T, ctx context.Context, fixture LifecycleUpdateFixture) {
t.Helper()
type disjointField struct {
name string
apply func(*publicops.IssuePatch, string)
read func(*types.Issue) string
}
fields := []disjointField{
{"Description", func(p *publicops.IssuePatch, v string) { p.Description = publicops.Field[string]{Set: true, Value: v} }, func(i *types.Issue) string { return i.Description }},
{"Design", func(p *publicops.IssuePatch, v string) { p.Design = publicops.Field[string]{Set: true, Value: v} }, func(i *types.Issue) string { return i.Design }},
{"AcceptanceCriteria", func(p *publicops.IssuePatch, v string) {
p.AcceptanceCriteria = publicops.Field[string]{Set: true, Value: v}
}, func(i *types.Issue) string { return i.AcceptanceCriteria }},
{"Notes", func(p *publicops.IssuePatch, v string) { p.Notes = publicops.Field[string]{Set: true, Value: v} }, func(i *types.Issue) string { return i.Notes }},
{"SpecID", func(p *publicops.IssuePatch, v string) { p.SpecID = publicops.Field[string]{Set: true, Value: v} }, func(i *types.Issue) string { return i.SpecID }},
{"AwaitID", func(p *publicops.IssuePatch, v string) { p.AwaitID = publicops.Field[string]{Set: true, Value: v} }, func(i *types.Issue) string { return i.AwaitID }},
{"Owner", func(p *publicops.IssuePatch, v string) { p.Owner = publicops.Field[string]{Set: true, Value: v} }, func(i *types.Issue) string { return i.Owner }},
// Assignee rides the same Update/ExpectedVersion machinery `bd assign`
// dispatches onto (cmd/bd/mutate_proxied_server.go's proxiedAssign, and
// its direct-route twin), so a disjoint racer on this column is this
// suite's single-winner coverage for assign (mc-zndi7.76, gap 3): there
// is no separate Assign method on Lifecycle to race independently.
{"Assignee", func(p *publicops.IssuePatch, v string) { p.Assignee = publicops.Field[string]{Set: true, Value: v} }, func(i *types.Issue) string { return i.Assignee }},
}
racers := len(fields)
id := fixture.IssuePrefix + "-lup-singlewinner-disjoint"
seedLifecycleUpdateIssue(t, ctx, fixture, lifecycleUpdateIssue(id))
seed := lifecycleUpdateRow(t, ctx, fixture, id)
racedToken := seed.RowVersion
var wg sync.WaitGroup
won := make([]bool, racers)
errs := make([]error, racers)
wg.Add(racers)
for i := 0; i < racers; i++ {
i := i
go func() {
defer wg.Done()
version := racedToken
var patch publicops.IssuePatch
fields[i].apply(&patch, fmt.Sprintf("racer-%d-%s", i, fields[i].name))
result, err := fixture.Lifecycle.Update(ctx, publicops.UpdateRequest{
Actor: "racer",
IssueID: id,
Patch: patch,
ExpectedVersion: &version,
})
errs[i] = err
won[i] = err == nil && result.Changed
}()
}
wg.Wait()
winners := 0
winner := -1
for i, win := range won {
if win {
winners++
winner = i
continue
}
if !errors.Is(errs[i], storage.ErrVersionMismatch) {
t.Errorf("racer %d (%s): err = %v, want nil (won) or ErrVersionMismatch (lost the race)", i, fields[i].name, errs[i])
}
}
if winners != 1 {
t.Fatalf("%d racers on disjoint columns shared one --if-revision token %d; got %d winners, want exactly 1 (errs=%v)",
racers, racedToken, winners, errs)
}
final := lifecycleUpdateRow(t, ctx, fixture, id)
wantValue := fmt.Sprintf("racer-%d-%s", winner, fields[winner].name)
for i, f := range fields {
got := f.read(final)
if i == winner {
if got != wantValue {
t.Errorf("final %s = %q, want the single winner's %q — a torn or lost write", f.name, got, wantValue)
}
continue
}
if got != "" {
t.Errorf("final %s = %q, want empty — a disjoint loser's write was not supposed to apply (false mutual exclusion from native cell-merge, not the version guard)", f.name, got)
}
}
if final.RowVersion == racedToken {
t.Errorf("final row version = %d, want it to have advanced past the raced token %d", final.RowVersion, racedToken)
}
}
// RunLifecycleCloseExpectedVersionSingleWinnerUnderConcurrency is
// RunLifecycleUpdateExpectedVersionSingleWinnerUnderConcurrency's Close twin
// (mc-zndi7.76, gap 3): CloseRequest.ExpectedVersion rides the same row_lock
// compare-and-swap Update's does (CloseRequest.ExpectedVersion's doc), and
// until now nothing proved that under real concurrency for Close specifically.
// N racers close the SAME open issue racing the SAME pre-close token; exactly
// one may apply its close, every other racer must see ErrVersionMismatch (not
// the idempotent-reclose no-op — the token is stale by the time it would
// observe that), and the row left behind must be exactly the single winner's.
func RunLifecycleCloseExpectedVersionSingleWinnerUnderConcurrency(t *testing.T, ctx context.Context, fixture LifecycleUpdateFixture) {
t.Helper()
const racers = 16
id := fixture.IssuePrefix + "-lup-close-singlewinner"
seedLifecycleUpdateIssue(t, ctx, fixture, lifecycleUpdateIssue(id))
seed := lifecycleUpdateRow(t, ctx, fixture, id)
racedToken := seed.RowVersion
var wg sync.WaitGroup
won := make([]bool, racers)
errs := make([]error, racers)
wg.Add(racers)
for i := 0; i < racers; i++ {
i := i
go func() {
defer wg.Done()
version := racedToken
result, err := fixture.Lifecycle.Close(ctx, publicops.CloseRequest{
Actor: "racer",
IssueID: id,
Reason: fmt.Sprintf("racer-%d", i),
ExpectedVersion: &version,
})
errs[i] = err
won[i] = err == nil && result.Changed
}()
}
wg.Wait()
winners := 0
winner := -1
for i, win := range won {
if win {
winners++
winner = i
continue
}
if !errors.Is(errs[i], storage.ErrVersionMismatch) {
t.Errorf("racer %d: err = %v, want nil (won) or ErrVersionMismatch (lost the race)", i, errs[i])
}
}
if winners != 1 {
t.Fatalf("%d racers shared one close --if-revision token %d; got %d winners, want exactly 1 (errs=%v)",
racers, racedToken, winners, errs)
}
final := lifecycleUpdateRow(t, ctx, fixture, id)
if final.Status != types.StatusClosed {
t.Errorf("final status = %q, want closed", final.Status)
}
wantReason := fmt.Sprintf("racer-%d", winner)
if final.CloseReason != wantReason {
t.Errorf("final close reason = %q, want the single winner's %q — a torn or lost write", final.CloseReason, wantReason)
}
if final.RowVersion == racedToken {
t.Errorf("final row version = %d, want it to have advanced past the raced token %d", final.RowVersion, racedToken)
}
}
// RunLifecycleUpdateExpectedVersionSingleWinnerAcrossUpdateAndCloseUnderConcurrency
// is this suite's mixed-verb single-winner case (mc-zndi7.76, gap 3): Update
// and Close share one row_lock compare-and-swap, so a token raced across BOTH
// verbs at once must still admit exactly one winner, whichever verb it turns
// out to be — an exclusion mechanism keyed to the row rather than to a given
// verb's own code path. Delete is deliberately NOT a racer here: delete's
// production code does not remint row_lock on a deletion (nothing is left to
// remint), so it does not share this exclusion at all today. That is a real,
// separately tracked bug (the sibling delete bead, mc-zndi7.73) and not a gap
// in this test — folding Delete in here would either mask the bug behind
// Update/Close's real exclusion winning the race, or make this case flake
// red on current main, neither of which belongs in a test pinning what DOES
// work.
func RunLifecycleUpdateExpectedVersionSingleWinnerAcrossUpdateAndCloseUnderConcurrency(t *testing.T, ctx context.Context, fixture LifecycleUpdateFixture) {
t.Helper()
const racers = 8 // four Update racers, four Close racers, interleaved.
id := fixture.IssuePrefix + "-lup-mixed-singlewinner"
seedLifecycleUpdateIssue(t, ctx, fixture, lifecycleUpdateIssue(id))
seed := lifecycleUpdateRow(t, ctx, fixture, id)
racedToken := seed.RowVersion
type outcome struct {
kind string
changed bool
err error
}
outcomes := make([]outcome, racers)
var wg sync.WaitGroup
wg.Add(racers)
for i := 0; i < racers; i++ {
i := i
go func() {
defer wg.Done()
version := racedToken
if i%2 == 0 {
result, err := fixture.Lifecycle.Update(ctx, publicops.UpdateRequest{
Actor: "racer",
IssueID: id,
Patch: publicops.IssuePatch{
Owner: publicops.Field[string]{Set: true, Value: fmt.Sprintf("update-racer-%d", i)},
},
ExpectedVersion: &version,
})
outcomes[i] = outcome{kind: "update", changed: err == nil && result.Changed, err: err}
return
}
result, err := fixture.Lifecycle.Close(ctx, publicops.CloseRequest{
Actor: "racer",
IssueID: id,
Reason: fmt.Sprintf("close-racer-%d", i),
ExpectedVersion: &version,
})
outcomes[i] = outcome{kind: "close", changed: err == nil && result.Changed, err: err}
}()
}
wg.Wait()
winners := 0
winner := -1
for i, o := range outcomes {
if o.changed {
winners++
winner = i
continue
}
if !errors.Is(o.err, storage.ErrVersionMismatch) {
t.Errorf("racer %d (%s): err = %v, want nil (won) or ErrVersionMismatch (lost the race)", i, o.kind, o.err)
}
}
if winners != 1 {
t.Fatalf("%d update/close racers shared one --if-revision token %d; got %d winners, want exactly 1 (outcomes=%+v)",
racers, racedToken, winners, outcomes)
}
final := lifecycleUpdateRow(t, ctx, fixture, id)
switch outcomes[winner].kind {
case "update":
wantOwner := fmt.Sprintf("update-racer-%d", winner)
if final.Owner != wantOwner {
t.Errorf("final owner = %q, want the single winner's %q — a torn or lost write", final.Owner, wantOwner)
}
if final.Status == types.StatusClosed {
t.Errorf("the winning racer was an update, not a close; final status must not be closed")
}
case "close":
if final.Status != types.StatusClosed {
t.Errorf("final status = %q, want closed — the winning racer was a close", final.Status)
}
wantReason := fmt.Sprintf("close-racer-%d", winner)
if final.CloseReason != wantReason {
t.Errorf("final close reason = %q, want the single winner's %q — a torn or lost write", final.CloseReason, wantReason)
}
}
if final.RowVersion == racedToken {
t.Errorf("final row version = %d, want it to have advanced past the raced token %d", final.RowVersion, racedToken)
}
}
// RunLifecycleUpdateConditionalGuardAcceptsRespelledAssignee pins the
// ga-5ksp5 fix beside RunLifecycleUpdateConditionalGuardsGateOrdinaryEdits
// above rather than inside it: that test's later "order-dependent composition"
@ -1920,10 +1538,10 @@ func RunLifecycleUpdateParentIDReplacesEveryParent(t *testing.T, ctx context.Con
// RunLifecycleUpdatePersistentPreservesUnversionedClass pins the half of the
// Persistence clause nobody else asserts: "Persistent preserves an existing
// durable unversioned class" (issueops/issueops.go:149). The refusal beside
// it — an unversioned row cannot be demoted to a wisp mode — is
// RunLifecycleUpdateWispModesRefuseAnUnversionedRow; this clause says the legal
// direction is a no-op that does NOT normalize the row into versioned storage.
// durable unversioned class" (issueops/issueops.go:135-136). The refusal beside
// it — an unversioned row cannot be demoted to a wisp mode — is pinned
// elsewhere; this clause says the legal direction is a no-op that does NOT
// normalize the row into versioned storage.
//
// WHAT A PERSISTENCE RESTATEMENT MUST NOT DO is where the two observations come
// in. A persistence MOVE deletes the row from one plane and re-inserts it into
@ -1964,90 +1582,6 @@ func RunLifecycleUpdatePersistentPreservesUnversionedClass(t *testing.T, ctx con
assertLifecycleUpdateWispAbsent(t, ctx, fixture, id, "after the persistent restatement")
}
// RunLifecycleUpdateWispModesRefuseAnUnversionedRow pins the refusal beside
// that clause: Ephemeral and NoHistory "select wisp retention modes, never
// durable unversioned storage" (issueops/issueops.go:150-151), so an
// unversioned row asked for either is refused. The refusal is the request's,
// a deterministic validation failure, so it matches ErrValidation on every
// leg — over http that is the 400 naming the patch rather than a 500 that
// drops the reason and alerts the operator — and it leaves the row where it
// was: durable, still unversioned, and absent from the wisp plane.
func RunLifecycleUpdateWispModesRefuseAnUnversionedRow(t *testing.T, ctx context.Context, fixture LifecycleUpdateFixture) {
t.Helper()
id := fixture.IssuePrefix + "-lup-unversioned-wisp"
seeded := lifecycleUpdateIssue(id)
seeded.StorageClass = types.StorageClassUnversioned
seedLifecycleUpdateIssue(t, ctx, fixture, seeded)
for _, mode := range []publicops.PersistenceMode{publicops.PersistenceModeEphemeral, publicops.PersistenceModeNoHistory} {
label := "after the refused " + string(mode) + " move"
before := lifecycleUpdateRow(t, ctx, fixture, id)
if _, err := fixture.Lifecycle.Update(ctx, publicops.UpdateRequest{Actor: "writer", IssueID: id, Patch: publicops.IssuePatch{
Persistence: publicops.Field[publicops.PersistenceMode]{Set: true, Value: mode},
}}); !errors.Is(err, storage.ErrValidation) {
t.Fatalf("move unversioned %s to %s: error = %v, want ErrValidation", id, mode, err)
}
assertLifecycleUpdateRowUnchanged(t, ctx, fixture, id, label, before)
after := lifecycleUpdateRow(t, ctx, fixture, id)
if after.Ephemeral || after.NoHistory || after.StorageClass != types.StorageClassUnversioned {
t.Errorf("%s %s = {ephemeral %v, no-history %v, class %q}, want the durable unversioned row it was",
id, label, after.Ephemeral, after.NoHistory, after.StorageClass)
}
assertLifecycleUpdateWispAbsent(t, ctx, fixture, id, label)
}
}
// RunLifecycleUpdatePersistentPromotesAWisp pins the move `bd promote` makes
// (issueops.Promote): Persistence = persistent on an ephemeral wisp is a
// MUTATION that leaves the row on the durable plane under the same id, with
// its labels carried across and nothing left behind on the wisp plane. A
// second identical request is the no-op the "same current mode" clause
// promises, which is how Promote tells a lost race from a promotion.
func RunLifecycleUpdatePersistentPromotesAWisp(t *testing.T, ctx context.Context, fixture LifecycleUpdateFixture) {
t.Helper()
if fixture.CreateWisp == nil {
t.Skip("fixture has no CreateWisp: this backend has no wisp plane to promote from")
}
id := fixture.IssuePrefix + "-lup-promote"
seedLifecycleUpdateWisp(t, ctx, fixture, lifecycleUpdateIssue(id, "keep-me"))
if got := lifecycleUpdateRow(t, ctx, fixture, id); !got.Ephemeral {
t.Fatalf("seeded %s is not ephemeral; the case has nothing to promote", id)
}
promote := publicops.UpdateRequest{Actor: "writer", IssueID: id, Patch: publicops.IssuePatch{
Persistence: publicops.Field[publicops.PersistenceMode]{Set: true, Value: publicops.PersistenceModePersistent},
}}
promoted, err := fixture.Lifecycle.Update(ctx, promote)
if err != nil {
t.Fatalf("promote %s: %v", id, err)
}
if !promoted.Changed {
t.Errorf("promoting wisp %s reported Changed = false, want a mutation", id)
}
if promoted.Issue == nil || promoted.Issue.ID != id || promoted.Issue.Ephemeral {
t.Errorf("promote result issue = %+v, want %s on the durable plane", promoted.Issue, id)
}
after := lifecycleUpdateRow(t, ctx, fixture, id)
if after.Ephemeral || after.NoHistory {
t.Errorf("%s came back {ephemeral %v, no-history %v} after the promotion, want a durable-plane row", id, after.Ephemeral, after.NoHistory)
}
if !slices.Contains(after.Labels, "keep-me") {
t.Errorf("%s labels after the promotion = %v, want the wisp's label carried across", id, after.Labels)
}
assertLifecycleUpdateWispAbsent(t, ctx, fixture, id, "after the promotion")
again, err := fixture.Lifecycle.Update(ctx, promote)
if err != nil {
t.Fatalf("re-promote %s: %v", id, err)
}
if again.Changed {
t.Errorf("re-promoting durable %s reported Changed = true, want the same-mode no-op", id)
}
}
// RunLifecycleUpdateProvenanceLabelsHistory pins UpdateRequest.Provenance
// against the history the backend actually writes
// (issueops/issueops.go:261-270): the entry reads as the caller's own string,
@ -2604,134 +2138,3 @@ func lifecycleUpdateHasEdge(dependencies []*types.Dependency, wantTarget string)
}
return false
}
// RunLifecycleUpdateRefusesATemplate pins Lifecycle.Update's template guard:
// templates are read-only, so EVERY update naming one refuses with
// *TemplateReadOnlyError — a field edit, a label edit, a claim, a status
// crossing — whatever force flags ride along, and nothing is written. It is the
// guard `bd update` used to apply as a CLI pre-read, which left bd serve and
// library callers editing templates bd refused.
//
// The refusal is asserted at the level a caller acts on — the typed error, its
// sentinel and the sentence bd prints, read off the typed error because a
// served refusal wraps it — and the row is read back to prove nothing moved.
// Two controls: the same patches land on an ordinary sibling, so the guard is
// not refusing the patch shapes; and a stale ExpectedVersion on the template
// still reports the mismatch, so the guard runs after the compare-and-set
// preconditions like every other update fence.
func RunLifecycleUpdateRefusesATemplate(t *testing.T, ctx context.Context, fixture LifecycleUpdateFixture) {
t.Helper()
template := fixture.IssuePrefix + "-lut-template"
sibling := fixture.IssuePrefix + "-lut-sibling"
for _, issue := range []*types.Issue{
{ID: template, IsTemplate: true},
{ID: sibling},
} {
issue.Title, issue.Status, issue.Priority, issue.IssueType = issue.ID, types.StatusOpen, 2, types.TypeTask
if err := fixture.CreateIssue(ctx, issue, "seed"); err != nil {
t.Fatalf("seed %s: %v", issue.ID, err)
}
}
before, err := fixture.GetIssue(ctx, template)
if err != nil {
t.Fatalf("read seeded template %s: %v", template, err)
}
requests := []struct {
name string
request publicops.UpdateRequest
}{
{name: "field edit", request: publicops.UpdateRequest{
Patch: publicops.IssuePatch{Title: publicops.Field[string]{Set: true, Value: "edited"}},
}},
{name: "label edit", request: publicops.UpdateRequest{
Patch: publicops.IssuePatch{Labels: publicops.LabelPatch{Add: []string{"lut-tag"}}},
}},
{name: "claim", request: publicops.UpdateRequest{Claim: true}},
{name: "forced status crossing", request: publicops.UpdateRequest{
Patch: publicops.IssuePatch{Status: publicops.Field[publicops.Status]{Set: true, Value: types.StatusClosed}},
ForceClosePolicy: true,
}},
{name: "forced assignee transfer", request: publicops.UpdateRequest{
Patch: publicops.IssuePatch{Assignee: publicops.Field[string]{Set: true, Value: "someone"}},
ForceAssigneeTransfer: true,
}},
}
for _, tc := range requests {
request := tc.request
request.Actor, request.IssueID = "writer", template
_, err := fixture.Lifecycle.Update(ctx, request)
var refusal *publicops.TemplateReadOnlyError
if !errors.As(err, &refusal) {
t.Fatalf("%s on template %s: err = %v, want *TemplateReadOnlyError", tc.name, template, err)
}
if refusal.IssueID != template || !errors.Is(err, publicops.ErrTemplateReadOnly) {
t.Errorf("%s refusal = %#v (%v), want IssueID %q matching ErrTemplateReadOnly", tc.name, refusal, err, template)
}
if want := "cannot modify template " + template + ": templates are read-only; use 'bd mol pour' to create a work item"; refusal.Error() != want {
t.Errorf("%s refusal reads %q, want %q", tc.name, refusal.Error(), want)
}
after, err := fixture.GetIssue(ctx, template)
if err != nil {
t.Fatalf("read template %s after the %s refusal: %v", template, tc.name, err)
}
if after.RowVersion != before.RowVersion || after.Title != before.Title || after.Status != before.Status ||
after.Assignee != before.Assignee || len(after.Labels) != len(before.Labels) {
t.Errorf("template %s after the %s refusal = %+v, want it unchanged from %+v", template, tc.name, after, before)
}
control := tc.request
control.Actor, control.IssueID = "writer", sibling
if _, err := fixture.Lifecycle.Update(ctx, control); err != nil {
t.Errorf("%s on the ordinary sibling %s: %v, want it to land", tc.name, sibling, err)
}
}
stale := before.RowVersion + 1
_, err = fixture.Lifecycle.Update(ctx, publicops.UpdateRequest{
Actor: "writer", IssueID: template, ExpectedVersion: &stale,
Patch: publicops.IssuePatch{Title: publicops.Field[string]{Set: true, Value: "edited"}},
})
if !errors.Is(err, publicops.ErrVersionMismatch) {
t.Errorf("stale-guarded update of template %s: err = %v, want ErrVersionMismatch ahead of the template guard", template, err)
}
}
// RunLifecycleUpdateAllowTemplateEditsATemplate pins the template guard's one
// stand-down: an update with AllowTemplate — what bd label and bd set-state
// send, since they have always edited templates — lands on a template, and
// only that request is waived (the same patch without it still refuses).
func RunLifecycleUpdateAllowTemplateEditsATemplate(t *testing.T, ctx context.Context, fixture LifecycleUpdateFixture) {
t.Helper()
template := fixture.IssuePrefix + "-lua-template"
issue := &types.Issue{ID: template, Title: template, Status: types.StatusOpen, Priority: 2, IssueType: types.TypeTask, IsTemplate: true}
if err := fixture.CreateIssue(ctx, issue, "seed"); err != nil {
t.Fatalf("seed %s: %v", template, err)
}
result, err := fixture.Lifecycle.Update(ctx, publicops.UpdateRequest{
Actor: "writer", IssueID: template, AllowTemplate: true,
Patch: publicops.IssuePatch{Labels: publicops.LabelPatch{Add: []string{"lua-tag"}}},
})
if err != nil {
t.Fatalf("AllowTemplate label edit on template %s: %v, want it to land", template, err)
}
if !result.Changed || result.Issue == nil || !lifecycleUpdateHasLabel(result.Issue.Labels, "lua-tag") {
t.Errorf("AllowTemplate label edit on template %s = %+v, want a change carrying lua-tag", template, result)
}
after, err := fixture.GetIssue(ctx, template)
if err != nil {
t.Fatalf("read template %s: %v", template, err)
}
if !after.IsTemplate {
t.Errorf("template %s is no longer a template after an AllowTemplate edit", template)
}
_, err = fixture.Lifecycle.Update(ctx, publicops.UpdateRequest{
Actor: "writer", IssueID: template,
Patch: publicops.IssuePatch{Labels: publicops.LabelPatch{Add: []string{"lua-other"}}},
})
if !errors.Is(err, publicops.ErrTemplateReadOnly) {
t.Errorf("the same edit without AllowTemplate: err = %v, want ErrTemplateReadOnly", err)
}
}

View file

@ -1,133 +0,0 @@
package conformance
import (
"context"
"testing"
"time"
publicops "github.com/steveyegge/beads/issueops"
)
// The patch half of the gate-member clauses; see lifecycle_create_gate_contract.go.
// RunLifecycleUpdatePatchesTheGateMembers pins IssuePatch.AwaitID and
// IssuePatch.Waiters: a set value lands and is answered on the result, waiters
// is a WHOLE-VALUE replacement stored as given (duplicates kept), a same-value
// patch is a no-op, a clear (empty await_id, nil waiters) empties both, and a
// second clear is a no-op. await_type and timeout are not patch members, so
// they ride through every edit untouched. The row is a task: no gate-type-only
// rule.
func RunLifecycleUpdatePatchesTheGateMembers(t *testing.T, ctx context.Context, fixture LifecycleUpdateFixture) {
t.Helper()
id := fixture.IssuePrefix + "-lug-gate"
seeded := lifecycleUpdateIssue(id)
seeded.AwaitType = "timer"
seeded.AwaitID = "seeded-await"
seeded.Timeout = time.Minute
seeded.Waiters = []string{"seeded"}
seedLifecycleUpdateIssue(t, ctx, fixture, seeded)
patch := publicops.IssuePatch{
AwaitID: publicops.Field[string]{Set: true, Value: "run-42"},
Waiters: publicops.Field[[]string]{Set: true, Value: []string{"w1", "w2", "w1"}},
}
wantWaiters := []string{"w1", "w2", "w1"}
updated, err := fixture.Lifecycle.Update(ctx, publicops.UpdateRequest{Actor: "writer", IssueID: id, Patch: patch})
if err != nil {
t.Fatalf("patch the gate members of %s: %v", id, err)
}
if !updated.Changed {
t.Errorf("patching the gate members of %s reported Changed = false, want a committed edit", id)
}
assertGateMembers(t, id, "in the update result", updated.Issue, "timer", "run-42", time.Minute, wantWaiters)
assertGateMembers(t, id, "in the stored row", lifecycleUpdateRow(t, ctx, fixture, id), "timer", "run-42", time.Minute, wantWaiters)
after := lifecycleUpdateRow(t, ctx, fixture, id)
again, err := fixture.Lifecycle.Update(ctx, publicops.UpdateRequest{Actor: "writer", IssueID: id, Patch: patch})
if err != nil {
t.Fatalf("re-apply the same gate patch to %s: %v", id, err)
}
if again.Changed {
t.Errorf("re-applying the same gate patch to %s reported Changed = true, want false", id)
}
assertLifecycleUpdateRowUnchanged(t, ctx, fixture, id, "after the same-value gate patch", after)
clear := publicops.UpdateRequest{Actor: "writer", IssueID: id, Patch: publicops.IssuePatch{
AwaitID: publicops.Field[string]{Set: true},
Waiters: publicops.Field[[]string]{Set: true},
}}
cleared, err := fixture.Lifecycle.Update(ctx, clear)
if err != nil {
t.Fatalf("clear the gate members of %s: %v", id, err)
}
if !cleared.Changed {
t.Errorf("clearing the gate members of %s reported Changed = false, want a committed edit", id)
}
assertGateMembers(t, id, "in the clear's result", cleared.Issue, "timer", "", time.Minute, nil)
assertGateMembers(t, id, "in the cleared row", lifecycleUpdateRow(t, ctx, fixture, id), "timer", "", time.Minute, nil)
afterClear := lifecycleUpdateRow(t, ctx, fixture, id)
reclear, err := fixture.Lifecycle.Update(ctx, clear)
if err != nil {
t.Fatalf("re-clear the gate members of %s: %v", id, err)
}
if reclear.Changed {
t.Errorf("re-clearing the already-empty gate members of %s reported Changed = true, want false", id)
}
assertLifecycleUpdateRowUnchanged(t, ctx, fixture, id, "after the re-clear", afterClear)
// An explicitly empty list clears exactly as a nil one does.
if _, err := fixture.Lifecycle.Update(ctx, publicops.UpdateRequest{Actor: "writer", IssueID: id, Patch: publicops.IssuePatch{
Waiters: publicops.Field[[]string]{Set: true, Value: []string{"back"}},
}}); err != nil {
t.Fatalf("re-set the waiters of %s: %v", id, err)
}
if _, err := fixture.Lifecycle.Update(ctx, publicops.UpdateRequest{Actor: "writer", IssueID: id, Patch: publicops.IssuePatch{
Waiters: publicops.Field[[]string]{Set: true, Value: []string{}},
}}); err != nil {
t.Fatalf("clear the waiters of %s with an empty list: %v", id, err)
}
assertGateMembers(t, id, "after the empty-list clear", lifecycleUpdateRow(t, ctx, fixture, id), "timer", "", time.Minute, nil)
}
// RunLifecycleUpdateBoundsTheGateMembers pins the patch half of the
// GateFieldError bounds from both sides: at-bound await_id and waiters land
// whole, one past either is refused as ErrValidation naming its member, and
// the refusal writes nothing — not the gate member, and not an ordinary member
// riding in the same patch.
func RunLifecycleUpdateBoundsTheGateMembers(t *testing.T, ctx context.Context, fixture LifecycleUpdateFixture) {
t.Helper()
id := fixture.IssuePrefix + "-lug-bounds"
seedLifecycleUpdateIssue(t, ctx, fixture, lifecycleUpdateIssue(id))
if _, err := fixture.Lifecycle.Update(ctx, publicops.UpdateRequest{Actor: "writer", IssueID: id, Patch: publicops.IssuePatch{
AwaitID: publicops.Field[string]{Set: true, Value: gateFieldAtBoundAwaitID},
Waiters: publicops.Field[[]string]{Set: true, Value: gateFieldAtBoundWaiters()},
}}); err != nil {
t.Fatalf("patch %s with await_id and waiters at their bounds: %v", id, err)
}
assertGateMembers(t, id, "in the stored row", lifecycleUpdateRow(t, ctx, fixture, id), "", gateFieldAtBoundAwaitID, 0, gateFieldAtBoundWaiters())
before := lifecycleUpdateRow(t, ctx, fixture, id)
for _, test := range []struct {
name string
field string
patch publicops.IssuePatch
}{
{"await_id", publicops.GateFieldAwaitID, publicops.IssuePatch{
Title: publicops.Field[string]{Set: true, Value: "must not land"},
AwaitID: publicops.Field[string]{Set: true, Value: gateFieldAtBoundAwaitID + "x"},
}},
{"waiters", publicops.GateFieldWaiters, publicops.IssuePatch{
Title: publicops.Field[string]{Set: true, Value: "must not land"},
Waiters: publicops.Field[[]string]{Set: true, Value: gateFieldOverBoundWaiters()},
}},
} {
_, err := fixture.Lifecycle.Update(ctx, publicops.UpdateRequest{Actor: "writer", IssueID: id, Patch: test.patch})
assertGateFieldError(t, err, "patch with "+test.name+" past its bound", test.field)
assertLifecycleUpdateRowUnchanged(t, ctx, fixture, id, "after the refused "+test.name, before)
assertGateMembers(t, id, "after the refused "+test.name, lifecycleUpdateRow(t, ctx, fixture, id), "", gateFieldAtBoundAwaitID, 0, gateFieldAtBoundWaiters())
}
}

View file

@ -233,11 +233,14 @@ func RunMemoriesRememberWithExplicitKeyStoresVerbatim(t *testing.T, ctx context.
}
// RunMemoriesRememberReplacesAndReportsIt pins
// memoryops.RememberResult.Replaced against row presence.
// memoryops.RememberResult.Replaced, including the leg that makes it different
// from RecallResult.Found.
//
// Three legs: a first write reports false, a second reports true and REPLACES
// rather than appends, and a write over an out-of-band EMPTY row reports true.
// The third is the one a body computing `previous != ""` gets wrong.
// rather than appends, and a write over an out-of-band EMPTY row reports true
// even though a Recall of that key would have reported Found false. The third
// is the divergence the leaf doc states — Replaced is about the ROW — and it is
// the one a body computing `previous != ""` gets wrong.
func RunMemoriesRememberReplacesAndReportsIt(t *testing.T, ctx context.Context, fixture MemoriesFixture) {
t.Helper()
neighbors := seedMemoriesAllFourClasses(t, ctx, fixture)
@ -259,7 +262,7 @@ func RunMemoriesRememberReplacesAndReportsIt(t *testing.T, ctx context.Context,
if err := fixture.SetConfig(ctx, "kv.memory."+emptied, ""); err != nil {
t.Fatalf("seed an empty memory row out of band: %v", err)
}
assertMemoriesRecall(t, ctx, fixture, emptied, "", true)
assertMemoriesRecall(t, ctx, fixture, emptied, "", false)
overEmpty := rememberMemory(t, ctx, fixture, memoryops.RememberRequest{Key: emptied, Content: "now it has content"})
if !overEmpty.Replaced {
t.Fatalf("Remember over a row stored EMPTY reported Replaced false: Replaced is about the row, " +
@ -371,8 +374,8 @@ func RunMemoriesRecallAnswersTheStoredValue(t *testing.T, ctx context.Context, f
}
// RunMemoriesRecallReportsAMissAsNotFoundNotAnError pins the decision recorded
// in memoryops/errors.go: absence is a result callers inspect, not an
// operational error they must classify.
// in memoryops/errors.go: there is no ErrNotFound on this role, because the
// seam beneath it cannot see the difference the error would claim.
func RunMemoriesRecallReportsAMissAsNotFoundNotAnError(t *testing.T, ctx context.Context, fixture MemoriesFixture) {
t.Helper()
seedMemoriesAllFourClasses(t, ctx, fixture)
@ -398,70 +401,33 @@ func RunMemoriesRecallReportsAMissAsNotFoundNotAnError(t *testing.T, ctx context
}
}
// RunMemoriesEmptyRowIsPresentUntilForgotten pins presence to the ROW rather
// than to whether its value is non-empty. No front door creates an empty
// memory, but out-of-band config writes and older workspaces can contain one,
// and it must remain addressable through Recall and Forget.
// RunMemoriesRecallConflatesStoredEmptyWithAbsent pins
// memoryops.RecallResult.Found's central claim, and the one asymmetry that lets
// a caller see past it: List enumerates the key, because the ROW exists.
//
// The second Forget is the retry leg: after the first call deletes the row, it
// reports a genuine miss and records no further history.
func RunMemoriesEmptyRowIsPresentUntilForgotten(t *testing.T, ctx context.Context, fixture MemoriesFixture) {
// That is the same same-answer-different-row shape the settings contract pins
// for `bd config get`, and stating it is what keeps a backend from "fixing" it
// on one leg and making the answer depend on the route.
func RunMemoriesRecallConflatesStoredEmptyWithAbsent(t *testing.T, ctx context.Context, fixture MemoriesFixture) {
t.Helper()
neighbors := seedMemoriesAllFourClasses(t, ctx, fixture)
seedMemoriesAllFourClasses(t, ctx, fixture)
emptied := fixture.IssuePrefix + "-stored-empty"
never := fixture.IssuePrefix + "-never-stored"
if err := fixture.SetConfig(ctx, "kv.memory."+emptied, ""); err != nil {
t.Fatalf("seed an empty memory row out of band: %v", err)
}
assertMemoriesRecall(t, ctx, fixture, emptied, "", true)
assertMemoriesRecall(t, ctx, fixture, emptied, "", false)
assertMemoriesRecall(t, ctx, fixture, never, "", false)
plane := listMemories(t, ctx, fixture, "")
if value, ok := plane[emptied]; !ok || value != "" {
t.Fatalf("List[%q] = %q (present=%v), want an enumerated empty value", emptied, value, ok)
t.Fatalf("List[%q] = %q (present=%v), want an empty value that IS enumerated: "+
"the row exists even though Recall denies it", emptied, value, ok)
}
if _, ok := plane[never]; ok {
t.Fatalf("List carries %q, which nothing stored", never)
}
first := forgetMemory(t, ctx, fixture, emptied)
if !first.Found || first.Value != "" {
t.Fatalf("first Forget(%q) = %+v, want Found true with the empty stored value", emptied, first)
}
assertMemoriesRawAbsent(t, ctx, fixture, "kv.memory."+emptied)
assertMemoriesNeighborsSurvived(t, ctx, fixture, neighbors)
var afterFirst int
if fixture.CountHistory != nil {
var err error
afterFirst, err = fixture.CountHistory(ctx)
if err != nil {
t.Fatalf("CountHistory after first Forget: %v", err)
}
}
second := forgetMemory(t, ctx, fixture, emptied)
if second.Found || second.Value != "" {
t.Fatalf("second Forget(%q) = %+v, want Found false with no value", emptied, second)
}
assertMemoriesRawAbsent(t, ctx, fixture, "kv.memory."+emptied)
assertMemoriesNeighborsSurvived(t, ctx, fixture, neighbors)
// The no-write half of the retry is the only leg that needs history, which
// is why it comes last: a backend that cannot observe history has run every
// other leg by here, and SKIPS this one with that reason, as the
// MemoriesFixture.CountHistory doc promises, rather than passing quietly.
if fixture.CountHistory == nil {
t.Skip("this backend cannot observe history, so the no-write half of the retry is unobservable here")
}
afterSecond, err := fixture.CountHistory(ctx)
if err != nil {
t.Fatalf("CountHistory after second Forget: %v", err)
}
if afterSecond != afterFirst {
t.Fatalf("history entries went %d -> %d across the second Forget, want no write", afterFirst, afterSecond)
}
}
// RunMemoriesForgetRemovesExactlyTheNamedRow IS THE QUADRANT CASE, and the
@ -562,7 +528,13 @@ func RunMemoriesForgetReportsTheForgottenValue(t *testing.T, ctx context.Context
// RunMemoriesForgetOfAnAbsentKeyIsNotFoundAndDeletesNothing pins that a miss is
// a RESULT and not an error, that it changes no row anywhere in the table, that
// the second call — the one a retrying caller actually makes — answers the same
// way.
// way, and that the SECOND kind of miss behaves like the first: a memory stored
// as the empty string is Found false, and its row is left standing.
//
// That last leg is memoryops.ForgetResult.Found's parenthesis, and it keeps
// Forget's answer and Recall's answer the same statement. A body that deleted
// on "the row is there" rather than on "Recall would find it" would report
// nothing removed while removing something.
//
// The whole-table row count is the assertion that matters: "the key is still
// absent" would pass on a delete that swept a neighboring plane.
@ -570,6 +542,10 @@ func RunMemoriesForgetOfAnAbsentKeyIsNotFoundAndDeletesNothing(t *testing.T, ctx
t.Helper()
neighbors := seedMemoriesAllFourClasses(t, ctx, fixture)
key := fixture.IssuePrefix + "-never-stored-forget"
emptied := fixture.IssuePrefix + "-empty-forget"
if err := fixture.SetConfig(ctx, "kv.memory."+emptied, ""); err != nil {
t.Fatalf("seed an empty memory row out of band: %v", err)
}
var before int
if err := fixture.QueryScalar(ctx, "SELECT COUNT(*) FROM config", nil, &before); err != nil {
@ -577,12 +553,14 @@ func RunMemoriesForgetOfAnAbsentKeyIsNotFoundAndDeletesNothing(t *testing.T, ctx
}
for attempt := 1; attempt <= 2; attempt++ {
result, err := fixture.Memories.Forget(ctx, memoryops.ForgetRequest{Key: key})
if err != nil {
t.Fatalf("Forget(%q) attempt %d = %v, want success with Found false", key, attempt, err)
}
if result.Found || result.Value != "" {
t.Fatalf("Forget(%q) attempt %d = %+v, want Found false and no value", key, attempt, result)
for _, miss := range []string{key, emptied} {
result, err := fixture.Memories.Forget(ctx, memoryops.ForgetRequest{Key: miss})
if err != nil {
t.Fatalf("Forget(%q) attempt %d = %v, want success with Found false", miss, attempt, err)
}
if result.Found || result.Value != "" {
t.Fatalf("Forget(%q) attempt %d = %+v, want Found false and no value", miss, attempt, result)
}
}
}
@ -591,8 +569,11 @@ func RunMemoriesForgetOfAnAbsentKeyIsNotFoundAndDeletesNothing(t *testing.T, ctx
t.Fatalf("count config rows after: %v", err)
}
if after != before {
t.Fatalf("config rows went %d -> %d across two forgets that found nothing, want no change", before, after)
t.Fatalf("config rows went %d -> %d across four forgets that found nothing, want no change", before, after)
}
// The stored-empty row is specifically still there: Found false said nothing
// was removed, and that has to be true of the row as well as of the answer.
assertMemoriesRawValue(t, ctx, fixture, "kv.memory."+emptied, "")
assertMemoriesNeighborsSurvived(t, ctx, fixture, neighbors)
// The empty key is a refusal, not a miss.

View file

@ -1,480 +0,0 @@
package conformance
import (
"context"
"errors"
"testing"
"github.com/steveyegge/beads/internal/types"
publicops "github.com/steveyegge/beads/issueops"
)
// This file holds the contract for the molecule operations every backend
// serves through one library entry each:
//
// - CloseRequest.AutoCloseMolecule / CloseBatchRequest.AutoCloseMolecule —
// the close closes the molecule root it completed IN ITS OWN TRANSACTION
// (internal/storage/issueops.CloseCompletedMoleculeInTx on the store
// backends, uow.CloseCompletedMoleculeInUOW on the unit of work, the
// server's own on http). Opt-in; unforced; guarded on the root revision.
// - issueops.MoleculeStepper — the advance behind `bd close --continue`,
// whose claim is a real claim (assignee = Actor) that never takes a step
// another actor holds.
//
// THE LEAF DOC COMMENTS ARE THE SPEC (issueops/issueops.go CloseRequest,
// issueops/batchcloser.go, issueops/moleculestepper.go, issueops/molecule.go).
// MoleculeFixture supplies adapter-specific storage access for the molecule
// assertions.
type MoleculeFixture struct {
// IssuePrefix namespaces the ids each assertion seeds.
IssuePrefix string
Lifecycle publicops.Lifecycle
BatchCloser publicops.BatchCloser
Stepper publicops.MoleculeStepper
// CreateIssue and CreateWisp seed one row in the issues and wisps plane.
CreateIssue func(context.Context, *types.Issue, string) error
CreateWisp func(context.Context, *types.Issue, string) error
// AddDependency seeds one edge.
AddDependency func(context.Context, *types.Dependency, string) error
// QueryScalar runs a single-row query and scans it.
QueryScalar func(context.Context, string, []any, ...any) error
}
const moleculeActor = "molecule-contract"
type moleculeSeed struct {
t *testing.T
ctx context.Context
fixture MoleculeFixture
}
func (s moleculeSeed) issue(id string, typ types.IssueType, status types.Status, ephemeral bool, labels ...string) {
s.t.Helper()
issue := &types.Issue{ID: id, Title: "molecule " + id, IssueType: typ, Status: status, Priority: 2, Labels: labels, Ephemeral: ephemeral}
if status == types.StatusClosed {
issue.CloseReason = "seeded closed"
}
create := s.fixture.CreateIssue
if ephemeral {
create = s.fixture.CreateWisp
}
if err := create(s.ctx, issue, moleculeActor); err != nil {
s.t.Fatalf("seed %s: %v", id, err)
}
}
func (s moleculeSeed) edge(from, to string, typ types.DependencyType) {
s.t.Helper()
if err := s.fixture.AddDependency(s.ctx, &types.Dependency{IssueID: from, DependsOnID: to, Type: typ}, moleculeActor); err != nil {
s.t.Fatalf("seed edge %s -> %s: %v", from, to, err)
}
}
// row reads id's status and assignee from whichever plane holds it.
func (s moleculeSeed) row(id string) (status, assignee string) {
s.t.Helper()
err := s.fixture.QueryScalar(s.ctx,
`SELECT status, COALESCE(assignee, '') FROM issues WHERE id = ?
UNION ALL SELECT status, COALESCE(assignee, '') FROM wisps WHERE id = ?`,
[]any{id, id}, &status, &assignee)
if err != nil {
s.t.Fatalf("read %s: %v", id, err)
}
return status, assignee
}
// molecule seeds root <- step1 (closed), step2 (open) and answers the ids.
func (s moleculeSeed) molecule(name string, rootType types.IssueType, ephemeral bool, labels ...string) (root, done, last string) {
s.t.Helper()
root = s.fixture.IssuePrefix + "-" + name
done, last = root+".1", root+".2"
s.issue(root, rootType, types.StatusOpen, ephemeral, labels...)
s.issue(done, types.TypeTask, types.StatusClosed, ephemeral)
s.issue(last, types.TypeTask, types.StatusOpen, ephemeral)
s.edge(done, root, types.DepParentChild)
s.edge(last, root, types.DepParentChild)
return root, done, last
}
func (s moleculeSeed) closeStep(id string, autoClose bool) publicops.CloseResult {
s.t.Helper()
res, err := s.fixture.Lifecycle.Close(s.ctx, publicops.CloseRequest{
Actor: moleculeActor, IssueID: id, Reason: "step done", Session: "molecule-session", AutoCloseMolecule: autoClose,
})
if err != nil {
s.t.Fatalf("close %s: %v", id, err)
}
return res
}
// RunMoleculeCloseAutoClosesTheCompletedRoot pins CloseRequest.AutoCloseMolecule:
// closing the last open step closes an auto-closing root in the same call,
// reports it, and records the auto-close reason.
func RunMoleculeCloseAutoClosesTheCompletedRoot(t *testing.T, ctx context.Context, fixture MoleculeFixture) {
t.Helper()
s := moleculeSeed{t, ctx, fixture}
for _, shape := range []struct {
name string
rootType types.IssueType
labels []string
}{
{"poured", types.TypeMolecule, nil},
{"template", types.TypeEpic, []string{publicops.MoleculeTemplateLabel}},
} {
root, _, last := s.molecule("auto-"+shape.name, shape.rootType, false, shape.labels...)
res := s.closeStep(last, true)
if !res.Changed || res.Issue == nil || res.Issue.Status != types.StatusClosed {
t.Fatalf("%s: close %s = %+v, want the step closed", shape.name, last, res)
}
if res.AutoClosedMolecule == nil || res.AutoClosedMolecule.ID != root {
t.Fatalf("%s: AutoClosedMolecule = %+v, want %s", shape.name, res.AutoClosedMolecule, root)
}
if res.MoleculeAutoCloseRefusal != "" {
t.Errorf("%s: MoleculeAutoCloseRefusal = %q, want none", shape.name, res.MoleculeAutoCloseRefusal)
}
if status, _ := s.row(root); status != string(types.StatusClosed) {
t.Errorf("%s: root %s status = %s, want closed", shape.name, root, status)
}
var reason string
if err := fixture.QueryScalar(ctx, `SELECT close_reason FROM issues WHERE id = ?`, []any{root}, &reason); err != nil {
t.Fatalf("read %s close_reason: %v", root, err)
}
if reason != publicops.MoleculeAutoCloseReason {
t.Errorf("%s: root close_reason = %q, want %q", shape.name, reason, publicops.MoleculeAutoCloseReason)
}
}
}
// RunMoleculeAutoCloseIsOptInAndRuleBound pins the opt-in default and the
// three roots the auto-close must leave open: one a request did not ask for,
// an incomplete one, and an ordinary epic (explicit close-eligible work).
func RunMoleculeAutoCloseIsOptInAndRuleBound(t *testing.T, ctx context.Context, fixture MoleculeFixture) {
t.Helper()
s := moleculeSeed{t, ctx, fixture}
root, _, last := s.molecule("optin", types.TypeMolecule, false)
if res := s.closeStep(last, false); res.AutoClosedMolecule != nil {
t.Errorf("close without AutoCloseMolecule reported %s auto-closed", res.AutoClosedMolecule.ID)
}
if status, _ := s.row(root); status != string(types.StatusOpen) {
t.Errorf("root %s status after an un-flagged close = %s, want open", root, status)
}
root, _, last = s.molecule("plain", types.TypeEpic, false)
if res := s.closeStep(last, true); res.AutoClosedMolecule != nil {
t.Errorf("an ordinary epic auto-closed: %s", res.AutoClosedMolecule.ID)
}
if status, _ := s.row(root); status != string(types.StatusOpen) {
t.Errorf("ordinary epic %s status = %s, want open", root, status)
}
root, done, last := s.molecule("incomplete", types.TypeMolecule, false)
if res := s.closeStep(done, true); res.AutoClosedMolecule != nil {
t.Errorf("an incomplete molecule auto-closed: %s", res.AutoClosedMolecule.ID)
}
if status, _ := s.row(root); status != string(types.StatusOpen) {
t.Errorf("incomplete molecule %s status = %s, want open (%s still open)", root, status, last)
}
}
// RunMoleculeRecloseHealsAStrandedRoot pins the replay clause: an idempotent
// re-close of the last step still closes a root left open.
func RunMoleculeRecloseHealsAStrandedRoot(t *testing.T, ctx context.Context, fixture MoleculeFixture) {
t.Helper()
s := moleculeSeed{t, ctx, fixture}
root := fixture.IssuePrefix + "-stranded"
step := root + ".1"
s.issue(root, types.TypeMolecule, types.StatusOpen, false)
s.issue(step, types.TypeTask, types.StatusClosed, false)
s.edge(step, root, types.DepParentChild)
res := s.closeStep(step, true)
if res.Changed {
t.Errorf("re-close of %s reported Changed", step)
}
if res.AutoClosedMolecule == nil || res.AutoClosedMolecule.ID != root {
t.Fatalf("re-close AutoClosedMolecule = %+v, want %s healed", res.AutoClosedMolecule, root)
}
if status, _ := s.row(root); status != string(types.StatusClosed) {
t.Errorf("stranded root %s status = %s, want closed", root, status)
}
}
// RunMoleculeBatchCloseAutoClosesTheRootOnce pins the batch clause: a batch
// that closes the remaining steps closes the root once, on one outcome.
func RunMoleculeBatchCloseAutoClosesTheRootOnce(t *testing.T, ctx context.Context, fixture MoleculeFixture) {
t.Helper()
s := moleculeSeed{t, ctx, fixture}
root, _, last := s.molecule("batch", types.TypeMolecule, false)
other := root + ".3"
s.issue(other, types.TypeTask, types.StatusOpen, false)
s.edge(other, root, types.DepParentChild)
res, err := fixture.BatchCloser.CloseBatch(ctx, publicops.CloseBatchRequest{
Actor: moleculeActor,
Items: []publicops.BatchCloseItem{{IssueID: last, Reason: "done"}, {IssueID: other, Reason: "done"}},
AutoCloseMolecule: true,
})
if err != nil {
t.Fatalf("CloseBatch: %v", err)
}
reported := 0
for _, outcome := range res.Outcomes {
if outcome.Err != nil {
t.Fatalf("outcome %s: %v", outcome.IssueID, outcome.Err)
}
if outcome.AutoClosedMolecule != nil {
reported++
if outcome.AutoClosedMolecule.ID != root {
t.Errorf("outcome %s auto-closed %s, want %s", outcome.IssueID, outcome.AutoClosedMolecule.ID, root)
}
}
}
if reported != 1 {
t.Errorf("the root was reported on %d outcomes, want exactly one", reported)
}
if status, _ := s.row(root); status != string(types.StatusClosed) {
t.Errorf("root %s status = %s, want closed", root, status)
}
}
// RunMoleculeRefusedRootKeepsTheStepClose pins the refusal clause: a root its
// own close policy refuses (a live blocker) stays open and is reported in the
// policy's own sentence, and the step close it followed stands.
func RunMoleculeRefusedRootKeepsTheStepClose(t *testing.T, ctx context.Context, fixture MoleculeFixture) {
t.Helper()
s := moleculeSeed{t, ctx, fixture}
root, _, last := s.molecule("blocked", types.TypeMolecule, false)
blocker := root + "-blocker"
s.issue(blocker, types.TypeTask, types.StatusOpen, false)
s.edge(root, blocker, types.DepBlocks)
res := s.closeStep(last, true)
if res.AutoClosedMolecule != nil {
t.Errorf("a blocked root auto-closed: %s", res.AutoClosedMolecule.ID)
}
if want := publicops.NewCloseBlockedError(root, []string{blocker}).Error(); res.MoleculeAutoCloseRefusal != want {
t.Errorf("MoleculeAutoCloseRefusal = %q, want the policy's own sentence %q", res.MoleculeAutoCloseRefusal, want)
}
if status, _ := s.row(last); status != string(types.StatusClosed) {
t.Errorf("step %s status = %s, want closed (the refusal must not undo it)", last, status)
}
if status, _ := s.row(root); status != string(types.StatusOpen) {
t.Errorf("blocked root %s status = %s, want open", root, status)
}
}
// RunMoleculeGuardedRootKeepsTheStepClose pins the guard clause: the root close
// is unforced, so a root a direct close would refuse — assigned to someone
// other than Actor, pinned, or a template — stays open and is reported in the
// guard's own sentence, on a single close and on a batch, and the step's close
// (and a batch's other items) stand.
func RunMoleculeGuardedRootKeepsTheStepClose(t *testing.T, ctx context.Context, fixture MoleculeFixture) {
t.Helper()
s := moleculeSeed{t, ctx, fixture}
for _, guard := range []struct {
name string
apply func(*types.Issue)
// refusal is the guard's own error for root, whose sentence
// MoleculeAutoCloseRefusal reports.
refusal func(root string) error
}{
{"assigned", func(root *types.Issue) { root.Assignee = "someone-else" }, func(root string) error {
return &publicops.CloseNotAssigneeError{IssueID: root, Assignee: "someone-else", Actor: moleculeActor}
}},
{"pinned", func(root *types.Issue) { root.Pinned = true }, func(root string) error {
return &publicops.PinnedError{IssueID: root}
}},
{"template", func(root *types.Issue) { root.IsTemplate = true }, func(root string) error {
return &publicops.TemplateReadOnlyError{IssueID: root}
}},
} {
for _, batch := range []bool{false, true} {
name := guard.name
if batch {
name += "-batch"
}
root := fixture.IssuePrefix + "-guarded-" + name
last := root + ".2"
rootIssue := &types.Issue{ID: root, Title: "molecule " + root, IssueType: types.TypeMolecule, Status: types.StatusOpen, Priority: 2}
guard.apply(rootIssue)
if err := fixture.CreateIssue(ctx, rootIssue, moleculeActor); err != nil {
t.Fatalf("%s: seed %s: %v", name, root, err)
}
s.issue(root+".1", types.TypeTask, types.StatusClosed, false)
s.issue(last, types.TypeTask, types.StatusOpen, false)
s.edge(root+".1", root, types.DepParentChild)
s.edge(last, root, types.DepParentChild)
var (
autoClosed *publicops.Issue
refusal string
closed = []string{last}
)
if batch {
other := root + "-other"
s.issue(other, types.TypeTask, types.StatusOpen, false)
closed = append(closed, other)
res, err := fixture.BatchCloser.CloseBatch(ctx, publicops.CloseBatchRequest{
Actor: moleculeActor,
Items: []publicops.BatchCloseItem{{IssueID: last, Reason: "done"}, {IssueID: other, Reason: "done"}},
AutoCloseMolecule: true,
})
if err != nil {
t.Fatalf("%s: CloseBatch: %v", name, err)
}
for _, outcome := range res.Outcomes {
if outcome.Err != nil {
t.Fatalf("%s: outcome %s: %v", name, outcome.IssueID, outcome.Err)
}
if outcome.IssueID == last {
autoClosed, refusal = outcome.AutoClosedMolecule, outcome.MoleculeAutoCloseRefusal
}
}
} else {
res := s.closeStep(last, true)
autoClosed, refusal = res.AutoClosedMolecule, res.MoleculeAutoCloseRefusal
}
if autoClosed != nil {
t.Errorf("%s: a guarded root auto-closed: %s", name, autoClosed.ID)
}
if want := guard.refusal(root).Error(); refusal != want {
t.Errorf("%s: MoleculeAutoCloseRefusal = %q, want the guard's own sentence %q", name, refusal, want)
}
for _, id := range closed {
if status, _ := s.row(id); status != string(types.StatusClosed) {
t.Errorf("%s: %s status = %s, want closed (the refusal must not undo it)", name, id, status)
}
}
if status, _ := s.row(root); status != string(types.StatusOpen) {
t.Errorf("%s: guarded root %s status = %s, want open", name, root, status)
}
}
}
}
// RunMoleculeStepperClaimsTheNextReadyStepForTheActor pins the advance and its
// claim: the next ready step becomes in progress AND assigned to Actor; without
// AutoClaim nothing is written.
func RunMoleculeStepperClaimsTheNextReadyStepForTheActor(t *testing.T, ctx context.Context, fixture MoleculeFixture) {
t.Helper()
s := moleculeSeed{t, ctx, fixture}
root := fixture.IssuePrefix + "-advance"
a, b, c := root+".1", root+".2", root+".3"
s.issue(root, types.TypeMolecule, types.StatusOpen, false)
s.issue(a, types.TypeTask, types.StatusClosed, false)
s.issue(b, types.TypeTask, types.StatusOpen, false)
s.issue(c, types.TypeTask, types.StatusOpen, false)
for _, id := range []string{a, b, c} {
s.edge(id, root, types.DepParentChild)
}
s.edge(c, b, types.DepBlocks)
res, err := fixture.Stepper.Advance(ctx, publicops.AdvanceRequest{Actor: moleculeActor, ClosedStepID: a})
if err != nil {
t.Fatalf("Advance: %v", err)
}
if res.MoleculeID != root || res.Claimed || res.NextStep == nil || res.NextStep.ID != b {
t.Fatalf("Advance without a claim = %+v, want next %s in %s, unclaimed", res, b, root)
}
if status, assignee := s.row(b); status != string(types.StatusOpen) || assignee != "" {
t.Errorf("%s after an unclaimed advance = %s/%q, want open and unassigned", b, status, assignee)
}
res, err = fixture.Stepper.Advance(ctx, publicops.AdvanceRequest{Actor: moleculeActor, ClosedStepID: a, AutoClaim: true})
if err != nil {
t.Fatalf("Advance with a claim: %v", err)
}
if !res.Claimed || res.NextStep == nil || res.NextStep.ID != b || res.NextStep.Assignee != moleculeActor {
t.Fatalf("Advance with a claim = %+v, want %s claimed for %s", res, b, moleculeActor)
}
if status, assignee := s.row(b); status != string(types.StatusInProgress) || assignee != moleculeActor {
t.Errorf("%s after the claim = %s/%q, want in_progress assigned to %s", b, status, assignee, moleculeActor)
}
if status, _ := s.row(c); status != string(types.StatusOpen) {
t.Errorf("%s (blocked) status = %s, want open", c, status)
}
}
// RunMoleculeStepperNeverTakesAStepAnotherActorHolds pins the refusal the claim
// carries: a ready step assigned to someone else is skipped for the next one,
// and left exactly as it was.
func RunMoleculeStepperNeverTakesAStepAnotherActorHolds(t *testing.T, ctx context.Context, fixture MoleculeFixture) {
t.Helper()
s := moleculeSeed{t, ctx, fixture}
root := fixture.IssuePrefix + "-held"
a, held, free := root+".1", root+".2", root+".3"
s.issue(root, types.TypeMolecule, types.StatusOpen, false)
s.issue(a, types.TypeTask, types.StatusClosed, false)
heldIssue := &types.Issue{ID: held, Title: "held", IssueType: types.TypeTask, Status: types.StatusOpen, Priority: 2, Assignee: "someone-else"}
if err := fixture.CreateIssue(ctx, heldIssue, moleculeActor); err != nil {
t.Fatalf("seed %s: %v", held, err)
}
s.issue(free, types.TypeTask, types.StatusOpen, false)
for _, id := range []string{a, held, free} {
s.edge(id, root, types.DepParentChild)
}
res, err := fixture.Stepper.Advance(ctx, publicops.AdvanceRequest{Actor: moleculeActor, ClosedStepID: a, AutoClaim: true})
if err != nil {
t.Fatalf("Advance: %v", err)
}
if !res.Claimed || res.NextStep == nil || res.NextStep.ID != free {
t.Fatalf("Advance = %+v, want %s skipped (held) and %s claimed", res, held, free)
}
if status, assignee := s.row(held); status != string(types.StatusOpen) || assignee != "someone-else" {
t.Errorf("held step %s = %s/%q, want untouched (open, someone-else)", held, status, assignee)
}
}
// RunMoleculeStepperAnswersCompleteAndOutsideAMolecule pins the two answers
// that claim nothing.
func RunMoleculeStepperAnswersCompleteAndOutsideAMolecule(t *testing.T, ctx context.Context, fixture MoleculeFixture) {
t.Helper()
s := moleculeSeed{t, ctx, fixture}
orphan := fixture.IssuePrefix + "-orphan"
s.issue(orphan, types.TypeTask, types.StatusClosed, false)
res, err := fixture.Stepper.Advance(ctx, publicops.AdvanceRequest{Actor: moleculeActor, ClosedStepID: orphan, AutoClaim: true})
if err != nil {
t.Fatalf("Advance(orphan): %v", err)
}
if res.MoleculeID != "" || res.NextStep != nil || res.Claimed || res.ClosedStep == nil || res.ClosedStep.ID != orphan {
t.Errorf("Advance(orphan) = %+v, want the step and no molecule", res)
}
root := fixture.IssuePrefix + "-complete"
s.issue(root, types.TypeEpic, types.StatusOpen, false)
s.issue(root+".1", types.TypeTask, types.StatusClosed, false)
s.edge(root+".1", root, types.DepParentChild)
res, err = fixture.Stepper.Advance(ctx, publicops.AdvanceRequest{Actor: moleculeActor, ClosedStepID: root + ".1", AutoClaim: true})
if err != nil {
t.Fatalf("Advance(complete): %v", err)
}
if res.MoleculeID != root || !res.Complete || res.NextStep != nil || res.Claimed {
t.Errorf("Advance(complete) = %+v, want %s complete", res, root)
}
if _, err := fixture.Stepper.Advance(ctx, publicops.AdvanceRequest{Actor: moleculeActor, ClosedStepID: fixture.IssuePrefix + "-absent"}); !errors.Is(err, publicops.ErrNotFound) {
t.Errorf("Advance(absent) = %v, want ErrNotFound", err)
}
}
// RunMoleculeStepperClaimsAWispStep pins the wisp plane: a wisp molecule's next
// step is claimed for the actor too.
func RunMoleculeStepperClaimsAWispStep(t *testing.T, ctx context.Context, fixture MoleculeFixture) {
t.Helper()
s := moleculeSeed{t, ctx, fixture}
root, done, last := s.molecule("wisp", types.TypeMolecule, true)
res, err := fixture.Stepper.Advance(ctx, publicops.AdvanceRequest{Actor: moleculeActor, ClosedStepID: done, AutoClaim: true})
if err != nil {
t.Fatalf("Advance: %v", err)
}
if res.MoleculeID != root || !res.Claimed || res.NextStep == nil || res.NextStep.ID != last {
t.Fatalf("Advance over a wisp molecule = %+v, want %s claimed", res, last)
}
if status, assignee := s.row(last); status != string(types.StatusInProgress) || assignee != moleculeActor {
t.Errorf("wisp step %s = %s/%q, want in_progress assigned to %s", last, status, assignee, moleculeActor)
}
}

View file

@ -42,7 +42,6 @@ func RunPortableMethods(t *testing.T, factory Factory) {
t.Run("ImportIssueComment", func(t *testing.T) { testImportIssueComment(t, factory) })
t.Run("AddIssueCommentBurstOrder", func(t *testing.T) { testAddIssueCommentBurstOrder(t, factory) })
t.Run("PromoteFromEphemeral", func(t *testing.T) { testPromoteFromEphemeral(t, factory) })
t.Run("PromoteClosedWispPreservesSession", func(t *testing.T) { testPromoteClosedWispPreservesSession(t, factory) })
t.Run("UpdateIssueID", func(t *testing.T) { testUpdateIssueID(t, factory) })
t.Run("DeleteIssuesBySourceRepo", func(t *testing.T) { testDeleteIssuesBySourceRepo(t, factory) })
t.Run("CreateIssuesWithFullOptions", func(t *testing.T) { testCreateIssuesWithFullOptions(t, factory) })
@ -578,36 +577,6 @@ func testPromoteFromEphemeral(t *testing.T, f Factory) {
}
}
// testPromoteClosedWispPreservesSession verifies that promoting a *closed*
// ephemeral wisp preserves its closed_by_session provenance. Before the fix
// (GH#4662), closed_by_session was absent from the shared issue select/scan
// and insert column set, so promotion (read wisp -> insert issue) hydrated a
// zero value and dropped the original closing session. Promotion re-inserts
// through that shared (classic) writer, so this case guards GH#4662's path
// only; the domain writer's copy of the column (db.insertIssueRow) is pinned
// by the domain/db Insert tests.
func testPromoteClosedWispPreservesSession(t *testing.T, f Factory) {
s := f(t)
c := ctx()
must(t, s.CreateIssue(c, withDefaults(&types.Issue{ID: "test-cw", Title: "Closed wisp", Ephemeral: true}), "a"))
must(t, s.CloseIssue(c, "test-cw", "done", "a", "sess-xyz"))
must(t, s.PromoteFromEphemeral(c, "test-cw", "a"))
got, err := s.GetIssue(c, "test-cw")
must(t, err)
if got.Ephemeral {
t.Error("promoted issue still Ephemeral")
}
if got.Status != types.StatusClosed {
t.Errorf("promoted issue status = %q, want %q", got.Status, types.StatusClosed)
}
if got.ClosedBySession != "sess-xyz" {
t.Errorf("closed_by_session after promote = %q, want %q (GH#4662)", got.ClosedBySession, "sess-xyz")
}
}
// --- Id rekey / source-repo purge / batch create ---
func testUpdateIssueID(t *testing.T, f Factory) {

View file

@ -113,10 +113,6 @@ type ReaderFixture struct {
AddDependency func(context.Context, *types.Dependency, string) error
// AddComment puts one comment on a durable issue.
AddComment func(ctx context.Context, issueID, author, text string) error
// PromoteWisp moves a seeded wisp into the durable plane. It is the only
// way to seed a DURABLE row of an infra type: creating one routes it to the
// wisps plane on every backend.
PromoteWisp func(ctx context.Context, id, actor string) error
}
// RunReaderReadyDefaultTypeExclusionsYieldToAnExplicitType pins
@ -790,112 +786,6 @@ func RunReaderListReadyFlagRefusesAFilterItCannotCarry(t *testing.T, ctx context
assertReaderPageIDs(t, "List --id without --ready", page, []string{one})
}
// RunReaderListQueryMatchesTheTitleOrTheID pins ListRequest.Query: `bd
// search`'s text, which matches a row whose title OR id contains it, case
// insensitively, and which narrows without lifting a default exclusion — and
// issueops.SearchListRequest, the request every `bd search` route sends, which
// does lift them.
//
// EVERY KIND OF ROW the search scope promises is seeded with the text, because
// a scope that silently loses one kind answers every other row correctly: a
// template, a gate, a wisp of an infra type, and a DURABLE row of that type —
// a promoted wisp, which a type filter that narrows an infra type to its
// ephemeral rows drops with no error. Each must come back under the bare scope
// and under its own type.
//
// It scopes itself with a label rather than an id set, so the served leg runs
// it as written: listIssues publishes no id parameter.
func RunReaderListQueryMatchesTheTitleOrTheID(t *testing.T, ctx context.Context, fixture ReaderFixture) {
t.Helper()
if fixture.PromoteWisp == nil {
t.Fatal("fixture has no PromoteWisp: a durable row of an infra type cannot be seeded, and it is the row a narrowed type filter drops")
}
scope := readerLabel(fixture, "lsquery")
needle := strings.ToLower(fixture.IssuePrefix) + "qneedle"
titleHit := readerID(fixture, "lsquery", "title")
idHit := readerID(fixture, "lsquery", "idhit")
closedHit := readerID(fixture, "lsquery", "closed")
miss := readerID(fixture, "lsquery", "miss")
template := readerID(fixture, "lsquery", "template")
gate := readerID(fixture, "lsquery", "gate")
wispMessage := readerID(fixture, "lsquery", "wispmsg")
promotedMessage := readerID(fixture, "lsquery", "promotedmsg")
// The title carries the needle in UPPER case and the request asks in lower,
// so a case-sensitive match finds nothing.
titleIssue := readerIssue(titleHit, types.TypeTask, scope)
titleIssue.Title = "fix the " + strings.ToUpper(needle) + " path"
// The id-hit's title says nothing about it: only its id can match.
idIssue := readerIssue(idHit, types.TypeTask, scope)
idIssue.Title = "unrelated words"
closedIssue := readerIssue(closedHit, types.TypeTask, scope)
closedIssue.Title = "old " + needle
closedIssue.Status = types.StatusClosed
missIssue := readerIssue(miss, types.TypeTask, scope)
missIssue.Title = "nothing to see"
templateIssue := readerIssue(template, types.TypeTask, scope)
templateIssue.Title = needle + " template"
templateIssue.IsTemplate = true
gateIssue := readerIssue(gate, types.TypeGate, scope)
gateIssue.Title = needle + " gate"
for _, issue := range []*types.Issue{titleIssue, idIssue, closedIssue, missIssue, templateIssue, gateIssue} {
seedReaderIssue(t, ctx, fixture, issue)
}
// Two rows of the same infra type, one per plane. `message` is built in,
// so the type is valid on every backend without configuration.
for _, id := range []string{wispMessage, promotedMessage} {
message := readerIssue(id, types.TypeMessage, scope)
message.Title = needle + " message"
message.Ephemeral = true
seedReaderWisp(t, ctx, fixture, message)
}
if err := fixture.PromoteWisp(ctx, promotedMessage, "seed"); err != nil {
t.Fatalf("promote wisp %s: %v", promotedMessage, err)
}
searchType := func(issueType types.IssueType) publicops.ListRequest {
req := searchScoped(needle, scope)
req.IssueType = string(issueType)
return req
}
for _, tc := range []struct {
name string
req publicops.ListRequest
want []string
}{
{"a title match, case-insensitively, under the default exclusions", publicops.ListRequest{Labels: []string{scope}, Query: needle}, []string{titleHit}},
{"AllFlag takes the closed match back", publicops.ListRequest{Labels: []string{scope}, Query: needle, AllFlag: true}, []string{titleHit, closedHit}},
{"an id match whose title does not contain the text", publicops.ListRequest{Labels: []string{scope}, Query: idHit, AllFlag: true}, []string{idHit}},
{"text nothing contains", publicops.ListRequest{Labels: []string{scope}, Query: needle + "-absent", AllFlag: true}, nil},
{"no text narrows nothing", publicops.ListRequest{Labels: []string{scope}}, []string{titleHit, idHit, miss}},
{"SearchListRequest, `bd search`'s scope, takes every status and every kind of row back", searchScoped(needle, scope), []string{titleHit, closedHit, template, gate, wispMessage, promotedMessage}},
{"SearchListRequest under an infra type keeps both planes' rows of it", searchType(types.TypeMessage), []string{wispMessage, promotedMessage}},
{"SearchListRequest under the gate type", searchType(types.TypeGate), []string{gate}},
{"SearchListRequest under a plain type keeps its templates", searchType(types.TypeTask), []string{titleHit, closedHit, template}},
// Outside the search scope an infra type alone reads only its
// ephemeral rows, which is where creating one puts it; IncludeEphemeral
// is what lifts that narrowing to the durable rows as well.
{"an infra type alone reads only its ephemeral rows", publicops.ListRequest{Labels: []string{scope}, Query: needle, IssueType: string(types.TypeMessage)}, []string{wispMessage}},
{"IncludeEphemeral lifts that narrowing", publicops.ListRequest{Labels: []string{scope}, Query: needle, IssueType: string(types.TypeMessage), IncludeEphemeral: true}, []string{wispMessage, promotedMessage}},
} {
page, err := fixture.Reader.List(ctx, tc.req)
if err != nil {
t.Errorf("List %s: %v", tc.name, err)
continue
}
assertReaderPageIDSet(t, "List "+tc.name, page, tc.want)
}
}
// searchScoped is the library's search request narrowed to one case's label,
// the request every `bd search` route sends.
func searchScoped(query, label string) publicops.ListRequest {
req := publicops.SearchListRequest(query)
req.Labels = []string{label}
return req
}
// RunReaderListEmptyPageIsWellFormed pins the page shape when nothing matches
// (reader.go:376-381). Items is never nil for a successful call, so no caller
// has to tell null from empty to learn that nothing matched, and an empty page
@ -3175,335 +3065,6 @@ func assertReaderBriefRow(t *testing.T, what string, brief, full *types.Issue) {
}
}
// RunReaderListTimeBoundsAreStrictAndWholeSecond pins the eight time bounds
// ListRequest carries beside the created pair — UpdatedAfter/Before,
// ClosedAfter/Before, DeferAfter/Before and DueAfter/Before — at their exact
// boundaries (reader.go: each is a strict bound on its column).
//
// THE BOUNDARY IS THE ASSERTION. Three rows sit one second apart around an
// instant T, so a body that compared inclusively, swapped the two ends, or
// bound the wrong column fails on a row rather than on nothing:
//
// - after=T selects exactly the T+1s row and before=T exactly the T-1s row,
// so the row AT T is excluded by both;
// - a bound carrying a sub-second remainder (T+900ms) behaves as T on both
// ends, because the bound is compared at whole-second precision (the
// storage builder formats it as RFC 3339 without a fraction);
// - a row whose column is NULL — an open row's closed_at, an unset
// defer_until or due_at — never matches either bound;
// - a bound spelled in a non-UTC zone selects exactly what the same instant
// spelled in UTC does. An offset is part of the instant, not decoration,
// and a body that dropped it would move the bound by the offset.
//
// Every family scopes itself by id and seeds no labels, so no write after the
// insert can move updated_at off the instant it was seeded at; AllFlag keeps
// the closed rows in view.
func RunReaderListTimeBoundsAreStrictAndWholeSecond(t *testing.T, ctx context.Context, fixture ReaderFixture) {
t.Helper()
at := time.Now().UTC().Truncate(time.Second).Add(-3 * time.Hour)
created := at.Add(-time.Hour)
instants := []struct {
tag string
at time.Time
}{
{"early", at.Add(-time.Second)},
{"exact", at},
{"late", at.Add(time.Second)},
}
for _, family := range []struct {
name string
// set stamps the family's column onto a seed.
set func(issue *types.Issue, v time.Time)
// nullable seeds a fourth row with the column NULL.
nullable bool
after func(*publicops.ListRequest, *time.Time)
before func(*publicops.ListRequest, *time.Time)
}{
{
name: "updated",
set: func(issue *types.Issue, v time.Time) { issue.UpdatedAt = v },
after: func(r *publicops.ListRequest, v *time.Time) { r.UpdatedAfter = v },
before: func(r *publicops.ListRequest, v *time.Time) { r.UpdatedBefore = v },
},
{
name: "closed",
set: func(issue *types.Issue, v time.Time) {
issue.Status = types.StatusClosed
issue.UpdatedAt = v
issue.ClosedAt = &v
},
nullable: true,
after: func(r *publicops.ListRequest, v *time.Time) { r.ClosedAfter = v },
before: func(r *publicops.ListRequest, v *time.Time) { r.ClosedBefore = v },
},
{
name: "defer",
set: func(issue *types.Issue, v time.Time) { issue.DeferUntil = &v },
nullable: true,
after: func(r *publicops.ListRequest, v *time.Time) { r.DeferAfter = v },
before: func(r *publicops.ListRequest, v *time.Time) { r.DeferBefore = v },
},
{
name: "due",
set: func(issue *types.Issue, v time.Time) { issue.DueAt = &v },
nullable: true,
after: func(r *publicops.ListRequest, v *time.Time) { r.DueAfter = v },
before: func(r *publicops.ListRequest, v *time.Time) { r.DueBefore = v },
},
} {
caseTag := "ltb" + family.name
ids := map[string]string{}
var scope []string
for _, inst := range instants {
id := readerID(fixture, caseTag, inst.tag)
ids[inst.tag] = id
scope = append(scope, id)
issue := readerIssue(id, types.TypeTask, "")
issue.CreatedAt, issue.UpdatedAt = created, created
family.set(issue, inst.at)
seedReaderIssue(t, ctx, fixture, issue)
}
if family.nullable {
id := readerID(fixture, caseTag, "null")
scope = append(scope, id)
issue := readerIssue(id, types.TypeTask, "")
issue.CreatedAt, issue.UpdatedAt = created, created
seedReaderIssue(t, ctx, fixture, issue)
}
idScope := readerIDFilter(scope...)
list := func(what string, apply func(*publicops.ListRequest, *time.Time), bound time.Time) []string {
t.Helper()
req := publicops.ListRequest{IDFilter: idScope, AllFlag: true}
apply(&req, &bound)
page, err := fixture.Reader.List(ctx, req)
if err != nil {
t.Fatalf("List (%s %s): %v", family.name, what, err)
}
assertReaderPageNotNil(t, "List ("+family.name+" "+what+")", page)
got := readerPageIDs(page)
slices.Sort(got)
return got
}
expect := func(what string, apply func(*publicops.ListRequest, *time.Time), bound time.Time, want string) {
t.Helper()
if got := list(what, apply, bound); !slices.Equal(got, []string{want}) {
t.Errorf("List (%s %s %s) = %v, want exactly [%s]", family.name, what, bound.Format(time.RFC3339Nano), got, want)
}
}
plus2 := time.FixedZone("UTC+2", 2*60*60)
for _, bound := range []struct {
what string
v time.Time
}{
{"at T", at},
{"at T with a sub-second remainder", at.Add(900 * time.Millisecond)},
{"at T spelled in a +02:00 zone", at.In(plus2)},
} {
expect("after "+bound.what, family.after, bound.v, ids["late"])
expect("before "+bound.what, family.before, bound.v, ids["early"])
}
// The NULL row is outside even the widest bounds on both ends.
if family.nullable {
wide := at.Add(-24 * time.Hour)
if got, want := list("after a day earlier", family.after, wide), sortedCopy(ids["early"], ids["exact"], ids["late"]); !slices.Equal(got, want) {
t.Errorf("List (%s after a day earlier) = %v, want %v — a NULL column never matches", family.name, got, want)
}
if got, want := list("before a day later", family.before, at.Add(24*time.Hour)), sortedCopy(ids["early"], ids["exact"], ids["late"]); !slices.Equal(got, want) {
t.Errorf("List (%s before a day later) = %v, want %v — a NULL column never matches", family.name, got, want)
}
}
}
}
// RunReaderListFilterFamiliesNarrowToTheirRows pins one included and one
// excluded row for each remaining ListRequest filter family that `bd list`
// publishes beyond the scope filters: the priority trio, the three text
// substrings, the empty-description and no-labels predicates, the top-level
// predicate, the type exclusion, the spec prefix, the label pattern and
// regex, the external-ref pair, the pinned-flag pair, the deferred and
// overdue predicates, the status exclusion and the molecule type.
//
// Each row is scoped by id and every arm asks AllFlag (the pinned arms
// excepted, which are about that interplay), so an arm whose filter the body
// dropped answers its whole scope and fails, and one whose filter the body
// inverted answers the other row.
//
// PinnedFlag with NoPinnedFlag is a contradiction, and the role refuses it as
// a validation error rather than letting one of the two silently win.
// ParentID with NoParent is refused the same way, as CountRequest refuses it.
func RunReaderListFilterFamiliesNarrowToTheirRows(t *testing.T, ctx context.Context, fixture ReaderFixture) {
t.Helper()
id := func(name string) string { return readerID(fixture, "lff", name) }
seed := func(name string, mutate func(*types.Issue)) string {
t.Helper()
issue := readerIssue(id(name), types.TypeTask, "")
if mutate != nil {
mutate(issue)
}
seedReaderIssue(t, ctx, fixture, issue)
return issue.ID
}
intp := func(v int) *int { return &v }
past := time.Now().UTC().Truncate(time.Second).Add(-48 * time.Hour)
future := time.Now().UTC().Truncate(time.Second).Add(48 * time.Hour)
label := readerLabel(fixture, "lffpat")
external := fixture.IssuePrefix + "-LFF-ext-17"
spec := "docs/" + fixture.IssuePrefix + "-lff/"
p0 := seed("p0", func(i *types.Issue) { i.Priority = 0 })
p2 := seed("p2", func(i *types.Issue) { i.Priority = 2 })
p4 := seed("p4", func(i *types.Issue) { i.Priority = 4 })
textT := seed("text-t", func(i *types.Issue) { i.Title = "a title carrying ttok-lff" })
textD := seed("text-d", func(i *types.Issue) { i.Description = "a description carrying dtok-lff" })
textN := seed("text-n", func(i *types.Issue) { i.Notes = "notes carrying ntok-lff" })
labeled := seed("labeled", func(i *types.Issue) { i.Labels = []string{label} })
unlabeled := seed("unlabeled", nil)
parent := seed("parent", func(i *types.Issue) { i.IssueType = types.TypeEpic })
child := seed("child", nil)
if err := fixture.AddDependency(ctx, &types.Dependency{IssueID: child, DependsOnID: parent, Type: types.DepParentChild}, "seed"); err != nil {
t.Fatalf("seed edge %s -> %s: %v", child, parent, err)
}
loose := seed("loose", nil)
typeTask := seed("type-task", nil)
typeBug := seed("type-bug", func(i *types.Issue) { i.IssueType = types.TypeBug })
typeChore := seed("type-chore", func(i *types.Issue) { i.IssueType = types.TypeChore })
specced := seed("specced", func(i *types.Issue) { i.SpecID = spec + "design.md" })
unspecced := seed("unspecced", nil)
extRow := seed("ext", func(i *types.Issue) { i.ExternalRef = &external })
extOther := seed("ext-other", func(i *types.Issue) {
other := fixture.IssuePrefix + "-other-99"
i.ExternalRef = &other
})
pinned := seed("pinned", func(i *types.Issue) { i.Pinned = true })
unpinned := seed("unpinned", nil)
deferred := seed("deferred", func(i *types.Issue) { i.DeferUntil = &future })
undeferred := seed("undeferred", nil)
overdue := seed("overdue", func(i *types.Issue) { i.DueAt = &past })
dueLater := seed("due-later", func(i *types.Issue) { i.DueAt = &future })
closedOverdue := seed("closed-overdue", func(i *types.Issue) {
i.Status = types.StatusClosed
closedAt := time.Now().UTC().Truncate(time.Second).Add(-time.Hour)
i.ClosedAt = &closedAt
i.DueAt = &past
})
noDue := seed("no-due", nil)
swarm := seed("mol-swarm", func(i *types.Issue) { i.MolType = types.MolTypeSwarm })
patrol := seed("mol-patrol", func(i *types.Issue) { i.MolType = types.MolTypePatrol })
stOpen := seed("st-open", nil)
stProgress := seed("st-progress", func(i *types.Issue) { i.Status = types.StatusInProgress })
stBlocked := seed("st-blocked", func(i *types.Issue) { i.Status = types.StatusBlocked })
stClosed := seed("st-closed", func(i *types.Issue) {
i.Status = types.StatusClosed
closedAt := time.Now().UTC().Truncate(time.Second).Add(-time.Hour)
i.ClosedAt = &closedAt
})
statusScope := readerIDFilter(stOpen, stProgress, stBlocked, stClosed)
molType := func(m types.MolType) *publicops.MolType { return &m }
scoped := func(ids ...string) publicops.ListRequest {
return publicops.ListRequest{IDFilter: readerIDFilter(ids...), AllFlag: true}
}
with := func(req publicops.ListRequest, mutate func(*publicops.ListRequest)) publicops.ListRequest {
mutate(&req)
return req
}
for _, test := range []struct {
name string
req publicops.ListRequest
want []string
}{
{"Priority is exact", with(scoped(p0, p2, p4), func(r *publicops.ListRequest) { r.Priority = intp(2) }), []string{p2}},
{"Priority 0 is a value, not unset", with(scoped(p0, p2, p4), func(r *publicops.ListRequest) { r.Priority = intp(0) }), []string{p0}},
{"PriorityMin is inclusive", with(scoped(p0, p2, p4), func(r *publicops.ListRequest) { r.PriorityMin = intp(2) }), []string{p2, p4}},
{"PriorityMax is inclusive", with(scoped(p0, p2, p4), func(r *publicops.ListRequest) { r.PriorityMax = intp(2) }), []string{p0, p2}},
{"PriorityMin and PriorityMax compose", with(scoped(p0, p2, p4), func(r *publicops.ListRequest) { r.PriorityMin, r.PriorityMax = intp(1), intp(3) }), []string{p2}},
{"TitleContains is a case-insensitive substring", with(scoped(textT, textD, textN), func(r *publicops.ListRequest) { r.TitleContains = "TTOK-LFF" }), []string{textT}},
{"DescContains reads the description only", with(scoped(textT, textD, textN), func(r *publicops.ListRequest) { r.DescContains = "dtok-lff" }), []string{textD}},
{"NotesContains reads the notes only", with(scoped(textT, textD, textN), func(r *publicops.ListRequest) { r.NotesContains = "ntok-lff" }), []string{textN}},
{"EmptyDesc keeps the rows with no description", with(scoped(textT, textD, textN), func(r *publicops.ListRequest) { r.EmptyDesc = true }), []string{textT, textN}},
{"NoLabels keeps the unlabeled row", with(scoped(labeled, unlabeled), func(r *publicops.ListRequest) { r.NoLabels = true }), []string{unlabeled}},
{"LabelPattern is a glob", with(scoped(labeled, unlabeled), func(r *publicops.ListRequest) { r.LabelPattern = fixture.IssuePrefix + "-scope-lff*" }), []string{labeled}},
{"LabelRegex is a regular expression", with(scoped(labeled, unlabeled), func(r *publicops.ListRequest) { r.LabelRegex = "-scope-lffp.t$" }), []string{labeled}},
{"NoParent keeps the top-level rows", with(scoped(parent, child, loose), func(r *publicops.ListRequest) { r.NoParent = true }), []string{parent, loose}},
{"ExcludeTypes drops the named type", with(scoped(typeTask, typeBug, typeChore), func(r *publicops.ListRequest) { r.ExcludeTypes = []string{"bug"} }), []string{typeTask, typeChore}},
{"ExcludeTypes takes a comma-separated value", with(scoped(typeTask, typeBug, typeChore), func(r *publicops.ListRequest) { r.ExcludeTypes = []string{"bug,chore"} }), []string{typeTask}},
{"SpecPrefix is a prefix", with(scoped(specced, unspecced), func(r *publicops.ListRequest) { r.SpecPrefix = spec }), []string{specced}},
{"ExternalContains is a case-insensitive substring", with(scoped(extRow, extOther), func(r *publicops.ListRequest) { r.ExternalContains = "lff-EXT" }), []string{extRow}},
{"ExternalRef is exact", with(scoped(extRow, extOther), func(r *publicops.ListRequest) { r.ExternalRef = external }), []string{extRow}},
{"AllFlag alone admits both pinned-flag states", scoped(pinned, unpinned), []string{pinned, unpinned}},
{"PinnedFlag selects the flagged row", publicops.ListRequest{IDFilter: readerIDFilter(pinned, unpinned), PinnedFlag: true}, []string{pinned}},
{"NoPinnedFlag holds the unflagged predicate under AllFlag", with(scoped(pinned, unpinned), func(r *publicops.ListRequest) { r.NoPinnedFlag = true }), []string{unpinned}},
{"DeferredFlag keeps the deferred row", with(scoped(deferred, undeferred), func(r *publicops.ListRequest) { r.DeferredFlag = true }), []string{deferred}},
{"OverdueFlag keeps the open row past its due date", with(scoped(overdue, dueLater, closedOverdue, noDue), func(r *publicops.ListRequest) { r.OverdueFlag = true }), []string{overdue}},
{"ExcludeStatus under AllFlag keeps every status not named", with(scoped(stOpen, stProgress, stBlocked, stClosed), func(r *publicops.ListRequest) { r.ExcludeStatus = []string{"closed"} }), []string{stOpen, stProgress, stBlocked}},
{"ExcludeStatus takes repeated and comma-separated values", with(scoped(stOpen, stProgress, stBlocked, stClosed), func(r *publicops.ListRequest) { r.ExcludeStatus = []string{"blocked,in_progress", " closed "} }), []string{stOpen}},
{"ExcludeStatus adds to the default exclusions rather than replacing them", publicops.ListRequest{IDFilter: statusScope, ExcludeStatus: []string{"blocked"}}, []string{stOpen, stProgress}},
{"ExcludeStatus narrows an explicit Status", publicops.ListRequest{IDFilter: statusScope, Status: "open,blocked,closed", ExcludeStatus: []string{"blocked"}}, []string{stOpen, stClosed}},
{"MolType is exact", with(scoped(swarm, patrol), func(r *publicops.ListRequest) { r.MolType = molType(types.MolTypeSwarm) }), []string{swarm}},
} {
page, err := fixture.Reader.List(ctx, test.req)
if err != nil {
t.Errorf("List (%s): %v", test.name, err)
continue
}
assertReaderPageIDSet(t, "List ("+test.name+")", page, test.want)
}
// An exclusion naming no status in the workspace vocabulary is refused,
// never an exclusion that silently excludes nothing.
if _, err := fixture.Reader.List(ctx, publicops.ListRequest{IDFilter: statusScope, ExcludeStatus: []string{"clsoed"}}); !errors.Is(err, publicops.ErrValidation) {
t.Errorf("List with ExcludeStatus naming an unknown status = %v, want an error wrapping ErrValidation", err)
}
_, err := fixture.Reader.List(ctx, publicops.ListRequest{
IDFilter: readerIDFilter(pinned, unpinned), PinnedFlag: true, NoPinnedFlag: true,
})
if !errors.Is(err, publicops.ErrValidation) {
t.Errorf("List with PinnedFlag and NoPinnedFlag = %v, want an error wrapping ErrValidation", err)
}
_, err = fixture.Reader.List(ctx, publicops.ListRequest{
IDFilter: readerIDFilter(parent, child, loose), ParentID: parent, NoParent: true,
})
if !errors.Is(err, publicops.ErrValidation) {
t.Errorf("List with ParentID and NoParent = %v, want an error wrapping ErrValidation", err)
}
}
// sortedCopy returns its arguments as a sorted slice.
func sortedCopy(ids ...string) []string {
out := slices.Clone(ids)
slices.Sort(out)
return out
}
// readerIssue builds the seed every case starts from: an open, unassigned,
// unblocked task that qualifies for ready work. A case that needs it to fail one
// of those tests changes the field it means to test and nothing else.

View file

@ -769,21 +769,7 @@ type EpochFixture struct {
// Version now resolves to under the new epoch. A nil hook means this
// backend cannot report that, and the case that needs it skips with
// that reason.
//
// It only reads: it mints nothing and changes no state. It returns the
// address it was given when nothing carried the Version to a new one,
// and an error for an address the store does not serve.
CurrentAddressFor func(ctx context.Context, storeID string, oldAddress Address) (Address, error)
// LoseVersion records that storeID no longer serves the Version named by
// address. That address, and every address the same Version was carried
// to or from by a token-scheme change, resolves GoneReorganization from
// then on, in every later epoch: an epoch voids what the store lost,
// never what it still serves (R20-n). It is idempotent, never revives
// anything, and returns an error for an address storeID never minted. A
// nil LoseVersion means this backend cannot record a loss, and the cases
// that need one skip with that reason.
LoseVersion func(ctx context.Context, storeID string, address Address) error
}
// RunAnEpochBumpIsTriggeredOnlyByRestoreReinitOrSchemeChange pins R20-m: a
@ -833,258 +819,94 @@ func RunAnEpochBumpIsTriggeredOnlyByRestoreReinitOrSchemeChange(t *testing.T, ct
// RunEpochBumpVoidsOnlyAddressesOfVersionsNoLongerServed pins R20-n — "Rev7
// tightening... the clause most likely to be gotten wrong" in the
// architecture doc's own words: an epoch voids what the store lost, never
// what it still serves.
// architecture doc's own words. A prior-epoch Address goes
// GoneReorganization UNLESS the backend still serves that Version, in which
// case it must stay Live AND additionally report the Address it now
// resolves to under the new epoch.
//
// Survival is RECORDED, never inferred (gastownhall/beads#6664, bee-ghosttrack
// review 5360880888, Major 1). An earlier form of this case made a Version
// survive by minting it again in every later epoch, and treated a Version
// nobody minted again as lost. That reads loss off the absence of a mint, so
// it could not express a Version the store lost after minting it, and it
// voided every survivor that nobody happened to mint again. Here a restore or
// a destructive reinit leaves every address row alone: an address the store
// still serves stays Live at its own address with no upkeep, and the only way
// an address goes Gone is LoseVersion saying so.
//
// Each phase is a named subtest, so a backend that cannot record a loss skips
// only the phases that need LoseVersion, and a failure names its phase.
// StillServes is an ORACLE here, not a control: this case cannot make a real
// backend keep serving one address and drop another, since Phase 0 wires no
// real backend. It asks StillServes what the fixture (once real) decided,
// and checks the rest of the contract's promise against that decision for
// both outcomes.
func RunEpochBumpVoidsOnlyAddressesOfVersionsNoLongerServed(t *testing.T, ctx context.Context, fixture EpochFixture) {
t.Helper()
epochSkipUnlessReady(t, fixture, false)
// survivor-and-lost: of two Versions minted before a transition, the one
// the store loses goes Gone and the other stays Live at the address it
// already had, with no re-mint, for both triggers that leave addresses
// alone.
t.Run("survivor-and-lost", func(t *testing.T) {
if fixture.LoseVersion == nil {
t.Skip(epochLoseVersionSkip)
}
for _, trigger := range []EpochBumpTrigger{EpochBumpTriggerRestore, EpochBumpTriggerDestructiveReinit} {
t.Run(trigger.String(), func(t *testing.T) {
store := epochStore(fixture, "survivor-"+trigger.String())
addrA := epochMintAddress(t, ctx, fixture, store, "record-a")
addrB := epochMintAddress(t, ctx, fixture, store, "record-b")
newEpoch := epochBumpTo(t, ctx, fixture, store, trigger)
epochLoseAddress(t, ctx, fixture, store, addrB)
epochRequireLive(t, ctx, fixture, store, addrA, newEpoch,
"record-a was never lost, so the transition leaves it served at its own address with no re-mint (R20-n's exception)")
epochRequireGone(t, ctx, fixture, store, addrB, newEpoch,
"record-b was lost, so the transition voids it (R20-n)")
current := epochCurrentAddress(t, ctx, fixture, store, addrA)
epochRequireLive(t, ctx, fixture, store, current, newEpoch,
"the address CurrentAddressFor reports for a survivor must be served")
epochRequireLive(t, ctx, fixture, store, addrA, newEpoch,
"asking CurrentAddressFor must not retire or move the survivor's address")
if lostCurrent, err := fixture.CurrentAddressFor(ctx, store, addrB); err == nil {
t.Errorf("CurrentAddressFor(a lost address) = %s with no error, want an error: a lost Version has no current address", lostCurrent)
}
epochRequireGone(t, ctx, fixture, store, addrB, newEpoch,
"CurrentAddressFor on a lost address must not bring it back")
})
}
})
// gone-is-terminal: once an address is lost it stays lost. A later mint of
// the same id starts a new lineage under a new address, and neither that
// mint nor CurrentAddressFor revives the lost one (bee-ghosttrack's
// assertion for Major 1: a read-only lookup must not mint a replacement
// that makes a lost address look served).
t.Run("gone-is-terminal", func(t *testing.T) {
if fixture.LoseVersion == nil {
t.Skip(epochLoseVersionSkip)
}
store := epochStore(fixture, "terminal")
lost := epochMintAddress(t, ctx, fixture, store, "record-g")
epochBumpTo(t, ctx, fixture, store, EpochBumpTriggerRestore)
epochLoseAddress(t, ctx, fixture, store, lost)
laterEpoch := epochBumpTo(t, ctx, fixture, store, EpochBumpTriggerRestore)
fresh := epochMintAddress(t, ctx, fixture, store, "record-g")
if fresh == lost {
t.Fatalf("MintUnderEpoch(record-g) returned %s, the address already lost: a lost address is never handed out again", lost)
}
epochRequireLive(t, ctx, fixture, store, fresh, laterEpoch,
"a fresh mint of the id is a new lineage and is served")
epochRequireGone(t, ctx, fixture, store, lost, laterEpoch,
"a later mint of the same id must not revive a lost address")
if replacement, err := fixture.CurrentAddressFor(ctx, store, lost); err == nil {
t.Errorf("CurrentAddressFor(a lost address) = %s with no error, want an error: asking where a lost address resolves must not mint a replacement", replacement)
}
epochRequireGone(t, ctx, fixture, store, lost, laterEpoch,
"CurrentAddressFor on a lost address must not revive it")
// Losing it a second time is a no-op that leaves the fresh lineage
// alone.
epochLoseAddress(t, ctx, fixture, store, lost)
epochRequireLive(t, ctx, fixture, store, fresh, laterEpoch,
"losing the old address again must leave the fresh lineage served")
})
// survival-needs-no-upkeep: with nothing lost, an address stays Live across
// any number of counter-only transitions without being minted again, and a
// later mint of the same id neither retires it nor revives anything. This
// is the phase the earlier, mint-driven form failed: it answered Gone for
// every survivor nobody minted again.
t.Run("survival-needs-no-upkeep", func(t *testing.T) {
store := epochStore(fixture, "upkeep")
kept := epochMintAddress(t, ctx, fixture, store, "record-c")
epochBumpTo(t, ctx, fixture, store, EpochBumpTriggerRestore)
epochBumpTo(t, ctx, fixture, store, EpochBumpTriggerDestructiveReinit)
finalEpoch := epochBumpTo(t, ctx, fixture, store, EpochBumpTriggerRestore)
epochRequireLive(t, ctx, fixture, store, kept, finalEpoch,
"nothing was lost, so three counter-only transitions leave the address served without a re-mint")
fresh := epochMintAddress(t, ctx, fixture, store, "record-c")
if fresh == kept {
t.Fatalf("MintUnderEpoch(record-c) returned %s again after three bumps, want a new address for the new epoch", kept)
}
epochRequireLive(t, ctx, fixture, store, kept, finalEpoch,
"a later mint of the same id must not retire a served address")
epochRequireLive(t, ctx, fixture, store, fresh, finalEpoch,
"the fresh mint is served")
current := epochCurrentAddress(t, ctx, fixture, store, kept)
epochRequireLive(t, ctx, fixture, store, current, finalEpoch,
"the current address of a survivor must be served")
epochRequireLive(t, ctx, fixture, store, kept, finalEpoch,
"asking for the current address must not change the survivor")
})
}
// RunTokenSchemeChangeCarriesLiveAddressesAndOnlyThose pins R20-n's retained
// mapping for the one trigger that changes how addresses are encoded. A
// token-scheme-change bump gives every Version the store still serves a new
// address under the new epoch and keeps the old address resolving, so a holder
// of the old address is neither stranded nor pointed at something else. A
// Version the store already lost gets no new address and stays Gone.
func RunTokenSchemeChangeCarriesLiveAddressesAndOnlyThose(t *testing.T, ctx context.Context, fixture EpochFixture) {
t.Helper()
epochSkipUnlessReady(t, fixture, true)
store := epochStore(fixture, "scheme-change")
addrA := epochMintAddress(t, ctx, fixture, store, "record-a")
addrB := epochMintAddress(t, ctx, fixture, store, "record-b")
// record-b is lost in the epoch it was minted in, which a store may do.
epochLoseAddress(t, ctx, fixture, store, addrB)
newEpoch := epochBumpTo(t, ctx, fixture, store, EpochBumpTriggerTokenSchemeChange)
epochRequireLive(t, ctx, fixture, store, addrA, newEpoch,
"record-a is still served after the scheme change, through the retained mapping")
epochRequireGone(t, ctx, fixture, store, addrB, newEpoch,
"record-b was lost before the scheme change, which must not carry it")
carried := epochCurrentAddress(t, ctx, fixture, store, addrA)
if carried == addrA {
t.Errorf("CurrentAddressFor(%s) = the same address after a token-scheme change, want a new one: a scheme change re-encodes every served address, which is what tells a carry from a no-op", addrA)
if fixture.MintUnderEpoch == nil {
t.Skip("this backend has no way to mint a Version under a known epoch (MintUnderEpoch is nil)")
}
epochRequireLive(t, ctx, fixture, store, carried, newEpoch,
"the carried address must be served under the new epoch")
epochRequireLive(t, ctx, fixture, store, addrA, newEpoch,
"the old address must keep resolving after its carried address is looked up")
if again := epochCurrentAddress(t, ctx, fixture, store, carried); again != carried {
t.Errorf("CurrentAddressFor(%s) = %s, want the carried address itself: from the newest address the mapping is already current", carried, again)
if fixture.BumpEpoch == nil {
t.Skip("this backend has no epoch concept yet (BumpEpoch is nil)")
}
if lostCurrent, err := fixture.CurrentAddressFor(ctx, store, addrB); err == nil {
t.Errorf("CurrentAddressFor(a lost address) = %s with no error, want an error: a lost Version is not carried", lostCurrent)
if fixture.StillServes == nil {
t.Skip("this backend cannot report whether it still serves a prior-epoch Version (StillServes is nil)")
}
}
if fixture.Resolve == nil {
t.Skip("this backend does not yet report retention state (Resolve is nil)")
}
if fixture.CurrentAddressFor == nil {
t.Skip("this backend cannot report a still-served Version's new Address (CurrentAddressFor is nil)")
}
store := epochStore(fixture, "voids")
// RunACarriedAddressKeepsResolvingAcrossLaterBumps pins that a carried mapping
// is recorded once and then simply persists: later counter-only transitions do
// not change it, and a second token-scheme change extends it to the newest
// address without breaking any older one. Every address of the Version points
// directly at the newest address (one hop from any member), never along a
// chain.
func RunACarriedAddressKeepsResolvingAcrossLaterBumps(t *testing.T, ctx context.Context, fixture EpochFixture) {
t.Helper()
epochSkipUnlessReady(t, fixture, false)
store := epochStore(fixture, "carried-later")
addrA := epochMintAddress(t, ctx, fixture, store, "record-a")
epochBumpTo(t, ctx, fixture, store, EpochBumpTriggerRestore)
epochBumpTo(t, ctx, fixture, store, EpochBumpTriggerTokenSchemeChange)
addrA1 := epochCurrentAddress(t, ctx, fixture, store, addrA)
if addrA1 == addrA {
t.Fatalf("CurrentAddressFor(%s) = the same address after a token-scheme change, want a new one", addrA)
addrA, err := fixture.MintUnderEpoch(ctx, store, "record-a")
if err != nil {
t.Fatalf("MintUnderEpoch(record-a): %v", err)
}
addrB, err := fixture.MintUnderEpoch(ctx, store, "record-b")
if err != nil {
t.Fatalf("MintUnderEpoch(record-b): %v", err)
}
// Two counter-only transitions, with nothing minted in between.
epochBumpTo(t, ctx, fixture, store, EpochBumpTriggerRestore)
counterEpoch := epochBumpTo(t, ctx, fixture, store, EpochBumpTriggerDestructiveReinit)
epochRequireLive(t, ctx, fixture, store, addrA, counterEpoch,
"the original address must still resolve after counter-only transitions")
epochRequireLive(t, ctx, fixture, store, addrA1, counterEpoch,
"the carried address must still resolve after counter-only transitions")
if got := epochCurrentAddress(t, ctx, fixture, store, addrA); got != addrA1 {
t.Errorf("CurrentAddressFor(%s) = %s, want %s: a counter-only transition does not change the mapping", addrA, got, addrA1)
newEpoch, err := fixture.BumpEpoch(ctx, store, EpochBumpTriggerRestore)
if err != nil {
t.Fatalf("BumpEpoch: %v", err)
}
// A second scheme change carries the Version again.
secondEpoch := epochBumpTo(t, ctx, fixture, store, EpochBumpTriggerTokenSchemeChange)
addrA2 := epochCurrentAddress(t, ctx, fixture, store, addrA)
if addrA2 == addrA || addrA2 == addrA1 {
t.Fatalf("CurrentAddressFor(%s) = %s after a second scheme change, want an address different from %s and %s", addrA, addrA2, addrA, addrA1)
servesA, err := fixture.StillServes(ctx, store, addrA)
if err != nil {
t.Fatalf("StillServes(%s): %v", addrA, err)
}
for _, member := range []Address{addrA, addrA1, addrA2} {
epochRequireLive(t, ctx, fixture, store, member, secondEpoch,
"every address of a carried Version must resolve after a second scheme change")
servesB, err := fixture.StillServes(ctx, store, addrB)
if err != nil {
t.Fatalf("StillServes(%s): %v", addrB, err)
}
if got := epochCurrentAddress(t, ctx, fixture, store, addrA1); got != addrA2 {
t.Errorf("CurrentAddressFor(%s) = %s, want %s: every address of the Version points straight at the newest one", addrA1, got, addrA2)
if servesA == servesB {
t.Skip("this scenario needs one still-served and one no-longer-served address to exercise both halves of R20-n; StillServes reported the same answer for both, so this fixture gives this case nothing to contrast")
}
finalEpoch := epochBumpTo(t, ctx, fixture, store, EpochBumpTriggerRestore)
epochRequireLive(t, ctx, fixture, store, addrA2, finalEpoch,
"the newest carried address must still resolve after a later restore")
}
// RunALostAddressStaysGoneAcrossASchemeChange pins that loss is terminal even
// across a token-scheme change. Losing a Version loses every address of its
// lineage at once, and a later scheme change must not carry a lost lineage
// back into service.
func RunALostAddressStaysGoneAcrossASchemeChange(t *testing.T, ctx context.Context, fixture EpochFixture) {
t.Helper()
epochSkipUnlessReady(t, fixture, true)
store := epochStore(fixture, "lost-scheme-change")
addrA := epochMintAddress(t, ctx, fixture, store, "record-a")
epochBumpTo(t, ctx, fixture, store, EpochBumpTriggerTokenSchemeChange)
addrA1 := epochCurrentAddress(t, ctx, fixture, store, addrA)
lostEpoch := epochBumpTo(t, ctx, fixture, store, EpochBumpTriggerRestore)
// One lineage, two addresses: losing either loses both.
epochLoseAddress(t, ctx, fixture, store, addrA)
epochRequireGone(t, ctx, fixture, store, addrA, lostEpoch,
"the original address of a lost Version must be Gone")
epochRequireGone(t, ctx, fixture, store, addrA1, lostEpoch,
"the carried address of a lost Version must be Gone too")
schemeEpoch := epochBumpTo(t, ctx, fixture, store, EpochBumpTriggerTokenSchemeChange)
epochRequireGone(t, ctx, fixture, store, addrA, schemeEpoch,
"a later scheme change must not carry a lost lineage back into service")
epochRequireGone(t, ctx, fixture, store, addrA1, schemeEpoch,
"a later scheme change must not carry a lost lineage back into service")
for _, lostAddress := range []Address{addrA, addrA1} {
if current, err := fixture.CurrentAddressFor(ctx, store, lostAddress); err == nil {
t.Errorf("CurrentAddressFor(%s) = %s with no error, want an error: a lost lineage has no current address", lostAddress, current)
}
stillServed, noLongerServed := addrA, addrB
if servesB && !servesA {
stillServed, noLongerServed = addrB, addrA
}
fresh := epochMintAddress(t, ctx, fixture, store, "record-a")
if fresh == addrA || fresh == addrA1 {
t.Fatalf("MintUnderEpoch(record-a) returned %s, an address of the lost lineage: a lost address is never handed out again", fresh)
voidedAnswer, err := fixture.Resolve(ctx, store, noLongerServed)
if err != nil {
t.Fatalf("Resolve(no-longer-served): %v", err)
}
if voidedAnswer.Restriction != RestrictionGoneReorganization {
t.Errorf("Resolve(a prior-epoch Address no longer served) = %s, want RestrictionGoneReorganization (R20-n)", voidedAnswer.Restriction)
}
if voidedAnswer.Epoch == nil {
t.Fatal("Resolve(a prior-epoch Address no longer served).Epoch = nil, want the current epoch populated (R20-n: the answer must name the current epoch, not just Restriction alone)")
} else if *voidedAnswer.Epoch != newEpoch {
t.Errorf("Resolve(a prior-epoch Address no longer served).Epoch = %d, want the current epoch %d", *voidedAnswer.Epoch, newEpoch)
}
keptAnswer, err := fixture.Resolve(ctx, store, stillServed)
if err != nil {
t.Fatalf("Resolve(still-served): %v", err)
}
if keptAnswer.Restriction != RestrictionLive {
t.Errorf("Resolve(a prior-epoch Address the backend still serves) = %s, want RestrictionLive (R20-n's exception)", keptAnswer.Restriction)
}
newAddr, err := fixture.CurrentAddressFor(ctx, store, stillServed)
if err != nil {
t.Fatalf("CurrentAddressFor(%s): %v", stillServed, err)
}
if newAddr == "" {
t.Error("CurrentAddressFor(a still-served prior-epoch Address) returned an empty Address, want a real one under the new epoch")
}
epochRequireLive(t, ctx, fixture, store, fresh, schemeEpoch,
"a fresh mint of the id after the loss is a new lineage and is served")
}
// --- fixture helpers -------------------------------------------------------
@ -1131,137 +953,6 @@ func epochStore(fixture EpochFixture, tag string) string {
return fixture.IssuePrefix + "-epoch-store-" + tag
}
// epochLoseVersionSkip is the skip reason of every phase that needs
// EpochFixture.LoseVersion.
const epochLoseVersionSkip = "this backend cannot record that the store lost a Version (LoseVersion is nil)"
// epochSkipUnlessReady skips the case when the fixture lacks a capability the
// epoch cases need. The cases that record a loss also need LoseVersion. The
// all-nil wiring test runs every case against an empty fixture, so each case
// must call this before it touches any of them.
func epochSkipUnlessReady(t *testing.T, fixture EpochFixture, needsLoseVersion bool) {
t.Helper()
if fixture.MintUnderEpoch == nil {
t.Skip("this backend has no way to mint a Version under a known epoch (MintUnderEpoch is nil)")
}
if fixture.BumpEpoch == nil {
t.Skip("this backend has no epoch concept yet (BumpEpoch is nil)")
}
if fixture.StillServes == nil {
t.Skip("this backend cannot report whether it still serves a prior-epoch Version (StillServes is nil)")
}
if fixture.Resolve == nil {
t.Skip("this backend does not yet report retention state (Resolve is nil)")
}
if fixture.CurrentAddressFor == nil {
t.Skip("this backend cannot report a still-served Version's new Address (CurrentAddressFor is nil)")
}
if needsLoseVersion && fixture.LoseVersion == nil {
t.Skip(epochLoseVersionSkip)
}
}
// epochMintAddress mints id on store, failing the case if minting fails.
func epochMintAddress(t *testing.T, ctx context.Context, fixture EpochFixture, store, id string) Address {
t.Helper()
address, err := fixture.MintUnderEpoch(ctx, store, id)
if err != nil {
t.Fatalf("MintUnderEpoch(%s, %s): %v", store, id, err)
}
return address
}
// epochBumpTo bumps store's epoch for trigger and returns the epoch it
// reports. Epochs are captured from the return value, never assumed: the
// counter is one per database, shared by every store the suite uses.
func epochBumpTo(t *testing.T, ctx context.Context, fixture EpochFixture, store string, trigger EpochBumpTrigger) int {
t.Helper()
epoch, err := fixture.BumpEpoch(ctx, store, trigger)
if err != nil {
t.Fatalf("BumpEpoch(%s, %s): %v", store, trigger, err)
}
return epoch
}
// epochLoseAddress records that store lost the Version behind address.
func epochLoseAddress(t *testing.T, ctx context.Context, fixture EpochFixture, store string, address Address) {
t.Helper()
if err := fixture.LoseVersion(ctx, store, address); err != nil {
t.Fatalf("LoseVersion(%s, %s): %v", store, address, err)
}
}
// epochCurrentAddress asks where address now resolves, failing the case on an
// error or an empty answer.
func epochCurrentAddress(t *testing.T, ctx context.Context, fixture EpochFixture, store string, address Address) Address {
t.Helper()
current, err := fixture.CurrentAddressFor(ctx, store, address)
if err != nil {
t.Fatalf("CurrentAddressFor(%s, %s): %v", store, address, err)
}
if current == "" {
t.Fatalf("CurrentAddressFor(%s, %s) returned an empty Address, want a real one", store, address)
}
return current
}
// epochRequireLive asserts that address is served at epoch: StillServes is true
// and Resolve answers RestrictionLive naming that epoch. why says what the
// assertion is checking, for the failure message.
func epochRequireLive(t *testing.T, ctx context.Context, fixture EpochFixture, store string, address Address, epoch int, why string) {
t.Helper()
serves, err := fixture.StillServes(ctx, store, address)
if err != nil {
t.Fatalf("StillServes(%s): %v", address, err)
}
if !serves {
t.Errorf("StillServes(%s) = false, want true: %s", address, why)
}
answer, err := fixture.Resolve(ctx, store, address)
if err != nil {
t.Fatalf("Resolve(%s): %v", address, err)
}
if answer.Restriction != RestrictionLive {
t.Errorf("Resolve(%s) = %s, want RestrictionLive: %s", address, answer.Restriction, why)
}
epochRequireAnswerEpoch(t, answer, address, epoch, why)
}
// epochRequireGone asserts that address is no longer served at epoch:
// StillServes is false and Resolve answers RestrictionGoneReorganization
// naming that epoch.
func epochRequireGone(t *testing.T, ctx context.Context, fixture EpochFixture, store string, address Address, epoch int, why string) {
t.Helper()
serves, err := fixture.StillServes(ctx, store, address)
if err != nil {
t.Fatalf("StillServes(%s): %v", address, err)
}
if serves {
t.Errorf("StillServes(%s) = true, want false: %s", address, why)
}
answer, err := fixture.Resolve(ctx, store, address)
if err != nil {
t.Fatalf("Resolve(%s): %v", address, err)
}
if answer.Restriction != RestrictionGoneReorganization {
t.Errorf("Resolve(%s) = %s, want RestrictionGoneReorganization: %s", address, answer.Restriction, why)
}
epochRequireAnswerEpoch(t, answer, address, epoch, why)
}
// epochRequireAnswerEpoch asserts that a Live or Gone answer names the current
// epoch (R20-n: the answer carries the epoch, not just the Restriction).
func epochRequireAnswerEpoch(t *testing.T, answer RetentionAnswer, address Address, epoch int, why string) {
t.Helper()
if answer.Epoch == nil {
t.Errorf("Resolve(%s).Epoch = nil, want the current epoch %d: %s", address, epoch, why)
return
}
if *answer.Epoch != epoch {
t.Errorf("Resolve(%s).Epoch = %d, want the current epoch %d: %s", address, *answer.Epoch, epoch, why)
}
}
// sameRetentionAnswer compares two RetentionAnswer values by content rather
// than identity, so a case can assert "this did not change" without
// depending on the concrete Restriction the backend happened to pick.

View file

@ -44,10 +44,6 @@ var roleContractCases = []roleContract{
RunBatchApplyRefusesACrossPlaneEdgeBetweenRowsItCreated,
RunBatchApplyAcceptsAnExternalEdgeTarget,
RunBatchApplyNormalizesTheWaitsForGate,
RunBatchApplyStampsSpawnerIDOnlyWhenNamed,
RunBatchApplyCarriesThreadIDOntoTheStoredEdge,
RunBatchApplyCarriesThreadIDOntoAnExistingEdge,
RunBatchApplyRefusesAThreadIDLongerThanItsColumn,
RunBatchApplySplicesAForwardMetadataRef,
RunBatchApplySplicesASelfMetadataRef,
RunBatchApplyRefusesAMetadataRefNoItemDeclares,
@ -58,12 +54,6 @@ var roleContractCases = []roleContract{
RunBatchApplyReplayMintsANewSetOfRows,
RunBatchApplyDoesNotMutateTheCallerRequest,
RunBatchApplyRefusesAnUnusableRequest,
RunBatchApplyUpdateItemsRefuseATemplate,
RunBatchApplySplicesTheMetadataOfATemplateItCreates,
RunBatchApplyCloseItemsAnswerToTheCloseGuards,
RunBatchApplyRefusesADottedChildGatedOnItsOwnParent,
RunBatchApplyAppliesTheDefaultPriority,
RunBatchApplyCarriesTheGateMembers,
),
roleCases("BatchCloser", "BatchCloser()", oncePerRole,
@ -88,7 +78,6 @@ var roleContractCases = []roleContract{
RunBatchCloserAllRefusedBatchRecordsNoHistory,
RunBatchCloserDoesNotMutateTheCallerRequest,
RunBatchCloserSettlesTheDependersOfWhatItClosed,
RunBatchCloserItemsAnswerToTheCloseGuards,
),
roleCases("BatchCreator", "BatchCreator()", oncePerRole,
@ -106,7 +95,6 @@ var roleContractCases = []roleContract{
RunBatchCreatorRecordsNoHistoryForAnEphemeralBatch,
RunBatchCreatorDoesNotMutateTheCallerRequest,
RunBatchCreatorEchoesSubSecondTimestamps,
RunBatchCreatorAppliesTheDefaultPriority,
),
roleCases("BlockingAnnotator", "BlockingAnnotator()", oncePerRole,
@ -128,7 +116,6 @@ var roleContractCases = []roleContract{
RunBlockingAnnotatorRefusesAnEmptyID,
RunBlockingAnnotatorLeavesTheRequestAlone,
RunBlockingAnnotatorWritesNothing,
RunBlockingAnnotatorReportsTheTransitiveBlockedFlag,
),
// One contract file covers both halves of workspace identity: the eight
@ -199,15 +186,6 @@ var roleContractCases = []roleContract{
RunCounterIncludeInfraExcludesGates,
RunCounterCountsClosedRows,
RunCounterAnUnknownStatusMatchesNothing,
RunCounterParentIDScopesToChildren,
RunCounterNoParentExcludesChildren,
RunCounterExcludeTypesNarrowsThePredicate,
RunCounterExcludeStatusNarrowsThePredicate,
RunCounterParentIDMatchesListCardinality,
RunCounterNoParentMatchesListCardinality,
RunCounterExcludeTypesMatchesListCardinality,
RunCounterParentIDIncludesAWispChild,
RunCounterParentIDAndExcludeStatusComposeOnAClosedChild,
RunCounterGroupsPartitionTheScalarSet,
RunCounterLabelBucketsOverlapSoTotalIsNotTheirSum,
RunCounterNamesTheEmptyBuckets,
@ -272,7 +250,6 @@ var roleContractCases = []roleContract{
RunDependencyEditorSameTypeReAddIsIdempotent,
RunDependencyEditorSameTypeReAddWithChangedMetadataMintsOneVersion,
RunDependencyEditorSameTypeReAddWithIdenticalMetadataIsANoOp,
RunDependencyEditorSameTypeReAddWithChangedThreadMintsOneVersion,
RunDependencyEditorRepeatsWithinOneRequestCollapse,
RunDependencyEditorAttributesItsEventsToTheActor,
RunDependencyEditorRetypeRefusalLeavesTheOriginalEdge,
@ -306,7 +283,6 @@ var roleContractCases = []roleContract{
RunDependencyEditorAcceptsADiamond,
RunDependencyEditorGateScopeFollowsTheEdgeType,
RunDependencyEditorAcceptsBlockingAcrossIssueTypes,
RunDependencyEditorRefusesADottedChildGatedOnItsOwnParent,
),
// The accessor named here is not an accessor at all, alone among these
@ -443,14 +419,12 @@ var roleContractCases = []roleContract{
RunLifecycleExpectedVersionIsCheckedBeforeTheNoOps,
RunLifecycleReopenRecordsItsReason,
RunLifecycleResultsAreHydratedPostStateSnapshots,
RunLifecycleResultsCarryThePostWriteRowVersion,
RunLifecycleCloseAndReopenRequireActorAndIssueID,
RunLifecycleReopenProvenanceLabelsHistory,
RunLifecycleCloseSettlesItsTransitiveAndCrossPlaneDependers,
RunLifecycleCloseSettlesTheClosedRowItselfAndItsChild,
RunLifecycleCloseOnASpawnersLastChildSatisfiesAWaitsForGate,
RunLifecycleReopenReblocksItsDependers,
RunLifecycleCloseEnforcesTheCloseGuards,
),
// The accessor-reachable half of Lifecycle.Create, moved out of the staging
@ -463,9 +437,6 @@ var roleContractCases = []roleContract{
RunLifecycleCreateInheritsParentLabels,
RunLifecycleCreateWritesEveryScalarField,
RunLifecycleCreateEchoesSubSecondTimestamps,
RunLifecycleCreateAppliesTheDefaultPriority,
RunLifecycleCreateWritesTheGateMembers,
RunLifecycleCreateBoundsTheGateMembers,
),
roleCases("LifecycleUpdate", "IssueLifecycle()", oncePerRole,
@ -480,10 +451,6 @@ var roleContractCases = []roleContract{
RunLifecycleUpdateRefusesUnknownIDsAndActorlessRequests,
RunLifecycleUpdateRefusalWritesNoMemberOfThePatch,
RunLifecycleUpdateConditionalGuardsGateOrdinaryEdits,
RunLifecycleUpdateExpectedVersionSingleWinnerUnderConcurrency,
RunLifecycleUpdateExpectedVersionSingleWinnerWithDisjointColumnsUnderConcurrency,
RunLifecycleCloseExpectedVersionSingleWinnerUnderConcurrency,
RunLifecycleUpdateExpectedVersionSingleWinnerAcrossUpdateAndCloseUnderConcurrency,
RunLifecycleUpdateConditionalGuardAcceptsRespelledAssignee,
RunLifecycleUpdateMetadataPatchOrdersMergeSetUnset,
RunLifecycleUpdateClosePolicy,
@ -492,13 +459,7 @@ var roleContractCases = []roleContract{
RunLifecycleUpdateParentIDReplacesTheParentEdge,
RunLifecycleUpdateParentIDReplacesEveryParent,
RunLifecycleUpdatePersistentPreservesUnversionedClass,
RunLifecycleUpdateWispModesRefuseAnUnversionedRow,
RunLifecycleUpdatePersistentPromotesAWisp,
RunLifecycleUpdateProvenanceLabelsHistory,
RunLifecycleUpdateRefusesATemplate,
RunLifecycleUpdateAllowTemplateEditsATemplate,
RunLifecycleUpdatePatchesTheGateMembers,
RunLifecycleUpdateBoundsTheGateMembers,
),
roleCases("Memories", "Memories()", oncePerRole,
@ -513,7 +474,7 @@ var roleContractCases = []roleContract{
RunMemoriesRememberRefusesAnUnderivableKey,
RunMemoriesRecallAnswersTheStoredValue,
RunMemoriesRecallReportsAMissAsNotFoundNotAnError,
RunMemoriesEmptyRowIsPresentUntilForgotten,
RunMemoriesRecallConflatesStoredEmptyWithAbsent,
RunMemoriesForgetRemovesExactlyTheNamedRow,
RunMemoriesForgetNeverTouchesTheSettingsPlane,
RunMemoriesForgetReportsTheForgottenValue,
@ -576,7 +537,6 @@ var roleContractCases = []roleContract{
RunReaderListKeysetPositionResumesTheCreatedDescIDAscOrder,
RunReaderListReadyFlagAnswersTheBlockerAwareSet,
RunReaderListReadyFlagRefusesAFilterItCannotCarry,
RunReaderListQueryMatchesTheTitleOrTheID,
RunReaderListEmptyPageIsWellFormed,
RunReaderListMaxRowsIsHonored,
RunReaderListMaxRowsBoundaryIsLimitPlusOffset,
@ -604,8 +564,6 @@ var roleContractCases = []roleContract{
RunReaderListWispTypeNarrowsTheAdmittedPlaneRatherThanAdmittingIt,
RunReaderListBriefDropsTheFreeFormTextAndNothingElse,
RunReaderReadyBriefDropsTheFreeFormTextAndNothingElse,
RunReaderListTimeBoundsAreStrictAndWholeSecond,
RunReaderListFilterFamiliesNarrowToTheirRows,
),
roleCases("ReadyClaimer", "ReadyClaimer() and IssueReader()", oncePerRole,
@ -708,7 +666,6 @@ var roleContractCases = []roleContract{
RunSweeperWispsPlaneClearsTheWholeWispsTable,
RunSweeperWispsPlaneRequiresAFilter,
RunSweeperProtectsLiveDependents,
RunSweeperProtectsTransitiveLiveDependents,
RunSweeperProtectsLiveDependentsAcrossPlanes,
RunSweeperLimitTakesTheOldestClosedFirst,
),

View file

@ -747,49 +747,6 @@ func RunSweeperProtectsLiveDependents(t *testing.T, ctx context.Context, fixture
sweeperAssertWispRows(t, ctx, fixture, 4, openChild, convoy, hooked, relater)
}
// RunSweeperProtectsTransitiveLiveDependents pins that protection propagates
// through closed candidates: an open grandchild keeps both its closed parent
// and closed grandparent. Otherwise sweeping the grandparent orphans a live
// hierarchy even though the direct parent was correctly retained.
func RunSweeperProtectsTransitiveLiveDependents(t *testing.T, ctx context.Context, fixture SweeperFixture) {
t.Helper()
if fixture.AddDependencies == nil {
t.Skip("fixture has no AddDependencies hook; cannot wire the hierarchy this case needs")
}
root := sweeperSeed(t, ctx, fixture, sweeperIssue(fixture, "transitive", "root", true), nil)
middle := sweeperSeed(t, ctx, fixture, sweeperIssue(fixture, "transitive", "middle", true), nil)
leafIssue := sweeperIssue(fixture, "transitive", "leaf", true)
leafIssue.Status = types.StatusOpen
leafIssue.ClosedAt = nil
leaf := sweeperSeed(t, ctx, fixture, leafIssue, nil)
if err := fixture.AddDependencies(ctx, publicops.AddDependenciesRequest{
Actor: "sweeper-seed",
Edges: []publicops.DependencyEdge{
{IssueID: middle, DependsOnID: root, Type: publicops.DepParentChild},
{IssueID: leaf, DependsOnID: middle, Type: publicops.DepParentChild},
},
}); err != nil {
t.Fatalf("wiring transitive hierarchy: %v", err)
}
request := publicops.SweepRequest{
Tier: publicops.SweepWispsPlane,
IDPattern: sweeperPattern(fixture, "transitive"),
ClosedBefore: &sweeperCutoff,
ProtectLiveDependents: true,
}
preview := sweeperSweep(t, ctx, fixture, sweeperAsDryRun(request))
if preview.Swept != 0 || preview.Skipped.LiveDependent != 2 {
t.Fatalf("dry run: Swept = %d, LiveDependent = %d; want 0 and 2", preview.Swept, preview.Skipped.LiveDependent)
}
result := sweeperSweep(t, ctx, fixture, request)
if result.Swept != 0 || result.Skipped.LiveDependent != 2 {
t.Fatalf("sweep: Swept = %d, LiveDependent = %d; want 0 and 2", result.Swept, result.Skipped.LiveDependent)
}
sweeperAssertWispRows(t, ctx, fixture, 3, root, middle, leaf)
}
// RunSweeperProtectsLiveDependentsAcrossPlanes pins that the live-dependent
// protection reads BOTH dependency tables: a closed wisp that a live DURABLE
// (issues-table) bead depends on through parent-child, tracks or blocks is

View file

@ -129,14 +129,5 @@ func TestVersionedHistoryPhase0RunsInFullSkipMode(t *testing.T) {
t.Run("EpochBumpVoidsOnlyAddressesOfVersionsNoLongerServed", func(t *testing.T) {
RunEpochBumpVoidsOnlyAddressesOfVersionsNoLongerServed(t, ctx, fixture)
})
t.Run("TokenSchemeChangeCarriesLiveAddressesAndOnlyThose", func(t *testing.T) {
RunTokenSchemeChangeCarriesLiveAddressesAndOnlyThose(t, ctx, fixture)
})
t.Run("ACarriedAddressKeepsResolvingAcrossLaterBumps", func(t *testing.T) {
RunACarriedAddressKeepsResolvingAcrossLaterBumps(t, ctx, fixture)
})
t.Run("ALostAddressStaysGoneAcrossASchemeChange", func(t *testing.T) {
RunALostAddressStaysGoneAcrossASchemeChange(t, ctx, fixture)
})
})
}

View file

@ -1,356 +0,0 @@
package conformance
import (
"context"
"testing"
"time"
)
// This file holds the contract for R7.1 (gastownhall/beads#6136, design doc
// gastownhall/beads#5898 revision 9): the as-of read — the "versioned
// reads" half of Phase 3's title, authored here from scratch, since no
// fixture for it exists anywhere in this package to un-skip.
//
// R7.1, VERBATIM (design doc #5898 rev 9): "An as-of read is a named read
// whose selector is an instant. Given an instant T or a version address, a
// store returns one Bead's durable state as of that point — the latest
// version it holds that was accepted at or before T, with everything later
// excluded — under R7's record shape, marking the address it served, or
// refuses as gone or unknown with the reason (R8, R20). Like every history
// answer it is complete for the answering store's holdings and may change
// after a sync (TC3)."
//
// ADDRESS, RESTRICTION, AND CHANGEATTRIBUTION ARE DECLARED IN
// expected_revision_contract.go — see that file's package-level note on
// where this suite's shared vocabulary lives and why. This file reuses
// Restriction's five values as-is for the gone-or-unknown refusal outcome
// (R8): an as-of read never invents a sixth state, and never distinguishes
// "gone" from "unknown" any differently than R20 already does.
//
// EVERY HOOK ON THE FIXTURE BELOW IS INDEPENDENTLY NILABLE — see the
// package-level note in expected_revision_contract.go. Every case
// nil-checks every hook it uses and SKIPS BY NAME when one is missing. No
// backend implements as-of reads yet — the implementation is
// the child this suite is written ahead of.
//
// EXPLICIT NON-GOAL: MEMORY-PLANE CONSUMER POLICY IS NOT PART OF THIS
// PRIMITIVE. R7.1's own text is explicit that a closed-before-T boundary,
// sibling exclusion, and supersession exclusion "are Memory-plane policies
// a consumer layers on this primitive (#5877), not part of it." This suite
// does not implement or assert any of the three — a future reader who finds
// them absent should read that as this file honoring R7.1's own scope, not
// as an oversight. This is the read-side analog of the R16/R16.1 boundary
// risk already recorded in expected_revision_contract.go: do not conflate
// the primitive with policy layered on top of it.
//
// THIS SUITE ASSERTS LOCAL COMPLETENESS ONLY (TC3). Nothing below requires,
// or even checks, that two stores asked about the same lineage agree — R7.1
// itself says an as-of answer "may change after a sync," so two stores at
// different sync points are expected to answer differently, and neither is
// wrong. RunAsOfReadIsCompleteOnlyForTheAnsweringStoresHoldings is the one
// case that touches more than one store, and what it asserts is exactly
// this: each store answers strictly from its own holdings, never a
// sibling's — not that the two agree.
// AsOfSelector names the point R7.1 resolves against: either a wall-clock
// instant, or a specific version Address treated as the selector itself —
// "the read that names its own answer" (R7.1: "an instant T or a version
// address"). Exactly one of At/Version is populated in every case this file
// exercises; R7.1 does not speak to the shape where both or neither are
// set, so this suite does not either.
type AsOfSelector struct {
At *time.Time
Version *Address
}
// AsOfReadRefusal is R8's typed outcome for an as-of read that cannot be
// answered. Restriction is always one of the four Gone*/Unknown values,
// never RestrictionLive — a live answer is a served AsOfReadResult, not a
// refusal. Reason explains why (R8).
type AsOfReadRefusal struct {
Restriction Restriction
Reason string
}
// AsOfReadResult is the outcome of an as-of read (R7.1). Address/State and
// Refusal are mutually exclusive: read Address/State only when Refusal is
// nil.
type AsOfReadResult struct {
// Address is the version this read served, marking "the address it
// served" (R7.1). Populated only when Refusal is nil.
Address Address
// State is the served version's durable state under R7's record shape.
// Opaque to this suite: the fixture adapter translates a backend's real
// record shape into this map, and no case here asserts its field-level
// content — only that a served result carries an Address.
State map[string]any
// Refusal is populated instead of Address/State when the read cannot be
// answered (R8). Nil means the read was served.
Refusal *AsOfReadRefusal
}
// AsOfRead resolves storeID's answer to an as-of read against id's lineage,
// at selector (R7.1).
type AsOfRead func(ctx context.Context, storeID, id string, selector AsOfSelector) (AsOfReadResult, error)
// AsOfReadFixture supplies the capability under test for R7.1: a read whose
// selector is an instant or a version address, resolving to the latest
// version accepted at or before that point, or a typed refusal.
type AsOfReadFixture struct {
IssuePrefix string
// Resolve performs the as-of read under test (R7.1). A nil hook means
// this backend does not implement as-of reads yet, and every case in
// this file skips with that reason.
Resolve AsOfRead
// MintAt mints a fresh version for id under storeID, recorded as
// accepted at the given instant, and returns its Address. Cases use
// this to build a lineage with known accept-times to resolve an as-of
// read against. A nil hook means this backend has no way to mint a
// version at a controlled accept-time, and cases that need one skip
// with that reason.
MintAt func(ctx context.Context, storeID, id string, acceptedAt time.Time) (Address, error)
// MakeUnanswerable arranges for id to be unanswerable at storeID for
// the given Restriction (one of RestrictionGoneRetention/GoneErasure/
// GoneReorganization/Unknown) — independently of
// RetentionFixture/EpochFixture's own removal machinery, since R7.1's
// refusal is a sibling contract to R17/R20, not a dependent of them. A
// nil hook means this backend has no way to arrange this, and the case
// that needs it skips with that reason.
MakeUnanswerable func(ctx context.Context, storeID, id string, restriction Restriction) error
}
// RunAsOfReadSelectorAcceptsEitherAnInstantOrAVersionAddress pins R7.1's
// selector shape: an instant T and the version address that instant
// resolves to are two names for the same answer, and a store must accept
// either.
func RunAsOfReadSelectorAcceptsEitherAnInstantOrAVersionAddress(t *testing.T, ctx context.Context, fixture AsOfReadFixture) {
t.Helper()
if fixture.Resolve == nil {
t.Skip("this backend does not implement as-of reads (Resolve is nil)")
}
if fixture.MintAt == nil {
t.Skip("this backend has no way to mint a version at a controlled accept-time (MintAt is nil)")
}
store := asOfReadStore(fixture, "selector-kinds")
id := fixture.IssuePrefix + "-asof-selector"
t0 := time.Now().UTC().Add(-time.Hour)
asOfReadMint(t, ctx, fixture, store, id, t0)
t1 := t0.Add(time.Minute)
second := asOfReadMint(t, ctx, fixture, store, id, t1)
byInstant, err := fixture.Resolve(ctx, store, id, AsOfSelector{At: &t1})
if err != nil {
t.Fatalf("Resolve(selector=instant): %v", err)
}
if byInstant.Refusal != nil {
t.Fatalf("Resolve(selector=instant) = %+v, want a served result", byInstant)
}
byVersion, err := fixture.Resolve(ctx, store, id, AsOfSelector{Version: &second})
if err != nil {
t.Fatalf("Resolve(selector=version address): %v", err)
}
if byVersion.Refusal != nil {
t.Fatalf("Resolve(selector=version address) = %+v, want a served result", byVersion)
}
if byInstant.Address != second {
t.Errorf("Resolve(selector=instant matching a version's own accept-time).Address = %s, want %s", byInstant.Address, second)
}
if byVersion.Address != second {
t.Errorf("Resolve(selector=version address).Address = %s, want the same address named %s", byVersion.Address, second)
}
if byInstant.Address != byVersion.Address {
t.Errorf("an instant selector (served %s) and a version-address selector naming the same version (served %s) resolved to different addresses; R7.1 accepts either as a name for the same answer", byInstant.Address, byVersion.Address)
}
}
// RunAsOfReadReturnsTheLatestVersionAtOrBeforeTStrictlyExcludingLater pins
// R7.1's ordering promise: resolving at T returns the latest version
// accepted at or before T, and a version accepted after T is excluded even
// when its own instant is close by.
func RunAsOfReadReturnsTheLatestVersionAtOrBeforeTStrictlyExcludingLater(t *testing.T, ctx context.Context, fixture AsOfReadFixture) {
t.Helper()
if fixture.Resolve == nil {
t.Skip("this backend does not implement as-of reads (Resolve is nil)")
}
if fixture.MintAt == nil {
t.Skip("this backend has no way to mint a version at a controlled accept-time (MintAt is nil)")
}
store := asOfReadStore(fixture, "ordering")
id := fixture.IssuePrefix + "-asof-ordering"
t0 := time.Now().UTC().Add(-time.Hour)
asOfReadMint(t, ctx, fixture, store, id, t0)
t1 := t0.Add(time.Minute)
middle := asOfReadMint(t, ctx, fixture, store, id, t1)
t2 := t0.Add(2 * time.Minute)
asOfReadMint(t, ctx, fixture, store, id, t2)
atExactly, err := fixture.Resolve(ctx, store, id, AsOfSelector{At: &t1})
if err != nil {
t.Fatalf("Resolve(T=middle's own instant): %v", err)
}
if atExactly.Refusal != nil || atExactly.Address != middle {
t.Errorf("Resolve(T=middle's own instant) = %+v, want the version accepted exactly at T (%s), not a later one", atExactly, middle)
}
between := t1.Add(30 * time.Second)
betweenResult, err := fixture.Resolve(ctx, store, id, AsOfSelector{At: &between})
if err != nil {
t.Fatalf("Resolve(T strictly between two versions): %v", err)
}
if betweenResult.Refusal != nil || betweenResult.Address != middle {
t.Errorf("Resolve(T strictly between two versions) = %+v, want the latest version at-or-before T (%s); the version accepted after T must be strictly excluded", betweenResult, middle)
}
}
// RunAsOfReadReportsTheAddressItServed pins R7.1's "marking the address it
// served": a served result names the exact Address of the version it
// returned, not merely a truthy success.
func RunAsOfReadReportsTheAddressItServed(t *testing.T, ctx context.Context, fixture AsOfReadFixture) {
t.Helper()
if fixture.Resolve == nil {
t.Skip("this backend does not implement as-of reads (Resolve is nil)")
}
if fixture.MintAt == nil {
t.Skip("this backend has no way to mint a version at a controlled accept-time (MintAt is nil)")
}
store := asOfReadStore(fixture, "reports-address")
id := fixture.IssuePrefix + "-asof-reports-address"
at := time.Now().UTC()
address := asOfReadMint(t, ctx, fixture, store, id, at)
result, err := fixture.Resolve(ctx, store, id, AsOfSelector{At: &at})
if err != nil {
t.Fatalf("Resolve: %v", err)
}
if result.Refusal != nil {
t.Fatalf("Resolve = %+v, want a served result", result)
}
if result.Address == "" {
t.Fatal("Resolve returned an empty Address on a served result, want the address of the version it served (R7.1)")
}
if result.Address != address {
t.Errorf("Resolve(...).Address = %s, want the served version's own address %s", result.Address, address)
}
}
// RunAsOfReadRefusesAsGoneOrUnknownNeverSubstitutingAnotherVersion pins R8:
// a read that cannot be answered refuses as a typed Gone or Unknown outcome
// with a reason, and never silently returns a neighboring version, the
// nearest surviving version, or current state as a substitute — R8's own
// text names all three as non-answers.
func RunAsOfReadRefusesAsGoneOrUnknownNeverSubstitutingAnotherVersion(t *testing.T, ctx context.Context, fixture AsOfReadFixture) {
t.Helper()
if fixture.Resolve == nil {
t.Skip("this backend does not implement as-of reads (Resolve is nil)")
}
if fixture.MintAt == nil {
t.Skip("this backend has no way to mint a version at a controlled accept-time (MintAt is nil)")
}
if fixture.MakeUnanswerable == nil {
t.Skip("this backend has no way to make a lineage unanswerable (MakeUnanswerable is nil)")
}
for _, restriction := range []Restriction{
RestrictionGoneRetention,
RestrictionGoneErasure,
RestrictionGoneReorganization,
RestrictionUnknown,
} {
t.Run(restriction.String(), func(t *testing.T) {
store := asOfReadStore(fixture, "unanswerable-"+restriction.String())
id := fixture.IssuePrefix + "-asof-unanswerable-" + restriction.String()
at := time.Now().UTC()
address := asOfReadMint(t, ctx, fixture, store, id, at)
if err := fixture.MakeUnanswerable(ctx, store, id, restriction); err != nil {
t.Fatalf("MakeUnanswerable(%s, %s): %v", id, restriction, err)
}
result, err := fixture.Resolve(ctx, store, id, AsOfSelector{At: &at})
if err != nil {
t.Fatalf("Resolve after MakeUnanswerable(%s): %v", restriction, err)
}
if result.Refusal == nil {
t.Fatalf("Resolve after MakeUnanswerable(%s) = %+v, want a Refusal, not a served result (R8)", restriction, result)
}
if result.Refusal.Restriction != restriction {
t.Errorf("Refusal.Restriction = %s, want %s", result.Refusal.Restriction, restriction)
}
if result.Refusal.Reason == "" {
t.Error("Refusal.Reason is empty, want a reason (R8)")
}
if result.Address != "" {
t.Errorf("Resolve on a refusal returned Address = %s, want empty: R8 forbids silently substituting a neighboring version, the nearest surviving version, or current state (the pre-refusal address was %s)", result.Address, address)
}
})
}
}
// RunAsOfReadIsCompleteOnlyForTheAnsweringStoresHoldings pins R7.1's closing
// clause and TC3: an as-of answer "is complete for the answering store's
// holdings and may change after a sync." This case asserts NOTHING about
// agreement between two stores asked about the same lineage — proving that
// absence is the point, not a gap. It mints a lineage into exactly one of
// two stores and confirms each store answers strictly from its own
// holdings: the store that holds the lineage serves it, and the store that
// never received it answers Unknown (FR-06, reused from R20) rather than
// reaching across to a sibling store's knowledge, erroring, or answering
// Gone — which would claim knowledge of a lineage it never held.
func RunAsOfReadIsCompleteOnlyForTheAnsweringStoresHoldings(t *testing.T, ctx context.Context, fixture AsOfReadFixture) {
t.Helper()
if fixture.Resolve == nil {
t.Skip("this backend does not implement as-of reads (Resolve is nil)")
}
if fixture.MintAt == nil {
t.Skip("this backend has no way to mint a version at a controlled accept-time (MintAt is nil)")
}
holds := asOfReadStore(fixture, "tc3-holds-the-lineage")
neverSynced := asOfReadStore(fixture, "tc3-never-synced")
id := fixture.IssuePrefix + "-asof-tc3"
at := time.Now().UTC()
address := asOfReadMint(t, ctx, fixture, holds, id, at)
local, err := fixture.Resolve(ctx, holds, id, AsOfSelector{At: &at})
if err != nil {
t.Fatalf("Resolve on the store that holds the lineage: %v", err)
}
if local.Refusal != nil || local.Address != address {
t.Fatalf("Resolve on the store that holds the lineage = %+v, want it served from that store's own holdings (%s)", local, address)
}
remote, err := fixture.Resolve(ctx, neverSynced, id, AsOfSelector{At: &at})
if err != nil {
t.Fatalf("Resolve on a store that never received this lineage: %v", err)
}
if remote.Refusal == nil {
t.Fatalf("Resolve on a store that never received this lineage = %+v, want a Refusal: an as-of answer is complete for the answering store's own holdings, not a sibling's (TC3)", remote)
}
if remote.Refusal.Restriction != RestrictionUnknown {
t.Errorf("Refusal.Restriction on the never-synced store = %s, want RestrictionUnknown: no lineage knowledge is Unknown, not Gone (FR-06)", remote.Refusal.Restriction)
}
}
// --- fixture helpers -------------------------------------------------------
// asOfReadStore names a storeID namespaced by the fixture's IssuePrefix and
// tag, so cases that need more than one store (e.g. the TC3 local-
// completeness case) get independent ones.
func asOfReadStore(fixture AsOfReadFixture, tag string) string {
return fixture.IssuePrefix + "-asof-store-" + tag
}
// asOfReadMint mints a version for id on store at the given instant via
// fixture.MintAt, fataling the case if minting fails.
func asOfReadMint(t *testing.T, ctx context.Context, fixture AsOfReadFixture, store, id string, at time.Time) Address {
t.Helper()
address, err := fixture.MintAt(ctx, store, id, at)
if err != nil {
t.Fatalf("MintAt(%s, %s, %s): %v", store, id, at, err)
}
return address
}

View file

@ -1,192 +0,0 @@
load("@rules_go//go:def.bzl", "go_library", "go_test")
load("@rules_shell//shell:sh_test.bzl", "sh_test")
go_library(
name = "http",
srcs = [
"attach.go",
"credential.go",
"errors.go",
"http.go",
"target.go",
],
importpath = "github.com/steveyegge/beads/backend/http",
visibility = ["//visibility:public"],
deps = [
"//backend",
"//internal/configfile",
"//internal/gitignore",
"//internal/httpapi/apigen",
"//internal/httpclient",
"//internal/httpclient/wire",
"//internal/storage/backends",
],
)
go_test(
name = "http_test",
# The served e2e cases run ~4-5 min on the farm under
# BEADS_TEST_EMBEDDED_DOLT=1, past the medium 300s action limit.
size = "large",
timeout = "long",
srcs = [
"attach_test.go",
"e2e_blocked_flags_test.go",
"e2e_blocked_test.go",
"e2e_cli_test.go",
"e2e_export_test.go",
"e2e_gates_test.go",
"e2e_heartbeat_test.go",
"e2e_link_test.go",
"e2e_list_filters_test.go",
"e2e_list_page_edges_test.go",
"e2e_mol_test.go",
"e2e_promote_test.go",
"e2e_read_your_own_write_test.go",
"e2e_recompute_blocked_test.go",
"e2e_remote_roles_test.go",
"e2e_request_budget_test.go",
"e2e_search_test.go",
"e2e_show_current_test.go",
"e2e_show_single_fetch_test.go",
"open_test.go",
"per_open_credential_test.go",
"register_test.go",
],
# The e2e files exec the real bd (bazeltest.PrebuiltBD); they run under
# BEADS_TEST_EMBEDDED_DOLT=1 and skip otherwise.
data = ["//cmd/bd:bd_for_tests"],
env = {"BEADS_TEST_BD_BINARY": "$(rlocationpath //cmd/bd:bd_for_tests)"},
deps = [
":http",
"//backend",
"//internal/configfile",
"//internal/httpapi",
"//internal/httpclient",
"//internal/storage",
"//internal/storage/backends",
"//internal/storage/domain",
"//internal/storage/embeddeddolt",
"//internal/storage/issueops",
"//internal/testutil/bazeltest",
],
)
# http_test again, with the e2e tier on: BEADS_TEST_EMBEDDED_DOLT=1 starts the
# in-process server over embedded Dolt and BEADS_HTTP_TEST_REQUIRED=1 turns a
# skip of that tier into a failure. http_test alone skips the TestE2E_* cases
# in every lane, because no lane sets those variables for it. It repeats
# http_test's `env` (go_test_pinned_shard.sh, like go_test_variant.sh, does
# not inherit it).
#
# Shard count: the package's tests are serial, and as one shard the target
# ran 235-394s on the lane's executors (2026-10-10..13), the embedded lane's
# longest action in most runs where it executed; the lane's other shards end
# by ~90-125s. The 19 TestE2E_* cases that take >= 3s are pinned
# (tools/bazel/go_test_pinned_shard.sh, served_pinned_shards.txt from
# tools/bazel/pin_shards.py --shards 6 --min-seconds 3) onto 6 shards, and
# the binary's round-robin runs the other ~28 (well under a second
# together) in the 7th. The durations are the maximum over two sharded runs
# of the lane (bazel.yml's bazel-embedded-served-testxml artifact): 11-90s
# each, ~770s together. The same test's time varied 2-5x between those runs
# with the executors' load, and sharded runs took up to 2x what the
# single-shard runs did, so size the pins from sharded runs of the lane,
# never from a single-shard or local one.
# Regenerate the manifest from PR runs' bazel-embedded-served-testxml
# artifacts (each http_served_test directory holds shard_*_of_7/test.xml;
# pass several runs, pin_shards.py takes each test's maximum):
# python3 tools/bazel/pin_shards.py --shards 6 --min-seconds 3 \
# --write backend/http/served_pinned_shards.txt \
# <run1>/http_served_test <run2>/http_served_test
#
# Tags:
# embedded: the embedded-Dolt tier; excluded from --config=prcore/ci,
# selected by --config=embedded.
sh_test(
name = "http_served_test",
size = "large",
# -test.timeout=19m fires (with a goroutine dump) before Bazel's 1200s
# action limit (eternal under --config=embedded).
timeout = "eternal",
srcs = ["//tools/bazel:go_test_pinned_shard.sh"],
args = [
"$(rootpath :served_pinned_shards.txt)",
"$(rootpath :http_test)",
"-test.v",
"-test.count=1",
"-test.timeout=19m",
],
data = [
"served_pinned_shards.txt",
":http_test",
"//cmd/bd:bd_for_tests",
],
env = {
"BEADS_HTTP_TEST_REQUIRED": "1",
"BEADS_TEST_BD_BINARY": "$(rlocationpath //cmd/bd:bd_for_tests)",
"BEADS_TEST_EMBEDDED_DOLT": "1",
},
shard_count = 7,
tags = ["embedded"],
)
# --- begin repo_files (managed by tools/bazel/go_srcs.py; run `make bazel-sync`) ---
filegroup(
name = "repo_doc_files",
srcs = glob(
[
"**/*.md",
"**/*.mdx",
],
allow_empty = True,
exclude = ["**/node_modules/**"],
),
visibility = ["//:__subpackages__"],
)
filegroup(
name = "repo_go_srcs",
srcs = glob(
["**/*.go"],
allow_empty = True,
exclude = [
"**/*_test.go",
"**/node_modules/**",
],
),
visibility = ["//:__subpackages__"],
)
filegroup(
name = "repo_go_test_srcs",
srcs = glob(
["**/*_test.go"],
allow_empty = True,
exclude = ["**/node_modules/**"],
),
visibility = ["//:__subpackages__"],
)
filegroup(
name = "repo_other_files",
srcs = glob(
["**"],
exclude = [
"**/*.db",
"**/*.exe",
"**/*.go",
"**/*.md",
"**/*.mdx",
"**/*.out",
"**/*.prof",
"**/*.pyc",
"**/*.test",
"**/__pycache__/**",
"**/node_modules/**",
],
),
visibility = ["//:__subpackages__"],
)
# --- end repo_files ---

View file

@ -1,133 +0,0 @@
// Written fresh for OSS beads S6 (no bd-enterprise source copied): closes the
// S6 review's MED-8 finding, which asked for one public helper an embedder
// (or `bd connect`) can call to activate a workspace for this backend,
// instead of each caller hand-assembling the two-file write itself.
package bdhttp
import (
"context"
"fmt"
"github.com/steveyegge/beads/internal/configfile"
"github.com/steveyegge/beads/internal/gitignore"
"github.com/steveyegge/beads/internal/httpclient"
)
// Attach activates the http backend for the workspace at beadsDir: it writes
// the per-user activation sidecar (SaveTarget) pinning target's server and
// project, then sets the workspace's git-tracked backend selection in
// metadata.json to this backend, preserving every other configured field
// (database, project id, ...) and creating a fresh default metadata.json only
// when none exists yet. Both files are written atomically (temp file plus
// rename, 0600): see SaveTarget and configfile.Config.Save.
//
// Unless the caller already set target.PreviousBackend, Attach fills it in
// from the workspace's PRIOR backend selection, so `bd connect --clear` can
// restore it later; see that field's doc.
//
// Attach does NOT verify target itself — it has no network access and takes
// target on faith. A caller MUST call Handshake (or httpclient.Handshake)
// against target first and only call Attach once that succeeds; attaching an
// unverified target lets a workspace record a server that is wrong, hostile,
// or simply never answers. Connect, below, does both in the right order and
// is the easier door for a caller that does not need them split.
//
// Attach does not create beadsDir itself — MkdirAll is the caller's job, same
// as SaveTarget's own precondition. It DOES ensure both of this backend's
// per-user filenames are covered by beadsDir's .gitignore
// (gitignore.EnsurePatternIgnored): the sidecar, and
// httpclient.LocalMetadataFileName, which the store writes on first use. That
// is the same guarantee `bd connect` makes via doctor.EnsureGitignoreForBeadsDir
// — but through a small, independent implementation here rather than
// importing cmd/bd/doctor, whose package as a whole pulls in dolt and
// git-process dependencies that would break backend/http's promise of a
// minimal dependency footprint for an embedder. The two are complementary and
// idempotent together.
//
// It is the one place that writes BOTH of the files that activate beads/http
// (the sidecar and metadata.json's backend selection; the local metadata file
// is the store's own), so a caller that used to hand-assemble the pair
// (`bd connect`'s own connectCmd.RunE, test/embedder's linkage proof) can call
// this instead and stay correct across a future change to either file's shape.
func Attach(beadsDir string, target Target) error {
cfg, err := configfile.Load(beadsDir)
if err != nil {
return fmt.Errorf("reading %s: %w", configfile.ConfigFileName, err)
}
if cfg == nil {
cfg = configfile.DefaultConfig()
}
// target.PreviousBackend (bee-ghosttrack CHANGES_REQUESTED on #7288,
// should-fix 1) is what `bd connect --clear` restores metadata.json's
// backend selection to. A caller rarely sets it itself (connect.go
// doesn't), so fill it in here unless the workspace is ALREADY on this
// backend — a re-connect (a new URL, or re-pinning the same one) must
// not overwrite an earlier recorded previous backend with "http" itself,
// or a chain of reconnects would forget what to restore and --clear
// would land back on http with no sidecar. Carry the ALREADY-recorded
// value forward instead; a failed or missing read just leaves it "",
// the same as a workspace with nothing to restore. The check reads the
// raw field: in a process that never ran Register, GetBackend() reports an
// http workspace as the dolt default, and the reconnect would record that.
if target.PreviousBackend == "" {
if cfg.Backend == httpclient.Backend {
if prior, err := httpclient.LoadTarget(beadsDir); err == nil {
target.PreviousBackend = prior.PreviousBackend
}
} else {
target.PreviousBackend = cfg.GetBackend()
}
}
if err := SaveTarget(beadsDir, target); err != nil {
return fmt.Errorf("writing %s: %w", httpclient.TargetFileName, err)
}
// Both of this backend's per-user files: the sidecar just written, and
// the local metadata file the store itself writes on first use, which
// never passes through here and so must be covered in advance.
for _, name := range []string{httpclient.TargetFileName, httpclient.LocalMetadataFileName} {
if err := gitignore.EnsurePatternIgnored(beadsDir, name); err != nil {
return fmt.Errorf("ensuring %s is gitignored: %w", name, err)
}
}
// Only the backend SELECTION changes here. cfg.Database/cfg.ProjectID (if
// an existing metadata.json carried them for a different, prior backend)
// are left exactly as loaded — see connect.go's own comment on this same
// hazard: this backend's identity lives entirely in the sidecar just
// written above, and clobbering those fields would corrupt a future
// `bd connect --clear` back to a different backend.
cfg.Backend = httpclient.Backend
if err := cfg.Save(beadsDir); err != nil {
return fmt.Errorf("writing %s: %w", configfile.ConfigFileName, err)
}
return nil
}
// Connect is Handshake followed by Attach: it verifies target — the same
// server-identity check `bd connect` performs before it ever writes
// anything — and only then activates the workspace. It is the convenience
// door for a caller that wants Attach's ordering guarantee (never attach a
// workspace to a server this process has not handshaken) without composing
// Handshake and Attach itself.
//
// Mirroring `bd connect`'s own project-id pinning: if target.ExpectProjectID
// is empty, Connect pins it to whatever project the server answered with
// before calling Attach, so the workspace is tied to that project from this
// call on. If it is already set, Handshake itself refuses a mismatch and
// Connect returns that error without calling Attach at all. Connect does not
// replicate `bd connect`'s other CLI-level policy — --force re-pinning an
// already-attached workspace, or refusing to switch a workspace from a
// different backend — those stay the command's own job; Connect's contract
// is exactly "handshake, then attach".
func Connect(ctx context.Context, beadsDir string, target Target, opts Options) (*ServerSnapshot, error) {
snapshot, err := Handshake(ctx, target, opts)
if err != nil {
return nil, err
}
if target.ExpectProjectID == "" {
target.ExpectProjectID = snapshot.ProjectID
}
if err := Attach(beadsDir, target); err != nil {
return nil, err
}
return snapshot, nil
}

View file

@ -1,180 +0,0 @@
package bdhttp_test
// Written fresh for OSS beads S6: pins the bee-ghosttrack CHANGES_REQUESTED
// finding on #7288, should-fix 1 — `bd connect --clear` restoring a
// workspace's previous backend selection needs Attach to have recorded what
// that previous backend WAS, onto the sidecar, at connect time.
import (
"net/url"
"os"
"path/filepath"
"strings"
"testing"
bdhttp "github.com/steveyegge/beads/backend/http"
"github.com/steveyegge/beads/internal/configfile"
"github.com/steveyegge/beads/internal/httpclient"
)
func mustAttachTestURL(t *testing.T, raw string) *url.URL {
t.Helper()
u, err := url.Parse(raw)
if err != nil {
t.Fatalf("url.Parse(%q): %v", raw, err)
}
return u
}
// TestAttachRecordsThePriorBackendAsPreviousBackend is the first-connect
// case: a workspace that selected "dolt" before ever running `bd connect`
// must have Attach record "dolt" as PreviousBackend, so --clear can restore
// it later.
func TestAttachRecordsThePriorBackendAsPreviousBackend(t *testing.T) {
beadsDir := t.TempDir()
cfg := &configfile.Config{Backend: "dolt", Database: "beads.db"}
if err := cfg.Save(beadsDir); err != nil {
t.Fatalf("seed metadata.json: %v", err)
}
target := bdhttp.Target{BaseURL: mustAttachTestURL(t, "http://127.0.0.1:8080")}
if err := bdhttp.Attach(beadsDir, target); err != nil {
t.Fatalf("Attach: %v", err)
}
got, err := bdhttp.LoadTarget(beadsDir)
if err != nil {
t.Fatalf("LoadTarget: %v", err)
}
if got.PreviousBackend != "dolt" {
t.Errorf("PreviousBackend = %q, want %q", got.PreviousBackend, "dolt")
}
after, err := configfile.Load(beadsDir)
if err != nil {
t.Fatalf("reload metadata.json: %v", err)
}
// Asserts on the raw stored field, not GetBackend(): GetBackend() falls
// back to BackendDolt for any name backendnames.Has doesn't recognize
// (TestGetBackendAllowlist in internal/configfile), and "http" is only
// ever added there by bdhttp.Register/httpclient.Register — a
// once-per-process, panics-on-duplicate production wiring call this test
// package must not make. The raw field is exactly what Attach controls.
if after.Backend != httpclient.Backend {
t.Errorf("metadata.json backend = %q after Attach, want %q", after.Backend, httpclient.Backend)
}
}
// TestAttachOnAFreshWorkspaceRecordsTheImplicitDoltDefault covers a
// workspace with no metadata.json at all: GetBackend()'s own default
// ("dolt") is what a future --clear restores to, matching what every other
// backend-selection read in this codebase already treats as this
// workspace's backend.
func TestAttachOnAFreshWorkspaceRecordsTheImplicitDoltDefault(t *testing.T) {
beadsDir := t.TempDir()
target := bdhttp.Target{BaseURL: mustAttachTestURL(t, "http://127.0.0.1:8080")}
if err := bdhttp.Attach(beadsDir, target); err != nil {
t.Fatalf("Attach: %v", err)
}
got, err := bdhttp.LoadTarget(beadsDir)
if err != nil {
t.Fatalf("LoadTarget: %v", err)
}
if got.PreviousBackend != "dolt" {
t.Errorf("PreviousBackend = %q, want %q (configfile.BackendDolt)", got.PreviousBackend, "dolt")
}
}
// TestAttachOnAReconnectKeepsTheEarlierPreviousBackend covers a workspace
// ALREADY on http (a bare re-connect, or --force re-pinning the same
// backend): Attach must not overwrite an already-recorded PreviousBackend
// with "http" itself, or a chain of reconnects would forget what --clear is
// supposed to restore.
func TestAttachOnAReconnectKeepsTheEarlierPreviousBackend(t *testing.T) {
beadsDir := t.TempDir()
// Not dolt: an unregistered "http" reads back through GetBackend() as the
// dolt default, so a dolt prior could not tell carrying it forward from
// recording that default.
cfg := &configfile.Config{Backend: "postgres", Database: "beads.db"}
if err := cfg.Save(beadsDir); err != nil {
t.Fatalf("seed metadata.json: %v", err)
}
first := bdhttp.Target{BaseURL: mustAttachTestURL(t, "http://127.0.0.1:8080")}
if err := bdhttp.Attach(beadsDir, first); err != nil {
t.Fatalf("first Attach: %v", err)
}
// A second connect to a different url, same workspace, same backend
// ("http", already selected) — the shape `bd connect --force` to a new
// server produces for an already-http workspace.
second := bdhttp.Target{BaseURL: mustAttachTestURL(t, "http://127.0.0.1:9090")}
if err := bdhttp.Attach(beadsDir, second); err != nil {
t.Fatalf("second Attach: %v", err)
}
got, err := bdhttp.LoadTarget(beadsDir)
if err != nil {
t.Fatalf("LoadTarget: %v", err)
}
if got.PreviousBackend != "postgres" {
t.Errorf("PreviousBackend after a reconnect = %q, want the original %q carried forward, not the just-left \"http\"", got.PreviousBackend, "postgres")
}
if got.BaseURL.String() != "http://127.0.0.1:9090" {
t.Errorf("BaseURL = %q, want the second connect's url", got.BaseURL.String())
}
}
// TestAttachHonorsACallerSuppliedPreviousBackend covers Connect's doc
// contract: a caller that already set target.PreviousBackend itself (none
// of this package's own callers do today) must have that value win over
// Attach's own inference.
func TestAttachHonorsACallerSuppliedPreviousBackend(t *testing.T) {
beadsDir := t.TempDir()
cfg := &configfile.Config{Backend: "dolt", Database: "beads.db"}
if err := cfg.Save(beadsDir); err != nil {
t.Fatalf("seed metadata.json: %v", err)
}
target := bdhttp.Target{BaseURL: mustAttachTestURL(t, "http://127.0.0.1:8080"), PreviousBackend: "mysql"}
if err := bdhttp.Attach(beadsDir, target); err != nil {
t.Fatalf("Attach: %v", err)
}
got, err := bdhttp.LoadTarget(beadsDir)
if err != nil {
t.Fatalf("LoadTarget: %v", err)
}
if got.PreviousBackend != "mysql" {
t.Errorf("PreviousBackend = %q, want the caller-supplied %q to win over the inferred %q", got.PreviousBackend, "mysql", "dolt")
}
}
// TestAttachGitignoresBothPerUserFiles pins Attach's .gitignore guarantee for
// both files this backend keeps per user in beadsDir: the sidecar Attach
// writes, and the local metadata file the store writes later, on first use.
// `bd connect` also covers the second through doctor's required patterns,
// but an embedder activating through Attach alone has only this. A reconnect
// must not duplicate either line.
func TestAttachGitignoresBothPerUserFiles(t *testing.T) {
beadsDir := t.TempDir()
for _, raw := range []string{"http://127.0.0.1:8080", "http://127.0.0.1:9090"} {
if err := bdhttp.Attach(beadsDir, bdhttp.Target{BaseURL: mustAttachTestURL(t, raw)}); err != nil {
t.Fatalf("Attach(%s): %v", raw, err)
}
}
content, err := os.ReadFile(filepath.Join(beadsDir, ".gitignore"))
if err != nil {
t.Fatalf("read .gitignore after Attach: %v", err)
}
for _, name := range []string{httpclient.TargetFileName, httpclient.LocalMetadataFileName} {
count := 0
for _, line := range strings.Split(string(content), "\n") {
if strings.TrimSpace(line) == name {
count++
}
}
if count != 1 {
t.Errorf(".gitignore names %s %d time(s) after two Attaches, want exactly 1:\n%s", name, count, content)
}
}
}

Some files were not shown because too many files have changed in this diff Show more