Merge latest base into adopted PR head (adopt-pr base refresh, merge mode)

Resolved three conflicts created by main's new darwin (arm64) non-CGO
cross-lint pass landing while this PR moved lint target selection out of
scripts/ci/pr-lint.sh into the checkout-owned scripts/pr-lint Go driver:

- scripts/ci/pr-lint.sh: keep the PR's pure delegation to the Go driver.
  Main added its third pass as shell policy, which this PR's own
  prlintmake test forbids (the wrapper's only `go` invocation must be the
  driver call), so the pass moves into the driver instead of being dropped.
- scripts/pr-lint/main.go: add the darwin/arm64 non-CGO pass mirroring the
  existing windows/amd64 pass, including the native-target skip guard and
  the Windows-host toolchain re-probe.
- engdocs/LINTING.md, engdocs/CI_CLEANUP_PLAN.md: union of both sides, with
  the newest `Last reviewed` marker per file.

Behaviour is the union of both sides: all three lint targets still run, and
the wrapper still holds no target-selection policy.
This commit is contained in:
Gas City Adopt-PR 2026-09-29 13:31:56 +00:00
commit 7f37ba5165
220 changed files with 18677 additions and 1094 deletions

205
.bazelrc
View file

@ -26,9 +26,18 @@ test --test_env=BD_DISABLE_EVENT_FLUSH=1
# -short, skips, tag filters); the environment comes from the wrapper above.
test:prcore --@rules_go//go/config:race
test:prcore --test_arg=-test.short
# pr-core.sh's -parallel 4. Without it -test.parallel defaults to GOMAXPROCS,
# the executor's core count (192 on a farm worker), not a runner's 4.
test:prcore --test_arg=-test.parallel=4
test:prcore --test_arg=-test.skip=^TestEmbedded
test:prcore --test_env=BEADS_TEST_SKIP=dolt
test:prcore --test_tag_filters=-requires-docker,-embedded,-manual
# As in pr.yml's PR Core step: a root or non-POSIX executor fails
# TestAddExcludePatternsRefusesReadErrors instead of skipping it.
test:prcore --test_env=BEADS_TEST_REQUIRE_EXCLUDE_PERMISSION=1
# Every tag that belongs to another lane (scripts/bazel_policy_test.go
# bazelPRCoreExcludedTags). integration-only targets run zero tests outside
# --config=integration.
test:prcore --test_tag_filters=-requires-docker,-dolt-server,-dolt-server-proxied,-dolt-server-integration,-embedded,-manual,-integration-only
test:ci --config=prcore
test:ci --keep_going --test_summary=terse
@ -38,16 +47,198 @@ test:ci --keep_going --test_summary=terse
# test.xml on the remote side, so ask for both.
test:ci --test_env=GO_TEST_WRAP_TESTV=1
test:ci --remote_download_regex=.*/test\.xml$
# bazel.yml publishes the non-race bd as pr.yml's ci-build-artifacts.
test:ci --remote_download_regex=.*/bin/cmd/bd/bd_for_tests/bd$
# Docker lane: only the requires-docker targets (pr.yml's container-backed
# jobs), on a host with a docker daemon. Race like those jobs, but no -short
# and no BEADS_TEST_SKIP=dolt, which would keep the containers from starting.
# Those targets are also tagged no-remote-exec, so they run on the host even
# with --config=remote-exec.
# jobs "Test (storage domain + uow)" and "Contract corpus"), on a host with a
# docker daemon. Race like the domain+uow job (//cmd/bd/protocol's variant
# opts out, like the non-race Contract corpus job), but no -short and no
# BEADS_TEST_SKIP=dolt, which would keep the containers from starting. Those
# targets are also tagged no-remote-exec, so they run on the host even with
# --config=remote-exec; their builds may still run remotely. -test.v in
# test.xml, as in test:ci, lets equivalence.py see which tests ran.
test:docker --@rules_go//go/config:race
test:docker --test_tag_filters=requires-docker
test:docker --build_tests_only
test:docker --keep_going
test:docker --test_env=GO_TEST_WRAP_TESTV=1
# Those jobs pass no -p/-parallel, so go test uses GOMAXPROCS, ubuntu-latest's
# 4 vCPUs, for both. Match that on any host: 4 test processes (hence at most
# 4 dolt containers starting at once) and -test.parallel=4.
test:docker --local_test_jobs=4
test:docker --test_arg=-test.parallel=4
# The variants depend on host state no action key sees (the docker daemon,
# the pulled dolt image, the network), so a cached result proves nothing about
# this host: always run them, like the jobs' `go test -count=1`.
test:docker --nocache_test_results
# Embedded-Dolt tier: PR Risk's embedded jobs ("Test (Embedded Dolt Cmd
# N/20)", "Test (Embedded Dolt Storage N/5)", "Test (Embedded Dolt
# Conformance - core/audit)"), as the `embedded`-tagged variants of bd_test
# and embeddeddolt_test. Race like the jobs' binaries, no -short, no
# BEADS_TEST_SKIP; each variant sets BEADS_TEST_EMBEDDED_DOLT=1. The shard
# variants run the jobs' shard scripts, so every Bazel shard runs exactly the
# tests of the job with the same number.
# Only the variants and what they need are built (the same race configuration
# as --config=ci, so the two lanes share every compile).
test:embedded --@rules_go//go/config:race
test:embedded --test_tag_filters=embedded
test:embedded --build_tests_only
test:embedded --keep_going
test:embedded --test_summary=terse
# The variants are timeout = "eternal" because the jobs' Go timeouts are past
# "long"; rbe-west rejects any action timeout over 1200s, so eternal means
# 1200s here, and the effective limits are: storage shards, the job's
# -test.timeout=15m; cmd shards and conformance core/audit, -test.timeout=19m
# (the jobs pass 20m and 30m), so that Go's timeout, which dumps every
# goroutine, fires before Bazel's 1200s kill, which does not (see the BUILD
# targets).
test:embedded --test_timeout=-1,-1,-1,1200
# The jobs pass no -parallel: GOMAXPROCS on a 4-vCPU runner.
test:embedded --test_arg=-test.parallel=4
test:embedded --test_env=GO_TEST_WRAP_TESTV=1
test:embedded --remote_download_regex=.*/test\.xml$
# Dolt-server lane: the same jobs as the docker lane ("Test (storage domain +
# uow)" and "Contract corpus"), but every dolt sql-server is a child of the
# test process, started from the pinned dolt in the test wrapper's runfiles
# (BEADS_TEST_DOLT_SERVER=local, set by each dolt-server target), so the
# targets run on remote workers and need no docker. Same selection rules as
# test:docker: race (//cmd/bd/protocol's variant opts out, like its job), no
# -short, no BEADS_TEST_SKIP=dolt, -test.parallel=4, and the no--short twins
# of the job's other packages. Results are cacheable: every input (test
# binary, dolt, env) is in the action key, and a server that cannot start
# fails the target (BEADS_TEST_REQUIRE_DOLT_CONTAINER=1) instead of skipping.
# --config=docker stays as the A/B control. test.xml is downloaded for
# tools/bazel/equivalence.py --job, test.log for bazel.yml's failure artifact.
test:doltserver --@rules_go//go/config:race
test:doltserver --test_tag_filters=dolt-server
test:doltserver --build_tests_only
test:doltserver --keep_going
test:doltserver --test_env=GO_TEST_WRAP_TESTV=1
test:doltserver --test_arg=-test.parallel=4
# Locally (fork PRs, rbe=off, no executor): at most 4 test processes, as in
# test:docker; remote workers are not limited by it.
test:doltserver --local_test_jobs=4
test:doltserver --remote_download_regex=.*/test\.(log|xml)$
# Proxied-server tier: PR Risk's "Test (Proxied Dolt Cmd N/15)" jobs, as
# //cmd/bd:bd_proxied_test (dolt-server-proxied tag). Kept out of
# --config=doltserver because bazel.yml runs that lane locally too (forks,
# rbe=off), where 15 shards of ~10 minutes, each with a dolt sql-server busy
# on ~4 cores, do not fit; bazel.yml runs this one only with remote
# execution, in a job of its own (bazel-proxied). The build is
# --config=doltserver's: race, like PR Risk's /tmp/bd-cmd-test (main.yml's
# twin job runs build-artifacts' non-race bd-cmd-test, so this is the
# stricter of the two); the subprocess bd is the non-race bd_for_tests, like
# the jobs'. Each shard runs its job's
# shard script, whose -test.timeout=15m is past "long": the target is
# eternal, which rbe-west caps at 1200s.
test:doltserver-proxied --@rules_go//go/config:race
test:doltserver-proxied --test_tag_filters=dolt-server-proxied
test:doltserver-proxied --build_tests_only
test:doltserver-proxied --keep_going
test:doltserver-proxied --test_summary=terse
test:doltserver-proxied --test_timeout=-1,-1,-1,1200
test:doltserver-proxied --test_env=GO_TEST_WRAP_TESTV=1
# The jobs pass no -parallel: GOMAXPROCS (the target's 4, a runner's vCPUs).
test:doltserver-proxied --test_arg=-test.parallel=4
test:doltserver-proxied --local_test_jobs=4
test:doltserver-proxied --remote_download_regex=.*/test\.(log|xml)$
# Server-Dolt storage tier: PR Risk's "Test (Server Dolt Conformance)" and
# "Test (Server Dolt Full Suite N/16)" jobs, as
# //internal/storage/dolt:dolt_server_{conformance,full}_test
# (dolt-server-integration tag): the integration-tagged internal/storage/dolt
# tests, non-race like the jobs' binary, against a local dolt sql-server.
# The build flags are exactly --config=integration's (the tags, and race for
# everything the variants do not turn off), so the two lanes share every
# compile: the variants' race-off binary lands in the configuration
# --config=integration already builds the non-race //cmd/bd:bd_for_tests in.
# A per-target gotags transition would instead compile the whole graph a
# third time. No BEADS_TEST_SKIP, no -short; the full suite's
# BEADS_TEST_ENV_RUN_DOLT=1 is target env. Remote only in bazel.yml, in a
# job of its own (bazel-server-storage) that shares bazel-integration's
# compiles through the remote cache.
build:doltserver-integration --@rules_go//go/config:tags=gms_pure_go,integration
test:doltserver-integration --@rules_go//go/config:race
test:doltserver-integration --test_tag_filters=dolt-server-integration
test:doltserver-integration --build_tests_only
test:doltserver-integration --keep_going
test:doltserver-integration --test_summary=terse
test:doltserver-integration --test_timeout=-1,-1,-1,1200
test:doltserver-integration --test_env=GO_TEST_WRAP_TESTV=1
# The jobs pass no -parallel: GOMAXPROCS (the targets' 4, a runner's vCPUs).
test:doltserver-integration --test_arg=-test.parallel=4
test:doltserver-integration --local_test_jobs=4
test:doltserver-integration --remote_download_regex=.*/test\.(log|xml)$
# Integration lane: main.yml's "Main Linux integration packages (N/6)" and
# "Main Linux integration cmd/bd (N/8)" jobs (and nightly.yml's Full Test
# Suite, which runs the same `go test` over ./... in one job): every package
# built with -tags=integration,gms_pure_go, race, no -short, no -skip,
# BEADS_TEST_SKIP=dolt. The tag is set for the whole build, as `go test -tags`
# does, not per target: gazelle generates srcs/deps with integration files
# included (root BUILD.bazel `gazelle:build_tags`), rules_go drops them from
# every other configuration, and //internal/testutil/integration (integration
# files only) compiles to its real contents only here. A per-target `gotags`
# would not save the compile either: it transitions the whole dep graph.
build:integration --@rules_go//go/config:tags=gms_pure_go,integration
test:integration --@rules_go//go/config:race
test:integration --test_env=BEADS_TEST_SKIP=dolt
# The variants the PR-core lane leaves out stay out, except integration-only
# (targets with tests only under the tag): the jobs' BEADS_TEST_SKIP=dolt
# keeps every container- or server-backed test skipped, which is what the
# untagged base targets already do. scripts/bazel_policy_test.go derives the
# required exclusions from the PR-core list, so a new lane tag lands here too.
test:integration --test_tag_filters=-requires-docker,-dolt-server,-dolt-server-proxied,-dolt-server-integration,-embedded,-manual
test:integration --build_tests_only
test:integration --keep_going
test:integration --test_summary=terse
# The jobs pass no -p/-parallel: GOMAXPROCS on a 4-vCPU ubuntu-latest runner.
test:integration --test_arg=-test.parallel=4
# The jobs give each package binary -timeout=30m. rbe-west rejects an action
# timeout over 1200s, so every size gets 1200s, and Go's own -test.timeout (19m,
# after the 1200s rules_go derives from TEST_TIMEOUT: the last flag wins) fires
# first and dumps every goroutine to test.log, which Bazel's kill does not.
test:integration --test_timeout=1200
test:integration --test_arg=-test.timeout=19m
# The runner is not root, so TestAddExcludePatternsRefusesReadErrors runs
# there; make a root executor fail it rather than skip (as test:prcore does).
test:integration --test_env=BEADS_TEST_REQUIRE_EXCLUDE_PERMISSION=1
# -test.v in test.xml, as in test:ci, for tools/bazel/equivalence.py.
test:integration --test_env=GO_TEST_WRAP_TESTV=1
# ci and integration build into the same output directory (the tags flag
# does not change it), so they share bazel-testlogs: a lane's test.xml is
# overwritten by the other lane's next run of the same target. Run
# equivalence.py / check_testcases.py right after each lane's own
# `bazel test`, before the other lane runs (or give the lanes separate jobs).
test:integration --remote_download_regex=.*/test\.xml$
# Pure-Go lane: pr.yml's "Check pure-Go and js/wasm boundaries
# (CGO_ENABLED=0)" job. CGO is off for every Go target (rules_go drops
# cgo-constrained files like go build does; third_party/patches/
# gozstd_nocgo.patch lets dolt's store/nbs, an unused but declared dep,
# compile; its package init panics, so a pure binary that links it fails when
# run). bazel.yml builds bd and the job's pure test binaries, runs each of
# them once (the contamination check `go build` does at compile time) and runs
# its -short cmd/bd subset.
build:pure --@rules_go//go/config:pure
test:pure --test_arg=-test.short
# The job passes no -parallel: GOMAXPROCS on a 4-vCPU runner.
test:pure --test_arg=-test.parallel=4
test:pure --test_env=GO_TEST_WRAP_TESTV=1
test:pure --remote_download_regex=.*/test\.xml$
# js/wasm hook boundary (same job): build for GOOS=js GOARCH=wasm. Bazel
# cannot run the wasm test binary itself; bazel.yml runs it with the Go SDK's
# go_js_wasm_exec (node), like `go test -exec`. The test toolchain needs an
# exec platform matching the target platform, hence
# --use_target_platform_for_tests (no test action runs under this config).
build:js-wasm --platforms=@rules_go//go/toolchain:js_wasm
build:js-wasm --use_target_platform_for_tests
build:js-wasm --remote_download_outputs=toplevel
# Remote execution against any REAPI-compatible service. Only generic tuning
# lives here; the executor endpoint and TLS credentials are never committed.
@ -57,6 +248,10 @@ build:remote-exec --jobs=64
build:remote-exec --remote_download_minimal
build:remote-exec --remote_timeout=600
build:remote-exec --remote_retries=3
# Upload only remotely executed results. A locally executed action (a
# no-remote-exec test, a host-dependent docker-lane result) must not seed the
# shared cache that CI and every other developer read.
build:remote-exec --noremote_upload_local_results
try-import %workspace%/.bazelrc.local
try-import %workspace%/user.bazelrc

56
.github/scripts/bazel-gate.sh vendored Executable file
View file

@ -0,0 +1,56 @@
#!/usr/bin/env bash
# pr.yml's ci-gate view of its bazel.yml call (the `bazel` job). bazel.yml's
# rbe job decides the execution mode once and exports it as the call's
# rbe-mode / rbe-enabled outputs; this script reads those outputs and never
# re-derives the decision (repo variable, fork, secrets) itself.
#
# bazel-gate.sh skips the Bazel gate ids whose job is skipped by design
# in this mode, for CI_GATE_SKIPPED_OK:
# skip: every lane and the aggregate (BAZEL)
# local: the remote-only BAZEL_EMBEDDED,
# BAZEL_PROXIED, BAZEL_SERVER_STORAGE
# remote: none
# bazel-gate.sh aggregate the value to gate on for BAZEL: the call's
# aggregate result, or, when the mode is missing
# or invalid (the rbe job failed, the call never
# started), an unexpected value that ci-gate.sh
# rejects.
#
# Any other skip, a failure, a cancellation, or a lane that should run but
# reported nothing (pr.yml maps an empty output to skipped) fails the gate.
#
# Inputs (environment): BAZEL_RBE_MODE, BAZEL_RBE_ENABLED (the call's
# rbe-mode / rbe-enabled outputs), BAZEL_CALL (needs.bazel.result).
set -euo pipefail
mode="${BAZEL_RBE_MODE:-}"
enabled="${BAZEL_RBE_ENABLED:-}"
valid=false
case "$mode/$enabled" in
remote/true | local/false | skip/false) valid=true ;;
esac
case "${1:-}" in
skips)
skips=()
if [[ "$valid" == true ]]; then
case "$mode" in
skip) skips+=(BAZEL BAZEL_TEST BAZEL_PURE BAZEL_EMBEDDED BAZEL_DOLTSERVER BAZEL_PROXIED BAZEL_SERVER_STORAGE) ;;
local) skips+=(BAZEL_EMBEDDED BAZEL_PROXIED BAZEL_SERVER_STORAGE) ;;
esac
fi
echo "${skips[*]-}"
;;
aggregate)
if [[ "$valid" != true ]]; then
echo "invalid-rbe-mode:$(printf '%s/%s' "$mode" "$enabled" | tr -cd 'a-z/')"
else
echo "${BAZEL_CALL:-}"
fi
;;
*)
echo "usage: $0 skips|aggregate" >&2
exit 2
;;
esac

135
.github/workflows/bazel-autofix.yml vendored Normal file
View file

@ -0,0 +1,135 @@
# Auto-fix stale Bazel BUILD files on PRs.
#
# bazel.yml's "BUILD files in sync" step runs `make bazel-sync` (gazelle,
# tools/bazel/go_srcs.py, bazel mod tidy) and, when that leaves drift, fails
# and uploads the BUILD.bazel / MODULE.bazel / MODULE.bazel.lock part of the
# fix as the bazel-sync-patch artifact (scripts/ci/bazel-sync-patch.sh). This
# workflow closes the loop, like docs-autofix.yml does for generated CLI docs:
# when a PR run fails and left that artifact, it pushes the sync commit to the
# PR branch (same-repo PRs) or leaves an idempotent comment with the apply
# recipe (fork PRs). Drift elsewhere (third_party/patches, go.mod) is never
# patched; the failing run lists it for a human.
#
# Trigger: only "PR" (pr.yml). bazel.yml has no pull_request trigger of its
# own: PRs run it through pr.yml's `bazel` job (workflow_call), so its
# bazel-sync-patch upload belongs to the PR run, and a failing sync step
# fails that run. The "Bazel" workflow's own runs (push to main, dispatch)
# are never pull_request events, so triggering on them would only ever be a
# no-op. A PR run without the artifact (it failed for other reasons) is a
# no-op too. bazel.yml builds the PR MERGE commit, so the patch also
# carries any drift main has; only files in packages the PR itself changed
# are pushed (see the script), so main's drift never lands on an unrelated PR.
#
# CONCURRENCY: job-level (a skipped run - success, or another event - never
# takes part), and shared with docs-autofix.yml per head branch without
# cancel-in-progress, so the two bots queue instead of racing on one branch
# or cancelling a fix that is already running. The second one sees the moved
# head and stops; with the PAT its push retriggers CI, which re-derives the
# other fix. Both bots now fire on the same PR run's completion, so one runs
# while the other waits. GitHub keeps one pending job per group: a later PR
# run finishing inside that short window can displace a waiting job, whose
# fix the next failing run re-derives.
#
# SECURITY MODEL: this runs with write permissions via workflow_run, so it
# never checks out or executes PR code. It checks out the base default branch
# for scripts, and treats the artifact strictly as data: only the two expected
# regular files are extracted, every path in the patch must match an anchored
# Bazel build-file allowlist (no hidden or `..` segments, nothing under
# third_party/), mode/symlink/rename/binary hunks are refused, and
# the patch is applied to an index in a bare clone (the PR tree never touches
# the disk) and re-checked once staged (scripts/bazel-autofix-push.sh), so a
# hostile patch can at most rewrite BUILD.bazel / MODULE.bazel /
# MODULE.bazel.lock on its own PR branch. Pushes are leased to the run's head
# SHA and skipped for heads that are protected or under a ruleset.
#
# TOKEN NOTE: pushes made with the default GITHUB_TOKEN do not retrigger PR
# checks. This reuses the DOCS_AUTOFIX_TOKEN repo secret (fine-grained PAT or
# GitHub App token with contents:write on this repo) rather than adding a
# second one; without it the pushed fix still lands but checks need a manual
# re-run. Fork PRs always get the apply-recipe comment - no token we hold can
# push to a fork. workflow_run always runs this file from the default branch,
# so edits take effect only after they merge.
name: Bazel Autofix
on:
workflow_run:
workflows: ["PR"]
types: [completed]
permissions:
contents: write
pull-requests: write
actions: read
jobs:
autofix:
name: Apply Bazel BUILD sync to PR
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'failure'
runs-on: ubuntu-latest
timeout-minutes: 10
# Shared with docs-autofix.yml; queue, never cancel (see header).
concurrency:
group: autofix-${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: false
steps:
# Trusted side only: base repo default branch, never the PR head. The
# workflow token is not left in .git/config.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
with:
persist-credentials: false
- name: Download BUILD sync patch (if any)
id: patch
env:
GH_TOKEN: ${{ github.token }}
RUN_ID: ${{ github.event.workflow_run.id }}
run: |
artifact_ids="$(gh api --paginate "repos/${GITHUB_REPOSITORY}/actions/runs/${RUN_ID}/artifacts?per_page=100" \
--jq '.artifacts[] | select(.name == "bazel-sync-patch") | .id')"
artifact_id="$(printf '%s\n' "$artifact_ids" | head -1)"
if [ -z "$artifact_id" ]; then
echo "No BUILD sync patch artifact on run ${RUN_ID}; it failed for other reasons."
echo "found=false" >> "$GITHUB_OUTPUT"
exit 0
fi
dir="${RUNNER_TEMP}/bazel-patch"
mkdir -p "$dir"
gh api "repos/${GITHUB_REPOSITORY}/actions/artifacts/${artifact_id}/zip" > "${RUNNER_TEMP}/bazel-patch.zip"
# Extract only the two expected names, and only as regular files.
unzip -o "${RUNNER_TEMP}/bazel-patch.zip" bazel-sync.patch bazel-sync-meta.txt -d "$dir" || true
ls -la "$dir"
for f in bazel-sync.patch bazel-sync-meta.txt; do
if [ -L "$dir/$f" ] || { [ -e "$dir/$f" ] && [ ! -f "$dir/$f" ]; }; then
echo "::error::artifact entry $f is not a regular file"
exit 1
fi
done
if [ ! -f "$dir/bazel-sync.patch" ]; then
echo "Artifact has no bazel-sync.patch; nothing to do."
echo "found=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "found=true" >> "$GITHUB_OUTPUT"
- name: Push sync commit or leave apply recipe
if: steps.patch.outputs.found == 'true'
env:
BASE_REPO: ${{ github.repository }}
HEAD_REPO: ${{ github.event.workflow_run.head_repository.full_name }}
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
PATCH_FILE: ${{ runner.temp }}/bazel-patch/bazel-sync.patch
META_FILE: ${{ runner.temp }}/bazel-patch/bazel-sync-meta.txt
RUN_ID: ${{ github.event.workflow_run.id }}
RUN_URL: ${{ github.event.workflow_run.html_url }}
# Split tokens: gh api calls (PR lookup, comments) always use the
# workflow token, which carries this job's pull-requests:write; the
# optional PAT is used ONLY for the git push, so it needs no more
# than contents:write.
GH_TOKEN: ${{ github.token }}
PUSH_TOKEN: ${{ secrets.DOCS_AUTOFIX_TOKEN || github.token }}
AUTOFIX_TOKEN_KIND: ${{ secrets.DOCS_AUTOFIX_TOKEN && 'pat' || 'default' }}
run: ./scripts/bazel-autofix-push.sh

View file

@ -1,16 +1,44 @@
# Bazel side-by-side lane (advisory). Runs `bazel test //... --config=ci`, the
# PR Core-parity selection (race, -short, dolt skip, -requires-docker), on the
# same commit as pr.yml's go test lanes. It is NOT in ci-gate's
# CI_GATE_REQUIRED; promotion needs the equivalence record described in
# tools/bazel/equivalence.py and a human decision.
# Bazel side-by-side lane, gated alongside the legacy go test jobs. Runs
# `bazel test //... --config=ci`, the PR Core-parity selection (race, -short,
# dolt skip, -requires-docker), plus one job per mirrored CI job (pure-Go and
# js/wasm, the dolt-server lane, pr-risk.yml's embedded-Dolt, proxied-server
# and server-Dolt storage tiers, main.yml's integration jobs).
#
# Execution mode, passed to .github/actions/setup-bazel:
# repo variable RBE_WEST_WORKERS=true plus secrets RBE_WEST_EXECUTOR (grpcs://
# endpoint), RBE_TLS_CERT, RBE_TLS_KEY (base64; RBE_TLS_CA optional):
# remote execution on rbe-west, instance "oss" (shared with gascity).
# fork PRs and rbe=off dispatches: local execution, slower but the same
# results. Same-repo runs are skipped while RBE_WEST_WORKERS is unset.
# workflow_dispatch with rbe=off simulates a fork run.
# PRs and merge groups run it through pr.yml's `bazel` job (workflow_call),
# in the same run as the legacy jobs it mirrors, which stay required too.
# This file has no pull_request or merge_group trigger of its own, so a PR
# runs the lane once. Every lane reports its job.status as a workflow_call
# output (named after the job) from an always() last step. pr.yml's ci-gate
# requires the call's aggregate result (BAZEL) and bazel-test, bazel-pure,
# bazel-embedded, bazel-doltserver, bazel-proxied and bazel-server-storage
# (BAZEL_TEST, BAZEL_PURE, BAZEL_EMBEDDED, BAZEL_DOLTSERVER, BAZEL_PROXIED,
# BAZEL_SERVER_STORAGE); .github/scripts/bazel-gate.sh turns the rbe job's
# rbe-mode output into the skips it accepts, so a lane skipped by its `if:`
# below passes and one that should have run and failed, was cancelled or
# reported nothing fails the gate. bazel-integration is not part of the PR
# call (pr.yml passes integration: "off"): its legacy counterparts, main.yml's
# integration jobs, run only on push to main, so it runs on push to main,
# dispatch and nightly, like them. Direct runs (push to main,
# workflow_dispatch, nightly.yml's call) gate nothing.
#
# Execution mode, decided once by the rbe job (every other job needs it and
# reads its outputs; none re-derives the condition) and passed to
# .github/actions/setup-bazel:
# remote: repo variable RBE_WEST_WORKERS=true, rbe not off, not a fork PR,
# and the secret RBE_WEST_EXECUTOR (grpcs:// endpoint) present, plus
# RBE_TLS_CERT, RBE_TLS_KEY (base64; RBE_TLS_CA optional): remote
# execution on rbe-west, instance "oss" (shared with gascity), from the
# Blacksmith runner.
# local: fork PRs, rbe=off dispatches, and same-repo runs without the
# secret (Dependabot PRs: same-repo, but no Actions secrets): local
# execution on ubuntu-latest, slower but the same results, for every job
# but the remote-only ones (bazel-embedded, bazel-integration,
# bazel-proxied, bazel-server-storage), which are skipped.
# skip: same-repo runs while RBE_WEST_WORKERS is unset (the farm switch).
# workflow_dispatch with rbe=off simulates a fork run. The decision is also a
# workflow_call output (rbe-mode, rbe-enabled), so pr.yml's gate can tell an
# expected skip from a missing lane without re-deriving it. Callers pass
# exactly the four RBE secrets below, never `secrets: inherit`.
#
# Accepted risk (same model as gascity's bazel-test.yml): on push, merge_group
# and same-repo pull_request runs, code from the PR head runs with the RBE
@ -19,16 +47,21 @@
# edit can point the BEP or the executor anywhere. Anyone who can push a
# branch here can therefore use or copy the certificate and write to the
# farm's cache. Fork PRs never get it: pull_request from a fork receives no
# secrets, this workflow has no pull_request_target trigger, and forks cannot
# write the runner cache. In place: secrets are referenced by the setup step
# alone and never by a workflow- or job-level env (policy-tested), decoded key
# secrets, neither this workflow nor its callers have a pull_request_target
# trigger, and forks cannot write the runner cache. Nor do Dependabot PRs, which run as same-repo but
# get no Actions secrets. In place: secrets are referenced by the setup step
# alone (plus the rbe job's emptiness test of RBE_WEST_EXECUTOR, which yields
# a boolean) and never by a workflow- or job-level env (policy-tested), decoded key
# material is masked in logs, and CI uploads only remotely executed results
# (--noremote_upload_local_results in the generated rc), and the certificate
# (--noremote_upload_local_results in .bazelrc's remote-exec config and in
# the generated rc), and the certificate
# is issued to beads CI alone, so it can be revoked without affecting other
# clients. Maintainers decided (2026-09-28) that same-repo PRs keep remote
# execution under this model. Still open: a beads-only RBE_INSTANCE and
# farm-side denial of client action-cache writes. The lane is advisory and
# nothing downstream consumes artifacts built here.
# farm-side denial of client action-cache writes. Nothing downstream consumes
# artifacts built here yet; in pr.yml's run the bd artifact is
# bazel-ci-build-artifacts, so it cannot collide with the build-artifacts
# job's ci-build-artifacts.
#
# Runner cache: one entry per (.bazelversion, MODULE.bazel.lock) pair, about
# 2 GB (Bazel's --repository_cache plus Bazelisk's Bazel download), written
@ -40,9 +73,6 @@
name: Bazel
on:
pull_request:
branches: [ main, 'release/**' ]
merge_group:
push:
branches: [ main ]
workflow_dispatch:
@ -58,6 +88,12 @@ on:
required: false
type: boolean
default: false
dolt-lane:
description: "Dolt-backed lane: doltserver (hermetic, remote) or docker (testcontainers A/B control)"
required: false
type: choice
default: "doltserver"
options: [ "doltserver", "docker" ]
workflow_call:
inputs:
rbe:
@ -76,8 +112,70 @@ on:
type: string
required: false
default: ""
# A string, not a boolean: on push and dispatch inputs.integration is
# null, and null == false in GitHub's loose comparison, so a boolean
# test would silently stop the lane on main.
integration:
description: >
"off" skips bazel-integration (pr.yml: its legacy counterparts do
not run on PRs); anything else runs it where remote execution is on.
type: string
required: false
default: "on"
build-artifact-name:
description: >
Name of the uploaded bd artifact (ci-build-artifacts layout). pr.yml
sets bazel-ci-build-artifacts: its build-artifacts job uploads
ci-build-artifacts in the same run.
type: string
required: false
default: "ci-build-artifacts"
# Only what the rbe job and setup-bazel need; callers pass them
# explicitly. None is required: fork and Dependabot runs have none.
secrets:
RBE_WEST_EXECUTOR:
required: false
RBE_TLS_CERT:
required: false
RBE_TLS_KEY:
required: false
RBE_TLS_CA:
required: false
# The rbe job's decision, and each lane's job.status (success, failure or
# cancelled; empty when the lane was skipped or never reported). pr.yml's
# ci-gate reads them through .github/scripts/bazel-gate.sh.
outputs:
rbe-enabled:
description: "'true' when the lanes executed remotely on rbe-west, else 'false'"
value: ${{ jobs.rbe.outputs.enabled }}
rbe-mode:
description: "remote, local (no remote-only jobs) or skip (no jobs): the rbe job's decision"
value: ${{ jobs.rbe.outputs.mode }}
bazel-test:
description: "bazel-test's job.status"
value: ${{ jobs.bazel-test.outputs.result }}
bazel-pure:
description: "bazel-pure's job.status"
value: ${{ jobs.bazel-pure.outputs.result }}
bazel-embedded:
description: "bazel-embedded's job.status"
value: ${{ jobs.bazel-embedded.outputs.result }}
bazel-integration:
description: "bazel-integration's job.status (empty in pr.yml's call, which turns the lane off)"
value: ${{ jobs.bazel-integration.outputs.result }}
bazel-doltserver:
description: "bazel-doltserver's job.status"
value: ${{ jobs.bazel-doltserver.outputs.result }}
bazel-proxied:
description: "bazel-proxied's job.status"
value: ${{ jobs.bazel-proxied.outputs.result }}
bazel-server-storage:
description: "bazel-server-storage's job.status"
value: ${{ jobs.bazel-server-storage.outputs.result }}
# Main runs always finish (they may save the runner cache); PR runs supersede.
# Main runs always finish (they may save the runner cache); PR runs (called
# from pr.yml, whose own group cancels the calling run too) supersede. The
# group differs from pr.yml's, as a called workflow's must.
concurrency:
group: bazel-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
@ -92,21 +190,66 @@ env:
BAZEL_BUDGET_SECONDS: "420"
jobs:
# The one place the execution mode is decided (see the header), so every
# job sees the same answer for the whole run. Its step reads one secret, and
# only to test it for emptiness: the step's env holds a boolean, never the
# value, and the step runs no repository code (no checkout). Dependabot
# runs read vars but get no secrets, so they come out local, not remote.
rbe:
name: execution mode
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
enabled: ${{ steps.decide.outputs.enabled }}
mode: ${{ steps.decide.outputs.mode }}
steps:
# The expressions' == is case-insensitive (RBE_WEST_WORKERS=True counts).
# A push, merge_group or dispatch has no pull_request, so FORK is false.
- name: Decide remote execution
id: decide
env:
RBE_VAR_ON: ${{ vars.RBE_WEST_WORKERS == 'true' }}
RBE_INPUT_OFF: ${{ inputs.rbe == 'off' }}
FORK: ${{ github.event.pull_request.head.repo.fork == true }}
HAS_EXECUTOR: ${{ secrets.RBE_WEST_EXECUTOR != '' }}
run: |
for v in RBE_VAR_ON RBE_INPUT_OFF FORK HAS_EXECUTOR; do
case "${!v}" in
true|false) ;;
*) echo "::error::$v is '${!v}', want true or false"; exit 1 ;;
esac
done
if [ "$RBE_INPUT_OFF" = true ] || [ "$FORK" = true ]; then
mode=local
elif [ "$RBE_VAR_ON" != true ]; then
mode=skip
elif [ "$HAS_EXECUTOR" = true ]; then
mode=remote
else
mode=local
fi
enabled=false
if [ "$mode" = remote ]; then enabled=true; fi
echo "mode=$mode" >> "$GITHUB_OUTPUT"
echo "enabled=$enabled" >> "$GITHUB_OUTPUT"
echo "Bazel execution mode: **$mode** (RBE_WEST_WORKERS on: $RBE_VAR_ON, rbe=off: $RBE_INPUT_OFF, fork: $FORK, executor secret: $HAS_EXECUTOR)" | tee -a "$GITHUB_STEP_SUMMARY"
bazel-test:
name: Bazel / test (advisory)
name: test
# Remote-execution runs use the org's Blacksmith pool (the farm's edge
# admits it; GitHub-hosted runners are refused) and do not count against
# GitHub's concurrent-job cap. Fork PRs and rbe=off have no remote
# executor and build everything locally, so they get the larger
# GitHub-hosted runner.
runs-on: ${{ (inputs.rbe || 'on') != 'off' && github.event.pull_request.head.repo.fork != true && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}
# GitHub's concurrent-job cap. Local runs (forks, rbe=off, no secrets)
# build everything on the runner, so they get the larger GitHub-hosted
# one.
needs: rbe
runs-on: ${{ needs.rbe.outputs.enabled == 'true' && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}
# Remote execution goes to rbe-west (instance "oss", the Blacksmith-backed
# worker pool shared with gascity), switched on by the repo variable
# RBE_WEST_WORKERS. Until it is set, only fork PRs and rbe=off dispatches
# run (locally); same-repo runs are skipped rather than failing on an
# unreachable executor.
if: ${{ vars.RBE_WEST_WORKERS == 'true' || inputs.rbe == 'off' || github.event.pull_request.head.repo.fork == true }}
# worker pool shared with gascity). Skipped only in mode skip (same-repo
# runs while RBE_WEST_WORKERS is unset).
if: ${{ needs.rbe.outputs.mode != 'skip' }}
timeout-minutes: 100
outputs:
result: ${{ steps.result.outputs.result }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
@ -131,11 +274,11 @@ jobs:
id: bazel
uses: ./.github/actions/setup-bazel
env:
BAZEL_REMOTE_EXECUTOR: ${{ (inputs.rbe || 'on') != 'off' && vars.RBE_WEST_WORKERS == 'true' && secrets.RBE_WEST_EXECUTOR || '' }}
RBE_TLS_CERT: ${{ (inputs.rbe || 'on') != 'off' && vars.RBE_WEST_WORKERS == 'true' && secrets.RBE_TLS_CERT || '' }}
RBE_TLS_KEY: ${{ (inputs.rbe || 'on') != 'off' && vars.RBE_WEST_WORKERS == 'true' && secrets.RBE_TLS_KEY || '' }}
RBE_TLS_CA: ${{ (inputs.rbe || 'on') != 'off' && vars.RBE_WEST_WORKERS == 'true' && secrets.RBE_TLS_CA || '' }}
RBE_INSTANCE: ${{ (inputs.rbe || 'on') != 'off' && vars.RBE_WEST_WORKERS == 'true' && 'oss' || '' }}
BAZEL_REMOTE_EXECUTOR: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_WEST_EXECUTOR || '' }}
RBE_TLS_CERT: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_CERT || '' }}
RBE_TLS_KEY: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_KEY || '' }}
RBE_TLS_CA: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_CA || '' }}
RBE_INSTANCE: ${{ needs.rbe.outputs.enabled == 'true' && 'oss' || '' }}
# T1: remote + restored repository cache; T2: remote, cold runner; local:
# no remote execution (reported, never budgeted).
@ -150,7 +293,7 @@ jobs:
else tier=local; fi
echo "tier=$tier" >> "$GITHUB_OUTPUT"
{
echo "### Bazel / test (advisory)"
echo "### Bazel / test"
echo
echo "Tier **$tier**: remote execution $REMOTE, runner cache restored $RESTORED."
echo
@ -173,6 +316,25 @@ jobs:
echo >> "$GITHUB_STEP_SUMMARY"
exit "$rc"
# pr.yml's build-artifacts job, built by Bazel: the same artifact name
# and layout (bd-linux-gms-pure, SHA256SUMS, build-manifest.txt), so its
# consumers (PR Core, domain+uow, the package gates) can switch to it.
# None does yet. The script documents which binary and how it differs
# from `go build`'s.
- name: Package bd (ci-build-artifacts layout)
id: bd-artifact
if: ${{ always() && steps.test.outcome != 'skipped' }}
run: ./scripts/ci/package-bazel-bd.sh "$RUNNER_TEMP/bd-artifacts"
- name: Upload build artifacts
if: ${{ always() && steps.bd-artifact.outcome == 'success' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: ${{ inputs.build-artifact-name || 'ci-build-artifacts' }}
path: ${{ runner.temp }}/bd-artifacts/
retention-days: 1
if-no-files-found: error
- name: Critical-path report
if: ${{ always() && steps.test.outcome != 'skipped' }}
env:
@ -195,6 +357,10 @@ jobs:
# manual, missing target, empty shard) unless it is allowlisted. With
# go test results (nightly) it also fails on tests that passed under go
# test and were skipped under Bazel; a PR run cannot see those.
# It reads test.xml from bazel-testlogs, which --config=integration
# shares with --config=ci (same output directory): if a job ever runs
# both lanes, run each lane's equivalence right after its own
# `bazel test`, before the other lane overwrites the logs.
- name: Go test equivalence
if: ${{ always() && steps.test.outcome != 'skipped' }}
timeout-minutes: 15
@ -209,13 +375,23 @@ jobs:
# Runs last: it rewrites BUILD files in the checkout. main moves BUILD
# inputs (imports, go.mod) without touching Bazel, so drift shows up here
# first.
# first. On drift the step still fails, and the BUILD.bazel /
# MODULE.bazel / MODULE.bazel.lock part of the fix is written as a patch
# for the bazel-sync-patch artifact, which bazel-autofix.yml pushes to
# same-repo PR branches (or turns into an apply recipe for forks).
- name: BUILD files in sync (gazelle, go_srcs, MODULE.bazel)
id: sync
if: ${{ always() && steps.bazel.outcome == 'success' }}
timeout-minutes: 15
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
start=$(date +%s)
make bazel-sync-check
# A stale go_srcs block is drift like any other: record it, then let
# bazel-sync fix it so the patch covers it too.
check=0
make bazel-sync-check || check=$?
make bazel-sync
drift="$(git status --porcelain --untracked-files=all)"
echo "BUILD sync check: $(( $(date +%s) - start ))s" >> "$GITHUB_STEP_SUMMARY"
@ -224,8 +400,20 @@ jobs:
echo "$drift"
git diff | head -200
echo "BUILD files **out of sync**; run \`make bazel-sync\` and commit the result." >> "$GITHUB_STEP_SUMMARY"
./scripts/ci/bazel-sync-patch.sh "$RUNNER_TEMP/bazel-sync-patch"
exit 1
fi
exit "$check"
# Data only: bazel-autofix.yml validates every path before applying it.
- name: Upload BUILD sync patch
if: ${{ always() && steps.sync.outcome == 'failure' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: bazel-sync-patch
path: ${{ runner.temp }}/bazel-sync-patch/
if-no-files-found: ignore
retention-days: 7
- name: Upload test logs
if: ${{ failure() && steps.test.outcome == 'failure' }}
@ -248,3 +436,522 @@ jobs:
with:
path: ${{ runner.temp }}/bazel-ci-cache
key: bazel-repo-v2-${{ runner.os }}-${{ hashFiles('.bazelversion', 'MODULE.bazel.lock') }}
# Last step: the job's result as a workflow_call output for pr.yml's
# ci-gate. always() runs it after a failure, a timeout or a
# cancellation too.
- name: Record job result
id: result
if: ${{ always() }}
env:
JOB_STATUS: ${{ job.status }}
run: echo "result=$JOB_STATUS" >> "$GITHUB_OUTPUT"
# pr.yml's check-cmd-bd-puregeo-tests job ("Check pure-Go and js/wasm
# boundaries (CGO_ENABLED=0)") with Bazel-built binaries: --config=pure
# builds bd and the job's three pure test binaries and runs its -short
# cmd/bd subset (PURE_CMD_BD_TESTS, kept equal to the job's -run selector by
# scripts/ci_workflow_test.go); --config=js-wasm builds the hooks test for
# js/wasm, which the Go SDK's go_js_wasm_exec runs under node with the job's
# exact pass-count guard.
bazel-pure:
name: pure-Go and js/wasm
# Same runner and skip rule as bazel-test.
needs: rbe
runs-on: ${{ needs.rbe.outputs.enabled == 'true' && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}
if: ${{ needs.rbe.outputs.mode != 'skip' }}
timeout-minutes: 90
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)'
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
# Only for go_js_wasm_exec and wasm_exec_node.js, which must match the
# Go version Bazel compiles with (go.mod's; policy-tested).
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
cache: false
- name: Set up Node.js
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v6
with:
node-version: '24'
- name: Set up Bazel
id: bazel
uses: ./.github/actions/setup-bazel
env:
BAZEL_REMOTE_EXECUTOR: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_WEST_EXECUTOR || '' }}
RBE_TLS_CERT: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_CERT || '' }}
RBE_TLS_KEY: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_KEY || '' }}
RBE_TLS_CA: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_CA || '' }}
RBE_INSTANCE: ${{ needs.rbe.outputs.enabled == 'true' && 'oss' || '' }}
- name: Run js/wasm hook boundary
run: |
set -euo pipefail
bazel build --config=js-wasm //internal/hooks:hooks_test
bin="$(bazel cquery --config=js-wasm --output=files //internal/hooks:hooks_test)"
cd internal/hooks
# Same selector and count guard as pr.yml's job.
test_status=0
# wasm_exec.js caps argv+env size; the Blacksmith runner's environment
# exceeds it, so run with only what the hook test needs.
wasm_exec="$(go env GOROOT)/lib/wasm/go_js_wasm_exec"
test_output="$(env -i PATH="$PATH" HOME="$HOME" TMPDIR="$RUNNER_TEMP" \
BD_DISABLE_METRICS=1 BD_DISABLE_EVENT_FLUSH=1 \
"$wasm_exec" "$GITHUB_WORKSPACE/$bin" \
-test.run '^TestRunHookReportsUnsupportedExecution$' \
-test.v 2>&1)" || test_status=$?
printf '%s\n' "$test_output"
(( test_status == 0 )) || exit "$test_status"
run_count=0
pass_count=0
nonpass_count=0
pass_pattern='^--- PASS: TestRunHookReportsUnsupportedExecution \([0-9.]+s\)$'
nonpass_pattern='^[[:space:]]*--- (FAIL|SKIP): '
while IFS= read -r line; do
if [[ "$line" == "=== RUN TestRunHookReportsUnsupportedExecution" ]]; then
((run_count += 1))
fi
if [[ "$line" =~ $pass_pattern ]]; then
((pass_count += 1))
fi
if [[ "$line" =~ $nonpass_pattern ]]; then
((nonpass_count += 1))
fi
done <<< "$test_output"
if (( run_count != 1 || pass_count != 1 || nonpass_count != 0 )); then
printf 'expected one exact js/wasm hook test run and pass with no failures or skips; got runs=%s passes=%s nonpasses=%s\n' \
"$run_count" "$pass_count" "$nonpass_count" >&2
exit 1
fi
- name: Build cmd/bd and pure-Go test binaries (--config=pure)
run: >-
bazel build --config=pure
//cmd/bd:bd
//cmd/bd:bd_test
//internal/storage/embeddeddolt:embeddeddolt_test
//internal/tracker:tracker_test
# `go build` with CGO_ENABLED=0 rejects a pure binary whose imports reach
# dolt's cgo-only store/nbs (gozstd). Bazel compiles gozstd's pure stubs
# instead, whose init panics (third_party/patches/gozstd_nocgo.patch), so
# the check happens here: every pure artifact is started once. bd_test
# starts in the next step. -test.run=^$ runs no test (TestMain still
# runs; BEADS_TEST_SKIP=dolt keeps tracker's from starting a container).
- name: Start every pure-Go artifact (gozstd contamination check)
run: |
set -euo pipefail
bazel run --config=pure //cmd/bd:bd -- version
bazel test --config=pure \
//internal/storage/embeddeddolt:embeddeddolt_test \
//internal/tracker:tracker_test \
--test_sharding_strategy=disabled \
'--test_arg=-test.run=^$' \
--test_env=BEADS_TEST_SKIP=dolt
# One unsharded process, like `go test -run`; the test.xml check keeps a
# selector that matches nothing from passing.
- name: Run pure-Go cmd/bd test subset (--config=pure)
run: |
set -euo pipefail
bazel test --config=pure //cmd/bd:bd_test \
--test_sharding_strategy=disabled \
"--test_arg=-test.run=$PURE_CMD_BD_TESTS"
n="$(grep -c '<testcase ' bazel-testlogs/cmd/bd/bd_test/test.xml || true)"
echo "pure cmd/bd subset: $n test cases"
(( n > 0 ))
# Last step: the job's result as a workflow_call output for pr.yml's
# ci-gate. always() runs it after a failure, a timeout or a
# cancellation too.
- name: Record job result
id: result
if: ${{ always() }}
env:
JOB_STATUS: ${{ job.status }}
run: echo "result=$JOB_STATUS" >> "$GITHUB_OUTPUT"
# pr-risk.yml's embedded-Dolt tier ("Test (Embedded Dolt Cmd N/20)",
# "Test (Embedded Dolt Storage N/5)", "Test (Embedded Dolt Conformance -
# core/audit)") as --config=embedded: the embedded-tagged variants of
# //cmd/bd:bd_test and //internal/storage/embeddeddolt:embeddeddolt_test.
# The shard variants run the jobs' own shard scripts and manifests, so Bazel
# shard k runs exactly the tests of job k. A job of its own rather than a
# second invocation in bazel-test: the tier's long race shards stay off
# bazel-test's critical path and budget, and it compiles nothing bazel-test
# does not (same race configuration, shared through the remote cache).
bazel-embedded:
name: embedded Dolt tier
# Remote execution only: skipped unless the rbe job chose remote (no
# fork, rbe=off or secret-less run). Locally the tier is 27 race test
# processes (~7-10k test-seconds) on one runner, an hour or more per run
# on the pool whose job cap this track exists to relieve, and it proves
# nothing pr-risk.yml's embedded jobs (which do run for forks) do not.
# The runs-on expression is the shared one and always picks the
# Blacksmith runner under this if.
needs: rbe
runs-on: ${{ needs.rbe.outputs.enabled == 'true' && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}
if: ${{ needs.rbe.outputs.enabled == 'true' }}
timeout-minutes: 60
outputs:
result: ${{ steps.result.outputs.result }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Bazel
id: bazel
uses: ./.github/actions/setup-bazel
env:
BAZEL_REMOTE_EXECUTOR: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_WEST_EXECUTOR || '' }}
RBE_TLS_CERT: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_CERT || '' }}
RBE_TLS_KEY: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_KEY || '' }}
RBE_TLS_CA: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_CA || '' }}
RBE_INSTANCE: ${{ needs.rbe.outputs.enabled == 'true' && 'oss' || '' }}
# --build_event_json_file is a command option, so it goes after `test`.
- name: bazel test //... --config=embedded
id: test
timeout-minutes: 50
run: |
set -o pipefail
start=$(date +%s)
rc=0
bazel test //... --config=embedded \
--build_event_json_file="$RUNNER_TEMP/bazel-bep.json" \
2>&1 | tee "$RUNNER_TEMP/bazel-test.log" || rc=$?
echo "bazel test --config=embedded: exit $rc, $(( $(date +%s) - start ))s wall" | tee -a "$GITHUB_STEP_SUMMARY"
exit "$rc"
# A shard the manifest assigns nothing, or a selector that matches
# nothing, exits 0: fail if any target's or shard's test.xml lists no
# tests (or is missing).
- name: Every target and shard ran tests
if: ${{ always() && steps.test.outcome != 'skipped' }}
run: python3 tools/bazel/check_testcases.py --bep "$RUNNER_TEMP/bazel-bep.json"
- name: Upload test logs
if: ${{ failure() && steps.test.outcome != 'skipped' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: bazel-embedded-testlogs
path: |
bazel-testlogs/**/test.log
bazel-testlogs/**/test.xml
if-no-files-found: ignore
retention-days: 7
# Last step: the job's result as a workflow_call output for pr.yml's
# ci-gate. always() runs it after a failure, a timeout or a
# cancellation too.
- name: Record job result
id: result
if: ${{ always() }}
env:
JOB_STATUS: ${{ job.status }}
run: echo "result=$JOB_STATUS" >> "$GITHUB_OUTPUT"
# main.yml's "Main Linux integration packages (N/6)" and "Main Linux
# integration cmd/bd (N/8)" jobs (nightly.yml's Full Test Suite runs the
# same go test in one job) as --config=integration: every package with
# -tags=integration,gms_pure_go, race, no -short, BEADS_TEST_SKIP=dolt (see
# .bazelrc). A job of its own: ci and integration share bazel-testlogs, so
# bazel-test's equivalence step would read this lane's test.xml if both ran
# in one job, and the tagged race build is a second full compile.
# No equivalence step: equivalence.py's default mode is the --config=ci
# selection (go list without the integration tag, -short, ^TestEmbedded
# skipped), and its job mode needs the integration jobs' go test -json,
# which no run here has. check_testcases.py still catches a target or
# shard that ran no tests.
bazel-integration:
name: integration (advisory)
# Remote execution only, like bazel-embedded: locally the tagged race
# build of //... plus 14 jobs' worth of tests on one runner is well over
# the timeout, for tests main.yml's integration jobs already run. Off in
# pr.yml's call (integration: "off"), as those jobs are off on PRs.
needs: rbe
runs-on: ${{ needs.rbe.outputs.enabled == 'true' && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}
if: ${{ needs.rbe.outputs.enabled == 'true' && inputs.integration != 'off' }}
timeout-minutes: 40
outputs:
result: ${{ steps.result.outputs.result }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Bazel
id: bazel
uses: ./.github/actions/setup-bazel
env:
BAZEL_REMOTE_EXECUTOR: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_WEST_EXECUTOR || '' }}
RBE_TLS_CERT: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_CERT || '' }}
RBE_TLS_KEY: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_KEY || '' }}
RBE_TLS_CA: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_CA || '' }}
RBE_INSTANCE: ${{ needs.rbe.outputs.enabled == 'true' && 'oss' || '' }}
# Remote: a cold compile plus the longest test action (1200s cap, see
# .bazelrc) fits well inside 30 minutes.
- name: bazel test //... --config=integration
id: test
timeout-minutes: 30
run: |
set -o pipefail
start=$(date +%s)
rc=0
bazel test //... --config=integration \
--build_event_json_file="$RUNNER_TEMP/bazel-bep.json" \
2>&1 | tee "$RUNNER_TEMP/bazel-test.log" || rc=$?
echo "bazel test --config=integration: exit $rc, $(( $(date +%s) - start ))s wall" | tee -a "$GITHUB_STEP_SUMMARY"
exit "$rc"
# As in bazel-embedded. dolt_version_test is a plain sh_test (no Go
# testcases in its test.xml), which --config=integration's tag filter
# keeps, unlike the embedded one.
- name: Every target and shard ran tests
if: ${{ always() && steps.test.outcome != 'skipped' }}
run: python3 tools/bazel/check_testcases.py --bep "$RUNNER_TEMP/bazel-bep.json" --not-go //tools/bazel:dolt_version_test
- name: Upload test logs
if: ${{ failure() && steps.test.outcome != 'skipped' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: bazel-integration-testlogs
path: |
bazel-testlogs/**/test.log
bazel-testlogs/**/test.xml
if-no-files-found: ignore
retention-days: 7
# Last step: the job's result as a workflow_call output (for
# symmetry; pr.yml's call turns this lane off).
- name: Record job result
id: result
if: ${{ always() }}
env:
JOB_STATUS: ${{ job.status }}
run: echo "result=$JOB_STATUS" >> "$GITHUB_OUTPUT"
# pr.yml's container-backed jobs, "Test (storage domain + uow)" and
# "Contract corpus", as Bazel's dolt-server lane: --config=doltserver runs
# the dolt-server variants (domain/..., uow in 8 shards, tracker/...,
# doctor/fix, protocol in 8 shards), each of which starts its own dolt
# sql-server from the pinned dolt, so they execute on the remote workers
# like any other test (locally for forks and rbe=off). The docker lane
# (--config=docker: the same suites against testcontainers on this runner,
# no-remote-exec) stays the A/B control: dispatch with dolt-lane=docker.
bazel-doltserver:
name: dolt-server lane
# Same runner and skip rule as bazel-test.
needs: rbe
runs-on: ${{ needs.rbe.outputs.enabled == 'true' && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}
if: ${{ needs.rbe.outputs.mode != 'skip' }}
timeout-minutes: 90
outputs:
result: ${{ steps.result.outputs.result }}
env:
BAZEL_DOLT_LANE: ${{ inputs.dolt-lane || 'doltserver' }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Bazel
id: bazel
uses: ./.github/actions/setup-bazel
env:
BAZEL_REMOTE_EXECUTOR: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_WEST_EXECUTOR || '' }}
RBE_TLS_CERT: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_CERT || '' }}
RBE_TLS_KEY: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_KEY || '' }}
RBE_TLS_CA: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_CA || '' }}
RBE_INSTANCE: ${{ needs.rbe.outputs.enabled == 'true' && 'oss' || '' }}
# Docker lane only (the A/B control), as in the mirrored jobs; its
# tests fail rather than skip without the image.
- name: Pull Dolt sql-server image
if: ${{ env.BAZEL_DOLT_LANE == 'docker' }}
run: ./scripts/ci/pull-dolt-image.sh
- name: bazel test //... --config=doltserver
id: test
timeout-minutes: 80
run: |
set -o pipefail
start=$(date +%s)
rc=0
bazel test //... "--config=$BAZEL_DOLT_LANE" 2>&1 | tee "$RUNNER_TEMP/bazel-test.log" || rc=$?
echo "bazel test --config=$BAZEL_DOLT_LANE: exit $rc, $(( $(date +%s) - start ))s wall" | tee -a "$GITHUB_STEP_SUMMARY"
exit "$rc"
- name: Upload test logs
if: ${{ failure() && steps.test.outcome == 'failure' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: bazel-${{ env.BAZEL_DOLT_LANE }}-testlogs
path: |
bazel-testlogs/**/test.log
bazel-testlogs/**/test.xml
if-no-files-found: ignore
retention-days: 7
# Last step: the job's result as a workflow_call output for pr.yml's
# ci-gate. always() runs it after a failure, a timeout or a
# cancellation too.
- name: Record job result
id: result
if: ${{ always() }}
env:
JOB_STATUS: ${{ job.status }}
run: echo "result=$JOB_STATUS" >> "$GITHUB_OUTPUT"
# pr-risk.yml's proxied-server tier, "Test (Proxied Dolt Cmd N/15)", as
# --config=doltserver-proxied: //cmd/bd:bd_proxied_test runs the job's
# shard script in 15 Bazel shards, so shard k runs exactly job k's tests.
# Same build as --config=doltserver (race bd_test, non-race bd_for_tests),
# shared with bazel-doltserver through the remote cache. PR Risk builds
# its bd-cmd-test with -race, as here; main.yml's test-proxied-cmd twin
# uses build-artifacts' non-race bd-cmd-test, so this lane is the stricter
# of the two. A job of its own, not gated by any integration switch: it
# runs in pr.yml's call and its gate requires it (BAZEL_PROXIED).
bazel-proxied:
name: proxied-server tier
# Remote execution only, like bazel-embedded: 15 shards of ~5-10
# minutes, each with a dolt sql-server busy on ~4 cores, do not fit a
# GitHub-hosted runner.
needs: rbe
runs-on: ${{ needs.rbe.outputs.enabled == 'true' && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}
if: ${{ needs.rbe.outputs.enabled == 'true' }}
timeout-minutes: 30
outputs:
result: ${{ steps.result.outputs.result }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Bazel
id: bazel
uses: ./.github/actions/setup-bazel
env:
BAZEL_REMOTE_EXECUTOR: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_WEST_EXECUTOR || '' }}
RBE_TLS_CERT: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_CERT || '' }}
RBE_TLS_KEY: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_KEY || '' }}
RBE_TLS_CA: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_CA || '' }}
RBE_INSTANCE: ${{ needs.rbe.outputs.enabled == 'true' && 'oss' || '' }}
# Remote: the longest shard takes ~5-8 minutes (each shard's Go
# timeout is its job's 15m, 1200s Bazel cap), plus a compile.
- name: bazel test //... --config=doltserver-proxied
id: test
timeout-minutes: 25
run: |
set -o pipefail
start=$(date +%s)
rc=0
bazel test //... --config=doltserver-proxied \
--build_event_json_file="$RUNNER_TEMP/bazel-bep.json" \
2>&1 | tee "$RUNNER_TEMP/bazel-test.log" || rc=$?
echo "bazel test --config=doltserver-proxied: exit $rc, $(( $(date +%s) - start ))s wall" | tee -a "$GITHUB_STEP_SUMMARY"
exit "$rc"
# As in bazel-embedded.
- name: Every target and shard ran tests
if: ${{ always() && steps.test.outcome != 'skipped' }}
run: python3 tools/bazel/check_testcases.py --bep "$RUNNER_TEMP/bazel-bep.json"
- name: Upload test logs
if: ${{ failure() && steps.test.outcome != 'skipped' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: bazel-proxied-testlogs
path: |
bazel-testlogs/**/test.log
bazel-testlogs/**/test.xml
if-no-files-found: ignore
retention-days: 7
# Last step: the job's result as a workflow_call output for pr.yml's
# ci-gate. always() runs it after a failure, a timeout or a
# cancellation too.
- name: Record job result
id: result
if: ${{ always() }}
env:
JOB_STATUS: ${{ job.status }}
run: echo "result=$JOB_STATUS" >> "$GITHUB_OUTPUT"
# pr-risk.yml's server-Dolt storage tier, "Test (Server Dolt Conformance)"
# and "Test (Server Dolt Full Suite N/16)", as --config=doltserver-integration:
# the conformance and 16-shard full-suite variants of
# //internal/storage/dolt over a non-race dolt_test build, each shard
# running the job's own shard script. --config=doltserver-integration has
# exactly --config=integration's build flags, so it compiles nothing
# bazel-integration does not (shared through the remote cache). A job of
# its own, not gated by any integration switch: this is a PR-time tier,
# unlike main.yml's integration jobs, and pr.yml's gate requires it
# (BAZEL_SERVER_STORAGE).
bazel-server-storage:
name: server-Dolt storage tier
# Remote execution only, like bazel-integration: locally the tagged race
# build of //... alone is most of the timeout.
needs: rbe
runs-on: ${{ needs.rbe.outputs.enabled == 'true' && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}
if: ${{ needs.rbe.outputs.enabled == 'true' }}
timeout-minutes: 30
outputs:
result: ${{ steps.result.outputs.result }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- name: Set up Bazel
id: bazel
uses: ./.github/actions/setup-bazel
env:
BAZEL_REMOTE_EXECUTOR: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_WEST_EXECUTOR || '' }}
RBE_TLS_CERT: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_CERT || '' }}
RBE_TLS_KEY: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_KEY || '' }}
RBE_TLS_CA: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_CA || '' }}
RBE_INSTANCE: ${{ needs.rbe.outputs.enabled == 'true' && 'oss' || '' }}
# Remote: the longest shard takes ~2-3 minutes (the storage suite's Go
# timeout is 15m per shard, 1200s Bazel cap), plus a compile.
- name: bazel test //... --config=doltserver-integration
id: test
timeout-minutes: 25
run: |
set -o pipefail
start=$(date +%s)
rc=0
bazel test //... --config=doltserver-integration \
--build_event_json_file="$RUNNER_TEMP/bazel-bep.json" \
2>&1 | tee "$RUNNER_TEMP/bazel-test.log" || rc=$?
echo "bazel test --config=doltserver-integration: exit $rc, $(( $(date +%s) - start ))s wall" | tee -a "$GITHUB_STEP_SUMMARY"
exit "$rc"
# As in bazel-embedded.
- name: Every target and shard ran tests
if: ${{ always() && steps.test.outcome != 'skipped' }}
run: python3 tools/bazel/check_testcases.py --bep "$RUNNER_TEMP/bazel-bep.json"
- name: Upload test logs
if: ${{ failure() && steps.test.outcome != 'skipped' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: bazel-server-storage-testlogs
path: |
bazel-testlogs/**/test.log
bazel-testlogs/**/test.xml
if-no-files-found: ignore
retention-days: 7
# Last step: the job's result as a workflow_call output for pr.yml's
# ci-gate. always() runs it after a failure, a timeout or a
# cancellation too.
- name: Record job result
id: result
if: ${{ always() }}
env:
JOB_STATUS: ${{ job.status }}
run: echo "result=$JOB_STATUS" >> "$GITHUB_OUTPUT"

View file

@ -11,9 +11,15 @@
# never checks out or executes PR code. It checks out the base default branch
# for scripts, and treats the artifact strictly as data: every path in the
# patch must match an anchored generated-docs allowlist (single path segment,
# no traversal, no symlink modes) and `git apply --index` supplies the
# underlying escape guards (scripts/docs-autofix-push.sh), so a hostile patch
# can at most rewrite generated doc files on its own PR branch.
# no traversal), mode/symlink/rename/copy/binary hunks are refused, and the
# patch is applied to an index in a bare clone and re-checked once staged
# (scripts/docs-autofix-push.sh), so a hostile patch can at most rewrite
# generated doc files on its own PR branch. Pushes are leased to the run's
# head SHA and skipped for heads that are protected or under a ruleset.
#
# CONCURRENCY: job-level, shared with bazel-autofix.yml per head branch and
# without cancel-in-progress, so the two bots queue instead of racing on one
# branch (see bazel-autofix.yml).
#
# TOKEN NOTE: pushes made with the default GITHUB_TOKEN do not retrigger PR
# checks. Configure a DOCS_AUTOFIX_TOKEN repo secret (fine-grained PAT or
@ -34,10 +40,6 @@ permissions:
pull-requests: write
actions: read
concurrency:
group: docs-autofix-${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: true
jobs:
autofix:
name: Apply CLI docs regeneration to PR
@ -45,9 +47,18 @@ jobs:
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'failure'
runs-on: ubuntu-latest
# Bounded: a hung run would hold the shared group for the default 6h.
timeout-minutes: 10
# Shared with bazel-autofix.yml; queue, never cancel.
concurrency:
group: autofix-${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: false
steps:
# Trusted side only: base repo default branch, never the PR head.
# Trusted side only: base repo default branch, never the PR head. The
# workflow token is not left in .git/config.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
with:
persist-credentials: false
- name: Download docs freshness patch (if any)
id: patch
@ -63,9 +74,22 @@ jobs:
echo "found=false" >> "$GITHUB_OUTPUT"
exit 0
fi
gh api "repos/${GITHUB_REPOSITORY}/actions/artifacts/${artifact_id}/zip" > patch.zip
unzip -o patch.zip -d "${RUNNER_TEMP}/docs-patch"
ls -la "${RUNNER_TEMP}/docs-patch"
dir="${RUNNER_TEMP}/docs-patch"
mkdir -p "$dir"
gh api "repos/${GITHUB_REPOSITORY}/actions/artifacts/${artifact_id}/zip" > "${RUNNER_TEMP}/docs-patch.zip"
# Extract only the expected name, and only as a regular file.
unzip -o "${RUNNER_TEMP}/docs-patch.zip" cli-docs-freshness.patch -d "$dir" || true
ls -la "$dir"
f="$dir/cli-docs-freshness.patch"
if [ -L "$f" ] || { [ -e "$f" ] && [ ! -f "$f" ]; }; then
echo "::error::artifact entry cli-docs-freshness.patch is not a regular file"
exit 1
fi
if [ ! -f "$f" ]; then
echo "Artifact has no cli-docs-freshness.patch; nothing to do."
echo "found=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "found=true" >> "$GITHUB_OUTPUT"
- name: Push regen commit or leave apply recipe

View file

@ -445,8 +445,8 @@ jobs:
run: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.10.1
# No BD_LINT_NEW_FROM_MERGE_BASE here: the push lane sweeps the whole
# tree, including the GOOS=windows cross-lint. pr.yml scopes the same
# wrapper to the PR's own diff.
# tree, including the GOOS=windows and GOOS=darwin cross-lints. pr.yml
# scopes the same wrapper to the PR's own diff.
- name: Run PR lint wrapper
run: make ci-pr-lint

View file

@ -96,14 +96,19 @@ jobs:
retention-days: 7
# Bazel lane with the full go test equivalence listing and the skip-parity
# check (advisory, like the PR run). Remote execution when the repo secrets
# are present.
# check (reported here; PRs gate on it through pr.yml). Remote execution
# when the repo secrets are present; bazel.yml gets those four and nothing
# else.
bazel:
name: Bazel equivalence (full detail)
needs: bazel-go-test-json
if: ${{ !cancelled() && (github.event_name == 'schedule' || inputs.suite == 'bazel') }}
uses: ./.github/workflows/bazel.yml
secrets: inherit
secrets:
RBE_WEST_EXECUTOR: ${{ secrets.RBE_WEST_EXECUTOR }}
RBE_TLS_CERT: ${{ secrets.RBE_TLS_CERT }}
RBE_TLS_KEY: ${{ secrets.RBE_TLS_KEY }}
RBE_TLS_CA: ${{ secrets.RBE_TLS_CA }}
with:
details: true
go-test-json-artifact: bazel-equivalence-go-test-json

View file

@ -452,7 +452,7 @@ jobs:
echo "Help text first line is correct"
ci-gate:
name: CI Gate / Required
name: PR Risk Gate / Required
runs-on: ubuntu-latest
needs:
- detect-ci-tier

View file

@ -486,6 +486,13 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- os: ubuntu-latest
expected_goos: linux
- os: macos-latest
expected_goos: darwin
- os: windows-latest
expected_goos: windows
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
@ -507,6 +514,12 @@ jobs:
shell: bash
run: go test '-tags=integration,gms_pure_go' -count=1 -run '^TestPRPreflight' ./scripts
- name: Check native user config diagnostics
shell: bash
env:
CGO_ENABLED: "0"
run: bash scripts/ci/test-user-config-diagnostic.sh '${{ matrix.expected_goos }}'
- name: Exercise test.sh prebuilt binary path
shell: bash
run: go test '-tags=gms_pure_go' -count=1 -run '^TestTestScriptPrebuiltBinaryContract$' ./scripts
@ -877,6 +890,15 @@ jobs:
sha256sum -c SHA256SUMS
chmod +x bd-linux-gms-pure
# The only lane with both the image and the pinned dolt CLI: compares
# the container and the local test server backend against the one
# checked-in fingerprint, so an image bump cannot drift the container
# side unnoticed. REQUIRE makes the container half fail, not skip.
- name: Test Dolt server fingerprint (container + local)
env:
BEADS_TEST_REQUIRE_DOLT_CONTAINER: "1"
run: go test -tags gms_pure_go -count=1 -timeout 5m -v -run '^TestDoltServerFingerprint$' ./internal/testutil/
- name: Test domain + uow + tracker
env:
BEADS_TEST_BD_BINARY: ${{ github.workspace }}/ci-build-artifacts/bd-linux-gms-pure
@ -1207,14 +1229,63 @@ jobs:
$proofRoot = Join-Path $env:RUNNER_TEMP ("make install proof " + [guid]::NewGuid().ToString('N'))
$fixtureRepo = Join-Path $proofRoot 'fixture repo'
$buildDir = Join-Path $fixtureRepo 'build output'
$fakeGoDir = Join-Path $proofRoot 'fake go bin'
$installRoot = Join-Path $proofRoot 'install sandbox'
$installProfile = Join-Path $installRoot 'profile with spaces'
New-Item -ItemType Directory -Force -Path $buildDir, $installProfile | Out-Null
New-Item -ItemType Directory -Force -Path $buildDir, $fakeGoDir, $installProfile | Out-Null
Copy-Item -LiteralPath (Join-Path $env:GITHUB_WORKSPACE 'Makefile') -Destination $fixtureRepo
Copy-Item -LiteralPath (Join-Path $env:GITHUB_WORKSPACE 'go.mod') -Destination $fixtureRepo
$sentinel = Join-Path $buildDir 'bd.exe'
Set-Content -LiteralPath $sentinel -Encoding ascii -NoNewline -Value 'native-install-sentinel'
$fakeGo = Join-Path $fakeGoDir 'go'
$fakeGoScript = @'
#!/usr/bin/env bash
set -euo pipefail
[[ "${1-}" == build ]] || exit 91
shift
output=
while (($#)); do
case "$1" in
-o)
[[ $# -ge 2 ]] || exit 92
output=$2
shift 2
;;
*) shift ;;
esac
done
[[ "$(cygpath -aw "$output")" == "$(cygpath -aw "$BEADS_FAKE_GO_EXPECTED_OUTPUT")" ]] || {
printf 'fake go received output %q, expected %q\n' "$output" "$BEADS_FAKE_GO_EXPECTED_OUTPUT" >&2
exit 93
}
printf native-build-sentinel > "$(cygpath -u "$output")"
'@
if (-not $fakeGoScript.StartsWith('#!', [StringComparison]::Ordinal)) {
throw 'Fake Go shebang must start at byte zero after YAML extraction'
}
[IO.File]::WriteAllText(
$fakeGo,
($fakeGoScript -replace "`r`n", "`n"),
[Text.UTF8Encoding]::new($false)
)
$priorPath = $env:PATH
Push-Location $fixtureRepo
try {
$env:BEADS_FAKE_GO_EXPECTED_OUTPUT = $sentinel
$env:PATH = "$fakeGoDir;$priorPath"
& $make --no-print-directory "BUILD_DIR=$buildDir" GIT_BUILD=build-proof CC=proof build
if ($LASTEXITCODE -ne 0) {
throw 'Native Make build failed for a spaced BUILD_DIR'
}
} finally {
$env:PATH = $priorPath
Remove-Item -LiteralPath Env:BEADS_FAKE_GO_EXPECTED_OUTPUT
Pop-Location
}
if (-not (Test-Path -LiteralPath $sentinel -PathType Leaf)) {
throw "Native Make did not build bd.exe at the exact spaced destination '$sentinel'"
}
$sentinelHash = (Get-FileHash -LiteralPath $sentinel -Algorithm SHA256).Hash
& $git -C $fixtureRepo init --quiet
@ -1363,6 +1434,31 @@ jobs:
throw 'Cygwin Make shell smoke failed'
}
# The Bazel lane (bazel.yml), gated alongside the legacy jobs it mirrors
# (PR Core, build-artifacts, the pure-Go/js-wasm check, domain+uow and
# contract corpus, and pr-risk.yml's embedded-Dolt, proxied-server and
# server-Dolt storage tiers), all of which stay required. bazel.yml has no pull_request/merge_group trigger of its own:
# this call is its only PR run. It gets the four RBE secrets and nothing
# else; its rbe job decides remote, local (forks, Dependabot: no
# remote-only lanes) or skip, and exports that for ci-gate. Its
# bazel-integration lane is off here (main.yml's integration jobs, its
# legacy counterpart, run only on push to main; bazel.yml runs it there).
# Its bd artifact is renamed so it cannot collide with build-artifacts'
# upload.
bazel:
name: Bazel
permissions:
contents: read
uses: ./.github/workflows/bazel.yml
secrets:
RBE_WEST_EXECUTOR: ${{ secrets.RBE_WEST_EXECUTOR }}
RBE_TLS_CERT: ${{ secrets.RBE_TLS_CERT }}
RBE_TLS_KEY: ${{ secrets.RBE_TLS_KEY }}
RBE_TLS_CA: ${{ secrets.RBE_TLS_CA }}
with:
build-artifact-name: bazel-ci-build-artifacts
integration: "off"
ci-gate:
name: CI Gate / Required
runs-on: ubuntu-latest
@ -1389,6 +1485,7 @@ jobs:
- fmt-check
- lint
- windows-make-shell
- bazel
if: ${{ always() }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
@ -1419,6 +1516,13 @@ jobs:
FMT_CHECK
LINT
WINDOWS_MAKE_SHELL
BAZEL
BAZEL_TEST
BAZEL_PURE
BAZEL_EMBEDDED
BAZEL_DOLTSERVER
BAZEL_PROXIED
BAZEL_SERVER_STORAGE
BUILD_ARTIFACTS: ${{ needs.build-artifacts.result }}
CHECK_BUILD_TAGS: ${{ needs.check-build-tags.result }}
CHECK_CMD_BD_PUREGEO_TESTS: ${{ needs.check-cmd-bd-puregeo-tests.result }}
@ -1441,10 +1545,32 @@ jobs:
FMT_CHECK: ${{ needs.fmt-check.result }}
LINT: ${{ needs.lint.result }}
WINDOWS_MAKE_SHELL: ${{ needs.windows-make-shell.result }}
# bazel.yml's lanes report their job.status as outputs; a lane that
# did not report (skipped, or lost before its last step) reads as
# skipped, which passes only in the modes bazel-gate.sh allows.
BAZEL_TEST: ${{ needs.bazel.outputs.bazel-test || 'skipped' }}
BAZEL_PURE: ${{ needs.bazel.outputs.bazel-pure || 'skipped' }}
BAZEL_EMBEDDED: ${{ needs.bazel.outputs.bazel-embedded || 'skipped' }}
BAZEL_DOLTSERVER: ${{ needs.bazel.outputs.bazel-doltserver || 'skipped' }}
BAZEL_PROXIED: ${{ needs.bazel.outputs.bazel-proxied || 'skipped' }}
BAZEL_SERVER_STORAGE: ${{ needs.bazel.outputs.bazel-server-storage || 'skipped' }}
# Inputs of bazel-gate.sh, which sets BAZEL (the call's aggregate,
# red on a missing or inconsistent mode) and the expected skips
# from bazel.yml's own rbe job decision.
BAZEL_CALL: ${{ needs.bazel.result }}
BAZEL_RBE_MODE: ${{ needs.bazel.outputs.rbe-mode }}
BAZEL_RBE_ENABLED: ${{ needs.bazel.outputs.rbe-enabled }}
run: |
skipped_ok=""
if [[ "$GITHUB_EVENT_NAME" == "merge_group" ]]; then
skipped_ok="CHECK_NO_BEADS_CHANGES"
fi
# Bazel lanes skipped by design in the call's execution mode (all
# of them in mode skip, the remote-only embedded, proxied and
# server-storage tiers in mode local), and the aggregate unless the
# mode is missing or invalid.
skipped_ok="$skipped_ok $(bash .github/scripts/bazel-gate.sh skips)"
BAZEL="$(bash .github/scripts/bazel-gate.sh aggregate)"
export BAZEL
export CI_GATE_SKIPPED_OK="$skipped_ok"
bash .github/scripts/ci-gate.sh

View file

@ -23,6 +23,7 @@ on:
- 'cmd/bd/proxied_server*.go'
- 'cmd/bd/dolt*.go'
- 'cmd/bd/*_proxied_server.go'
- 'cmd/bd/backup*.go'
- 'cmd/bd/purge*.go'
- 'cmd/bd/*managed_local*'
- 'cmd/bd/proxied_outage_reconnect_integration_test.go'
@ -50,6 +51,7 @@ on:
- 'cmd/bd/proxied_server*.go'
- 'cmd/bd/dolt*.go'
- 'cmd/bd/*_proxied_server.go'
- 'cmd/bd/backup*.go'
- 'cmd/bd/purge*.go'
- 'cmd/bd/*managed_local*'
- 'cmd/bd/proxied_outage_reconnect_integration_test.go'
@ -128,7 +130,11 @@ jobs:
TestManagedLocalProxiedDoltStartRefusesWithProxyDown \
TestManagedLocalProxiedDoltLifecycleLeavesOtherTopologiesAlone \
TestManagedLocalProxiedTrackerUOWConformance \
TestManagedLocalProxiedPurgeWispsPlaneRetention
TestManagedLocalProxiedBackupRoundTrip \
TestManagedLocalProxiedAutoBackup \
TestManagedLocalProxiedBackupRestoreRefusedWhileAttached \
TestManagedLocalProxiedPurgeWispsPlaneRetention \
TestManagedLocalProxiedBackendCleanExitRetiresProxy
do
if ! grep -qx "$test_name" <<<"$listed"; then
echo "managed-local lifecycle test $test_name is missing; got: '$listed'" >&2

View file

@ -77,7 +77,7 @@ jobs:
needs: detect-regression-need
if: needs.detect-regression-need.outputs.run_regression == 'true'
runs-on: ubuntu-latest
timeout-minutes: 25
timeout-minutes: 45
steps:
- name: Show regression trigger reason
run: echo "${{ needs.detect-regression-need.outputs.reason }}"
@ -117,5 +117,17 @@ jobs:
path: ~/.cache/beads-regression
key: regression-baseline-${{ hashFiles('tests/regression/BASELINE_VERSION') }}
# Passing-side wall time already overlapped the go deadline below, so
# ordinary GitHub-runner speed variance -- not a real hang -- was
# tripping this step. Measured over the 100 most recent Regression
# Tests runs (2026-09-03/04, ~29.5h): p50 593s (~10m), max passing
# 1189s (~19.8m) against the prior 1200s (20m) cap, and 5 runs in that
# window hit the identical `panic: test timed out after 20m0s` with
# zero `--- FAIL` lines -- a budget defect, not a regression. Match
# main.yml's Test job fix for the same failure mode: raise the go
# deadline to cover the observed slowdown and keep it inside a larger
# finite job budget (see timeout-minutes above), so the go deadline
# fires first and prints goroutine stacks -- a REAL hang stays
# diagnosable instead of being cut off by a bare job kill.
- name: Run regression tests
run: go test -tags=regression,gms_pure_go -timeout=20m -v ./tests/regression/...
run: go test -tags=regression,gms_pure_go -timeout=40m -v ./tests/regression/...

View file

@ -87,7 +87,13 @@ test runs if `du -sh /tmp/beads-* /tmp/bd-*` shows accumulation. See bd-3q2u.
2. **Run the required lint contract when its code surface changed**:
`make ci-pr-lint`
3. **Update docs**: If you changed behavior, update README.md or other docs
4. **Commit**: With git hooks installed (`bd hooks install`), Dolt changes are auto-committed
4. **Sync Bazel BUILD files** if you added, removed or renamed Go files, or
changed imports or `go.mod`: `make bazel-sync` (needs Bazel), then commit
the BUILD.bazel / MODULE.bazel changes. Without Bazel, let CI do it: on
same-repo PRs the bazel-autofix workflow pushes the fix for the packages
your PR changed to your branch (pull before pushing again); fork PRs get
a comment with an apply recipe.
5. **Commit**: With git hooks installed (`bd hooks install`), Dolt changes are auto-committed
### Commit Message Convention

View file

@ -2,7 +2,11 @@ load("@gazelle//:def.bzl", "gazelle")
load("@rules_go//go:def.bzl", "go_library", "go_test")
# gazelle:prefix github.com/steveyegge/beads
# gazelle:build_tags gms_pure_go
# gazelle drops files whose build constraints name a tag it does not know.
# integration is listed so the `//go:build integration` test files (and
# //internal/testutil/integration) are in srcs and deps; rules_go filters them
# out of every build except --config=integration (.bazelrc), which sets the tag.
# gazelle:build_tags gms_pure_go,integration
# integrations/ holds no Go; it stays visible to Bazel (not in .bazelignore)
# only so //test/docsync can declare the markdown its link checks resolve.
# gazelle:exclude integrations
@ -73,6 +77,31 @@ filegroup(
visibility = ["//scripts:__pkg__"],
)
# PR Risk's manifest-sharded tiers' shard scripts and their committed
# manifests (embedded-Dolt cmd and storage, proxied-server cmd, server-Dolt
# storage). The variants (//cmd/bd:bd_embedded_test, //cmd/bd:bd_proxied_test,
# //internal/storage/embeddeddolt:embeddeddolt_embedded_test,
# //internal/storage/dolt:dolt_server_full_test) run them through
# tools/bazel/go_test_manifest_shard.sh, so each Bazel shard runs exactly the
# tests of the CI job with the same shard number.
exports_files(
[
".github/scripts/embedded-cmd-test-shards.txt",
".github/scripts/embedded-storage-test-shard.sh",
".github/scripts/embedded-storage-test-shards.txt",
".github/scripts/embedded-test-shard.sh",
".github/scripts/proxied-cmd-test-shards.txt",
".github/scripts/proxied-test-shard.sh",
".github/scripts/server-storage-test-shard.sh",
".github/scripts/server-storage-test-shards.txt",
],
visibility = [
"//cmd/bd:__pkg__",
"//internal/storage/dolt:__pkg__",
"//internal/storage/embeddeddolt:__pkg__",
],
)
# //scripts:scripts_test runs scripts/test.sh, which sources the canonical
# build flags and reads the known-broken-test skip list.
filegroup(

View file

@ -9,6 +9,87 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- **The #6716 fan-in stall is fixed on the proxied-server route and the
remaining store routes.** Two blockers of one dependent taken away at the
same time (parallel workers closing both, or a close racing a
`bd dep remove` or a delete of the other) could leave the dependent
`is_blocked=1` and missing from `bd ready` until `bd recompute-blocked`
([#6716](https://github.com/gastownhall/beads/issues/6716)). The post-commit
recheck the Dolt store write transactions gained for that issue now also
runs on every write the proxied-server (uow/domain-db) route serves, which
under `--proxied-server` — the default topology — is `bd close` (single
and batch), `bd update --status`, `bd dep remove`, `bd delete`, `bd batch`
and `bd serve`; on `RunInTransaction` (`bd batch` direct, `bd cook`,
`bd mol squash`/`burn`, and SDK callers that close or update inside a
transaction); and on the wisp close, update and delete writers and the
legacy dependency removal behind `bd duplicates --merge`. Demote-to-wisp
moves a row between planes without taking a blocker away and is unchanged.
- **An explicit `BEADS_DIR` is authoritative during workspace discovery.**
When `BEADS_DIR` named a directory without project files yet (missing,
empty, or not initialized), discovery ignored it and walked up from the
current directory instead, then rebound `BEADS_DIR` to whatever ancestor
workspace it found. `bd init` refused with "already initialized" because of
the parent workspace, and data commands such as `bd create` and `bd list`
read and wrote the parent's store. Discovery now reports no workspace for
such a `BEADS_DIR`, so `bd init` initializes the named directory and other
commands fail with "no beads database found". `bd import`/`bd setup` and
`bd bootstrap` target the named directory when they create a workspace.
Behaviour with `BEADS_DIR` unset is unchanged. **Behaviour change:** a
`BEADS_DIR` that points at a project root rather than its `.beads`
directory (for example `BEADS_DIR=$repo` instead of `BEADS_DIR=$repo/.beads`),
or at a `.beads` that does not exist yet, used to work by accident because
discovery walked up to the nearest workspace; it now fails with "no beads
database found". Point `BEADS_DIR` at the `.beads` directory itself.
([#6938](https://github.com/gastownhall/beads/pull/6938))
- **A proxied workspace's proxy retires when its Dolt backend exits
cleanly.** The proxy noticed its `dolt sql-server` child exiting only when
the exit status was non-zero. A backend that shut down gracefully (for
example on SIGTERM) left the proxy up and adoptable in front of a dead store:
with `--proxied-server-idle-timeout 0` it never went away, `bd dolt status`
called it running, and every command failed until `bd dolt stop`. The proxy
now retires on any backend exit, as it already did on a crash, so the next bd
command (including `bd ping`) starts a fresh proxy and backend. `bd dolt
status` no longer reports a proxy whose managed backend is gone as running:
the text says "not serving" and the JSON reports `running: false` (with
`proxy_pid` still set), including for a stranded proxy started by an older
bd. ([#6937](https://github.com/gastownhall/beads/pull/6937))
- **`bd sql` no longer drops the rows of CTE queries or CALL result sets**
([#6932](https://github.com/gastownhall/beads/pull/6932)). In proxied-server
mode, `WITH name(cols) AS (...) SELECT ...` and `WITH RECURSIVE ...` queries
were misread as writes and printed `OK, 0 rows affected` with no error; they
now return their rows. Statements are now classified with the Dolt SQL
parser (shared by the proxied and direct paths): reads return rows, plain
writes (including CTE-prefixed `UPDATE`/`DELETE`) commit and report
`rows_affected`, and anything that may both write and return rows (`CALL`,
`EXPLAIN ANALYZE` of a write, `RETURNING`) or that the parser cannot
classify is committed and prints whatever rows it returns, so
`CALL DOLT_BRANCH(...)`-style result sets are rendered instead of discarded.
Visible changes for scripts: in direct server mode a multi-statement write,
or a single write statement the parser cannot classify, now prints `OK` /
`{"status":"ok"}` (as proxied mode already did) instead of
`OK, N rows affected` / `{"rows_affected":N}`; and `--readonly` now refuses
statements it cannot parse (for example `PRAGMA`) instead of treating them
as reads.
- **`bd types` now lists exactly the types `bd create --type` accepts**
([#6934](https://github.com/gastownhall/beads/pull/6934)). The two resolved
the type set through different code and could disagree: a server-mode
workspace's `bd types` dropped `.beads/config.yaml` `types.custom` entries
once the database had any custom type, although create accepts them; in
proxied mode `bd config set storage-class.<type>` checked `config.yaml` alone
and refused custom types registered in the database; and the built-in system
types `message`, `molecule`, `gate` and `event` were never listed. Every
mode now composes custom types by one rule (the `custom_types` table, else
the `types.custom` config row, always unioned with `config.yaml`). `bd types`
gains a "System types" section, and `bd types --json` an additive
`system_types` field; `core_types` and `custom_types` are unchanged. A
failure to read the custom types now fails `bd types`, `bd create --graph`
and `bd config set storage-class.*` instead of being silently treated as "no
custom types".
- **`notion.token` is kept out of the Dolt database**
([#6676](https://github.com/gastownhall/beads/issues/6676)). It was missing
from the yaml-only key list that holds the other tracker secrets, so
@ -32,6 +113,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
A token that was already pushed should still be rotated: deleting the row
locally does not unpublish it from remotes that already have a copy.
- **A server-mode workspace with an empty `.beads/dolt` is no longer refused
as legacy**
([#5682](https://github.com/gastownhall/beads/issues/5682),
[#6935](https://github.com/gastownhall/beads/pull/6935)). bd creates `.beads/dolt` on use even when the data lives on an
external Dolt server, and leaves it empty. When the gitignored
`.local_version` witness was missing — after a fresh checkout, or when a
provisioner created the empty root before `bd init --server --external` —
the legacy-upgrade guard refused every command, `bd init` included, as a
"legacy Dolt server workspace", and no bd command could repair it. An empty
root holds nothing a legacy release could have left, so the guard now admits
it: `bd init` writes the witness, and an existing workspace in that state
re-seeds it on the next command. A pre-1.0 witness, or a `.beads/dolt` that
holds anything, is still refused.
- **`bd -C dir prime` now describes the target workspace instead of the launch
directory** ([#5509](https://github.com/gastownhall/beads/issues/5509)). `-C`
resolves `BEADS_DIR` but never changes directory, so prime's cwd-relative
@ -49,6 +144,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
up, but it can flip auto-backup on or off for `-C` invocations whose launch
directory and target differ in remote configuration.
- **`bd show --watch` works under `--proxied-server`.** It was refused with
`proxy.watch.unsupported` although the provider can answer the poll the way
`bd list --watch` already does, so every proxied workspace — the default
transport for managed-local setups — had no way to watch a bead. The proxied
route now shares the direct route's loop: render once, re-read every 2s,
redraw only when the issue's status or `updated_at` changes, stop cleanly on
Ctrl+C/SIGTERM, and require exactly one id. Each poll opens its own short
unit of work, so a long watch never pins a transaction, and a poll that
fails (the issue was deleted, the backend blipped) keeps the last render
without printing, as on the direct route. On both routes a watch whose id
cannot be found now exits non-zero instead of 0.
- **Generated git hooks accept uutils coreutils `timeout` as a deadline helper**
([#5541](https://github.com/gastownhall/beads/issues/5541)). The managed hook
section probes `timeout` and `gtimeout` with `--version` and accepted only the
@ -92,12 +199,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
update to an inactive status, a dependency removal, a delete) and runs
through a Dolt store write transaction now rechecks the dependents it
recomputed once that transaction has committed
([#6716](https://github.com/gastownhall/beads/issues/6716)). Writes that
reach the database another way still need the `bd doctor` /
`bd recompute-blocked` repair they needed before: `bd batch` (on both its
plain and its proxied transaction), `bd cook`, `bd mol squash`,
`bd mol burn`, `bd duplicates --merge`, and the wisp writes — closes,
updates, deletes and demote-to-wisp.
([#6716](https://github.com/gastownhall/beads/issues/6716)). The
proxied-server route and the remaining store routes are covered by the
entry above.
- **`bd list --watch --format` is refused instead of silently dropping the
@ -190,6 +294,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- **Auto-backup runs on a managed-local proxied-server workspace.** The
proxied arm of the post-command hook now calls auto-backup, so an explicit
`backup.enabled=true` (or `BD_BACKUP_ENABLED=1`) takes the same throttled,
change-detected Dolt-native backup into `.beads/backup` it takes in direct
mode, through the proxied provider's non-transactional seam. Before this the
opt-in was inert on every proxied workspace and `bd backup status` said so.
The default stays OFF, as on every server-mode workspace: many bd clients
share one server. It is honored exactly where `bd backup sync` is — a
proxied server bd started itself — and stays inert on an external or
team-server topology, strict `--readonly`, `bd serve`, a preview
(`--dry-run`/`--inspect`) and a migration freeze. A command that opened no
provider (e.g. `bd dolt stop`) backs nothing up rather than relaunching the
server to do so. `bd backup status` now reports the proxied default as
`auto: off in proxied-server mode; set backup.enabled=true to opt in`.
- **Auto-backup and `bd backup sync` no longer overlap.** A per-workspace
backup lock (`.beads/backup.lock`) serializes them in every mode:
auto-backup skips when another backup holds it, and `bd backup sync` waits
up to 5 seconds (the bound restore uses for the workspace gate) and then
fails with "another backup is running for this workspace".
- **`bd purge` covers an orchestrator's wisp retention sweep.** Three changes
that together let `bd purge --wisps-plane --older-than 168h --force` replace
a raw `DELETE FROM wisps` retention step:
@ -252,6 +377,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
server topology. Wiring an auto-backup hook through the new routes is left to
a later slice.
- **`bd` says when it resolved a partial ID instead of matching one exactly.**
([#6302](https://github.com/gastownhall/beads/pull/6302)) ID resolution tries an exact match first and only then falls back to
leading-prefix abbreviation (`a3f8` -> `a3f8e9`). Ambiguity was already a hard
error naming every candidate, but a *sole* abbreviation match was returned
silently, so a caller could act on an issue it had not named without any
signal. bd now writes a one-line note to stderr identifying both the input and
what it resolved to. The case that motivates it: a hierarchical child is a
valid leading-prefix match for its own parent's ID, so after a parent is
renamed or deleted the vacated ID quietly resolves to the child. Note this
covers **every** leading-prefix abbreviation, not only that shape, so the
ordinary documented `a3f8` -> `bd-a3f8e9` path now emits a line too, once per
resolved argument. That breadth is deliberate: a `.`-boundary rule would fix
parent/child but leave `bd-x.1` -> `bd-x.11` just as silent. stdout and
`--json` are unchanged; silence it with `--quiet` or
`BD_NO_PARTIAL_ID_NOTICE=1`.
- **`bd count` supports repeatable `--metadata-field key=value` filters**
([#6023](https://github.com/gastownhall/beads/issues/6023)), so callers can
count the same metadata-scoped set `bd list` returns without fetching every
@ -342,6 +483,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- **`bd prime` describes the memory split instead of prohibiting `MEMORY.md`**
([#6111](https://github.com/gastownhall/beads/pull/6111), refs
[#5169](https://github.com/gastownhall/beads/issues/5169)). The guidance
line used to read `Do NOT use MEMORY.md files — they fragment across
accounts`. That warning predates harnesses that ship a first-party,
machine-local memory whose index file is also named `MEMORY.md`, so in a
workspace running both, prime told the agent every session not to use a file
the harness was actively maintaining. The line now says what each store is
for: durable **project** facts go in `bd remember`, because per-tool memory
files fragment across accounts; per-operator preferences stay in the
harness's own memory. Output text only, no behaviour change. The same
sentence is updated in its sibling renderings — the MCP/minimal context, the
generated AGENTS.md sections for the minimal and Codex harness templates,
and the README snippet — so `bd init` and copy-paste do not re-introduce the
prohibition.
- **`bd purge` keeps closed beads a live bead depends on.** A closed bead
that a not-done bead depends on through `parent-child`, `tracks` or
`blocks` is no longer purged (reported as `live_dependent_skipped`), so a

View file

@ -43,7 +43,14 @@ go_deps.module_override(
patches = ["//third_party/patches:dolt_go_serial.patch"],
path = "github.com/dolthub/dolt/go",
)
use_repo(go_deps, "com_github_anthropics_anthropic_sdk_go", "com_github_burntsushi_toml", "com_github_cenkalti_backoff_v4", "com_github_charmbracelet_x_ansi", "com_github_data_dog_go_sqlmock", "com_github_dolthub_dolt_go", "com_github_dolthub_driver_v2", "com_github_dolthub_eventkit", "com_github_dolthub_go_mysql_server", "com_github_go_sql_driver_mysql", "com_github_google_uuid", "com_github_gowebpki_jcs", "com_github_invopop_jsonschema", "com_github_johanneskaufmann_html_to_markdown_v2", "com_github_mattn_go_sqlite3", "com_github_microcosm_cc_bluemonday", "com_github_oapi_codegen_oapi_codegen_v2", "com_github_olebedev_when", "com_github_spf13_cobra", "com_github_spf13_pflag", "com_github_spf13_viper", "com_github_stretchr_testify", "com_github_subosito_gotenv", "com_github_testcontainers_testcontainers_go", "com_github_testcontainers_testcontainers_go_modules_dolt", "com_github_yuin_goldmark", "in_gopkg_yaml_v3", "io_opentelemetry_go_otel", "io_opentelemetry_go_otel_exporters_otlp_otlpmetric_otlpmetrichttp", "io_opentelemetry_go_otel_exporters_stdout_stdoutmetric", "io_opentelemetry_go_otel_exporters_stdout_stdouttrace", "io_opentelemetry_go_otel_metric", "io_opentelemetry_go_otel_sdk", "io_opentelemetry_go_otel_sdk_metric", "io_opentelemetry_go_otel_trace", "io_rsc_script", "land_charm_glamour_v2", "land_charm_huh_v2", "land_charm_lipgloss_v2", "org_golang_x_mod", "org_golang_x_net", "org_golang_x_sync", "org_golang_x_sys", "org_golang_x_term")
# Pure-Go stubs so --config=pure can compile dolt's store/nbs (see the patch).
go_deps.module_override(
patch_strip = 1,
patches = ["//third_party/patches:gozstd_nocgo.patch"],
path = "github.com/dolthub/gozstd",
)
use_repo(go_deps, "com_github_anthropics_anthropic_sdk_go", "com_github_burntsushi_toml", "com_github_cenkalti_backoff_v4", "com_github_charmbracelet_x_ansi", "com_github_data_dog_go_sqlmock", "com_github_dolthub_dolt_go", "com_github_dolthub_driver_v2", "com_github_dolthub_eventkit", "com_github_dolthub_go_mysql_server", "com_github_dolthub_vitess", "com_github_go_sql_driver_mysql", "com_github_google_uuid", "com_github_gowebpki_jcs", "com_github_invopop_jsonschema", "com_github_johanneskaufmann_html_to_markdown_v2", "com_github_mattn_go_sqlite3", "com_github_microcosm_cc_bluemonday", "com_github_oapi_codegen_oapi_codegen_v2", "com_github_olebedev_when", "com_github_spf13_cobra", "com_github_spf13_pflag", "com_github_spf13_viper", "com_github_stretchr_testify", "com_github_subosito_gotenv", "com_github_testcontainers_testcontainers_go", "com_github_testcontainers_testcontainers_go_modules_dolt", "com_github_yuin_goldmark", "in_gopkg_yaml_v3", "io_opentelemetry_go_otel", "io_opentelemetry_go_otel_exporters_otlp_otlpmetric_otlpmetrichttp", "io_opentelemetry_go_otel_exporters_stdout_stdoutmetric", "io_opentelemetry_go_otel_exporters_stdout_stdouttrace", "io_opentelemetry_go_otel_metric", "io_opentelemetry_go_otel_sdk", "io_opentelemetry_go_otel_sdk_metric", "io_opentelemetry_go_otel_trace", "io_rsc_script", "land_charm_glamour_v2", "land_charm_huh_v2", "land_charm_lipgloss_v2", "org_golang_x_mod", "org_golang_x_net", "org_golang_x_sync", "org_golang_x_sys", "org_golang_x_term")
# Hermetic Dolt CLI for tests (tools/bazel/dolt.bzl pins the release to
# scripts/ci/install-dolt.sh). //tools/bazel:dolt selects the repository for

View file

@ -52,6 +52,7 @@ endif
all: build
BUILD_DIR := .
BD_BUILD_OUTPUT := $(BUILD_DIR)/bd$(if $(filter Windows_NT,$(OS)),.exe)
GIT_BUILD := $(shell git rev-parse --short HEAD)
ifeq ($(OS),Windows_NT)
INSTALL_DIR := $(USERPROFILE)/.local/bin
@ -104,21 +105,21 @@ build:
ifeq ($(OS),Windows_NT)
@if [ -n "$$CC" ]; then \
echo "Using CC=$$CC"; \
go build -tags "$(BUILD_TAGS)" -ldflags="-X main.Build=$(GIT_BUILD)" -o $(BUILD_DIR)/bd.exe ./cmd/bd; \
go build -tags "$(BUILD_TAGS)" -ldflags="-X main.Build=$(GIT_BUILD)" -o "$(BD_BUILD_OUTPUT)" ./cmd/bd; \
elif command -v gcc >/dev/null 2>&1; then \
CC=gcc go build -tags "$(BUILD_TAGS)" -ldflags="-X main.Build=$(GIT_BUILD)" -o $(BUILD_DIR)/bd.exe ./cmd/bd; \
CC=gcc go build -tags "$(BUILD_TAGS)" -ldflags="-X main.Build=$(GIT_BUILD)" -o "$(BD_BUILD_OUTPUT)" ./cmd/bd; \
elif command -v clang >/dev/null 2>&1 && clang -dumpmachine 2>/dev/null | grep -qi 'windows.*gnu'; then \
CC=clang go build -tags "$(BUILD_TAGS)" -ldflags="-X main.Build=$(GIT_BUILD)" -o $(BUILD_DIR)/bd.exe ./cmd/bd; \
CC=clang go build -tags "$(BUILD_TAGS)" -ldflags="-X main.Build=$(GIT_BUILD)" -o "$(BD_BUILD_OUTPUT)" ./cmd/bd; \
else \
for bin in $(WINDOWS_CGO_BINS); do \
if [ -x "$$bin/gcc.exe" ]; then \
echo "Using Windows CGO gcc from $$bin"; \
PATH="$$bin:$$PATH" CC=gcc go build -tags "$(BUILD_TAGS)" -ldflags="-X main.Build=$(GIT_BUILD)" -o $(BUILD_DIR)/bd.exe ./cmd/bd; \
PATH="$$bin:$$PATH" CC=gcc go build -tags "$(BUILD_TAGS)" -ldflags="-X main.Build=$(GIT_BUILD)" -o "$(BD_BUILD_OUTPUT)" ./cmd/bd; \
exit $$?; \
fi; \
if [ -x "$$bin/clang.exe" ] && "$$bin/clang.exe" -dumpmachine 2>/dev/null | grep -qi 'windows.*gnu'; then \
echo "Using Windows CGO clang from $$bin"; \
PATH="$$bin:$$PATH" CC=clang go build -tags "$(BUILD_TAGS)" -ldflags="-X main.Build=$(GIT_BUILD)" -o $(BUILD_DIR)/bd.exe ./cmd/bd; \
PATH="$$bin:$$PATH" CC=clang go build -tags "$(BUILD_TAGS)" -ldflags="-X main.Build=$(GIT_BUILD)" -o "$(BD_BUILD_OUTPUT)" ./cmd/bd; \
exit $$?; \
fi; \
done; \
@ -128,9 +129,9 @@ ifeq ($(OS),Windows_NT)
exit 1; \
fi
else
go build -tags "$(BUILD_TAGS)" -ldflags="-X main.Build=$(GIT_BUILD)" -o $(BUILD_DIR)/bd ./cmd/bd
go build -tags "$(BUILD_TAGS)" -ldflags="-X main.Build=$(GIT_BUILD)" -o "$(BD_BUILD_OUTPUT)" ./cmd/bd
ifeq ($(shell uname),Darwin)
@codesign -s - -f $(BUILD_DIR)/bd 2>/dev/null || true
@codesign -s - -f "$(BD_BUILD_OUTPUT)" 2>/dev/null || true
@echo "Signed bd for macOS"
endif
endif
@ -264,7 +265,7 @@ test-regression:
# Override version: ./scripts/upgrade-smoke-test.sh v0.62.0
test-upgrade: build
@echo "Running upgrade smoke tests..."
@CANDIDATE_BIN=./bd ./scripts/upgrade-smoke-test.sh
@CANDIDATE_BIN="$(BD_BUILD_OUTPUT)" ./scripts/upgrade-smoke-test.sh
# Run cross-version smoke tests (last 30 tags → candidate).
@ -273,14 +274,14 @@ test-upgrade: build
# All from v0.30.0: ./scripts/cross-version-smoke-test.sh --from v0.30.0
test-cross-version: build
@echo "Running cross-version smoke tests..."
@CANDIDATE_BIN=./bd ./scripts/cross-version-smoke-test.sh
@CANDIDATE_BIN="$(BD_BUILD_OUTPUT)" ./scripts/cross-version-smoke-test.sh
# Run the authenticated historical upgrade corpus with strict fidelity checks.
# All qualified versions: ./scripts/migration-test/run.sh
# Single version: ./scripts/migration-test/run.sh --version v0.49.6
test-migration: build
@echo "Running migration test harness..."
@CANDIDATE_BIN=./bd ./scripts/migration-test/run.sh
@CANDIDATE_BIN="$(BD_BUILD_OUTPUT)" ./scripts/migration-test/run.sh
# Regenerate the golden-JSON contract corpus (cmd/bd/protocol/testdata/corpus/).
# Run after any deliberate bd --json wire change; review the diff, then commit.
@ -351,10 +352,10 @@ install install-force: build
@mkdir -p "$(INSTALL_DIR)"
ifeq ($(OS),Windows_NT)
@rm -f "$(INSTALL_DIR)/bd" "$(INSTALL_DIR)/bd.exe"
@cp "$(BUILD_DIR)/bd.exe" "$(INSTALL_DIR)/bd.exe"
@cp "$(BD_BUILD_OUTPUT)" "$(INSTALL_DIR)/bd.exe"
@echo "Installed bd.exe to $(INSTALL_DIR)/bd.exe"
else
@cp "$(BUILD_DIR)/bd" "$(INSTALL_DIR)/.bd.install.tmp.$$$$" && mv -f "$(INSTALL_DIR)/.bd.install.tmp.$$$$" "$(INSTALL_DIR)/bd"
@cp "$(BD_BUILD_OUTPUT)" "$(INSTALL_DIR)/.bd.install.tmp.$$$$" && mv -f "$(INSTALL_DIR)/.bd.install.tmp.$$$$" "$(INSTALL_DIR)/bd"
@echo "Installed bd to $(INSTALL_DIR)/bd"
@ln -sfn bd "$(INSTALL_DIR)/.beads.install.tmp.$$$$" && mv -f "$(INSTALL_DIR)/.beads.install.tmp.$$$$" "$(INSTALL_DIR)/beads"
@echo "Created 'beads' alias -> bd"
@ -376,7 +377,7 @@ fmt-check:
# Validate documentation references against actual CLI flags
check-docs:
@echo "Building bd for docs checks..."
@CGO_ENABLED=0 go build -tags "$(BUILD_TAGS)" -ldflags="-X main.Build=$(GIT_BUILD)" -o $(BUILD_DIR)/bd ./cmd/bd
@CGO_ENABLED=0 go build -tags "$(BUILD_TAGS)" -ldflags="-X main.Build=$(GIT_BUILD)" -o "$(BUILD_DIR)/bd" ./cmd/bd
@./scripts/check-doc-flags.sh ./bd
@./scripts/check-doc-freshness.sh
@go test -tags=gms_pure_go ./test/docsync

View file

@ -53,7 +53,7 @@ This project uses bd (beads) for issue tracking.
- Run `bd prime` for workflow context and command guidance.
- Use `bd ready`, `bd show <id>`, `bd update <id> --claim`, and `bd close <id>`.
- Use `bd remember "insight"` for persistent project memory; do not create MEMORY.md files.
- Use `bd remember "insight"` for durable project facts; keep per-operator preferences in your harness's own memory.
- Do not use markdown TODO lists for task tracking.
```

View file

@ -29,7 +29,9 @@ func testMainInner(m *testing.M) int {
// AD-01 (be-c5p): allow root tests to connect to the test container.
os.Setenv("BEADS_TEST_SERVER", "1")
if err := testutil.EnsureDoltContainerForTestMain(); err != nil {
fmt.Fprintf(os.Stderr, "WARN: %v, skipping Dolt tests\n", err)
if testutil.DoltUnavailableForTestMain(err) {
return 1
}
} else {
defer testutil.TerminateDoltContainer()
testServerPort = testutil.DoltContainerPortInt()

View file

@ -1,4 +1,5 @@
load("@rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
load("@rules_shell//shell:sh_test.bzl", "sh_test")
# testdata/ holds the compilable preflight fixture below. Left to itself gazelle
# would make testdata/ its own package, which empties this package's
@ -25,6 +26,7 @@ go_library(
"backup_auto.go",
"backup_dolt.go",
"backup_export.go",
"backup_lock.go",
"backup_proxied_server.go",
"backup_restore.go",
"batch.go",
@ -293,6 +295,7 @@ go_library(
"show_display.go",
"show_format.go",
"show_proxied_server.go",
"show_proxied_watch.go",
"show_refs.go",
"show_thread.go",
"show_unit_helpers.go",
@ -327,7 +330,6 @@ go_library(
"todo_proxied_server.go",
"tracker_store.go",
"types.go",
"types_proxied_server.go",
"unclaim.go",
"unclaim_proxied_server.go",
"undefer.go",
@ -413,6 +415,7 @@ go_library(
"//internal/storage/issueops",
"//internal/storage/kvkeys",
"//internal/storage/schema",
"//internal/storage/sqlclass",
"//internal/storage/uow",
"//internal/storage/versioncontrolops",
"//internal/telemetry",
@ -496,17 +499,22 @@ go_test(
srcs = [
"aaa_stdio_baseline_test.go",
"actor_test.go",
"ado_roundtrip_test.go",
"ado_test.go",
"agent_hook_test.go",
"assign_fence_embedded_test.go",
"assign_fence_proxied_test.go",
"auto_import_upgrade_test.go",
"auto_import_upgrade_unit_test.go",
"autocommit_embedded_test.go",
"backend_registry_contract_test.go",
"backup_auto_proxied_local_integration_test.go",
"backup_auto_proxied_test.go",
"backup_auto_test.go",
"backup_dolt_test.go",
"backup_embedded_test.go",
"backup_export_failure_test.go",
"backup_lock_test.go",
"backup_proxied_external_integration_test.go",
"backup_proxied_local_integration_test.go",
"backup_proxied_policy_test.go",
@ -533,8 +541,10 @@ go_test(
"children_embedded_test.go",
"children_test.go",
"claim_pools_embedded_test.go",
"cli_fast_test.go",
"close_embedded_test.go",
"close_failure_report_test.go",
"close_fanin_proxied_integration_test.go",
"close_gate_test.go",
"close_last_touched_test.go",
"close_proxied_integration_test.go",
@ -583,6 +593,7 @@ go_test(
"context_proxied_integration_test.go",
"context_test.go",
"contributor_embedded_test.go",
"contributor_routing_e2e_test.go",
"cook_qnt_test.go",
"cook_test.go",
"count_embedded_test.go",
@ -623,6 +634,7 @@ go_test(
"delete_input_test.go",
"delete_proxied_integration_test.go",
"delete_proxied_server_output_test.go",
"delete_test.go",
"dep_add_target_test.go",
"dep_batch_test.go",
"dep_bulk_role_test.go",
@ -644,6 +656,7 @@ go_test(
"doctor_embedded_test.go",
"doctor_fix_order_test.go",
"doctor_fix_pending_migrations_test.go",
"doctor_health_integration_test.go",
"doctor_health_smoke_test.go",
"doctor_health_test.go",
"doctor_init_diagnostics_cgo_test.go",
@ -655,19 +668,23 @@ go_test(
"doctor_test.go",
"doctor_validate_test.go",
"dolt_autocommit_exemption_wiring_test.go",
"dolt_autocommit_integration_test.go",
"dolt_autocommit_server_test.go",
"dolt_autocommit_test.go",
"dolt_autopush_test.go",
"dolt_autostart_lifecycle_integration_test.go",
"dolt_clean_databases_purge_proxied_integration_test.go",
"dolt_clean_databases_purge_test.go",
"dolt_clean_databases_quote_test.go",
"dolt_commit_proxied_integration_test.go",
"dolt_commit_proxied_server_test.go",
"dolt_doctor_integration_test.go",
"dolt_embedded_test.go",
"dolt_help_auth_test.go",
"dolt_lifecycle_proxied_server_test.go",
"dolt_local_only_embedded_test.go",
"dolt_local_only_test.go",
"dolt_metadata_e2e_test.go",
"dolt_proxied_lifecycle_test.go",
"dolt_remote_add_test.go",
"dolt_remote_adopt_test.go",
@ -731,6 +748,7 @@ go_test(
"gc_embedded_test.go",
"gc_prune_test.go",
"git_repo_template_test.go",
"gitlab_integration_test.go",
"gitlab_test.go",
"global_identity_integration_test.go",
"gomodcache_rehome_test.go",
@ -749,6 +767,7 @@ go_test(
"history_full_hash_test.go",
"history_proxied_integration_test.go",
"history_remote_frontdoor_matrix_test.go",
"hook_env_test.go",
"hooks_embedded_test.go",
"hooks_exec_composition_test.go",
"hooks_export_staged_deletion_test.go",
@ -770,7 +789,9 @@ go_test(
"import_embedded_test.go",
"import_from_jsonl_test.go",
"import_global_prefix_isolation_test.go",
"import_missing_config_prefix_test.go",
"import_orphan_embedded_test.go",
"import_prefix_test.go",
"import_promoted_wisp_embedded_test.go",
"import_proxied_integration_test.go",
"import_shared_unit_test.go",
@ -779,8 +800,10 @@ go_test(
"info_kv_exclusion_test.go",
"info_proxied_integration_test.go",
"info_test.go",
"init_cancel_e2e_test.go",
"init_commit_test.go",
"init_embedded_test.go",
"init_explicit_beads_dir_embedded_test.go",
"init_gateway_test.go",
"init_git_bootstrap_routing_test.go",
"init_guard_test.go",
@ -817,8 +840,11 @@ go_test(
"last_touched_test.go",
"legacy_upgrade_guard_config_yaml_test.go",
"legacy_upgrade_guard_e2e_test.go",
"legacy_upgrade_guard_empty_root_test.go",
"legacy_upgrade_guard_external_server_test.go",
"legacy_upgrade_guard_test.go",
"legacy_upgrade_guard_witness_test.go",
"linear_roundtrip_test.go",
"linear_test.go",
"lint_embedded_test.go",
"lint_stale_proxied_integration_test.go",
@ -856,6 +882,7 @@ go_test(
"metadata_ready_test.go",
"metadataless_server_workspace_test.go",
"metrics_test.go",
"migrate_dolt_mode_frontdoor_integration_test.go",
"migrate_dolt_mode_test.go",
"migrate_embedded_test.go",
"migrate_force_test.go",
@ -917,6 +944,7 @@ go_test(
"provenance_test.go",
"proxied_direct_only_refusal_frontdoor_test.go",
"proxied_integration_helpers_test.go",
"proxied_local_backend_exit_test.go",
"proxied_local_dolt_lifecycle_test.go",
"proxied_local_helpers_test.go",
"proxied_local_identity_lifecycle_linux_test.go",
@ -966,10 +994,12 @@ go_test(
"rename_prefix_rewrite_test.go",
"rename_prefix_test.go",
"rename_prefix_worktree_test.go",
"reopen_defer_test.go",
"reopen_embedded_test.go",
"reopen_proxied_integration_test.go",
"reopen_test.go",
"repair_deps_test.go",
"reparent_test.go",
"reset_global_guard_test.go",
"reset_hook_ownership_test.go",
"reset_worktree_test.go",
@ -987,6 +1017,7 @@ go_test(
"search_embedded_test.go",
"search_proxied_integration_test.go",
"search_test.go",
"send_metrics_diagnostics_test.go",
"serve_batch_close_proxied_integration_test.go",
"serve_claim_next_proxied_integration_test.go",
"serve_claim_proxied_integration_test.go",
@ -1028,7 +1059,10 @@ go_test(
"show_not_found_hint_test.go",
"show_proxied_integration_test.go",
"show_proxied_reader_test.go",
"show_proxied_watch_integration_test.go",
"show_test.go",
"show_unit_helpers_test.go",
"show_watch_loop_test.go",
"show_watch_test.go",
"simple_helpers_test.go",
"skip_store_annotation_test.go",
@ -1073,6 +1107,7 @@ go_test(
"telemetry_scrub_test.go",
"template_test.go",
"test_dolt_server_cgo_test.go",
"test_helpers_integration_test.go",
"test_helpers_pure_test.go",
"test_helpers_test.go",
"test_repo_beads_guard_darwin_test.go",
@ -1084,6 +1119,8 @@ go_test(
"todo_embedded_test.go",
"tracker_frontdoor_proxy_test.go",
"tracker_proxy_uow_conformance_integration_test.go",
"types_builtin_test.go",
"types_create_agreement_test.go",
"types_embedded_test.go",
"unclaim_conditional_embedded_test.go",
"unclaim_conditional_parity_test.go",
@ -1268,6 +1305,106 @@ go_test(
}),
)
# bd_test as PR Risk's "Test (Embedded Dolt Cmd N/20)" jobs run it: shard k
# runs .github/scripts/embedded-test-shard.sh k 20 (the TestEmbedded* functions
# of *_embedded_test.go, assigned by the committed manifest) against this
# configuration's bd_test, with BEADS_TEST_EMBEDDED_DOLT=1 and the race bd
# (//cmd/bd:bd under --config=embedded) as the subprocess binary, like the
# jobs' /tmp/bd-embedded-test. It repeats bd_test's `env` (the wrapper cannot
# inherit it). shard_count must stay equal to the manifest's shard total.
#
# Tags:
# embedded: the embedded-Dolt tier; excluded from --config=prcore/ci,
# selected by --config=embedded.
sh_test(
name = "bd_embedded_test",
size = "large",
# The script gives the binary the job's -test.timeout=20m, as long as
# Bazel's 1200s action limit (eternal under --config=embedded), which
# starts earlier and kills without a goroutine dump (rules_go's wrapper
# ignores the SIGTERM). The trailing -test.timeout=19m overrides it (the
# last flag wins) so Go's own timeout fires first and dumps to test.log.
timeout = "eternal",
srcs = ["//tools/bazel:go_test_manifest_shard.sh"],
args = [
"$(rootpath //:.github/scripts/embedded-test-shard.sh)",
"BEADS_TEST_CMD_BINARY",
"$(rootpath :bd_test)",
"-test.timeout=19m",
],
data = [
":bd",
":bd_test",
":go_srcs",
"//:.github/scripts/embedded-cmd-test-shards.txt",
"//:.github/scripts/embedded-test-shard.sh",
"@go_sdk//:bin/gofmt",
],
env = {
"BEADS_TEST_BD_BINARY": "$(rlocationpath :bd)",
"BEADS_TEST_EMBEDDED_DOLT": "1",
"BEADS_TEST_GOFMT": "$(rlocationpath @go_sdk//:bin/gofmt)",
},
shard_count = 20,
tags = ["embedded"],
)
# bd_test as PR Risk's "Test (Proxied Dolt Cmd N/15)" jobs run it: shard k
# runs .github/scripts/proxied-test-shard.sh k+1 15 (the TestProxiedServer*
# functions, assigned by the committed manifest) against this configuration's
# (race) bd_test with BEADS_TEST_PROXIED_SERVER=1 and the non-race
# bd_for_tests as the subprocess binary, like the jobs' /tmp/bd-cmd-test and
# /tmp/bd-proxied. (main.yml's twin job runs the same shard script against
# build-artifacts' non-race bd-cmd-test; race here is the stricter one.)
# The shared proxied harness gets its dolt sql-server from
# internal/testutil's local backend (the pinned dolt in the test wrapper's
# runfiles) instead of the jobs' container, and fails instead of skipping
# when it cannot start one. It repeats bd_test's `env`. shard_count must
# stay equal to the manifest's shard total.
#
# Tags:
# dolt-server-proxied: the proxied-server tier; starts hermetic dolt
# sql-servers; excluded from --config=prcore/ci, selected by
# --config=doltserver-proxied.
sh_test(
name = "bd_proxied_test",
size = "large",
# The script's -test.timeout=15m fires (with a goroutine dump) before
# Bazel's 1200s action limit (eternal under the lane's --test_timeout).
timeout = "eternal",
srcs = ["//tools/bazel:go_test_manifest_shard.sh"],
args = [
"$(rootpath //:.github/scripts/proxied-test-shard.sh)",
"BEADS_TEST_CMD_BINARY",
"$(rootpath :bd_test)",
],
data = [
":bd_for_tests",
":bd_test",
":go_srcs",
"//:.github/scripts/proxied-cmd-test-shards.txt",
"//:.github/scripts/proxied-test-shard.sh",
"@go_sdk//:bin/gofmt",
],
env = {
"BEADS_TEST_BD_BINARY": "$(rlocationpath :bd_for_tests)",
"BEADS_TEST_DOLT_SERVER": "local",
# The jobs' "Configure Git and Dolt identity" global git identity
# (tools/bazel/test_env.sh).
"BEADS_TEST_GIT_IDENTITY": "1",
"BEADS_TEST_GOFMT": "$(rlocationpath @go_sdk//:bin/gofmt)",
"BEADS_TEST_PROXIED_SERVER": "1",
"BEADS_TEST_REQUIRE_DOLT_CONTAINER": "1",
# The 4-vCPU runner shape: -test.parallel defaults to GOMAXPROCS, and
# the job runs 4 tests at once, not one per worker core (39
# concurrent `bd init --proxied-server` against one server hung a
# 192-core worker).
"GOMAXPROCS": "4",
},
shard_count = 15,
tags = ["dolt-server-proxied"],
)
# CLI flag registrations pinned by //internal/httpapi spec parity tests.
exports_files(
[

View file

@ -4,11 +4,13 @@ import (
"context"
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
)
// Shared helpers for the agent lifecycle hook commands (codex-hook, cursor-hook).
@ -16,17 +18,113 @@ import (
// the prime-runner and one-shot refresh-marker mechanics are identical and live
// here to avoid divergence.
// allowedPrimeArgs is the closed set of flags the agent hooks may pass to the
// re-executed bd binary. The hooks only ever run the fixed `bd prime`
// invocation (optionally --memories-only); anything else is a programming
// error and is refused before the subprocess is built.
var allowedPrimeArgs = map[string]bool{"--memories-only": true}
// errPrimeTestBinary is returned by resolvePrimeExecutable when the running
// binary is a test binary. Mirrors doctor/fix's ErrTestBinary: re-execing a
// test binary with `prime` fork-bombs the suite.
var errPrimeTestBinary = errors.New("running as test binary - cannot re-exec bd")
// primeExecutable resolves the re-exec target for runBdPrime. A var so tests
// can stub resolution and prove no subprocess is ever built from unexpected
// input.
var primeExecutable = resolvePrimeExecutable
// resolvePrimeExecutable is the production re-exec resolver. It restates
// getBdBinary (cmd/bd/doctor/fix/common.go), the repo's existing answer to "bd
// re-invokes bd": prefer the running binary, resolve symlinks so every re-exec
// site agrees on one path, refuse a test binary so an unstubbed test call
// fails loudly instead of fork-bombing, and fall back to a validated PATH
// lookup when the running binary cannot be resolved. getBdBinary is
// package-private to doctor/fix, so this restates the precedent rather than
// reusing it.
//
// One trade-off is kept deliberately, and it is narrower than it looks. Linux
// reports an unlinked image with a " (deleted)" suffix, but os.Executable
// strips that suffix (os/executable_procfs.go), so no "(deleted)" path ever
// reaches this resolver: a bd replaced in place mid-session (an ordinary
// `go install ./cmd/bd`) still resolves to its own path, EvalSymlinks succeeds
// against the new file, and the re-exec runs the replacement. The residual gap
// is a bd deleted without being replaced: EvalSymlinks fails, that failure is
// tolerated so the stale path is kept, and the PATH fallback is correctly not
// taken because os.Executable itself returned no error. Accepted: the target is
// PATH-independent because it contains a path separator (exec.Command calls
// LookPath only when filepath.Base(name) == name), and both hook handlers treat
// a prime failure as non-fatal, so the effect is a session primed without
// context.
func resolvePrimeExecutable() (string, error) {
exe, err := os.Executable()
if err == nil {
if resolved, linkErr := filepath.EvalSymlinks(exe); linkErr == nil {
exe = resolved
}
// testing.Testing() is the authoritative signal and must come first:
// rules_go links test binaries as <name>_test (cmd/bd's is bd_test),
// which no ".test" name check can see, so under the Bazel lane the
// name checks alone would let an unstubbed call re-exec the test
// binary. The name checks remain for binaries built with `go test -c`
// and run outside the harness. Mirrors doctor/fix's isTestBinary.
base := filepath.Base(exe)
if testing.Testing() || strings.HasSuffix(base, ".test") || strings.Contains(base, ".test.") {
return "", errPrimeTestBinary
}
return exe, nil
}
bdPath, lookErr := exec.LookPath("bd")
if lookErr != nil {
return "", fmt.Errorf("bd binary not found in PATH: %w", lookErr)
}
return bdPath, nil
}
// validatePrimeArgs rejects any argument outside allowedPrimeArgs so the
// re-exec below can never be steered by caller-supplied strings.
func validatePrimeArgs(args []string) error {
for _, arg := range args {
if !allowedPrimeArgs[arg] {
return fmt.Errorf("bd prime: unsupported hook argument %q", arg)
}
}
return nil
}
// primeCommand validates args, resolves the re-exec target, and builds the
// `bd prime [args...]` command without running it. Split out from runBdPrime
// so a test can assert the exec target and argv — the thing this seam exists
// to guarantee — without launching a subprocess.
func primeCommand(ctx context.Context, args ...string) (*exec.Cmd, error) {
if err := validatePrimeArgs(args); err != nil {
return nil, err
}
exe, err := primeExecutable()
if err != nil {
return nil, fmt.Errorf("bd prime: resolve executable: %w", err)
}
cmdArgs := append([]string{"prime"}, args...)
// #nosec G204 - exe comes from primeExecutable (resolvePrimeExecutable in
// production: this bd binary re-invoking itself); cmdArgs is the fixed
// "prime" subcommand plus allowlisted internal flags, never
// attacker-controlled input. Documentation only: .golangci.yml excludes
// G204 repo-wide, so this annotation is not what keeps lint green.
return exec.CommandContext(ctx, exe, cmdArgs...), nil
}
// runBdPrime shells out to `bd prime [args...]` and returns its combined output.
// The hooks exec a subprocess (rather than calling prime in process) to avoid
// re-entrant store initialization.
func runBdPrime(ctx context.Context, args ...string) (string, error) {
cmdArgs := append([]string{"prime"}, args...)
// #nosec G702 - os.Args[0] is this bd binary re-invoking itself; cmdArgs is the
// fixed "prime" subcommand plus internal flags, never attacker-controlled input.
cmd := exec.CommandContext(ctx, os.Args[0], cmdArgs...)
cmd, err := primeCommand(ctx, args...)
if err != nil {
return "", err
}
out, err := cmd.CombinedOutput()
if err != nil {
return "", fmt.Errorf("bd %s: %w: %s", strings.Join(cmdArgs, " "), err, strings.TrimSpace(string(out)))
return "", fmt.Errorf("bd %s: %w: %s", strings.Join(cmd.Args[1:], " "), err, strings.TrimSpace(string(out)))
}
return string(out), nil
}

131
cmd/bd/agent_hook_test.go Normal file
View file

@ -0,0 +1,131 @@
package main
import (
"context"
"errors"
"slices"
"strings"
"testing"
)
func TestValidatePrimeArgsAcceptsHookFlags(t *testing.T) {
if err := validatePrimeArgs(nil); err != nil {
t.Fatalf("no args should be allowed, got %v", err)
}
if err := validatePrimeArgs([]string{"--memories-only"}); err != nil {
t.Fatalf("--memories-only should be allowed, got %v", err)
}
}
func TestValidatePrimeArgsRejectsUnknownFlag(t *testing.T) {
err := validatePrimeArgs([]string{"--config"})
if err == nil {
t.Fatal("expected unknown flag to be rejected")
}
if !strings.Contains(err.Error(), `"--config"`) {
t.Fatalf("rejection should name the offending argument, got: %v", err)
}
}
// runBdPrime must refuse non-allowlisted arguments before it resolves the
// executable or builds a subprocess. The resolver is stubbed so the test also
// proves validation runs first — if a future change drops or reorders the
// validatePrimeArgs call, the resolver (and with it the subprocess) would be
// reached and this test fails instead of live-exec'ing anything.
func TestRunBdPrimeRejectsUnknownArgsBeforeExec(t *testing.T) {
called := false
orig := primeExecutable
primeExecutable = func() (string, error) {
called = true
return "", errors.New("resolver must not run for rejected args")
}
t.Cleanup(func() { primeExecutable = orig })
_, err := runBdPrime(context.Background(), "--config")
if err == nil {
t.Fatal("expected runBdPrime to reject unknown args")
}
if !strings.Contains(err.Error(), `"--config"`) {
t.Fatalf("rejection should name the offending argument, got: %v", err)
}
if called {
t.Fatal("executable resolver ran before argument validation")
}
}
// With allowlisted args, a resolver failure surfaces as the wrapped
// resolve-executable error and no subprocess is built.
func TestRunBdPrimeExecutableResolutionError(t *testing.T) {
orig := primeExecutable
primeExecutable = func() (string, error) {
return "", errors.New("no executable")
}
t.Cleanup(func() { primeExecutable = orig })
_, err := runBdPrime(context.Background())
if err == nil || !strings.Contains(err.Error(), "resolve executable") {
t.Fatalf("want resolve-executable error, got: %v", err)
}
}
// The point of the seam: the command must be built from the *resolved*
// executable, not from os.Args[0]. primeCommand builds without running, so
// this asserts the exec target and the full argv directly. The sentinel
// deliberately contains a path separator — exec.Command only skips LookPath
// for names that do, so a bare name would leave cmd.Path host-PATH-dependent
// and set cmd.Err, making the assertion vacuous.
func TestPrimeCommandUsesResolvedExecutable(t *testing.T) {
const sentinel = "/tmp/beads-prime-sentinel-bd"
orig := primeExecutable
primeExecutable = func() (string, error) { return sentinel, nil }
t.Cleanup(func() { primeExecutable = orig })
cmd, err := primeCommand(context.Background(), "--memories-only")
if err != nil {
t.Fatalf("primeCommand with allowlisted args: %v", err)
}
if cmd.Err != nil {
t.Fatalf("separator-containing sentinel should build cleanly, got cmd.Err=%v", cmd.Err)
}
if cmd.Path != sentinel {
t.Fatalf("exec target should be the resolved executable %q, got %q", sentinel, cmd.Path)
}
want := []string{sentinel, "prime", "--memories-only"}
if !slices.Equal(cmd.Args, want) {
t.Fatalf("argv should be %q, got %q", want, cmd.Args)
}
}
// primeCommand refuses non-allowlisted args before resolving, and returns no
// command to run.
func TestPrimeCommandRejectsUnknownArgs(t *testing.T) {
orig := primeExecutable
primeExecutable = func() (string, error) {
return "", errors.New("resolver must not run for rejected args")
}
t.Cleanup(func() { primeExecutable = orig })
cmd, err := primeCommand(context.Background(), "--config")
if err == nil {
t.Fatal("expected primeCommand to reject unknown args")
}
if cmd != nil {
t.Fatalf("rejected args must not yield a command, got %v", cmd.Args)
}
}
// The production resolver refuses a test binary rather than handing back a
// path whose re-exec would fork-bomb the suite — the guard doctor/fix's
// getBdBinary pairs with os.Executable. Under `go test` the running binary is
// the package test binary, so this exercises the refusal directly, the same
// way cmd/bd/doctor/fix's own suites assert ErrTestBinary.
func TestResolvePrimeExecutableRefusesTestBinary(t *testing.T) {
path, err := resolvePrimeExecutable()
if !errors.Is(err, errPrimeTestBinary) {
t.Fatalf("want errPrimeTestBinary under go test, got path=%q err=%v", path, err)
}
if path != "" {
t.Fatalf("refusal must not return a path, got %q", path)
}
}

View file

@ -42,10 +42,10 @@ Auto-backup default:
coordinate destinations). 'bd config get backup.enabled' shows the effective
value and its source.
On a proxied-server workspace that opt-in does not apply: auto-backup has
no post-command hook on that path, so backup.enabled=true is inert there.
The five backup verbs above are honored on a managed-local proxied server —
run 'bd backup sync' explicitly to back one up.`,
A proxied-server workspace is server mode too: auto-backup is OFF by
default and backup.enabled=true opts in. Both the opt-in and the five
backup verbs above are honored only on a managed-local proxied server —
one bd started itself; on a Dolt server bd does not own they are refused.`,
GroupID: "sync",
}

View file

@ -2,6 +2,7 @@ package main
import (
"context"
"errors"
"fmt"
"os"
"strings"
@ -46,28 +47,21 @@ func isBackupAutoEnabled() bool {
// already computed so the note cannot disagree with the number beside
// it — and so status does not re-run the git-remote probe.
//
// The note narrates the reason the decision actually used. Proxied-server
// is checked first and ignores the config source, because on that topology
// auto-backup cannot run at all whatever backup.enabled says: the proxied
// arm of PersistentPostRunE never calls runPostRunAutoBackup (main.go), so
// an explicit backup.enabled=true is inert and reporting a bare
// "enabled=true" would send the operator away believing backups happen.
// The five backup verbs are honored on managed-local (the only proxied
// shape that reaches this line — every other one is refused by
// requireLocalProxiedBackup), so `bd backup sync` is the real answer there.
//
// Every other sql-server shape keeps its post-run hook, so there the
// default is merely off — the reason `bd config get backup.enabled`
// already reports for the same condition. Before this arm existed, status
// attributed that OFF to a missing git remote, which is untrue: server
// mode short-circuits isBackupAutoEnabled whether or not a remote exists.
// The note narrates the reason the decision actually used. An explicit
// backup.enabled needs no note: the source explains it, and every shape
// that reaches `bd backup status` honors it — including a managed-local
// proxied server, whose post-run arm runs auto-backup (every other proxied
// shape is refused by requireLocalProxiedBackup before status renders).
// A server-mode default is OFF whether or not a git remote exists, so it
// must not be attributed to the remote; before these arms existed, status
// did exactly that.
func backupAutoStatusNote(enabled bool) string {
if usesProxiedServer() {
return "auto-backup does not run on proxied-server; use 'bd backup sync'"
}
if config.GetValueSource("backup.enabled") != config.SourceDefault {
return ""
}
if usesProxiedServer() {
return "auto: off in proxied-server mode; set backup.enabled=true to opt in"
}
if usesSQLServer() {
return "auto: off in sql-server mode"
}
@ -125,6 +119,21 @@ func clientServerShareFilesystem() bool {
// bd sessions don't need a chatty repeat on every command.
var autoBackupSkipNoticeOnce sync.Once
// autoBackupBackendForCommand returns the storage this command's auto-backup
// runs against, or ok=false when there is nothing it may back up.
func autoBackupBackendForCommand() (localBackupBackend, bool) {
if usesProxiedServer() {
return proxiedAutoBackupBackend()
}
if store == nil {
return nil, false
}
if lm, ok := storage.UnwrapStore(store).(storage.LifecycleManager); ok && lm.IsClosed() {
return nil, false
}
return directLocalBackup{store: store}, true
}
// maybeAutoBackup runs a Dolt-native backup if enabled and the throttle interval has passed.
// Called from PersistentPostRun after auto-commit.
func maybeAutoBackup(ctx context.Context) {
@ -139,10 +148,8 @@ func maybeAutoBackup(ctx context.Context) {
if !isBackupAutoEnabled() {
return
}
if store == nil {
return
}
if lm, ok := storage.UnwrapStore(store).(storage.LifecycleManager); ok && lm.IsClosed() {
backend, ok := autoBackupBackendForCommand()
if !ok {
return
}
@ -152,7 +159,11 @@ func maybeAutoBackup(ctx context.Context) {
// constructs is meaningless to the server — register fails on
// every command. Skip cleanly with a one-time INFO so operators
// know auto-backup is silent on purpose.
if !clientServerShareFilesystem() {
//
// Proxied workspaces do not consult the host: proxiedAutoBackupBackend
// has already required managed-local, where bd spawned the server on
// this filesystem itself.
if !usesProxiedServer() && !clientServerShareFilesystem() {
autoBackupSkipNoticeOnce.Do(func() {
if !isQuiet() && !jsonOutput {
fmt.Fprintln(os.Stderr,
@ -190,7 +201,7 @@ func maybeAutoBackup(ctx context.Context) {
}
// Change detection: skip if nothing changed
currentCommit, err := store.GetCurrentCommit(ctx)
currentCommit, err := backend.CurrentCommit(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "Warning: auto-backup skipped: failed to get current commit: %v\n", err)
return
@ -200,8 +211,21 @@ func maybeAutoBackup(ctx context.Context) {
return
}
// One backup at a time per workspace (backup_lock.go). Auto-backup never
// waits: a held lock means a backup is already running.
release, err := acquireBackupLock(0)
if err != nil {
if errors.Is(err, errBackupBusy) {
debug.Logf("backup: skipping — another backup is running\n")
return
}
fmt.Fprintf(os.Stderr, "Warning: auto-backup skipped: %v\n", err)
return
}
defer release()
// Run the backup (force=true since we already checked change detection above)
if _, err := runBackupExport(ctx, true); err != nil {
if _, err := runBackupExport(ctx, backend, true); err != nil {
if !isQuiet() && !jsonOutput {
fmt.Fprintf(os.Stderr, "Warning: auto-backup failed: %v\n", err)
}

View file

@ -0,0 +1,240 @@
//go:build cgo && unix
package main
import (
"context"
"encoding/json"
"os"
"path/filepath"
"slices"
"strings"
"testing"
"time"
"github.com/steveyegge/beads/internal/storage/dbproxy/proxy"
"github.com/steveyegge/beads/internal/storage/dbproxy/server"
"github.com/steveyegge/beads/internal/workspacegate"
)
// autoBackupOptIn is the explicit opt-in a server-mode workspace needs, with
// the throttle collapsed so every command in a test is due.
var autoBackupOptIn = []string{"BD_BACKUP_ENABLED=true", "BD_BACKUP_INTERVAL=1ms"}
// TestManagedLocalProxiedAutoBackup is the claim this slice makes: on a
// managed-local proxied workspace, an explicit backup.enabled=true makes the
// post-command hook take a Dolt-native backup into .beads/backup, exactly as
// it does in direct mode — and that backup restores.
//
// Like the explicit-verb round trip next door, the proof is a restore, not an
// exit code: an auto-backup that wrote a manifest nobody can restore from would
// pass every other assertion here.
//
// Named TestManagedLocalProxied* so the proxied-local smoke lane runs it.
func TestManagedLocalProxiedAutoBackup(t *testing.T) {
requireManagedLocalProxiedEnv(t)
bd := buildEmbeddedBD(t)
p := bdManagedLocalInit(t, bd, "bkauto", 5*time.Minute)
autoDir := filepath.Join(p.beadsDir, "backup")
manifest := filepath.Join(autoDir, "manifest")
// Server mode defaults auto-backup OFF: many clients share one server.
// Nothing may be written without the opt-in.
bdProxiedCreate(t, bd, p.dir, "no opt-in, no backup", "-p", "2")
if _, err := os.Stat(manifest); err == nil {
t.Fatalf("auto-backup ran without an opt-in: %s exists", manifest)
}
// With the opt-in, one ordinary write is enough.
created := proxiedAutoBackupCreate(t, bd, p, "captured by auto-backup")
if _, err := os.Stat(manifest); err != nil {
t.Fatalf("opted-in auto-backup produced no manifest at %s: %v", manifest, err)
}
state := readProxiedAutoBackupState(t, bd, p)
if state.LastDoltCommit == "" || state.Timestamp.IsZero() {
t.Fatalf("auto-backup did not record its watermark: %+v", state)
}
wantIDs := proxiedIssueIDs(t, bd, p)
if !slices.Contains(wantIDs, created) {
t.Fatalf("precondition: %s missing from %v", created, wantIDs)
}
// A read-only command with nothing new to capture must not advance the
// watermark: change detection runs before the backup, as in direct mode.
if _, stderr, err := bdProxiedRunBuffersWithEnv(t, bd, p.dir, autoBackupOptIn, "list", "--json"); err != nil {
t.Fatalf("bd list with auto-backup opted in: %v\n%s", err, stderr)
}
if again := readProxiedAutoBackupState(t, bd, p); again.LastDoltCommit != state.LastDoltCommit {
t.Fatalf("auto-backup advanced with no new commit: %q -> %q", state.LastDoltCommit, again.LastDoltCommit)
}
// `bd dolt stop` opens no provider, so its post-run hook has nothing to
// back up — and must not relaunch the server it just stopped to find out.
if _, stderr, err := bdProxiedRunBuffersWithEnv(t, bd, p.dir, autoBackupOptIn, "dolt", "stop"); err != nil {
t.Fatalf("bd dolt stop: %v\n%s", err, stderr)
}
assertManagedProxiedQuiescent(t, p, "bd dolt stop with auto-backup opted in")
// Diverge from the backup, then restore it and compare.
after := bdProxiedCreate(t, bd, p.dir, "created after the auto-backup", "-p", "2")
out, err := bdProxiedRun(t, bd, p.dir, "backup", "restore", autoDir, "--force", "--json")
if err != nil {
t.Fatalf("bd backup restore %s --force: %v\n%s", autoDir, err, out)
}
gotIDs := proxiedIssueIDs(t, bd, p)
if slices.Contains(gotIDs, after.ID) {
t.Fatalf("restore kept %s, created after the auto-backup; got %v", after.ID, gotIDs)
}
if !slices.Equal(gotIDs, wantIDs) {
t.Fatalf("restored issues differ from the auto-backed-up set:\n got %v\n want %v", gotIDs, wantIDs)
}
}
// TestManagedLocalProxiedBackupRestoreRefusedWhileAttached pins the restore
// design choice: restore REPLACES the database, so it refuses while any other
// bd command is attached to the workspace, and in that case touches nothing —
// the serving child keeps running and the data stays as it was.
//
// "Attached" is what another bd process holds for its lifetime: a SHARED
// workspace gate. The test holds exactly that, in-process, rather than racing
// a second process into position.
func TestManagedLocalProxiedBackupRestoreRefusedWhileAttached(t *testing.T) {
requireManagedLocalProxiedEnv(t)
bd := buildEmbeddedBD(t)
p := bdManagedLocalInit(t, bd, "bkatt", 5*time.Minute)
bdProxiedCreate(t, bd, p.dir, "in the backup", "-p", "1")
dest := filepath.Join(t.TempDir(), "dolt-backup")
if out, err := bdProxiedRun(t, bd, p.dir, "backup", "init", dest); err != nil {
t.Fatalf("bd backup init: %v\n%s", err, out)
}
if out, err := bdProxiedRun(t, bd, p.dir, "backup", "sync"); err != nil {
t.Fatalf("bd backup sync: %v\n%s", err, out)
}
after := bdProxiedCreate(t, bd, p.dir, "not in the backup", "-p", "1")
before := proxiedIssueIDs(t, bd, p)
proxyPID := readManagedProxyPidFile(t, p)
backendPID := readManagedBackendPidFile(t, p)
if proxyPID == nil || backendPID == nil {
t.Fatal("precondition: the managed topology should be serving")
}
gates, err := buildWorkspaceGateSet(p.beadsDir)
if err != nil {
t.Fatalf("resolve workspace gates: %v", err)
}
held, err := workspacegate.AcquireAll(context.Background(), workspacegate.Shared,
workspacegate.Options{Reason: "test: attached bd client"}, gates...)
if err != nil {
t.Fatalf("hold the workspace gate: %v", err)
}
released := false
release := func() {
if !released {
released = true
if err := held.Release(); err != nil {
t.Errorf("release workspace gate: %v", err)
}
}
}
t.Cleanup(release)
stdout, _, err := bdProxiedRunBuffers(t, bd, p.dir, "backup", "restore", dest, "--force", "--json")
if err == nil {
t.Fatalf("bd backup restore succeeded while another bd client was attached:\n%s", stdout)
}
var refusal struct {
Error string `json:"error"`
}
if jerr := json.Unmarshal([]byte(stdout[strings.Index(stdout, "{"):]), &refusal); jerr != nil {
t.Fatalf("restore refusal is not JSON on stdout: %v\n%s", jerr, stdout)
}
if !strings.Contains(refusal.Error, "other bd commands are using this workspace") {
t.Fatalf("restore refusal does not say why: %q", refusal.Error)
}
// Refused means untouched: the serving topology is the same processes.
if pf := readManagedProxyPidFile(t, p); pf == nil || pf.Pid != proxyPID.Pid || !processAlive(pf.Pid) {
t.Fatalf("refused restore disturbed the proxy: before %+v, now %+v", proxyPID, pf)
}
if pf := readManagedBackendPidFile(t, p); pf == nil || pf.Pid != backendPID.Pid || !processAlive(pf.Pid) {
t.Fatalf("refused restore disturbed the dolt child: before %+v, now %+v", backendPID, pf)
}
release()
if got := proxiedIssueIDs(t, bd, p); !slices.Equal(got, before) || !slices.Contains(got, after.ID) {
t.Fatalf("refused restore changed the data:\n got %v\n want %v", got, before)
}
// Once the other client detaches, the same restore goes through.
if out, err := bdProxiedRun(t, bd, p.dir, "backup", "restore", dest, "--force", "--json"); err != nil {
t.Fatalf("bd backup restore after the client detached: %v\n%s", err, out)
}
if slices.Contains(proxiedIssueIDs(t, bd, p), after.ID) {
t.Fatalf("restore after detach did not replace the database: %s is still here", after.ID)
}
}
// proxiedAutoBackupCreate creates an issue with auto-backup opted in and
// returns its ID.
func proxiedAutoBackupCreate(t *testing.T, bd string, p proxiedProject, title string) string {
t.Helper()
stdout, stderr, err := bdProxiedRunBuffersWithEnv(t, bd, p.dir, autoBackupOptIn, "create", title, "-p", "2", "--silent")
if err != nil {
t.Fatalf("bd create with auto-backup opted in: %v\n%s", err, stderr)
}
if strings.Contains(stderr, "auto-backup") {
t.Fatalf("auto-backup reported a problem:\n%s", stderr)
}
id := strings.TrimSpace(stdout)
if id == "" {
t.Fatalf("bd create --silent printed no ID; stderr:\n%s", stderr)
}
return id
}
// readProxiedAutoBackupState reads the auto-backup watermark through
// `bd backup status --json`, the surface an operator uses.
func readProxiedAutoBackupState(t *testing.T, bd string, p proxiedProject) backupState {
t.Helper()
out, err := bdProxiedRun(t, bd, p.dir, "backup", "status", "--json")
if err != nil {
t.Fatalf("bd backup status --json: %v\n%s", err, out)
}
start := strings.Index(string(out), "{")
if start < 0 {
t.Fatalf("bd backup status --json produced no JSON:\n%s", out)
}
var status struct {
Backup backupState `json:"backup"`
}
if err := json.Unmarshal(out[start:], &status); err != nil {
t.Fatalf("parse backup status JSON: %v\n%s", err, out)
}
return status.Backup
}
// proxiedIssueIDs lists every issue ID in the workspace, sorted.
func proxiedIssueIDs(t *testing.T, bd string, p proxiedProject) []string {
t.Helper()
var ids []string
for _, issue := range bdProxiedListJSON(t, bd, p, "--all") {
ids = append(ids, issue.ID)
}
slices.Sort(ids)
return ids
}
// assertManagedProxiedQuiescent fails when either managed-local pidfile is
// present, i.e. something relaunched the topology.
func assertManagedProxiedQuiescent(t *testing.T, p proxiedProject, after string) {
t.Helper()
for _, name := range []string{proxy.PIDFileName, server.PIDFileName} {
if _, err := os.Stat(filepath.Join(p.proxyRoot, name)); err == nil {
t.Fatalf("after %s, %s is present: the topology was relaunched", after, name)
}
}
}

View file

@ -0,0 +1,142 @@
package main
import (
"context"
"database/sql"
"os"
"testing"
"github.com/spf13/cobra"
"github.com/steveyegge/beads/internal/configfile"
"github.com/steveyegge/beads/internal/storage/uow"
)
// fakeMaintenanceProvider is a proxied provider stand-in exposing the
// non-transactional seam proxied auto-backup runs on. It never opens a
// connection; the tests here only assert whether it would be used.
type fakeMaintenanceProvider struct {
uow.UnitOfWorkProvider
runs int
}
func (f *fakeMaintenanceProvider) RunNonTx(context.Context, func(context.Context, *sql.Conn) error) error {
f.runs++
return nil
}
func (f *fakeMaintenanceProvider) Close(context.Context) error { return nil }
// TestProxiedAutoBackupBackendFollowsLocality pins where auto-backup may run on
// a proxied workspace: exactly where `bd backup sync` is honored. Auto-backup
// registers a server-side backup remote, which on a server bd does not own is
// global to every client of it — the storm the explicit verbs refuse by design
// — so an implicit trigger must not get further than the explicit one. An
// unreadable sidecar resolves to the unknown topology and fails closed.
//
// Cannot be parallel: mutates the proxiedServerMode and uowProvider globals.
func TestProxiedAutoBackupBackendFollowsLocality(t *testing.T) {
for _, tc := range []struct {
name string
sidecar string
noProvider bool
wantBackend bool
}{
{name: "managed-local with an open provider", sidecar: `{}`, wantBackend: true},
{name: "managed-local with no provider open", sidecar: `{}`, noProvider: true},
{name: "external tcp", sidecar: `{"external":{"host":"db.example.com","port":3306}}`},
{name: "external unix socket", sidecar: `{"external":{"socket":"/tmp/dolt.sock"}}`},
{name: "unreadable sidecar", sidecar: `{not json`},
} {
t.Run(tc.name, func(t *testing.T) {
beadsDir := prepareBackupStatusTest(t)
proxiedServerMode = true
if err := os.WriteFile(configfile.ProxiedServerClientInfoPath(beadsDir), []byte(tc.sidecar), 0o600); err != nil {
t.Fatalf("write proxied sidecar: %v", err)
}
oldProvider := uowProvider
t.Cleanup(func() { uowProvider = oldProvider })
fake := &fakeMaintenanceProvider{}
uowProvider = fake
if tc.noProvider {
uowProvider = nil
}
backend, ok := autoBackupBackendForCommand()
if ok != tc.wantBackend {
t.Fatalf("autoBackupBackendForCommand() ok = %v, want %v", ok, tc.wantBackend)
}
if !ok {
return
}
if _, isProxied := backend.(proxiedLocalBackup); !isProxied {
t.Fatalf("backend = %T, want proxiedLocalBackup", backend)
}
if fake.runs != 0 {
t.Fatalf("resolving the backend ran %d maintenance call(s); it must not touch the server", fake.runs)
}
})
}
}
// TestPersistentPostRunProxiedRunsAutoBackup pins the wiring: the proxied arm
// of PersistentPostRunE calls the auto-backup hook, under the same gate the
// direct arm's maintenance net uses, plus previews.
//
// Before this hook existed the proxied arm only pruned the journal and closed
// the provider, so backup.enabled=true was inert on every proxied workspace.
//
// Cannot be parallel: mutates PersistentPostRunE's package globals.
func TestPersistentPostRunProxiedRunsAutoBackup(t *testing.T) {
for _, tc := range []struct {
name string
cmd func() *cobra.Command
readonly bool
want int
}{
{name: "ordinary command", cmd: func() *cobra.Command { return &cobra.Command{Use: "list"} }, want: 1},
{name: "strict readonly", cmd: func() *cobra.Command { return &cobra.Command{Use: "list"} }, readonly: true},
{name: "bd serve", cmd: func() *cobra.Command { return &cobra.Command{Use: serveCmdName} }},
{name: "preview", cmd: func() *cobra.Command {
c := &cobra.Command{Use: "list"}
c.Flags().Bool("dry-run", false, "")
if err := c.Flags().Set("dry-run", "true"); err != nil {
t.Fatalf("set --dry-run: %v", err)
}
return c
}},
} {
t.Run(tc.name, func(t *testing.T) {
t.Chdir(t.TempDir())
t.Setenv("BEADS_DIR", "")
oldStore, oldProvider := store, uowProvider
oldReadonly, oldProxied := readonlyMode, proxiedServerMode
oldRootCtx, oldRootCancel := rootCtx, rootCancel
oldSpan, oldProfile, oldTrace := commandSpan, profileFile, traceFile
oldBackup := runPostRunAutoBackup
t.Cleanup(func() {
store, uowProvider = oldStore, oldProvider
readonlyMode, proxiedServerMode = oldReadonly, oldProxied
rootCtx, rootCancel = oldRootCtx, oldRootCancel
commandSpan, profileFile, traceFile = oldSpan, oldProfile, oldTrace
runPostRunAutoBackup = oldBackup
})
calls := 0
runPostRunAutoBackup = func(context.Context) { calls++ }
store, uowProvider = nil, nil
readonlyMode = tc.readonly
proxiedServerMode = true
rootCtx, rootCancel = context.Background(), nil
commandSpan, profileFile, traceFile = nil, nil, nil
if err := rootCmd.PersistentPostRunE(tc.cmd(), nil); err != nil {
t.Fatalf("PersistentPostRunE: %v", err)
}
if calls != tc.want {
t.Fatalf("auto-backup hook calls = %d, want %d", calls, tc.want)
}
})
}
}

View file

@ -133,9 +133,9 @@ func TestIsBackupAutoEnabled(t *testing.T) {
// status` reachable on a proxied server for the first time, where it rendered
// the embedded-mode footnote "(auto: no git remote)". On any sql-server shape
// the value is false because usesSQLServer() short-circuits, whether or not a
// remote exists, so that reason was simply untrue; and on proxied specifically
// even an explicit backup.enabled=true changes nothing, because the proxied
// arm of PersistentPostRunE never calls runPostRunAutoBackup.
// remote exists, so that reason was simply untrue. Since the proxied post-run
// arm gained its auto-backup hook, an explicit opt-in on proxied is honored
// and needs no caveat.
//
// Cannot be parallel: mutates the proxiedServerMode global, primeHasGitRemote
// and env vars.
@ -191,23 +191,25 @@ func TestBackupAutoStatusNote(t *testing.T) {
wantNote: "",
},
{
name: "proxied default → names the missing hook, not the remote",
// Proxied is server mode: the default is off whether or not a
// remote exists, and the note names the opt-in that now works.
name: "proxied default → off, names the opt-in, not the remote",
envVal: "\x00",
hasRemote: true,
proxied: true,
wantEnabled: false,
wantNote: "auto-backup does not run on proxied-server; use 'bd backup sync'",
wantNote: "auto: off in proxied-server mode; set backup.enabled=true to opt in",
},
{
// The dead opt-in: enabled=true with nothing to run it. The note
// must survive an explicit source here, or status reports a bare
// "enabled=true" and the operator believes backups are happening.
name: "proxied explicit opt-in → still inert, still annotated",
// The proxied post-run arm runs auto-backup on managed-local (the
// only proxied shape status renders on), so an explicit opt-in is
// real there and needs no caveat.
name: "proxied explicit opt-in → honored, no note",
envVal: "true",
hasRemote: false,
proxied: true,
wantEnabled: true,
wantNote: "auto-backup does not run on proxied-server; use 'bd backup sync'",
wantNote: "",
},
}

View file

@ -142,6 +142,20 @@ Run 'bd backup init <path>' first to configure a destination.`,
}()
ctx := rootCtx
if usesProxiedServer() {
if err := requireLocalProxiedBackup("backup sync"); err != nil {
return err
}
}
release, err := acquireBackupLock(backupLockWait)
if err != nil {
if errors.Is(err, errBackupBusy) {
return HandleErrorRespectJSON("%v; retry when it completes", err)
}
return HandleErrorRespectJSON("%v", err)
}
defer release()
if usesProxiedServer() {
return runBackupSyncProxied(ctx)
}
@ -453,7 +467,7 @@ backup configuration. The backup data at the destination is not deleted.`,
}
// Also remove backup_export if it exists (auto-export may have created it at same URL)
_ = bs.BackupRemove(ctx, "backup_export")
_ = bs.BackupRemove(ctx, versioncontrolops.ExportBackupName)
// Remove local config
if path, err := doltBackupConfigPath(); err == nil {

View file

@ -122,9 +122,35 @@ func atomicWriteFile(path string, data []byte) error {
return nil
}
// localBackupBackend is what a Dolt-native backup into a local directory needs
// from storage: the commit it would capture, and the backup itself. The direct
// store supplies one (directLocalBackup) and so does the proxied provider
// (proxiedLocalBackup, backup_proxied_server.go).
type localBackupBackend interface {
CurrentCommit(ctx context.Context) (string, error)
BackupToDir(ctx context.Context, dir string) error
}
// directLocalBackup is localBackupBackend over an embedded or sql-server store.
type directLocalBackup struct {
store storage.DoltStorage
}
func (b directLocalBackup) CurrentCommit(ctx context.Context) (string, error) {
return b.store.GetCurrentCommit(ctx)
}
func (b directLocalBackup) BackupToDir(ctx context.Context, dir string) error {
bs, ok := storage.UnwrapStore(b.store).(storage.BackupStore)
if !ok {
return fmt.Errorf("storage backend does not support backup operations")
}
return bs.BackupDatabase(ctx, dir)
}
// runBackupExport performs a Dolt-native backup to .beads/backup/.
// Returns the updated state.
func runBackupExport(ctx context.Context, force bool) (*backupState, error) {
func runBackupExport(ctx context.Context, backend localBackupBackend, force bool) (*backupState, error) {
dir, err := backupDir()
if err != nil {
return nil, err
@ -137,7 +163,7 @@ func runBackupExport(ctx context.Context, force bool) (*backupState, error) {
// Change detection: skip if nothing changed (unless forced)
if !force {
currentCommit, err := store.GetCurrentCommit(ctx)
currentCommit, err := backend.CurrentCommit(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get current commit: %w", err)
}
@ -147,12 +173,7 @@ func runBackupExport(ctx context.Context, force bool) (*backupState, error) {
}
}
bs, ok := storage.UnwrapStore(store).(storage.BackupStore)
if !ok {
return nil, fmt.Errorf("storage backend does not support backup operations")
}
if err := bs.BackupDatabase(ctx, dir); err != nil {
if err := backend.BackupToDir(ctx, dir); err != nil {
// Persist the attempt time even on failure so the throttle
// interval (checked by maybeAutoBackup via state.Timestamp)
// applies to the next command. Without this, a sync that keeps
@ -170,7 +191,7 @@ func runBackupExport(ctx context.Context, force bool) (*backupState, error) {
}
// Update watermarks
currentCommit, err := store.GetCurrentCommit(ctx)
currentCommit, err := backend.CurrentCommit(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get current commit for state: %w", err)
}

View file

@ -63,13 +63,10 @@ func TestRunBackupExport_PersistsThrottleOnFailure(t *testing.T) {
t.Fatalf("precondition: expected zero timestamp, got %v", st.Timestamp)
}
oldStore := store
fake := &failingBackupStore{commit: "deadbeef", backupErr: errors.New("sync to backup: server too busy")}
store = fake
t.Cleanup(func() { store = oldStore })
before := time.Now().UTC()
if _, err := runBackupExport(context.Background(), true); err == nil {
if _, err := runBackupExport(context.Background(), directLocalBackup{store: fake}, true); err == nil {
t.Fatal("expected runBackupExport to return the sync error, got nil")
}
if fake.backupCalls != 1 {

71
cmd/bd/backup_lock.go Normal file
View file

@ -0,0 +1,71 @@
package main
import (
"errors"
"fmt"
"os"
"path/filepath"
"time"
"github.com/steveyegge/beads/internal/beads"
"github.com/steveyegge/beads/internal/lockfile"
)
// The backup lock serializes the two writers of a workspace's Dolt backup:
// post-command auto-backup and an explicit `bd backup sync`. Both run under the
// command's SHARED workspace gate, so the gate alone lets them overlap, and the
// auto-backup body does remove → add → sync on one fixed remote name — two
// concurrent runs race each other's registration and full-sync the database
// twice. Restore needs no part in it: it holds the workspace gate EXCLUSIVELY,
// which already excludes every command that could take this lock.
//
// The two callers wait differently, and deliberately:
// - auto-backup does not wait. Another backup running means one is already
// happening; it skips, and the throttle picks it up on a later command.
// - `bd backup sync` waits up to backupLockWait — the same bound an exclusive
// workspace-gate acquisition (restore) uses — and then fails with an error
// naming the busy lock, so an operator is never told it synced when it
// did not.
const backupLockFileName = "backup.lock"
// backupLockWait bounds how long `bd backup sync` waits for another backup.
// A var so tests can shorten it.
var backupLockWait = exclusiveGateWait
// errBackupBusy is returned when another backup holds the lock past the wait.
var errBackupBusy = errors.New("another backup is running for this workspace")
const backupLockPoll = 50 * time.Millisecond
// acquireBackupLock takes the workspace's backup lock, polling up to wait
// (zero means one non-blocking attempt). The returned release must be called.
func acquireBackupLock(wait time.Duration) (release func(), err error) {
beadsDir := beads.FindBeadsDir()
if beadsDir == "" {
return nil, fmt.Errorf("backup lock: %s", activeWorkspaceNotFoundError())
}
path := filepath.Join(beadsDir, backupLockFileName)
f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0o600) //nolint:gosec // path is the workspace's own lock file
if err != nil {
return nil, fmt.Errorf("backup lock: open %s: %w", path, err)
}
deadline := time.Now().Add(wait)
for {
err := lockfile.FlockExclusiveNonBlocking(f)
if err == nil {
return func() {
_ = lockfile.FlockUnlock(f)
_ = f.Close()
}, nil
}
if !lockfile.IsLocked(err) {
_ = f.Close()
return nil, fmt.Errorf("backup lock: %s: %w", path, err)
}
if !time.Now().Before(deadline) {
_ = f.Close()
return nil, errBackupBusy
}
time.Sleep(backupLockPoll)
}
}

133
cmd/bd/backup_lock_test.go Normal file
View file

@ -0,0 +1,133 @@
package main
import (
"context"
"errors"
"os"
"strings"
"testing"
"time"
)
// TestBackupLockSerializesBackups pins the lock itself: a second holder is
// refused while the first holds it, a bounded wait gives up with errBackupBusy,
// and releasing makes it available again.
//
// Cannot be parallel: prepareBackupStatusTest mutates package globals.
func TestBackupLockSerializesBackups(t *testing.T) {
prepareBackupStatusTest(t)
release, err := acquireBackupLock(0)
if err != nil {
t.Fatalf("first acquisition: %v", err)
}
if _, err := acquireBackupLock(0); !errors.Is(err, errBackupBusy) {
t.Fatalf("non-blocking acquisition while held = %v, want errBackupBusy", err)
}
start := time.Now()
if _, err := acquireBackupLock(150 * time.Millisecond); !errors.Is(err, errBackupBusy) {
t.Fatalf("bounded wait while held = %v, want errBackupBusy", err)
}
if waited := time.Since(start); waited < 100*time.Millisecond {
t.Fatalf("bounded wait returned after %s; it must poll for the wait it was given", waited)
}
release()
again, err := acquireBackupLock(0)
if err != nil {
t.Fatalf("acquisition after release: %v", err)
}
again()
}
// TestAutoBackupSkipsWhileAnotherBackupRuns: auto-backup never waits on the
// lock. With it held the backup does not run and the throttle state is left
// alone, so the next command retries; once released, the same call backs up.
func TestAutoBackupSkipsWhileAnotherBackupRuns(t *testing.T) {
prepareBackupStatusTest(t)
t.Setenv("BD_BACKUP_ENABLED", "true")
t.Setenv("BD_BACKUP_INTERVAL", "1ms")
t.Setenv("BD_GIT_HOOK", "")
initConfigForTest(t)
oldStore := store
fake := &failingBackupStore{commit: "c1"}
store = fake
t.Cleanup(func() { store = oldStore })
release, err := acquireBackupLock(0)
if err != nil {
t.Fatalf("hold the backup lock: %v", err)
}
maybeAutoBackup(context.Background())
if fake.backupCalls != 0 {
t.Fatalf("auto-backup ran %d backup(s) while another backup held the lock", fake.backupCalls)
}
dir, err := backupDir()
if err != nil {
t.Fatal(err)
}
if st, _ := loadBackupState(dir); !st.Timestamp.IsZero() {
t.Fatalf("a skipped auto-backup advanced the throttle to %v", st.Timestamp)
}
release()
maybeAutoBackup(context.Background())
if fake.backupCalls != 1 {
t.Fatalf("auto-backup ran %d backup(s) after the lock was released, want 1", fake.backupCalls)
}
}
// TestBackupSyncFailsWhenAnotherBackupHoldsTheLock: an explicit sync waits
// backupLockWait for another backup and then fails loudly, before touching the
// store — it never reports a sync it did not do.
func TestBackupSyncFailsWhenAnotherBackupHoldsTheLock(t *testing.T) {
prepareBackupStatusTest(t)
oldWait := backupLockWait
backupLockWait = 100 * time.Millisecond
t.Cleanup(func() { backupLockWait = oldWait })
oldStore := store
fake := &failingBackupStore{commit: "c1"}
store = fake
t.Cleanup(func() { store = oldStore })
release, err := acquireBackupLock(0)
if err != nil {
t.Fatalf("hold the backup lock: %v", err)
}
defer release()
var runErr error
stderr := captureStderrForBackupLockTest(t, func() {
runErr = backupSyncCmd.RunE(backupSyncCmd, nil)
})
if runErr == nil {
t.Fatal("bd backup sync succeeded while another backup held the lock")
}
if !strings.Contains(stderr, "another backup is running") {
t.Fatalf("sync refusal does not say why; stderr:\n%s", stderr)
}
if fake.backupCalls != 0 {
t.Fatalf("refused sync still reached the store (%d backup calls)", fake.backupCalls)
}
}
func captureStderrForBackupLockTest(t *testing.T, fn func()) string {
t.Helper()
stdioMutex.Lock()
defer stdioMutex.Unlock()
r, w, err := os.Pipe()
if err != nil {
t.Fatal(err)
}
old := os.Stderr
os.Stderr = w
fn()
os.Stderr = old
_ = w.Close()
buf := make([]byte, 1<<16)
n, _ := r.Read(buf)
_ = r.Close()
return string(buf[:n])
}

View file

@ -12,6 +12,7 @@ import (
"github.com/steveyegge/beads/internal/beads"
"github.com/steveyegge/beads/internal/configfile"
"github.com/steveyegge/beads/internal/debug"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/storage/dbproxy/proxy"
"github.com/steveyegge/beads/internal/storage/issueops"
@ -47,19 +48,83 @@ const proxiedBackupTargetName = defaultDoltBackupName
// Defense in depth, not a second policy: the rule and its wording come from the
// same registry row the pre-provider gate consults, so the two cannot drift.
func requireLocalProxiedBackup(path string) error {
row, ok := LookupCapabilityRow(path, "")
rule, ok := proxiedBackupRule(path)
if !ok {
// Unreachable: TestProxyCapabilityRegistryCoversCommandTree fails the
// build for a backup path with no row. Refuse rather than guess.
return HandleErrorRespectJSON("%s has no proxied-server capability row", path)
}
rule := row.ruleFor(resolveProxiedTopology(beads.FindBeadsDir()))
if rule.Outcome == ProxyOutcomeHonored {
return nil
}
return HandleProxyCapabilityError(proxyCapabilityErrorFor(rule))
}
// proxiedBackupRule resolves the registry rule for a backup path on this
// workspace's proxied topology. ok is false only for a path with no row.
func proxiedBackupRule(path string) (proxyCapabilityRule, bool) {
row, ok := LookupCapabilityRow(path, "")
if !ok {
return proxyCapabilityRule{}, false
}
return row.ruleFor(resolveProxiedTopology(beads.FindBeadsDir())), true
}
// proxiedAutoBackupBackend returns the backend post-command auto-backup runs
// against on a proxied-server workspace, or ok=false when it must not run.
//
// Auto-backup is a `bd backup sync` nobody typed, so it is honored exactly
// where that verb is — the "backup sync" registry row, i.e. managed-local
// only. Anywhere else the backup remote it registers would land on a server bd
// does not own, where it is global to every client; that is the storm the
// explicit verbs refuse by design, and an implicit trigger must not reopen it.
//
// It never opens a provider of its own. A command that did not open one (or
// closed it, as restore does) has no live topology to back up, and opening one
// here would relaunch a server the command may just have stopped.
func proxiedAutoBackupBackend() (localBackupBackend, bool) {
if rule, ok := proxiedBackupRule("backup sync"); !ok || rule.Outcome != ProxyOutcomeHonored {
debug.Logf("backup: skipping auto-backup — proxied topology does not honor backup sync\n")
return nil, false
}
if uowProvider == nil {
return nil, false
}
mp, ok := uowProvider.(uow.MaintenanceProvider)
if !ok {
debug.Logf("backup: skipping auto-backup — provider %T has no maintenance seam\n", uowProvider)
return nil, false
}
return proxiedLocalBackup{provider: mp}, true
}
// proxiedLocalBackup is localBackupBackend over the proxied provider's
// non-transactional seam, the one `bd backup sync` uses.
//
// No pre-backup commit: change detection compares HEAD, and every proxied
// write transaction already ends in DOLT_COMMIT('-Am') (uow doltServerTx), so
// HEAD is where the data is — the invariant direct mode gets from running
// auto-commit just before auto-backup.
type proxiedLocalBackup struct {
provider uow.MaintenanceProvider
}
func (b proxiedLocalBackup) CurrentCommit(ctx context.Context) (string, error) {
var hash string
err := b.provider.RunNonTx(ctx, func(ctx context.Context, conn *sql.Conn) error {
var err error
hash, err = versioncontrolops.CurrentCommit(ctx, conn)
return err
})
return hash, err
}
func (b proxiedLocalBackup) BackupToDir(ctx context.Context, dir string) error {
return b.provider.RunNonTx(ctx, func(ctx context.Context, conn *sql.Conn) error {
return versioncontrolops.BackupToDir(ctx, conn, conn, dir)
})
}
// proxiedActiveDatabase asks the server which database the provider opened,
// rather than re-deriving it from the workspace config. The provider already
// resolved that question (metadata.json, then --database/--db), and a second
@ -203,7 +268,7 @@ func runBackupRemoveProxied(ctx context.Context) error {
return err
}
// auto-export may have registered a second remote at the same URL.
_ = versioncontrolops.BackupRemove(ctx, conn, "backup_export")
_ = versioncontrolops.BackupRemove(ctx, conn, versioncontrolops.ExportBackupName)
return nil
})
if err != nil {

View file

@ -190,7 +190,9 @@ Examples:
if isGitRepo() && !isBareGitRepo() {
if originURL, err := gitOriginGetURL(); err == nil && originURL != "" {
if gitOriginHasDoltDataRef() {
if fallbackDir := beads.GetWorktreeFallbackBeadsDir(); fallbackDir != "" {
if explicitDir := beads.ExplicitBeadsDir(); explicitDir != "" {
beadsDir = explicitDir
} else if fallbackDir := beads.GetWorktreeFallbackBeadsDir(); fallbackDir != "" {
beadsDir = fallbackDir
} else {
cwd, err := os.Getwd()

View file

@ -0,0 +1,84 @@
//go:build cgo
package main
import (
"bytes"
"encoding/json"
"fmt"
"os/exec"
"strings"
"sync"
"testing"
"github.com/steveyegge/beads/internal/types"
)
// TestProxiedServerCloseSiblingBlockersFanIn is gastownhall/beads#6716 end to
// end on the proxied CLI: the fan-in of a formula whose parallel workers
// close the two blockers of one step at the same time. Each round closes the
// blockers with two concurrent `bd close` processes and then requires the
// dependent in `bd ready`. Without the post-commit recheck on the uow path a
// round whose closes overlap leaves the dependent is_blocked=1 and missing
// from ready work. The interleaving is not pinned here (see
// TestProxiedBlockedRecheckAfterRacingUnblocks in internal/storage/uow for
// the deterministic race); this proves the settled CLI outcome.
func TestProxiedServerCloseSiblingBlockersFanIn(t *testing.T) {
requireSharedProxiedServer(t)
t.Parallel()
bd := buildEmbeddedBD(t)
p := newSharedProxiedProject(t, bd, "fan")
const rounds = 6
for round := 0; round < rounds; round++ {
a := bdProxiedCreate(t, bd, p.dir, fmt.Sprintf("round %d blocker a", round)).ID
b := bdProxiedCreate(t, bd, p.dir, fmt.Sprintf("round %d blocker b", round)).ID
c := bdProxiedCreate(t, bd, p.dir, fmt.Sprintf("round %d fan-in", round)).ID
for _, blocker := range []string{a, b} {
if out, err := bdProxiedRun(t, bd, p.dir, "dep", "add", c, blocker); err != nil {
t.Fatalf("round %d: dep add %s %s: %v\n%s", round, c, blocker, err, out)
}
}
var wg sync.WaitGroup
errs := make([]string, 2)
for i, id := range []string{a, b} {
wg.Add(1)
go func() {
defer wg.Done()
cmd := exec.Command(bd, "close", id)
cmd.Dir = p.dir
cmd.Env = bdProxiedEnv(p.dir)
var stderr bytes.Buffer
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
errs[i] = fmt.Sprintf("close %s: %v\n%s", id, err, stderr.String())
}
}()
}
wg.Wait()
if joined := strings.TrimSpace(strings.Join(errs, "")); joined != "" {
t.Fatalf("round %d: %s", round, joined)
}
out, err := bdProxiedRun(t, bd, p.dir, "ready", "--json", "--limit", "0")
if err != nil {
t.Fatalf("round %d: bd ready: %v\n%s", round, err, out)
}
start := bytes.IndexByte(out, '[')
if start < 0 {
t.Fatalf("round %d: bd ready printed no JSON array: %s", round, out)
}
var ready []types.Issue
if err := json.Unmarshal(out[start:], &ready); err != nil {
t.Fatalf("round %d: parse bd ready: %v\n%s", round, err, out)
}
found := false
for _, issue := range ready {
found = found || issue.ID == c
}
if !found {
t.Fatalf("round %d: %s has both blockers closed but is missing from bd ready", round, c)
}
}
}

View file

@ -1264,7 +1264,11 @@ func validateStorageClassConfig(key, value string) error {
if canonical := issueType.Normalize(); canonical != issueType {
return fmt.Errorf("invalid key %q: %q is an alias of %q, and create-time lookup uses the canonical type; set storage-class.%s instead", key, suffix, canonical, canonical)
}
if !issueType.IsValidWithCustom(loadEmbeddedCustomTypes()) {
customTypes, err := resolveWorkspaceCustomTypes(rootCtx)
if err != nil {
return err
}
if !issueType.IsValidWithCustom(customTypes) {
return fmt.Errorf("invalid key %q: unknown issue type %q (use a built-in type, or add it to types.custom first)", key, suffix)
}
if _, err := types.ParseStorageClass(value); err != nil {

View file

@ -11,7 +11,6 @@ import (
"github.com/spf13/cobra"
"github.com/steveyegge/beads/internal/config"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/storage/domain"
"github.com/steveyegge/beads/internal/storage/uow"
@ -21,13 +20,6 @@ import (
"github.com/steveyegge/beads/issueops"
)
func resolveProxiedCustomTypes(dbTypes []string) []string {
if len(dbTypes) > 0 {
return dbTypes
}
return config.GetCustomTypesFromYAML()
}
func runCreateProxiedServer(cmd *cobra.Command, ctx context.Context, in createInput) error {
if in.repoOverrideSet {
// Defense in depth: validateProxyCapabilitiesBeforeProvider already
@ -394,7 +386,7 @@ func runCreateProxiedGraph(_ *cobra.Command, ctx context.Context, in createInput
// The returned useWisp is the plan-wide table routing decision.
func validateProxiedGraphPlan(plan *GraphApplyPlan, in createInput, cctx domain.CreateContext, issueExists func(id string) (bool, error)) (useWisp bool, err error) {
cfg := graphPlanConfig{
customTypes: resolveProxiedCustomTypes(cctx.CustomTypes),
customTypes: cctx.CustomTypes,
// No YAML fallback for statuses — the server database is authoritative
// (that's where 'bd config set status.custom' writes) and statuses are
// store-only everywhere (single-issue create, list filters), unlike

View file

@ -3,13 +3,10 @@ package main
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"reflect"
"testing"
"time"
"github.com/steveyegge/beads/internal/config"
"github.com/steveyegge/beads/internal/types"
"github.com/steveyegge/beads/issueops"
)
@ -473,55 +470,3 @@ func TestParseMarkdownDependencies_DoesNotSwapBlocks(t *testing.T) {
t.Errorf("got %#v, want %#v (no swap-direction)", got, want)
}
}
func TestResolveProxiedCustomTypes_PrefersDBTypes(t *testing.T) {
got := resolveProxiedCustomTypes([]string{"db-a", "db-b"})
if !reflect.DeepEqual(got, []string{"db-a", "db-b"}) {
t.Errorf("got %#v, want [db-a db-b] — DB types must win when non-empty", got)
}
}
func TestResolveProxiedCustomTypes_FallsBackToYAML(t *testing.T) {
restore := withTestYAMLCustomTypes(t, "molecule,gate,convoy")
defer restore()
for _, dbTypes := range [][]string{nil, {}} {
got := resolveProxiedCustomTypes(dbTypes)
if !reflect.DeepEqual(got, []string{"molecule", "gate", "convoy"}) {
t.Errorf("dbTypes=%v: got %#v, want YAML fallback [molecule gate convoy]", dbTypes, got)
}
}
}
func TestResolveProxiedCustomTypes_EmptyEverywhere(t *testing.T) {
restore := withTestYAMLCustomTypes(t, "")
defer restore()
got := resolveProxiedCustomTypes(nil)
if len(got) != 0 {
t.Errorf("expected empty result, got %#v", got)
}
}
func withTestYAMLCustomTypes(t *testing.T, customCSV string) func() {
t.Helper()
tmpDir := t.TempDir()
beadsDir := filepath.Join(tmpDir, ".beads")
if err := os.MkdirAll(beadsDir, 0o755); err != nil {
t.Fatalf("mkdir .beads: %v", err)
}
var content string
if customCSV != "" {
content = "types:\n custom: \"" + customCSV + "\"\n"
}
if err := os.WriteFile(filepath.Join(beadsDir, "config.yaml"), []byte(content), 0o644); err != nil {
t.Fatalf("write config.yaml: %v", err)
}
t.Chdir(tmpDir)
config.ResetForTesting()
if err := config.Initialize(); err != nil {
t.Fatalf("config.Initialize: %v", err)
}
return func() { config.ResetForTesting() }
}

View file

@ -92,6 +92,37 @@ func TestProxiedServerDeferUndefer(t *testing.T) {
}
})
t.Run("undefer_clears_stray_defer_until_when_status_not_deferred", func(t *testing.T) {
// Mirrors TestEmbeddedUndefer's ga-bq3w5 coverage on the proxied-server
// route (runUndeferProxiedServer): a status that is neither "open" nor
// "deferred" makes the conditional status write observable — writing
// status=open here would be a real change, not a no-op.
j := bdProxiedCreate(t, bd, p.dir, "Stray future defer on in_progress issue", "--type", "task")
if out, err := bdProxiedRun(t, bd, p.dir, "update", j.ID, "--status", "in_progress", "--defer", "2099-01-01"); err != nil {
t.Fatalf("update --status in_progress --defer: %v\n%s", err, out)
}
status, deferUntil := showStatus(t, j.ID)
if status != string(types.StatusInProgress) || deferUntil == nil {
t.Fatalf("precondition: expected status=in_progress with defer_until set, got status=%q defer_until=%v", status, deferUntil)
}
stdout, stderr, err := bdProxiedRunBuffers(t, bd, p.dir, "undefer", j.ID)
if err != nil {
t.Fatalf("undefer: %v\nstdout=%s\nstderr=%s", err, stdout, stderr)
}
if strings.Contains(stdout+stderr, "is not deferred") {
t.Errorf("undefer refused instead of clearing the stray defer_until: stdout=%s stderr=%s", stdout, stderr)
}
status, deferUntil = showStatus(t, j.ID)
if status != string(types.StatusInProgress) {
t.Errorf("expected status to stay in_progress (not clobbered to open), got %q", status)
}
if deferUntil != nil {
t.Errorf("expected defer_until cleared after undefer, got %v", deferUntil)
}
})
t.Run("defer_is_idempotent", func(t *testing.T) {
d := bdProxiedCreate(t, bd, p.dir, "Idempotent defer", "--type", "task")
if out, err := bdProxiedRun(t, bd, p.dir, "defer", d.ID); err != nil {

View file

@ -17,6 +17,12 @@ import (
type deferProxiedResult struct {
issues []*types.Issue
errs []string
// wasDeferred tracks, in lockstep with issues, whether each undeferred
// issue was actually status=deferred (status flips to open) versus just
// carrying a stray defer_until on some other status (status untouched,
// only the timestamp cleared — ga-bq3w5). Unused by runDeferProxiedServer.
wasDeferred []bool
}
func proxiedUpdateByID(ctx context.Context, uw uow.UnitOfWork, id string, isWisp bool, updates map[string]any) error {
@ -125,21 +131,29 @@ func runUndeferProxiedServer(ctx context.Context, args []string) error {
continue
}
fullID := issue.ID
if issue.Status != types.StatusDeferred {
// Gate on defer_until, not status alone (ga-bq3w5) — mirrors the
// embedded-backend fix in undefer.go. See that file's comment for
// the full rationale.
wasDeferred := issue.Status == types.StatusDeferred
if !wasDeferred && issue.DeferUntil == nil {
r.errs = append(r.errs, fmt.Sprintf("%s is not deferred (status: %s)", fullID, string(issue.Status)))
continue
}
updates := map[string]interface{}{
"status": string(types.StatusOpen),
"defer_until": nil,
}
if wasDeferred {
updates["status"] = string(types.StatusOpen)
}
if uerr := proxiedUpdateByID(ctx, uw, fullID, isWisp, updates); uerr != nil {
r.errs = append(r.errs, fmt.Sprintf("Error undeferring %s: %v", fullID, uerr))
continue
}
if updated := proxiedGetByID(ctx, uw, fullID, isWisp); updated != nil {
r.issues = append(r.issues, updated)
r.wasDeferred = append(r.wasDeferred, wasDeferred)
}
}
if len(r.issues) == 0 {
@ -162,8 +176,12 @@ func runUndeferProxiedServer(ctx context.Context, args []string) error {
}
}
} else {
for _, iss := range res.issues {
fmt.Printf("%s Undeferred %s (now open)\n", ui.RenderPass("*"), iss.ID)
for i, iss := range res.issues {
if i < len(res.wasDeferred) && res.wasDeferred[i] {
fmt.Printf("%s Undeferred %s (now open)\n", ui.RenderPass("*"), iss.ID)
} else {
fmt.Printf("%s Cleared stale defer_until on %s (status unchanged: %s)\n", ui.RenderPass("*"), iss.ID, string(iss.Status))
}
}
}

View file

@ -89,7 +89,9 @@ func testMainInner(m *testing.M) int {
}
if err := testutil.EnsureDoltContainerForTestMain(); err != nil {
fmt.Fprintf(os.Stderr, "WARN: %v, skipping Dolt tests\n", err)
if testutil.DoltUnavailableForTestMain(err) {
return 1
}
} else {
defer testutil.TerminateDoltContainer()
port := testutil.DoltContainerPortInt()

View file

@ -114,13 +114,47 @@ sh_test(
srcs = ["//tools/bazel:go_test_variant.sh"],
args = ["$(rootpath :fix_test)"],
data = [":fix_test"],
env = {"BEADS_FIX_REQUIRE_DOLT": "1"},
# Pinned to the container backend (the docker lane is the A/B control);
# rule env beats --test_env, so =local on the command line cannot flip it.
env = {
"BEADS_FIX_REQUIRE_DOLT": "1",
"BEADS_TEST_DOLT_SERVER": "container",
},
tags = [
"no-remote-exec",
"requires-docker",
],
)
# The Dolt-backed half of fix_test, as pr.yml's "Test doctor/fix (Dolt-backed,
# hard-require container)" step runs it, on the dolt-server lane: TestMain's
# server is a local `dolt sql-server` child of the test process, and
# BEADS_FIX_REQUIRE_DOLT=1 keeps the suite from skipping when it cannot start.
# fix_docker_test is the A/B control. 4 shards: unsharded it was the lane's
# critical path (~4 min remotely).
#
# Tags:
# dolt-server: starts hermetic dolt sql-servers from the pinned dolt in the
# test wrapper's runfiles (BEADS_TEST_DOLT_SERVER=local); excluded from
# --config=prcore/ci, selected by --config=doltserver. Runs remotely: no
# docker, and a missing server fails (REQUIRE=1) instead of skipping, so
# a cached pass is as good as a fresh one.
sh_test(
name = "fix_dolt_test",
size = "large",
srcs = ["//tools/bazel:go_test_variant.sh"],
args = ["$(rootpath :fix_test)"],
data = [":fix_test"],
env = {
"BEADS_FIX_REQUIRE_DOLT": "1",
"BEADS_TEST_DOLT_SERVER": "local",
"BEADS_TEST_REQUIRE_DOLT_CONTAINER": "1",
"GOMAXPROCS": "4",
},
shard_count = 4,
tags = ["dolt-server"],
)
# --- begin go_srcs (managed by tools/bazel/go_srcs.py; run `make bazel-sync`) ---
filegroup(

View file

@ -26,7 +26,9 @@ func testMainInner(m *testing.M) int {
// database-name firewall when they connect to the spawned test server.
os.Setenv("BEADS_TEST_SERVER", "1")
if err := testutil.EnsureDoltContainerForTestMain(); err != nil {
fmt.Fprintf(os.Stderr, "WARN: %v, skipping Dolt tests\n", err)
if testutil.DoltUnavailableForTestMain(err) {
return 1
}
} else {
defer testutil.TerminateDoltContainer()
}

View file

@ -43,9 +43,12 @@ func proxiedDoltStartRefusal() *ProxyCapabilityError {
// proxiedDoltStatus is the `bd dolt status --json` payload for a proxied
// workspace. It reports the two processes separately because they fail
// separately and an operator's next move differs: Running describes the proxy,
// which is the endpoint every bd command connects through, while the Backend*
// fields describe the dolt server behind it.
// separately and an operator's next move differs: Running says whether the
// workspace is serving (a live proxy, and on a managed topology a live dolt
// behind it), Proxy* describe the proxy every bd command connects through, and
// the Backend* fields describe the dolt server behind it. A proxy left in front
// of a dead managed backend (possible with proxies started by an older bd)
// therefore reports running=false with proxy_pid still set.
type proxiedDoltStatus struct {
Mode string `json:"mode"`
Root string `json:"root"`
@ -98,9 +101,17 @@ func collectProxiedDoltStatus(beadsDir string) (proxiedDoltStatus, error) {
status.BackendEndpoint = externalDoltEndpoint(*info.External)
}
}
status.Running = proxiedStatusServing(live.ProxyRunning, status.BackendManaged, status.BackendRunning)
return status, nil
}
// proxiedStatusServing reports whether a proxied workspace is serving: its
// proxy is live and, when bd manages the backend, that dolt server is live
// too. A proxy in front of a dead managed backend serves nothing.
func proxiedStatusServing(proxyRunning, backendManaged, backendRunning bool) bool {
return proxyRunning && (!backendManaged || backendRunning)
}
func externalDoltEndpoint(cfg configfile.ExternalDoltConfig) string {
if cfg.Socket != "" {
return "unix:" + cfg.Socket
@ -116,11 +127,20 @@ func renderProxiedDoltStatus(status proxiedDoltStatus) {
return
}
if status.Running {
// A live proxy in front of a managed backend that is gone serves nothing,
// so do not call it running. The proxy retires itself once it notices
// the backend exit; a proxy from an older bd may not.
backendDown := !status.Running && status.ProxyPID != 0 && status.BackendManaged && !status.BackendRunning
switch {
case backendDown:
fmt.Printf("Dolt server: not serving (%s): proxy is up but its dolt backend is not running\n", status.Mode)
fmt.Printf(" Proxy PID: %d\n", status.ProxyPID)
fmt.Printf(" Proxy port: %d\n", status.ProxyPort)
case status.Running:
fmt.Printf("Dolt server: running (%s)\n", status.Mode)
fmt.Printf(" Proxy PID: %d\n", status.ProxyPID)
fmt.Printf(" Proxy port: %d\n", status.ProxyPort)
} else {
default:
fmt.Printf("Dolt server: not running (%s)\n", status.Mode)
}
fmt.Printf(" Root: %s\n", status.Root)
@ -135,9 +155,12 @@ func renderProxiedDoltStatus(status proxiedDoltStatus) {
if status.IdleTimeout != "" {
fmt.Printf(" Idle timeout: %s\n", status.IdleTimeout)
}
if !status.Running {
if !status.Running && !backendDown {
fmt.Println(" The proxy starts on demand; the next bd command launches it.")
}
if backendDown {
fmt.Println(" Run 'bd dolt stop' to retire the proxy; the next bd command starts a fresh proxy and backend.")
}
if isDoltLocalOnly() {
fmt.Println(" Remote sync: disabled (dolt.local-only=true)")
}

View file

@ -151,6 +151,28 @@ func TestRenderProxiedDoltStatus(t *testing.T) {
}
})
t.Run("text does not call a proxy over a dead managed backend running", func(t *testing.T) {
defer restoreJSONOutput(t)()
jsonOutput = false
stranded := running
stranded.Running = false
stranded.BackendRunning, stranded.BackendPID, stranded.BackendPort = false, 0, 0
out := captureStdout(t, func() error { renderProxiedDoltStatus(stranded); return nil })
if strings.Contains(out, "Dolt server: running") {
t.Errorf("proxy with a dead backend reported as running:\n%s", out)
}
for _, want := range []string{
"Dolt server: not serving (proxied-server)",
"Proxy PID: 111",
"Backend: not running",
"bd dolt stop",
} {
if !strings.Contains(out, want) {
t.Errorf("missing %q in:\n%s", want, out)
}
}
})
t.Run("text marks an external backend as somebody else's", func(t *testing.T) {
defer restoreJSONOutput(t)()
jsonOutput = false
@ -180,6 +202,24 @@ func TestRenderProxiedDoltStatus(t *testing.T) {
})
}
func TestProxiedStatusServing(t *testing.T) {
for _, tc := range []struct {
name string
proxyRunning, managed, backendRunning bool
want bool
}{
{"managed pair live", true, true, true, true},
{"proxy over dead managed backend", true, true, false, false},
{"external backend", true, false, false, true},
{"proxy down", false, true, true, false},
{"nothing running", false, true, false, false},
} {
if got := proxiedStatusServing(tc.proxyRunning, tc.managed, tc.backendRunning); got != tc.want {
t.Errorf("%s: proxiedStatusServing(%v, %v, %v) = %v, want %v", tc.name, tc.proxyRunning, tc.managed, tc.backendRunning, got, tc.want)
}
}
}
func restoreJSONOutput(t *testing.T) func() {
t.Helper()
orig := jsonOutput

View file

@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"sort"
"strings"
"sync"
@ -18,6 +19,7 @@ import (
"github.com/steveyegge/beads/internal/beads"
"github.com/steveyegge/beads/internal/config"
"github.com/steveyegge/beads/internal/debug"
"github.com/steveyegge/beads/internal/execenv"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/storage/dolt"
"github.com/steveyegge/beads/internal/types"
@ -1072,6 +1074,10 @@ func gitIndexLockPath(path string, env []string) (string, error) {
return filepath.Join(gitDir, "index.lock"), nil
}
// hookEnvGOOS lets both hook filters exercise either key policy on every test host.
// Process-wide seam: tests that swap it must not run in parallel.
var hookEnvGOOS = runtime.GOOS
// scrubGitHookEnv returns env with the GIT_* variables that can poison
// git's repo/worktree auto-discovery or object-store resolution removed,
// so git falls back to auto-discovery from cwd. The scrub is
@ -1090,34 +1096,28 @@ func gitIndexLockPath(path string, env []string) (string, error) {
// GIT_CONFIG namespace, which includes _COUNT, _KEY_n, _VALUE_n,
// _GLOBAL, _SYSTEM, _NOSYSTEM, and the legacy GIT_CONFIG itself.
func scrubGitHookEnv(env []string) []string {
return scrubGitHookEnvForOS(env, hookEnvGOOS)
}
func scrubGitHookEnvForOS(env []string, goos string) []string {
// The GIT_CONFIG prefix (no trailing "=") is intentional: it matches
// GIT_CONFIG=, GIT_CONFIG_COUNT=, GIT_CONFIG_KEY_n=, GIT_CONFIG_VALUE_n=,
// GIT_CONFIG_PARAMETERS=, GIT_CONFIG_GLOBAL=, GIT_CONFIG_SYSTEM=, and
// GIT_CONFIG_NOSYSTEM= — the whole family — in one entry. No standard
// git env var starts with GIT_CONFIG that we want to preserve.
prefixes := []string{
"GIT_DIR=",
"GIT_WORK_TREE=",
"GIT_INDEX_FILE=",
"GIT_COMMON_DIR=",
"GIT_PREFIX=",
"GIT_OBJECT_DIRECTORY=",
"GIT_ALTERNATE_OBJECT_DIRECTORIES=",
"GIT_CEILING_DIRECTORIES=",
"GIT_DISCOVERY_ACROSS_FILESYSTEM=",
"GIT_CONFIG",
}
out := make([]string, 0, len(env))
for _, e := range env {
skip := false
for _, p := range prefixes {
if strings.HasPrefix(e, p) {
skip = true
break
}
}
if !skip {
out = append(out, e)
cleaned := execenv.WithoutForOS(env, goos,
"GIT_DIR", "GIT_WORK_TREE", "GIT_INDEX_FILE", "GIT_COMMON_DIR",
"GIT_PREFIX", "GIT_OBJECT_DIRECTORY", "GIT_ALTERNATE_OBJECT_DIRECTORIES",
"GIT_CEILING_DIRECTORIES", "GIT_DISCOVERY_ACROSS_FILESYSTEM",
)
// Without owns a fresh slice, so this second filter cannot mutate env.
out := cleaned[:0]
for _, entry := range cleaned {
// Prefix policy also drops valueless GIT_CONFIG entries. Without
// intentionally preserves valueless exact keys such as GIT_DIR.
key := execenv.EntryKey(entry)
if !execenv.KeyHasPrefixForOS(key, "GIT_CONFIG", goos) {
out = append(out, entry)
}
}
return out

View file

@ -12,7 +12,6 @@ import (
"strings"
"time"
"github.com/steveyegge/beads/internal/config"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/types"
"github.com/steveyegge/beads/internal/validation"
@ -305,15 +304,6 @@ func warnUnknownGraphFields(w io.Writer, unknown map[string][]string) []string {
return hintFields
}
func loadEmbeddedCustomTypes() []string {
if store != nil {
if ct, err := store.GetCustomTypes(rootCtx); err == nil && len(ct) > 0 {
return ct
}
}
return config.GetCustomTypesFromYAML()
}
// loadEmbeddedCustomStatuses reads custom statuses from the store only — no
// YAML fallback, matching single-issue create and loadListFilterConfig
// (custom types fall back to YAML; custom statuses deliberately do not).
@ -348,9 +338,13 @@ func createIssuesFromGraph(planFile string, dryRun bool, opts GraphApplyOptions)
return HandleErrorRespectJSON("parsing graph plan: %v", err)
}
customTypes, err := resolveWorkspaceCustomTypes(rootCtx)
if err != nil {
return HandleErrorRespectJSON("%v", err)
}
dbPrefix, allowedPrefixes := loadEmbeddedIDPrefixes()
cfg := graphPlanConfig{
customTypes: loadEmbeddedCustomTypes(),
customTypes: customTypes,
customStatuses: loadEmbeddedCustomStatuses(),
dbPrefix: dbPrefix,
allowedPrefixes: allowedPrefixes,

76
cmd/bd/hook_env_test.go Normal file
View file

@ -0,0 +1,76 @@
package main
import (
"slices"
"testing"
)
func TestFilterChainedHookEnvUsesHostKeyIdentity(t *testing.T) {
checkHookEnvForBothHosts(t, checkChainedHookEnv)
}
// Callers and subtests must remain serial while they swap the process-wide seam.
func checkHookEnvForBothHosts(t *testing.T, check func(*testing.T)) {
t.Helper()
for _, goos := range []string{"linux", "windows"} {
t.Run(goos, func(t *testing.T) {
previous := hookEnvGOOS
hookEnvGOOS = goos
t.Cleanup(func() { hookEnvGOOS = previous })
check(t)
})
}
}
func checkChainedHookEnv(t *testing.T) {
t.Helper()
env := []string{
"BD_GIT_HOOK=canonical", "bd_git_hook=mixed", "BD_GİT_HOOK=unicode-case",
"BD_GIT_HOOK=unicode-case", "BD_GIT_HOOK=",
"BD_GıT_HOOK=distinct", "KEEP=first", "KEEP=BD_GIT_HOOK=1",
"BD_GIT_HOOK", `=C:=C:\work`,
}
original := slices.Clone(env)
want := []string{"BD_GıT_HOOK=distinct", "KEEP=first", "KEEP=BD_GIT_HOOK=1", "BD_GIT_HOOK", `=C:=C:\work`}
if hookEnvGOOS != "windows" {
want = append([]string{"bd_git_hook=mixed", "BD_GİT_HOOK=unicode-case", "BD_GIT_HOOK=unicode-case"}, want...)
}
if got := filterEnv(env, "BD_GIT_HOOK"); !slices.Equal(got, want) {
t.Errorf("chained-hook environment = %q, want %q", got, want)
}
if !slices.Equal(env, original) {
t.Errorf("input environment mutated: %q", env)
}
}
func TestScrubGitHookEnvUsesHostKeyIdentity(t *testing.T) {
checkHookEnvForBothHosts(t, checkGitHookEnv)
}
func checkGitHookEnv(t *testing.T) {
t.Helper()
env := []string{
"GIT_DIR=canonical", "git_dir=mixed", "GİT_DİR=unicode-case", "GIT_DıR=distinct",
"GIT_WORK_TREE=unicode-case", "GIT_DIſCOVERY_ACROSS_FILESYSTEM=distinct", "GIT_CONFIG=",
"GIT_CONFIG_COUNT=1", "git_config_parameters=mixed", "gİt_config_count=unicode-case",
"GIT_CONFIG_UNSET", "git_config_unset", "KEEP=first", "KEEP=GIT_CONFIG_COUNT=1",
"GIT_AUTHOR_NAME=author", "GIT_OPTIONAL_LOCKS=1", "GIT_DIR", "MALFORMED", `=C:=C:\work`,
}
original := slices.Clone(env)
want := []string{"GIT_DıR=distinct"}
if hookEnvGOOS != "windows" {
want = append([]string{"git_dir=mixed", "GİT_DİR=unicode-case"}, want...)
want = append(want, "GIT_WORK_TREE=unicode-case")
}
want = append(want, "GIT_DIſCOVERY_ACROSS_FILESYSTEM=distinct")
if hookEnvGOOS != "windows" {
want = append(want, "git_config_parameters=mixed", "gİt_config_count=unicode-case", "git_config_unset")
}
want = append(want, "KEEP=first", "KEEP=GIT_CONFIG_COUNT=1", "GIT_AUTHOR_NAME=author", "GIT_OPTIONAL_LOCKS=1", "GIT_DIR", "MALFORMED", `=C:=C:\work`)
if got := scrubGitHookEnv(env); !slices.Equal(got, want) {
t.Errorf("Git-hook environment = %q, want %q", got, want)
}
if !slices.Equal(env, original) {
t.Errorf("input environment mutated: %q", env)
}
}

View file

@ -14,6 +14,7 @@ import (
"github.com/steveyegge/beads/internal/beads"
"github.com/steveyegge/beads/internal/config"
"github.com/steveyegge/beads/internal/debug"
"github.com/steveyegge/beads/internal/execenv"
"github.com/steveyegge/beads/internal/git"
"github.com/steveyegge/beads/internal/gitenv"
"github.com/steveyegge/beads/internal/metrics"
@ -2100,14 +2101,11 @@ func warnJSONLWithoutDoltRemote(reason string) {
// filterEnv returns a copy of env with entries matching the given key removed.
func filterEnv(env []string, key string) []string {
prefix := key + "="
out := make([]string, 0, len(env))
for _, e := range env {
if !strings.HasPrefix(e, prefix) {
out = append(out, e)
}
}
return out
return filterEnvForOS(env, key, hookEnvGOOS)
}
func filterEnvForOS(env []string, key, goos string) []string {
return execenv.WithoutForOS(env, goos, key)
}
// runPostMergeHook runs chained hooks after merge, then runs the legacy

View file

@ -0,0 +1,146 @@
//go:build cgo
package main
import (
"bytes"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"github.com/steveyegge/beads/internal/configfile"
"github.com/steveyegge/beads/internal/storage/dbproxy/proxy"
)
// explicitBeadsDirMode describes how a storage mode's bd subprocesses are
// initialized and run for the explicit-BEADS_DIR regression tests.
type explicitBeadsDirMode struct {
initArgs []string
env func(home string) []string
proxied bool
}
// runExplicitBeadsDirBD runs bd in dir with the mode's isolated environment.
// beadsDir, when non-empty, is passed as an explicit BEADS_DIR.
func runExplicitBeadsDirBD(t *testing.T, bd string, mode explicitBeadsDirMode, home, dir, beadsDir string, args ...string) (string, string, error) {
t.Helper()
cmd := exec.Command(bd, args...)
cmd.Dir = dir
env := append(mode.env(home), "XDG_CONFIG_HOME="+filepath.Join(home, ".config"))
if beadsDir != "" {
env = append(env, "BEADS_DIR="+beadsDir)
}
cmd.Env = env
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
return stdout.String(), stderr.String(), err
}
// testExplicitBeadsDirIsAuthoritative covers the regression where an explicit
// BEADS_DIR without project files was ignored during discovery: bd walked up
// from CWD, bound the parent workspace, and `bd init` then refused ("already
// initialized") while data commands read and wrote the parent's store.
func testExplicitBeadsDirIsAuthoritative(t *testing.T, bd string, mode explicitBeadsDirMode) {
t.Helper()
home := t.TempDir()
parent := t.TempDir()
initGitRepoAt(t, parent)
parentBeadsDir := filepath.Join(parent, ".beads")
child := filepath.Join(parent, "child")
explicit := filepath.Join(child, ".beads")
if err := os.MkdirAll(child, 0o755); err != nil {
t.Fatal(err)
}
if mode.proxied {
for _, root := range []string{filepath.Join(parentBeadsDir, "dolt"), filepath.Join(explicit, "dolt")} {
root := root
t.Cleanup(func() {
if _, err := os.Stat(root); err != nil {
return
}
if err := proxy.Shutdown(root); err != nil {
t.Logf("proxy.Shutdown(%s): %v", root, err)
}
})
shutdownProxyOnInterrupt(t, root)
}
}
initArgs := append([]string{"init", "--quiet", "--non-interactive", "--skip-agents", "--skip-hooks"}, mode.initArgs...)
if stdout, stderr, err := runExplicitBeadsDirBD(t, bd, mode, home, parent, "", append(initArgs, "--prefix", "par")...); err != nil {
t.Fatalf("parent bd init: %v\nstdout:\n%s\nstderr:\n%s", err, stdout, stderr)
}
parentID, stderr, err := runExplicitBeadsDirBD(t, bd, mode, home, parent, "", "create", "--silent", "parent issue")
if err != nil {
t.Fatalf("parent bd create: %v\nstderr:\n%s", err, stderr)
}
parentID = strings.TrimSpace(parentID)
// A data command against the uninitialized explicit dir must not fall
// back to the parent workspace.
stdout, stderr, err := runExplicitBeadsDirBD(t, bd, mode, home, child, explicit, "list", "--json")
if err == nil || strings.Contains(stdout, parentID) {
t.Errorf("bd list with BEADS_DIR=%s (no workspace yet) should fail without reading the parent store; err=%v\nstdout:\n%s\nstderr:\n%s", explicit, err, stdout, stderr)
} else if !strings.Contains(stderr, "no beads database found") {
t.Errorf("bd list with an uninitialized BEADS_DIR: want \"no beads database found\", got stderr:\n%s", stderr)
}
// bd init must initialize the explicit dir (existing but empty, as a
// caller that pre-creates it would leave it), not refuse because of the
// parent workspace.
if err := os.MkdirAll(explicit, 0o755); err != nil {
t.Fatal(err)
}
if stdout, stderr, err := runExplicitBeadsDirBD(t, bd, mode, home, child, explicit, append(initArgs, "--prefix", "kid")...); err != nil {
t.Fatalf("bd init with BEADS_DIR=%s: %v\nstdout:\n%s\nstderr:\n%s", explicit, err, stdout, stderr)
}
childCfg, err := configfile.Load(explicit)
if err != nil || childCfg == nil {
t.Fatalf("load %s metadata: cfg=%v err=%v", explicit, childCfg, err)
}
if childCfg.DoltDatabase != "kid" {
t.Fatalf("explicit BEADS_DIR dolt_database = %q, want %q", childCfg.DoltDatabase, "kid")
}
parentCfg, err := configfile.Load(parentBeadsDir)
if err != nil || parentCfg == nil || parentCfg.DoltDatabase != "par" {
t.Fatalf("parent metadata changed: cfg=%+v err=%v", parentCfg, err)
}
// Writes through the explicit dir land in the new workspace only.
childID, stderr, err := runExplicitBeadsDirBD(t, bd, mode, home, child, explicit, "create", "--silent", "child issue")
if err != nil {
t.Fatalf("bd create with BEADS_DIR=%s: %v\nstderr:\n%s", explicit, err, stderr)
}
childID = strings.TrimSpace(childID)
if !strings.HasPrefix(childID, "kid-") {
t.Fatalf("bd create with BEADS_DIR=%s minted %q, want a kid- ID", explicit, childID)
}
parentList, stderr, err := runExplicitBeadsDirBD(t, bd, mode, home, parent, "", "list", "--json")
if err != nil {
t.Fatalf("parent bd list: %v\nstderr:\n%s", err, stderr)
}
if strings.Contains(parentList, childID) || !strings.Contains(parentList, parentID) {
t.Fatalf("parent store should hold only %s, got:\n%s", parentID, parentList)
}
}
func TestEmbeddedInitExplicitBeadsDirIsAuthoritative(t *testing.T) {
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt init tests")
}
t.Parallel()
testExplicitBeadsDirIsAuthoritative(t, buildEmbeddedBD(t), explicitBeadsDirMode{env: bdEnv})
}
func TestProxiedServerInitExplicitBeadsDirIsAuthoritative(t *testing.T) {
requireProxiedServerEnv(t)
testExplicitBeadsDirIsAuthoritative(t, buildEmbeddedBD(t), explicitBeadsDirMode{
initArgs: []string{"--proxied-server"},
env: bdProxiedEnv,
proxied: true,
})
}

View file

@ -76,6 +76,20 @@ func guardLegacyUpgradeWorkspace(beadsDir string) error {
return nil
}
if serverMode {
if !present && isEmptyDirectory(filepath.Join(beadsDir, "dolt")) {
// An empty .beads/dolt holds no Dolt data, so no legacy release
// could have left anything in it to protect: it carries no more
// evidence than a server workspace without that directory, which
// is admitted above. bd creates exactly this shape itself — the
// local Dolt root is made on use even when the data lives on an
// external server — so refusing it made `bd init --server
// --external` fail over a provisioner's empty root, and made a
// workspace that lost its gitignored witness unusable with no bd
// command able to repair it. Admitting it lets the command re-seed
// the witness. A present pre-1.0 witness was refused above, and a
// root holding anything at all still refuses below.
return nil
}
if present && classifyVersionWitness(version) == witnessEraUnknown {
// A witness that is present but unreadable — including one left
// blank or whitespace-only by an interrupted or disk-full
@ -270,6 +284,22 @@ func hasLegacyDoltRoot(beadsDir string) bool {
return err == nil && info.IsDir() && info.Mode()&os.ModeSymlink == 0
}
// isEmptyDirectory reports whether path is a real (non-symlink) directory with
// no entries. Any error reading it answers false, so callers fail closed.
func isEmptyDirectory(path string) bool {
info, err := os.Lstat(path)
if err != nil || !info.IsDir() || info.Mode()&os.ModeSymlink != 0 {
return false
}
dir, err := os.Open(path) // #nosec G304 -- bounded probe beneath selected workspace
if err != nil {
return false
}
defer func() { _ = dir.Close() }()
names, err := dir.Readdirnames(1)
return len(names) == 0 && err == io.EOF
}
func isNonEmptyRegularFile(path string) bool {
info, err := os.Lstat(path)
return err == nil && info.Mode().IsRegular() && info.Size() > 0

View file

@ -31,7 +31,7 @@ func bindSelectedWorkspaceConfig(t *testing.T, beadsDir string) {
}
// writeDoltRootWorkspace lays down the ambiguous shape the guard classifies: a
// .beads directory that owns a local Dolt root, plus whatever metadata.json,
// .beads directory that owns a populated local Dolt root, plus whatever metadata.json,
// config.yaml and version witness the case needs. An empty string means "do not
// write this file at all".
func writeDoltRootWorkspace(t *testing.T, metadata, configYaml, version string) string {
@ -52,9 +52,7 @@ func writeDoltRootWorkspace(t *testing.T, metadata, configYaml, version string)
t.Fatal(err)
}
}
if err := os.Mkdir(filepath.Join(beadsDir, "dolt"), 0o700); err != nil {
t.Fatal(err)
}
populateLegacyDoltRoot(t, beadsDir)
bindSelectedWorkspaceConfig(t, beadsDir)
return beadsDir
}

View file

@ -490,7 +490,7 @@ func TestLegacyGuardUsesSelectedTargetSharedServerConfig(t *testing.T) {
// TestLegacyGuardAdmitsConfigYamlServerWorkspace runs the real binary against
// the workspace shape gc provisions — `dolt.mode: server` in
// .beads/config.yaml, a local .beads/dolt root, a metadata.json that names no
// .beads/config.yaml, a populated local .beads/dolt root, a metadata.json that names no
// dolt_mode — and pins that the guard no longer calls it legacy. The in-process
// guard tests bind the workspace config themselves; only a subprocess proves
// that PersistentPreRunE's own binding puts the selected workspace's
@ -518,9 +518,7 @@ func TestLegacyGuardAdmitsConfigYamlServerWorkspace(t *testing.T) {
repoDir := t.TempDir()
initGitRepo(t, repoDir)
beadsDir := filepath.Join(repoDir, ".beads")
if err := os.MkdirAll(filepath.Join(beadsDir, "dolt"), 0o700); err != nil {
t.Fatal(err)
}
populateLegacyDoltRoot(t, beadsDir)
writeFile(t, filepath.Join(beadsDir, "metadata.json"), []byte(`{"backend":"dolt","dolt_database":"hq"}`))
writeFile(t, filepath.Join(beadsDir, "config.yaml"), []byte("dolt:\n mode: server\n auto-start: false\n"))
if tt.version != "" {

View file

@ -0,0 +1,143 @@
package main
import (
"os"
"path/filepath"
"testing"
)
// populateLegacyDoltRoot lays down a .beads/dolt root that holds a Dolt
// database, the shape a historical local sql-server left behind. The guard has
// to treat such a root as evidence worth protecting.
func populateLegacyDoltRoot(t *testing.T, beadsDir string) {
t.Helper()
if err := os.MkdirAll(filepath.Join(beadsDir, "dolt", "beads", ".dolt"), 0o700); err != nil {
t.Fatal(err)
}
}
// writeEmptyDoltRootServerWorkspace lays down the shape a current bd leaves
// behind after `bd init --server --external`: server mode selected, a
// .beads/dolt directory that bd created on use but that holds nothing because
// the data lives on the external server, and — once the gitignored witness has
// been lost, or when a provisioner created the empty root before bd init —
// no .local_version.
func writeEmptyDoltRootServerWorkspace(t *testing.T, metadata, configYaml, version string) string {
t.Helper()
beadsDir := t.TempDir()
for name, contents := range map[string]string{
"metadata.json": metadata,
"config.yaml": configYaml,
} {
if contents == "" {
continue
}
if err := os.WriteFile(filepath.Join(beadsDir, name), []byte(contents), 0o600); err != nil {
t.Fatal(err)
}
}
if version != "" {
if err := writeLocalVersion(filepath.Join(beadsDir, localVersionFile), version); err != nil {
t.Fatal(err)
}
}
if err := os.Mkdir(filepath.Join(beadsDir, "dolt"), 0o700); err != nil {
t.Fatal(err)
}
bindSelectedWorkspaceConfig(t, beadsDir)
return beadsDir
}
const externalServerMetadata = `{"backend":"dolt","dolt_mode":"server","dolt_server_host":"db.example.test","dolt_database":"ext_db"}`
// TestLegacyUpgradeGuardAdmitsServerWorkspaceWithEmptyDoltRoot pins the
// external-host recovery: a server-mode workspace whose .beads/dolt is empty
// and whose witness is missing holds no local Dolt data a legacy release could
// have left there, so it carries no more evidence than a workspace with no
// .beads/dolt at all — which the guard already admits. Refusing it made the
// workspace unusable after `bd init --server --external` whenever the witness
// was absent, with no bd command able to repair it.
func TestLegacyUpgradeGuardAdmitsServerWorkspaceWithEmptyDoltRoot(t *testing.T) {
cases := []struct {
name string
metadata string
configYaml string
}{
{name: "metadata.json external server", metadata: externalServerMetadata},
{name: "metadata.json server", metadata: `{"backend":"dolt","dolt_mode":"server"}`},
{name: "config.yaml server mode", configYaml: configYamlServerMode},
// Proxied-server does not select server mode, so it never reaches the
// empty-root branch; it is admitted by the final non-embedded arm. Pin
// that so a later change to either arm cannot start refusing it.
{name: "metadata.json proxied server", metadata: `{"backend":"dolt","dolt_mode":"proxied-server"}`},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
warnings := captureLegacyUpgradeWarnings(t)
beadsDir := writeEmptyDoltRootServerWorkspace(t, tc.metadata, tc.configYaml, "")
if err := guardLegacyUpgradeWorkspace(beadsDir); err != nil {
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want nil", err)
}
if warnings.Len() != 0 {
t.Fatalf("guard warned about an absent witness: %q", warnings.String())
}
})
}
}
// TestLegacyUpgradeGuardEmptyDoltRootAdmissionStaysNarrow proves the empty-root
// admission relaxes nothing else: pre-1.0 evidence still refuses, a root that
// holds anything still refuses, and outside server mode an empty root is still
// the legacy embedded shape.
func TestLegacyUpgradeGuardEmptyDoltRootAdmissionStaysNarrow(t *testing.T) {
t.Run("historical server witness", func(t *testing.T) {
captureLegacyUpgradeWarnings(t)
beadsDir := writeEmptyDoltRootServerWorkspace(t, externalServerMetadata, "", "0.62.0")
if err := guardLegacyUpgradeWorkspace(beadsDir); !isLegacyUpgradeRefusal(err) {
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want migration refusal", err)
}
})
t.Run("historical embedded witness", func(t *testing.T) {
captureLegacyUpgradeWarnings(t)
beadsDir := writeEmptyDoltRootServerWorkspace(t, externalServerMetadata, "", "0.49.6")
if err := guardLegacyUpgradeWorkspace(beadsDir); !isLegacyUpgradeRefusal(err) {
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want migration refusal", err)
}
})
for _, entry := range []string{"beads", ".dolt", "stray-file"} {
t.Run("root holding "+entry, func(t *testing.T) {
captureLegacyUpgradeWarnings(t)
beadsDir := writeEmptyDoltRootServerWorkspace(t, externalServerMetadata, "", "")
path := filepath.Join(beadsDir, "dolt", entry)
var err error
if entry == "stray-file" {
err = os.WriteFile(path, nil, 0o600)
} else {
err = os.Mkdir(path, 0o700)
}
if err != nil {
t.Fatal(err)
}
if err := guardLegacyUpgradeWorkspace(beadsDir); !isLegacyUpgradeRefusal(err) {
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want migration refusal", err)
}
})
}
for _, metadata := range []string{`{"backend":"dolt"}`, `{"backend":"dolt","dolt_mode":"embedded"}`} {
t.Run("embedded "+metadata, func(t *testing.T) {
captureLegacyUpgradeWarnings(t)
beadsDir := writeEmptyDoltRootServerWorkspace(t, metadata, "", "")
if err := guardLegacyUpgradeWorkspace(beadsDir); !isLegacyUpgradeRefusal(err) {
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want migration refusal", err)
}
})
}
}

View file

@ -0,0 +1,141 @@
//go:build cgo
package main
import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"time"
)
// runExternalServerBD runs the bd binary under test in repoDir with env and
// returns its combined output.
func runExternalServerBD(t *testing.T, repoDir string, env []string, args ...string) (string, error) {
t.Helper()
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
cmd := exec.CommandContext(ctx, buildBDUnderTest(t), args...)
cmd.Dir = repoDir
cmd.Env = env
out, err := cmd.CombinedOutput()
if ctxErr := ctx.Err(); ctxErr != nil {
t.Fatalf("bd %s did not finish before the deadline: %v\n%s", strings.Join(args, " "), ctxErr, out)
}
return string(out), err
}
// externalServerTestEnv isolates a bd child from the developer's home and
// config (a real ~/.beads may select a shared server) and from the ambient
// BEADS_DOLT_* endpoint this package's TestMain exports, so only the flags and
// files under test choose the target.
func externalServerTestEnv(t *testing.T) []string {
t.Helper()
home := t.TempDir()
return append(envWithoutBeadsStorageSettings(),
"HOME="+home,
"XDG_CONFIG_HOME="+filepath.Join(home, ".config"),
"BEADS_TEST_IGNORE_REPO_CONFIG=1",
"BD_DISABLE_METRICS=1",
"BEADS_DOLT_AUTO_START=0",
)
}
func externalServerInitArgs(database string, extra ...string) []string {
args := []string{
"init", "--quiet", "--server", "--external",
"--server-host", "127.0.0.1",
"--server-port", fmt.Sprintf("%d", testDoltServerPort),
"--database", database,
"--prefix", "ext",
"--skip-hooks", "--skip-agents",
}
return append(args, extra...)
}
func assertCurrentVersionWitness(t *testing.T, beadsDir string) {
t.Helper()
data, err := os.ReadFile(filepath.Join(beadsDir, localVersionFile))
if err != nil {
t.Fatalf("expected %s after the command: %v", localVersionFile, err)
}
if got := strings.TrimSpace(string(data)); got != Version {
t.Fatalf("%s = %q, want %q", localVersionFile, got, Version)
}
}
// TestExternalServerInitWritesWitnessOverEmptyDoltRoot reproduces the
// provisioner shape: config.yaml already selects server mode and an empty
// .beads/dolt exists before `bd init --server --external` runs. The legacy
// guard used to refuse that init as a "legacy Dolt server workspace", so the
// scope never got a witness and every later command was refused too.
func TestExternalServerInitWritesWitnessOverEmptyDoltRoot(t *testing.T) {
skipIfNoDolt(t)
env := externalServerTestEnv(t)
repoDir := t.TempDir()
initGitRepo(t, repoDir)
beadsDir := filepath.Join(repoDir, ".beads")
if err := os.MkdirAll(filepath.Join(beadsDir, "dolt"), 0o700); err != nil {
t.Fatal(err)
}
writeFile(t, filepath.Join(beadsDir, "config.yaml"), []byte("dolt.mode: server\n"))
database := uniqueTestDBName(t)
t.Cleanup(func() { dropTestDatabase(database, testDoltServerPort) })
out, err := runExternalServerBD(t, repoDir, append(env, "BEADS_DIR="+beadsDir),
externalServerInitArgs(database, "--init-if-missing")...)
if err != nil {
t.Fatalf("bd init --server --external over an empty .beads/dolt failed: %v\n%s", err, out)
}
assertCurrentVersionWitness(t, beadsDir)
}
// TestExternalServerWorkspaceRecoversMissingWitness covers a workspace already
// in the broken state: initialized against an external server, then left
// without .local_version (it is gitignored, so a fresh checkout or a cleanup
// drops it) while bd's own empty .beads/dolt remains. The next ordinary
// command must open the workspace and re-seed the witness with no manual
// steps.
func TestExternalServerWorkspaceRecoversMissingWitness(t *testing.T) {
skipIfNoDolt(t)
env := externalServerTestEnv(t)
repoDir := t.TempDir()
initGitRepo(t, repoDir)
beadsDir := filepath.Join(repoDir, ".beads")
database := uniqueTestDBName(t)
t.Cleanup(func() { dropTestDatabase(database, testDoltServerPort) })
out, err := runExternalServerBD(t, repoDir, env, externalServerInitArgs(database)...)
if err != nil {
t.Fatalf("bd init --server --external failed: %v\n%s", err, out)
}
assertCurrentVersionWitness(t, beadsDir)
entries, err := os.ReadDir(filepath.Join(beadsDir, "dolt"))
if err != nil {
t.Fatalf("precondition: expected bd init to leave a .beads/dolt directory: %v", err)
}
if len(entries) != 0 {
t.Fatalf("precondition: expected an empty .beads/dolt for an external server, found %d entries", len(entries))
}
if err := os.Remove(filepath.Join(beadsDir, localVersionFile)); err != nil {
t.Fatal(err)
}
out, err = runExternalServerBD(t, repoDir, env, "list", "--json", "--all")
if err != nil {
t.Fatalf("bd list on an external-server workspace without a witness failed: %v\n%s", err, out)
}
if strings.Contains(out, "explicit migration is required") {
t.Fatalf("bd list reported a legacy-upgrade refusal:\n%s", out)
}
assertCurrentVersionWitness(t, beadsDir)
}

View file

@ -206,14 +206,12 @@ func TestLegacyUpgradeGuardMetadataLessSQLiteAndCurrentEmbeddedPrecedence(t *tes
}
})
t.Run("explicit server metadata with missing version witness and local Dolt root is refused", func(t *testing.T) {
t.Run("explicit server metadata with missing version witness and populated local Dolt root is refused", func(t *testing.T) {
beadsDir := t.TempDir()
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), []byte(`{"backend":"dolt","dolt_mode":"server"}`), 0o600); err != nil {
t.Fatal(err)
}
if err := os.Mkdir(filepath.Join(beadsDir, "dolt"), 0o700); err != nil {
t.Fatal(err)
}
populateLegacyDoltRoot(t, beadsDir)
if err := guardLegacyUpgradeWorkspace(beadsDir); !isLegacyUpgradeRefusal(err) {
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want migration refusal", err)
}
@ -290,9 +288,7 @@ func TestLegacyUpgradeGuardServerSelectionBeatsStaleEmbeddedRepository(t *testin
t.Fatal(err)
}
}
if err := os.Mkdir(filepath.Join(beadsDir, "dolt"), 0o700); err != nil {
t.Fatal(err)
}
populateLegacyDoltRoot(t, beadsDir)
staleRepo := filepath.Join(beadsDir, "embeddeddolt", "stale", ".dolt")
if err := os.MkdirAll(staleRepo, 0o700); err != nil {
t.Fatal(err)

View file

@ -84,7 +84,8 @@ func TestLegacyServerVersionSpansHistoricalServerEra(t *testing.T) {
}
// writeSelectedServerWorkspace lays down the ambiguous shape the guard has to
// classify: a selected Dolt server workspace that still owns a local Dolt root.
// classify: a selected Dolt server workspace that still owns a populated local
// Dolt root.
func writeSelectedServerWorkspace(t *testing.T, version string) string {
t.Helper()
beadsDir := t.TempDir()
@ -97,9 +98,7 @@ func writeSelectedServerWorkspace(t *testing.T, version string) string {
t.Fatal(err)
}
}
if err := os.Mkdir(filepath.Join(beadsDir, "dolt"), 0o700); err != nil {
t.Fatal(err)
}
populateLegacyDoltRoot(t, beadsDir)
return beadsDir
}

View file

@ -420,7 +420,7 @@ func init() {
listCmd.Flags().String("title", "", "Filter by title text (case-insensitive substring match)")
listCmd.Flags().String("spec", "", "Filter by spec_id prefix")
listCmd.Flags().String("id", "", "Filter by specific issue IDs (comma-separated, e.g., bd-1,bd-5,bd-10)")
listCmd.Flags().IntP("limit", "n", workapi.DefaultListLimit, "Limit results (default 50, use 0 for unlimited)")
listCmd.Flags().IntP("limit", "n", workapi.DefaultListLimit, "Limit results (an explicit --limit always wins, 0 meaning unlimited; otherwise --all is unlimited; otherwise a configured list.limit applies; otherwise unlimited when piped, else 20 in agent mode at a terminal, else 50)")
listCmd.Flags().Int("offset", 0, "Skip the first N matching results (0-based). Only supported under --proxied-server.")
listCmd.Flags().String("format", "", "Output format: 'digraph' (for golang.org/x/tools/cmd/digraph), 'dot' (Graphviz), or Go template")
listCmd.Flags().Bool("all", false, "Show all issues including closed (overrides default filter)")

View file

@ -91,3 +91,62 @@ func TestListLimitPolicyIsResolvedBeforeTheRequest(t *testing.T) {
})
}
}
// GH#6069: the --limit flag help must describe the switch pinned above, in
// the switch's own order, not claim an unconditional "default 50". The whole
// usage string is pinned verbatim: a substring check would accept a clause
// scoped wider than its arm (an earlier draft's "--all is always unlimited"
// contained every needle and was still false, because an explicit --limit
// outranks --all). The cases below tie the three claims a reader is most
// likely to get wrong back to the switch, each with list.limit configured.
func TestListLimitHelpDescribesPipedBehavior(t *testing.T) {
flag := listCmd.Flags().Lookup("limit")
if flag == nil {
t.Fatal("listCmd has no --limit flag registered")
}
const want = "Limit results (an explicit --limit always wins, 0 meaning unlimited; otherwise --all is unlimited; otherwise a configured list.limit applies; otherwise unlimited when piped, else 20 in agent mode at a terminal, else 50)"
if flag.Usage != want {
t.Errorf("--limit help = %q\nwant %q", flag.Usage, want)
}
t.Chdir(t.TempDir())
config.ResetForTesting()
t.Cleanup(config.ResetForTesting)
if err := config.Initialize(); err != nil {
t.Fatalf("config.Initialize: %v", err)
}
config.Set("list.limit", 7)
if got := config.GetValueSource("list.limit"); got == config.SourceDefault {
t.Fatal("precondition: config.Set did not make list.limit count as configured")
}
for _, tc := range []struct {
name string
args []string
want int
needsPipe bool
}{
// limitChanged is the first arm, so --all does not make an explicit
// --limit unlimited. Holds at a terminal or a pipe alike.
{"an explicit --limit outranks --all", []string{"--all", "--limit", "5"}, 5, false},
// The AllFlag arm precedes listLimitConfigured and !IsTerminal, so
// this holds at a terminal too and never needs to skip.
{"--all is unlimited even with list.limit configured", []string{"--all"}, 0, false},
// listLimitConfigured precedes the !IsTerminal arm. Only a piped
// stdout can show that ordering; at a terminal the same 7 would
// prove nothing about the piped arm.
{"piped output takes a configured list.limit", nil, 7, true},
} {
t.Run(tc.name, func(t *testing.T) {
if tc.needsPipe && ui.IsTerminal() {
t.Skip("this case shows a configured list.limit outranking the piped-stdout arm, so stdout must be a pipe; go test's is, this run's is not")
}
in, err := gatherListInput(newListLimitCommand(t, tc.args...))
if err != nil {
t.Fatalf("gatherListInput(%v): %v", tc.args, err)
}
if in.effectiveLimit != tc.want {
t.Errorf("effectiveLimit = %d, want %d", in.effectiveLimit, tc.want)
}
})
}
}

View file

@ -228,16 +228,43 @@ func TestProxiedServerList(t *testing.T) {
})
t.Run("ready_parent_tree_excludes_blocked_descendants", func(t *testing.T) {
// TODO: re-enable once `bd dep add` is ported to proxied mode.
// Currently bd dep add fails with "storage is nil" under proxied
// since the dep subcommand has no usesProxiedServer() dispatch.
t.Skip("requires bd dep add proxied support")
parent := bdProxiedCreate(t, bd, p.dir, "Ready parent tree", "--type", "epic")
readyChild := bdProxiedCreate(t, bd, p.dir, "Ready child in tree", "--type", "task", "--parent", parent.ID)
blockedChild := bdProxiedCreate(t, bd, p.dir, "Blocked child in tree", "--type", "task", "--parent", parent.ID)
blocker := bdProxiedCreate(t, bd, p.dir, "Tree child blocker", "--type", "task")
bdProxiedDep(t, bd, p.dir, "add", blockedChild.ID, blocker.ID)
out := bdProxiedList(t, bd, p, "--ready", "--parent", parent.ID, "--no-pager")
if !strings.Contains(out, readyChild.ID) {
t.Errorf("ready child %s should appear in ready parent tree:\n%s", readyChild.ID, out)
}
if strings.Contains(out, blockedChild.ID) {
t.Errorf("blocked child %s should not appear in ready parent tree:\n%s", blockedChild.ID, out)
}
})
// Regression for gastownhall/beads#3936: relates-to between two epics
// must not nest them, and bidirectional relates-to must not drop them.
// must not nest them in `bd list` tree mode, and a bidirectional
// relates-to must not silently drop both epics from the output.
t.Run("tree_relates_to_does_not_nest_or_drop_epics", func(t *testing.T) {
t.Skip("requires bd dep add proxied support")
epicA := bdProxiedCreate(t, bd, p.dir, "Relates Epic A", "--type", "epic", "--priority", "2")
epicB := bdProxiedCreate(t, bd, p.dir, "Relates Epic B", "--type", "epic", "--priority", "2")
bdProxiedDep(t, bd, p.dir, "add", epicA.ID, epicB.ID, "--type", "relates-to")
out := bdProxiedList(t, bd, p, "--no-pager", "--type", "epic")
if !strings.Contains(out, epicA.ID) || !strings.Contains(out, epicB.ID) {
t.Fatalf("one-direction relates-to should keep both epics visible:\n%s", out)
}
if strings.Contains(out, "└── "+epicA.ID) || strings.Contains(out, "└── "+epicB.ID) ||
strings.Contains(out, "├── "+epicA.ID) || strings.Contains(out, "├── "+epicB.ID) {
t.Fatalf("relates-to must not nest epics under each other:\n%s", out)
}
bdProxiedDep(t, bd, p.dir, "add", epicB.ID, epicA.ID, "--type", "relates-to")
out = bdProxiedList(t, bd, p, "--no-pager", "--type", "epic")
if !strings.Contains(out, epicA.ID) || !strings.Contains(out, epicB.ID) {
t.Fatalf("bidirectional relates-to must not drop epics from tree output:\n%s", out)
}
})
t.Run("ready_parent_filter_includes_grandchildren", func(t *testing.T) {

View file

@ -1465,6 +1465,11 @@ var rootCmd = &cobra.Command{
// would create a local database instead of using the redirect target.
// (GH#bd-0qel)
targetBeadsDir := beads.FindBeadsDir()
if targetBeadsDir == "" {
// An explicit BEADS_DIR is authoritative even
// before it holds project files.
targetBeadsDir = beads.ExplicitBeadsDir()
}
if targetBeadsDir == "" {
targetBeadsDir = ".beads"
}
@ -2077,6 +2082,15 @@ var rootCmd = &cobra.Command{
if shouldAutoPruneEventsJournal(cmd) {
maybeAutoPruneEventsJournal(rootCtx, beads.FindBeadsDir())
}
// Auto-backup, through the provider this command opened. Same
// gate as the direct arm's maintenance net below (strict
// --readonly, `bd serve` and a migration freeze all skip it),
// plus previews: a --dry-run must not register a backup remote
// or write backup state. proxiedAutoBackupBackend decides the
// topology, so this stays inert off managed-local.
if runsPostCommandMaintenance(cmd.Name(), readonlyMode) && !isPreviewCommand(cmd) && !commandFreeze.Frozen() {
runPostRunAutoBackup(rootCtx)
}
if uowProvider != nil {
_ = uowProvider.Close(rootCtx)
uowProvider = nil
@ -2223,31 +2237,9 @@ var rootCmd = &cobra.Command{
_ = traceFile.Close() // Best effort cleanup
}
// Heap profiling: --mem-profile flag or BEADS_MEM_PROFILE env var.
// Runs a GC first by default; BEADS_MEM_PROFILE_NOGC=1 skips it to capture peak.
heapDest := memProfilePath
if heapDest == "" {
heapDest = os.Getenv("BEADS_MEM_PROFILE")
}
if heapDest != "" {
if os.Getenv("BEADS_MEM_PROFILE_NOGC") == "" {
runtime.GC()
}
if f, err := os.Create(heapDest); err == nil { // #nosec G304 -- user-supplied profiling path
_ = pprof.WriteHeapProfile(f)
_ = f.Close()
}
}
// Optional one-line MemStats summary: BEADS_MEM_STATS=/path/to/stats.txt
if statsDest := os.Getenv("BEADS_MEM_STATS"); statsDest != "" {
var ms runtime.MemStats
runtime.ReadMemStats(&ms)
if f, err := os.Create(statsDest); err == nil { // #nosec G304 -- user-supplied profiling path
fmt.Fprintf(f, "HeapAlloc=%d HeapSys=%d HeapInuse=%d HeapObjects=%d\n",
ms.HeapAlloc, ms.HeapSys, ms.HeapInuse, ms.HeapObjects)
_ = f.Close()
}
}
// Heap profiling / MemStats summary: --mem-profile flag or
// BEADS_MEM_PROFILE / BEADS_MEM_STATS env vars. See writeMemDiagnostics.
writeMemDiagnostics(memProfilePath)
// The signal context is canceled and cleared by the deferred hook
// registered at the top of this function, so that it also covers the
@ -2256,6 +2248,69 @@ var rootCmd = &cobra.Command{
},
}
// flusherDiagnosticsSuffix separates the detached send-metrics child's memory
// diagnostics from the parent command's. See memDiagnosticsDest.
const flusherDiagnosticsSuffix = ".send-metrics"
// memDiagnosticsDest returns the destination writeMemDiagnostics should write
// dest to, suffixed when this process is the detached flusher child.
//
// MaybeSpawnFlusher hands the child the parent's environment minus the endpoint
// (flusherChildEnv in internal/metrics/spawn.go), so BEADS_MEM_PROFILE and
// BEADS_MEM_STATS arrive holding the same absolute paths the parent resolved.
// The spawn happens on main()'s post-ExecuteC tail, i.e. after
// PersistentPostRunE already wrote them, so an unsuffixed child would silently
// replace the profile of the command the user actually asked about with a
// profile of the trivial flusher -- no error, no size anomaly. Error exits are
// worse: CheckReadonly and the pre-run gates call CloseAndFlush while
// PersistentPostRunE never runs, leaving the child's file as the only one.
//
// BD_IS_FLUSHER=1 is set only by flusherChildEnv, so a human running
// `bd send-metrics` directly still gets the plain path. The suffix is applied
// to the resolved destination, after the flag/env fallback, so both knobs and
// both sources follow one rule.
func memDiagnosticsDest(dest string) string {
if dest == "" || os.Getenv(metrics.EnvIsFlusher) != "1" {
return dest
}
return dest + flusherDiagnosticsSuffix
}
// writeMemDiagnostics honors the heap-profile and MemStats diagnostic knobs
// (--mem-profile / BEADS_MEM_PROFILE / BEADS_MEM_PROFILE_NOGC / BEADS_MEM_STATS).
// memProfileFlag is the --mem-profile flag value, which wins over
// BEADS_MEM_PROFILE. Both call sites pass memProfilePath: --mem-profile is
// registered on rootCmd.PersistentFlags(), so every subcommand inherits it,
// including the hidden send-metrics one -- which calls this directly because its
// Run exits before Cobra ever reaches PersistentPostRunE below.
func writeMemDiagnostics(memProfileFlag string) {
// Runs a GC first by default; BEADS_MEM_PROFILE_NOGC=1 skips it to capture peak.
heapDest := memProfileFlag
if heapDest == "" {
heapDest = os.Getenv("BEADS_MEM_PROFILE")
}
heapDest = memDiagnosticsDest(heapDest)
if heapDest != "" {
if os.Getenv("BEADS_MEM_PROFILE_NOGC") == "" {
runtime.GC()
}
if f, err := os.Create(heapDest); err == nil { // #nosec G304 -- user-supplied profiling path
_ = pprof.WriteHeapProfile(f)
_ = f.Close()
}
}
// Optional one-line MemStats summary: BEADS_MEM_STATS=/path/to/stats.txt
if statsDest := memDiagnosticsDest(os.Getenv("BEADS_MEM_STATS")); statsDest != "" {
var ms runtime.MemStats
runtime.ReadMemStats(&ms)
if f, err := os.Create(statsDest); err == nil { // #nosec G304 -- user-supplied profiling path
fmt.Fprintf(f, "HeapAlloc=%d HeapSys=%d HeapInuse=%d HeapObjects=%d\n",
ms.HeapAlloc, ms.HeapSys, ms.HeapInuse, ms.HeapObjects)
_ = f.Close()
}
}
}
func shouldRunPostCommandAutoExport(cmd *cobra.Command) bool {
if cmd == nil {
return true

View file

@ -782,7 +782,7 @@ func outputMCPContext(w io.Writer, stealthMode bool) error {
- **Default**: Use beads for ALL task tracking (` + "`bd create`" + `, ` + "`bd ready`" + `, ` + "`bd close`" + `)
- **Prohibited**: Do NOT use TodoWrite, TaskCreate, or markdown files for task tracking
- **Workflow**: Create beads issue BEFORE writing code, mark in_progress when starting
- **Memory**: Use ` + "`bd remember`" + ` for persistent knowledge. Do NOT use MEMORY.md files.
- **Memory**: Use ` + "`bd remember`" + ` for durable project facts, not per-tool memory files. Per-operator preferences belong in your harness's own memory.
- Persistence you don't need beats lost context
- ` + profileRule + `
@ -976,7 +976,7 @@ git status # Check changed files
- **Default**: Use beads for ALL task tracking (` + "`bd create`" + `, ` + "`bd ready`" + `, ` + "`bd close`" + `)
- **Prohibited**: Do NOT use TodoWrite, TaskCreate, or markdown files for task tracking
- **Workflow**: Create beads issue BEFORE writing code, mark in_progress when starting
- **Memory**: Use ` + "`bd remember \"insight\"`" + ` for persistent knowledge across sessions. Do NOT use MEMORY.md files — they fragment across accounts. Search with ` + "`bd memories <keyword>`" + `.
- **Memory**: Use ` + "`bd remember \"insight\"`" + ` for durable **project** facts — keep them here rather than in per-tool memory files, which fragment across accounts and are often capped. Per-operator preferences and agent-specific corrections belong in your harness's own memory; they aren't project knowledge, so keep them out of beads. Search with ` + "`bd memories <keyword>`" + `.
- Persistence you don't need beats lost context
- ` + profileRule + `
- ` + gitWorkflowRule + `

View file

@ -397,6 +397,44 @@ func TestPrimeClaimGuidanceUsesAtomicClaim(t *testing.T) {
}
}
// TestPrimeMemoryGuidanceDoesNotProhibitHarnessMemory guards GH#6111: both
// renderings used to emit "Do NOT use MEMORY.md files", which contradicts
// harnesses that ship a first-party memory whose index file has exactly that
// name. The guidance now names the store each content class belongs in, so
// neither rendering may name the file again. The assertion is negative on the
// old prohibition rather than positive on the new prose, so it survives any
// future rewording; the bd remember check keeps it from passing vacuously if
// the memory bullet is dropped altogether.
func TestPrimeMemoryGuidanceDoesNotProhibitHarnessMemory(t *testing.T) {
defer stubPrimeStoreUnavailable()()
defer stubIsEphemeralBranch(false)()
defer stubPrimeHasGitRemote(true)()
defer stubPrimeAgentProfile(config.ProfileConservative)()
for _, tc := range []struct {
name string
mcpMode bool
}{
{name: "CLI", mcpMode: false},
{name: "MCP", mcpMode: true},
} {
t.Run(tc.name, func(t *testing.T) {
var buf bytes.Buffer
if err := outputPrimeContext(&buf, tc.mcpMode, false); err != nil {
t.Fatalf("outputPrimeContext failed: %v", err)
}
output := buf.String()
if !strings.Contains(output, "bd remember") {
t.Fatalf("prime output should still teach bd remember; output:\n%s", output)
}
if strings.Contains(output, "MEMORY.md") {
t.Errorf("prime output should not name MEMORY.md; output:\n%s", output)
}
})
}
}
func TestPrimeStartsWithTruncationDirective(t *testing.T) {
defer stubPrimeStoreUnavailable()()
defer stubIsEphemeralBranch(false)()

View file

@ -1,5 +1,6 @@
load("@rules_go//go:def.bzl", "go_library", "go_test")
load("@rules_shell//shell:sh_test.bzl", "sh_test")
load("//tools/bazel:race.bzl", "go_test_race_off")
go_library(
name = "protocol",
@ -51,11 +52,32 @@ go_test(
],
)
# protocol_test as pr.yml's "Contract corpus" job runs it: TestMain starts a
# dolt sql-server container and BEADS_PROTOCOL_REQUIRE_DOLT=1 turns a missing
# container into a failure instead of a skip. It repeats protocol_test's `env`
# (go_test_variant.sh cannot inherit it). protocol_test itself stays untagged:
# under --config=prcore (BEADS_TEST_SKIP=dolt) its Dolt-backed tests skip.
# protocol_test without the race detector, which --config=docker otherwise
# turns on for every target: pr.yml's "Contract corpus" job runs
# `go test ./cmd/bd/protocol` without -race (PR Core covers the race build).
# Matching it is cheap: tools/bazel/race.bzl lands protocol_test's deps in
# the configuration the non-race //cmd/bd:bd_for_tests already builds them in,
# so the extra work is protocol_test's test-only libraries and one link.
# Racing it instead would also be acceptable (a race-only failure is a real
# bug); then drop this target and point protocol_docker_test back at
# :protocol_test.
#
# Tags:
# manual: only protocol_docker_test's input, never a build target of its
# own. `bazel test //...` in every lane still builds it through
# protocol_docker_test (a test tag filter does not stop the build).
go_test_race_off(
name = "protocol_race_off",
tags = ["manual"],
test = ":protocol_test",
)
# protocol_test as pr.yml's "Contract corpus" job runs it: non-race, TestMain
# starts a dolt sql-server container and BEADS_PROTOCOL_REQUIRE_DOLT=1 turns a
# missing container into a failure instead of a skip. It repeats
# protocol_test's `env` (go_test_variant.sh cannot inherit it). protocol_test
# itself stays untagged: under --config=prcore (BEADS_TEST_SKIP=dolt) its
# Dolt-backed tests skip.
#
# Tags:
# requires-docker: needs a docker daemon; excluded from --config=prcore/ci,
@ -65,14 +87,17 @@ sh_test(
name = "protocol_docker_test",
size = "large",
srcs = ["//tools/bazel:go_test_variant.sh"],
args = ["$(rootpath :protocol_test)"],
args = ["$(rootpath :protocol_race_off)"],
data = [
":protocol_test",
":protocol_race_off",
"//cmd/bd:bd_for_tests",
],
# Pinned to the container backend (the docker lane is the A/B control);
# rule env beats --test_env, so =local on the command line cannot flip it.
env = {
"BEADS_PROTOCOL_REQUIRE_DOLT": "1",
"BEADS_TEST_BD_BINARY": "$(rlocationpath //cmd/bd:bd_for_tests)",
"BEADS_TEST_DOLT_SERVER": "container",
},
# ~10 min unsharded without -race in pr.yml.
shard_count = 8,
@ -81,3 +106,36 @@ sh_test(
"requires-docker",
],
)
# protocol_test as pr.yml's "Contract corpus" job runs it (non-race, like the
# job; see protocol_race_off), on the dolt-server lane: TestMain's server is a
# local `dolt sql-server` child of the test process, and
# BEADS_PROTOCOL_REQUIRE_DOLT=1 turns a server that cannot start into a
# failure, so the golden and double-run determinism tests cannot skip. It
# repeats protocol_test's `env`. protocol_docker_test is the A/B control.
#
# Tags:
# dolt-server: starts hermetic dolt sql-servers from the pinned dolt in the
# test wrapper's runfiles (BEADS_TEST_DOLT_SERVER=local); excluded from
# --config=prcore/ci, selected by --config=doltserver. Runs remotely: no
# docker, and a missing server fails (REQUIRE=1) instead of skipping, so
# a cached pass is as good as a fresh one.
sh_test(
name = "protocol_dolt_test",
size = "large",
srcs = ["//tools/bazel:go_test_variant.sh"],
args = ["$(rootpath :protocol_race_off)"],
data = [
":protocol_race_off",
"//cmd/bd:bd_for_tests",
],
env = {
"BEADS_PROTOCOL_REQUIRE_DOLT": "1",
"BEADS_TEST_BD_BINARY": "$(rlocationpath //cmd/bd:bd_for_tests)",
"BEADS_TEST_DOLT_SERVER": "local",
"BEADS_TEST_REQUIRE_DOLT_CONTAINER": "1",
"GOMAXPROCS": "4",
},
shard_count = 8,
tags = ["dolt-server"],
)

View file

@ -53,7 +53,9 @@ func testMainInner(m *testing.M) int {
// AD-01 (be-c5p): allow protocol tests to connect to the spawned test server.
os.Setenv("BEADS_TEST_SERVER", "1")
if err := testutil.EnsureDoltContainerForTestMain(); err != nil {
fmt.Fprintf(os.Stderr, "WARN: %v, skipping Dolt tests\n", err)
if testutil.DoltUnavailableForTestMain(err) {
return 1
}
} else {
defer testutil.TerminateDoltContainer()
testDoltPort = testutil.DoltContainerPortInt()

View file

@ -0,0 +1,71 @@
//go:build cgo && unix
package main
import (
"encoding/json"
"strings"
"syscall"
"testing"
"time"
)
// backendCleanExitRetireTimeout bounds how long the proxy may outlive a dolt
// backend that shut down gracefully. dolt's own SIGTERM shutdown dominates it;
// the proxy's health watcher polls every 100ms.
const backendCleanExitRetireTimeout = 30 * time.Second
// TestManagedLocalProxiedBackendCleanExitRetiresProxy extends the child-death
// contract (see TestManagedLocalProxiedOutageReconnectContract, which kills
// the backend) to a backend that exits CLEANLY: SIGTERM makes dolt shut down
// gracefully with status 0. The proxy must retire just as it does for a
// crash, so the next bd command starts a fresh proxy/backend pair and `bd
// ping` answers from a live store.
//
// Before the fix the proxy only noticed non-zero exits. With idle timeout 0
// (never idle out) it stayed up and adoptable in front of a dead backend
// indefinitely: `bd dolt status` said "running", and every command, `bd ping`
// included, failed until an operator ran `bd dolt stop`.
func TestManagedLocalProxiedBackendCleanExitRetiresProxy(t *testing.T) {
requireManagedLocalProxiedEnv(t)
bd := buildEmbeddedBD(t)
p := bdProxiedInit(t, bd, "clean_exit", "--proxied-server-idle-timeout", "0")
sentinel := bdProxiedCreate(t, bd, p.dir, "clean exit sentinel")
proxyBefore := readManagedProxyPidFile(t, p)
if proxyBefore == nil || !processAlive(proxyBefore.Pid) {
t.Fatalf("managed-local proxy is not running: %+v", proxyBefore)
}
backendBefore := readManagedBackendPidFile(t, p)
if backendBefore == nil || !processAlive(backendBefore.Pid) {
t.Fatalf("managed-local backend is not running: %+v", backendBefore)
}
if err := syscall.Kill(backendBefore.Pid, syscall.SIGTERM); err != nil {
t.Fatalf("SIGTERM dolt backend pid %d: %v", backendBefore.Pid, err)
}
waitForManagedProxiedShutdown(t, p, proxyBefore.Pid, backendBefore.Pid, backendCleanExitRetireTimeout)
out, err := bdProxiedRun(t, bd, p.dir, "ping", "--json")
if err != nil {
t.Fatalf("bd ping after the backend exited: %v\n%s", err, out)
}
var ping struct {
Status string `json:"status"`
}
if err := json.Unmarshal([]byte(strings.TrimSpace(string(out))), &ping); err != nil || ping.Status != "ok" {
t.Fatalf("bd ping --json: status=%q err=%v\n%s", ping.Status, err, out)
}
if got := bdProxiedShow(t, bd, p.dir, sentinel.ID); got.Title != "clean exit sentinel" {
t.Fatalf("sentinel after restart: %+v", got)
}
proxyAfter := readManagedProxyPidFile(t, p)
backendAfter := readManagedBackendPidFile(t, p)
if proxyAfter == nil || proxyAfter.Pid == proxyBefore.Pid || !processAlive(proxyAfter.Pid) {
t.Fatalf("expected a fresh live proxy: before=%+v after=%+v", proxyBefore, proxyAfter)
}
if backendAfter == nil || backendAfter.Pid == backendBefore.Pid || !processAlive(backendAfter.Pid) {
t.Fatalf("expected a fresh live backend: before=%+v after=%+v", backendBefore, backendAfter)
}
}

View file

@ -35,6 +35,9 @@ func sharedProxiedServerPort(t *testing.T) int {
sharedProxiedPort = port
})
if sharedProxiedErr != nil {
if os.Getenv(testutil.EnvRequireDoltContainer) == "1" {
t.Fatalf("shared proxied-server unavailable: %v, but %s=1; this lane must not skip", sharedProxiedErr, testutil.EnvRequireDoltContainer)
}
t.Skipf("shared proxied-server unavailable: %v", sharedProxiedErr)
}
return sharedProxiedPort

View file

@ -167,8 +167,10 @@ var (
// is threading it through the UOW reader the way `list` already does, so
// the refusal itself is the gap.
maxRowsRefusal = refused("proxy.max_rows.unsupported", "--max-rows / BEADS_MAX_ROWS is not supported in proxied-server mode", ProxyReasonUnimplemented, trackLongTail)
// `list --watch` is routed, so watching is possible over the provider;
// nothing else has been wired to it.
// The mode-wide default for a --watch that has not been wired to the
// provider. Both commands that register the flag (`list`, `show`) poll the
// provider and are honored per-command below, so this refuses only a
// future --watch until someone routes it.
watchRefusal = refused("proxy.watch.unsupported", "watch mode not supported in proxied-server mode", ProxyReasonUnimplemented, trackLongTail)
// --repo routes to another workspace, bypassing the proxied root entirely,
// which is why it is design rather than a gap. `bd create` is the only
@ -219,7 +221,7 @@ var proxyCapabilityMatrix = map[ProxyMode]map[ProxyCapability]proxyCapabilityRul
// command line can reach. TestProxyCapabilityRowsNameFlagsTheCommandRegisters
// enforces both directions of that rule.
var proxyCommandCapabilities = map[string]map[ProxyMode]map[ProxyCapability]proxyCapabilityRule{
"show": {ProxyModeProxied: {ProxyCapWatch: watchRefusal}},
"show": {ProxyModeProxied: {ProxyCapWatch: honored()}},
"list": {ProxyModeProxied: {ProxyCapWatch: honored(), ProxyCapMaxRows: honored(), ProxyCapRepo: notApplicable()}},
"dep tree": {ProxyModeProxied: {ProxyCapMaxRows: honored()}},
"ready": {ProxyModeProxied: {ProxyCapMaxRows: maxRowsRefusal}},
@ -348,11 +350,6 @@ func validateProxyCapabilitiesBeforeProvider(cmd *cobra.Command) error {
if path == "create" && cmd.Flags().Changed("repo") {
return HandleProxyCapabilityError(AssertProxyCapability(ProxyModeProxied, ProxyCapRepo))
}
if path == "show" {
if watch, _ := cmd.Flags().GetBool("watch"); watch {
return HandleProxyCapabilityError(AssertProxyCommandCapability(path, ProxyModeProxied, ProxyCapWatch))
}
}
if path == "ready" && !readyGatedArm(cmd) {
// --claim is NOT exempt. The proxied ready role cannot enforce a row
// cap on either arm, and ready.go refuses a positive cap on both (see

View file

@ -470,7 +470,7 @@ func TestProxyCapabilityCommandRows(t *testing.T) {
{"ready", "--max-rows", ProxyOutcomeRefused},
{"graph", "--max-rows", ProxyOutcomeRefused},
{"find-duplicates", "--max-rows", ProxyOutcomeRefused},
{"show", "--watch", ProxyOutcomeRefused},
{"show", "--watch", ProxyOutcomeHonored},
{"list", "--watch", ProxyOutcomeHonored},
}
for _, topology := range []ProxyTopology{ProxyTopologyManagedLocal, ProxyTopologyExternalTCP, ProxyTopologyExternalUnix} {
@ -634,21 +634,21 @@ func TestProxyMaintenanceRefusalLeavesFilesUntouched(t *testing.T) {
}
}
// newWatchShowCommand builds `bd show --watch`. The root matters: the front
// door keys on a command's path below its root, so a parentless command has no
// path and matches no rule — which is how a test tree can report success for a
// refusal that never fired.
func newWatchShowCommand(t *testing.T) *cobra.Command {
// newProxyFrontDoorCommand builds `bd <use> --<flag>` under a real root. The
// root matters: the front door keys on a command's path below its root, so a
// parentless command has no path and matches no rule — which is how a test
// tree can report success for a refusal that never fired.
func newProxyFrontDoorCommand(t *testing.T, use, flag string) *cobra.Command {
t.Helper()
root := &cobra.Command{Use: "bd"}
cmd := &cobra.Command{Use: "show"}
cmd.Flags().Bool("watch", false, "")
cmd := &cobra.Command{Use: use}
cmd.Flags().Bool(flag, false, "")
root.AddCommand(cmd)
if err := cmd.Flags().Set("watch", "true"); err != nil {
if err := cmd.Flags().Set(flag, "true"); err != nil {
t.Fatal(err)
}
if got := commandRegistryPath(cmd); got != "show" {
t.Fatalf("test command path = %q, want %q", got, "show")
if got := commandRegistryPath(cmd); got != use {
t.Fatalf("test command path = %q, want %q", got, use)
}
return cmd
}
@ -657,9 +657,9 @@ func TestProxyCapabilityRefusalFrontDoorTextBeforeProvider(t *testing.T) {
oldJSON := jsonOutput
jsonOutput = false
t.Cleanup(func() { jsonOutput = oldJSON })
cmd := newWatchShowCommand(t)
cmd := newProxyFrontDoorCommand(t, "create", "repo")
got := captureStderr(t, func() { _ = validateProxyCapabilitiesBeforeProvider(cmd) })
if !strings.Contains(got, "watch mode not supported in proxied-server mode") {
if !strings.Contains(got, "--repo is not supported with --proxied-server") {
t.Fatalf("text refusal = %q", got)
}
}
@ -668,16 +668,37 @@ func TestProxyCapabilityRefusalFrontDoorJSONIncludesCode(t *testing.T) {
oldJSON := jsonOutput
jsonOutput = true
t.Cleanup(func() { jsonOutput = oldJSON })
cmd := newWatchShowCommand(t)
cmd := newProxyFrontDoorCommand(t, "create", "repo")
out := captureStdout(t, func() error {
_ = validateProxyCapabilitiesBeforeProvider(cmd)
return nil
})
if !strings.Contains(out, `"code": "proxy.watch.unsupported"`) {
if !strings.Contains(out, `"code": "proxy.repo.unsupported"`) {
t.Fatalf("JSON refusal = %q", out)
}
}
// TestProxyFrontDoorAdmitsShowWatch pins that `bd show --watch` reaches the
// proxied provider. It used to be refused here with proxy.watch.unsupported,
// although the provider can answer the poll exactly as `list --watch` does.
func TestProxyFrontDoorAdmitsShowWatch(t *testing.T) {
oldJSON := jsonOutput
jsonOutput = true
t.Cleanup(func() { jsonOutput = oldJSON })
cmd := newProxyFrontDoorCommand(t, "show", "watch")
var err error
out := captureStdout(t, func() error {
err = validateProxyCapabilitiesBeforeProvider(cmd)
return nil
})
if err != nil || strings.Contains(out, "proxy.watch.unsupported") {
t.Fatalf("front door refused show --watch: err=%v out=%q", err, out)
}
if err := AssertProxyCommandCapability("show", ProxyModeProxied, ProxyCapWatch); err != nil {
t.Fatalf("show --watch capability refused: %v", err)
}
}
func TestProxyCapabilityDirectEscapeHatch(t *testing.T) {
for _, cap := range []ProxyCapability{ProxyCapReadonly, ProxyCapMaxRows, ProxyCapWatch, ProxyCapRepo} {
if err := AssertProxyCapability(ProxyModeDirect, cap); err != nil {

View file

@ -18,7 +18,17 @@ var sendMetricsCmd = &cobra.Command{
// send-metrics. MaybeSpawnFlusher also refuses to spawn when EnvIsFlusher
// is set on this process, so the no-recursion guarantee is structural and
// not solely dependent on this exit.
os.Exit(metrics.RunSendMetrics())
//
// That same early exit means this Run returns before Cobra ever reaches
// PersistentPostRunE in main.go, so --mem-profile/BEADS_MEM_PROFILE/
// BEADS_MEM_STATS are silently inert for this subcommand unless honored
// here directly (be-wwy2.2). --mem-profile is registered on
// rootCmd.PersistentFlags(), so this hidden command inherits it and
// prints it in --help; pass memProfilePath exactly as PersistentPostRunE
// does, or the advertised flag would be parsed and then discarded.
code := metrics.RunSendMetrics()
writeMemDiagnostics(memProfilePath)
os.Exit(code)
},
}

View file

@ -0,0 +1,215 @@
package main
import (
"compress/gzip"
"io"
"os"
"os/exec"
"path/filepath"
"regexp"
"testing"
"github.com/steveyegge/beads/internal/metrics"
)
// memStatsLine is the exact shape writeMemDiagnostics' MemStats summary writes.
var memStatsLine = regexp.MustCompile(`^HeapAlloc=\d+ HeapSys=\d+ HeapInuse=\d+ HeapObjects=\d+\n$`)
// requireHeapProfile fails unless path holds a real heap profile.
// runtime/pprof.WriteHeapProfile always gzips its protobuf output, so
// decompressing cleanly to a non-empty body is strong evidence a genuine profile
// was written -- without pulling in a pprof-parsing dependency just for this
// test. knob names the surface under test so a failure says which one broke.
func requireHeapProfile(t *testing.T, knob, path string) {
t.Helper()
f, err := os.Open(path)
if err != nil {
t.Fatalf("%s file was not written: %v", knob, err)
}
defer f.Close()
gz, err := gzip.NewReader(f)
if err != nil {
t.Fatalf("%s is not valid gzip: %v", knob, err)
}
body, err := io.ReadAll(gz)
if err != nil {
t.Fatalf("%s gzip stream corrupt: %v", knob, err)
}
if len(body) == 0 {
t.Fatalf("%s decompressed to 0 bytes, want a real heap profile", knob)
}
}
// TestSendMetricsHonorsMemDiagnostics is the be-wwy2.2 regression: send-metrics's
// Run calls os.Exit() directly, so it returns before Cobra ever reaches
// PersistentPostRunE (main.go) -- the one place --mem-profile / BEADS_MEM_PROFILE /
// BEADS_MEM_PROFILE_NOGC / BEADS_MEM_STATS are honored for every other bd
// subcommand. That makes the diagnostic tooling unreachable for the one child
// process that runs on the tail of nearly every bd invocation fleet-wide.
//
// This builds a real bd binary and exercises `bd send-metrics` as a subprocess
// (like MaybeSpawnFlusher does in production) rather than calling RunSendMetrics
// in-process, because the bug is specifically about the Cobra command-tree
// wiring around this subcommand, which only an actual subprocess run exercises.
func TestSendMetricsHonorsMemDiagnostics(t *testing.T) {
bdBin := buildBDForInitTests(t)
// send-metrics returns from PersistentPreRunE before any workspace/store
// setup (main.go: `if cmd.Name() == metrics.SendMetricsSubcommand { return nil }`),
// so no .beads workspace is needed here. BD_DISABLE_METRICS=1 makes
// RunSendMetrics's Enabled() check false, so it returns 0 right after a
// no-op prune of the (nonexistent) queue dir -- deterministic and offline,
// with no real network attempt.
baseEnv := func(home string) []string {
return []string{
"HOME=" + home,
"PATH=" + os.Getenv("PATH"),
"BD_DISABLE_METRICS=1",
}
}
t.Run("default with no diagnostics env vars is unaffected", func(t *testing.T) {
cmd := exec.Command(bdBin, metrics.SendMetricsSubcommand)
cmd.Env = baseEnv(t.TempDir())
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("bd send-metrics: %v\noutput: %s", err, out)
}
if len(out) != 0 {
t.Fatalf("bd send-metrics produced output with no diagnostics requested: %q", out)
}
})
t.Run("BEADS_MEM_STATS writes a one-line MemStats summary", func(t *testing.T) {
statsPath := filepath.Join(t.TempDir(), "stats.txt")
cmd := exec.Command(bdBin, metrics.SendMetricsSubcommand)
cmd.Env = append(baseEnv(t.TempDir()), "BEADS_MEM_STATS="+statsPath)
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("bd send-metrics: %v\noutput: %s", err, out)
}
data, err := os.ReadFile(statsPath)
if err != nil {
t.Fatalf("BEADS_MEM_STATS file was not written: %v", err)
}
if !memStatsLine.Match(data) {
t.Fatalf("BEADS_MEM_STATS content = %q, want match of %s", data, memStatsLine)
}
})
t.Run("BEADS_MEM_PROFILE writes a valid gzipped heap profile", func(t *testing.T) {
profilePath := filepath.Join(t.TempDir(), "heap.pprof")
cmd := exec.Command(bdBin, metrics.SendMetricsSubcommand)
cmd.Env = append(baseEnv(t.TempDir()), "BEADS_MEM_PROFILE="+profilePath)
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("bd send-metrics: %v\noutput: %s", err, out)
}
requireHeapProfile(t, "BEADS_MEM_PROFILE", profilePath)
})
// --mem-profile is registered on rootCmd.PersistentFlags() (main.go), so this
// hidden subcommand inherits it and advertises it in --help. The call site
// used to hardcode "", which parsed the flag and then discarded it -- the same
// "accepted but silently inert" state be-wwy2.2 exists to remove, one line
// below the fix. No BEADS_MEM_PROFILE here, so only the flag can produce the
// file.
t.Run("--mem-profile flag is honored, not just the env var", func(t *testing.T) {
profilePath := filepath.Join(t.TempDir(), "flag.pprof")
cmd := exec.Command(bdBin, metrics.SendMetricsSubcommand, "--mem-profile="+profilePath)
cmd.Env = baseEnv(t.TempDir())
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("bd send-metrics --mem-profile: %v\noutput: %s", err, out)
}
requireHeapProfile(t, "--mem-profile", profilePath)
})
// The detached flusher child inherits the parent's BEADS_MEM_* paths verbatim
// (flusherChildEnv strips only the endpoint and the flusher marker), and
// MaybeSpawnFlusher runs on main()'s post-ExecuteC tail -- after
// PersistentPostRunE already wrote them. Without a distinct destination the
// child's trivial profile would silently replace the profile of the command
// the user actually asked about. BD_IS_FLUSHER=1 is what production sets on
// the child, so driving it here is the real shape, not a contrivance.
t.Run("flusher child writes beside the parent's files instead of over them", func(t *testing.T) {
dir := t.TempDir()
profilePath := filepath.Join(dir, "heap.pprof")
statsPath := filepath.Join(dir, "stats.txt")
// Stand in for the parent command's own writeMemDiagnostics call, which
// has already happened by the time the flusher is spawned.
parentProfile := []byte("parent heap profile, must survive the spawn\n")
parentStats := []byte("parent memstats, must survive the spawn\n")
if err := os.WriteFile(profilePath, parentProfile, 0o600); err != nil {
t.Fatalf("seed parent profile: %v", err)
}
if err := os.WriteFile(statsPath, parentStats, 0o600); err != nil {
t.Fatalf("seed parent stats: %v", err)
}
cmd := exec.Command(bdBin, metrics.SendMetricsSubcommand)
cmd.Env = append(baseEnv(t.TempDir()),
"BEADS_MEM_PROFILE="+profilePath,
"BEADS_MEM_STATS="+statsPath,
metrics.EnvIsFlusher+"=1",
)
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("bd send-metrics as flusher child: %v\noutput: %s", err, out)
}
// The parent's data is untouched, byte for byte.
if got, err := os.ReadFile(profilePath); err != nil {
t.Fatalf("parent profile disappeared: %v", err)
} else if string(got) != string(parentProfile) {
t.Fatalf("flusher child overwrote the parent's heap profile: got %q, want %q", got, parentProfile)
}
if got, err := os.ReadFile(statsPath); err != nil {
t.Fatalf("parent stats disappeared: %v", err)
} else if string(got) != string(parentStats) {
t.Fatalf("flusher child overwrote the parent's MemStats: got %q, want %q", got, parentStats)
}
// ...and the child's own diagnostics are still produced, just beside
// them. This is the half that distinguishes suffixing the destination
// from simply scrubbing the vars out of the child's environment, which
// would reinstate the inertness be-wwy2.2 removes.
requireHeapProfile(t, "flusher child BEADS_MEM_PROFILE", profilePath+".send-metrics")
childStats, err := os.ReadFile(statsPath + ".send-metrics")
if err != nil {
t.Fatalf("flusher child wrote no MemStats of its own: %v", err)
}
if !memStatsLine.Match(childStats) {
t.Fatalf("flusher child MemStats content = %q, want match of %s", childStats, memStatsLine)
}
})
t.Run("BEADS_MEM_PROFILE_NOGC is accepted and still writes the profile", func(t *testing.T) {
profilePath := filepath.Join(t.TempDir(), "heap.pprof")
cmd := exec.Command(bdBin, metrics.SendMetricsSubcommand)
cmd.Env = append(baseEnv(t.TempDir()), "BEADS_MEM_PROFILE="+profilePath, "BEADS_MEM_PROFILE_NOGC=1")
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("bd send-metrics: %v\noutput: %s", err, out)
}
if _, err := os.Stat(profilePath); err != nil {
t.Fatalf("BEADS_MEM_PROFILE file was not written under NOGC: %v", err)
}
})
t.Run("diagnostics still run and exit code is preserved when RunSendMetrics fails", func(t *testing.T) {
statsPath := filepath.Join(t.TempDir(), "stats.txt")
cmd := exec.Command(bdBin, metrics.SendMetricsSubcommand)
// Deliberately no HOME: DataDir()'s os.UserHomeDir() fails
// deterministically and offline, so RunSendMetrics() returns 1 before
// ever reaching the enabled/network checks.
cmd.Env = []string{"PATH=" + os.Getenv("PATH"), "BEADS_MEM_STATS=" + statsPath}
out, err := cmd.CombinedOutput()
exitErr, ok := err.(*exec.ExitError)
if !ok {
t.Fatalf("bd send-metrics: want a non-zero *exec.ExitError, got %v (%T)\noutput: %s", err, err, out)
}
if code := exitErr.ExitCode(); code != 1 {
t.Fatalf("bd send-metrics exit code = %d, want 1 (RunSendMetrics's own failure code, preserved through the fix)", code)
}
if _, statErr := os.Stat(statsPath); statErr != nil {
t.Fatalf("BEADS_MEM_STATS file was not written even though the command failed: %v", statErr)
}
})
}

View file

@ -99,8 +99,7 @@ var showCmd = &cobra.Command{
if len(args) != 1 {
return HandleErrorRespectJSON("watch mode requires exactly one issue ID")
}
watchIssue(ctx, args[0])
return nil
return watchIssue(ctx, args[0])
}
if showThread {

View file

@ -14,73 +14,109 @@ import (
"github.com/steveyegge/beads/internal/uimd"
)
// displayShowIssue displays a single issue (reusable for watch mode).
// Matches the full bd show output: header, metadata, content, labels, deps, comments.
func displayShowIssue(ctx context.Context, issueID string) {
displayShowIssueReturn(ctx, issueID)
}
// singleIssueSnapshot builds a comparable string from a single issue's state
// so we can detect when the issue has changed between poll cycles.
func singleIssueSnapshot(issue *types.Issue) string {
return fmt.Sprintf("%s:%s:%d", issue.ID, issue.Status, issue.UpdatedAt.UnixNano())
}
// issueWatchSource is what a `bd show --watch` loop reads from. render draws
// the full view and returns the issue it drew, or nil when there was nothing to
// draw (it reports why itself); fetch re-reads the issue for the change check
// and must not print anything, since the loop owns what a failed poll means.
// The direct store and the proxied-server provider each supply one, so both
// routes share the snapshot, redraw and poll-failure rules below instead of
// copying them.
type issueWatchSource struct {
render func(ctx context.Context) *types.Issue
fetch func(ctx context.Context) (*types.Issue, error)
}
// showWatchPollInterval is how often a watched issue is re-read.
const showWatchPollInterval = 2 * time.Second
// watchIssue polls for changes to an issue and auto-refreshes the display (GH#654).
// Uses polling instead of fsnotify because Dolt stores data in a server-side
// database, not files — file watchers never fire.
func watchIssue(ctx context.Context, issueID string) {
// Initial display and snapshot
issue := displayShowIssueReturn(ctx, issueID)
func watchIssue(ctx context.Context, issueID string) error {
return runIssueWatch(ctx, issueWatchSource{
render: func(ctx context.Context) *types.Issue { return displayShowIssueReturn(ctx, issueID) },
fetch: func(ctx context.Context) (*types.Issue, error) { return fetchIssue(ctx, issueID) },
})
}
// runIssueWatch drives watchIssueLoop on a real ticker until Ctrl+C or SIGTERM.
// It fails when the initial render found nothing to watch; the render has
// already said why, so the failure is silent.
func runIssueWatch(ctx context.Context, src issueWatchSource) error {
// Deferred Stop prevents signal handler leak
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
defer signal.Stop(sigChan)
ticker := time.NewTicker(showWatchPollInterval)
defer ticker.Stop()
if !watchIssueLoop(ctx, src, ticker.C, sigChan) {
return SilentExit()
}
return nil
}
// watchIssueLoop renders the issue once, then on every tick re-reads it and
// redraws only when singleIssueSnapshot changes. A poll that fails — the
// issue was deleted, the backend blipped, a unit of work would not open — keeps
// the last render on screen and is retried on the next tick without printing:
// the watch is a live view, and a line (or, under --json, an error object) on
// every tick for a condition the user can already see would bury it. It
// returns when stop fires, or immediately, reporting false, when the initial
// render found nothing to watch.
func watchIssueLoop(ctx context.Context, src issueWatchSource, tick <-chan time.Time, stop <-chan os.Signal) bool {
issue := src.render(ctx)
if issue == nil {
return
return false
}
lastSnapshot := singleIssueSnapshot(issue)
fmt.Fprintf(os.Stderr, "\nWatching for changes... (Press Ctrl+C to exit)\n")
// Handle Ctrl+C — deferred Stop prevents signal handler leak
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
defer signal.Stop(sigChan)
pollInterval := 2 * time.Second
ticker := time.NewTicker(pollInterval)
defer ticker.Stop()
for {
select {
case <-sigChan:
case <-stop:
fmt.Fprintf(os.Stderr, "\nStopped watching.\n")
return
case <-ticker.C:
issue := fetchIssue(ctx, issueID)
if issue == nil {
return true
case <-tick:
issue, err := src.fetch(ctx)
if err != nil || issue == nil {
continue
}
snap := singleIssueSnapshot(issue)
if snap != lastSnapshot {
lastSnapshot = snap
displayShowIssue(ctx, issueID)
src.render(ctx)
fmt.Fprintf(os.Stderr, "\nWatching for changes... (Press Ctrl+C to exit)\n")
}
}
}
}
// fetchIssue retrieves a single issue by ID, returning nil on error.
func fetchIssue(ctx context.Context, issueID string) *types.Issue {
// fetchIssue retrieves a single issue by ID without printing anything.
func fetchIssue(ctx context.Context, issueID string) (*types.Issue, error) {
result, err := resolveAndGetIssueWithRouting(ctx, store, issueID)
if result != nil {
defer result.Close()
}
if err != nil || result == nil || result.Issue == nil {
return nil
if err != nil {
return nil, err
}
return result.Issue
if result == nil || result.Issue == nil {
return nil, fmt.Errorf("issue %s not found", issueID)
}
return result.Issue, nil
}
// displayShowIssueReturn displays a single issue and returns it for snapshot use.
// Matches the full bd show output: header, metadata, content, labels, deps, comments.
func displayShowIssueReturn(ctx context.Context, issueID string) *types.Issue {
result, err := resolveAndGetIssueWithRouting(ctx, store, issueID)
if result != nil {

View file

@ -3,13 +3,16 @@
package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"os/exec"
"strings"
"sync"
"testing"
"time"
"github.com/steveyegge/beads/internal/types"
)
@ -148,6 +151,28 @@ func TestEmbeddedShow(t *testing.T) {
bdShowFail2(t, bd, dir, "ts-nonexistent999")
})
// A watch on an id that does not exist used to print "Issue not found"
// and exit 0 on this route, watching nothing. It now exits 1 like plain
// `bd show <missing>`, and like the proxied route.
t.Run("show_watch_nonexistent_id_exits_1", func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
cmd := exec.CommandContext(ctx, bd, "show", "ts-nonexistent999", "--watch")
cmd.Dir = dir
cmd.Env = bdEnv(dir)
out, err := cmd.CombinedOutput()
if ctx.Err() != nil {
t.Fatalf("bd show --watch on a missing id kept watching:\n%s", out)
}
var exitErr *exec.ExitError
if !errors.As(err, &exitErr) || exitErr.ExitCode() != 1 {
t.Fatalf("bd show --watch on a missing id: err=%v, want exit 1\n%s", err, out)
}
if !strings.Contains(string(out), "ts-nonexistent999") {
t.Errorf("output does not name the missing id:\n%s", out)
}
})
t.Run("show_no_args", func(t *testing.T) {
bdShowFail2(t, bd, dir)
})

View file

@ -908,17 +908,6 @@ func TestProxiedServerShow3(t *testing.T) {
}
})
t.Run("show_watch_rejected_in_proxied_mode", func(t *testing.T) {
t.Parallel()
p := newSharedProxiedProject(t, bd, "swt")
issue := bdProxiedCreate(t, bd, p.dir, "Watch test", "--type", "task")
stdout, stderr := bdProxiedShowFail(t, bd, p.dir, issue.ID, "--watch")
combined := stdout + stderr
if !strings.Contains(combined, "watch mode not supported in proxied-server mode") {
t.Errorf("expected proxied watch-rejection error, got: %s", combined)
}
})
t.Run("show_wisp_comments_default_count_only", func(t *testing.T) {
t.Parallel()
p := newSharedProxiedProject(t, bd, "swcc")

View file

@ -94,19 +94,47 @@ func proxiedIssueReader() (issueops.Reader, error) {
func runShowProxiedServer(cmd *cobra.Command, ctx context.Context, args []string) error {
in := gatherShowProxiedInput(cmd, args)
if in.watchMode {
// Defense in depth, like create's --repo fallback: the pre-provider
// gate refuses `show --watch` first. Typed so all three refusals render
// identically if one ever becomes reachable.
return HandleProxyCapabilityError(AssertProxyCommandCapability("show", ProxyModeProxied, ProxyCapWatch))
}
uw, err := proxiedOpenReadUOW(ctx)
if err != nil {
return err
}
if err := resolveShowProxiedIDs(ctx, uw, in); err != nil {
uw.Close(ctx)
return err
}
// Same precedence as the direct route: --as-of answers a point-in-time
// read, which has nothing to watch.
if in.watchMode && in.asOfRef == "" {
// The watch opens a fresh unit of work per poll; holding this one
// would pin a transaction for as long as the user watches.
uw.Close(ctx)
if len(in.ids) != 1 {
return HandleErrorRespectJSON("watch mode requires exactly one issue ID")
}
return runIssueWatch(ctx, proxiedIssueWatchSource(in))
}
defer uw.Close(ctx)
switch {
case in.asOfRef != "":
runShowProxiedAsOf(ctx, uw, in)
case in.thread:
return runShowProxiedThread(ctx, uw, in)
case in.refs:
runShowProxiedRefs(ctx, uw, in)
case in.children:
runShowProxiedChildren(ctx, uw, in)
default:
return runShowProxiedDefault(ctx, uw, in)
}
return nil
}
// resolveShowProxiedIDs turns --current into an explicit id and rejects an
// empty id list, the same checks the direct route makes before dispatching.
func resolveShowProxiedIDs(ctx context.Context, uw uow.UnitOfWork, in *showProxiedInput) error {
if in.currentMode {
if len(in.ids) > 0 {
return HandleErrorRespectJSON("--current cannot be combined with explicit issue IDs")
@ -121,19 +149,6 @@ func runShowProxiedServer(cmd *cobra.Command, ctx context.Context, args []string
if len(in.ids) == 0 {
return HandleErrorRespectJSON("at least one issue ID is required (use positional args, --id flag, or --current)")
}
switch {
case in.asOfRef != "":
runShowProxiedAsOf(ctx, uw, in)
case in.thread:
return runShowProxiedThread(ctx, uw, in)
case in.refs:
runShowProxiedRefs(ctx, uw, in)
case in.children:
runShowProxiedChildren(ctx, uw, in)
default:
return runShowProxiedDefault(ctx, uw, in)
}
return nil
}
@ -507,9 +522,10 @@ func proxiedRenderIssue(ctx context.Context, uw uow.UnitOfWork, issue *types.Iss
// A READ on an ALTERNATE view. `bd show`'s detail view is on
// issueops.Reader on both routes and gets its labels hydrated there; this
// renderer serves --refs, --children, --thread and --as-of, which answer
// with shapes the Reader contract does not describe, from a unit of work
// the caller already holds and has already read the issue from. Asking the
// renderer serves the text views the Reader contract does not describe —
// --refs, --children, --thread, --as-of, and every render of --watch
// (show_proxied_watch.go) — from a unit of work the caller already holds
// and has already read the issue from. Asking the
// role here would open a second transaction to re-fetch a row this function
// was handed. Alternate views reaching roles of their own is the follow-up
// (ga-2ltro.12).

View file

@ -0,0 +1,57 @@
package main
import (
"context"
"errors"
"time"
"github.com/steveyegge/beads/internal/types"
"github.com/steveyegge/beads/internal/workapi"
)
// proxiedIssueWatchSource feeds `bd show --watch` from the proxied-server
// provider. Every render and every poll opens its own short unit of work, so a
// long watch never pins a transaction and each read sees the latest commit.
// After the first render the resolved id is used, so a partial id is resolved
// once, as the direct route's first render does.
func proxiedIssueWatchSource(in *showProxiedInput) issueWatchSource {
id := in.ids[0]
formatTime := func(t time.Time) string {
if in.localTime {
t = t.Local()
}
return t.Format("2006-01-02 15:04")
}
return issueWatchSource{
render: func(ctx context.Context) *types.Issue {
uw, err := proxiedOpenReadUOW(ctx)
if err != nil {
return nil
}
defer uw.Close(ctx)
issue, isWisp, err := workapi.GetIssueOrWisp(ctx, workapi.NewUOWDetailSource(uw), id)
if err != nil {
reportIssueLookupFailure("fetching", id, err)
return nil
}
id = issue.ID
proxiedRenderIssue(ctx, uw, issue, isWisp, in, 0, formatTime)
return issue
},
// Opens its unit of work directly rather than through
// proxiedOpenReadUOW, which reports its own failure: a poll must stay
// silent and leave the verdict to watchIssueLoop.
fetch: func(ctx context.Context) (*types.Issue, error) {
if uowProvider == nil {
return nil, errors.New("proxied-server UOW provider not initialized")
}
uw, err := uowProvider.NewUOW(ctx)
if err != nil {
return nil, err
}
defer uw.Close(ctx)
issue, _, err := workapi.GetIssueOrWisp(ctx, workapi.NewUOWDetailSource(uw), id)
return issue, err
},
}
}

View file

@ -0,0 +1,216 @@
//go:build cgo
package main
import (
"bytes"
"os/exec"
"strings"
"sync"
"syscall"
"testing"
"time"
)
// watchBannerWriter buffers a stream and signals every time the watch banner
// is printed, so a test can wait for the Nth render instead of sleeping.
type watchBannerWriter struct {
mu sync.Mutex
buf bytes.Buffer
count int
renders chan int
}
const showWatchBanner = "Watching for changes..."
func (w *watchBannerWriter) Write(p []byte) (int, error) {
w.mu.Lock()
defer w.mu.Unlock()
n, err := w.buf.Write(p)
if now := strings.Count(w.buf.String(), showWatchBanner); now > w.count {
w.count = now
select {
case w.renders <- now:
default:
}
}
return n, err
}
func (w *watchBannerWriter) String() string {
w.mu.Lock()
defer w.mu.Unlock()
return w.buf.String()
}
// waitForRender blocks until the banner has been printed at least want times,
// giving up when the process exits or the timeout elapses.
func (w *watchBannerWriter) waitForRender(want int, timeout time.Duration, exited <-chan struct{}) bool {
deadline := time.After(timeout)
for {
w.mu.Lock()
got := w.count
w.mu.Unlock()
if got >= want {
return true
}
select {
case <-w.renders:
case <-exited:
w.mu.Lock()
defer w.mu.Unlock()
return w.count >= want
case <-deadline:
return false
}
}
}
// TestProxiedServerShowWatch pins `bd show --watch` under --proxied-server to
// the direct route's contract: render once, redraw when the issue's
// status/updated_at snapshot changes, and stop cleanly on SIGINT. Proxied mode
// used to refuse it outright (proxy.watch.unsupported), so every consumer on
// the default proxied transport had to reimplement the poll itself.
func TestProxiedServerShowWatch(t *testing.T) {
requireSharedProxiedServer(t)
t.Parallel()
bd := buildEmbeddedBD(t)
t.Run("redraws_on_change_and_stops_on_interrupt", func(t *testing.T) {
t.Parallel()
p := newSharedProxiedProject(t, bd, "swr")
issue := bdProxiedCreate(t, bd, p.dir, "Watch me", "--type", "task")
var stdout bytes.Buffer
stderr := &watchBannerWriter{renders: make(chan int, 1)}
cmd := exec.Command(bd, "show", issue.ID, "--watch")
cmd.Dir = p.dir
cmd.Env = bdProxiedEnv(p.dir)
cmd.Stdout = &stdout
cmd.Stderr = stderr
if err := cmd.Start(); err != nil {
t.Fatalf("start bd show --watch: %v", err)
}
var waitErr error
exited := make(chan struct{})
go func() {
waitErr = cmd.Wait()
close(exited)
}()
t.Cleanup(func() {
_ = cmd.Process.Kill()
<-exited
})
if !stderr.waitForRender(1, 60*time.Second, exited) {
t.Fatalf("bd show --watch never started watching\nstdout:\n%s\nstderr:\n%s", stdout.String(), stderr.String())
}
if strings.Contains(stderr.String(), "not supported") {
t.Fatalf("bd show --watch refused under --proxied-server:\n%s", stderr.String())
}
bdProxiedUpdateOne(t, bd, p.dir, issue.ID, "--status", "in_progress")
if !stderr.waitForRender(2, 60*time.Second, exited) {
t.Fatalf("bd show --watch did not redraw after the status change\nstdout:\n%s\nstderr:\n%s", stdout.String(), stderr.String())
}
if err := cmd.Process.Signal(syscall.SIGINT); err != nil {
t.Fatalf("signal bd show --watch: %v", err)
}
select {
case <-exited:
if waitErr != nil {
t.Fatalf("bd show --watch exited with %v after SIGINT, want 0\nstderr:\n%s", waitErr, stderr.String())
}
case <-time.After(30 * time.Second):
t.Fatalf("bd show --watch ignored SIGINT\nstderr:\n%s", stderr.String())
}
if !strings.Contains(stderr.String(), "Stopped watching.") {
t.Errorf("stderr lacks the stop line:\n%s", stderr.String())
}
out := stdout.String()
if got := strings.Count(out, "Watch me"); got < 2 {
t.Errorf("stdout rendered the issue %d time(s), want an initial render and a redraw:\n%s", got, out)
}
if !strings.Contains(strings.ToUpper(out), "IN_PROGRESS") {
t.Errorf("redraw does not show the new status:\n%s", out)
}
})
// A poll that fails keeps the last render and prints nothing: the route
// used to print "Error refreshing <id>" every 2s once the issue was
// deleted, and under --json an error object on stdout each time.
t.Run("deleted_issue_polls_stay_quiet", func(t *testing.T) {
t.Parallel()
p := newSharedProxiedProject(t, bd, "swd")
issue := bdProxiedCreate(t, bd, p.dir, "Watch then delete", "--type", "task")
// Locked: stdout is read while the child is still writing to it.
stdout := &watchBannerWriter{renders: make(chan int, 1)}
stderr := &watchBannerWriter{renders: make(chan int, 1)}
cmd := exec.Command(bd, "--json", "show", issue.ID, "--watch")
cmd.Dir = p.dir
cmd.Env = bdProxiedEnv(p.dir)
cmd.Stdout = stdout
cmd.Stderr = stderr
if err := cmd.Start(); err != nil {
t.Fatalf("start bd show --watch: %v", err)
}
exited := make(chan struct{})
go func() {
_ = cmd.Wait()
close(exited)
}()
t.Cleanup(func() {
_ = cmd.Process.Kill()
<-exited
})
if !stderr.waitForRender(1, 60*time.Second, exited) {
t.Fatalf("bd show --watch never started watching\nstdout:\n%s\nstderr:\n%s", stdout.String(), stderr.String())
}
before := len(stdout.String())
bdProxiedDelete(t, bd, p.dir, issue.ID, "--force")
// Several poll intervals, so a per-tick report would have fired.
select {
case <-exited:
t.Fatalf("bd show --watch exited after the issue was deleted\nstderr:\n%s", stderr.String())
case <-time.After(3 * showWatchPollInterval):
}
if after := stdout.String()[before:]; after != "" {
t.Errorf("stdout grew after the delete:\n%s", after)
}
if strings.Contains(stderr.String(), "Error") || strings.Contains(stderr.String(), "not found") {
t.Errorf("stderr reported the failed polls:\n%s", stderr.String())
}
})
t.Run("missing_id_fails_instead_of_watching", func(t *testing.T) {
t.Parallel()
p := newSharedProxiedProject(t, bd, "swm")
stdout, stderr, err, timedOut := bdProxiedRunDeadline(t, bd, p.dir, 60*time.Second, "show", "swm-nonexistent999", "--watch")
if timedOut {
t.Fatalf("bd show --watch on a missing id kept watching\nstdout:\n%s\nstderr:\n%s", stdout, stderr)
}
if err == nil {
t.Fatalf("bd show --watch on a missing id exited 0\nstdout:\n%s\nstderr:\n%s", stdout, stderr)
}
if want := "Issue swm-nonexistent999 not found"; !strings.Contains(stderr, want) {
t.Errorf("stderr = %q, want it to contain %q", stderr, want)
}
})
t.Run("requires_exactly_one_id", func(t *testing.T) {
t.Parallel()
p := newSharedProxiedProject(t, bd, "swo")
a := bdProxiedCreate(t, bd, p.dir, "Watch A", "--type", "task")
b := bdProxiedCreate(t, bd, p.dir, "Watch B", "--type", "task")
stdout, stderr := bdProxiedShowFail(t, bd, p.dir, a.ID, b.ID, "--watch")
if combined := stdout + stderr; !strings.Contains(combined, "watch mode requires exactly one issue ID") {
t.Errorf("want the direct route's one-id error, got:\n%s", combined)
}
})
}

View file

@ -0,0 +1,152 @@
package main
import (
"context"
"errors"
"os"
"slices"
"strings"
"testing"
"time"
"github.com/steveyegge/beads/internal/types"
)
// watchPoll is one scripted fetch result.
type watchPoll struct {
issue *types.Issue
err error
}
// scriptedWatchSource replays a fixed sequence of fetch results and counts
// renders, so the loop's redraw rule can be checked without a store.
type scriptedWatchSource struct {
initial *types.Issue
polls []watchPoll
renders int
// rendersAtFetch records the render count as each poll starts, i.e. the
// result of the poll before it. Written only on the loop's goroutine and
// read after the loop returns.
rendersAtFetch []int
}
func (s *scriptedWatchSource) source() issueWatchSource {
return issueWatchSource{
render: func(context.Context) *types.Issue {
s.renders++
return s.initial
},
fetch: func(context.Context) (*types.Issue, error) {
s.rendersAtFetch = append(s.rendersAtFetch, s.renders)
next := s.polls[0]
s.polls = s.polls[1:]
return next.issue, next.err
},
}
}
// driveWatchLoop runs the loop over src for every scripted poll, stops it, and
// returns whether it reported watching plus everything it wrote to stderr.
func driveWatchLoop(t *testing.T, src *scriptedWatchSource) (bool, string) {
t.Helper()
polls := len(src.polls)
var watched bool
stderr := captureStderr(t, func() {
tick := make(chan time.Time)
stop := make(chan os.Signal, 1)
done := make(chan bool)
go func() { done <- watchIssueLoop(context.Background(), src.source(), tick, stop) }()
// tick is unbuffered, so each send lands only once the loop is back in
// its select, i.e. after the previous poll (and any redraw) finished.
for range polls {
tick <- time.Time{}
}
stop <- os.Interrupt
watched = <-done
})
return watched, stderr
}
// TestWatchIssueLoopRedrawsOnlyOnSnapshotChange pins the redraw rule both
// `bd show --watch` routes share: an unchanged snapshot or a failed read does
// not redraw, a status or updated_at change does, and stop ends the loop.
func TestWatchIssueLoopRedrawsOnlyOnSnapshotChange(t *testing.T) {
base := time.Date(2026, 1, 2, 3, 4, 5, 0, time.UTC)
open := &types.Issue{ID: "w-1", Status: types.StatusOpen, UpdatedAt: base}
sameAgain := &types.Issue{ID: "w-1", Status: types.StatusOpen, UpdatedAt: base}
inProgress := &types.Issue{ID: "w-1", Status: types.StatusInProgress, UpdatedAt: base.Add(time.Second)}
touched := &types.Issue{ID: "w-1", Status: types.StatusInProgress, UpdatedAt: base.Add(2 * time.Second)}
src := &scriptedWatchSource{
initial: open,
polls: []watchPoll{
{issue: sameAgain},
{err: errors.New("backend blip")},
{issue: inProgress},
{issue: inProgress},
{issue: touched},
},
}
watched, _ := driveWatchLoop(t, src)
if !watched {
t.Fatal("watchIssueLoop reported nothing watched after a successful render")
}
// Poll order: unchanged, failed read, status change, unchanged,
// updated_at change.
if want := []int{1, 1, 1, 2, 2}; !slices.Equal(src.rendersAtFetch, want) {
t.Fatalf("renders before each poll = %v, want %v", src.rendersAtFetch, want)
}
if src.renders != 3 {
t.Fatalf("renders = %d, want 3 (initial, status change, updated_at change)", src.renders)
}
}
// TestWatchIssueLoopFailedPollsStayQuiet pins the poll-failure rule both routes
// share: a poll that fails (a deleted issue, a unit of work that will not open)
// keeps the last render and prints nothing, however many ticks it lasts, and a
// later successful poll with a change redraws as usual. The proxied route used
// to print an error line — under --json, an error object — on every tick.
func TestWatchIssueLoopFailedPollsStayQuiet(t *testing.T) {
base := time.Date(2026, 1, 2, 3, 4, 5, 0, time.UTC)
open := &types.Issue{ID: "w-2", Status: types.StatusOpen, UpdatedAt: base}
closed := &types.Issue{ID: "w-2", Status: types.StatusClosed, UpdatedAt: base.Add(time.Second)}
src := &scriptedWatchSource{
initial: open,
polls: []watchPoll{
{err: errors.New("issue w-2 not found")},
{err: errors.New("open unit of work: connection refused")},
{err: errors.New("issue w-2 not found")},
{issue: closed},
},
}
watched, stderr := driveWatchLoop(t, src)
if !watched {
t.Fatal("watchIssueLoop reported nothing watched after a successful render")
}
if strings.Contains(stderr, "not found") || strings.Contains(stderr, "connection refused") || strings.Contains(stderr, "Error") {
t.Fatalf("failed polls printed to stderr:\n%s", stderr)
}
// Initial banner, the redraw's banner after the recovery, and the stop line.
if got := strings.Count(stderr, "Watching for changes..."); got != 2 {
t.Fatalf("banner printed %d times, want 2 (initial + one redraw):\n%s", got, stderr)
}
if src.renders != 2 {
t.Fatalf("renders = %d, want 2 (initial, redraw after recovery)", src.renders)
}
}
// TestWatchIssueLoopStopsWhenNothingToWatch pins that a failed initial render
// returns at once rather than polling an issue that was never shown.
func TestWatchIssueLoopStopsWhenNothingToWatch(t *testing.T) {
src := issueWatchSource{
render: func(context.Context) *types.Issue { return nil },
fetch: func(context.Context) (*types.Issue, error) {
t.Fatal("fetch called after a failed initial render")
return nil, nil
},
}
if watchIssueLoop(context.Background(), src, make(chan time.Time), make(chan os.Signal)) {
t.Fatal("watchIssueLoop reported watching after a failed initial render")
}
}

View file

@ -9,6 +9,7 @@ import (
"github.com/spf13/cobra"
"github.com/steveyegge/beads/internal/metrics"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/storage/sqlclass"
)
var sqlCmd = &cobra.Command{
@ -25,9 +26,11 @@ Examples:
bd sql 'DELETE FROM dirty_issues WHERE issue_id = "bd-abc123"'
bd sql --csv 'SELECT id, title, status FROM issues'
The query is passed directly to the database. SELECT queries return results as a
table (or JSON/CSV with --json/--csv). Non-SELECT queries (INSERT, UPDATE, DELETE)
report the number of rows affected.
The query is passed directly to the database. Reads (SELECT, WITH ... SELECT,
SHOW, EXPLAIN) return results as a table (or JSON/CSV with --json/--csv). Writes
(INSERT, UPDATE, DELETE, DDL) report the number of rows affected. Statements
that may both write and return rows, such as CALL, are committed and print any
rows they return (or "OK").
In proxied-server mode, multiple statements separated by ';' run as a single
committed batch and report "OK", and --database runs the query against a
@ -71,15 +74,13 @@ WARNING: Direct database access bypasses the storage layer. Use with caution.`,
ctx := rootCtx
trimmed := strings.TrimSpace(strings.ToUpper(query))
isRead := strings.HasPrefix(trimmed, "SELECT") ||
strings.HasPrefix(trimmed, "EXPLAIN") ||
strings.HasPrefix(trimmed, "PRAGMA") ||
strings.HasPrefix(trimmed, "SHOW") ||
strings.HasPrefix(trimmed, "DESCRIBE") ||
strings.HasPrefix(trimmed, "WITH")
if isRead {
// Reads and statements that may return rows go through Query so a
// result set is always rendered; only plain writes use Exec.
kind := sqlclass.Classify(query)
if kind != sqlclass.Write {
if kind == sqlclass.Mixed {
CheckReadonly("sql")
}
rows, err := db.QueryContext(ctx, query)
if err != nil {
return HandleErrorRespectJSON("query error: %v", err)
@ -90,6 +91,9 @@ WARNING: Direct database access bypasses the storage layer. Use with caution.`,
if err != nil {
return HandleErrorRespectJSON("getting columns: %v", err)
}
if kind == sqlclass.Mixed && len(columns) == 0 {
return printSQLStatusOK()
}
allRows := make([]map[string]interface{}, 0)
for rows.Next() {

View file

@ -179,3 +179,80 @@ func sqlValueEquals(v any, want float64) bool {
return false
}
}
// TestProxiedServerSQLStatementRouting pins how proxied `bd sql` routes
// statements that a prefix scan misreads: CTE reads must return their rows,
// CTE writes must commit, and a statement that writes and returns a result set
// must render that result set instead of reporting "0 rows affected".
func TestProxiedServerSQLStatementRouting(t *testing.T) {
requireSharedProxiedServer(t)
t.Parallel()
bd := buildEmbeddedBD(t)
p := newSharedProxiedProject(t, bd, "sqlcte")
one := bdProxiedCreate(t, bd, p.dir, "CTE issue one", "--type", "task", "--priority", "1")
two := bdProxiedCreate(t, bd, p.dir, "CTE issue two", "--type", "task", "--priority", "2")
t.Run("cte_column_list_select_returns_rows", func(t *testing.T) {
rows := bdProxiedSQLJSON(t, bd, p.dir,
"WITH t(issue_id) AS (SELECT id FROM issues WHERE id = '"+one.ID+"') SELECT issue_id FROM t")
if len(rows) != 1 {
t.Fatalf("expected 1 row, got %d: %v", len(rows), rows)
}
if rows[0]["issue_id"] != one.ID {
t.Errorf("expected issue_id=%q, got %v", one.ID, rows[0]["issue_id"])
}
})
t.Run("recursive_cte_select_returns_rows", func(t *testing.T) {
query := "WITH RECURSIVE n(i) AS (SELECT 1 UNION ALL SELECT i + 1 FROM n WHERE i < 3) SELECT i FROM n"
rows := bdProxiedSQLJSON(t, bd, p.dir, query)
if len(rows) != 3 {
t.Fatalf("expected 3 rows, got %d: %v", len(rows), rows)
}
stdout, _ := bdProxiedSQL(t, bd, p.dir, query)
if !strings.Contains(stdout, "(3 rows)") {
t.Errorf("expected '(3 rows)' in table output, got:\n%s", stdout)
}
})
t.Run("cte_write_commits", func(t *testing.T) {
stdout, _ := bdProxiedSQL(t, bd, p.dir, "--json",
"WITH t(issue_id) AS (SELECT id FROM issues WHERE id = '"+two.ID+"') "+
"UPDATE issues SET priority = 0 WHERE id IN (SELECT issue_id FROM t)")
start := strings.Index(stdout, "{")
if start < 0 {
t.Fatalf("no JSON object in exec output:\n%s", stdout)
}
var res map[string]interface{}
if err := json.Unmarshal([]byte(stdout[start:]), &res); err != nil {
t.Fatalf("parse exec JSON: %v\nraw: %s", err, stdout[start:])
}
if !sqlValueEquals(res["rows_affected"], 1) {
t.Errorf("expected rows_affected=1, got %v", res["rows_affected"])
}
db := openProxiedDB(t, p)
var priority int
if err := db.QueryRow("SELECT priority FROM issues WHERE id = ?", two.ID).Scan(&priority); err != nil {
t.Fatalf("query priority for %s: %v", two.ID, err)
}
if priority != 0 {
t.Errorf("expected committed priority=0, got %d", priority)
}
})
t.Run("call_renders_result_set", func(t *testing.T) {
rows := bdProxiedSQLJSON(t, bd, p.dir, "CALL DOLT_BRANCH('sql-routing-probe')")
if len(rows) != 1 {
t.Fatalf("expected the procedure's 1 status row, got %d: %v", len(rows), rows)
}
if _, ok := rows[0]["status"]; !ok {
t.Errorf("expected a status column, got %v", rows[0])
}
branches := bdProxiedSQLJSON(t, bd, p.dir, "SELECT name FROM dolt_branches WHERE name = 'sql-routing-probe'")
if len(branches) != 1 {
t.Errorf("expected the CALL to have created branch sql-routing-probe, got %v", branches)
}
})
}

View file

@ -8,6 +8,7 @@ import (
"strings"
"github.com/steveyegge/beads/internal/storage/domain"
"github.com/steveyegge/beads/internal/storage/sqlclass"
"github.com/steveyegge/beads/internal/storage/uow"
)
@ -16,9 +17,16 @@ func runSQLProxiedServer(ctx context.Context, query string, csvOutput bool) erro
return HandleError("proxied-server UOW provider not initialized")
}
multiStatement := isMultiStatementSQL(query)
if isMultiStatementSQL(query) {
CheckReadonly("sql")
if _, err := runSQLProxiedExec(ctx, query); err != nil {
return err
}
return printSQLStatusOK()
}
if !multiStatement && sqlQueryIsRead(query) {
switch sqlclass.Classify(query) {
case sqlclass.Read:
result, err := uow.RunTxRead(ctx, uowProvider, func(ctx context.Context, uw uow.UnitOfWork) (*domain.RawSQLResult, error) {
return uw.RawSQLUseCase().Query(ctx, query)
})
@ -26,10 +34,45 @@ func runSQLProxiedServer(ctx context.Context, query string, csvOutput bool) erro
return HandleErrorRespectJSON("query error: %v", err)
}
return renderRawSQLResult(result, csvOutput)
case sqlclass.Write:
CheckReadonly("sql")
affected, err := runSQLProxiedExec(ctx, query)
if err != nil {
return err
}
if jsonOutput {
return outputJSON(map[string]interface{}{
"rows_affected": affected,
})
}
fmt.Printf("OK, %d rows affected\n", affected)
return nil
default:
// The statement may write and may return rows. Run it through Query
// inside a committing transaction so a result set is rendered rather
// than silently discarded, and any write is committed rather than
// rolled back with a read transaction.
CheckReadonly("sql")
result, err := uow.RunTxResult(ctx, uowProvider, func(ctx context.Context, uw uow.UnitOfWork) (*domain.RawSQLResult, string, error) {
result, err := uw.RawSQLUseCase().Query(ctx, query)
if err != nil {
return nil, "", err
}
return result, "bd sql: " + query, nil
})
if err != nil {
return HandleErrorRespectJSON("query error: %v", err)
}
if len(result.Columns) == 0 {
return printSQLStatusOK()
}
return renderRawSQLResult(result, csvOutput)
}
}
CheckReadonly("sql")
func runSQLProxiedExec(ctx context.Context, query string) (int64, error) {
affected, err := uow.RunTxResult(ctx, uowProvider, func(ctx context.Context, uw uow.UnitOfWork) (int64, string, error) {
affected, err := uw.RawSQLUseCase().Exec(ctx, query)
if err != nil {
@ -38,26 +81,18 @@ func runSQLProxiedServer(ctx context.Context, query string, csvOutput bool) erro
return affected, "bd sql: " + query, nil
})
if err != nil {
return HandleErrorRespectJSON("exec error: %v", err)
}
if multiStatement {
if jsonOutput {
return outputJSON(map[string]interface{}{
"status": "ok",
})
}
fmt.Println("OK")
return nil
return 0, HandleErrorRespectJSON("exec error: %v", err)
}
return affected, nil
}
func printSQLStatusOK() error {
if jsonOutput {
return outputJSON(map[string]interface{}{
"rows_affected": affected,
"status": "ok",
})
}
fmt.Printf("OK, %d rows affected\n", affected)
fmt.Println("OK")
return nil
}
@ -134,59 +169,6 @@ func topLevelStatementCount(query string) int {
return count
}
func sqlQueryIsRead(query string) bool {
trimmed := strings.TrimSpace(strings.ToUpper(query))
switch {
case strings.HasPrefix(trimmed, "SELECT"),
strings.HasPrefix(trimmed, "EXPLAIN"),
strings.HasPrefix(trimmed, "PRAGMA"),
strings.HasPrefix(trimmed, "SHOW"),
strings.HasPrefix(trimmed, "DESCRIBE"):
return true
case strings.HasPrefix(trimmed, "WITH"):
return withOuterStatementIsRead(trimmed)
default:
return false
}
}
func withOuterStatementIsRead(upperTrimmed string) bool {
depth := 0
var quote byte
closedCTE := false
for i := 0; i < len(upperTrimmed); i++ {
c := upperTrimmed[i]
if quote != 0 {
if c == quote {
quote = 0
}
continue
}
switch c {
case '\'', '"', '`':
quote = c
case '(':
depth++
case ')':
depth--
if depth == 0 {
closedCTE = true
}
case ' ', '\t', '\n', '\r', ',':
if c == ',' && depth == 0 {
closedCTE = false
}
default:
if depth == 0 && closedCTE {
rest := strings.TrimLeft(upperTrimmed[i:], " \t\n\r")
return strings.HasPrefix(rest, "SELECT") ||
strings.HasPrefix(rest, "EXPLAIN")
}
}
}
return true
}
func renderRawSQLResult(result *domain.RawSQLResult, csvOutput bool) error {
columns := result.Columns

View file

@ -38,7 +38,10 @@ func startTestDoltServer() func() {
return func() { testutil.TerminateDoltContainer() }
}
if err := testutil.EnsureDoltContainerForTestMain(); err != nil {
fmt.Fprintf(os.Stderr, "WARN: %v, skipping Dolt tests\n", err)
if testutil.DoltUnavailableForTestMain(err) {
// Nothing has been started yet; there is nothing to clean up.
os.Exit(1)
}
return func() {}
}

View file

@ -6,7 +6,9 @@ import (
"strings"
"github.com/spf13/cobra"
"github.com/steveyegge/beads/internal/config"
"github.com/steveyegge/beads/internal/metrics"
"github.com/steveyegge/beads/internal/storage/issueops"
"github.com/steveyegge/beads/internal/types"
)
@ -26,14 +28,45 @@ var coreWorkTypes = []struct {
{types.TypeMilestone, "Marks completion of a set of related issues (contains no work itself)"},
}
// systemTypeDescriptions describes the built-in types that are not core work
// types. bd's own commands create them (mail, molecules, gates, set-state), and
// like the core types they validate without any types.custom entry.
var systemTypeDescriptions = map[types.IssueType]string{
types.TypeMessage: "Message between agents or users",
types.TypeMolecule: "Molecule root for swarm coordination (bd mol)",
types.TypeGate: "Async coordination gate (bd gate, formula gates)",
types.TypeEvent: "Audit-trail event (bd set-state)",
}
// systemWorkTypes lists every built-in type that is not a core work type, in
// the types package's declaration order. Together with coreWorkTypes it covers
// exactly the types IssueType.IsBuiltIn accepts.
func systemWorkTypes() []typeInfo {
core := make(map[types.IssueType]bool, len(coreWorkTypes))
for _, t := range coreWorkTypes {
core[t.Type] = true
}
var out []typeInfo
for _, t := range append(append([]types.IssueType{}, types.AllIssueTypes...), types.TypeEvent) {
if core[t] {
continue
}
out = append(out, typeInfo{Name: string(t), Description: systemTypeDescriptions[t]})
}
return out
}
var typesCmd = &cobra.Command{
Use: "types",
GroupID: "views",
Short: "List valid issue types",
Long: `List all valid issue types that can be used with bd create --type.
Core work types (bug, task, feature, chore, epic, decision, spike, story, milestone) are always valid.
Additional types require configuration via types.custom in .beads/config.yaml.
Core work types (bug, task, feature, chore, epic, decision, spike, story, milestone)
and system types (message, molecule, gate, event) are always valid.
Custom types are registered with 'bd config set types.custom' or declared under
types.custom in .beads/config.yaml; the list shown is exactly the set that
bd create --type accepts.
Examples:
bd types # List all types with descriptions
@ -55,32 +88,56 @@ Examples:
return printSections(jsonOutput)
}
if usesProxiedServer() {
return runTypesProxiedServer(rootCtx)
}
if err := ensureDirectMode("types command requires direct database access"); err != nil {
return HandleError("%v", err)
}
var customTypes []string
ctx := context.Background()
if store != nil {
if ct, err := store.GetCustomTypes(ctx); err == nil {
customTypes = ct
if !usesProxiedServer() {
if err := ensureDirectMode("types command requires direct database access"); err != nil {
return HandleError("%v", err)
}
}
customTypes, err := resolveWorkspaceCustomTypes(rootCtx)
if err != nil {
return HandleError("%v", err)
}
return renderTypes(customTypes)
},
}
// resolveWorkspaceCustomTypes returns the workspace's registered custom issue
// types in either storage mode. Both routes end in issueops.ComposeCustomTypes,
// the rule issue create/update validation also resolves through, so what
// `bd types` lists is exactly what `bd create --type` accepts.
func resolveWorkspaceCustomTypes(ctx context.Context) ([]string, error) {
if usesProxiedServer() {
uw, err := openProxiedListUOW(ctx)
if err != nil {
return nil, err
}
defer uw.Close(ctx)
customTypes, err := uw.ConfigUseCase().GetCustomTypes(ctx)
if err != nil {
return nil, fmt.Errorf("reading custom types: %w", err)
}
return customTypes, nil
}
if store == nil {
// No database is open (e.g. a --dry-run plan check): the config.yaml
// layer is the only one available, composed by the same rule.
return issueops.ComposeCustomTypes(nil, "", config.GetCustomTypesFromYAML()), nil
}
customTypes, err := store.GetCustomTypes(ctx)
if err != nil {
return nil, fmt.Errorf("reading custom types: %w", err)
}
return customTypes, nil
}
func renderTypes(customTypes []string) error {
if jsonOutput {
result := struct {
CoreTypes []typeInfo `json:"core_types"`
SystemTypes []typeInfo `json:"system_types"`
CustomTypes []string `json:"custom_types,omitempty"`
}{}
}{SystemTypes: systemWorkTypes()}
for _, t := range coreWorkTypes {
result.CoreTypes = append(result.CoreTypes, typeInfo{
@ -97,6 +154,11 @@ func renderTypes(customTypes []string) error {
fmt.Printf(" %-14s %s\n", t.Type, t.Description)
}
fmt.Println("\nSystem types (built-in, created by bd commands):")
for _, t := range systemWorkTypes() {
fmt.Printf(" %-14s %s\n", t.Name, t.Description)
}
if len(customTypes) > 0 {
fmt.Println("\nConfigured custom types:")
for _, t := range customTypes {

View file

@ -0,0 +1,40 @@
package main
import (
"testing"
"github.com/steveyegge/beads/internal/types"
)
// TestBdTypesListsEveryBuiltIn pins that `bd types` (core + system sections)
// lists exactly the types that validate without configuration, i.e. the set
// IssueType.IsBuiltIn accepts, each with a description.
func TestBdTypesListsEveryBuiltIn(t *testing.T) {
listed := map[types.IssueType]bool{}
for _, ct := range coreWorkTypes {
if listed[ct.Type] {
t.Errorf("core type %q listed twice", ct.Type)
}
listed[ct.Type] = true
}
for _, st := range systemWorkTypes() {
it := types.IssueType(st.Name)
if listed[it] {
t.Errorf("type %q listed as both core and system", it)
}
if st.Description == "" {
t.Errorf("system type %q has no description", it)
}
listed[it] = true
}
for it := range listed {
if !it.IsBuiltIn() {
t.Errorf("bd types lists %q as built-in, but IsBuiltIn rejects it", it)
}
}
for _, it := range append(append([]types.IssueType{}, types.AllIssueTypes...), types.TypeEvent) {
if !listed[it] {
t.Errorf("built-in type %q validates without configuration but bd types does not list it", it)
}
}
}

View file

@ -0,0 +1,130 @@
//go:build cgo
package main
import (
"encoding/json"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
)
// typesAgreementRunner runs bd in a workspace and returns stdout (or stdout+stderr on
// failure) plus the exit error.
type typesAgreementRunner func(t *testing.T, args ...string) ([]byte, error)
// assertTypesAgreeWithCreate is the `bd types` ⇔ `bd create --type` contract:
// every type `bd types --json` lists is accepted by create and by
// storage-class config validation, and an unlisted type is rejected.
// Custom types are seeded from both sources — the database (bd config set)
// and the project's .beads/config.yaml — because each storage mode resolves
// them; the listing and validation paths must compose them identically.
func assertTypesAgreeWithCreate(t *testing.T, run typesAgreementRunner, beadsDir string) {
t.Helper()
if out, err := run(t, "config", "set", "types.custom", "dbtype"); err != nil {
t.Fatalf("config set types.custom: %v\n%s", err, out)
}
cfgPath := filepath.Join(beadsDir, "config.yaml")
cfg, err := os.ReadFile(cfgPath)
if err != nil {
t.Fatalf("read config.yaml: %v", err)
}
if strings.Contains(string(cfg), "types.custom") || strings.Contains(string(cfg), "\ntypes:") {
t.Fatalf("fixture config.yaml already declares types; test assumes it does not:\n%s", cfg)
}
cfg = append(cfg, []byte("\ntypes.custom: \"yamltype\"\n")...)
if err := os.WriteFile(cfgPath, cfg, 0o644); err != nil {
t.Fatalf("write config.yaml: %v", err)
}
out, err := run(t, "types", "--json")
if err != nil {
t.Fatalf("types --json: %v\n%s", err, out)
}
var listed struct {
CoreTypes []typeInfo `json:"core_types"`
SystemTypes []typeInfo `json:"system_types"`
CustomTypes []string `json:"custom_types"`
}
if err := json.Unmarshal(out, &listed); err != nil {
t.Fatalf("unmarshal types --json: %v\n%s", err, out)
}
names := map[string]bool{}
for _, ti := range append(listed.CoreTypes, listed.SystemTypes...) {
names[ti.Name] = true
}
for _, c := range listed.CustomTypes {
names[c] = true
}
// Types create is known to accept must be listed.
for _, want := range []string{"task", "message", "molecule", "gate", "event", "dbtype", "yamltype"} {
if !names[want] {
t.Errorf("bd types does not list %q, but bd create accepts it; listed=%v", want, names)
}
}
// Every listed type must be accepted by create ...
for name := range names {
if out, err := run(t, "create", "--silent", "--type", name, "agreement "+name); err != nil {
t.Errorf("bd types lists %q but bd create --type %s failed: %v\n%s", name, name, err, out)
}
}
// ... and by storage-class validation, which names issue types too.
for _, name := range listed.CustomTypes {
if out, err := run(t, "config", "set", "storage-class."+name, "versioned"); err != nil {
t.Errorf("bd types lists %q but config set storage-class.%s failed: %v\n%s", name, name, err, out)
}
}
// An unlisted type is rejected.
if out, err := run(t, "create", "--silent", "--type", "notregistered", "agreement unlisted"); err == nil {
t.Errorf("bd create accepted unlisted type notregistered: %s", out)
}
}
func TestProxiedServerTypesAgreeWithCreate(t *testing.T) {
requireSharedProxiedServer(t)
t.Parallel()
bd := buildEmbeddedBD(t)
p := newSharedProxiedProject(t, bd, "tac")
assertTypesAgreeWithCreate(t, func(t *testing.T, args ...string) ([]byte, error) {
return bdProxiedRun(t, bd, p.dir, args...)
}, p.beadsDir)
}
func TestEmbeddedTypesAgreeWithCreate(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", "tac")
assertTypesAgreeWithCreate(t, func(t *testing.T, args ...string) ([]byte, error) {
return bdRunWithFlockRetry(t, bd, dir, args...)
}, beadsDir)
}
// Server mode (`bd init --server` against an external dolt sql-server) lists
// through DoltStore.GetCustomTypes, the resolver that used to drop
// config.yaml types once the database had any.
func TestServerModeTypesAgreeWithCreate(t *testing.T) {
requireSharedProxiedServer(t)
t.Parallel()
bd := buildEmbeddedBD(t)
p := newServerModeProject(t, bd, "tas")
assertTypesAgreeWithCreate(t, func(t *testing.T, args ...string) ([]byte, error) {
t.Helper()
cmd := exec.Command(bd, args...)
cmd.Dir = p.dir
cmd.Env = p.env
stdout, stderr, err := runCommandBuffers(t, cmd)
if err != nil {
return append(stdout.Bytes(), stderr.Bytes()...), err
}
return stdout.Bytes(), nil
}, p.beadsDir)
}

View file

@ -1,20 +0,0 @@
package main
import (
"context"
)
func runTypesProxiedServer(ctx context.Context) error {
uw, err := openProxiedListUOW(ctx)
if err != nil {
return HandleError("%v", err)
}
defer uw.Close(ctx)
var customTypes []string
if ct, err := uw.ConfigUseCase().GetCustomTypes(ctx); err == nil {
customTypes = ct
}
return renderTypes(customTypes)
}

View file

@ -19,6 +19,10 @@ var undeferCmd = &cobra.Command{
This brings issues back from the icebox so they can be worked on again.
Issues will appear in 'bd ready' if they have no blockers.
If an issue carries a defer_until timestamp but its status isn't
"deferred" (e.g. after an explicit --status change), undefer clears
the stray timestamp without touching status.
Examples:
bd undefer bd-abc # Undefer a single issue
bd undefer bd-abc bd-def # Undefer multiple issues`,
@ -64,15 +68,26 @@ Examples:
fmt.Fprintf(os.Stderr, "Error getting %s: %v\n", fullID, err)
continue
}
if issue.Status != types.StatusDeferred {
// Gate on defer_until, not status alone (ga-bq3w5): bd ready hides
// any issue with a future defer_until regardless of status, so
// `bd update <id> --status open --defer <date>` leaves a status=open
// issue permanently invisible with no status-based signal anywhere.
// Mirrors GH#3233's `bd update --defer=""` gate (update.go): only
// flip status to open when it was actually "deferred" — other
// statuses shouldn't be clobbered just to clear a stray timestamp.
wasDeferred := issue.Status == types.StatusDeferred
if !wasDeferred && issue.DeferUntil == nil {
fmt.Fprintf(os.Stderr, "%s is not deferred (status: %s)\n", fullID, string(issue.Status))
continue
}
updates := map[string]interface{}{
"status": string(types.StatusOpen),
"defer_until": nil,
}
if wasDeferred {
updates["status"] = string(types.StatusOpen)
}
if err := store.UpdateIssue(ctx, fullID, updates, actor); err != nil {
fmt.Fprintf(os.Stderr, "Error undeferring %s: %v\n", fullID, err)
@ -84,8 +99,10 @@ Examples:
if issue != nil {
undeferredIssues = append(undeferredIssues, issue)
}
} else {
} else if wasDeferred {
fmt.Printf("%s Undeferred %s (now open)\n", ui.RenderPass("*"), fullID)
} else {
fmt.Printf("%s Cleared stale defer_until on %s (status unchanged: %s)\n", ui.RenderPass("*"), fullID, string(issue.Status))
}
}

View file

@ -69,6 +69,79 @@ func TestEmbeddedUndefer(t *testing.T) {
t.Errorf("expected 'not deferred' message: %s", out)
}
})
// ===== Stray defer_until on a non-deferred status (ga-bq3w5) =====
t.Run("undefer_clears_stray_defer_until_when_status_not_deferred", func(t *testing.T) {
issue := bdCreate(t, bd, dir, "Stray future defer on open issue", "--type", "task")
// Reproduces ga-bq3w5: an explicit --status wins over --defer's own
// status=deferred default (update.go), so this single command leaves
// status=open with a live future defer_until — exactly the shape that
// silently starves an issue out of `bd ready` with no status-based
// signal anywhere.
cmd := exec.Command(bd, "update", issue.ID, "--status", "open", "--defer", "2099-01-01")
cmd.Dir = dir
cmd.Env = bdEnv(dir)
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("bd update --status open --defer failed: %v\n%s", err, out)
}
status, deferUntil := showDeferState(t, bd, dir, issue.ID)
if status != "open" || deferUntil == nil {
t.Fatalf("precondition: expected status=open with defer_until set, got status=%q defer_until=%v", status, deferUntil)
}
if ids := wakeReadyIDs(t, bd, dir); ids[issue.ID] {
t.Fatalf("precondition: issue should be hidden from bd ready by its future defer_until")
}
out := bdUndefer(t, bd, dir, issue.ID)
if strings.Contains(out, "is not deferred") {
t.Errorf("undefer refused instead of clearing the stray defer_until: %s", out)
}
status, deferUntil = showDeferState(t, bd, dir, issue.ID)
if status != "open" {
t.Errorf("expected status to stay open, got %q", status)
}
if deferUntil != nil {
t.Errorf("expected defer_until cleared after undefer, got %v", deferUntil)
}
if ids := wakeReadyIDs(t, bd, dir); !ids[issue.ID] {
t.Errorf("expected issue back in bd ready after undefer cleared its defer_until")
}
})
// ===== Stray defer_until on a non-open status must not be clobbered =====
t.Run("undefer_clears_stray_defer_until_without_clobbering_in_progress", func(t *testing.T) {
// The "open" case above can't distinguish the conditional status
// write (only flip to open when wasDeferred) from an unconditional
// one: writing status=open to an already-open issue is a no-op.
// in_progress makes the distinction observable.
issue := bdCreate(t, bd, dir, "Stray future defer on in_progress issue", "--type", "task")
cmd := exec.Command(bd, "update", issue.ID, "--status", "in_progress", "--defer", "2099-01-01")
cmd.Dir = dir
cmd.Env = bdEnv(dir)
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("bd update --status in_progress --defer failed: %v\n%s", err, out)
}
status, deferUntil := showDeferState(t, bd, dir, issue.ID)
if status != "in_progress" || deferUntil == nil {
t.Fatalf("precondition: expected status=in_progress with defer_until set, got status=%q defer_until=%v", status, deferUntil)
}
out := bdUndefer(t, bd, dir, issue.ID)
if strings.Contains(out, "is not deferred") {
t.Errorf("undefer refused instead of clearing the stray defer_until: %s", out)
}
status, deferUntil = showDeferState(t, bd, dir, issue.ID)
if status != "in_progress" {
t.Errorf("expected status to stay in_progress (not clobbered to open), got %q", status)
}
if deferUntil != nil {
t.Errorf("expected defer_until cleared after undefer, got %v", deferUntil)
}
})
}
// TestEmbeddedUndeferConcurrent exercises undefer operations concurrently.

View file

@ -85,6 +85,12 @@ Install with `uv tool install git+https://github.com/jklenk/thread`. Built by [@
- **[LoopTroop](https://github.com/looptroop-ai/LoopTroop)** - Local AI coding orchestrator for automated task planning, execution, and feedback loops. Uses a Beads-inspired methodology with LLM Council consensus and worktree isolation. Built by [@looptroop-ai](https://github.com/looptroop-ai). (Node.js/TypeScript)
- **[beads-pm-kit](https://github.com/cuongbphv/beads-pm-kit)** - Ten skills that let an agent run a Beads board the way a project manager does: split a spec into sized beads, estimate from measured history, take and loop through ready work, run a batch in parallel worktrees, report progress, forecast an ETA (or refuse to give a date), audit "already done" claims, and hand off a session. One authored copy builds for Claude Code, Cursor, Codex and Antigravity; all reads and writes go through the `bd` CLI. Install with `npx skills add cuongbphv/beads-pm-kit`. Built by [@cuongbphv](https://github.com/cuongbphv). (Markdown/Node.js/Python)
## Mail Delegates
- **[aweb beads-mail](https://aweb.ai/docs/beads-mail/)** - Gives `bd mail` a mail provider in any beads repo: `npm i -g @awebai/aw`, `aw init`, `bd config set mail.delegate "aw beads-mail"`. [aweb](https://github.com/awebai/aweb) is an open-source communication layer for AI agents: each agent gets a stable identity and address, mail and chat are stored durably on a server so recipients can be offline, and a wake-up event tells the recipient's runtime (Claude Code, Pi, Codex, or any process reading the event stream) that work is waiting. Identities are either local, routable only inside one team, or global, addressable as `domain/name` across organizations and across independently run servers, which federate with each other. Messages are signed by the sender's own key and verified against a public registry, so `From:` is an identity rather than a caller-asserted name. MIT; run the whole stack yourself with Docker, or use the hosted service at app.aweb.ai. Built by [@juanre](https://github.com/juanre). (Go/Python)
## Coordination Servers
- **[BeadHub](https://github.com/beadhub/beadhub)** - Open-source coordination server for AI agent teams running beads. The `bdh` CLI is a transparent wrapper over `bd` that adds work claiming, file reservation, presence awareness, and inter-agent messaging (async mail and sync chat). Includes a web dashboard. Free hosted at beadhub.ai for open-source projects. Built by [@juanre](https://github.com/juanre). (Python/TypeScript)

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
# CI Cleanup Plan
Last reviewed: 2026-08-14
Last reviewed: 2026-09-03
Freshness source: `engdocs/CI_TEST_SURFACE_AUDIT.md`, `.github/workflows/*.yml`,
`.buildflags`, `.golangci.yml`, `scripts/ci/pr-lint.sh`, `scripts/pr-lint/`,
@ -170,12 +170,15 @@ easy to identify and rerun. It includes:
downloads, a five-minute timeout, and the `gms_pure_go` build tag.
- A second non-CGO Windows cross-lint pass when the native target does not
already cover that build tuple.
- A third non-CGO darwin (arm64) cross-lint pass under the same rule. Both
cross-lints are compile-only passes on the Linux runner; they add no macOS or
Windows runner and do not change the platform column above.
The two lint passes and their target selection are owned by the
All three lint passes and their target selection are owned by the
checkout-local `scripts/pr-lint` Go driver. The Bash wrapper retains formatting,
direct invocation, and aggregate timing without duplicating that policy.
Both passes are SCOPED BY LANE. On a PR the wrapper takes
All three passes are SCOPED BY LANE. On a PR the wrapper takes
`BD_LINT_NEW_FROM_MERGE_BASE` and reports only the findings that PR introduces,
matching the `only-new-issues` setting on the sibling `lint` job; on a push to
`main`, and for anyone running `make ci-pr-lint` by hand, it is unset and the
@ -771,7 +774,7 @@ artifacts, so `postinstall` URLs are populated before the package is published.
where practical so branch-protection migration can be handled separately.
10. Add stable aggregate required-check candidates after the split.
Initial aggregate jobs exist on branch `ci/bd-am3.1-wrapper-commands` as
`PR / CI Gate / Required` and `PR Risk / CI Gate / Required`, backed by
`PR / CI Gate / Required` and `PR Risk / PR Risk Gate / Required`, backed by
`.github/scripts/ci-gate.sh`.
## Deferred Decisions

View file

@ -1,7 +1,7 @@
# Required Check Topology
Status: aggregate gate jobs are implemented; branch-protection and ruleset
adoption remain pending. The aggregate-gate policy below remains maintainer
Status: aggregate gate jobs are implemented, and the default-branch ruleset
requires both aggregates (see Current State). The aggregate-gate policy below remains maintainer
context, but `.github/workflows/*.yml` and their structural tests are
authoritative for current job membership and display names. Copied workflow
wiring and rollout steps in this note describe the initial rollout, not the
@ -36,12 +36,43 @@ Current PR-related workflow names:
- `.github/workflows/pr.yml`: `PR`
Runs on `pull_request` and `merge_group`. Contains the baseline PR jobs,
Linux build artifact stage, policy/lint compatibility jobs, package gates
that consume the Linux artifact, focused storage domain/uow coverage, and
the baseline aggregate gate `PR / CI Gate / Required`.
that consume the Linux artifact, focused storage domain/uow coverage, the
Bazel lane (the `bazel` job calls `bazel.yml`), and the baseline aggregate
gate `PR / CI Gate / Required`.
- `.github/workflows/bazel.yml`: `Bazel`
Runs on `push` to `main`, manual dispatch, and `workflow_call` only. PRs and
merge groups run it once, through `pr.yml`'s `bazel` job. Its `rbe` job
decides the execution mode once (`remote`, `local` for fork and Dependabot
PRs, or `skip` while the `RBE_WEST_WORKERS` repo variable is unset) and
exports it as the `rbe-mode` / `rbe-enabled` outputs; every lane exports its
`job.status` as an output named after the job. `pr.yml`'s gate requires the
call's result (`BAZEL`) and `BAZEL_TEST`, `BAZEL_PURE`, `BAZEL_EMBEDDED`,
`BAZEL_DOLTSERVER`, `BAZEL_PROXIED` and `BAZEL_SERVER_STORAGE`. The legacy jobs these mirror stay required in `pr.yml`
and `pr-risk.yml`.
`.github/scripts/bazel-gate.sh` reads the exported mode, never the variable
or the fork flag: mode `skip` allows every Bazel id to skip, mode `local`
allows only the remote-only `BAZEL_EMBEDDED`, `BAZEL_PROXIED` and
`BAZEL_SERVER_STORAGE` (fork and Dependabot PRs rely on `pr-risk.yml`'s
legacy tiers for those), and mode `remote` allows none.
A lane that should run and fails, is cancelled, or reports no result fails
the gate, and so does a missing or invalid mode.
`bazel-integration` is not part of the PR call (`pr.yml` passes
`integration: "off"`) and has no gate id: its legacy counterparts
(`main.yml`'s integration jobs) run only on push to `main`, and so does it
(plus dispatch and nightly). `scripts/ci_workflow_test.go` fails when a new
`bazel.yml` job has neither a gate id nor an advisory entry.
Runbook: if `main`'s Bazel BUILD files drift (every PR's Bazel lanes go
red, and autofix only patches packages the PR itself changed), the RBE
farm is down, or the beads CI RBE client certificate expires (about
2027-09-27; a partial secret set also fails every same-repo run), fix
`main` (`make bazel-sync`) or renew the secrets, or unset the
`RBE_WEST_WORKERS` repo variable: same-repo runs then take mode `skip`,
which the gate accepts (fork PRs still run locally, so drift on `main`
still reaches them).
- `.github/workflows/pr-risk.yml`: `PR Risk`
Runs on `pull_request` and `merge_group`. Contains embedded Dolt risk
detection, embedded build/test shards, the Nix flake smoke check, and the
risk aggregate gate `PR Risk / CI Gate / Required`.
risk aggregate gate `PR Risk / PR Risk Gate / Required`.
- `.github/workflows/main.yml`: `Main`
Runs on pushes to `main`. Contains the main branch health checks, package
gates, platform smoke/short coverage, embedded Dolt coverage, and promoted
@ -63,7 +94,17 @@ Current PR-related workflow names:
As of 2026-05-26, the live `gastownhall/beads` ruleset named
`Protect main - light (beads and gastown)` enforces deletion and non-fast-forward
protection on the default branch. It does not currently require status checks.
protection on the default branch. It does not require status checks.
Since 2026-09-29 a second, beads-only ruleset, `beads main: required CI
gates`, is active on the default branch. It requires the GitHub Actions
checks `CI Gate / Required` (`pr.yml`, which includes the Bazel lanes through
the `bazel` call) and `PR Risk Gate / Required` (`pr-risk.yml`). PR Risk's
gate job was renamed from `CI Gate / Required` to `PR Risk Gate / Required`
(#6939), so the two required contexts are distinct; before that both
workflows reported the same check name. Organization admins and one team
may bypass it. There is no merge queue, so the checks run on
`pull_request`.
## Required Check Contract
@ -76,7 +117,7 @@ rollout uses one aggregate per required workflow. An external status aggregator
would only be needed if maintainers still want exactly one required check.
- Baseline aggregate candidate: `PR / CI Gate / Required`
- Risk aggregate candidate: `PR Risk / CI Gate / Required`
- Risk aggregate candidate: `PR Risk / PR Risk Gate / Required`
- Source: GitHub Actions
- Required on: pull requests and merge queue groups targeting `main`
@ -102,6 +143,7 @@ Do not require these existing check names directly:
- `Upgrade smoke (<version> -> candidate)`
- `Resolve versions to test`
- `nix build .#default`
- `Bazel / test` and the other jobs of `bazel.yml`
Those checks should remain visible for diagnosis, but branch protection should
point at aggregate gates after the gate jobs are verified.

View file

@ -161,7 +161,7 @@ The former monolithic `ci.yml` has been split by tier/domain:
the aggregate check `PR / CI Gate / Required`.
- `pr-risk.yml`: pull request and merge queue risk jobs. It owns embedded Dolt
risk detection, embedded build/storage/cmd shards, the Nix flake smoke, and
the aggregate check `PR Risk / CI Gate / Required`.
the aggregate check `PR Risk / PR Risk Gate / Required`.
- `main.yml`: push-to-`main` branch health. It reruns the baseline wrappers,
package gates, Linux/macOS short coverage, Windows smoke, embedded Dolt, Nix,
storage domain/uow, and promoted Linux no-short integration shards.
@ -183,7 +183,7 @@ Key jobs preserved by display name:
- `Build (Embedded Dolt)`, `Test (Embedded Dolt Storage N/5)`, and
`Test (Embedded Dolt Cmd N/20)`.
- Aggregate required-check candidates: `PR / CI Gate / Required` and
`PR Risk / CI Gate / Required`.
`PR Risk / PR Risk Gate / Required`.
- Main-only platform and integration jobs: `Test (ubuntu-latest)`,
`Test (macos-latest)`, `Test (Windows - smoke)`,
`Main Linux integration packages (N/6)`, and

View file

@ -1,5 +1,6 @@
# Documentation Disposition Inventory
Graph-plane design records added: 2026-09-10.
Reviewed: 2026-07-07 (paths updated 2026-07-10 for the Mintlify port: user docs now live in the docs/ site tree; this ledger and other internal docs live in engdocs/)
CI cleanup entry added: 2026-05-28
@ -57,6 +58,9 @@ Follow-up automation should replace marker-only checks with generated or
| `ANTIVIRUS.md` | Keep | User-facing operational note; review vendor/version claims when touched. |
| `ARCHITECTURE.md` | Keep | Primary architecture overview; evidence is current package layout and Dolt-only storage path. |
| `ATTRIBUTION.md` | Keep | Attribution record for removed merge engine. |
| `BDP_BEAD_GRAPH_PLAN.md` | Keep | Graph-plane design record; ruled contracts and dated dependency sources, not runtime or merge clearance. |
| `BDP_GRAPH_ARCHITECTURE.md` | Keep | Graph-plane design record; ruled contracts and dated dependency sources, not runtime or merge clearance. |
| `BDP_GRAPH_CLI_AND_STORAGE_SPEC.md` | Keep | Graph-plane design record; ruled contracts and dated dependency sources, not runtime or merge clearance. |
| `CLAUDE_INTEGRATION.md` | Keep | Design/user guide for Claude setup; paired with `SETUP.md`. |
| `CLAUDE.md` | Revise | Kept as architecture orientation only; command/workflow duplication was reduced in favour of root `AGENTS.md` and `AGENT_INSTRUCTIONS.md`. |
| `CLI_REFERENCE.md` | Keep/generated | Generated command reference from live help output. |

View file

@ -42,11 +42,14 @@ The wrapper runs:
`.golangci.yml`, readonly module downloads, a five-minute timeout, the
`gms_pure_go` build tag, and `--new-from-merge-base` when
`BD_LINT_NEW_FROM_MERGE_BASE` names a ref, then runs the same scope for the
non-CGO Windows target when the native host does not already cover it.
non-CGO Windows target and the non-CGO darwin (arm64) target when the native
host does not already cover them, so `//go:build windows && !cgo` and
`//go:build darwin` files are linted from the Linux runner.
The shell wrapper records one aggregate timing for the Go lint driver. The
driver prints a heading and result for each native or Windows pass so failures
remain attributable without duplicating target-selection policy in Bash.
driver prints a heading and result for each native or cross-target pass so
failures remain attributable without duplicating target-selection policy in
Bash.
The shared driver owns the lint passes used by `scripts/ci/pr-lint.sh` and
Beads-source `bd preflight`. The standalone workflow lint action and pre-commit

View file

@ -81,6 +81,39 @@ To skip an optional service explicitly, use the existing skip mechanism:
BEADS_TEST_SKIP=dolt ./scripts/test.sh ./...
```
Tests that need a Dolt SQL server get one from `internal/testutil`
(`EnsureDoltContainerForTestMain`, `RequireDoltContainer`,
`StartIsolatedDoltContainer[Handle]`, `NewContainerProvider`). Two backends
sit behind that API, selected by `BEADS_TEST_DOLT_SERVER`:
- `container`: the `dolthub/dolt-sql-server` image through testcontainers
(needs docker and the pulled image). The default under plain `go test`.
- `local`: a `dolt sql-server` started by the test process from the pinned
dolt CLI (`BEADS_TEST_DOLT_BINARY`, else `dolt` on `PATH`; it must be the
image's version). No docker. Used only when explicitly selected, under
`go test` and `bazel test` alike (a Bazel target's `env`, or
`--test_env=BEADS_TEST_DOLT_SERVER=local`); unset means `container`, which
in a Bazel action without docker keeps the usual skip.
`BEADS_TEST_REQUIRE_DOLT_CONTAINER=1` turns an unavailable backend into a
failure (per test and in every `TestMain`) instead of a skip; lanes that
exist to run the Dolt suites set it.
Under Bazel, `bazel test //... --config=doltserver` runs the Dolt-backed
suites of pr.yml's "Test (storage domain + uow)" and "Contract corpus" jobs
on the `local` backend (the `dolt-server` targets); they need no docker and
execute remotely with `--config=remote-exec`. `--config=docker` runs the same
suites on the `container` backend (host docker) as the A/B control.
PR Risk's heavier server tiers have configs of their own, run by bazel.yml
only with remote execution, each in a job of its own (`bazel-proxied`,
`bazel-server-storage`): `--config=doltserver-proxied` is the
proxied-server cmd/bd tier ("Test (Proxied Dolt Cmd N/15)",
`//cmd/bd:bd_proxied_test`), and `--config=doltserver-integration` the
server-Dolt storage tier ("Test (Server Dolt Conformance)", "Test (Server
Dolt Full Suite N/16)", `//internal/storage/dolt:dolt_server_*_test`), which
builds with the integration tag like `--config=integration`. Each shard
runs its CI job's shard script, so Bazel shard k runs the tests of job k+1.
Tests that need a temporary repository or store should use `t.TempDir()` and
`t.Cleanup()`. Temporary repositories must set a repository-local hooks path;
do not inherit the developer's global hooks configuration.

2
go.mod
View file

@ -154,7 +154,7 @@ require (
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 // indirect
github.com/dolthub/ishell v0.0.0-20260414231531-5f031e3e9037 // indirect
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71 // indirect
github.com/dolthub/vitess v0.0.0-20260728212736-0542037326d7 // indirect
github.com/dolthub/vitess v0.0.0-20260728212736-0542037326d7
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/ebitengine/purego v0.10.0 // indirect
github.com/edsrzf/mmap-go v1.2.0 // indirect

View file

@ -24,14 +24,21 @@ go_test(
name = "beads_test",
srcs = [
"beads_coverage_test.go",
"beads_hash_multiclone_test.go",
"beads_inherited_artifacts_test.go",
"beads_integration_test.go",
"beads_multidb_test.go",
"beads_symlink_test.go",
"beads_test.go",
"context_test.go",
"cwd_priority_test.go",
"explicit_beads_dir_test.go",
"fingerprint_test.go",
"routing_integration_test.go",
"sqlite_database_path_test.go",
"suite_temp_test.go",
"testmain_default_test.go",
"testmain_integration_test.go",
"testmain_test.go",
],
embed = [":beads"],
@ -41,7 +48,11 @@ go_test(
"//internal/doltserver",
"//internal/git",
"//internal/gitenv",
"//internal/routing",
"//internal/storage/dolt",
"//internal/testutil",
"//internal/testutil/bazeltest",
"//internal/types",
"//internal/utils",
],
)

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