Compare commits

...
Sign in to create a new pull request.

55 commits

Author SHA1 Message Date
Julian Knutsen
f3c47390e7
fix(storage): refuse graph_mode workspaces on library opens (#7721)
#7671 fences graph workspaces in cmd/bd: command admission, the store
factories and the other CLI paths refuse one, and #7722 extends that
fence to a .beads holding the graph-preview-format marker whatever its
metadata says. But the public library opens (beads.OpenBestAvailable,
OpenBestAvailableWith, OpenFromConfig, OpenGated) and the Dolt store's
metadata-driven constructors (NewFromConfig, NewFromConfigWithOptions,
NewFromConfigWithCLIOptions) still opened either kind of graph workspace
as an Issue store and ran Issue schema migrations into the graph
database (or, with no metadata beside the marker, created an Issue
database inside the graph workspace).

- Move the typed refusal into internal/configfile
  (UnsupportedWorkspaceFormatError with BeadsDir, GraphMode and
  FormatMarker; CheckWorkspaceFormat; GraphFormatMarkerFile;
  HasGraphFormatMarker) with byte-identical text and hints for both the
  graph_mode and the marker refusal, and move cmd/bd's discovery
  pre-checks there as LoadAndCheckWorkspaceFormat and
  CheckDiscoveredWorkspaceFormat (LoadForDiscovery, which never migrates
  a legacy config.json; unreadable metadata beside the marker is refused
  as the marker's format). cmd/bd's checkWorkspaceFormat,
  loadAndCheckWorkspaceFormat, hasGraphFormatMarker and
  checkDiscoveredWorkspaceFormat become thin delegates, so the CLI keeps
  its behaviour (exit 16 with the same hints) and every caller of them is
  unchanged; bootstrap's ancestor walk builds the configfile type.
- Every public metadata-driven open runs CheckDiscoveredWorkspaceFormat
  as its first statement: before OpenGated takes its gates and before
  OpenBestAvailableWith's Load can migrate config.json. A refused open
  leaves the workspace byte-identical. The type is exported as
  beads.UnsupportedWorkspaceFormatError.
- The Dolt constructors run CheckDiscoveredWorkspaceFormat before
  configfile.Load, so a graph workspace marked only by a legacy
  config.json, or by the marker beside stripped, missing or unparseable
  metadata, is refused before Load can migrate it into metadata.json
  (and drop graph_* keys this build does not know). requireDoltBackend
  re-checks the loaded config as a backstop, so they also refuse before
  resolving a server or writing a port file or Dolt root.

Tests: configfile unit tests for both refusals (exact marker text and
hint, graph_mode winning over the marker, unparseable metadata with and
without the marker); the public opens and the three Dolt constructors
against graph_mode workspaces and against marker-only, stripped
(metadata.json and legacy config.json), server, explicit dependency and
unparseable-metadata marker workspaces, each refused with the typed
error and the workspace left unchanged.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-20 09:29:54 +00:00
Julian Knutsen
bc1cd64c78
fix(cli): refuse graph workspaces marked by graph-preview-format (#7722)
The graph-mode fence decides a workspace's format from graph_mode in its
metadata alone. Graph-preview builds also write a
.beads/graph-preview-format marker before metadata.json (donnabox fork
commit deea8d57df, Donna Box), so that an interrupted or metadata-lost
graph workspace stays fenced. bd ignored the marker. When a bd that
predates graph_mode had rewritten metadata.json without the field, bd
opened the graph database by its recorded name and `bd list` ran Issue
schema initialization against it. When metadata.json was never written
or was lost, bd fell back to the default database name and created an
Issue database inside the graph workspace, and `bd init` initialized an
Issue workspace there.

checkWorkspaceFormat now also refuses a beadsDir that holds anything at
graph-preview-format, whatever its content and whatever the metadata
says (absent, stripped, or an explicit "dependency"). The graph_mode
check still runs first, so a normal graph workspace is still reported
by its graph_mode. The refusal is the same typed error with its own
message and a hint to restore metadata.json, so every call site, the
--json rendering and exit code 16 (ExitUnsupportedWorkspaceFormat) are
unchanged. An empty beadsDir never probes the working directory.

loadAndCheckWorkspaceFormat reads the metadata with LoadForDiscovery
and refuses metadata that cannot be parsed beside the marker as the
marker's format: the marker alone declares it. Command admission
(guardLegacyUpgradeWorkspaceForInit) uses it, and
checkDiscoveredWorkspaceFormat now delegates to it, so the paths that
check before a migrating configfile.Load (the four store factories,
create --repo's ensureBeadsDirForPath and dry-run target open, the bd
dolt loaders, bootstrap's undiscovered walk) refuse a marked workspace
too, with or without readable metadata. Other metadata load failures
are still left to the caller's own load, so a malformed legacy
config.json without the marker keeps create --repo's
auto-initialization.

bootstrap's ancestor walk (findParentConfig) refuses an ancestor that
holds the marker without metadata it can read, as it refuses one whose
metadata declares graph_mode. It used to skip a marker-only ancestor
and take a more distant workspace's metadata or the defaults, and to
report a marked ancestor with unparseable metadata as a load failure
(exit 1). With the check in checkWorkspaceFormat, bootstrap in a .beads
holding only the marker refuses it (exit 16) instead of reporting no
workspace.

validateConfiguredBackend returns early for nil metadata, so its
backstop covers the marker only when metadata was loaded; every caller
runs admission or checkDiscoveredWorkspaceFormat on the same beadsDir
first, and its comment now says so.

Tests: guard unit tests for marker-only, metadata lost, stripped
(metadata.json and legacy config.json), server, explicit dependency,
unparseable metadata, marker over a legacy Dolt root, and arbitrary
marker content; the four store factories (cgo, and the CGO_ENABLED=0
copies goreleaser ships) with stripped, missing and, for cgo,
unparseable metadata beside the marker; findParentConfig with a marked
ancestor below an ordinary workspace; the exit-code mapping;
ensureBeadsDirForPath with a malformed config.json with and without the
marker; and the subprocess e2e matrices (in-workspace commands, plain
`bd init`, and the outside entry points: create --repo, create
--dry-run, --db, BEADS_DB, init --proxied-server, bootstrap below it)
extended with four marker fixtures that must exit 16 with the marker
refusal and leave .beads byte-identical, while store-less commands
still run. The e2e subprocess timeout goes from 10s to 20s: refused
runs finish in well under a second, but an unrefused one creates or
opens a database and can approach 10s under load, so without the
fence the rows fail on their assertion rather than on the timeout.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-20 07:25:38 +00:00
gascity-eddie[bot]
d0d9aa2145
test(list): pin --deps scheduling ordering under --sort closed in the tree (#7703)
* test(list): pin orderSiblingsByDeps ready-set ordering under a sort-derived comparator

Drive orderSiblingsByDeps with compareIssuesForTree("closed", false) over
shuffled input so the caller-supplied compare at the initial ready-set sort
and the post-pop re-sort is exercised with an ordering that disagrees with
priority. Exact-order assertion: dropping or re-hardcoding the post-pop sort
only swaps pa-b and pa-v.

AC: AC-1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 5c973b4ba9)

Ported-From: opus/5c973b4ba9d93def077dfabe8186622052abffd5
AC: AC-1

* test(list): pin orderSiblingsByDeps cycle fallback under a sort-derived comparator

A two-node scheduling cycle where priority and ID favor pa-x but --sort
closed favors pa-y: the cycle fallback must follow the caller's compare.

AC: AC-2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit d29c4611e6)

Ported-From: opus/d29c4611e63422cee2ff9aee9cf2a9719b5dff71
AC: AC-2

* test(list): pin --deps scheduling ordering under --sort closed in the tree

Render the tree with depsMode=scheduling and sortBy=closed at both the root
level and under one parent: the blocks edge must still put dep before late,
while the requested sort (not priority) puts the unlinked free first. Covers
both orderSiblingsByDeps call sites in list_tree.go.

AC: AC-3

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit f434dcd5e4)

Ported-From: opus/f434dcd5e47643121c1b4f882f57c7bc68fc69a9
AC: AC-3

---------

Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
2026-10-20 02:19:13 +00:00
Julian Knutsen
1fcd715e75
fix(cli): refuse graph_mode workspaces and keep their metadata marker on save (#7671)
* fix(configfile): carry graph_mode and graph_* binding through Save

Graph-preview builds of bd persist a per-workspace format in
metadata.json: "graph_mode": "link" plus graph_scope_url,
graph_authority_id, graph_workspace, graph_schema_version and
graph_ready, beside an ordinary Dolt backend. configfile.Config had no
such fields, so every Save, and Load's config.json -> metadata.json
migration, rewrote the file without them, turning a graph workspace's
metadata into an ordinary Issue workspace's.

Config now carries the marker and the binding as omitempty fields, so
a Save round-trips them unchanged and metadata.json written for an
ordinary workspace is byte-for-byte what it was. GetGraphMode resolves
the marker: absent or "dependency" is the historical default, "link"
is recognized, and any other value is an error rather than a fallback
to the Issue store. Nothing in this build opens a non-default mode;
the CLI refusal follows in the next commit.

Ported from the donnabox fork commit deea8d57df (graph_mode.go,
graph_mode_test.go and the configfile.go fields), without any graph
code. The binding-survives-Save and omitted-from-ordinary-metadata
tests are new.

Co-authored-by: Donna Box <dbox@boxenllc.com>
Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(cli): refuse graph_mode workspaces before opening them

A workspace whose metadata.json declares a graph_mode other than
"dependency" holds a graph database behind an ordinary Dolt backend,
and nothing else in its metadata says so. bd admitted it like any
current workspace: `bd list` ran the Issue schema initialization
against the graph database (beads_graph_<id>), `bd init --force` wrote
a .gitignore and a .beads/dolt root into it, `bd dolt start` started a
server for it, and `bd doctor` reported on it as an Issue store.

guardLegacyUpgradeWorkspace, the admission check every store-opening
command, store-less command with workspace effects, init, doctor and
bootstrap already run before touching a workspace, now refuses such a
workspace first, before the legacy classifications that would admit
it or report it as a legacy store to migrate. An unknown graph_mode
value is refused the same way. The refusal is a typed error naming the
workspace and the format, rendered with a hint (as JSON under --json)
and exit code 16, ExitUnsupportedWorkspaceFormat, so a wrapper can
tell "needs a different bd build" from a generic failure.
`bd version`, `bd --version`, `bd help` and completion stay exempt, as
they are for legacy workspaces. validateConfiguredBackend refuses the
same metadata, which covers the store-open paths that skip command
admission (routed writes, cross-repository reads, create --repo).

Tests: guard and store-factory unit tests; a subprocess e2e test that
show/list/create/context/where/dolt start/doctor/bootstrap/init are
refused with exit 16 and leave .beads byte-identical (metadata.json and
legacy config.json, link and unknown markers, embedded and server
layouts), and that store-less commands still run; an embedded test
that an ordinary workspace, with the marker absent or "dependency",
still creates and lists issues and keeps the marker through a
metadata.json rewrite.

The guard hunk and graph_mode_admission_e2e_test.go are ported from
the donnabox fork commit deea8d57df; the exit code, rendering, store
factory backstop and remaining tests are new.

Co-authored-by: Donna Box <dbox@boxenllc.com>
Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(cli): refuse graph workspaces reached outside command admission

Command admission refuses a graph_mode workspace a command runs in, but
bd also reaches workspaces before or without admission: a create --repo
target, the path --db or BEADS_DB names, and the stores the factories
open for routed and cross-repository work. On those paths a workspace
marked only by a legacy config.json was changed before anything refused
it: configfile.Load migrates config.json into metadata.json before the
format check sees the loaded metadata, and create --repo initialized
such a target as a new workspace. Where the refusal did come, create
reported it with exit 1 rather than 16.

- checkDiscoveredWorkspaceFormat checks a workspace's metadata as
  configfile.LoadForDiscovery reads it, which never rewrites it.
  ensureBeadsDirForPath, the dry-run target open and the four store
  factories (cgo and nocgo builds) run it before their own load.
- resolveBeadsDirForDBPath and findDatabaseInBeadsDir locate a
  workspace with LoadForDiscovery, so resolving --db, BEADS_DB or a
  create target no longer migrates it.
- bd create renders a refused target as the workspace refusal, exit 16
  with its hint, on the initializing and both dry-run paths. A dry run
  without --parent opens no target, so it now checks a local one before
  rendering the preview (checkRepoTargetFormat).
- bd bootstrap, when discovery finds no workspace, reads each .beads
  from the working directory up to the repository root without
  migrating it and refuses one in a format this build cannot open, the
  way commands without a workspace already do. A .beads marked only by
  config.json is passed over by discovery, so bootstrap reported "no
  workspace" there instead of exit 16. The walk now returns its
  candidates (undiscoveredWorkspaceCandidates) to both checks: handing
  it the check as a func(string) error made gosec's G702 taint analysis
  connect BEADS_DIR to every func(string) error that runs git.
- backendNameForErrorFraming reads with LoadForDiscovery, and
  loadDoltBackendConfig, bd dolt status and bd dolt show refuse a graph
  workspace before their migrating configfile.Load. Admission refuses
  first on every path that reaches them today; this keeps a new caller
  from migrating a legacy config.json before the refusal.
- The CHANGELOG entry and the configfile comment now claim what holds:
  a routed read fails without touching a graph workspace but not with
  code 16, and a Save keeps only the known graph_* fields, with the
  tags graph-preview builds declare. workspace_gate.go no longer lists
  the pre-gate discovery reads as migrating.
- New e2e rows run create --repo from a workspace and from outside one,
  create --dry-run with and without --parent, --db, BEADS_DB, init
  --proxied-server, bootstrap in a workspace nested in a graph one, and
  the hook shim's bd hooks run pre-commit against every fixture; each
  refusal must exit 16 and name the format and the hint. bootstrap in a
  workspace marked only by config.json now refuses like the other
  commands. The store factory test also runs on a config.json graph
  workspace, TestWorkspaceMetadataReadersLeaveGraphWorkspaceUnchanged
  covers the framing, bd dolt loader and diagnostic reads, and
  TestNocgoStoreFactoriesRefuseGraphWorkspace covers the CGO_ENABLED=0
  factories; bazel.yml's pure lane runs it by name (PURE_CMD_BD_TESTS,
  pinned in scripts/ci_workflow_test.go).

Measured with gocyclo/gocognit: every function this changes stays below
the PR's worst changed function (guardLegacyUpgradeWorkspaceForInit
29/28, resolveBeadsDirForDBPath 26/36); showDoltConfig is 19/31 (was
18/30) and guardUndiscoveredLegacyWorkspace 3/3 (was 9/12).

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Donna Box <dbox@boxenllc.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
2026-10-20 00:05:39 +00:00
gascity-eddie[bot]
4df395698b
fix(bazel): the root go_srcs glob skips Bazel's convenience symlinks, so //cmd/bd tests cache (#7714)
The root //:go_srcs filegroup is glob(["**/*.go"]), and a glob follows the
checkout's bazel-bin/bazel-out/bazel-testlogs/bazel-beads symlinks into the
output tree. CI's test step is the first build in a fresh checkout, so it never
sees them, but in any checkout that has built before every test that reads
//:go_srcs (bd_test, bd_embedded_test, bd_embedded_part2_test,
bd_dolt_server_test, bd_proxied_test, bd_managed_local_test) gains the output
base's .go files: their inputs differ on every run, they are never cached, and
loading grows with the output tree.

Measured on main 2563f021ed with the symlinks present, `bazel test
//cmd/bd:bd_test --config=ci --test_filter='^TestResolveCommitHash$'` twice:
both runs executed all 16 shards remotely, and the analysed graph grew from
20,773 to 56,941 configured targets (14 s, then 25 s). With this change the
second run is `(cached)` in 3.6 s. In agent worktrees the glob had reached
433,026 output-tree files, a cached re-run took 36 s to load against ~3 s
without them, and 135 of 202 blocking test minutes of the factory's beads
seats went to these six targets (formula-overhead audit 4; bead ga-ylpbsy.24).

tools/bazel/go_srcs.py gives the root block exclude = ["bazel-*/**"] (the
same pattern ROOT_REPO_FILES_EXCLUDE already uses for //:repo_files); only
the root BUILD.bazel changes. CI's action keys do not change: its checkout has
no such files. scripts/bazel_policy_test.go's
TestBazelRootGoSrcsSkipsConvenienceSymlinks fails without the exclude.

Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 23:30:10 +00:00
Julian Knutsen
c86a87bb20
test(oracle-a): pin BEADS_TIP_SEED so human-output scenarios stop flaking (#7707)
After a successful human-output create/show/list/ready, bd may append a
"💡 Tip:" line chosen by a probability roll whose RNG is clock-seeded
unless BEADS_TIP_SEED is set. run_scenario env_clear()s and passes only
PATH/HOME/TMPDIR + BEADS_TEST_MODE=1, so on a host with ~/.claude (claude_setup
tip eligible, p=0.6) every bd process rolled independently and out-of-scope
human-output scenarios (create_human_readable_output, show_short_mode_text,
show_multiple_short, ready_empty_no_issues_plain, ...) diverged main-vs-main.

Pass BEADS_TIP_SEED=1214 to every step for both reference and candidate.
Go math/rand's first Float64() for that seed is 0.0000159, so the
highest-priority eligible tip always wins its roll. Where the host makes a
tip eligible, it stays visible and lands on a deterministic step, so a change
to which tip prints, on which step, or to its text (including a tip leaking
into --json) still diverges instead of being normalized away. Where no tip is
eligible (no ~/.claude, beads plugin enabled, or a `bd prime` hook) none
prints and tip changes go unobserved; the README now says so.

The new unit test spawns printenv through run_scenario. That races the
existing stub-bd test, which writes its stub with std::fs::write and then
execs it: a fork while the write fd is open makes the exec fail with ETXTBSY
(rust-lang/rust#114554). Serialize both spawning tests on a SPAWN mutex.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 22:02:44 +00:00
Julian Knutsen
8988340994
ci(embedded): run every BEADS_TEST_EMBEDDED_DOLT-gated cmd/bd test in the embedded lane (#7708)
* test(cmd/bd): repair the embedded-gated tests that rotted while no lane ran them

These tests skip unless BEADS_TEST_EMBEDDED_DOLT=1 but no CI lane selected
them, so they rotted unseen. Running them shows:

- TestEventsTailFollowReportsTruncationOnTheStream raced on a plain
  bytes.Buffer that os/exec's copy goroutine writes while the test polls it.
  Use the package's syncBuffer.
- TestCorruptMetadataDiagnosticsRunAndDataFailsLoud still asserted that
  doctor and init run on a corrupt metadata.json. #4857 deliberately made
  every workspace command refuse instead (pinned for doctor by
  TestDoctorRejectsCorruptMetadataBeforeSharedServerChecks). Rewrite it to
  the shipped contract as TestEmbeddedCorruptMetadataFailsLoudUntilRestored:
  version warns, doctor/list/init refuse naming the file without touching
  it, and restoring the file brings the data back.
- dolt_remote_origin_guard_embedded_test.go was tagged
  `embeddeddolt && cgo`, a tag no lane sets, so it never compiled in CI
  (gazelle left it out of bd_test srcs). Retag it `cgo`, as #4153 did for
  its dolt_local_only sibling, and add it to srcs. Drop its four bd doctor
  git-origin tests: bd doctor runs no checks on an embedded workspace
  (GH#3794), so two could never pass and two passed vacuously on empty
  output. Rename the surviving tests into the TestEmbedded* prefix.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(embedded): run every BEADS_TEST_EMBEDDED_DOLT-gated cmd/bd test in the embedded lane

The embedded-Dolt cmd lane selected tests with
grep '^func TestEmbedded' cmd/bd/*_embedded_test.go, and only its two
Bazel targets set BEADS_TEST_EMBEDDED_DOLT. A test that skips without the
variable but missed the name prefix or the file suffix skipped in every
lane and reported green: 92 of them, including #7203's --if-revision CLI
coverage (TestIfRevisionMatchAndMismatch, TestReassignFenceCLI, ...).

- embedded-test-shard.sh and gen_embedded_cmd_shard_manifest.py select
  TestEmbedded* by name across cmd/bd/*_test.go, as proxied-test-shard.sh
  does, leaving authors one rule.
- Rename the gated tests into the TestEmbedded* prefix
  (TestDoctorEmbedded<X> -> TestEmbeddedDoctor<X>) and update every
  reference.
- Place the new names with gen_embedded_cmd_shard_manifest.py 100
  --weights=duration --write (incremental).
- Add TestEmbeddedGatedTestsRunInTheEmbeddedLane: it walks cmd/bd's tests
  for any that reach os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" and fails
  if a shard of the lane never lists one. The proxied guard's helpers now
  take the variable and the script; a fixture test pins the walk.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 22:02:22 +00:00
Julian Knutsen
2563f021ed
perf(httpclient): remember the server's external-dependency policy across processes (#7700)
* perf(httpclient): remember the server's external-dependency policy across processes

Every bd ready over an HTTP workspace fetched GET /v0/beads/context before
its listing. listReadyWork itself needs no handshake; the fetch came from the
external-dependency decorator asking ServerEnforcesExternalDependencyPolicy
whether the server already applies the policy. In a one-shot CLI that is one
extra round trip per process (about 54 ms at a 52 ms RTT) to relearn a bit
that only changes when the server is restarted with a different composition.

The store opened from a workspace now keeps that answer in the user cache
directory (beads/http-policy/), keyed by the server URL and the project the
workspace pinned at bd connect, for BEADS_HTTP_POLICY_CACHE_TTL (5 minutes by
default; off disables it). A fresh entry answers the probe without dialing; a
handshake this process already holds wins and refreshes the entry. A
workspace with no project pin, and a store an embedder opens through
OpenWith, are not cached. Writing the entry is best effort.

The staleness this allows is bounded by the TTL: a server restarted without
the policy within the window is still trusted to enforce it until the entry
ages out. Carrying the policy on every response would close that window but
needs a server change and does nothing for servers already deployed.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of gascity-agent
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(httpclient): claims and closes ask the server for the policy, never the cache

Review follow-up to the policy cache. The claim and close guards (direct
claim, claim-next, batch close, the lifecycle close and claim, and the legacy
ClaimReadyIssue and CloseIssueChecked) handshake anyway, and a stale cached
"the server enforces it" would stand down their client-side refusal of
externally blocked work. Those entry points now mark their context with
storage.WithLivePolicyProbe, and httpclient.Store answers such a probe from
the server, refreshing the cache entry. Reads keep the cached answer.

Tests: externaldeps TestClaimsAndClosesAskForALivePolicyProbe and
TestRemoteClaimsAndClosesAskForALivePolicyProbe pin which entry points probe
live (every claim and close) and which do not (ready listings), over a local
and a remote store; httpclient TestALiveProbeSkipsThePolicyCache pins the
store side; TestPolicyCacheRefusesEntriesItCannotTrust now also covers an
entry written for another server URL.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of gascity-agent
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 19:05:55 +00:00
Julian Knutsen
d097b6c8a4
perf(ready): skip the countReadyWork request when bd ready --json prints no total (#7699)
* perf(ready): skip the countReadyWork request when bd ready --json prints no total

Over a remote backend, bd ready --json sent GET /v0/beads/ready and then,
whenever the page came back with has_more, GET /v0/beads/ready:count, only to
put "of N" into the stderr hint. Without BD_JSON_ENVELOPE nothing else prints
the total, so that second request (about 120 ms at a 52 ms RTT) bought a
number no caller reads.

On a remote backend without the envelope, bd ready --json now lists one row
past the limit and says whether more exist without saying how many, in the
wording the proxied route already uses. A local store keeps the in-band total
it takes in the page's own transaction, and the envelope keeps
pagination.total. A --max-rows cap at or below the limit keeps the counted
listing, so the extra row never trips the cap.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of gascity-agent
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(ready): say "1 ready issue", not "1 ready issues", in the no-total hint

Review follow-up. The hint the remote --json path shares with the proxied
route now agrees in number; both routes take it from readyHiddenHint, so
they stay one wording.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of gascity-agent
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 18:15:57 +00:00
Julian Knutsen
d28f56cd46
perf(startup): initialize packages on four Ps, not every CPU (#7701)
* perf(startup): initialize packages on four Ps, not every CPU

bd links several thousand packages whose init functions allocate about
20 MB before main runs, which triggers four or five garbage collections.
Each one starts mark workers and stops the world across every P, and on a
large host that costs more than the collection itself: on a 192-CPU machine
`bd version` spent about 20 of its 110 ms there, paid again by every bd
process a script or an orchestrator starts.

internal/initprocs lowers GOMAXPROCS to 4 for the duration of package
initialization. It imports only runtime and syscall, so it initializes
ahead of the heavy packages, and main hands GOMAXPROCS back first thing:
to the GOMAXPROCS environment value when one is set, else to the runtime
default, which keeps tracking the CPU limit.

cmd/bd's TestMain does the same hand-back, since tests never run main, and
resets the -test.parallel default testing derived from the capped count.

Measured on that host (40 runs each, `bd version`): p50 103 -> 86 ms.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of gascity-agent
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(initprocs): tell an explicit GOMAXPROCS hand-back from the runtime default

Review follow-up. TestDoneHonorsAnExplicitGOMAXPROCS swaps the two runtime
calls for recorders and pins that Done restores the exact value when
GOMAXPROCS is set and calls SetDefaultGOMAXPROCS when it is not; the earlier
test only saw the resulting count, which is the same either way on a host
whose default equals the saved value.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of gascity-agent
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 17:15:54 +00:00
Julian Knutsen
18b5c3cc39
fix(httpclient): name the connect failure when bd serve cannot be reached (#7702)
* fix(httpclient): name the connect failure when bd serve cannot be reached

A workspace whose server does not answer reported the transport's text:
`cannot reach bd serve at https://host:30699: Get "https://host:30699/v0/beads/context":
dial tcp 100.85.56.42:30699: i/o timeout`. It names the request rather than
the address that failed, and says nothing about what a dial timeout usually
means. An operator chasing an unreachable store had to know that "i/o
timeout" on a dial means the SYN went unanswered.

A request whose connection could not be opened now fails with a
*wire.DialError inside the *ConnectError: a refused connect names the
address and says nothing is listening there; a connect that times out names
the address that never answered, how long the attempt waited, and that a
firewall dropping the connection or a down host is the usual cause; a host
name that does not resolve is named as such. The transport's error stays
reachable through Unwrap, so errors.Is checks (ECONNREFUSED, timeouts) and
*ConnectError classification are unchanged, and a dial the caller canceled
keeps its own error. The events:watch connect gets the same classification.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of gascity-agent
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(httpclient): keep the transport's dial text in connect errors

Review follow-up. The refused and DNS messages dropped "connection refused"
and "dial tcp", the vocabulary gc's text classifier matches to tell an
unavailable store from other failures; without it the dispatcher's serve
loop exits and control beads are quarantined. Every DialError message now
ends with the transport's own *net.OpError text in brackets, after the
explanation.

TestACanceledDialIsTheCallersOwn now actually reaches the ctx.Err() guard:
its round tripper cancels and hands back a genuine refused dial, which the
guard alone keeps from becoming a DialError (removing the guard fails it).

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of gascity-agent
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 16:54:25 +00:00
gascity-eddie[bot]
4f9174e6ba
docs(agents): bazel test is authoritative; agents never run go test (#7695)
* docs(agents): bazel test is authoritative; agents never run go test

Agents run tests only with `bazel test`, also while iterating on one
behavior: AGENTS.md shows the focused form
(`bazel test //cmd/bd:bd_test --config=ci --test_filter='^TestName$'`), the
target naming, that one --test_filter covers every target, that a cached
result for unchanged inputs is the same evidence, and that a new test file
needs `make bazel-sync` before Bazel runs it. `go test` (`./scripts/test.sh`,
`make test-go`) stays a convenience for humans working offline. TESTING.md's
focused red/green row and its plain-go-test section say the same.

Why: on the maintainer-city factory host, seats' own uncached `go test`
reruns of the same packages are the largest tool cost in adopt-pr, while
`bazel test` there executes on rbe-west and returns an unchanged target's
cached result in seconds.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(agents): check that a focused test ran; exempt golden regeneration

Review fixes for #7695 (iterations 1 and 2).

The focused form exits 0 with "1 test passes" when the test never ran: a
filter that matches nothing, an integration-tagged file --config=ci does not
compile, the TestEmbedded* name skip, a -short skip, and a parent test whose
every subtest skipped (Go still prints "--- PASS" for the parent). It now
adds --test_output=all, and a run counts only when its log shows
"--- PASS: <TestName>" and no "--- SKIP" for the test or a <TestName>/...
subtest; a subtest that skips by design is left out with a subtest filter.

engdocs/TESTING.md gains "Check That the Test Ran"; AGENTS.md links there
instead of restating it. The section names the tests --config=ci does not
run and the way into each:
- Dolt-backed: the three --test_env flags, or the test's Dolt lane.
- -short-gated: --test_arg=-test.short=false.
- integration-tagged: --config=integration; the Dolt-backed ones of cmd/bd,
  tests/regression and internal/storage/dolt run in their Dolt-server lane
  target, whose env the suite needs. No lane runs those of other packages
  with Dolt, so a failure there is compared with the base commit first.
- TestEmbedded*: --test_arg=-test.skip= lifts the name skip; a test that
  then still skips for BEADS_TEST_EMBEDDED_DOLT=1 runs in its package's
  embedded-tagged target under --config=embedded (the cmd/bd and
  internal/storage/embeddeddolt targets are named).
- files BUILD.bazel does not list: make bazel-sync.
A lane's sh_test can hand the test binary its own -test.run, which
overrides --test_filter, so a trailing --test_arg=-test.run with sharding
disabled selects the test there. In a sharded target the other shards print
"testing: warning: no tests to run". The section also gives the
target-naming rule.

Golden regeneration (make corpus-regen, make githooks-regen,
BD_UPDATE_GOLDEN=1 ... go test, -update-ledger-doc) writes the source tree,
which a Bazel test cannot do: it runs from its runfiles tree, and on
rbe-west update mode fails with "permission denied". AGENTS.md and the new
"Regenerating Golden Files" section exempt these go test runs; where a host
refuses go test even for them, a maintainer regenerates. The factory seat
shim (gastownhall/workflows#102, scripts/seat-bin/go) still refuses update
mode and needs the same carve-out there.

Also: the plain-go-test opener scopes "humans working offline" to the
runner and its go test targets, so the Dolt-backend, fixture and
testing.Short() rules still bind agents; make ci-pr-core is marked plain go
test; the beads-docs skill's docsync gate is the Bazel target; RELEASING.md
and engdocs/RELEASE-STABILITY-GATE.md name the regression suite's Bazel
target (//tests/regression:regression_test under --config=doltserver-cmd)
in place of make test-regression, which is plain go test.

Measured on rbe-west (exit 0 unless noted). Iteration 1, at c4d5409895:
- a mistyped filter, and //internal/compact TestNew (integration-tagged)
  under --config=ci: "testing: warning: no tests to run"
- TestNew under --config=integration: "--- SKIP" (BEADS_TEST_SKIP=dolt);
  with the Dolt flags added it runs (and fails, exit 3, on the local
  backend: its store finds no "beads" database; outside this PR)
- TestConcurrentHeartbeatReclaimClose with the Dolt flags: "--- SKIP"
  (short mode); plus --test_arg=-test.short=false: "--- PASS"
- //cmd/bd:bd_embedded_test, sharding disabled: --test_filter alone ran
  TestEmbeddedUpdateConcurrent (manifest shard 1's test); the trailing
  -test.run ran "--- PASS: TestEmbeddedShowBasicsAndJSON"
- //scripts:go_test_sources_test
  TestEmbeddedCmdShardManifestBareWriteIsIdempotent: --config=ci "no tests
  to run"; plus --test_arg=-test.skip=: "--- PASS"
Iteration 2, at b1d25543aa (the same Go inputs):
- //internal/storage/dolt:dolt_test TestMoveIssuePersistenceInTxTransitions
  under --config=ci: "--- PASS" for the parent and "--- SKIP" for all 6
  subtests (BEADS_TEST_SKIP=dolt), "1 test passes"; with the Dolt flags and
  --test_filter='^TestMoveIssuePersistenceInTxTransitions$/^persistent-to-ephemeral$'
  "--- PASS" for the parent and that subtest only, no "--- SKIP"
- //internal/storage/embeddeddolt:embeddeddolt_test
  TestEmbeddedRemoteMigrateGate_BlocksReopen under --config=ci plus
  --test_arg=-test.skip=: "--- SKIP" (BEADS_TEST_EMBEDDED_DOLT unset);
  //internal/storage/embeddeddolt:embeddeddolt_embedded_test under
  --config=embedded, sharding disabled, trailing -test.run: "--- PASS"
  (the shard script listed 433 tests; only the named one ran)
- --config=ci plus --test_arg=-test.skip=: "--- PASS" for //tools/nogo
  TestEmbeddedConfigIsTheRepositoryConfig and //internal/tracker
  TestEmbeddedDoltExternalRefChangedAfterUsesHistoryFastPath
- sharding disabled, trailing -test.run: "--- PASS" for
  //internal/storage/dolt:dolt_server_full_test
  TestWispDeleteCascade_TransactionDeleteIssue under
  --config=doltserver-integration, and for //cmd/bd:bd_dolt_server_test
  TestCLI_ReopenClearsDeferUntil under --config=doltserver-cmd
- make check-docs: exit 0 (docsync: 10 test cases ran, none skipped)

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 14:04:30 +00:00
Julian Knutsen
1de9b59324
fix(setup): bd setup claude --global manages the section in ~/.claude/CLAUDE.md, not the current directory (#7696)
* fix(setup): keep bd setup claude --global's section in ~/.claude/CLAUDE.md

bd setup claude --global put its hook in ~/.claude/settings.json but wrote
the managed beads section into the current directory's CLAUDE.md, and
--remove --global stripped it from there. Run from $HOME it created
~/CLAUDE.md with project scaffolding, which stops Claude Code reading
AGENTS.md in projects below it; run inside a project it removed the
section that project's own install had written, leaving its hooks.

A global install and removal now manage the section in Claude Code's
user-level ~/.claude/CLAUDE.md (created holding only the section, no
project scaffolding), with hints naming bd setup claude --global. With
global or plugin hooks, --check reports that file when the project's
instructions have no beads section; a project install is still judged
on the project's file alone. Project installs are unchanged.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(setup): render the user-level CLAUDE.md section independently of the project

~/.claude/CLAUDE.md is shared by every project, but bd setup claude --global
rendered and --check judged its section with the current directory's beads
config (sync.remote, sync.git-remote, no-push). From a project with a remote
and one without, --check called the other's install stale and its hint
flipped the file back. The user-level file now always renders with the
default options, so install and --check agree across projects.

Also pin --check's fallback to the project's file and project hint when
neither file has a section, tell existing --global users to re-run it, and
name ~/.claude/CLAUDE.md in the ide-setup recipe table.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(setup): judge the user-level Claude files from $HOME and ~/.claude

Run from the home directory, the project's .claude/settings.json is the
global one, so bd setup claude --check reported a global install as project
hooks and judged ~/CLAUDE.md; its "Run: bd setup claude" hint then created
the ~/CLAUDE.md a global install exists to avoid. Run from ~/.claude, the
project's CLAUDE.md is the user-level file, and --check judged it with that
directory's render options and the project hint.

--check now reports hooks as global from $HOME and judges the user-level
file there and from ~/.claude with the fixed options and the --global hint.
With user-level hooks and no section in either file it names --global
unless the project has its own CLAUDE.md. A --remove run from $HOME, which
removes the global hooks, also removes the user-level section.

The init agent-artifact test ran bd setup claude with HOME at the project,
so its checks would now see a home directory; it gets a separate HOME and
its goldens are unchanged.

Rebase note (maintainer): rebased onto main after #7678 merged; main's
agent-artifact harness already runs bd with a separate HOME, so this
commit's harness edits to cmd/bd/agent_artifacts_embedded_test.go were
dropped.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(setup): pin --check's user-level choice beside project instructions

With global hooks, --check judges ~/.claude/CLAUDE.md when the project's
own CLAUDE.md has no beads section but the user-level file has one, and
when run from the home directory whose ~/CLAUDE.md has no section. Nothing
exercised either half of that condition: replacing it with false left the
suite and goldens green. Add a subtest for each; each now fails when its
half of the condition is dropped.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(setup): name --global when --check finds no hooks from $HOME

From the home directory --check with no hooks said 'Run: bd setup claude'.
Following it runs a project install there, which creates ~/CLAUDE.md with
project scaffolding, the file that stops Claude Code reading AGENTS.md in
the projects below it. The missing-section hint at home already names
--global; make the missing-hooks hint match, with a subtest.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(setup): qualify the --global CHANGELOG entry; watch ~/.claude/CLAUDE.md

The CHANGELOG said --check from the home directory judges the user-level
files, but a beads section still in ~/CLAUDE.md is judged instead, and
the --global hint for a missing section applies only when the project has
no CLAUDE.md of its own. Say both, mention the new missing-hooks hint at
home, and re-wrap the paragraph.

The embedded agent-artifact harness comment said a global install writes
$HOME/CLAUDE.md; it now writes $HOME/.claude/CLAUDE.md. Track that path
too and reword the comment. The bd init goldens do not change.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(setup): word the user-level CLAUDE.md section for repositories that use beads

bd setup claude --global writes its section to ~/.claude/CLAUDE.md, which
Claude Code loads in every project, but rendered it with the project
wording: "This project uses bd (beads)" and "Use bd for ALL task tracking —
do NOT use TodoWrite". In a repository without beads that told the agent to
give up its own task tools and pointed it at bd, whose answer there is
"run 'bd init'", while the global hook, bd prime, stays silent outside a
workspace.

RenderOpts.UserLevel rewords the opening line and the task-tracking rules of
both profiles so they apply only in beads repositories. The global env fixes
it through agents.UserLevelRenderOpts, so install, in-place update and
--check agree on the hash from every directory, and a project-worded section
left in ~/.claude/CLAUDE.md reads as stale and is reworded by --global. The
new minimal-user and full-user variants are pinned by golden and hash; the
project rendering is unchanged.

Also pin sameDir's symlink following: --check from a symlink to $HOME or to
~/.claude still judges the user-level files.

Refreshed onto main past #7692, whose --remove takes the blank lines
around the section with it and whose setup appends a section after one
blank line: claude-setup-global-beside-project-install.golden no longer
records the old hole (an extra blank line before the appended section,
two left behind by --remove --global).

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
2026-10-19 12:22:04 +00:00
Julian Knutsen
2829d22192
test(oracle-a): let scenarios that start with init own initialization (#7704)
run_scenario always ran `bd init -p <prefix> --quiet` before a scenario's
steps. 43 deterministic catalog scenarios start with their own
`init --prefix X --non-interactive ...`; in 40 of them that step always hit
"This workspace is already initialized" (exit 1), pinning the double-init
refusal instead of a real init. The other 3 fail flag validation first,
which is what they test, and are unchanged. Their later steps (the commands
they are named for) ran against the harness's own pre-init and are
unaffected.

A scenario whose first step's command token is `init` now owns
initialization (Scenario::owns_init) and starts in an empty workspace; every
other scenario keeps the pre-init, and a later `init` step stays a re-init.
The pre-init decision is the pure harness_init() helper, and the step loop
is run_steps(), which takes the command runner as a closure.
normalize() now collapses the `Repository ID`/`Clone ID` values a real init
prints (hashed from the random workspace path) to <REPO_ID>/<CLONE_ID>.
init_proxied_server_not_implemented is marked deterministic:false: its
premise is stale and, un-masked, it starts a managed dolt sql-server.

New tests cover the owns_init rule, the harness_init decision, the
run_steps argv sequence (via a recording closure) and the fingerprint
normalization. None spawns a process, so none can hit the write-then-exec
ETXTBSY race against the suite's process-spawning tests.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 10:57:02 +00:00
Julian Knutsen
21dac62a4c
fix(init): drop bd dolt push from AGENTS.md Quick Reference without a remote (#7694)
A new AGENTS.md written by bd init rendered its managed section with the
HasRemote/NoPush rule, but wrote the template text around it verbatim, so
the Quick Reference still listed `bd dolt push` in workspaces with no Dolt
remote or declared no-push. Add EmbeddedDefaultWithOpts, sharing one
omitsDoltPush predicate with the managed-section renderer, and use it for
new AGENTS.md files. Managed-section bytes and hashes are unchanged; an
existing AGENTS.md and a custom --agents-template are written as before.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 10:36:59 +00:00
gascity-eddie[bot]
4c473b4580
fix(query): report an uppercase duration unit as an unparseable time, not a negated internal error (#7683)
* refactor(timeparsing): export IsCompactDuration

The query lexer keeps its own copy of the compact-duration unit set, and
that copy has drifted from the grammar: it accepts the uppercase units
H D W M Y, which ParseCompactDuration rejects. Export the classifier so
the lexer can ask timeparsing instead of keeping a copy, and pin that it
agrees with ParseCompactDuration on every row, uppercase spellings
included.

AC: AC-1
Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(query): classify durations with timeparsing.IsCompactDuration

The query lexer kept its own copy of the compact-duration unit set:
isDurationSuffix for single runes and durationWords for "min". The copy
had drifted. It accepted H D W M Y, which the case-sensitive grammar
rejects, so "created>30M" reached the evaluator as a duration and failed
with the internal error `not a compact duration: "-30M"`, quoting a value
the user never typed.

Classify the whole digit-led lexeme with timeparsing.IsCompactDuration
and delete the copy (isDurationSuffix, durationWords, acceptDurationWord).
Uppercase units now lex as identifiers and fail as an unparseable time;
every lowercase input lexes as before. A unit added to compactDurationRe
now reaches the lexer with no edit here: with "sec" added to the regex
alone, TestCompactDurationGrammarReachesQueryPlane fails on the old lexer
and passes on this one. Retire that test's text naming the deleted copy.

AC: AC-2
Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(query): pin that uppercase duration units lex as identifiers

"updated>30M", "updated>30H" and "label=30D" lex the value as one
TokenIdent with the text as typed; "updated>30m" and "updated>+30d"
still lex as TokenDuration. On the base lexer the three uppercase rows
fail (typed DURATION).

AC: AC-3
Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(query): pin the error for an uppercase duration unit

created>, updated<, closed>= and started<= compared to 30M, 30D, 30W,
30Y, 30H or 1H, alone or in "... OR status=open", fail with
`cannot parse time expression: "<value as typed>"`, never with the
internal `not a compact duration` error and never quoting the negated
"-<value>". 30MIN and 30Min, which always took this path, are the
controls. On the base lexer 30 of the 40 subtests fail; the 10 controls
pass.

AC: AC-4
Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(query): bind the lexer's duration grammar to timeparsing both ways

TestCompactDurationGrammarReachesQueryPlane asserted only that every
suffix ParseCompactDuration accepts lexes as a duration. Assert the
reverse too: a suffix it rejects must not lex as TokenDuration, or the
evaluator fails on it with ParseCompactDuration's internal error about a
negated value. Widen the candidates to every one- and two-letter ASCII
suffix in either case, every three-letter lowercase one, and every case
spelling of an accepted three-letter unit.

On the base lexer the reverse sweep fails on exactly [D H M W Y]. A
mutant that case-folds before classifying fails it on those plus the
seven other spellings of "min".

AC: AC-5
Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(query): pin that a signed uppercase unit stops at the parser

"created>+30M" and "created>-30M" fail Parse and EvaluateAt with
`unexpected token "M" at position 11 (expected end of query)`, as
"created>+30x" already does: a signed digit run has no identifier
fallback, so "+30" is a number and "M" a stray token. On the base lexer
both parsed as a duration and failed in the evaluator with
`not a compact duration: "-30M"` and `"--30M"`; the +30x control passes
on both.

AC: AC-6
Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(query): pin the values rejecting uppercase units leaves alone

At a fixed now, created>+30d is still 30 days ago, updated>5pm still
17:00 that day, and label=30M / title=30M still filter the literal
"30M". TestQueryMinutesUnitResolvesAgo already pins created>30m (30
months ago) and created>30min (30 minutes ago). These rows pass on the
base lexer as well, which is the point; a lexer mutant that stops typing
signed lexemes as durations fails the +30d row.

AC: AC-7
Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Eddie the Engineer <julianknutsen@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 09:18:13 +00:00
gascity-eddie[bot]
994f5b82dd
fix(config): stop bd config set truncating config.yaml at a 64 KiB line (#7670)
* fix(config): stop bd config set truncating config.yaml at a 64 KiB line

updateYamlKey's flat-key path reads config.yaml through a default
bufio.Scanner and never checked scanner.Err(). A line of
bufio.MaxScanTokenSize (65,536) bytes or more makes Scan return false
partway through the document, so the function returned the lines read
so far with a nil error and setYamlConfigAtPath wrote them over the
file, dropping the long line and everything after it. Measured at
5c9c02ab77: a 65,550-byte document came back as the 8-byte
`k1: "zz"` when the key was present, and as 16 bytes when it was absent
(the new key appended onto the truncated prefix).

Check scanner.Err() after the loop and refuse with an error that wraps
bufio.ErrTooLong. It is returned before setYamlConfigAtPath's
os.WriteFile, so `bd config set` and `set-many` now fail and leave the
file as it was. The guard returns only on a scan error, so a document
whose lines all fit gets the same rewrite as before. Unset
(commentOutYamlKey) already splits instead of scanning, and dotted keys
rewrite through yaml.Node, so neither needs it.

TestUpdateYamlKeyRejectsOversizeLine fails at the base (nil error, 8-
and 16-byte results) and passes with the guard. Adds a CHANGELOG
Fixed entry.

AC: AC-1
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(config): pin that a line just under the scanner limit still rewrites

The oversize-line refusal must fire only at the bufio.Scanner cliff. The
default scanner buffer holds bufio.MaxScanTokenSize (65,536) bytes, so a
line of 65,535 bytes still fits with its newline, and updateYamlKey has
to give a document with such a line the same rewrite a short document
gets: the key replaced in place when present, appended when absent.

Adds both rows to TestUpdateYamlKeyRejectsOversizeLine. They pass at the
base and with the AC-1 guard, which returns only on a scan error. Two
over-eager variants of the guard pass the existing yaml tests and the
AC-1 rows but fail these rows: capping the scanner buffer at
MaxScanTokenSize-1, and a pre-scan length check that refuses a line of
MaxScanTokenSize-1 bytes.

AC: AC-2
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(config): pin that a refused bd config set leaves config.yaml unchanged

setYamlConfigAtPath reads config.yaml, rewrites it through
updateYamlKey, and writes the result back. The AC-1 guard makes
updateYamlKey refuse a document with a line of bufio.MaxScanTokenSize
bytes or more, and setYamlConfigAtPath returns that error before its
os.WriteFile, so the file is never touched. No test covered that order.

TestSetYamlConfigAtPathOversizeLineLeavesFileUntouched writes a
config.yaml with a 65,538-byte comment line, sets no-db, and checks that
the error wraps bufio.ErrTooLong and that the file still holds all
65,563 of its bytes. At 5c9c02ab77 it fails both checks: a nil error,
and the file cut to the 11-byte `no-db: true`. It passes with the AC-1
guard and needs no code change of its own. A variant that writes the
file before returning the error fails the byte check (0 bytes left), and
one that swallows the error fails the error check.

AC: AC-3
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(changelog): say set-many keeps keys it wrote before a refused one

The entry said `bd config set` and `set-many` both fail and leave
config.yaml as it was. That holds for `set`, and for a `set-many` whose
first config.yaml key is the refused one. But `set-many` writes its
config.yaml pairs one at a time, in argument order, and returns on the
first error with no rollback, so a key listed before the refused
undotted key (a dotted `sync.remote`, say) is already on disk when the
command exits 1.

Measured at 0d3aa63761 with a 70,000-byte comment line in config.yaml:
`bd config set-many sync.remote=git@example.com:o/r.git actor=bob`
exits 1 and adds the `sync:` block (70,039 -> 70,083 bytes);
`set-many actor=bob sync.remote=...` and `bd config set actor bob` exit
1 and leave the file byte-identical.

de330c3e7f's message makes the same claim; this commit does not rewrite
it.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Eddie the Engineer <julianknutsen@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
2026-10-19 09:15:48 +00:00
Julian Knutsen
4c48829c07
fix(list): print bd list --format dot in a deterministic order (#7688)
outputDotFormat declared nodes and edges in the order of the list page it
was handed. The default page order breaks priority ties by created_at at
one-second precision, so two equal-priority issues swapped places depending
on whether they were created in the same second, and the proxied route's
edge query orders by source only. The same graph printed different bytes
(Oracle A list_dot_format_dependency_edges flipped between runs).

Declare nodes in byte order of id and each node's edges in byte order of
(target, type), on copies of the caller's slices. --sort and --limit still
choose which issues are listed.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 08:59:23 +00:00
Steve Yegge
d855ac6c88
test(bazel): pin vet policy to module toolchain (#7668)
* test(bazel): pin vet policy to module toolchain (wy-kk1b9a)

Agent-Signature: codex-unknown-model-unknown-reasoning on behalf of Steve Yegge

* test(bazel): report an unavailable pinned toolchain as a missing host tool

Review fixes for #7668 (adopt-pr iterations 1-2).

The GOTOOLCHAIN pin added a failure path that base did not have. A host
that runs another Go release and cannot fetch go.mod's toolchain
(offline, GOPROXY=off, empty module cache) failed
TestPRRunsGoTestsBazelSkips with a bare "exit status 1": cmd.Output()
keeps the go command's stderr in the ExitError, and t.Fatal printed
only the status.

- Report the failure through skipOrFailWithoutHostTool, naming the
  pinned version and the go command's stderr when it printed any.
  Plain go test skips; Bazel still fails, and there the registered SDK
  is go.mod's toolchain, so nothing is fetched.
- Compare VET_PASSES in a subtest, so the skip covers only the check
  that needs the toolchain. Given the parent's t, it skipped the whole
  test, and with it the six checks after it that read only the
  checkout. A failed subtest still fails the parent, so Bazel stays
  fail-closed.
- Pad a two-component version ("go 1.26" with no toolchain line) to
  go1.26.0 in goToolchainName, as scripts/ci/gofmt-bin.sh does.
  GOTOOLCHAIN=go1.26 is rejected as a language version, not a
  toolchain version. A table test pins 1.26, 1.26.7 and 1.26rc1.
- Say in the helper comment that the pin overrides an ambient
  GOTOOLCHAIN, local included, and may download into GOMODCACHE.

Validated with go1.26.7-built test binaries under env -i, GOPROXY=off,
with an empty HOME and module cache unless noted:
- go1.26.9 host: the VET_PASSES subtest skips, naming go1.26.7 and
  "toolchain not available", and the parent passes. With a planted
  scripts/ci/go-test-vet.sh the parent fails, as on base; iteration 1
  skipped the whole test there (rc 0). Same on go1.26.5 with
  GOTOOLCHAIN=local.
- go1.27.1 host with go1.26.7 cached: passes; base fails on
  stdversion. go1.26.7 host: passes.
- Bazel branch (TEST_SRCDIR, BEADS_TEST_GO): SDK go1.26.7 passes. SDK
  go1.26.9 fails the subtest and the parent with "executor lacks a
  host tool". A non-executable SDK path ends the message with the exec
  error, with no dangling ": ".
- go.mod "go 1.26" without a toolchain line: passes on go1.26.0 and
  under Bazel with SDK go1.26.0; a go1.26.9 host skips, naming
  go1.26.0. Iteration 1's unpadded mutant only skipped under plain go
  test (it failed under Bazel); the table test now fails it, and fails
  mutants that count dots or drop the regex anchors.
- go test ./scripts on go1.26.7: 306 pass, 0 fail, 1 skip; the only
  outcomes not on iteration 1 (305/0/1) are the two new tests passing.
  go vet ./scripts and the pinned gofmt -l are clean.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 08:52:30 +00:00
gascity-eddie[bot]
395e7beec0
fix(config): stop bd config set dropping the file's trailing newline (#7669)
* fix(config): keep config.yaml's trailing newline on bd config set

updateYamlKey's flat-key path, which `bd config set` takes for every
single-segment key, read the document with bufio.Scanner and joined the
lines back with "\n". ScanLines drops the final terminator, so the result
was exactly one newline short of any terminated config.yaml:
"issue_prefix: vp\ndolt.mode: server\n" came back without its final
newline, a spurious no-newline-at-end-of-file change in a git-tracked file.

Re-attach the input's own trailing run at the return, the tail
commentOutYamlKey got for the unset side in #6749. One statement covers
both the in-place and the appended branch, and a document without a
trailing newline still does not acquire one. The TODO that recorded the
defect is removed in the next commit.

The test file's header now covers both verbs; the set test follows the
unset ones.

AC: AC-1
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(config): drop the TODO that deferred the bd config set newline fix

The TODO above updateYamlKey's return recorded that `bd config set` was
knowingly left one newline short, as a scope call in #6749. The previous
commit fixed that, so the TODO now describes a defect that no longer exists.

Check: searching internal/config/yaml_config.go for the phrase
"`bd config set` is knowingly left unfixed" finds one match at the base
and none after this commit.

AC: AC-11
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(config): pin a set's blank-line trailing run, not just a final newline

A config.yaml that ends in one or two blank lines came back from
`bd config set` one newline short, so the output still ended in "\n".
Compare the exact trailing run, as the unset table does, so that loss
stays visible. Both rows fail on the base code (run "\n" vs "\n\n", and
"\n\n" vs "\n\n\n") and pass with the tail fix.

AC: AC-2
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(config): pin the appended key's terminator on bd config set

When the key is absent, updateYamlKey appends it as the new last line,
and the old join left that line unterminated: "x\n" came back
"x\n\nnewkey: \"v\"". Pin the exact output for "x\n", where the separator
blank line is kept and the newline follows the new key, plus a table row
for the trailing run. Both fail on the base code and pass with the tail
fix.

AC: AC-3
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(config): pin a set appended over a blank-line tail

For "x\n\n" without the key, the existing blank line already separates,
so updateYamlKey adds no second one and the document's own two-newline
run now follows the new key: "x\n\nnewkey: \"v\"\n\n". Restoring a single
newline would leave this exact shape one short again, so pin it exactly,
plus the matching table row. Both fail on the base code, which returned
"x\n\nnewkey: \"v\"", and pass with the tail fix.

AC: AC-4
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(config): pin that a set does not invent a trailing newline

The repair re-attaches the document's own trailing run instead of appending
a newline, so a config.yaml that ends without one still ends without one
after `bd config set`. Pin that for both branches: a present key rewritten
in place, and an absent key appended as the new last line.

This passes on the base as well; it is a pin on "preserve, not append".
The always-append mutant (`return out + "\n", nil`) turns both inputs red.

AC: AC-5
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(config): pin a set's output on a CRLF config.yaml

A set of a single-segment key has always rewritten a CRLF document to LF,
because the scan drops each line's "\r". What the old join added on top was
a missing terminator: "actor: a\r\nother: x\r\n" came back
"actor: \"b\"\nother: x". With the restored tail it comes back
"actor: \"b\"\nother: x\n", which is also how an unset of the same document
ends.

Pin the exact output, and check the trailing run against commentOutYamlKey
on the same input, in a subtest named after unset's CRLF subtest. It fails
on the base (exact and parity) and passes with the tail from AC-1.

AC: AC-6
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(config): keep a CRLF config.yaml's blank-line tail on bd config set

The restored tail measures the trailing run on the raw content, where
strings.TrimRight(content, "\n") stops at the last "\r". On a CRLF file the
re-attached run was therefore always a bare "\n", however many blank lines
followed: "actor: a\r\nother: x\r\n\r\n\r\n" came back "…x\n", one newline
shorter than even the base's "…x\n\n".

Normalize CRLF the way commentOutYamlKey does before the scan, so the run is
the LF run and a set ends the file exactly as an unset of the same document
does. The scan output is unchanged, since ScanLines already drops each
line's "\r". The line sits below the nested dispatch, not at the top: some
updateNestedYamlKey branches carry "\r" through on untouched lines, and
this fix leaves that path alone.

Also correct the comment on unset's CRLF subtest, which still blamed a
leftover "\r" for the bare-"\n" tail; commentOutYamlKey normalizes up front,
so that mechanism no longer exists and the new set cases contradict it.

AC: AC-7
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(config): pin the trailing newline through SetYamlConfig

setYamlConfigAtPath writes updateYamlKey's output verbatim, so the dropped
newline reached the git-tracked config.yaml. Add the writer-level twin of
TestUnsetThroughTheFileKeepsTheTrailingNewline: a .beads/config.yaml ending
in a blank line, BEADS_DIR pointed at it, SetYamlConfig("actor", "bob"),
and the re-read file must keep its "\n\n" run. It first checks that the
value landed, so an untouched file cannot pass.

On the base the run comes back "\n"; with the tail from AC-1 it is "\n\n".

AC: AC-8
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(config): pin that a set of a dotted key bypasses the CRLF normalization

The CRLF normalization in updateYamlKey sits below the nested dispatch on
purpose. replaceFlatKeyLine and appendNestedYamlKey keep "\r" on the lines
they leave alone, so hoisting the line above the dispatch would silently
change what a dotted-key set writes:
"issue_prefix: vp\r\ndolt.mode: server\r\n" comes back
"issue_prefix: vp\r\ndolt.mode: \"embedded\"\n" today and would lose the
first "\r".

Compare updateYamlKey with updateNestedYamlKey on four CRLF documents for
dolt.mode: a literal dotted key, a nested block, an absent key, and a
comment-only document. This passes on the base as well; it pins the
boundary, not the nested writer's outputs. The hoisted mutant turns the
literal-dotted-key and comment-only rows red; the other two are re-marshalled
to LF either way.

AC: AC-9
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(config): append an absent key after a blank-line tail as one line

updateYamlKey's flat path appends an absent key after the scan's empty
tokens for the file's trailing blank lines, so those blank lines already
sit ahead of the new line; the tail rule then re-attached content's whole
run after it as well. A set of a new single-segment key on a file ending
in blank lines therefore repeated them at EOF: "x\n\n" came back
"x\n\nnewkey: \"v\"\n\n", "x\n\n\n" came back
"x\n\n\nnewkey: \"v\"\n\n\n", and CRLF "x\r\n\r\n" came back
"x\n\nnewkey: \"v\"\n\n" -- the diff noise this PR exists to remove.

The appended branch now re-attaches only the one terminator
bufio.Scanner dropped, and only when content had it; the in-place branch
keeps the TrimRight + content's-run rule it shares with
commentOutYamlKey. The appended-key subtest now wants
"x\n\nnewkey: \"v\"\n", adds "x\n\n\n" and CRLF rows, and drops the
comment claiming a single terminator would leave it one newline short.
The suffix-run table drops its blank-tail append row, whose expectation
assumed the file's run follows the key, and
TestSetOfAnAbsentKeyThroughTheFileAddsOneLine pins the shape through
SetYamlConfig. The doc comment states the nested boundary and the tail
rule.

Not changed here: the unchecked scanner.Err() is #7670's fix (its guard
lands right after this scan loop, and ./internal/config/ is green on the
union of both PRs). The stale bufio.Scanner narration in
commentOutYamlKey's comment stays a follow-up, since #7613 edits that
function.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Eddie the Engineer <julianknutsen@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
2026-10-19 08:49:00 +00:00
Julian Knutsen
c67a36e5e7
fix(cli): refuse backup init/sync/remove/restore and import under strict --readonly (#7673)
* fix(cli): refuse backup init/sync/remove and import under --readonly

Strict --readonly is meant to refuse every command that writes, with
"Error: operation '<op>' is not allowed in read-only mode" and exit 1.
bd backup init, backup sync, backup remove and bd import never called
CheckReadonly, so that gate never refused them:

- On a server-mode store they ran to completion under --readonly:
  backup init and backup remove rewrote or emptied the server's
  dolt_backups registry, backup sync wrote the backup destination, and
  import wrote issues.
- On an embedded store they failed only because the store was opened
  read-only, with the storage layer's "store is read-only" text, and
  backup sync took the backup lock first and left .beads/backup.lock
  behind.

The three backup verbs now call CheckReadonly first in their RunE, as
the other write commands do. Its migration-freeze half is redundant for
them: their leaf names are not on the read-only list and they have no
preview flag, so PersistentPreRunE's early freeze gate refuses them
first.

bd import calls it only when --readonly is set. CheckReadonly also
answers a migration freeze, and does so by exiting the process, while
runImport answers a freeze by returning the error so cleanup still
runs; guarding the call leaves that path exactly as it was.

bd import --dry-run is refused too. The preview opens the store
read-only and writes nothing, so this is a policy choice. It matches
create --dry-run (also refused under --readonly) and import's own
freeze posture: a migration freeze already refuses import --dry-run
(TestImportBlockedDuringMigrationFreeze), and CheckReadonly treats the
two gates as one. The cost is small, since the same preview runs
without --readonly. bd backup status and bd backup itself (a command
group that only prints help) stay allowed.

TestBackupAndImportBlockedInReadonlyMode runs each command, plus
import --dry-run, under --readonly and --readonly --sandbox against an
embedded workspace and one on the Dolt test server. Each row expects
exit 1, exactly the standard refusal on stderr, an empty stdout, and
nothing changed: the .beads tree, the backup destination, the issue
count, and, in server mode, the dolt_backups registry.
TestBackupStatusAndListWorkInReadonlyMode is the control showing that
backup status and list still run.

Ported from the versioned-beads fork: b86df6a9eb (test) and
5a067acc56 (fix). The comment on TestImportBlockedDuringMigrationFreeze
is updated, since runImport now calls CheckReadonly under --readonly.

Co-authored-by: Jim Wordelman <jim@wordelman.name>
Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(backup): refuse --readonly backup restore before the exclusive gate

A restore replaces the store, so strict --readonly must refuse it.
Nothing did:

- In server mode no storage layer stops the connection, so
  `bd --readonly backup restore --force` ran to the end: exit 0,
  "Restore complete", and the store was replaced.
- In embedded mode the command took the EXCLUSIVE workspace gate first,
  leaving the holder sidecars (.beads.gate.lock.info,
  .beads/embeddeddolt.gate.lock.info) behind, and was stopped only
  later by the storage layer's "store is read-only".

acquireCommandWorkspaceGates now calls CheckReadonly("backup restore")
first for the exclusive (restore) case when readonlyMode is set. That
is before any gate file is created or the store is opened, so nothing
is held and the exit skips no release. The guard checks readonlyMode
alone, so a restore without --readonly, including one refused by a
migration freeze, keeps its existing order. The restore RunE also calls
CheckReadonly first, as every write command does.

This does not depend on the strict-readonly SHARED-gate change
(workspacegate.Options.ReadOnly): the refusal comes before any gate is
built.

The one visible change in proxied-server mode, where every --readonly
command is already refused: `bd --readonly backup restore` now gets
this standard refusal (plain text, exit 1). Before, the proxy
capability refusal answered it (exit 1, typed JSON under --json), and
only after the exclusive gate had been taken.

TestEmbeddedBackupRestoreStrictReadonly and
TestBackupRestoreStrictReadonlyServerMode run the built bd as a
subprocess, because CheckReadonly exits. The workspace's live store
holds three issues and its backup holds two. Each test asserts the
standard refusal with exit 1 and an empty stdout, no storage-layer
message, an unchanged project directory and .beads tree, and an
unchanged issue count. Each runs under --readonly and under
--readonly --sandbox. A control restores without --readonly and
expects two issues, so "unchanged" cannot be vacuous.

Ported from the versioned-beads fork: 1cd5f1c202 (test) and
6ac79d6207 (fix). The fork's test used a dirEntryNames helper that
belongs to its separate SHARED-gate change. It is inlined here so this
change compiles and lands on its own in either order. The server test's
comment is corrected too: the fixture's backup and the restore both run
inside the server at the same path, so it passes against a
containerized test server as well as a local one.

Co-authored-by: Jim Wordelman <jim@wordelman.name>
Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Jim Wordelman <jim@wordelman.name>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 08:48:37 +00:00
Julian Knutsen
9893f9020d
fix(setup): leave a current agents-file beads section untouched (#7693)
* fix(setup): leave a current agents-file beads section untouched

installAgents rewrote the instructions file whenever it found a beads
marker, discarding ReplaceSectionWithOpts' changed flag and error. A rerun
of `bd setup claude` (and `bd init`, which runs it) replaced a byte-identical
CLAUDE.md with a new file (new inode, fresh mtime, mode reset to 0644) and
reported "Updated existing beads section", while bd init's updateAgentFile
reported AGENTS.md current in the same run. A section whose END marker was
lost or came before BEGIN was likewise "updated" without change.

Mirror updateAgentFile: write only when the section changes, report
"<file> already has the current beads section" otherwise, and return
ErrMalformedMarkers instead of rewriting. claude/gemini warn and continue;
factory/opencode/mux fail (mux before installing its .mux hooks), per their
existing error policies. Tests pin inode, mode and mtime of the untouched
file and the claude/mux policies for both malformed-marker shapes. Goldens
updated for the new rerun message.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(setup): keep CLAUDE.md's beads block when the AGENTS.md update fails

When CLAUDE.md is an @AGENTS.md stub that still holds a beads block,
installClaude strips that block once the redirect is active, gated only on
installAgents not having skipped a symlinked AGENTS.md. It ignored
installAgents' error, so now that installAgents returns ErrMalformedMarkers
instead of writing a malformed AGENTS.md back, the strip deleted the stub's
block while AGENTS.md kept no usable section, and the warning named
CLAUDE.md. Base had the same end state behind a false "Updated" report; the
new error is what makes the failure detectable, so the gate belongs here.

Gate the strip on a nil installAgents error too, so it runs only once
AGENTS.md holds the current section (written now or already current), and
name the file that failed in the warning (AGENTS.md when redirected). A
redirect subtest in TestInstallClaudeWarnsOnMalformedMarkers pins both, for
both malformed shapes: dropping the gate reds it on CLAUDE.md's content,
inode, mtime and mode, and naming CLAUDE.md again reds it on the warning.

Also correct updateBeadsSectionWithProfile's doc comment, which claimed an
error string it never returned: it returns the content unchanged when the
section cannot be replaced. The CHANGELOG entry notes the redirect case.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
2026-10-19 08:45:04 +00:00
gascity-eddie[bot]
6db46664da
test(cmd/bd): pin mixed-case dep tree --format Mermaid through the CLI (#7697)
* test(cmd/bd): pin mixed-case dep tree --format Mermaid through the CLI

TestDepTreeFormatMermaidCaseInsensitive calls isMermaidTreeFormat directly,
so reverting the runDepTree dispatch to formatStr == "mermaid" (the PR #6646
bug) kept every test green. Add a --format Mermaid call to the embedded
tree_format_mermaid subtest so the flag-to-renderer wiring is pinned.

AC: AC-1
AC: AC-2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit c325246d4a)

Ported-From: opus/c325246d4a8e4cd5f60f9548053b5385e20a4d2e
AC: AC-1

* test(cmd/bd): record AC-2 mutant evidence for the mixed-case pin

No code change: AC-2 is the mutant-killing property of the row added in
the AC-1 commit. Evidence (bazel test //cmd/bd:bd_test --config=ci
--test_filter='TestDepTreeFormat|TestEmbeddedDepBTreeAndCycles/tree_format_mermaid'
--test_arg=-test.skip= --test_env=BEADS_TEST_EMBEDDED_DOLT=1
--test_output=all):

- Mutant M1 (cmd/bd/dep_tree.go:153 changed to formatStr == "mermaid",
  isMermaidTreeFormat left intact), row absent: all targeted tests pass —
  the hole.
- M1 applied, row present: TestEmbeddedDepBTreeAndCycles/tree_format_mermaid
  FAILS with the plain-text fall-through header ("Dependency tree for"),
  while TestDepTreeFormatMermaidCaseInsensitive, TestDepTreeFormatFlag and
  the lowercase e2e row stay green.
- M1 reverted, row kept: all pass; no SKIPs in any run.

AC: AC-2
Agent-Signature: claude-code-glm-5.3-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Code <noreply@anthropic.com>
(cherry picked from commit 38df0c5b22)

Ported-From: glm/38df0c5b224c41fa312dd130b8e7fe378d74b0b4
AC: AC-2

---------

Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
2026-10-19 08:36:16 +00:00
gascity-eddie[bot]
8f960b1b6e
test(cmd/bd): pin count and omitted flag on the embedded wisp include view (#7698)
* test(cmd/bd): pin comments_omitted on the embedded wisp count-only view

show_json_wisp_comment_count asserted comment_count and the absent
comments slice but never read comments_omitted, the flag the GH#5565
fix unlocks. A regression that stops setting it stayed green here.

AC: AC-1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 9b5be54bdf)

Ported-From: opus/9b5be54bdf3c4ef69f5b8eaf68770b26b102ff35
AC: AC-1

* test(cmd/bd): add the embedded --include-comments wisp twin

The proxied plane pins a wisp's comment behavior with a pair of
subtests; the embedded plane had only the count-only half. Add
show_json_wisp_comments_include_streams, which asserts that
--include-comments streams both of a wisp's comments, and let
bdShowDetails carry extra flags after --json.

AC: AC-2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit d1795e55f1)

Ported-From: opus/d1795e55f15710e3112a37852361f577d42eeff9
AC: AC-2

* test(cmd/bd): pin count and omitted flag on the embedded wisp include view

GH#5565's symptom was --include-comments returning rows the count said
did not exist. Assert the include payload's comment_count matches the
streamed rows and that comments_omitted stays absent (omitempty) when
rows are present.

AC: AC-3

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit ae43c79065)

Ported-From: opus/ae43c790652261e5d004bdc1b23b768a391ce8a9
AC: AC-3

---------

Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
2026-10-19 08:31:05 +00:00
Julian Knutsen
ee441fdc73
fix(setup): stop leaving a blank-line hole on --remove (#7692)
`bd setup claude --remove` (and the factory, mux, opencode and gemini
recipes that share removeBeadsSection) cut exactly the managed section
and kept the blank lines that set it off, leaving a 3-line hole in the
CLAUDE.md bd init writes. installAgents then appended a re-added section
after two blank lines, so every remove/re-add cycle grew the file.

removeBeadsSection now drops the line breaks next to the section (never
text): the surrounding text is rejoined with one blank line, or none if
the section had none; a section at the top leaves no leading blank
lines and one at the bottom leaves a single final line break. CRLF is
preserved, and a marker sharing its line with text is still cut
exactly. installAgents appends like bd init's updateAgentFile: ensure a
final newline, then one blank line. remove(add(x)) == x for a file
ending in a newline, and after the first remove, setup and --remove
toggle between the same two files; a re-added section goes at the end.

Goldens regenerated with BD_UPDATE_GOLDEN=1.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 08:28:18 +00:00
Julian Knutsen
5e2158ea08
fix(setup): route Claude hook-removal lines through the installer output (#7691)
bd init --quiet still printed "✓ Removed SessionStart hook" and
"✓ Removed PreCompact hook" when the project's .claude/settings.json (or
the legacy settings.local.json) carried the bare `bd prime` hooks an older
bd registered. removeHookCommand printed with fmt.Printf straight to the
process stdout, bypassing the discarding writer that --quiet hands the
project installers.

removeHookCommand now takes the caller's writer; Claude and Gemini pass
env.stdout at every call site. bd setup claude/gemini print the same
lines in the same order; quiet init drops them while still migrating the
hooks. This is the removal half of the #7186 class; #7195 covers
addHookCommand and the two changes merge cleanly in either order.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 07:44:30 +00:00
Julian Knutsen
fb912f2438
fix(oracle-a): write scoreboard failure detail per run, not to shared /tmp (#7690)
The scoreboard dumped every in-scope failure to the host-global
/tmp/oracle-a-failures.txt, and run-oracle-a.sh copied it into its scratch
dir only after scoring finished. A concurrent scoreboard (another worktree,
a shard, another user) finishing in between overwrote or swapped the
detail, so a failing run could print nothing or another run's divergence.

The scoreboard now honors ORACLE_FAILURES_FILE (unset or empty keeps the
historical /tmp default for standalone use), and run-oracle-a.sh points it
at $SCRATCH/oracle-a-failures.txt and prints that file directly. The cp
and the /tmp fallback are gone.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 07:34:17 +00:00
Julian Knutsen
e3efb3107a
test(oracle-a): always remove the reference worktree on exit (#7689)
run-oracle-a.sh's EXIT trap removed its reference worktree only when
`git worktree list --porcelain | grep -qF "$REF_SRC"` matched. Under
pipefail that check reported a registered worktree as absent in two ways:
grep -q exits on its first match while git is still writing a large
listing, so git dies of SIGPIPE (141) and the pipeline fails; and git
lists the resolved path, which $REF_SRC never matches when $TMPDIR has a
trailing slash or runs through a symlink (both macOS defaults). Either
way the ref-src registration leaked as a prunable worktree.

Run `git worktree remove --force` unconditionally. It resolves the path
itself and fails harmlessly (silenced, `|| true`) when nothing is
registered, so cleanup is idempotent and exit codes are unchanged.

TestOracleAScriptRemovesItsReferenceWorktree runs the real script in a
fixture repo with a stand-in go that fails the reference build, covering
a >3 MB listing, a trailing-slash TMPDIR, a symlinked TMPDIR, and a run
that dies before the worktree is added.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 07:29:55 +00:00
Julian Knutsen
9e2f25c322
fix(http): bd link over a connected HTTP workspace, through the DependencyEditor role (#7685)
* fix(http): bd link over a connected HTTP workspace, through the DependencyEditor role

bd link wrote through the store's raw AddDependencyWithOptions, which the
HTTP client refuses by design (D8), so every bd link failed on an HTTP
workspace whatever the type. Its direct route now writes through the
DependencyEditor role with the helper bd dep add uses
(addDependencyEdgesDirect), which serves local stores and HTTP workspaces
alike: over HTTP one dependencies:add request, and the server already takes
any 1-32 character type.

link keeps its own checks before the write (and before the dial): the
dotted-child rule and the type's length only, never bd dep add's
well-known-type list. The proxied-server route is unchanged.

backend/http TestE2E_LinkOverHTTP covers owned-by and the other roadmap
types, the empty and over-long type refusals (no write reaches the server),
and the typed conflict for an edge of another type.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* build(bazel): auto-sync BUILD files

Applied from the bazel-sync-patch artifact of https://github.com/gastownhall/beads/actions/runs/39201892756
(`make bazel-sync`: gazelle, tools/bazel/go_srcs.py, bazel mod tidy).
Only BUILD.bazel, MODULE.bazel and MODULE.bazel.lock are ever pushed; see
scripts/bazel-autofix-push.sh.

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-10-19 07:15:13 +00:00
Julian Knutsen
786ed8a4b0
fix(show): exit 1 when bd show --as-of reads no issue (#7687)
showIssueAsOf reported each failed AS OF lookup on stderr and continued, but never counted what it read and returned nil, so a bad ref (an instant or a versioned-history address the Dolt AS OF read does not take, an unknown branch or commit) or an issue absent at the ref exited 0 with an empty stdout, under --json too. Its proxied-server twin, runShowProxiedAsOf, returned nothing and its dispatcher returned nil.

Both now count the issues they read and, when that is zero, end the way plain bd show ends a batch that found nothing: show's JSON error envelope on stdout under --json, a bare exit 1 otherwise, with the per-id reasons still on stderr. A batch that reads at least one issue still exits 0, as plain show's does. The read itself is unchanged (Dolt AS OF).

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 07:10:26 +00:00
Julian Knutsen
36f81bab1c
test(cmd/bd): pin the command tree and representative --help output (#7675)
* test(cmd/bd): pin the command tree and representative --help output

Add two in-process goldens for the bd command surface, so any added,
removed, hidden or reworded command or flag fails until the goldens are
regenerated and shows up as a reviewed testdata diff:

- TestCommandTreeGolden walks the whole cobra tree (hidden commands
  included) and records, per command, Use, Aliases, Short, Long, Example,
  group, hidden/deprecated state, runnability and annotations, plus every
  local and persistent flag it defines (name, shorthand, type, default,
  usage, hidden, deprecation, annotations). Output is sorted and rendered
  twice to prove it is deterministic.
- TestCommandHelpGolden runs `bd <cmd> --help` through rootCmd for root,
  create, show, list, update, close, version, versions, config and serve.
  --help returns before the root pre-run, so no store is opened; color
  escapes are stripped. The snapshots are byte-identical to a built bd
  binary's --help output.

Both run from a fresh ordinary (dependency-mode) workspace: a
.beads/metadata.json with no graph marker and no database behind it.

The tree is primed the way the binary is (main()'s help command and its
--all/--doc/--list/--docs-root flags, ExecuteC's completion command), and
cobra's history-dependent pieces (the lazily added per-command --help flag,
the __complete request commands) are excluded, so the result does not
depend on which in-process tests ran first. The help runs reset every flag
afterwards so a later in-process command does not inherit --help.

docs/cli-docs.pin holds check-doc-flags at the v1.2.2 release, so drift on
main is not caught there; these goldens are the live guard. They pin the
cgo build (the !cgo build swaps in a federation stub). Regenerate with
BD_UPDATE_GOLDEN=1 go test -tags gms_pure_go ./cmd/bd -run '^TestCommand(Tree|Help)Golden$'.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(cmd/bd): keep the command goldens from merging flags into the shared tree

TestCommandTreeGolden read each command's flags through
LocalNonPersistentFlags, and TestCommandHelpGolden dispatches
`bd serve --help`. Both run cobra's mergePersistentFlags, which copies
every inherited persistent flag (--json, --db, ...) into the command's
own flag set for the rest of the process. TestServeFlags pins serveCmd's
exact flag set, so it failed whenever a golden test ran before it in the
same test binary: tree then serve flags, help then serve flags, and
-test.shuffle seeds 2 and 3, on the PR head and on its merge with main.
CI passes only because bd_test's 16 Bazel shards happen to run them in
different processes. Of 37 candidate tests, TestServeFlags is the only
one affected.

- goldenLocalFlags reads the set LocalNonPersistentFlags reports without
  calling it: c.Flags() minus c's own persistent flags and minus
  inherited copies. Like cobra, it treats a flag as inherited only if it
  is the nearest ancestor's own *pflag.Flag, so copies left by an
  earlier in-process execution are skipped and a flag that shadows an
  inherited one still renders.
- TestCommandTreeGolden fails if rendering changes the number of flags
  in any command's flag set.
- TestCommandHelpGolden calls restoreServeGlobals, which re-registers
  serveCmd's flags after the `bd serve --help` dispatch.

Review minors:
- The regeneration command (doc comment, failure-message constant,
  tree.golden header) sets CGO_ENABLED=1. Without cgo the file does not
  build, so the command matches no test and exits 0.
- enterOrdinaryWorkspaceForGolden calls isolateBeadsDirForTest.
- renderCommandHelpGolden's comment says when the ANSI strip matters.
- cmd/bd/AGENTS.md lists the goldens under "Adding a command" and
  "Guard tests".

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
2026-10-19 05:56:15 +00:00
Julian Knutsen
eb5ab48950
test(setup): pin the Claude agent artifacts bd init and bd setup claude write (#7678)
* test(setup): pin the Claude agent artifacts bd init and bd setup claude write

Before-parity pin P11. Nothing pinned the agent artifacts byte for byte, so
a change to them -- a new hook event in .claude/settings.json, new text in
the minimal CLAUDE.md/AGENTS.md template and with it a new marker hash that
marks every installed section stale -- could land without anyone seeing
the user-visible diff. These goldens make any such change a reviewed diff.

- internal/templates/agents: TestManagedSectionGolden pins each managed
  section (minimal and full profile, with and without a Dolt remote)
  markers included; TestManagedSectionHashes pins their marker hashes as
  hand-maintained literals; NoPush is pinned to render the no-remote bytes.
- cmd/bd/setup: TestClaudeSetupArtifactsGolden records transcripts of
  bd setup claude, --check and --remove (project, --stealth, --global, a
  user's own settings and CLAUDE.md, a stale section, a legacy
  settings.local.json install, a CLAUDE.md that imports AGENTS.md): each
  step's result and output, and the settings and instruction files it
  creates, changes or deletes. TestClaudePluginManifestHookEvents pins the
  hook events and commands the beads Claude plugin declares.
- cmd/bd: TestEmbeddedInitAgentArtifactsGolden runs a real bd init (default
  and --agents-profile full) and then bd setup claude --check, --remove and
  a reinstall through the binary, with exit codes.

A managed section in a transcript is shown by its marker line and a
pointer to the template golden it is checked to match byte for byte, so a
template change shows up once in full and as a hash bump wherever it lands.
Regenerate with BD_UPDATE_GOLDEN=1.

CI companions: the new test files and testdata in BUILD.bazel (bd_test
gains its internal/templates/agents dep), and the new TestEmbedded* in the
100-shard embedded cmd manifest (incremental --write).

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(setup): drop BD_OTEL_* and split HOME in the agent artifact golden

TestEmbeddedInitAgentArtifactsGolden pins bd's stderr byte for byte, but
bdEnv passes the caller's BD_OTEL_* variables through, and bd prints a
deprecation warning on stderr for a legacy one (BD_OTEL_METRICS_URL,
BD_OTEL_LOGS_URL, BD_OTEL_STDOUT=true) before it checks whether
telemetry is on. On a host that exports them (agent hosts do; CI does
not), both scenarios failed at the first stderr block with no code
drift.

The test now runs bd init and every bd setup claude step with
agentArtifactEnv: bdEnv(dir) without BD_OTEL_* and OTEL_*. It filters
the env slice instead of calling clearTelemetryEnv, which uses t.Setenv
and so cannot run in these parallel tests.

The same helper gives bd a HOME of its own instead of bdEnv's HOME ==
project. With the two equal, a bd that wrote the hook and CLAUDE.md into
the home directory instead of the project passed every pin. The
transcript now also records $HOME/.claude/settings.json and
$HOME/CLAUDE.md, and output paths under HOME read $HOME. bd init runs
the steps bdInit does (git repo, seeded schema) with that env.

The test doc now names what it does not pin: a proxied-server bd init
(no Codex section, HasRemote from its own remote URL), a bd init with a
remote, and the Cursor files. It also says a change to AGENTS.md's
wrapper text or Codex section can fail only here.

The goldens are unchanged.

Validation (env -i, go1.26.7, GOFLAGS=-mod=readonly, GOPROXY=off,
BEADS_TEST_EMBEDDED_DOLT=1, -tags gms_pure_go):
- the golden passes in a clean env; with BD_OTEL_METRICS_URL=x
  BD_OTEL_LOGS_URL=y; with every legacy selector plus BD_OTEL_ENABLED
  and OTEL_EXPORTER_OTLP_ENDPOINT; and under -race;
- the previous test with BD_OTEL_METRICS_URL=x BD_OTEL_LOGS_URL=y fails
  at golden line 132 on the deprecation warning;
- swapping homeDir and projectDir in setup's defaultClaudeEnv passes the
  previous test and fails this one at golden line 5 (the transcript
  shows created $HOME/.claude/settings.json).

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
2026-10-19 05:19:28 +00:00
Julian Knutsen
3a5ade3a76
test(cmd/bd): pin workspace discovery refusal text and exit codes (#7677)
* test(cmd/bd): pin workspace discovery refusal text and exit codes

Add before-parity pins for what an ordinary bd prints, and with which
exit code, when workspace discovery cannot select a usable workspace:

- no .beads, an empty .beads, or a .beads with config.yaml but no
  metadata.json and no database ("no beads database found", and bd
  where's text and --json refusals);
- a corrupt metadata.json, for list, create, where (all refuse) and
  version (warns, exits 0);
- an exported BEADS_DIR naming a missing path, an empty directory, a
  regular file or a corrupt workspace, run from a corrupt workspace so a
  fallback to cwd discovery would show;
- .beads/.env: BEADS_DIR routing, an exported BEADS_DIR winning, BEADS_DB
  routing bd where but not a data command, BD_JSON applying only in the
  selected workspace, and a .env BD_BACKEND not being refused;
- .beads/redirect: missing and non-workspace targets (warning, then the
  source), a corrupt target, a chain, and a redirect behind BEADS_DIR;
- --db paths and names, and BEADS_DB / BD_DB, including the two
  inconsistencies main has today (a data command ignores BD_DB, and lets
  a discoverable cwd workspace shadow BEADS_DB, while bd where honors
  both);
- BD_BACKEND / BD_DATABASE_BACKEND being refused before any of the
  above, for store-less commands too.

The cases use workspaces with a corrupt metadata.json as sentinels: the
refusal names the metadata.json it failed to parse, which shows the
directory discovery selected without opening a store, so the store-less
pins need neither Dolt nor cgo. One embedded-Dolt pin covers the
store-backed .env case: BD_READONLY=true in .beads/.env refuses a write
with the read-only text and exit 1, reads still run, and an exported
BD_READONLY wins over the file.

These pin today's origin/main, not an ideal. A change that reorders
admission, discovery or checkBlockedEnvVars in the root PersistentPreRunE
now has to change an expectation here and is reviewed as a test diff.
Built from the merge base with the graph fork (46aa59cc65), bd passes
every store-less pin; the fork tip fails two (a BEADS_DIR naming a
regular file exits 5 with graph_not_initialized instead of exit 1, also
when BD_BACKEND is set).

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(cmd/bd): keep the discovery pins independent of PATH and cgo

The version case under TestDiscoveryRefusalPinsCorruptMetadata pinned
bd version's full stderr. bd version also appends a "Warning: multiple
'bd' binaries found in PATH" block when the caller's PATH holds more
than one distinct bd binary (a release install plus a dev build, or
Homebrew plus go install), and the fixture passes the caller's PATH
through. Such a machine failed the pin spuriously. normalize now drops
that block from stderr, as it already drops the sandbox auto-detection
notice, so the rest of the case is still pinned exactly.

The file also said the store-less pins need no cgo. They need a cgo bd.
A CGO_ENABLED=0 bd is server-only, and its no-database hints add "run
'bd doctor' to diagnose", so a CGO_ENABLED=0 go test of the package
failed 16 cases on the hint wording alone. The file now builds only
with cgo, and its header says why. CI runs none of these in its
CGO_ENABLED=0 lane, whose -run subset is fixed by PURE_CMD_BD_TESTS.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(cmd/bd): pin a working-directory .beads that is a regular file

The ExplicitBeadsDir pins cover a BEADS_DIR that names a regular file.
This adds the same case reached by the working-directory walk instead:
a project whose .beads is a regular file. bd list and bd where both exit
1 with "Error: loading config: reading config: open
$ROOT/p/.beads/metadata.json: not a directory".

bd built from the fork merge base 46aa59cc65 passes both cases. The
fork tip b9eebc31f8 fails both: it exits 5 with "graph_not_initialized:
open $ROOT/p/.beads/graph-preview-format: not a directory", the same
reorder the BEADS_DIR pin already catches.

A .beads that is an unreadable directory (chmod 000) splits main and
the fork the same way, but it is not pinned: a test run as root can
still read the directory.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(cmd/bd): close the embedded discovery pin's environment

Maintainer fixup from the adoption review of #7677.

TestEmbeddedDiscoveryPinsEnvFileReadonly compares bd's output exactly,
but its run helper started from bdEnv, which drops only BEADS_* and
BD_ROUTING_MODE. Every other BD_* the caller exported reached bd: with
BD_OTEL_METRICS_URL/BD_OTEL_LOGS_URL set (as on agent hosts) the
deprecation warning lands in front of the read-only refusal, with
BD_JSON_ENVELOPE=1 the empty list is printed as an envelope, and in a
sandbox the "Sandbox detected" notice precedes the refusal; each failed
the pin. The run helper now uses the store-less pins' closed environment,
factored out of discoveryPinFixture.baseEnv as discoveryPinEnv (HOME stays
the directory bd init used), and drops the sandbox notice from stderr
with the same discoveryPinSandboxNotice pattern normalize now uses.

normalize collapsed every consecutive repeat of a stderr line, which also
hid a doubled "Error:" line. It now folds only repeated
"Warning: redirect" lines, the ones discovery prints once per re-resolve.

blocked-backend-not-checked used a corrupt-metadata sentinel, whose
bind-time refusal comes before the legacy guard, so a blocked-variable
check added after .env loading would not have changed its output. It now
uses a config.yaml-only workspace and pins discovery's no-database
refusal.

Measured with the PR head's bd and test binaries under env -i:
- the embedded pin passes on a clean environment and failed with
  BD_OTEL_*, BD_JSON_ENVELOPE=1, or kill(2) returning EPERM (strace
  inject); with this change it passes in all of them, plus an exported
  XDG_CONFIG_HOME, an existing BD_MIGRATION_FREEZE_FILE and the agent
  host's BD_*/BEADS_* set;
- it still fails when .beads/.env overrides the caller (gotenv.OverLoad)
  or is not loaded;
- the store-less suite passes 54/54 subtests; a bd that prints the
  legacy-guard error twice now fails 12 of them, and a bd that checks
  the blocked variables again after the legacy guard now fails
  blocked-backend-not-checked; both passed the suite before.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
2026-10-19 04:51:18 +00:00
Julian Knutsen
e24940e0c1
fix(workspacegate): strict --readonly never creates workspace gate files (#7672)
* fix(workspacegate): strict --readonly never creates workspace gate files

Strict --readonly is mutation-free by policy (effectiveRootStorePolicy),
but the command chokepoint took its SHARED workspace gates with
O_CREATE|O_RDWR. On a workspace no bd command had gated yet, a strict
readonly command therefore left <project>/.beads.gate.lock and the
physical-root gate file (.beads/embeddeddolt.gate.lock or
.beads/dolt.gate.lock) behind.

Add workspacegate.Options.ReadOnly. A Shared acquisition with it opens
the gate file O_RDONLY (the idiom ExclusiveHolder already uses) and never
creates it. A gate file that does not exist means nothing has ever been
gated there, so Acquire succeeds with an empty handle whose Release is a
no-op. An existing gate file is held SHARED as before, so maintenance
still sees the command and a live exclusive holder still makes it wait
and then refuses it. The option is ignored for Exclusive: maintenance has
to be able to create the file it locks.

ReadOnly composes with the fair, bounded waiting from #7225 without
changes to it: the writer-fairness probe (ExclusiveQueued) already opens
the intent file read-only and treats a missing one as nothing queued, so
a waiting ReadOnly acquisition creates no .intent or .info file either.
readonly_wait_test.go pins that seam.

The chokepoint passes ReadOnly: readonlyMode in the SHARED branch. Every
other command keeps creating the gate files, which is what makes it
visible to maintenance. Residual, documented at the chokepoint: on a
workspace that has never been gated, a strict readonly command is
invisible to a maintenance operation that starts while it runs.

Ported from the versioned-beads integration fork (donnabox):
0c86e2b205 (red tests), bac6ff95dc (fix), b7a4f96a5a (fair-wait tests),
2af5a664dc (BUILD.bazel registration), and the #7225 conflict resolution
in 9d128f8c51. The fork's `--readonly backup restore` refusal
(6ac79d6207) is a separate change and is not included.

Co-authored-by: Jim Wordelman <jim@wordelman.name>
Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(cli): release the previous command's workspace gate before acquiring

acquireCommandWorkspaceGates stored its new handle over whatever
workspaceGateHandle already held. cobra skips PersistentPostRunE when
RunE fails, so in a process that runs more than one command (tests,
embedders) a command could start with the previous command's handle
still set. Two things then went wrong:

- on the paths that take no new gate (no .beads on disk, a failed or
  fail-open acquisition) the stale handle stayed set, so the previous
  workspace stayed held for the whole command;
- on a successful acquisition the stale handle was overwritten without
  being released, so its flock stayed held on the previous workspace
  until the garbage collector closed the file, and a maintenance
  operation there was turned away by a command that had finished.

Release any held handle first. In a single-command bd process the handle
is always nil at that point, so this is a no-op there.

Ported from the versioned-beads integration fork (donnabox): 3a25b42ed1
(cherry-pick of ad87442c92). The test
TestAcquireCommandWorkspaceGatesReleasesThePreviousCommandsHold is new
here and covers the successful-acquisition case the fork's tests do not.

Co-authored-by: Donna Box <dbox@boxenllc.com>
Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(cli): close a stale store before the leading gate release

Review fixups for #7672, apply-fixes iteration 1.

The leading releaseWorkspaceGates() that the second commit added to the
chokepoint was the only production release without a
closeStoreBeforeGateRelease() first. When an in-process command's RunE
fails, Cobra skips PersistentPostRunE. The next command in the same
process then dropped that command's gates while its store and provider
were still open, and later overwrote and leaked them. Close them first,
as every other release path does. The current command assigns
store/uowProvider only after the chokepoint, so anything set there
belongs to the previous command. Only multi-command processes (tests,
embedders) are affected; production runs one command per process.

A strict --readonly hold on a never-gated workspace locks nothing. The
chokepoint still exported this PID in BEADS_GATE_SHARED_HOLDER_PID, so bd
children skipped the writer-fairness queue behind a parent that blocks
no exclusive acquirer. Add Handle.Empty and MultiHandle.Empty, and
advertise only when at least one gate is actually locked.

Tests:
- A regression test runs the chokepoint over a stub store and provider.
  It pins that both close while the previous command's gate is still
  held.
- A marker test forces advertiseSharedHoldEnabled on. It pins that a
  hold of nothing is not advertised, and that the hold is advertised
  once the gate files exist.
- The strict-readonly chokepoint subtests now require a handle that
  holds nothing. SHARED fail-open leaves no handle, so these subtests
  now fail the review's W2 mutant, which passed them before.
- A package test covers Empty.

The posture comment now says the gate follows the strict flag only.
Allowlisted reads and --dry-run/--inspect previews still create the gate
files.

Not changed: `bd --readonly backup restore` still creates gate files on
its exclusive acquisition. This PR covers shared gates only. Sibling #7673
refuses a strict-readonly restore before it takes the exclusive gate.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Jim Wordelman <jim@wordelman.name>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Donna Box <dbox@boxenllc.com>
Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
2026-10-19 04:31:00 +00:00
Julian Knutsen
8fac20a7f1
test(oracle-a): normalize per-run revision token and workspace path so main-vs-main is clean (#7680)
* test(oracle-a): normalize the per-write revision token so main-vs-main is clean

Since #5535, `bd show --json` publishes `"revision"`, the decimal spelling
of the row's row_lock. Every create and status/ownership write remints that
token from crypto/rand (issueops.freshRowLock), so it differs between any
two runs of the same scenario. The harness did not normalize it, so Oracle A
failed against itself: on the curated tier, origin/main vs origin/main scored
31 pass / 13 fail in scope, and each failure was a `show --json` step that
differed only in `"revision"`.

normalize() now collapses a non-zero decimal `"revision"` string to `<REV>`.
It keeps everything else literal: the member name, its presence and its
string type, "0" (a row that was never stamped), number-typed values, other
`*_revision` members, and escaped text inside a JSON string. A new unit test
covers each of these cases.

Curated tier, REF_REF=origin/main, run against itself: before 31 pass /
13 fail in scope (0/1 out of scope); after 44 pass / 0 fail (1/0).

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(oracle-a): normalize the per-run workspace path

Each scenario runs in a fresh tempfile::tempdir(), so any bd output that
echoes the workspace path differs on every run. When origin/main's bd was
captured twice with the deep tier (ORACLE_CATALOG=1, 546 scenarios), 40
catalog scenarios differed only in that path. All 40 start with their own
`init --prefix X --non-interactive` step, which runs in a workspace the
harness already initialized and fails with "Found existing Dolt database:
/tmp/.tmpXXXXXX/.beads/embeddeddolt/X".

run_scenario now hands normalize_in_workspace() the exact workspace path
and its symlink-resolved spelling, and that function replaces only those
strings with <WORKSPACE>, longest first. Other paths stay literal, so no
stable value is collapsed. All 40 scenarios are out of scope, so in-scope
counts do not change.

Deep tier, origin/main's bd against itself, scored by the scoreboard:
- base harness: 256 pass / 67 fail in scope, 154 / 69 out of scope.
- with both normalizers: 323 / 0 in scope, 219 / 4 out of scope.

The out-of-scope remainder changes from run to run and none of it is a
field value. It comes from randomized "Tip:" lines in human output and one
unordered `list --format dot`.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(oracle-a): document and pin the <REV> match scope and the workspace wiring (mc-ro9kg)

Review fixes for #7680, iteration 1.

revision_regex runs over the raw stdout/stderr text before any JSON
parse, so it collapses every "revision" member holding a non-zero
decimal string, at any depth and in plain text, not only the
bd show --json issue token. That includes a user metadata key named
revision, which the in-scope --set-metadata/--metadata flags can set,
so a change to its value passes the gate. The regex comment and a new
README "What green does NOT prove" bullet now say so, and
normalize_collapses_revision_by_member_name_at_any_depth pins the
scope: a nested metadata member and plain text are collapsed, while a
metadata key with any other name still gates. The old test name said
nothing else was collapsed; it is now
normalize_collapses_non_zero_revision_strings.

run_scenario_collapses_the_workspace_in_both_step_streams runs
run_scenario against a stub bd that prints its cwd on stdout and its
resolved path on stderr, and expects <WORKSPACE> in both. Before, the
two normalize_in_workspace calls in run_scenario could be reverted with
every unit test and the curated tier still green.

The remint wording in the comment and the README now names every
writer (create, update, close, reopen, claim and unclaim) instead of
only status/ownership writes.

Tests: cargo test --locked --offline (7 passed), clippy clean, no new
rustfmt hunks. Mutants, each in its own copy and target dir: reverting
either or both normalize_in_workspace calls fails the run_scenario
test; skipping a nested metadata member, or matching only after { or
",", fails the scope test.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
2026-10-19 04:27:28 +00:00
Julian Knutsen
05fffb1e11
test(storage): versioned-history flag-off differential and statement pins (#6132, #6135) (#7681)
* test(domain/db): pin the statements the history-off upsert Insert issues

The participation_generation write fence (#6943) gave domain/db Insert's
upsert path (CreateOnly unset: the quick, todo, gate and batch proxied
servers' create) an existence probe ahead of the upsert, skipped while
versioned history is off. Pin that skip with a sqlmock statement-sequence
test: with history off, the upsert into issues and into wisps issues
exactly the three statements the pre-stack code (4a67d0d028) issues --
the upsert, the created event's same-content scan and its insert -- and
nothing else.

The mock is reached through internal/storage/sqlcount, and the pin also
requires exactly three statements to reach the driver. sqlmock alone
answers an unscripted statement with an error and fails only if the
caller returns it, so a best-effort read whose error Insert dropped would
pass its checks; the count catches it. The history-on run of the same
script is the control: the probe (and the mint after it) must make the
pin refuse it, which shows the script is exhaustive and that Insert reads
the transaction's scope.

Passes on 4a67d0d028 and on main; main issues no extra read with history
off. Before-parity pin P2 (Insert half) from the fork gap analysis, for
gastownhall/beads#6132 / #6135.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(issueops): pin the statements the history-off defer-wake sweep issues

Port the fork's sqlmock pin of WakeExpiredDefersInTx with versioned
history off (donnabox/codex/preview3-source-catchup-46aa 11c74cb575):
a one-row sweep issues exactly the expired-row SELECT, the UPDATE, the
event's same-content SELECT and INSERT, and the empty wisps pass, so any
read added before or after waking a row while history is off fails the
pin. It passes on main unchanged and guards the fork's wake-skip change,
which checks each expired row against the mint before waking it and must
keep that check free with history off.

Adapted for main: the doc no longer describes the fork's pre-wake check
as existing; a history-on run of the same script is added as the control
(the mint's read must make the pin refuse it), so the pin cannot pass
vacuously; and the mock is reached through internal/storage/sqlcount, so
the pin also requires exactly five statements to reach the driver. That
catches a read whose error the sweep swallowed, which sqlmock alone does
not see. Passes on 4a67d0d028 and on main. Before-parity pin P2 (wake
half), for gastownhall/beads#6132 / #6135.

Co-authored-by: Jim Wordelman <jim@wordelman.name>
Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(storage): versioned-history flag-off differential against pre-stack goldens

gastownhall/beads#6132 and #6135 require a differential test proving that
with versioned history off (the default) storage behaves byte-identically
to before the feature. Existing coverage stops short of that:
TestDualWriteContractFlagOff only counts version rows, the
participation-generation contracts check one column, and createbatchequiv
runs its batch with history on over a column subset.

Add internal/storage/historyoffequiv. Each leg (embedded Dolt, Dolt
server, unit of work) runs one scripted mutation set through its own
front doors on a store whose history was never turned on:

- on the issues plane, every write role: creates, batch create, apply
  batch, updates, the no-op update, reparent, dependency add/remove,
  comments, claim/heartbeat/release, lease reclaim, metadata CAS,
  close/reopen, batch close with a refused item, defer and wake, delete;
- the persistence moves in both directions;
- on the wisps plane, the roles again: create, update and the no-op
  update, dependency add/remove, comment, metadata CAS, close/reopen,
  apply batch, batch close, release, defer and wake (the sweep's wisps
  pass), delete, a forced close of a no-history wisp, and the refusals
  the lease roles' contracts give a wisp (Claim, Heartbeat; Reclaim finds
  nothing);
- each leg's own surface: the store legs' DoltStorage methods (import
  upsert, promotion, RunInTransaction, ...) and the uow leg's
  CreateOnly-unset domain upsert and importer.

Neither reclaim sweep finds an expired lease, since no role can age one.
The harness then dumps every column of every base table, plus the
scenario's Dolt commit messages and the final dolt_status, and compares
per-table SHA-256 digests with goldens recorded by running the same
harness against origin/main 4a67d0d028, the commit before the stack
(#6943, #6661, #6664).

The only tolerated differences are listed in schemaAdditions: the stack's
new columns (issues/wisps.participation_generation,
issue_versions.removed_restriction) must be NULL in every row and are
then left out of the digest; its new table (epoch_minted_addresses) must
be empty; its own migration bookkeeping rows (0070-0072, ignored/0028)
may each be there once. Recording and checking apply that rule the same
way, so a golden re-recorded from main is byte-identical to the
pre-stack one (verified on all three legs). The package doc says how the
goldens are kept: a later migration whose schema flag-off leaves
untouched adds its own schemaAdditions entry; a deliberate flag-off
change, a scenario change or an engine rendering change re-records them
and shows the dump diff. Wall-clock instants, wall-clock-derived ids and
random tokens are masked by explicit, documented rules found by diffing
two runs; instants the scenario supplies stay verbatim, so a write that
starts overwriting one still shows.

All three legs pass on main. Before-parity pin P1 from the fork gap
analysis; the new embedded test is placed in the 40-shard storage block.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Jim Wordelman <jim@wordelman.name>
2026-10-19 03:47:00 +00:00
Julian Knutsen
f142cc2ffd
test(cli): before-parity pins for --format json, ordinary --if-revision, and version/config/history/as-of shapes (P7, P8, P10) (#7676)
* test(cli): pin --format json == --json on show, list, ready and memories

Before-parity pin P7 (gap analysis 2026-10-17, section 5a). The hidden
root --format flag is an alias for --json (GH#2612). It is a root
persistent flag, so a subcommand that registers a --format of its own
shadows it (the GH#6278 hazard): `bd list` already does and passes `json`
through by hand, and a graph-preview fork that added a local --format to
`bd show` made `bd show ID --format json` exit nonzero.

TestEmbeddedFormatJSONAliasMatchesJSON runs show, list, ready and memories
with --json and then with `--format json`, `--format=json` and a leading
`bd --format json <verb>`, and requires exit 0 and byte-identical stdout.
It adds bdRunStreams, a small helper returning stdout, stderr and the exit
status separately, which the following pins reuse.

The new TestEmbedded* function is listed in the bd_test srcs and placed in
the 100-shard embedded cmd manifest by
gen_embedded_cmd_shard_manifest.py --write (incremental).

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(cli): pin the ordinary --if-revision compare-and-swap contract

Before-parity pin P8 (gap analysis 2026-10-17, section 5a). --if-revision
is the decimal int64 compare-and-swap merged in #7203, and gascity's
bdstore_conditional.go classifier reads both its exit status and its
machine body. A second, opaque-token meaning for the same flag in another
kind of workspace must leave the ordinary one unchanged.

TestEmbeddedIfRevisionOrdinaryCAS pins, through the real binary:
  - a stale decimal token on update, close, assign and delete (preview
    and --force) exits 13, prints nothing on stdout, writes nothing, and
    ends stderr with a precondition_failed body naming the id and the
    expected and current revisions as exact JSON integers;
  - a non-decimal token exits 1 with the "invalid --if-revision" refusal
    in text and --json modes, never 13, and writes nothing;
  - the current token applies on update, close, assign and delete.

It is the ordinary-workspace half of
TestGraphPreviewIfRevisionOutsideLinkModeIsUpstreamCAS from the
donnabox/codex/preview3-source-catchup-46aa branch (added in 3d16d826be,
revised in 1640940fa9, 3ff2fe73ce, 55dbb61156, 653369305a and
97446d1f08), ported onto this package's embedded helpers. The port drops
the graph-only forget refusal, extends the stale and non-decimal cases
from update/delete to close and assign, and compares revisions as
json.Number rather than float64, since they are int64 values past 2^53.

It is named TestEmbedded* so the bazel-embedded lane, which discovers
`^func TestEmbedded` in *_embedded_test.go, runs it; the existing
TestIfRevisionMatchAndMismatch is not discovered there. The file is
listed in the bd_test srcs and placed in the 100-shard embedded cmd
manifest by gen_embedded_cmd_shard_manifest.py --write (incremental).

Co-authored-by: Jim Wordelman <jim@wordelman.name>
Co-authored-by: Donna Box <dbox@boxenllc.com>
Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(cli): pin version, config set, history and show --as-of shapes

Before-parity pin P10 (gap analysis 2026-10-17, section 5a): the
store-less and history-adjacent commands a later versioned-history or
graph slice could change by accident.

  - TestEmbeddedVersionOutputShape: `bd version` with no arguments exits
    0 and prints one "bd version <version> (<build>...)" line, in a
    workspace and outside one; --json is one object with version, build
    and schema_version (plus commit and branch when known) agreeing with
    the text line, and --format json prints the same document; an
    argument exits 1 and points at `bd versions <arg>` (#6661), on stderr
    or as the --json error, through the real binary rather than RunE.
  - TestEmbeddedConfigSetOtherKeysSkipTheVersionedHistoryScan: in a store
    holding a row the pre-enable scan refuses over, `bd config set` and
    `bd config set-many` of another key with the value "true" exit 0,
    store it, print no refusal and leave the switch off; the switch
    itself is still refused afterwards, as a control.
  - TestEmbeddedHistoryAndShowAsOfReadDoltCommits: with versioned history
    recording, `bd history <id> --json` is still the Dolt-commit history
    (an array of CommitHash/Committer/CommitDate/Issue entries with full
    32-character Dolt hashes, no recorded-version fields, and the same
    hashes in the text output), and `bd show <id> --as-of <hash>` with a
    hash from it is the Dolt AS OF read in show's JSON shape, not the
    R7.1 as-of read over issue_versions; `--as-of main` reads the branch
    head.

The three TestEmbedded* functions are placed in the 100-shard embedded
cmd manifest by gen_embedded_cmd_shard_manifest.py --write (incremental).

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Jim Wordelman <jim@wordelman.name>
Co-authored-by: Donna Box <dbox@boxenllc.com>
2026-10-19 03:41:08 +00:00
Julian Knutsen
f6f122894f
test(serve): before-parity pins for the httpapi startup event and ordinary-workspace bd serve (P13, P14) (#7679)
* test(httpapi): pin the startup event's capabilities and database source

TestStartupLines and TestStartupNamesTheDatabaseSource check the
event=startup line by substring, and neither reads its capabilities
field. A server could print one capability list and advertise another
on GET /v0/beads/context, or a new kind of database source could
relabel the line, and both tests would stay green.

TestStartupEventPublishesTheAdvertisedCapabilitiesAndSource parses the
line back into its fields and pins, for the provider and roles sources
with and without the external-dependency policy: the exact field
sequence, db=provider|roles, and a capabilities value equal to the
handshake's list joined with commas. It is a before-parity pin: a
future alternative source on the same server must leave this line
unchanged for the Issue API's two sources.

Test-only; no behavior change.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(serve): pin ordinary-workspace bd serve under BD_GRAPH_MODE=dependency

bd reads no BD_GRAPH_MODE today. "dependency" names the format every
existing workspace already has, so any later reader of that variable
(a graph-mode serve dispatch, for example) has to keep serving an
ordinary workspace through runServe exactly as it does now. These
tests pin that before such a reader exists.

Each test runs bd serve twice in one workspace, once with the variable
unset and once with BD_GRAPH_MODE=dependency. It requires the
event=startup and event=limits lines to match byte for byte apart
from the ephemeral port, and the GET /v0/beads/context bodies to be
equal. Each run is also checked against what runServe builds: the
serveResolvedMode label, the db source, and a startup capabilities
field equal to the handshake's list. Two runs that were both routed
somewhere else therefore cannot pass by agreeing with each other.

- TestServeOrdinaryWorkspaceIgnoresGraphModeDependency: in-process
  through rootCmd (PersistentPreRunE included), on the store source of
  a registered-backend workspace. Runs in bd_test.
- TestServerModeServeIgnoresGraphModeDependency: a real bd on a
  `bd init --server` workspace, which uses the provider source. Gated
  on BEADS_TEST_PROXIED_SERVER like the other TestServerMode* tests,
  and placed in the proxied 34-shard manifest by
  gen_proxied_shard_manifest.py --write (incremental).

The new file is listed in cmd/bd/BUILD.bazel's bd_test srcs.
Test-only; no behavior change.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(serve): stop the in-process graph-mode pin hanging when serve fails

serveInProcessSnapshot's cleanup decided whether the server was still
running by looking at rootCancel. That holds for a clean run, which
clears rootCancel in PersistentPostRunE. A run whose RunE returns an
error skips PersistentPostRunE, so rootCancel stays set even though the
main flow has already read the run's only result from done. The
cleanup then called rootCancel and blocked on done for good, and the
failure surfaced as a test-binary timeout panic that takes the whole
bd_test shard with it instead of a FAIL for this test.

The cleanup now keys on whether done has been read. A serve that binds,
answers, and then returns an error (one way a future graph-serve
dispatch could regress) now fails in about 5s with "bd serve returned
<err>, want a clean shutdown". A failure before done is read (a bad
GET, say) still cancels the server and waits for it.

Test-only; no behavior change.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 03:26:45 +00:00
Julian Knutsen
3488dc4536
fix(init): bd init --server --external starts no server; a failed bd init --server can be retried (#7674)
* fix(init): admit a retried `bd init --server` over an empty .beads/dolt

A first `bd init --server` that cannot reach its server fails after
creating the local Dolt root, leaving an empty .beads/dolt, no
.local_version witness, and no config.yaml/metadata.json recording the
server choice. The legacy-upgrade guard runs before init writes that
choice, so it saw an embedded-looking workspace with a local Dolt root
and refused every retry as a "legacy Dolt workspace"; no bd command could
repair it.

guardLegacyUpgradeWorkspaceForInit(beadsDir, initSelectsServer) carries
init's already-resolved server intent into the guard. It is consulted
for exactly one decision: an empty, witness-less .beads/dolt is admitted,
the same admission a workspace that records server mode already gets
(#6935). It is deliberately not folded into the workspace's own server
mode, so a non-empty root with an unreadable witness and an embedded
repository beside a non-empty root keep their current outcomes.
guardLegacyUpgradeWorkspace is now the initSelectsServer=false wrapper,
and only init's main guard call passes the flag; the proxied-server
init path keeps the plain wrapper.

Ported from the versioned-beads fork (donnabox/codex/preview3-source-
catchup-46aa), commits bc8d72182a (red) and 5bdfbfe5e2 (green). The
fork's graph_mode refusal in the same function is graph-preview-only
and is not carried here.

Tests: TestLegacyUpgradeGuardForInitAdmitsEmptyDoltRoot and
TestLegacyUpgradeGuardForInitAdmissionStaysNarrow pin the admission and
its narrowness at the guard; TestInitServerFlagAdmitsEmptyDoltRootWithoutConfig
and TestInitServerFlagRetryAfterFailedFirstAttempt run the real binary
against the test Dolt server and fail on main with the legacy refusal.

Co-authored-by: Jim Wordelman <jim@wordelman.name>
Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(init): `bd init --server --external` must not auto-start a server

`--external` declares the Dolt server managed outside bd ("skip server
startup", per its help), but init builds its dolt.Config by hand with
`AutoStart: initServerMode && BEADS_DOLT_AUTO_START != "0"`, so the flag
never reached the auto-start decision. A `bd init --server --external`
that named no port therefore ran dolt and tried to start a repo-local
sql-server. A named port was already declared external by rule 2c
(#5934), but its failure still advised `bd dolt start`, the one thing
--external says bd must not do, and each route (host:port, socket,
shared server, auto-start pinned off) worded the failure differently.

- AutoStart is now `initServerMode && !externalServer && ...`.
- externalServerUnreachableMessage rewrites only a failed dial
  (*net.OpError with Op "dial") under --external: it names the endpoint
  that was dialed and says bd did not start a server. A dial to port 0
  means no port was named, so that message asks for --server-port or
  BEADS_DOLT_SERVER_PORT and offers no default (GH#2098, GH#2372). Any
  other open failure keeps its own text.

Ported from the versioned-beads fork (donnabox/codex/preview3-source-
catchup-46aa), commits 234ca3d502 and a601a80e77 (red/green), 03a64a1aba
(socket helper rename), and a6ca0536c9 and 397fc4c69e (red/green: no-port
arm and wording). The fork's graph-preview dispatch at the top of init
and its --skip-hooks help text change are graph-only and not carried.
The TestInitExternalProvisionerShape doc comment is corrected: on main
every provisioner cell is a control (a named port is already external),
not a reproduction.

Tests: TestInitServerExternalDeadPortStartsNoServer,
TestInitServerExternalNoPortStartsNoServer and
TestInitExternalUnreachableMessage run the real binary against a dolt
shim that records every launch and fail on main;
TestInitSharedServerExternalDeadPortStillFails,
TestInitServerWithoutNamedPortStillStartsServer and
TestInitExternalProvisionerShape are controls; and
TestExternalServerUnreachableMessage pins which errors are rewritten.

Co-authored-by: Jim Wordelman <jim@wordelman.name>
Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Jim Wordelman <jim@wordelman.name>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 03:11:14 +00:00
Jim Wordelman
5c9c02ab77
Phase 3 (R20): epoch-transition enforcement + minted-address CAS - gastownhall/beads#6136 (#6664)
* test(conformance): un-skip R16 CAS + R20 epoch tests with honest not-implemented stubs

Wires all 10 ExpectedRevisionFixture-gated Run* functions and both
EpochFixture-gated Run* functions to real (non-nil) hooks on all three
storage legs (dolt, embeddeddolt, uow), replacing the Phase 0 all-nil
fixtures that made these cases t.Skip.

Every wired hook is an unconditional "not implemented yet" stub rather
than a partial-real implementation. This is deliberate: every Run*
function under test calls its primary hook (CompareAndSetVersion, or
CurrentEpoch/MintUnderEpoch) first, before any other hook, so a stub
that errors unconditionally on that first call guarantees deterministic
RED with zero risk of an accidental pass -- a concern that's concrete,
not hypothetical, since at least one case
(RunExpectedRevisionAcceptsAWriteNamingNoVersion) would go green under
a partially-real read/unconditional-write strategy backed by Phase 1's
already-persisted current_revision/store_epoch columns.

Each case now fails for its documented reason: most via a direct
t.Fatalf quoting the stub's "not implemented" error, and two
(RefusalIsDistinguishableFromNotFound,
RefusalIsDistinguishableFromValidationFailure) via a clean want/got
mismatch against the sentinel errors they expect.

Explicitly out of scope and untouched: CrossRecordInvariantFixture
(R16.1) and the non-epoch RetentionFixture cases (R17) -- confirmed via
test run that TestRetentionContract still reports PASS with all 13
subtests SKIP on every leg.

TestEveryLegWiresEveryRoleContract (internal/storage/leg_contract_wiring_test.go)
is a source-level AST naming check independent of hook nil-ness; all 12
entrypoints were already called by every leg pre-change, so this lock
was satisfied before and remains satisfied after.

Sentinel error messages reference be-x5jqd.3 (R16 CAS implementation)
and be-x5jqd.4 (R20 epoch enforcement implementation), the two builder
children this un-skip unblocks.

Verified via go build ./..., go vet ./..., and go test -tags cgo across
all three legs: all 10 R16 + 2 R20 subtests FAIL for the documented
reason, TestRetentionContract unaffected.

Bead: be-x5jqd.1

* feat: green — Implement R20 epoch-transition enforcement (refs be-x5jqd.4)

* fix(epoch): honor R20-n's retained-mapping exception in StillServes/Resolve

StillServesInTx and ResolveEpochInTx only ever checked whether the
literal queried address's own row matched the current epoch. Per R20-n
(#5898 rev 9), a version that survives an epoch transition keeps its
prior-epoch address resolving once its id has been carried forward into
the current epoch (via CurrentAddressForInTx or a fresh
MintUnderEpochInTx) — that carried-forward row wasn't being consulted,
so a legitimately retained address would wrongly stop resolving.

Add mintedIDHasAddressAtEpochInTx and consult it as a fallback in both
functions when the queried address's own row is stale. Addresses whose
id was never carried forward are unaffected (row.mintedID has no row
at the current epoch, same false/GoneReorganization answer as before).

Round-2 response to be-rskwc's causal_disproof finding: the merge-base
commit FAILed honestly on this defect, this branch's tdd_green SKIPped
instead (attribution_evidence). This fix is real and verified via a new
sqlmock unit test (TestStillServesInTxHonorsARetainedMapping et al.),
but does not by itself flip
TestEpochContract/EpochBumpVoidsOnlyAddressesOfVersionsNoLongerServed
from SKIP to PASS: that test's own construction mints two records
identically and never carries either forward before comparing
StillServes on both, so no backend implementation can make them differ
(escalation follows on a needs-mayor bead).

refs be-x5jqd.4, be-rskwc round 2

* test(feat): red — harden EpochBumpVoidsOnlyAddressesOfVersionsNoLongerServed (refs be-9fiaw)

Per mayor ruling on be-9fiaw: fix the test rather than waive it. The
fixture already lets record-a survive an epoch bump by minting it again
under the new epoch; record-b, never re-minted, does not survive. That
asymmetry was previously only discovered after the fact (skip if
StillServes agreed for both addresses), which meant the case could pass
by observing either polarity. Assert the concrete expected values
instead: servesA must be true, servesB must be false. This makes the
case deterministically exercise both halves of R20-n, and closes a
latent gap where a backend with the polarity reversed could have
silently passed via the old discover-then-swap logic.

* fix(schema): renumber epoch_minted_addresses to 0070, linearizing our own slot collision (refs be-hs42e.7)

R20's epoch_minted_addresses and R7.1's removed_restriction both claimed
migration slot 0069 on parallel sibling branches. Neither contained the
other, so nothing in either branch's own CI could see the union: each was
green alone, and the second to merge would panic checkNoDuplicateVersions at
store open -- before any command's RunE, so every bd invocation bricks rather
than one package reddening. Same hazard bee reproduced for #6358 vs #6008.

This linearizes them instead of leaving it to merge order. R7.1 keeps 0069:
it is published beneath #6661 and cannot move without rewriting a branch a
reviewer is reading. R20 stops being a sibling, rebases onto R7.1, and takes
the next contiguous slot.

Contiguity is why the renumber could not be done pre-emptively in either
branch alone: TestAllMigrationsSQLAppliesThroughDoltCLIAndRecordsLatestVersion
asserts COUNT(*) == LatestVersion(), so a jump to a far slot fails until the
gap is filled. The order had to be settled first.

- migrations/0069_add_epoch_minted_addresses.{up,down}.sql -> 0070_*
- migration_0069_add_epoch_minted_addresses_test.go -> migration_0070_*, with
  TestLatestVersionIncludesMigration0069 -> ...0070 (want 70)
- 0069_add_removed_restriction_test.go retires its own LatestVersion pin in
  favour of 0070's, keeping the one-pin-at-a-time chain 0068 -> 0069 -> 0070

cli_migrations.go needs no change: its only override is R7.1's guarded
PREPARE, which keeps 0069. The epoch migration is a plain unguarded
CREATE TABLE IF NOT EXISTS and needs none.

Verified: TestEmbeddedMigrationSourcesHaveNoDuplicateVersions,
TestLatestVersionIncludesMigration0070,
TestAllMigrationsSQLAppliesThroughDoltCLIAndRecordsLatestVersion (applies the
full 0001..0070 chain through the dolt CLI),
TestBundleMigrationsWithPreparedALTERAreOverriddenOrJustified and
TestAllMigrationsSQLUsesDirectDDLForKnownCLIIncompatibilities all pass.
go build ./... and go vet ./... clean.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* test(feat): red — Fix PR #6664: restore R16 honest-skip (stale be-x5jqd.3 premise) + address bee's 2 blockers on epoch_cas.go (refs be-ah0jf)

* feat: green — Fix PR #6664: restore R16 honest-skip (stale be-x5jqd.3 premise) + address bee's 2 blockers on epoch_cas.go (refs be-ah0jf)

* test(feat): red — Review: Fix PR #6664: restore R16 honest-skip (stale be-x5jqd.3 premise) + address bee's 2 blockers on epoch_cas.go (refs be-yj55d)

* feat: green — Review: Fix PR #6664: restore R16 honest-skip (stale be-x5jqd.3 premise) + address bee's 2 blockers on epoch_cas.go (refs be-yj55d)

* docs(epoch): cite epoch_minted_addresses as migration 0071

Upstream's 0069_widen_issue_versions_datetime_precision (#6675) took slot
0069 first, so removed_restriction moved to 0070 and epoch_minted_addresses
to 0071. The three epoch_cas.go headers still named 0070.

Rebase note (maintainer): the migration is now 0072, per the landing-order
ruling (#6943's participation_generation is 0070 and #6661's
removed_restriction is 0071); the commit "chore(schema): renumber
epoch_minted_addresses to 0072 after #6661's 0071" updates these three
headers.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(feat): red — move #6664's Dolt server leg to post-transaction publish for store_epoch and epoch_minted_addresses (latent lost-update pattern)

Tests only. On the commit before this one they fail for these reasons:

- the server leg publishes store_epoch / epoch_minted_addresses inside the open
  SQL transaction (DOLT_ADD before COMMIT) for BumpEpoch, MintUnderEpoch and
  CurrentAddressFor: the lost-update hazard documented on doltAddAndCommitInTx
- MintUnderEpoch and CurrentAddressFor stage only epoch_minted_addresses, so the
  first mint leaves store_epoch modified in the working set, on both legs
  (#6664 Major 2, reproduced with Status() on a real server and embedded)
- BumpEpoch must surface a Dolt commit that fails after its SQL commit, while
  the mint paths keep their rows
- ensureStoreEpochRow seeds with INSERT IGNORE and reads the row back

TestMintOverlappingABumpCommitsAnAddressThatIsAlreadyGone characterizes current
behaviour and passes now: a mint overlapping a bump commits an address the bump
already voided. Its doc comment records why that is left as it is.

* feat: green — move #6664's Dolt server leg to post-transaction publish for store_epoch and epoch_minted_addresses (latent lost-update pattern)

Server leg (internal/storage/dolt/epoch_cas.go): BumpEpoch, MintUnderEpoch and
CurrentAddressFor no longer stage and Dolt-commit inside the open SQL
transaction. The two mint paths publish through runIssueOperationTxWithMessage,
which commits the SQL transaction first. BumpEpoch commits it, then publishes
with doltAddAndCommitPostTx and RETURNS a failed Dolt commit: a bump that is
committed but unpublished must not read as success.

Both legs: a mint stages store_epoch with epoch_minted_addresses, because the
first mint inserts the singleton row (#6664 Major 2). The set lives in
issueops.EpochMintDirtyTables so the legs cannot drift from what the body writes.

issueops: ensureStoreEpochRow seeds with INSERT IGNORE and reads the row back,
as version_history.go does for the same row.

Not changed, on purpose: a mint overlapping a concurrent bump can still commit an
address the bump already voided. Dolt has no lock for it and the only conflicting
write would overwrite bumped_at/bumped_reason; see the doc comment on
TestMintOverlappingABumpCommitsAnAddressThatIsAlreadyGone. One comment in that
test file is reworded; no test logic changed since the red commit.

* chore(bazel): bazel-sync (gazelle) for the two new epoch test files

Only the two go_test srcs entries for the test files this branch adds:
epoch_cas_publish_test.go (dolt) and epoch_cas_status_test.go (embeddeddolt).
gazelle wanted nothing else for them (no deps change).

* test(conformance): add the optional EpochFixture.LoseVersion capability

Record survival explicitly instead of inferring it (gastownhall/beads#6664,
review 5360880888, Major 1). Once an address stays served unless its own row
says the store lost it, the only way for the contract to produce a Gone
address is an explicit loss, so the contract needs a way to say "the store
lost this Version".

LoseVersion is additive and optional: no existing field changes signature,
and a nil LoseVersion makes the cases that need one skip with a named reason.
It is its own commit so that it can be judged, or replaced, on its own: the
same semantics could ride on BumpEpoch taking a lost set, and only the
plumbing would differ. Nothing uses it yet.

* chore(epoch): add signature-only stubs for the survival rework

The tests that follow exercise BumpEpochCarryingInTx, LoseVersionInTx,
ErrEpochAddressNotServed and the BumpEpochCarrying and LoseVersion store
methods (gastownhall/beads#6664, review 5360880888). Stubs give those names
so the tree builds and the tests fail for their real, behavioural reasons
instead of failing to compile.

No logic: ErrEpochAddressNotServed is a sentinel, BumpEpochCarrying advances
the counter exactly as BumpEpoch does and carries nothing, and LoseVersion
returns "not implemented". The next commit adds the tests; the one after
replaces these bodies.

* test(feat): red — record survival explicitly in epoch_minted_addresses, make CurrentAddressFor read-only, carry on a token-scheme change

Tests for the survival rework of gastownhall/beads#6664 (review 5360880888:
Major 1, Minors 3 and 4). Every test is written before any production change.

- Contract: the earlier mint-driven R20-n case is restated as three named
  phases (a survivor and a lost Version, loss is terminal, survival needs no
  upkeep), plus three new cases for a token-scheme change (carry the live
  lineages and only those, a carried address keeps resolving across later
  bumps, a lost address stays Gone across a scheme change). All three legs
  register them and wire LoseVersion and the carrying bump.
- Shared body: unit tests for the row-based resolver (exactly the address's
  row and the epoch, fail closed on a row from a future epoch), a read-only
  CurrentAddressFor with typed errors, LoseVersion, a bump that writes only
  store_epoch, a mint that never hands back a lost address, and the
  per-database counter (Minor 3). Minor 4 gets a guard that no address in the
  test file is written by hand.
- Real engine: the carry on the embedded leg (one carry row per live id, the
  lineage root, the collision rule, a row from a future epoch, a rewound
  counter, database-wide, lost lineages), the publication sets of every
  writer, and on the server leg the overlap of a mint with a bump (now a Live
  survivor) and a deterministic mint-after-loss interleaving that must not
  revive the lost address.
- Migration 0071 byte pin and a real-dolt shape check for carried_from,
  gone_at_epoch, the carried_from index and the gone-not-before-mint CHECK.

These fail on the current code, and some do not build yet because
BumpEpochCarryingInTx, LoseVersionInTx, ErrEpochAddressNotServed and the store
methods they exercise do not exist.

* feat: green — record survival explicitly in epoch_minted_addresses, make CurrentAddressFor read-only, carry on a token-scheme change

The survival rework of gastownhall/beads#6664 (review 5360880888: Major 1,
Minors 3 and 4). An address's status is now a function of its own row and the
current epoch, never inferred from other rows.

- Migration 0071 (edited in place; no new slot, no ALTER): the table gains
  carried_from, gone_at_epoch, an index on carried_from and a CHECK that a loss
  epoch is not before the mint epoch.
- Shared body: Live unless gone_at_epoch is set, and a row from an epoch that
  has not happened yet fails closed; the chain query is deleted. CurrentAddressFor
  only reads and returns typed errors. LoseVersion marks a whole lineage lost,
  once, guarded by gone_at_epoch IS NULL. BumpEpochCarrying (token-scheme change)
  writes one carry row per live lineage naming the lineage root, resolves a
  shared-id collision by carrying the newest and losing the rest, and fails if a
  row already sits at the new epoch. A mint only inserts its own root row and
  never hands back an address that is not served. A restore or reinit bump
  still writes only store_epoch.
- Both Dolt legs: BumpEpochCarrying publishes store_epoch and
  epoch_minted_addresses, LoseVersion publishes epoch_minted_addresses and
  returns a failed publication, and CurrentAddressFor runs on the read path and
  publishes nothing. The per-database epoch counter (Minor 3) and the
  requirement that a caller of the carrying bump hold the workspace gate
  exclusively are documented where they apply.

One change to tests written in the previous commit: the three real-server
publication probes that only need a clean working set now open a database of
their own, as the overlap tests do, instead of queueing on the shared test
database's schema-init lock. Its five-second acquire timeout ran out under load
and failed two of them; no assertion changed.

* test(dolt): run the epoch contract on a database of its own

TestEpochContract set up through setupTestStore, which puts every parallel
test on the shared test database and queues their schema initialization on one
lock with a five-second acquire timeout. Under host load a setup that waits
behind another parallel test's runs out of it and fails at its first line with
"schema migration lock unavailable: timeout". That failed the unchanged
first-mint test twice in the dolt lane once this change had added tests to it,
and the contract's own setup is exposed to the same timeout.

The contract now opens a database of its own, the way the overlap tests and the
publication probes already do, so this change adds no contention on the shared
database's lock. No assertion changed.

* docs: replace internal tracker ids in the epoch comments and test names with plain descriptions

Comment and text edits only; no behavior changes and no line is added or
removed (21 lines are replaced one for one). Each replaced line named an
internal tracker id in a header, a test comment, a failure message or the
migration header; it now says what it meant in plain words or cites the
upstream issue or pull request. The EpochFixture API lines and the already
published commit messages are left as they were.

* ci: list this PR's embedded storage tests in the embedded shard manifest

#7156 made the embedded-Dolt tier's shard manifests exact-once (50 cmd
shards, 15 storage shards), so every embedded test must be listed. This PR
adds eleven embedded storage tests and no embedded cmd tests; this commit is
exactly what the generators write for them:

  python3 scripts/ci/gen_embedded_cmd_shard_manifest.py 50 --weights=duration --write
  python3 scripts/ci/gen_embedded_storage_shard_manifest.py 15 --weights=duration --write

Incremental: 11 lines added, none moved; the cmd manifest is unchanged.

Rebase note (maintainer): regenerated on current main, whose embedded storage
manifest uses a 40-shard block; the generator's incremental output placed
these tests at shards 7, 9, 11, 20, 21, 28, 31, 32, 33, 34 and 36 of 40, one
test per shard (gen_embedded_storage_shard_manifest.py 40 --weights=duration
--write; --check passes).

* chore(bazel): bazel-sync for the epoch sources and migration 0071

The BUILD files did not list epoch_cas.go in the dolt, embeddeddolt and
issueops libraries, issueops' epoch_cas_test.go, or migration 0071 and its
test, so Bazel could not compile those packages' tests. This is exactly the
patch make bazel-sync writes (gazelle plus go_srcs.py; the PR's BUILD-sync
CI step printed it): 4 files, 6 lines, nothing else.

Rebase note (maintainer): the migration is now 0072, per the landing-order
ruling (#6943's participation_generation is 0070 and #6661's
removed_restriction is 0071); the commit "chore(schema): renumber
epoch_minted_addresses to 0072 after #6661's 0071" renames these BUILD
entries. On the rebased base, this commit's internal/storage/schema/BUILD.bazel
hunk is merged with the base's 0070 and 0071 entries.

* chore(schema): renumber epoch_minted_addresses to 0072 after #6661's 0071

Migrations are numbered by landing order. #6943 (participation_generation,
the versioned-history write fence) owns main-plane 0070 and #6661
(removed_restriction) owns 0071, so this PR's epoch_minted_addresses
migration moves to the next free slot, 0072. The rename is done here, as one
maintainer commit, rather than inside the replayed commits, so the history
shows exactly what changed relative to the PR as reviewed.

- migrations/0071_add_epoch_minted_addresses.{up,down}.sql become 0072_*.
  Neither header names its own number, so the SQL and its comments are
  unchanged. Neither file exists on main, #6943 or #6661, so this is not an
  edit to a shipped migration.
- cli_migrations.go needs nothing: the migration is a plain CREATE TABLE IF
  NOT EXISTS with no CLI-bundle override.
- migration_0071_add_epoch_minted_addresses_test.go becomes
  migration_0072_add_epoch_minted_addresses_test.go; its consts, tests and
  messages say 0072, it owns the one LatestVersion pin (72), and its slot
  history now records the move past #6943's 0070.
  TestLatestVersionIncludesMigration0071 in #6661's removed_restriction test
  was already retired to a pointer comment by the rebase's resolution of
  "renumber epoch_minted_addresses to 0070"; that comment now names
  TestLatestVersionIncludesMigration0072 and its file.
- BUILD.bazel embedsrcs/srcs, and the three epoch_cas.go headers (dolt,
  embeddeddolt, issueops) that cite the migration number.

The intermediate commits of the rebase are not expected to build, for two
reasons:

- a duplicate migration version: the PR's epoch_minted_addresses migration
  shares 0069 with main's 0069_widen_issue_versions_datetime_precision until
  the PR's own "renumber epoch_minted_addresses to 0070", and from there
  shares 0071 with #6661's removed_restriction until this commit;
- a helper-name collision: from the PR's "feat: green — Fix PR #6664: restore
  R16 honest-skip ... (refs be-ah0jf)" on, internal/storage/issueops declares
  readStoreEpochInTx twice, once in #6943's version_history.go and once in
  this PR's epoch_cas.go, until "fix(epoch): rename #6664's read-only
  store_epoch read past #6943's readStoreEpochInTx" later in this stack.

This commit ends the duplicate version, but it still does not compile on its
own because of the collision; the stack builds from the rename commit on.

Checked at the tip of the stack, where the rename has landed: go test
./internal/storage/schema/... with the dolt CLI lane
(including TestAllMigrationsSQLAppliesThroughDoltCLIAndRecordsLatestVersion
and TestMigration0072RecordsSurvivalInTheAddressTableThroughDoltCLI), and
scripts/check-migration-hygiene.sh with BASE_SHA=origin/main and
BASE_SHA=vh/6661-rebase.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(epoch): waive #6664's three new epoch contracts on main's http leg

main gained an HTTP storage leg (#7247) after this PR's base, and
TestEveryLegWiresEveryRoleContract requires every leg to name or waive every
role contract. This PR adds three EpochFixture cases
(RunTokenSchemeChangeCarriesLiveAddressesAndOnlyThose,
RunACarriedAddressKeepsResolvingAcrossLaterBumps and
RunALostAddressStaysGoneAcrossASchemeChange); dolt, embeddeddolt and uow wire
them, and the http leg did not name them.

They are waived on the http leg with the existing
retentionEpochNoRoleWaiverReason, which already covers every other
RetentionFixture/EpochFixture case there: EpochFixture is raw storage hooks
(CurrentEpoch, BumpEpoch, MintUnderEpoch, StillServes, Resolve,
CurrentAddressFor, LoseVersion) with no publicops role behind them,
and internal/httpclient is a remote client with no epoch counter or address
table of its own. The constant's doc comment now counts eighteen cases.

Test-only; no production code changes. After this, the http leg's only
unnamed entrypoints are #6943's seven RunParticipationGeneration* contracts,
whose waivers belong to #6943.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(epoch): rename #6664's read-only store_epoch read past #6943's readStoreEpochInTx

#6943's "a create stamps participation even when the row is flagged
no-history" (7c00d65fa6) adds readStoreEpochInTx to version_history.go: the
mint's read of store_epoch, which SEEDS the singleton row when it is absent.
This PR's epoch_cas.go already declared a readStoreEpochInTx of its own, so
the package stopped compiling once #6664 was stacked on that commit.

The two cannot be folded into one. This PR's helper is deliberately
read-only: an absent row answers epoch 1 without writing, so
CurrentEpochInTx, StillServesInTx, ResolveEpochInTx, CurrentAddressForInTx and
LoseVersionInTx never write from a read (review item B4, pinned by
TestCurrentAddressForNeverReseedsAnAbsentStoreEpochRow and
TestCurrentAddressForWritesAndPublishesNothing). Calling #6943's seeding read
from those paths would break that.

So #6664's helper becomes readStoreEpochWithoutSeedingInTx, and its doc
comment says why it is not readStoreEpochInTx. The five call sites and the
ensureStoreEpochRow comment that names it follow. No behavior changes on
either side: #6943's mint path keeps its seeding read, and this PR's read-only
paths keep theirs. (ensureStoreEpochRow, which BumpEpochInTx and
MintUnderEpochInTx use, now has the same body as #6943's readStoreEpochInTx;
it is left as it is rather than folded in here.)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(storage): say exactly why the retention and epoch contracts stay waived on http

All but four of the participation-generation contracts (#6943's write
fence) now run over the served wire
(internal/httpclient/served_participation_generation_test.go): their subject
is a create or an update, which the client can send, and the fixture reads
the reference store's raw columns. The four stay waived, because the
mutation each needs has no form on the wire. This checked whether the
eighteen RetentionFixture/EpochFixture cases waived on the http leg,
including the three this PR adds, can be wired the same way. They cannot,
cheaply or otherwise, without a new wire operation:

- every EpochFixture hook (CurrentEpoch, BumpEpoch, MintUnderEpoch,
  StillServes, Resolve, CurrentAddressFor, LoseVersion) is the operation
  under test, not a seed or a raw read. Those operations are methods on the
  concrete *DoltStore and *EmbeddedDoltStore over issueops' *InTx bodies, on
  no storage interface, no publicops role and no wire operation. Every call
  path into them starts in a test: the methods are called only from each
  store leg's own _test.go files (its EpochFixture, which the conformance
  contracts drive, and its epoch tests), and the *InTx bodies only from those
  methods, from each other and from tests (the uow leg's fixture through a
  test-only type assertion, and issueops' and the dolt leg's own tests). No
  command, role or server handler reaches them, so no client mutation
  touches epoch state either;
- RetentionFixture's hooks (Resolve, Remove, Hold, ForceRemove, Erase, Mint)
  are implemented by no backend yet (every store leg wires them nil and its
  cases skip), and the wire has no removal, hold, erasure or gone/unknown
  resolve to bind them to.

Binding the epoch hooks to the reference store behind the served env would
pass, but as a property of that store, which the store legs already pin,
never of the client. So the waivers stay; retentionEpochNoRoleWaiverReason's
comment and reason string now say the above, in the shape #6661 gave
asOfReadNoHTTPWireWaiverReason, instead of the earlier general "raw storage
hooks with no publicops role" wording.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(epoch): report applied-but-unpublished epoch writes as indeterminate, bound address length, verify dup-key mints

Maintainer fixup for the #6664 review (adopt-pr attempt 1, iteration 1).

Major 1, applied writes reported as failed. An epoch writer whose SQL
commit has landed, or may have, now wraps storage.ErrCommitIndeterminate
on both legs and hands back what it applied, so nothing replays a bump
that has already advanced the counter:
- embedded BumpEpoch and BumpEpochCarrying return the new epoch with the
  error (failedBump), and MintUnderEpoch its address;
- server bumps wrap the sentinel on every Dolt failure after the SQL
  commit, including a failed staged-set read (unpublishedBump), and so
  does LoseVersion; an indeterminate SQL commit returns the epoch or
  address it may have committed, and a definite (typed MySQL) commit
  error returns neither.
Tests: TestEpochWritesReportAnUnpublishedCommitAsIndeterminate (new,
embedded, through an afterSQLCommit seam in runTransactionWithMessage);
on the server leg TestEpochWritesMarkAFailedStagedReadIndeterminate,
TestEpochWritesReturnWhatAnIndeterminateSQLCommitMayHaveApplied and
TestEpochWritesReturnNothingWhenTheSQLCommitFailsDefinitely, and the
sentinel asserted in every publication-failure test.

Major 2, address overflow. MintUnderEpochInTx refuses a pair whose
address would outgrow epoch_minted_addresses.address (VARCHAR(255)) at
the widest epoch the counter can reach, with a typed
ErrEpochAddressTooLong, so a carry can never fail on a lineage that
gained an epoch digit.

Major 3, duplicate-key mint. A duplicate key from the mint's INSERT is
no longer success: the row is read again and the mint stands only if
this transaction sees it served; a Gone row fails the mint with
ErrEpochAddressNotServed, an unreadable one with the duplicate-key
error. Measured on dolt-sql-server 2.2.0, the stale-snapshot INSERT does
not report a duplicate key at all: its COMMIT fails with Error 1213 and
the retried mint answers ErrEpochAddressNotServed
(TestAMintRacingTheMintAndLossOfItsAddressConflictsAtCommit).

Minors:
- absent store_epoch row: sqlmock cases pin that CurrentEpoch,
  StillServes, Resolve, CurrentAddressFor and LoseVersion never seed it;
  switching any of the five to the seeding reader now fails the test;
- the server publication tests mint their address instead of writing it
  by hand, and TestEpochCASTestsBuildEveryAddressWithEpochAddress scans
  that file too (issueops_test gains //internal/storage/dolt:go_srcs as
  data);
- stale text: the duplicate-key and carry comments, the issueops
  header's CompareAndSetVersionInTx citation, the embedded header's
  parity claim, and the 0072 header's "upserts the same row" (0072 is
  past the frozen floor).

Declined, for the owner:
- a scheme-change carry voids an older live lineage re-minted after a
  restore: rule (a), document and pin it, or rule (b), resolve the loser
  to the winner's carry, is a design call about R20-n, not a review fix;
- the uow epoch fixtures' in-transaction DOLT_COMMIT('-Am'): test-only
  fixtures with no production caller; routing them through RunTxScoped
  is follow-up work.

Validation: go build ./...; go vet; nogo (bazel --config=nogo) on
issueops, dolt and embeddeddolt; issueops epoch tests; the dolt epoch
tests against a real dolt-sql-server (56 pass) and the fake-backed
publication tests; embedded epoch tests with BEADS_TEST_EMBEDDED_DOLT=1;
uow epoch contract; the schema package; the address guard under bazel
in the local sandbox. All 14 overlay mutants of the fixes are killed.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Jim Wordelman <mayor@quad341.uk>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
2026-10-18 21:20:57 +00:00
Jim Wordelman
9c6f6e15cd
bd versions + a config switch for versioned history — the minimum cut that makes versioned beads usable (#6138) (#6661)
* test(conformance): author R7.1 as-of-read conformance contract

Adds a new Phase 0 conformance contract for R7.1 (as-of reads,
gastownhall/beads#6136, design doc #5898 rev 9) -- no fixture existed for
this anywhere in backend/conformance/, so this is authored from scratch,
not un-skipped.

AsOfReadFixture supplies three hooks: Resolve (the read under test),
MintAt (seeds a version at a controlled accept-time), and
MakeUnanswerable (arranges a Gone/Unknown refusal 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).

Five Run* functions cover the bead's five required-coverage points
verbatim:
- selector accepts either an instant or a version address, and both name
  the same answer when they resolve to the same version;
- resolution returns the latest version at-or-before T, with a version
  accepted after T strictly excluded even when close by;
- a served result reports the exact address it served;
- an unanswerable read refuses as a typed Gone*/Unknown outcome with a
  reason, and never substitutes a neighboring version, the nearest
  surviving version, or current state -- asserted directly by requiring
  Address == "" on every refusal;
- local completeness only (TC3): a lineage minted into one of two stores
  resolves there and refuses Unknown (FR-06) on the store that never
  received it, asserting nothing about agreement between the two.

The file's doc comment states the Memory-plane-consumer-policy non-goal
explicitly (closed-before-T boundary, sibling exclusion, supersession
exclusion are consumer policy per #5877, not part of this primitive) so
the gap reads as deliberate scope, not an oversight.

Wired onto all three storage legs (dolt, embeddeddolt, uow) with
unconditional "not implemented" stubs rather than partial-real hooks, so
every case fails via MintAt on its first fixture call -- deterministic
RED with no risk of an accidental pass, per the precedent set by
be-x5jqd.1. Sentinel error messages reference be-x5jqd.5, the
implementation child this suite is written ahead of.

TestEveryLegWiresEveryRoleContract requires zero waivers: all 5 new
entrypoints are fully wired (not nil) on all three legs.

Branch cut from the rebased be-2h167 head (5fdfb92fe5).

Verified via go build ./..., go vet ./..., gofmt -l, and go test -tags
cgo across all three legs: all 5 new subtests (8 counting the 4-way
Gone/Unknown table) FAIL for the documented reason,
TestEveryLegWiresEveryRoleContract passes cleanly on all three legs, and
TestVersionedHistoryPhase0RunsInFullSkipMode is unaffected.

Bead: be-x5jqd.2

* fix(history): refuse metadata integers binary64 cannot hold exactly (refs be-wdlod, #6358 follow-up)

canonicalDurableState canonicalizes numbers per RFC 8785 (JCS), which
renders every number as an IEEE-754 binary64 double regardless of
magnitude. An integer-valued metadata literal past 2^53-1 therefore
rounds to a DIFFERENT VALUE on the way into durable_state -- not a
formatting change, a value change -- which can collapse two distinct
issue states onto one durable_state and therefore one content token.

refuseUnrepresentableIntegers is the fix: an admission gate, one layer
above the JCS step, that parses each JSON number literal exactly with
math/big (never float64 -- float64 rounding is the exact thing being
guarded against) and refuses whenever the literal's VALUE, not its
spelling, is an integer whose magnitude exceeds 2^53-1. Value-not-form
matters because the first cut of this gate skipped any literal
containing '.', 'e', or 'E' outright, reasoning that non-integer forms
round-trip losslessly -- true for genuinely fractional literals, but
not for an integer VALUE spelled in decimal or exponential form: QA
found that 9007199254740993.0 and 9.007199254740993e15 walked straight
past that first gate and canonicalized to the same colliding target as
the bare literal. The predicate now inspects the value via
big.Rat.SetString/.IsInt, so all three spellings are refused alike.

1e300 is refused too, no notation carve-out: it denotes the integer
10^300, and binary64 spacing near that magnitude is roughly 2^248 --
vastly wider than the collision window at the 2^53 boundary this gate
exists to close. Admitting that spelling while refusing 9007199254740993
would be the same defect with a bigger window (mayor's ruling, citing
this collision-window argument as decisive). Non-integer values stay
admissible past the bound (1.5e300 is fine): ES6 shortest-round-trip
formatting is a bijection on doubles, so two non-integer literals
collide only if they already denoted the same double before this gate
ever ran, and a fractional literal never carried a promise of exact
decimal storage the way an integer -- an id, a count, a timestamp --
carries a promise of exactness that silent rounding would corrupt.

jcsCanonicalize is canonicalDurableState's RFC 8785 step pulled out on
its own, below the gate rather than behind it, because refusing 1e300
puts the admission policy at odds with one of this store's own spec-
conformance fixtures: testdata/jcs/input/values.json, one of the 10
official RFC 8785 vectors shipped verbatim from the spec's reference
suite (not authored here), itself contains 1E30. RFC 8785 conformance
is a claim about the canonicalizer, not about this store's admission
policy, so TestCanonicalDurableStateIsJCS now runs all 10 shipped
vectors -- values.json included, still asserting 1E30 folds to 1e+30
per spec -- through the ungated jcsCanonicalize, while its two local ad
hoc cases keep exercising the full gated canonicalDurableState, since
neither conflicts and both are more faithful to production traffic that
way. The gate's own refusal of that magnitude is pinned separately, on
its own terms, in version_history_integer_admission_test.go.

Severity is MINOR, not MAJOR: Dolt's JSON column type already
renormalizes metadata to float64 on every read regardless of this gate
(measured on dolt 2.2.3: 9007199254740993 reads back as
9007199254740992, 1e300 as 1e+300), which converges two distinct
in-memory states to one stored state before any version row is minted.
The collision this gate closes is therefore unreachable through normal
bd update traffic on this backend; it stays real for off-path writes --
bd sql, a hand-written JSONL import, or a TEXT-column backend -- which
is why this landed as a follow-up rather than gating Phase 2 itself.

Verified clean: a full module compile; static analysis over the
storage tree; the complete issueops package suite (260 subtests); the
schema package suite; and the broader storage tree, apart from one
dolt-package test that fails identically against the pre-this-diff
baseline (a Dolt server port collision with a concurrent session's
process on this host) -- confirmed pre-existing and environmental, not
caused by this change.

* feat(issueops): implement R7.1 as-of read's store-layer primitive (be-x5jqd.5)

Turns backend/conformance/versioned_read_contract.go (authored RED in
6aefdce60, gastownhall/beads#5898 rev 9, #6136) towards GREEN. This
commit lands the shared production seam; wiring the three per-leg
fixtures (dolt, embeddeddolt, uow) onto it is a follow-up commit.

asof_read.go (new): AsOfReadInTx resolves an AsOfSelector (an instant
or a previously-served version address) to one issue_versions row --
the latest version accepted at or before T, everything later strictly
excluded -- and reports either its state and address, or a typed
refusal (gone-retention/gone-erasure/gone-reorganization/unknown) with
a reason. storeID is accepted only for signature parity with the
fixture hook shape (Design D: the conformance suite's own ad hoc
dispatch string selects among per-leg isolated test stores; issue_versions
carries no store_id column, matching CurrentEpochInTx's precedent).
AsOfRestriction is string-backed, unlike R20's int-backed
EpochRestriction, because it round-trips directly through the new
removed_restriction column with a plain cast.

Migration 0069 adds issue_versions.removed_restriction VARCHAR(30),
nullable (NULL = live, never a stored value). Sits alongside removed_at/
removed_reason (migration 0067, virgin until this slice); AsOfReadInTx
only READS all three -- a future R17 is the real writer via hold/remove/
erase primitives, no collision. Guarded PREPARE + CLI direct-DDL
override + schema_test.go hygiene entries, all modeled on 0068's
pattern; TestLatestVersionIncludesMigration0068 is superseded per the
one-pin-at-a-time convention.

version_history.go: splits RecordVersionInTx into a versionedHistoryEnabled-
gated wrapper and a new exported RecordVersionAtInTx, both delegating to
a shared recordVersionAtInTx(..., at time.Time) body. RecordVersionAtInTx
is test-support only -- ungated, caller-chosen timestamp -- so an as-of-
read fixture's MintAt hook can mint version rows dated in the past
without flipping a store's history-enabled flag. No behavior change for
existing RecordVersionInTx callers.

The new/moved code shifted which function each completeness guard sees
as the enclosing write site, so all three needed updating, not bypassing:
- row_lock_guard_test.go's funcNameExemptions key moves from
  RecordVersionInTx to recordVersionAtInTx (the write's new actual
  enclosing function), reasoning extended to cover both callers.
- journal_completeness_test.go's beadDMLExemptions and
  version_completeness_test.go's versionExemptions each gain a
  RecordVersionAtInTx entry mirroring RecordVersionInTx's own (test-
  support twin, no production caller, no mutation of its own to
  journal/mint beyond the seam itself).

Also fixed a latent test-helper gotcha found while writing the 0069
Dolt-CLI test: queryDoltCSV trims the whole `dolt sql -r csv` output
before parsing, so a row whose ONLY selected column is NULL renders as
a bare blank line that strings.TrimSpace silently swallows when it's
the trailing line, collapsing "one row, NULL value" into "zero rows".
Fixed by selecting a non-NULL anchor column (issue_id) alongside the
column under test.

Verification performed: full module compile and static analysis, gofmt
clean; the complete internal/storage/schema suite with the real-Dolt-CLI
lane enabled; and the complete internal/storage/issueops suite,
including every completeness/row-lock structural guard -- all clean.

* feat(issueops): wire dolt, embeddeddolt, and uow onto R7.1 as-of read (be-x5jqd.5)

Turns backend/conformance/versioned_read_contract.go fully GREEN
(authored RED in 6aefdce60, gastownhall/beads#5898 rev 9, #6136): this
follows up on 4da98a9a8's shared production seam by wiring all three
storage legs' AsOfReadFixture (Resolve/MintAt/MakeUnanswerable) onto
issueops.AsOfReadInTx, per that commit's own stated plan.

Each leg's asOfReadHarness is Design D's dispatch table: the
conformance suite invents storeID strings to select among N isolated
stores, and isolating them is entirely the harness's job --
AsOfReadInTx itself stays storeID-oblivious. The three legs differ
only in how they get that isolation cheaply:
  - dolt: one shared testcontainer, N randomly-named databases
  - embeddeddolt: N fully independent on-disk databases
  - uow: one shared dolt sql-server subprocess (NewDoltServerUOWProvider's
    adoption semantics collapse repeat calls against the same root dir
    onto the same process), N randomly-named databases

All three harnesses are Fatalf/Skip-free below their own
TestAsOfReadContract body: AsOfReadFixture's hooks carry no *testing.T
of their own and run from inside t.Run subtest closures (sometimes
nested two deep), where FailNow/SkipNow would panic with "subtest may
have called FailNow on a parent test". Failures instead flow back as a
plain error into conformance.RunAsOfReadXXX, which Fatalfs correctly
on the subtest's own goroutine.

Two small companion fixes surfaced while wiring the legs on:

  - issueops.asOfVersionAddress -> AsOfVersionAddress (exported): each
    leg's MintAt needs to build the exact token its own
    RecordVersionAtInTx write will resolve against, from a different
    package than issueops.

  - recordVersionAtInTx now truncates `at` to whole seconds before
    writing it to issue_versions.change_at (DATETIME, migration 0067).
    Measured on dolt 2.2.3: the column ROUNDS a sub-second value rather
    than truncating it, so a change_at of 13:32:04.77 lands at 13:32:05
    -- strictly later than the instant it was meant to record. That
    breaks resolveAsOfRevisionInTx's "at or before T" comparison
    (asof_read.go) for any T between the true instant and the rounded-
    up one. This is a production correctness fix, not test-only:
    RecordVersionInTx hits the identical hazard on every real
    time.Now().UTC() call whose nanosecond component rounds up.

Verification performed:
  - uow: TestAsOfReadContract green standalone (5 subtests, 4 nested
    restriction variants) and the full uow package green in isolation
    (673s, includes pre-existing TestReleaserContract and everything
    else). A `go test ./internal/storage/...` full-tree sweep flagged
    uow FAIL via a 600s hang inside TestReleaserContract's migration
    lock -- traced to cross-package parallel resource contention from
    running the whole storage tree's dolt-sql-server-spinning suites
    concurrently, not a regression: the same test is clean when the
    package runs alone.
  - embeddeddolt: TestAsOfReadContract green (22.89s, all subtests and
    all 4 restriction variants).
  - dolt: skipped on this host -- no Docker for the leg's testcontainer,
    the same pre-existing skipIfNoDolt gate the whole dolt package
    already runs under, unrelated to this change.
  - TestEveryLegWiresEveryRoleContract and
    TestEveryContractImporterInTheStorageTreeIsRegistered both pass for
    all three legs.
  - gofmt clean; whole-module build and vet clean.

Bead: be-x5jqd.5

* feat(versions): bd versions + a config switch for versioned history (refs be-hs42e.6.2)

Versioned history has been buildable but not usable: migrations 0067+ create
issue_versions, and the Phase 2 writer fills it, but SetVersionedHistoryEnabled
was a Go method nothing in cmd/bd ever called. There was no supported way for a
person to turn the feature on, and no way at all to read it back without raw
Dolt SQL. This adds the switch and a reader.

- versioned-history.enabled (env BD_VERSIONED_HISTORY_ENABLED), default off,
  applied at the top of wireStorageDecorators. It MUST run on the raw store:
  the capability is a type assertion and no decorator forwards it, so applying
  it after a wrap would silently leave history off while the config said it was
  on. TestVersionedHistoryConfigAppliesToTheRawStore pins the ordering, and
  fails rather than skips if a decorator ever starts forwarding.

- storage.VersionLister + issueops.ListVersionsInTx over issue_versions, on the
  dolt and embeddeddolt legs. A narrow capability rather than a Storage method,
  following ExternalRefHistoryQuerier: a backend that cannot know must be able
  to say so instead of answering "none".

- bd versions <id>, with three distinguishable outcomes rather than two. Off,
  unsupported, and empty are different answers with different fixes; an empty
  list is a claim about the bead, and returning it for the other two would be a
  wrong answer rather than an empty one. The four removal restrictions render
  as four sentences, and unknown (no lineage knowledge here) is not gone.

- REV is printed as a local ordinal with a footer saying so. It is deliberately
  NOT presented as a citable address: AsOfVersionAddress mints over the ordinal,
  two clones can both hold revision 8 of the same bead, and the durable
  version_id primary key has not landed. An address printed now would break
  every citation once it does.

- bd version <id> now points at bd versions <id> instead of printing bd's own
  build and looking like the bead has no history. Bare bd version is unchanged.

No migration: 0067/0068/0069 already carry every column this reads.

Verified on a scratch store: create + 2 updates + close with the flag on lists
4 attributed versions; with the flag off, 0 rows in issue_versions and the
command refuses naming the key.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(versions): emit local_revision, not revision, in --json (bee's #5898 consumer read)

types.Issue already ships `json:"revision"` (types.go:1206) and it is the
row-lock CAS token — an unrelated value, and a string where this one is an
int64. Emitting "revision" from the versions payload would put two meanings
and two types on one key in the place machines read: the `bd version`
collision again, with worse consequences, since a script that learned one
shape gets the other and cannot tell.

local_revision also carries the non-citability with the value rather than
only in a footer no script parses, and needs no rename when version_id lands
beside it.

Raised by @bee-ghosttrack's consumer read on #5898, who reported a couple of
hundred script files parsing `bd … --json` — this is the part of the surface
they would actually touch. Pinned by
TestVersionsJSONDoesNotCollideWithIssueRevision.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(versions): make the advertised switch actually switch it on (#6661 review)

@bee-ghosttrack's blocking finding: the help text and the off-refusal both
told the user to run `bd config set versioned-history.enabled true`, and that
command did not turn the feature on. The key is not yaml-only, so `bd config
set` routed it to the workspace DATABASE; both readers called config.GetBool,
which is viper (yaml + env) only. The user ran exactly what they were told,
was told it was set, and recording stayed off — configured on, actually off,
one layer up from the decorator-ordering hazard this command already guards.

Takes bee's option (b): read the switch from the store's own config, where
`bd config set` already writes it. That also makes recording a property of
the STORE rather than of whoever is calling, which is what closes finding 2 —
two clients of one sql-server can no longer disagree about whether a write is
recorded.

The two planes are OR'd rather than ranked. The hazard is a write that fails
to record, never one that records when it needn't, so either saying yes is
enough and neither can silently switch the other off. BD_VERSIONED_HISTORY_ENABLED
still works for a one-off run. A store with no settings plane (proxied, no-db)
falls back to viper instead of failing the command.

Also from that review:

- finding 3: the read no longer refuses just because recording is off. A store
  that recorded for a month and was switched off HAS versions; refusing made a
  claim about the store from a fact about this invocation's config, which
  VersionLister's own doc says are independent. Rows are listed either way,
  with a note when recording is currently off; refuse-with-remedy only when
  off AND empty.
- finding 4: an unresolved id with no versions is "no such bead", not "none
  yet". Falling through on an unresolved id stays right — a deleted bead can
  still have versions — but only until the answer is empty.
- finding 5: the ordering test's escape hatch is t.Fatal, not t.Skip; a skip
  returned before the assertion that actually guards the ordering. The
  storage_chain.go doc cited a test name that never existed. version_lister.go
  promised a list of compile-time assertions that was not there; the
  assertions now exist in each leg's own package, where they can compile.
- `versioned-history.` is a recognized config prefix, so the set no longer
  prints "not a recognized config key" immediately before confirming the set.

Test: TestVersionedHistorySwitchRoundTrip_Embedded drives the real
`bd config set` through to a real `bd versions` against a real store, with
BD_VERSIONED_HISTORY_ENABLED cleared so a pass proves the store setting
carried it alone. This is the round trip bee asked for, and it is the only
shape that could have caught the original defect — a fake-backed unit test
cannot see a disagreement between two real planes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* docs(versions): name what the OR'd switch planes cost (#6661 review)

@bee-ghosttrack, round 2: with the two planes OR'd rather than ranked, the
consequence worth naming is that once the store setting says on,
BD_VERSIONED_HISTORY_ENABLED=0 cannot countermand it for a single run. The
help now says so, and says where to turn it off instead.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(versions): gate the wiring store read on the capability, not a recover (#6661 review)

@bee-ghosttrack's round-3 blocking finding. wireStorageDecorators reads the
versioned-history switch off the raw store on every bd invocation, and did so
before anything established that the store could use the answer. cmd/bd's own
fakeProbingDoltStore embeds a nil storage.DoltStorage, so the promoted
WorkspaceConfig SIGSEGV'd at wiring time -- and a panic takes the whole test
binary down, which is why one unguarded read showed up as two red CI steps
(Test (macos-latest), PR Core (wrapper timing)) rather than one failed test.

Takes the fix bee prescribed: assert storage.VersionedHistoryConfigurer first
and read the store plane only when the store could act on the answer.

The previous round fixed this with a recover plus a WorkspaceConfig on the
fake, and left a comment arguing that no capability assertion could work. That
argument was wrong, and wrong in a specific way worth recording: it reasoned
about asserting WorkspaceConfig, which IS declared on storage.DoltStorage and
so matches every store including the nil-embedding fake. bee proposed
asserting VersionedHistoryConfigurer, which is a different interface --
SetVersionedHistoryEnabled is NOT part of DoltStorage, so the fake does not
promote it and does not satisfy it. The comment rebutted a fix that had not
been proposed. It now states what is actually true.

So the fake goes back to byte-identical with the pushed head: the wiring fix
fixes that test without touching it, as bee said it would, and the fake keeps
the "only the methods below may be called" constraint its own doc asserts.

The recover stays, as a backstop rather than the guard. It covers what the
assertion does not: versionedHistoryEnabled is also called from `bd versions`,
where the read is the point and no capability gate precedes it, and a store
that DOES implement the capability can still have a half-built settings plane.

The viper plane is still read first and unconditionally, so a set-but-unsupported
store still reaches applyVersionedHistoryConfig and still gets its warning. Only
the store-plane read is gated. The one case that loses a warning is a store whose
own settings plane says true but which lacks the capability -- and `bd config
set` could not have written that plane on such a store to begin with.

Tests, split so each layer fails for its own reason:

- TestWireStorageDecoratorsSkipsTheStoreReadForANonConfigurer asserts calls == 0,
  not merely that it survived. "It survived" is what the recover delivers too,
  which is how this regressed the first time.
- TestWireStorageDecoratorsSurvivesAStoreThatCannotAnswer keeps the recover's
  case, now on a store that IS a configurer so the guard lets it through.
- TestVersionedHistoryEnabledForWiringReadsTheStoreWhenItCanRecord pins that the
  guard did not stop reading the plane finding 1 existed to start reading.

Mutation-verified both ways: removing the guard fails the first test on
calls=1/want=0 while everything still "passes" by surviving; removing the
recover leaves the first test green and fails only the second.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* test(versions): name the embedded round-trip so CI selects it (#6661 review)

@bee-ghosttrack's round-3 finding 2. The round-trip test that proves the two
config planes agree ran only on the author's machine.

.github/scripts/embedded-test-shard.sh discovers what to run with
`grep -rh '^func TestEmbedded' cmd/bd/*_embedded_test.go` and validates
manifest entries against ^TestEmbedded[A-Za-z0-9_]+$.
TestVersionedHistorySwitchRoundTrip_Embedded matched neither, so the only
lane that sets BEADS_TEST_EMBEDDED_DOLT=1 for cmd/bd never selected it; the
generic Test jobs run without that env, where the test's own guard skipped it.
Skipped and passed look alike from outside, which is what made it invisible.

Renaming is the whole fix -- a test absent from the shard manifest still gets
a shard from the fallback distribution. Verified by running the script's own
selector over the tree and confirming the new name is discovered.

The rationale is now a comment on the test, because the old name reads more
naturally and nothing else in the file explains why the prefix is load-bearing.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* test(versions): drop the dead fixture, name the empty arm (#6661 review)

@bee-ghosttrack's round-3 finding 3. TestVersionsRefusesWhenFlagOff built a
backend holding one recorded version, handed it to nothing, and ended in
`_ = backend`.

The fixture was load-bearing for the assertion the test was named after --
that the read was refused BEFORE the backend was consulted. Finding 3 removed
that behaviour on purpose, so the assertion went with it; the fixture stayed
behind, unused, under a name still promising the old contract.

Renamed to TestVersionsOffAndEmptyRefusesWithRemedy for what it actually pins,
moved beside TestVersionsOffButRecordedStillLists so the two read as the pair
they are -- recording off decides the FOOTER, never whether to read; off with
rows lists them, off and empty is the one case that refuses -- and the dead
fixture is gone.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(proxy): give bd versions a capability row, a typed refusal (#6661)

main's proxied-server capability registry (#6582) requires every command
path to carry a row, and TestProxyCapabilityRegistryCoversCommandTree
fails for `bd versions`, which this PR adds.

It is refused, reason unimplemented, rather than permitted. It is a pure
read (issueops.ListVersionsInTx in one read transaction), so nothing
about it is unsafe on a shared backend and "design" would be wrong. But
it reaches the backend only through the optional storage.VersionLister,
which the dolt and embedded stores implement and the uow provider does
not. Permitting it would open the proxied provider in the root pre-run
(starting the proxy and dolt) and then fail untyped at
errVersionsUnsupported. The row refuses with proxy.versions.unsupported
before any side effect, and its tracking names the missing piece: a
VersionLister over the proxied uow provider (tracker #6132).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(uow): register verified shutdown cleanup in TestAsOfReadContract (#6661)

main's TestEveryServerFixtureRegistersVerifiedCleanup (#6441) requires
every server fixture to use verifiedShutdownCleanup(t, storeRootDir)
instead of calling proxy.Shutdown directly, so a shutdown that refuses
cannot leave a live dolt sql-server behind a green run. TestAsOfReadContract
still had its own proxy.Shutdown cleanup that only logged the error.

The cleanup is registered at the same point, so the LIFO ordering the
harness relies on (every provider closed before the shared server stops)
is unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* style(schema): gofmt cli_migrations.go after the 0070 renumber

The rebase onto upstream's 0069_widen_issue_versions_datetime_precision
(#6675) joined its const and the renumbered 0070 comment without the
separating blank line, which make fmt-check rejects.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(history): stop flooring change_at now that 0069 widened it (refs be-hs42e.10)

recordVersionAtInTx carried `at = at.Truncate(time.Second)`. That was correct
while 0067's plain DATETIME was in force: Dolt's datetime(0) does not truncate
sub-second input, it ROUNDS half-up, so a change_at could be stored strictly
LATER than the instant it recorded and break AsOfReadInTx's "latest version
accepted at or before T". Flooring first left nothing to round.

Migration 0069 widened change_at and removed_at to DATETIME(6), which removes
the rounding entirely and makes the floor actively harmful — it threw away the
microseconds the widening exists to keep. Two versions minted in the same
second collapsed onto one stored value and stopped being distinguishable by
change_at, which defeats --at, the only PORTABLE selector the read surface
offers while revision stays a per-store ordinal and no durable version address
has shipped.

This was measured, not inferred. On a store carrying both the widening and the
floor, four versions minted inside one second all read back 15:40:38.000000:
the column could hold microseconds and the writer refused to supply them. Two
correct fixes cancelling each other, and only the second one was visible.

removed_at needs no matching change: MarkLatestVersionRemovedInTx already
passes time.Now().UTC() straight through and was never floored. Audited rather
than assumed.

Pinned by TestRecordVersionKeepsSubSecondChangeAt (embeddeddolt), which mints
two versions 500ms apart inside one second and asserts both that the
fractional part survives and that the two differ. Verified it FAILS with the
floor restored — reporting exactly the 11:04:07.000000 collapse — and passes
without it, so it is a real guard rather than a test that passes either way.
The column's own half of the contract stays pinned by
TestMigration0069ChangeAtSurvivesSubSecondPrecisionThroughDoltCLI.

Also drops this branch's own tx-minting guard commit, which upstream landed
independently as #6833.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* test(feat): red — Activate versioned history in every store and provider factory, each store reading its own #6661 switch (stacked on #6661) (refs be-qxq70)

Tests first, all failing on the right reasons at fb6e219d6a (#6661's head):
- D1: on real embedded stores a routed update, a routed close and
  `bd create --repo` into a rig whose OWN row is on each gain 0
  issue_versions rows, want 1; the control (a write inside the rig) gains 1.
- D3: BD_VERSIONED_HISTORY_ENABLED=1 records into no routed store, and =0 is
  shown not to switch off a store whose row is on.
- D4: TestEveryStoreConstructionActivatesVersionedHistory flags all 9 store and
  provider factories, and its mutation probe reports "probed 0 of 9".
- wiring: wireStorageDecorators still reads the store's row (1 read) and
  switches it on; activation belongs to the factories.
- internal/versionedhistory (does not exist yet) and the doctor repair opener:
  the resolver, the provider read (K1), the error-vs-absent diagnostics and the
  shared-activation requirement.

* feat: green — Activate versioned history in every store and provider factory, each store reading its own #6661 switch (stacked on #6661) (refs be-qxq70)

Stacked on #6661 (fb6e219d6a). #6661's plane and approved commits are
unchanged: the switch stays a row of the store's own config table, OR'd with
viper, and `bd config set versioned-history.enabled true` still writes that
row and not config.yaml.

The defect: applyVersionedHistoryConfig ran only from wireStorageDecorators, so
the one store a command opens for its own workspace was activated and every
store built by newDoltStoreFromConfig (prefix-routed update/close, `bd create
--repo`, the direct-mode open) was not. With the switch on they recorded no
issue_versions row while the command reported success.

- Activation moves to where a store or unit-of-work provider is constructed
  (the store_factory.go/_nocgo.go twins, uow_factory.go's two provider
  constructors, the personal-migration planning store, and bd doctor's repair
  opener), on the raw store, before anything can wrap it. wireStorageDecorators
  no longer activates, so each store's row is read once per open.
- One resolver, in internal/versionedhistory, reachable from doctor/fix which
  cannot import package main. #6661's semantics are preserved: one key
  spelling, viper first, then the capability check, then the row read, with
  the recover backstop. The behavior-preserving refactor of #6661's
  versioned_history_switch.go / storage_chain.go is the only edit to files
  #6661 introduced; the resolver tests moved with the code, assertions
  unchanged.
- K1: a provider has no DoltStorage, so its row is read through a unit of work
  (NewUOW + ConfigUseCase().GetConfig) at construction: a pooled connection,
  one SELECT, rolled back. The constructors have already run initSchema, so
  this starts no server and creates nothing. It does not fall back to viper
  alone.
- A row read that errors resolves to off but is reported under BD_DEBUG; an
  absent row stays silent.
- Docs (configuration.md), a CHANGELOG entry, and a hint at `bd config set ...
  true` time that the setting replicates and is single-writer only.

The bazel-sync run also wanted unrelated BUILD entries for files that already
exist at #6661's head (versions.go, versioned_read_contract.go, ...); they are
not part of this change and are left out.

* test(feat): green — a served mutation records from the provider's own row, on a real server (refs be-qxq70)

K1 is the one place the resolver cannot ask a DoltStorage: `bd serve` against a
server-mode workspace writes through a unit-of-work provider, so its flag is
read through NewUOW + ConfigUseCase().GetConfig at construction. The fakes in
internal/versionedhistory prove the read; this proves it WORKS against a real
Dolt server at that moment (pool open, database selected, schema migrated).

Two server-mode workspaces on the shared test container: the one whose own row
says on records a served HTTP mutation (+1 issue_versions row), the one with no
row records none.

Measured both ways: passes with the provider activation in place, and fails
("added 0 issue_versions row(s), want 1") with it deleted from both provider
constructors in uow_factory.go.

Proxied lane only (BEADS_TEST_PROXIED_SERVER=1 BEADS_TEST_ENV_RUN_DOLT=1
TESTCONTAINERS_RYUK_DISABLED=true), like TestServeActivatesTheEventsJournal, so
it skips in a plain make test.

* test(feat): red — #6661 review round, small items: findings 2, 4, 5, 6 and 8

Tests for the small findings in the second review round on #6661.

- 2: `bd versions` must decide "recording" from the store's own setting.
  BD_VERSIONED_HISTORY_ENABLED=1 with the store's row unset and nothing
  recorded must refuse, not answer "none yet"; the help text must not offer
  the variable as a per-run switch for a read.
- 4: `bd versions --json` is one object, {"versions": [...], "recording":
  bool}, with [] rather than null when nothing is recorded.
- 5: AsOfReadInTx reports any stored removed_restriction outside its four
  values, "live" included, as unknown.
- 6: the 0070 header spells the restriction vocabulary with the underscore
  spellings the code stores and compares.
- 8: `bd version <arg>` exits 1 and points at `bd versions <arg>`. This one
  pins behaviour the branch already has, so it passes at red; it was shown
  to fail with the guard removed.

Item 7 is a comment-only fix and has no test.

* feat: green — #6661 review round, small items: findings 2, 4, 5, 6 and 7

- 2: `bd versions` reports the store's own setting. It read the environment
  and config.yaml as well, so BD_VERSIONED_HISTORY_ENABLED=1 made a store that
  never recorded answer "No versions recorded yet" instead of refusing with
  the remedy. It only reads, so those planes cannot make the store record.
  The "for one run" hint is dropped from the help and the refusal, since it
  could only ever produce the wrong answer.
- 4: `bd versions --json` is always {"versions": [...], "recording": bool},
  with [] rather than null when nothing is recorded. Previously a bare array,
  or null, and no recording flag.
- 5: AsOfReadInTx reports a stored removed_restriction outside its four
  values, "live" included, as unknown instead of passing it through.
- 6: the 0070 header and its test use the underscore spellings the code
  stores and compares. 0070 is unreleased, and this changes its content hash.
- 7: comment only. DATETIME(6) still rounds to the microsecond; the comment
  said 0069 removed the rounding entirely.

* test(fix): red — #6661 number admission: fractions past the bound, exponent cost, pre-enable scan

Tests for the review round on the number-admission gate, written before the change:

- a fraction whose nearest double is at or past 2^53 is refused (9007199254740993.5,
  9007199254740994.5, 9007199254740991.5), and the gate is closed under its own
  canonicalization, checked as a property over a corpus
- classification depends on magnitude, not on the size of an exponent: 1e100000000 and
  -1e400 are refusals, 1e-100000000 and 1e-400 are admitted, and allocation does not grow
  with the exponent
- the sentinel's text names the I-JSON exact-integer range
- CheckMetadataVersionable agrees with the mint, and FindUnversionableMetadata finds what
  the mint would refuse and skips what it never versions
- bd config set versioned-history.enabled true refuses, writing nothing, over rows the mint
  would refuse, and false never scans

Guards that pass before and after by design: the verdict on every literal as the store
returns it, the mint's refusal writing nothing, and, on the server and embedded legs, the
store-level property that no two literals reading back as different numbers share a canonical
form. Those store tests also log what each Dolt holds for a number outside the range when
history is off, and pin that a later write to such a row is refused once history is on.

* fix: green — #6661 number admission: the nearest-double rule, ParseFloat classification, a pre-enable scan at the switch

The admission gate now refuses a JSON number literal if and only if the binary64 nearest to it
has magnitude above 2^53-1, or it overflows, whatever the literal's spelling:

- a fraction that rounds to or past 2^53 (9007199254740993.5, 9007199254740994.5,
  9007199254740991.5) is refused, so the gate is closed under its own canonicalization
- literals are classified with strconv.ParseFloat, linear in their length, so 1e1000000 no
  longer builds a million-digit integer inside the writer's transaction; an overflow is the
  sentinel and a magnitude too small for binary64 is admitted; math/big is gone
- the sentinel reads "number is outside the I-JSON exact-integer range (magnitude above
  2^53-1)"; ErrIntegerNotRepresentable keeps its name, with a comment saying why
- ordinary fractions such as 0.1 stay admitted; no verdict on a value the store hands back
  changes

The header now says what the mint's refusal is: an integrity backstop inside the writer's
transaction, not an admission policy for metadata.

bd config set versioned-history.enabled true now checks the store first. It reads every issue
the mint would version, runs the mint's own function over each one's metadata
(issueops.CheckMetadataVersionable, through issueops.FindUnversionableMetadata), and refuses,
writing nothing, while any is refused, printing the count, the ids and the fix. There is no
override; setting it false never scans. The environment and config.yaml planes do not pass
through the command and rely on the refusal at write time.

Also: docs and a CHANGELOG entry, and comments in the existing admission tests that described
the old rule.

* test(fix): keep the exponent-cost allocation test stable under the race detector

TestNumberAdmissionAllocationsDoNotGrowWithTheExponent compared two
independently averaged allocation counts with a strict >. Under -race
sync.Pool drops one Put in four at random, and the refusal's fmt.Errorf
takes its printer from a pool, so a call now and then allocates one more
than it would. The test failed on most runs of `go test -race -short`, the
flag set of the required lane, and never without -race.

That noise only ever adds allocations, so compare the fewest allocations
over many single-call samples instead. The comparison stays strict, and it
still fails on the exact big.Rat gate this test exists to keep out (49
allocations for 1e1000000 against 36 for 1e400). The doc comment no longer
claims the count is deterministic under -race.

* test(fix): red — set-many skips the pre-enable scan; pin what the scan reads

bd config set-many versioned-history.enabled=true switches versioned history
on with no pre-enable scan: only bd config set makes it. With a row holding a
number outside the I-JSON exact-integer range the setting is turned on and the
next write to that row fails. The new embedded test drives the real verb over
such a row and expects the whole batch to be refused, writing nothing.

The scan's own embedded test only used open issues, so deleting AllFlag or
IncludeAllTypes, or replacing the unlimited Limit, left it green. It now adds a
closed, a pinned and a gate offender, and a second test imports more rows than
one default page and expects every one of them counted.

* fix: green — bd config set-many runs the pre-enable scan for versioned-history.enabled

bd config set refuses to turn versioned history on while an issue holds
metadata a version could not record. bd config set-many writes the same
setting through a validation loop of its own and made no such check, so it
switched history on over a row whose next write then failed. It now runs the
same check for that one key inside its validation loop, before any pair of
the batch is written, so a refusal stores nothing. The check reads through
the accessor it already used on both routes: the store the command has
opened on the direct route, the provider on the proxied one.

* chore: strip internal tracker ids from the comments and tests across #6661's range

Comment and test-text changes only; no behaviour changes. Across every commit from the
merge-base with upstream main to here, the comments and tests named internal tracker ids
(one bead id in eleven comments and in one test failure message, an example id in the
`bd version` guard's comment, and an internal decision's attribution in the huge-exponent
admission test). They now cite gastownhall/beads#5898 and #6136 only, which is what a reader
of the public branch can follow.

The 0070 migration's header comment is one of the edits. That migration is new on this branch
(it does not exist on upstream main), so the change is not an edit to a shipped migration, but
it does change the file's content hash; the schema tests that compute hashes are self-consistent.

Text that already exists on upstream main is left as it is, even where it mentions an id: this
commit does not rewrite lines the range did not add.

* chore(bazel): bazel-sync (gazelle) for the #6661 range

* fix(bazel): give fix_test the store.go its activation guard parses

TestVersionedHistoryDoctorRepairOpenerUsesTheSharedActivation parses
store.go from its working directory. `go test` runs in the package
directory, so the file is there. A Bazel test only sees its declared
runfiles, so the test failed with

    parse store.go: open store.go: no such file or directory

in //cmd/bd/doctor/fix:fix_test (--config=ci) and in shard 1 of
//cmd/bd/doctor/fix:fix_dolt_test (--config=doltserver), which runs the
same binary through data = [":fix_test"].

Declare store.go as data on fix_test.

* test(fix): red — the pre-enable scan must check the whole issue, as the mint does

bd config set versioned-history.enabled true runs a check over every issue
before it turns history on. The check looked at each issue's metadata alone,
while the mint canonicalizes the whole issue. A gate's timeout is a
time.Duration that a version holds as nanoseconds, so a gate whose timeout is
past 2^53-1 ns (about 104.25 days) holds a number outside the I-JSON
exact-integer range: the mint refuses every write to it, the scan never
looked, and the switch could be turned on over it.

- The agreement test's domain widens from metadata documents to whole issues:
  the metadata corpus, plus timeouts at 2500h (admitted), 2600h, 8760h and
  -2600h (refused), exactly 2^53-1 ns (admitted) and 2^53 ns (refused).
- The scan test covers a gate over 105 days and expects the verdict to name
  the field, "timeout".
- The mint-level refusal test covers the same gate and expects the refusal to
  name the field as well as the literal, for a number in metadata too.
- An end-to-end test on the direct route and one on the proxied route create
  gates with bd gate create --timeout, expect the enable to refuse and name
  them, and expect the issues the scan names to be exactly the issues whose
  next write the mint refuses.
- Three guards keep the scan's lite read from hiding a number: every column it
  leaves out is a string or a list of strings, nothing the mint adds and the
  scan does not load can hold a number, and no exported check over part of an
  issue exists beside the one the mint runs. Each guard is also run against
  shapes it must refuse, so it cannot pass by finding nothing.

The new symbols (CheckIssueVersionable, FindUnversionable and the Field of
UnversionableIssue) do not exist yet, so the issueops tests do not build.

* fix: green — the pre-enable scan runs the mint's own check over the whole issue

The check behind bd config set versioned-history.enabled true looked at each
issue's metadata alone. The mint canonicalizes the whole issue, and a gate's
timeout, a time.Duration held as nanoseconds, is a number outside the I-JSON
exact-integer range once it is past 2^53-1 ns (about 104.25 days). The mint
refuses every write to such a gate, the scan cleared the switch over it, and
the first write after that failed.

CheckIssueVersionable is now exactly canonicalDurableState's refusal over the
whole issue, and FindUnversionable runs it over every issue the mint would
version. It replaces FindUnversionableMetadata, and CheckMetadataVersionable
is gone, so no check over part of an issue is exported beside the one the mint
runs. A refusal names the top-level field it found the value in ("metadata",
"timeout") as well as the literal, on the mint and on the scan; the field is
located only after a refusal, so a write that is admitted still reads the
document once. A gate timeout above 2^53-1 ns is unrecordable by policy: it is
refused at the write, named by field and documented, not re-encoded.

The refusal at the switch gives the fix for each field. For a number in
metadata that is bd update --metadata or --unset-metadata, which works with
history on or off because a version is recorded from the state after the write.
For a gate timeout, which bd update cannot change, it is removing the gate with
bd delete, or setting the timeout_ns column with bd sql while history is off;
bd sql needs a server-backed store, and the text says so. It also says the
check runs once, now: a writer that does not record (an older bd, bd sql, a
pull from a clone that had history off) can add such a row afterwards, and the
first write to it then fails with the same refusal. Making the check and the
write of the setting one transaction would narrow that window, not close it.

Corrected in the comments, the docs and the changelog as well: an import is not
a path that skips the mint, since it goes through the same batch create; and
Dolt's JSON column collapses duplicate keys when it stores a document, so on a
Dolt store neither the scan nor the mint can see one, and the duplicate-key
refusal is a defence for a backend that keeps them.

* test(fix): red — the listing must answer as the as-of read does; the SDK opens must be accounted for

Three review findings on the versioned-history change and one wording fix,
tests first.

- A removed version's restriction. AsOfReadInTx answers a stored value outside
  the four-value vocabulary (a NULL or empty column, "live", a hyphenated or
  arbitrary string) as unknown, but ListVersionsInTx hands the column back as
  stored, for every row, and the label bd versions prints passes such a string
  through. A table test runs the listing and the as-of read on the same stored
  value, for a version that was removed and one that was not, and expects the
  same answer, and none for a version that was never removed. The label gets
  the same out-of-vocabulary values and is expected to render what unknown
  renders.
- The SDK's store opens. The shared construction guard now scans the repository
  root as well, so the Go SDK's five opens (Open, OpenFromConfig and OpenGated,
  and OpenBestAvailable in each build-tag twin) are noticed. Nothing accounts
  for them yet, so both guards fail on exactly those five sites.
- A bytes bound beside the allocation-count bound on the number admission
  gate. A classifier that builds the number it is asked about makes one
  allocation whatever the exponent, so the count bound passes it, and the bytes
  grow. The fewest bytes one call allocates for a literal with a huge exponent
  must be no more than for a small one plus a margin. It passes today, because
  the gate never builds the number; it fails for a gate that does.
- The refusal at the switch names the gate remedy as bd delete <id> --force,
  says that without --force bd only previews, and says that removing the gate
  unblocks anything it was blocking. The embedded and proxied end-to-end tests
  expect all three.

* fix: green — the listing answers as the as-of read does; the SDK opens are accounted for

Three review findings on the versioned-history change and one wording fix.

A removed version's restriction. A stored removed_restriction is a free string,
and only the four values of the vocabulary are answers. The as-of read already
reported anything else (a NULL or empty column, "live", a hyphenated or
arbitrary string) as unknown, but the listing handed the column back as stored,
for every row, and the label bd versions prints passed it through.
NormalizeRemovedRestriction is now the one place that decision is made.
AsOfReadInTx calls it; ListVersionsInTx calls it for a version that was removed
and gives a version that was not removed no restriction; and restrictionLabel
renders through it. The listing, its JSON and the label now say what the as-of
read says for the same row.

The SDK's store opens. The Go SDK's five opens (Open, OpenFromConfig and
OpenGated, and OpenBestAvailable in each build-tag twin) apply neither per-store
switch, the events journal's or versioned history's, and they still do not.
Applying them would change the library's behavior for every embedder, so that
is a separate change; this one declares the boundary. The shared construction
guard now accounts for the five with one exemption reason that is true of both
switches, so a new SDK open is noticed rather than missed, and its staleness
check keeps the exemptions honest. The docs gain one bullet saying that writers
built on the SDK do not apply the switch.

The bytes bound on the number admission gate needs no production change: the
gate never builds the number, which is what the bound pins.

The refusal at the switch now names the gate remedy as bd delete <id> --force,
says that without --force bd only previews, and says that removing the gate
also unblocks anything it was blocking. The docs line says the same. For a gate
that blocks an issue, bd delete without --force prints a preview and exits 1,
and with --force the gate is removed and what it blocked is ready again.

* test(bazel): declare the root package's Go source as data for //cmd/bd:bd_test

The shared store-construction scan now reads the repository root, where the Go
SDK's opens live, but //cmd/bd:bd_test declared none of the root package's
source. Under bazel test the scan therefore saw an empty directory, reported
the five SDK exemptions as no longer matching a store construction site, and
failed the events-journal guard, while go test, which sees the whole checkout,
passed.

List the root in tools/bazel/go_srcs.py so the generator emits its managed
go_srcs filegroup there, and add that filegroup to bd_test's data. The new
block is the generator's own output and nothing else changes.

* ci: list the switch scan's proxied gate-timeout test in the 30-shard manifest

Upstream main (#7129) moved the proxied-server tier to 30 duration-balanced
shards, and TestProxiedShardManifestGeneratorNotStale requires every
TestProxiedServer*/TestServerMode* test exactly once in that block. This
branch adds TestProxiedServerVersionedHistorySwitchRefusesAnUnrecordableGateTimeout
(cmd/bd/versioned_history_switch_scan_proxied_integration_test.go), so the
block needs its line. Written by the generator itself:
python3 scripts/ci/gen_proxied_shard_manifest.py 30 --weights=duration --write
(one line, shard 8); --check exits 0 afterwards.

Rebase note (maintainer): regenerated on current main, whose proxied-server
tier uses 34 shards; the generator's incremental output
(gen_proxied_shard_manifest.py 34 --weights=duration --write) placed this
test at shard 6 of the 34-shard block.

* ci: list the PR's embedded versioned-history tests in the embedded shard manifests

#7156 made the embedded-Dolt tier's shard manifests exact-once (50 cmd
shards, 15 storage shards), so every embedded test must be listed. This PR
adds five embedded cmd tests and three embedded storage tests; this commit is
exactly what the generators write for them:

  python3 scripts/ci/gen_embedded_cmd_shard_manifest.py 50 --weights=duration --write
  python3 scripts/ci/gen_embedded_storage_shard_manifest.py 15 --weights=duration --write

Incremental: 8 lines added, none moved.

Rebase note (maintainer): regenerated on current main, whose embedded
manifests use 100 cmd shards and 40 storage shards; the generator's
incremental output placed these tests at cmd shards 55
(TestEmbeddedVersionedHistorySwitchScansEveryRowNotOnePage), 56
(...SwitchRoundTrip), 57 (...SwitchRefusesUnversionableMetadata), 58
(...SwitchRefusesAnUnrecordableGateTimeout) and 59
(...SetManyRefusesUnversionableMetadata) of the 100-shard block, and at
storage shards 5 (TestRecordVersionKeepsSubSecondChangeAt), 6
(TestVersionedHistoryKeepsNumbersTheStoreDistinguishesApart) and 23
(TestAsOfReadContract) of the 40-shard block.

* test: exempt OpenBestAvailableWith, where #7188 moved the SDK's store construction

Upstream #7188 split beads.OpenBestAvailable: it now delegates to the new
OpenBestAvailableWith, which builds the store. This PR's two construction
guards (TestEveryStoreConstructionActivatesTheEventsJournal and
TestEveryStoreConstructionActivatesVersionedHistory) share one exemption
list keyed by function, so after merging main they flagged
OpenBestAvailableWith as an unexempted construction site and reported the
OpenBestAvailable entries as stale. The two build-tag twins' keys now name
OpenBestAvailableWith. The reason is unchanged: it is the SDK's library
surface for embedders, and no code in the bd binary calls it. gofmt
realigned the three neighbouring entries.

* chore(schema): renumber removed_restriction to 0071 after #6943's 0070

Migrations are numbered by landing order. #6943 (participation_generation,
the versioned-history write fence) lands first and owns main-plane 0070 and
ignored/0028, so this PR's removed_restriction migration moves to the next
free slot, 0071. The rename is done here, as one maintainer commit, rather
than inside the replayed commits, so the history shows exactly what changed
relative to the PR as reviewed; the intermediate commits of the rebase carry
a duplicate 0070 and are not expected to build.

- migrations/0070_add_removed_restriction.{up,down}.sql become 0071_*, with
  their header comments updated (the SQL itself is unchanged). Neither file
  exists on main or on #6943, so this is not an edit to a shipped migration.
- cli_migrations.go: the CLI-bundle override is keyed to the new file name
  and renamed cliMigration0071AddRemovedRestriction, and its const now sits
  after 0070's.
- migration_0070_add_removed_restriction_test.go becomes
  migration_0071_add_removed_restriction_test.go; its tests and messages say
  0071, and it now owns the one LatestVersion pin (71).
  TestLatestVersionIncludesMigration0070 in #6943's participation_generation
  test is superseded by it and replaced by the usual pointer comment, and
  0069's pointer comment now names the 0070 file that superseded it.
- schema_test.go hygiene comments, BUILD.bazel embedsrcs/srcs, and the
  asof_read.go comment that cited the migration number.

Checked: go test ./internal/storage/schema/... (with the dolt CLI lane,
including TestAllMigrationsSQLAppliesThroughDoltCLIAndRecordsLatestVersion)
and scripts/check-migration-hygiene.sh against origin/main and against
#6943's tip.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(versions): reconcile #6661's tests and docs with #6943's write fence

#6943's write fence (design §16.2b) makes an update-shaped write to a legacy
record -- one whose participation_generation is NULL because it was created
while versioned history was off -- a skip, not a refusal: the fence returns
before the snapshot is canonicalized, so nothing is versioned and the mint's
admission gate never runs. Several of #6661's tests seed rows with history
off and then expect a later write to them to be versioned or refused, and
several comments say every later write to an offending row fails. On a tree
that carries both PRs those tests fail and those comments are wrong.

This ports, without changing their substance, the fence-integration commits
Jim Wordelman wrote for the donnabox integration fork, where both PRs were
already folded together:

- eff898db80 / 5d2e5a2ac4 (issueops, dolt, embeddeddolt): the mocked mint
  sequence scripts the fence's participation_generation read; the number
  fidelity test splits phase 2 into 2a (a legacy row is written, not
  versioned, not refused, stays NULL) and 2b (a participating row is
  refused and left untouched); TestRecordVersionInTxSkipsALegacyRowBefore-
  TheAdmissionGate pins the fence's order against the gate.
- e0ad9d1e3c / 1528022dfa (cmd/bd): the switch round trip and the routing/env
  end-to-end tests build the rows they expect a version for after the setting
  is on, and assert that the pre-setting seeds gain nothing.
- 18b9015bf5 (cmd/bd): the embedded and proxied gate-timeout scan tests assert
  the whole scan-vs-mint truth table (legacy offenders are named by the scan
  but not refused by the mint; participating offenders are both).
- 5929ebd50c / 8ce872be03 (comments, CHANGELOG, configuration reference): the
  mint's refusal binds rows that participate in history; the pre-enable scan
  cannot see participation, so it over-approximates in the safe direction.

Left out on purpose: the fork's mintSkipsRow helper and defer-wake sweep
change, and its bd doctor "Versionable Issues" check and the docs that point
at it; none of those are part of #6661 or #6943.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Jim Wordelman <jim@wordelman.name>

* test(versions): adapt #6661's guards to what main changed under it

Three test-side adjustments for code that landed on main after #6661's last
merge of it; no production code changes.

- internal/storage/leg_contract_wiring_test.go: main gained an HTTP storage
  leg, and TestEveryLegWiresEveryRoleContract requires every leg to name or
  waive every role contract. The five R7.1 as-of read contracts this PR adds
  are a storage capability the HTTP client does not serve (internal/httpclient
  answers AsOf with an explicit unsupported error, and the wire has no
  instant/address selector or gone/unknown refusal), so they are waived on
  the http leg with that reason, as the donnabox integration fork does.
- cmd/bd/versioned_history_construction_test.go: main split
  newDoltStoreFromConfig into two thin wrappers over openDoltStoreFromConfig,
  which is where the activation defer now lives (this rebase's resolution of
  the activation commit), so the factory guard keys on that body.
- cmd/bd/versioned_history_serve_e2e_test.go: main's
  TestProxiedGatedTestsRunInTheProxiedLane requires a test that skips unless
  BEADS_TEST_PROXIED_SERVER=1 to be one the proxied lane selects, so
  TestVersionedHistoryServeActivatesTheProviderFromItsOwnRow becomes
  TestProxiedServerVersionedHistoryServeActivatesTheProviderFromItsOwnRow,
  and the 34-shard proxied manifest gains its line (written by
  gen_proxied_shard_manifest.py 34 --weights=duration --write, incremental;
  --check passes).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* chore(bazel): emit go_srcs.py's managed blocks for internal/versionedhistory

Main's tools/bazel/go_srcs.py now manages a repo_files filegroup block in
every package BUILD file, lists those filegroups in the root BUILD.bazel's
aggregates, and lists every go_library in tools/bazel's release_cross_build
target. internal/versionedhistory is a package this PR adds, so after the
rebase those managed blocks were stale and TestBazelGoSrcsBlocksCurrent
(go test ./scripts/...) failed. This is the generator's own output
(python3 tools/bazel/go_srcs.py) and nothing else; --check passes
afterwards.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(versions): don't publish change_agent in bd versions --json

`bd versions <id> --json` prints storage.IssueVersion as-is, so every JSON
tag on that struct is part of a public contract. Provenance V2
(gastownhall/beads#7510, as ruled by the maintainer) removes the ad hoc
agent field in favour of an actor chain; shipping a "change_agent" key now
would make a public contract out of a field that is on its way out.

IssueVersion.ChangeAgent is now tagged json:"-". Nothing else changes: the
issue_versions.change_agent column (migration 0067) stays, ListVersionsInTx
still reads it, change_actor and change_message are still published, and
the human listing never showed the agent. No doc or golden named the key.

TestVersionsJSONDoesNotPublishChangeAgent pins the absence with a non-empty
value, so an omitempty-style regression would still fail, and pins that
change_actor and change_message are still there.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(issueops): pin what the unfenced test-support mint does on #6943's new paths

#6943's two fixes to the shared mint body -- (a) no issues row means no
mint and no error, and (b) a create-shaped call on a new issues-table row
flagged no-history stamps participation_generation without minting -- were
written for its two kinds. This PR's shared body has a third,
mintUnfenced, behind RecordVersionAtInTx (the R7.1 as-of fixtures'
controlled-timestamp mint). The rebase resolution decided what (a) and (b)
mean for it; this pins that decision:

- (a) applies. It is the plane rule (FR-8: the table that holds the row
  decides its plane), not the fence, and the unfenced kind already honoured
  the flag-based form of the same rule (IsWisp). Without it, an unfenced
  mint for an unflagged wisps-table row would insert a version row that no
  issues row points at. The shared body's issues-table read now runs for
  all three kinds; only the update kind acts on the value it reads.
- (b) does not apply. The unfenced mint never declares participation, so a
  flagged row returns right after the snapshot, as before: no read, no
  stamp.
- The fence still does not apply: a legacy row is minted, and the closing
  UPDATE advances current_revision alone.

TestRecordVersionAtInTxKeepsThePlaneRuleButNotTheFence scripts each of
those three sequences exactly with sqlmock.
TestTestSupportMintsStayOutsideTheShapeSplit places RecordVersionAtInTx
outside #6943's create / dual-shape / update classification explicitly (it
is the seam's exempt twin, not a mutation entry point or mint site): it must
be in none of the shape lists, stay in versionExemptions, and reach neither
RecordVersionForCreateInTx (it never stamps) nor RecordVersionInTx (whose
gate and fence would stop the as-of fixtures minting history-off rows). The
row-lock guard's exemption comment for recordVersionAtInTx already names the
stamp-only UPDATE: #6943's own wording of it (all three UPDATE issues
statements) was carried into that exemption when the as-of read commit was
replayed.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(storage): say exactly why the as-of read contracts stay waived on http

#6943 now runs most of its participation-generation contracts over the
served wire (internal/httpclient/served_participation_generation_test.go):
their subject is a create or an update, which the client can send, and the
fixture reads the reference store's raw columns. This checked whether the
five R7.1 as-of read contracts can be wired the same way. They cannot,
cheaply or otherwise, without a new wire operation:

- their subject is the read itself (AsOfReadFixture.Resolve), and R7.1's
  read, issueops.AsOfReadInTx, is reached by no publicops role and served
  by no wire operation;
- the wire carries neither selector (an instant or a served version
  address) nor the gone/unknown refusal the read answers with;
- the client's only point-in-time read, DoltStorage.AsOf, is a Dolt
  commit-ref read, not R7.1, and is on the client's D8 unsupported
  allowlist.

Binding Resolve to the reference store behind the served env would pass,
but as a property of that store, which the store legs already pin, never
of the client. So the waiver stays; its comment and reason string now say
the above instead of the earlier shorthand ("HTTP AsOf is explicitly
unsupported"), which conflated the client's commit-ref AsOf with R7.1.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(versions): describe what the write fence does to beads that predate recording

With #6943's write fence (design §16.2b) a bead that existed before
versioned history was turned on (participation_generation NULL) is legacy:
an update-shaped write to it is skipped, so it is never versioned however
often it is edited. Several user-facing strings from #6661 still described
the behaviour before the fence, and an independent review reproduced each
with a built bd (a legacy bead edited twice after enabling still lists no
versions; a legacy bead the switch refuses over is written without refusal
under BD_VERSIONED_HISTORY_ENABLED=1). Text only; no behaviour changes.

- bd versions help: only beads created while recording is on are versioned;
  a bead that already existed is legacy and editing it records nothing; no
  backfill. (Was: "a bead edited yesterday shows nothing until it is
  edited again".)
- bd versions empty listing: drops "yet" and says why the list is empty -- a
  bead created while recording is on always has its create version, so an
  empty list means the bead predates recording (or was made by a writer
  that was not recording), or is no-history or a wisp. The line still
  starts "No versions recorded for <id>", which the switch round-trip test
  pins.
- bd versions with recording off: only beads created after it is turned on
  are versioned.
- bd config set versioned-history.enabled true refusal: Jim's scan stays as
  conservative as he made it -- it cannot see participation, and a legacy
  row can still be minted create-shaped if it re-enters the issues plane --
  but the text now says a listed issue's writes are refused only if it
  participates (created while history was on, or entered the issues plane
  while it was on), and that legacy issues are listed because the check
  cannot tell. The closing line says the same of a value a non-recording
  writer adds later.
- docs/reference/configuration.md: the section opener says every accepted
  change to an issue created while history is on is snapshotted, and that a
  pre-existing issue is legacy; the "participates" parenthetical drops "or
  written" (a write never stamps participation; only a create-shaped mint
  does) and names entering the issues plane, matching the refusal text.

CHANGELOG already says "if it participates in history" and is unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(versions): keep updated_at across update-shaped version mints

The update-shaped mint ended with UPDATE issues SET current_revision = ?
WHERE id = ?. current_revision always changes there, so the column's
ON UPDATE CURRENT_TIMESTAMP clause fired: with versioned history on, every
label, dependency or import write moved issues.updated_at to the session's
wall clock (local time, read back as UTC). An import with
RejectStaleUpserts then stored the wall clock instead of the source's
updated_at, and the source's next genuine edit was rejected as stale. The
statement now assigns updated_at to itself, the rule #4298, blocked_state.go's
mark/unmark templates and the create-shaped mint statements already follow,
so history on leaves updated_at exactly where history off does. It is the
one statement every production update-shaped mint ends with.

Tests:
- TestEmbeddedMintLeavesUpdatedAtWhereHistoryOffDoes (embeddeddolt) ages a
  bead, adds and removes a label and a dependency, and runs two
  RejectStaleUpserts imports, with history off first as the control. With
  the fix reverted, history on fails all six arms (updated_at reads the
  wall clock, and the later source edit is rejected as stale); history off
  passes either way.
- RunParticipationGenerationFlagOffSkipsUpdateOnParticipatingRecord, wired
  on the dolt, embeddeddolt, uow and http legs: a record created with the
  flag on and updated with it off mints nothing and keeps its
  current_revision. Every other flag-off case uses a legacy record, which
  the fence stops first, so with RecordVersionInTx's gate removed this is
  the only case that fails, on all four legs. That gate is the single entry
  for every production update-shaped mint, so the one update arm covers
  label and close writes too.
- The sqlmock pin of the statement (version_history_preenable_scan_test.go)
  and the journal-completeness exemption comment follow the new SQL.
- The createbatchequiv issues_updated_at goldens of small, depadd,
  import458 and import458-reject-stale are re-recorded. They pinned the
  wall-clock bump, so each row minted a second time (eq-n2; eq-db1 and
  eq-dl; eq-b3 and eq-b250) had dropped out of the compared set; CI's
  embedded and server legs both printed the new digests. Recorded on
  embedded Dolt, the fix-reverted tree reproduces every committed golden
  byte for byte, HEAD moves only these four digests, and its rows equal
  the history-off rows in every scenario. GoldenDirEnv's comment lists it
  as the goldens' third deliberate change.
- The new embedded test has its line in the storage shard manifest
  (gen_embedded_storage_shard_manifest.py 40 --weights=duration --write),
  so TestStorageEmbeddedShardManifestGeneratorNotStale stays green. It sits
  after TestEmbeddedEveryAcceptedLifecycleMutationMintsOneVersion rather
  than at the end of the file, where #7646 appends its own test, so the two
  PRs still merge without a conflict in that file.

Docs:
- CHANGELOG: the feature's two entries under ### Fixed described fixes to a
  switch no released bd has. One ### Added entry replaces them, covering
  bd versions, the versioned-history.enabled switch and its per-store
  semantics, the pre-enable check, the single-writer caveat, migration 0071
  and the bd version <arg> refusal.
- The bd versions help, its recording-off refusal and empty-listing note,
  and the opening paragraph of the configuration doc's Versioned Issue
  History section now state the rule the pre-enable refusal prints: a bead
  participates if it was created, or entered the issues plane (a wisp
  promoted or made persistent), while recording was on.

bd version: the "did you mean bd versions" refusal now runs after the
command's metrics event is created, like the other in-RunE argument
refusals, so a mistyped bd version <id> is counted as a version invocation
instead of going uncounted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen

---------

Co-authored-by: Jim Wordelman <mayor@quad341.uk>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
2026-10-18 17:28:16 +00:00
Jim Wordelman
ce70b261c5
storage: add participation_generation (migration 0070) and the versioned-history write fence (#6943)
* schema+storage: restore 0068, move participation_generation to 0070 (be-blvmg)

MAYOR RULING 2026-09-29 on tracker be-waare: migration 0068 shipped to
origin/main as attribution_status-only (be-v33pa). be-h89oq's lineage had
appended participation_generation steps 4-5 to that same file while it was
still unmerged, which check-migration-hygiene.sh Check C correctly rejects
once 0068 is frozen on main. This restores 0068 to origin/main's exact
content and re-homes the participation_generation column (issues + wisps,
design section 16.3 steps 4-5, be-dt74u amendment) in a new migration 0070,
with its clone-local ignored/0028 twin for wisps. Ports back the
participation_generation write-fence consumer code (RecordVersionInTx in
internal/storage/issueops/version_history.go and its callers) and the
dualwrite contract tests that exercise it.

RED: the CLI-bundle direct-DDL override for 0070's guarded PREPARE/ALTER
pair is not yet registered in cli_migrations.go, so
TestBundleMigrationsWithPreparedALTERAreOverriddenOrJustified,
TestMigration0070AddsParticipationGeneration, and
TestAllMigrationsSQLUsesDirectDDLForKnownCLIIncompatibilities fail --
correctly: a fresh CLI-built bundle would silently omit the column
(dolthub/dolt#11345) while a runtime-migrated store has it.

git diff origin/main -- internal/storage/schema/migrations/0068_*.sql is
empty, confirming 0068 is untouched.

Agent-Signature: model=claude-sonnet-5; reasoning=high

* schema: register CLI-bundle direct-DDL override for migration 0070 (be-blvmg)

GREEN: adds cliMigration0070AddParticipationGeneration and its dispatch
entries (cliCompatibleMigrationSQL, cliSubstituteAssumesWispTables), the
same pre-2.3 Dolt CLI PREPARE/ALTER escape hatch 0067's wisps.current_revision
and 0068's attribution_status already use (dolthub/dolt#11345). Makes
TestBundleMigrationsWithPreparedALTERAreOverriddenOrJustified,
TestMigration0070AddsParticipationGeneration, and
TestAllMigrationsSQLUsesDirectDDLForKnownCLIIncompatibilities pass: a
fresh CLI-built bundle now carries participation_generation on both
issues and wisps, matching what a runtime-migrated store gets.

scripts/check-migration-hygiene.sh checks A-D pass; 0068 remains
byte-identical to origin/main.

Agent-Signature: model=claude-sonnet-5; reasoning=high

* build: bazel-sync BUILD.bazel for migration 0070 files (be-blvmg)

make bazel-sync (gazelle) picked up two files the RED commit added that
the hand-ported BUILD.bazel hadn't listed yet: 0070's embedded .up.sql in
the go_library embedsrcs and migration_0070_add_participation_generation_test.go
in the go_test srcs.

Agent-Signature: model=claude-sonnet-5; reasoning=high

* test(feat): red — Fix: enable history before fixtures in TestDualWriteDeleteNeighborRewriteRidesTheDeletesDoltCommit — PR #6943's §16.2b write fence leaves its flag-off neighbor legacy, so the delete mints 0 rows (stacked on 44418b3) (refs be-fyaja)

* feat: green — Fix: enable history before fixtures in TestDualWriteDeleteNeighborRewriteRidesTheDeletesDoltCommit — PR #6943's §16.2b write fence leaves its flag-off neighbor legacy, so the delete mints 0 rows (stacked on 44418b3)

(refs be-fyaja)

* test(conformance): pin that a wisp reaching the issues plane begins its history (be-31mnz)

Review feedback on #6943, blocker 1: with the flag on, a promoted wisp is
never versioned. None of the five RunParticipationGeneration* cases reaches
a promotion, so nothing caught it.

Two contract cases, wired on all three legs:

- RunParticipationGenerationWispPromotionBeginsHistory: create a wisp with
  the flag on, promote it, and require a stamped participation_generation,
  one version row, and +1 on the next update.
- RunParticipationGenerationWispPersistenceMoveBeginsHistory: the same
  check for a persistence-mode update (bd update --persistent). This mints
  at a different site than promotion on every leg: the guarded update's one
  end-of-update mint on dolt and embeddeddolt, and
  MoveIssuePersistenceInTx's own on uow.

"Wisp" is in the names because this contract already says "promoted" in
R2.3's sense (ProceedsForPromotedRecord), which is a different operation.
The fixture gains CreateWisp, PromoteWisp and MovePersistent closures, and
each leg's FixtureKitIsWired checks them.

Red at this commit on the embedded leg: after the arrival there are 0 rows
and participation_generation is NULL, and after the update there are still
0 rows. A flag-on durable create goes 1 -> 2 in the same store.

* fix(issueops): mint a wisp's first issues-plane version create-shaped (be-31mnz)

Review feedback on #6943, blocker 1. A promotion, or a persistence move out
of the wisps table, inserts a new issues row. A wisp never declares
participation (FR-8), so that row's participation_generation is NULL. Both
sites minted through the update-shaped RecordVersionInTx, and the section
16.2b fence read the NULL as legacy and skipped the mint. Nothing stamps the
column later, so every later update skipped too, and a record created with
versioned history on was never versioned.

These sites now use RecordVersionForCreateInTx, which stamps the column and
mints version 1, as a create on the issues plane does:

- PromoteFromEphemeralInTx (promote.go).
- MoveIssuePersistenceInTx's move out of the wisps table.
- ExecuteUpdate's one end-of-update mint (execution.go), when its
  persistence patch did that move. This is the site bd update --persistent
  reaches on the dolt and embeddeddolt legs, and the review did not list
  it. PersistenceMoveResult.EnteredIssuesPlane tells ExecuteUpdate which
  entry point to use.

One site the review named stays update-shaped on purpose:
MoveIssuePersistenceInTx's same-plane repair, which clears a stray wisp
flag on a row already in issues. That row keeps its own
participation_generation. A row created with the flag on still mints. A
legacy row stays legacy, because a repair is an ordinary write and R2.3
says an ordinary write does not promote it. A create-shaped mint there
would stamp the legacy row and start versioning it.

* docs(schema): 0070 must precede turning versioned history on (be-31mnz)

Review note on #6943 (schema skew). The write fence reads
participation_generation on every flag-on mint of an issues-plane row. On a
store that has not applied 0070 the read fails, and the mutation fails with
it instead of skipping. The migration header now says so, and says that the
flag-off path (the default) returns before the read, so a store below 0070
writes exactly as before.

Comment only. 0070 is not on main, so check-migration-hygiene's frozen-file
check does not apply to it, and no test pins its bytes.

* test(dolt): a persistence repair keeps the row's own participation (be-31mnz)

Pins why MoveIssuePersistenceInTx's same-plane repair stays update-shaped
while promotion and a move out of the wisps table became create-shaped (the
previous commit). The repair clears a stray wisp flag on a row that already
lives in issues, so the row keeps its own participation_generation.

TestPersistenceRepairKeepsTheRowsOwnParticipation runs the repair with
versioned history on for a legacy row (created with the flag off) and a
participating row (created with it on), through both repair entry points:
MoveIssuePersistenceInTx and a guarded update with a persistence patch. They
mint at different sites. The legacy row must stay NULL and mint nothing,
since R2.3 says an ordinary write does not promote it. The participating row
must mint one version. participation_generation must not change in either
case.

It fails if the repair mint is create-shaped, which would stamp and start
versioning the legacy row.

* test(dolt): a delete's rewrite of a legacy neighbor mints nothing (be-31mnz)

Folded in from bee's R1 on #6961, note 1. Once
TestDualWriteDeleteNeighborRewriteRidesTheDeletesDoltCommit started creating
its neighbor with history on, nothing covered a delete whose neighbor was
created with history off. Under the section 16.2b fence, the expected result
for that case is different: the rewrite still runs, but it mints nothing.

TestDualWriteDeleteSkipsALegacyNeighborsRewrite creates the fixtures with
history off, turns history on, and force-deletes the cited target. It then
checks four things: the rewrite ran (ReferencesUpdated=1), the neighbor has
no issue_versions rows, its participation_generation is still NULL, and
dolt_status is clean for issue_versions, store_epoch and issues.

* test(embeddeddolt): batch-created rows are stamped with the participation generation

A batch create writes its rows first and mints each created row's first
version last, after the creation-time edges land. The mint has to stay
create-shaped for rows the batch inserted (stamping participation_generation
from the store epoch) and update-shaped for rows it only upserted over
(skipped while the row is a legacy row), so the per-row isNew has to survive
the deferral to the batch's final mint pass.

Pin that on the embedded engine:

- brand-new explicit-id rows are stamped with the store epoch and get one
  version row each, and match the same input run one row at a time with the
  batch-create fast paths off (5 rows, and 250 rows across three INSERT
  statements);
- a legacy row the batch upserts over keeps a NULL participation_generation
  and gets no version row, while the new rows beside it are stamped;
- with versioned history off, no row is stamped and no version row is written.

* ci(bazel): enroll the participation-generation tests in the embedded shards

The embedded-Dolt shard manifest has to name every top-level Test* in
internal/storage/embeddeddolt, or the exact-once coverage check fails.
The two participation-generation fence tests were written before that
check landed on main, and the batch-create stamping test is new, so none
of the three is listed yet. Add them to the 15-shard block as the
generator's incremental output: three inserted lines, no existing
assignment moves.

Also list the new batch-create test file in the embeddeddolt_test srcs,
in sorted position, so the Bazel target compiles it alongside the Go
build. Its imports are already among that target's deps.

Rebase note (maintainer): on current main the embedded storage manifest
uses a 40-shard block; the generator's incremental output placed these
three tests in shards 18, 19 and 39 and re-sorted one existing shard-12
line.

* fix(issueops): keep a created row's updated_at when its first version is minted

Minting a version is bookkeeping. It must not change a user-visible column
of the row it versions.

The create-shaped mint stamps participation_generation with an UPDATE of the
issues row. issues.updated_at is ON UPDATE CURRENT_TIMESTAMP, so an UPDATE
that changes any other column and does not name updated_at rewrites it with
the clock. Before the stamp, a row's first mint left current_revision at its
column default of 1, so the UPDATE changed nothing and the clause never
fired. The stamp moves participation_generation from NULL to the store
epoch, so the clause fires on every row whose first version is minted and
replaces the updated_at an import supplies.

Set updated_at to itself in the stamp, as the blocked-state recompute in
issueops/blocked_state.go already does, so the timestamp the row was created
with survives. Add a regression that batch-creates rows with a supplied
updated_at and requires both the stamp and the unchanged timestamp.

* test(createbatchequiv): re-record the digests the participation-generation fence moves

The fence does not re-mint rows that predate the stamp: a row whose
participation_generation is still NULL gets no new version when a batch
touches it. Main mints one, so six recorded entries move.

The issue_versions entry of five scenarios loses the versions main mints
for rows that predate the stamp: three rows in small, all eleven in
depadd, all fifteen in waitsfor, four in import458 and two in
import458-reject-stale. In depadd, eq-db1 and eq-dl are the only rows
main mints more than once, and each of those mints moves their updated_at
off the fixture date. The fence skips them, so the two rows keep the
fixture date and join the issues_updated_at entry.

No other table, list or counter digest changes, and the fast and per-row
bodies already agree in every scenario. The digests were recorded with
the embedded backend. The doc comment on GoldenDirEnv now says which
entries were re-recorded.

* test(storage): waive the participation-generation contracts on the http leg

main's #7247 (6d21d337ad, "a served http conformance leg") registered a
fourth leg, http, after this PR's original base. The PR's seven
RunParticipationGeneration* entrypoints are neither wired nor waived there,
so TestEveryLegWiresEveryRoleContract/http fails on the rebased branch.

ParticipationGenerationFixture toggles the store's own versioned-history
write flag and reads the raw participation_generation column back: store
write-fence bookkeeping (design §16.2b), not a publicops role the HTTP
client serves. Waive the seven cases on http with a named reason, the same
waiver the donnabox fork carries (09e7ce05af), and keep the gap visible
until a supported HTTP surface is designed and tested.

go test ./internal/storage/ -run TestEveryLegWiresEveryRoleContract now
passes on dolt, embeddeddolt, http and uow.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(issueops): decide the fence's plane by the table that holds the row

recordVersionInTx chose the plane from the row's flags (IsWisp: Ephemeral
|| NoHistory) and then read participation_generation from the issues table
only. A wisps-TABLE row can carry neither flag, so it passed the IsWisp
return and the issues read failed with sql.ErrNoRows, aborting the whole
mutation whenever versioned history is on. Two producers:

  - bd mol squash clears an ephemeral root's flag in place
    (UpdateIssue {"wisp": false}, after the root's close, in the squash's
    one transaction); update.go and the uow repository's Update both mint
    after it unconditionally.
  - import's "wisp_plane" marker (WispPlaneOverride = &true, flags false)
    routes the row to wisps, and the batch create mints it create-shaped.

On origin/main the same paths do not fail but mint a stray issue_versions
row for a wisps-table row, an FR-8 leak (wisps are never versioned).

Fix: no issues row means nothing to version. ErrNoRows on the
participation_generation read now returns nil (no version, no error) for
update- and create-shaped calls alike. That read is the right signal and
IsActiveWispInTx is not: GetIssueInTx has already resolved the row, so
ErrNoRows on the issues read can only mean "not in issues", which is
exactly the question the fence has to answer before it stamps or advances
an issues row. It costs no extra query. IsActiveWispInTx asks the inverse
question ("is it in wisps?") with one more query per mint, and it folds
every error, including a transient one, into "not a wisp".

Tests come first, as three new conformance contracts with three new
ParticipationGenerationFixture hooks (ClearWispFlag, SquashWispRoot,
CreateUnflaggedWisp). They are wired on the dolt, embeddeddolt and uow legs
as subtests of each leg's TestParticipationGenerationFence (no new
top-level test, so the shard manifests do not change) and waived on http
with participationGenerationRawStoreWaiverReason:

  RunParticipationGenerationWispFlagClearMintsNothing      (create wisp,
      UpdateIssue {"wisp": false}: no error, 0 versions)
  RunParticipationGenerationWispRootSquashMintsNothing     (close +
      UpdateIssue {"wisp": false} in one transaction: no error, 0 versions)
  RunParticipationGenerationUnflaggedWispCreateMintsNothing (CreateIssues
      with WispPlaneOverride=&true, flags false: no error, 0 versions)

Red before the fix, green after, run both ways:
  embeddeddolt (BEADS_TEST_EMBEDDED_DOLT=1): all three FAIL with
    "versioned history: read participation_generation for pg-...: sql: no
    rows in result set"; all three PASS after.
  uow: all three FAIL with the same error; all three PASS after.
  dolt (BEADS_TEST_DOLT_SERVER=local): WispRootSquash and UnflaggedWispCreate
    FAIL with the same error; both PASS after. WispFlagClear passes both
    ways on this leg. The store-level wisp update (updateWisp) runs in a
    transaction versioned history never scopes, so it never reaches the
    mint. For the same reason the leg's SquashWispRoot hook turns the events
    journal on for its one transaction: that pins the wisp writes to the
    scoped regular transaction, as in a journal-enabled workspace, so that
    case does reach the seam.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(issueops): a create stamps participation even when the row is flagged no-history

A create-shaped mint (RecordVersionForCreateInTx) of a brand-new
ISSUES-TABLE row that carries NoHistory or Ephemeral returned at the IsWisp
check before the isCreate stamp, so participation_generation stayed NULL
although the row was created with versioned history on.

Import produces exactly that row: bd-r9uce keeps a promoted no-history
wisp's durable row on the issues plane with its stray no_history=true
(import_shared.go applyImportWispPlane: WispPlaneOverride = &false). When
bd update --persistent later repairs the flag, it is a same-plane normalize
whose mint is update-shaped by design (persistence.go: "A row created with
the flag on proceeds; a legacy row stays legacy"). The NULL column made the
fence read the row as legacy, so the repair and every later update were
fenced and the row was never versioned. origin/main versions it after the
repair (0, then 1, then 2 rows).

Fix: on a create-shaped call, a flagged row that the issues table holds
gets participation_generation stamped from store_epoch.epoch, the same
source the minting stamp uses, read in the same transaction. No version is
minted and updated_at is kept (SET ..., updated_at = updated_at), then the
call returns. Update-shaped calls on flagged rows still return before any
read. The table check from the previous commit now runs ahead of the IsWisp
branch for create-shaped calls, so a flagged wisps-table row (the common
wisp create) still mints and stamps nothing. That costs a create-shaped
call on a flagged wisp one primary-key miss on issues, and only while
versioned history is on. The store_epoch read/seed moves into
readStoreEpochInTx so both stamps share it.

Tests first:
  - New conformance contract
    RunParticipationGenerationNoHistoryIssueCreateDeclaresParticipation and
    hook CreateNoHistoryIssue. Wired on dolt, embeddeddolt and uow as a
    TestParticipationGenerationFence subtest and waived on http. With
    history on: create {NoHistory: true, WispPlaneOverride: &false} gives
    participation_generation non-NULL and 0 versions. The persistent repair
    (MovePersistent) then gives 1 version, and an update-shaped edit
    (MutateExisting, a title edit) gives 2.
  - New subtest
    TestCreateBatchParticipationGeneration/NoHistoryRowIsStampedUnversionedAndKeepsTheCallersUpdatedAt
    (embeddeddolt): a batch of such rows with a supplied updated_at comes
    out stamped, unversioned, and with updated_at unchanged.

Red before the fix, green after, run both ways:
  dolt (BEADS_TEST_DOLT_SERVER=local), embeddeddolt
  (BEADS_TEST_EMBEDDED_DOLT=1), uow: the contract FAILS on all three legs
    ("participation_generation for pg-no-history-create is NULL ...", then
    "= 0 after the persistent repair, want 1", then "went from 0 to 0 ...
    want exactly +1"). It PASSES on all three after.
  embeddeddolt subtest: FAILS before the fix ("store_epoch has no row after
    the batch, so nothing stamped the 5 rows"). With the fix minus the
    updated_at = updated_at clause it FAILS on every row's updated_at. It
    PASSES with the full fix.
No new top-level Test*, so the shard manifests do not change. The
createbatchequiv goldens are unchanged: the dolt and embeddeddolt
equivalence tests pass.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs: fix comments the rebase left stale

Comment-only.

- createbatchequiv.GoldenDirEnv said "One deliberate behavior change since
  ... nothing else moved" and then listed a second re-record, the
  participation-generation fence's. It now says there are two deliberate
  changes, puts each in its own paragraph, and scopes "nothing else moved"
  to apply.json, the only golden the first change touched.
- issueops CreateIssueResult.isNew and deferredVersion still described one
  write path. After main's #7205, a row written by deferredCreates'
  multi-row INSERT reaches finishCreateIssueInTx(..., true) directly
  (create_batch_cache.go flush) and never passes through InsertIssueIfNew
  or CreateIssueInTxWithResult. isNew is InsertIssueIfNew's result on the
  per-row path and always true for a multi-row-INSERT row. deferredVersion
  is filled from both paths.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(issueops): pin the create/update shape split in the version guard

TestEveryVersionedEntryPointMints counts RecordVersionInTx and
RecordVersionForCreateInTx as one seam. A create-shaped site that fell back
to the update-shaped entry therefore stayed green, though the fence then
reads the new row's NULL participation_generation as legacy and the record
is never versioned. The reverse case also stayed green: an update path that
reached the create-shaped entry would stamp an existing legacy row and
promote it, which R2.3 forbids.

Add the split to the structural guard. It is two small tests over the same
journalscan fixpoint and mintVersion edge discipline, with no AST changes:

- TestCreateShapedEntryPointsMintCreateShaped: the create-shaped mint sites
  (finishCreateIssueInTx, CreateIssuesInTxWithContext,
  PromoteFromEphemeralInTx, moveIssuePersistenceInTx, executeUpdate) must
  each call RecordVersionForCreateInTx themselves. A delegate is not enough
  here, because executeUpdate runs its move with mintVersion=false and a
  batch switches finishCreateIssueInTx's mint off at run time. Every
  create-shaped entry point, the delegates and #7205's
  deferredCreates.flush included, must reach it.
- TestUpdateShapedEntryPointsNeverMintCreateShaped: every other
  versionedEntryPoint must not reach RecordVersionForCreateInTx. The
  exception is ApplyBatchInTx, which runs create and update items together
  and is listed as mixed with a reason.

Mutation-checked, each probe reverted afterwards. executeUpdate's
EnteredIssuesPlane mint, PromoteFromEphemeralInTx's mint, or the batch's
deferred create-shaped mint switched to RecordVersionInTx: each fails the
create half. update.go's end-of-update mint switched to
RecordVersionForCreateInTx: fails the update half for UpdateIssueInTx and
every entry point that writes through it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(issueops): hold the dual-shape mint sites to both halves of the split

f006c871c5 listed executeUpdate, moveIssuePersistenceInTx,
finishCreateIssueInTx and CreateIssuesInTxWithContext (and the
ExecuteUpdate/MoveIssuePersistenceInTx/create wrappers that delegate to
them) as create-shaped, so TestUpdateShapedEntryPointsNeverMintCreateShaped
skipped them. Each one also mints update-shaped, on its existing-row or
same-plane branch, which is the common path: a guarded update of an
existing row, the bd update --persistent repair of an issues-plane row's
flags, a create or batch create that resolved to a row already there.
Switching that branch to RecordVersionForCreateInTx stamped a legacy row
out of legacy (R2.3), and every guard stayed green.

Split the lists by what each function actually mints:

- versionCreateShapedMintSites keeps only the pure create-shaped site,
  PromoteFromEphemeralInTx. It must call RecordVersionForCreateInTx and
  must not call RecordVersionInTx.
- versionDualShapeMintSites names the four, each with its two branches.
  TestDualShapeMintSitesCallBothEntries requires each to call BOTH entries
  directly. A delegate does not count, for the same mintVersion=false and
  DeferVersionMint reasons as before.
- versionCreateShapedEntryPoints keeps PromoteFromEphemeralInTx and
  deferredCreates.flush, which passes isNew=true for every row.
- versionDualShapeEntryPoints replaces versionMixedShapeEntryPoints. It
  holds ApplyBatchInTx and the create, persistence-move and guarded-update
  entries that delegate to a dual-shape site, each with a reason. Each must
  reach both entries transitively.

The update half skips the create-shaped and dual-shape entry points, as
before. The update-shaped branch inside a dual-shape site is now the new
test's to pin.

Mutation-checked in a throwaway worktree. Switching the update-shaped mint
to RecordVersionForCreateInTx at execution.go:301, persistence.go:97,
create.go:260 or create.go:499 now fails
TestDualShapeMintSitesCallBothEntries for that site. Before this commit,
the whole issueops package stayed green under each of these switches.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(httpclient): run the participation-generation fence over the served wire

edd3b72a1a waived all eleven ParticipationGeneration contracts on the http
leg, saying the client had "no write flag to toggle and no raw column to
read". That reason was wrong. served_dualwrite_history_test.go already
flips the reference store's VersionedHistoryConfigurer and reads its raw
columns, with the client driving the mutation. The waiver also hid the
one harness that runs the fence behind the update a connected workspace
actually sends. Every store leg's MutateExisting is store.UpdateIssue,
but the served Lifecycle.Update reaches the guarded update,
ExecuteUpdate.

Add served_participation_generation_test.go on the same pattern:

- Bound to the client: Mutate is Lifecycle.Create, MutateExisting is
  Lifecycle.Update, MovePersistent is the persistence-mode
  Lifecycle.Update that bd update --persistent sends, and PromoteWisp is
  issueops.Promote over the client's Reader/Lifecycle/Commenter, the
  entry bd promote dials over http.
- Bound to the reference store, as before: SetFlag, the CreateWisp seed,
  and the raw reads.

TestServedParticipationGenerationFence runs seven cases:
CreateWithFlagOnStampsAValue, CreateWithFlagOffLeavesLegacyNull,
SkipsUpdateOnLegacyRecord, ProceedsForPromotedRecord,
FenceIgnoresSchemaSkewHatch, WispPromotionBeginsHistory and
WispPersistenceMoveBeginsHistory. All seven pass, and no case turned up a
server-side fence bug.

Four cases stay waived, now with a reason that names the actual wire gap
(participationGenerationWireGapWaiverReason):

- WispFlagClearMintsNothing: the in-place {"wisp": false} is an untyped
  UpdateIssue, and IssuePatch.Persistence moves the row instead.
- WispRootSquashMintsNothing: it needs RunInTransaction. That and
  UpdateIssue are both on the client's unsupported allowlist (D8).
- UnflaggedWispCreateMintsNothing and
  NoHistoryIssueCreateDeclaresParticipation: both need WispPlaneOverride,
  which every create shape on the wire drops
  (roleIgnoredCreateIssueMembers).

The new file is listed in httpclient_test's srcs. The served lane deals
unpinned tests round-robin, so no shard manifest names it.

Mutation-checked in a throwaway worktree. With execution.go:301 (the
guarded update's update-shaped mint) switched to
RecordVersionForCreateInTx, SkipsUpdateOnLegacyRecord and
FenceIgnoresSchemaSkewHatch fail here ("version row count for
hpg-legacy-skip went from 0 to 1"). The embeddeddolt and uow
Participation|DualWrite|Version suites stay green under the same probe.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(conformance): an update never stamps a legacy no-history row

7c00d65fa6 made the seam write participation_generation on a flagged
(NoHistory or Ephemeral) issues-table row when the call is create-shaped.
Only the early `if IsWisp(issue) && !isCreate { return nil }` keeps an
update-shaped call out of that branch, and nothing pinned it. The new
contract and its subtest covered only the positive, create-shaped side.
With the early return dropped, an ordinary update stamped a legacy
no-history row out of legacy (R2.3), and every suite stayed green.

Add RunParticipationGenerationLegacyNoHistoryIssueStaysLegacy beside
NoHistoryIssueCreateDeclaresParticipation as its negative twin:

1. Create the no-history issues-table row with the flag OFF.
2. Turn the flag on and run MutateExisting. participation_generation must
   stay NULL, with 0 versions and current_revision unchanged.
3. Run MovePersistent, the bd update --persistent repair that clears the
   flag in place. The repair is update-shaped too, so the same three
   things must still hold.

Wired on all four legs: dolt, embeddeddolt, uow and http. On http the
case exercises the client's Lifecycle.Update and persistence update.
Their precondition, the flag-off no-history create, is seeded through
the reference store, because no client create can land that row in the
issues table. That gap is also why the case whose SUBJECT is that create
stays waived on http.

Mutation-checked in a throwaway worktree, with the early return made
`if false && IsWisp(issue) && !isCreate`. The new case fails on all four
legs and is the only case that fails:
"participation_generation for pg-no-history-legacy = 1 after an
update-shaped mutation with the flag on, want NULL" (dolt server leg,
embeddeddolt, uow and http). At tip it passes on all four.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(issueops): say which table and which mint the fence comments mean

Comment and doc corrections. No code changes.

- RecordVersionForCreateInTx's doc comment covered a flagged issues-table
  row but not a wisps-table row. A row the wisps table holds mints and
  stamps nothing, whatever its flags say: there is no issues row to stamp
  (FR-8). That holds for an ordinary wisp create and for import's
  unflagged "wisp_plane" row.
- The no-history stamp branch said the bd update --persistent repair mints
  update-shaped "(MoveIssuePersistenceInTx)". That is true only on the
  unit-of-work path. On dolt and embeddeddolt the repair goes through the
  guarded update: executeUpdate runs moveIssuePersistenceInTx with
  mintVersion=false and mints once at its own end. The fixture's
  MovePersistent doc already says this.
- VERSIONED-BEADS-WRITE-PATHS.md row 13 still credited the whole wisp
  exclusion to `RecordVersionInTx returns on IsWisp` and called every case
  a NO-OP. After ec52d29030, the table holding the row decides its plane:
  only an update-shaped call on a flagged wisp returns on IsWisp. Every
  other wisps-table row, including an unflagged one, is excluded by the
  issues-table participation_generation read, which finds no row. After
  7c00d65fa6, a create-shaped call on a flagged issues-table row is
  stamped but not versioned, so the row says that too.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(conformance): the wisps-table cases check the row is still a wisp

runWispTableRowMintsNothing asserted 0 versions but never checked its own
precondition, that the wisps table still holds the row. Suppose a step
moved the row onto the issues plane through an update-shaped mint. That
mint would hit the new row's NULL participation_generation and be fenced,
so the count stayed 0 and the case passed without saying anything about
a wisps-table row.

- Add an InWispsTable hook to ParticipationGenerationFixture and bind it
  on dolt, embeddeddolt and uow as a raw wisps-table count. The
  wisps-table body now Fatals if the row is not in the wisps table after
  its steps. Each leg's KitIsWired test checks the hook. On http it
  stays nil with the other wisps-table hooks, whose cases are waived
  there.
- The dolt ClearWispFlag hook now bites. A bare store.UpdateIssue on a
  wisp goes through updateWisp, whose transaction versioned history never
  scopes. So WispFlagClearMintsNothing passed on dolt with or without the
  ec52d29030 fix, as that commit's message admits. The hook now runs the
  lone flag clear in a RunInTransaction with the events journal on: the
  journal-enabled shape the SquashWispRoot hook already uses.
- Both hooks go through a new withEventsJournal helper. It restores the
  store's previous journal setting rather than unconditionally setting it
  to false afterwards, which assumed the store started with the journal
  off.

Mutation-checked in throwaway worktrees:
- With version_history.go at ec52d29030^, dolt's WispFlagClearMintsNothing
  now fails ("read participation_generation for pg-flag-clear: sql: no
  rows in result set"). It used to pass there.
- Embedded ClearWispFlag rerouted as a flag-off persistence move followed
  by a flag-on title update: the case fails on the new precondition ("is
  not in the wisps table after flag-clear"). With the precondition
  disabled, the same probe passes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(storage): review fixups for the participation_generation fence

The review of d17b716115 approved the PR with no required changes and
raised four minors and three nits. Each one below says what changed and
why, or why it did not.

Minor 1, the upsert create's new-or-existing choice was untested. The
unit-of-work create that is not CreateOnly (bd batch, bd todo, tracker
sync and mol port) inserts through an upsert, and db.Insert's existed
probe picks the mint's shape; forcing it either way shipped green. The
new uow TestParticipationGenerationUpsertCreate pins all three outcomes:
a new row is stamped and begins its history, a legacy row the upsert
resolves to stays legacy with no version, and a participating row mints
exactly one more. No served-route case is added because every served
create is CreateOnly (uow createParams), so the http wire cannot reach
this branch. The cmd/bd proxied-server batch and todo creates call this
same use-case method.

Minor 2, an update-shaped mint still lets issues.updated_at move
through ON UPDATE CURRENT_TIMESTAMP. Not changed here. The maintainer
listed it on the PR as follow-up (2), and the approving review of
d17b716115 accepted carrying it as a follow-up. It does not change
the fence's contract as pinned.

Minor 3, the depadd and waitsfor goldens had been re-recorded to zero
issue_versions rows. Their seeds run with history off, so every seeded
row was legacy and the harness stopped checking the dependency-add,
close and reopen mints. Both scenarios now stamp their seeded
issues-table rows after the seed (stampParticipation; wisps stay
unstamped). Their goldens are back to main's pre-fence files byte for
byte: depadd mints 11 version rows and waitsfor 15. The fenced legacy
outcome stays pinned by small, import458 and import458-reject-stale. A
run scenario that mints no version row now fails rather than recording
an empty digest.

Minor 4, PromoteFromEphemeralInTx always minted create-shaped. When the
issues plane already held the id (the dual presence GH#4455 records),
its upsert resolved to that row and the create-shaped mint stamped a
legacy record (R2.3). It now keeps InsertIssueIfNew's isNew and mints
update-shaped for an existing row, as finishCreateIssueInTx does. The
version guard lists it as a dual-shape mint site and entry point, and
PromoteOverDualPresenceKeepsLegacy pins the behavior at run time.

Nit 1: with versioned history off, db.Insert skips the existed probe,
since both mint entries return before reading anything. A create costs
the round trips it did before the fence.

Nit 2: the MINT COST comment now counts the fence read (about 6 to 7
round trips) and no longer says the snapshot reads current_revision;
the fence read can select it for #6379's ordinal seed. Moving that read
now would only add a column nothing consumes yet.

Nit 3: the http leg's participation-generation wire-gap waiver opens as
PENDING and names the wire mutation that would retire each case.

Validation, in a scrubbed env with -tags=gms_pure_go on embedded and
server Dolt (all pass, none skipped):
- uow: TestParticipationGenerationFence, its FixtureKitIsWired check
  and TestParticipationGenerationUpsertCreate with its 4 subtests.
- embeddeddolt: the create-batch equivalence parts (small/depadd,
  apply/waitsfor), the parts-coverage guard, the large scenarios, and
  the fence and kit.
- dolt: TestCreateBatchFastPathsMatchPerRow_Dolt, the fence,
  FenceIgnoresSchemaSkewHatch and the kit.
- httpclient: TestServedParticipationGenerationFence.
- TestEveryLegWiresEveryRoleContract, the issueops structural guards,
  and the issueops, storage and domain/db packages.

Eleven mutants, graded in 13 runs, each fail the test meant to catch
them:
- upsert always create-shaped or always update-shaped;
- the probe guard inverted;
- promote always create-shaped or always update-shaped;
- the seed left unstamped;
- the dependency-add, close or reopen mint dropped;
- two on-disk single-entry promotes.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(storage): a wisp upsert must not stamp a legacy issues twin

domain/db's Insert chose the mint shape of its upsert (the create that
is not CreateOnly) from an existence probe of the target table. For a
wisps-table insert that probe asks the wrong plane: the seam snapshots
the issues table first (GetIssueInTx), so when the issues plane already
held the id as a legacy row, the wisp create took the create-shaped
mint and stamped and versioned that untouched twin. An ordinary wisp
write promoted a legacy record, which R2.3 forbids. bd mol port and the
proxied mol and wisp writers call CreateWisp this way. It is latent
until versioned history is enabled (#6661).

A wisps-table insert never creates an issues row, so it now mints
update-shaped, without the probe. The fence leaves a legacy twin alone,
a wisp-only id still mints nothing through either entry (FR-8), and a
participating twin mints the one version main already minted for it.
Insert's comment now records that last case: the dual presence
predates the fence, and this upsert does not refuse it the way
issueops' create path does.

TestParticipationGenerationUpsertCreate gains
WispOverLegacyIssuesRowKeepsItLegacy, which fails against the previous
dispatch (twin stamped, one version row). Also from review: the version
shape guard names the dual-shape site its parse cannot see, and the
row-lock exemption comment counts all three of the seam's UPDATE issues
statements.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
2026-10-18 13:10:57 +00:00
gascity-eddie[bot]
4a67d0d028
fix(bootstrap): cut the host part before stripping userinfo (mc-gcmer) (#7616)
* fix(bootstrap): cut the host part before stripping userinfo (mc-gcmer)

urlHostname stripped userinfo through the first "@" anywhere in the URL,
before cutting out the host part, so an "@" in a path, query or fragment
picked the host: https://my-dolt.example.com/x@github.com/path read as
github.com. isGitCodeRepoURL then called it a forge, and doltRemoteURL
rewrote what is really a Dolt remotesapi URL to git+https:// (the GH#3339
class). The SCP branch made the same split, so both
my-dolt.example.com:org/x@github.com:db and the local path
./backups/me@github.com:db read as github.com too.

Cut the host part first, then strip userinfo through its last "@":

- scheme URLs: the authority, ending at the first "/", "?" or "#". That is
  the host net/url dials, and Dolt's earl.Parse hands scheme URLs to
  net/url. Taking the last "@" matches net/url too, so
  https://a@b@github.com/org/db is now a forge, as Dolt would dial it,
  instead of going raw to the remotesapi client (the #4421 class).
- SCP: everything before the first ":", unless a "/" comes first (a local
  path) - the split doltremote.FromGitURL makes.

TestIsGitCodeRepoURL gains the path/query/fragment-@, SCP path-@,
local-path-@ and last-@ cases, 7 of them red before this change, plus
userinfo controls in both URL forms that stay green.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(bootstrap): scrub credentials from the Bootstrap failed message (mc-gcmer)

An unencoded "#" or "?" in a sync.remote password ends the URL's
authority early, so urlHostname no longer reads the remote as a forge and
bootstrap clones it as configured. The clone error then carries the URL,
password included, twice: sanitizeURL passes through a URL net/url cannot
parse, and Dolt's "invalid remote url:" repeats it. Scrub the error with
scrubURLCredentials where "Bootstrap failed:" prints it.
TestEmbeddedBootstrapCloneFailureScrubsCredentials pins this; it fails
against the pre-fix binary for both "pa#ss" and "pa?ss", and the new test
is registered in the embedded shard manifest.

Also add a forgeSyncRemoteForms row for multi-@ userinfo without a .git
suffix, so the routing pin covers a URL only its host can make a forge.
The row fails with the base urlHostname.

Review: PR #7616 synthesis F1 (minor) and F5 (nit).

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 18:07:50 +00:00
Julian Knutsen
bdd16d6383
fix(sqlbuild): bind time bounds as their UTC instant (#7655)
* fix(sqlbuild): bind time bounds as their UTC instant

BuildIssueFilterClauses bound every time bound (created/updated/closed/
started/defer/due, after and before) as tc.v.Format(time.RFC3339), which
keeps the value's offset. The columns hold UTC wall clock, and an engine
whose timestamp column carries no zone reads a literal's wall clock and
drops the offset, so a bound spelled +02:00 would compare two hours late.
Bind tc.v.UTC().Format(time.RFC3339): the same instant, spelled in UTC, at
whole seconds. Dolt already converts an offset literal to UTC and bd's
client resolves bounds to UTC, so no answer changes on any backend here;
this keeps the shared builder correct for every engine.

TestTimeBoundsBindTheUTCInstant pins all twelve bounds to the UTC spelling
of a +02:00 instant with a sub-second remainder.

Also correct the AfterCreatedAt comment, which justified the time.Time
cursor binding by a SQLite backend that no longer exists.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(sqlbuild): bind the keyset cursor as its UTC instant too

Review fixups on #7655.

BuildIssueFilterClauses bound IssueFilter.AfterCreatedAt as the caller's
time.Time, unconverted. The embedded Dolt driver sends a time.Time as its
wall clock with no zone (vitess BuildBindVariable formats it as
"2006-01-02 15:04:05.000000"), and the columns hold UTC wall clock, so a
cursor in another zone paged from the wrong position there: the keyset
walk with +02:00 cursors re-delivers rows on embedded Dolt.
go-sql-driver/mysql converts to the connection's zone (UTC) first, so
server Dolt was unaffected. Bind filter.AfterCreatedAt.UTC(), still a
time.Time, and reword the comment, which claimed the driver carries the
instant. TestKeysetCursorBindsTheUTCInstant pins the cursor args of both
orders.

The httpapi query.timestamp comment and the
TestListFilterTimeBoundsAreNormalizedToUTC doc justified the route's UTC
normalization by the old sink behavior (formatting a bound in its own
zone). They now say sqlbuild binds every range bound in UTC and the
route's normalization is its own guard in front of that.

The CHANGELOG bullet gets a bold lead, covers the cursor, and drops the
blank line that made the Fixed list loose.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
2026-10-17 16:19:50 +00:00
Steve Yegge
46aa59cc65
test(cmd/bd): stop tests from mutating the host checkout's .git; guard it in TestMain (wy-qlvlmf) (#7650)
* wy-qlvlmf: test(cmd/bd): stop tests from mutating the host checkout's .git; guard it in TestMain

On 2026-10-16 a 'go test ./cmd/bd' run from a linked worktree rewrote the
host rig's shared .git/config (core.bare=true, extensions.worktreeConfig,
remote.origin.url replaced by metadata_test's fixture URL, user identity,
core.hooksPath) and its hooks dir, leaving every worktree of that clone
answering 'fatal: this operation must be run in a work tree' (r880).

Root causes, all one class — fixture git commands routed at the repository
the test process itself lives in instead of a fixture the test owns:
- TestRunApplyAllOK ran runApply(false) (a LIVE apply: hook reinstall,
  hooksPath mkdir) with no fixture, against the package cwd's repo.
- runGitForBootstrapTest treated dir=="" as 'inherit package cwd'.
- doctor/fix setupGitRepoInDir swallowed git config failures non-fatally
  and ran with whatever git routing env (GIT_DIR, GIT_WORK_TREE) leaked in.

Fixes:
- TestRunApplyAllOK / TestRunApplyDryRun now chdir into an isolated
  git+.beads fixture (isolatedApplyFixture + runInDir).
- runGitForBootstrapTest: empty dir gets a neutral t.TempDir() cwd, never
  the package cwd; env scrubbed of git routing vars.
- initGitRepoAt / doctor setupGitRepoInDir / doctor-fix setupGitRepoInDir:
  refuse an empty dir, fail on ANY git error, scrub routing env.
- testMainInner scrubs git routing env process-wide at startup.
- TestMain's repo guard now also snapshots the checkout's own git state
  (common .git/config, config.worktree, common hooks dir) and reddens the
  run on any diff, naming the mutated file.

Guard vacuity check: a probe test writing one key into the checkout's
.git/config passes individually and reddens the suite via the guard.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* build(bazel): auto-sync BUILD files

Applied from the bazel-sync-patch artifact of https://github.com/gastownhall/beads/actions/runs/39013861275
(`make bazel-sync`: gazelle, tools/bazel/go_srcs.py, bazel mod tidy).
Only BUILD.bazel, MODULE.bazel and MODULE.bazel.lock are ever pushed; see
scripts/bazel-autofix-push.sh.

* test(cmd/bd): scrub doctor suites, keep git fences, key-level config guard (wy-qlvlmf)

Maintainer fixup on top of #7650 by cat, for the first review's three
majors, minor and nit, and three of the second review's minors.

- Doctor suites: the leaked-GIT_DIR vector was still open in
  cmd/bd/doctor and cmd/bd/doctor/fix. Their four TestMains now unset
  the repository-location env first (testutil.UnsetGitRepoLocationEnv),
  and the three initGitTemplate copies plus
  testutil.ForceRepoLocalHooksPath run git with a filtered env. With
  GIT_DIR/GIT_WORK_TREE leaked at a decoy repo, the PR head wrote
  core.hooksPath into the decoy and failed 120 doctor tests; with this
  commit all three packages pass and the decoy stays byte-identical.

- Narrower scrub: the process-wide scrub also removed
  GIT_CEILING_DIRECTORIES and the GIT_CONFIG_* fences that
  tools/bazel/test_env.sh and scripts/ci/lib/test-env.sh set on purpose.
  testutil.WithoutGitRepoLocationEnv removes only GIT_DIR, GIT_WORK_TREE,
  GIT_COMMON_DIR, GIT_INDEX_FILE, GIT_OBJECT_DIRECTORY,
  GIT_ALTERNATE_OBJECT_DIRECTORIES, GIT_NAMESPACE and the legacy
  GIT_CONFIG (which sends `git config` reads and writes to the file it
  names, even under -C). Keys match exactly, so GIT_CEILING_DIRECTORIES,
  GIT_CONFIG_GLOBAL and GIT_CONFIG_NOSYSTEM stay. Every helper that
  built its own scrubbed env now uses it.

- Guard false reds: the TestMain guard compared the shared common config
  byte for byte, so a sibling worktree's routine branch write failed a
  passing run. It now diffs `git config --list -z` key by key.
  branch.<name>.* keys, and a remote other than origin added or removed
  whole, print a NOTE and leave the exit code alone. Any other key
  (including origin appearing or disappearing, and a changed key of a
  remote that exists before and after), any config.worktree change, any
  hook file change or an unparseable config still fails the run.

- config.worktree: the guard also snapshots a main checkout's own
  config.worktree, which sits in the common dir. With
  extensions.worktreeConfig set its keys override the shared config, and
  before this an escaped `git config --worktree` write there went
  unreported.

- Report: changed keys are named with values redacted, deleted and new
  files are reported as such, pre-run copies of the changed files are
  saved (0700 dir, 0600 files) and their path printed, and a failure to
  locate the checkout's git dirs prints a warning instead of disarming
  the guard silently.

- doctor setupGitRepoInDir stat-checks its dir like the doctor/fix copy.

New tests: internal/testutil/git_env_test.go, and
cmd/bd/test_repo_git_guard_test.go (real-git fixtures for locating the
git dirs, classifying writes, config parsing and the report).

Validation: ./scripts/test.sh ./cmd/bd in a scratch clone with GIT_DIR
leaked at a decoy (ok; decoy and the clone's .git unchanged; guard
quiet); bazel test --config=ci for testutil, doctor, doctor/fix,
fmt_test and the new bd_test guard tests; make ci-pr-lint;
tools/bazel/go_srcs.py --check.

Second review: leaving GIT_CONFIG out of the scrub fails
TestWithoutGitRepoLocationEnvKeepsWrapperGitControls and
TestForceRepoLocalHooksPathIgnoresLeakedGitDir; the old main-checkout
config.worktree path fails TestLocateRepoGitDirs/main_checkout and the
new config.worktree case; treating origin like any other remote fails
the new origin added and removed cases. In a scratch main-checkout clone
with extensions.worktreeConfig set, a test that wrote
`git config --worktree user.email` into the checkout now fails the
suite (exit 1, an ERROR naming .git/config.worktree). bazel test
--config=ci passes for testutil, fmt_test and the bd_test guard tests.

Not in this commit: the same scrub in beads_test_env_enter
(scripts/ci/lib/test-env.sh) and tools/bazel/test_env.sh, which would
cover the packages outside cmd/bd that still write to the clone under a
hook-leaked GIT_DIR. That predates this PR and is left to a follow-up.

Co-authored-by: cat <cino@ghosttrack.com>
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: cat <cino@ghosttrack.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
2026-10-17 12:36:48 +00:00
Julian Knutsen
4450fe99bb
feat(http): bd blocked over bd serve (blocked.list), plus bd blocked --flags [--raw] (#7649)
* feat(http): bd blocked over bd serve (blocked.list) through issueops.BlockedLister

`bd blocked` refused against an HTTP workspace: it called the legacy
GetBlockedIssues, which the HTTP backend stubs as unsupported. It now runs
one role on every route, and bd serve publishes that role.

- Role: issueops.BlockedLister.ListBlocked(BlockedRequest{ParentID, Labels,
  LabelsAny, ExcludeLabels}) -> BlockedResult{Items}. One body,
  internal/storage/issueops.ExecuteListBlockedInTx over the unchanged
  GetBlockedIssuesInTx; labels normalized in the role (BlockedFilter);
  Items never nil and in a total order (priority, created_at desc, id).
- Legs: DoltStore (read tx), EmbeddedDoltStore (read conn), uow (read unit
  of work through the use case's GetBlockedIssues, so the
  external-dependency uow decorator applies). Census: storage.DoltStorage
  gains BlockedLister(); HookFiringStore passes it through (a read),
  telemetry wraps it, uow.notifyingProvider, externaldeps.uowProvider and
  httpapi.timedProvider build it.
- externaldeps.Store.BlockedLister is built over its own GetBlockedIssues,
  so local `bd blocked` output is unchanged. Over a remote store it takes
  the server's listing when the server advertises
  policy.external_dependencies, else decorates the server's listing here
  through EdgeReader and BatchGetter (decorateBlocked, factored out of
  GetBlockedIssues).
- Wire: GET /v0/beads/blocked (listBlockedIssues; parent, label,
  label_any, exclude_label) answering BlockedPage {items, has_more} with
  the new x-go-type-pinned BlockedIssue schema, behind the new
  blocked.list token. apigen and the wire-shape golden regenerated; the
  golden diff is additive only, so wire_revision stays 2.
  Config.BlockedLister is a required role, wired in bd serve.
- Client: httpclient.Store.BlockedLister dials through Store.dispatch, so
  an older server is refused BEFORE the dial with *wire.CapabilityError
  naming blocked.list. The legacy Store.GetBlockedIssues rides the role
  (page and row cap applied to its answer) and leaves the unsupported
  shell. Divergence ledger row F-blocked retired.
- CLI: `bd blocked` takes BlockedLister() from the store on the direct
  routes and from the provider's BlockedListerSource on the proxied route;
  runBlockedProxiedServer is deleted. --json output is the same rows in
  the same order, [] when empty.

Tests: backend/conformance RunBlockedLister (10 cases: direct blocker,
child attributed to its blocked parent, closed blocker, wisp plane, pinned
status, parent filter, label filters with normalization, order, empty
slice, request not mutated) on dolt, embedded, uow and the served HTTP
client; httpapi handler tests (mapping, unknown/repeated params,
projection, capability); httpclient stub tests (pre-dial refusal naming
the token, encoding, projection, legacy door paging); skew and vocabulary
counts; TestE2E_BlockedOverHTTP (served `bd blocked --json` equals the
local command's after mapping ids and timestamps, member order included,
external blocker named, older-server refusal with no dial); corpus
gc-blocked re-marked and gc-blocked-parent added, both pending until the
reference server advertises blocked.list.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(blocked): pin server-side external decoration, refuse has_more, serve the legacy door over http

Review fixes for the blocked.list slice.

- Server-side external decoration is now pinned on the compositions bd
  serve answers from. TestWrapUOWProviderBlockedListerNamesExternalBlockers
  lists through the wrapped unit-of-work provider's own BlockedLister
  accessor (the bd serve provider path) and requires an external-only row
  and a mixed row to carry their external: refs; building that lister over
  the inner provider fails it. TestServedBlockedListerCarriesExternalRefs-
  WhenTheServerEnforces serves the store-shaped composition
  (externaldeps.Store.BlockedLister, policy advertised) and requires the
  operation's own answer, through the undecorated client role, to carry the
  refs, and the client's decorated chain to return it unchanged; serving
  the inner store's lister fails it.
- The client refuses an answer reporting has_more with the new typed
  httpclient.TruncatedListingError instead of returning a short listing:
  the operation has no cursor, and a caller reads a missing row as
  unblocked. The legacy door inherits it.
- externaldeps.Store.GetBlockedIssues over an http store reads the extra
  sources through the served roles (EdgeReader, BatchGetter) instead of the
  raw GetIssuesByIDs / GetDependencyRecordsForIssues the http backend
  refuses, and the decoration skips the source read when there is nothing
  to load. The legacy door on the CLI chain (bd mol stale, the wisp
  commands) now answers over http in both policy modes;
  TestServedLegacyGetBlockedIssuesThroughTheDecorator pins it, paging
  included. bd ready --explain still refuses on its other raw reads; the
  CHANGELOG says so.
- Docs: the spec and the retired F-blocked ledger row state that the
  listing is unpaged, bounded by the client's 32 MiB response limit
  (refused, never read in part), and that has_more is refused.
- Contract: new cases for waits-for and conditional-blocks blockers, no
  type exclusions (gate, epic), and a stale flag with no nameable blocker
  (on the legs that can write the column: dolt, embedded; skipped
  elsewhere with the reason). Order seeds explicit created_at values with
  five rows tied on priority and created_at, two of them wisps, so only the
  id tiebreak orders them; dropping the tiebreak now fails every run.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat(blocked): bd blocked --flags, the blocked flag per id from stdin

`bd blocked --flags [--json]` reads ids from stdin, one per line (blank
lines and repeats ignored), and prints the blocked flag bd holds for each:
with --json, [{"id","is_blocked"}] in the order the ids were first given,
omitting an id that names no row on either plane, [] for no input. It is
the readiness column a consumer otherwise had to read with `bd sql`, so no
such consumer needs a local-only command.

It is the FLAG, not the listing: `bd blocked` narrows the stored flag to
rows it can name a blocker for, and --flags does not, so a row whose flag
is set with no nameable blocker reads true here and is absent from the
listing. Where the external-dependency policy applies, an unsatisfied
external: blocker sets the flag, as it keeps the row out of `bd ready`.

One library entry on every route: issueops.BlockedFlags over the route's
BlockingAnnotator (the store's accessor on dolt, embedded and HTTP, the
provider's on the proxied route). Over HTTP that is listBlockingAnnotations
with is_blocked behind dependencies.blocking.isBlocked; a server without
that token is refused before the dial, naming it. No wire change. The
listing's filter flags are refused with --flags rather than ignored.

Tests: TestE2E_BlockedFlagsOverHTTP (served JSON equals the local command's
after mapping ids to titles, unknown id omitted, repeat collapsed, [] on
empty stdin, filters refused; a stale-flagged row with no blocker reads
true and is absent from `bd blocked --json`, which fails if --flags is
derived from the listing; an older server's handshake refused naming the
token with no dial); TestProxiedServerBlocked/flags_reads_ids_from_stdin on
the proxied route; corpus gc-blocked-flags, pending until the reference
server advertises the token. CHANGELOG entry.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat(blocked): bd blocked --flags --raw, the stored is_blocked column

`bd blocked --flags --raw [--json]` answers the stored is_blocked column
for each id read from stdin, exactly what reading is_blocked from the issues
and wisps tables returns, without the external-dependency policy: a row
blocked only by an unsatisfied external: ref reads false (the policy-aware
--flags reads true), and a stale flag reads true either way. Same output
shape as --flags. This lets a consumer move off a `bd sql` read of the
column with no change in what it reads. The default --flags is unchanged.

The role is taken from beneath every decorator: storage.UnwrapStore on the
direct routes, uow.UnwrapProvider on the proxied route. Over HTTP the
innermost store is the http client, whose annotation read is the server's
answer: against a server that does not advertise
policy.external_dependencies that answer is the column, and --raw is
served. A server that advertises it decorates the flag it answers, the v0
wire has no member asking it for the column, and the decorated flag cannot
be turned back into the column client-side, so --raw against such a server
is refused before the annotation read, naming the token, rather than
answered with the decorated flag. --raw without --flags is refused.

Tests: TestE2E_BlockedFlagsOverHTTP/raw_is_the_stored_column (served --raw
equals local --raw; the externally-blocked-only row reads true with --flags
and false with --raw on both; locally blocked rows agree; a stale-flagged
row reads true in both modes; --raw without --flags exits 1; a server
advertising the policy refuses --raw with no annotation request);
TestProxiedServerBlocked/flags_raw_is_the_stored_column; corpus
gc-blocked-flags-raw (pending until the reference server advertises
dependencies.blocking.isBlocked). Routing --raw through the decorated
annotator fails the e2e. CHANGELOG entry.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(changelog): bd blocked --flags --raw is for the local and proxied routes

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(blocked): give the e2e gate-kid its own priority; document --flags answers closed ids

TestE2E_BlockedOverHTTP seeded gate-parent and gate-kid at one priority, so
when both landed in the same second their order fell to the generated ids,
which differ between the local and the served workspace: the comparison
failed intermittently. gate-kid now has its own priority. Ten runs on the
embedded lane pass.

bd blocked --flags answers a closed id too, with its stored flag; a SQL read
of the column filtered on status <> 'closed' leaves it out. Said in the
command's doc and the CHANGELOG.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(blocked): apply label filters to external-only blocked rows

The external-dependency policy appends a row blocked only by an
unsatisfied external: ref after the label query has run, so --label,
--label-any and --exclude-label never judged it: bd blocked and
GET /v0/beads/blocked listed it whatever its labels, on every route.
Both decorators now filter those rows by the request's labels. The uow
decorator reads them through GetMany, chunked at MaxGetManyIDs, so their
labels are hydrated; GetIssuesByIDs left them empty, which also printed
them unlabelled on the proxied route.

Review fixes (adopt-pr apply-fixes, iteration 1):
- major #1: label filters on external-only rows in the store and uow
  decorators, with absence-asserting arms in the unit, served httpclient
  (server- and client-enforced policy), e2e and proxied tiers; the spec
  and the role doc say such rows are narrowed like every other row.
- minor #2: the policy.external_dependencies token prose names the
  blocked listing (spec, routes.go, regenerated types.gen.go).
- minor #6: SERVE_RUNBOOK and the allowUnlimited comment record the
  blocked listing's unbounded whole-set answer and why.
- minor #10: BlockedLister telemetry-outermost and typed-unsupported pins
  beside the ReadyCounter pair, plus the externaldeps wrap pin.
- nit #9: F-blocked names --flags --raw's refusal against a server that
  applies the policy (ledger.go and the regenerated ledger doc).
- nit #11: the remote BlockedLister no longer builds a local lister it
  then discards.

Review fixes (adopt-pr apply-fixes, iteration 2; the review approved at
940 with one minor and two nits, none gating):
- minor (the --flags refusal list was unpinned): the new
  TestBlockedFlagsRefusesEveryListingFilter pins blockedFlagFilterFlags
  to the flags blockedCmd registers, in both directions. Every
  registered flag except --flags and --raw must be refused, and every
  entry must name a registered flag. The test walks Flags() rather than
  LocalFlags(), so it does not merge the root's persistent flags into
  blockedCmd, and it skips inherited root flags and cobra's --help.
  Mutants:
  - four fail it: a new filter flag left off the list, a dropped
    entry, a misspelled entry, and --raw added to the list;
  - a simulated earlier in-process run (merged root flags plus --help)
    stays green, and fails once either skip is removed.
- nit (the remote branch's span): the remote BlockedLister comment now
  says why that lister is not wrapped again. The inner lister already
  carries telemetry's span, so wrapping would nest a second span of the
  same name. The comment also says what runs outside that span.
- nit (duplicated order comparator): left as is. finishBlockedIssues
  predates this PR, so merging the two sorts would refactor existing
  code with no review pass left after this one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
2026-10-17 12:29:13 +00:00
Julian Knutsen
601be8a6bf
feat(list): bd list's remaining filters over http behind issues.list.filters (#7647)
* feat(list): bd list's remaining filters over http behind issues.list.filters

Over http every `bd list` filter beyond the created bounds and the title,
id and no-assignee scope refused (time bounds, priority range, text and external-ref
matches, spec, label pattern/regex, exclude-type, no-parent, no-labels,
empty-description, pinned/no-pinned, deferred, overdue, mol/wisp type).
The library entry already applied all of them: issueops.Reader.List via
workapi.BuildListFilter, shared by the CLI and the handler. This adds
only the wire.

- Server: GET /v0/beads/issues decodes 29 new optional parameters
  (listFilterParams, decode only; countIssues' names where it already
  spells the filter) into the existing ListRequest, behind one new
  behavior token, issues.list.filters. mol_type/wisp_type are closed
  enums refused by name (an empty value too). wire_revision stays 2;
  apigen and the wireshape golden are regenerated (additive only).
- Every RFC 3339 bound the listing and count decode is normalized to UTC,
  so an offset-bearing bound selects what its Z twin does on a zone-less
  timestamp column.
- workapi.BuildListFilter refuses PinnedFlag with NoPinnedFlag
  (ErrValidation, the CLI's own sentence) instead of letting PinnedFlag
  win; over http that is a 400 on no_pinned.
- Client: the encoder sends the members (encode.ListFiltersMembers, one
  list read by the encoder, the pre-dial gate and a spec-parity test).
  Against a server not advertising the token, httpReader.List refuses
  before dialing with ErrUnsupported naming issues.list.filters. The 29
  E-ListRequest ledger refusal rows retire; the ledger doc is updated;
  skew flag mappings added.
- Tests: handler decode/parity/enum/UTC/malformed/pinned-pair tests;
  encode member/gate/spec parity and bound encoding; per-member
  ride-behind-token and pre-dial skew refusal; two new Reader contract
  cases on every leg (dolt, embedded, uow, served): the eight time
  bounds at exact boundaries (strict, whole-second truncation, NULL never
  matches, +02:00 equals UTC) and one in/out row per remaining family;
  three served Reader cases unparked; TestE2E_ListFilterParityOverHTTP
  (served == embedded, masked server refuses naming the token, no dial);
  five corpus shapes marked pending until the reference server profile
  advertises the token.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat(list): exclude_status on listIssues, the 30th issues.list.filters member

issueops.ListRequest gains ExcludeStatus: statuses to leave out of a
listing, appended to the default exclusions (never re-admitting what they
hide), comma-separated or repeated, and validated against the workspace's
statuses by the same rule CountRequest.ExcludeStatus uses (an unknown name
is ErrValidation). The rule moves into one shared function,
workapi.ParseExcludeStatus, called by both builders. With AllFlag it reads
the active set without enumerating every status, so an http-backed caller
can list O(active) rows instead of the whole history.

- Server: listIssues decodes a repeatable `exclude_status` under the same
  issues.list.filters token (no new token); an unknown name is a 400 on
  exclude_status. apigen and the wireshape golden are regenerated
  (additive).
- Client: the encoder sends it and it joins encode.ListFiltersMembers, so
  the pre-dial gate asks for the token.
- It is refused together with ReadyFlag, like the other members the ready
  query cannot carry.
- No `bd list --exclude-status` flag yet (it would need the CLI docs
  regenerated); the member is reachable through the library and the wire.

Tests: builder unit test (append, AllFlag, comma split, unknown name);
handler decode and 400; encoder, round-trip and gate; Reader contract
cases on every leg (active set under AllFlag, repeated and comma values,
adds to the defaults, narrows an explicit Status, unknown name refused).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(list): label_regex compile errors are 400s; review polish for list filters

- An invalid `label_regex` on GET /v0/beads/issues, /v0/beads/ready and
  /v0/beads/ready:count is now `400 invalid_argument` (`invalid_value` on
  `label_regex`) instead of `500 internal`. The database still compiles
  the pattern in its own dialect; a request that sent a regex and earned
  the engine's "regular expression is invalid" refusal is attributed to
  the parameter (failRegexReadErr). The same text on a request with no
  regex stays a server fault.
- mol_type and wisp_type refuse each other's vocabulary (tests pin
  `mol_type=heartbeat` and `wisp_type=swarm`), so the call-site
  allowlist, not just the spec enum, is covered.
- exclude_status with a workspace custom status: leg tests on the
  embedded store and over the served wire (accepted and applied; a name in
  no vocabulary refused). ReaderFixture cannot configure custom statuses,
  so these sit beside the count's twin rather than in the contract.
- The search e2e gains a positive arm: --desc-contains returns exactly the
  row whose description carries the token.
- Docs: `all` plus `exclude_status` keeps every status not named (pinned,
  hooked and custom done/frozen included unless named), not "the active
  set"; label_regex documents its 400. A corpus source line is made
  neutral; a test message says 30.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(list): compose issues.list.filters with the --title-contains fold

#7631, now on main, folds `bd list --title-contains` onto listIssues
`title` and refuses the TitleContains left over from a --title and
--title-contains pair that differs, because the listing then had one
title parameter. This branch publishes `title_contains` behind
issues.list.filters, so that leftover now rides it beside `title` and
the server applies both. Neither half is dropped, and against a server
without the token the pre-dial gate refuses, naming issues.list.filters.

- encode.FoldTitleContains still runs first; its doc now says where a
  differing pair goes.
- Tests: the fold table expects `title` plus `title_contains` for a
  differing pair, including the ſ/s pair strings.EqualFold would match;
  the differing-pair refusal names issues.list.filters; the
  list_filters_test sweep pairs its TitleContains probe with a differing
  TitleSearch, since a lone one asks only for issues.list.title; the e2e
  differing-pair refusal becomes a listFilterShapes row that answers
  exactly child-a over http and embedded, and refuses before dialing
  without the token.
- The gc-polecat-closed-after corpus shape's pending reason also names
  issues.list.title. The CHANGELOG --title-contains entry no longer
  lists the differing pair and --closed-after as refused.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* build(bazel): auto-sync BUILD files

Applied from the bazel-sync-patch artifact of https://github.com/gastownhall/beads/actions/runs/39013611268
(`make bazel-sync`: gazelle, tools/bazel/go_srcs.py, bazel mod tidy).
Only BUILD.bazel, MODULE.bazel and MODULE.bazel.lock are ever pushed; see
scripts/bazel-autofix-push.sh.

* fix(list): serve --priority-max in search parity, refuse the parent pair

The proxied tier's search parity table still expected a remote
`bd search --priority-max 1` to refuse, because listIssues could not
carry it. This branch serves priority_max behind issues.list.filters,
so the remote route answered and the dolt-race shard went red in
TestProxiedServerSearchRoutesAgree. The row now expects the answer on
every route. It was the last wireCan=false row; the branch stays, with
a comment, for the next flag listIssues cannot carry.

- ParentID with NoParent: a served listing now carries no_parent beside
  parent, and ANDing the two answered only the edge-less rows under the
  parent's dotted id. BuildListFilter refuses the pair with
  ErrValidation, in the sentence bd list and BuildCountFilter already
  use, so issueops.Reader.List refuses it on every backend and the
  listing answers 400 on no_parent. Pinned by a builder test, a reader
  conformance case (dolt, embedded, uow, served http) and two httpapi
  tests.
- POST /v0/beads/issues:claimNext shares the ready listing's
  label_regex but answered a pattern the database cannot compile with
  500. It now gives the listing's 400 invalid_value on label_regex,
  through the helper the listing's mapping is split into.
- The descendant walk's ledger rows said listIssues publishes no
  parameter for members it now serves behind issues.list.filters. They
  now say the walk does not send them yet, and that --flat or --json
  asks listIssues directly. The ExcludeStatus, Pinned and ExcludeTypes
  rows, the parentwalk.go header, the walk table's doc and two walk test
  comments are corrected the same way, and the ledger doc is
  regenerated. parentWalkRefusals notes that a member moved off the list
  must check issues.list.filters itself, because the walk dials past
  the listing's pre-dial gate.
- Spec: the listing's no_parent documents the pair's 400, the count's
  exclude_status no longer says it has no listing counterpart, and
  claimNext's label_regex documents its 400. types.gen.go is
  regenerated. Comment-only: countFilters, and readyScopeFields'
  ExcludeStatus entry.
- CHANGELOG and README say the default `bd list --parent` tree view
  does not carry the new filters yet; the label_regex entry names
  claimNext, and a Changed entry records the parent-pair refusal.

Second review pass: docs and comments only, no behavior change.

- The prose copies of the issues.list.filters member set now match
  ListFiltersMembers: CapIssuesListFilters and wire.CapListFilters name
  the status exclusion, and the spec's capabilities text names
  label-regex.
- Every time bound on the listing and the count goes through
  q.timestamp, which normalizes it to UTC, and sqlbuild compares it
  strictly at whole-second precision. listIssues' created_before and
  created_after, and countIssues' created, updated and closed bounds,
  now say so in the words the new listing bounds use. The count's
  updated bounds also say what they filter, and its closed bounds say
  that a NULL closed_at never matches. types.gen.go is regenerated.
- README and CHANGELOG: `--flat` or `--json` applies the filters to the
  parent's direct children, not its whole subtree.
- The 29 listRefusal rows this branch serves stay deleted rather than
  kept as retired rows, as #7550 deleted its TitleSearch, IDFilter and
  NoAssignee rows when it served them. The CHANGELOG now says the rows
  are removed, not retired.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-10-17 11:21:18 +00:00
Julian Knutsen
b2d5cff6c0
fix(gate): add-waiter retries contention the store gave up replaying (#7648)
* fix(gate): add-waiter retries contention the store gave up replaying

bd gate add-waiter writes the whole waiter list guarded by the version it
read and retried only ErrVersionMismatch. A convoy adder therefore failed
when its write ended in contention the backend stopped replaying: a
serialization failure or deadlock (Dolt/MySQL 1213/1205, Postgres
40001/40P01, uow.IsSerializationError) on a direct route, or a 503 busy
(wire.ErrBusy) over HTTP, which bd serve sends when its admission limiter
refuses or its transaction retry budget is spent.

gateAddWaiterLostRound now retries those like a version miss, under the
same jittered backoff and 20-write bound, and a busy answer's Retry-After
raises that round's wait, capped at 2s (gateAddWaiterRetryWait).

The retry is safe because of how a round is built, not because a 503 means
nothing was written: the client maps any 503 to wire.ErrBusy, and a gateway
can answer 503 after the write committed. Each round re-reads the gate,
deduplicates and writes the whole list guarded by the version it read, so a
landed write is found on the re-read (the waiter is never added twice) and a
stale list never overwrites a newer one. A server fault (500, e.g. an
indeterminate commit) and an unreachable database are still returned at
once.

TestAddGateWaiterRetriesTransientContention pins the three retried
spellings, the bound, busy-after-commit (one write, the waiter once), the
500 / db-unavailable / other-SQLSTATE non-retries, and the capped
Retry-After. It is red without the fix.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(gate): bound add-waiter's contention retries and honor Retry-After

Review fixups for #7648.

- A write lost to contention reaches addGateWaiter only after the store or
  bd serve has spent a whole replay budget on it (withRetryTx: 5s, 15s in
  server mode; bd serve's: 15s), so retrying it under the 20-write bound a
  version miss gets could hold an adder for minutes (about five on the
  direct server-mode route). Contended writes now get their own bound,
  gateAddWaiterContentionRetries = 2, like the HTTP client's for a busy
  read. They still count against gateAddWaiterMaxAttempts, and version
  misses keep the 20. The const doc states the worst case: three 15s
  budgets and two 5s waits, about a minute.
- A busy answer's Retry-After is waited out as sent, plus the jittered
  backoff, instead of being capped at 2s. bd serve asks for 5s after a
  spent budget because a convoy back sooner holds slots and starves reads,
  and the wire client already bounds the header. The jitter keeps adders
  answered busy together from retrying together.
- When the last write the bounds allow is answered busy, one more read
  checks the gate before the command fails, with no wait first. A 503 (a
  gateway's, say) can answer a write that committed, and every earlier
  round's re-read would have found it; the last write has no round left.
  A waiter found there is reported as already registered, and a read that
  fails confirms nothing.
- The exhaustion error says "changed on every one of N attempts" only when
  no write was contended. Otherwise it reads "no write to X was confirmed
  in N attempts (K answered busy or lost to write contention)": it names
  the contention, so the operator of a busy server is not sent looking for
  a concurrent writer, and it does not claim that nothing landed.
- gateAddWaiterContended names what maps to each class: Dolt/MySQL
  1213/1205 and SQLSTATE 40001/40P01 on the direct route, and wire.ErrBusy
  from bd serve's busy answer or from a 503 with no code or an unknown one
  (db_unavailable and events_watch_saturated map to their own sentinels).
  It also says why Dolt's 1105 "@autocommit transaction rolled back" is
  not admitted: Dolt raises it for conflicts that a merge inside the
  transaction left behind, while a write lost to a concurrent writer comes
  back as 1213.
- Tests: 1213 and 1205 rows built as *mysql.MySQLError (the default Dolt
  route's shape), the contention bound for busy and for 1213 with no wait
  after the last contended write, version misses not spending it, the
  three exhaustion wordings, a 5s Retry-After waited whole plus the
  jitter, a busy answer to the last write at either bound that landed and
  is found by the extra read, and a failed extra read that confirms
  nothing. Thirteen mutants each fail at least one subtest: no bound, busy
  only counted, version misses counted, no jitter, the 2s cap, the old
  wording, an off-by-one bound, no extra read, an extra read that ignores
  the waiter, one that takes a failed read as landed, a wait before it, a
  wait at the end of each round, and the bound checked after the wait.
- CHANGELOG entry updated to match.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
2026-10-17 10:08:48 +00:00
Julian Knutsen
925e26bc48
fix(http): serve bd list --title-contains by folding it onto title (#7631)
* fix(http): serve bd list --title-contains by folding it onto title

`bd list --title-contains X` refused against an HTTP workspace because
listIssues publishes no title_contains parameter. The store compiles
TitleContains and TitleSearch to the same predicate (LOWER(title) LIKE
'%v%'), so the client now folds TitleContains onto TitleSearch before the
pre-dial gate (encode.FoldTitleContains) when TitleSearch is empty or equal.
The request then rides the existing `title` parameter behind
issues.list.title, and against a server without that token it refuses before
dialing, naming the token. A --title and --title-contains that differ still
refuse: the listing has one title parameter and dropping either value would
widen the answer.

No wire change. The ledger row E-ListRequest.TitleContains narrows to the
differing pair.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(http): fold case-only title pairs and qualify the CHANGELOG

Review fixups for #7631.

- FoldTitleContains also folds a pair that differs only in letter case.
  The store binds each value as '%' + strings.ToLower(v) + '%', so a pair
  equal under strings.ToLower is one predicate. It does not use
  strings.EqualFold, which matches pairs such as "ſ" and "s" that lower to
  different patterns. Unit cases pin both directions, and the served test
  answers a case-only pair like the single flags.
- CHANGELOG: name what still refuses over HTTP: a pair that differs other
  than in case, either flag with --parent in the default tree view, and
  --closed-after, which gascity's polecat pre-flight lookup of recently
  closed beads (step 3d) uses.
- Corpus: add gc-polecat-title-contains-closed-after, the 3d lookup,
  pending until the reference server advertises issues.list.title and
  listIssues carries closed_after (E-ListRequest.ClosedAfter).
- Drop two assertions that could not fail (a request passed by value
  cannot be mutated), and bring the e2e shape header, the
  tokenedListFilters comment, the encoder table comment and the
  E-ListRequest.TitleContains ledger row (doc regenerated) up to date.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
2026-10-17 06:00:33 +00:00
Julian Knutsen
ae693ef7cc
fix(http): bd gate create, add-waiter and discover over a connected HTTP workspace (#7621)
* fix(http): gate create, add-waiter and discover through the library roles

bd gate create, bd gate add-waiter and bd gate discover wrote through the
legacy CreateIssue, AddDependency and map-based UpdateIssue, which the http
store does not implement, so over a connected HTTP workspace each failed
before any gate member reached the wire. They now run through the roles on
every route (direct, proxied server, http):

- gate create is ONE Lifecycle.Create carrying the gate members and a
  reverse blocks edge from the blocked issue to the new gate: atomic on
  every route, one createIssue over http behind issues.create.gates. The
  proxied-server route's private unit of work is gone; it uses the same
  role.
- gate add-waiter reads through Reader.Get, deduplicates, and writes the
  whole waiter list through Lifecycle.Update guarded by the row version it
  read, retrying up to three times on ErrVersionMismatch, so concurrent
  adders cannot lose each other's waiter. Over http: issues.update.gates.
- gate discover lists through issueops.ListGates and records the run ID
  through the same Lifecycle await_id patch gate check makes; bd close's
  gh:run persist (updateGateAwaitID) takes the same path.
- Against a server without the token, each refuses before any write,
  naming the token.
- gate discover skips template gates, as gate check already does, instead
  of recording a run ID on a proto every later pour copies.

Tests: unit tests for the one-Create shape, the refusal, the add-waiter CAS
retry, and discover over ListGates with its template skip;
backend/http TestE2E_GatesOverHTTP (advertised and masked); four served
corpus shapes, pending until the reference server advertises the gate
tokens (verified to pass against a profile that does). CHANGELOG.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(gate): add-waiter backs off under contention; discover fails on a failed write

Review follow-ups to the gate CLI port.

- gate add-waiter's guarded write retried three times with no wait, so a
  convoy of workers registering on one gate at once failed all but a few
  (the proxied route's old unit of work had served them all). Each retry
  now waits a jittered, doubling backoff (10 ms to 400 ms, drawn from
  [d/2, d)), for at most 20 writes. The bound is attempts, not wall time:
  under a loaded server one round takes seconds, and a wall-clock budget
  failed the convoy after two or three rounds. A cancelled wait stops the
  loop. TestProxiedServerGateAddWaiterConvoy (direct SQL and
  proxied, real Dolt server) and TestE2E_GatesOverHTTP's concurrent case
  run 11 simultaneous adders (one duplicate): all exit 0, every waiter
  present once.
- gate discover counts only the gates whose run ID was recorded and exits
  non-zero when any matched gate's write failed; it used to print the
  refused gate as updated and exit 0. TestE2E_GatesOverHTTP covers
  discover with and without issues.update.gates (fake gh).
- TestServedGateCheckOverAwaitTypedGates masks issues.update.gates itself,
  so upgrading reference_server.json does not turn its gh:run case into a
  different test.
- The discover listing test asserts closed gates are not listed.
- CHANGELOG: discover's template skip and add-waiter's template refusal
  are behavior changes on the local routes; gate create refuses
  a negative --timeout; gate create/add-waiter follow dolt.auto-commit and
  use the role's commit messages; the proxied create no longer journals
  dependency_added.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-17 02:15:07 +00:00
Julian Knutsen
a3e1b24e2b
fix(import): tolerate only typed dependency refusals, not walk-query errors (#7630)
* fix(import): tolerate only typed dependency refusals, not walk-query errors

With SkipDependencyValidationErrors set (the import mode), the dependency
pass recorded ANY error from checkHierarchy/checkCycle as a skipped edge
and continued. That included failed walk queries (an untranslated
statement, a statement timeout, a dropped connection), so an import could
commit without the edge and report the SQL error only as a skip reason;
on a backend whose transaction aborts on a failed statement, the import
failed later at an unrelated statement with the real cause hidden.

Tolerate only the typed refusals (ErrSelfDependency, ErrDependencyCycle,
*DependencyHierarchyConflictError) via isDependencyValidationRefusal and
return every other error, keeping the %w chain so serialization retry and
error classification apply.

Tests: sqlmock cases where the hierarchy and cycle walks fail under import
mode, on both the per-edge statements and the batch graph, must abort the
pass; typed refusals on both shapes are still skipped. Removing the
predicate fails both error tests.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(import): record the dependency-check fix in the CHANGELOG; tidy two test comments

Review fixups for #7630.

- CHANGELOG (Unreleased, Fixed): bd import now fails when a dependency
  check's own query fails, instead of reporting the SQL error as a skipped
  dependency and, on Dolt, committing without the edge. Refused edges (a
  self-dependency, a cycle, a hierarchy conflict) are still skipped. docs/
  is left alone because it tracks the pinned release (v1.2.2).
- create_test.go: two doc comments kept the line breaks left where the
  internal tracker IDs were removed. They are reflowed into sentences; no
  test logic changes.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-16 23:55:53 +00:00
Julian Knutsen
47d5db39ff
feat(http): bd heartbeat over bd serve (issues.heartbeat), and close the re-arm orphan-lease race (#7600)
* feat(roles): issueops.Heartbeater role on the dolt, embedded and uow legs

Adds issueops.Heartbeater.Heartbeat(HeartbeatRequest{Actor, IssueID}) ->
HeartbeatResult{IssueID, Holder, HeartbeatAt, LeaseExpiresAt, Rearmed},
the lease refresh behind `bd heartbeat`, as its own role with its own
accessor.

- One body: internal/storage/issueops.ExecuteHeartbeatInTx validates
  (*HeartbeatFieldError for a blank/over-long actor or empty id), refuses
  a wisp, then runs RenewLeaseInTx, which is HeartbeatIssueInTx's body
  reporting the renewal. HeartbeatIssueInTx is now a wrapper, so the legacy
  HeartbeatIssue legs answer the same text and sentinels.
- The refresh is fenced on the holder AND on the live claim: after the
  holder-fenced UPDATE, a read in the same transaction requires the issue
  to be in_progress under the holder (the `update leases set` prefix and
  the one IF() the Postgres dialect rewrites are unchanged; a Postgres port
  should expect more serialization retries from that read). A refusal deletes the caller's orphaned lease
  row, and the legs commit that refusal.
- A refresh writes only the lease row: no row_lock, version, updated_at,
  event, journal entry, Dolt commit or hook. A re-arm (a live hand-doled
  claim with no lease row the caller holds) is recorded as a mutation:
  row_lock reminted, updated_at stamped, a lease_rearmed event, a journal
  entry, a version, a Dolt commit (LeaseRearmVersionCommit) and on_update.
  The remint makes a re-arm collide with a racing release or close instead
  of leaving an orphaned lease on an open or closed issue (a pre-existing
  race on every Dolt route). Rearmed is true only when a row was created:
  a same-second refresh (0 changed rows on embedded Dolt) or a holder
  spelled differently refreshes the existing row in place and keeps its
  granted_at/granted_node. Reported times are rounded to whole seconds,
  the stored values; the binds stay unrounded so a same-second refresh is
  never a 0-row UPDATE on Dolt.
- Typed refusals: an absent id is ErrNotFound; a foreign holder is
  *LeaseConflictError{Holder} wrapping ErrAlreadyClaimed; a wisp
  (Ephemeral) or no live claim is *LeaseConflictError wrapping the new
  ErrLeaseNotHeld, which also matches ErrNotClaimable.
- Legs: DoltStore and EmbeddedDoltStore through the issue-operation
  funnel (DOLT_ADD of the named tables, then DOLT_COMMIT -m, after the SQL
  commit); uow.NewHeartbeater through the new uow.RunTxScoped: a refresh or
  a refusal commits with the plain SQL COMMIT (no working-set scan, no Dolt
  commit, nothing another writer left uncommitted is swept), and a re-arm
  commits through the new ScopedCommitter (DOLT_ADD of exactly its tables,
  DOLT_COMMIT -m, never -Am). The legacy HeartbeatIssue doors commit a
  re-arm the same way and keep a refusal's orphan delete, and the
  proxied-server `bd heartbeat` route runs the role's body with the same
  scoped commit.
- Census: storage.Storage gains Heartbeater(); HookFiringStore wraps it
  (fires on_update for a re-arm only, RoleFiresHooks knows it), telemetry
  wraps it, httpapi.timedProvider, uow.notifyingProvider (records a re-arm)
  and externaldeps.uowProvider build it; the journal and version guards
  list the heartbeat family as entry points; the httpclient unsupported
  shell is regenerated and Heartbeater sits on its unsupported allowlist
  until the wire lands.

Conformance: RunHeartbeater* (18 cases) on dolt, embedded dolt and uow:
refresh post-state with the stored times pinned to the result; no
row_lock/current_revision/updated_at/events/journal/issue_versions/
version-control/hook change; a guarded write with the pre-heartbeat
revision still lands; foreign holder refused against an aged lease;
refused after close/release/reclaim/status move; wisp refused; hand-doled
claim re-armed as a mutation; same-second heartbeat is not a re-arm;
orphaned leases on released, closed and reassigned issues refused and
deleted; a refresh and a refusal against a dirty working set make no
commit and leave the other writer's change uncommitted, and a re-arm
commits only its own tables; absent id; request rules; no request mutation. The http leg is
waived until the wire lands.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat(httpapi): POST /v0/beads/issues/{id}:heartbeat behind issues.heartbeat

Publishes issueops.Heartbeater on bd serve as heartbeatIssue, the served
lease refresh behind `bd heartbeat`.

- Spec: the operation, HeartbeatIssueRequest {actor} and
  HeartbeatIssueResponse {id, holder, heartbeat_at, lease_expires_at,
  rearmed}; no `revision` (a refresh writes nothing to the row) and no
  expected_version (the fence is the holder and the live claim).
  issues.heartbeat joins the capability vocabulary and lease_not_held
  (409) the Problem.code list; `reason: ephemeral` qualifies it for a
  wisp. apigen and the wire-shape golden are regenerated; the golden diff
  is additive only, so wire_revision stays 2.
- Server: route row on the custom-method dispatcher, handleHeartbeat in
  heartbeat.go (claim's actor rules via bodyActor, unknown member and
  query refusals), Config.Heartbeater as a required role (sourceRoles,
  roleSourceNames, the per-request uow.HeartbeaterSource accessor).
  failHeartbeat maps *LeaseConflictError typed fields: a foreign holder
  is the claim's conflict shape (already_claimed + assignee +
  issue_status); no live claim, a wisp included, is the new
  lease_not_held (+ issue_status, + reason: ephemeral for a wisp), matched
  before the generic arms so ErrLeaseNotHeld's ErrNotClaimable never
  surfaces as not_claimable. Its detail names the one state the refusing
  transaction found (closed, open and not claimed, an ephemeral wisp, ...).
- bd serve wires the role from its peeled store (serveRoleSource gains
  Heartbeater); the serve stub stores, the corpus and e2e harnesses, the
  served harness and the encode oracle bind it.
- Wire client vocabulary: OpHeartbeatIssue/issues.heartbeat and
  MethodHeartbeat are CLASSIFIED (the capability set-equality gate),
  ReasonEphemeral is pinned to the server's, and lease_not_held rebuilds
  *LeaseConflictError{Status, Ephemeral} wrapping ErrLeaseNotHeld in the
  native words (the code-table set-equality gate). No accessor yet.

Tests: heartbeat_test.go (request mapping and projection, edge refusals,
every role refusal with its code, members and state-specific detail, the
code row, the capability). The served-http Heartbeater leg
(served_heartbeater_test.go, 18 cases) runs the contract against a real
bd serve through a test-local dial over the store's own dispatch, and the
http-leg waivers are deleted.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat(http): bd heartbeat over http through httpclient.Heartbeater

The client leg of the served lease refresh, and `bd heartbeat` on the
role for every route.

- httpclient.Store.Heartbeater (heartbeater.go) dials POST
  /v0/beads/issues/{id}:heartbeat through Store.dispatch, so
  issues.heartbeat is preflighted: an older server is refused BEFORE the
  dial with *wire.CapabilityError naming the token (unwraps to
  *storage.ErrUnsupported{Capability: "issues.heartbeat"}); it never falls
  back to a re-claim or a metadata stamp.
- The role's request rules are restated before the dial
  (validateHeartbeatRequest, pinned to
  storeops.ValidateHeartbeatRequest): blank/over-long actor, empty id, each
  a *HeartbeatFieldError.
- Problem mapping: already_claimed (which the shared table rebuilds as the
  claim's ClaimConflictError) becomes *issueops.LeaseConflictError naming
  the holder and wrapping ErrAlreadyClaimed, in the native words ("issue
  already claimed by <holder>"); lease_not_held already arrives as
  LeaseConflictError (Ephemeral from `reason`); not_found is ErrNotFound;
  invalid_argument on `actor` is the role's field error.
- Idempotent: true, the one write this client marks replayable (a repeat
  only moves the expiry later; a replay after a reclaim fails the fence).
- Legacy Store.HeartbeatIssue rides the role. Both leave the generated
  shell and completeness_test's unsupported allowlist.
- `bd heartbeat` takes Heartbeater() from the resolved store on the direct
  routes (dolt, embedded, http) and from the provider's HeartbeaterSource
  on the proxied route (exact id resolution in a read unit of work, then
  the role); runHeartbeatProxiedServer and heartbeat_proxied_server.go are
  deleted. Success output and exit codes are unchanged; refusal text
  changes per route (see CHANGELOG).

Tests: heartbeater_test.go (stub server: preflight refusal naming the
token with no POST, request/answer projection, each refusal's typed
mapping including the wisp's reason, the 503 replay, pre-dial validation,
validator parity, the legacy door). served_heartbeater_test.go runs the
18-case contract through env.subject.Heartbeater(), with
HookedHeartbeater wired off a HookFiringStore. TestE2E_HeartbeatOverHTTP:
real bd against an in-process serve: holder ok with revision and
updated_at unchanged and a guarded write with the pre-heartbeat revision
landing; a non-holder refused against an aged lease that stays untouched;
closed, wisp and unclaimed refused, each naming its own state; an older
server's handshake refused naming issues.heartbeat with no write. Corpus
shapes gc-heartbeat, -non-holder, -closed, -wisp pending until
reference_server.json advertises the token. CHANGELOG entry for the whole
track, including the orphaned-lease race fix.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* build(bazel): auto-sync BUILD files

Applied from the bazel-sync-patch artifact of https://github.com/gastownhall/beads/actions/runs/38875641041
(`make bazel-sync`: gazelle, tools/bazel/go_srcs.py, bazel mod tidy).
Only BUILD.bazel, MODULE.bazel and MODULE.bazel.lock are ever pushed; see
scripts/bazel-autofix-push.sh.

* fix(heartbeat): roll back a no-issue refusal; restate refresh vs re-arm

Review fixes for #7600 (adopt-pr apply-fixes, iterations 1-2).

Legacy HeartbeatIssue doors commit a refusal only when it read the issue.
The dolt and embedded HeartbeatIssue callbacks committed every
LeaseRenewalRefusal, including Found=false (the issue read failed). That
refusal deletes nothing, but it can follow a fast-path UPDATE that
already extended an orphan lease row's expiry, so committing it kept the
extension. issueops.LeaseRenewalRefusalCommits now gates the commit on
Found, the rule the Heartbeater role's HeartbeatRefusalCommits applies.
New tests on both legs pin both arms: a no-issue orphan's expiry is
unchanged, and a released issue's orphan is deleted.

Refresh vs re-arm contract docs. Comments, Long help, the OpenAPI spec
and the generated apigen still said every heartbeat writes only the
lease row, makes no Dolt commit and fires no hook. A re-arm is recorded
as a mutation: it remints the revision, records an event and a version
entry, commits once (LeaseRearmVersionCommit) and fires on_update
through the wrapping hook decorator. Restated in domain, uow, issueops,
storage.go (why RoleFiresHooks answers true, so bd serve takes the
heartbeater off a peeled store), cmd/bd heartbeat and serve, httpapi,
httpclient, the spec (apigen regenerated), and the conformance and
contract-test docs.

Minor review findings:
- The 409 already_claimed and lease_not_held details now end "nothing
  on the issue was written": the refusal may have deleted and committed
  the caller's orphan lease row.
- docs/multi-agent/federation.md and the CHANGELOG entry describe the
  spelling-mismatch heartbeat: the row is refreshed in place and keeps
  granted_at and granted_node; only a re-arm stamps this node. The
  embedded spelling test pins both columns, and the lease.go comments
  say "refreshed in place" instead of "re-arms".
- The refusal's orphan delete judges the holder under actorMatches, as
  the in-place refresh does (iteration 2). It matched holder = ? on the
  actor as sent, so a dead claim's orphan held under another spelling
  of the caller (gastown.mayor, heartbeat as gastown__mayor) survived
  the refusal until TTL. The refused closure now reads the row's holder
  and deletes that stored holder only when actorMatches(holder, actor).
  Both TestHeartbeatIssueCommitsARefusalOnlyWhenItReadTheIssue twins
  gain a cross-spelling arm (row deleted) and a control: another
  identity's row (gastown.dog-3) survives.

Not changed: `bd heartbeat --json` still omits `rearmed`, since adding
it changes a CLI JSON contract (follow-up). The federation.md paragraph
post-dates the v1.2.2 docs pin, so documenting this main-only behaviour
there is a maintainer call under
engdocs/decisions/2026-07-17-docs-release-pin.md section 1.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(uow): run the scoped re-arm's Dolt commit after the SQL commit

The proxied-server heartbeat commits a re-arm with doltServerTx.CommitScoped,
which ran DOLT_ADD per table and DOLT_COMMIT('-m') INSIDE the open
transaction, before the SQL COMMIT. DOLT_ADD stages whole tables from the
session's transaction root, so that Dolt commit was built from the re-arm's
start snapshot: an issues row another session changed while the re-arm was
open (a write still only in the working set, as in batch mode or before that
writer's own Dolt commit) was staged at its old value, and HEAD disagreed
with the rows every reader sees. This is the LatentLabsSpace/NEXUS#92
ordering the DoltStore funnel (runIssueOperationTxWithMessage) already
avoids, and the review's major finding on this PR.

CommitScoped now commits the SQL transaction first, then stages exactly the
named tables (plus the versioned-history tables) and makes the Dolt commit on
the same pinned connection, the uow twin of doltAddAndCommitPostTx:

- a serialization failure of the SQL COMMIT is still returned, so
  RunTxScoped replays the unit of work;
- the Dolt commit runs detached on its own budget and replays only conflicts
  that leave nothing behind: serialization failures and Dolt's 1105
  "@autocommit transaction rolled back" (new isDoltAutocommitRollbackError,
  mirroring the DoltStore classifier of the same name);
- nothing staged, or "nothing to commit", is not an error: a concurrent
  writer's Dolt commit already took the row. A "nothing to commit" past the
  staged check is logged, as the funnel logs it, so the missing audit line
  is explicable;
- any other failure is logged, never returned. The data is committed, and
  returning it would make RunTxScoped replay a committed re-arm, which would
  then report a refresh. The session is poisoned rather than pooled, since
  its state is unknown. uow records no metrics, so that log line is the
  drop's only signal; bd.db.post_tx_commit_dropped counts only the funnel's.

Statements go through schema.DrainCall, retiring the local drainCall fork
(review nit).

Tests: five sqlmock tests pin the order (SQL COMMIT before any DOLT_ADD),
the swallow-and-poison path, the 1105 retry, the returned serialization
failure and the empty-commit tolerance; each fails against the previous
CommitScoped. TestIsDoltAutocommitRollbackError carries the DoltStore
classifier's table over to the uow copy, plus the prefix boundary; dropping
the prefix branch, the prefix's period, the 1105 check or the type check
each fails a case. TestHeartbeaterRearmKeepsAConcurrentWrite is the
real-Dolt regression: a change to another issues row made while the
re-arm's transaction is open must be at HEAD after the re-arm's Dolt
commit. Its working-set-only writer fails on the old ordering (dolt
2.1.8); the writer that Dolt-commits its own change passes on both and is
kept as coverage.

Review follow-ups folded in (comments, a file move and a test; the
absorption log line above is the only behaviour change among them):

- the freshRowLock invariant and its row_lock_guard_test.go mirror name the
  re-arm as the one deliberate remint without a lifecycle-field change,
  load-bearing for the release/close collision;
- httpclient: "a write is never retried" (wire/client.go, stall_retry.go)
  and "only a read's answer is yes" (dispatch.go) now allow for the
  Idempotent heartbeat, and httpHeartbeater and issueops.HeartbeatResult
  document that a replayed heartbeat can report Rearmed false after a
  committed re-arm, with the guarded write's revision check as the backstop;
- the proxied route moves back to cmd/bd/heartbeat_proxied_server.go, the
  file family cmd/bd/AGENTS.md prescribes;
- the ScopedCommitter and RunTxScoped docs no longer say every other
  writer's uncommitted change stays out of the commit: a staged table is
  committed whole, so such a change to a named table rides in the re-arm's
  commit, as it does in the funnel, and only other tables keep theirs;
- commitStagedTables says its drop is log-only, the absorption is logged,
  and the uow classifier gets its table test (see Tests).

Not folded in: the base-owned IssueUseCase.Heartbeat /
IssueSQLRepository.HeartbeatIssue door, dead in production since the
proxied route moved to the Heartbeater role. Its one caller is the
notifying hook-parity test (uow/notifying_test.go), and moving that case
onto the Heartbeater means re-deriving its RenewLease hook semantics, so it
is left for a follow-up.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
2026-10-16 22:38:23 +00:00
gascity-eddie[bot]
91a72ef7b5
fix(mol): route bond operand resolution like show/update/close (closes #4714) (follow-up to #4720) (#7622)
* fix(mol): route bond operand resolution like show/update/close (closes #4714)

bd mol bond resolved operands with utils.ResolvePartialID against the local
store only, so a bead that lived in a routed store failed with
"'<id>' not found (not an issue ID or formula name)" — even though bd show
resolved the same ID. This broke `gt sling <bead> <rig>`, which cooks the
default formula and bonds it to a rig-routed bead.

- Resolve operands through resolveAndGetIssueForMutation, the same routing
  fallback bd show/update/close use (local, then prefix-routed rig via
  routes.jsonl, then contributor auto-routing). Write-intent so a prefix-routed
  target opens writable and the bond commits where the bead lives.
- Run the bond mutation against the store that owns the resolved issue instead
  of the global local store; reject a bond whose two operands resolve to
  different stores rather than writing to the wrong database.
- Route the --dry-run preview read-only so it previews routed operands too.
- Add TestResolveMolBondOperandRouting covering local and routed resolution.

Same routing-parity fix as #3608/#3609 for bd close.

* fix(mol): fail fast on read-only routed stores, share same-rig bond handles

Address the two structural issues from the #4720 review beyond the rebase
itself (the rebase already preserves main's unconditional formula fallback
from #3874 instead of reintroducing the looksLikeFormulaName gate):

- Routed operands resolve but couldn't be bonded: contributor auto-routing
  deliberately opens stores read-only (they hydrate foreign projects that
  must never be mutated), yet the bond selected that store and dispatched
  mutations that only failed at the store layer. Operand resolution now
  mirrors resolveCloseTargets explicitly (local, then prefix-routed
  write-intent, then the shared auto-routed read-only handle) and records
  writability per operand; pickBondStore rejects a bond pinned to a
  read-only store with a clear message before any mutation is attempted.
  TestMolBondPrefixRoutedWriteThrough now verifies the actual dependency
  write commits in the routed database, not just resolution, and
  TestMolBondAutoRoutedReadOnlyFailsFast covers the fail-fast path.

- Same routed database compared as two different stores: pickBondStore
  compared Go handle identity, but each route-open constructs a fresh store
  in server mode, so two operands in the same routed rig were wrongly
  rejected as cross-store. Both operands of a bond now share one routed
  handle (an already-opened routed store is tried before opening another),
  and sameBondStore falls back to StoreLocator identity (CLIDir pins the
  concrete database) for separately-opened handles onto the same database.
  TestSameBondStoreSeparateHandles covers the two-handle case directly.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(mol): validate routed bond homes before mutation

Discover bond operands read-only, enforce dry-run parity and cross-store policy before writable reopen, unwrap decorated store identities, preserve actionable route failures, and verify the accepted home after reopen.

Co-authored-by: Johan Snyman <johan.snyman@orange.com>

Agent-Signature: codex-gpt-5.6-sol-high on behalf of matt wilkie

* fix(mol): reconcile routed bond discovery with #5253 var validation

The rebase onto current main carried two silent regressions the Aug 16
review named: the discovery-based resolution (which replaced
resolveOrDescribe on the direct-store path) never validated --var values,
so `bd mol bond --dry-run <formula> <x> --var bad=...` previewed success
for a bond execution refuses — exactly the false preview #5253 fixed —
and materializeMolBondOperand wrapped every cook error as
"'%s' not found as issue or formula", re-introducing the ErrVarValidation
double-wrap #5253 removed from resolveOrCookToSubgraph.

discoverMolBondOperand now takes the provided vars and runs
formula.ValidateProvidedVars on its formula fallback, so --dry-run and
execution reject the bond identically, before any writable reopen.
materializeMolBondOperand passes formula.ErrVarValidation through
unwrapped, matching resolveOrCookToSubgraph and pour/wisp.

Agent-Signature: claude-fable-5 on behalf of R0SEWT

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(mol): review polish — fs.ErrNotExist, hook-isolated test repos, auto-route coverage

Three non-blocking notes from the Aug 16 review:

- routed.go: errors.Is(err, fs.ErrNotExist) instead of the legacy
  os.IsNotExist, so the not-found check keeps working if loadPrefixRoutes
  ever starts wrapping its open error.
- mol_bond_routing_test.go: pin core.hooksPath to .git/hooks after each
  git init (the initGitRepoAt convention), so a developer or CI box with a
  global hooksPath override never runs foreign hooks inside test repos.
- The widened openAutoRoutedStore behavior (maintainer/default auto-routes
  open writable for any validated write-intent resolver, not just mol bond)
  now has both the CHANGELOG sentence and a write-through test:
  TestMaintainerAutoRouteMutationWritesThrough drives
  resolveAndGetIssueForMutation — the bd update resolver — through a
  maintainer auto-route, commits a real update there, and re-reads it via a
  fresh routed read.

Agent-Signature: claude-fable-5 on behalf of R0SEWT

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(mol): carry main's #5761 formula validation into routed bond discovery

Rebase adaptation for #4720 onto main b303d494df. The PR moved the direct
(non-proxied) `bd mol bond` path off resolveOrDescribe and
resolveOrCookToSubgraph onto discoverMolBondOperand and
materializeMolBondOperand. Main's #5761 meanwhile fixed the old pair so a
--dry-run fails on exactly what the real bond fails on; the new pair did not
have that fix:

- discoverMolBondOperand loaded the formula with parser.LoadByName, which
  never runs Formula.Validate, so a --dry-run previewed a successful bond for
  a formula the cook rejects (e.g. a waits_for gate with no spawner). It also
  validated --var values against the unmerged formula, so a var whose enum is
  declared only in a parent went unchecked. Discovery now resolves the
  formula with parser.Resolve first, the way resolveAndCookFormulaWithVars
  does, and wraps both failures the way the cook does, so --dry-run and
  execution report the same message.
- materializeMolBondOperand passed only formula.ErrVarValidation through
  unwrapped. A formula that fails validation was reported as "not found as
  issue or formula". formula.ErrValidation now passes through too, as in
  main's resolveOrCookToSubgraph.

TestDiscoverMolBondOperandRejectsWhatMaterializeRejects and
TestDiscoverMolBondOperandValidatesVarsAgainstTheMergedFormula assert the two
phases against each other, like main's TestBondDryRun* pair does for the
proxied route.

Also:
- The PR's routing tests now pass the `exact` argument that main's #5393
  added to resolveViaPrefixRoutingWithAccess. They pass false, which keeps
  the partial-ID resolution the tests were written against.
- The PR's three new cgo test files are added to the bd_test srcs. This is
  `make bazel-sync` output on the merged tree, and it touches nothing else.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Rody Vilchez <102562850+R0SEWT@users.noreply.github.com>

* test(mol): rebuild the RepoContext cache in the PR's role-routing tests

Rebase adaptation for #4720 onto main b303d494df. Main's #5243 moved
auto-routing role detection onto beads.GetRepoContext(), which caches the
repo context once per process; before it, role detection ran
routing.DetectUserRole(".") on every call. The PR's auto-routing tests chdir
into a fresh repo and set beads.role there, so after the rebase they read
the context an earlier test built for its own, now-deleted repo. There
beads.role is unset, and the remote-URL fallback finds no origin and answers
maintainer:

- TestMolBondAutoRoutedReadOnlyFailsFast fails whenever a role-routing test
  ran before it in the same binary (reproducible alone with -count=2):
  discovery looks for the contributor operand in the local store and reports
  it not found.
- TestDiscoverMolBondOperandRouting/maintainer_routed_issue and
  TestMaintainerAutoRouteMutationWritesThrough still pass, but only because
  that fallback is also maintainer; they never read the beads.role they
  configure.

Each test now calls resetRepoContextCachesForTest after its chdir, as #5243
did for main's own role-routing tests (TestResolveCloseTargets, which
TestDiscoverMolBondOperandRouting mirrors, and the routing_read tests).

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Rody Vilchez <102562850+R0SEWT@users.noreply.github.com>

* fix(routing): open maintainer auto-routes writable for exact-match writes

#5393 landed after this PR was written. It moved `bd comment` and
`bd comments add` off resolveAndGetIssueForMutation onto a new
resolveAndGetIssueForMutationExact. This PR widens the former's auto-route
tier for write intent: a maintainer/default target opens writable, while a
contributor target stays read-only and MutationForbidden. On the PR's
original base that widening covered comment writes. After the rebase the
exact resolver still opened every auto-route read-only, so comment writes
lost it and the CHANGELOG's "any validated write-intent resolver" no longer
held.

The exact resolver is meant to keep the mutation resolver's routing
fallbacks and only tighten matching (#5393: it "keeps the existing
cross-rig prefix-routing and contributor auto-routing fallbacks intact").
Its auto tier now takes the same write-intent path. Matching stays exact,
and the abbreviation-refusal precedence is unchanged.

TestMaintainerAutoRouteExactMutationWritesThrough pins the change: the
routed store must not be read-only, and a comment written through it must
commit in the planning database. Without this change the read-only check
fails. The write itself still succeeds, because a server-mode read-only
open does not refuse it.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Rody Vilchez <102562850+R0SEWT@users.noreply.github.com>

* fix(routing): harden routed writes and surface routing failures

Review fixes for #4720.

bd close resolved its batch's shared auto-route through
openRoutedReadStore, so the route opened read-only even though every
other write-intent resolver opened it writable. The shared handle now
opens through openAutoRoutedStore with write intent, so the close commits
where the issue lives.

A contributor auto-route now opens writable for write-intent callers, as
maintainer and default routes do. The refusal the previous revision added
(errContributorRouteMutationForbidden, contributorRouteRefusal,
RoutedResult.MutationForbidden) is gone. A contributor's route target is
their own planning repository, the one bd create writes to:
docs/multi-agent/multi-repo-migration.md and
examples/contributor-workflow/README.md have the contributor claim and
close planning issues from the fork, and GH#2345, beads-0km and GH#3608
made bd show, update and close reach those issues. The read-only rule
came from #4389's review fixes (e8ae7a291a), which kept "contributor
auto-routing" read-only to preserve the bd-6dnrw.32/GH#3231 guarantee
that "routed reads never mutate a foreign project's history". That
guarantee is about reads, and the planning repository is not a foreign
project. Base therefore split by backend: a server-mode bd update, close
or comment of a planning issue committed, because a read-only server
store accepts the write, while the embedded store refused it with "store
is read-only". Refusing in every resolver would have broken the
documented workflow on both backends. bd mol bond was the only command
that checked MutationForbidden, so its check goes too, and a bond of
planning issues commits in the planning repository like any other routed
write. Reads through every route stay read-only. This reverses the
previous revision's stance and is flagged here as a maintainer call.

bd unclaim now resolves its issue through resolveAndGetIssueForMutation,
as bd update --claim does, so a routed issue opens writable; with the
read resolver an embedded routed target refused the release with "store
is read-only". Like bd close, it commits a routed change itself
(commitPendingIfEmbedded), since the post-run auto-commit covers only the
local store. bd human respond and dismiss already opened their target
writable but never committed it, so on an embedded workspace the close
sat uncommitted in the routed repository's working set; they now commit
it the same way. resolveAndGetIssueWithRoutingAccess's
writablePrefixRoute parameter is renamed writable, since it now governs
auto routes too.

A routed commit that fails no longer looks like success, and a retry
commits it. bd unclaim printed "Unclaimed" (or listed the issue in its
--json output) even when the release's routed commit failed; it now
reports the commit error and leaves the issue out. The failed commit
leaves the release, or the close human respond and dismiss make, in the
routed repository's working set. There a retry finds the issue
unassigned or already closed and refuses before it reaches its commit,
and nothing else commits a routed target. On that refusal unclaim,
respond and dismiss now commit the pending write before reporting it,
through commitRoutedWrite, which their success paths share.

A routed write never creates the target's database. The routed open runs
before the lookup it serves, so an embedded open of a repository that had
not been bootstrapped yet created an empty database that outlived an id
that missed; bd bootstrap then took it for the real one and skipped the
clone from sync.remote. openRoutedTargetStore's writable branch now opens
through newExistingDoltStoreFromConfig, which refuses an embedded
workspace without a database (embeddeddolt.HasRepository) before the
sanitize migration can rewrite anything there. A server-mode open already
never creates one.

resolveAndGetIssueForMutation already returned a routing failure (an
unreadable routes.jsonl, a routed store that fails to open) as itself. The
exact resolver and bd close still fell through to "no issue found
matching", which misstates why the lookup missed. All of them now share
isRoutingFailure. The exact resolver checks its abbreviation refusal first,
so the auto tier still gets its chance at an exact match. A prefix route
whose target has no usable metadata.json now names the route and the file
and says why the file could not be used.

An auto-routed store now opens the target's own dolt_database, as a prefix
route already did. Otherwise BEADS_DOLT_SERVER_DATABASE, which names the
launching workspace's database, would point a server-mode open at the wrong
database on a shared server. openRoutedTargetStore holds that override for
both route kinds. A write refuses a target whose metadata.json cannot be
read or parsed or names no dolt_database (autoRouteTargetDatabase) instead
of falling back to that variable. A target with no metadata.json at all
opens, read or written, the only embedded database it holds
(embeddeddolt.Databases), or the default database
(configfile.DefaultDoltDatabase) when it holds none or several.
Contributor setup leaves the planning repository without one until the
first routed bd create writes it, and names its database the way any
workspace without metadata.json does, BEADS_DOLT_SERVER_DATABASE first.
The open would otherwise resolve that name again from the launcher's
variable, so when the two differed a read that missed failed with
"database not found" and a write that missed created a database beside
the one setup created. A server-mode target holds no embedded database,
so with the variable set such a route now opens the default database
rather than the launcher's, which is what it opens without the variable.
A read of a target whose metadata.json is unreadable or names no
database keeps the lenient lookup it had.

bd mol bond's routed home now gets the external-dependency policy and
nothing else, as wireExternalDependencyPolicy asks of routed stores. The
launching workspace's hooks and telemetry no longer wrap writes into
another rig. runMolBond's tail is split into planMolBond, openMolBondHome,
materializeMolBondOperands and bondMolBondOperands, which takes it from
cyclomatic 26 down to 10 or less per function. getIssueWithRouting and the
resolveViaAutoRouting wrapper had no callers left and are removed.

Tests:
- TestMaintainerAutoRouteMutationWritesThrough now checks that the routed
  store is writable. Without that check it passes even against a read-only
  open, because a server-mode read-only store accepts the write.
- TestAutoRouteCloseTargetWriteIntent covers bd close's write intent for a
  maintainer route.
- TestContributorAutoRouteWritesThrough replaces
  TestContributorAutoRouteRefusesWriteIntent: an update, a comment and a
  close through a contributor route each open the target writable and
  commit, a read through the same route stays read-only, and a missing id
  stays a plain not-found.
- TestEmbeddedContributorRoutedWritesCommitInPlanning runs bd update
  --claim, unclaim, comment, close, human respond and human dismiss
  through the bd binary in a contributor checkout. Each advances the
  planning database's HEAD, and the issues end up closed there and absent
  from the fork's database. The embedded shard manifest gains the test.
- TestMolBondContributorAutoRoutedWriteThrough replaces
  TestMolBondAutoRoutedReadOnlyFailsFast: bd mol bond's pipeline bonds two
  planning issues through a contributor route, and a fresh routed read
  sees the dependency; setupAutoRoute now seeds extra planning issues for
  it. TestDiscoverMolBondOperandRouting's contributor case now expects the
  writable reopen.
- TestResolveCloseTargets keeps base's contributor cases (beads-0km); the
  previous revision had moved them to routing.maintainer.
- TestRoutedWriteDoesNotCreateTargetDatabase (in-process) and
  TestEmbeddedRoutedWriteMissDoesNotCreateTargetDatabase (the bd binary)
  check that a missed write through a prefix route and through a
  maintainer auto-route leaves an embedded target that has not been
  bootstrapped without an embeddeddolt directory. The embedded shard
  manifest gains the test.
- TestRoutedMutationResolversReportRoutingFailures runs each write-intent
  resolver against an auto route whose store fails to open, an auto route
  whose target's metadata.json names no dolt_database while
  BEADS_DOLT_SERVER_DATABASE names the launcher's, and a prefix route
  whose target cannot load.
- TestAutoRouteTargetDatabase covers a write and a read of a target whose
  metadata.json names a database, is missing, names none, or cannot be
  parsed; a missing one yields the target's only embedded database, or
  the default database when it holds none or several, either way.
  TestDatabases covers the listing, which applies HasRepository's .dolt
  marker probe to each database.
- TestAutoRouteMissWithoutMetadataIgnoresEnv runs a missed read and a
  missed write through an auto-route to a target that has one database
  but no metadata.json: the default database while
  BEADS_DOLT_SERVER_DATABASE names the launcher's, and a database named
  after the launcher's with the variable set and unset at use. Each miss
  must report not found and leave the target holding only its database.
- TestRoutedWriteRetryCommitsFailedCommit fails the routed commit of bd
  unclaim (text and --json), human respond and human dismiss with an
  invalid --dolt-auto-commit. The run must fail with nothing on stdout and
  leave the routed repository's HEAD as it was; a retry must report its
  refusal and commit the write there.
- TestAutoRouteOpensTargetDatabaseDespiteEnv checks the target-database
  change.
- The auto-routing tests clear BEADS_ROUTING_MODE and BD_ROUTING_MODE
  through neutralizeRoutingModeEnv. Viper ranks them above the
  routing.mode the tests write, so a host that exports either var never
  routes. bdEnv, which builds the bd binary's environment in the
  embedded tests, now drops BD_ROUTING_MODE as it drops BEADS_*; agent
  hosts export it, and TestEmbeddedContributorRoutedWritesCommitInPlanning
  failed on such a host.
  TestEmbeddedRoutedWriteMissDoesNotCreateTargetDatabase no longer needs
  its own envWithout.
- Reverting each fix turns its test red: the contributor read-only clamp
  (the contributor tests above), unclaim's resolver or commit and the
  respond and dismiss commits (the matching step of the embedded test),
  and each autoRouteTargetDatabase rule. So does dropping unclaim's,
  respond's or dismiss's retry commit, or unclaim's skip of a release
  whose commit failed (TestRoutedWriteRetryCommitsFailedCommit); either
  earlier no-metadata.json rule, the variable, which leaves the stray
  database the review reported, or a fixed default database, which fails
  the read of a target setup named after the variable
  (TestAutoRouteMissWithoutMetadataIgnoresEnv and
  TestAutoRouteTargetDatabase), and taking the first of several databases
  (TestAutoRouteTargetDatabase); and bdEnv's BD_ROUTING_MODE drop, on a
  host that exports BD_ROUTING_MODE=off (both embedded tests).

The CHANGELOG entry now records that every auto-route opens writable for
the commands that change an existing issue, the unclaim and human
respond/dismiss commits, that a routed write never creates the target's
database, and the target-database and routing-failure changes.
docs/multi-agent/routing.md says that write commands follow every route,
contributor, maintainer and default alike, never create the routed
repository's database, and refuse a target whose metadata.json is
unreadable or names no dolt_database. Both say that an auto-route opens
a target with no metadata.json at the one embedded database it holds, or
its default database when it holds none or several, while a prefix route
always needs the target's dolt_database. That page documents
behavior that is not in a release yet, which the docs release-pin
decision (engdocs/decisions/2026-07-17-docs-release-pin.md §1) would
leave undocumented. The review asked for docs that match the behavior,
as feature PRs #6508, #5855, #5997 and #5092 also did, so it is flagged
here as a maintainer call.

Open, and not changed here. bd close has the same retry gap on base: a
re-close of an issue that a failed routed commit left closed counts as
already closed and never commits that store (mutatedStores).
commitPendingIfEmbedded gates on the launcher's mode (isEmbeddedMode),
not the routed store's, so a server-mode launcher that opens an embedded
routed repository would leave the write uncommitted there. That gate is
shared by every routed write command and is not exercised here.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Rody Vilchez <102562850+R0SEWT@users.noreply.github.com>

* ci(shards): list TestDatabases in the 40-shard embedded storage manifest

The routed-write hardening added TestDatabases to
internal/storage/embeddeddolt/detection_test.go without a slot in the
Bazel-only 40-shard block of .github/scripts/embedded-storage-test-shards.txt,
so gen_embedded_storage_shard_manifest.py 40 --weights=duration --check
reported it missing and TestStorageEmbeddedShardManifestGeneratorNotStale
(go test ./scripts) failed.

Regenerated with the repository command
(gen_embedded_storage_shard_manifest.py 40 --weights=duration --write);
the incremental pack adds exactly one line, on shard 25.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Rody Vilchez <102562850+R0SEWT@users.noreply.github.com>

---------

Co-authored-by: Rody Vilchez <102562850+R0SEWT@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: matt wilkie <maphew@gmail.com>
Co-authored-by: Eddie the Engineer <julianknutsen@users.noreply.github.com>
Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
2026-10-16 21:10:12 +00:00
Julian Knutsen
babf8d7ed7
perf(dolt): sweep the circuit-breaker dir once per process and age out closed files (#7593)
* perf(dolt): sweep the circuit-breaker dir once per process and age out closed files

CleanStaleCircuitBreakerFiles is documented as an init-time cleanup that
is "fast — typically 0-2 files", but it reads every breaker file in the
live directory on every server-mode store open. Two things made that the
dominant fixed cost of a bd write on a busy dev host:

- Every host:port:db a process opens leaves a closed-state file behind,
  and ephemeral test-server ports mint a new name each time. Closed files
  in the live directory were never removed, so one host's
  $TMPDIR/beads-circuit held 2335 of them.
- A write command opens its store twice — the non-mutating preview open
  for the workspace-identity check (be-0gfcs), then the writable open —
  and each open ran the full sweep. One `bd update` opened 4755 breaker
  files.

The store-open path now sweeps at most once per process
(cleanStaleCircuitBreakerFilesOnce); bd doctor --fix still calls the
sweep directly. And the live directory ages out closed files untouched
for 24 h exactly as the legacy /tmp/beads-circuit sweep already did
(legacyClosedSweepTTL becomes closedSweepTTL for both). A closed file
that old is indistinguishable from no file: readState reads an absent
file as closed, and a closed state's failure count only matters inside
circuitFailureWindow. A breaker in use is rewritten on every successful
open, so its mtime stays fresh and it is kept.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(dolt): pin closedSweepTTL's 24h width; document what the sweep removes

Maintainer fixup for the PR #7593 review (iteration 1; all non-gating):

- TestCleanStaleCircuitBreakerFiles_AgesOutClosedLiveFiles stamps its closed
  files at literal ages instead of ones derived from closedSweepTTL: a file
  idle 25h must go and one idle 23h must survive. A TTL lowered to
  5m/61s/30s/22h or raised to 26h/48h, or a use site compared against
  circuitStaleTTL, now fails the test; every one of them passed before.
- CleanStaleCircuitBreakerFiles' godoc lists the closed-file age-out and the
  corrupt-file removal it already does, which directories it sweeps, and that
  store open reaches it once per process while bd doctor --fix calls it
  directly.
- The cleanServerCircuitState seam notes that a test driving the real sweep
  through it must start a fresh staleCircuitSweep.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-16 17:05:11 +00:00
Julian Knutsen
3862b03ff5
feat(http): gate await members on create and update over bd serve (#7589)
* feat(issueops): gate members on create and update, one bounds validator

The library half of serving gate await fields. Every local leg already
stores await_type, await_id, timeout and waiters on create, and await_id
on update; this adds the two missing pieces.

- IssuePatch.Waiters: a whole-value replacement of the waiter list (nil
  or empty clears, stored as []), mapped by UpdateFields and by the
  unit-of-work updateSpec, deep-copied by CloneUpdateRequest, and
  classified as a non-coordination signal on the dolt leg. Duplicates are
  stored as given; dedup stays the CLI's.
- ValidateGateFields / ValidateGatePatch with *issueops.GateFieldError
  {Field, Detail} wrapping ErrValidation, mirroring ReclaimFieldError so a
  front door can name the member. The rules are the columns' only:
  await_type <= 32 characters, await_id <= 255 characters, the JSON
  waiter list <= one TEXT column (65535 bytes), and timeout >= 0. No
  await_type allowlist, no gate-type-only rule, no timer-needs-timeout
  rule. Run from ValidatePublicCreateRequest (every create shape on every
  backend) and ValidateUpdateRequest (await_id, waiters).
- Conformance: LifecycleCreate WritesTheGateMembers / BoundsTheGateMembers,
  LifecycleUpdate PatchesTheGateMembers / BoundsTheGateMembers and
  BatchApply CarriesTheGateMembers, each bound asserted from both sides,
  wired on the dolt, embedded and uow legs and parked on the http leg on
  the live refusal rows until the wire slices land.
- httpclient: IssuePatch.Waiters is refused before the dial on both patch
  documents under a new W-IssuePatch.Waiters row (refuse-not-drop), until
  the wire publishes it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat(httpapi): publish the gate members on create and update

The wire half of serving gate await fields, over the library slice.

- createIssue and the issues:batchApply create item publish await_type,
  await_id, timeout (nanoseconds, the encoding Issue.timeout reads back)
  and waiters, behind the new behavior token issues.create.gates (one token
  for both create shapes, the issues.create.defaultPriority precedent).
- updateIssue's patch and the batchApply update item's patch publish
  await_id and waiters (whole-value replacement; [] clears), behind
  issues.update.gates. await_type and timeout are not patch members: no
  local update route changes them. Neither is nullable; null is refused
  naming the member, as on title.
- The handlers only decode and project (createGateMembers,
  patchGateMembers). The wire is no stricter than the library: every bound
  is the role's *issueops.GateFieldError (await_type <= 32, await_id <=
  255, the JSON waiter list <= one TEXT column, timeout >= 0), mapped to the
  existing 400 invalid_argument with param naming the member at its level
  (await_type, patch.waiters, items[i].create.timeout,
  items[i].update.patch.await_id). The spec mirrors exactly that:
  maxLength 32/255 and minimum 0, and no minLength/maxLength/maxItems on
  waiters. Blank and duplicate waiters and any await_type reach the role
  untouched.
- Spec: the four schemas, the capability prose, and the stale sentences
  (createIssue's "await_* publishes on no operation, read or write" and the
  patch's "spec_id and await_id publish nowhere yet"). apigen regenerated
  (from the remote drift test's diff), wireshape golden regenerated:
  additive entries and sides only, wire_revision stays 2.
- Client: the two tokens are mirrored in wire.behaviorCapabilities so the
  vocabulary stays set-equal with the server's. The client still refuses
  every gate member before the dial (the client slice flips that); the write-ledger
  pending sets name the newly published members under their live refusal
  rows, and the W-CreateRequest.Issue / W-IssuePatch.AwaitID /
  W-IssuePatch.Waiters reasons, the served-leg park reasons and the S4b
  waiver now say the server publishes them and this client does not send
  them yet.

Tests: internal/httpapi/gate_fields_test.go pins member mapping on all four
bodies, clear-by-empty on both patches, null and unpublished-member refusal,
GateFieldError -> param at every nesting level, and both tokens advertised.
Mutating the handlers (dropping the mapping, the GateFieldError arms or the
tokens) turns them red.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat(httpclient): send the gate members behind their tokens

The client half of serving gate await fields, over the wire slice.

- Create: await_type, await_id, timeout (nanoseconds) and waiters join the
  create vocabulary on createIssue and batchApply create items (now
  twenty-four members), sent verbatim when populated. Patch: await_id (by
  presence; "" clears) and waiters (whole-value; nil/empty travels as [])
  are encoded on both updateIssue's and the batchApply update item's patch.
- Token gate before the dial: a create naming any gate member needs
  issues.create.gates, a patch naming one needs issues.update.gates. Without
  the token the request refuses with wire.NewCapabilityError naming it
  (typed ErrUnsupported{Capability}), never a dropped member. batchApply
  checks the whole plan once, so no partial plan is sent. A request naming
  no gate member never reads either token. Store.requireCapabilityBeforeDial
  is the shared helper; requirePersistenceMove now uses it.
- Bounds read back typed: the server's 400 invalid_argument/invalid_value
  whose param names a gate member at any level (await_type, patch.waiters,
  items[i].create.timeout, items[i].update.patch.await_id) is rebuilt as the
  role's *issueops.GateFieldError, the problem kept in the chain (and a batch
  refusal still becomes its *ItemError). Without this the served bounds
  contracts could not pass.
- Ledger: W-IssuePatch.AwaitID RETIRED; the library slice's W-IssuePatch.Waiters row
  deleted (it never shipped outside this branch); W-CreateRequest.Issue and
  W-CreateItem.Issue no longer cover the gate members; new
  W-CreateRequest.Gates (refuse, Capability issues.create.gates) records the
  token-gated late refusal for both create shapes. engdocs ledger
  regenerated from Ledger() (262 rows: 201 refuse, 34 degrade, 27 retired).
- Write-ledger table: the wire slice's pending sets are flipped into carried.
- Served leg: the five gate cases (LifecycleCreate Writes/Bounds,
  LifecycleUpdate Patches/Bounds, BatchApply Carries) are un-parked and run;
  the S4b waiver and served comments now say await_id is sent.

Tests: internal/httpclient/gate_fields_test.go (encode on all four bodies,
clears, old-server refusal per member naming the token with no dial, no
partial batchApply plan, plain requests unaffected on old and new servers,
GateFieldError rebuilt from the problem). Disabling the three pre-dial
checks turns the refusal tests red.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* build(bazel): auto-sync BUILD files

Applied from the bazel-sync-patch artifact of https://github.com/gastownhall/beads/actions/runs/38841144413
(`make bazel-sync`: gazelle, tools/bazel/go_srcs.py, bazel mod tidy).
Only BUILD.bazel, MODULE.bazel and MODULE.bazel.lock are ever pushed; see
scripts/bazel-autofix-push.sh.

* docs(issueops): say the gate timeout rule is no column's

The gate validator's doc said its rules were the stored columns' and that
no command line can produce a negative timeout. The widths are the
columns' (VARCHAR(32), VARCHAR(255), TEXT), but timeout_ns is a BIGINT,
so a non-negative timeout is a rule no column enforces; the wire
publishes it as minimum 0. The raw store creates (CreateIssue,
CreateIssues) and import do not run the validator, so bd gate create
--timeout=-5m, a formula step's gate.timeout and a template clone still
store a negative timeout until they move onto the role.

Also say that GateFieldError.Detail is prose whose HTTP copy ends with
the server's own clause, so a caller dispatches on Field, and why a
create omits an empty waiter list while a patch sends [] to clear it.

Comments only; no behaviour change.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(corpus): gh:run await_id persist refuses by the missing gate token

#7604 (now on main) made bd gate check persist a gh:run gate's discovered
run ID through Lifecycle.Update. Its served test expected the HTTP
client's W-IssuePatch.AwaitID refusal, which persistGateCheckAwaitID
rewords to name await_id. This PR retires that row: the patch carries
await_id behind issues.update.gates. Through the reference proxy, whose
server advertises no gate token, the persist is now refused before the
dial by the capability error ("bd serve at ... does not advertise
capability "issues.update.gates", which updateIssue requires"), so the
merged tree failed the subtest's await_id and updateIssue assertions.

The subtest now expects that refusal: no writes, the error names the
gate, the missing token and the server, no role or store method leaks,
and await_id is untouched. persistGateCheckAwaitID already returns a
capability error as the role raised it (#7604 pins that), so no code
changes. Against a server that advertises the token the persist goes
through: a scratch probe against the in-process server recorded
await_id=4242 and closed the gate.

Also correct the gate.go comment and the CHANGELOG entry that still said
the HTTP client refuses every await_id patch.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Eddie the Engineer <adopt-pr@gascity.com>
2026-10-16 17:02:27 +00:00
572 changed files with 65495 additions and 2369 deletions

View file

@ -201,7 +201,8 @@ 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: `go test ./test/docsync` (nav↔file sync + link conventions),
The short list: `bazel test //test/docsync:docsync_test --config=ci`
(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,8 +39,9 @@ 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:** `go test ./test/docsync`, every fence parses, no body H1, no
HTML comments (MDX), preview with `make docs-dev`.
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`.
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 @@ 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).
go test ./test/docsync
bazel test //test/docsync:docsync_test --config=ci
# 2. Generated CLI docs freshness: regenerates from the live command tree
# and diffs docs/CLI_REFERENCE.md, docs/cli-reference/, and the CLI

View file

@ -11,7 +11,7 @@
# 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/*_embedded_test.go. --write is
# 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
@ -59,105 +59,206 @@
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
@ -222,6 +323,7 @@
100 71 TestEmbeddedCloseJSONReportsMoleculeAutoClose
100 71 TestEmbeddedInitRoleRoutingExplicitDefault
100 71 TestEmbeddedPrimeChangeDirRedirectNoticeFollowsTarget
100 71 TestEmbeddedRoutedCreateHonorsTheEnvOverrideOverTheTargetsConfig
100 71 TestEmbeddedSearchRoutesAgree
100 72 TestEmbeddedContributorCreateMultiple
@ -332,8 +434,10 @@
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
@ -342,8 +446,10 @@
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

View file

@ -176,14 +176,17 @@
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
@ -193,6 +196,7 @@
40 6 TestEmbeddedRelationsAnswersAWispTargetInTheOutDirection
40 6 TestPromoteStillWorksWithCollisionGuard
40 6 TestSearchWithMissingWispPlaneTables
40 6 TestVersionedHistoryKeepsNumbersTheStoreDistinguishesApart
40 7 TestConcurrencyMultiProcess
40 7 TestEmbeddedBatchCloserRecordsOneHistoryEntryForWhatLanded
@ -201,17 +205,20 @@
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
@ -230,8 +237,10 @@
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
@ -251,6 +260,7 @@
40 12 TestEmbeddedReadyClaimerAnswersTheQuestionReaderReadyLists
40 12 TestHistoryPresenceContract
40 12 TestLifecycleUpdateContract
40 12 TestReaderListExcludeStatusAcceptsAWorkspaceCustomStatus
40 13 TestEmbeddedDepRekeyConvergesRenameChain
40 13 TestEmbeddedDependencyEditorAppliesParentChildBeforeBlockingEdges
@ -271,6 +281,7 @@
40 14 TestEmbeddedReaderReadyDefaultTypeExclusionsYieldToAnExplicitType
40 14 TestEmbeddedReadyClaimerClaimsTheFrontRowAndReturnsThePostClaimState
40 14 TestEmbeddedReadyClaimerDoesNotMutateTheCallerRequest
40 14 TestHeartbeatIssueCommitsARefusalOnlyWhenItReadTheIssueEmbedded
40 14 TestHistory_NullTextColumns
40 15 TestCreateIssuesRejectStaleUpserts
@ -307,6 +318,7 @@
40 17 TestStatsReporterContract
40 17 TestVersionReconcilerContract
40 18 TestCreateBatchParticipationGeneration
40 18 TestEmbeddedBatchCloserIdempotentRecloseIsAPerItemSuccess
40 18 TestEmbeddedDependencyEditorMixedBatchWritesBothPlanes
40 18 TestEmbeddedIssueOperationsUpdateRawMetadataTakesTheFunnelsValueShapes
@ -326,9 +338,11 @@
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
@ -340,6 +354,7 @@
40 20 TestHeartbeatRejectsWispEmbedded
40 20 TestIgnoredCursorHealNeverResurrectsRolledBackVersions
40 21 TestBumpEpochCarryingCarriesTheLiveRowsOfEveryStoreInTheDatabase
40 21 TestCreateRejectsCrossTableIDCollision
40 21 TestEmbeddedBatchCloserItemsAnswerToTheCloseGuards
40 21 TestEmbeddedDependencyEditorAcceptsATypeOutsideTheConstants
@ -363,6 +378,7 @@
40 22 TestLeaseLifecycleEmbedded
40 22 TestPolicyBlockingAnnotatorForeignOpensAreSublinear
40 23 TestAsOfReadContract
40 23 TestEmbeddedBatchCloserBackendFailureReturnsNoOutcomes
40 23 TestEmbeddedBatchCloserClaimNextHydratesWhenSomethingClosed
40 23 TestEmbeddedDependencyEditorAcceptsBlockingAcrossIssueTypes
@ -388,12 +404,14 @@
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
@ -423,6 +441,7 @@
40 27 TestRemoteGitDataRefOnEngine
40 27 TestSweeperContract
40 28 TestBumpEpochCarryingDoesNotCarryALostLineage
40 28 TestEmbeddedBatchCloserForceBypassesOnlyClosePolicy
40 28 TestEmbeddedBatchCloserSettlesTheDependersOfWhatItClosed
40 28 TestEmbeddedClaimerClaimsAnUnassignedOpenIssueAndAnswersTheBareRow
@ -441,6 +460,7 @@
40 29 TestEmbeddedDependencyEditorRecordsOneHistoryEntryPerLandedRequest
40 29 TestEmbeddedMergeAndSettleMetadataConflict
40 29 TestEmbeddedReaderListDefaultExclusionsAndTheirOverrides
40 29 TestEmbeddedReaderListTimeBoundsAreStrictAndWholeSecond
40 29 TestEmbeddedReaderReadySetOwnsItsStatusPinnedAndTemplateDecisions
40 29 TestEmbeddedTransactionSameStatusDoesNotPublishUnrelatedDurableChanges
40 29 TestEventsJournalAccessor
@ -459,6 +479,7 @@
40 30 TestLegacyTrackedIgnoredCursorUnwedgesPull
40 30 TestUpdateMergeOps_DoltEngine_TwoIssues
40 31 TestBumpEpochCarryingWritesOneCarryRowPerLiveIDNamingTheLineageRoot
40 31 TestDualWriteContract
40 31 TestEmbeddedDependencyEditorAcceptsAForeignRepoTarget
40 31 TestEmbeddedDependencyEditorMaintainsBlockedStateAcrossPlanes
@ -471,6 +492,7 @@
40 31 TestReadyCounterContract
40 31 TestWithPeerAuth_KeyMismatchFailsClosed
40 32 TestCurrentAddressForNeverReseedsAnAbsentStoreEpochRow
40 32 TestEmbeddedClaimerGrantsALiveLeaseOnTheRowItWonAndLeavesARefusedOneAlone
40 32 TestEmbeddedDependencyEditorRefusesAMissingLocalTarget
40 32 TestEmbeddedDirtyTablesGate_BlocksReopenThenWorkingSetReconcileRecovers
@ -491,11 +513,13 @@
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
@ -519,6 +543,7 @@
40 35 TestReadyWorkWithMissingDeferredParentTables
40 35 TestReclaimExpiredLeaseSurvivesRestartEmbedded
40 36 TestBumpEpochCarryingFailsAndRollsBackWhenARowAlreadyExistsAtTheNewEpoch
40 36 TestCommenterContract
40 36 TestConcurrentOpenReturnsCached
40 36 TestEmbeddedBatchCloserAllRefusedBatchRecordsNoHistory
@ -541,6 +566,7 @@
40 37 TestEmbeddedMergeAndSettleReportsOperatorConflicts
40 37 TestEmbeddedReaderListBriefDropsTheFreeFormTextAndNothingElse
40 37 TestEmbeddedReaderListNaturalNumericIDSortTrimsAfterTheFetch
40 37 TestEpochWritesReportAnUnpublishedCommitAsIndeterminate
40 37 TestIgnoredCursorHealRespectsOverrideUnderBroaderPattern
40 38 TestCreateIssues
@ -564,6 +590,7 @@
40 39 TestEmbeddedMigrateRepairedDependenciesIDColumnCommitsAtomicallyWithVersion53_4690
40 39 TestEmbeddedReaderListSkipCountsDropsTheCardinalitiesAndNothingElse
40 39 TestEmbeddedRelationsResolvesAWispAnchor
40 39 TestParticipationGenerationFence
40 39 TestPreviewStoreRefusesLocalMetadataWrite
40 39 TestReclaimRefusesForeignReplicaLease
40 39 TestWorkspaceConfigContract

View file

@ -3,7 +3,7 @@
#
# Usage: embedded-test-shard.sh <shard_number> <total_shards>
#
# Discovers all TestEmbedded* top-level functions from cmd/bd/*_embedded_test.go.
# Discovers all TestEmbedded* top-level functions in cmd/bd/*_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,8 +33,12 @@ fi
SHARD_INDEX=$(( SHARD_NUMBER - 1 ))
MANIFEST="${BEADS_TEST_SHARD_MANIFEST:-.github/scripts/embedded-cmd-test-shards.txt}"
# Discover all top-level TestEmbedded* functions.
ALL_TESTS=$(grep -rh '^func TestEmbedded' cmd/bd/*_embedded_test.go \
# 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 \
| sed 's/func \(TestEmbedded[A-Za-z0-9_]*\).*/\1/' \
| sort -u)

View file

@ -69,6 +69,7 @@
34 6 TestProxiedServerServeReadsTheJournalItJustWrote
34 6 TestProxiedServerSwarm
34 6 TestProxiedServerUpdate2B
34 6 TestProxiedServerVersionedHistorySwitchRefusesAnUnrecordableGateTimeout
34 6 TestProxiedServerWispList
34 7 TestProxiedServerCloseConcurrent
@ -156,6 +157,7 @@
34 17 TestProxiedServerPrime
34 17 TestProxiedServerSQLDatabaseFlag
34 17 TestProxiedServerServeModeGate
34 17 TestServerModeServeIgnoresGraphModeDependency
34 18 TestProxiedServerClose3
34 18 TestProxiedServerCount
@ -254,11 +256,13 @@
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

View file

@ -1085,7 +1085,7 @@ jobs:
outputs:
result: ${{ steps.result.outputs.result }}
env:
PURE_CMD_BD_TESTS: '^Test(Help|CheckRemoteSafety|FormatDestroyToken|ShouldWireInitRemote|ExtractPrefix|IsNumericID|GetWorktreeGitDir|DriftItemStatuses|RunDriftChecks|IsServerProbablyRunning|CheckHooksDriftNotGitRepo|CheckServerDriftNoBeadsDir|CheckRemoteDriftNoBeadsDir|NocgoFactoriesHonorSharedServer|NocgoNewDoltStoreFromConfig_ErrorSuggestsCorrectFlag|NocgoNewReadOnlyStoreFromConfig_ErrorSuggestsCorrectFlag)'
PURE_CMD_BD_TESTS: '^Test(Help|CheckRemoteSafety|FormatDestroyToken|ShouldWireInitRemote|ExtractPrefix|IsNumericID|GetWorktreeGitDir|DriftItemStatuses|RunDriftChecks|IsServerProbablyRunning|CheckHooksDriftNotGitRepo|CheckServerDriftNoBeadsDir|CheckRemoteDriftNoBeadsDir|NocgoFactoriesHonorSharedServer|NocgoNewDoltStoreFromConfig_ErrorSuggestsCorrectFlag|NocgoNewReadOnlyStoreFromConfig_ErrorSuggestsCorrectFlag|NocgoStoreFactoriesRefuseGraphWorkspace)'
# The only pre-merge run of these boundaries: where it executes
# remotely --config=sole-run fails on a remote cache eviction instead
# of re-running the whole invocation (whose retry could turn a failed

View file

@ -126,9 +126,29 @@ make install # build and install bd to ~/.local/bin (canonical)
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.
- `go test` (`./scripts/test.sh`, `make test-go`) is an inner-loop
convenience only. CI does not enforce it, and it skips nogo, gofmt and the
guards; finish with `make test`.
- Agents run tests only with `bazel test`, also while iterating on one
behavior:
```bash
bazel test //cmd/bd:bd_test --config=ci --test_filter='^TestName$' --test_output=all
```
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`,

View file

@ -74,6 +74,13 @@ exports_files(
visibility = ["//scripts:__pkg__"],
)
# //scripts:shell_scripts_test: Oracle A's runner, whose EXIT-trap removal of
# its reference worktree oracle_a_script_test.go checks in a fixture repository.
exports_files(
["tests/oracle-a/run-oracle-a.sh"],
visibility = ["//scripts:__pkg__"],
)
# The nested Go modules' go.mod files, which mark where the root module ends:
# //scripts:go_test_sources_test's scan of every _test.go file skips their
# trees, as `go test ./...` does. (go.mod is in no Go partition below: it is
@ -246,6 +253,20 @@ exports_files(
visibility = ["//internal/httpclient/encode:__pkg__"],
)
# --- begin go_srcs (managed by tools/bazel/go_srcs.py; run `make bazel-sync`) ---
filegroup(
name = "go_srcs",
srcs = glob(
["**/*.go"],
allow_empty = True,
exclude = ["bazel-*/**"],
),
visibility = ["//:__subpackages__"],
)
# --- end go_srcs ---
# --- begin repo_files (managed by tools/bazel/go_srcs.py; run `make bazel-sync`) ---
filegroup(
@ -344,6 +365,7 @@ filegroup(
"//internal/httpclient/encode:repo_doc_files",
"//internal/httpclient/wire:repo_doc_files",
"//internal/idgen:repo_doc_files",
"//internal/initprocs:repo_doc_files",
"//internal/jira:repo_doc_files",
"//internal/linear:repo_doc_files",
"//internal/lockfile:repo_doc_files",
@ -383,6 +405,7 @@ filegroup(
"//internal/storage/externaldeps:repo_doc_files",
"//internal/storage/fs:repo_doc_files",
"//internal/storage/git:repo_doc_files",
"//internal/storage/historyoffequiv:repo_doc_files",
"//internal/storage/issueops:repo_doc_files",
"//internal/storage/journalscan:repo_doc_files",
"//internal/storage/kvkeys:repo_doc_files",
@ -413,6 +436,7 @@ filegroup(
"//internal/utils:repo_doc_files",
"//internal/validation:repo_doc_files",
"//internal/versioncheck:repo_doc_files",
"//internal/versionedhistory:repo_doc_files",
"//internal/workapi:repo_doc_files",
"//internal/workapi/storecounter:repo_doc_files",
"//internal/workapi/storequerier:repo_doc_files",
@ -578,6 +602,7 @@ filegroup(
"//internal/httpclient/encode:repo_go_srcs",
"//internal/httpclient/wire:repo_go_srcs",
"//internal/idgen:repo_go_srcs",
"//internal/initprocs:repo_go_srcs",
"//internal/jira:repo_go_srcs",
"//internal/linear:repo_go_srcs",
"//internal/lockfile:repo_go_srcs",
@ -617,6 +642,7 @@ filegroup(
"//internal/storage/externaldeps:repo_go_srcs",
"//internal/storage/fs:repo_go_srcs",
"//internal/storage/git:repo_go_srcs",
"//internal/storage/historyoffequiv:repo_go_srcs",
"//internal/storage/issueops:repo_go_srcs",
"//internal/storage/journalscan:repo_go_srcs",
"//internal/storage/kvkeys:repo_go_srcs",
@ -647,6 +673,7 @@ filegroup(
"//internal/utils:repo_go_srcs",
"//internal/validation:repo_go_srcs",
"//internal/versioncheck:repo_go_srcs",
"//internal/versionedhistory:repo_go_srcs",
"//internal/workapi:repo_go_srcs",
"//internal/workapi/storecounter:repo_go_srcs",
"//internal/workapi/storequerier:repo_go_srcs",
@ -797,6 +824,7 @@ filegroup(
"//internal/httpclient/encode:repo_go_test_srcs",
"//internal/httpclient/wire:repo_go_test_srcs",
"//internal/idgen:repo_go_test_srcs",
"//internal/initprocs:repo_go_test_srcs",
"//internal/jira:repo_go_test_srcs",
"//internal/linear:repo_go_test_srcs",
"//internal/lockfile:repo_go_test_srcs",
@ -836,6 +864,7 @@ filegroup(
"//internal/storage/externaldeps:repo_go_test_srcs",
"//internal/storage/fs:repo_go_test_srcs",
"//internal/storage/git:repo_go_test_srcs",
"//internal/storage/historyoffequiv:repo_go_test_srcs",
"//internal/storage/issueops:repo_go_test_srcs",
"//internal/storage/journalscan:repo_go_test_srcs",
"//internal/storage/kvkeys:repo_go_test_srcs",
@ -866,6 +895,7 @@ filegroup(
"//internal/utils:repo_go_test_srcs",
"//internal/validation:repo_go_test_srcs",
"//internal/versioncheck:repo_go_test_srcs",
"//internal/versionedhistory:repo_go_test_srcs",
"//internal/workapi:repo_go_test_srcs",
"//internal/workapi/storecounter:repo_go_test_srcs",
"//internal/workapi/storequerier:repo_go_test_srcs",
@ -1025,6 +1055,7 @@ filegroup(
"//internal/httpclient/encode:repo_other_files",
"//internal/httpclient/wire:repo_other_files",
"//internal/idgen:repo_other_files",
"//internal/initprocs:repo_other_files",
"//internal/jira:repo_other_files",
"//internal/linear:repo_other_files",
"//internal/lockfile:repo_other_files",
@ -1064,6 +1095,7 @@ filegroup(
"//internal/storage/externaldeps:repo_other_files",
"//internal/storage/fs:repo_other_files",
"//internal/storage/git:repo_other_files",
"//internal/storage/historyoffequiv:repo_other_files",
"//internal/storage/issueops:repo_other_files",
"//internal/storage/journalscan:repo_other_files",
"//internal/storage/kvkeys:repo_other_files",
@ -1094,6 +1126,7 @@ filegroup(
"//internal/utils:repo_other_files",
"//internal/validation:repo_other_files",
"//internal/versioncheck:repo_other_files",
"//internal/versionedhistory:repo_other_files",
"//internal/workapi:repo_other_files",
"//internal/workapi/storecounter:repo_other_files",
"//internal/workapi/storequerier:repo_other_files",

View file

@ -9,6 +9,189 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- `bd versions <id>` lists the versions recorded for a bead, and
`versioned-history.enabled` turns recording on. While it is on, every
accepted change to a bead created while it is on, or that enters the issues
plane while it is on (a wisp promoted or made persistent), stores a
snapshot of it as a row of `issue_versions` in the same transaction. It is
off by default and nothing is backfilled: a bead already on the issues
plane when it is turned on is legacy, and editing it records nothing. A
recorded write leaves `updated_at` where an unrecorded one would, so
`bd import`'s stale check sees the same timestamps either way.
`bd versions --json` answers `{"versions": [...], "recording": bool}`; the
command still lists what was recorded after recording is turned off, and
proxied-server and HTTP workspaces refuse it. The setting is a row of each
store's `config` table (`bd config set versioned-history.enabled true`),
and every store reads its own when it is opened: a write routed into
another workspace (a prefix-routed `bd update` or `bd close`,
`bd create --repo`) follows the target store's row, a proxied-server
provider reads it when it is constructed, and a long-lived `bd serve`
keeps the value it read until it restarts.
`BD_VERSIONED_HISTORY_ENABLED=1` (or a `config.yaml` value) turns
recording on for every store the process opens, and never turns it off.
The row replicates on `bd dolt push`/`pull`, and recording is single-writer
only: two clones recording at once can mint the same revision and fail the
pull, and a write from a writer that is not recording is folded into the
next recorded version under that version's actor, so keep recording on for
every writer of a store or off for all of them. Turning it on with
`bd config set` first checks every issue the store would version and
refuses, writing nothing, while any holds a number outside the I-JSON
exact-integer range (magnitude above 2^53-1, however it is spelled) in its
metadata or in a gate's timeout (held as nanoseconds, so about 104.25
days), and prints the count, the ids, the field and the fix. There is no
override, and the check runs once; after that, a recorded write that would
hold such a number fails atomically. Migration 0071 adds a nullable
`removed_restriction` column to `issue_versions`. `bd version` now refuses
an argument and suggests `bd versions <arg>`, instead of printing bd's
build for a mistyped `bd version bd-123`.
- `bd blocked --flags` prints the blocked flag for each id read from stdin
(one per line; blank lines and repeats ignored), with `--json` as
`[{"id","is_blocked"}]` in the order the ids were given, omitting an id that
names no row on either plane. A closed id is answered too, with its stored
flag (a `status <> 'closed'` SQL read of the column leaves it out). It is the flag `bd ready` filters on, not the
listing: a row whose stored flag is set with no nameable blocker reads true
here and is absent from `bd blocked`. It runs `issueops.BlockedFlags` on
every route; over HTTP that is `listBlockingAnnotations` with `is_blocked`,
behind `dependencies.blocking.isBlocked`, refused before the dial against a
server that does not advertise it. The listing's filter flags are refused
with `--flags`.
- `bd blocked --flags --raw` answers the stored `is_blocked` column itself,
without the external-dependency policy: a row blocked only by an
unsatisfied `external:` ref reads `false` (the policy-aware `--flags`
reads `true`); a stale flag reads `true` either way. `--raw` is for the
local and proxied routes, where it reads the column directly and the two
answer the same. Over HTTP it is answered only by a server that does not
advertise `policy.external_dependencies` (whose flag is the column); a
server advertising it answers only the policy-aware flag, so `--raw`
against it is refused before the dial rather than answered with the
decorated flag. `--raw` without `--flags` is refused.
- `bd blocked` works over a connected HTTP workspace. The blocked listing is
a role, `issueops.BlockedLister` (`ListBlocked(BlockedRequest{ParentID,
Labels, LabelsAny, ExcludeLabels}) -> BlockedResult{Items}`), on every
backend leg over the same body `GetBlockedIssues` runs, and `bd serve`
publishes it as `GET /v0/beads/blocked` (`parent`, and the repeatable
`label`, `label_any` and `exclude_label`), answering `{items, has_more}`
with `BlockedIssue` rows (the element `bd blocked --json` prints), behind
the new `blocked.list` capability token (additive; no wire_revision bump).
The listing names unsatisfied `external:` blockers wherever the
external-dependency policy applies: on the server when it advertises
`policy.external_dependencies`, else on the client, as every other policy
read does. The HTTP backend's `BlockedLister()` and legacy
`GetBlockedIssues` dial it; against a server that does not advertise the
token they refuse before dialing with a typed capability error naming
`blocked.list`, and never compose the listing from other reads. The
listing is unpaged: a server answer that reports `has_more` is refused
with the new `httpclient.TruncatedListingError` rather than returned
short, and an answer over the client's 32 MiB response limit is refused
as any oversized response is. The external-dependency decorator's legacy
`GetBlockedIssues` over an HTTP store now reads the extra sources through
the served roles (it failed on a raw multi-id read before), so callers of
that door no longer fail on it; commands that also make other raw reads
the HTTP backend does not serve (`bd ready --explain`) still refuse on
those. `bd
blocked` runs the role on every route (the proxied-server route through
the provider's accessor) with unchanged output: `--json` prints the same
rows in the same order (priority, then newest first, then id, which now
also breaks a tie the order used to leave to chance), and `[]`, never
`null`, when nothing is blocked.
- `bd list`'s remaining filters work over a connected HTTP workspace.
`GET /v0/beads/issues` accepts `updated_after`/`updated_before`,
`closed_after`/`closed_before`, `defer_after`/`defer_before`,
`due_after`/`due_before`, `priority`, `priority_min`, `priority_max`,
`title_contains`, `desc_contains`, `notes_contains`, `external_contains`,
`external_ref`, `spec`, `label_pattern`, `label_regex`,
`empty_description`, `no_labels`, `no_parent`, a repeatable
`exclude_type`, `pinned`, `no_pinned`, `deferred`, `overdue`, `mol_type`
and `wisp_type`, behind one new capability token, `issues.list.filters`
(additive; no wire_revision bump; the names are `issues:count`'s where it
already spells the filter), and applies them through the same Reader role a
local `bd list` reads through. Bounds are strict and compared at
whole-second precision on both routes; relative and date-only values are
resolved on the client's clock and timezone as locally, while `--overdue`
compares against the server's clock. Against a server that does not
advertise the token the client refuses before dialing, naming
`issues.list.filters`, rather than sending a filter an older server rejects
or dropping one and answering a wider listing. The 29 corresponding
divergence-ledger refusal rows are removed. The default `bd list --parent`
tree view does not carry these filters yet: its descendant walk still
refuses one over HTTP rather than drop it, and `--flat` or `--json` skips
the walk and applies them to the parent's direct children (not its whole
subtree).
- `issueops.ListRequest.ExcludeStatus`: statuses to leave out of a listing,
appended to the default exclusions (never re-admitting what they hide),
comma-separated or repeated, each validated against the workspace's
statuses like `CountRequest.ExcludeStatus` (an unknown name is
`ErrValidation`). `GET /v0/beads/issues` accepts it as a repeatable
`exclude_status` under the same `issues.list.filters` token (an unknown
name is a `400` on `exclude_status`), so an HTTP-backed caller can leave
closed history out of an `all` listing (`all` plus
`exclude_status=closed` keeps every status not named, the `pinned` and
`hooked` statuses and custom done/frozen statuses included) instead of
reading the whole history. It is refused together with `ReadyFlag`, like the other
members the ready query cannot carry. There is no `bd list` flag for it
yet.
- `bd serve` publishes the gate members: `await_type`,
`await_id`, `timeout` (nanoseconds) and `waiters` on `POST
/v0/beads/issues` and on `issues:batchApply` create items, behind the new
`issues.create.gates` capability token, and `await_id` and `waiters` (a
whole-value replacement; `[]` clears) on the `patch` of `PATCH
/v0/beads/issues/{id}` and of `issues:batchApply` update items, behind
`issues.update.gates`. Additive; no wire_revision bump. The bounds are the
library role's, the same ones a local create or update now enforces (see
Changed), answered as `400 invalid_argument` with `param` naming the
member.
- `issueops.IssuePatch.Waiters`: a whole-value replacement of a gate's waiter
list (nil or empty clears it, stored as `[]`), on `Lifecycle.Update` and on
`BatchApplier` update items, on every backend. `issueops.GateFieldError`
(`Field`, `Detail`; wraps `ErrValidation`) names the gate member a create or
update refused, as one of the new `issueops.GateFieldAwaitType`,
`GateFieldAwaitID`, `GateFieldTimeout` and `GateFieldWaiters` constants.
- The HTTP client sends the gate members on create, update and
`issues:batchApply` (create and update items) to a server that advertises
`issues.create.gates` / `issues.update.gates`. Against an older server a
request naming any gate member is refused before the dial with a typed
capability error naming the missing token (never sent without the
member); a batchApply plan is checked whole, so no partial plan is sent.
A request naming no gate member is unaffected by either token.
- `bd heartbeat` works over a connected HTTP workspace.
The lease refresh is a role, `issueops.Heartbeater`
(`Heartbeat(HeartbeatRequest{Actor, IssueID}) -> HeartbeatResult{IssueID,
Holder, HeartbeatAt, LeaseExpiresAt, Rearmed}`), on every backend leg, and
`bd serve` publishes it as `POST /v0/beads/issues/{id}:heartbeat` behind the
new `issues.heartbeat` capability token (additive; no wire_revision bump),
with the new `lease_not_held` (409) problem code (`reason: ephemeral` for a
wisp). A refresh writes ONLY the lease row: the issue's `revision` is not
reminted (a guarded write against the pre-heartbeat token still lands), no
version, event, journal entry or Dolt commit is recorded, and no hook
fires. `Rearmed` is true only when the heartbeat created the caller's lease
row (a hand-doled claim's first heartbeat). A re-arm is recorded as a
mutation; a refresh is not: the re-arm remints `revision`, stamps
`updated_at`, records a `lease_rearmed` event, a journal entry and a
version, makes a Dolt commit and fires `on_update` (see Fixed); the
reported times are whole seconds, exactly what the lease row stores. The
HTTP backend's `Heartbeater()` and legacy `HeartbeatIssue` dial it;
against a server that does not advertise the token they refuse before
dialing with a typed capability error naming `issues.heartbeat`, and never
fall back to a re-claim or a metadata stamp. A
busy (503) answer is replayed, because a repeat only moves the expiry later.
`bd heartbeat` now runs the role on every route (the proxied-server route
through the provider's accessor), with the same
`{"id","status":"heartbeat","owner"}` success output and the same exit
codes. Refusal TEXT on stderr changes per route: the direct routes (Dolt
server, embedded) gain a `lease not held: ` prefix
(`heartbeat X: lease not held: issue not claimable: X status closed`); the
proxied-server route loses its
`Heartbeat: db: IssueSQLRepository.HeartbeatIssue: ` prefix and reads as the
direct routes do; over HTTP the refusal is the problem's detail, which names
the state found (`it is closed`, `an ephemeral wisp`, `open and not
claimed`) or, for a foreign holder, the native `issue already claimed by
<holder>`. An id that names no row answers not-found from the role rather
than "not claimable" (the CLI resolves the id first, so its output is
unchanged), and every refusal for a caller that holds no live claim
(closed, released, reclaimed, moved off in_progress, or a wisp) is
`issueops.ErrLeaseNotHeld`, which still matches `ErrNotClaimable`.
- `GET /v0/beads/dependencies/blocking` accepts `is_blocked`, behind the new
`dependencies.blocking.isBlocked` capability token (additive; no
wire_revision bump), and answers each item's stored, transitive
@ -316,6 +499,80 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Over an HTTP workspace, `bd ready --json` without `BD_JSON_ENVELOPE` no
longer sends `GET /v0/beads/ready:count` after a page the limit cut short:
the total only went into the stderr hint. It lists one row past the limit
instead, and the hint says more issues matched without saying how many
(the wording the proxied-server route already uses). A local store, and the
envelope's `pagination.total`, keep the total.
- `bd` initializes its packages with `GOMAXPROCS` capped at 4 and hands it
back before `main` runs anything, so the garbage collections package
initialization triggers do not stop the world across every CPU of a large
host. On a 192-CPU machine this takes about 17 ms off every bd process. An
explicit `GOMAXPROCS` is restored as set.
- Over an HTTP workspace, `bd ready` no longer fetches `GET /v0/beads/context`
before its listing in every process only to learn whether the server
enforces the external-dependency policy. The answer is kept for 5 minutes
per server URL and pinned project under the user cache directory
(`BEADS_HTTP_POLICY_CACHE_TTL`, a duration, a number of seconds, or `off`),
and a handshake the process already holds still wins. Claims and closes
always ask the server.
- `bd serve` normalizes every RFC 3339 time bound on the issue listing and
count (`created_*`, `updated_*`, `closed_*`, and the new `defer_*` and
`due_*`) to UTC before it reaches storage. A bound carrying an offset
(`...+02:00`) now selects exactly what its `Z` twin does; previously a
backend whose timestamp column has no zone could read the offset bound's
wall clock and compare it hours off. `bd`'s own client always sent `Z`, so
its answers are unchanged.
- `bd serve` answers a `label_regex` the database cannot compile with
`400 invalid_argument` (`invalid_value` on `label_regex`) on
`GET /v0/beads/issues`, `GET /v0/beads/ready`, `GET /v0/beads/ready:count`
and `POST /v0/beads/issues:claimNext`, instead of `500 internal`. The pattern is
still compiled by the database in its own dialect; only the attribution
of its refusal changed.
- `issueops.Reader.List` refuses `PinnedFlag` together with `NoPinnedFlag`
with `ErrValidation` (`--pinned and --no-pinned are mutually exclusive`) on
every backend; it used to let `PinnedFlag` win silently. `bd list` already
refused the pair at flag parse, so its behavior is unchanged; over HTTP the
pair is a `400 invalid_argument` on `no_pinned`.
- `issueops.Reader.List` refuses `ParentID` together with `NoParent` with
`ErrValidation` (`--parent and --no-parent are mutually exclusive`) on
every backend, as `CountRequest` already did; it used to answer with only
the edge-less rows under the parent's dotted id, which both clauses match.
`bd list` already refused the pair at flag parse, so its behavior is
unchanged; over HTTP the pair is a `400 invalid_argument` on `no_parent`.
- **`bd gate discover` skips template gates, as `bd gate check` does.** A
template gh:run gate is a proto that work is poured from; on the direct,
proxied and embedded routes `bd gate discover` used to record a discovered
run ID on it, which every later pour copied. It is now left alone on every
route. `bd gate add-waiter` on a template gate is refused by the update
role's template guard, where the direct, proxied and embedded routes all
used to write the waiter.
- **`bd gate create` refuses a negative `--timeout` on every route**
(`timeout cannot be negative`); the direct, proxied and embedded routes
used to store it. A `--type` longer than 32 characters fails with the same
typed validation error instead of a raw Dolt column error.
- **`bd gate create` and `bd gate add-waiter` follow `dolt.auto-commit`
like every other role write.** Under `dolt.auto-commit=off` `bd gate
create` no longer makes its own Dolt commit on the direct and embedded
routes (the proxied route already did not). The Dolt commit messages are
the role's: `bd: create gate X blocking Y` becomes the create's default
message, and `bd gate add-waiter`'s becomes the update's (`bd: update X`
on the direct and embedded routes, `update issue` on the proxied route).
On the proxied route `bd gate create` no longer journals a
`dependency_added` event on the blocked issue, matching the direct route
and `bd create --deps`.
- **Gate members are bounds-checked in the library, on every local backend.**
`issueops.Lifecycle.Create`, `Lifecycle.Update` and `BatchApplier` (create
and update items) now refuse, with a typed `*issueops.GateFieldError`
wrapping `ErrValidation`: a negative `Timeout` (previously accepted and
stored), an `await_type` over 32 characters, an `await_id` over 255
characters, and a waiter list whose JSON encoding exceeds its TEXT column
(65535 bytes). Creates check all four; an update can change only
`await_id` and `waiters`, so it checks those two. The over-width values
previously failed with a raw Dolt driver error. There is no `await_type` vocabulary, no gate-type-only rule
and no waiter deduplication.
- **Over an http workspace, a bd command answers its repeated reads of a row
or setting from one response.** `bd show <id> --json` makes one request
instead of three, text `bd show` three instead of six, and `bd update`,
@ -524,6 +781,322 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- An HTTP workspace whose server cannot be reached now says which step
failed. A connect that is refused names the address and says nothing is
listening; one that times out (a filtered port, a down host) names the
address that never answered and how long it waited; a host name that does
not resolve is named as such. The error was the transport's
`Get "https://…/v0/beads/context": dial tcp …: i/o timeout`, which named the
request rather than the address.
- **`bd link` works over a connected HTTP workspace.** It wrote through the
store's raw `AddDependencyWithOptions`, which the HTTP client refuses, so
every `bd link` failed there with `operation "AddDependencyWithOptions" not
supported by the http backend`, whatever the type. It now writes through
the `DependencyEditor` role, the route `bd dep add` takes, on the direct
and HTTP routes alike (the proxied-server route is unchanged). Over HTTP
that is one `dependencies:add` request, so `bd link` keeps accepting any
non-empty type of at most 32 characters (`owned-by`, `ships-in`, ...).
An empty or over-long type is still refused before anything is written,
and an edge that already exists with another type still reports the typed
conflict. On a Dolt store the history commit is now the role's, like
`bd dep add`'s: `bd: dep add <from> <to>` in place of
`dependency: add <type> <from> -> <to>`.
- **`bd query` reports an uppercase duration unit as an unparseable time, not
a negated internal error.** `created>30M` failed with
`not a compact duration: "-30M"`, naming a value nobody typed; it now fails
with `cannot parse time expression: "30M"`. A signed spelling
(`created>+30M`) stops at the parser, as `created>+30x` already did, so
quote one to match it as a literal (`label="+30M"`). Units remain lowercase
(`30min`, `6h`, `7d`, `2w`, `3m`, `1y`); help and docs already say so.
- **Strict `--readonly` no longer creates workspace gate files.** A
`bd --readonly` command took its shared workspace gates with
create-if-missing, so on a workspace no bd command had gated yet it left
`<project>/.beads.gate.lock` and the physical-root gate file
(`.beads/embeddeddolt.gate.lock` or `.beads/dolt.gate.lock`) behind, although
strict readonly promises not to mutate the workspace. It now opens an
existing gate file read-only and holds it shared as before, so a maintenance
operation still sees it and a running one still makes it wait; when no gate
file exists it holds nothing. Every other command still creates the files.
- **Strict `--readonly` refuses `bd backup init`, `backup sync`,
`backup remove`, `backup restore` and `bd import`.** None of them checked
readonly mode. On a server-mode store they ran to completion under
`--readonly`: `backup init` and `backup remove` rewrote or emptied the
server's backup registry, `backup sync` wrote the backup destination,
`backup restore --force` replaced the store, and `import` wrote issues. On
an embedded store they failed with the storage layer's `store is read-only`
error instead, after `backup sync` had left `.beads/backup.lock` behind and
`backup restore` had left workspace-gate holder files. They now exit 1 with
the standard `Error: operation '<op>' is not allowed in read-only mode`,
and a restore is refused before it takes the exclusive workspace gate.
`bd import --dry-run` is refused too, as `bd create --dry-run` already is
and as a migration freeze already refuses it. `bd backup status` still runs
under `--readonly`.
- **`bd init --server --external` no longer starts a Dolt server of its own.**
Init builds its store config by hand and turned auto-start on for every
server init, so an `--external` init that named no port launched a
repo-local `dolt sql-server`, although `--external` says the server is
managed outside bd. `--external` now turns auto-start off. When the
external server cannot be reached, init gives one message on every route
(host and port, socket, shared server, auto-start pinned off): it names the
endpoint it dialed, says that bd did not start a server, and no longer
advises `bd dolt start`. With no port named at all, it asks for one
(`--server-port` or `BEADS_DOLT_SERVER_PORT`) instead of offering a default.
- **A failed `bd init --server` can be retried.** A first attempt that could
not reach its server left an empty `.beads/dolt` and nothing on disk that
records the server choice, so the legacy-upgrade guard refused every retry
as a "legacy Dolt workspace" and no bd command could repair it. When init
itself selects server mode, the guard now admits exactly that root: empty,
with no `.local_version` witness. A pre-1.0 witness, or a `.beads/dolt` that
holds anything, is still refused, and commands other than `bd init` are
decided as before.
- **A graph-mode workspace is refused instead of opened as an Issue store.**
Graph-preview builds mark their workspaces with `"graph_mode": "link"` and
`graph_*` binding fields in `metadata.json`, beside an ordinary Dolt
backend. bd opened such a workspace as an Issue store and ran Issue schema
initialization against the graph database, and every `metadata.json` rewrite
(including the `config.json` to `metadata.json` migration) dropped the
marker and the binding. Now any `graph_mode` other than `dependency`,
including a value bd does not recognize, makes every command that runs in
the workspace or names it with `--db` or `BEADS_DB` (`bd init`, `bd doctor`
and `bd bootstrap` included), and `bd create --repo` aimed at it, refuse it
before touching anything. The refusal names the format and exits with code
16, so installed beads git hooks refuse commits and pushes there too.
Commands that reach such a workspace only through a route from another
one, such as a routed `bd show`, fail without touching it, but not with
code 16. Store-less commands such as `bd version` and `bd help` still run.
A `metadata.json` rewrite keeps `graph_mode` and the `graph_*` fields
graph-preview builds write, and like those builds it omits a zero
`graph_schema_version` and a false `graph_ready`.
- **A graph workspace without `graph_mode` in its metadata is refused too.**
Graph-preview builds write a `.beads/graph-preview-format` marker before
`metadata.json`. bd ignored it. When an older bd had rewritten
`metadata.json` without `graph_mode`, bd opened the graph database by its
recorded name and ran Issue schema initialization against it; when
`metadata.json` was never written or was lost, bd fell back to the default
database name and created an Issue database inside the graph workspace, and
`bd init` initialized an Issue workspace there. A `.beads` holding that
marker, whatever it contains and whatever its metadata says (absent,
stripped, unparseable or an explicit `dependency`), is now refused wherever
a `graph_mode` workspace is: commands run in it or naming it with `--db` or
`BEADS_DB`, `bd create --repo` aimed at it, and `bd bootstrap` in a
workspace below it that would take its metadata exit with code 16 and a
hint to restore `metadata.json`, and routed and cross-repository opens fail
without opening its database.
- **The Go library's opens refuse a graph workspace too.**
`beads.OpenBestAvailable`, `OpenBestAvailableWith`, `OpenFromConfig` and
`OpenGated` opened a workspace whose `metadata.json` declares a
`graph_mode` other than `dependency`, or whose `.beads` holds the
`graph-preview-format` marker, as an Issue store and ran Issue schema
migrations into the graph database. They now
return `*beads.UnsupportedWorkspaceFormatError` (match it with `errors.As`)
before opening, creating or changing anything, the same refusal the CLI
exits 16 with.
- **`bd setup claude --remove` no longer leaves a blank-line hole.** Removing
the beads section from `CLAUDE.md` (or, with the other setup recipes, from
`AGENTS.md` or `GEMINI.md`) left the blank lines around it behind, three in
the `CLAUDE.md` `bd init` writes, and setup then re-added the section after
two more, so every remove and re-add grew the file. `--remove` now takes
those blank lines with the section, and setup appends a section after one
blank line, so removing and re-adding it toggles between the same two files.
A re-added section goes at the end of the file.
- **`bd config set` no longer truncates a `config.yaml` that has a line of
64 KiB or more.** Setting an undotted key (such as `actor` or `no-db`)
rewrites the file line by line, and a line of 65,536 bytes or more ended
that read early without an error, so the command reported success and wrote
back only the lines before the long one, plus the key it set. Dotted keys
and `bd config unset` were not affected. Setting an undotted key in such a
file now fails with `bufio.Scanner: token too long`. `bd config set` leaves
the file as it was. `set-many` stops at that key, but it has already written
any `config.yaml` keys listed before it, such as a dotted `sync.remote`.
- **`bd show --as-of` exits 1 when it reads no issue.** A ref the Dolt AS OF
read does not take (an instant, a versioned-history address), a ref that
does not exist, or an issue that did not exist at the ref was reported on
stderr while the command exited 0 with nothing on stdout, even under
`--json`. It now ends the way plain `bd show` does: exit 1, with the JSON
error envelope on stdout under `--json`. A batch that reads at least one of
its ids still exits 0. Both the direct and the proxied-server routes
changed.
- **`bd list --format dot` prints the same graph the same way every time.**
Nodes are declared in id order and edges in source, target and type order.
They used to follow the listing order, which breaks a priority tie by
creation time to the second, so two equal-priority issues swapped places
depending on whether they were created in the same second, and the
proxied-server route did not pin the order of one issue's edges. `--sort`
and `--limit` still choose which issues are listed.
- **`bd init --quiet` no longer prints "Removed SessionStart hook" or "Removed
PreCompact hook"** when the project's `.claude/settings.json` (or the legacy
`.claude/settings.local.json`) still carries the bare `bd prime` hooks an
older bd registered. The hooks are still migrated to the SessionStart
`bd prime --hook-json` hook; the removal lines now go to the installer's own
output, which `--quiet` discards, instead of straight to stdout.
- **A new `AGENTS.md` from `bd init` lists `bd dolt push` in its Quick
Reference only when the workspace has a Dolt remote.** The managed Beads
section already left out its push lines when no Dolt remote is configured or
the workspace is `no-push`, but the Quick Reference above it still showed
`bd dolt push # Push beads data to remote`. It now follows the same rule.
`bd init` still leaves an existing `AGENTS.md` alone outside the managed
section, and writes an `--agents-template` as given.
- **`bd setup claude` no longer rewrites a CLAUDE.md whose beads section is
already current.** A rerun (and `bd init`, which runs it) wrote the same
bytes back as a new file, resetting its mode to 0644 and its mtime, and
reported "Updated existing beads section"; it now leaves the file alone and
reports the section current (the report `bd init` already gives a current
AGENTS.md). `bd setup factory`, `opencode`, `mux` and `gemini` share the
fix. A section whose END marker is missing or comes before BEGIN, which was
also reported as updated while nothing changed, is now reported as an error:
`bd setup factory`, `opencode` and `mux` exit 1 (`mux` before installing its
`.mux` hooks), while `claude` and `gemini` warn and carry on. When CLAUDE.md
is an `@AGENTS.md` stub and it is AGENTS.md that cannot be updated, `claude`
now names AGENTS.md in the warning and keeps the beads block left in the
stub, which it used to delete although AGENTS.md was never updated.
- **Time-bound filters and the keyset cursor compare the same instant on every
engine, whatever zone they are given in.** The storage filter builder binds
every time bound (`created_*`, `updated_*`, `closed_*`, `started_*`,
`defer_*`, `due_*`) as the UTC spelling of its instant. An engine whose
timestamp column carries no zone drops a literal's offset, so a `+02:00`
bound would have compared as that wall clock; Dolt already honored the
offset and `bd` resolves bounds to UTC, so no answer changes here. The
keyset cursor (`AfterCreatedAt`) is now bound in UTC too: embedded Dolt's
driver sends a `time.Time` as its wall clock with no zone, so a library
caller paging with a cursor in another zone was answered from the wrong
position there (server Dolt was unaffected).
- **`bd setup claude --global` keeps its beads section in `~/.claude/CLAUDE.md`.**
It wrote the section into the current directory's `CLAUDE.md`: run from your
home directory it created `~/CLAUDE.md`, which by default stops Claude Code
reading `AGENTS.md` in the projects below it, and `--remove --global`
stripped the section a project's own install had put in its `CLAUDE.md`
while leaving that project's hooks in place. A global install and removal now
use only the user-level files beside `~/.claude/settings.json`. A new
`~/.claude/CLAUDE.md` holds just the section, rendered the same whichever
project you run from. Claude Code loads that file in every project, so its
section, task-tracking rules included, applies only in repositories that use
beads. With global or plugin hooks `--check` accepts it when the project's
instructions have none, or names `--global` when it is missing and the
project has no `CLAUDE.md` of its own. Run from `~/.claude`,
or from your home directory unless `~/CLAUDE.md` still holds a section an
earlier run left there, `--check` judges the user-level files, and from your
home directory it names `--global` when no hooks are installed. From your
home directory, whose `.claude/settings.json` is the global one, `--remove`
removes the user-level section with the hooks. If you ran `--global` before,
re-run `bd setup claude --global` to add the section to `~/.claude/CLAUDE.md`.
A section an earlier `--global` run left in a directory's `CLAUDE.md` stays
there; delete it by hand if you don't want it.
- **`bd blocked --label`, `--label-any` and `--exclude-label` apply to a row
blocked only by an unsatisfied `external:` dependency.** The
external-dependency policy lists such a row itself, after the label query
has run, and it was listed whatever its labels; it is now narrowed by the
label filters like every other row, on every route. On the proxied-server
route such a row also printed with no labels; it now prints them.
- **`bd gate add-waiter` survives contention the store gave up replaying.**
It retried only a version miss, so a convoy adder failed when its guarded
write ended in a serialization failure or deadlock the backend stopped
replaying (Dolt/MySQL 1213/1205, Postgres 40001/40P01), or, over HTTP, in a
503 busy. Those are now retried, but at most twice: each arrives only after
the store or `bd serve` has spent a whole replay budget on the write (up to
15s), so the 20-write bound a version miss gets could hold an adder for
minutes. Each retry waits the jittered backoff plus a busy answer's
Retry-After, as `bd serve` sent it. The retry is safe because every round
re-reads the gate, deduplicates and writes the whole list guarded by the
version it read: a 503 is not proof that nothing was written (a gateway can
answer one after the commit), and a write that did land is found on the
re-read, so the waiter is never added twice; when the last write allowed is
answered busy, one more read checks for it before the command fails. A
server fault (500) and an unreachable database are still returned at once,
and once the retries run out the error says no write was confirmed and
names the write contention, instead of saying the gate kept changing.
- `bd list --title-contains X` works against an HTTP workspace. The client
folds it onto the listing's existing `title` parameter (the store compiles
both flags to the same case-insensitive substring predicate), so it needs
the `issues.list.title` capability, like `--title`. A `--title` and a
`--title-contains` that differ other than in letter case are two
predicates, so they ride `title` and `title_contains` together and also
need `issues.list.filters` (see Added), as does the `--closed-after` in
gascity's polecat pre-flight lookup of recently closed beads. Either flag
with `--parent` in the default tree view still refuses over HTTP.
- **`bd gate create`, `bd gate add-waiter` and `bd gate discover` work over a
connected HTTP workspace.** They wrote through the legacy `CreateIssue`,
`AddDependency` and map-based `UpdateIssue`, which the HTTP store does not
implement, so each failed before any gate member reached the wire. They now
run through the library roles on every route:
- `bd gate create` is ONE `Lifecycle.Create` carrying the gate members and
a reverse `blocks` edge from the blocked issue to the new gate, so the
gate and its edge land atomically (one `createIssue` over HTTP, behind
`issues.create.gates`). The direct route used to make two writes and an
explicit commit; the proxied-server route now uses the same role.
- `bd gate add-waiter` reads the gate through `Reader.Get`, deduplicates,
and writes the whole waiter list through `Lifecycle.Update` guarded by
the row version it read. On a version mismatch it re-reads and retries
after a jittered, doubling backoff (10 ms up to 400 ms per wait, at most
20 writes), so a convoy of workers registering on one gate at once all
succeed. On the direct route concurrent adders used to lose
each other's waiters while every one exited 0; no waiter is lost now.
Over HTTP it needs `issues.update.gates`.
- `bd gate discover` lists through `issueops.ListGates` (as `bd gate check`
does) and records each discovered run ID through `Lifecycle.Update`, the
same `await_id` write `bd gate check` and `bd close` make. Over HTTP it
needs `issues.update.gates`. Its summary now counts only the gates whose
run ID was recorded, and it exits non-zero when any matched gate's write
failed (it used to report such a gate as updated and exit 0).
Against a server that does not advertise the token it needs, `bd gate
create` and `bd gate add-waiter` are refused before any write, naming the
token; `bd gate discover` writes nothing and reports the token as that
gate's error. The served corpus gains `mc-gate-create-timer`,
`mc-gate-check-timer-resolves`, `mc-gate-add-waiter` and
`mc-update-await-id` (pending until the reference server advertises the
gate tokens), pinned passing by `TestE2E_GatesOverHTTP`.
- **`bd import` no longer reports a failed dependency check as a skipped
dependency.** Import skips an edge the dependency checks refuse (a
self-dependency, a cycle, or a blocker that is the issue's own ancestor or
descendant) and reports it on a `Skipped dependency:` line, or in
`skipped_dependencies` with `--json`. It did the same when the check's own
query failed, for example on a timeout, a dropped connection or a statement
the backend could not run: the SQL error became the skip reason, and on
Dolt, where the transaction survives a failed statement, the import
committed without the edge and exited 0. Such an error now fails the
import. Refused edges are still skipped as before.
- **`bd mol bond <A> <B>` ignored prefix routing** — operand resolution now uses
the same routing fallback as `bd show`/`bd update`/`bd close`, so a bead that
lives in a routed store (a prefix-routed rig via `routes.jsonl`, or the
contributor planning store) resolves instead of failing with `'<id>' not found
as issue or formula`. Previously `bd mol bond` resolved operands
against the local store only, so `gt sling <bead> <rig>` — which cooks the
default formula and bonds it to a rig-routed bead — died at `bd mol bond` even
though `bd show <bead>` resolved the same ID. Resolution is write-intent: the
routed target opens writable and the bond commits where the bead lives. Two
operands that live in the same routed rig share one store handle and bond
normally; only a bond whose operands resolve to genuinely different databases
is rejected rather than written to the wrong one. As part of this change, an
auto-route — contributor, maintainer or default — now opens writable for the
commands that change an existing issue (`bd update`, `bd close`,
`bd comment`, `bd unclaim`, `bd dep` and the other routed mutation commands,
as well as `bd mol bond`), so the write commits where the issue lives: for a
contributor, in the planning repository, as the contributor workflow
documents. Every auto-route used to open read-only, so on an embedded
workspace these writes were refused. `bd unclaim` now opens a routed issue
writable, as `bd update --claim` does, and commits the release there; on an
embedded workspace `bd human respond` and `bd human dismiss` now record a
routed change as a Dolt commit in the routed repository instead of leaving it
uncommitted in that repository's working set. A routed
write, prefix or auto, never creates the target's database: an embedded
repository that has not been bootstrapped yet fails the write instead of
gaining an empty database that `bd bootstrap` would then take for the real
one. An auto-routed store, read or write, now opens the target's own
configured `dolt_database`, as a prefix route already did, even when
`BEADS_DOLT_SERVER_DATABASE` names the current workspace's database. An
auto-routed write refuses a target whose `metadata.json` is unreadable or
names no `dolt_database`, while a target with no `metadata.json` at all (a
planning repository nothing has been created in yet) opens the one embedded
database it holds, or its default database when it holds none or several; a
prefix route still requires the target's `dolt_database`. A
routing failure, such as an unreadable `routes.jsonl` or a
routed store that fails to open, is now reported as itself instead of as
`no issue found matching`. Same routing-parity fix as
[#3608](https://github.com/gastownhall/beads/issues/3608) for `bd close`.
Fixes [#4714](https://github.com/gastownhall/beads/issues/4714).
- **`bd gate check` works over a connected HTTP workspace.** Its open-gate
listing built the same raw `SearchIssues` filter `bd gate list` did before
S20, so the HTTP backend refused the command before reading a gate and gc's
@ -536,11 +1109,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`UpdateIssue`, which the HTTP store does not implement, so every open bead
gate with an open target was an error on every sweep; it now goes through
the Lifecycle role's `Update` (a single-key metadata set, `issues.update` on
the wire), as does the gh:run discovery's `await_id` persist. The HTTP
client still refuses the `await_id` patch before the dial, so a gh:run gate
with a workflow-name hint stays that gate's error, now naming the run and
the server that does not accept the `await_id` update rather than a Go
method. The sweep also skips the gates of a persisted proto
the wire), as does the gh:run discovery's `await_id` persist, which the
HTTP client sends to a server that advertises `issues.update.gates` (see
Added). Against an older server it refuses that patch before the dial, so a
gh:run gate with a workflow-name hint stays that gate's error, naming the
missing token and the server rather than a Go method.
The sweep also skips the gates of a persisted proto
(`bd cook --persist`): they are templates that every pour copies, so a
write to one was refused on every sweep and, in a local workspace, a
resolved one (an expired timer, say) was closed in the proto itself. The
@ -568,6 +1142,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1,000 listed rows: +0.07 s at 1,000 rows and +0.46 s at 4,000 on embedded
Dolt. A store with many wisps, whose edges the old read also scanned, is
faster at every page size.
- A heartbeat can no longer resurrect a lease after a release or close. A
heartbeat re-arming a hand-doled claim (in_progress with no lease row) could
race a release or close on Dolt and leave an orphaned lease row on an open
or closed issue; every later heartbeat by the former holder then refreshed
it and answered success for a claim it no longer held. This affected every
Dolt route, including releases before this one. The re-arm is now recorded
as a mutation and remints the issue's row_lock, which every claim-ending
path rewrites, so it collides with a racing release or close and one side
is replayed against the other's result (the cost: a hand-doled claim's
first heartbeat changes its `revision` once). The refresh also requires, in
the same transaction, that the issue is still in_progress under the holder,
and a refusal deletes the caller's orphaned lease row, so a lease row
orphaned any other way never answers a heartbeat. A refresh and a refusal
still make no Dolt commit on any route; a re-arm commits only its own
tables (never `DOLT_COMMIT('-Am')`), so another writer's uncommitted
batch-mode edits to other tables stay uncommitted (a re-arm stages its
tables whole, as every other direct-route write does). On embedded Dolt, a heartbeat landing in
the same second as the previous one no longer re-grants the lease
(rewriting its `granted_at` / `granted_node`), and on every route a
heartbeat whose actor is a different spelling of the lease's holder
(`gastown.mayor` for `gastown__mayor`) refreshes the lease in place,
keeping its `granted_at` and granting replica, instead of re-granting it
under this node. For a Postgres port: the
refresh now reads the issue row, so under SERIALIZABLE expect more retried
serialization failures between a holder's own edits and its heartbeat.
- **`bd gate list` works over a connected HTTP workspace** (S20). The
workspace-wide listing built a raw `SearchIssues` filter, which the HTTP
backend refuses, so gc's `renudge-stale-human-gates` order failed on every

View file

@ -275,16 +275,40 @@ 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. `off` turns off only the
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`).
(`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

View file

@ -145,7 +145,8 @@ Before starting a release:
- [ ] All tests passing (`make test`, the Bazel test lane)
- [ ] 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** (`make test-regression`)
- [ ] **Regression tests pass**
(`bazel test //tests/regression:regression_test --config=doltserver-cmd`)
- [ ] **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

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 | `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. |
| 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. |
| 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

@ -11,9 +11,11 @@ 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",
@ -27,9 +29,11 @@ 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",
@ -38,7 +42,9 @@ go_library(
"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",
@ -59,6 +65,7 @@ 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",

View file

@ -0,0 +1,145 @@
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

@ -0,0 +1,426 @@
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

@ -71,11 +71,13 @@ 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 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.
// 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.
// - 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

@ -0,0 +1,644 @@
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

@ -0,0 +1,837 @@
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

@ -0,0 +1,170 @@
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

@ -0,0 +1,133 @@
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

@ -3175,6 +3175,335 @@ 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,7 +769,21 @@ 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
@ -819,94 +833,258 @@ 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. 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.
// architecture doc's own words: an epoch voids what the store lost, never
// what it still serves.
//
// 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.
// 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.
func RunEpochBumpVoidsOnlyAddressesOfVersionsNoLongerServed(t *testing.T, ctx context.Context, fixture EpochFixture) {
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)")
}
store := epochStore(fixture, "voids")
epochSkipUnlessReady(t, fixture, false)
addrA, err := fixture.MintUnderEpoch(ctx, store, "record-a")
if err != nil {
t.Fatalf("MintUnderEpoch(record-a): %v", err)
// 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)
}
addrB, err := fixture.MintUnderEpoch(ctx, store, "record-b")
if err != nil {
t.Fatalf("MintUnderEpoch(record-b): %v", err)
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 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)
}
}
// 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)
}
newEpoch, err := fixture.BumpEpoch(ctx, store, EpochBumpTriggerRestore)
if err != nil {
t.Fatalf("BumpEpoch: %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)
}
servesA, err := fixture.StillServes(ctx, store, addrA)
if err != nil {
t.Fatalf("StillServes(%s): %v", addrA, 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)
}
servesB, err := fixture.StillServes(ctx, store, addrB)
if err != nil {
t.Fatalf("StillServes(%s): %v", addrB, 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")
}
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")
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)
}
stillServed, noLongerServed := addrA, addrB
if servesB && !servesA {
stillServed, noLongerServed = addrB, addrA
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)
}
}
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")
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)
}
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 -------------------------------------------------------
@ -953,6 +1131,137 @@ 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

@ -63,6 +63,7 @@ var roleContractCases = []roleContract{
RunBatchApplyCloseItemsAnswerToTheCloseGuards,
RunBatchApplyRefusesADottedChildGatedOnItsOwnParent,
RunBatchApplyAppliesTheDefaultPriority,
RunBatchApplyCarriesTheGateMembers,
),
roleCases("BatchCloser", "BatchCloser()", oncePerRole,
@ -463,6 +464,8 @@ var roleContractCases = []roleContract{
RunLifecycleCreateWritesEveryScalarField,
RunLifecycleCreateEchoesSubSecondTimestamps,
RunLifecycleCreateAppliesTheDefaultPriority,
RunLifecycleCreateWritesTheGateMembers,
RunLifecycleCreateBoundsTheGateMembers,
),
roleCases("LifecycleUpdate", "IssueLifecycle()", oncePerRole,
@ -494,6 +497,8 @@ var roleContractCases = []roleContract{
RunLifecycleUpdateProvenanceLabelsHistory,
RunLifecycleUpdateRefusesATemplate,
RunLifecycleUpdateAllowTemplateEditsATemplate,
RunLifecycleUpdatePatchesTheGateMembers,
RunLifecycleUpdateBoundsTheGateMembers,
),
roleCases("Memories", "Memories()", oncePerRole,
@ -599,6 +604,8 @@ var roleContractCases = []roleContract{
RunReaderListWispTypeNarrowsTheAdmittedPlaneRatherThanAdmittingIt,
RunReaderListBriefDropsTheFreeFormTextAndNothingElse,
RunReaderReadyBriefDropsTheFreeFormTextAndNothingElse,
RunReaderListTimeBoundsAreStrictAndWholeSecond,
RunReaderListFilterFamiliesNarrowToTheirRows,
),
roleCases("ReadyClaimer", "ReadyClaimer() and IssueReader()", oncePerRole,

View file

@ -129,5 +129,14 @@ 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

@ -0,0 +1,356 @@
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

@ -31,8 +31,13 @@ go_test(
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",
@ -62,6 +67,7 @@ go_test(
"//internal/storage/backends",
"//internal/storage/domain",
"//internal/storage/embeddeddolt",
"//internal/storage/issueops",
"//internal/testutil/bazeltest",
],
)

View file

@ -8,6 +8,7 @@ import (
"net/http"
"os"
"path/filepath"
"slices"
"strings"
"sync"
"testing"
@ -51,9 +52,12 @@ func gateCheckWrites(reqs []string) []string {
}
// TestServedGateCheckOverAwaitTypedGates runs `bd gate check` over HTTP, through
// the reference proxy, against REAL await-typed gates. No wire create accepts
// await_*, so the gates are seeded straight into the served store before it
// listens, and every outcome is read back from that store:
// the reference proxy, against REAL await-typed gates, on a server that
// advertises neither gate token (issues.create.gates, issues.update.gates; the
// profile is masked here, so this holds whatever reference_server.json
// advertises). No create through it carries await_*: the gates are seeded
// straight into the served store before it listens, and every outcome is read
// back from that store:
//
// - --dry-run writes nothing;
// - an expired timer closes, a pending one stays open;
@ -61,8 +65,10 @@ func gateCheckWrites(reqs []string) []string {
// and one whose target is closed closes;
// - a merged gh:pr gate closes, a closed one escalates and stays open;
// - a gh:run gate with a workflow-name hint discovers its run but cannot
// persist await_id over the wire: that gate's error names the await_id
// update and the server, not a Go method, and await_id is untouched;
// persist await_id through a server without issues.update.gates: the
// client refuses the patch before the dial, that gate's error names the
// missing token and the server, not a Go method, and await_id is
// untouched;
// - a persisted proto's gates are templates: listed, but no sweep evaluates
// or writes them, and they take no row of --limit (they sort first here).
//
@ -137,7 +143,13 @@ func TestServedGateCheckOverAwaitTypedGates(t *testing.T) {
}
})
proxy := newReferenceProxy(t, loadReferenceProfile(t), srv.Addr())
// The gh:run case pins a server that cannot take an await_id patch, so the
// profile is held without issues.update.gates whatever
// reference_server.json advertises: upgrading the reference profile must
// not turn this case into a different test.
profile := loadReferenceProfile(t)
profile.Capabilities = slices.DeleteFunc(profile.Capabilities, func(c string) bool { return c == "issues.update.gates" })
proxy := newReferenceProxy(t, profile, srv.Addr())
reqs := &gateCheckRequestLog{next: proxy}
proxyAddr := startProxy(t, reqs)
@ -308,16 +320,16 @@ esac
}
})
t.Run("gh:run await_id persist refuses by name", func(t *testing.T) {
t.Run("gh:run await_id persist refuses by the missing token", func(t *testing.T) {
r := runBD(t, bin, dir, env, "", "gate", "check", "--type=gh:run")
if r.code == 0 {
t.Fatalf("bd gate check --type=gh:run succeeded; the wire cannot carry await_id: %s", r)
t.Fatalf("bd gate check --type=gh:run succeeded; the reference server does not advertise issues.update.gates: %s", r)
}
if w := gateCheckWrites(reqs.take()); len(w) != 0 {
t.Errorf("the refused await_id persist sent writes %v", w)
}
if !strings.Contains(r.stderr, "e2e-g-run-hint") || !strings.Contains(r.stderr, "await_id") {
t.Errorf("gh:run error does not name the gate and the await_id update:\n%s", r)
if !strings.Contains(r.stderr, "e2e-g-run-hint") || !strings.Contains(r.stderr, `does not advertise capability "issues.update.gates"`) {
t.Errorf("gh:run error does not name the gate and the missing issues.update.gates token:\n%s", r)
}
if !strings.Contains(r.stderr, "bd serve at http://"+proxyAddr) {
t.Errorf("gh:run error does not name the server it reached:\n%s", r)
@ -325,7 +337,9 @@ esac
if strings.Contains(r.stderr, "e2e-tpl-run") {
t.Errorf("the template gh:run gate was checked:\n%s", r)
}
for _, leak := range []string{"UpdateIssue", "Lifecycle.Update", "updateIssue"} {
// The capability refusal names the wire operation (updateIssue) that
// needs the token; the role and store methods stay out of it.
for _, leak := range []string{"UpdateIssue", "Lifecycle.Update"} {
if strings.Contains(r.stderr, leak) {
t.Errorf("gh:run error leaks %q:\n%s", leak, r)
}

View file

@ -142,6 +142,10 @@ func corpusServeConfig(t *testing.T, s storage.DoltStorage) httpapi.Config {
must("BatchGetter")
cfg.LeaseReclaimer, err = s.LeaseReclaimer()
must("LeaseReclaimer")
cfg.Heartbeater, err = s.Heartbeater()
must("Heartbeater")
cfg.BlockedLister, err = s.BlockedLister()
must("BlockedLister")
cfg.Relations, err = s.IssueRelations()
must("IssueRelations")
cfg.Commenter, err = s.Commenter()

View file

@ -96,11 +96,18 @@ files:
{"key": "t-ifa", "id": "e2e-t-ifa", "title": "target ifa", "type": "task", "assignee": "worker", "metadata": {"seeded": "keep"}},
{"key": "t-death", "id": "e2e-t-death", "title": "target death", "type": "task", "assignee": "worker"},
{"key": "t-rc", "id": "e2e-t-rc", "title": "target rc", "type": "task", "assignee": "worker"},
{"key": "t-hb", "id": "e2e-t-hb", "title": "target hb", "type": "task"},
{"key": "t-hb2", "id": "e2e-t-hb2", "title": "target hb2", "type": "task"},
{"key": "t-hb3", "id": "e2e-t-hb3", "title": "target hb3", "type": "task"},
{"key": "t-boot", "id": "e2e-t-boot", "title": "target boot", "type": "task"},
{"key": "t-ro", "id": "e2e-t-ro", "title": "target reopen", "type": "task"},
{"key": "t-dr", "id": "e2e-t-dr", "title": "target dep remove", "type": "task", "deps": [{"target": "t-db"}]},
{"key": "t-dc", "id": "e2e-t-dc", "title": "cascade root", "type": "epic"},
{"key": "t-dc.1", "id": "e2e-t-dc.1", "title": "cascade child", "type": "task", "parent_key": "t-dc"}
{"key": "t-dc.1", "id": "e2e-t-dc.1", "title": "cascade child", "type": "task", "parent_key": "t-dc"},
{"key": "t-gcr", "id": "e2e-t-gcr", "title": "target gate create", "type": "task"},
{"key": "t-gct", "id": "e2e-t-gct", "title": "target gate check", "type": "task"},
{"key": "t-gw", "id": "e2e-t-gw", "title": "target gate waiter", "type": "gate"},
{"key": "t-gaw", "id": "e2e-t-gaw", "title": "target gate await id", "type": "gate"}
]}
- name: bulk-ready-a.json
bulk: {id_prefix: e2e-bra, count: 60, priority: 3, metadata: {gc.routed_to: pool-a}}
@ -301,6 +308,39 @@ shapes:
source: mc skills/pr-review (list --all --id --json --limit)
args: [list, --all, --id, "e2e-r1,e2e-a1", --json, --limit, "0"]
pending: {slice: "SRV-1", reason: "S15b sends --id as listIssues id behind issues.list.ids, which the reference server does not advertise, so the client refuses before dialing (pinned passing against the current server by backend/http TestE2E_ListScopeFiltersOverHTTP); remove the mark when reference_server.json is upgraded"}
- id: gc-polecat-title-contains
source: gascity core formulas/mol-polecat-base.toml (list --title-contains --status a,b,c --json)
args: [list, --title-contains, "Routed", --status, "open,in_progress,blocked", --json]
pending: {slice: "SRV-1", reason: "--title-contains folds onto listIssues title behind issues.list.title, which the reference server does not advertise, so the client refuses before dialing (pinned passing against the current server by backend/http TestE2E_ListScopeFiltersOverHTTP); remove the mark when reference_server.json is upgraded"}
- id: gc-polecat-title-contains-closed-after
source: gascity core formulas/mol-polecat-base.toml (pre-flight 3d, list --title-contains --status closed --closed-after DATE --json)
args: [list, --title-contains, "closed task", --status, closed, --closed-after, "2000-01-01", --json]
pending: {slice: "SRV-1", reason: "needs issues.list.title (--title-contains folds onto listIssues title) and issues.list.filters (closed_after), which the reference server does not advertise, so the client refuses before dialing; remove the mark when reference_server.json is upgraded"}
- id: gc-polecat-closed-after
source: gascity core formulas/mol-polecat-base.toml:267 (list --title-contains --status closed --closed-after --json)
args: [list, --title-contains, "task", --status, closed, --closed-after, "2000-01-01", --json]
compare: ids
pending: {slice: "SRV-1", reason: "needs issues.list.title (--title-contains folds onto listIssues title) and issues.list.filters (closed_after), which the reference server does not advertise, so the client refuses before dialing (pinned passing against the current server by backend/http TestE2E_ListFilterParityOverHTTP); remove the mark when reference_server.json is upgraded"}
- id: wf-session-cleanup
source: an order cleanup script's closed-session sweep (list --all --include-infra --include-gates --status closed --label --closed-before --updated-before)
args: [list, --json, --all, --include-infra, --include-gates, --status, closed, --label, "lane:a", --closed-before, "2100-01-01T00:00:00Z", --updated-before, "2100-01-01T00:00:00Z", --limit, "0"]
compare: ids
pending: {slice: "SRV-1", reason: "needs issues.list.filters, which the reference server does not advertise, so the client refuses before dialing (pinned passing against the current server by backend/http TestE2E_ListFilterParityOverHTTP); remove the mark when reference_server.json is upgraded"}
- id: list-filter-priority-range
source: bd list --priority-min/--priority-max (listing filter parity)
args: [list, --json, --priority-min, "1", --priority-max, "3", --limit, "0"]
compare: ids
pending: {slice: "SRV-1", reason: "needs issues.list.filters, which the reference server does not advertise, so the client refuses before dialing (pinned passing against the current server by backend/http TestE2E_ListFilterParityOverHTTP); remove the mark when reference_server.json is upgraded"}
- id: list-filter-exclude-type-no-parent
source: bd list --exclude-type --no-parent (listing filter parity)
args: [list, --json, --exclude-type, epic, --no-parent, --limit, "0"]
compare: ids
pending: {slice: "SRV-1", reason: "needs issues.list.filters, which the reference server does not advertise, so the client refuses before dialing (pinned passing against the current server by backend/http TestE2E_ListFilterParityOverHTTP); remove the mark when reference_server.json is upgraded"}
- id: list-filter-updated-after
source: bd list --updated-after (listing filter parity)
args: [list, --json, --updated-after, "2000-01-01", --limit, "0"]
compare: ids
pending: {slice: "SRV-1", reason: "needs issues.list.filters, which the reference server does not advertise, so the client refuses before dialing (pinned passing against the current server by backend/http TestE2E_ListFilterParityOverHTTP); remove the mark when reference_server.json is upgraded"}
- id: mc-list-assignee-status
source: mc review summaries (list --assignee --json --limit --status)
args: [list, --assignee, alice, --json, --limit, "10", --status, open]
@ -364,7 +404,23 @@ shapes:
- id: gc-blocked
source: gc bdstore_ready_projection.go fetchReadyProjectionViaBlocked
args: [blocked, --json]
pending: {slice: "S18", reason: "bd blocked hits the GetBlockedIssues stub (B3 #10)"}
pending: {slice: "SRV-1", reason: "bd blocked dials listBlockedIssues behind blocked.list, which the reference server does not advertise, so the client refuses at its capability preflight (pinned passing against the current server by backend/http TestE2E_BlockedOverHTTP); remove the mark when reference_server.json is upgraded"}
- id: gc-blocked-flags
source: gc bdstore_ready_projection.go readiness door (bd blocked --flags --json, ids on stdin)
args: [blocked, --flags, --json]
stdin: "e2e-mol\ne2e-mol.1\ne2e-mol.2\ne2e-no-such-row\n"
compare: json
pending: {slice: "SRV-1", reason: "bd blocked --flags reads listBlockingAnnotations is_blocked behind dependencies.blocking.isBlocked, which the reference server does not advertise, so the client refuses at its capability preflight (pinned passing against the current server by backend/http TestE2E_BlockedFlagsOverHTTP); remove the mark when reference_server.json is upgraded"}
- id: gc-blocked-flags-raw
source: gc bdstore_ready_projection.go readiness door (the stored is_blocked column, bd blocked --flags --raw --json, ids on stdin)
args: [blocked, --flags, --raw, --json]
stdin: "e2e-mol\ne2e-mol.1\ne2e-mol.2\ne2e-no-such-row\n"
compare: json
pending: {slice: "SRV-1", reason: "bd blocked --flags reads listBlockingAnnotations is_blocked behind dependencies.blocking.isBlocked, which the reference server does not advertise, so the client refuses at its capability preflight (pinned passing against the current server by backend/http TestE2E_BlockedFlagsOverHTTP); remove the mark when reference_server.json is upgraded"}
- id: gc-blocked-parent
source: bd blocked --parent (the molecule-scoped blocked listing)
args: [blocked, --json, --parent, e2e-mol]
pending: {slice: "SRV-1", reason: "bd blocked dials listBlockedIssues behind blocked.list, which the reference server does not advertise, so the client refuses at its capability preflight (pinned passing against the current server by backend/http TestE2E_BlockedOverHTTP); remove the mark when reference_server.json is upgraded"}
# ---------------------------------------------------------------- molecules
- id: mc-mol-current
@ -442,7 +498,8 @@ shapes:
source: core pack orders (gate list --all)
args: [gate, list, --all, --json]
# gate check lists the open gates through the same ListGates entry. No
# seeded gate carries an await type (no wire create accepts await_*), so the
# seeded gate carries an await type (the seed graph carries no gate members;
# mc-gate-check-timer-resolves below creates a real timer gate), so the
# typed sweeps find nothing of their type and the untyped one lists the open
# gates and evaluates none: the listing is what these shapes prove served,
# and nothing resolves, escalates (no gt exec) or writes.
@ -710,6 +767,35 @@ shapes:
compare: exit
verify: [[show, --json, e2e-t-rc]]
pending: {slice: "SRV-1", reason: "the reference server does not advertise issues.reclaim (B3 #12), so the client refuses at its capability preflight"}
- id: gc-heartbeat
source: gc formulas/mol-do-work.toml:47 (gc bd heartbeat <id> -> bd heartbeat)
setup: [[update, e2e-t-hb, --claim]]
args: [heartbeat, e2e-t-hb, --json]
verify: [[show, --json, e2e-t-hb]]
pending: {slice: "reference-server-heartbeat", reason: "the reference server does not advertise issues.heartbeat, so the client refuses at its capability preflight; pinned passing by backend/http TestE2E_HeartbeatOverHTTP; remove the mark when reference_server.json is upgraded"}
- id: gc-heartbeat-non-holder
source: gc formulas/mol-do-work.toml:47 (a worker heartbeating a bead another actor holds)
setup: [[update, e2e-t-hb2, --claim, --actor, alice]]
args: [heartbeat, e2e-t-hb2]
expect_exit: 1
expect_stderr: "(?i)claimed by|alice"
compare: exit
pending: {slice: "reference-server-heartbeat", reason: "the reference server does not advertise issues.heartbeat, so the client refuses at its capability preflight; pinned passing by backend/http TestE2E_HeartbeatOverHTTP; remove the mark when reference_server.json is upgraded"}
- id: gc-heartbeat-closed
source: gc formulas/mol-do-work.toml:47 (a worker heartbeating a bead that was closed under it)
setup: [[update, e2e-t-hb3, --claim], [close, e2e-t-hb3]]
args: [heartbeat, e2e-t-hb3]
expect_exit: 1
expect_stderr: "(?i)status closed|is closed"
compare: exit
pending: {slice: "reference-server-heartbeat", reason: "the reference server does not advertise issues.heartbeat, so the client refuses at its capability preflight; pinned passing by backend/http TestE2E_HeartbeatOverHTTP; remove the mark when reference_server.json is upgraded"}
- id: gc-heartbeat-wisp
source: gc formulas/mol-do-work.toml:47 (a heartbeat on a wisp, which is never leased)
args: [heartbeat, e2e-wisp-2]
expect_exit: 1
expect_stderr: "(?i)ephemeral"
compare: exit
pending: {slice: "reference-server-heartbeat", reason: "the reference server does not advertise issues.heartbeat, so the client refuses at its capability preflight; pinned passing by backend/http TestE2E_HeartbeatOverHTTP; remove the mark when reference_server.json is upgraded"}
- id: mc-promote
source: mc mol-normalized-issue-pr-v1 (promote --reason)
args: [promote, e2e-wisp-p, --reason, "keep it"]
@ -764,3 +850,33 @@ shapes:
expect_exit: 1
expect_stderr: 'unknown command "meta"'
compare: exit
# ---------------------------------------------------------------- gates
# The gate writes: create (one createIssue carrying the gate members and the
# blocks edge), a real timer gate resolving under gate check, add-waiter (a
# guarded waiters patch) and update --await-id. A --timeout=1ns timer is
# expired by the time gate check runs, so the resolution is deterministic.
- id: mc-gate-create-timer
source: core formulas / gate-sweep (bd gate create --type=timer --timeout --blocks)
args: [gate, create, --type=timer, --timeout=1ns, --blocks, e2e-t-gcr, --json]
ignore_fields: [id] # each side mints its own gate id
pending: {slice: "SRV-1", reason: "bd gate create sends the gate members on createIssue behind issues.create.gates, which the reference server does not advertise, so the client refuses before dialing (pinned passing against the current server by backend/http TestE2E_GatesOverHTTP); remove the mark when reference_server.json is upgraded"}
- id: mc-gate-check-timer-resolves
source: core gate-sweep.sh (gate check --type=timer --escalate) over a real timer gate
setup: [[gate, create, --type=timer, --timeout=1ns, --blocks, e2e-t-gct]]
args: [gate, check, --type=timer, --escalate]
compare: exit
verify: [[ready, --json, --limit, "0"]] # e2e-t-gct is ready on both sides
ignore_fields: [depends_on_id] # its (closed) gate's id is minted per workspace
pending: {slice: "SRV-1", reason: "the setup bd gate create sends the gate members on createIssue behind issues.create.gates, which the reference server does not advertise, so the client refuses before dialing (pinned passing against the current server by backend/http TestE2E_GatesOverHTTP); remove the mark when reference_server.json is upgraded"}
- id: mc-gate-add-waiter
source: bd done --phase-complete (gate add-waiter)
args: [gate, add-waiter, e2e-t-gw, "rig/workers/a"]
compare: text
verify: [[show, --json, e2e-t-gw]]
pending: {slice: "SRV-1", reason: "bd gate add-waiter sends waiters on updateIssue behind issues.update.gates, which the reference server does not advertise, so the client refuses before dialing (pinned passing against the current server by backend/http TestE2E_GatesOverHTTP); remove the mark when reference_server.json is upgraded"}
- id: mc-update-await-id
source: gate discover / gate check gh:run persist (update --await-id)
args: [update, e2e-t-gaw, --await-id, "12345", --json]
compare: exit
verify: [[show, --json, e2e-t-gaw]]
pending: {slice: "SRV-1", reason: "bd update --await-id sends await_id on updateIssue behind issues.update.gates, which the reference server does not advertise, so the client refuses before dialing (pinned passing against the current server by backend/http TestE2E_GatesOverHTTP); remove the mark when reference_server.json is upgraded"}

View file

@ -0,0 +1,287 @@
//go:build cgo
package bdhttp_test
import (
"context"
"encoding/json"
"errors"
"os/exec"
"reflect"
"sort"
"strings"
"testing"
"github.com/steveyegge/beads/internal/storage/issueops"
)
// runBDStdin is runBD with stdin.
func runBDStdin(t *testing.T, f *remoteRolesFixture, stdin string, args ...string) bdResult {
t.Helper()
cmd := exec.Command(f.bin, args...)
cmd.Dir = f.dir
cmd.Env = minimalBDEnv(f.dir)
cmd.Stdin = strings.NewReader(stdin)
var o, e strings.Builder
cmd.Stdout, cmd.Stderr = &o, &e
err := cmd.Run()
code := 0
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
code = exitErr.ExitCode()
} else if err != nil {
t.Fatalf("run bd %v: %v", args, err)
}
return bdResult{stdout: o.String(), stderr: e.String(), code: code}
}
type blockedFlagRow struct {
ID string `json:"id"`
IsBlocked bool `json:"is_blocked"`
}
func parseBlockedFlags(t *testing.T, out string) []blockedFlagRow {
t.Helper()
var rows []blockedFlagRow
if err := json.Unmarshal([]byte(strings.TrimSpace(out)), &rows); err != nil {
t.Fatalf("parse bd blocked --flags --json: %v\n%s", err, out)
}
if rows == nil {
t.Fatalf("bd blocked --flags --json printed null, want an array: %s", out)
}
return rows
}
// flagStdin is every id the fixture created, in title order, plus an id that
// names no row, a blank line and a repeat: the omitted, ignored and collapsed
// cases.
func flagStdin(f *remoteRolesFixture) string {
titles := make([]string, 0, len(f.ids))
for title := range f.ids {
titles = append(titles, title)
}
sort.Strings(titles)
var b strings.Builder
for _, title := range titles {
b.WriteString(f.ids[title] + "\n")
}
b.WriteString("\n " + f.ids[titles[0]] + " \ne2e-no-such-row\n")
return b.String()
}
// TestE2E_BlockedFlagsOverHTTP runs `bd blocked --flags --json` (the blocked
// flag per id read from stdin, the readiness column gc projects) through the
// real `bd` binary against an in-process `bd serve` and against a local
// embedded workspace holding the same graph, and requires the same JSON once
// each generated id is mapped to its title. Over HTTP the read is
// listBlockingAnnotations with is_blocked; an older server's handshake is
// refused before the dial, naming dependencies.blocking.isBlocked.
//
// It also pins that this is the FLAG and not the listing: a row whose stored
// flag is set with no nameable blocker reads true here and is absent from
// `bd blocked --json`.
func TestE2E_BlockedFlagsOverHTTP(t *testing.T) {
skipUnlessEmbeddedDolt(t)
bin := buildBD(t)
seed := func(f *remoteRolesFixture) {
f.seed()
blocker := f.create("blocker", "-t", "task")
gp := f.create("gate-parent", "-t", "epic")
kid := f.create("gate-kid", "-t", "task")
f.mustRun(nil, "dep", "add", kid, gp, "--type", "parent-child")
f.mustRun(nil, "dep", "add", gp, blocker)
}
t.Run("served equals local", func(t *testing.T) {
addr := startE2EServer(t)
local := newEmbeddedFixture(t, bin)
seed(local)
served := newHTTPFixture(t, bin, addr)
seed(served)
lr := runBDStdin(t, local, flagStdin(local), "blocked", "--flags", "--json")
sr := runBDStdin(t, served, flagStdin(served), "blocked", "--flags", "--json")
if lr.code != 0 || sr.code != 0 {
t.Fatalf("exit local=%d served=%d\nlocal: %s %s\nserved: %s %s", lr.code, sr.code, lr.stdout, lr.stderr, sr.stdout, sr.stderr)
}
normalize := func(f *remoteRolesFixture, rows []blockedFlagRow) []blockedFlagRow {
titleOf := map[string]string{}
for title, id := range f.ids {
titleOf[id] = title
}
out := make([]blockedFlagRow, 0, len(rows))
for _, row := range rows {
if title, ok := titleOf[row.ID]; ok {
row.ID = title
}
out = append(out, row)
}
return out
}
want := normalize(local, parseBlockedFlags(t, lr.stdout))
got := normalize(served, parseBlockedFlags(t, sr.stdout))
if !reflect.DeepEqual(want, got) {
t.Errorf("served bd blocked --flags --json differs from the local command:\nlocal: %v\nserved: %v", want, got)
}
if len(want) != len(local.ids) {
t.Errorf("local answered %d rows for %d ids (the unknown id omitted, the repeat collapsed): %v", len(want), len(local.ids), want)
}
blocked := map[string]bool{}
for _, row := range got {
blocked[row.ID] = row.IsBlocked
}
for title, wantBlocked := range map[string]bool{
"loner": true, "child-x": true, "gate-parent": true, "gate-kid": true,
"blocker": false, "child-b": false, "parent": false,
} {
if blocked[title] != wantBlocked {
t.Errorf("%s is_blocked = %v, want %v (rows %v)", title, blocked[title], wantBlocked, got)
}
}
// Byte-for-byte the same members in the same order.
if strings.Count(lr.stdout, "\n") != strings.Count(sr.stdout, "\n") {
t.Errorf("line counts differ:\nlocal:\n%s\nserved:\n%s", lr.stdout, sr.stdout)
}
// Nothing piped is an empty array.
if r := runBDStdin(t, served, "", "blocked", "--flags", "--json"); r.code != 0 || strings.TrimSpace(r.stdout) != "[]" {
t.Errorf("empty stdin: exit %d stdout %q, want [] and exit 0", r.code, r.stdout)
}
// The listing's filters are refused, not silently ignored.
if r := runBDStdin(t, served, "x\n", "blocked", "--flags", "--json", "--label", "a"); r.code != 1 {
t.Errorf("--flags --label exited %d, want 1: %s", r.code, r.stdout)
}
})
t.Run("the flag, not the listing", func(t *testing.T) {
addr, reference := startE2EServerWithStore(t, e2eProjectID, e2eDatabase)
served := newHTTPFixture(t, bin, addr)
stale := served.create("stale")
if err := reference.RunEventsMaintenanceTx(context.Background(), func(ctx context.Context, tx issueops.DBTX) error {
_, err := tx.ExecContext(ctx, "UPDATE issues SET is_blocked = 1 WHERE id = ?", stale)
return err
}); err != nil {
t.Fatalf("set the stale flag: %v", err)
}
rows := parseBlockedFlags(t, runBDStdin(t, served, stale+"\n", "blocked", "--flags", "--json").stdout)
if len(rows) != 1 || rows[0].ID != stale || !rows[0].IsBlocked {
t.Errorf("--flags for a stale-flagged row = %v, want [{%s true}]", rows, stale)
}
listing := served.mustRun(nil, "blocked", "--json").stdout
if strings.Contains(listing, stale) {
t.Errorf("bd blocked --json lists %s, which has no nameable blocker: %s", stale, listing)
}
})
t.Run("raw is the stored column", func(t *testing.T) {
addr, reference := startE2EServerWithStore(t, e2eProjectID, e2eDatabase)
local := newEmbeddedFixture(t, bin)
seed(local)
served := newHTTPFixture(t, bin, addr)
seed(served)
flagsOf := func(f *remoteRolesFixture, stdin string, args ...string) map[string]bool {
t.Helper()
r := runBDStdin(t, f, stdin, append([]string{"blocked", "--flags", "--json"}, args...)...)
if r.code != 0 {
t.Fatalf("bd blocked --flags --json %v exited %d: %s %s", args, r.code, r.stdout, r.stderr)
}
titleOf := map[string]string{}
for title, id := range f.ids {
titleOf[id] = title
}
out := map[string]bool{}
for _, row := range parseBlockedFlags(t, r.stdout) {
key := row.ID
if title, ok := titleOf[row.ID]; ok {
key = title
}
out[key] = row.IsBlocked
}
return out
}
localRaw := flagsOf(local, flagStdin(local), "--raw")
servedRaw := flagsOf(served, flagStdin(served), "--raw")
if !reflect.DeepEqual(localRaw, servedRaw) {
t.Errorf("served --raw differs from local --raw:\nlocal: %v\nserved: %v", localRaw, servedRaw)
}
lr := runBDStdin(t, local, flagStdin(local), "blocked", "--flags", "--json", "--raw")
sr := runBDStdin(t, served, flagStdin(served), "blocked", "--flags", "--json", "--raw")
if strings.Count(lr.stdout, "\n") != strings.Count(sr.stdout, "\n") {
t.Errorf("--raw line counts differ:\nlocal:\n%s\nserved:\n%s", lr.stdout, sr.stdout)
}
// child-x is blocked ONLY by an unsatisfied external ref: the policy
// flag says blocked, the stored column does not.
decorated := flagsOf(served, flagStdin(served))
if !decorated["child-x"] || servedRaw["child-x"] || localRaw["child-x"] {
t.Errorf("child-x (externally blocked only): --flags %v, --raw served %v local %v; want true, false, false",
decorated["child-x"], servedRaw["child-x"], localRaw["child-x"])
}
// Locally blocked rows read the same either way.
for _, title := range []string{"loner", "gate-parent", "gate-kid", "blocker"} {
if decorated[title] != servedRaw[title] {
t.Errorf("%s: --flags %v, --raw %v; a local blocker is the column", title, decorated[title], servedRaw[title])
}
}
// A stale flag (set, no blocker) is the column, so both read true.
stale := served.create("stale")
if err := reference.RunEventsMaintenanceTx(context.Background(), func(ctx context.Context, tx issueops.DBTX) error {
_, err := tx.ExecContext(ctx, "UPDATE issues SET is_blocked = 1 WHERE id = ?", stale)
return err
}); err != nil {
t.Fatalf("set the stale flag: %v", err)
}
if got := flagsOf(served, stale+"\n", "--raw"); !got["stale"] {
t.Errorf("--raw for the stale-flagged row = %v, want true", got)
}
if got := flagsOf(served, stale+"\n"); !got["stale"] {
t.Errorf("--flags for the stale-flagged row = %v, want true", got)
}
// --raw qualifies --flags only.
if r := runBDStdin(t, served, "", "blocked", "--json", "--raw"); r.code != 1 || !strings.Contains(r.stdout+r.stderr, "--raw") {
t.Errorf("bd blocked --raw without --flags: exit %d %s %s, want exit 1 naming --raw", r.code, r.stdout, r.stderr)
}
// A server that applies the policy answers the decorated flag and the
// wire cannot ask it for the column: --raw is refused there, before
// the annotation read, rather than answered with the policy flag.
proxyAddr, counter := startMaskingProxy(t, addr, func(body map[string]any) {
caps, _ := body["capabilities"].([]any)
body["capabilities"] = append(caps, "policy.external_dependencies")
})
enforced := newHTTPFixture(t, bin, proxyAddr)
counter.reset()
r := runBDStdin(t, enforced, served.ids["child-x"]+"\n", "blocked", "--flags", "--json", "--raw")
if r.code != 1 || !strings.Contains(r.stdout+r.stderr, "policy.external_dependencies") {
t.Errorf("--raw against a policy server: exit %d %s %s, want exit 1 naming the policy token", r.code, r.stdout, r.stderr)
}
for _, p := range counter.snapshot() {
if strings.Contains(p, "/v0/beads/dependencies/blocking") {
t.Errorf("a refused --raw dialed %s", p)
}
}
})
t.Run("older server mask", func(t *testing.T) {
addr := startE2EServer(t)
proxyAddr, counter := startMaskingProxy(t, addr, mcContextMask)
f := newHTTPFixture(t, bin, proxyAddr)
counter.reset()
r := runBDStdin(t, f, "e2e-anything\n", "blocked", "--flags", "--json")
if r.code != 1 {
t.Fatalf("bd blocked --flags against a server without the token exited %d, want 1: %s", r.code, r.stdout)
}
if !strings.Contains(r.stdout+r.stderr, "dependencies.blocking.isBlocked") {
t.Errorf("refusal does not name the missing capability: stdout=%s stderr=%s", r.stdout, r.stderr)
}
for _, p := range counter.snapshot() {
if strings.Contains(p, "/v0/beads/dependencies/blocking") {
t.Errorf("a refused bd blocked --flags dialed %s", p)
}
}
})
}

View file

@ -0,0 +1,229 @@
//go:build cgo
package bdhttp_test
import (
"encoding/json"
"reflect"
"slices"
"strings"
"testing"
)
// TestE2E_BlockedOverHTTP runs `bd blocked --json` (the blocked door gc's
// readiness projection reads) through the real `bd` binary against an
// in-process `bd serve`, and against a local embedded workspace holding the
// same graph.
//
// Over HTTP the CLI takes the store's BlockedLister, which dials
// GET /v0/beads/blocked behind blocked.list. The two answers must be the same
// JSON once the values that cannot agree between two workspaces (each row's
// generated id, and its timestamps) are mapped out: the same rows, the same
// members, the same blockers (local, parent-attributed and external), in the
// same order. Against a server that does not advertise blocked.list (an older
// server's handshake) the client refuses before the dial, naming the token.
func TestE2E_BlockedOverHTTP(t *testing.T) {
skipUnlessEmbeddedDolt(t)
bin := buildBD(t)
addr := startE2EServer(t)
seedBlocked := func(f *remoteRolesFixture) {
f.seed()
// A plain blocks edge, a blocked parent's child attributed to the
// parent, and a labelled blocked row for the filter arms.
blocker := f.create("blocker", "-t", "task", "-p", "1")
gp := f.create("gate-parent", "-t", "epic", "-p", "2")
// Its own priority: rows tied on priority and created_at fall to the
// id order, and ids are generated per workspace, so a tie would order
// the two workspaces differently.
kid := f.create("gate-kid", "-t", "task", "-p", "3")
tagged := f.create("tagged", "-t", "task", "-p", "1", "-l", "lane:a")
// Blocked by nothing but an unsatisfied external ref, as child-x is,
// and labelled: the decorator lists such rows itself, after the label
// query ran, so the filter arms must judge them too.
extTagged := f.create("ext-tagged", "-t", "task", "-p", "4", "-l", "lane:a")
f.mustRun(nil, "dep", "add", kid, gp, "--type", "parent-child")
f.mustRun(nil, "dep", "add", gp, blocker)
f.mustRun(nil, "dep", "add", tagged, blocker)
f.mustRun(nil, "dep", "add", extTagged, "external:other:cap")
}
local := newEmbeddedFixture(t, bin)
seedBlocked(local)
served := newHTTPFixture(t, bin, addr)
seedBlocked(served)
for _, args := range [][]string{
{"blocked", "--json"},
{"blocked", "--json", "--label", "lane:a"},
{"blocked", "--json", "--label-any", "lane:a"},
{"blocked", "--json", "--exclude-label", "lane:a"},
{"blocked", "--json", "--parent", "{gate-parent}"},
{"blocked", "--json", "--label", "no-such-label"},
} {
t.Run(strings.Join(args[1:], " "), func(t *testing.T) {
want := local.mustRun(nil, local.expand(args)...).stdout
got := served.mustRun(nil, served.expand(args)...).stdout
if strings.TrimSpace(want) == "null" || strings.TrimSpace(got) == "null" {
t.Fatalf("bd blocked --json printed null: local=%s served=%s", want, got)
}
if w, g := normalizeBlocked(t, local, want), normalizeBlocked(t, served, got); !reflect.DeepEqual(w, g) {
t.Errorf("served bd blocked --json differs from the local command:\nlocal: %v\nserved: %v", w, g)
}
if w, g := blockedKeyOrder(t, want), blockedKeyOrder(t, got); !reflect.DeepEqual(w, g) {
t.Errorf("served member order %v differs from the local command's %v", g, w)
}
})
}
t.Run("names the external blocker", func(t *testing.T) {
got := normalizeBlocked(t, served, served.mustRun(nil, "blocked", "--json").stdout)
found := false
for _, row := range got {
if row["id"] == "child-x" {
found = reflect.DeepEqual(row["blocked_by"], []any{"external:other:cap"})
}
}
if !found {
t.Errorf("served bd blocked --json does not list child-x blocked by its external ref: %v", got)
}
})
// The arms above compare the two answers, which agree just as well when
// both list a row the filter rules out. These pin which rows each filter
// leaves, the external-only ones (child-x unlabelled, ext-tagged
// labelled) among them.
for _, tc := range []struct {
args []string
want []string // the whole listing, when set
listed, ruled []string
}{
{args: []string{"--label", "lane:a"}, want: []string{"ext-tagged", "tagged"}},
{args: []string{"--label-any", "lane:a"}, want: []string{"ext-tagged", "tagged"}},
{args: []string{"--label", "no-such-label"}, want: []string{}},
{args: []string{"--exclude-label", "lane:a"}, listed: []string{"child-x"}, ruled: []string{"ext-tagged", "tagged"}},
} {
t.Run("filters external-only rows "+strings.Join(tc.args, " "), func(t *testing.T) {
for _, f := range []struct {
name string
f *remoteRolesFixture
}{{"local", local}, {"served", served}} {
got := f.f.titlesOf(f.f.mustRun(nil, append([]string{"blocked", "--json"}, tc.args...)...).stdout)
if tc.want != nil && !slices.Equal(got, tc.want) {
t.Errorf("%s bd blocked %s listed %v, want %v", f.name, strings.Join(tc.args, " "), got, tc.want)
}
for _, title := range tc.listed {
if !slices.Contains(got, title) {
t.Errorf("%s bd blocked %s does not list %s: %v", f.name, strings.Join(tc.args, " "), title, got)
}
}
for _, title := range tc.ruled {
if slices.Contains(got, title) {
t.Errorf("%s bd blocked %s lists %s, which the filter rules out: %v", f.name, strings.Join(tc.args, " "), title, got)
}
}
}
})
}
t.Run("older server mask", func(t *testing.T) {
proxyAddr, counter := startMaskingProxy(t, addr, mcContextMask)
f := newHTTPFixture(t, bin, proxyAddr)
counter.reset()
r := f.run(nil, "blocked", "--json")
if r.code != 1 {
t.Fatalf("bd blocked against a server without blocked.list exited %d, want 1: %s", r.code, r.stdout)
}
if !strings.Contains(r.stdout+r.stderr, "blocked.list") {
t.Errorf("refusal does not name the missing capability: stdout=%s stderr=%s", r.stdout, r.stderr)
}
for _, p := range counter.snapshot() {
if strings.Contains(p, "/v0/beads/blocked") {
t.Errorf("a refused bd blocked dialed %s; the refusal must come before the dial", p)
}
}
})
}
// normalizeBlocked parses `bd blocked --json` and maps out what two
// workspaces cannot share: each id (and each blocker id) becomes the title the
// fixture created it under, and every timestamp member is blanked.
func normalizeBlocked(t *testing.T, f *remoteRolesFixture, out string) []map[string]any {
t.Helper()
var rows []map[string]any
if err := json.Unmarshal([]byte(strings.TrimSpace(out)), &rows); err != nil {
t.Fatalf("parse bd blocked --json: %v\n%s", err, out)
}
titleOf := map[string]string{}
for title, id := range f.ids {
titleOf[id] = title
}
var walk func(key string, v any) any
walk = func(key string, v any) any {
switch v := v.(type) {
case map[string]any:
for k, inner := range v {
v[k] = walk(k, inner)
}
return v
case []any:
for i := range v {
v[i] = walk("", v[i])
}
return v
case string:
if strings.HasSuffix(key, "_at") {
return "<time>"
}
if title, ok := titleOf[v]; ok {
return title
}
}
return v
}
for _, row := range rows {
walk("", row)
}
return rows
}
// blockedKeyOrder is the member order of each row as printed, so the two
// encodings are compared as text, not only as values.
func blockedKeyOrder(t *testing.T, out string) [][]string {
t.Helper()
var rows []json.RawMessage
if err := json.Unmarshal([]byte(strings.TrimSpace(out)), &rows); err != nil {
t.Fatalf("parse bd blocked --json: %v\n%s", err, out)
}
order := make([][]string, 0, len(rows))
for _, raw := range rows {
dec := json.NewDecoder(strings.NewReader(string(raw)))
var keys []string
depth := 0
for {
tok, err := dec.Token()
if err != nil {
break
}
switch v := tok.(type) {
case json.Delim:
if v == '{' || v == '[' {
depth++
} else {
depth--
}
case string:
if depth == 1 {
keys = append(keys, v)
// Skip the value.
var skip json.RawMessage
if err := dec.Decode(&skip); err != nil {
t.Fatalf("decode value of %s: %v", v, err)
}
}
}
}
order = append(order, keys)
}
return order
}

View file

@ -733,6 +733,15 @@ func startE2EServer(t *testing.T) string {
// the one a prior `bd connect` already pinned, to prove the pin is honored
// rather than silently replaced.
func startE2EServerWithIdentity(t *testing.T, projectID, database string) string {
t.Helper()
addr, _ := startE2EServerWithStore(t, projectID, database)
return addr
}
// startE2EServerWithStore is startE2EServerWithIdentity that also hands back
// the reference store the server serves, for a test that must plant or age
// state no wire verb can reach (an aged lease row).
func startE2EServerWithStore(t *testing.T, projectID, database string) (string, *embeddeddolt.EmbeddedDoltStore) {
t.Helper()
beadsDir := t.TempDir()
ctx := context.Background()
@ -761,7 +770,7 @@ func startE2EServerWithIdentity(t *testing.T, projectID, database string) string
t.Error("the in-process server did not shut down")
}
})
return srv.Addr()
return srv.Addr(), reference
}
func e2eServeConfig(t *testing.T, s storage.DoltStorage, projectID, database string) httpapi.Config {
@ -803,6 +812,10 @@ func e2eServeConfig(t *testing.T, s storage.DoltStorage, projectID, database str
fail("BatchGetter")
cfg.LeaseReclaimer, err = s.LeaseReclaimer()
fail("LeaseReclaimer")
cfg.Heartbeater, err = s.Heartbeater()
fail("Heartbeater")
cfg.BlockedLister, err = s.BlockedLister()
fail("BlockedLister")
cfg.Relations, err = s.IssueRelations()
fail("IssueRelations")
cfg.Commenter, err = s.Commenter()

View file

@ -0,0 +1,315 @@
//go:build cgo
package bdhttp_test
import (
"encoding/json"
"fmt"
"net/http"
"os"
"path/filepath"
"slices"
"strings"
"sync"
"testing"
"time"
)
// gateTokens are the two behavior tokens the gate commands depend on:
// issues.create.gates for a create carrying gate members (bd gate create),
// issues.update.gates for an await_id or waiters patch (bd gate add-waiter,
// bd gate discover, gate check's gh:run persist, bd update --await-id).
var gateTokens = []string{"issues.create.gates", "issues.update.gates"}
// withoutGateTokens rewrites the handshake into a server that predates the
// gate members: the live capability list minus the two gate tokens.
func withoutGateTokens(body map[string]any) {
caps, _ := body["capabilities"].([]any)
kept := make([]any, 0, len(caps))
for _, c := range caps {
if s, _ := c.(string); slices.Contains(gateTokens, s) {
continue
}
kept = append(kept, c)
}
body["capabilities"] = kept
}
// gateShow is the subset of `bd show --json` the gate cases read.
type gateShow struct {
ID string `json:"id"`
Status string `json:"status"`
IssueType string `json:"issue_type"`
AwaitType string `json:"await_type"`
AwaitID string `json:"await_id"`
Timeout int64 `json:"timeout"`
Waiters []string `json:"waiters"`
}
func showGate(t *testing.T, f *remoteRolesFixture, id string) gateShow {
t.Helper()
out := strings.TrimSpace(f.mustRun(nil, "show", id, "--json").stdout)
var rows []gateShow
if err := json.Unmarshal([]byte(out), &rows); err != nil {
var one gateShow
if err1 := json.Unmarshal([]byte(out), &one); err1 != nil {
t.Fatalf("parse bd show --json: %v\n%s", err, out)
}
return one
}
if len(rows) == 0 {
t.Fatalf("bd show %s --json returned no row", id)
}
return rows[0]
}
func readyIDs(t *testing.T, f *remoteRolesFixture) map[string]bool {
t.Helper()
ids := map[string]bool{}
for _, row := range jsonRows(t, f.mustRun(nil, "ready", "--json", "--limit", "0").stdout) {
if id, ok := row["id"].(string); ok {
ids[id] = true
}
}
return ids
}
func writesOf(paths []string) []string {
var writes []string
for _, p := range paths {
if !strings.HasPrefix(p, http.MethodGet+" ") {
writes = append(writes, p)
}
}
return writes
}
// TestE2E_GatesOverHTTP runs the gate commands through the real `bd` binary
// against an in-process `bd serve`.
//
// Against a server that advertises the gate tokens:
// - `bd gate create` is ONE createIssue carrying the gate members and the
// blocks edge (timer, gh:run and bead gates), and the blocked issue
// leaves the ready set;
// - `bd gate check --type=timer` closes an expired timer gate and the
// blocked issue becomes ready;
// - `bd gate add-waiter` registers a waiter once (the repeat writes nothing);
// - `bd update --await-id` sets await_id.
//
// Against a server that does not advertise them, each command is refused
// before any write, naming the token it needs, and nothing changes.
func TestE2E_GatesOverHTTP(t *testing.T) {
skipUnlessEmbeddedDolt(t)
bin := buildBD(t)
addr := startE2EServer(t)
proxyAddr, counter := startCountingProxy(t, addr)
f := newHTTPFixture(t, bin, proxyAddr)
var waiterGate string
t.Run("advertised", func(t *testing.T) {
timerTarget := f.create("timer target")
counter.reset()
created := f.mustRun(nil, "gate", "create", "--type=timer", "--timeout=1ns", "--blocks", timerTarget, "--json")
if w := writesOf(counter.snapshot()); !slices.Equal(w, []string{"POST /v0/beads/issues"}) {
t.Errorf("gate create wrote %v, want exactly one createIssue", w)
}
timerGate := firstJSONField(t, created.stdout, "id")
if g := showGate(t, f, timerGate); g.IssueType != "gate" || g.AwaitType != "timer" || g.Timeout != 1 || g.Status != "open" {
t.Errorf("timer gate reads back %+v, want an open timer gate with a 1ns timeout", g)
}
if readyIDs(t, f)[timerTarget] {
t.Errorf("%s is ready while its gate is open", timerTarget)
}
time.Sleep(10 * time.Millisecond)
r := f.mustRun(nil, "gate", "check", "--type=timer", "--escalate")
if !strings.Contains(r.stdout, "1 resolved") {
t.Errorf("gate check --type=timer = %q, want one resolved gate", r.stdout)
}
if g := showGate(t, f, timerGate); g.Status != "closed" {
t.Errorf("expired timer gate %s is %s after gate check, want closed", timerGate, g.Status)
}
if !readyIDs(t, f)[timerTarget] {
t.Errorf("%s is not ready after its timer gate resolved", timerTarget)
}
runTarget := f.create("run target")
runGate := firstJSONField(t, f.mustRun(nil, "gate", "create", "--type=gh:run", "--await-id=ci-wf", "--repo=owner/repo", "--blocks", runTarget, "--json").stdout, "id")
if g := showGate(t, f, runGate); g.AwaitType != "gh:run" || g.AwaitID != "ci-wf" {
t.Errorf("gh:run gate reads back %+v, want await gh:run ci-wf", g)
}
awaited := f.create("awaited bead")
beadTarget := f.create("bead target")
beadGate := firstJSONField(t, f.mustRun(nil, "gate", "create", "--type=bead", "--await-id", awaited, "--blocks", beadTarget, "--json").stdout, "id")
if g := showGate(t, f, beadGate); g.AwaitType != "bead" || g.AwaitID != awaited {
t.Errorf("bead gate reads back %+v, want await bead %s", g, awaited)
}
waiterGate = beadGate
counter.reset()
r = f.mustRun(nil, "gate", "add-waiter", beadGate, "rig/workers/a")
if !strings.Contains(r.stdout, "Added waiter to gate "+beadGate+": rig/workers/a") {
t.Errorf("add-waiter output = %q", r.stdout)
}
if w := writesOf(counter.snapshot()); len(w) != 1 || !strings.HasPrefix(w[0], "PATCH /v0/beads/issues/") {
t.Errorf("add-waiter wrote %v, want one updateIssue", w)
}
counter.reset()
r = f.mustRun(nil, "gate", "add-waiter", beadGate, "rig/workers/a")
if !strings.Contains(r.stdout, "Waiter already registered on gate "+beadGate) {
t.Errorf("repeat add-waiter output = %q", r.stdout)
}
if w := writesOf(counter.snapshot()); len(w) != 0 {
t.Errorf("a repeat add-waiter wrote %v", w)
}
f.mustRun(nil, "gate", "add-waiter", beadGate, "rig/workers/b")
if g := showGate(t, f, beadGate); !slices.Equal(g.Waiters, []string{"rig/workers/a", "rig/workers/b"}) {
t.Errorf("waiters = %v, want [rig/workers/a rig/workers/b]", g.Waiters)
}
f.mustRun(nil, "update", runGate, "--await-id", "12345", "--json")
if g := showGate(t, f, runGate); g.AwaitID != "12345" {
t.Errorf("await_id after update --await-id = %q, want 12345", g.AwaitID)
}
})
// A convoy registering on one gate at once: every adder must exit 0 and
// every waiter must be on the gate. Each round of simultaneous guarded
// writes has one winner, so this pins the retry backoff, not just the
// compare-and-set.
t.Run("concurrent add-waiter", func(t *testing.T) {
const adders = 10
target := f.create("convoy target")
gate := firstJSONField(t, f.mustRun(nil, "gate", "create", "--blocks", target, "--json").stdout, "id")
results := make([]bdResult, adders+1)
var wg sync.WaitGroup
start := make(chan struct{})
for i := 0; i <= adders; i++ {
waiter := fmt.Sprintf("rig/workers/c%d", i%adders) // the last one repeats c0
wg.Add(1)
go func(i int) {
defer wg.Done()
<-start
results[i] = f.run(nil, "gate", "add-waiter", gate, waiter)
}(i)
}
close(start)
wg.Wait()
for i, r := range results {
if r.code != 0 {
t.Errorf("adder %d exited %d: %s", i, r.code, r.stderr)
}
}
got := showGate(t, f, gate).Waiters
slices.Sort(got)
var want []string
for i := 0; i < adders; i++ {
want = append(want, fmt.Sprintf("rig/workers/c%d", i))
}
slices.Sort(want)
if !slices.Equal(got, want) {
t.Errorf("waiters after %d concurrent adders = %v, want each exactly once: %v", adders+1, got, want)
}
})
// gate discover over HTTP: a fake gh answers the run listing, and the
// discovered run ID is recorded through updateIssue (issues.update.gates).
binDir := t.TempDir()
gh := `#!/bin/sh
case "$1 $2" in
"run list") echo '[{"databaseId":4242,"name":"ci-wf","status":"in_progress","conclusion":"","createdAt":"'"$(date -u +%Y-%m-%dT%H:%M:%SZ)"'","workflowName":"ci-wf","headBranch":"main"}]' ;;
*) echo "unexpected gh $*" >&2; exit 3 ;;
esac
`
if err := os.WriteFile(filepath.Join(binDir, "gh"), []byte(gh), 0o755); err != nil {
t.Fatalf("write fake gh: %v", err)
}
ghEnv := []string{"PATH=" + binDir + string(os.PathListSeparator) + os.Getenv("PATH")}
t.Run("discover", func(t *testing.T) {
target := f.create("discover target")
gate := firstJSONField(t, f.mustRun(nil, "gate", "create", "--type=gh:run", "--await-id=ci-wf", "--blocks", target, "--json").stdout, "id")
counter.reset()
r := f.run(ghEnv, "gate", "discover")
if r.code != 0 {
t.Fatalf("gate discover exited %d: %s %s", r.code, r.stdout, r.stderr)
}
if !strings.Contains(r.stdout, "Updated 1 gate(s)") {
t.Errorf("gate discover output = %q, want one updated gate", r.stdout)
}
if w := writesOf(counter.snapshot()); len(w) != 1 || !strings.HasPrefix(w[0], "PATCH /v0/beads/issues/") {
t.Errorf("gate discover wrote %v, want one updateIssue", w)
}
if g := showGate(t, f, gate); g.AwaitID != "4242" {
t.Errorf("await_id after discover = %q, want 4242", g.AwaitID)
}
})
t.Run("refused without the tokens", func(t *testing.T) {
if waiterGate == "" {
t.Skip("the advertised case created no gate")
}
maskedAddr, maskedCounter := startMaskingProxy(t, addr, withoutGateTokens)
m := newHTTPFixture(t, bin, maskedAddr)
target := m.create("masked target")
before := showGate(t, f, waiterGate)
cases := []struct {
name string
args []string
token string
}{
{"gate create", []string{"gate", "create", "--type=timer", "--timeout=1h", "--blocks", target}, "issues.create.gates"},
{"gate create human", []string{"gate", "create", "--blocks", target}, "issues.create.gates"},
{"gate add-waiter", []string{"gate", "add-waiter", waiterGate, "rig/workers/c"}, "issues.update.gates"},
{"update --await-id", []string{"update", waiterGate, "--await-id", "999"}, "issues.update.gates"},
}
for _, tc := range cases {
maskedCounter.reset()
r := m.run(nil, tc.args...)
if r.code == 0 {
t.Errorf("%s against a server without %s exited 0: %s", tc.name, tc.token, r.stdout)
}
if !strings.Contains(r.stderr, tc.token) {
t.Errorf("%s refusal does not name %s: %s", tc.name, tc.token, r.stderr)
}
if w := writesOf(maskedCounter.snapshot()); len(w) != 0 {
t.Errorf("a refused %s wrote %v; the refusal must come before any write", tc.name, w)
}
}
// gate discover finds the run but cannot record it: the gate's error
// names the token, nothing is written, and the command fails rather
// than reporting the gate as updated.
runTarget := f.create("masked discover target")
runGate := firstJSONField(t, f.mustRun(nil, "gate", "create", "--type=gh:run", "--await-id=ci-wf", "--blocks", runTarget, "--json").stdout, "id")
maskedCounter.reset()
r := m.run(ghEnv, "gate", "discover")
if r.code == 0 {
t.Errorf("gate discover against a server without issues.update.gates exited 0: %s", r.stdout)
}
if !strings.Contains(r.stderr, "issues.update.gates") || !strings.Contains(r.stderr, runGate) {
t.Errorf("gate discover refusal does not name the gate and issues.update.gates: %s", r.stderr)
}
if strings.Contains(r.stdout, "Updated 1") {
t.Errorf("gate discover reported the refused gate as updated: %s", r.stdout)
}
if w := writesOf(maskedCounter.snapshot()); len(w) != 0 {
t.Errorf("a refused gate discover wrote %v", w)
}
if g := showGate(t, f, runGate); g.AwaitID != "ci-wf" {
t.Errorf("await_id after a refused discover = %q, want ci-wf untouched", g.AwaitID)
}
if !readyIDs(t, m)[target] {
t.Errorf("%s left the ready set though every gate create was refused", target)
}
after := showGate(t, f, waiterGate)
if after.AwaitID != before.AwaitID || !slices.Equal(after.Waiters, before.Waiters) {
t.Errorf("refused writes changed the gate: before %+v after %+v", before, after)
}
})
}

View file

@ -0,0 +1,185 @@
//go:build cgo
package bdhttp_test
import (
"context"
"encoding/json"
"strings"
"testing"
"time"
"github.com/steveyegge/beads/internal/storage/issueops"
)
// TestE2E_HeartbeatOverHTTP runs `bd heartbeat <id>` — the keepalive gc's
// mol-do-work formula issues every ~90s (`gc bd heartbeat`, corpus shapes
// gc-heartbeat*) — through the real `bd` binary against an in-process `bd
// serve`.
//
// The CLI takes the store's Heartbeater, which over HTTP dials POST
// /v0/beads/issues/{id}:heartbeat. What a worker relies on is pinned here end
// to end: exit 0 and the {"id","status":"heartbeat","owner"} shape for the
// holder, with the row's revision and updated_at UNCHANGED (the heartbeat
// writes only the lease, so the holder's guarded writes keep their token);
// exit 1 for a foreign holder (whose lease stays untouched), a closed issue, a
// wisp and an unclaimed issue, each saying which. Against a server that does
// not advertise issues.heartbeat (an older server's handshake shape) the
// client refuses BEFORE the dial, naming the token, and never falls back.
func TestE2E_HeartbeatOverHTTP(t *testing.T) {
skipUnlessEmbeddedDolt(t)
bin := buildBD(t)
addr, reference := startE2EServerWithStore(t, e2eProjectID, e2eDatabase)
leaseRow := func(id string) string {
t.Helper()
var row string
if err := reference.RunEventsMaintenanceTx(context.Background(), func(ctx context.Context, tx issueops.DBTX) error {
return tx.QueryRowContext(ctx,
"SELECT CONCAT(holder, '|', CAST(lease_expires_at AS CHAR), '|', CAST(heartbeat_at AS CHAR)) FROM leases WHERE issue_id = ?", id,
).Scan(&row)
}); err != nil {
t.Fatalf("read the lease row on %s: %v", id, err)
}
return row
}
ageLease := func(id string) {
t.Helper()
aged := time.Now().UTC().Add(-time.Minute).Truncate(time.Second)
if err := reference.RunEventsMaintenanceTx(context.Background(), func(ctx context.Context, tx issueops.DBTX) error {
_, err := tx.ExecContext(ctx, "UPDATE leases SET lease_expires_at = ?, heartbeat_at = ? WHERE issue_id = ?", aged, aged, id)
return err
}); err != nil {
t.Fatalf("age the lease on %s: %v", id, err)
}
}
heartbeatPosts := func(paths []string) int {
n := 0
for _, p := range paths {
if strings.HasPrefix(p, "POST ") && strings.HasSuffix(p, ":heartbeat") {
n++
}
}
return n
}
t.Run("advertised", func(t *testing.T) {
proxyAddr, counter := startCountingProxy(t, addr)
f := newHTTPFixture(t, bin, proxyAddr)
id := f.create("heartbeat target")
f.mustRun(nil, "update", id, "--claim", "--actor", "worker-7")
before := f.mustRun(nil, "show", id, "--json").stdout
revision := firstJSONField(t, before, "revision")
if revision == "" {
t.Fatalf("bd show --json reported no revision: %s", before)
}
updatedAt := firstJSONField(t, before, "updated_at")
counter.reset()
r := f.mustRun(nil, "heartbeat", id, "--actor", "worker-7", "--json")
var out map[string]any
if err := json.Unmarshal([]byte(strings.TrimSpace(r.stdout)), &out); err != nil {
t.Fatalf("parse bd heartbeat --json: %v\n%s", err, r.stdout)
}
if out["id"] != id || out["status"] != "heartbeat" || out["owner"] != "worker-7" {
t.Errorf("bd heartbeat --json = %v, want {id: %s, status: heartbeat, owner: worker-7}", out, id)
}
if n := heartbeatPosts(counter.snapshot()); n != 1 {
t.Errorf("bd heartbeat sent %d :heartbeat requests, want exactly one: %v", n, counter.snapshot())
}
for _, p := range counter.snapshot() {
if strings.HasPrefix(p, "PATCH ") || (strings.HasPrefix(p, "POST ") && !strings.HasSuffix(p, ":heartbeat")) {
t.Errorf("bd heartbeat sent %s; a heartbeat writes nothing but the lease", p)
}
}
after := f.mustRun(nil, "show", id, "--json").stdout
if got := firstJSONField(t, after, "revision"); got != revision {
t.Errorf("revision moved across a heartbeat: %s -> %s; a guarded write against the pre-heartbeat token would now fail", revision, got)
}
if got := firstJSONField(t, after, "updated_at"); got != updatedAt {
t.Errorf("updated_at moved across a heartbeat: %s -> %s", updatedAt, got)
}
// The holder's guarded write with the pre-heartbeat token still lands.
f.mustRun(nil, "update", id, "--notes", "still mine", "--if-revision", revision, "--actor", "worker-7")
// A second heartbeat is fine: it only moves the expiry later.
f.mustRun(nil, "heartbeat", id, "--actor", "worker-7")
})
t.Run("refusals", func(t *testing.T) {
f := newHTTPFixture(t, bin, addr)
foreign := f.create("held by alice")
f.mustRun(nil, "update", foreign, "--claim", "--actor", "alice")
// Aged first, so a heartbeat that ignored the holder fence would
// really change the row rather than rewrite the claim's own second.
ageLease(foreign)
held := leaseRow(foreign)
r := f.run(nil, "heartbeat", foreign, "--actor", "bob")
if r.code != 1 || !strings.Contains(r.stderr, "claimed by alice") {
t.Errorf("heartbeat by a non-holder: exit %d stderr=%s, want exit 1 naming the holder", r.code, r.stderr)
}
if got := leaseRow(foreign); got != held {
t.Errorf("a refused heartbeat by a non-holder moved alice's lease: %s -> %s", held, got)
}
// Each lease_not_held names the one state it found, and no other.
says := func(what, stderr, want string, not ...string) {
t.Helper()
if !strings.Contains(stderr, want) {
t.Errorf("heartbeat on %s: stderr=%s, want it to say %q", what, stderr, want)
}
for _, n := range not {
if strings.Contains(stderr, n) {
t.Errorf("heartbeat on %s: stderr=%s says %q, which is not the state it found", what, stderr, n)
}
}
}
closed := f.create("closed under its worker")
f.mustRun(nil, "update", closed, "--claim", "--actor", "worker-7")
f.mustRun(nil, "close", closed, "--actor", "worker-7")
r = f.run(nil, "heartbeat", closed, "--actor", "worker-7")
if r.code != 1 {
t.Errorf("heartbeat on a closed issue exited %d, want 1: %s", r.code, r.stderr)
}
says("a closed issue", r.stderr, "is closed", "ephemeral", "not claimed")
wisp := f.create("a wisp is never leased", "--ephemeral")
r = f.run(nil, "heartbeat", wisp, "--actor", "worker-7")
if r.code != 1 {
t.Errorf("heartbeat on a wisp exited %d, want 1: %s", r.code, r.stderr)
}
says("a wisp", r.stderr, "ephemeral wisp", "closed", "not claimed")
unclaimed := f.create("never claimed")
r = f.run(nil, "heartbeat", unclaimed, "--actor", "worker-7")
if r.code != 1 {
t.Errorf("heartbeat on an unclaimed issue exited %d, want 1: %s", r.code, r.stderr)
}
says("an unclaimed issue", r.stderr, "not claimed", "closed", "ephemeral")
})
t.Run("older server mask", func(t *testing.T) {
proxyAddr, counter := startMaskingProxy(t, addr, mcContextMask)
f := newHTTPFixture(t, bin, proxyAddr)
id := f.create("an old server cannot refresh this lease")
f.mustRun(nil, "update", id, "--claim", "--actor", "worker-7")
counter.reset()
r := f.run(nil, "heartbeat", id, "--actor", "worker-7")
if r.code != 1 {
t.Fatalf("bd heartbeat against a server without issues.heartbeat exited %d, want 1: %s", r.code, r.stdout)
}
if !strings.Contains(r.stderr, "issues.heartbeat") {
t.Errorf("refusal does not name the missing capability: %s", r.stderr)
}
for _, p := range counter.snapshot() {
if !strings.HasPrefix(p, "GET ") {
t.Errorf("a refused heartbeat sent %s; the refusal must come before any write", p)
}
}
})
}

View file

@ -0,0 +1,137 @@
//go:build cgo
package bdhttp_test
import (
"encoding/json"
"strings"
"testing"
)
// TestE2E_LinkOverHTTP runs `bd link` through the real `bd` binary against an
// in-process `bd serve`.
//
// bd link writes through the DependencyEditor role (one addDependencies
// request), so it is served over http for any type a workspace spells, well-
// known or not: the server takes any 1-32 character type. Its own checks —
// a non-empty type of at most 32 characters — refuse before anything is
// written, and an edge that already exists with another type reports the
// typed conflict.
func TestE2E_LinkOverHTTP(t *testing.T) {
skipUnlessEmbeddedDolt(t)
bin := buildBD(t)
addr := startE2EServer(t)
proxyAddr, counter := startCountingProxy(t, addr)
f := newHTTPFixture(t, bin, proxyAddr)
t.Run("custom types are served", func(t *testing.T) {
for _, depType := range []string{"owned-by", "ships-in", "available-in", "excluded-from", "advances", "launches", "blocks"} {
from := f.create("link source " + depType)
to := f.create("link target " + depType)
counter.reset()
r := f.mustRun(nil, "link", from, to, "--type", depType, "--json")
var out map[string]any
if err := json.Unmarshal([]byte(strings.TrimSpace(r.stdout)), &out); err != nil {
t.Fatalf("bd link --json: %v\n%s", err, r.stdout)
}
if out["status"] != "added" || out["issue_id"] != from || out["depends_on_id"] != to || out["type"] != depType {
t.Errorf("bd link --type %s --json = %v, want added %s -> %s", depType, out, from, to)
}
adds := 0
for _, p := range counter.snapshot() {
if p == "POST /v0/beads/dependencies:add" {
adds++
}
}
if adds != 1 {
t.Errorf("bd link --type %s sent %d addDependencies requests, want exactly one: %v", depType, adds, counter.snapshot())
}
list := f.mustRun(nil, "dep", "list", from, "--json").stdout
if !depListHas(t, list, to, depType) {
t.Errorf("bd dep list %s does not show the %s edge to %s: %s", from, depType, to, list)
}
}
})
t.Run("text output names both issues", func(t *testing.T) {
from := f.create("text link source")
to := f.create("text link target")
r := f.mustRun(nil, "link", from, to, "--type", "owned-by")
if !strings.Contains(r.stdout, "Linked:") || !strings.Contains(r.stdout, "text link source") ||
!strings.Contains(r.stdout, "text link target") || !strings.Contains(r.stdout, "(owned-by)") {
t.Errorf("bd link output = %q, want the Linked line with both titles and the type", r.stdout)
}
})
t.Run("invalid types refuse before any write", func(t *testing.T) {
from := f.create("invalid link source")
to := f.create("invalid link target")
for _, depType := range []string{"", strings.Repeat("x", 33)} {
counter.reset()
r := f.run(nil, "link", from, to, "--type", depType)
if r.code == 0 {
t.Fatalf("bd link --type %q exited 0: %s", depType, r.stdout)
}
if !strings.Contains(r.stderr, "invalid dependency type") {
t.Errorf("bd link --type %q stderr = %s, want the invalid-type refusal", depType, r.stderr)
}
for _, p := range counter.snapshot() {
if !strings.HasPrefix(p, "GET ") {
t.Errorf("bd link --type %q wrote %s; the refusal must come before any write", depType, p)
}
}
}
if list := f.mustRun(nil, "dep", "list", from, "--json").stdout; depListHas(t, list, to, "") {
t.Errorf("a refused link left an edge %s -> %s: %s", from, to, list)
}
})
t.Run("an edge of another type is a typed conflict", func(t *testing.T) {
from := f.create("conflict source")
to := f.create("conflict target")
f.mustRun(nil, "link", from, to, "--type", "owned-by")
r := f.run(nil, "link", from, to, "--type", "ships-in")
if r.code == 0 {
t.Fatalf("bd link over an existing owned-by edge with ships-in exited 0: %s", r.stdout)
}
// The server answers the role's typed conflict as 409
// dependency_exists, which the client surfaces verbatim.
if !strings.Contains(r.stderr, "dependency_exists") || !strings.Contains(r.stderr, "different type") {
t.Errorf("conflict stderr = %s, want the typed dependency_exists conflict", r.stderr)
}
list := f.mustRun(nil, "dep", "list", from, "--json").stdout
if !depListHas(t, list, to, "owned-by") || depListHas(t, list, to, "ships-in") {
t.Errorf("the conflicting link changed the edge: %s", list)
}
// Re-asserting the same edge is idempotent.
f.mustRun(nil, "link", from, to, "--type", "owned-by")
})
}
// depListHas reports whether `bd dep list --json` lists an edge to target of
// depType (any type when depType is empty).
func depListHas(t *testing.T, out, target, depType string) bool {
t.Helper()
trimmed := strings.TrimSpace(out)
if trimmed == "" || trimmed == "null" {
return false
}
var rows []map[string]any
if err := json.Unmarshal([]byte(trimmed), &rows); err != nil {
t.Fatalf("parse bd dep list --json: %v\n%s", err, out)
}
for _, row := range rows {
if row["id"] != target && row["depends_on_id"] != target {
continue
}
if depType == "" {
return true
}
if row["dependency_type"] == depType || row["type"] == depType {
return true
}
}
return false
}

View file

@ -8,12 +8,16 @@ import (
"testing"
)
// listScopeShapes are the four maintainer-city `bd list` shapes S15b serves,
// one per corpus shape (backend/http/corpus/testdata/corpus.yaml), with the
// token each needs and the titles each must answer on the scope seed:
// listScopeShapes are the tokened `bd list` shapes, with the token each needs
// and the titles each must answer on the scope seed. Five are corpus shapes
// (backend/http/corpus/testdata/corpus.yaml) and one pins the title fold:
// - gc-list-on-boot: gc's default on_boot hook, run on every agent boot;
// - gc-list-on-boot-workflow: the same recovery, workflow lane;
// - mc-list-title: the PR-intake formula's `--title "$SUBJECT"`;
// - gc-polecat-title-contains: the polecat pre-flight's open-bead lookup,
// `--title-contains "$SYMPTOM_KEY"`, folded onto `title`;
// - title-and-title-contains-equal (not a corpus shape): one value under
// both title flags is one `title`;
// - mc-list-id: the pr-review skill's `--id <ids>`.
var listScopeShapes = []struct {
corpusID string
@ -31,6 +35,15 @@ var listScopeShapes = []struct {
{"mc-list-title",
[]string{"list", "--all", "--include-infra", "--json", "--limit", "10", "--title", "CHILD-A"},
"issues.list.title", []string{"child-a"}},
// --title-contains folds onto the same `title` parameter: case-insensitive
// substring, and the status set leaves the closed child-c out.
{"gc-polecat-title-contains",
[]string{"list", "--title-contains", "CHILD", "--status", "open,in_progress,blocked", "--json"},
"issues.list.title", []string{"child-a", "child-b", "child-x"}},
// The same value under both flags is one predicate.
{"title-and-title-contains-equal",
[]string{"list", "--all", "--title", "child-a", "--title-contains", "child-a", "--json"},
"issues.list.title", []string{"child-a"}},
// A closed id in the set is listed under --all; ids outside it are not.
{"mc-list-id",
[]string{"list", "--all", "--id", "{child-c},{loner}", "--json", "--limit", "0"},
@ -111,3 +124,131 @@ func TestE2E_ListScopeFiltersOverHTTP(t *testing.T) {
}
})
}
// listFilterShapes are the `bd list` shapes that ride the listing filters
// behind issues.list.filters, each with the titles it must answer on the seed
// plus seedListFilters. Five are corpus shapes and one pins the title pair the
// fold leaves:
// - wf-session-cleanup: the session-cleanup sweep's closed-and-stale scan;
// - gc-polecat-closed-after: the polecat formula's "has the fix landed"
// check (title substring, closed after a cutoff);
// - list-filter-priority-range, list-filter-exclude-type-no-parent and
// list-filter-updated-after: one representative per remaining family;
// - title-and-title-contains-differ (not a corpus shape): a `--title` and a
// `--title-contains` that differ ride `title` and `title_contains`
// together, and the server applies both.
var listFilterShapes = []struct {
corpusID string
args []string
want []string
}{
{"wf-session-cleanup",
[]string{"list", "--json", "--all", "--include-infra", "--include-gates", "--status", "closed", "--label", "lane:a",
"--closed-before", "2100-01-01T00:00:00Z", "--updated-before", "2100-01-01T00:00:00Z", "--limit", "0"},
[]string{"lane task closed"}},
{"gc-polecat-closed-after",
[]string{"list", "--title-contains", "task", "--status", "closed", "--closed-after", "2000-01-01", "--json"},
[]string{"lane task closed", "other lane task closed"}},
{"list-filter-priority-range",
[]string{"list", "--json", "--priority-min", "1", "--priority-max", "3", "--limit", "0"},
[]string{"child-a", "child-b", "loner", "open task p2", "parent", "tmpl"}},
{"list-filter-exclude-type-no-parent",
[]string{"list", "--json", "--exclude-type", "epic", "--no-parent", "--limit", "0"},
[]string{"loner", "open task p2", "p4 row", "tmpl"}},
{"list-filter-updated-after",
[]string{"list", "--json", "--updated-after", "2000-01-01", "--limit", "0"},
[]string{"child-a", "child-b", "child-x", "loner", "open task p2", "p4 row", "parent", "tmpl"}},
// Either substring alone answers more: "child" every child, "a" the
// lane tasks, parent and open task p2 too.
{"title-and-title-contains-differ",
[]string{"list", "--all", "--title", "child", "--title-contains", "a", "--json"},
[]string{"child-a"}},
}
// seedListFilters adds the rows the filter shapes split: two closed tasks on
// different lanes (the label keeps one out of the session-cleanup scan, the
// title substring keeps child-c out of the polecat check), a P4 row the
// priority range leaves out, and an open P2 task beside it.
func (f *remoteRolesFixture) seedListFilters() {
f.t.Helper()
a := f.create("lane task closed", "-t", "task", "-l", "lane:a")
b := f.create("other lane task closed", "-t", "task", "-l", "lane:b")
f.mustRun(nil, "close", a, "--reason", "done")
f.mustRun(nil, "close", b, "--reason", "done")
f.create("p4 row", "-t", "task", "-p", "4")
f.create("open task p2", "-t", "task", "-p", "2")
}
// withoutListFilters rewrites the handshake into a server that is current in
// every respect but one: it does not advertise issues.list.filters.
func withoutListFilters(body map[string]any) {
caps, _ := body["capabilities"].([]any)
kept := make([]any, 0, len(caps))
for _, c := range caps {
if c != "issues.list.filters" {
kept = append(kept, c)
}
}
body["capabilities"] = kept
}
// TestE2E_ListFilterParityOverHTTP: `bd list`'s time bounds and every other
// filter the listing refused over http now ride listIssues behind the one
// behavior token issues.list.filters, applied by the same Reader role a local
// `bd list` reads through. Each shape must answer the rows an embedded
// workspace answers, and exactly the rows it names.
//
// Against a server that does not advertise the token each shape refuses
// BEFORE dialing listIssues, naming the token, rather than answering a wider
// listing.
func TestE2E_ListFilterParityOverHTTP(t *testing.T) {
skipUnlessEmbeddedDolt(t)
bin := buildBD(t)
addr := startE2EServer(t)
remote := newHTTPFixture(t, bin, addr)
local := newEmbeddedFixture(t, bin)
for _, f := range []*remoteRolesFixture{remote, local} {
f.seed()
f.seedListFilters()
}
for _, shape := range listFilterShapes {
t.Run(shape.corpusID, func(t *testing.T) {
r := remote.run(nil, shape.args...)
if r.code != 0 {
t.Fatalf("http: bd %s failed (exit %d): stderr=%s", strings.Join(shape.args, " "), r.code, r.stderr)
}
l := local.mustRun(nil, shape.args...)
got, want := remote.titlesOf(r.stdout), local.titlesOf(l.stdout)
if !slices.Equal(got, want) {
t.Errorf("http rows %v, embedded rows %v", got, want)
}
if !slices.Equal(got, shape.want) {
t.Errorf("http rows %v, want exactly %v", got, shape.want)
}
})
}
t.Run("a server without issues.list.filters refuses before dialing", func(t *testing.T) {
proxyAddr, counter := startMaskingProxy(t, addr, withoutListFilters)
f := newHTTPFixture(t, bin, proxyAddr)
f.ids = remote.ids // same workspace behind the proxy
for _, shape := range listFilterShapes {
counter.reset()
r := f.run(nil, shape.args...)
if r.code == 0 {
t.Errorf("%s: bd %s exited 0 against a server lacking issues.list.filters: %s", shape.corpusID, strings.Join(shape.args, " "), r.stdout)
continue
}
if !strings.Contains(r.stderr+r.stdout, "issues.list.filters") {
t.Errorf("%s: the refusal does not name issues.list.filters: stdout=%s stderr=%s", shape.corpusID, r.stdout, r.stderr)
}
for _, p := range counter.snapshot() {
if p == "GET /v0/beads/issues" {
t.Errorf("%s: dialed listIssues against a server lacking issues.list.filters: %v", shape.corpusID, counter.snapshot())
break
}
}
}
})
}

View file

@ -53,8 +53,15 @@ func TestE2E_PerCommandRequestBudget(t *testing.T) {
args []string
}{
{"ready", 2, []string{"ready", "--json"}},
// The limit hides rows, and without BD_JSON_ENVELOPE nothing
// prints their count: one listing, no ready:count after it.
{"ready --limit 1", 2, []string{"ready", "--json", "--limit", "1"}},
{"list", 4, []string{"list", "--json"}},
{"show", 1, []string{"show", target, "--json"}},
// The first ready learned the server's external-dependency
// policy from the handshake; a later process reads it from the
// policy cache instead of fetching the context again.
{"ready, policy cached", 1, []string{"ready", "--json"}},
{"create", 2, []string{"create", "budget created", "-t", "task", "--json"}},
{"update --append-notes", 3, []string{"update", target, "--append-notes", "more", "--json"}},
{"update --status", 3, []string{"update", target, "--status", "in_progress", "--json"}},

View file

@ -49,9 +49,24 @@ func TestE2E_SearchOverHTTP(t *testing.T) {
t.Errorf("bd search %s did not match the issue by its id: %v", other, byID)
}
// A flag listIssues publishes nothing for refuses rather than widening the
// search.
if r := bd("search", "routed", "--desc-contains", "pool", "--json"); r.code == 0 {
t.Errorf("bd search --desc-contains succeeded over http; the wire cannot carry it, so it must refuse: %s", r.stdout)
// A search filter rides listIssues behind issues.list.filters and narrows
// rather than being dropped: "pool" is in a TITLE here and in no
// description, so the answer is empty, where a dropped filter would answer
// every routed row.
r = bd("search", "routed", "--desc-contains", "pool", "--json")
if r.code != 0 {
t.Fatalf("bd search --desc-contains failed over http (exit %d): stdout=%s stderr=%s", r.code, r.stdout, r.stderr)
}
if narrowed := jsonIDSet(t, r.stdout); len(narrowed) != 0 {
t.Errorf("bd search routed --desc-contains pool = %v, want nothing: no description contains it", narrowed)
}
// And it matches: a description carrying the token answers exactly that
// row, so the empty answer above is the filter narrowing, not a filter
// that matches nothing for some other reason.
mustRun(t, bd, "update", alsoRouted, "--description", "a lantern in the description", "--json")
matched := jsonIDSet(t, mustRun(t, bd, "search", "routed", "--desc-contains", "LANTERN", "--json").stdout)
if len(matched) != 1 || !matched[alsoRouted] {
t.Errorf("bd search routed --desc-contains LANTERN = %v, want exactly %s, whose description contains it", matched, alsoRouted)
}
}

View file

@ -118,6 +118,7 @@ const (
EventLabelAdded = types.EventLabelAdded
EventLabelRemoved = types.EventLabelRemoved
EventLeaseReclaimed = types.EventLeaseReclaimed
EventLeaseRearmed = types.EventLeaseRearmed
EventCompacted = types.EventCompacted
)

View file

@ -99,6 +99,18 @@ func configuredBackendUnavailable(backend, beadsDir string, cfg *configfile.Conf
}
}
// UnsupportedWorkspaceFormatError is returned by OpenBestAvailable,
// OpenBestAvailableWith, OpenFromConfig and OpenGated when the workspace
// declares a data model this build cannot open: a metadata.json graph_mode
// other than "dependency", such as the "link" workspaces graph-preview builds
// of bd write, or the .beads/graph-preview-format marker those builds write
// beside it (FormatMarker), whatever the metadata says. Nothing was opened,
// created or modified. Match it with errors.As to read BeadsDir, GraphMode and
// FormatMarker; the bd CLI refuses the same workspaces with exit code 16.
// Aliased here because internal/configfile is unimportable outside this
// module.
type UnsupportedWorkspaceFormatError = configfile.UnsupportedWorkspaceFormatError
// Transaction provides atomic multi-operation support within a database transaction.
// Use Storage.RunInTransaction() to obtain a Transaction instance.
type Transaction = beads.Transaction
@ -369,6 +381,9 @@ func Open(ctx context.Context, dbPath string) (Storage, error) {
// name configuration.
// beadsDir is the path to the .beads directory.
func OpenFromConfig(ctx context.Context, beadsDir string) (Storage, error) {
if err := configfile.CheckDiscoveredWorkspaceFormat(beadsDir); err != nil {
return nil, err
}
return dolt.NewFromConfigWithOptions(ctx, beadsDir, &dolt.Config{CreateIfMissing: true})
}
@ -403,6 +418,11 @@ func OpenFromConfig(ctx context.Context, beadsDir string) (Storage, error) {
// operation holds one exclusively; zero means fail fast. A busy gate is
// reported as ErrGateBusy (match with errors.Is).
func OpenGated(ctx context.Context, beadsDir string, wait time.Duration) (Storage, error) {
// Before the gates: taking them creates gate files in and beside a
// workspace this build must leave untouched.
if err := configfile.CheckDiscoveredWorkspaceFormat(beadsDir); err != nil {
return nil, err
}
wsGate, err := workspacegate.ForWorkspace(beadsDir)
if err != nil {
return nil, err

View file

@ -46,6 +46,11 @@ func OpenBestAvailable(ctx context.Context, beadsDir string) (Storage, error) {
// typed refusal (the matching ErrXWithoutOpenWith sentinel), never a silent
// open with the field ignored.
func OpenBestAvailableWith(ctx context.Context, beadsDir string, opts OpenOptions) (Storage, error) {
// Before Load, which can migrate a legacy config.json, and before any
// backend is chosen, as the CLI store factories do.
if err := configfile.CheckDiscoveredWorkspaceFormat(beadsDir); err != nil {
return nil, err
}
cfg, err := configfile.Load(beadsDir)
if err != nil {
return nil, fmt.Errorf("loading storage metadata: %w", err)

View file

@ -32,6 +32,11 @@ func OpenBestAvailable(ctx context.Context, beadsDir string) (Storage, error) {
// rationale; behavior here is identical except that embedded Dolt is
// unavailable without CGO.
func OpenBestAvailableWith(ctx context.Context, beadsDir string, opts OpenOptions) (Storage, error) {
// Before Load, which can migrate a legacy config.json, and before any
// backend is chosen, as the CLI store factories do.
if err := configfile.CheckDiscoveredWorkspaceFormat(beadsDir); err != nil {
return nil, err
}
cfg, err := configfile.Load(beadsDir)
if err != nil {
return nil, fmt.Errorf("loading storage metadata: %w", err)

View file

@ -38,6 +38,10 @@ Which tier a test belongs in, and which command runs it, is decided by
6. Regenerate the CLI reference with `scripts/generate-cli-docs.sh`;
`scripts/check-cli-docs-drift.sh` fails a PR whose command-surface change
leaves the generated docs stale.
7. Regenerate the command-surface goldens and review the testdata diff:
`BD_UPDATE_GOLDEN=1 CGO_ENABLED=1 go test -tags gms_pure_go ./cmd/bd -run '^TestCommand(Tree|Help)Golden$'`.
`TestCommandTreeGolden` fails on any added, removed or reworded command or
flag until you do.
Prefer a flag on an existing command over a new command, and route
recovery/repair operations to `bd doctor --fix`; see the CLI design principles
@ -85,6 +89,9 @@ no linter enforces it).
or serialize the call under `stdioMutex`.
- `TestCorpusGolden` (`protocol/`) — no unreviewed change to the `--json`
wire shapes.
- `TestCommandTreeGolden` and `TestCommandHelpGolden` — no unreviewed change
to the command tree (every command and flag, hidden ones included) or to
the pinned `--help` output in `testdata/command_tree/`.
Fresh-workspace command fixtures call `isolateBeadsDirForTest(t)` before
setup or dispatch and must not use `t.Parallel()`.

View file

@ -49,6 +49,7 @@ go_library(
"backup_restore.go",
"batch.go",
"batch_proxied_server.go",
"blocked_flags.go",
"bootstrap.go",
"branch.go",
"capability_registry.go",
@ -374,9 +375,13 @@ go_library(
"version.go",
"version_proxied_server.go",
"version_tracking.go",
"versioned_history.go",
"versioned_history_switch.go",
"versions.go",
"where.go",
"wisp.go",
"wisp_proxied_server.go",
"workspace_format_guard.go",
"workspace_gate.go",
"worktree.go",
"worktree_cmd.go",
@ -416,6 +421,8 @@ go_library(
"//internal/hooks",
"//internal/httpapi",
"//internal/httpclient",
"//internal/httpclient/wire",
"//internal/initprocs",
"//internal/jira",
"//internal/linear",
"//internal/lockfile",
@ -461,6 +468,7 @@ go_library(
"//internal/utils",
"//internal/validation",
"//internal/versioncheck",
"//internal/versionedhistory",
"//internal/workapi",
"//internal/workspacegate",
"//internal/worktreeremove",
@ -541,6 +549,7 @@ go_test(
"actor_test.go",
"ado_roundtrip_test.go",
"ado_test.go",
"agent_artifacts_embedded_test.go",
"agent_hook_test.go",
"assign_fence_embedded_test.go",
"assign_fence_proxied_test.go",
@ -567,6 +576,7 @@ go_test(
"batch_parity_test.go",
"batch_test.go",
"blocked_embedded_test.go",
"blocked_flags_test.go",
"blocked_proxied_integration_test.go",
"bootstrap_backend_guard_test.go",
"bootstrap_embedded_test.go",
@ -597,6 +607,7 @@ go_test(
"cobra_flag_reset_test.go",
"codex_hook_test.go",
"command_telemetry_test.go",
"command_tree_golden_test.go",
"comment_promote_embedded_test.go",
"comment_proxied_integration_test.go",
"comment_reserved_word_test.go",
@ -707,6 +718,8 @@ go_test(
"dependency_hierarchy_embedded_test.go",
"diff_embedded_test.go",
"directory_flag_test.go",
"discovery_refusal_pins_embedded_test.go",
"discovery_refusal_pins_test.go",
"doctor_backend_guard_test.go",
"doctor_check_gate_test.go",
"doctor_context_test.go",
@ -748,6 +761,7 @@ go_test(
"dolt_remote_add_test.go",
"dolt_remote_adopt_test.go",
"dolt_remote_json_test.go",
"dolt_remote_origin_guard_embedded_test.go",
"dolt_remote_origin_guard_test.go",
"dolt_remote_remove_proxied_integration_test.go",
"dolt_remote_reset_data_embedded_test.go",
@ -797,10 +811,12 @@ go_test(
"find_duplicates_test.go",
"flags_test.go",
"flatten_embedded_test.go",
"format_json_alias_embedded_test.go",
"formula_fixture_proxied_test.go",
"formula_help_test.go",
"formula_primitives_test.go",
"formula_schema_test.go",
"gate_add_waiter_contention_test.go",
"gate_check_listing_test.go",
"gate_check_proxied_integration_test.go",
"gate_discover_test.go",
@ -828,6 +844,8 @@ go_test(
"graph_apply_thread_spawner_embedded_test.go",
"graph_embedded_test.go",
"graph_export_test.go",
"graph_mode_admission_e2e_test.go",
"graph_mode_dependency_embedded_test.go",
"graph_proxied_integration_test.go",
"graph_test.go",
"graph_visual_test.go",
@ -857,6 +875,7 @@ go_test(
"identity_preview_refusal_test.go",
"if_revision_embedded_test.go",
"if_revision_gc_matcher_embedded_test.go",
"if_revision_ordinary_cas_embedded_test.go",
"if_revision_proxied_close_delete_test.go",
"if_revision_proxied_integration_test.go",
"if_revision_reassign_fence_embedded_test.go",
@ -879,10 +898,13 @@ go_test(
"info_kv_exclusion_test.go",
"info_proxied_integration_test.go",
"info_test.go",
"init_agent_test.go",
"init_cancel_e2e_test.go",
"init_commit_test.go",
"init_embedded_test.go",
"init_explicit_beads_dir_embedded_test.go",
"init_external_autostart_test.go",
"init_external_message_test.go",
"init_gateway_test.go",
"init_git_bootstrap_routing_test.go",
"init_guard_force_e2e_test.go",
@ -931,6 +953,8 @@ go_test(
"legacy_upgrade_guard_e2e_test.go",
"legacy_upgrade_guard_empty_root_test.go",
"legacy_upgrade_guard_external_server_test.go",
"legacy_upgrade_guard_init_flag_e2e_test.go",
"legacy_upgrade_guard_init_flag_test.go",
"legacy_upgrade_guard_test.go",
"legacy_upgrade_guard_witness_test.go",
"linear_roundtrip_test.go",
@ -995,7 +1019,9 @@ go_test(
"mol_bond_gwn_test.go",
"mol_bond_proxied_integration_test.go",
"mol_bond_ref_attach_test.go",
"mol_bond_routing_test.go",
"mol_bond_test.go",
"mol_bond_var_validation_test.go",
"mol_burn_proxied_integration_test.go",
"mol_current_proxied_integration_test.go",
"mol_distill_proxied_integration_test.go",
@ -1080,6 +1106,7 @@ go_test(
"ready_embedded_test.go",
"ready_explain_ids_test.go",
"ready_input_test.go",
"ready_json_no_total_test.go",
"ready_max_rows_proxied_test.go",
"ready_max_rows_test.go",
"ready_proxied_integration_test.go",
@ -1115,6 +1142,7 @@ go_test(
"restore_test.go",
"root_context_lifecycle_test.go",
"routed_local_near_miss_test.go",
"routed_mutation_test.go",
"routed_test.go",
"routing_notice_test.go",
"routing_read_remote_test.go",
@ -1141,6 +1169,7 @@ go_test(
"serve_delete_proxied_integration_test.go",
"serve_dependencies_proxied_integration_test.go",
"serve_edge_counts_proxied_integration_test.go",
"serve_graph_mode_env_test.go",
"serve_inprocess_test.go",
"serve_list_sort_proxied_integration_test.go",
"serve_proxied_integration_test.go",
@ -1236,6 +1265,7 @@ go_test(
"test_helpers_test.go",
"test_repo_beads_guard_darwin_test.go",
"test_repo_beads_guard_test.go",
"test_repo_git_guard_test.go",
"test_wait_helper_test.go",
"thread_test.go",
"tips_example_test.go",
@ -1282,6 +1312,14 @@ go_test(
"version_embedded_test.go",
"version_test.go",
"version_tracking_test.go",
"versioned_history_construction_test.go",
"versioned_history_e2e_test.go",
"versioned_history_serve_e2e_test.go",
"versioned_history_switch_scan_embedded_test.go",
"versioned_history_switch_scan_proxied_integration_test.go",
"versioned_history_switch_test.go",
"versions_switch_embedded_test.go",
"versions_test.go",
"where_cgo_test.go",
"where_embedded_test.go",
"where_test.go",
@ -1291,6 +1329,7 @@ go_test(
"wisp_gc_purge_closed_embedded_test.go",
"wisp_proxied_integration_test.go",
"wisp_test.go",
"workspace_format_guard_test.go",
"workspace_gate_test.go",
"workspace_identity_test.go",
"worktree_cmd_test.go",
@ -1311,6 +1350,7 @@ go_test(
":go_srcs",
":preflight_go_fixture",
"//:bd_test_files",
"//:go_srcs",
"//cmd/bd/doctor:go_srcs",
"//cmd/bd/doctor/fix:go_srcs",
"//internal/storage/embeddeddolt/cmd:go_srcs",
@ -1345,6 +1385,8 @@ go_test(
"//internal/httpapi",
"//internal/httpclient",
"//internal/httpclient/encode",
"//internal/httpclient/wire",
"//internal/initprocs",
"//internal/linear",
"//internal/metrics",
"//internal/migration",
@ -1376,6 +1418,7 @@ go_test(
"//internal/storage/uow",
"//internal/storage/versioncontrolops",
"//internal/telemetry",
"//internal/templates/agents",
"//internal/testutil",
"//internal/testutil/bazeltest",
"//internal/testutil/credentialcmd",
@ -1448,7 +1491,7 @@ go_test(
)
# bd_embedded_test and bd_embedded_part2_test run the TestEmbedded* functions
# of *_embedded_test.go between them: the manifest's 100-shard block
# of cmd/bd's _test.go files between them: the manifest's 100-shard block
# (duration-balanced; see scripts/ci/embedded_cmd_test_durations.json) is
# more than Bazel's 50-shard cap per rule, so bd_embedded_test runs its
# shards 1-50 and bd_embedded_part2_test its shards 51-100

View file

@ -0,0 +1,310 @@
//go:build cgo
package main
import (
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"github.com/steveyegge/beads/internal/templates/agents"
)
// TestEmbeddedInitAgentArtifactsGolden pins the Claude agent artifacts a real
// `bd init` writes — .claude/settings.json with its hook events and commands,
// CLAUDE.md and AGENTS.md with their managed sections — and what
// `bd setup claude --check`, `--remove` and a reinstall then report and leave
// behind, through the bd binary. Each scenario is a transcript golden under
// testdata/agent_artifacts/, so a change to any artifact or outcome (a new
// hook event, a changed command, new template text and its hash) shows up as
// a reviewed golden diff.
//
// A managed section is shown by its BEGIN marker line (profile and hash) and a
// pointer to the internal/templates/agents golden that pins its bytes
// (TestManagedSectionGolden), after checking the file holds exactly that
// section; one that matches no rendered variant is shown in full. The
// in-process `bd setup claude` scenarios are pinned by
// TestClaudeSetupArtifactsGolden in cmd/bd/setup.
//
// The scenarios run a direct (embedded) bd init with no Dolt remote. Not
// pinned here: a proxied-server bd init, which installs no Codex section and
// decides HasRemote from its own remote URL; a bd init with a remote, which
// renders the managed section's with-remote variant; and the Cursor files.
// AGENTS.md is shown in full apart from its managed section, so a change to
// its wrapper text or its Codex section can pass the cmd/bd/setup and
// internal/templates/agents tests and fail only here.
//
// bd runs with HOME outside the project, so an artifact written to the home
// directory instead of the project shows up under $HOME.
//
// Regenerate with
//
// BEADS_TEST_EMBEDDED_DOLT=1 BD_UPDATE_GOLDEN=1 go test -tags gms_pure_go ./cmd/bd/ -run TestEmbeddedInitAgentArtifactsGolden
func TestEmbeddedInitAgentArtifactsGolden(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}
t.Parallel()
bd := buildEmbeddedBD(t)
scenarios := []struct {
name string
initArgs []string
steps [][]string
}{
{
name: "init-default",
initArgs: []string{"--prefix", "aa"},
steps: [][]string{
{"setup", "claude", "--check"},
{"setup", "claude"},
{"setup", "claude", "--remove"},
{"setup", "claude", "--check"},
{"setup", "claude"},
{"setup", "claude", "--check"},
},
},
{
name: "init-agents-profile-full",
initArgs: []string{"--prefix", "ab", "--agents-profile", "full"},
steps: [][]string{
{"setup", "claude", "--check"},
},
},
}
for _, sc := range scenarios {
t.Run(sc.name, func(t *testing.T) {
t.Parallel()
// bdInit, with HOME in a directory of its own.
dir, home := t.TempDir(), t.TempDir()
initGitRepoAt(t, dir)
database, seeded := seededInitDatabase(sc.initArgs)
if seeded {
seedEmbeddedSchema(t, dir, database)
}
initArgs := append([]string{"init", "--quiet"}, sc.initArgs...)
if stdout, stderr, exitCode := runAgentArtifactCommand(t, bd, dir, home, initArgs...); exitCode != 0 {
t.Fatalf("bd %s: exit %d\nstdout:\n%s\nstderr:\n%s", strings.Join(initArgs, " "), exitCode, stdout, stderr)
}
if seeded {
requireSeededEmbeddedInit(t, filepath.Join(dir, ".beads"), database)
}
var transcript strings.Builder
fmt.Fprintf(&transcript, "# bd init agent artifact transcript: %s\n", sc.name)
fmt.Fprintf(&transcript, "# Regenerate with BEADS_TEST_EMBEDDED_DOLT=1 BD_UPDATE_GOLDEN=1 go test -tags gms_pure_go ./cmd/bd/ -run TestEmbeddedInitAgentArtifactsGolden\n")
fmt.Fprintf(&transcript, "\n=== bd %s\n", strings.Join(initArgs, " "))
previous := map[string]string{}
writeAgentArtifactChanges(t, &transcript, dir, home, previous)
for _, args := range sc.steps {
stdout, stderr, exitCode := runAgentArtifactCommand(t, bd, dir, home, args...)
fmt.Fprintf(&transcript, "\n=== bd %s\n", strings.Join(args, " "))
fmt.Fprintf(&transcript, "exit: %d\n", exitCode)
writeAgentArtifactBlock(&transcript, "stdout", normalizeAgentArtifactOutput(stdout, dir, home))
writeAgentArtifactBlock(&transcript, "stderr", normalizeAgentArtifactOutput(stderr, dir, home))
writeAgentArtifactChanges(t, &transcript, dir, home, previous)
}
assertAgentArtifactGolden(t, filepath.Join("testdata", "agent_artifacts", sc.name+".golden"), transcript.String())
})
}
}
// agentArtifactPaths are the Claude agent artifacts bd init and bd setup
// claude write in a project ($PROJECT), and those in the home directory
// ($HOME): the $HOME/.claude/ files a global install writes, and the
// $HOME/CLAUDE.md an older --global run from $HOME wrote.
var agentArtifactPaths = []string{
"$PROJECT/.claude/settings.json",
"$PROJECT/.claude/settings.local.json",
"$PROJECT/AGENTS.md",
"$PROJECT/CLAUDE.md",
"$HOME/.claude/settings.json",
"$HOME/.claude/CLAUDE.md",
"$HOME/CLAUDE.md",
}
// agentArtifactManagedSections maps each managed section bd renders to the
// internal/templates/agents golden file that pins its bytes.
var agentArtifactManagedSections = []struct {
golden string
profile agents.Profile
opts agents.RenderOpts
}{
{golden: "managed-section-minimal.md", profile: agents.ProfileMinimal, opts: agents.RenderOpts{HasRemote: true}},
{golden: "managed-section-minimal-no-remote.md", profile: agents.ProfileMinimal, opts: agents.RenderOpts{}},
{golden: "managed-section-minimal-user.md", profile: agents.ProfileMinimal, opts: agents.UserLevelRenderOpts()},
{golden: "managed-section-full.md", profile: agents.ProfileFull, opts: agents.RenderOpts{HasRemote: true}},
{golden: "managed-section-full-no-remote.md", profile: agents.ProfileFull, opts: agents.RenderOpts{}},
{golden: "managed-section-full-user.md", profile: agents.ProfileFull, opts: agents.UserLevelRenderOpts()},
}
// elideAgentArtifactManagedSection replaces the body of a managed section
// that is byte-identical to a rendered variant with a pointer to that
// variant's golden, keeping the BEGIN marker line (profile and hash) and the
// END marker.
func elideAgentArtifactManagedSection(content string) string {
const endMarker = "<!-- END BEADS INTEGRATION -->\n"
begin := strings.Index(content, "<!-- BEGIN BEADS INTEGRATION")
if begin < 0 {
return content
}
rel := strings.Index(content[begin:], endMarker)
if rel < 0 {
return content
}
end := begin + rel + len(endMarker)
section := content[begin:end]
for _, v := range agentArtifactManagedSections {
if section == agents.RenderSectionWithOpts(v.profile, v.opts) {
marker, _, _ := strings.Cut(section, "\n")
return content[:begin] + marker + "\n[managed section body: byte-identical to internal/templates/agents/testdata/" + v.golden + "]\n" + endMarker + content[end:]
}
}
return content
}
// runAgentArtifactCommand runs bd in dir with HOME at home and returns its
// stdout, stderr and exit code.
func runAgentArtifactCommand(t *testing.T, bd, dir, home string, args ...string) (stdout, stderr string, exitCode int) {
t.Helper()
cmd := exec.Command(bd, args...)
cmd.Dir = dir
cmd.Env = agentArtifactEnv(dir, home)
outBuf, errBuf, err := runCommandBuffers(t, cmd)
if err != nil {
var exitErr *exec.ExitError
if !errors.As(err, &exitErr) {
t.Fatalf("bd %s: %v", strings.Join(args, " "), err)
}
exitCode = exitErr.ExitCode()
}
return outBuf.String(), errBuf.String(), exitCode
}
// agentArtifactEnv is bdEnv(dir) with HOME at home and without the caller's
// BD_OTEL_* and OTEL_* variables: bd warns on stderr about a legacy BD_OTEL_*
// one whether or not telemetry is on, and the transcript pins stderr byte for
// byte. (clearTelemetryEnv cannot be used: it calls t.Setenv, and these tests
// run in parallel.)
func agentArtifactEnv(dir, home string) []string {
var env []string
for _, e := range bdEnv(dir) {
if strings.HasPrefix(e, "BD_OTEL_") || strings.HasPrefix(e, "OTEL_") || strings.HasPrefix(e, "HOME=") {
continue
}
env = append(env, e)
}
return append(env, "HOME="+home)
}
// writeAgentArtifactChanges appends every artifact created, modified or
// deleted since previous (which it then updates), with its contents.
func writeAgentArtifactChanges(t *testing.T, b *strings.Builder, dir, home string, previous map[string]string) {
t.Helper()
roots := strings.NewReplacer("$PROJECT", dir, "$HOME", home)
changed := false
for _, path := range agentArtifactPaths {
data, err := os.ReadFile(filepath.FromSlash(roots.Replace(path)))
before, existed := previous[path]
switch {
case os.IsNotExist(err):
if existed {
fmt.Fprintf(b, "--- files: deleted %s\n", path)
delete(previous, path)
changed = true
}
case err != nil:
t.Fatalf("read %s: %v", path, err)
case !existed || before != string(data):
verb := "created"
if existed {
verb = "modified"
}
shown := string(data)
if strings.HasSuffix(path, ".md") {
shown = elideAgentArtifactManagedSection(shown)
}
writeAgentArtifactBlock(b, fmt.Sprintf("files: %s %s", verb, path), shown)
previous[path] = string(data)
changed = true
}
}
if !changed {
b.WriteString("--- files: unchanged\n")
}
}
// writeAgentArtifactBlock appends a titled block, marking empty content and a
// missing trailing newline so neither is lost in the golden.
func writeAgentArtifactBlock(b *strings.Builder, title, content string) {
fmt.Fprintf(b, "--- %s\n", title)
switch {
case content == "":
b.WriteString("(empty)\n")
case !strings.HasSuffix(content, "\n"):
b.WriteString(content)
b.WriteString("\n(no newline at end of file)\n")
default:
b.WriteString(content)
}
}
// normalizeAgentArtifactOutput replaces the project and home directories (as
// given and with symlinks resolved, since bd reports the paths it sees) with
// $PROJECT and $HOME and uses forward slashes, so the transcript is the same
// on every host.
func normalizeAgentArtifactOutput(s, dir, home string) string {
for _, root := range []struct{ path, label string }{{dir, "$PROJECT"}, {home, "$HOME"}} {
if resolved, err := filepath.EvalSymlinks(root.path); err == nil && resolved != root.path {
s = strings.ReplaceAll(s, resolved, root.label)
}
s = strings.ReplaceAll(s, root.path, root.label)
}
if filepath.Separator != '/' {
s = strings.ReplaceAll(s, string(filepath.Separator), "/")
}
return s
}
// assertAgentArtifactGolden compares got with the golden file at path, or
// rewrites the file when BD_UPDATE_GOLDEN=1.
func assertAgentArtifactGolden(t *testing.T, path, got string) {
t.Helper()
if os.Getenv("BD_UPDATE_GOLDEN") == "1" {
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
t.Fatalf("mkdir %s: %v", filepath.Dir(path), err)
}
if err := os.WriteFile(path, []byte(got), 0o644); err != nil {
t.Fatalf("write golden %s: %v", path, err)
}
t.Logf("updated golden %s", path)
return
}
want, err := os.ReadFile(path)
if err != nil {
t.Fatalf("read golden %s (regenerate with BD_UPDATE_GOLDEN=1): %v", path, err)
}
if got == string(want) {
return
}
wantLines, gotLines := strings.Split(string(want), "\n"), strings.Split(got, "\n")
line := func(lines []string, i int) string {
if i >= len(lines) {
return "(end of output)"
}
return fmt.Sprintf("%q", lines[i])
}
i := 0
for i < len(wantLines) && i < len(gotLines) && wantLines[i] == gotLines[i] {
i++
}
t.Errorf("bd init agent artifacts drifted from %s (regenerate with BD_UPDATE_GOLDEN=1 if intended)\nfirst difference at line %d:\n want: %s\n got: %s\n--- got ---\n%s", path, i+1, line(wantLines, i), line(gotLines, i), got)
}

View file

@ -43,7 +43,7 @@ func bdRunOK(t *testing.T, bd, dir string, args ...string) string {
return string(out)
}
// TestReassignFenceCLI drives the bd-98s5c live-claim reassign fence
// TestEmbeddedReassignFenceCLI drives the bd-98s5c live-claim reassign fence
// end-to-end: plain `bd update -a` and `bd assign` were the last unfenced
// cross-actor takeover path (--claim, unclaim, and close all refuse without
// --force). The fence must refuse ONLY the silent steamroll — a different
@ -51,7 +51,7 @@ func bdRunOK(t *testing.T, bd, dir string, args ...string) string {
// leave routine dispatch untouched: open-bead reassigns, self-edits,
// idempotent re-asserts, pool-alias takes, and holder-aware --if-assignee
// transfers all proceed without --force.
func TestReassignFenceCLI(t *testing.T) {
func TestEmbeddedReassignFenceCLI(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}

View file

@ -12,10 +12,23 @@ import (
// the rejection inspects it (read-only) so a workspace that already holds a Dolt
// database is told to fix the stale "backend" value rather than to export and
// reinitialize. Pass "" only where there is genuinely no workspace directory.
//
// It also refuses metadata that declares a workspace format this build cannot
// open (checkWorkspaceFormat). Command admission refuses those first, and the
// store factories check before their migrating configfile.Load
// (checkDiscoveredWorkspaceFormat), so here it backs up any other caller that
// validates metadata it loaded itself. It returns early for a nil cfg, so that
// backstop covers the graph format marker only when metadata was loaded; a
// caller that may have none must check beadsDir with
// checkDiscoveredWorkspaceFormat or command admission first, as every caller
// does today.
func validateConfiguredBackend(cfg *configfile.Config, beadsDir string) error {
if cfg == nil {
return nil
}
if err := checkWorkspaceFormat(cfg, beadsDir); err != nil {
return err
}
if backends.Registered(cfg.Backend) {
return nil
}
@ -80,14 +93,16 @@ func openStoreError(backendName string, err error) error {
return fmt.Errorf("failed to open database: %w", err)
}
// backendNameForErrorFraming best-effort loads metadata.json to learn which
// backendNameForErrorFraming best-effort reads metadata.json to learn which
// backend a failed open was for, so a caller that does not already have cfg
// in scope (for example direct mode's single-shot store-open) can still give
// openStoreError the name it needs. A failure to even read the config
// degrades to "" — openStoreError's default, Dolt-shaped framing — rather
// than compounding one error with another.
// than compounding one error with another. It reads with LoadForDiscovery:
// the open it frames may have just refused the workspace, and
// configfile.Load would migrate a legacy config.json into metadata.json.
func backendNameForErrorFraming(beadsDir string) string {
cfg, err := configfile.Load(beadsDir)
cfg, err := configfile.LoadForDiscovery(beadsDir)
if err != nil || cfg == nil {
return ""
}
@ -95,6 +110,12 @@ func backendNameForErrorFraming(beadsDir string) string {
}
func loadDoltBackendConfig(beadsDir string) (*configfile.Config, error) {
// Refuse a workspace format this build cannot open before configfile.Load,
// which would otherwise migrate a legacy config.json into metadata.json
// before requireDoltBackend's own format check could refuse it.
if err := checkDiscoveredWorkspaceFormat(beadsDir); err != nil {
return nil, err
}
cfg, err := configfile.Load(beadsDir)
if err != nil {
return nil, fmt.Errorf("loading config: %w", err)

View file

@ -53,6 +53,8 @@ After adding, run 'bd backup sync' to push your data.`,
SilenceUsage: true,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
CheckReadonly("backup init")
evt := metrics.NewCommandEvent("backup-init")
defer func() {
if c := metrics.Global(); c != nil {
@ -134,6 +136,8 @@ Run 'bd backup init <path>' first to configure a destination.`,
SilenceUsage: true,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
CheckReadonly("backup sync")
evt := metrics.NewCommandEvent("backup-sync")
defer func() {
if c := metrics.Global(); c != nil {
@ -439,6 +443,8 @@ backup configuration. The backup data at the destination is not deleted.`,
SilenceUsage: true,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
CheckReadonly("backup remove")
evt := metrics.NewCommandEvent("backup-remove")
defer func() {
if c := metrics.Global(); c != nil {

View file

@ -217,3 +217,78 @@ func TestEmbeddedBackupConcurrent(t *testing.T) {
t.Error("backup destination should exist after concurrent syncs")
}
}
// TestEmbeddedBackupRestoreStrictReadonly pins the refusal of a strict
// --readonly restore. A restore replaces the store, so CheckReadonly must stop
// it with the standard message before the command takes the exclusive workspace
// gate. Embedded mode used to be stopped only by the storage layer
// ("embeddeddolt: store is read-only"), after the gate had already left its
// holder files in the workspace. The control proves the fixture really does
// restore when --readonly is not asked for, so "the store is unchanged" below
// cannot be vacuous.
func TestEmbeddedBackupRestoreStrictReadonly(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt backup tests")
}
t.Parallel()
bd := buildEmbeddedBD(t)
// newWorkspace returns a workspace whose live store holds one issue its
// backup does not (three against two), so a restore that really ran shows up
// as a changed issue count. Each case gets its own: a restore that runs
// replaces the store and would hide a leak from the next.
newWorkspace := func(t *testing.T, prefix string) (dir, backupDir string) {
t.Helper()
dir, _, _ = bdInit(t, bd, "--prefix", prefix)
bdCreateSilent(t, bd, dir, "issue in the backup A")
bdCreateSilent(t, bd, dir, "issue in the backup B")
backupDir = filepath.Join(t.TempDir(), "dolt-backup")
if err := os.MkdirAll(backupDir, 0o750); err != nil {
t.Fatal(err)
}
bdBackup(t, bd, dir, "init", "file://"+backupDir)
bdBackup(t, bd, dir, "sync")
bdCreateSilent(t, bd, dir, "issue created after the backup")
return dir, backupDir
}
t.Run("control_restore_without_readonly", func(t *testing.T) {
dir, backupDir := newWorkspace(t, "rrctl")
stdout, stderr, code := runBDMigrationFreeze(t, bd, dir, "backup", "restore", "--force", backupDir)
if code != 0 {
t.Fatalf("restore without --readonly exited %d\nstdout:\n%s\nstderr:\n%s", code, stdout, stderr)
}
if !strings.Contains(stdout, "Restore complete") {
t.Errorf("stdout is missing %q:\n%s", "Restore complete", stdout)
}
if got := len(bdListJSON(t, bd, dir)); got != 2 {
t.Errorf("issue count after a real restore = %d, want 2: the backup holds two issues and the live store held three", got)
}
})
for _, tc := range []struct {
name string
prefix string
flags []string
}{
{"readonly", "rrro", []string{"--readonly"}},
{"readonly_sandbox", "rrrosb", []string{"--readonly", "--sandbox"}},
} {
t.Run(tc.name, func(t *testing.T) {
dir, backupDir := newWorkspace(t, tc.prefix)
before := snapshotWorkspace(t, dir)
args := append(append([]string{}, tc.flags...), "backup", "restore", "--force", backupDir)
stdout, stderr, code := runBDMigrationFreeze(t, bd, dir, args...)
assertStrictReadonlyRestoreRefused(t, stdout, stderr, code)
assertWorkspaceUnchanged(t, dir, before)
if got := len(bdListJSON(t, bd, dir)); got != 3 {
t.Errorf("issue count after the refused restore = %d, want 3: the restore replaced the store", got)
}
})
}
}

View file

@ -34,6 +34,8 @@ To initialize and restore in one step, use: bd init && bd backup restore`,
SilenceUsage: true,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
CheckReadonly("backup restore")
evt := metrics.NewCommandEvent("backup-restore")
defer func() {
if c := metrics.Global(); c != nil {

View file

@ -4,14 +4,22 @@ package main
import (
"context"
"encoding/json"
"fmt"
"os"
"path/filepath"
"slices"
"sort"
"strings"
"testing"
"time"
"github.com/steveyegge/beads/internal/beads"
"github.com/steveyegge/beads/internal/configfile"
"github.com/steveyegge/beads/internal/git"
"github.com/steveyegge/beads/internal/storage/dolt"
"github.com/steveyegge/beads/internal/testutil"
"github.com/steveyegge/beads/internal/types"
)
func TestBackupRestoreMissingDir(t *testing.T) {
@ -84,3 +92,257 @@ func TestSyncProjectIDFromDB_NoWorkspaceUsesActiveWorkspaceError(t *testing.T) {
t.Fatalf("syncProjectIDFromDB should not create local .beads, stat err = %v", statErr)
}
}
// strictReadonlyRestoreRefusal is the line CheckReadonly prints when a write
// command is run under strict --readonly.
const strictReadonlyRestoreRefusal = "Error: operation 'backup restore' is not allowed in read-only mode\n"
// assertStrictReadonlyRestoreRefused checks one refused `bd --readonly backup
// restore` run: the standard CheckReadonly refusal (text and exit code), nothing
// on stdout, and none of the storage-layer message that embedded mode gives when
// the command gets past CheckReadonly and opens the store.
func assertStrictReadonlyRestoreRefused(t *testing.T, stdout, stderr string, code int) {
t.Helper()
if code != 1 {
t.Errorf("exit code = %d, want 1\nstdout:\n%s\nstderr:\n%s", code, stdout, stderr)
}
if !strings.Contains(stderr, strictReadonlyRestoreRefusal) {
t.Errorf("stderr is missing the standard refusal %q:\n%s", strictReadonlyRestoreRefusal, stderr)
}
if strings.Contains(stderr, "embeddeddolt: store is read-only") {
t.Errorf("stderr carries the storage-layer refusal, so the command opened the store before being refused:\n%s", stderr)
}
if strings.TrimSpace(stdout) != "" {
t.Errorf("stdout should be empty when the restore is refused, got:\n%s", stdout)
}
}
// workspaceSnapshot is what a refused command must leave alone: the entries of
// the project directory (the workspace gate file and its holder sidecar sit
// beside .beads, not in it) and everything below .beads, content included.
type workspaceSnapshot struct {
projectEntries []string
beads readonlyTreeSnapshot
}
func snapshotWorkspace(t *testing.T, dir string) workspaceSnapshot {
t.Helper()
entries, err := os.ReadDir(dir)
if err != nil {
t.Fatal(err)
}
names := make([]string, 0, len(entries))
for _, e := range entries {
names = append(names, e.Name())
}
return workspaceSnapshot{
projectEntries: names,
beads: snapshotReadonlyTree(t, filepath.Join(dir, ".beads")),
}
}
// assertWorkspaceUnchanged fails, naming each path, when the workspace under dir
// no longer matches a snapshot taken before a refused command.
func assertWorkspaceUnchanged(t *testing.T, dir string, before workspaceSnapshot) {
t.Helper()
after := snapshotWorkspace(t, dir)
var diffs []string
for _, name := range before.projectEntries {
if !slices.Contains(after.projectEntries, name) {
diffs = append(diffs, "removed: "+name)
}
}
for _, name := range after.projectEntries {
if !slices.Contains(before.projectEntries, name) {
diffs = append(diffs, "created: "+name)
}
}
for path, want := range before.beads.Entries {
switch got, ok := after.beads.Entries[path]; {
case !ok:
diffs = append(diffs, "removed: .beads/"+path)
case got != want:
diffs = append(diffs, "changed: .beads/"+path)
}
}
for path := range after.beads.Entries {
if _, ok := before.beads.Entries[path]; !ok {
diffs = append(diffs, "created: .beads/"+path)
}
}
if len(diffs) == 0 {
return
}
sort.Strings(diffs)
const show = 20
if len(diffs) > show {
diffs = append(diffs[:show], fmt.Sprintf("... and %d more", len(diffs)-show))
}
t.Errorf("the refused restore changed the workspace:\n%s", strings.Join(diffs, "\n"))
}
// TestBackupRestoreStrictReadonlyServerMode is the server-mode counterpart of
// TestEmbeddedBackupRestoreStrictReadonly. Server mode is where the missing
// refusal mattered: no storage layer stops a server connection, so a
// `bd --readonly backup restore --force` ran to the end and replaced the store.
// It drives the built bd as a subprocess because CheckReadonly exits the
// process. Both the fixture's backup and the restore run inside the Dolt
// server, against the same path on the server's own filesystem, so a local
// and a containerized test server both serve.
func TestBackupRestoreStrictReadonlyServerMode(t *testing.T) {
if testDoltServerPort == 0 {
t.Skip("Dolt test server not available")
}
if testutil.DoltContainerCrashed() {
t.Skipf("Dolt test server crashed: %v", testutil.DoltContainerCrashError())
}
bd := buildBDForInitTests(t)
// newWorkspace builds a server-mode workspace on the test server whose live
// store holds one issue its backup does not (three against two), so a restore
// that really ran shows up as a changed issue count. Each case gets its own: a
// restore that runs replaces the store and would hide a leak from the next.
newWorkspace := func(t *testing.T) (dir string, env []string, backupDir string) {
t.Helper()
dir = t.TempDir()
beadsDir := filepath.Join(dir, ".beads")
if err := os.MkdirAll(beadsDir, 0o700); err != nil {
t.Fatal(err)
}
database := uniqueTestDBName(t)
if err := (&configfile.Config{
Backend: configfile.BackendDolt,
DoltMode: configfile.DoltModeServer,
DoltServerHost: "127.0.0.1",
DoltServerPort: testDoltServerPort,
DoltDatabase: database,
}).Save(beadsDir); err != nil {
t.Fatalf("save workspace metadata: %v", err)
}
ctx := context.Background()
seedStore, err := dolt.New(ctx, &dolt.Config{
Path: filepath.Join(beadsDir, "dolt"),
BeadsDir: beadsDir,
ServerHost: "127.0.0.1",
ServerPort: testDoltServerPort,
Database: database,
CreateIfMissing: true,
})
if err != nil {
t.Fatalf("create the server-mode database: %v", err)
}
t.Cleanup(func() { dropTestDatabase(database, testDoltServerPort) })
defer func() { _ = seedStore.Close() }()
if err := seedStore.SetConfig(ctx, "issue_prefix", "rr"); err != nil {
t.Fatalf("set issue_prefix: %v", err)
}
seed := func(id, title string) {
t.Helper()
now := time.Now()
issue := &types.Issue{
ID: id,
Title: title,
Status: types.StatusOpen,
Priority: 2,
IssueType: types.TypeTask,
CreatedAt: now,
UpdatedAt: now,
}
if err := seedStore.CreateIssue(ctx, issue, "test-user"); err != nil {
t.Fatalf("create issue %s: %v", id, err)
}
}
commit := func(message string) {
t.Helper()
if err := seedStore.Commit(ctx, message); err != nil && !strings.Contains(err.Error(), "nothing to commit") {
t.Fatalf("commit %q: %v", message, err)
}
}
seed("rr-1", "issue in the backup A")
seed("rr-2", "issue in the backup B")
commit("issues the backup holds")
backupDir = filepath.Join(t.TempDir(), "dolt-backup")
if err := os.MkdirAll(backupDir, 0o750); err != nil {
t.Fatal(err)
}
if err := seedStore.BackupDatabase(ctx, backupDir); err != nil {
t.Fatalf("back up the database (the Dolt server must be able to write %s): %v", backupDir, err)
}
seed("rr-3", "issue created after the backup")
commit("issue the backup lacks")
env = []string{
"BEADS_TEST_MODE=1",
// The subprocess connects to a testdb_* database on the test server;
// this is the opt-in the test-database firewall asks for.
"BEADS_TEST_SERVER=1",
"BEADS_DIR=" + beadsDir,
"XDG_CONFIG_HOME=" + t.TempDir(),
// Keep the subprocess's circuit-breaker state in the suite's own
// directory rather than the host's temp dir.
"BEADS_TEST_CIRCUIT_DIR=" + os.Getenv("BEADS_TEST_CIRCUIT_DIR"),
}
return dir, env, backupDir
}
issueCount := func(t *testing.T, dir string, env []string) int {
t.Helper()
stdout, stderr, code := runBDMigrationFreezeWithEnv(t, bd, dir, env, "list", "--json")
if code != 0 {
t.Fatalf("bd list --json exited %d\nstdout:\n%s\nstderr:\n%s", code, stdout, stderr)
}
start := strings.Index(stdout, "[")
if start < 0 {
t.Fatalf("no JSON array in bd list --json output:\n%s", stdout)
}
var issues []json.RawMessage
if err := json.Unmarshal([]byte(stdout[start:]), &issues); err != nil {
t.Fatalf("parse bd list --json output: %v\n%s", err, stdout)
}
return len(issues)
}
// The control proves the fixture really does restore when --readonly is not
// asked for, so "the store is unchanged" below cannot be vacuous.
t.Run("control_restore_without_readonly", func(t *testing.T) {
dir, env, backupDir := newWorkspace(t)
stdout, stderr, code := runBDMigrationFreezeWithEnv(t, bd, dir, env, "backup", "restore", "--force", backupDir)
if code != 0 {
t.Fatalf("restore without --readonly exited %d\nstdout:\n%s\nstderr:\n%s", code, stdout, stderr)
}
if !strings.Contains(stdout, "Restore complete") {
t.Errorf("stdout is missing %q:\n%s", "Restore complete", stdout)
}
if got := issueCount(t, dir, env); got != 2 {
t.Errorf("issue count after a real restore = %d, want 2: the backup holds two issues and the live store held three", got)
}
})
for _, tc := range []struct {
name string
flags []string
}{
{"readonly", []string{"--readonly"}},
{"readonly_sandbox", []string{"--readonly", "--sandbox"}},
} {
t.Run(tc.name, func(t *testing.T) {
dir, env, backupDir := newWorkspace(t)
before := snapshotWorkspace(t, dir)
args := append(append([]string{}, tc.flags...), "backup", "restore", "--force", backupDir)
stdout, stderr, code := runBDMigrationFreezeWithEnv(t, bd, dir, env, args...)
assertStrictReadonlyRestoreRefused(t, stdout, stderr, code)
assertWorkspaceUnchanged(t, dir, before)
if got := issueCount(t, dir, env); got != 3 {
t.Errorf("issue count after the refused restore = %d, want 3: the restore replaced the store", got)
}
})
}
}

View file

@ -234,7 +234,7 @@ func TestEmbeddedBlockedLabelFilters(t *testing.T) {
}
})
// blockedFilterFromFlags normalizes, as every sibling label filter does.
// the blocked role normalizes, as every sibling label filter does.
// Without it an untrimmed value returns nothing and is indistinguishable
// from "nothing blocked carries that label".
t.Run("leading_space_is_trimmed_like_every_other_label_filter", func(t *testing.T) {

167
cmd/bd/blocked_flags.go Normal file
View file

@ -0,0 +1,167 @@
package main
import (
"bufio"
"context"
"fmt"
"io"
"strings"
"github.com/spf13/cobra"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/storage/uow"
"github.com/steveyegge/beads/issueops"
)
// blockedFlagRow is one line of `bd blocked --flags --json`: an id the caller
// named and the blocked flag bd holds for it.
type blockedFlagRow struct {
ID string `json:"id"`
IsBlocked bool `json:"is_blocked"`
}
// blockedFlagFilterFlags are the listing's filters, which --flags does not
// take: it answers about the ids it is handed, not about a set it derives.
var blockedFlagFilterFlags = []string{"parent", "label", "label-any", "exclude-label"}
// runBlockedFlags is `bd blocked --flags`: the blocked flag for each id read
// from stdin (one per line; blank lines and repeats ignored), through the
// issueops.BlockedFlags library entry over the route's BlockingAnnotator.
//
// IT IS THE FLAG, NOT THE LISTING. The listing narrows the stored flag to
// rows bd can name a blocker for; this answers the flag itself, the column
// `bd ready` filters on, so a row whose flag is set with no nameable blocker
// reads true here and is absent from the listing. Where the
// external-dependency policy applies, an unsatisfied external: blocker sets
// the flag as it keeps the row out of `bd ready`.
//
// Every id that names a row on either plane is answered, in the order the ids
// were first given, a closed row included (its flag is whatever is stored);
// an id naming no row is omitted. Over HTTP the read is
// listBlockingAnnotations with is_blocked, behind
// dependencies.blocking.isBlocked; a server without that token is refused
// before the dial, naming it.
//
// --raw answers the stored column itself, without the external-dependency
// decoration (blockedFlagsAnnotator): exactly what reading is_blocked from
// the issues and wisps tables returns.
func runBlockedFlags(cmd *cobra.Command, ctx context.Context, in io.Reader) error {
for _, name := range blockedFlagFilterFlags {
if cmd.Flags().Changed(name) {
return HandleErrorRespectJSON("--flags answers the ids read from stdin and takes no --%s", name)
}
}
ids, err := readBlockedFlagIDs(in)
if err != nil {
return HandleErrorRespectJSON("reading ids from stdin: %v", err)
}
raw, _ := cmd.Flags().GetBool("raw")
annotator, err := blockedFlagsAnnotator(ctx, raw)
if err != nil {
return HandleErrorRespectJSON("%v", err)
}
flags, err := issueops.BlockedFlags(ctx, annotator, ids)
if err != nil {
return HandleErrorRespectJSON("%v", err)
}
rows := make([]blockedFlagRow, 0, len(flags))
seen := make(map[string]bool, len(ids))
for _, id := range ids {
blocked, ok := flags[id]
if !ok || seen[id] {
continue
}
seen[id] = true
rows = append(rows, blockedFlagRow{ID: id, IsBlocked: blocked})
}
if jsonOutput {
return outputJSON(rows)
}
for _, row := range rows {
state := "not blocked"
if row.IsBlocked {
state = "blocked"
}
fmt.Printf("%s\t%s\n", row.ID, state)
}
return nil
}
// readBlockedFlagIDs reads one id per line, trimmed, skipping blank lines.
func readBlockedFlagIDs(in io.Reader) ([]string, error) {
var ids []string
scanner := bufio.NewScanner(in)
scanner.Buffer(make([]byte, 0, 64*1024), 1024*1024)
for scanner.Scan() {
if id := strings.TrimSpace(scanner.Text()); id != "" {
ids = append(ids, id)
}
}
return ids, scanner.Err()
}
// blockedFlagsAnnotator is the BlockingAnnotator for the route this
// invocation runs: the store's own accessor on the direct routes (dolt,
// embedded dolt, HTTP), and the proxied-server provider's on the proxied one.
// Both carry the external-dependency decoration the rest of bd reads through.
//
// With raw it is the same role taken from BENEATH every decorator (the
// innermost store, the innermost provider), so the answer is the stored
// is_blocked column and nothing else: an unsatisfied external: blocker does
// not set it, because the column has never known about other projects.
func blockedFlagsAnnotator(ctx context.Context, raw bool) (issueops.BlockingAnnotator, error) {
if !raw {
if usesProxiedServer() {
return proxiedBlockingAnnotator()
}
if store == nil {
return nil, fmt.Errorf("no storage available")
}
return store.BlockingAnnotator()
}
if usesProxiedServer() {
if uowProvider == nil {
return nil, fmt.Errorf("proxied-server UOW provider not initialized")
}
src, ok := uow.UnwrapProvider(uowProvider).(uow.BlockingAnnotatorSource)
if !ok {
return nil, fmt.Errorf("proxied-server provider %T does not offer the blocking-decoration surface", uowProvider)
}
return src.BlockingAnnotator()
}
if store == nil {
return nil, fmt.Errorf("no storage available")
}
base := storage.UnwrapStore(store)
if err := refuseRawFlagsFromAPolicyServer(ctx, base); err != nil {
return nil, err
}
return base.BlockingAnnotator()
}
// refuseRawFlagsFromAPolicyServer refuses --raw against a served workspace
// whose server applies the external-dependency policy itself
// (policy.external_dependencies). That server's blocking annotation already
// sets the flag for an unsatisfied external: blocker, the v0 wire has no
// member that asks it for the bare column, and the decorated flag cannot be
// turned back into the column on this side (a row that is externally blocked
// may or may not also carry the stored flag). Answering anyway would be the
// decorated flag spelled as the raw one. Against a server that does not apply
// the policy, its annotation IS the column, and --raw is served.
func refuseRawFlagsFromAPolicyServer(ctx context.Context, base storage.DoltStorage) error {
prober, ok := base.(storage.ExternalDependencyPolicyProber)
if !ok {
return nil
}
enforced, err := prober.ServerEnforcesExternalDependencyPolicy(ctx)
if err != nil {
return err
}
if enforced {
return fmt.Errorf("bd blocked --flags --raw is not served by this workspace's server: it applies the " +
"external-dependency policy (policy.external_dependencies) to the blocked flag it answers, and the v0 " +
"wire cannot ask it for the stored column; use bd blocked --flags (the policy-aware flag)")
}
return nil
}

View file

@ -0,0 +1,57 @@
package main
import (
"slices"
"testing"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
// TestBlockedFlagsRefusesEveryListingFilter pins blockedFlagFilterFlags to the
// flags blockedCmd registers. --flags answers the ids read from stdin, so a
// listing filter it does not refuse is silently ignored: a filter added to
// blockedCmd but not to the refusal list would answer every id while the
// caller believes the answer was narrowed. The reverse direction catches an
// entry naming no registered flag, which Changed never reports as set.
//
// It walks Flags() and PersistentFlags() with VisitAll, not LocalFlags(),
// which would merge the root's persistent flags into blockedCmd for the rest
// of the process (see TestNoSubcommandShadowsRootJSONFlag). A root flag that
// an earlier in-process run already merged in is skipped by identity, and
// cobra's own --help by its annotation.
func TestBlockedFlagsRefusesEveryListingFilter(t *testing.T) {
// The flags --flags itself reads: the mode switch and its qualifier.
modeFlags := []string{"flags", "raw"}
var registered []string
visit := func(f *pflag.Flag) {
if f == rootCmd.PersistentFlags().Lookup(f.Name) || len(f.Annotations[cobra.FlagSetByCobraAnnotation]) > 0 {
return
}
if !slices.Contains(registered, f.Name) {
registered = append(registered, f.Name)
}
}
blockedCmd.PersistentFlags().VisitAll(visit)
blockedCmd.Flags().VisitAll(visit)
for _, name := range modeFlags {
if !slices.Contains(registered, name) {
t.Errorf("blockedCmd registers no --%s; this test's mode flags are stale", name)
}
}
for _, name := range registered {
if !slices.Contains(modeFlags, name) && !slices.Contains(blockedFlagFilterFlags, name) {
t.Errorf("--%s is registered on blockedCmd but --flags does not refuse it: add it to blockedFlagFilterFlags, or to this test's mode flags if --flags reads it", name)
}
}
for _, name := range blockedFlagFilterFlags {
if slices.Contains(modeFlags, name) {
t.Errorf("blockedFlagFilterFlags refuses --%s, which --flags itself reads", name)
}
if !slices.Contains(registered, name) {
t.Errorf("blockedFlagFilterFlags names --%s, which blockedCmd does not register", name)
}
}
}

View file

@ -5,6 +5,8 @@ package main
import (
"bytes"
"encoding/json"
"os/exec"
"slices"
"strings"
"testing"
@ -81,6 +83,68 @@ func TestProxiedServerBlocked(t *testing.T) {
}
})
t.Run("flags_reads_ids_from_stdin", func(t *testing.T) {
t.Parallel()
p := newSharedProxiedProject(t, bd, "bkf")
blocker := bdProxiedCreate(t, bd, p.dir, "Flag blocker")
dependent := bdProxiedCreate(t, bd, p.dir, "Flag dependent", "--deps", "depends-on:"+blocker.ID)
cmd := exec.Command(bd, "blocked", "--flags", "--json")
cmd.Dir = p.dir
cmd.Env = bdProxiedEnv(p.dir)
cmd.Stdin = strings.NewReader(dependent.ID + "\n" + blocker.ID + "\nbk-no-such-row\n")
var stdout, stderr bytes.Buffer
cmd.Stdout, cmd.Stderr = &stdout, &stderr
if err := cmd.Run(); err != nil {
t.Fatalf("bd blocked --flags --json: %v\nstdout:\n%s\nstderr:\n%s", err, stdout.String(), stderr.String())
}
var rows []struct {
ID string `json:"id"`
IsBlocked bool `json:"is_blocked"`
}
if err := json.Unmarshal(bytes.TrimSpace(stdout.Bytes()), &rows); err != nil {
t.Fatalf("parse: %v\n%s", err, stdout.String())
}
if len(rows) != 2 || rows[0].ID != dependent.ID || !rows[0].IsBlocked || rows[1].ID != blocker.ID || rows[1].IsBlocked {
t.Errorf("rows = %+v, want [{%s true} {%s false}] (unknown id omitted)", rows, dependent.ID, blocker.ID)
}
})
t.Run("flags_raw_is_the_stored_column", func(t *testing.T) {
t.Parallel()
p := newSharedProxiedProject(t, bd, "bkr")
ext := bdProxiedCreate(t, bd, p.dir, "Externally blocked only")
if _, stderr, err := bdProxiedRunBuffers(t, bd, p.dir, "dep", "add", ext.ID, "external:otherproj:cap"); err != nil {
t.Fatalf("dep add external: %v\n%s", err, stderr)
}
flag := func(args ...string) bool {
t.Helper()
cmd := exec.Command(bd, append([]string{"blocked", "--flags", "--json"}, args...)...)
cmd.Dir = p.dir
cmd.Env = bdProxiedEnv(p.dir)
cmd.Stdin = strings.NewReader(ext.ID + "\n")
var stdout, stderr bytes.Buffer
cmd.Stdout, cmd.Stderr = &stdout, &stderr
if err := cmd.Run(); err != nil {
t.Fatalf("bd blocked --flags %v: %v\n%s\n%s", args, err, stdout.String(), stderr.String())
}
var rows []struct {
ID string `json:"id"`
IsBlocked bool `json:"is_blocked"`
}
if err := json.Unmarshal(bytes.TrimSpace(stdout.Bytes()), &rows); err != nil || len(rows) != 1 {
t.Fatalf("parse %v: %v\n%s", args, err, stdout.String())
}
return rows[0].IsBlocked
}
if !flag() {
t.Errorf("--flags for an externally blocked row = false, want true (the policy flag)")
}
if flag("--raw") {
t.Errorf("--flags --raw for an externally blocked row = true, want false (the stored column)")
}
})
t.Run("empty_case", func(t *testing.T) {
t.Parallel()
p := newSharedProxiedProject(t, bd, "bk2")
@ -125,4 +189,42 @@ func TestProxiedServerBlocked(t *testing.T) {
t.Errorf("non-descendant %s leaked into --parent result", outside.ID)
}
})
t.Run("label_filters_apply_to_external_only_rows", func(t *testing.T) {
t.Parallel()
p := newSharedProxiedProject(t, bd, "bkl")
// A row blocked only by an unsatisfied external ref is listed by the
// unit-of-work decorator after the label query ran, so the filters
// must judge it by its own labels, read hydrated.
tagged := bdProxiedCreate(t, bd, p.dir, "Externally blocked, labelled", "-l", "lane:a")
bare := bdProxiedCreate(t, bd, p.dir, "Externally blocked, unlabelled")
for _, id := range []string{tagged.ID, bare.ID} {
if _, stderr, err := bdProxiedRunBuffers(t, bd, p.dir, "dep", "add", id, "external:otherproj:cap"); err != nil {
t.Fatalf("dep add %s external: %v\n%s", id, err, stderr)
}
}
for _, tc := range []struct {
args []string
want []string
}{
{nil, []string{tagged.ID, bare.ID}},
{[]string{"--label", "lane:a"}, []string{tagged.ID}},
{[]string{"--label-any", "lane:a"}, []string{tagged.ID}},
{[]string{"--exclude-label", "lane:a"}, []string{bare.ID}},
} {
got := bdProxiedBlockedJSON(t, bd, p, tc.args...)
ids := make([]string, 0, len(got))
for _, bi := range got {
ids = append(ids, bi.ID)
if bi.ID == tagged.ID && !slices.Equal(bi.Labels, []string{"lane:a"}) {
t.Errorf("bd blocked %v: %s prints labels %v, want [lane:a]", tc.args, bi.ID, bi.Labels)
}
}
slices.Sort(ids)
slices.Sort(tc.want)
if !slices.Equal(ids, tc.want) {
t.Errorf("bd blocked %v listed %v, want %v", tc.args, ids, tc.want)
}
}
})
}

View file

@ -207,6 +207,12 @@ Examples:
}
if beadsDir == "" {
// Discovery passes over a .beads marked only by a legacy
// config.json. One in a format this build cannot open is refused
// as that, not reported as no workspace.
if err := checkUndiscoveredWorkspaceFormat(); err != nil {
return handleWorkspaceGuardError(err)
}
if jsonOutput {
if err := outputJSON(noWorkspaceBootstrapPayload()); err != nil {
return err
@ -219,7 +225,7 @@ Examples:
}
if err := guardLegacyUpgradeWorkspace(beadsDir); err != nil {
return HandleError("%v", err)
return handleWorkspaceGuardError(err)
}
// Load config from .beads/metadata.json. When the beadsDir was
@ -234,7 +240,9 @@ Examples:
}
if cfg == nil {
cfg, err = findParentConfig(beadsDir)
if err != nil {
if isUnsupportedWorkspaceFormat(err) {
return handleWorkspaceGuardError(err)
} else if err != nil {
return HandleError("failed to load ancestor storage metadata: %v; no storage database was opened or modified; fix or restore metadata.json and retry", err)
}
}
@ -274,7 +282,11 @@ Examples:
}
if err := executeBootstrapPlan(plan, cfg, nonInteractive); err != nil {
return HandleError("Bootstrap failed: %v", err)
// The error can carry sync.remote verbatim, credentials and all:
// sanitizeURL passes through a URL net/url cannot parse (a
// password with an unencoded "#" or "?"), and Dolt's "invalid
// remote url:" repeats it. Scrub it where it is printed.
return HandleError("Bootstrap failed: %s", scrubURLCredentials(err.Error()))
}
return nil
},
@ -1582,6 +1594,9 @@ func isNonInteractiveBootstrap(flagValue bool) bool {
// parent workspace does. Returns nil if no parent config is found. A malformed
// or unreadable ancestor metadata file is authoritative and returned as an error;
// bootstrap must not skip it and select a more distant workspace or defaults.
// An ancestor holding the graph format marker without metadata it can read is
// a graph workspace, refused like one whose metadata declares graph_mode,
// rather than skipped or reported as a metadata load failure.
func findParentConfig(beadsDir string) (*configfile.Config, error) {
// Start from the parent of beadsDir's enclosing directory.
// beadsDir is typically "<project>/.beads", so we start from <project>'s parent.
@ -1599,6 +1614,9 @@ func findParentConfig(beadsDir string) (*configfile.Config, error) {
for dir, ok := walk.Next(); ok; dir, ok = walk.Next() {
candidate := filepath.Join(dir, ".beads")
cfg, err := configfile.LoadForDiscovery(candidate)
if (err != nil || cfg == nil) && hasGraphFormatMarker(candidate) {
return nil, &configfile.UnsupportedWorkspaceFormatError{BeadsDir: candidate, FormatMarker: true}
}
if err != nil {
return nil, fmt.Errorf("%s: %w", configfile.ConfigPath(candidate), err)
}
@ -1656,14 +1674,21 @@ func isGitCodeRepoURL(rawURL string) bool {
// urlHostname extracts the lowercase hostname from a URL without importing
// net/url. Handles scheme://[user@]host[:port]/path and SCP git@host:path.
//
// The host part is cut out before userinfo is stripped through its last "@",
// so an "@" in a path, query or fragment never selects the host (mc-gcmer).
// For a scheme URL the host part is the authority, which ends at the first
// "/", "?" or "#" — the host net/url, and so Dolt, would dial. For SCP it is
// everything before the first ":", unless a "/" comes first, which makes it a
// local path (the split doltremote.FromGitURL makes).
func urlHostname(rawURL string) string {
if sep := strings.Index(rawURL, "://"); sep >= 0 {
rest := rawURL[sep+3:]
if at := strings.Index(rest, "@"); at >= 0 {
rest = rest[at+1:]
if end := strings.IndexAny(rest, "/?#"); end >= 0 {
rest = rest[:end]
}
if slash := strings.Index(rest, "/"); slash >= 0 {
rest = rest[:slash]
if at := strings.LastIndex(rest, "@"); at >= 0 {
rest = rest[at+1:]
}
if colon := strings.Index(rest, ":"); colon >= 0 {
rest = rest[:colon]
@ -1671,10 +1696,9 @@ func urlHostname(rawURL string) string {
return strings.ToLower(rest)
}
// SCP-style: git@github.com:org/repo
if at := strings.Index(rawURL, "@"); at >= 0 {
rest := rawURL[at+1:]
if colon := strings.Index(rest, ":"); colon >= 0 {
return strings.ToLower(rest[:colon])
if colon := strings.Index(rawURL, ":"); colon >= 0 && !strings.Contains(rawURL[:colon], "/") {
if at := strings.LastIndex(rawURL[:colon], "@"); at >= 0 {
return strings.ToLower(rawURL[at+1 : colon])
}
}
return ""

View file

@ -295,3 +295,49 @@ func TestEmbeddedBootstrapConcurrent(t *testing.T) {
}
}
}
// TestEmbeddedBootstrapCloneFailureScrubsCredentials pins the credential scrub
// at the "Bootstrap failed:" print site (mc-gcmer). An unencoded "#" or "?" in
// the password ends the URL's authority early, so the remote is not a forge
// and is cloned as configured. The clone error then carries the password
// twice: sanitizeURL passes a URL net/url cannot parse through unchanged, and
// Dolt's "invalid remote url:" repeats it.
func TestEmbeddedBootstrapCloneFailureScrubsCredentials(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}
t.Parallel()
bd := buildEmbeddedBD(t)
for _, tc := range []struct{ name, password string }{
{"hash", "pa#ss"},
{"question_mark", "pa?ss"},
} {
t.Run(tc.name, func(t *testing.T) {
dir := t.TempDir()
initGitRepoAt(t, dir)
beadsDir := filepath.Join(dir, ".beads")
if err := os.MkdirAll(beadsDir, 0o750); err != nil {
t.Fatalf("mkdir .beads: %v", err)
}
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), []byte("{}"), 0o644); err != nil {
t.Fatalf("write metadata.json: %v", err)
}
seedSyncRemote(t, beadsDir, "https://alice:"+tc.password+"@github.com/org/db")
cmd := exec.Command(bd, "bootstrap", "--yes")
cmd.Dir = dir
cmd.Env = bdEnv(dir)
stdout, stderr, err := runCommandBuffers(t, cmd)
// A failure before the clone would pass the leak check below
// without reaching the print site.
if err == nil || !strings.Contains(stderr.String(), "Bootstrap failed: clone from remote:") {
t.Fatalf("bootstrap should fail at the clone, got err=%v\nstdout:\n%s\nstderr:\n%s", err, stdout.String(), stderr.String())
}
if strings.Contains(stdout.String()+stderr.String(), tc.password) {
t.Errorf("bootstrap printed the sync.remote password %q:\nstdout:\n%s\nstderr:\n%s", tc.password, stdout.String(), stderr.String())
}
})
}
}

View file

@ -60,6 +60,21 @@ func TestIsGitCodeRepoURL(t *testing.T) {
// SCP-style to non-forge — allowed
{"git@my-dolt.example.com:org/db", false},
// Userinfo before a forge host is stripped, in either URL form
{"ssh://git@github.com/org/db", true},
{"https://x-access-token:secret@github.com/org/db", true},
{"git@github.com:org/db", true},
// ...through the last "@" of the host part, as net/url (and so Dolt) reads it
{"https://a@b@github.com/org/db", true},
{"a@b@github.com:org/db", true},
// An "@" outside the host part never selects the host (mc-gcmer)
{"https://my-dolt.example.com/x@github.com/path", false},
{"https://my-dolt.example.com?x@github.com", false},
{"https://my-dolt.example.com#x@github.com", false},
{"my-dolt.example.com:org/x@github.com:db", false},
{"./backups/me@github.com:db", false},
// Edge: empty string
{"", false},
}
@ -121,6 +136,9 @@ var forgeSyncRemoteForms = []struct {
{"already git+https", "git+https://github.com/org/repo.git", "git+https://github.com/org/repo.git"},
{"git+ssh without user", "git+ssh://github.com/org/repo.git", "git+ssh://github.com/org/repo.git"},
{"gitlab", "https://gitlab.com/group/repo.git", "git+https://gitlab.com/group/repo.git"},
// No .git suffix, so only the host can make it a forge: github.com, after
// the last "@" of the authority (mc-gcmer).
{"multi-@ userinfo", "https://a@b@github.com/org/repo", "git+https://a@b@github.com/org/repo"},
}
// newForgeSyncRemoteWorkspace builds a workspace whose config.yaml carries

View file

@ -79,6 +79,9 @@ const (
trackSync = "proxied-parity S5 (bd sync)"
trackDegradation = "proxied-parity S6 (doctor, config show, degradations)"
trackLongTail = "proxied-parity S7 (long-tail policy pass)"
// Versioned history (gastownhall/beads#6132) is not a proxied-parity slice:
// its reads need a storage.VersionLister over the proxied uow provider.
trackVersionedHistory = "versioned history: VersionLister over the proxied uow provider (gastownhall/beads#6132)"
)
// capabilityRow is one command-path policy row. ArgSet is the sorted set of
@ -451,6 +454,16 @@ var proxyCapabilityRegistry = []capabilityRow{
// at the front door would leave those modes with no way to flush.
permitted("dolt commit").withHistory(HistoryProxySupported),
// --- versioned history ----------------------------------------------------
// `bd versions` is a pure read (issueops.ListVersionsInTx in one read
// transaction), so nothing about it is unsafe on a shared backend. It is
// refused only because no proxied route exists yet: it reaches the backend
// through the optional storage.VersionLister, which the dolt and embedded
// stores implement and the uow provider does not. Permitting it would open
// the proxied provider in the root pre-run and then fail untyped at
// errVersionsUnsupported, so it is refused here, before any side effect.
refusedPath("versions", "proxy.versions.unsupported", ProxyReasonUnimplemented, trackVersionedHistory),
// --- untyped refusals inside RunE ---------------------------------------
// The gate permits these paths and the command refuses itself with a bare
// string, so a JSON consumer gets no code and no mutates flag. They are

View file

@ -872,10 +872,12 @@ func resolveReasonFile(cmd *cobra.Command, hasExistingReason bool) (string, bool
// resolveCloseTargets resolves a batch of partial issue IDs for `bd close`,
// preserving input order. For each ID it tries the local store first, then
// explicit prefix routing via routes.jsonl, then a shared contributor-routed
// store. This matches resolveAndGetIssueWithRouting's routing precedence.
// explicit prefix routing via routes.jsonl, then a shared auto-routed store.
// This matches resolveAndGetIssueForMutation's routing precedence and write
// intent, and like it returns a routing failure (an unreadable routes.jsonl, a
// routed store that fails to open) as itself rather than as a not-found.
//
// The contributor-routed handle is shared across the batch so bulk close does
// The auto-routed handle is shared across the batch so bulk close does
// not repeatedly open the same planning store and every result has a clear store
// owner for subsequent close-time checks and writes.
//
@ -884,60 +886,92 @@ func resolveReasonFile(cmd *cobra.Command, hasExistingReason bool) (string, bool
// no-op for routed-via-shared-handle entries because they don't own the handle.
func resolveCloseTargets(ctx context.Context, localStore storage.DoltStorage, ids []string) ([]*RoutedResult, func(), error) {
results := make([]*RoutedResult, 0, len(ids))
var sharedRouted storage.DoltStorage
var sharedRoutedTried bool
shared := &closeAutoRoute{localStore: localStore}
cleanup := func() {
for _, r := range results {
r.Close()
}
if sharedRouted != nil {
_ = sharedRouted.Close()
}
}
ensureShared := func() (storage.DoltStorage, error) {
if sharedRouted != nil {
return sharedRouted, nil
}
if sharedRoutedTried {
return nil, fmt.Errorf("no auto-routed store available")
}
sharedRoutedTried = true
rs, routed, _, err := openRoutedReadStore(ctx, localStore)
if err != nil {
return nil, err
}
if !routed {
return nil, fmt.Errorf("no auto-routed store available")
}
sharedRouted = rs
return rs, nil
shared.Close()
}
for _, id := range ids {
// Local first.
if r, err := resolveAndGetFromStore(ctx, localStore, id, false); err == nil {
results = append(results, r)
continue
} else if !isNotFoundErr(err) {
r, err := resolveCloseTarget(ctx, localStore, shared, id)
if err != nil {
cleanup()
return nil, func() {}, fmt.Errorf("resolving ID %s: %w", id, err)
return nil, func() {}, err
}
// Write-intent: a prefix-routed target opens writable so the close
// commits on the target head (#4141). Contributor auto-routing below
// stays read-only: it hydrates foreign projects that must not be mutated.
if r, err := resolveViaPrefixRoutingWithAccess(ctx, id, true, false); err == nil {
results = append(results, r)
continue
}
// Contributor auto-routing uses one shared store for the whole batch.
if rs, rerr := ensureShared(); rerr == nil {
if r, err := resolveAndGetFromStore(ctx, rs, id, true); err == nil {
// Per-id RoutedResult does not own the shared handle; cleanup() does.
results = append(results, r)
continue
}
}
cleanup()
return nil, func() {}, fmt.Errorf("resolving ID %s: no issue found matching %q", id, id)
results = append(results, r)
}
return results, cleanup, nil
}
// resolveCloseTarget resolves one ID of a bd close batch: the local store,
// then a prefix route, then the batch's shared auto-routed store.
func resolveCloseTarget(ctx context.Context, localStore storage.DoltStorage, shared *closeAutoRoute, id string) (*RoutedResult, error) {
// Local first.
r, err := resolveAndGetFromStore(ctx, localStore, id, false)
if err == nil {
return r, nil
}
if !isNotFoundErr(err) {
return nil, fmt.Errorf("resolving ID %s: %w", id, err)
}
// Write-intent: a prefix-routed target opens writable so the close
// commits on the target head (#4141).
r, err = resolveViaPrefixRoutingWithAccess(ctx, id, true, false)
if err == nil {
return r, nil
}
if isRoutingFailure(err) {
return nil, fmt.Errorf("resolving ID %s: %w", id, err)
}
r, err = shared.resolve(ctx, id)
if err == nil {
return r, nil
}
if isRoutingFailure(err) {
return nil, fmt.Errorf("resolving ID %s: %w", id, err)
}
return nil, fmt.Errorf("resolving ID %s: no issue found matching %q", id, id)
}
// closeAutoRoute is the auto-routed store a bd close batch shares. It opens on
// first use and is closed once, by the batch's cleanup.
type closeAutoRoute struct {
localStore storage.DoltStorage
store storage.DoltStorage
err error
tried bool
}
// resolve looks id up in the shared auto-routed store, opening it on the first
// call with write intent, as resolveAndGetIssueForMutation does: the target
// opens writable, whichever rule selected it, so the close commits where the
// issue lives. The outcome of that open, failure included, holds for the rest
// of the batch.
func (a *closeAutoRoute) resolve(ctx context.Context, id string) (*RoutedResult, error) {
if !a.tried {
a.tried = true
rs, routed, _, err := openAutoRoutedStore(ctx, a.localStore, true)
switch {
case err != nil:
a.err = err
case !routed:
a.err = fmt.Errorf("%w: no auto-routed store available", errRoutingUnavailable)
default:
a.store = rs
}
}
if a.err != nil {
return nil, a.err
}
// Per-id RoutedResult does not own the shared handle; Close does.
return resolveAndGetFromStore(ctx, a.store, id, true)
}
// Close closes the shared auto-routed store, if one was opened.
func (a *closeAutoRoute) Close() {
if a.store != nil {
_ = a.store.Close()
a.store = nil
}
}

View file

@ -10,7 +10,7 @@ import (
"github.com/steveyegge/beads/internal/types"
)
// TestIfRevisionCloseReplaysMoleculeAutoClose pins mc-zndi7.75 item 1 on the
// TestEmbeddedIfRevisionCloseReplaysMoleculeAutoClose pins mc-zndi7.75 item 1 on the
// embedded/direct --if-revision close route: runCloseDirectIfRevision bypasses
// `bd close`'s batch architecture entirely (A8, beads#4682 — BatchCloseItem
// carries no per-item ExpectedVersion), so it must re-drive molecule auto-close
@ -22,7 +22,7 @@ import (
// state a crash between the final step's close and its root auto-close would
// leave), then re-close the final step — this time guarded — and require the
// stranded-open root to heal.
func TestIfRevisionCloseReplaysMoleculeAutoClose(t *testing.T) {
func TestEmbeddedIfRevisionCloseReplaysMoleculeAutoClose(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}
@ -60,12 +60,12 @@ func TestIfRevisionCloseReplaysMoleculeAutoClose(t *testing.T) {
}
}
// TestIfRevisionCloseWarnsOnForcedOpenChildren pins mc-zndi7.75 item 3: the
// TestEmbeddedIfRevisionCloseWarnsOnForcedOpenChildren pins mc-zndi7.75 item 3: the
// "warning: closing X with N open child issue(s) still active" line
// (close.go:194-196) must still print on the guarded direct close route when
// --force waives the engine's open-children refusal, exactly as it does on
// the unguarded batch path.
func TestIfRevisionCloseWarnsOnForcedOpenChildren(t *testing.T) {
func TestEmbeddedIfRevisionCloseWarnsOnForcedOpenChildren(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}

View file

@ -10,7 +10,7 @@ import (
)
// TestProxiedServerIfRevisionCloseReplaysMoleculeAutoClose is
// TestIfRevisionCloseReplaysMoleculeAutoClose's proxied-server twin, pinning
// TestEmbeddedIfRevisionCloseReplaysMoleculeAutoClose's proxied-server twin, pinning
// mc-zndi7.75 item 1 on the route `bd serve` actually runs:
// runCloseProxiedIfRevision bypasses the batch entirely (A8, beads#4682), so
// it must re-drive molecule auto-close itself via its own post-close unit of
@ -53,7 +53,7 @@ func TestProxiedServerIfRevisionCloseReplaysMoleculeAutoClose(t *testing.T) {
}
// TestProxiedServerIfRevisionCloseWarnsOnForcedOpenChildren is
// TestIfRevisionCloseWarnsOnForcedOpenChildren's proxied-server twin, pinning
// TestEmbeddedIfRevisionCloseWarnsOnForcedOpenChildren's proxied-server twin, pinning
// mc-zndi7.75 item 3 on the proxied route.
func TestProxiedServerIfRevisionCloseWarnsOnForcedOpenChildren(t *testing.T) {
requireSharedProxiedServer(t)

View file

@ -69,6 +69,7 @@ func TestResolveCloseTargets(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
initConfigForTest(t)
neutralizeRoutingModeEnv(t)
tmpDir := t.TempDir()
repoDir := filepath.Join(tmpDir, "repo")

View file

@ -0,0 +1,444 @@
//go:build cgo
// cgo only: the goldens pin the cgo build, which every lane that runs this
// package's full suite compiles. The !cgo build replaces the federation
// subtree with a one-command stub (federation_nocgo.go), so its tree differs
// by design.
package main
import (
"bytes"
"fmt"
"os"
"path/filepath"
"sort"
"strings"
"testing"
"github.com/charmbracelet/x/ansi"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
// The committed command-surface goldens. Regenerate after an intentional CLI
// change, then review the diff like code:
//
// BD_UPDATE_GOLDEN=1 CGO_ENABLED=1 go test -tags gms_pure_go ./cmd/bd -run '^TestCommand(Tree|Help)Golden$'
//
// CGO_ENABLED=1 because this file builds only with cgo: with cgo off the
// command matches no test, exits 0 and leaves the goldens as they were.
const (
commandTreeGoldenPath = "testdata/command_tree/tree.golden"
commandHelpGoldenDir = "testdata/command_tree/help"
commandGoldenRegen = "BD_UPDATE_GOLDEN=1 CGO_ENABLED=1 go test -tags gms_pure_go ./cmd/bd -run '^TestCommand(Tree|Help)Golden$'"
)
// commandHelpGoldenArgs is the representative set of commands whose exact
// --help output is pinned, each as the argv after "bd". The tree golden
// covers every command's metadata; these cover the rendering (usage line,
// flag table layout, inherited global flags, root command groups).
var commandHelpGoldenArgs = [][]string{
{},
{"create"},
{"show"},
{"list"},
{"update"},
{"close"},
{"version"},
{"versions"},
{"config"},
{"serve"},
}
// TestCommandTreeGolden pins the whole bd command tree: for every command and
// subcommand, hidden ones included, its Use, Aliases, Short, Long, Example,
// group, hidden/deprecated state, runnability and annotations, and every
// local and persistent flag it defines (name, shorthand, type, default,
// usage, hidden, deprecation, annotations). Any added, removed or reworded
// command or flag fails this test until the golden is regenerated, so the
// change shows up as a reviewed testdata diff. It reads the in-memory tree
// only: no store or subprocess.
//
// docs/cli-docs.pin pins the generated CLI reference (and check-doc-flags)
// to a release, so drift on main is not caught there; this golden is the
// live guard for the command surface.
func TestCommandTreeGolden(t *testing.T) {
pkgDir := enterOrdinaryWorkspaceForGolden(t)
primeCommandTreeForGolden()
flagCounts := commandFlagCounts(rootCmd)
got := renderCommandTreeGolden(rootCmd)
// A renderer that iterated a map would pass on the run that regenerated
// the golden and flake afterwards.
if again := renderCommandTreeGolden(rootCmd); again != got {
t.Fatalf("command tree rendering is not deterministic:\n%s", goldenLineDiff(got, again))
}
// Nor may rendering change the tree it reads: tests sharing this binary
// pin a command's exact flag set (TestServeFlags). See goldenLocalFlags.
if after := commandFlagCounts(rootCmd); after != flagCounts {
t.Fatalf("rendering the command tree added flags to a command's own flag set:\n%s", goldenLineDiff(flagCounts, after))
}
checkCommandGolden(t, pkgDir, commandTreeGoldenPath, got)
}
// TestCommandHelpGolden pins the exact `bd <command> --help` output of a
// representative set of commands, executed in-process through the real root
// command. --help returns before the root pre-run, so no store is opened.
// Color escapes are stripped so the snapshot is independent of terminal
// detection; otherwise the snapshots are byte-identical to what a built bd
// prints.
func TestCommandHelpGolden(t *testing.T) {
pkgDir := enterOrdinaryWorkspaceForGolden(t)
// Parsing `bd serve --help` merges the root's persistent flags into
// serveCmd's own flag set, which TestServeFlags pins; restoreServeGlobals
// re-registers that set afterwards.
restoreServeGlobals(t)
want := map[string]bool{}
for _, args := range commandHelpGoldenArgs {
name := strings.Join(append([]string{"bd"}, args...), "_")
file := name + ".golden"
want[file] = true
t.Run(name, func(t *testing.T) {
checkCommandGolden(t, pkgDir, filepath.Join(commandHelpGoldenDir, file), renderCommandHelpGolden(t, args))
})
}
// The directory holds exactly the listed snapshots: a command dropped
// from the list must not leave a stale file that still looks pinned.
dir := filepath.Join(pkgDir, commandHelpGoldenDir)
entries, err := os.ReadDir(dir)
if err != nil {
t.Fatalf("read %s: %v", commandHelpGoldenDir, err)
}
for _, e := range entries {
if want[e.Name()] {
continue
}
if os.Getenv("BD_UPDATE_GOLDEN") == "1" {
if err := os.Remove(filepath.Join(dir, e.Name())); err != nil {
t.Fatalf("remove stale help golden %s: %v", e.Name(), err)
}
t.Logf("removed stale help golden %s", e.Name())
continue
}
t.Errorf("%s/%s is not in commandHelpGoldenArgs; delete it or regenerate with %s", commandHelpGoldenDir, e.Name(), commandGoldenRegen)
}
}
// enterOrdinaryWorkspaceForGolden moves the test into a fresh ordinary
// (dependency-mode) workspace: a .beads/metadata.json with no graph marker
// and no database behind it, so nothing can be read from or written to a
// store. It returns the package directory, where the goldens live.
func enterOrdinaryWorkspaceForGolden(t *testing.T) string {
t.Helper()
isolateBeadsDirForTest(t)
pkgDir, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
ws := t.TempDir()
beadsDir := filepath.Join(ws, ".beads")
if err := os.Mkdir(beadsDir, 0o750); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), []byte(`{"backend":"dolt"}`), 0o600); err != nil {
t.Fatal(err)
}
t.Chdir(ws)
return pkgDir
}
// primeCommandTreeForGolden completes the tree the way the bd binary does
// before it dispatches: main() adds cobra's help command and its
// --all/--doc/--list/--docs-root flags, and ExecuteC adds the completion
// command. All three are idempotent, so the tree is the same whether or not
// an earlier in-process test already executed rootCmd.
func primeCommandTreeForGolden() {
rootCmd.InitDefaultHelpCmd()
registerHelpAllFlag()
rootCmd.InitDefaultCompletionCmd()
}
// renderCommandTreeGolden walks cmd's tree depth first, children sorted by
// name, and renders one block per command.
func renderCommandTreeGolden(root *cobra.Command) string {
var b strings.Builder
b.WriteString("# bd command tree (cgo build), pinned by TestCommandTreeGolden.\n")
b.WriteString("# Regenerate after an intentional CLI change:\n")
b.WriteString("# " + commandGoldenRegen + "\n")
var walk func(*cobra.Command)
walk = func(c *cobra.Command) {
writeCommandGoldenBlock(&b, c)
children := append([]*cobra.Command(nil), c.Commands()...)
sort.Slice(children, func(i, j int) bool { return children[i].Name() < children[j].Name() })
for _, sub := range children {
// cobra adds the hidden shell-completion request commands only
// for an execution that invokes them, and then never removes
// them: whether they are present depends on test history, not
// on the bd surface.
if sub.Name() == cobra.ShellCompRequestCmd || sub.Name() == cobra.ShellCompNoDescRequestCmd {
continue
}
walk(sub)
}
}
walk(root)
return b.String()
}
func writeCommandGoldenBlock(b *strings.Builder, c *cobra.Command) {
fmt.Fprintf(b, "\n%s\n", c.CommandPath())
fmt.Fprintf(b, " use: %q\n", c.Use)
if len(c.Aliases) > 0 {
fmt.Fprintf(b, " aliases: %q\n", c.Aliases)
}
fmt.Fprintf(b, " short: %q\n", c.Short)
if c.GroupID != "" {
fmt.Fprintf(b, " group: %q\n", c.GroupID)
}
fmt.Fprintf(b, " hidden: %t\n", c.Hidden)
if c.Deprecated != "" {
fmt.Fprintf(b, " deprecated: %q\n", c.Deprecated)
}
fmt.Fprintf(b, " runnable: %t\n", c.Runnable())
if c.DisableFlagParsing {
b.WriteString(" disable-flag-parsing: true\n")
}
if len(c.ValidArgs) > 0 {
fmt.Fprintf(b, " valid-args: %q\n", c.ValidArgs)
}
if len(c.Annotations) > 0 {
fmt.Fprintf(b, " annotations: %s\n", formatGoldenAnnotations(c.Annotations))
}
writeGoldenTextBlock(b, "long", c.Long)
writeGoldenTextBlock(b, "example", c.Example)
for _, line := range commandGoldenFlagLines(c.PersistentFlags()) {
fmt.Fprintf(b, " persistent-flag %s\n", line)
}
for _, line := range commandGoldenFlagLines(goldenLocalFlags(c)) {
fmt.Fprintf(b, " flag %s\n", line)
}
}
// goldenLocalFlags returns the non-persistent flags c registers itself,
// including any that shadow an inherited flag: the set
// c.LocalNonPersistentFlags() reports, read without calling it. That
// accessor, like LocalFlags and InheritedFlags, runs cobra's
// mergePersistentFlags, which copies every inherited persistent flag into
// c.Flags() for the rest of the process. Over the whole tree that would leave
// `bd serve` carrying the root's --json, --db and the rest, and break
// TestServeFlags (see TestNoSubcommandShadowsRootJSONFlag).
//
// c.Flags() may already hold such copies from an earlier in-process
// execution. They are recognized by identity, the way cobra itself tells
// them apart: an inherited flag is the nearest ancestor's own *pflag.Flag of
// that name, and a shadowing flag is a different one.
func goldenLocalFlags(c *cobra.Command) *pflag.FlagSet {
local := pflag.NewFlagSet(c.Name(), pflag.ContinueOnError)
c.Flags().VisitAll(func(f *pflag.Flag) {
if c.PersistentFlags().Lookup(f.Name) != nil {
return // rendered as a persistent-flag line
}
for p := c.Parent(); p != nil; p = p.Parent() {
if inherited := p.PersistentFlags().Lookup(f.Name); inherited != nil {
if inherited == f {
return
}
break
}
}
local.AddFlag(f)
})
return local
}
// commandFlagCounts renders how many flags each command's own flag set holds,
// one line per command, read without merging anything into it.
func commandFlagCounts(root *cobra.Command) string {
var b strings.Builder
var walk func(*cobra.Command)
walk = func(c *cobra.Command) {
n := 0
c.Flags().VisitAll(func(*pflag.Flag) { n++ })
fmt.Fprintf(&b, "%s %d\n", c.CommandPath(), n)
for _, sub := range c.Commands() {
walk(sub)
}
}
walk(root)
return b.String()
}
// writeGoldenTextBlock writes a multi-line field one source line per golden
// line, behind a "|" gutter so leading whitespace and blank lines survive.
func writeGoldenTextBlock(b *strings.Builder, name, text string) {
if text == "" {
return
}
fmt.Fprintf(b, " %s:\n", name)
for _, line := range strings.Split(text, "\n") {
if line == "" {
b.WriteString(" |\n")
continue
}
fmt.Fprintf(b, " | %s\n", line)
}
}
// commandGoldenFlagLines renders each flag of fs on one line, sorted by name.
// cobra's own lazily added --help flag (FlagSetByCobraAnnotation) is skipped:
// it exists only on commands an earlier in-process execution reached.
func commandGoldenFlagLines(fs *pflag.FlagSet) []string {
var flags []*pflag.Flag
fs.VisitAll(func(f *pflag.Flag) {
if _, byCobra := f.Annotations[cobra.FlagSetByCobraAnnotation]; byCobra {
return
}
flags = append(flags, f)
})
sort.Slice(flags, func(i, j int) bool { return flags[i].Name < flags[j].Name })
lines := make([]string, 0, len(flags))
for _, f := range flags {
var b strings.Builder
fmt.Fprintf(&b, "--%s", f.Name)
if f.Shorthand != "" {
fmt.Fprintf(&b, " -%s", f.Shorthand)
}
fmt.Fprintf(&b, " type=%s default=%q", f.Value.Type(), f.DefValue)
if f.NoOptDefVal != "" && !implicitNoOptDefault(f) {
fmt.Fprintf(&b, " no-opt-default=%q", f.NoOptDefVal)
}
if f.Hidden {
b.WriteString(" hidden")
}
if f.Deprecated != "" {
fmt.Fprintf(&b, " deprecated=%q", f.Deprecated)
}
if f.ShorthandDeprecated != "" {
fmt.Fprintf(&b, " shorthand-deprecated=%q", f.ShorthandDeprecated)
}
if len(f.Annotations) > 0 {
fmt.Fprintf(&b, " annotations=%s", formatGoldenAnnotations(f.Annotations))
}
fmt.Fprintf(&b, " usage=%q", f.Usage)
lines = append(lines, b.String())
}
return lines
}
// implicitNoOptDefault reports whether f's NoOptDefVal is the one pflag gives
// every flag of its type (a bare --bool means true, a bare --count adds one),
// which would only repeat the type on each line.
func implicitNoOptDefault(f *pflag.Flag) bool {
switch f.Value.Type() {
case "bool":
return f.NoOptDefVal == "true"
case "count":
return f.NoOptDefVal == "+1"
}
return false
}
// formatGoldenAnnotations renders a command's or a flag's annotations sorted
// by key.
func formatGoldenAnnotations[V string | []string](m map[string]V) string {
keys := make([]string, 0, len(m))
for k := range m {
keys = append(keys, k)
}
sort.Strings(keys)
parts := make([]string, 0, len(keys))
for _, k := range keys {
parts = append(parts, fmt.Sprintf("%s=%q", k, m[k]))
}
return "{" + strings.Join(parts, " ") + "}"
}
// renderCommandHelpGolden runs `bd <args> --help` through rootCmd in-process
// and returns its stdout with color escapes stripped. cobra keeps the parsed
// --help value on the shared tree, so every flag is put back afterwards: a
// later in-process `bd create ...` must not print help instead.
//
// internal/ui decides color once, at init, from CLICOLOR_FORCE and whether the
// test binary's stdout is a terminal. CI never gives it one, so there the
// strip removes nothing; it is what keeps a run from a terminal matching the
// goldens.
func renderCommandHelpGolden(t *testing.T, args []string) string {
t.Helper()
argv := append(append([]string(nil), args...), "--help")
primeCommandTreeForGolden()
var execErr error
out := captureStdout(t, func() error {
rootCmd.SetArgs(argv)
defer rootCmd.SetArgs(nil)
defer resetCommandFlags(rootCmd)
_, execErr = rootCmd.ExecuteC()
return nil
})
if execErr != nil {
t.Fatalf("bd %s: %v", strings.Join(argv, " "), execErr)
}
return ansi.Strip(out)
}
// checkCommandGolden compares got with the golden at rel under pkgDir, or
// rewrites the golden when BD_UPDATE_GOLDEN=1 (the package's shared golden
// switch).
func checkCommandGolden(t *testing.T, pkgDir, rel, got string) {
t.Helper()
path := filepath.Join(pkgDir, rel)
if os.Getenv("BD_UPDATE_GOLDEN") == "1" {
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
t.Fatalf("mkdir %s: %v", filepath.Dir(rel), err)
}
if err := os.WriteFile(path, []byte(got), 0o644); err != nil {
t.Fatalf("write golden %s: %v", rel, err)
}
t.Logf("updated golden %s", rel)
return
}
want, err := os.ReadFile(path)
if err != nil {
t.Fatalf("read golden %s (regenerate with %s): %v", rel, commandGoldenRegen, err)
}
if bytes.Equal([]byte(got), want) {
return
}
t.Errorf("bd command surface drifted from %s.\n%s\nIf the change is intended, regenerate with\n %s\nand review the testdata diff.",
rel, goldenLineDiff(string(want), got), commandGoldenRegen)
}
// goldenLineDiff reports the region where want and got differ: the common
// leading and trailing lines are trimmed and the rest is shown as -/+ lines,
// capped so a large drift stays readable (the reviewed artifact is the
// regenerated testdata diff, not this message).
func goldenLineDiff(want, got string) string {
const maxLines = 40
w := strings.Split(want, "\n")
g := strings.Split(got, "\n")
pre := 0
for pre < len(w) && pre < len(g) && w[pre] == g[pre] {
pre++
}
suf := 0
for suf < len(w)-pre && suf < len(g)-pre && w[len(w)-1-suf] == g[len(g)-1-suf] {
suf++
}
var b strings.Builder
fmt.Fprintf(&b, "first difference at line %d:\n", pre+1)
write := func(sign string, lines []string) {
for i, line := range lines {
if i == maxLines {
fmt.Fprintf(&b, "%s ... (%d more lines)\n", sign, len(lines)-maxLines)
return
}
fmt.Fprintf(&b, "%s %s\n", sign, line)
}
}
write("-", w[pre:len(w)-suf])
write("+", g[pre:len(g)-suf])
return b.String()
}

View file

@ -280,6 +280,12 @@ var configSetCmd = &cobra.Command{
if err != nil {
return HandleError("%v", err)
}
// Per-key validation that needs the store rather than the key alone: turning
// versioned history on refuses, writing nothing, while any issue holds a value a
// version could not record. The store is open here, on whichever route this is.
if err := checkVersionedHistoryCanBeEnabled(rootCtx, key, value); err != nil {
return HandleError("%v", err)
}
result, err := settings.SetSetting(rootCtx, issueops.SetSettingRequest{Key: key, Value: value})
if err != nil {
return HandleError("setting config: %v", err)
@ -1222,6 +1228,14 @@ Examples:
return HandleError("%v", err)
}
}
// The pre-enable check `bd config set` makes: turning versioned history
// on refuses while any issue holds a value a version could not record.
// This verb writes the same setting through a loop of its own, so it
// makes the check itself, here and before any pair is written: a refusal
// stores nothing from the batch.
if err := checkVersionedHistoryCanBeEnabled(rootCtx, p.key, p.value); err != nil {
return HandleError("%v", err)
}
}
var yamlPairs, gitPairs, dbPairs []kvPair
@ -1352,7 +1366,7 @@ var recognizedConfigPrefixes = []string{
"status.", "types.", "doctor.suppress.", "routing.", "sync.", "git.",
"directory.", "repos.", "external_projects.", "validation.",
"lint.", "hierarchy.", "ai.", "backup.", "federation.", "metrics.",
"agent.", "claim.", "storage-class.",
"agent.", "claim.", "storage-class.", "versioned-history.",
}
// validateStorageClassConfig validates a storage-class.<type> per-type

View file

@ -193,32 +193,52 @@ func TestApplyServerSkipsWhenAutoStartDisabled(t *testing.T) {
}
}
// isolatedApplyFixture builds a throwaway git repo with a .beads dir for the
// runApply tests. runApply(false) is a live apply: it inspects AND MUTATES the
// repository that owns the process cwd (hook reinstalls, hooksPath mkdirs).
// Run bare from the package dir, that repository is this checkout — the r880
// host .git clobber (wy-qlvlmf) — so these tests must always chdir into a
// fixture they own first.
func isolatedApplyFixture(t *testing.T) string {
t.Helper()
dir := t.TempDir()
initGitRepoAt(t, dir)
if err := os.MkdirAll(filepath.Join(dir, ".beads"), 0o755); err != nil {
t.Fatalf("create fixture .beads: %v", err)
}
return dir
}
func TestRunApplyAllOK(t *testing.T) {
t.Setenv("BEADS_TEST_IGNORE_REPO_CONFIG", "1")
// In a test environment with no drift, all results should be ok or skipped
results := runApply(false)
if len(results) != 3 {
t.Errorf("expected 3 results, got %d", len(results))
}
for _, r := range results {
if r.Status == applyStatusError {
t.Errorf("unexpected error for check %q: %s", r.Check, r.Error)
runInDir(t, isolatedApplyFixture(t), func() {
// In a test environment with no drift, all results should be ok or skipped
results := runApply(false)
if len(results) != 3 {
t.Errorf("expected 3 results, got %d", len(results))
}
}
for _, r := range results {
if r.Status == applyStatusError {
t.Errorf("unexpected error for check %q: %s", r.Check, r.Error)
}
}
})
}
func TestRunApplyDryRun(t *testing.T) {
t.Setenv("BEADS_TEST_IGNORE_REPO_CONFIG", "1")
results := runApply(true)
if len(results) != 3 {
t.Errorf("expected 3 results, got %d", len(results))
}
// In dry-run, no actions should be "applied"
for _, r := range results {
if r.Status == applyStatusApplied {
t.Errorf("dry-run should not apply actions, but check %q was applied", r.Check)
runInDir(t, isolatedApplyFixture(t), func() {
results := runApply(true)
if len(results) != 3 {
t.Errorf("expected 3 results, got %d", len(results))
}
}
// In dry-run, no actions should be "applied"
for _, r := range results {
if r.Status == applyStatusApplied {
t.Errorf("dry-run should not apply actions, but check %q was applied", r.Check)
}
}
})
}
func TestDriftDomainsGroupsDottedChecks(t *testing.T) {

View file

@ -4,6 +4,8 @@ import (
"fmt"
"os"
"strings"
"github.com/steveyegge/beads/internal/versionedhistory"
)
// configSideEffect describes a hint or warning to show after a config change.
@ -65,6 +67,11 @@ func checkConfigSetSideEffects(key, value string) []configSideEffect {
Message: fmt.Sprintf("Git sync remote set to %q. Ensure this git remote exists.", value),
Command: fmt.Sprintf("git remote -v | grep %s", value),
})
case key == versionedHistorySettingKey && versionedhistory.ValueEnables(value):
effects = append(effects, configSideEffect{
Message: "Versioned history now records for this store. The setting replicates on 'bd dolt push' and 'bd dolt pull', so every clone that pulls it records too, and it is safe with a single writer only: keep one writer at a time per store (docs/reference/configuration.md#versioned-issue-history).",
})
}
return effects

View file

@ -2,6 +2,7 @@ package main
import (
"os"
"strings"
"testing"
)
@ -105,6 +106,34 @@ func TestCheckConfigSetSideEffects_UnknownKey(t *testing.T) {
}
}
// versioned-history.enabled is a row of the store's config table, which
// replicates on `bd dolt push` and `bd dolt pull`, and the feature is single
// writer only. `bd config set ... true` is the moment someone turns it on, so it
// is where that caveat belongs -- said once, at the command that has the effect.
func TestVersionedHistoryConfigSetHintsAboutReplicationAndSingleWriter(t *testing.T) {
for _, on := range []string{"true", "TRUE", " true ", "1", "t"} {
effects := checkConfigSetSideEffects(versionedHistorySettingKey, on)
if len(effects) != 1 {
t.Errorf("value %q turns recording on: expected 1 hint, got %d", on, len(effects))
continue
}
for _, want := range []string{"replicates", "single writer"} {
if !strings.Contains(strings.ToLower(effects[0].Message), want) {
t.Errorf("value %q: the hint does not mention %q: %s", on, want, effects[0].Message)
}
}
}
// Turning it off, or anything that does not turn it on, needs no caveat.
for _, off := range []string{"false", "0", "", "off", "nonsense"} {
if effects := checkConfigSetSideEffects(versionedHistorySettingKey, off); len(effects) != 0 {
t.Errorf("value %q does not turn recording on: expected no hint, got %d", off, len(effects))
}
}
if effects := checkConfigUnsetSideEffects(versionedHistorySettingKey); len(effects) != 0 {
t.Errorf("unsetting the key needs no hint, got %d", len(effects))
}
}
func TestCheckConfigUnsetSideEffects_FederationRemote(t *testing.T) {
effects := checkConfigUnsetSideEffects("federation.remote")
if len(effects) != 1 {

View file

@ -11,6 +11,7 @@ import (
"testing"
"github.com/steveyegge/beads/internal/storage/embeddeddolt"
"github.com/steveyegge/beads/internal/types"
)
// The TestEmbeddedContributorCreate* tests exercise the full contributor mode flow in
@ -98,6 +99,67 @@ func TestEmbeddedContributorCreateMultiple(t *testing.T) {
})
}
// TestEmbeddedContributorRoutedWritesCommitInPlanning runs, through the bd
// binary in a contributor checkout, the commands that change an issue living in
// the planning repository: each writes the change there and advances the
// planning database's HEAD, as the TestEmbeddedRoutedSiblingWritesCommitTargetHead*
// tests pin for a prefix route. While the contributor auto-route opened its
// target read-only, the embedded store refused every one of these writes.
func TestEmbeddedContributorRoutedWritesCommitInPlanning(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt contributor tests")
}
t.Parallel()
bd := buildEmbeddedBD(t)
dir, planningDir := initContributor(t, bd, "cw")
planningBeadsDir := filepath.Join(planningDir, ".beads")
issue := bdCreate(t, bd, dir, "Planning issue")
question := bdCreate(t, bd, dir, "Planning question")
dismissed := bdCreate(t, bd, dir, "Planning request")
for _, step := range []struct {
name string
args []string
}{
{"update --claim", []string{"update", issue.ID, "--claim"}},
{"unclaim", []string{"unclaim", issue.ID}},
{"comment", []string{"comment", issue.ID, "planning comment"}},
{"close", []string{"close", issue.ID, "--reason", "done"}},
{"human respond", []string{"human", "respond", question.ID, "--response", "answered"}},
{"human dismiss", []string{"human", "dismiss", dismissed.ID, "--reason", "not needed"}},
} {
before := embeddedCurrentCommit(t, planningBeadsDir, "cw")
bdCommand(t, bd, dir, step.args...)
assertEmbeddedHeadAdvanced(t, planningBeadsDir, "cw", before, step.name)
}
planningStore := openStore(t, planningBeadsDir, "cw")
for _, id := range []string{issue.ID, question.ID, dismissed.ID} {
got, err := planningStore.GetIssue(t.Context(), id)
if err != nil {
t.Fatalf("GetIssue(%s) in the planning store: %v", id, err)
}
if got.Status != types.StatusClosed {
t.Errorf("%s status in the planning store = %q, want %q", id, got.Status, types.StatusClosed)
}
}
comments, err := planningStore.GetIssueComments(t.Context(), issue.ID)
if err != nil {
t.Fatalf("GetIssueComments: %v", err)
}
found := false
for _, c := range comments {
if c.Text == "planning comment" {
found = true
}
}
if !found {
t.Errorf("the comment did not land in the planning store: %+v", comments)
}
assertIssueNotInStore(t, filepath.Join(dir, ".beads"), "cw", issue.ID)
}
// initContributor sets up a project with contributor mode enabled and returns
// the project dir and planning dir paths. The contributor wizard runs via
// subprocess with stdin piped to answer the interactive prompts.

View file

@ -373,6 +373,11 @@ var createCmd = &cobra.Command{
}
if dryRun && parentID == "" {
// The preview opens no target, but it refuses a local one in a
// format this build cannot open, as the create it previews would.
if err := checkRepoTargetFormat(repoPath); err != nil {
return handleWorkspaceGuardError(err)
}
return renderDryRun()
}
@ -402,6 +407,9 @@ var createCmd = &cobra.Command{
// flag value can be ambiguous.
allowCreate := !isAmbiguousRepoTarget(cmd.Flags().Changed("repo"), repoOverride)
if err := ensureBeadsDirForPath(rootCtx, targetBeadsDir, store, allowCreate); err != nil {
if isUnsupportedWorkspaceFormat(err) {
return handleWorkspaceGuardError(err)
}
return HandleError("failed to initialize target repo: %v", err)
}
@ -969,8 +977,12 @@ func init() {
}
// handleCreateTargetStoreError preserves the existing text path for ordinary
// store failures while rendering capability refusals as typed JSON when asked.
// store failures while rendering capability refusals as typed JSON when asked,
// and a target in a format this build cannot open as the workspace refusal.
func handleCreateTargetStoreError(err error, targetPath, fallbackFormat string) error {
if isUnsupportedWorkspaceFormat(err) {
return handleWorkspaceGuardError(err)
}
var capErr *ProxyCapabilityError
if !errors.As(err, &capErr) {
return HandleError(fallbackFormat, err)
@ -1020,6 +1032,12 @@ func openDryRunTargetStore(ctx context.Context, repoPath string) (storage.DoltSt
targetPath := routing.ExpandPath(repoPath)
beadsDir := filepath.Join(targetPath, ".beads")
// A target in a format this build cannot open is refused as that, even
// one marked only by a legacy config.json, which the check below would
// report as not initialized.
if err := checkDiscoveredWorkspaceFormat(beadsDir); err != nil {
return nil, err
}
metadataPath := filepath.Join(beadsDir, "metadata.json")
if _, err := os.Stat(metadataPath); err != nil {
if os.IsNotExist(err) {
@ -1035,6 +1053,17 @@ func openDryRunTargetStore(ctx context.Context, repoPath string) (storage.DoltSt
return store, nil
}
// checkRepoTargetFormat refuses a local create target in a format this build
// cannot open, reading its metadata without opening or migrating it. The
// command's own workspace (".") has passed admission already, and a remote
// target has no local metadata to read, so both pass.
func checkRepoTargetFormat(repoPath string) error {
if repoPath == "." || remotecache.IsRemoteURL(repoPath) {
return nil
}
return checkDiscoveredWorkspaceFormat(filepath.Join(routing.ExpandPath(repoPath), ".beads"))
}
// isAmbiguousRepoTarget reports whether an explicit --repo value is a
// bare/relative filesystem path (not absolute, not "~/"-prefixed). Such a
// value silently resolves against the current working directory (see
@ -1055,6 +1084,14 @@ func ensureBeadsDirForPath(ctx context.Context, targetPath string, sourceStore s
beadsDir := filepath.Join(targetPath, ".beads")
metadataPath := filepath.Join(beadsDir, "metadata.json")
// A target in a format this build cannot open is refused before anything
// below: one marked only by a legacy config.json or by the graph format
// marker file has no metadata.json, so it would otherwise be initialized
// here, with an Issue database and a metadata.json written beside it.
if err := checkDiscoveredWorkspaceFormat(beadsDir); err != nil {
return err
}
// Check if beads directory already exists with a Dolt database.
// metadata.json is the canonical marker for an initialized beads dir.
if _, err := os.Stat(metadataPath); err == nil {

View file

@ -390,6 +390,14 @@ func TestEmbeddedDepBTreeAndCycles(t *testing.T) {
if !strings.Contains(out, "flowchart") && !strings.Contains(out, "graph") {
t.Errorf("expected mermaid flowchart/graph syntax: %s", out)
}
// Mixed-case pins case-folding at the runDepTree dispatch site.
// TestDepTreeFormatMermaidCaseInsensitive calls isMermaidTreeFormat
// directly and would stay green if the call site went back to
// formatStr == "mermaid" (the PR #6646 bug).
mixed := bdDep(t, bd, dir, "tree", epic.ID, "--format", "Mermaid")
if !strings.Contains(mixed, "flowchart") && !strings.Contains(mixed, "graph") {
t.Errorf("expected mermaid flowchart/graph syntax for --format Mermaid: %s", mixed)
}
})
t.Run("tree_json_output", func(t *testing.T) {

View file

@ -0,0 +1,86 @@
//go:build cgo
package main
import (
"bytes"
"encoding/json"
"errors"
"os"
"os/exec"
"path/filepath"
"testing"
)
// TestEmbeddedDiscoveryPinsEnvFileReadonly is the store-backed member of the
// before-parity discovery pins (discovery_refusal_pins_test.go holds the
// store-less ones). It pins how an ordinary workspace applies a BD_READONLY
// supplied by its own .beads/.env: a write is refused with the read-only text
// and exit 1, also under --json, while reads still run; and a BD_READONLY the
// caller exports wins over the file.
func TestEmbeddedDiscoveryPinsEnvFileReadonly(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}
t.Parallel()
bd := buildEmbeddedBD(t)
dir, beadsDir, _ := bdInit(t, bd, "--prefix", "pin")
if err := os.WriteFile(filepath.Join(beadsDir, ".env"), []byte("BD_READONLY=true\n"), 0o600); err != nil {
t.Fatalf("write .beads/.env: %v", err)
}
run := func(extraEnv []string, args ...string) (exit int, stdout, stderr string) {
t.Helper()
cmd := exec.Command(bd, args...)
cmd.Dir = dir
// The store-less pins' closed environment: no BD_*/BEADS_* the caller
// exports (BD_READONLY, BD_JSON_ENVELOPE, BD_OTEL_*, ...) reaches bd.
// HOME stays dir, where bd init ran.
cmd.Env = append(discoveryPinEnv(dir, filepath.Join(dir, "no-such-freeze-marker")),
"BEADS_DOLT_AUTO_START=0", "BEADS_NO_DAEMON=1")
cmd.Env = append(cmd.Env, extraEnv...)
var out, errOut bytes.Buffer
cmd.Stdout, cmd.Stderr = &out, &errOut
if err := cmd.Run(); err != nil {
var exitErr *exec.ExitError
if !errors.As(err, &exitErr) {
t.Fatalf("run bd %v: %v", args, err)
}
exit = exitErr.ExitCode()
}
return exit, out.String(), discoveryPinSandboxNotice.ReplaceAllLiteralString(errOut.String(), "")
}
exit, stdout, stderr := run(nil, "create", "refused by .env", "--json")
if exit != 1 || stdout != "" || stderr != "Error: operation 'create' is not allowed in read-only mode\n" {
t.Fatalf("create under .env BD_READONLY=true: exit=%d stdout=%q stderr=%q; want exit=1, no stdout, the read-only refusal", exit, stdout, stderr)
}
exit, stdout, stderr = run(nil, "list", "--json")
if exit != 0 || stdout != "[]\n" {
t.Fatalf("list under .env BD_READONLY=true: exit=%d stdout=%q stderr=%q; want exit=0 and an empty list", exit, stdout, stderr)
}
exit, stdout, stderr = run([]string{"BD_READONLY=false"}, "create", "allowed by the caller", "--json")
if exit != 0 {
t.Fatalf("create with exported BD_READONLY=false: exit=%d stdout=%q stderr=%q; want the caller's setting to win", exit, stdout, stderr)
}
var created struct {
Title string `json:"title"`
}
if err := json.Unmarshal([]byte(stdout), &created); err != nil || created.Title != "allowed by the caller" {
t.Fatalf("create with exported BD_READONLY=false printed %q (decode error %v)", stdout, err)
}
exit, stdout, stderr = run(nil, "list", "--json")
var listed []struct {
Title string `json:"title"`
}
if exit != 0 {
t.Fatalf("list after the allowed create: exit=%d stderr=%q", exit, stderr)
}
if err := json.Unmarshal([]byte(stdout), &listed); err != nil || len(listed) != 1 || listed[0].Title != "allowed by the caller" {
t.Fatalf("list after the allowed create = %q (decode error %v); want only the allowed issue, the refused create wrote nothing", stdout, err)
}
}

View file

@ -0,0 +1,885 @@
//go:build cgo
package main
// Before-parity pins for workspace discovery refusals.
//
// These tests hold the exact text and exit code an ordinary bd prints when
// workspace discovery cannot select a usable workspace: a missing or corrupt
// metadata.json, an explicit BEADS_DIR that names no workspace, selection
// supplied by .beads/.env, .beads/redirect files, --db / BEADS_DB / BD_DB
// selection, and the blocked backend environment variables. They pin what
// origin/main does today, not what it ideally should do. A change that
// reorders admission, discovery or checkBlockedEnvVars in the root
// PersistentPreRunE has to change an expectation here, so it shows up in
// review as a test diff rather than as an unexplained behavior change.
//
// Every case runs the real bd binary in a fresh fixture and stops before any
// store is opened, so these need no Dolt server or database. Fixture
// workspaces with a corrupt metadata.json double as sentinels: the refusal
// names the metadata.json it failed to parse, so the text shows which
// directory discovery selected without opening a database.
//
// The pinned no-database hints are an embedded-capable bd's. A CGO_ENABLED=0
// bd is server-only and adds "run 'bd doctor' to diagnose" to them, so this
// file builds only with cgo, and the bd it runs (built by
// buildBDForInitTests, or BEADS_TEST_BD_BINARY) must be a cgo build too.
import (
"bytes"
"errors"
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"sort"
"strings"
"testing"
"github.com/steveyegge/beads/internal/testutil"
)
// pinNoDatabaseRefusal is what a store-requiring command prints when
// discovery finds no workspace with a database.
const pinNoDatabaseRefusal = "Error: no beads database found\n" +
"Hint: run 'bd where' to inspect the resolved workspace, or 'bd init' to create a new database\n" +
" or set BEADS_DIR to point to your .beads directory\n"
// pinNoWorkspaceWhereRefusal is bd where's text refusal when no workspace is
// selected.
const pinNoWorkspaceWhereRefusal = "Error: No active beads workspace found.\n" +
"Hint: check BEADS_DIR/worktree setup, or run 'bd init' to create a new database\n"
// pinNoWorkspaceWhereJSON is bd where --json's refusal. It goes to stdout.
const pinNoWorkspaceWhereJSON = `{
"error": "no_beads_directory",
"hint": "check BEADS_DIR/worktree setup, or run 'bd init' to create a new database",
"message": "No active beads workspace found.",
"schema_version": 1
}
`
// pinCorruptMetadata is the content of every corrupt metadata.json fixture.
const pinCorruptMetadata = "{\n"
// pinCorruptMetadataWarning is the warning printed while the selected
// workspace is bound, before the refusal itself.
func pinCorruptMetadataWarning(beadsDir string) string {
return "warning: load " + beadsDir + "/metadata.json: parsing config: unexpected end of JSON input; " +
"no storage database was opened or modified (storage mode unknown; data commands refuse to fall back to the embedded store)\n"
}
// pinCorruptMetadataRefusal is the full stderr of a command refused because
// the selected workspace's metadata.json does not parse.
func pinCorruptMetadataRefusal(beadsDir string) string {
return pinCorruptMetadataWarning(beadsDir) +
"Error: loading config: parsing config: unexpected end of JSON input\n"
}
// pinBlockedEnvRefusal is checkBlockedEnvVars' refusal for name.
func pinBlockedEnvRefusal(name string) string {
return "Error: " + name + " env var is not supported and has been removed to prevent data fragmentation.\n" +
"Unset " + name + "; storage selection comes from .beads/metadata.json. " +
"To choose a different supported backend, follow 'bd help init-safety'; do not edit metadata.json by hand\n"
}
// discoveryPinCase is one bd invocation and its exact expected result. The
// arguments and the expected strings write the fixture root as $ROOT.
type discoveryPinCase struct {
name string
// setup builds the fixture and returns the working directory and any
// environment the invocation adds to the hermetic base.
setup func(f *discoveryPinFixture) (cwd string, env []string)
args []string
exit int
stdout string
stderr string
// stderrPrefix compares only the start of stderr. Use it only where the
// rest of the output is not part of the pin.
stderrPrefix bool
}
func runDiscoveryPinCases(t *testing.T, cases []discoveryPinCase) {
t.Helper()
if runtime.GOOS == "windows" {
t.Skip("the pinned texts embed POSIX paths")
}
t.Parallel()
bd := buildBDForInitTests(t)
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
f := newDiscoveryPinFixture(t)
cwd, env := tc.setup(f)
args := make([]string, len(tc.args))
for i, arg := range tc.args {
args[i] = strings.ReplaceAll(arg, "$ROOT", f.root)
}
exit, stdout, stderr := f.run(bd, cwd, env, args...)
if exit != tc.exit {
t.Errorf("bd %s: exit = %d, want %d", strings.Join(tc.args, " "), exit, tc.exit)
}
if stdout != tc.stdout {
t.Errorf("bd %s: stdout differs\n got: %q\nwant: %q", strings.Join(tc.args, " "), stdout, tc.stdout)
}
gotStderr := stderr
if tc.stderrPrefix && len(gotStderr) > len(tc.stderr) {
gotStderr = gotStderr[:len(tc.stderr)]
}
if gotStderr != tc.stderr {
t.Errorf("bd %s: stderr differs\n got: %q\nwant: %q", strings.Join(tc.args, " "), stderr, tc.stderr)
}
})
}
}
type discoveryPinFixture struct {
t *testing.T
root string
forms []string // spellings of root to rewrite as $ROOT, longest first
}
func newDiscoveryPinFixture(t *testing.T) *discoveryPinFixture {
t.Helper()
root := t.TempDir()
forms := []string{root}
if resolved, err := filepath.EvalSymlinks(root); err == nil && resolved != root {
forms = append(forms, resolved)
}
sort.Slice(forms, func(i, j int) bool { return len(forms[i]) > len(forms[j]) })
f := &discoveryPinFixture{t: t, root: root, forms: forms}
f.mkdir("home")
return f
}
// path returns the absolute path of a root-relative slash path.
func (f *discoveryPinFixture) path(rel string) string {
return filepath.Join(f.root, filepath.FromSlash(rel))
}
func (f *discoveryPinFixture) mkdir(rel string) string {
f.t.Helper()
dir := f.path(rel)
if err := os.MkdirAll(dir, 0o700); err != nil {
f.t.Fatalf("mkdir %s: %v", dir, err)
}
return dir
}
func (f *discoveryPinFixture) write(rel, content string) {
f.t.Helper()
if err := os.WriteFile(f.path(rel), []byte(content), 0o600); err != nil {
f.t.Fatalf("write %s: %v", rel, err)
}
}
// project creates rel as a git repository with no .beads. The repository
// root is the discovery walk's boundary, so nothing above the fixture leaks
// into a case.
func (f *discoveryPinFixture) project(rel string) string {
f.t.Helper()
dir := f.mkdir(rel)
initGitRepoAt(f.t, dir)
return dir
}
// workspace creates project rel with a .beads directory holding files, each
// named relative to .beads.
func (f *discoveryPinFixture) workspace(rel string, files map[string]string) string {
f.t.Helper()
dir := f.project(rel)
f.mkdir(rel + "/.beads")
for name, content := range files {
f.write(rel+"/.beads/"+name, content)
}
return dir
}
// corruptWorkspace creates project rel whose metadata.json does not parse,
// plus any extra .beads files.
func (f *discoveryPinFixture) corruptWorkspace(rel string, extra map[string]string) string {
f.t.Helper()
files := map[string]string{"metadata.json": pinCorruptMetadata}
for name, content := range extra {
files[name] = content
}
return f.workspace(rel, files)
}
// yamlWorkspace creates project rel whose .beads holds only a config.yaml
// (no metadata.json and no database), plus any extra .beads files.
func (f *discoveryPinFixture) yamlWorkspace(rel string, extra map[string]string) string {
f.t.Helper()
files := map[string]string{"config.yaml": "# discovery pin fixture\n"}
for name, content := range extra {
files[name] = content
}
return f.workspace(rel, files)
}
// discoveryPinEnv is the caller environment without any BEADS_*/BD_*
// selector or setting and without git repository-location variables, with
// HOME and XDG_CONFIG_HOME under home, metrics and event flush off, and the
// migration freeze marker pointed at freezeMarker, a path that does not exist.
func discoveryPinEnv(home, freezeMarker string) []string {
var env []string
for _, kv := range testutil.WithoutGitRepoLocationEnv(os.Environ()) {
key, _, _ := strings.Cut(kv, "=")
if strings.HasPrefix(key, "BEADS_") || strings.HasPrefix(key, "BD_") ||
key == "HOME" || key == "XDG_CONFIG_HOME" {
continue
}
env = append(env, kv)
}
return append(env,
"HOME="+home,
"XDG_CONFIG_HOME="+filepath.Join(home, ".config"),
"BD_DISABLE_METRICS=1",
"BD_DISABLE_EVENT_FLUSH=1",
"BD_MIGRATION_FREEZE_FILE="+freezeMarker,
)
}
func (f *discoveryPinFixture) run(bd, cwd string, extraEnv []string, args ...string) (exit int, stdout, stderr string) {
f.t.Helper()
cmd := exec.Command(bd, args...)
cmd.Dir = cwd
cmd.Env = append(discoveryPinEnv(f.path("home"), f.path("no-such-freeze-marker")), extraEnv...)
var out, errOut bytes.Buffer
cmd.Stdout, cmd.Stderr = &out, &errOut
if err := cmd.Run(); err != nil {
var exitErr *exec.ExitError
if !errors.As(err, &exitErr) {
f.t.Fatalf("run bd %s: %v", strings.Join(args, " "), err)
}
exit = exitErr.ExitCode()
}
return exit, f.normalize(out.String(), false), f.normalize(errOut.String(), true)
}
var discoveryPinVersionLine = regexp.MustCompile(`(?m)^bd version .*$`)
// discoveryPinDuplicateBinaries matches the warning bd version appends when
// the caller's PATH holds more than one distinct bd binary.
var discoveryPinDuplicateBinaries = regexp.MustCompile(
`\nWarning: multiple 'bd' binaries found in PATH:\n(?: [^\n]*\n)*` +
`The first one is being used\. Remove duplicates to avoid confusion\.\n`)
// discoveryPinSandboxNotice matches the notice bd prints when it auto-detects
// a sandbox, which it does when it is not allowed to signal its own process.
var discoveryPinSandboxNotice = regexp.MustCompile(`(?m)^.*Sandbox detected, using direct mode\n`)
// normalize rewrites the fixture root as $ROOT and the build's version line
// as "bd version $VERSION". For stderr it also drops the notices that depend
// on the caller's environment rather than on the fixture (sandbox
// auto-detection, and bd version's duplicate binaries in PATH) and collapses
// consecutive repeats of a "Warning: redirect" line: discovery re-resolves
// the same redirect several times per invocation and how many times it warns
// is not part of the pin. Any other repeated line, such as a doubled
// "Error:", is kept.
func (f *discoveryPinFixture) normalize(s string, stderr bool) string {
for _, form := range f.forms {
s = strings.ReplaceAll(s, form, "$ROOT")
}
s = discoveryPinVersionLine.ReplaceAllLiteralString(s, "bd version $VERSION")
if !stderr {
return s
}
s = discoveryPinDuplicateBinaries.ReplaceAllLiteralString(s, "")
s = discoveryPinSandboxNotice.ReplaceAllLiteralString(s, "")
var b strings.Builder
prev := ""
for _, line := range strings.SplitAfter(s, "\n") {
if line == prev && strings.HasPrefix(line, "Warning: redirect ") {
continue
}
b.WriteString(line)
prev = line
}
return b.String()
}
// TestDiscoveryRefusalPinsMissingMetadata pins discovery when no workspace,
// a workspace without metadata.json and without a database, or a .beads that
// is a regular file is found.
func TestDiscoveryRefusalPinsMissingMetadata(t *testing.T) {
noBeads := func(f *discoveryPinFixture) (string, []string) { return f.project("p"), nil }
regularFileBeads := func(f *discoveryPinFixture) (string, []string) {
cwd := f.project("p")
f.write("p/.beads", "not a workspace\n")
return cwd, nil
}
runDiscoveryPinCases(t, []discoveryPinCase{
{
name: "no-beads-dir/list",
setup: noBeads,
args: []string{"list"},
exit: 1,
stderr: pinNoDatabaseRefusal,
},
{
// --json does not turn the refusal into a JSON document.
name: "no-beads-dir/list-json",
setup: noBeads,
args: []string{"list", "--json"},
exit: 1,
stderr: pinNoDatabaseRefusal,
},
{
name: "no-beads-dir/where",
setup: noBeads,
args: []string{"where"},
exit: 1,
stderr: pinNoWorkspaceWhereRefusal,
},
{
name: "no-beads-dir/where-json",
setup: noBeads,
args: []string{"where", "--json"},
exit: 1,
stdout: pinNoWorkspaceWhereJSON,
},
{
name: "empty-beads-dir/list",
setup: func(f *discoveryPinFixture) (string, []string) {
return f.workspace("p", nil), nil
},
args: []string{"list"},
exit: 1,
stderr: pinNoDatabaseRefusal,
},
{
name: "config-yaml-only/list",
setup: func(f *discoveryPinFixture) (string, []string) {
return f.yamlWorkspace("p", nil), nil
},
args: []string{"list"},
exit: 1,
stderr: pinNoDatabaseRefusal,
},
{
// The same directory is a workspace to bd where.
name: "config-yaml-only/where",
setup: func(f *discoveryPinFixture) (string, []string) {
return f.yamlWorkspace("p", nil), nil
},
args: []string{"where"},
stdout: "$ROOT/p/.beads\n",
},
{
// The working-directory walk selects a .beads that is a regular
// file, then fails to read its metadata.json (the BEADS_DIR form
// is in TestDiscoveryRefusalPinsExplicitBeadsDir).
name: "beads-is-regular-file/list",
setup: regularFileBeads,
args: []string{"list"},
exit: 1,
stderr: "Error: loading config: reading config: open $ROOT/p/.beads/metadata.json: not a directory\n",
},
{
name: "beads-is-regular-file/where",
setup: regularFileBeads,
args: []string{"where"},
exit: 1,
stderr: "Error: loading config: reading config: open $ROOT/p/.beads/metadata.json: not a directory\n",
},
})
}
// TestDiscoveryRefusalPinsCorruptMetadata pins the refusal for a discovered
// workspace whose metadata.json does not parse.
func TestDiscoveryRefusalPinsCorruptMetadata(t *testing.T) {
corrupt := func(f *discoveryPinFixture) (string, []string) { return f.corruptWorkspace("p", nil), nil }
runDiscoveryPinCases(t, []discoveryPinCase{
{
name: "list",
setup: corrupt,
args: []string{"list"},
exit: 1,
stderr: pinCorruptMetadataRefusal("$ROOT/p/.beads"),
},
{
name: "list-json",
setup: corrupt,
args: []string{"list", "--json"},
exit: 1,
stderr: pinCorruptMetadataRefusal("$ROOT/p/.beads"),
},
{
name: "create",
setup: corrupt,
args: []string{"create", "must not be written", "--json"},
exit: 1,
stderr: pinCorruptMetadataRefusal("$ROOT/p/.beads"),
},
{
// bd where never opens a store, but it still refuses.
name: "where",
setup: corrupt,
args: []string{"where"},
exit: 1,
stderr: pinCorruptMetadataRefusal("$ROOT/p/.beads"),
},
{
name: "where-json",
setup: corrupt,
args: []string{"where", "--json"},
exit: 1,
stderr: pinCorruptMetadataRefusal("$ROOT/p/.beads"),
},
{
// bd version warns and succeeds.
name: "version",
setup: corrupt,
args: []string{"version"},
stdout: "bd version $VERSION\n",
stderr: pinCorruptMetadataWarning("$ROOT/p/.beads"),
},
})
}
// TestDiscoveryRefusalPinsExplicitBeadsDir pins an exported BEADS_DIR that
// names no workspace. Each case runs from a corrupt workspace, so falling
// back to discovery from the working directory would print that workspace's
// refusal instead.
func TestDiscoveryRefusalPinsExplicitBeadsDir(t *testing.T) {
from := func(beadsDir func(f *discoveryPinFixture) string) func(f *discoveryPinFixture) (string, []string) {
return func(f *discoveryPinFixture) (string, []string) {
cwd := f.corruptWorkspace("cwd", nil)
return cwd, []string{"BEADS_DIR=" + beadsDir(f)}
}
}
missing := from(func(f *discoveryPinFixture) string { return f.path("missing/.beads") })
runDiscoveryPinCases(t, []discoveryPinCase{
{
name: "missing-dir/list",
setup: missing,
args: []string{"list"},
exit: 1,
stderr: pinNoDatabaseRefusal,
},
{
name: "missing-dir/where",
setup: missing,
args: []string{"where"},
exit: 1,
stderr: pinNoWorkspaceWhereRefusal,
},
{
name: "missing-dir/where-json",
setup: missing,
args: []string{"where", "--json"},
exit: 1,
stdout: pinNoWorkspaceWhereJSON,
},
{
name: "empty-dir/list",
setup: from(func(f *discoveryPinFixture) string { return f.mkdir("empty") }),
args: []string{"list"},
exit: 1,
stderr: pinNoDatabaseRefusal,
},
{
name: "regular-file/list",
setup: from(func(f *discoveryPinFixture) string {
f.write("file", "not a workspace\n")
return f.path("file")
}),
args: []string{"list"},
exit: 1,
stderr: "Error: loading config: reading config: open $ROOT/file/metadata.json: not a directory\n",
},
{
name: "corrupt-workspace/list",
setup: from(func(f *discoveryPinFixture) string {
f.corruptWorkspace("other", nil)
return f.path("other/.beads")
}),
args: []string{"list"},
exit: 1,
stderr: pinCorruptMetadataRefusal("$ROOT/other/.beads"),
},
})
}
// TestDiscoveryRefusalPinsBeadsEnvFile pins settings supplied by the
// discovered workspace's .beads/.env.
func TestDiscoveryRefusalPinsBeadsEnvFile(t *testing.T) {
runDiscoveryPinCases(t, []discoveryPinCase{
{
// A .env BEADS_DIR routes discovery to its target.
name: "beads-dir-routes-to-target",
setup: func(f *discoveryPinFixture) (string, []string) {
f.corruptWorkspace("target", nil)
return f.yamlWorkspace("p", map[string]string{".env": "BEADS_DIR=" + f.path("target/.beads") + "\n"}), nil
},
args: []string{"list"},
exit: 1,
stderr: pinCorruptMetadataRefusal("$ROOT/target/.beads"),
},
{
// The routing workspace's own corrupt metadata.json causes no refusal.
name: "beads-dir-route-skips-local-metadata",
setup: func(f *discoveryPinFixture) (string, []string) {
return f.corruptWorkspace("p", map[string]string{".env": "BEADS_DIR=" + f.path("missing/.beads") + "\n"}), nil
},
args: []string{"list"},
exit: 1,
stderr: pinNoDatabaseRefusal,
},
{
// An exported BEADS_DIR wins; the .env is never read.
name: "exported-beads-dir-wins",
setup: func(f *discoveryPinFixture) (string, []string) {
f.corruptWorkspace("target", nil)
cwd := f.yamlWorkspace("p", map[string]string{".env": "BEADS_DIR=" + f.path("target/.beads") + "\n"})
return cwd, []string{"BEADS_DIR=" + f.path("missing/.beads")}
},
args: []string{"list"},
exit: 1,
stderr: pinNoDatabaseRefusal,
},
{
// A .env BEADS_DB does not route a data command away from the
// workspace that holds the .env (the shadowing
// TestDiscoveryRefusalPinsDBSelection records for an exported
// BEADS_DB) ...
name: "beads-db-list",
setup: func(f *discoveryPinFixture) (string, []string) {
f.corruptWorkspace("target", nil)
return f.yamlWorkspace("p", map[string]string{".env": "BEADS_DB=" + f.path("target/.beads/dolt") + "\n"}), nil
},
args: []string{"list"},
exit: 1,
stderr: pinNoDatabaseRefusal,
},
{
// ... but it does route bd where.
name: "beads-db-where",
setup: func(f *discoveryPinFixture) (string, []string) {
f.corruptWorkspace("target", nil)
return f.yamlWorkspace("p", map[string]string{".env": "BEADS_DB=" + f.path("target/.beads/dolt") + "\n"}), nil
},
args: []string{"where"},
exit: 1,
stderr: pinCorruptMetadataRefusal("$ROOT/target/.beads"),
},
{
// Settings in the selected workspace's .env apply (BD_JSON here).
name: "setting-applies-in-selected-workspace",
setup: func(f *discoveryPinFixture) (string, []string) {
return f.yamlWorkspace("p", map[string]string{".env": "BD_JSON=true\n"}), nil
},
args: []string{"where"},
stdout: "{\n \"path\": \"$ROOT/p/.beads\",\n \"schema_version\": 1\n}\n",
},
{
// A .env that routes elsewhere contributes only its selector:
// its other settings are not imported, so the refusal is text.
name: "setting-not-imported-from-routing-source",
setup: func(f *discoveryPinFixture) (string, []string) {
return f.yamlWorkspace("p", map[string]string{".env": "BD_JSON=true\nBEADS_DIR=" + f.path("missing/.beads") + "\n"}), nil
},
args: []string{"where"},
exit: 1,
stderr: pinNoWorkspaceWhereRefusal,
},
{
// checkBlockedEnvVars sees only the exported environment, and runs
// before any .env is loaded: a .env BD_BACKEND is not refused, here
// or anywhere before discovery's own no-database refusal.
name: "blocked-backend-not-checked",
setup: func(f *discoveryPinFixture) (string, []string) {
return f.yamlWorkspace("p", map[string]string{".env": "BD_BACKEND=sqlite\n"}), nil
},
args: []string{"list"},
exit: 1,
stderr: pinNoDatabaseRefusal,
},
})
}
// TestDiscoveryRefusalPinsRedirect pins .beads/redirect handling: the
// warnings for unusable targets and which directory is selected afterwards.
func TestDiscoveryRefusalPinsRedirect(t *testing.T) {
runDiscoveryPinCases(t, []discoveryPinCase{
{
// A missing target is ignored and discovery keeps the source.
name: "missing-target",
setup: func(f *discoveryPinFixture) (string, []string) {
return f.corruptWorkspace("p", map[string]string{"redirect": f.path("missing/.beads") + "\n"}), nil
},
args: []string{"list"},
exit: 1,
stderr: "Warning: redirect target does not exist or is not a directory: $ROOT/missing/.beads\n" +
pinCorruptMetadataRefusal("$ROOT/p/.beads"),
},
{
// A target without project files is ignored the same way.
name: "target-without-workspace",
setup: func(f *discoveryPinFixture) (string, []string) {
f.mkdir("bare/.beads")
return f.corruptWorkspace("p", map[string]string{"redirect": "../bare/.beads\n"}), nil
},
args: []string{"list"},
exit: 1,
stderr: "Warning: ignoring redirect from $ROOT/p/.beads to $ROOT/bare/.beads because the target has no database or metadata.json; fix or delete the redirect file\n" +
pinCorruptMetadataRefusal("$ROOT/p/.beads"),
},
{
name: "corrupt-target",
setup: func(f *discoveryPinFixture) (string, []string) {
f.corruptWorkspace("target", nil)
return f.workspace("p", map[string]string{"redirect": "../target/.beads\n"}), nil
},
args: []string{"list"},
exit: 1,
stderr: pinCorruptMetadataRefusal("$ROOT/target/.beads"),
},
{
// Only one level is followed.
name: "chain",
setup: func(f *discoveryPinFixture) (string, []string) {
f.corruptWorkspace("final", nil)
f.corruptWorkspace("middle", map[string]string{"redirect": "../final/.beads\n"})
return f.workspace("p", map[string]string{"redirect": "../middle/.beads\n"}), nil
},
args: []string{"list"},
exit: 1,
stderr: "Warning: redirect chains not allowed, ignoring redirect in $ROOT/middle/.beads\n" +
pinCorruptMetadataRefusal("$ROOT/middle/.beads"),
},
{
// An explicit BEADS_DIR is followed through its redirect.
name: "explicit-beads-dir",
setup: func(f *discoveryPinFixture) (string, []string) {
f.corruptWorkspace("target", nil)
f.workspace("source", map[string]string{"redirect": "../target/.beads\n"})
return f.project("p"), []string{"BEADS_DIR=" + f.path("source/.beads")}
},
args: []string{"list"},
exit: 1,
stderr: pinCorruptMetadataRefusal("$ROOT/target/.beads"),
},
{
name: "where-reports-source",
setup: func(f *discoveryPinFixture) (string, []string) {
f.yamlWorkspace("target", nil)
return f.workspace("p", map[string]string{"redirect": "../target/.beads\n"}), nil
},
args: []string{"where"},
stdout: "$ROOT/target/.beads\n (via redirect from $ROOT/p/.beads)\n",
},
})
}
// TestDiscoveryRefusalPinsDBSelection pins database selection by --db and by
// the BEADS_DB and BD_DB environment variables.
//
// Two of these record inconsistencies as they stand rather than endorse
// them: a data command ignores BD_DB, and lets a discoverable workspace in
// the working directory shadow BEADS_DB, while bd where honors both.
func TestDiscoveryRefusalPinsDBSelection(t *testing.T) {
target := func(f *discoveryPinFixture) string {
f.corruptWorkspace("target", nil)
return f.path("target/.beads/dolt")
}
runDiscoveryPinCases(t, []discoveryPinCase{
{
// A --db path selects the workspace that owns it.
name: "db-path",
setup: func(f *discoveryPinFixture) (string, []string) {
target(f)
return f.project("p"), nil
},
args: []string{"--db", "$ROOT/target/.beads/dolt", "list"},
exit: 1,
stderr: pinCorruptMetadataRefusal("$ROOT/target/.beads"),
},
{
name: "db-path-beats-beads-dir",
setup: func(f *discoveryPinFixture) (string, []string) {
target(f)
f.corruptWorkspace("other", nil)
return f.project("p"), []string{"BEADS_DIR=" + f.path("other/.beads")}
},
args: []string{"--db", "$ROOT/target/.beads/dolt", "list"},
exit: 1,
stderr: pinCorruptMetadataRefusal("$ROOT/target/.beads"),
},
{
name: "db-path-beats-working-directory",
setup: func(f *discoveryPinFixture) (string, []string) {
target(f)
return f.corruptWorkspace("p", nil), nil
},
args: []string{"--db", "$ROOT/target/.beads/dolt", "list"},
exit: 1,
stderr: pinCorruptMetadataRefusal("$ROOT/target/.beads"),
},
{
// A --db value that is a database name rather than an existing
// path leaves discovery to the working directory.
name: "db-name-without-workspace",
setup: func(f *discoveryPinFixture) (string, []string) {
return f.project("p"), nil
},
args: []string{"--db", "pindb", "list"},
exit: 1,
stderr: pinNoDatabaseRefusal,
},
{
name: "db-name-in-workspace",
setup: func(f *discoveryPinFixture) (string, []string) {
return f.corruptWorkspace("p", nil), nil
},
args: []string{"--db", "pindb", "list"},
exit: 1,
stderr: pinCorruptMetadataRefusal("$ROOT/p/.beads"),
},
{
name: "beads-db-env",
setup: func(f *discoveryPinFixture) (string, []string) {
return f.project("p"), []string{"BEADS_DB=" + target(f)}
},
args: []string{"list"},
exit: 1,
stderr: pinCorruptMetadataRefusal("$ROOT/target/.beads"),
},
{
// Inconsistency: the working directory's workspace shadows BEADS_DB.
name: "beads-db-env-shadowed-by-working-directory",
setup: func(f *discoveryPinFixture) (string, []string) {
return f.corruptWorkspace("p", nil), []string{"BEADS_DB=" + target(f)}
},
args: []string{"list"},
exit: 1,
stderr: pinCorruptMetadataRefusal("$ROOT/p/.beads"),
},
{
name: "beads-db-env-where",
setup: func(f *discoveryPinFixture) (string, []string) {
return f.corruptWorkspace("p", nil), []string{"BEADS_DB=" + target(f)}
},
args: []string{"where"},
exit: 1,
stderr: pinCorruptMetadataRefusal("$ROOT/target/.beads"),
},
{
// Inconsistency: a data command ignores BD_DB.
name: "bd-db-env",
setup: func(f *discoveryPinFixture) (string, []string) {
return f.project("p"), []string{"BD_DB=" + target(f)}
},
args: []string{"list"},
exit: 1,
stderr: pinNoDatabaseRefusal,
},
{
name: "bd-db-env-where",
setup: func(f *discoveryPinFixture) (string, []string) {
return f.project("p"), []string{"BD_DB=" + target(f)}
},
args: []string{"where"},
exit: 1,
stderr: pinCorruptMetadataRefusal("$ROOT/target/.beads"),
},
})
}
// TestDiscoveryRefusalPinsBlockedEnvVarsRunFirst pins that the blocked
// backend variables are refused before any discovery, for every command.
func TestDiscoveryRefusalPinsBlockedEnvVarsRunFirst(t *testing.T) {
runDiscoveryPinCases(t, []discoveryPinCase{
{
name: "no-workspace",
setup: func(f *discoveryPinFixture) (string, []string) {
return f.project("p"), []string{"BD_BACKEND=sqlite"}
},
args: []string{"list"},
exit: 1,
stderr: pinBlockedEnvRefusal("BD_BACKEND"),
},
{
name: "corrupt-metadata",
setup: func(f *discoveryPinFixture) (string, []string) {
return f.corruptWorkspace("p", nil), []string{"BD_BACKEND=sqlite"}
},
args: []string{"list"},
exit: 1,
stderr: pinBlockedEnvRefusal("BD_BACKEND"),
},
{
name: "explicit-beads-dir",
setup: func(f *discoveryPinFixture) (string, []string) {
return f.project("p"), []string{"BD_BACKEND=sqlite", "BEADS_DIR=" + f.path("missing/.beads")}
},
args: []string{"list"},
exit: 1,
stderr: pinBlockedEnvRefusal("BD_BACKEND"),
},
{
// A BEADS_DIR that cannot even be read as a directory is still
// reached only after the blocked variable is refused.
name: "unreadable-beads-dir",
setup: func(f *discoveryPinFixture) (string, []string) {
f.write("file", "not a workspace\n")
return f.project("p"), []string{"BD_BACKEND=sqlite", "BEADS_DIR=" + f.path("file")}
},
args: []string{"list"},
exit: 1,
stderr: pinBlockedEnvRefusal("BD_BACKEND"),
},
{
name: "db-path",
setup: func(f *discoveryPinFixture) (string, []string) {
f.corruptWorkspace("target", nil)
return f.project("p"), []string{"BD_BACKEND=sqlite"}
},
args: []string{"--db", "$ROOT/target/.beads/dolt", "list"},
exit: 1,
stderr: pinBlockedEnvRefusal("BD_BACKEND"),
},
{
// --json does not turn the refusal into a JSON document.
name: "database-backend-json",
setup: func(f *discoveryPinFixture) (string, []string) {
return f.corruptWorkspace("p", nil), []string{"BD_DATABASE_BACKEND=dolt"}
},
args: []string{"list", "--json"},
exit: 1,
stderr: pinBlockedEnvRefusal("BD_DATABASE_BACKEND"),
},
{
name: "where-json",
setup: func(f *discoveryPinFixture) (string, []string) {
return f.project("p"), []string{"BD_BACKEND=sqlite"}
},
args: []string{"where", "--json"},
exit: 1,
stderr: pinBlockedEnvRefusal("BD_BACKEND"),
},
{
name: "version-command",
setup: func(f *discoveryPinFixture) (string, []string) {
return f.project("p"), []string{"BD_BACKEND=sqlite"}
},
args: []string{"version"},
exit: 1,
stderr: pinBlockedEnvRefusal("BD_BACKEND"),
},
{
// The root command then prints cobra's error and usage; only the
// refusal itself is pinned.
name: "version-flag",
setup: func(f *discoveryPinFixture) (string, []string) {
return f.project("p"), []string{"BD_BACKEND=sqlite"}
},
args: []string{"--version"},
exit: 1,
stderr: pinBlockedEnvRefusal("BD_BACKEND"),
stderrPrefix: true,
},
})
}

View file

@ -220,7 +220,7 @@ Examples:
if err := validateDoctorWorkspaceBackend(absPath); isLegacyUpgradeRefusal(err) {
return printLegacyUpgradeDiagnostic(err)
} else if err != nil {
return HandleError("%v", err)
return handleWorkspaceGuardError(err)
}
if doctorFix && isOrchestratorRoot(absPath) {

View file

@ -57,6 +57,14 @@ func TestMain(m *testing.M) {
}
func testMainInner(m *testing.M) int {
// A GIT_DIR/GIT_WORK_TREE leaked in from the invoking shell or a git hook
// would route the fixture `git init`/`git config` writes in this suite
// into that repository: the host checkout in the r880 clobber (wy-qlvlmf).
if err := testutil.UnsetGitRepoLocationEnv(); err != nil {
fmt.Fprintf(os.Stderr, "FATAL: %v\n", err)
return 1
}
os.Setenv("BEADS_TEST_MODE", "1")
// AD-01 (be-c5p): doctor e2e tests connect to a per-package test server.
// The dolt.New database-name firewall requires this opt-in to allow

View file

@ -43,6 +43,7 @@ go_library(
"//internal/storage/issueops",
"//internal/types",
"//internal/utils",
"//internal/versionedhistory",
"@com_github_burntsushi_toml//:toml",
"@com_github_go_sql_driver_mysql//:mysql",
"@in_gopkg_yaml_v3//:yaml_v3",
@ -81,7 +82,11 @@ go_test(
"testmain_cgo_test.go",
"testmain_nocgo_test.go",
"validation_test.go",
"versioned_history_activation_test.go",
],
# versioned_history_activation_test.go parses store.go from its working
# directory, and a Bazel test only sees its declared runfiles.
data = ["store.go"],
embed = [":fix"],
deps = [
"//internal/configfile",

View file

@ -30,8 +30,13 @@ func initGitTemplate() {
}
gitTemplateDir = dir
// The template is built once, inside whichever test asks first. Its
// writes must land in dir even if that test set GIT_DIR/GIT_WORK_TREE,
// or they hit that repository (the r880 clobber class, wy-qlvlmf).
env := testutil.WithoutGitRepoLocationEnv(os.Environ())
cmd := gitCommand("init", "--initial-branch=main")
cmd.Dir = dir
cmd.Env = env
if err := cmd.Run(); err != nil {
gitTemplateErr = fmt.Errorf("git init failed: %w", err)
return
@ -43,6 +48,7 @@ func initGitTemplate() {
} {
cmd = gitCommand(args...)
cmd.Dir = dir
cmd.Env = env
if err := cmd.Run(); err != nil {
gitTemplateErr = fmt.Errorf("git %v failed: %w", args, err)
return

View file

@ -12,6 +12,7 @@ import (
mysql "github.com/go-sql-driver/mysql"
"github.com/steveyegge/beads/internal/configfile"
"github.com/steveyegge/beads/internal/testutil"
)
// TestFixMissingMetadata_NotBeadsWorkspace verifies that FixMissingMetadata
@ -199,8 +200,21 @@ func TestFixMissingMetadataJSON_NotBeadsWorkspace(t *testing.T) {
}
// setupGitRepoInDir initializes a git repo in the given directory with a remote.
//
// Every step is fatal on failure, the dir must exist, and the child env is
// scrubbed of the git vars that name a repository (GIT_DIR, GIT_WORK_TREE,
// ...). An empty dir, a swallowed config failure, or a leaked GIT_DIR each make
// these writes land in whatever repository git resolves from the process
// environment — the host checkout's own .git/config in the r880 clobber
// (wy-qlvlmf), where this helper's remote.origin.url overwrote the real origin.
func setupGitRepoInDir(t *testing.T, dir string) {
t.Helper()
if dir == "" {
t.Fatal("setupGitRepoInDir: empty dir would run git against the host checkout")
}
if info, err := os.Stat(dir); err != nil || !info.IsDir() {
t.Fatalf("setupGitRepoInDir: %q is not an existing directory (err=%v)", dir, err)
}
cmds := [][]string{
{"git", "init"},
{"git", "config", "user.email", "test@test.com"},
@ -211,11 +225,9 @@ func setupGitRepoInDir(t *testing.T, dir string) {
for _, args := range cmds {
cmd := exec.Command(args[0], args[1:]...)
cmd.Dir = dir
if err := cmd.Run(); err != nil {
// git init must succeed; config failures are non-fatal
if args[1] == "init" {
t.Fatalf("git init failed: %v", err)
}
cmd.Env = testutil.WithoutGitRepoLocationEnv(os.Environ())
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("%v failed: %v\n%s", args, err, out)
}
}
}

View file

@ -5,10 +5,11 @@ import (
"github.com/steveyegge/beads/internal/eventsjournal"
"github.com/steveyegge/beads/internal/storage/dolt"
"github.com/steveyegge/beads/internal/versionedhistory"
)
// openBeadMutatingStore opens a repair handler's store WITH the workspace's
// events-journal activation applied.
// events-journal and versioned-history activation applied.
//
// Most of bd doctor inspects and repairs workspace state — schema cursors,
// metadata, remotes, fingerprints, git — and none of that belongs in a journal
@ -17,7 +18,10 @@ import (
// fresh-clone import paths CREATE them. Those are ordinary bead mutations, and
// a consumer whose mirror silently diverges because someone ran
// `bd doctor --fix` is exactly the failure the journal exists to prevent — the
// more so because a repair is unattended and nobody is watching the diff.
// more so because a repair is unattended and nobody is watching the diff. The
// same repairs are also ordinary issue mutations for version history, and an
// issue_versions trail with a silent gap where `bd doctor --fix` ran is the same
// failure one table over.
//
// The read-only and workspace-state handlers deliberately keep opening the
// store directly; they carry their exemption in the construction guard, with a
@ -27,7 +31,7 @@ import (
// is what a repair path legitimately does.
func openBeadMutatingStore(ctx context.Context, beadsDir string) (*dolt.DoltStore, error) {
store, err := dolt.NewFromConfig(ctx, beadsDir)
return activated(beadsDir, store, err)
return activated(ctx, beadsDir, store, err)
}
// openBeadMutatingStoreCreating is openBeadMutatingStore for the fresh-clone
@ -36,15 +40,23 @@ func openBeadMutatingStore(ctx context.Context, beadsDir string) (*dolt.DoltStor
// guard rather than failing on an absent database.
func openBeadMutatingStoreCreating(ctx context.Context, beadsDir string) (*dolt.DoltStore, error) {
store, err := dolt.NewFromConfigWithOptions(ctx, beadsDir, &dolt.Config{CreateIfMissing: true})
return activated(beadsDir, store, err)
return activated(ctx, beadsDir, store, err)
}
// activated applies the workspace's journal setting and closes the store if it
// cannot be honored. A failed open passes straight through, so the typed-nil
// store never reaches the activation.
func activated(beadsDir string, store *dolt.DoltStore, err error) (*dolt.DoltStore, error) {
// activated applies the workspace's journal setting and the store's own
// versioned-history setting, and closes the store if the journal cannot be
// honored. A failed open passes straight through, so the typed-nil store never
// reaches the activation.
//
// Versioned history cannot fail an open (a plumbing that cannot version simply
// records nothing), so it needs no error handling of its own; it runs after the
// journal so a store the journal refused is never activated. It is the shared
// internal/versionedhistory rule, not a copy: package main cannot be imported
// from here.
func activated(ctx context.Context, beadsDir string, store *dolt.DoltStore, err error) (*dolt.DoltStore, error) {
if _, err = eventsjournal.ActivateStore(beadsDir, store, err); err != nil {
return nil, err
}
_, _ = versionedhistory.ActivateStore(ctx, store, nil)
return store, nil
}

View file

@ -21,6 +21,14 @@ func TestMain(m *testing.M) {
// exits — os.Exit skips deferred calls, so TestMain itself must never defer
// anything (be-5kkk6).
func testMainInner(m *testing.M) int {
// A GIT_DIR/GIT_WORK_TREE leaked in from the invoking shell or a git hook
// would route the fixture `git init`/`git config` writes in this suite
// into that repository: the host checkout in the r880 clobber (wy-qlvlmf).
if err := testutil.UnsetGitRepoLocationEnv(); err != nil {
fmt.Fprintf(os.Stderr, "FATAL: %v\n", err)
return 1
}
os.Setenv("BEADS_TEST_MODE", "1")
// AD-01 (be-c5p): allow doctor/fix tests through the dolt.New
// database-name firewall when they connect to the spawned test server.

View file

@ -19,6 +19,14 @@ func TestMain(m *testing.M) {
}
func testMainInner(m *testing.M) int {
// A GIT_DIR/GIT_WORK_TREE leaked in from the invoking shell or a git hook
// would route the fixture `git init`/`git config` writes in this suite
// into that repository: the host checkout in the r880 clobber (wy-qlvlmf).
if err := testutil.UnsetGitRepoLocationEnv(); err != nil {
fmt.Fprintf(os.Stderr, "FATAL: %v\n", err)
return 1
}
// Clear out the roots of earlier runs of this suite whose process is
// gone, before claiming one of our own. A `go test -timeout` panic skips
// every defer here AND the post-run sweep, so the servers such a run

View file

@ -0,0 +1,87 @@
package fix
import (
"go/ast"
"go/parser"
"go/token"
"strconv"
"strings"
"testing"
)
const (
versionedHistoryPkg = "github.com/steveyegge/beads/internal/versionedhistory"
// package main cannot be imported at all; the guard below is that the
// activation this package applies lives in a package it CAN import, so the
// repair handlers apply the identical rule as the command surface rather than
// a copy of it.
beadMutatingStoreFile = "store.go"
)
// TestVersionedHistoryDoctorRepairOpenerUsesTheSharedActivation holds the one
// construction site the cmd/bd construction guard cannot see. bd doctor is exempted
// from that guard as a package (its CHECKS are read-only), so the repair opener --
// which opens the store the bead-mutating repairs (stale-closed cleanup, pollution
// cleanup, the fresh-clone imports) write through -- is held to the property here.
//
// A repair that deletes or creates issues is an ordinary mutation for version
// history: an issue_versions trail with a silent gap where `bd doctor --fix` ran is
// the same failure the routed-write bug produced, one command over, and the more
// dangerous for being unattended.
//
// The check is structural for the same reason the cmd/bd guard is: activation
// failing is invisible from inside the process. It requires the activation that
// `activated` applies to come from internal/versionedhistory -- the ONE
// implementation of the rule, which this package can import and package main cannot
// be.
func TestVersionedHistoryDoctorRepairOpenerUsesTheSharedActivation(t *testing.T) {
fset := token.NewFileSet()
file, err := parser.ParseFile(fset, beadMutatingStoreFile, nil, 0)
if err != nil {
t.Fatalf("parse %s: %v", beadMutatingStoreFile, err)
}
imports := map[string]string{}
for _, spec := range file.Imports {
path, err := strconv.Unquote(spec.Path.Value)
if err != nil {
t.Fatalf("unquote import %s: %v", spec.Path.Value, err)
}
name := path[strings.LastIndex(path, "/")+1:]
if spec.Name != nil {
name = spec.Name.Name
}
imports[name] = path
}
var activated *ast.FuncDecl
for _, decl := range file.Decls {
if fn, ok := decl.(*ast.FuncDecl); ok && fn.Name.Name == "activated" {
activated = fn
}
}
if activated == nil {
t.Fatalf("%s has no `activated` function: the repair opener's activation moved and this guard no longer looks at it", beadMutatingStoreFile)
}
called := false
ast.Inspect(activated, func(n ast.Node) bool {
call, ok := n.(*ast.CallExpr)
if !ok {
return true
}
sel, ok := call.Fun.(*ast.SelectorExpr)
if !ok {
return true
}
if ident, ok := sel.X.(*ast.Ident); ok && imports[ident.Name] == versionedHistoryPkg && sel.Sel.Name == "ActivateStore" {
called = true
}
return true
})
if !called {
t.Errorf("`activated` in %s never calls versionedhistory.ActivateStore: every repair that mutates issues through it "+
"mints NO issue_versions row while `bd doctor --fix` reports success. Apply the shared activation there; "+
"it is the same rule as the command surface and package main cannot be imported to reuse it.", beadMutatingStoreFile)
}
}

View file

@ -30,8 +30,13 @@ func initGitTemplate() {
}
gitTemplateDir = dir
// The template is built once, inside whichever test asks first. Its
// writes must land in dir even if that test set GIT_DIR/GIT_WORK_TREE,
// or they hit that repository (the r880 clobber class, wy-qlvlmf).
env := testutil.WithoutGitRepoLocationEnv(os.Environ())
cmd := gitCommand("init", "--initial-branch=main")
cmd.Dir = dir
cmd.Env = env
if err := cmd.Run(); err != nil {
gitTemplateErr = fmt.Errorf("git init failed: %w", err)
return
@ -43,6 +48,7 @@ func initGitTemplate() {
} {
cmd = gitCommand(args...)
cmd.Dir = dir
cmd.Env = env
if err := cmd.Run(); err != nil {
gitTemplateErr = fmt.Errorf("git %v failed: %w", args, err)
return

View file

@ -5,6 +5,8 @@ import (
"path/filepath"
"strings"
"testing"
"github.com/steveyegge/beads/internal/testutil"
)
// setupGitRepo creates a temporary git repository for testing
@ -51,6 +53,15 @@ func TestCheckGitHooks(t *testing.T) {
// setupGitRepoInDir initializes a git repo in the given directory with .beads
func setupGitRepoInDir(t *testing.T, dir string) {
t.Helper()
if dir == "" {
// cmd.Dir = "" inherits the test process cwd — this checkout's own
// package dir — so the config write below would hit the host .git
// (the r880 clobber class, wy-qlvlmf).
t.Fatal("setupGitRepoInDir: empty dir would run git against the host checkout")
}
if info, err := os.Stat(dir); err != nil || !info.IsDir() {
t.Fatalf("setupGitRepoInDir: %q is not an existing directory (err=%v)", dir, err)
}
// Create .beads directory
beadsDir := filepath.Join(dir, ".beads")
@ -68,11 +79,14 @@ func setupGitRepoInDir(t *testing.T, dir string) {
}
// Force repo-local hooks path for test isolation. This prevents global
// core.hooksPath from affecting hook detection behavior in tests.
// core.hooksPath from affecting hook detection behavior in tests. The env
// scrub keeps a leaked GIT_DIR/GIT_WORK_TREE from routing the write at
// some other repository.
cmd := gitCommand("config", "core.hooksPath", ".git/hooks")
cmd.Dir = dir
if err := cmd.Run(); err != nil {
t.Fatalf("failed to set core.hooksPath for test repo: %v", err)
cmd.Env = testutil.WithoutGitRepoLocationEnv(os.Environ())
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("failed to set core.hooksPath for test repo: %v\n%s", err, out)
}
}

View file

@ -19,6 +19,14 @@ func TestMain(m *testing.M) {
}
func testMainInner(m *testing.M) int {
// A GIT_DIR/GIT_WORK_TREE leaked in from the invoking shell or a git hook
// would route the fixture `git init`/`git config` writes in this suite
// into that repository: the host checkout in the r880 clobber (wy-qlvlmf).
if err := testutil.UnsetGitRepoLocationEnv(); err != nil {
fmt.Fprintf(os.Stderr, "FATAL: %v\n", err)
return 1
}
// Clear out the roots of earlier runs of this suite whose process is
// gone, before claiming one of our own. A `go test -timeout` panic skips
// every defer here AND the post-run sweep, so the servers such a run

View file

@ -43,10 +43,10 @@ func runBDSplit(t *testing.T, bd, dir string, args ...string) (stdout, stderr st
return stdoutBuf.String(), stderrBuf.String(), err
}
// TestDoctorEmbeddedSupportedChecks verifies that --check=artifacts,
// TestEmbeddedDoctorSupportedChecks verifies that --check=artifacts,
// --check=conventions, and --check=pollution run in embedded mode rather
// than hitting the "not yet supported" stub (GH#3597).
func TestDoctorEmbeddedSupportedChecks(t *testing.T) {
func TestEmbeddedDoctorSupportedChecks(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}
@ -83,11 +83,11 @@ func TestDoctorEmbeddedSupportedChecks(t *testing.T) {
}
}
// TestDoctorEmbeddedUnsupportedJSON verifies that variants which still require
// TestEmbeddedDoctorUnsupportedJSON verifies that variants which still require
// server mode (bare doctor, --check=validate) emit a structured JSON payload
// when --json or --agent --json is set, rather than the prose stub. Tooling
// can detect "unsupported" without text-matching (GH#3597).
func TestDoctorEmbeddedUnsupportedJSON(t *testing.T) {
func TestEmbeddedDoctorUnsupportedJSON(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}
@ -150,10 +150,10 @@ func TestDoctorEmbeddedUnsupportedJSON(t *testing.T) {
}
}
// TestDoctorEmbeddedUnsupportedProse verifies that bare bd doctor (without
// TestEmbeddedDoctorUnsupportedProse verifies that bare bd doctor (without
// --json) still emits the human-readable prose stub for terminal users,
// pointing at the supported --check=* variants (GH#3597).
func TestDoctorEmbeddedUnsupportedProse(t *testing.T) {
func TestEmbeddedDoctorUnsupportedProse(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}

View file

@ -9,16 +9,28 @@
// beside the rest of the freeze suite; both halves share the helpers below and
// the hermetic subprocess harness declared there.
//
// The same gate for `bd backup init`, `backup remove`, `backup sync` and
// `bd import` sits further down, between the doctor tests it mirrors.
//
// This file MUST NOT carry a cgo build tag: it drives a bd binary built with
// the gms_pure_go tag via subprocess, and asserts only on files and output.
// the gms_pure_go tag via subprocess, and asserts on files and output (and, for
// the server rows of the backup/import tests, on the Dolt test server's tables).
package main
import (
"context"
"database/sql"
"encoding/json"
"fmt"
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"testing"
"github.com/steveyegge/beads/internal/storage/doltutil"
)
// doctorMutationSurface is one class of doctor invocation that mutates the
@ -122,6 +134,306 @@ func TestDoctorMutationBlockedInReadonlyMode(t *testing.T) {
}
}
// The backup and import commands: the same gate, a different failure.
//
// `bd backup init`, `backup remove`, `backup sync` and `bd import` never called
// CheckReadonly, so strict --readonly only held as far as the store underneath
// happened to refuse. An embedded store is opened read-only, so those commands
// failed, but with the storage layer's text rather than the standard refusal,
// and `backup sync` took the backup lock first and left .beads/backup.lock
// behind. A server-mode store has no such floor: the same commands ran to
// completion and rewrote or emptied the backup registry, wrote the backup
// destination, or imported issues. So every row runs in both flavours, and the
// checks go past the file tree: a server-mode import leaves .beads untouched
// even when it succeeds, so the issue count and the registry are compared too.
//
// `backup status` and `list` only read, and stay allowed;
// TestBackupStatusAndListWorkInReadonlyMode pins that. `bd backup` on its own is
// a command group that only prints help, and is left as it is.
// backupImportSurface is one command that strict --readonly must refuse.
type backupImportSurface struct {
name string
// args are the command and its arguments; the test appends the global flags.
args []string
// op is the operation label the gate reports.
op string
}
func backupImportSurfaces(w *readonlyGateWorkspace) []backupImportSurface {
return []backupImportSurface{
// A destination other than the registered one, so a run that goes
// through shows up as a changed registry.
{name: "backup-init", args: []string{"backup", "init", filepath.Join(w.dir, "other-backup-dest")}, op: "backup init"},
{name: "backup-remove", args: []string{"backup", "remove"}, op: "backup remove"},
{name: "backup-sync", args: []string{"backup", "sync"}, op: "backup sync"},
{name: "import", args: []string{"import", w.importFile}, op: "import"},
// A preview writes nothing, but strict --readonly already refuses
// `create --dry-run`, so import's is refused the same way.
{name: "import-dry-run", args: []string{"import", "--dry-run", w.importFile}, op: "import"},
}
}
// readonlyGateFlagSets are the global flag combinations every row runs under.
// --sandbox changes how bd treats the store (it disables auto-push); the gate
// has to hold with it as well.
var readonlyGateFlagSets = []struct {
name string
flags []string
}{
{name: "readonly", flags: []string{"--readonly"}},
{name: "readonly-sandbox", flags: []string{"--readonly", "--sandbox"}},
}
// readonlyGateFlavours are the two stores the gate has to hold over.
var readonlyGateFlavours = []struct {
name string
setup func(*testing.T) *readonlyGateWorkspace
}{
{name: "embedded", setup: newEmbeddedReadonlyGateWorkspace},
{name: "server", setup: newServerReadonlyGateWorkspace},
}
// readonlyGateWorkspace is an initialized workspace holding one issue and one
// registered backup, plus what a refused command has to leave alone.
type readonlyGateWorkspace struct {
bd, dir string
prefix string
dest string // directory behind the registered default backup
importFile string // a one-issue JSONL file for `bd import`
// Server flavour only: the shared test server and this workspace's database
// on it. A zero port means the embedded flavour.
port int
database string
}
// readonlyGateState is everything a refused command could have changed.
type readonlyGateState struct {
tree readonlyTreeSnapshot // the whole .beads directory
dest readonlyTreeSnapshot // the backup destination
issues int // what `bd list` reports
registry string // server flavour only: dolt_backups as name=url rows
}
func newEmbeddedReadonlyGateWorkspace(t *testing.T) *readonlyGateWorkspace {
t.Helper()
bd, dir := setupMigrationFreezeWorkspace(t)
w := &readonlyGateWorkspace{bd: bd, dir: dir, prefix: "test"}
w.seed(t)
return w
}
// newServerReadonlyGateWorkspace is the same workspace on the shared Dolt test
// server. The default lane starts none, so it skips there, as the other
// server-mode readonly test in this package does.
func newServerReadonlyGateWorkspace(t *testing.T) *readonlyGateWorkspace {
t.Helper()
port, err := strconv.Atoi(os.Getenv("BEADS_DOLT_PORT"))
if err != nil || port <= 0 {
t.Skip("shared Dolt test server is unavailable")
}
dir := t.TempDir()
bd := buildBDForInitTests(t)
runGitForBootstrapTest(t, dir, "init", "-q")
runGitForBootstrapTest(t, dir, "config", "core.hooksPath", ".git/hooks")
// The prefix names the database on the shared server, so it must be unique.
prefix := "rog" + strings.TrimPrefix(uniqueTestDBName(t), "testdb_")
stdout, stderr, code := runBDMigrationFreeze(t, bd, dir, "init", "--server", "--server-host", "127.0.0.1",
"--server-port", strconv.Itoa(port), "--external", "--prefix", prefix,
"--quiet", "--non-interactive", "--skip-hooks", "--skip-agents")
if code != 0 {
t.Fatalf("bd init --server failed (exit %d):\nstdout:\n%s\nstderr:\n%s", code, stdout, stderr)
}
var meta struct {
Database string `json:"dolt_database"`
}
data, err := os.ReadFile(filepath.Join(dir, ".beads", "metadata.json"))
if err != nil {
t.Fatalf("reading metadata.json: %v", err)
}
if err := json.Unmarshal(data, &meta); err != nil || meta.Database == "" {
t.Fatalf("metadata.json names no dolt_database (%v):\n%s", err, data)
}
t.Cleanup(func() {
db, err := sql.Open("mysql", doltutil.ServerDSN{Host: "127.0.0.1", Port: port, User: "root"}.String())
if err != nil {
return
}
defer db.Close()
_, _ = db.ExecContext(context.Background(), fmt.Sprintf("DROP DATABASE IF EXISTS `%s`", meta.Database)) //nolint:gosec // generated test name
})
w := &readonlyGateWorkspace{bd: bd, dir: dir, prefix: prefix, port: port, database: meta.Database}
w.seed(t)
return w
}
// seed gives the workspace one issue, one registered backup and a JSONL file
// whose single issue is not in the workspace yet.
func (w *readonlyGateWorkspace) seed(t *testing.T) {
t.Helper()
w.dest = filepath.Join(w.dir, "backup-dest")
w.importFile = filepath.Join(w.dir, "import.jsonl")
record := fmt.Sprintf(`{"id":"%s-gate1","title":"imported under readonly","status":"open","priority":2,"issue_type":"task","created_at":"2026-01-01T00:00:00Z"}`+"\n", w.prefix)
if err := os.WriteFile(w.importFile, []byte(record), 0o644); err != nil {
t.Fatalf("writing %s: %v", w.importFile, err)
}
if stdout, stderr, code := w.run(t, "create", "seed issue", "-p", "2"); code != 0 {
t.Fatalf("bd create failed (exit %d):\nstdout:\n%s\nstderr:\n%s", code, stdout, stderr)
}
w.registerBackup(t)
}
func (w *readonlyGateWorkspace) run(t *testing.T, args ...string) (stdout, stderr string, exitCode int) {
t.Helper()
return runBDMigrationFreeze(t, w.bd, w.dir, args...)
}
// registerBackup points the default backup at w.dest. Rows call it before each
// run: a row that went through when it should have been refused may have moved
// or removed the backup, and the next row still needs one to be refused against.
func (w *readonlyGateWorkspace) registerBackup(t *testing.T) {
t.Helper()
if stdout, stderr, code := w.run(t, "backup", "init", "file://"+w.dest); code != 0 {
t.Fatalf("bd backup init failed (exit %d):\nstdout:\n%s\nstderr:\n%s", code, stdout, stderr)
}
}
func (w *readonlyGateWorkspace) state(t *testing.T) readonlyGateState {
t.Helper()
// Count the issues first: that is itself a strict --readonly read, so
// anything it creates lazily exists before the snapshot instead of showing
// up in it as a change.
s := readonlyGateState{issues: w.issueCount(t)}
s.tree = snapshotReadonlyTree(t, filepath.Join(w.dir, ".beads"))
s.dest = snapshotReadonlyTree(t, w.dest)
if w.port != 0 {
s.registry = w.backupRegistry(t)
}
return s
}
func (w *readonlyGateWorkspace) issueCount(t *testing.T) int {
t.Helper()
stdout, stderr, code := w.run(t, "list", "--json", "--readonly")
if code != 0 {
t.Fatalf("bd list failed (exit %d):\nstdout:\n%s\nstderr:\n%s", code, stdout, stderr)
}
var issues []json.RawMessage
if err := json.Unmarshal([]byte(stdout), &issues); err != nil {
t.Fatalf("bd list --json is not a JSON array: %v\n%s", err, stdout)
}
return len(issues)
}
// backupRegistry reads the backups the server has registered for this
// workspace's database. No bd command prints them, and the file tree never
// shows them, so a refused run is checked against the server itself.
func (w *readonlyGateWorkspace) backupRegistry(t *testing.T) string {
t.Helper()
db, err := sql.Open("mysql", doltutil.ServerDSN{Host: "127.0.0.1", Port: w.port, User: "root", Database: w.database}.String())
if err != nil {
t.Fatalf("connecting to the test server: %v", err)
}
defer db.Close()
rows, err := db.QueryContext(context.Background(), "SELECT name, url FROM dolt_backups ORDER BY name")
if err != nil {
t.Fatalf("reading dolt_backups: %v", err)
}
defer rows.Close()
var lines []string
for rows.Next() {
var name, url string
if err := rows.Scan(&name, &url); err != nil {
t.Fatalf("scanning dolt_backups: %v", err)
}
lines = append(lines, name+"="+url)
}
if err := rows.Err(); err != nil {
t.Fatalf("reading dolt_backups: %v", err)
}
return strings.Join(lines, "\n")
}
// assertUnchanged proves a refusal happened before any mutation, not merely
// that the refusal text was printed.
func (w *readonlyGateWorkspace) assertUnchanged(t *testing.T, before readonlyGateState) {
t.Helper()
after := w.state(t)
if diff := readonlyTreeDiff(before.tree, after.tree); len(diff) > 0 {
t.Errorf("a refused run changed .beads:\n %s", strings.Join(diff, "\n "))
}
if diff := readonlyTreeDiff(before.dest, after.dest); len(diff) > 0 {
t.Errorf("a refused run changed the backup destination:\n %s", strings.Join(diff, "\n "))
}
if after.issues != before.issues {
t.Errorf("a refused run changed the issue count: %d -> %d", before.issues, after.issues)
}
if after.registry != before.registry {
t.Errorf("a refused run changed the backup registry:\nbefore:\n%s\nafter:\n%s", before.registry, after.registry)
}
}
// readonlyTreeDiff names what differs between two snapshots, so a leaked
// mutation reads as "+ backup.lock" rather than as two opaque hash maps.
func readonlyTreeDiff(before, after readonlyTreeSnapshot) []string {
var diff []string
if before.Exists != after.Exists {
diff = append(diff, fmt.Sprintf("exists: %t -> %t", before.Exists, after.Exists))
}
for path, was := range before.Entries {
if now, ok := after.Entries[path]; !ok {
diff = append(diff, "- "+path)
} else if now != was {
diff = append(diff, "~ "+path)
}
}
for path := range after.Entries {
if _, ok := before.Entries[path]; !ok {
diff = append(diff, "+ "+path)
}
}
sort.Strings(diff)
return diff
}
// TestBackupAndImportBlockedInReadonlyMode is the readonly gate for the backup
// and import commands. One workspace per flavour serves every row; each row
// re-registers the backup first, so none depends on what the previous one did.
func TestBackupAndImportBlockedInReadonlyMode(t *testing.T) {
for _, flavour := range readonlyGateFlavours {
t.Run(flavour.name, func(t *testing.T) {
w := flavour.setup(t)
for _, tt := range backupImportSurfaces(w) {
t.Run(tt.name, func(t *testing.T) {
for _, flagSet := range readonlyGateFlagSets {
t.Run(flagSet.name, func(t *testing.T) {
w.registerBackup(t)
before := w.state(t)
args := append(append([]string{}, tt.args...), flagSet.flags...)
stdout, stderr, code := w.run(t, args...)
want := "Error: operation '" + tt.op + "' is not allowed in read-only mode\n"
if code != 1 {
t.Errorf("exit code = %d, want 1\nstdout:\n%s\nstderr:\n%s", code, stdout, stderr)
}
if stderr != want {
t.Errorf("stderr is not exactly the standard refusal\ngot: %q\nwant: %q", stderr, want)
}
if stdout != "" {
t.Errorf("stdout should be empty when the command is refused, got:\n%s", stdout)
}
w.assertUnchanged(t, before)
})
}
})
}
})
}
}
// TestDoctorDiagnosisWorksInReadonlyMode pins the other half of the contract:
// the gate keys on --fix/--clean alone, so every diagnosis mode still runs
// under --readonly. Diagnosing a sandboxed workspace is the whole point.
@ -143,6 +455,25 @@ func TestDoctorDiagnosisWorksInReadonlyMode(t *testing.T) {
}
}
// TestBackupStatusAndListWorkInReadonlyMode is the control for the backup and
// import gate: it keys on the commands that write, so `backup status` and
// `list` still run under --readonly, in both flavours.
func TestBackupStatusAndListWorkInReadonlyMode(t *testing.T) {
for _, flavour := range readonlyGateFlavours {
t.Run(flavour.name, func(t *testing.T) {
w := flavour.setup(t)
for _, args := range [][]string{{"backup", "status"}, {"list"}} {
t.Run(strings.Join(args, "_"), func(t *testing.T) {
stdout, stderr, code := w.run(t, append(append([]string{}, args...), "--readonly")...)
if code != 0 || strings.Contains(stderr, "not allowed in read-only mode") {
t.Errorf("bd %v under --readonly should run (exit %d):\nstdout:\n%s\nstderr:\n%s", args, code, stdout, stderr)
}
})
}
})
}
}
// TestDoctorMaintenanceSkippedInReadonlyMode is the readonly twin of
// TestDoctorMaintenanceSkippedDuringMigrationFreeze — see that test for why
// plain `bd doctor` had hidden writes at all, and for the shared-server setup.

View file

@ -1124,6 +1124,11 @@ is shown as not running, and the next bd command launches it.`,
if beadsDir == "" {
return HandleErrorWithHint(activeWorkspaceNotFoundError(), diagHint())
}
// A workspace in a format this build cannot open is refused before
// configfile.Load, which would first migrate a legacy config.json.
if err := checkDiscoveredWorkspaceFormat(beadsDir); err != nil {
return handleWorkspaceGuardError(err)
}
cfg, cfgErr := configfile.Load(beadsDir)
if cfgErr != nil {
return HandleError("loading config: %v", cfgErr)
@ -2004,6 +2009,11 @@ func showDoltConfig(testConnection bool) error {
return HandleErrorWithHint(activeWorkspaceNotFoundError(), diagHint())
}
// A workspace in a format this build cannot open is refused before
// configfile.Load, which would first migrate a legacy config.json.
if err := checkDiscoveredWorkspaceFormat(beadsDir); err != nil {
return handleWorkspaceGuardError(err)
}
cfg, err := configfile.Load(beadsDir)
if err != nil {
return HandleError("loading config: %v", err)

View file

@ -41,7 +41,7 @@ func bdDoltSeparate(t *testing.T, bd, dir string, args ...string) (string, strin
// -- push --
func TestDoltLocalOnly_Push_ExitsZeroWithMessage(t *testing.T) {
func TestEmbeddedDoltLocalOnly_Push_ExitsZeroWithMessage(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run dolt.local-only embedded tests")
}
@ -62,7 +62,7 @@ func TestDoltLocalOnly_Push_ExitsZeroWithMessage(t *testing.T) {
}
}
func TestDoltLocalOnly_Push_LocalStoreCopy(t *testing.T) {
func TestEmbeddedDoltLocalOnly_Push_LocalStoreCopy(t *testing.T) {
// The push no-op message must include the "Your issues are stored locally" line.
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run dolt.local-only embedded tests")
@ -77,7 +77,7 @@ func TestDoltLocalOnly_Push_LocalStoreCopy(t *testing.T) {
}
}
func TestDoltLocalOnly_Push_JSON_DisabledStatus(t *testing.T) {
func TestEmbeddedDoltLocalOnly_Push_JSON_DisabledStatus(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run dolt.local-only embedded tests")
}
@ -101,7 +101,7 @@ func TestDoltLocalOnly_Push_JSON_DisabledStatus(t *testing.T) {
// -- pull --
func TestDoltLocalOnly_Pull_ExitsZeroWithMessage(t *testing.T) {
func TestEmbeddedDoltLocalOnly_Pull_ExitsZeroWithMessage(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run dolt.local-only embedded tests")
}
@ -122,7 +122,7 @@ func TestDoltLocalOnly_Pull_ExitsZeroWithMessage(t *testing.T) {
}
}
func TestDoltLocalOnly_Pull_JSON_DisabledStatus(t *testing.T) {
func TestEmbeddedDoltLocalOnly_Pull_JSON_DisabledStatus(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run dolt.local-only embedded tests")
}
@ -146,7 +146,7 @@ func TestDoltLocalOnly_Pull_JSON_DisabledStatus(t *testing.T) {
// -- remote add --
func TestDoltLocalOnly_RemoteAdd_RefusesExitOne(t *testing.T) {
func TestEmbeddedDoltLocalOnly_RemoteAdd_RefusesExitOne(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run dolt.local-only embedded tests")
}
@ -169,7 +169,7 @@ func TestDoltLocalOnly_RemoteAdd_RefusesExitOne(t *testing.T) {
}
}
func TestDoltLocalOnly_RemoteAdd_ErrorOnStderr(t *testing.T) {
func TestEmbeddedDoltLocalOnly_RemoteAdd_ErrorOnStderr(t *testing.T) {
// The refusal must go to stderr (not stdout) so agents can distinguish errors.
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run dolt.local-only embedded tests")
@ -189,7 +189,7 @@ func TestDoltLocalOnly_RemoteAdd_ErrorOnStderr(t *testing.T) {
// -- config round-trip --
func TestDoltLocalOnly_ConfigRoundTrip(t *testing.T) {
func TestEmbeddedDoltLocalOnly_ConfigRoundTrip(t *testing.T) {
// bd config set dolt.local-only true / unset must persist via config.yaml.
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run dolt.local-only embedded tests")
@ -215,7 +215,7 @@ func TestDoltLocalOnly_ConfigRoundTrip(t *testing.T) {
// -- bd dolt status --
func TestDoltLocalOnly_DoltStatus_ShowsDisabled(t *testing.T) {
func TestEmbeddedDoltLocalOnly_DoltStatus_ShowsDisabled(t *testing.T) {
// When dolt.local-only=true, bd dolt status must include the indicator line.
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run dolt.local-only embedded tests")

View file

@ -1,21 +1,19 @@
//go:build embeddeddolt && cgo
//go:build cgo
package main
import (
"bytes"
"encoding/json"
"os"
"os/exec"
"strings"
"testing"
)
// Integration tests for be-7eu1d: git-origin collision guard in bd dolt remote
// add and bd doctor (FR-06 to FR-09).
//
// TDD gate tests — these fail before the implementation exists. Run with
// BEADS_TEST_EMBEDDED_DOLT=1.
// Integration tests for be-7eu1d's git-origin collision guard in bd dolt
// remote add (FR-06, FR-07). Its bd doctor half (FR-08, FR-09:
// doctor.CheckDoltRemoteGitOrigin) is server-mode only: bd doctor runs none of
// its checks on an embedded workspace (GH#3794), so it cannot be driven here.
// remoteAdd runs "bd dolt remote add <args>" returning (stdout, stderr, error)
// with separate buffers. Delegates to bdDoltSeparate (dolt_local_only_embedded_test.go).
@ -34,25 +32,11 @@ func setGitOrigin(t *testing.T, dir, url string) {
}
}
// bdDoctorSeparate runs "bd doctor <args>" returning (stdout, stderr, error).
func bdDoctorSeparate(t *testing.T, bd, dir string, args ...string) (string, string, error) {
t.Helper()
fullArgs := append([]string{"doctor"}, args...)
cmd := exec.Command(bd, fullArgs...)
cmd.Dir = dir
cmd.Env = bdEnv(dir)
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
return stdout.String(), stderr.String(), err
}
// -- bd dolt remote add: collision with git origin --
// TestDoltRemoteAdd_GitOriginCollision_Exits1 asserts that adding a Dolt remote
// TestEmbeddedDoltRemoteAdd_GitOriginCollision_Exits1 asserts that adding a Dolt remote
// whose URL matches the git origin exits non-zero and prints the refusal message.
func TestDoltRemoteAdd_GitOriginCollision_Exits1(t *testing.T) {
func TestEmbeddedDoltRemoteAdd_GitOriginCollision_Exits1(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded integration tests")
}
@ -75,9 +59,9 @@ func TestDoltRemoteAdd_GitOriginCollision_Exits1(t *testing.T) {
}
}
// TestDoltRemoteAdd_GitOriginCollision_RefusalMessageCopy verifies exact phrases
// TestEmbeddedDoltRemoteAdd_GitOriginCollision_RefusalMessageCopy verifies exact phrases
// from the UX spec (be-fxwbm §2.1) appear in the refusal output.
func TestDoltRemoteAdd_GitOriginCollision_RefusalMessageCopy(t *testing.T) {
func TestEmbeddedDoltRemoteAdd_GitOriginCollision_RefusalMessageCopy(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded integration tests")
}
@ -103,9 +87,9 @@ func TestDoltRemoteAdd_GitOriginCollision_RefusalMessageCopy(t *testing.T) {
}
}
// TestDoltRemoteAdd_AllowGitOrigin_Exits0 asserts that --allow-git-origin
// TestEmbeddedDoltRemoteAdd_AllowGitOrigin_Exits0 asserts that --allow-git-origin
// bypasses the collision guard and exits 0.
func TestDoltRemoteAdd_AllowGitOrigin_Exits0(t *testing.T) {
func TestEmbeddedDoltRemoteAdd_AllowGitOrigin_Exits0(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded integration tests")
}
@ -122,9 +106,9 @@ func TestDoltRemoteAdd_AllowGitOrigin_Exits0(t *testing.T) {
}
}
// TestDoltRemoteAdd_AllowGitOrigin_WarningOnStderr asserts the one-liner warning
// TestEmbeddedDoltRemoteAdd_AllowGitOrigin_WarningOnStderr asserts the one-liner warning
// from be-fxwbm §2.2 appears on stderr when --allow-git-origin is set.
func TestDoltRemoteAdd_AllowGitOrigin_WarningOnStderr(t *testing.T) {
func TestEmbeddedDoltRemoteAdd_AllowGitOrigin_WarningOnStderr(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded integration tests")
}
@ -146,9 +130,9 @@ func TestDoltRemoteAdd_AllowGitOrigin_WarningOnStderr(t *testing.T) {
}
}
// TestDoltRemoteAdd_NoGitOrigin_ProceedsNormally asserts no refusal fires when
// TestEmbeddedDoltRemoteAdd_NoGitOrigin_ProceedsNormally asserts no refusal fires when
// the git repo has no 'origin' remote.
func TestDoltRemoteAdd_NoGitOrigin_ProceedsNormally(t *testing.T) {
func TestEmbeddedDoltRemoteAdd_NoGitOrigin_ProceedsNormally(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded integration tests")
}
@ -167,9 +151,9 @@ func TestDoltRemoteAdd_NoGitOrigin_ProceedsNormally(t *testing.T) {
}
}
// TestDoltRemoteAdd_DifferentURL_ProceedsNormally asserts the guard does not
// TestEmbeddedDoltRemoteAdd_DifferentURL_ProceedsNormally asserts the guard does not
// fire when the Dolt remote URL is different from the git origin.
func TestDoltRemoteAdd_DifferentURL_ProceedsNormally(t *testing.T) {
func TestEmbeddedDoltRemoteAdd_DifferentURL_ProceedsNormally(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded integration tests")
}
@ -190,10 +174,10 @@ func TestDoltRemoteAdd_DifferentURL_ProceedsNormally(t *testing.T) {
}
}
// TestDoltRemoteAdd_LocalOnly_FiresBeforeGuard verifies that when
// TestEmbeddedDoltRemoteAdd_LocalOnly_FiresBeforeGuard verifies that when
// dolt.local-only=true is set, the local-only refusal fires before the
// git-origin guard — the local-only guard takes priority (be-3v2ou ordering).
func TestDoltRemoteAdd_LocalOnly_FiresBeforeGuard(t *testing.T) {
func TestEmbeddedDoltRemoteAdd_LocalOnly_FiresBeforeGuard(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded integration tests")
}
@ -218,130 +202,9 @@ func TestDoltRemoteAdd_LocalOnly_FiresBeforeGuard(t *testing.T) {
}
}
// -- bd doctor: Dolt remote matches git origin --
// TestDoctor_DoltRemoteMatchesGitOrigin_Warning verifies that bd doctor emits a
// warning when a Dolt remote URL matches the git origin.
func TestDoctor_DoltRemoteMatchesGitOrigin_Warning(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded integration tests")
}
t.Parallel()
bd := buildEmbeddedBD(t)
dir, _, _ := bdInit(t, bd, "--prefix", "dw")
originURL := "file:///tmp/origin-collision-for-doctor"
setGitOrigin(t, dir, originURL)
// Add a Dolt remote that matches the git origin (using --allow-git-origin to bypass the guard).
bdDolt(t, bd, dir, "remote", "add", "--allow-git-origin", "origin", originURL)
stdout, _, _ := bdDoctorSeparate(t, bd, dir)
combined := stdout
// Doctor must surface the warning check.
if !strings.Contains(combined, "warning") && !strings.Contains(combined, "Warning") {
t.Errorf("bd doctor: expected warning when Dolt remote matches git origin\noutput:\n%s", combined)
}
if !strings.Contains(combined, "git origin") {
t.Errorf("bd doctor: expected 'git origin' in warning output\noutput:\n%s", combined)
}
}
// TestDoctor_DoltRemoteNoMatch_OK verifies that bd doctor does NOT emit a
// git-origin warning when the Dolt remote URL differs from the git origin.
func TestDoctor_DoltRemoteNoMatch_OK(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded integration tests")
}
t.Parallel()
bd := buildEmbeddedBD(t)
dir, _, _ := bdInit(t, bd, "--prefix", "dn")
setGitOrigin(t, dir, "https://github.com/org/repo.git")
remoteDir := t.TempDir()
bdDolt(t, bd, dir, "remote", "add", "dolt-origin", "file://"+remoteDir)
stdout, _, _ := bdDoctorSeparate(t, bd, dir)
if strings.Contains(stdout, "Dolt remote matches git origin") {
t.Errorf("bd doctor: unexpected git-origin warning when URLs differ\noutput:\n%s", stdout)
}
}
// TestDoctor_NoGitOrigin_OK verifies that bd doctor shows OK for the git-origin
// check when no git origin is configured.
func TestDoctor_NoGitOrigin_OK(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded integration tests")
}
t.Parallel()
bd := buildEmbeddedBD(t)
dir, _, _ := bdInit(t, bd, "--prefix", "ng")
// bdInit creates a git repo but no origin.
remoteDir := t.TempDir()
bdDolt(t, bd, dir, "remote", "add", "dolt-origin", "file://"+remoteDir)
stdout, _, _ := bdDoctorSeparate(t, bd, dir)
// Should not emit a warning for the git-origin check.
if strings.Contains(stdout, "Dolt remote matches git origin") {
t.Errorf("bd doctor: unexpected git-origin warning when no git origin\noutput:\n%s", stdout)
}
}
// TestDoctor_JSON_DoltRemoteMatchesGitOrigin_Warning verifies that
// bd doctor --json exposes the git-origin warning check with "status":"warning".
func TestDoctor_JSON_DoltRemoteMatchesGitOrigin_Warning(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded integration tests")
}
t.Parallel()
bd := buildEmbeddedBD(t)
dir, _, _ := bdInit(t, bd, "--prefix", "dj")
originURL := "file:///tmp/origin-collision-for-json"
setGitOrigin(t, dir, originURL)
bdDolt(t, bd, dir, "remote", "add", "--allow-git-origin", "origin", originURL)
stdout, _, _ := bdDoctorSeparate(t, bd, dir, "--json")
// Output should be JSON array of checks.
var checks []map[string]interface{}
if err := json.Unmarshal([]byte(strings.TrimSpace(stdout)), &checks); err != nil {
// May be wrapped in an outer object — try extracting the checks array.
var outer map[string]interface{}
if jsonErr := json.Unmarshal([]byte(strings.TrimSpace(stdout)), &outer); jsonErr != nil {
t.Fatalf("bd doctor --json: not valid JSON: %v\noutput:\n%s", err, stdout)
}
if arr, ok := outer["checks"].([]interface{}); ok {
data, _ := json.Marshal(arr)
_ = json.Unmarshal(data, &checks)
}
}
found := false
for _, check := range checks {
name, _ := check["name"].(string)
if strings.Contains(name, "git origin") || strings.Contains(name, "Dolt remote") {
found = true
status, _ := check["status"].(string)
if status != "warning" {
t.Errorf("doctor JSON check %q: status = %q, want \"warning\"", name, status)
}
if _, hasFix := check["fix"]; !hasFix {
t.Errorf("doctor JSON check %q: missing \"fix\" field", name)
}
break
}
}
if !found {
t.Errorf("bd doctor --json: no git-origin check found in output\noutput:\n%s", stdout)
}
}
// TestDoltRemoteAdd_JSON_AllowGitOrigin_WarningOnStderr asserts that even in
// TestEmbeddedDoltRemoteAdd_JSON_AllowGitOrigin_WarningOnStderr asserts that even in
// --json mode, the override warning still appears on stderr (not stdout).
func TestDoltRemoteAdd_JSON_AllowGitOrigin_WarningOnStderr(t *testing.T) {
func TestEmbeddedDoltRemoteAdd_JSON_AllowGitOrigin_WarningOnStderr(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded integration tests")
}

View file

@ -56,7 +56,7 @@ func lsRemoteRef(t *testing.T, remoteDir, ref string) string {
return fields[0]
}
func TestDoltRemoteResetData_GitBacked(t *testing.T) {
func TestEmbeddedDoltRemoteResetData_GitBacked(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded integration tests")
}
@ -112,7 +112,7 @@ func TestDoltRemoteResetData_GitBacked(t *testing.T) {
}
}
func TestDoltRemoteResetData_UnknownRemote(t *testing.T) {
func TestEmbeddedDoltRemoteResetData_UnknownRemote(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded integration tests")
}
@ -129,7 +129,7 @@ func TestDoltRemoteResetData_UnknownRemote(t *testing.T) {
}
}
func TestDoltRemoteResetData_CloudRemoteRefused(t *testing.T) {
func TestEmbeddedDoltRemoteResetData_CloudRemoteRefused(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded integration tests")
}

View file

@ -13,7 +13,7 @@ import (
"github.com/steveyegge/beads/internal/storage"
)
// TestAutoPruneBoundsTheJournalAfterAMutatingCommand is the feature as a user
// TestEmbeddedAutoPruneBoundsTheJournalAfterAMutatingCommand is the feature as a user
// meets it: enable the journal, write, and the journal stays inside its floors
// without anyone running `bd events prune`.
//
@ -30,7 +30,7 @@ import (
// because the throttle's persisted watermark is never stamped while auto-prune
// is off, so the next command with it on is the first pass this workspace has
// ever run.
func TestAutoPruneBoundsTheJournalAfterAMutatingCommand(t *testing.T) {
func TestEmbeddedAutoPruneBoundsTheJournalAfterAMutatingCommand(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}
@ -117,12 +117,12 @@ func TestAutoPruneBoundsTheJournalAfterAMutatingCommand(t *testing.T) {
}
}
// TestAutoPruneLeavesAnUnboundedJournalAlone. Both floors at 0 is the documented
// TestEmbeddedAutoPruneLeavesAnUnboundedJournalAlone. Both floors at 0 is the documented
// way to keep every record, and it is also the configuration the truncation
// tests run under — so a maintenance pass that ignored it would quietly delete
// the history those tests (and any consumer that chose an unbounded ledger)
// depend on.
func TestAutoPruneLeavesAnUnboundedJournalAlone(t *testing.T) {
func TestEmbeddedAutoPruneLeavesAnUnboundedJournalAlone(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}
@ -158,7 +158,7 @@ func TestAutoPruneLeavesAnUnboundedJournalAlone(t *testing.T) {
}
}
// TestAutoPruneRespectsBdConfigSet drives the whole retention story through
// TestEmbeddedAutoPruneRespectsBdConfigSet drives the whole retention story through
// `bd config set` rather than the environment.
//
// The four events-journal keys are startup settings read through viper before
@ -167,7 +167,7 @@ func TestAutoPruneLeavesAnUnboundedJournalAlone(t *testing.T) {
// `bd config set events-journal true` reported success and changed nothing.
// A new key is one YamlOnlyKeys entry away from repeating it, and the symptom
// is invisible: retention that silently keeps whatever the default was.
func TestAutoPruneRespectsBdConfigSet(t *testing.T) {
func TestEmbeddedAutoPruneRespectsBdConfigSet(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}
@ -221,7 +221,7 @@ func TestAutoPruneRespectsBdConfigSet(t *testing.T) {
}
}
// TestAutoPruneDoesNotRunForReadOnlyCommands. The trigger is writer-pays, and
// TestEmbeddedAutoPruneDoesNotRunForReadOnlyCommands. The trigger is writer-pays, and
// three separate gates keep it that way — each one covered here by a command
// that would prune the journal without it:
//
@ -236,7 +236,7 @@ func TestAutoPruneRespectsBdConfigSet(t *testing.T) {
// - `bd migrate --dry-run` is a PREVIEW. It promised not to mutate and holds
// a write-refusing store; maintenance must not be the one write it
// performs.
func TestAutoPruneDoesNotRunForReadOnlyCommands(t *testing.T) {
func TestEmbeddedAutoPruneDoesNotRunForReadOnlyCommands(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}

View file

@ -34,7 +34,7 @@ func runBDOut(t *testing.T, bd, dir string, env []string, args ...string) (strin
return stdout.String(), stderr.String()
}
// TestDeleteJournalsTheRequestingActor is #5985's repro, verbatim: create two
// TestEmbeddedDeleteJournalsTheRequestingActor is #5985's repro, verbatim: create two
// beads with an edge between them, delete the blocker with an explicit --actor,
// and read the journal back. Both the delete record and the cascade dep_remove
// record must name that actor.
@ -42,7 +42,7 @@ func runBDOut(t *testing.T, bd, dir string, env []string, args ...string) (strin
// The whole route is exercised — cobra flag to journal column — because the
// actor is resolved, threaded through the role, and written by the storage
// seam, and a unit test at any one of those cannot see the drop at the next.
func TestDeleteJournalsTheRequestingActor(t *testing.T) {
func TestEmbeddedDeleteJournalsTheRequestingActor(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}
@ -92,13 +92,13 @@ func TestDeleteJournalsTheRequestingActor(t *testing.T) {
}
}
// TestEventsReadNoticesADisabledJournal pins the "nothing to read and no way to
// TestEmbeddedEventsReadNoticesADisabledJournal pins the "nothing to read and no way to
// tell why" fix. A workspace that never enabled the journal serves an empty
// export forever, which a consumer cannot distinguish from being caught up, so
// the read says so on stderr — and keeps stdout clean and the exit status zero,
// because exporting a historical ledger from a now-disabled workspace is
// legitimate.
func TestEventsReadNoticesADisabledJournal(t *testing.T) {
func TestEmbeddedEventsReadNoticesADisabledJournal(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}

View file

@ -118,7 +118,7 @@ func eventsJournalMaintenanceRunnerFor(plumbing any) issueops.EventsMaintenanceR
// with OpenForReadOnlyCommand, which is "otherwise a normal writable
// store", so nothing underneath refuses a maintenance delete. Drop this
// check and `bd list` prunes the journal — which
// TestAutoPruneDoesNotRunForReadOnlyCommands catches.
// TestEmbeddedAutoPruneDoesNotRunForReadOnlyCommands catches.
//
// Two more gates are specific to this trigger:
//

View file

@ -57,7 +57,7 @@ func TestProxiedServerServeActivatesTheEventsJournal(t *testing.T) {
}
}
// TestRoutedCreateJournalsIntoTheTargetWorkspace covers the cross-workspace
// TestEmbeddedRoutedCreateJournalsIntoTheTargetWorkspace covers the cross-workspace
// store: `bd create --repo <other>` opens a SECOND store for another workspace
// and writes the bead there.
//
@ -65,7 +65,7 @@ func TestProxiedServerServeActivatesTheEventsJournal(t *testing.T) {
// TARGET's own config.yaml, so a workspace that enabled the journal gets its
// mutations recorded no matter which directory bd was launched from — and the
// launching workspace, which enabled nothing, records nothing of its own.
func TestRoutedCreateJournalsIntoTheTargetWorkspace(t *testing.T) {
func TestEmbeddedRoutedCreateJournalsIntoTheTargetWorkspace(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}
@ -120,13 +120,13 @@ func TestRoutedCreateJournalsIntoTheTargetWorkspace(t *testing.T) {
}
}
// TestRoutedCreateHonorsTheEnvOverrideOverTheTargetsConfig is the precedence
// TestEmbeddedRoutedCreateHonorsTheEnvOverrideOverTheTargetsConfig is the precedence
// half. BD_EVENTS_JOURNAL is the documented way to turn the journal on for a
// process without editing a workspace, and a routed write is exactly where an
// operator reaches for it — so a target whose config.yaml says false must not
// be able to veto it. Getting this backwards makes the env var a suggestion,
// and the operator finds out by discovering an empty journal later.
func TestRoutedCreateHonorsTheEnvOverrideOverTheTargetsConfig(t *testing.T) {
func TestEmbeddedRoutedCreateHonorsTheEnvOverrideOverTheTargetsConfig(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}

View file

@ -89,15 +89,21 @@ var qualifiedActivationCalls = map[string]map[string]bool{
// scannedPackages are the directories searched for construction sites: every
// package that builds a store or provider for the bd binary, plus the standalone
// embedded-Dolt utility so it is accounted for rather than merely unnoticed.
// Each maps to the prefix its sites are keyed under.
// embedded-Dolt utility and the Go SDK's own opens (the repository root), so they
// are accounted for rather than merely unnoticed. Each maps to the prefix its
// sites are keyed under.
var scannedPackages = map[string]string{
".": "",
"doctor": "doctor/",
"doctor/fix": "doctor/fix/",
"../../internal/storage/embeddeddolt/cmd": "embeddeddolt-cmd/",
"../..": "sdk/",
}
// sdkOpenExemptionReason is the one reason the Go SDK's five opens share. It has
// to be true of both per-store switches, because the exemption list is shared.
const sdkOpenExemptionReason = "SDK entry point (library surface, not the bd binary): applies neither per-store switch, the events journal's or versioned history's; the bd binary's factories do"
// constructionExemptions are construction sites that legitimately do NOT
// activate the events journal, each with a reason. Keyed by
// "<pkg>/<file>:<Recv.Func>" so the two build-tag twins of a factory are
@ -172,6 +178,17 @@ var constructionExemptions = map[string]string{
// A standalone developer utility binary, not bd. It has no workspace config
// to read and never runs as part of a bd command.
"embeddeddolt-cmd/main.go:main": "standalone embeddeddolt debug utility, not the bd binary; no workspace config and no bd command context",
// The Go SDK's own opens (the repository root's beads package). They are a
// library surface that embedders call directly, and they build stores without
// applying either per-store switch. They are declared here so that a new SDK
// open is noticed rather than missed. Making them apply the switches would
// change the library's behavior for every embedder, so it is a separate change.
"sdk/beads.go:Open": sdkOpenExemptionReason,
"sdk/beads.go:OpenFromConfig": sdkOpenExemptionReason,
"sdk/beads.go:OpenGated": sdkOpenExemptionReason,
"sdk/beads_cgo.go:OpenBestAvailableWith": sdkOpenExemptionReason,
"sdk/beads_nocgo.go:OpenBestAvailableWith": sdkOpenExemptionReason,
}
func TestEveryStoreConstructionActivatesTheEventsJournal(t *testing.T) {
@ -235,6 +252,9 @@ func exemptionFor(key string) (exemption, reason string, ok bool) {
type constructionSite struct {
constructors []string
activates bool
// activatesVersionedHistory is the same question for the versioned-history
// guard, which reuses this scan (see versioned_history_construction_test.go).
activatesVersionedHistory bool
}
// scanStoreConstructionSites parses each scanned package and returns one entry
@ -364,10 +384,16 @@ func inspectConstructionSite(node ast.Node, imports map[string]string) *construc
if qualifiedActivationCalls[path][fun.Sel.Name] {
site.activates = true
}
if qualifiedVersionedHistoryActivationCalls[path][fun.Sel.Name] {
site.activatesVersionedHistory = true
}
case *ast.Ident:
if activationCalls[fun.Name] {
site.activates = true
}
if versionedHistoryActivationCalls[fun.Name] {
site.activatesVersionedHistory = true
}
}
return true
})

View file

@ -3,7 +3,6 @@
package main
import (
"bytes"
"encoding/json"
"fmt"
"os"
@ -16,7 +15,7 @@ import (
"github.com/steveyegge/beads/internal/storage"
)
// TestEventsTailReportsTruncationToTheCLI is the end-to-end guard for the
// TestEmbeddedEventsTailReportsTruncationToTheCLI is the end-to-end guard for the
// retention boundary as a consumer actually meets it: through the binary, not
// through the store API.
//
@ -27,7 +26,7 @@ import (
// that; this one fails if either path regresses. It also proves the whole
// config chain end to end: BD_EVENTS_JOURNAL turns the journal on, and the two
// BD_EVENTS_JOURNAL_RETAIN_* floors reach the prune.
func TestEventsTailReportsTruncationToTheCLI(t *testing.T) {
func TestEmbeddedEventsTailReportsTruncationToTheCLI(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}
@ -109,7 +108,7 @@ func TestEventsTailReportsTruncationToTheCLI(t *testing.T) {
}
}
// TestEventsTailFollowReportsTruncationOnTheStream covers the OTHER read call
// TestEmbeddedEventsTailFollowReportsTruncationOnTheStream covers the OTHER read call
// site: the --follow poll, which the one-shot test above cannot reach.
//
// A follower is the consumer most exposed to a prune — it is the one sitting
@ -120,7 +119,7 @@ func TestEventsTailReportsTruncationToTheCLI(t *testing.T) {
// it interrupts. The consumer on the other end is a line reader; a
// pretty-printed multi-line object in the middle of its input is unparseable,
// and it would see the stream stop with garbage after the last good record.
func TestEventsTailFollowReportsTruncationOnTheStream(t *testing.T) {
func TestEmbeddedEventsTailFollowReportsTruncationOnTheStream(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}
@ -163,7 +162,7 @@ func TestEventsTailFollowReportsTruncationOnTheStream(t *testing.T) {
follow := exec.Command(bd, "events", "tail", "--since", "0", "--limit", "1", "--follow", "--json")
follow.Dir = dir
follow.Env = env
var stdout, stderr bytes.Buffer
var stdout, stderr syncBuffer
follow.Stdout = &stdout
follow.Stderr = &stderr
if err := follow.Start(); err != nil {
@ -226,11 +225,11 @@ func TestEventsTailFollowReportsTruncationOnTheStream(t *testing.T) {
}
}
// TestEventsPruneHonorsRetainRowsFloorFromConfig proves the shipped defaults
// TestEmbeddedEventsPruneHonorsRetainRowsFloorFromConfig proves the shipped defaults
// reach the CLI: a `prune --before <huge>` on a workspace that configured no
// floors of its own must be stopped by the built-in retain-rows floor rather
// than deleting the whole journal and stranding its consumer.
func TestEventsPruneHonorsRetainRowsFloorFromConfig(t *testing.T) {
func TestEmbeddedEventsPruneHonorsRetainRowsFloorFromConfig(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}

View file

@ -47,9 +47,9 @@ func parseExportedIssues(t *testing.T, jsonl string) []*types.Issue {
return issues
}
// TestExportExcludeOwner_flag verifies that bd export --exclude-owner=<name>
// TestEmbeddedExportExcludeOwner_flag verifies that bd export --exclude-owner=<name>
// filters out issues created_by that identity from the export.
func TestExportExcludeOwner_flag(t *testing.T) {
func TestEmbeddedExportExcludeOwner_flag(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}
@ -86,9 +86,9 @@ func TestExportExcludeOwner_flag(t *testing.T) {
}
}
// TestExportExcludeOwner_config verifies that export.exclude_owners config
// TestEmbeddedExportExcludeOwner_config verifies that export.exclude_owners config
// filters issues without a command-line flag.
func TestExportExcludeOwner_config(t *testing.T) {
func TestEmbeddedExportExcludeOwner_config(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}
@ -115,8 +115,8 @@ func TestExportExcludeOwner_config(t *testing.T) {
}
}
// TestExportExcludeOwner_verbose verifies that --verbose emits a filtered count message.
func TestExportExcludeOwner_verbose(t *testing.T) {
// TestEmbeddedExportExcludeOwner_verbose verifies that --verbose emits a filtered count message.
func TestEmbeddedExportExcludeOwner_verbose(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}
@ -151,12 +151,12 @@ func TestExportExcludeOwner_verbose(t *testing.T) {
}
}
// TestAutoExportExcludeOwner_config is a regression test for the maphew review
// TestEmbeddedAutoExportExcludeOwner_config is a regression test for the maphew review
// of PR #4023 (be-e2nb): the export.exclude_owners safety net must also apply to
// the git-committed auto-export (.beads/issues.jsonl), not only to manual
// `bd export`. Before the fix, contributor/personal issues that the manual path
// excludes could still leak into git history and PRs via auto-export.
func TestAutoExportExcludeOwner_config(t *testing.T) {
func TestEmbeddedAutoExportExcludeOwner_config(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
}

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