Merge latest main into adopted PR head (adopt-pr gate, merge mode)
Neither rebase nor a plain merge applied: main landed this branch's whole dependency stack (#6454, #6459, #6461, #6457, #6462, #6463, #6464, all refined further on main), so all 18 conflicted files collided with main's final form of the same code. Reconciliation, hunk by hunk: - 16 files resolve to main byte-for-byte. Every line the stack added that is absent on main was refined there: ScrubRoutingAndSuppression for role authority, roleAuthorityEnv, execenv.KeyIdentityForOS, the 3-argument ensureMatchingCLIRemote, and no isRoleGitRepo helper. - The maintainer fixup's parts are already on main in main's own form: the scoped role-writer comment in cmd/bd/config.go, the worktrees.md startup probe wording, and the #6477 collision repair (core.bare row plus TestConfig_BeadsRoleScrubsInheritedRoutingEnv, captured_home expecting the error). - Contested, resolved to main: the fixup's removal of GIT_CEILING_DIRECTORIES and GIT_DISCOVERY_ACROSS_FILESYSTEM from gitenv.routingKeys. Main keeps both keys on purpose and documents why at IsRoutingKeyForOS (#6459). #6462 declined to split the set, and three main pins would fail without the ceiling key (internal/gitenv/routing_test.go scrub table, internal/config/worktree_config_test.go, and cmd/bd/init_git_bootstrap_routing_test.go). So this merge drops the fixup's routing.go change and its two fence pins (TestScrubRoutingRetainsDiscoveryFences and TestScrubbedGitCommandsHonorOperatorCeiling). The fence-policy question stays tracked in bd-dz16y. - Kept, and still absent from main: the GH#6384 origin-selection core (saa-cgh.120.8). resolveProxiedInitRemoteURL now reads origin from the selected project directory rather than the Beads-storage use case. This also keeps the #6460 bootstrap note and TestProxiedInitRemoteURLUsesSelectedProject. Net diff against main: 2 files, +129/-2. Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
8e77aa3523
670 changed files with 58020 additions and 2560 deletions
12
.bazelignore
Normal file
12
.bazelignore
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
examples/library-usage
|
||||
examples/bd-example-extension-go
|
||||
npm-package
|
||||
website
|
||||
node_modules
|
||||
.claude
|
||||
.worktrees
|
||||
.beads
|
||||
.dolt
|
||||
dist
|
||||
.runtime
|
||||
tmp
|
||||
257
.bazelrc
Normal file
257
.bazelrc
Normal file
|
|
@ -0,0 +1,257 @@
|
|||
# Bazel configuration for beads (side-by-side with the Go toolchain; `go build`
|
||||
# and `go test` are unaffected). Bzlmod only; Bazel version is pinned in
|
||||
# .bazelversion.
|
||||
common --enable_bzlmod
|
||||
common --color=no
|
||||
|
||||
# ICU policy (engdocs/ICU-POLICY.md): build go-mysql-server with its pure-Go
|
||||
# regex backend so no target links libicu. MODULE.bazel carries the matching
|
||||
# gazelle_override for github.com/dolthub/go-mysql-server.
|
||||
build --@rules_go//go/config:tags=gms_pure_go
|
||||
|
||||
# Keep the client PATH/env out of action keys.
|
||||
build --incompatible_strict_action_env
|
||||
|
||||
test --test_output=errors
|
||||
# Test environment isolation (the pr-core `go test` environment of
|
||||
# scripts/ci/lib/test-env.sh): every test process runs under a wrapper that
|
||||
# gives it a private HOME, XDG_CONFIG_HOME, DOLT_ROOT_PATH, empty global
|
||||
# gitconfig and a short, per-process TMPDIR (unix-socket sun_path limit).
|
||||
# Client HOME/TMPDIR are never forwarded, so no host value enters the action key.
|
||||
test --run_under=//tools/bazel:test_env
|
||||
test --test_env=BD_DISABLE_METRICS=1
|
||||
test --test_env=BD_DISABLE_EVENT_FLUSH=1
|
||||
|
||||
# PR-core parity: the same test selection as scripts/ci/pr-core.sh (race,
|
||||
# -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
|
||||
# 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
|
||||
# tools/bazel/equivalence.py compares the Go tests Bazel ran with the ones
|
||||
# `go test` would run, from each target's test.xml. rules_go only lists passing
|
||||
# tests in test.xml under -test.v, and --remote_download_minimal would leave
|
||||
# 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 "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.
|
||||
# Developers put them in a gitignored user.bazelrc or .bazelrc.local; CI writes
|
||||
# a generated rc outside the workspace and passes it with --bazelrc.
|
||||
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
|
||||
1
.bazelversion
Normal file
1
.bazelversion
Normal file
|
|
@ -0,0 +1 @@
|
|||
9.2.0
|
||||
|
|
@ -19,7 +19,7 @@ if command -v bd >/dev/null 2>&1; then
|
|||
if command -v "$_bd_timeout_candidate" >/dev/null 2>&1; then
|
||||
if _bd_timeout_version="$("$_bd_timeout_candidate" --version 2>/dev/null)"; then
|
||||
case "$_bd_timeout_version" in
|
||||
"timeout (GNU coreutils) "*) _bd_timeout_command=$_bd_timeout_candidate; break ;;
|
||||
"timeout (GNU coreutils) "*|"timeout (uutils coreutils) "*) _bd_timeout_command=$_bd_timeout_candidate; break ;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ if command -v bd >/dev/null 2>&1; then
|
|||
if command -v "$_bd_timeout_candidate" >/dev/null 2>&1; then
|
||||
if _bd_timeout_version="$("$_bd_timeout_candidate" --version 2>/dev/null)"; then
|
||||
case "$_bd_timeout_version" in
|
||||
"timeout (GNU coreutils) "*) _bd_timeout_command=$_bd_timeout_candidate; break ;;
|
||||
"timeout (GNU coreutils) "*|"timeout (uutils coreutils) "*) _bd_timeout_command=$_bd_timeout_candidate; break ;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ if command -v bd >/dev/null 2>&1; then
|
|||
if command -v "$_bd_timeout_candidate" >/dev/null 2>&1; then
|
||||
if _bd_timeout_version="$("$_bd_timeout_candidate" --version 2>/dev/null)"; then
|
||||
case "$_bd_timeout_version" in
|
||||
"timeout (GNU coreutils) "*) _bd_timeout_command=$_bd_timeout_candidate; break ;;
|
||||
"timeout (GNU coreutils) "*|"timeout (uutils coreutils) "*) _bd_timeout_command=$_bd_timeout_candidate; break ;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ if command -v bd >/dev/null 2>&1; then
|
|||
if command -v "$_bd_timeout_candidate" >/dev/null 2>&1; then
|
||||
if _bd_timeout_version="$("$_bd_timeout_candidate" --version 2>/dev/null)"; then
|
||||
case "$_bd_timeout_version" in
|
||||
"timeout (GNU coreutils) "*) _bd_timeout_command=$_bd_timeout_candidate; break ;;
|
||||
"timeout (GNU coreutils) "*|"timeout (uutils coreutils) "*) _bd_timeout_command=$_bd_timeout_candidate; break ;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ if command -v bd >/dev/null 2>&1; then
|
|||
if command -v "$_bd_timeout_candidate" >/dev/null 2>&1; then
|
||||
if _bd_timeout_version="$("$_bd_timeout_candidate" --version 2>/dev/null)"; then
|
||||
case "$_bd_timeout_version" in
|
||||
"timeout (GNU coreutils) "*) _bd_timeout_command=$_bd_timeout_candidate; break ;;
|
||||
"timeout (GNU coreutils) "*|"timeout (uutils coreutils) "*) _bd_timeout_command=$_bd_timeout_candidate; break ;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
|
|
|
|||
70
.github/actions/setup-bazel/action.yml
vendored
Normal file
70
.github/actions/setup-bazel/action.yml
vendored
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
name: setup-bazel
|
||||
description: >
|
||||
Install a sha256-pinned Bazelisk (Bazel itself comes from .bazelversion),
|
||||
restore the runner Bazel cache (--repository_cache and Bazelisk only),
|
||||
and write a CI bazelrc outside the workspace. When the caller passes all of
|
||||
BAZEL_REMOTE_EXECUTOR, RBE_TLS_CERT and RBE_TLS_KEY in the step env, that rc
|
||||
enables --config=remote-exec for every bazel command; with none of them the
|
||||
job runs locally (fork PRs); a partial set fails. `bazel` on PATH is a
|
||||
wrapper that always passes the generated rc.
|
||||
outputs:
|
||||
remote:
|
||||
description: '"true" when remote execution is configured'
|
||||
value: ${{ steps.rc.outputs.remote }}
|
||||
cache-restored:
|
||||
description: '"true" when a runner Bazel cache was restored (any prefix match)'
|
||||
value: ${{ steps.restore.outputs.cache-matched-key != '' }}
|
||||
cache-hit:
|
||||
description: '"true" when the cache for this .bazelversion and MODULE.bazel.lock was restored exactly'
|
||||
value: ${{ steps.restore.outputs.cache-hit }}
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
# Keyed on what determines its content; saved only by a push to main that
|
||||
# missed the exact key (see the caller's "Save Bazel runner cache" step).
|
||||
# A lock change restores the previous lock's entry, which still holds most
|
||||
# of the downloads.
|
||||
- name: Restore Bazel runner cache
|
||||
id: restore
|
||||
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
|
||||
with:
|
||||
path: ${{ runner.temp }}/bazel-ci-cache
|
||||
key: bazel-repo-v2-${{ runner.os }}-${{ hashFiles('.bazelversion', 'MODULE.bazel.lock') }}
|
||||
restore-keys: |
|
||||
bazel-repo-v2-${{ runner.os }}-
|
||||
|
||||
- name: Install Bazelisk
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
version=v1.29.0
|
||||
case "$(uname -m)" in
|
||||
x86_64) arch=amd64; sha=5a408715e932c0250d28bd84555f12edbf70117de42f9181691c736eacc4a992 ;;
|
||||
aarch64 | arm64) arch=arm64; sha=e20e8b0f4f240091b7a55bf17b9398bd4f40ee70ae0208dff95dd4c445fb4010 ;;
|
||||
*) echo "setup-bazel: unsupported arch $(uname -m)" >&2; exit 1 ;;
|
||||
esac
|
||||
curl -fsSL --retry 3 --max-time 120 -o "$RUNNER_TEMP/bazelisk" \
|
||||
"https://github.com/bazelbuild/bazelisk/releases/download/${version}/bazelisk-linux-${arch}"
|
||||
echo "${sha} $RUNNER_TEMP/bazelisk" | sha256sum -c -
|
||||
sudo install -m 755 "$RUNNER_TEMP/bazelisk" /usr/local/bin/bazelisk
|
||||
rm -f "$RUNNER_TEMP/bazelisk"
|
||||
echo "BAZELISK_HOME=$RUNNER_TEMP/bazel-ci-cache/bazelisk" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Write CI bazelrc
|
||||
id: rc
|
||||
shell: bash
|
||||
env:
|
||||
BAZEL_CI_CACHE_DIR: ${{ runner.temp }}/bazel-ci-cache
|
||||
BAZEL_CI_SECRET_DIR: ${{ runner.temp }}/bazel-ci-secret
|
||||
run: bash "$GITHUB_ACTION_PATH/write-bazelrc.sh"
|
||||
|
||||
- name: Install bazel wrapper
|
||||
shell: bash
|
||||
env:
|
||||
RC: ${{ steps.rc.outputs.rc }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
printf '%s\n' '#!/usr/bin/env bash' "exec /usr/local/bin/bazelisk --bazelrc=\"$RC\" \"\$@\"" > "$RUNNER_TEMP/bazel-wrapper"
|
||||
sudo install -m 755 "$RUNNER_TEMP/bazel-wrapper" /usr/local/bin/bazel
|
||||
rm -f "$RUNNER_TEMP/bazel-wrapper"
|
||||
/usr/local/bin/bazelisk --version
|
||||
152
.github/actions/setup-bazel/write-bazelrc.sh
vendored
Normal file
152
.github/actions/setup-bazel/write-bazelrc.sh
vendored
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
#!/usr/bin/env bash
|
||||
# Write the CI bazelrc for .github/actions/setup-bazel.
|
||||
#
|
||||
# Always: --repository_cache under BAZEL_CI_CACHE_DIR (the directory the
|
||||
# runner cache saves and restores). Never --disk_cache: remote runs have the
|
||||
# remote cache, and a local run's disk cache (about 7 GB) would not fit next to
|
||||
# its output base on a hosted runner.
|
||||
#
|
||||
# Remote execution only when all three of BAZEL_REMOTE_EXECUTOR, RBE_TLS_CERT
|
||||
# and RBE_TLS_KEY are set (repo secrets; empty on fork PRs, so those runs stay
|
||||
# local). Exactly one or two of them is a misconfiguration and fails. Optional:
|
||||
# RBE_TLS_CA (base64 PEM CA bundle) and RBE_INSTANCE (instance name; a warning
|
||||
# when empty, because the default instance may share its action cache with
|
||||
# other repos on the same farm). Cert and key are base64-encoded PEM (raw PEM
|
||||
# is accepted too). Every line of the decoded PEM is masked in the job log.
|
||||
#
|
||||
# CI uploads only remotely executed results (--noremote_upload_local_results):
|
||||
# a job's locally executed actions (PR code included) never enter the shared
|
||||
# action cache from here. Developer rcs keep Bazel's default.
|
||||
#
|
||||
# The rc and the key material go to BAZEL_CI_SECRET_DIR, which must be outside
|
||||
# the workspace (tests that walk the checkout must never see an endpoint or a
|
||||
# cert path) and outside BAZEL_CI_CACHE_DIR (the runner cache must never store
|
||||
# credentials). The endpoint is masked in the job log.
|
||||
#
|
||||
# Outputs (to $GITHUB_OUTPUT when set, else stdout): rc=<path>, remote=true|false.
|
||||
set -euo pipefail
|
||||
|
||||
cache_dir="${BAZEL_CI_CACHE_DIR:?BAZEL_CI_CACHE_DIR is required}"
|
||||
secret_dir="${BAZEL_CI_SECRET_DIR:?BAZEL_CI_SECRET_DIR is required}"
|
||||
workspace="${GITHUB_WORKSPACE:-$PWD}"
|
||||
|
||||
abs() { mkdir -p "$1" && (cd "$1" && pwd -P); }
|
||||
cache_dir="$(abs "$cache_dir")"
|
||||
secret_dir="$(abs "$secret_dir")"
|
||||
workspace="$(cd "$workspace" && pwd -P)"
|
||||
case "$secret_dir/" in
|
||||
"$workspace"/*)
|
||||
echo "setup-bazel: BAZEL_CI_SECRET_DIR ($secret_dir) must be outside the workspace" >&2
|
||||
exit 1
|
||||
;;
|
||||
"$cache_dir"/*)
|
||||
echo "setup-bazel: BAZEL_CI_SECRET_DIR must not be inside the cached BAZEL_CI_CACHE_DIR" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
chmod 700 "$secret_dir"
|
||||
mkdir -p "$cache_dir/repo"
|
||||
|
||||
mask() {
|
||||
local v="${1:-}"
|
||||
[[ -z "$v" ]] && return 0
|
||||
printf '::add-mask::%s\n' "$v"
|
||||
}
|
||||
|
||||
# Mask the endpoint and its bare host[:port]: Bazel prints bytestream:// URIs
|
||||
# that carry the host without the scheme.
|
||||
executor="${BAZEL_REMOTE_EXECUTOR:-}"
|
||||
if [[ -n "$executor" ]]; then
|
||||
mask "$executor"
|
||||
hostport="${executor#*://}"
|
||||
hostport="${hostport%%/*}"
|
||||
mask "$hostport"
|
||||
mask "${hostport%:*}"
|
||||
# Bazel's connection errors print the resolved address ("host/1.2.3.4:443").
|
||||
if command -v getent >/dev/null 2>&1; then
|
||||
while read -r addr _; do
|
||||
mask "$addr"
|
||||
done < <(getent ahosts "${hostport%:*}" 2>/dev/null | sort -u -k1,1)
|
||||
fi
|
||||
fi
|
||||
|
||||
cert="${RBE_TLS_CERT:-}"
|
||||
key="${RBE_TLS_KEY:-}"
|
||||
ca="${RBE_TLS_CA:-}"
|
||||
instance="${RBE_INSTANCE:-}"
|
||||
|
||||
rc="$secret_dir/ci.bazelrc"
|
||||
umask 077
|
||||
{
|
||||
echo "# Generated by .github/actions/setup-bazel; not a workspace file."
|
||||
echo "common --repository_cache=$cache_dir/repo"
|
||||
} >"$rc"
|
||||
|
||||
# write_pem DEST VALUE: decode base64 (or accept raw PEM) and check it is PEM.
|
||||
write_pem() {
|
||||
local dest="$1" body="$2"
|
||||
body="$(printf '%s' "$body" | tr -d '\r')"
|
||||
if [[ "$body" != *"-----BEGIN "* ]]; then
|
||||
if ! body="$(printf '%s' "$body" | tr -d '\n ' | base64 -d 2>/dev/null)"; then
|
||||
echo "setup-bazel: $(basename "$dest") secret is neither PEM nor base64 PEM" >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
if [[ "$body" != *"-----BEGIN "* ]]; then
|
||||
echo "setup-bazel: $(basename "$dest") secret does not decode to PEM" >&2
|
||||
return 1
|
||||
fi
|
||||
# GitHub masks the secret as stored (base64), not what it decodes to.
|
||||
local line
|
||||
while IFS= read -r line; do
|
||||
[[ -z "$line" || "$line" == -----* ]] || mask "$line"
|
||||
done <<<"$body"
|
||||
printf '%s\n' "$body" >"$dest"
|
||||
chmod 600 "$dest"
|
||||
}
|
||||
|
||||
set_fields=0
|
||||
for v in "$executor" "$cert" "$key"; do
|
||||
[[ -n "$v" ]] && set_fields=$((set_fields + 1))
|
||||
done
|
||||
|
||||
remote=false
|
||||
if [[ "$set_fields" -eq 3 ]]; then
|
||||
write_pem "$secret_dir/client.crt" "$cert"
|
||||
write_pem "$secret_dir/client.key" "$key"
|
||||
# Outside the rc block below: write_pem's mask commands go to the log.
|
||||
if [[ -n "$ca" ]]; then
|
||||
write_pem "$secret_dir/ca.crt" "$ca"
|
||||
fi
|
||||
{
|
||||
echo "build:remote-exec --remote_executor=$executor"
|
||||
echo "build:remote-exec --tls_client_certificate=$secret_dir/client.crt"
|
||||
echo "build:remote-exec --tls_client_key=$secret_dir/client.key"
|
||||
if [[ -n "$ca" ]]; then
|
||||
echo "build:remote-exec --tls_certificate=$secret_dir/ca.crt"
|
||||
fi
|
||||
if [[ -n "$instance" ]]; then
|
||||
echo "build:remote-exec --remote_instance_name=$instance"
|
||||
fi
|
||||
echo "build:remote-exec --noremote_upload_local_results"
|
||||
# Every command in this job (test, run //:gazelle, query) uses the
|
||||
# executor; the committed .bazelrc holds the generic remote-exec tuning.
|
||||
echo "build --config=remote-exec"
|
||||
} >>"$rc"
|
||||
if [[ -z "$instance" ]]; then
|
||||
echo "::warning title=RBE_INSTANCE not set::remote execution uses the executor's default instance, whose action cache other repos on the farm may share; set RBE_INSTANCE to a beads-only instance"
|
||||
fi
|
||||
remote=true
|
||||
echo "setup-bazel: remote execution enabled"
|
||||
elif [[ "$set_fields" -ne 0 ]]; then
|
||||
echo "setup-bazel: remote execution is partially configured; BAZEL_REMOTE_EXECUTOR, RBE_TLS_CERT and RBE_TLS_KEY must be set together (or none, for local execution)" >&2
|
||||
exit 1
|
||||
else
|
||||
echo "setup-bazel: no remote execution secrets; running locally"
|
||||
fi
|
||||
|
||||
out="${GITHUB_OUTPUT:-/dev/stdout}"
|
||||
{
|
||||
echo "rc=$rc"
|
||||
echo "remote=$remote"
|
||||
} >>"$out"
|
||||
56
.github/scripts/bazel-gate.sh
vendored
Executable file
56
.github/scripts/bazel-gate.sh
vendored
Executable 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
|
||||
11
.github/scripts/server-storage-test-shards.txt
vendored
11
.github/scripts/server-storage-test-shards.txt
vendored
|
|
@ -2,13 +2,10 @@
|
|||
#
|
||||
# Format: <total_shards> <shard_number> <top_level_test_name>
|
||||
#
|
||||
# Unlike the embedded manifest, per-test timing is known for the tests
|
||||
# pinned below (see be-extn's investigation of CI job 95616282508):
|
||||
# TestCloudAuthCLIRouting alone costs ~9.5 minutes -- its 16 subtests each
|
||||
# call openCloudAuthTestStore, which does CREATE DATABASE + the full
|
||||
# migration chain + dolt init + dolt remote add + DROP DATABASE, and the
|
||||
# test uses t.Setenv so it can never run t.Parallel. It is pinned alone on
|
||||
# shard 1 so no other test shares its runtime. The remaining pins below
|
||||
# TestCloudAuthCLIRouting uses one shared outer store (#5841); its
|
||||
# environment-sensitive subtests run serially. #6396 checks that remote
|
||||
# writes use the shared fixture without imposing a machine-speed threshold.
|
||||
# It remains pinned alone on shard 1. The remaining pins below
|
||||
# (TestCloudAuthCLIRoutingStructural, TestCreateGuard_* (9 tests),
|
||||
# TestFederationPeerCredentialLifecycleLazyKeyInit,
|
||||
# TestConcurrentWorkQueueDrain, TestHighContentionStress,
|
||||
|
|
|
|||
135
.github/workflows/bazel-autofix.yml
vendored
Normal file
135
.github/workflows/bazel-autofix.yml
vendored
Normal 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
|
||||
957
.github/workflows/bazel.yml
vendored
Normal file
957
.github/workflows/bazel.yml
vendored
Normal file
|
|
@ -0,0 +1,957 @@
|
|||
# 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).
|
||||
#
|
||||
# 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
|
||||
# client certificate. setup-bazel is itself PR code, the key file is readable
|
||||
# by every later step and by locally executed Bazel actions, and a .bazelrc
|
||||
# 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, 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 .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. 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
|
||||
# only by a push to main that missed it. No --disk_cache: remote runs use the
|
||||
# remote cache, and local runs would need about 7 GB more.
|
||||
#
|
||||
# Workflow-file changes suppress pull_request runs under the org approval
|
||||
# policy; validate edits to this file with workflow_dispatch on the branch.
|
||||
name: Bazel
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
rbe:
|
||||
description: "Remote execution: on (use secrets) or off (fork simulation)"
|
||||
required: true
|
||||
type: choice
|
||||
default: "on"
|
||||
options: [ "on", "off" ]
|
||||
details:
|
||||
description: "List every equivalence divergence"
|
||||
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:
|
||||
type: string
|
||||
required: false
|
||||
default: "on"
|
||||
details:
|
||||
type: boolean
|
||||
required: false
|
||||
default: true
|
||||
go-test-json-artifact:
|
||||
description: >
|
||||
Artifact (from the calling run) holding go-test.json, PR Core's
|
||||
`go-test -json` on this commit; enables the equivalence skip-parity
|
||||
check. nightly.yml sets it.
|
||||
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 (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' }}
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
env:
|
||||
BD_DISABLE_METRICS: "1"
|
||||
BD_DISABLE_EVENT_FLUSH: "1"
|
||||
# Phase B report-only budget for T1/T2 (tools/bazel/critpath.py).
|
||||
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: 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. 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). 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
|
||||
|
||||
# Go is for tools/bazel/equivalence.py's `go list` and for make; Bazel
|
||||
# uses its own hermetic SDK.
|
||||
- name: Set up Go
|
||||
id: setup-go
|
||||
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
|
||||
with:
|
||||
go-version-file: 'go.mod'
|
||||
cache: false
|
||||
|
||||
# Read-only: main.yml's build-artifacts job owns this cache.
|
||||
- name: Restore Go module cache
|
||||
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: beads-go-mod-v2-${{ runner.os }}-${{ runner.arch }}-go-${{ steps.setup-go.outputs.go-version }}-${{ hashFiles('go.mod', 'go.sum') }}
|
||||
restore-keys: beads-go-mod-v2-${{ runner.os }}-${{ runner.arch }}-go-${{ steps.setup-go.outputs.go-version }}-
|
||||
|
||||
- name: 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' || '' }}
|
||||
|
||||
# T1: remote + restored repository cache; T2: remote, cold runner; local:
|
||||
# no remote execution (reported, never budgeted).
|
||||
- name: Measurement tier
|
||||
id: tier
|
||||
env:
|
||||
REMOTE: ${{ steps.bazel.outputs.remote }}
|
||||
RESTORED: ${{ steps.bazel.outputs.cache-restored }}
|
||||
run: |
|
||||
if [ "$REMOTE" = "true" ] && [ "$RESTORED" = "true" ]; then tier=T1
|
||||
elif [ "$REMOTE" = "true" ]; then tier=T2
|
||||
else tier=local; fi
|
||||
echo "tier=$tier" >> "$GITHUB_OUTPUT"
|
||||
{
|
||||
echo "### Bazel / test"
|
||||
echo
|
||||
echo "Tier **$tier**: remote execution $REMOTE, runner cache restored $RESTORED."
|
||||
echo
|
||||
} >> "$GITHUB_STEP_SUMMARY"
|
||||
|
||||
# --profile and --build_event_json_file are command options, so they go
|
||||
# after `test` (a startup position fails).
|
||||
- name: bazel test //... --config=ci
|
||||
id: test
|
||||
timeout-minutes: 90
|
||||
run: |
|
||||
set -o pipefail
|
||||
start=$(date +%s)
|
||||
rc=0
|
||||
bazel test //... --config=ci \
|
||||
--profile="$RUNNER_TEMP/bazel-profile.json" \
|
||||
--build_event_json_file="$RUNNER_TEMP/bazel-bep.json" \
|
||||
2>&1 | tee "$RUNNER_TEMP/bazel-test.log" || rc=$?
|
||||
echo "bazel test: exit $rc, $(( $(date +%s) - start ))s wall" | tee -a "$GITHUB_STEP_SUMMARY"
|
||||
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:
|
||||
TIER: ${{ steps.tier.outputs.tier }}
|
||||
run: |
|
||||
budget=()
|
||||
if [ "$TIER" != "local" ]; then budget=(--budget "$BAZEL_BUDGET_SECONDS"); fi
|
||||
python3 tools/bazel/critpath.py "$RUNNER_TEMP/bazel-profile.json" \
|
||||
--tier "$TIER" --log "$RUNNER_TEMP/bazel-test.log" "${budget[@]}"
|
||||
|
||||
# nightly.yml's PR Core `go test -json` on the same commit.
|
||||
- name: Download go-test results
|
||||
if: ${{ always() && inputs.go-test-json-artifact != '' && steps.test.outcome != 'skipped' }}
|
||||
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
|
||||
with:
|
||||
name: ${{ inputs.go-test-json-artifact }}
|
||||
path: ${{ runner.temp }}/go-test-json
|
||||
|
||||
# Fails on any Go test that `go test` runs and Bazel did not (tag filter,
|
||||
# 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
|
||||
env:
|
||||
DETAILS: ${{ inputs.details && '--details' || '' }}
|
||||
GO_TEST_JSON: ${{ inputs.go-test-json-artifact != '' && format('{0}/go-test-json/go-test.json', runner.temp) || '' }}
|
||||
run: |
|
||||
args=()
|
||||
if [ -n "$DETAILS" ]; then args+=("$DETAILS"); fi
|
||||
if [ -n "$GO_TEST_JSON" ]; then args+=(--go-test-json "$GO_TEST_JSON"); fi
|
||||
python3 tools/bazel/equivalence.py --bep "$RUNNER_TEMP/bazel-bep.json" "${args[@]}"
|
||||
|
||||
# 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. 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)
|
||||
# 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"
|
||||
if [ -n "$drift" ]; then
|
||||
echo "::error title=Bazel BUILD files out of sync::run 'make bazel-sync' and commit the result"
|
||||
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' }}
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
|
||||
with:
|
||||
name: bazel-testlogs
|
||||
path: |
|
||||
bazel-testlogs/**/test.log
|
||||
bazel-testlogs/**/test.xml
|
||||
if-no-files-found: ignore
|
||||
retention-days: 7
|
||||
|
||||
# Only a push to main that missed the exact key writes the runner cache.
|
||||
# Its content (--repository_cache and Bazelisk's download, never the rc
|
||||
# or credentials) is fixed by .bazelversion and MODULE.bazel.lock, so one
|
||||
# entry per lock is enough and later pushes do not churn the quota.
|
||||
- name: Save Bazel runner cache
|
||||
if: ${{ always() && github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.bazel.outcome == 'success' && steps.bazel.outputs.cache-hit != 'true' }}
|
||||
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
|
||||
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"
|
||||
46
.github/workflows/docs-autofix.yml
vendored
46
.github/workflows/docs-autofix.yml
vendored
|
|
@ -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
|
||||
|
|
|
|||
13
.github/workflows/main.yml
vendored
13
.github/workflows/main.yml
vendored
|
|
@ -181,7 +181,7 @@ jobs:
|
|||
# is available; the goal here is to catch compile-time contamination,
|
||||
# not run the full suite.
|
||||
run: |
|
||||
go test -tags gms_pure_go -count=1 -short -run '^Test(Help|CheckRemoteSafety|FormatDestroyToken|ShouldWireInitRemote|ExtractPrefix|IsNumericID|GetWorktreeGitDir|DriftItemStatuses|RunDriftChecks|IsServerProbablyRunning|CheckHooksDriftNotGitRepo|CheckServerDriftNoBeadsDir|CheckRemoteDriftNoBeadsDir)' ./cmd/bd
|
||||
go test -tags gms_pure_go -count=1 -short -run '^Test(Help|CheckRemoteSafety|FormatDestroyToken|ShouldWireInitRemote|ExtractPrefix|IsNumericID|GetWorktreeGitDir|DriftItemStatuses|RunDriftChecks|IsServerProbablyRunning|CheckHooksDriftNotGitRepo|CheckServerDriftNoBeadsDir|CheckRemoteDriftNoBeadsDir|NocgoFactoriesHonorSharedServer|NocgoNewDoltStoreFromConfig_ErrorSuggestsCorrectFlag|NocgoNewReadOnlyStoreFromConfig_ErrorSuggestsCorrectFlag)' ./cmd/bd
|
||||
|
||||
# Fast check to ensure all version files are in sync
|
||||
check-version-consistency:
|
||||
|
|
@ -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
|
||||
|
||||
|
|
@ -1226,6 +1226,13 @@ jobs:
|
|||
id: nix_help
|
||||
run: |
|
||||
nix run .#default -- --help > help.txt
|
||||
# Every flake check for the runner's own system (today: hook-timeout-
|
||||
# backends, checks.nix). `nix flake check` rather than a spelled-out
|
||||
# `.#checks.x86_64-linux.<name>`: no hardcoded system, and a check added
|
||||
# to checks.nix is run without a workflow edit.
|
||||
- name: Run the flake checks
|
||||
run: |
|
||||
nix flake check -L
|
||||
- name: Verify help text
|
||||
if: steps.nix_help.outcome == 'success'
|
||||
run: |
|
||||
|
|
|
|||
71
.github/workflows/nightly.yml
vendored
71
.github/workflows/nightly.yml
vendored
|
|
@ -26,6 +26,7 @@ on:
|
|||
- nix
|
||||
- mcp-package
|
||||
- npm-package
|
||||
- bazel
|
||||
smoke_version:
|
||||
description: "Optional previous release for cross-version-smoke"
|
||||
required: false
|
||||
|
|
@ -38,12 +39,80 @@ env:
|
|||
jobs:
|
||||
measure:
|
||||
name: Measure selected CI suite
|
||||
if: ${{ github.event_name == 'workflow_dispatch' && inputs.suite != 'full-test' }}
|
||||
if: ${{ github.event_name == 'workflow_dispatch' && inputs.suite != 'full-test' && inputs.suite != 'bazel' }}
|
||||
uses: ./.github/workflows/ci-measurements.yml
|
||||
with:
|
||||
suite: ${{ inputs.suite }}
|
||||
smoke_version: ${{ inputs.smoke_version }}
|
||||
|
||||
# PR Core's go test (scripts/ci/pr-core.sh) with -json output, so the Bazel
|
||||
# job below can compare per-test status: a test that passes here and skips
|
||||
# under Bazel fails the equivalence check unless allowlisted.
|
||||
bazel-go-test-json:
|
||||
name: Bazel equivalence (go-test side)
|
||||
if: ${{ github.event_name == 'schedule' || inputs.suite == 'bazel' }}
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
|
||||
|
||||
- name: Set up Go
|
||||
id: setup-go
|
||||
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
|
||||
with:
|
||||
go-version-file: 'go.mod'
|
||||
cache: false
|
||||
|
||||
- name: Restore Go module cache
|
||||
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: beads-go-mod-v2-${{ runner.os }}-${{ runner.arch }}-go-${{ steps.setup-go.outputs.go-version }}-${{ hashFiles('go.mod', 'go.sum') }}
|
||||
restore-keys: beads-go-mod-v2-${{ runner.os }}-${{ runner.arch }}-go-${{ steps.setup-go.outputs.go-version }}-
|
||||
|
||||
- name: Install Dolt
|
||||
run: ./scripts/ci/install-dolt.sh
|
||||
|
||||
- name: Configure Git and Dolt identity
|
||||
run: |
|
||||
git config --global user.name "CI Bot"
|
||||
git config --global user.email "ci@beads.test"
|
||||
dolt config --global --add user.name "CI Bot"
|
||||
dolt config --global --add user.email "ci@beads.test"
|
||||
|
||||
- name: Run PR core go-test (JSON)
|
||||
env:
|
||||
BEADS_PR_CORE_GO_TEST_JSON: ${{ runner.temp }}/go-test.json
|
||||
run: make ci-pr-core
|
||||
|
||||
# Uploaded even when tests fail: the status comparison still applies.
|
||||
- name: Upload go-test results
|
||||
if: ${{ always() }}
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
|
||||
with:
|
||||
name: bazel-equivalence-go-test-json
|
||||
path: ${{ runner.temp }}/go-test.json
|
||||
if-no-files-found: error
|
||||
retention-days: 7
|
||||
|
||||
# Bazel lane with the full go test equivalence listing and the skip-parity
|
||||
# check (reported here; PRs gate on it through pr.yml). Remote execution
|
||||
# when the repo secrets are present; bazel.yml gets those four and nothing
|
||||
# else.
|
||||
bazel:
|
||||
name: Bazel equivalence (full detail)
|
||||
needs: bazel-go-test-json
|
||||
if: ${{ !cancelled() && (github.event_name == 'schedule' || inputs.suite == 'bazel') }}
|
||||
uses: ./.github/workflows/bazel.yml
|
||||
secrets:
|
||||
RBE_WEST_EXECUTOR: ${{ secrets.RBE_WEST_EXECUTOR }}
|
||||
RBE_TLS_CERT: ${{ secrets.RBE_TLS_CERT }}
|
||||
RBE_TLS_KEY: ${{ secrets.RBE_TLS_KEY }}
|
||||
RBE_TLS_CA: ${{ secrets.RBE_TLS_CA }}
|
||||
with:
|
||||
details: true
|
||||
go-test-json-artifact: bazel-equivalence-go-test-json
|
||||
|
||||
full-test:
|
||||
name: Full Test Suite
|
||||
if: ${{ github.event_name == 'schedule' || inputs.suite == 'full-test' }}
|
||||
|
|
|
|||
9
.github/workflows/pr-risk.yml
vendored
9
.github/workflows/pr-risk.yml
vendored
|
|
@ -431,6 +431,13 @@ jobs:
|
|||
id: nix_help
|
||||
run: |
|
||||
nix run .#default -- --help > help.txt
|
||||
# Every flake check for the runner's own system (today: hook-timeout-
|
||||
# backends, checks.nix). `nix flake check` rather than a spelled-out
|
||||
# `.#checks.x86_64-linux.<name>`: no hardcoded system, and a check added
|
||||
# to checks.nix is run without a workflow edit.
|
||||
- name: Run the flake checks
|
||||
run: |
|
||||
nix flake check -L
|
||||
- name: Verify help text
|
||||
if: steps.nix_help.outcome == 'success'
|
||||
run: |
|
||||
|
|
@ -445,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
|
||||
|
|
|
|||
133
.github/workflows/pr.yml
vendored
133
.github/workflows/pr.yml
vendored
|
|
@ -251,7 +251,7 @@ jobs:
|
|||
# is available; the goal here is to catch compile-time contamination,
|
||||
# not run the full suite.
|
||||
run: |
|
||||
go test -tags gms_pure_go -count=1 -short -run '^Test(Help|CheckRemoteSafety|FormatDestroyToken|ShouldWireInitRemote|ExtractPrefix|IsNumericID|GetWorktreeGitDir|DriftItemStatuses|RunDriftChecks|IsServerProbablyRunning|CheckHooksDriftNotGitRepo|CheckServerDriftNoBeadsDir|CheckRemoteDriftNoBeadsDir)' ./cmd/bd
|
||||
go test -tags gms_pure_go -count=1 -short -run '^Test(Help|CheckRemoteSafety|FormatDestroyToken|ShouldWireInitRemote|ExtractPrefix|IsNumericID|GetWorktreeGitDir|DriftItemStatuses|RunDriftChecks|IsServerProbablyRunning|CheckHooksDriftNotGitRepo|CheckServerDriftNoBeadsDir|CheckRemoteDriftNoBeadsDir|NocgoFactoriesHonorSharedServer|NocgoNewDoltStoreFromConfig_ErrorSuggestsCorrectFlag|NocgoNewReadOnlyStoreFromConfig_ErrorSuggestsCorrectFlag)' ./cmd/bd
|
||||
|
||||
# The lingering-handle liveness regression test is //go:build windows: the
|
||||
# Ubuntu job above selects it by name but compiles it out, and main.yml's
|
||||
|
|
@ -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
|
||||
|
|
@ -733,6 +746,7 @@ jobs:
|
|||
|
||||
- name: Run PR core wrapper
|
||||
env:
|
||||
BEADS_TEST_REQUIRE_EXCLUDE_PERMISSION: '1'
|
||||
BEADS_TEST_BD_BINARY: ${{ github.workspace }}/ci-build-artifacts/bd-linux-gms-pure
|
||||
GOCACHE: ${{ runner.temp }}/go-cache/race
|
||||
run: make ci-pr-core
|
||||
|
|
@ -876,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
|
||||
|
|
@ -1206,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
|
||||
|
|
@ -1362,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
|
||||
|
|
@ -1388,6 +1485,7 @@ jobs:
|
|||
- fmt-check
|
||||
- lint
|
||||
- windows-make-shell
|
||||
- bazel
|
||||
if: ${{ always() }}
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
|
||||
|
|
@ -1418,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 }}
|
||||
|
|
@ -1440,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
|
||||
|
|
|
|||
11
.github/workflows/proxied-local-smoke.yml
vendored
11
.github/workflows/proxied-local-smoke.yml
vendored
|
|
@ -23,6 +23,8 @@ 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'
|
||||
- 'cmd/bd/db_proxy_child.go'
|
||||
|
|
@ -49,6 +51,8 @@ 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'
|
||||
- 'cmd/bd/db_proxy_child.go'
|
||||
|
|
@ -125,7 +129,12 @@ jobs:
|
|||
TestManagedLocalProxiedDoltStartRefusesOverLiveProxy \
|
||||
TestManagedLocalProxiedDoltStartRefusesWithProxyDown \
|
||||
TestManagedLocalProxiedDoltLifecycleLeavesOtherTopologiesAlone \
|
||||
TestManagedLocalProxiedTrackerUOWConformance
|
||||
TestManagedLocalProxiedTrackerUOWConformance \
|
||||
TestManagedLocalProxiedBackupRoundTrip \
|
||||
TestManagedLocalProxiedAutoBackup \
|
||||
TestManagedLocalProxiedBackupRestoreRefusedWhileAttached \
|
||||
TestManagedLocalProxiedPurgeWispsPlaneRetention \
|
||||
TestManagedLocalProxiedBackendCleanExitRetiresProxy
|
||||
do
|
||||
if ! grep -qx "$test_name" <<<"$listed"; then
|
||||
echo "managed-local lifecycle test $test_name is missing; got: '$listed'" >&2
|
||||
|
|
|
|||
16
.github/workflows/regression.yml
vendored
16
.github/workflows/regression.yml
vendored
|
|
@ -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/...
|
||||
|
|
|
|||
6
.gitignore
vendored
6
.gitignore
vendored
|
|
@ -255,3 +255,9 @@ tmp/build/cli-docs/where.md
|
|||
tmp/build/cli-docs/worktree.md
|
||||
tmp/docs/CLI_REFERENCE.md
|
||||
*.gate.lock*
|
||||
|
||||
# Bazel: output symlinks and machine-local rc files (remote executor endpoint,
|
||||
# TLS credentials). Never commit these.
|
||||
/bazel-*
|
||||
/.bazelrc.local
|
||||
/user.bazelrc
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
178
BUILD.bazel
Normal file
178
BUILD.bazel
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
load("@gazelle//:def.bzl", "gazelle")
|
||||
load("@rules_go//go:def.bzl", "go_library", "go_test")
|
||||
|
||||
# gazelle:prefix github.com/steveyegge/beads
|
||||
# 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
|
||||
gazelle(name = "gazelle")
|
||||
|
||||
exports_files([
|
||||
"go.mod",
|
||||
"go.sum",
|
||||
])
|
||||
|
||||
# Repository files read by source-scanning tests, declared as their `data` so
|
||||
# the tests run under `bazel test` and remote execution.
|
||||
exports_files(
|
||||
[".gitattributes"],
|
||||
visibility = ["//scripts/gitattributespolicy:__pkg__"],
|
||||
)
|
||||
|
||||
# //cmd/bd:bd_test: tracked git hooks (generator parity) and the formula
|
||||
# primitive fixtures.
|
||||
filegroup(
|
||||
name = "bd_test_files",
|
||||
srcs = glob([
|
||||
".githooks/*",
|
||||
"examples/formulas/primitives/**",
|
||||
]),
|
||||
visibility = ["//cmd/bd:__pkg__"],
|
||||
)
|
||||
|
||||
exports_files(
|
||||
[".claude-plugin/marketplace.json"],
|
||||
visibility = ["//cmd/bd/setup:__pkg__"],
|
||||
)
|
||||
|
||||
# //test/docsync: the Mintlify site, engdocs, root markdown, and the files
|
||||
# outside those trees that their local links point at.
|
||||
#
|
||||
# The out-of-tree link targets are hand-listed: a new docs/engdocs link to a
|
||||
# file outside these globs passes `go test` but fails under Bazel until the
|
||||
# target is added here. The globs stop at package boundaries, so no BUILD file
|
||||
# may live under docs/ or engdocs/ (enforced by scripts/bazel_policy_test.go).
|
||||
filegroup(
|
||||
name = "docsync_files",
|
||||
srcs = glob([
|
||||
"*.md",
|
||||
"docs/**",
|
||||
"engdocs/**",
|
||||
]) + [
|
||||
"integrations/beads-mcp/PYPI.md",
|
||||
"//scripts:README.md",
|
||||
],
|
||||
visibility = ["//test/docsync:__pkg__"],
|
||||
)
|
||||
|
||||
# //scripts:scripts_test workflow-policy and CI-script tests: the whole
|
||||
# .github tree (workflows, composite actions, CI helper scripts) they parse
|
||||
# and run. The one whole-tree input the plan allows (it is small).
|
||||
filegroup(
|
||||
name = "workflow_files",
|
||||
srcs = glob([".github/**"]),
|
||||
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(
|
||||
name = "test_sh_files",
|
||||
srcs = [
|
||||
".buildflags",
|
||||
".test-skip",
|
||||
],
|
||||
visibility = ["//scripts:__pkg__"],
|
||||
)
|
||||
|
||||
# Inputs of the Bazel policy tests in //scripts (bazel_policy_test.go), so they
|
||||
# run under `bazel test` as well as `go test`.
|
||||
filegroup(
|
||||
name = "bazel_policy_files",
|
||||
srcs = [
|
||||
".bazelrc",
|
||||
".bazelversion",
|
||||
".gitignore",
|
||||
"BUILD.bazel",
|
||||
"MODULE.bazel",
|
||||
"go.mod",
|
||||
],
|
||||
visibility = ["//scripts:__pkg__"],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "beads",
|
||||
srcs = [
|
||||
"beads.go",
|
||||
"beads_cgo.go",
|
||||
"beads_nocgo.go",
|
||||
"claim.go",
|
||||
],
|
||||
importpath = "github.com/steveyegge/beads",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//internal/beads",
|
||||
"//internal/configfile",
|
||||
"//internal/doltserver",
|
||||
"//internal/storage",
|
||||
"//internal/storage/backends",
|
||||
"//internal/storage/dolt",
|
||||
"//internal/storage/domain",
|
||||
"//internal/storage/embeddeddolt",
|
||||
"//internal/storage/schema",
|
||||
"//internal/types",
|
||||
"//internal/workspacegate",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "beads_test",
|
||||
srcs = [
|
||||
"beads_gated_test.go",
|
||||
"beads_test.go",
|
||||
"claim_roundtrip_test.go",
|
||||
"claim_test.go",
|
||||
"errors_test.go",
|
||||
"export_dependency_add_options_test.go",
|
||||
"issue_lifecycle_external_test.go",
|
||||
"issue_roles_external_test.go",
|
||||
"open_backend_selection_test.go",
|
||||
"open_nocgo_test.go",
|
||||
"query_interfaces_cgo_test.go",
|
||||
"query_interfaces_test.go",
|
||||
],
|
||||
embed = [":beads"],
|
||||
deps = [
|
||||
"//internal/hooks",
|
||||
"//internal/storage",
|
||||
"//internal/storage/backends",
|
||||
"//internal/storage/dolt",
|
||||
"//internal/storage/domain",
|
||||
"//internal/storage/embeddeddolt",
|
||||
"//internal/telemetry",
|
||||
"//internal/testutil",
|
||||
"//internal/types",
|
||||
"//internal/workspacegate",
|
||||
"//issueops",
|
||||
],
|
||||
)
|
||||
377
CHANGELOG.md
377
CHANGELOG.md
|
|
@ -9,6 +9,191 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Fixed
|
||||
|
||||
- **`bd doctor` no longer flags a `.local_version` that starts with `v`.** The
|
||||
canonical spelling of a Go module version — and the string a build stamped
|
||||
from a Go pseudo-version reports and writes into `.local_version` itself —
|
||||
was rejected by the Version Tracking check (`Invalid version format`), and
|
||||
read as major 0 in version comparisons, because the helpers parsed digits
|
||||
first. They now accept an optional leading `v`; versions without it are
|
||||
unchanged ([#6152](https://github.com/gastownhall/beads/issues/6152)).
|
||||
|
||||
- **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".
|
||||
|
||||
- **`bd` refuses a bare tooling sentinel (`null`, `undefined`, an empty string)
|
||||
as an issue ID** ([#6214](https://github.com/gastownhall/beads/issues/6214)).
|
||||
`jq -r` prints the literal `null` when a selector misses and JS tooling prints
|
||||
`undefined`, so `bd update "$(bd list --json | jq -r '.[0].id')" --status
|
||||
closed` arrived at ID resolution as a plain four-character token. Those tokens
|
||||
are a valid partial-ID shape, so they reached the leading-prefix abbreviation
|
||||
branch and resolved to whichever issue's hash began with them — closing an
|
||||
issue the caller never named and exiting 0 with a success line. `bd update
|
||||
null`, `bd comment null` and every other command that resolves an ID now fail
|
||||
before any lookup, because the guard sits in the shared resolver. An ID that
|
||||
merely contains a token (`bd-null`, `null3t0`, `undefined-behavior`) still
|
||||
resolves, and abbreviation matching is otherwise unchanged. The empty string
|
||||
already failed; it now says why.
|
||||
|
||||
- **`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
|
||||
`bd config set notion.token` — the command `bd notion status` recommends —
|
||||
wrote it to the database, whose contents `bd dolt push` sends to the remote.
|
||||
It is now written to `config.yaml` like `github.token`, `gitlab.token` and
|
||||
the other tracker secrets, and refused on a git-tracked `config.yaml` with a
|
||||
pointer to `NOTION_TOKEN`. A token an older bd already stored in the database
|
||||
is still read, after `config.yaml` and before `NOTION_TOKEN`, so existing
|
||||
setups keep authenticating. `bd config unset notion.token` removes both
|
||||
copies — the `config.yaml` entry and any row an older bd left in the database
|
||||
— and reports which of them it actually removed; that cleanup covers every
|
||||
yaml-only secret key, not just this one. The database half is best effort and
|
||||
says so: it is skipped only where reaching the row would mean creating a
|
||||
database (the command never creates one), so it still runs for a server-mode
|
||||
or proxied workspace whose database is simply not on local disk, and it is
|
||||
attempted even when the `config.yaml` edit fails, so a workspace whose only
|
||||
copy is the stored row still has a remover. `bd notion status` now reports the
|
||||
auth source as `database_legacy` rather than `config_token` while the stored
|
||||
row is the one authenticating, so an affected workspace can identify itself.
|
||||
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
|
||||
surfaces still described wherever the command was launched: the clone-local
|
||||
`.beads/PRIME.md` tier, the AGENTS.md/CLAUDE.md divergence reminder, the git
|
||||
upstream/remote probes behind the template's git-authority wording, and the
|
||||
redirect notice. All four now resolve against the `-C` target, matching
|
||||
`cd dir && bd prime`; without `-C` the behavior is byte-for-byte unchanged.
|
||||
|
||||
Note for `-C` users: the git-remote probe prime shares with auto-backup
|
||||
(`isBackupAutoEnabled`) follows the same change, so under
|
||||
`bd -C dir <any command>` auto-backup enablement and the `bd backup status`
|
||||
note are now decided by the `-C` target's git remote rather than the launch
|
||||
directory's. That makes the probe agree with the store actually being backed
|
||||
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
|
||||
GNU coreutils banner, so a host whose `timeout` is uutils coreutils
|
||||
(Ubuntu 25.10+, or a distribution configured with `uutils-coreutils` in place
|
||||
of GNU) failed the probe and fell through. Where Perl was
|
||||
installed the shim still got a deadline from the Perl `alarm` arm — which Git
|
||||
for Windows Perl does not guarantee across `exec` — so the missing deadline
|
||||
bit uutils hosts *without* Perl, which ran `bd hooks run` unbounded (with the
|
||||
documented warning). The probe now also accepts the
|
||||
`timeout (uutils coreutils) ` banner; native Windows `timeout.exe` stays
|
||||
rejected ([#5503](https://github.com/gastownhall/beads/issues/5503)). The
|
||||
widened probe ships in the generated hook section, which is rewritten only by
|
||||
`bd hooks install` — hosts that already installed hooks must run it once to
|
||||
pick up the fix.
|
||||
|
||||
- **`bd close` now exits non-zero when any issue in a batch fails to close**
|
||||
([#6648](https://github.com/gastownhall/beads/issues/6648)). A batch with one
|
||||
refused id used to exit 0 as long as another id closed, so scripts could not
|
||||
|
|
@ -21,11 +206,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
close runs, while the proxied route refuses that argument and closes the
|
||||
rest.) In `--json` mode the summary is instead a compact JSON line on stderr
|
||||
naming the failed ids, matching `bd update`'s partial-failure report, while
|
||||
stdout keeps the usual closed-issues array. `--claim-next` still claims when
|
||||
stdout keeps the usual closed-issues array. Each `failed[]` entry carries the
|
||||
refusal as the engine worded it, identically on both routes; the `--force`
|
||||
hint and the route's own framing stay on the human-readable stderr line, which
|
||||
is unchanged. `--claim-next` still claims when
|
||||
part of the batch closed — the claim commits inside the batch's own
|
||||
transaction and a sibling's refusal does not roll it back — so the summary
|
||||
names the claimed id rather than leaving it silently assigned.
|
||||
|
||||
- Unblocking two blockers of one dependent at the same time — closing both,
|
||||
or a close racing a `bd dep remove` or a delete of the other — no longer
|
||||
leaves the dependent stuck as blocked and hidden from `bd ready` until
|
||||
`bd recompute-blocked`: a write that takes a blocker away (a close, an
|
||||
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)). 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
|
||||
format** ([#6277](https://github.com/gastownhall/beads/issues/6277)).
|
||||
`--watch` always re-renders the pretty listing, so on the direct route a
|
||||
|
|
@ -114,8 +314,71 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
`--format` now wins over the config default; an explicit `--json` still wins
|
||||
over `--format`.
|
||||
|
||||
- **Strict readonly no longer records last-touched state**
|
||||
([#5785](https://github.com/gastownhall/beads/issues/5785)). Under strict
|
||||
readonly (`--readonly`, or `readonly` in config), `bd show` wrote the issue
|
||||
id to `.beads/last-touched` even though readonly promises not to mutate
|
||||
workspace-local state — the database store was opened read-only while this
|
||||
marker file was still written. `SetLastTouchedID` now returns early in that
|
||||
mode, so a readonly workspace leaves the marker untouched. Ordinary
|
||||
(non-readonly) `bd show` keeps recording last-touched exactly as before, so
|
||||
only consumers driving `bd --readonly … --json` see the change.
|
||||
|
||||
### 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:
|
||||
- **Live-dependent protection, always on.** `bd purge` no longer deletes a
|
||||
closed bead that a live bead depends on through a `parent-child`,
|
||||
`tracks` or `blocks` edge — a closed molecule root whose step is still
|
||||
open, a closed wisp a live convoy tracks, a closed blocker of live work.
|
||||
"Live" is any status that is not done, including custom statuses. The
|
||||
held-back count is reported as `live_dependent_skipped` in `--json` (and
|
||||
on its own line in text output). The protection is on the role
|
||||
(`issueops.SweepRequest.ProtectLiveDependents`); `bd prune` does not ask
|
||||
for it.
|
||||
- **`--wisps-plane`** selects every closed row stored in the wisps table,
|
||||
including `--no-history` beads, which the default ephemeral selection
|
||||
leaves to `bd prune`. It works on embedded, server and proxied
|
||||
workspaces, and because it reaches durable-tier rows it requires
|
||||
`--older-than` or `--pattern`, like `bd prune`
|
||||
(`issueops.SweepWispsPlane`).
|
||||
- **`--older-than` accepts hour and finer durations** (`36h`, `168h`,
|
||||
`90m`, down to `1s`) on both `bd purge` and `bd prune`. Day values (`7`,
|
||||
`7d`, `2w`) are unchanged. An `Nh` value used to be converted to whole
|
||||
days: floored above a day (`36h` swept rows only 24 hours old) and
|
||||
rounded UP to one day below it (`12h` kept everything younger than 24
|
||||
hours). Both are now taken exactly, so `bd prune --older-than 12h` now
|
||||
deletes rows closed 12–24 hours ago that it used to keep. A value too
|
||||
large to represent (e.g. `213504d`) is now refused instead of silently
|
||||
wrapping to a tiny age.
|
||||
- **`--limit N`** caps one `bd purge` run at N beads, oldest-closed first
|
||||
(`issueops.SweepRequest.Limit`), so a large backlog drains in bounded
|
||||
transactions; `--json` then adds `remaining` and `has_more`. Loop while
|
||||
`has_more` is true.
|
||||
|
||||
- **`bd backup` works on a proxied-server workspace bd runs the Dolt server
|
||||
for.** `bd backup init`, `sync`, `remove`, `status` and `restore` are routed
|
||||
over the proxied provider; before this, a proxied workspace — the default
|
||||
|
|
@ -146,10 +409,63 @@ 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` accepts `--has-metadata-key`**
|
||||
([#6160](https://github.com/gastownhall/beads/issues/6160)), closing the last
|
||||
metadata-filter gap against `bd list`, `bd ready` and `bd search`. A caller
|
||||
counting rows that merely carry a key no longer has to list them and measure
|
||||
the page.
|
||||
|
||||
- **`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
|
||||
row.
|
||||
- **`bd label rename <old> <new>` fixes a label everywhere it appears, in one
|
||||
command instead of a per-issue add-then-remove loop**
|
||||
([#6009](https://github.com/gastownhall/beads/pull/6009)). An issue that
|
||||
already carries the new label doesn't error — the rename drops its stale
|
||||
old label and counts the issue as a merge instead, reported honestly:
|
||||
`Renamed label 'Backend' to 'backend': 6 issues (2 already had 'backend')`.
|
||||
A label nothing carries is a clean no-op (`No issues found with label
|
||||
'Backend'`, exit 0). The sweep covers both planes, durable issues and
|
||||
wisps, and the direct and proxied-server routes end at the same
|
||||
`issueops.RenameLabelInTx` primitive — the proxied route journals through
|
||||
`domain.LabelUseCase.RenameLabel` rather than a per-issue add+remove
|
||||
fan-out, so merge semantics, the zero-carrier no-op, and the single
|
||||
`label_renamed` event per touched row are identical on both.
|
||||
|
||||
`--dry-run` previews the blast radius (a count and the first 10 issues,
|
||||
all of them under `--json`) without writing anything, through a read-only
|
||||
path kept apart from the write path so a preview can never reach a
|
||||
transaction. Its `merged` count is a plain snapshot intersection of two
|
||||
independent reads, though, not the write path's measured one: the real
|
||||
rename derives `merged` from what its `INSERT IGNORE` actually affected,
|
||||
specifically so a concurrent label add between two reads can't skew the
|
||||
count, and the preview has no insert to measure against. Treat the
|
||||
dry-run number as an estimate — the flag's own help text says so now too.
|
||||
A rename that fails partway through reports an UPPER BOUND - up to how many
|
||||
issues may have been renamed, and up to how many of those were merges -
|
||||
rather than only the error. It cannot be a landed count: both routes assign
|
||||
those numbers inside the transaction, so a rollback or an exhausted retry
|
||||
returns them still describing an attempt that landed nothing. Only a Dolt
|
||||
publication failure after the SQL side already committed is a genuine
|
||||
partial, and the count alone cannot tell the two apart.
|
||||
|
||||
|
||||
### Fixed
|
||||
|
||||
|
|
@ -236,6 +552,65 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Changed
|
||||
|
||||
- **A formula with a `waits_for` gate and no spawner to wait for is now
|
||||
rejected, and an invalid formula is no longer reported as not found.** A gate
|
||||
step infers its spawner from `needs[0]`, so with nothing to infer from,
|
||||
cooking stamped the `gate:<value>` label and emitted no dependency edge at
|
||||
all - a gate bead that never blocks and never resolves. `bd create` already
|
||||
refused `--waits-for-gate` without `--waits-for`; the formula path was the
|
||||
outlier. `Formula.Validate` now enforces the same rule. Separately, a
|
||||
validation failure is distinguishable from "this name is not a formula":
|
||||
callers that fall back to a proto/issue lookup previously swallowed the real
|
||||
error and reported `not found as issue or formula`, so an invalid formula
|
||||
looked like a typo. `bd mol bond --dry-run` also resolves through
|
||||
`parser.Resolve` now, so it resolves and validates the same way the real
|
||||
bond does rather than previewing a bond that then errors on those checks.
|
||||
Later cook transforms (inline expansions, expansions, aspects and
|
||||
condition filtering) are still only exercised by the real bond.
|
||||
|
||||
- **`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 mol bond --ref` no longer deadlocks the molecule it bonds into, and no
|
||||
longer accepts `--type conditional`.** A `--ref` arm is nested inside its
|
||||
target and its hierarchical ID records that, so an ordering edge onto the
|
||||
target was unsatisfiable in both directions: the arm waited for the molecule
|
||||
to close, and the molecule could not close while it held an open arm. `bd
|
||||
ready` went empty with nothing to point at. For a sequential bond (the
|
||||
default) that edge is now dropped, so the arm carries **no ordering** and is
|
||||
ready as soon as it is spawned - containment is a nested arm's only
|
||||
satisfiable relationship to its container. A conditional edge has no such
|
||||
degradation: it means "run only if the target fails", so dropping it would
|
||||
run the arm unconditionally, turning a deadlock into a silent false dispatch.
|
||||
`--ref` with `--type conditional` is therefore refused outright (including
|
||||
under `--dry-run` and on the proxied route); omit `--ref` to bond a
|
||||
conditional arm as a sibling, which is satisfiable and keeps its edge.
|
||||
|
||||
- **`bd mol ready --gated` prints a dispatch command that exists.** The hint
|
||||
named `bd sling`, which has never been a command in this binary, so the one
|
||||
actionable line in the output could not be run. It now prints `bd assign
|
||||
<ready-step-id> <agent>`, and says which listed molecule the example belongs
|
||||
to when more than one is waiting.
|
||||
|
||||
- **`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
|
||||
purge that used to delete a closed molecule root under a live step now
|
||||
leaves it. See the `--wisps-plane` entry under Added.
|
||||
|
||||
- **Proxied-server refusals now say *why* they refuse.** The JSON a refused
|
||||
command prints gains a `reason` field next to the existing `code`, `error`
|
||||
and `mutates`: `design` for a refusal that is expected to stay (shared
|
||||
|
|
|
|||
78
MODULE.bazel
Normal file
78
MODULE.bazel
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
module(
|
||||
name = "beads",
|
||||
version = "0.0.0",
|
||||
)
|
||||
|
||||
bazel_dep(name = "platforms", version = "1.1.0")
|
||||
bazel_dep(name = "rules_go", version = "0.63.0")
|
||||
bazel_dep(name = "gazelle", version = "0.53.0")
|
||||
bazel_dep(name = "rules_shell", version = "0.6.1")
|
||||
|
||||
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
|
||||
go_sdk.download(
|
||||
name = "go_sdk",
|
||||
version = "1.26.7",
|
||||
)
|
||||
use_repo(go_sdk, "go_sdk")
|
||||
|
||||
go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
|
||||
go_deps.from_file(go_mod = "//:go.mod")
|
||||
|
||||
# beads builds go-mysql-server with its stdlib-regex backend (ICU policy):
|
||||
# gazelle must see gms_pure_go as satisfied so it selects regex_pure.go and
|
||||
# drops the go-icu-regex (libicu, cgo) edge entirely.
|
||||
go_deps.gazelle_override(
|
||||
directives = [
|
||||
"gazelle:build_tags gms_pure_go",
|
||||
"gazelle:exclude internal/regex/regex_cgo.go",
|
||||
],
|
||||
path = "github.com/dolthub/go-mysql-server",
|
||||
)
|
||||
go_deps.module_override(
|
||||
patch_strip = 1,
|
||||
patches = ["//third_party/patches:eventsapi_schema_build.patch"],
|
||||
path = "github.com/dolthub/eventsapi_schema",
|
||||
)
|
||||
go_deps.module_override(
|
||||
patch_strip = 1,
|
||||
patches = ["//third_party/patches:flatbuffers_v23_importpath.patch"],
|
||||
path = "github.com/dolthub/flatbuffers/v23",
|
||||
)
|
||||
go_deps.module_override(
|
||||
patch_strip = 1,
|
||||
patches = ["//third_party/patches:dolt_go_serial.patch"],
|
||||
path = "github.com/dolthub/dolt/go",
|
||||
)
|
||||
|
||||
# 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
|
||||
# the execution platform, so only that tarball is downloaded.
|
||||
dolt_release = use_repo_rule("//tools/bazel:dolt.bzl", "dolt_release")
|
||||
|
||||
dolt_release(
|
||||
name = "dolt_linux_amd64",
|
||||
platform = "linux-amd64",
|
||||
)
|
||||
|
||||
dolt_release(
|
||||
name = "dolt_linux_arm64",
|
||||
platform = "linux-arm64",
|
||||
)
|
||||
|
||||
dolt_release(
|
||||
name = "dolt_darwin_amd64",
|
||||
platform = "darwin-amd64",
|
||||
)
|
||||
|
||||
dolt_release(
|
||||
name = "dolt_darwin_arm64",
|
||||
platform = "darwin-arm64",
|
||||
)
|
||||
820
MODULE.bazel.lock
generated
Normal file
820
MODULE.bazel.lock
generated
Normal file
|
|
@ -0,0 +1,820 @@
|
|||
{
|
||||
"lockFileVersion": 28,
|
||||
"registryFileHashes": {
|
||||
"https://bcr.bazel.build/bazel_registry.json": "8a28e4aff06ee60aed2a8c281907fb8bcbf3b753c91fb5a5c57da3215d5b3497",
|
||||
"https://bcr.bazel.build/modules/abseil-cpp/20210324.2/MODULE.bazel": "7cd0312e064fde87c8d1cd79ba06c876bd23630c83466e9500321be55c96ace2",
|
||||
"https://bcr.bazel.build/modules/abseil-cpp/20211102.0/MODULE.bazel": "70390338f7a5106231d20620712f7cccb659cd0e9d073d1991c038eb9fc57589",
|
||||
"https://bcr.bazel.build/modules/abseil-cpp/20230125.1/MODULE.bazel": "89047429cb0207707b2dface14ba7f8df85273d484c2572755be4bab7ce9c3a0",
|
||||
"https://bcr.bazel.build/modules/abseil-cpp/20230802.0.bcr.1/MODULE.bazel": "1c8cec495288dccd14fdae6e3f95f772c1c91857047a098fad772034264cc8cb",
|
||||
"https://bcr.bazel.build/modules/abseil-cpp/20230802.0/MODULE.bazel": "d253ae36a8bd9ee3c5955384096ccb6baf16a1b1e93e858370da0a3b94f77c16",
|
||||
"https://bcr.bazel.build/modules/abseil-cpp/20230802.1/MODULE.bazel": "fa92e2eb41a04df73cdabeec37107316f7e5272650f81d6cc096418fe647b915",
|
||||
"https://bcr.bazel.build/modules/abseil-cpp/20240116.1/MODULE.bazel": "37bcdb4440fbb61df6a1c296ae01b327f19e9bb521f9b8e26ec854b6f97309ed",
|
||||
"https://bcr.bazel.build/modules/abseil-cpp/20240116.2/MODULE.bazel": "73939767a4686cd9a520d16af5ab440071ed75cec1a876bf2fcfaf1f71987a16",
|
||||
"https://bcr.bazel.build/modules/abseil-cpp/20250127.1/MODULE.bazel": "c4a89e7ceb9bf1e25cf84a9f830ff6b817b72874088bf5141b314726e46a57c1",
|
||||
"https://bcr.bazel.build/modules/abseil-cpp/20250512.1/MODULE.bazel": "d209fdb6f36ffaf61c509fcc81b19e81b411a999a934a032e10cd009a0226215",
|
||||
"https://bcr.bazel.build/modules/abseil-cpp/20250814.1/MODULE.bazel": "51f2312901470cdab0dbdf3b88c40cd21c62a7ed58a3de45b365ddc5b11bcab2",
|
||||
"https://bcr.bazel.build/modules/abseil-cpp/20250814.1/source.json": "cea3901d7e299da7320700abbaafe57a65d039f10d0d7ea601c4a66938ea4b0c",
|
||||
"https://bcr.bazel.build/modules/apple_support/1.11.1/MODULE.bazel": "1843d7cd8a58369a444fc6000e7304425fba600ff641592161d9f15b179fb896",
|
||||
"https://bcr.bazel.build/modules/apple_support/1.15.1/MODULE.bazel": "a0556fefca0b1bb2de8567b8827518f94db6a6e7e7d632b4c48dc5f865bc7c85",
|
||||
"https://bcr.bazel.build/modules/apple_support/1.21.0/MODULE.bazel": "ac1824ed5edf17dee2fdd4927ada30c9f8c3b520be1b5fd02a5da15bc10bff3e",
|
||||
"https://bcr.bazel.build/modules/apple_support/1.21.1/MODULE.bazel": "5809fa3efab15d1f3c3c635af6974044bac8a4919c62238cce06acee8a8c11f1",
|
||||
"https://bcr.bazel.build/modules/apple_support/1.24.2/MODULE.bazel": "0e62471818affb9f0b26f128831d5c40b074d32e6dda5a0d3852847215a41ca4",
|
||||
"https://bcr.bazel.build/modules/apple_support/1.24.2/source.json": "2c22c9827093250406c5568da6c54e6fdf0ef06238def3d99c71b12feb057a8d",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.1.0/MODULE.bazel": "cfd42ff3b815a5f39554d97182657f8c4b9719568eb7fded2b9135f084bf760b",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.1.1/MODULE.bazel": "27b8c79ef57efe08efccbd9dd6ef70d61b4798320b8d3c134fd571f78963dbcd",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.10.0/MODULE.bazel": "f75e8807570484a99be90abcd52b5e1f390362c258bcb73106f4544957a48101",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.11.0/MODULE.bazel": "f9382337dd5a474c3b7d334c2f83e50b6eaedc284253334cf823044a26de03e8",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.15.0/MODULE.bazel": "d38ff6e517149dc509406aca0db3ad1efdd890a85e049585b7234d04238e2a4d",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.17.0/MODULE.bazel": "039de32d21b816b47bd42c778e0454217e9c9caac4a3cf8e15c7231ee3ddee4d",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.18.0/MODULE.bazel": "1be0ae2557ab3a72a57aeb31b29be347bcdc5d2b1eb1e70f39e3851a7e97041a",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.19.0/MODULE.bazel": "59adcdf28230d220f0067b1f435b8537dd033bfff8db21335ef9217919c7fb58",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.21.0/MODULE.bazel": "675642261665d8eea09989aa3b8afb5c37627f1be178382c320d1b46afba5e3b",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.23.0/MODULE.bazel": "fd1ac84bc4e97a5a0816b7fd7d4d4f6d837b0047cf4cbd81652d616af3a6591a",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.27.0/MODULE.bazel": "621eeee06c4458a9121d1f104efb80f39d34deff4984e778359c60eaf1a8cb65",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.28.0/MODULE.bazel": "4b4200e6cbf8fa335b2c3f43e1d6ef3e240319c33d43d60cc0fbd4b87ece299d",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.3.0/MODULE.bazel": "cdcafe83ec318cda34e02948e81d790aab8df7a929cec6f6969f13a489ccecd9",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.30.0/MODULE.bazel": "a14b62d05969a293b80257e72e597c2da7f717e1e69fa8b339703ed6731bec87",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.33.0/MODULE.bazel": "8b8dc9d2a4c88609409c3191165bccec0e4cb044cd7a72ccbe826583303459f6",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.36.0/MODULE.bazel": "596cb62090b039caf1cad1d52a8bc35cf188ca9a4e279a828005e7ee49a1bec3",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.4.1/MODULE.bazel": "e45b6bb2350aff3e442ae1111c555e27eac1d915e77775f6fdc4b351b758b5d7",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.42.1/MODULE.bazel": "275a59b5406ff18c01739860aa70ad7ccb3cfb474579411decca11c93b951080",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.42.1/source.json": "fcd4396b2df85f64f2b3bb436ad870793ecf39180f1d796f913cc9276d355309",
|
||||
"https://bcr.bazel.build/modules/bazel_features/1.9.1/MODULE.bazel": "8f679097876a9b609ad1f60249c49d68bfab783dd9be012faf9d82547b14815a",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.0.3/MODULE.bazel": "bcb0fd896384802d1ad283b4e4eb4d718eebd8cb820b0a2c3a347fb971afd9d8",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.1.1/MODULE.bazel": "1add3e7d93ff2e6998f9e118022c84d163917d912f5afafb3058e3d2f1545b5e",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.2.0/MODULE.bazel": "44fe84260e454ed94ad326352a698422dbe372b21a1ac9f3eab76eb531223686",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.2.1/MODULE.bazel": "f35baf9da0efe45fa3da1696ae906eea3d615ad41e2e3def4aeb4e8bc0ef9a7a",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.3.0/MODULE.bazel": "20228b92868bf5cfc41bda7afc8a8ba2a543201851de39d990ec957b513579c5",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.4.1/MODULE.bazel": "a0dcb779424be33100dcae821e9e27e4f2901d9dfd5333efe5ac6a8d7ab75e1d",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.4.2/MODULE.bazel": "3bd40978e7a1fac911d5989e6b09d8f64921865a45822d8b09e815eaa726a651",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.5.0/MODULE.bazel": "32880f5e2945ce6a03d1fbd588e9198c0a959bb42297b2cfaf1685b7bc32e138",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.6.1/MODULE.bazel": "8fdee2dbaace6c252131c00e1de4b165dc65af02ea278476187765e1a617b917",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.7.0/MODULE.bazel": "0db596f4563de7938de764cc8deeabec291f55e8ec15299718b93c4423e9796d",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.7.1/MODULE.bazel": "3120d80c5861aa616222ec015332e5f8d3171e062e3e804a2a0253e1be26e59b",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.8.1/MODULE.bazel": "88ade7293becda963e0e3ea33e7d54d3425127e0a326e0d17da085a5f1f03ff6",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.8.2/MODULE.bazel": "69ad6927098316848b34a9142bcc975e018ba27f08c4ff403f50c1b6e646ca67",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.8.2/source.json": "34a3c8bcf233b835eb74be9d628899bb32999d3e0eadef1947a0a562a2b16ffb",
|
||||
"https://bcr.bazel.build/modules/buildozer/8.5.1/MODULE.bazel": "a35d9561b3fc5b18797c330793e99e3b834a473d5fbd3d7d7634aafc9bdb6f8f",
|
||||
"https://bcr.bazel.build/modules/buildozer/8.5.1/source.json": "e3386e6ff4529f2442800dee47ad28d3e6487f36a1f75ae39ae56c70f0cd2fbd",
|
||||
"https://bcr.bazel.build/modules/gazelle/0.32.0/MODULE.bazel": "b499f58a5d0d3537f3cf5b76d8ada18242f64ec474d8391247438bf04f58c7b8",
|
||||
"https://bcr.bazel.build/modules/gazelle/0.33.0/MODULE.bazel": "a13a0f279b462b784fb8dd52a4074526c4a2afe70e114c7d09066097a46b3350",
|
||||
"https://bcr.bazel.build/modules/gazelle/0.34.0/MODULE.bazel": "abdd8ce4d70978933209db92e436deb3a8b737859e9354fb5fd11fb5c2004c8a",
|
||||
"https://bcr.bazel.build/modules/gazelle/0.36.0/MODULE.bazel": "e375d5d6e9a6ca59b0cb38b0540bc9a05b6aa926d322f2de268ad267a2ee74c0",
|
||||
"https://bcr.bazel.build/modules/gazelle/0.51.3/MODULE.bazel": "618a729142f66de1e2cb776d026413763be5b80d5e3d29ffb9d3d90c5defde90",
|
||||
"https://bcr.bazel.build/modules/gazelle/0.53.0/MODULE.bazel": "76158efbaf12e35ae17af02f4a715bc6e7b3b410c693d34f422922ff4a56a925",
|
||||
"https://bcr.bazel.build/modules/gazelle/0.53.0/source.json": "1f5a4dd0399e5a20e0daeaa3ba1f42391a1b909bc3d337f7a62d3216ddbdfad0",
|
||||
"https://bcr.bazel.build/modules/google_benchmark/1.8.2/MODULE.bazel": "a70cf1bba851000ba93b58ae2f6d76490a9feb74192e57ab8e8ff13c34ec50cb",
|
||||
"https://bcr.bazel.build/modules/googletest/1.11.0/MODULE.bazel": "3a83f095183f66345ca86aa13c58b59f9f94a2f81999c093d4eeaa2d262d12f4",
|
||||
"https://bcr.bazel.build/modules/googletest/1.14.0.bcr.1/MODULE.bazel": "22c31a561553727960057361aa33bf20fb2e98584bc4fec007906e27053f80c6",
|
||||
"https://bcr.bazel.build/modules/googletest/1.14.0/MODULE.bazel": "cfbcbf3e6eac06ef9d85900f64424708cc08687d1b527f0ef65aa7517af8118f",
|
||||
"https://bcr.bazel.build/modules/googletest/1.15.2/MODULE.bazel": "6de1edc1d26cafb0ea1a6ab3f4d4192d91a312fd2d360b63adaa213cd00b2108",
|
||||
"https://bcr.bazel.build/modules/googletest/1.17.0/MODULE.bazel": "dbec758171594a705933a29fcf69293d2468c49ec1f2ebca65c36f504d72df46",
|
||||
"https://bcr.bazel.build/modules/googletest/1.17.0/source.json": "38e4454b25fc30f15439c0378e57909ab1fd0a443158aa35aec685da727cd713",
|
||||
"https://bcr.bazel.build/modules/jsoncpp/1.9.5/MODULE.bazel": "31271aedc59e815656f5736f282bb7509a97c7ecb43e927ac1a37966e0578075",
|
||||
"https://bcr.bazel.build/modules/jsoncpp/1.9.6/MODULE.bazel": "2f8d20d3b7d54143213c4dfc3d98225c42de7d666011528dc8fe91591e2e17b0",
|
||||
"https://bcr.bazel.build/modules/jsoncpp/1.9.6/source.json": "a04756d367a2126c3541682864ecec52f92cdee80a35735a3cb249ce015ca000",
|
||||
"https://bcr.bazel.build/modules/libpfm/4.11.0/MODULE.bazel": "45061ff025b301940f1e30d2c16bea596c25b176c8b6b3087e92615adbd52902",
|
||||
"https://bcr.bazel.build/modules/nlohmann_json/3.6.1/MODULE.bazel": "6f7b417dcc794d9add9e556673ad25cb3ba835224290f4f848f8e2db1e1fca74",
|
||||
"https://bcr.bazel.build/modules/nlohmann_json/3.6.1/source.json": "f448c6e8963fdfa7eb831457df83ad63d3d6355018f6574fb017e8169deb43a9",
|
||||
"https://bcr.bazel.build/modules/package_metadata/0.0.3/MODULE.bazel": "77890552ecea9e284b5424c9de827a58099348763a4359e975c359a83d4faa83",
|
||||
"https://bcr.bazel.build/modules/package_metadata/0.0.5/MODULE.bazel": "ef4f9439e3270fdd6b9fd4dbc3d2f29d13888e44c529a1b243f7a31dfbc2e8e4",
|
||||
"https://bcr.bazel.build/modules/package_metadata/0.0.5/source.json": "2326db2f6592578177751c3e1f74786b79382cd6008834c9d01ec865b9126a85",
|
||||
"https://bcr.bazel.build/modules/platforms/0.0.10/MODULE.bazel": "8cb8efaf200bdeb2150d93e162c40f388529a25852b332cec879373771e48ed5",
|
||||
"https://bcr.bazel.build/modules/platforms/0.0.11/MODULE.bazel": "0daefc49732e227caa8bfa834d65dc52e8cc18a2faf80df25e8caea151a9413f",
|
||||
"https://bcr.bazel.build/modules/platforms/0.0.4/MODULE.bazel": "9b328e31ee156f53f3c416a64f8491f7eb731742655a47c9eec4703a71644aee",
|
||||
"https://bcr.bazel.build/modules/platforms/0.0.5/MODULE.bazel": "5733b54ea419d5eaf7997054bb55f6a1d0b5ff8aedf0176fef9eea44f3acda37",
|
||||
"https://bcr.bazel.build/modules/platforms/0.0.6/MODULE.bazel": "ad6eeef431dc52aefd2d77ed20a4b353f8ebf0f4ecdd26a807d2da5aa8cd0615",
|
||||
"https://bcr.bazel.build/modules/platforms/0.0.7/MODULE.bazel": "72fd4a0ede9ee5c021f6a8dd92b503e089f46c227ba2813ff183b71616034814",
|
||||
"https://bcr.bazel.build/modules/platforms/0.0.8/MODULE.bazel": "9f142c03e348f6d263719f5074b21ef3adf0b139ee4c5133e2aa35664da9eb2d",
|
||||
"https://bcr.bazel.build/modules/platforms/0.0.9/MODULE.bazel": "4a87a60c927b56ddd67db50c89acaa62f4ce2a1d2149ccb63ffd871d5ce29ebc",
|
||||
"https://bcr.bazel.build/modules/platforms/1.0.0/MODULE.bazel": "f05feb42b48f1b3c225e4ccf351f367be0371411a803198ec34a389fb22aa580",
|
||||
"https://bcr.bazel.build/modules/platforms/1.1.0/MODULE.bazel": "1c0c09f5bdcf4b3f924720d2478a3711cb39f4977019ca5988685e5b7e18b3d2",
|
||||
"https://bcr.bazel.build/modules/platforms/1.1.0/source.json": "fcf351c47596c939140ab0d333dfdd08ed1ea6ce33c2fe70c12493a301cf1344",
|
||||
"https://bcr.bazel.build/modules/protobuf/21.7/MODULE.bazel": "a5a29bb89544f9b97edce05642fac225a808b5b7be74038ea3640fae2f8e66a7",
|
||||
"https://bcr.bazel.build/modules/protobuf/27.0/MODULE.bazel": "7873b60be88844a0a1d8f80b9d5d20cfbd8495a689b8763e76c6372998d3f64c",
|
||||
"https://bcr.bazel.build/modules/protobuf/27.1/MODULE.bazel": "703a7b614728bb06647f965264967a8ef1c39e09e8f167b3ca0bb1fd80449c0d",
|
||||
"https://bcr.bazel.build/modules/protobuf/29.0-rc2.bcr.1/MODULE.bazel": "52f4126f63a2f0bbf36b99c2a87648f08467a4eaf92ba726bc7d6a500bbf770c",
|
||||
"https://bcr.bazel.build/modules/protobuf/29.0-rc2/MODULE.bazel": "6241d35983510143049943fc0d57937937122baf1b287862f9dc8590fc4c37df",
|
||||
"https://bcr.bazel.build/modules/protobuf/29.0-rc3/MODULE.bazel": "33c2dfa286578573afc55a7acaea3cada4122b9631007c594bf0729f41c8de92",
|
||||
"https://bcr.bazel.build/modules/protobuf/29.0/MODULE.bazel": "319dc8bf4c679ff87e71b1ccfb5a6e90a6dbc4693501d471f48662ac46d04e4e",
|
||||
"https://bcr.bazel.build/modules/protobuf/29.1/MODULE.bazel": "557c3457560ff49e122ed76c0bc3397a64af9574691cb8201b4e46d4ab2ecb95",
|
||||
"https://bcr.bazel.build/modules/protobuf/3.19.0/MODULE.bazel": "6b5fbb433f760a99a22b18b6850ed5784ef0e9928a72668b66e4d7ccd47db9b0",
|
||||
"https://bcr.bazel.build/modules/protobuf/3.19.2/MODULE.bazel": "532ffe5f2186b69fdde039efe6df13ba726ff338c6bc82275ad433013fa10573",
|
||||
"https://bcr.bazel.build/modules/protobuf/3.19.6/MODULE.bazel": "9233edc5e1f2ee276a60de3eaa47ac4132302ef9643238f23128fea53ea12858",
|
||||
"https://bcr.bazel.build/modules/protobuf/32.1/MODULE.bazel": "89cd2866a9cb07fee9ff74c41ceace11554f32e0d849de4e23ac55515cfada4d",
|
||||
"https://bcr.bazel.build/modules/protobuf/33.4/MODULE.bazel": "114775b816b38b6d0ca620450d6b02550c60ceedfdc8d9a229833b34a223dc42",
|
||||
"https://bcr.bazel.build/modules/protobuf/33.4/source.json": "555f8686b4c7d6b5ba731fbea13bf656b4bfd9a7ff629c1d9d3f6e1d6155de79",
|
||||
"https://bcr.bazel.build/modules/pybind11_bazel/2.11.1/MODULE.bazel": "88af1c246226d87e65be78ed49ecd1e6f5e98648558c14ce99176da041dc378e",
|
||||
"https://bcr.bazel.build/modules/pybind11_bazel/2.12.0/MODULE.bazel": "e6f4c20442eaa7c90d7190d8dc539d0ab422f95c65a57cc59562170c58ae3d34",
|
||||
"https://bcr.bazel.build/modules/pybind11_bazel/2.12.0/source.json": "6900fdc8a9e95866b8c0d4ad4aba4d4236317b5c1cd04c502df3f0d33afed680",
|
||||
"https://bcr.bazel.build/modules/re2/2023-09-01/MODULE.bazel": "cb3d511531b16cfc78a225a9e2136007a48cf8a677e4264baeab57fe78a80206",
|
||||
"https://bcr.bazel.build/modules/re2/2024-07-02.bcr.1/MODULE.bazel": "b4963dda9b31080be1905ef085ecd7dd6cd47c05c79b9cdf83ade83ab2ab271a",
|
||||
"https://bcr.bazel.build/modules/re2/2024-07-02.bcr.1/source.json": "2ff292be6ef3340325ce8a045ecc326e92cbfab47c7cbab4bd85d28971b97ac4",
|
||||
"https://bcr.bazel.build/modules/re2/2024-07-02/MODULE.bazel": "0eadc4395959969297cbcf31a249ff457f2f1d456228c67719480205aa306daa",
|
||||
"https://bcr.bazel.build/modules/rules_android/0.1.1/MODULE.bazel": "48809ab0091b07ad0182defb787c4c5328bd3a278938415c00a7b69b50c4d3a8",
|
||||
"https://bcr.bazel.build/modules/rules_android/0.1.1/source.json": "e6986b41626ee10bdc864937ffb6d6bf275bb5b9c65120e6137d56e6331f089e",
|
||||
"https://bcr.bazel.build/modules/rules_apple/3.16.0/MODULE.bazel": "0d1caf0b8375942ce98ea944be754a18874041e4e0459401d925577624d3a54a",
|
||||
"https://bcr.bazel.build/modules/rules_apple/4.1.0/MODULE.bazel": "76e10fd4a48038d3fc7c5dc6e63b7063bbf5304a2e3bd42edda6ec660eebea68",
|
||||
"https://bcr.bazel.build/modules/rules_apple/4.1.0/source.json": "8ee81e1708756f81b343a5eb2b2f0b953f1d25c4ab3d4a68dc02754872e80715",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.0.1/MODULE.bazel": "cb2aa0747f84c6c3a78dad4e2049c154f08ab9d166b1273835a8174940365647",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.0.10/MODULE.bazel": "ec1705118f7eaedd6e118508d3d26deba2a4e76476ada7e0e3965211be012002",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.0.13/MODULE.bazel": "0e8529ed7b323dad0775ff924d2ae5af7640b23553dfcd4d34344c7e7a867191",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.0.15/MODULE.bazel": "6704c35f7b4a72502ee81f61bf88706b54f06b3cbe5558ac17e2e14666cd5dcc",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.0.16/MODULE.bazel": "7661303b8fc1b4d7f532e54e9d6565771fea666fbdf839e0a86affcd02defe87",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.0.17/MODULE.bazel": "2ae1d8f4238ec67d7185d8861cb0a2cdf4bc608697c331b95bf990e69b62e64a",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.0.2/MODULE.bazel": "6915987c90970493ab97393024c156ea8fb9f3bea953b2f3ec05c34f19b5695c",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.0.6/MODULE.bazel": "abf360251023dfe3efcef65ab9d56beefa8394d4176dd29529750e1c57eaa33f",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.0.8/MODULE.bazel": "964c85c82cfeb6f3855e6a07054fdb159aced38e99a5eecf7bce9d53990afa3e",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.0.9/MODULE.bazel": "836e76439f354b89afe6a911a7adf59a6b2518fafb174483ad78a2a2fde7b1c5",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.1.1/MODULE.bazel": "2f0222a6f229f0bf44cd711dc13c858dad98c62d52bd51d8fc3a764a83125513",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.1.2/MODULE.bazel": "557ddc3a96858ec0d465a87c0a931054d7dcfd6583af2c7ed3baf494407fd8d0",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.1.5/MODULE.bazel": "88dfc9361e8b5ae1008ac38f7cdfd45ad738e4fa676a3ad67d19204f045a1fd8",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.2.0/MODULE.bazel": "b5c17f90458caae90d2ccd114c81970062946f49f355610ed89bebf954f5783c",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.2.13/MODULE.bazel": "eecdd666eda6be16a8d9dc15e44b5c75133405e820f620a234acc4b1fdc5aa37",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.2.17/MODULE.bazel": "1849602c86cb60da8613d2de887f9566a6d354a6df6d7009f9d04a14402f9a84",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.2.17/source.json": "3832f45d145354049137c0090df04629d9c2b5493dc5c2bf46f1834040133a07",
|
||||
"https://bcr.bazel.build/modules/rules_cc/0.2.8/MODULE.bazel": "f1df20f0bf22c28192a794f29b501ee2018fa37a3862a1a2132ae2940a23a642",
|
||||
"https://bcr.bazel.build/modules/rules_foreign_cc/0.9.0/MODULE.bazel": "c9e8c682bf75b0e7c704166d79b599f93b72cfca5ad7477df596947891feeef6",
|
||||
"https://bcr.bazel.build/modules/rules_fuzzing/0.5.2/MODULE.bazel": "40c97d1144356f52905566c55811f13b299453a14ac7769dfba2ac38192337a8",
|
||||
"https://bcr.bazel.build/modules/rules_go/0.41.0/MODULE.bazel": "55861d8e8bb0e62cbd2896f60ff303f62ffcb0eddb74ecb0e5c0cbe36fc292c8",
|
||||
"https://bcr.bazel.build/modules/rules_go/0.42.0/MODULE.bazel": "8cfa875b9aa8c6fce2b2e5925e73c1388173ea3c32a0db4d2b4804b453c14270",
|
||||
"https://bcr.bazel.build/modules/rules_go/0.46.0/MODULE.bazel": "3477df8bdcc49e698b9d25f734c4f3a9f5931ff34ee48a2c662be168f5f2d3fd",
|
||||
"https://bcr.bazel.build/modules/rules_go/0.59.0/MODULE.bazel": "b7e43e7414a3139a7547d1b4909b29085fbe5182b6c58cbe1ed4c6272815aeae",
|
||||
"https://bcr.bazel.build/modules/rules_go/0.63.0/MODULE.bazel": "a2079e783a5d2715a90e6e2970ec8ffd717a487ff2aecb5f553e3975c5294a21",
|
||||
"https://bcr.bazel.build/modules/rules_go/0.63.0/source.json": "5bf37b45c440ac03abad0cbfa8b8b8dd89cc4e82bc8305f468b8436fa58bae78",
|
||||
"https://bcr.bazel.build/modules/rules_java/4.0.0/MODULE.bazel": "5a78a7ae82cd1a33cef56dc578c7d2a46ed0dca12643ee45edbb8417899e6f74",
|
||||
"https://bcr.bazel.build/modules/rules_java/5.3.5/MODULE.bazel": "a4ec4f2db570171e3e5eb753276ee4b389bae16b96207e9d3230895c99644b86",
|
||||
"https://bcr.bazel.build/modules/rules_java/6.5.2/MODULE.bazel": "1d440d262d0e08453fa0c4d8f699ba81609ed0e9a9a0f02cd10b3e7942e61e31",
|
||||
"https://bcr.bazel.build/modules/rules_java/7.10.0/MODULE.bazel": "530c3beb3067e870561739f1144329a21c851ff771cd752a49e06e3dc9c2e71a",
|
||||
"https://bcr.bazel.build/modules/rules_java/7.12.2/MODULE.bazel": "579c505165ee757a4280ef83cda0150eea193eed3bef50b1004ba88b99da6de6",
|
||||
"https://bcr.bazel.build/modules/rules_java/7.2.0/MODULE.bazel": "06c0334c9be61e6cef2c8c84a7800cef502063269a5af25ceb100b192453d4ab",
|
||||
"https://bcr.bazel.build/modules/rules_java/7.6.1/MODULE.bazel": "2f14b7e8a1aa2f67ae92bc69d1ec0fa8d9f827c4e17ff5e5f02e91caa3b2d0fe",
|
||||
"https://bcr.bazel.build/modules/rules_java/8.3.2/MODULE.bazel": "7336d5511ad5af0b8615fdc7477535a2e4e723a357b6713af439fe8cf0195017",
|
||||
"https://bcr.bazel.build/modules/rules_java/8.5.1/MODULE.bazel": "d8a9e38cc5228881f7055a6079f6f7821a073df3744d441978e7a43e20226939",
|
||||
"https://bcr.bazel.build/modules/rules_java/8.6.1/MODULE.bazel": "f4808e2ab5b0197f094cabce9f4b006a27766beb6a9975931da07099560ca9c2",
|
||||
"https://bcr.bazel.build/modules/rules_java/9.1.0/MODULE.bazel": "ee63f27e36a3fada80342869361182f120a9819c74320e8e65b1e04ba0cd7a9d",
|
||||
"https://bcr.bazel.build/modules/rules_java/9.1.0/source.json": "da589573c1dee2c9ac4a568b301269a2e8191110ff0345c1a959fa7ea6c4dfd6",
|
||||
"https://bcr.bazel.build/modules/rules_jvm_external/4.4.2/MODULE.bazel": "a56b85e418c83eb1839819f0b515c431010160383306d13ec21959ac412d2fe7",
|
||||
"https://bcr.bazel.build/modules/rules_jvm_external/5.1/MODULE.bazel": "33f6f999e03183f7d088c9be518a63467dfd0be94a11d0055fe2d210f89aa909",
|
||||
"https://bcr.bazel.build/modules/rules_jvm_external/5.2/MODULE.bazel": "d9351ba35217ad0de03816ef3ed63f89d411349353077348a45348b096615036",
|
||||
"https://bcr.bazel.build/modules/rules_jvm_external/6.3/MODULE.bazel": "c998e060b85f71e00de5ec552019347c8bca255062c990ac02d051bb80a38df0",
|
||||
"https://bcr.bazel.build/modules/rules_jvm_external/6.7/MODULE.bazel": "e717beabc4d091ecb2c803c2d341b88590e9116b8bf7947915eeb33aab4f96dd",
|
||||
"https://bcr.bazel.build/modules/rules_jvm_external/6.7/source.json": "5426f412d0a7fc6b611643376c7e4a82dec991491b9ce5cb1cfdd25fe2e92be4",
|
||||
"https://bcr.bazel.build/modules/rules_kotlin/1.9.6/MODULE.bazel": "d269a01a18ee74d0335450b10f62c9ed81f2321d7958a2934e44272fe82dcef3",
|
||||
"https://bcr.bazel.build/modules/rules_kotlin/1.9.6/source.json": "2faa4794364282db7c06600b7e5e34867a564ae91bda7cae7c29c64e9466b7d5",
|
||||
"https://bcr.bazel.build/modules/rules_license/0.0.3/MODULE.bazel": "627e9ab0247f7d1e05736b59dbb1b6871373de5ad31c3011880b4133cafd4bd0",
|
||||
"https://bcr.bazel.build/modules/rules_license/0.0.7/MODULE.bazel": "088fbeb0b6a419005b89cf93fe62d9517c0a2b8bb56af3244af65ecfe37e7d5d",
|
||||
"https://bcr.bazel.build/modules/rules_license/1.0.0/MODULE.bazel": "a7fda60eefdf3d8c827262ba499957e4df06f659330bbe6cdbdb975b768bb65c",
|
||||
"https://bcr.bazel.build/modules/rules_license/1.0.0/source.json": "a52c89e54cc311196e478f8382df91c15f7a2bfdf4c6cd0e2675cc2ff0b56efb",
|
||||
"https://bcr.bazel.build/modules/rules_pkg/0.7.0/MODULE.bazel": "df99f03fc7934a4737122518bb87e667e62d780b610910f0447665a7e2be62dc",
|
||||
"https://bcr.bazel.build/modules/rules_pkg/1.0.1/MODULE.bazel": "5b1df97dbc29623bccdf2b0dcd0f5cb08e2f2c9050aab1092fd39a41e82686ff",
|
||||
"https://bcr.bazel.build/modules/rules_pkg/1.0.1/source.json": "bd82e5d7b9ce2d31e380dd9f50c111d678c3bdaca190cb76b0e1c71b05e1ba8a",
|
||||
"https://bcr.bazel.build/modules/rules_proto/4.0.0/MODULE.bazel": "a7a7b6ce9bee418c1a760b3d84f83a299ad6952f9903c67f19e4edd964894e06",
|
||||
"https://bcr.bazel.build/modules/rules_proto/5.3.0-21.7/MODULE.bazel": "e8dff86b0971688790ae75528fe1813f71809b5afd57facb44dad9e8eca631b7",
|
||||
"https://bcr.bazel.build/modules/rules_proto/6.0.0-rc1/MODULE.bazel": "1e5b502e2e1a9e825eef74476a5a1ee524a92297085015a052510b09a1a09483",
|
||||
"https://bcr.bazel.build/modules/rules_proto/6.0.2/MODULE.bazel": "ce916b775a62b90b61888052a416ccdda405212b6aaeb39522f7dc53431a5e73",
|
||||
"https://bcr.bazel.build/modules/rules_proto/7.0.2/MODULE.bazel": "bf81793bd6d2ad89a37a40693e56c61b0ee30f7a7fdbaf3eabbf5f39de47dea2",
|
||||
"https://bcr.bazel.build/modules/rules_proto/7.1.0/MODULE.bazel": "002d62d9108f75bb807cd56245d45648f38275cb3a99dcd45dfb864c5d74cb96",
|
||||
"https://bcr.bazel.build/modules/rules_proto/7.1.0/source.json": "39f89066c12c24097854e8f57ab8558929f9c8d474d34b2c00ac04630ad8940e",
|
||||
"https://bcr.bazel.build/modules/rules_python/0.10.2/MODULE.bazel": "cc82bc96f2997baa545ab3ce73f196d040ffb8756fd2d66125a530031cd90e5f",
|
||||
"https://bcr.bazel.build/modules/rules_python/0.23.1/MODULE.bazel": "49ffccf0511cb8414de28321f5fcf2a31312b47c40cc21577144b7447f2bf300",
|
||||
"https://bcr.bazel.build/modules/rules_python/0.25.0/MODULE.bazel": "72f1506841c920a1afec76975b35312410eea3aa7b63267436bfb1dd91d2d382",
|
||||
"https://bcr.bazel.build/modules/rules_python/0.28.0/MODULE.bazel": "cba2573d870babc976664a912539b320cbaa7114cd3e8f053c720171cde331ed",
|
||||
"https://bcr.bazel.build/modules/rules_python/0.31.0/MODULE.bazel": "93a43dc47ee570e6ec9f5779b2e64c1476a6ce921c48cc9a1678a91dd5f8fd58",
|
||||
"https://bcr.bazel.build/modules/rules_python/0.33.2/MODULE.bazel": "3e036c4ad8d804a4dad897d333d8dce200d943df4827cb849840055be8d2e937",
|
||||
"https://bcr.bazel.build/modules/rules_python/0.4.0/MODULE.bazel": "9208ee05fd48bf09ac60ed269791cf17fb343db56c8226a720fbb1cdf467166c",
|
||||
"https://bcr.bazel.build/modules/rules_python/1.3.0/MODULE.bazel": "8361d57eafb67c09b75bf4bbe6be360e1b8f4f18118ab48037f2bd50aa2ccb13",
|
||||
"https://bcr.bazel.build/modules/rules_python/1.4.1/MODULE.bazel": "8991ad45bdc25018301d6b7e1d3626afc3c8af8aaf4bc04f23d0b99c938b73a6",
|
||||
"https://bcr.bazel.build/modules/rules_python/1.6.0/MODULE.bazel": "7e04ad8f8d5bea40451cf80b1bd8262552aa73f841415d20db96b7241bd027d8",
|
||||
"https://bcr.bazel.build/modules/rules_python/1.7.0/MODULE.bazel": "d01f995ecd137abf30238ad9ce97f8fc3ac57289c8b24bd0bf53324d937a14f8",
|
||||
"https://bcr.bazel.build/modules/rules_python/1.7.0/source.json": "028a084b65dcf8f4dc4f82f8778dbe65df133f234b316828a82e060d81bdce32",
|
||||
"https://bcr.bazel.build/modules/rules_shell/0.2.0/MODULE.bazel": "fda8a652ab3c7d8fee214de05e7a9916d8b28082234e8d2c0094505c5268ed3c",
|
||||
"https://bcr.bazel.build/modules/rules_shell/0.3.0/MODULE.bazel": "de4402cd12f4cc8fda2354fce179fdb068c0b9ca1ec2d2b17b3e21b24c1a937b",
|
||||
"https://bcr.bazel.build/modules/rules_shell/0.6.1/MODULE.bazel": "72e76b0eea4e81611ef5452aa82b3da34caca0c8b7b5c0c9584338aa93bae26b",
|
||||
"https://bcr.bazel.build/modules/rules_shell/0.6.1/source.json": "20ec05cd5e592055e214b2da8ccb283c7f2a421ea0dc2acbf1aa792e11c03d0c",
|
||||
"https://bcr.bazel.build/modules/rules_swift/1.16.0/MODULE.bazel": "4a09f199545a60d09895e8281362b1ff3bb08bbde69c6fc87aff5b92fcc916ca",
|
||||
"https://bcr.bazel.build/modules/rules_swift/2.1.1/MODULE.bazel": "494900a80f944fc7aa61500c2073d9729dff0b764f0e89b824eb746959bc1046",
|
||||
"https://bcr.bazel.build/modules/rules_swift/2.4.0/MODULE.bazel": "1639617eb1ede28d774d967a738b4a68b0accb40650beadb57c21846beab5efd",
|
||||
"https://bcr.bazel.build/modules/rules_swift/3.1.2/MODULE.bazel": "72c8f5cf9d26427cee6c76c8e3853eb46ce6b0412a081b2b6db6e8ad56267400",
|
||||
"https://bcr.bazel.build/modules/rules_swift/3.1.2/source.json": "e85761f3098a6faf40b8187695e3de6d97944e98abd0d8ce579cb2daf6319a66",
|
||||
"https://bcr.bazel.build/modules/stardoc/0.5.1/MODULE.bazel": "1a05d92974d0c122f5ccf09291442580317cdd859f07a8655f1db9a60374f9f8",
|
||||
"https://bcr.bazel.build/modules/stardoc/0.5.3/MODULE.bazel": "c7f6948dae6999bf0db32c1858ae345f112cacf98f174c7a8bb707e41b974f1c",
|
||||
"https://bcr.bazel.build/modules/stardoc/0.7.0/MODULE.bazel": "05e3d6d30c099b6770e97da986c53bd31844d7f13d41412480ea265ac9e8079c",
|
||||
"https://bcr.bazel.build/modules/stardoc/0.7.2/MODULE.bazel": "fc152419aa2ea0f51c29583fab1e8c99ddefd5b3778421845606ee628629e0e5",
|
||||
"https://bcr.bazel.build/modules/stardoc/0.7.2/source.json": "58b029e5e901d6802967754adf0a9056747e8176f017cfe3607c0851f4d42216",
|
||||
"https://bcr.bazel.build/modules/swift_argument_parser/1.3.1.1/MODULE.bazel": "5e463fbfba7b1701d957555ed45097d7f984211330106ccd1352c6e0af0dcf91",
|
||||
"https://bcr.bazel.build/modules/swift_argument_parser/1.3.1.2/MODULE.bazel": "75aab2373a4bbe2a1260b9bf2a1ebbdbf872d3bd36f80bff058dccd82e89422f",
|
||||
"https://bcr.bazel.build/modules/swift_argument_parser/1.3.1.2/source.json": "5fba48bbe0ba48761f9e9f75f92876cafb5d07c0ce059cc7a8027416de94a05b",
|
||||
"https://bcr.bazel.build/modules/upb/0.0.0-20220923-a547704/MODULE.bazel": "7298990c00040a0e2f121f6c32544bab27d4452f80d9ce51349b1a28f3005c43",
|
||||
"https://bcr.bazel.build/modules/zlib/1.2.11/MODULE.bazel": "07b389abc85fdbca459b69e2ec656ae5622873af3f845e1c9d80fe179f3effa0",
|
||||
"https://bcr.bazel.build/modules/zlib/1.2.12/MODULE.bazel": "3b1a8834ada2a883674be8cbd36ede1b6ec481477ada359cd2d3ddc562340b27",
|
||||
"https://bcr.bazel.build/modules/zlib/1.3.1.bcr.5/MODULE.bazel": "eec517b5bbe5492629466e11dae908d043364302283de25581e3eb944326c4ca",
|
||||
"https://bcr.bazel.build/modules/zlib/1.3.1.bcr.5/source.json": "22bc55c47af97246cfc093d0acf683a7869377de362b5d1c552c2c2e16b7a806",
|
||||
"https://bcr.bazel.build/modules/zlib/1.3.1/MODULE.bazel": "751c9940dcfe869f5f7274e1295422a34623555916eb98c174c1e945594bf198"
|
||||
},
|
||||
"selectedYankedVersions": {},
|
||||
"moduleExtensions": {
|
||||
"@@pybind11_bazel+//:internal_configure.bzl%internal_configure_extension": {
|
||||
"general": {
|
||||
"bzlTransitiveDigest": "NRXra7941UfmNUyIxnLt82V5hULluVGL2nBsijTl4j4=",
|
||||
"usagesDigest": "D1r3lfzMuUBFxgG8V6o0bQTLMk3GkaGOaPzw53wrwyw=",
|
||||
"recordedInputs": [
|
||||
"REPO_MAPPING:pybind11_bazel+,bazel_tools bazel_tools",
|
||||
"FILE:@@pybind11_bazel+//MODULE.bazel e6f4c20442eaa7c90d7190d8dc539d0ab422f95c65a57cc59562170c58ae3d34"
|
||||
],
|
||||
"generatedRepoSpecs": {
|
||||
"pybind11": {
|
||||
"repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive",
|
||||
"attributes": {
|
||||
"build_file": "@@pybind11_bazel+//:pybind11-BUILD.bazel",
|
||||
"strip_prefix": "pybind11-2.12.0",
|
||||
"urls": [
|
||||
"https://github.com/pybind/pybind11/archive/v2.12.0.zip"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"@@rules_kotlin+//src/main/starlark/core/repositories:bzlmod_setup.bzl%rules_kotlin_extensions": {
|
||||
"general": {
|
||||
"bzlTransitiveDigest": "+Kp6j204mBZ3mxlIDDR0gBoP45BZ4jYRhRAcB8sU0qc=",
|
||||
"usagesDigest": "QI2z8ZUR+mqtbwsf2fLqYdJAkPOHdOV+tF2yVAUgRzw=",
|
||||
"recordedInputs": [
|
||||
"REPO_MAPPING:rules_kotlin+,bazel_tools bazel_tools"
|
||||
],
|
||||
"generatedRepoSpecs": {
|
||||
"com_github_jetbrains_kotlin_git": {
|
||||
"repoRuleId": "@@rules_kotlin+//src/main/starlark/core/repositories:compiler.bzl%kotlin_compiler_git_repository",
|
||||
"attributes": {
|
||||
"urls": [
|
||||
"https://github.com/JetBrains/kotlin/releases/download/v1.9.23/kotlin-compiler-1.9.23.zip"
|
||||
],
|
||||
"sha256": "93137d3aab9afa9b27cb06a824c2324195c6b6f6179d8a8653f440f5bd58be88"
|
||||
}
|
||||
},
|
||||
"com_github_jetbrains_kotlin": {
|
||||
"repoRuleId": "@@rules_kotlin+//src/main/starlark/core/repositories:compiler.bzl%kotlin_capabilities_repository",
|
||||
"attributes": {
|
||||
"git_repository_name": "com_github_jetbrains_kotlin_git",
|
||||
"compiler_version": "1.9.23"
|
||||
}
|
||||
},
|
||||
"com_github_google_ksp": {
|
||||
"repoRuleId": "@@rules_kotlin+//src/main/starlark/core/repositories:ksp.bzl%ksp_compiler_plugin_repository",
|
||||
"attributes": {
|
||||
"urls": [
|
||||
"https://github.com/google/ksp/releases/download/1.9.23-1.0.20/artifacts.zip"
|
||||
],
|
||||
"sha256": "ee0618755913ef7fd6511288a232e8fad24838b9af6ea73972a76e81053c8c2d",
|
||||
"strip_version": "1.9.23-1.0.20"
|
||||
}
|
||||
},
|
||||
"com_github_pinterest_ktlint": {
|
||||
"repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_file",
|
||||
"attributes": {
|
||||
"sha256": "01b2e0ef893383a50dbeb13970fe7fa3be36ca3e83259e01649945b09d736985",
|
||||
"urls": [
|
||||
"https://github.com/pinterest/ktlint/releases/download/1.3.0/ktlint"
|
||||
],
|
||||
"executable": true
|
||||
}
|
||||
},
|
||||
"rules_android": {
|
||||
"repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive",
|
||||
"attributes": {
|
||||
"sha256": "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806",
|
||||
"strip_prefix": "rules_android-0.1.1",
|
||||
"urls": [
|
||||
"https://github.com/bazelbuild/rules_android/archive/v0.1.1.zip"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"@@rules_python+//python/extensions:config.bzl%config": {
|
||||
"general": {
|
||||
"bzlTransitiveDigest": "dzD8Q2YmrP3fz8saWLHPmlwPLO91ImtTmP/c9JKTStM=",
|
||||
"usagesDigest": "ZVSXMAGpD+xzVNPuvF1IoLBkty7TROO0+akMapt1pAg=",
|
||||
"recordedInputs": [
|
||||
"REPO_MAPPING:rules_python+,bazel_tools bazel_tools",
|
||||
"REPO_MAPPING:rules_python+,pypi__build rules_python++config+pypi__build",
|
||||
"REPO_MAPPING:rules_python+,pypi__click rules_python++config+pypi__click",
|
||||
"REPO_MAPPING:rules_python+,pypi__colorama rules_python++config+pypi__colorama",
|
||||
"REPO_MAPPING:rules_python+,pypi__importlib_metadata rules_python++config+pypi__importlib_metadata",
|
||||
"REPO_MAPPING:rules_python+,pypi__installer rules_python++config+pypi__installer",
|
||||
"REPO_MAPPING:rules_python+,pypi__more_itertools rules_python++config+pypi__more_itertools",
|
||||
"REPO_MAPPING:rules_python+,pypi__packaging rules_python++config+pypi__packaging",
|
||||
"REPO_MAPPING:rules_python+,pypi__pep517 rules_python++config+pypi__pep517",
|
||||
"REPO_MAPPING:rules_python+,pypi__pip rules_python++config+pypi__pip",
|
||||
"REPO_MAPPING:rules_python+,pypi__pip_tools rules_python++config+pypi__pip_tools",
|
||||
"REPO_MAPPING:rules_python+,pypi__pyproject_hooks rules_python++config+pypi__pyproject_hooks",
|
||||
"REPO_MAPPING:rules_python+,pypi__setuptools rules_python++config+pypi__setuptools",
|
||||
"REPO_MAPPING:rules_python+,pypi__tomli rules_python++config+pypi__tomli",
|
||||
"REPO_MAPPING:rules_python+,pypi__wheel rules_python++config+pypi__wheel",
|
||||
"REPO_MAPPING:rules_python+,pypi__zipp rules_python++config+pypi__zipp"
|
||||
],
|
||||
"generatedRepoSpecs": {
|
||||
"rules_python_internal": {
|
||||
"repoRuleId": "@@rules_python+//python/private:internal_config_repo.bzl%internal_config_repo",
|
||||
"attributes": {
|
||||
"transition_setting_generators": {},
|
||||
"transition_settings": []
|
||||
}
|
||||
},
|
||||
"pypi__build": {
|
||||
"repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive",
|
||||
"attributes": {
|
||||
"url": "https://files.pythonhosted.org/packages/e2/03/f3c8ba0a6b6e30d7d18c40faab90807c9bb5e9a1e3b2fe2008af624a9c97/build-1.2.1-py3-none-any.whl",
|
||||
"sha256": "75e10f767a433d9a86e50d83f418e83efc18ede923ee5ff7df93b6cb0306c5d4",
|
||||
"type": "zip",
|
||||
"build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n"
|
||||
}
|
||||
},
|
||||
"pypi__click": {
|
||||
"repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive",
|
||||
"attributes": {
|
||||
"url": "https://files.pythonhosted.org/packages/00/2e/d53fa4befbf2cfa713304affc7ca780ce4fc1fd8710527771b58311a3229/click-8.1.7-py3-none-any.whl",
|
||||
"sha256": "ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28",
|
||||
"type": "zip",
|
||||
"build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n"
|
||||
}
|
||||
},
|
||||
"pypi__colorama": {
|
||||
"repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive",
|
||||
"attributes": {
|
||||
"url": "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl",
|
||||
"sha256": "4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6",
|
||||
"type": "zip",
|
||||
"build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n"
|
||||
}
|
||||
},
|
||||
"pypi__importlib_metadata": {
|
||||
"repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive",
|
||||
"attributes": {
|
||||
"url": "https://files.pythonhosted.org/packages/2d/0a/679461c511447ffaf176567d5c496d1de27cbe34a87df6677d7171b2fbd4/importlib_metadata-7.1.0-py3-none-any.whl",
|
||||
"sha256": "30962b96c0c223483ed6cc7280e7f0199feb01a0e40cfae4d4450fc6fab1f570",
|
||||
"type": "zip",
|
||||
"build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n"
|
||||
}
|
||||
},
|
||||
"pypi__installer": {
|
||||
"repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive",
|
||||
"attributes": {
|
||||
"url": "https://files.pythonhosted.org/packages/e5/ca/1172b6638d52f2d6caa2dd262ec4c811ba59eee96d54a7701930726bce18/installer-0.7.0-py3-none-any.whl",
|
||||
"sha256": "05d1933f0a5ba7d8d6296bb6d5018e7c94fa473ceb10cf198a92ccea19c27b53",
|
||||
"type": "zip",
|
||||
"build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n"
|
||||
}
|
||||
},
|
||||
"pypi__more_itertools": {
|
||||
"repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive",
|
||||
"attributes": {
|
||||
"url": "https://files.pythonhosted.org/packages/50/e2/8e10e465ee3987bb7c9ab69efb91d867d93959095f4807db102d07995d94/more_itertools-10.2.0-py3-none-any.whl",
|
||||
"sha256": "686b06abe565edfab151cb8fd385a05651e1fdf8f0a14191e4439283421f8684",
|
||||
"type": "zip",
|
||||
"build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n"
|
||||
}
|
||||
},
|
||||
"pypi__packaging": {
|
||||
"repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive",
|
||||
"attributes": {
|
||||
"url": "https://files.pythonhosted.org/packages/49/df/1fceb2f8900f8639e278b056416d49134fb8d84c5942ffaa01ad34782422/packaging-24.0-py3-none-any.whl",
|
||||
"sha256": "2ddfb553fdf02fb784c234c7ba6ccc288296ceabec964ad2eae3777778130bc5",
|
||||
"type": "zip",
|
||||
"build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n"
|
||||
}
|
||||
},
|
||||
"pypi__pep517": {
|
||||
"repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive",
|
||||
"attributes": {
|
||||
"url": "https://files.pythonhosted.org/packages/25/6e/ca4a5434eb0e502210f591b97537d322546e4833dcb4d470a48c375c5540/pep517-0.13.1-py3-none-any.whl",
|
||||
"sha256": "31b206f67165b3536dd577c5c3f1518e8fbaf38cbc57efff8369a392feff1721",
|
||||
"type": "zip",
|
||||
"build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n"
|
||||
}
|
||||
},
|
||||
"pypi__pip": {
|
||||
"repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive",
|
||||
"attributes": {
|
||||
"url": "https://files.pythonhosted.org/packages/8a/6a/19e9fe04fca059ccf770861c7d5721ab4c2aebc539889e97c7977528a53b/pip-24.0-py3-none-any.whl",
|
||||
"sha256": "ba0d021a166865d2265246961bec0152ff124de910c5cc39f1156ce3fa7c69dc",
|
||||
"type": "zip",
|
||||
"build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n"
|
||||
}
|
||||
},
|
||||
"pypi__pip_tools": {
|
||||
"repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive",
|
||||
"attributes": {
|
||||
"url": "https://files.pythonhosted.org/packages/0d/dc/38f4ce065e92c66f058ea7a368a9c5de4e702272b479c0992059f7693941/pip_tools-7.4.1-py3-none-any.whl",
|
||||
"sha256": "4c690e5fbae2f21e87843e89c26191f0d9454f362d8acdbd695716493ec8b3a9",
|
||||
"type": "zip",
|
||||
"build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n"
|
||||
}
|
||||
},
|
||||
"pypi__pyproject_hooks": {
|
||||
"repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive",
|
||||
"attributes": {
|
||||
"url": "https://files.pythonhosted.org/packages/ae/f3/431b9d5fe7d14af7a32340792ef43b8a714e7726f1d7b69cc4e8e7a3f1d7/pyproject_hooks-1.1.0-py3-none-any.whl",
|
||||
"sha256": "7ceeefe9aec63a1064c18d939bdc3adf2d8aa1988a510afec15151578b232aa2",
|
||||
"type": "zip",
|
||||
"build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n"
|
||||
}
|
||||
},
|
||||
"pypi__setuptools": {
|
||||
"repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive",
|
||||
"attributes": {
|
||||
"url": "https://files.pythonhosted.org/packages/90/99/158ad0609729111163fc1f674a5a42f2605371a4cf036d0441070e2f7455/setuptools-78.1.1-py3-none-any.whl",
|
||||
"sha256": "c3a9c4211ff4c309edb8b8c4f1cbfa7ae324c4ba9f91ff254e3d305b9fd54561",
|
||||
"type": "zip",
|
||||
"build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n"
|
||||
}
|
||||
},
|
||||
"pypi__tomli": {
|
||||
"repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive",
|
||||
"attributes": {
|
||||
"url": "https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl",
|
||||
"sha256": "939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc",
|
||||
"type": "zip",
|
||||
"build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n"
|
||||
}
|
||||
},
|
||||
"pypi__wheel": {
|
||||
"repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive",
|
||||
"attributes": {
|
||||
"url": "https://files.pythonhosted.org/packages/7d/cd/d7460c9a869b16c3dd4e1e403cce337df165368c71d6af229a74699622ce/wheel-0.43.0-py3-none-any.whl",
|
||||
"sha256": "55c570405f142630c6b9f72fe09d9b67cf1477fcf543ae5b8dcb1f5b7377da81",
|
||||
"type": "zip",
|
||||
"build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n"
|
||||
}
|
||||
},
|
||||
"pypi__zipp": {
|
||||
"repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive",
|
||||
"attributes": {
|
||||
"url": "https://files.pythonhosted.org/packages/da/55/a03fd7240714916507e1fcf7ae355bd9d9ed2e6db492595f1a67f61681be/zipp-3.18.2-py3-none-any.whl",
|
||||
"sha256": "dce197b859eb796242b0622af1b8beb0a722d52aa2f57133ead08edd5bf5374e",
|
||||
"type": "zip",
|
||||
"build_file_content": "package(default_visibility = [\"//visibility:public\"])\n\nload(\"@rules_python//python:py_library.bzl\", \"py_library\")\n\npy_library(\n name = \"lib\",\n srcs = glob([\"**/*.py\"]),\n data = glob([\"**/*\"], exclude=[\n # These entries include those put into user-installed dependencies by\n # data_exclude to avoid non-determinism.\n \"**/*.py\",\n \"**/*.pyc\",\n \"**/*.pyc.*\", # During pyc creation, temp files named *.pyc.NNN are created\n \"**/*.dist-info/RECORD\",\n \"BUILD\",\n \"WORKSPACE\",\n ]),\n # This makes this directory a top-level in the python import\n # search path for anything that depends on this.\n imports = [\".\"],\n)\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"@@rules_python+//python/uv:uv.bzl%uv": {
|
||||
"general": {
|
||||
"bzlTransitiveDigest": "ijW9KS7qsIY+yBVvJ+Nr1mzwQox09j13DnE3iIwaeTM=",
|
||||
"usagesDigest": "H8dQoNZcoqP+Mu0tHZTi4KHATzvNkM5ePuEqoQdklIU=",
|
||||
"recordedInputs": [
|
||||
"REPO_MAPPING:rules_python+,bazel_tools bazel_tools",
|
||||
"REPO_MAPPING:rules_python+,platforms platforms"
|
||||
],
|
||||
"generatedRepoSpecs": {
|
||||
"uv": {
|
||||
"repoRuleId": "@@rules_python+//python/uv/private:uv_toolchains_repo.bzl%uv_toolchains_repo",
|
||||
"attributes": {
|
||||
"toolchain_type": "'@@rules_python+//python/uv:uv_toolchain_type'",
|
||||
"toolchain_names": [
|
||||
"none"
|
||||
],
|
||||
"toolchain_implementations": {
|
||||
"none": "'@@rules_python+//python:none'"
|
||||
},
|
||||
"toolchain_compatible_with": {
|
||||
"none": [
|
||||
"@platforms//:incompatible"
|
||||
]
|
||||
},
|
||||
"toolchain_target_settings": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"facts": {
|
||||
"@@rules_go+//go:extensions.bzl%go_sdk": {
|
||||
"1.25.0": {
|
||||
"aix_ppc64": [
|
||||
"go1.25.0.aix-ppc64.tar.gz",
|
||||
"e5234a7dac67bc86c528fe9752fc9d63557918627707a733ab4cac1a6faed2d4"
|
||||
],
|
||||
"darwin_amd64": [
|
||||
"go1.25.0.darwin-amd64.tar.gz",
|
||||
"5bd60e823037062c2307c71e8111809865116714d6f6b410597cf5075dfd80ef"
|
||||
],
|
||||
"darwin_arm64": [
|
||||
"go1.25.0.darwin-arm64.tar.gz",
|
||||
"544932844156d8172f7a28f77f2ac9c15a23046698b6243f633b0a0b00c0749c"
|
||||
],
|
||||
"dragonfly_amd64": [
|
||||
"go1.25.0.dragonfly-amd64.tar.gz",
|
||||
"5ed3cf9a810a1483822538674f1336c06b51aa1b94d6d545a1a0319a48177120"
|
||||
],
|
||||
"freebsd_386": [
|
||||
"go1.25.0.freebsd-386.tar.gz",
|
||||
"abea5d5c6697e6b5c224731f2158fe87c602996a2a233ac0c4730cd57bf8374e"
|
||||
],
|
||||
"freebsd_amd64": [
|
||||
"go1.25.0.freebsd-amd64.tar.gz",
|
||||
"86e6fe0a29698d7601c4442052dac48bd58d532c51cccb8f1917df648138730b"
|
||||
],
|
||||
"freebsd_arm": [
|
||||
"go1.25.0.freebsd-arm.tar.gz",
|
||||
"d90b78e41921f72f30e8bbc81d9dec2cff7ff384a33d8d8debb24053e4336bfe"
|
||||
],
|
||||
"freebsd_arm64": [
|
||||
"go1.25.0.freebsd-arm64.tar.gz",
|
||||
"451d0da1affd886bfb291b7c63a6018527b269505db21ce6e14724f22ab0662e"
|
||||
],
|
||||
"freebsd_riscv64": [
|
||||
"go1.25.0.freebsd-riscv64.tar.gz",
|
||||
"7b565f76bd8bda46549eeaaefe0e53b251e644c230577290c0f66b1ecdb3cdbe"
|
||||
],
|
||||
"illumos_amd64": [
|
||||
"go1.25.0.illumos-amd64.tar.gz",
|
||||
"b1e1fdaab1ad25aa1c08d7a36c97d45d74b98b89c3f78c6d2145f77face54a2c"
|
||||
],
|
||||
"linux_386": [
|
||||
"go1.25.0.linux-386.tar.gz",
|
||||
"8c602dd9d99bc9453b3995d20ce4baf382cc50855900a0ece5de9929df4a993a"
|
||||
],
|
||||
"linux_amd64": [
|
||||
"go1.25.0.linux-amd64.tar.gz",
|
||||
"2852af0cb20a13139b3448992e69b868e50ed0f8a1e5940ee1de9e19a123b613"
|
||||
],
|
||||
"linux_arm64": [
|
||||
"go1.25.0.linux-arm64.tar.gz",
|
||||
"05de75d6994a2783699815ee553bd5a9327d8b79991de36e38b66862782f54ae"
|
||||
],
|
||||
"linux_armv6l": [
|
||||
"go1.25.0.linux-armv6l.tar.gz",
|
||||
"a5a8f8198fcf00e1e485b8ecef9ee020778bf32a408a4e8873371bfce458cd09"
|
||||
],
|
||||
"linux_loong64": [
|
||||
"go1.25.0.linux-loong64.tar.gz",
|
||||
"cab86b1cf761b1cb3bac86a8877cfc92e7b036fc0d3084123d77013d61432afc"
|
||||
],
|
||||
"linux_mips": [
|
||||
"go1.25.0.linux-mips.tar.gz",
|
||||
"d66b6fb74c3d91b9829dc95ec10ca1f047ef5e89332152f92e136cf0e2da5be1"
|
||||
],
|
||||
"linux_mips64": [
|
||||
"go1.25.0.linux-mips64.tar.gz",
|
||||
"4082e4381a8661bc2a839ff94ba3daf4f6cde20f8fb771b5b3d4762dc84198a2"
|
||||
],
|
||||
"linux_mips64le": [
|
||||
"go1.25.0.linux-mips64le.tar.gz",
|
||||
"70002c299ec7f7175ac2ef673b1b347eecfa54ae11f34416a6053c17f855afcc"
|
||||
],
|
||||
"linux_mipsle": [
|
||||
"go1.25.0.linux-mipsle.tar.gz",
|
||||
"b00a3a39eff099f6df9f1c7355bf28e4589d0586f42d7d4a394efb763d145a73"
|
||||
],
|
||||
"linux_ppc64": [
|
||||
"go1.25.0.linux-ppc64.tar.gz",
|
||||
"df166f33bd98160662560a72ff0b4ba731f969a80f088922bddcf566a88c1ec1"
|
||||
],
|
||||
"linux_ppc64le": [
|
||||
"go1.25.0.linux-ppc64le.tar.gz",
|
||||
"0f18a89e7576cf2c5fa0b487a1635d9bcbf843df5f110e9982c64df52a983ad0"
|
||||
],
|
||||
"linux_riscv64": [
|
||||
"go1.25.0.linux-riscv64.tar.gz",
|
||||
"c018ff74a2c48d55c8ca9b07c8e24163558ffec8bea08b326d6336905d956b67"
|
||||
],
|
||||
"linux_s390x": [
|
||||
"go1.25.0.linux-s390x.tar.gz",
|
||||
"34e5a2e19f2292fbaf8783e3a241e6e49689276aef6510a8060ea5ef54eee408"
|
||||
],
|
||||
"netbsd_386": [
|
||||
"go1.25.0.netbsd-386.tar.gz",
|
||||
"f8586cdb7aa855657609a5c5f6dbf523efa00c2bbd7c76d3936bec80aa6c0aba"
|
||||
],
|
||||
"netbsd_amd64": [
|
||||
"go1.25.0.netbsd-amd64.tar.gz",
|
||||
"ae8dc1469385b86a157a423bb56304ba45730de8a897615874f57dd096db2c2a"
|
||||
],
|
||||
"netbsd_arm": [
|
||||
"go1.25.0.netbsd-arm.tar.gz",
|
||||
"1ff7e4cc764425fc9dd6825eaee79d02b3c7cafffbb3691687c8d672ade76cb7"
|
||||
],
|
||||
"netbsd_arm64": [
|
||||
"go1.25.0.netbsd-arm64.tar.gz",
|
||||
"e1b310739f26724216aa6d7d7208c4031f9ff54c9b5b9a796ddc8bebcb4a5f16"
|
||||
],
|
||||
"openbsd_386": [
|
||||
"go1.25.0.openbsd-386.tar.gz",
|
||||
"4802a9b20e533da91adb84aab42e94aa56cfe3e5475d0550bed3385b182e69d8"
|
||||
],
|
||||
"openbsd_amd64": [
|
||||
"go1.25.0.openbsd-amd64.tar.gz",
|
||||
"c016cd984bebe317b19a4f297c4f50def120dc9788490540c89f28e42f1dabe1"
|
||||
],
|
||||
"openbsd_arm": [
|
||||
"go1.25.0.openbsd-arm.tar.gz",
|
||||
"a1e31d0bf22172ddde42edf5ec811ef81be43433df0948ece52fecb247ccfd8d"
|
||||
],
|
||||
"openbsd_arm64": [
|
||||
"go1.25.0.openbsd-arm64.tar.gz",
|
||||
"343ea8edd8c218196e15a859c6072d0dd3246fbbb168481ab665eb4c4140458d"
|
||||
],
|
||||
"openbsd_ppc64": [
|
||||
"go1.25.0.openbsd-ppc64.tar.gz",
|
||||
"694c14da1bcaeb5e3332d49bdc2b6d155067648f8fe1540c5de8f3cf8e157154"
|
||||
],
|
||||
"openbsd_riscv64": [
|
||||
"go1.25.0.openbsd-riscv64.tar.gz",
|
||||
"aa510ad25cf54c06cd9c70b6d80ded69cb20188ac6e1735655eef29ff7e7885f"
|
||||
],
|
||||
"plan9_386": [
|
||||
"go1.25.0.plan9-386.tar.gz",
|
||||
"46f8cef02086cf04bf186c5912776b56535178d4cb319cd19c9fdbdd29231986"
|
||||
],
|
||||
"plan9_amd64": [
|
||||
"go1.25.0.plan9-amd64.tar.gz",
|
||||
"29b34391d84095e44608a228f63f2f88113a37b74a79781353ec043dfbcb427b"
|
||||
],
|
||||
"plan9_arm": [
|
||||
"go1.25.0.plan9-arm.tar.gz",
|
||||
"0a047107d13ebe7943aaa6d54b1d7bbd2e45e68ce449b52915a818da715799c2"
|
||||
],
|
||||
"solaris_amd64": [
|
||||
"go1.25.0.solaris-amd64.tar.gz",
|
||||
"9977f9e4351984364a3b2b78f8b88bfd1d339812356d5237678514594b7d3611"
|
||||
],
|
||||
"windows_386": [
|
||||
"go1.25.0.windows-386.zip",
|
||||
"df9f39db82a803af0db639e3613a36681ab7a42866b1384b3f3a1045663961a7"
|
||||
],
|
||||
"windows_amd64": [
|
||||
"go1.25.0.windows-amd64.zip",
|
||||
"89efb4f9b30812eee083cc1770fdd2913c14d301064f6454851428f9707d190b"
|
||||
],
|
||||
"windows_arm64": [
|
||||
"go1.25.0.windows-arm64.zip",
|
||||
"27bab004c72b3d7bd05a69b6ec0fc54a309b4b78cc569dd963d8b3ec28bfdb8c"
|
||||
]
|
||||
},
|
||||
"1.26.7": {
|
||||
"aix_ppc64": [
|
||||
"go1.26.7.aix-ppc64.tar.gz",
|
||||
"e5aed98bc83f569a374dbfd79d632b058e5130192fbd4c4ee0d4f6e3d9c101bb"
|
||||
],
|
||||
"darwin_amd64": [
|
||||
"go1.26.7.darwin-amd64.tar.gz",
|
||||
"92e8b34bff3c89ab16404c595669ac8cb004cc2f676dcbd1f5b87a6b8def3b47"
|
||||
],
|
||||
"darwin_arm64": [
|
||||
"go1.26.7.darwin-arm64.tar.gz",
|
||||
"020a1e8224811be75163e920bc77e0926a1390a6aeea19bdcf23f74b9d749f6d"
|
||||
],
|
||||
"dragonfly_amd64": [
|
||||
"go1.26.7.dragonfly-amd64.tar.gz",
|
||||
"d980dc9ecc48de09b2fa1765886abb8c7b0ad738bf8cc483b76019facc2df4d1"
|
||||
],
|
||||
"freebsd_386": [
|
||||
"go1.26.7.freebsd-386.tar.gz",
|
||||
"7eecfa4d6c126bcdedb8e16583ec672857e607659c672c60a9d645f8957da117"
|
||||
],
|
||||
"freebsd_amd64": [
|
||||
"go1.26.7.freebsd-amd64.tar.gz",
|
||||
"2ad37146fa8449907716b494dd268aeae6f79592b875915525c28c8c337ad32a"
|
||||
],
|
||||
"freebsd_arm": [
|
||||
"go1.26.7.freebsd-arm.tar.gz",
|
||||
"bc56379ed419cd93cf7002dcb95f554b3e3a2bd58d804182f8873e313a870b70"
|
||||
],
|
||||
"freebsd_arm64": [
|
||||
"go1.26.7.freebsd-arm64.tar.gz",
|
||||
"23d425a3a51876df8bf050f080b1ae50340048def689fbcc44c939fa23485ce0"
|
||||
],
|
||||
"illumos_amd64": [
|
||||
"go1.26.7.illumos-amd64.tar.gz",
|
||||
"be51df2411786e1fa6325461e509224a94c5e8d001da8e4548d9e028a53a3c22"
|
||||
],
|
||||
"linux_386": [
|
||||
"go1.26.7.linux-386.tar.gz",
|
||||
"5b6fad4a7fe8fa230c935625b67450305be95e2f4f976b731623f76b88fc4821"
|
||||
],
|
||||
"linux_amd64": [
|
||||
"go1.26.7.linux-amd64.tar.gz",
|
||||
"ffb5f8de10c62550dfddab66b36b57030721e0a44a3218e9e1181d7b59f121ca"
|
||||
],
|
||||
"linux_arm64": [
|
||||
"go1.26.7.linux-arm64.tar.gz",
|
||||
"5a4ec883379d51ee9ce1040d5e87f8d35e20387574dd8c947feb01eabc3c1b37"
|
||||
],
|
||||
"linux_armv6l": [
|
||||
"go1.26.7.linux-armv6l.tar.gz",
|
||||
"6a41557335d1d9fa9bfc7439cedcfd0e4df2fc83d916175b5f3eae4685f5fe3f"
|
||||
],
|
||||
"linux_loong64": [
|
||||
"go1.26.7.linux-loong64.tar.gz",
|
||||
"89b5e92446e719719e23db447a41860d7d573252bab0704c9acb09ad97e9eca1"
|
||||
],
|
||||
"linux_mips": [
|
||||
"go1.26.7.linux-mips.tar.gz",
|
||||
"fbdbf78b04494843fde47b15150e12adb7e2c0e2289eacbc18e6629a99604620"
|
||||
],
|
||||
"linux_mips64": [
|
||||
"go1.26.7.linux-mips64.tar.gz",
|
||||
"93b1360a29f4a71dbb6995f149b9312f67f5ce52197fea0042e9c9423809a496"
|
||||
],
|
||||
"linux_mips64le": [
|
||||
"go1.26.7.linux-mips64le.tar.gz",
|
||||
"402dd2bd57fb4c982ef0eccbb4f7209ae98a753856e99baf962f1ac54493d65d"
|
||||
],
|
||||
"linux_mipsle": [
|
||||
"go1.26.7.linux-mipsle.tar.gz",
|
||||
"967da58e88c45c401593a8552be9beedaa989a3484a3105850d2beb6ca9ed698"
|
||||
],
|
||||
"linux_ppc64": [
|
||||
"go1.26.7.linux-ppc64.tar.gz",
|
||||
"8feee58b3fa8d270343519d10d66736150e627d39aee937e6e889ba5445c8be9"
|
||||
],
|
||||
"linux_ppc64le": [
|
||||
"go1.26.7.linux-ppc64le.tar.gz",
|
||||
"22d3b362d557175fd16b79651cab0cad64f8aaaedca745f66d16f44d56bc5de1"
|
||||
],
|
||||
"linux_riscv64": [
|
||||
"go1.26.7.linux-riscv64.tar.gz",
|
||||
"21e1dc0e2f7dd9f80e0e94613fc324f1f99403b99997f9d8c5f80f8132fc642b"
|
||||
],
|
||||
"linux_s390x": [
|
||||
"go1.26.7.linux-s390x.tar.gz",
|
||||
"bc3308e05e9397958ad4aac453e3dc4565ba6d548e9ace0a9b4b165feb6382f2"
|
||||
],
|
||||
"netbsd_386": [
|
||||
"go1.26.7.netbsd-386.tar.gz",
|
||||
"c0a28bd30d8c07966cf7bc43fc6936866fb1a0e84ab4e983d4e8ca15edc1a4d1"
|
||||
],
|
||||
"netbsd_amd64": [
|
||||
"go1.26.7.netbsd-amd64.tar.gz",
|
||||
"dff0b16d129f5e70f3bb38ed98d467404b5b130c7c8b3fe6b074601855f2bcd5"
|
||||
],
|
||||
"netbsd_arm": [
|
||||
"go1.26.7.netbsd-arm.tar.gz",
|
||||
"36d15f8c5c5a5a048251b39ce67ed5a7ae2d072f1aa5c301cbde110670e824b2"
|
||||
],
|
||||
"netbsd_arm64": [
|
||||
"go1.26.7.netbsd-arm64.tar.gz",
|
||||
"b75802b366e5b60aa6cfded871f0a72abadf297c5a68c523c5857822a5b92d34"
|
||||
],
|
||||
"openbsd_386": [
|
||||
"go1.26.7.openbsd-386.tar.gz",
|
||||
"c26201688339b2a10bf980be2d64adfd3a383b31a164377b0123ad78bde6979c"
|
||||
],
|
||||
"openbsd_amd64": [
|
||||
"go1.26.7.openbsd-amd64.tar.gz",
|
||||
"562de088b844764029f59ff52e82218711a4b585ab7ae175b88eff53e051a8df"
|
||||
],
|
||||
"openbsd_arm": [
|
||||
"go1.26.7.openbsd-arm.tar.gz",
|
||||
"646e19cd3449aec767bf75622d368b02c73d529a5478a25f2a7e21148b1a4cb6"
|
||||
],
|
||||
"openbsd_arm64": [
|
||||
"go1.26.7.openbsd-arm64.tar.gz",
|
||||
"2045303632e112290e939dfd4678401109f612f7913f459e2d7d079e750723f5"
|
||||
],
|
||||
"openbsd_ppc64": [
|
||||
"go1.26.7.openbsd-ppc64.tar.gz",
|
||||
"23e89de68225dc41dd981601602e67fab0c4ca87af8f70a25131c06a301f9000"
|
||||
],
|
||||
"openbsd_riscv64": [
|
||||
"go1.26.7.openbsd-riscv64.tar.gz",
|
||||
"c0de2c6c353a582ca7682ed5a550056a8b5d59649260da4d1e327cf96684c822"
|
||||
],
|
||||
"plan9_386": [
|
||||
"go1.26.7.plan9-386.tar.gz",
|
||||
"14ae7414a2ea05d26e1fc499d9b372c7f8f17726c49a5222fa9063b0f752a22c"
|
||||
],
|
||||
"plan9_amd64": [
|
||||
"go1.26.7.plan9-amd64.tar.gz",
|
||||
"f9459b8137bdb81621d4e0cdba4c849a617c89c11a3088083ad3a8c97467c6a5"
|
||||
],
|
||||
"plan9_arm": [
|
||||
"go1.26.7.plan9-arm.tar.gz",
|
||||
"4f444bd2e0f8a08ba8799131dd3531bea8723bf96b8ffa0e0948936a3c4aa8f0"
|
||||
],
|
||||
"solaris_amd64": [
|
||||
"go1.26.7.solaris-amd64.tar.gz",
|
||||
"04b5b280e0e0de1b91d7da5e34801dbf75e5621615f80cfd9935091d673f1238"
|
||||
],
|
||||
"windows_386": [
|
||||
"go1.26.7.windows-386.zip",
|
||||
"59cf0b9814c41c960d70df3cd5360fda0793e5d2230737d58e009392181fb636"
|
||||
],
|
||||
"windows_amd64": [
|
||||
"go1.26.7.windows-amd64.zip",
|
||||
"f4f534a486e4bc3387fa18f08208f2f854b7aaea8a08f2a2d829a914a05abb11"
|
||||
],
|
||||
"windows_arm64": [
|
||||
"go1.26.7.windows-arm64.zip",
|
||||
"6f1b08de9e2dd94f69c52e524ab6834737275253291e8fd7f1c12ed4eceeda89"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"factsVersions": {}
|
||||
}
|
||||
60
Makefile
60
Makefile
|
|
@ -43,14 +43,16 @@ export PATH := $(GIT_WINDOWS_ROOT)/usr/bin;$(PATH)
|
|||
endif
|
||||
endif
|
||||
|
||||
.PHONY: all build doctor-build test test-icu-path test-full-cgo test-regression test-upgrade test-cross-version test-migration corpus-regen bench bench-quick clean clean-test-tmp install install-force help check-up-to-date fmt fmt-check check-testing-short
|
||||
.PHONY: all build doctor-build test test-icu-path test-full-cgo test-regression test-upgrade test-cross-version test-migration corpus-regen githooks-regen bench bench-quick clean clean-test-tmp install install-force help check-up-to-date fmt fmt-check check-testing-short
|
||||
.PHONY: ci-pr-core ci-pr-policy ci-pr-lint ci-complexity ci-complexity-diff ci-complexity-check ci-package-mcp ci-package-npm
|
||||
.PHONY: api-gen api-check
|
||||
.PHONY: bazel-sync bazel-sync-check
|
||||
|
||||
# Default target
|
||||
all: build
|
||||
|
||||
BUILD_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
|
||||
|
|
@ -103,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; \
|
||||
|
|
@ -127,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
|
||||
|
|
@ -263,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).
|
||||
|
|
@ -272,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.
|
||||
|
|
@ -288,6 +290,15 @@ corpus-regen:
|
|||
@echo "Regenerating contract corpus..."
|
||||
go test -tags "$(BUILD_TAGS)" ./cmd/bd/protocol -run TestCorpusGolden -corpus.update -count=1
|
||||
|
||||
# The tracked .githooks/* carry the managed section cmd/bd/hooks.go generates;
|
||||
# TestTrackedManagedHookSectionsMatchGenerator holds them byte-equal. Run this
|
||||
# after changing the generator or after bumping Version in cmd/bd/version.go
|
||||
# (the section markers carry the version), then commit the regenerated hooks
|
||||
# alongside it.
|
||||
githooks-regen:
|
||||
@echo "Regenerating managed sections in .githooks/*..."
|
||||
BD_UPDATE_HOOKS_GOLDEN=1 go test -tags "$(BUILD_TAGS)" ./cmd/bd -run TestTrackedManagedHookSectionsMatchGenerator -count=1
|
||||
|
||||
|
||||
# Run performance benchmarks against Dolt storage backend
|
||||
# Requires CGO and Dolt; generates CPU profile files
|
||||
|
|
@ -341,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"
|
||||
|
|
@ -366,8 +377,8 @@ 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
|
||||
@./scripts/check-doc-flags.sh ./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 "$(BUILD_DIR)/bd"
|
||||
@./scripts/check-doc-freshness.sh
|
||||
@go test -tags=gms_pure_go ./test/docsync
|
||||
|
||||
|
|
@ -399,6 +410,23 @@ diagrams-excalidraw:
|
|||
docs-dev:
|
||||
./mint.sh dev
|
||||
|
||||
# Bazel (side-by-side with the Go toolchain; `go build`/`go test` do not need
|
||||
# it). Regenerate BUILD.bazel files with gazelle and refresh the MODULE.bazel
|
||||
# use_repo list + MODULE.bazel.lock, then refresh the go_srcs filegroups that
|
||||
# source-scanning tests declare as data (tools/bazel/go_srcs.py). Run after
|
||||
# changing Go imports, go.mod, or packages.
|
||||
BAZEL ?= bazel
|
||||
bazel-sync:
|
||||
$(BAZEL) run //:gazelle
|
||||
python3 tools/bazel/go_srcs.py
|
||||
$(BAZEL) mod tidy
|
||||
|
||||
# Fail (printing a diff) when a go_srcs block that tools/bazel/go_srcs.py
|
||||
# manages is stale, e.g. after gazelle added a package under a scanned tree.
|
||||
# Needs no Bazel; scripts/bazel_policy_test.go runs the same check.
|
||||
bazel-sync-check:
|
||||
python3 tools/bazel/go_srcs.py --check
|
||||
|
||||
# Ensure -short is not used as an implicit CI tier boundary.
|
||||
check-testing-short:
|
||||
@./scripts/check-testing-short.sh
|
||||
|
|
@ -447,6 +475,8 @@ help:
|
|||
@echo " make check-docs - Validate docs against CLI flags"
|
||||
@echo " make api-gen - Regenerate HTTP API types from the OpenAPI spec"
|
||||
@echo " make api-check - OpenAPI drift gate (regenerate, diff-or-fail, spec tests)"
|
||||
@echo " make bazel-sync - Regenerate Bazel BUILD files and tidy MODULE.bazel (gazelle + mod tidy)"
|
||||
@echo " make bazel-sync-check - Fail if generated go_srcs Bazel filegroups are stale"
|
||||
@echo " make clean - Remove build artifacts and profile files"
|
||||
@echo " make clean-test-tmp - Sweep orphaned cmd/bd test temp dirs from \$$TMPDIR"
|
||||
@echo " make help - Show this help message"
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
```
|
||||
|
||||
|
|
|
|||
45
backend/BUILD.bazel
Normal file
45
backend/BUILD.bazel
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
load("@rules_go//go:def.bzl", "go_library", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "backend",
|
||||
srcs = [
|
||||
"backend.go",
|
||||
"errors.go",
|
||||
"types.go",
|
||||
],
|
||||
importpath = "github.com/steveyegge/beads/backend",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//internal/storage",
|
||||
"//internal/storage/backends",
|
||||
"//internal/types",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "backend_test",
|
||||
srcs = [
|
||||
"completeness_test.go",
|
||||
"errors_test.go",
|
||||
],
|
||||
data = [":go_srcs"],
|
||||
deps = [
|
||||
":backend",
|
||||
"//backend/conformance",
|
||||
"//internal/storage",
|
||||
"//internal/testutil/bazeltest",
|
||||
],
|
||||
)
|
||||
|
||||
# --- begin go_srcs (managed by tools/bazel/go_srcs.py; run `make bazel-sync`) ---
|
||||
|
||||
filegroup(
|
||||
name = "go_srcs",
|
||||
srcs = glob(
|
||||
["**/*.go"],
|
||||
allow_empty = True,
|
||||
),
|
||||
visibility = ["//:__subpackages__"],
|
||||
)
|
||||
|
||||
# --- end go_srcs ---
|
||||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"go/parser"
|
||||
"go/token"
|
||||
"io/fs"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"sort"
|
||||
|
|
@ -14,6 +13,7 @@ import (
|
|||
|
||||
"github.com/steveyegge/beads/backend"
|
||||
"github.com/steveyegge/beads/backend/conformance"
|
||||
"github.com/steveyegge/beads/internal/testutil/bazeltest"
|
||||
)
|
||||
|
||||
const internalPrefix = "github.com/steveyegge/beads/internal/"
|
||||
|
|
@ -77,7 +77,7 @@ func publicAliases(t *testing.T) map[string]bool {
|
|||
if !ok {
|
||||
t.Fatal("runtime.Caller failed")
|
||||
}
|
||||
dir := filepath.Dir(thisFile)
|
||||
dir := bazeltest.CallerDir(thisFile, "backend")
|
||||
fset := token.NewFileSet()
|
||||
pkgs, err := parser.ParseDir(fset, dir, func(fi fs.FileInfo) bool {
|
||||
return !strings.HasSuffix(fi.Name(), "_test.go")
|
||||
|
|
|
|||
112
backend/conformance/BUILD.bazel
Normal file
112
backend/conformance/BUILD.bazel
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
load("@rules_go//go:def.bzl", "go_library", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "conformance",
|
||||
srcs = [
|
||||
"audit.go",
|
||||
"audit_config_metadata_slots_repomtime.go",
|
||||
"audit_dependencies_readiness.go",
|
||||
"audit_issue-lifecycle.go",
|
||||
"audit_labels-comments-events.go",
|
||||
"audit_molecule_wisp_batch_iter.go",
|
||||
"audit_search-counts-stats.go",
|
||||
"batch_apply_contract.go",
|
||||
"batch_closer_contract.go",
|
||||
"batch_creator_contract.go",
|
||||
"blocked_state.go",
|
||||
"blocking_annotator_contract.go",
|
||||
"bootstrapper_contract.go",
|
||||
"claim.go",
|
||||
"claimer_contract.go",
|
||||
"commenter_contract.go",
|
||||
"conformance.go",
|
||||
"counter_contract.go",
|
||||
"cross_record_invariant_contract.go",
|
||||
"cycle_detector_contract.go",
|
||||
"deleter_contract.go",
|
||||
"dependency_editor_contract.go",
|
||||
"dualwrite_history_contract.go",
|
||||
"edge_reader_contract.go",
|
||||
"expected_revision_contract.go",
|
||||
"graph_counter_contract.go",
|
||||
"history_matching.go",
|
||||
"importer_contract.go",
|
||||
"issue_operations_contract.go",
|
||||
"issue_operations_staging.go",
|
||||
"journal_contract.go",
|
||||
"lifecycle_close_reopen_contract.go",
|
||||
"lifecycle_create_contract.go",
|
||||
"lifecycle_update_contract.go",
|
||||
"memories_contract.go",
|
||||
"metadata_cas_contract.go",
|
||||
"portable.go",
|
||||
"querier_contract.go",
|
||||
"reader_contract.go",
|
||||
"ready_claimer_contract.go",
|
||||
"ready_counter_contract.go",
|
||||
"reclaim_scope.go",
|
||||
"relations_contract.go",
|
||||
"releaser_contract.go",
|
||||
"retention_epoch_contract.go",
|
||||
"role_bundle.go",
|
||||
"role_bundle_cases.go",
|
||||
"search_paging.go",
|
||||
"stats_reporter_contract.go",
|
||||
"sweeper_contract.go",
|
||||
"transaction_parity.go",
|
||||
"tree_walker_contract.go",
|
||||
"version_reconciler_contract.go",
|
||||
"workspaceconfig_contract.go",
|
||||
],
|
||||
importpath = "github.com/steveyegge/beads/backend/conformance",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//internal/storage",
|
||||
"//internal/storage/issueops",
|
||||
"//internal/storage/kvkeys",
|
||||
"//internal/storage/sqlbuild",
|
||||
"//internal/types",
|
||||
"//issueops",
|
||||
"//journalops",
|
||||
"//memoryops",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "conformance_test",
|
||||
srcs = [
|
||||
"role_bundle_test.go",
|
||||
"role_coverage_gate_test.go",
|
||||
"role_coverage_scan_test.go",
|
||||
"versioned_history_wiring_test.go",
|
||||
],
|
||||
data = [
|
||||
":go_srcs",
|
||||
"//beadserrors:go_srcs",
|
||||
"//internal/types:go_srcs",
|
||||
"//issueops:go_srcs",
|
||||
"//journalops:go_srcs",
|
||||
"//memoryops:go_srcs",
|
||||
],
|
||||
embed = [":conformance"],
|
||||
deps = [
|
||||
"//internal/storage",
|
||||
"//internal/testutil/bazeltest",
|
||||
"//issueops",
|
||||
"//journalops",
|
||||
"//memoryops",
|
||||
],
|
||||
)
|
||||
|
||||
# --- begin go_srcs (managed by tools/bazel/go_srcs.py; run `make bazel-sync`) ---
|
||||
|
||||
filegroup(
|
||||
name = "go_srcs",
|
||||
srcs = glob(
|
||||
["**/*.go"],
|
||||
allow_empty = True,
|
||||
),
|
||||
visibility = ["//:__subpackages__"],
|
||||
)
|
||||
|
||||
# --- end go_srcs ---
|
||||
|
|
@ -657,6 +657,11 @@ var roleContractCases = []roleContract{
|
|||
RunSweeperEmptyMatchIsZeroAndNil,
|
||||
RunSweeperRecordsExactlyOneHistoryEntry,
|
||||
RunSweeperDoesNotMutateTheCallerRequest,
|
||||
RunSweeperWispsPlaneClearsTheWholeWispsTable,
|
||||
RunSweeperWispsPlaneRequiresAFilter,
|
||||
RunSweeperProtectsLiveDependents,
|
||||
RunSweeperProtectsLiveDependentsAcrossPlanes,
|
||||
RunSweeperLimitTakesTheOldestClosedFirst,
|
||||
),
|
||||
|
||||
roleCases("TreeWalker", "TreeWalker()", oncePerRole,
|
||||
|
|
|
|||
|
|
@ -9,12 +9,13 @@ import (
|
|||
"io/fs"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/testutil/bazeltest"
|
||||
)
|
||||
|
||||
// TestRoleContractCasesCoverEveryContractCase is the drift guard on the role
|
||||
|
|
@ -314,7 +315,7 @@ func TestRoleCasesFailsWhenAFactoryReturnsNil(t *testing.T) {
|
|||
func runProbeChild(t *testing.T, mode string) (string, error) {
|
||||
t.Helper()
|
||||
cmd := exec.Command(os.Args[0], "-test.run=^"+t.Name()+"$", "-test.v")
|
||||
cmd.Env = append(os.Environ(), roleBundleProbeEnv+"="+mode)
|
||||
cmd.Env = append(bazeltest.ShardFreeEnv(os.Environ()), roleBundleProbeEnv+"="+mode)
|
||||
out, err := cmd.CombinedOutput()
|
||||
return string(out), err
|
||||
}
|
||||
|
|
@ -333,7 +334,7 @@ func parseRoleContractCases(t *testing.T) []string {
|
|||
t.Fatal("runtime.Caller failed")
|
||||
}
|
||||
fset := token.NewFileSet()
|
||||
pkgs, err := parser.ParseDir(fset, filepath.Dir(thisFile), func(fi fs.FileInfo) bool {
|
||||
pkgs, err := parser.ParseDir(fset, bazeltest.CallerDir(thisFile, "backend/conformance"), func(fi fs.FileInfo) bool {
|
||||
return !strings.HasSuffix(fi.Name(), "_test.go")
|
||||
}, 0)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/testutil/bazeltest"
|
||||
"github.com/steveyegge/beads/issueops"
|
||||
"github.com/steveyegge/beads/journalops"
|
||||
"github.com/steveyegge/beads/memoryops"
|
||||
|
|
@ -59,6 +60,9 @@ var errorType = reflect.TypeOf((*error)(nil)).Elem()
|
|||
// repoRoot locates the module root from this file's own path, so the gate
|
||||
// finds the facade packages without depending on the working directory.
|
||||
func repoRoot() (string, error) {
|
||||
if root := bazeltest.OverrideRoot(); root != "" {
|
||||
return root, nil
|
||||
}
|
||||
_, thisFile, _, ok := runtime.Caller(0)
|
||||
if !ok {
|
||||
return "", errors.New("runtime.Caller failed")
|
||||
|
|
|
|||
|
|
@ -89,6 +89,11 @@ type SweeperFixture struct {
|
|||
// by hand. A nil Exec means "this backend cannot seed raw rows", and the
|
||||
// case that needs it SKIPS with that reason rather than passing quietly.
|
||||
Exec func(ctx context.Context, statements []SQLStatement) error
|
||||
// AddDependencies wires edges between seeded rows, filled from the
|
||||
// backend's DependencyEditor role so each adapter routes an edge to the
|
||||
// dependency table of its source's plane itself. The live-dependent case
|
||||
// needs it; a nil hook SKIPS that case with the reason.
|
||||
AddDependencies func(ctx context.Context, req publicops.AddDependenciesRequest) error
|
||||
}
|
||||
|
||||
// sweeperClosedAt is the stamp every seeded candidate carries, and
|
||||
|
|
@ -345,7 +350,7 @@ func RunSweeperDryRunChangesNothing(t *testing.T, ctx context.Context, fixture S
|
|||
IDPattern: sweeperPattern(fixture, "dry"),
|
||||
}
|
||||
|
||||
preview := sweeperSweep(t, ctx, fixture, sweeperWithDryRun(request, true))
|
||||
preview := sweeperSweep(t, ctx, fixture, sweeperAsDryRun(request))
|
||||
if !preview.DryRun {
|
||||
t.Error("preview.DryRun = false; the result must echo the request it answered")
|
||||
}
|
||||
|
|
@ -356,7 +361,7 @@ func RunSweeperDryRunChangesNothing(t *testing.T, ctx context.Context, fixture S
|
|||
|
||||
// A second preview: a dry run that had deleted anything reports a smaller
|
||||
// number here.
|
||||
if again := sweeperSweep(t, ctx, fixture, sweeperWithDryRun(request, true)); again.Swept != preview.Swept {
|
||||
if again := sweeperSweep(t, ctx, fixture, sweeperAsDryRun(request)); again.Swept != preview.Swept {
|
||||
t.Fatalf("second preview Swept = %d, first = %d: the first preview changed the store", again.Swept, preview.Swept)
|
||||
}
|
||||
|
||||
|
|
@ -556,7 +561,7 @@ func RunSweeperRecordsExactlyOneHistoryEntry(t *testing.T, ctx context.Context,
|
|||
}
|
||||
|
||||
before := sweeperHistory(t, ctx, fixture)
|
||||
sweeperSweep(t, ctx, fixture, sweeperWithDryRun(request, true))
|
||||
sweeperSweep(t, ctx, fixture, sweeperAsDryRun(request))
|
||||
if after := sweeperHistory(t, ctx, fixture); after != before {
|
||||
t.Errorf("history went %d -> %d across a DRY RUN, want no entry at all", before, after)
|
||||
}
|
||||
|
|
@ -609,6 +614,230 @@ func RunSweeperDoesNotMutateTheCallerRequest(t *testing.T, ctx context.Context,
|
|||
}
|
||||
}
|
||||
|
||||
// RunSweeperWispsPlaneClearsTheWholeWispsTable pins issueops.SweepWispsPlane:
|
||||
// the selection is the wisps TABLE, so a closed no-history bead — durable-tier,
|
||||
// and left alone by SweepEphemeral (RunSweeperLeavesNoHistoryBeadsToTheDurableTier)
|
||||
// — goes with the closed ephemeral wisp, while a closed issues-plane row the
|
||||
// same pattern admits stays.
|
||||
func RunSweeperWispsPlaneClearsTheWholeWispsTable(t *testing.T, ctx context.Context, fixture SweeperFixture) {
|
||||
t.Helper()
|
||||
wisp := sweeperSeedClosedIssue(t, ctx, fixture, "plane", true)
|
||||
durable := sweeperSeedClosedIssue(t, ctx, fixture, "plane", false)
|
||||
noHistory := sweeperIssue(fixture, "plane", "nohist", false)
|
||||
noHistory.NoHistory = true
|
||||
if err := fixture.CreateWisp(ctx, noHistory, "sweeper-seed"); err != nil {
|
||||
t.Fatalf("seeding %s: %v", noHistory.ID, err)
|
||||
}
|
||||
pinned := sweeperSeed(t, ctx, fixture, sweeperIssue(fixture, "plane", "pinned", true), func(issue *types.Issue) {
|
||||
issue.Pinned = true
|
||||
})
|
||||
|
||||
request := publicops.SweepRequest{
|
||||
Tier: publicops.SweepWispsPlane,
|
||||
IDPattern: sweeperPattern(fixture, "plane"),
|
||||
ClosedBefore: &sweeperCutoff,
|
||||
}
|
||||
preview := sweeperSweep(t, ctx, fixture, sweeperAsDryRun(request))
|
||||
if preview.Swept != 2 {
|
||||
t.Fatalf("dry-run Swept = %d, want 2 (the ephemeral wisp and the no-history bead)", preview.Swept)
|
||||
}
|
||||
sweeperAssertWispRows(t, ctx, fixture, 3, wisp, noHistory.ID, pinned)
|
||||
|
||||
result := sweeperSweep(t, ctx, fixture, request)
|
||||
if result.Swept != 2 {
|
||||
t.Errorf("Swept = %d, want 2 (the ephemeral wisp and the no-history bead)", result.Swept)
|
||||
}
|
||||
if result.Skipped.Pinned != 1 {
|
||||
t.Errorf("Skipped.Pinned = %d, want 1 — the plane selector does not override pinning", result.Skipped.Pinned)
|
||||
}
|
||||
sweeperAssertWispRows(t, ctx, fixture, 0, wisp, noHistory.ID)
|
||||
sweeperAssertWispRows(t, ctx, fixture, 1, pinned)
|
||||
sweeperAssertIssueRows(t, ctx, fixture, 1, durable)
|
||||
}
|
||||
|
||||
// RunSweeperWispsPlaneRequiresAFilter pins that the wisps-plane tier carries
|
||||
// the durable tier's require-a-filter gate: it reaches no-history beads, which
|
||||
// are durable-tier. The refusal is asserted with its effect, as the durable
|
||||
// case does.
|
||||
func RunSweeperWispsPlaneRequiresAFilter(t *testing.T, ctx context.Context, fixture SweeperFixture) {
|
||||
t.Helper()
|
||||
id := sweeperSeedClosedIssue(t, ctx, fixture, "planegate", true)
|
||||
|
||||
result, err := fixture.Sweeper.Sweep(ctx, publicops.SweepRequest{Tier: publicops.SweepWispsPlane})
|
||||
if !errors.Is(err, publicops.ErrValidation) {
|
||||
t.Fatalf("Sweep(wisps-plane, no cutoff, no pattern) error = %v, want ErrValidation", err)
|
||||
}
|
||||
if result.Swept != 0 {
|
||||
t.Errorf("refused sweep reported Swept = %d, want 0", result.Swept)
|
||||
}
|
||||
sweeperAssertWispRows(t, ctx, fixture, 1, id)
|
||||
}
|
||||
|
||||
// RunSweeperProtectsLiveDependents pins issueops.SweepRequest.ProtectLiveDependents:
|
||||
// a closed row a LIVE row depends on through parent-child, tracks or blocks is
|
||||
// held back and counted, while a closed row reached only by a non-structural
|
||||
// edge, or only by a dependent that is itself closed, is swept.
|
||||
//
|
||||
// The live sources carry three different not-done statuses (open,
|
||||
// in_progress, hooked), because "live" is the not-done set and not "open".
|
||||
// It runs on the wisps-plane tier with a cutoff — the request an
|
||||
// orchestrator's retention sweep sends — after proving on a dry run that the
|
||||
// same rows ARE candidates without the protection.
|
||||
func RunSweeperProtectsLiveDependents(t *testing.T, ctx context.Context, fixture SweeperFixture) {
|
||||
t.Helper()
|
||||
if fixture.AddDependencies == nil {
|
||||
t.Skip("fixture has no AddDependencies hook; cannot wire the edges this case needs")
|
||||
}
|
||||
live := func(name string, status types.Status) string {
|
||||
issue := sweeperIssue(fixture, "live", name, true)
|
||||
issue.Status = status
|
||||
issue.ClosedAt = nil
|
||||
return sweeperSeed(t, ctx, fixture, issue, nil)
|
||||
}
|
||||
closed := func(name string) string {
|
||||
return sweeperSeed(t, ctx, fixture, sweeperIssue(fixture, "live", name, true), nil)
|
||||
}
|
||||
|
||||
parent := closed("parent")
|
||||
openChild := live("child-open", types.StatusOpen)
|
||||
tracked := closed("tracked")
|
||||
convoy := live("convoy", types.StatusInProgress)
|
||||
blocker := closed("blocker")
|
||||
hooked := live("hooked", types.StatusHooked)
|
||||
related := closed("related")
|
||||
relater := live("relater", types.StatusOpen)
|
||||
doneParent := closed("done-parent")
|
||||
doneChild := closed("done-child")
|
||||
|
||||
if err := fixture.AddDependencies(ctx, publicops.AddDependenciesRequest{
|
||||
Actor: "sweeper-seed",
|
||||
Edges: []publicops.DependencyEdge{
|
||||
{IssueID: openChild, DependsOnID: parent, Type: publicops.DepParentChild},
|
||||
{IssueID: convoy, DependsOnID: tracked, Type: publicops.DepTracks},
|
||||
{IssueID: hooked, DependsOnID: blocker, Type: publicops.DepBlocks},
|
||||
{IssueID: relater, DependsOnID: related, Type: publicops.DepRelated},
|
||||
{IssueID: doneChild, DependsOnID: doneParent, Type: publicops.DepParentChild},
|
||||
},
|
||||
}); err != nil {
|
||||
t.Fatalf("wiring dependencies: %v", err)
|
||||
}
|
||||
|
||||
request := publicops.SweepRequest{
|
||||
Tier: publicops.SweepWispsPlane,
|
||||
IDPattern: sweeperPattern(fixture, "live"),
|
||||
ClosedBefore: &sweeperCutoff,
|
||||
}
|
||||
unprotected := sweeperSweep(t, ctx, fixture, sweeperAsDryRun(request))
|
||||
if unprotected.Swept != 6 || unprotected.Skipped.LiveDependent != 0 {
|
||||
t.Fatalf("unprotected dry run: Swept = %d, LiveDependent = %d; want 6 and 0 — "+
|
||||
"the protection must be asked for", unprotected.Swept, unprotected.Skipped.LiveDependent)
|
||||
}
|
||||
|
||||
request.ProtectLiveDependents = true
|
||||
result := sweeperSweep(t, ctx, fixture, request)
|
||||
if result.Skipped.LiveDependent != 3 {
|
||||
t.Errorf("Skipped.LiveDependent = %d, want 3 (the parent, the tracked bead and the blocker)",
|
||||
result.Skipped.LiveDependent)
|
||||
}
|
||||
if result.Swept != 3 {
|
||||
t.Errorf("Swept = %d, want 3 (the related-only bead and the closed parent/child pair)", result.Swept)
|
||||
}
|
||||
sweeperAssertWispRows(t, ctx, fixture, 3, parent, tracked, blocker)
|
||||
sweeperAssertWispRows(t, ctx, fixture, 0, related, doneParent, doneChild)
|
||||
sweeperAssertWispRows(t, ctx, fixture, 4, openChild, convoy, hooked, relater)
|
||||
}
|
||||
|
||||
// RunSweeperProtectsLiveDependentsAcrossPlanes pins that the live-dependent
|
||||
// protection reads BOTH dependency tables: a closed wisp that a live DURABLE
|
||||
// (issues-table) bead depends on through parent-child, tracks or blocks is
|
||||
// kept, whatever not-done status the durable source carries.
|
||||
func RunSweeperProtectsLiveDependentsAcrossPlanes(t *testing.T, ctx context.Context, fixture SweeperFixture) {
|
||||
t.Helper()
|
||||
if fixture.AddDependencies == nil {
|
||||
t.Skip("fixture has no AddDependencies hook; cannot wire the edges this case needs")
|
||||
}
|
||||
durableLive := func(name string, status types.Status) string {
|
||||
issue := sweeperIssue(fixture, "xplane", name, false)
|
||||
issue.Status = status
|
||||
issue.ClosedAt = nil
|
||||
return sweeperSeed(t, ctx, fixture, issue, nil)
|
||||
}
|
||||
closedWisp := func(name string) string {
|
||||
return sweeperSeed(t, ctx, fixture, sweeperIssue(fixture, "xplane", name, true), nil)
|
||||
}
|
||||
|
||||
parent := closedWisp("parent")
|
||||
tracked := closedWisp("tracked")
|
||||
blocker := closedWisp("blocker")
|
||||
loose := closedWisp("loose")
|
||||
child := durableLive("child", types.StatusOpen)
|
||||
convoy := durableLive("convoy", types.StatusInProgress)
|
||||
waiter := durableLive("waiter", types.StatusDeferred)
|
||||
|
||||
if err := fixture.AddDependencies(ctx, publicops.AddDependenciesRequest{
|
||||
Actor: "sweeper-seed",
|
||||
Edges: []publicops.DependencyEdge{
|
||||
{IssueID: child, DependsOnID: parent, Type: publicops.DepParentChild},
|
||||
{IssueID: convoy, DependsOnID: tracked, Type: publicops.DepTracks},
|
||||
{IssueID: waiter, DependsOnID: blocker, Type: publicops.DepBlocks},
|
||||
},
|
||||
}); err != nil {
|
||||
t.Fatalf("wiring cross-plane dependencies: %v", err)
|
||||
}
|
||||
|
||||
result := sweeperSweep(t, ctx, fixture, publicops.SweepRequest{
|
||||
Tier: publicops.SweepWispsPlane,
|
||||
IDPattern: sweeperPattern(fixture, "xplane"),
|
||||
ClosedBefore: &sweeperCutoff,
|
||||
ProtectLiveDependents: true,
|
||||
})
|
||||
if result.Skipped.LiveDependent != 3 || result.Swept != 1 {
|
||||
t.Errorf("Swept = %d, LiveDependent = %d; want 1 (the unlinked wisp) and 3", result.Swept, result.Skipped.LiveDependent)
|
||||
}
|
||||
sweeperAssertWispRows(t, ctx, fixture, 3, parent, tracked, blocker)
|
||||
sweeperAssertWispRows(t, ctx, fixture, 0, loose)
|
||||
sweeperAssertIssueRows(t, ctx, fixture, 3, child, convoy, waiter)
|
||||
}
|
||||
|
||||
// RunSweeperLimitTakesTheOldestClosedFirst pins issueops.SweepRequest.Limit:
|
||||
// one call deletes at most Limit rows, oldest closed_at first, and reports the
|
||||
// rest as Remaining; the next call picks up where it stopped.
|
||||
func RunSweeperLimitTakesTheOldestClosedFirst(t *testing.T, ctx context.Context, fixture SweeperFixture) {
|
||||
t.Helper()
|
||||
seed := func(name string, closed time.Time) string {
|
||||
return sweeperSeed(t, ctx, fixture, sweeperIssue(fixture, "limit", name, true), func(issue *types.Issue) {
|
||||
issue.ClosedAt = &closed
|
||||
})
|
||||
}
|
||||
newest := seed("newest", sweeperClosedAt)
|
||||
middle := seed("middle", sweeperClosedAt.Add(-24*time.Hour))
|
||||
oldest := seed("oldest", sweeperClosedAt.Add(-48*time.Hour))
|
||||
|
||||
request := publicops.SweepRequest{
|
||||
Tier: publicops.SweepEphemeral,
|
||||
IDPattern: sweeperPattern(fixture, "limit"),
|
||||
Limit: 2,
|
||||
}
|
||||
first := sweeperSweep(t, ctx, fixture, request)
|
||||
if first.Swept != 2 || first.Remaining != 1 {
|
||||
t.Fatalf("first limited sweep: Swept = %d, Remaining = %d; want 2 and 1", first.Swept, first.Remaining)
|
||||
}
|
||||
sweeperAssertWispRows(t, ctx, fixture, 0, oldest, middle)
|
||||
sweeperAssertWispRows(t, ctx, fixture, 1, newest)
|
||||
|
||||
second := sweeperSweep(t, ctx, fixture, request)
|
||||
if second.Swept != 1 || second.Remaining != 0 {
|
||||
t.Fatalf("second limited sweep: Swept = %d, Remaining = %d; want 1 and 0", second.Swept, second.Remaining)
|
||||
}
|
||||
sweeperAssertWispRows(t, ctx, fixture, 0, newest)
|
||||
|
||||
if _, err := fixture.Sweeper.Sweep(ctx, publicops.SweepRequest{
|
||||
Tier: publicops.SweepEphemeral, IDPattern: sweeperPattern(fixture, "limit"), Limit: -1,
|
||||
}); !errors.Is(err, publicops.ErrValidation) {
|
||||
t.Fatalf("negative Limit error = %v, want ErrValidation", err)
|
||||
}
|
||||
}
|
||||
|
||||
// --- fixture helpers -------------------------------------------------------
|
||||
|
||||
// sweeperPattern is the glob that scopes one case's ids: a sweep is asked of a
|
||||
|
|
@ -664,8 +893,8 @@ func sweeperSeedOpen(t *testing.T, ctx context.Context, fixture SweeperFixture,
|
|||
return sweeperSeed(t, ctx, fixture, issue, nil)
|
||||
}
|
||||
|
||||
func sweeperWithDryRun(request publicops.SweepRequest, dryRun bool) publicops.SweepRequest {
|
||||
request.DryRun = dryRun
|
||||
func sweeperAsDryRun(request publicops.SweepRequest) publicops.SweepRequest {
|
||||
request.DryRun = true
|
||||
return request
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
21
beadserrors/BUILD.bazel
Normal file
21
beadserrors/BUILD.bazel
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
load("@rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "beadserrors",
|
||||
srcs = ["errors.go"],
|
||||
importpath = "github.com/steveyegge/beads/beadserrors",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
# --- begin go_srcs (managed by tools/bazel/go_srcs.py; run `make bazel-sync`) ---
|
||||
|
||||
filegroup(
|
||||
name = "go_srcs",
|
||||
srcs = glob(
|
||||
["**/*.go"],
|
||||
allow_empty = True,
|
||||
),
|
||||
visibility = ["//:__subpackages__"],
|
||||
)
|
||||
|
||||
# --- end go_srcs ---
|
||||
262
checks.nix
Normal file
262
checks.nix
Normal file
|
|
@ -0,0 +1,262 @@
|
|||
# Flake checks. Run all with `nix flake check`; one with
|
||||
# `nix build .#checks.<system>.<name> -L`.
|
||||
pkgs:
|
||||
let
|
||||
inherit (pkgs) lib;
|
||||
|
||||
# hook-timeout-backends: run the tracked hook shims against REAL timeout
|
||||
# implementations.
|
||||
#
|
||||
# cmd/bd/hooks_timeout_process_test.go pins the shim's selection logic with
|
||||
# scripted helpers, and TestTrackedManagedHookSectionsMatchGenerator holds
|
||||
# the tracked .githooks/* byte-equal to the generator. This check closes the
|
||||
# remaining gap — what the helpers on real hosts actually do — by running the
|
||||
# tracked sections against the binaries themselves. That is where the
|
||||
# surprises live: uutils prints a different banner (GH#5541); busybox exits
|
||||
# 143 on expiry, not 124, so allowlisting it as-is would turn every timeout
|
||||
# into a failed hook; toybox exits 125 from --version.
|
||||
#
|
||||
# The matrix is derived from a model of the contract, so a change to the
|
||||
# allowlist is one line here and the binaries either agree or they do not.
|
||||
# Reading .githooks/* rather than building bd keeps this at about one
|
||||
# deadline of wall time and independent of the Go build.
|
||||
#
|
||||
# Each case: one hook, one shell (the `sh`s a `#!/usr/bin/env sh` hook meets
|
||||
# in the wild), a PATH of exactly one timeout implementation — under the
|
||||
# name `timeout`, or for the multicall ones also under `gtimeout` alone —
|
||||
# plus optionally perl, BEADS_HOOK_TIMEOUT=1, and a fake `bd` that blocks on a held-open fifo
|
||||
# until a helper kills it. The fake records the signal that killed it, which
|
||||
# is how the check asserts the backend and not just "it finished":
|
||||
# coreutils backend → TERM from timeout, shim reports the deadline, exit 0
|
||||
# perl backend → ALRM from perl's alarm, same report, exit 0
|
||||
# no backend → the fake returns at once; shim warns it is running
|
||||
# without a deadline, exit 0
|
||||
# A non-zero hook exit blocks the user's push, so every case asserts exit 0.
|
||||
# No clock is involved: if nothing kills the fake, the harness's own
|
||||
# `timeout 10` (on its full PATH, not the shim's) fails the case.
|
||||
|
||||
# The identity allowlist in cmd/bd/hooks.go, as data.
|
||||
allowlisted = [
|
||||
"gnu-coreutils"
|
||||
"uutils-coreutils"
|
||||
];
|
||||
|
||||
implementations = {
|
||||
gnu-coreutils = pkgs.coreutils;
|
||||
uutils-coreutils = pkgs.uutils-coreutils-noprefix;
|
||||
none = null;
|
||||
}
|
||||
// lib.optionalAttrs pkgs.stdenv.isLinux {
|
||||
busybox = pkgs.busybox;
|
||||
toybox = pkgs.toybox;
|
||||
};
|
||||
|
||||
# The shim probes `timeout` first and `gtimeout` second (Homebrew's prefixed
|
||||
# GNU coreutils on macOS). Whether a helper is accepted under the second name
|
||||
# depends on what its banner does with argv[0]. The multicall implementations
|
||||
# dispatch on it and then print the CANONICAL utility name: uutils'
|
||||
# src/bin/coreutils.rs matches `argv[0].ends_with(<util>)`, so `gtimeout`
|
||||
# (or `mytimeout`) is `timeout` to it and reports "timeout (uutils
|
||||
# coreutils) <version>" — accepted (measured on 0.8.0, this flake's
|
||||
# nixos-25.11 pin, and on 0.11.0); busybox and toybox know no `gtimeout`
|
||||
# applet and fail the probe outright — rejected either way. These variants put each multicall on PATH under the name `gtimeout`
|
||||
# ONLY, so the second candidate is the one that runs. GNU has no variant:
|
||||
# nixpkgs' coreutils is a single-binary multicall that refuses a name it does
|
||||
# not know ("coreutils: unknown program 'gtimeout'"), while Homebrew's
|
||||
# gtimeout is a separate binary whose banner is the fixed "timeout (GNU
|
||||
# coreutils) 9.11" — GNU is immune by construction, not by measurement here.
|
||||
asGtimeout =
|
||||
impl: pkg:
|
||||
pkgs.runCommand "${impl}-as-gtimeout" { } ''
|
||||
mkdir -p "$out/bin"
|
||||
ln -s ${pkg}/bin/timeout "$out/bin/gtimeout"
|
||||
'';
|
||||
|
||||
# What goes on a case's PATH: every implementation as itself, and the
|
||||
# multicalls once more under the other candidate name. `impl` is what the
|
||||
# model reasons about; `label` is what the case is called.
|
||||
installs = lib.concatLists (
|
||||
lib.mapAttrsToList (
|
||||
impl: pkg:
|
||||
[
|
||||
{
|
||||
inherit impl;
|
||||
label = impl;
|
||||
dirs = lib.optional (pkg != null) "${pkg}/bin";
|
||||
}
|
||||
]
|
||||
++ lib.optional (pkg != null && impl != "gnu-coreutils") {
|
||||
inherit impl;
|
||||
label = "${impl}-as-gtimeout";
|
||||
dirs = [ "${asGtimeout impl pkg}/bin" ];
|
||||
}
|
||||
) implementations
|
||||
);
|
||||
|
||||
shells = {
|
||||
dash = "${pkgs.dash}/bin/dash";
|
||||
bash = "${pkgs.bash}/bin/bash";
|
||||
}
|
||||
// lib.optionalAttrs pkgs.stdenv.isLinux {
|
||||
busybox-ash = "${pkgs.busybox}/bin/sh";
|
||||
};
|
||||
|
||||
hooks = [
|
||||
"pre-commit"
|
||||
"post-merge"
|
||||
"pre-push"
|
||||
"post-checkout"
|
||||
"prepare-commit-msg"
|
||||
];
|
||||
|
||||
backendFor =
|
||||
impl: withPerl:
|
||||
if lib.elem impl allowlisted then
|
||||
"coreutils"
|
||||
else if withPerl then
|
||||
"perl"
|
||||
else
|
||||
"none";
|
||||
|
||||
# One `run_case` line per point in the matrix, all backgrounded.
|
||||
cases = lib.concatMap (
|
||||
install:
|
||||
lib.concatMap
|
||||
(
|
||||
withPerl:
|
||||
lib.concatLists (
|
||||
lib.mapAttrsToList (
|
||||
shellName: shell:
|
||||
map (hook: {
|
||||
name = "${hook}/${shellName}/${install.label}${lib.optionalString withPerl "+perl"}";
|
||||
inherit hook shell;
|
||||
backend = backendFor install.impl withPerl;
|
||||
path = install.dirs ++ lib.optional withPerl "${pkgs.perl}/bin";
|
||||
}) hooks
|
||||
) shells
|
||||
)
|
||||
)
|
||||
[
|
||||
false
|
||||
true
|
||||
]
|
||||
) installs;
|
||||
|
||||
caseLine =
|
||||
c:
|
||||
"run_case ${
|
||||
lib.escapeShellArgs [
|
||||
c.name
|
||||
c.hook
|
||||
c.backend
|
||||
c.shell
|
||||
]
|
||||
} ${lib.escapeShellArgs c.path} &\n";
|
||||
|
||||
trackedHooks = lib.fileset.toSource {
|
||||
root = ./.;
|
||||
fileset = ./.githooks;
|
||||
};
|
||||
in
|
||||
{
|
||||
hook-timeout-backends =
|
||||
pkgs.runCommand "bd-hook-timeout-backends"
|
||||
{
|
||||
# Only .githooks/* is an input: nothing else in the repo changes what
|
||||
# this check measures.
|
||||
githooks = "${trackedHooks}/.githooks";
|
||||
}
|
||||
''
|
||||
# 1. Shims under test: the managed section of each tracked hook, as
|
||||
# bd installs it into a fresh repo (shebang + section).
|
||||
shims="$TMPDIR/shims"
|
||||
mkdir -p "$shims"
|
||||
for hook in ${lib.escapeShellArgs hooks}; do
|
||||
{
|
||||
echo '#!/usr/bin/env sh'
|
||||
sed -n '/^# --- BEGIN BEADS INTEGRATION/,/^# --- END BEADS INTEGRATION/p' "$githooks/$hook"
|
||||
} > "$shims/$hook"
|
||||
grep -q 'bd hooks run' "$shims/$hook" || { echo "no managed section in .githooks/$hook"; exit 1; }
|
||||
done
|
||||
|
||||
# 2. The fake bd the shim will find on its restricted PATH. It blocks
|
||||
# until killed and records the signal, re-raising it so it dies the
|
||||
# way a real bd would (143 / 142), not by a made-up exit code.
|
||||
fake="$TMPDIR/fakebin"
|
||||
mkdir -p "$fake"
|
||||
cat > "$fake/bd" <<'FAKE'
|
||||
#!/bin/sh
|
||||
trap 'echo TERM > "$FAKE_BD_SIGNAL"; trap - TERM; kill -TERM $$' TERM
|
||||
trap 'echo ALRM > "$FAKE_BD_SIGNAL"; trap - ALRM; kill -ALRM $$' ALRM
|
||||
[ -n "$FAKE_BD_BLOCK" ] && read -r _
|
||||
exit 0
|
||||
FAKE
|
||||
chmod +x "$fake/bd"
|
||||
mkfifo "$TMPDIR/hang"
|
||||
exec 3<> "$TMPDIR/hang"
|
||||
|
||||
# 3. The matrix.
|
||||
results="$TMPDIR/results"
|
||||
mkdir -p "$results"
|
||||
run_case() {
|
||||
name=$1 hook=$2 backend=$3 shell=$4
|
||||
shift 4
|
||||
case_dir="$TMPDIR/cases/$name"
|
||||
mkdir -p "$case_dir/bin"
|
||||
ln -s "$shell" "$case_dir/bin/sh"
|
||||
path="$fake:$case_dir/bin"
|
||||
for dir in "$@"; do path="$path:$dir"; done
|
||||
block=1
|
||||
[ "$backend" = none ] && block=
|
||||
signal_file="$case_dir/signal"
|
||||
# `|| rc=$?`: the builder runs under set -e, and a bare assignment
|
||||
# from a failing command would end this subshell before it reports.
|
||||
rc=0
|
||||
case_out=$(timeout 10 env PATH="$path" BEADS_HOOK_TIMEOUT=1 \
|
||||
FAKE_BD_BLOCK="$block" FAKE_BD_SIGNAL="$signal_file" \
|
||||
"$case_dir/bin/sh" "$shims/$hook" origin https://example.invalid 2>&1 <&3) || rc=$?
|
||||
signal=$(cat "$signal_file" 2>/dev/null || true)
|
||||
verdict=ok
|
||||
if [ "$rc" -eq 124 ]; then
|
||||
# This is the one mode that is intermittent and not reproducible
|
||||
# locally, so it needs the output most: report it like the branch
|
||||
# below rather than as a bare string.
|
||||
verdict="FAIL: nothing killed the fake bd (harness safety net fired), signal='$signal': $case_out"
|
||||
elif [ "$rc" -ne 0 ]; then
|
||||
verdict="FAIL: hook exit $rc (would block the push): $case_out"
|
||||
else
|
||||
case "$backend" in
|
||||
coreutils)
|
||||
case "$case_out" in *"timed out after 1s"*) ;; *) verdict="FAIL: no deadline report: $case_out" ;; esac
|
||||
[ "$signal" = TERM ] || verdict="FAIL: expected coreutils timeout (TERM), fake saw '$signal'"
|
||||
;;
|
||||
perl)
|
||||
case "$case_out" in *"timed out after 1s"*) ;; *) verdict="FAIL: no deadline report: $case_out" ;; esac
|
||||
[ "$signal" = ALRM ] || verdict="FAIL: expected perl alarm (ALRM), fake saw '$signal'"
|
||||
;;
|
||||
none)
|
||||
case "$case_out" in *"running without timeout"*) ;; *) verdict="FAIL: no unbounded warning: $case_out" ;; esac
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
printf '%-52s %-10s %s\n' "$name" "$backend" "$verdict" > "$results/$(echo "$name" | tr / _)"
|
||||
}
|
||||
|
||||
${lib.concatMapStrings caseLine cases}
|
||||
wait
|
||||
|
||||
printf '%-52s %-10s %s\n' CASE BACKEND RESULT
|
||||
sort "$results"/*
|
||||
echo
|
||||
reported=$(ls "$results" | wc -l)
|
||||
echo "$reported of ${toString (lib.length cases)} cases reported, $(grep -l FAIL "$results"/* | wc -l) failed"
|
||||
if [ "$reported" -ne ${toString (lib.length cases)} ]; then
|
||||
echo "some cases never reported a verdict"
|
||||
exit 1
|
||||
fi
|
||||
if grep -q FAIL "$results"/*; then
|
||||
exit 1
|
||||
fi
|
||||
touch "$out"
|
||||
'';
|
||||
}
|
||||
1432
cmd/bd/BUILD.bazel
Normal file
1432
cmd/bd/BUILD.bazel
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -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
131
cmd/bd/agent_hook_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
|
|
@ -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",
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
240
cmd/bd/backup_auto_proxied_local_integration_test.go
Normal file
240
cmd/bd/backup_auto_proxied_local_integration_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
142
cmd/bd/backup_auto_proxied_test.go
Normal file
142
cmd/bd/backup_auto_proxied_test.go
Normal 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -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: "",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
71
cmd/bd/backup_lock.go
Normal 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
133
cmd/bd/backup_lock_test.go
Normal 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])
|
||||
}
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -38,6 +38,9 @@ func runBatchProxiedServer(ctx context.Context, ops []batchOp, commitMsg string)
|
|||
if uowProvider == nil {
|
||||
return nil, HandleErrorRespectJSON("proxied-server UOW provider not initialized")
|
||||
}
|
||||
// Explicit commit point, like `transact` on the direct route: the commit
|
||||
// carries the caller's message whatever dolt.auto-commit says (GH#4995).
|
||||
ctx = explicitCommitPointContext(ctx)
|
||||
return uow.RunTxResult(ctx, uowProvider, func(ctx context.Context, uw uow.UnitOfWork) ([]batchOpResult, string, error) {
|
||||
// Built per attempt, not per call: a retried batch must report the
|
||||
// results of the attempt that actually committed.
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import (
|
|||
"github.com/steveyegge/beads/internal/storage/embeddeddolt"
|
||||
"github.com/steveyegge/beads/internal/storage/schema"
|
||||
"github.com/steveyegge/beads/internal/storage/versioncontrolops"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
"github.com/steveyegge/beads/internal/utils"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
|
@ -119,7 +120,9 @@ Bootstrap auto-detects the right action:
|
|||
• If git origin has Dolt data (refs/dolt/data): clones from git and wires origin for future push/pull
|
||||
• If .beads/backup/*.jsonl exists: restores from backup
|
||||
• If .beads/issues.jsonl exists: imports from git-tracked JSONL
|
||||
• If no database exists: creates a fresh one
|
||||
• If no database exists: creates a fresh one — unless the workspace was already
|
||||
initialized (metadata.json has a project_id) and its server-mode database is
|
||||
missing, in which case bootstrap refuses rather than strand the existing data
|
||||
• If database already exists: validates and reports status
|
||||
|
||||
If sync.remote points at a git repository, bootstrap verifies refs/dolt/data
|
||||
|
|
@ -187,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()
|
||||
|
|
@ -294,7 +299,7 @@ func applyBootstrapMetadataRepair(beadsDir string, cfg *configfile.Config, apply
|
|||
|
||||
// BootstrapPlan describes what bootstrap will do.
|
||||
type BootstrapPlan struct {
|
||||
Action string `json:"action"` // "sync", "restore", "jsonl-import", "init", "none"
|
||||
Action string `json:"action"` // "sync", "restore", "jsonl-import", "init", "none", "refuse"
|
||||
Reason string `json:"reason"` // Human-readable explanation
|
||||
BeadsDir string `json:"beads_dir"`
|
||||
Database string `json:"database"`
|
||||
|
|
@ -315,14 +320,28 @@ type BootstrapPlan struct {
|
|||
// Blocked marks a plan that took no action and found no database. It is
|
||||
// derived in detectBootstrapAction from Action+HasExisting, never set by a
|
||||
// detection branch, and it is the single discriminator the exit code and
|
||||
// the printed output both switch on. Additive on purpose: JSON consumers
|
||||
// switch on "action", so a new action value would break them, while
|
||||
// "none" + "blocked" + a non-zero exit code is backwards compatible.
|
||||
// the printed output both switch on.
|
||||
//
|
||||
// "blocked" is the stable, script-facing signal and must be set for EVERY
|
||||
// no-database outcome, so a consumer that only understands "none" is never
|
||||
// told a run succeeded when it did not. A new "action" value is acceptable
|
||||
// only for a state that must not be conflated with an existing one — the
|
||||
// refusal is one, because "none" also covers the benign "a database
|
||||
// already exists, nothing to do" — and only when it is accompanied by
|
||||
// "blocked" and, outside --dry-run, a non-zero exit code. That is the
|
||||
// contract to preserve when extending this enum: not "never add an action",
|
||||
// but "never add an action that is the only signal of what happened".
|
||||
Blocked bool `json:"blocked,omitempty"`
|
||||
// BlockedRemote is the credential-free remote URL a Blocked plan could not
|
||||
// verify, carried only so the diagnostic can name it.
|
||||
BlockedRemote string `json:"blocked_remote,omitempty"`
|
||||
HasExisting bool `json:"has_existing"`
|
||||
|
||||
// refusalDetail is the full operator-facing explanation for
|
||||
// Action=="refuse". It is unexported so the ANSI styling it carries never
|
||||
// leaks into --json output; JSON consumers read the plain-text one-liner
|
||||
// in Reason instead.
|
||||
refusalDetail string
|
||||
}
|
||||
|
||||
// MarshalJSON renders the plan for `bd bootstrap --json` (and `--dry-run --json`)
|
||||
|
|
@ -394,8 +413,24 @@ func requireBootstrapDoltBackend(cfg *configfile.Config, beadsDir string) error
|
|||
// branch can leave a stale flag behind for a later branch to inherit.
|
||||
func detectBootstrapAction(beadsDir string, cfg *configfile.Config) BootstrapPlan {
|
||||
plan := detectBootstrapPlan(beadsDir, cfg)
|
||||
plan.Blocked = plan.Action == "none" && !plan.HasExisting
|
||||
if !plan.Blocked {
|
||||
// "refuse" is a no-database outcome too, so it carries the same flag as
|
||||
// "none": the action string says WHY bootstrap stopped, Blocked says THAT
|
||||
// it stopped, and only the latter is the contract scripts switch on. This
|
||||
// changes no exit code — RunE routes Action=="refuse" through
|
||||
// executeBootstrapPlan, which errors, and --dry-run is contractually
|
||||
// exit 0 either way (see bootstrapPlanOutcome) — it only stops a refusal
|
||||
// from being the one bootstrap outcome that produced nothing yet reported
|
||||
// "blocked" absent.
|
||||
plan.Blocked = (plan.Action == "none" || plan.Action == "refuse") && !plan.HasExisting
|
||||
if plan.Blocked {
|
||||
// Keep SyncRemote's documented "empty on a Blocked plan" invariant
|
||||
// true now that refusals are Blocked: a refusal can be reached with a
|
||||
// forge SyncRemote already recorded (planConfiguredSyncRemote keeps it
|
||||
// for the workspace it expected to create), and no Blocked plan wires
|
||||
// up, clones from, or pushes to a remote. Inert for execution — every
|
||||
// consumer of plan.SyncRemote runs on a sync/provisioning action.
|
||||
plan.SyncRemote = ""
|
||||
} else {
|
||||
plan.BlockedRemote = ""
|
||||
}
|
||||
return plan
|
||||
|
|
@ -436,8 +471,22 @@ func detectBootstrapPlan(beadsDir string, cfg *configfile.Config) BootstrapPlan
|
|||
// probe-error branch, which then inherited HasExisting=true and printed the
|
||||
// #5743 success tick again.
|
||||
var deferredExistingPlan *BootstrapPlan
|
||||
if dbAction, ok := existingBootstrapDBPlan(beadsDir, cfg, isServer, isSharedServer); ok {
|
||||
if beadsDirExists || dbAction.Action != "none" {
|
||||
dbAction, dbProbe, hasExistingDB := existingBootstrapDBPlan(beadsDir, cfg, isServer, isSharedServer)
|
||||
// The same masking hazard applies to a server-side hit with no local
|
||||
// evidence. Probing on ProjectID alone (see existingBootstrapDBPlan) means
|
||||
// a shadow-dir-less workspace now reaches the Exists arm, where the only
|
||||
// thing matched is the database NAME — nothing checks that the database on
|
||||
// the server holds this project's data. Such a workspace previously
|
||||
// skipped the probe entirely and always fell through to sync.remote, so
|
||||
// settling here would let a stale or unrelated same-named database (including
|
||||
// one left behind by the very bug this guard fixes) silently suppress the
|
||||
// configured recovery path. Defer it exactly as a missing beadsDir is
|
||||
// deferred: sync.remote / refs/dolt/data / local files get their turn, and
|
||||
// the name match survives as the fallback verdict rather than becoming the
|
||||
// verdict.
|
||||
settledOnNameAlone := dbProbe.Ran && !dbProbe.LocalEvidence
|
||||
if hasExistingDB {
|
||||
if dbAction.Action != "none" || (beadsDirExists && !settledOnNameAlone) {
|
||||
return dbAction
|
||||
}
|
||||
deferredExistingPlan = &dbAction
|
||||
|
|
@ -484,6 +533,16 @@ func detectBootstrapPlan(beadsDir string, cfg *configfile.Config) BootstrapPlan
|
|||
return plan
|
||||
}
|
||||
|
||||
// Every recovery source has now been ruled out, so the fall-through below
|
||||
// is a fresh, empty database. Decide the refusal HERE rather than inside
|
||||
// executeInitAction: at plan time the answer reaches --dry-run and --json,
|
||||
// printBootstrapPlan never advertises "will create fresh database" for a
|
||||
// plan that cannot run, and confirmPrompt never asks the operator to
|
||||
// approve one. The probe result is reused, so no second dial is needed.
|
||||
if refusal, refused := refuseServerModeInitPlan(plan, cfg, isServer, isSharedServer, dbProbe); refused {
|
||||
return refusal
|
||||
}
|
||||
|
||||
// Fresh setup
|
||||
plan.Action = "init"
|
||||
plan.Reason = "No existing database, remote, or backup — will create fresh database"
|
||||
|
|
@ -600,77 +659,176 @@ func localFileRecoveryPlan(plan BootstrapPlan, beadsDir string) (BootstrapPlan,
|
|||
return BootstrapPlan{}, false
|
||||
}
|
||||
|
||||
func existingBootstrapDBPlan(beadsDir string, cfg *configfile.Config, isServer, isSharedServer bool) (BootstrapPlan, bool) {
|
||||
// refuseServerModeInitPlan turns a would-be fresh "init" into an explicit
|
||||
// "refuse" plan when metadata.json proves this workspace was already
|
||||
// initialized (ProjectID set) and the configured server-mode database could
|
||||
// not be confirmed to exist. Creating one here would strand the existing issue
|
||||
// data behind a new, empty database of the same name — the same root cause
|
||||
// PR #5791 (open, not yet merged) addresses for bd init.
|
||||
//
|
||||
// Reaching the init fall-through already implies the database was not
|
||||
// confirmed: existingBootstrapDBPlan returns a settled "none" plan whenever a
|
||||
// probe found it. The probe is passed in rather than re-run so the refusal
|
||||
// costs no extra round-trip and can quote why the check failed.
|
||||
func refuseServerModeInitPlan(plan BootstrapPlan, cfg *configfile.Config, isServer, isSharedServer bool, probe serverDBProbe) (BootstrapPlan, bool) {
|
||||
if !isServer || cfg.ProjectID == "" || !probe.Ran || probe.Exists {
|
||||
return BootstrapPlan{}, false
|
||||
}
|
||||
host := cfg.GetDoltServerHost()
|
||||
port := bootstrapServerPort(plan.BeadsDir, cfg, isSharedServer)
|
||||
plan.Action = "refuse"
|
||||
plan.Reason = bootstrapMissingServerDBSummary(plan.Database, host, port, probe.Err)
|
||||
plan.refusalDetail = bootstrapMissingServerDBRefusal(plan.Database, host, port, probe.Err).Error()
|
||||
return plan, true
|
||||
}
|
||||
|
||||
// serverDBProbe records what a server-mode existence probe concluded, so the
|
||||
// answer can be reused by the init fall-through instead of dialing the server
|
||||
// a second time.
|
||||
type serverDBProbe struct {
|
||||
Ran bool // a probe was actually performed
|
||||
Exists bool // the server confirmed the database exists
|
||||
Err error // the probe could not reach or question the server
|
||||
// LocalEvidence records whether anything on this machine ties this
|
||||
// workspace to the database the probe asked about — in practice a
|
||||
// populated local shadow directory. Without it the probe can only match
|
||||
// on the database NAME, which is why the caller refuses to let an
|
||||
// Exists verdict settle the plan ahead of the real recovery sources.
|
||||
LocalEvidence bool
|
||||
}
|
||||
|
||||
// existingBootstrapDBPlan reports whether an existing database already settles
|
||||
// the bootstrap plan. The returned serverDBProbe carries the server-mode
|
||||
// probe result — including on the false path, where the caller needs it to
|
||||
// decide whether a fall-through to "init" is safe.
|
||||
func existingBootstrapDBPlan(beadsDir string, cfg *configfile.Config, isServer, isSharedServer bool) (BootstrapPlan, serverDBProbe, bool) {
|
||||
plan := BootstrapPlan{
|
||||
BeadsDir: beadsDir,
|
||||
Database: cfg.GetDoltDatabase(),
|
||||
}
|
||||
|
||||
var dbPath string
|
||||
if isServer {
|
||||
dbPath = bootstrapServerDoltDir(beadsDir, cfg, isSharedServer)
|
||||
} else {
|
||||
dbPath = filepath.Join(beadsDir, "embeddeddolt")
|
||||
// Scope note: this is per-workspace evidence in locally-managed server
|
||||
// mode only. In shared-server mode bootstrapServerDoltDir resolves to
|
||||
// doltserver.SharedDoltDir() — ~/.beads/shared-server/dolt/, one
|
||||
// directory for EVERY shared-server database on the machine — so a
|
||||
// fresh clone of project B reads a populated directory belonging to
|
||||
// projects A and C. Everything below that calls this "local evidence"
|
||||
// is therefore only sound for the locally-managed case; the
|
||||
// shared-server granularity gap is pre-existing (main probes on the
|
||||
// same signal) and is tracked separately rather than narrowed here,
|
||||
// because keying on the database-named subdirectory would also change
|
||||
// the locally-managed verdict for a data dir holding only .doltcfg.
|
||||
dbPath := bootstrapServerDoltDir(beadsDir, cfg, isSharedServer)
|
||||
hasLocalShadowDir := false
|
||||
if info, err := os.Stat(dbPath); err == nil && info.IsDir() {
|
||||
if entries, _ := os.ReadDir(dbPath); len(entries) > 0 {
|
||||
hasLocalShadowDir = true
|
||||
}
|
||||
}
|
||||
// A missing/empty local shadow directory normally means no database
|
||||
// exists yet. But when metadata.json carries a ProjectID, this
|
||||
// workspace was already initialized somewhere — most likely a fresh
|
||||
// clone of an already-bootstrapped server-mode project, which has no
|
||||
// local shadow directory by design. In that case, skip the local-dir
|
||||
// short-circuit and live-probe the server directly rather than
|
||||
// concluding "no database" from local-disk state alone.
|
||||
if !hasLocalShadowDir && cfg.ProjectID == "" {
|
||||
return BootstrapPlan{}, serverDBProbe{}, false
|
||||
}
|
||||
|
||||
// Retry the reachable-but-absent window only when the local shadow
|
||||
// directory says this database really does live here; see
|
||||
// probeBootstrapServerDB for why a fresh clone must not pay 70s.
|
||||
result := probeBootstrapServerDB(beadsDir, cfg, isSharedServer, hasLocalShadowDir)
|
||||
probe := serverDBProbe{Ran: true, Exists: result.Exists, Err: result.Err, LocalEvidence: hasLocalShadowDir}
|
||||
|
||||
if result.Exists {
|
||||
plan.HasExisting = true
|
||||
plan.Action = "none"
|
||||
plan.Reason = fmt.Sprintf("Database %s already exists on server at %s:%d", cfg.GetDoltDatabase(), cfg.GetDoltServerHost(), bootstrapServerPort(beadsDir, cfg, isSharedServer))
|
||||
return plan, probe, true
|
||||
}
|
||||
// An unverifiable probe means UNKNOWN, never "exists". Answering
|
||||
// "nothing to do" for it is only defensible with local evidence that
|
||||
// the database lives here — a populated shadow directory (in
|
||||
// locally-managed server mode; see the scope note above, it is not
|
||||
// per-database in shared-server mode), where a down server is a live
|
||||
// database we simply cannot see right now.
|
||||
// Without that evidence the very same error describes a fresh clone
|
||||
// whose server has not been started yet, which is the normal state of
|
||||
// every locally-managed server-mode clone before its first sync. Such
|
||||
// a clone must stay eligible for sync.remote, refs/dolt/data,
|
||||
// .beads/backup/ and issues.jsonl, so report "not found" and let
|
||||
// detectBootstrapAction consult them.
|
||||
//
|
||||
// When it does settle here, Blocked is still not hand-set:
|
||||
// detectBootstrapAction derives it from Action=="none" && !HasExisting
|
||||
// (HasExisting is false on this branch), keeping one owner for the flag
|
||||
// and the #5743 non-zero exit rather than a false success tick.
|
||||
if result.Err != nil && hasLocalShadowDir {
|
||||
plan.Action = "none"
|
||||
plan.Reason = fmt.Sprintf("Could not verify existing server database %s: %v", cfg.GetDoltDatabase(), result.Err)
|
||||
return plan, probe, true
|
||||
}
|
||||
return BootstrapPlan{}, probe, false
|
||||
}
|
||||
|
||||
dbPath := filepath.Join(beadsDir, "embeddeddolt")
|
||||
if info, err := os.Stat(dbPath); err != nil || !info.IsDir() {
|
||||
return BootstrapPlan{}, false
|
||||
return BootstrapPlan{}, serverDBProbe{}, false
|
||||
}
|
||||
|
||||
entries, _ := os.ReadDir(dbPath)
|
||||
if len(entries) == 0 {
|
||||
return BootstrapPlan{}, false
|
||||
}
|
||||
|
||||
if isServer {
|
||||
probeCfg := bootstrapServerProbeConfig{
|
||||
host: cfg.GetDoltServerHost(),
|
||||
port: bootstrapServerPort(beadsDir, cfg, isSharedServer),
|
||||
user: cfg.GetDoltServerUser(),
|
||||
pass: cfg.GetDoltServerPassword(),
|
||||
database: cfg.GetDoltDatabase(),
|
||||
tls: cfg.GetDoltServerTLS(),
|
||||
}
|
||||
// When the server is reachable but the DB appears absent, retry with
|
||||
// exponential backoff before concluding the DB is genuinely missing.
|
||||
// A managed Dolt restart completes in <30 s; three retries over 70 s
|
||||
// cover all observed restart windows.
|
||||
retryDelays := []time.Duration{10 * time.Second, 20 * time.Second, 40 * time.Second}
|
||||
var result bootstrapServerDBCheck
|
||||
for attempt := 0; ; attempt++ {
|
||||
result = checkBootstrapServerDB(probeCfg)
|
||||
if result.Err != nil || result.Exists || !result.Reachable {
|
||||
break
|
||||
}
|
||||
if attempt >= len(retryDelays) {
|
||||
break
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Database %s not found on reachable server (attempt %d/%d), retrying in %v (possible transient restart)\n",
|
||||
cfg.GetDoltDatabase(), attempt+1, len(retryDelays), retryDelays[attempt])
|
||||
bootstrapRetryDelay(retryDelays[attempt])
|
||||
}
|
||||
if result.Err != nil {
|
||||
// Same "declined, and no database was confirmed" class as a
|
||||
// failed remote probe: report it and exit non-zero rather than
|
||||
// printing a success tick (#5743). Blocked is not hand-set here —
|
||||
// detectBootstrapAction derives it from Action=="none" && !HasExisting
|
||||
// (HasExisting is false on this branch), keeping one owner for the flag.
|
||||
plan.Action = "none"
|
||||
plan.Reason = fmt.Sprintf("Could not verify existing server database %s: %v", cfg.GetDoltDatabase(), result.Err)
|
||||
return plan, true
|
||||
}
|
||||
if result.Exists {
|
||||
plan.HasExisting = true
|
||||
plan.Action = "none"
|
||||
plan.Reason = fmt.Sprintf("Database %s already exists on server at %s:%d", probeCfg.database, probeCfg.host, probeCfg.port)
|
||||
return plan, true
|
||||
}
|
||||
return BootstrapPlan{}, false
|
||||
return BootstrapPlan{}, serverDBProbe{}, false
|
||||
}
|
||||
|
||||
plan.HasExisting = true
|
||||
plan.Action = "none"
|
||||
plan.Reason = "Database already exists at " + dbPath
|
||||
return plan, true
|
||||
return plan, serverDBProbe{}, true
|
||||
}
|
||||
|
||||
// probeBootstrapServerDB checks whether the configured database exists on
|
||||
// the Dolt server.
|
||||
//
|
||||
// When retryTransient is set, a reachable server that reports the database
|
||||
// absent is retried with backoff, because a managed Dolt restart can
|
||||
// transiently look like a missing database for up to ~30s. That budget costs
|
||||
// 70s, so it is only worth paying when something independent says the
|
||||
// database really is supposed to be here — in practice, a populated local
|
||||
// shadow directory. A caller with no such evidence (a fresh clone, which by
|
||||
// design has no shadow directory) is not watching a database disappear; it is
|
||||
// simply ahead of its first sync, and must pass retryTransient=false so the
|
||||
// answer costs one round-trip instead of 70s.
|
||||
func probeBootstrapServerDB(beadsDir string, cfg *configfile.Config, isSharedServer, retryTransient bool) bootstrapServerDBCheck {
|
||||
probeCfg := bootstrapServerProbeConfig{
|
||||
host: cfg.GetDoltServerHost(),
|
||||
port: bootstrapServerPort(beadsDir, cfg, isSharedServer),
|
||||
user: cfg.GetDoltServerUser(),
|
||||
pass: cfg.GetDoltServerPassword(),
|
||||
database: cfg.GetDoltDatabase(),
|
||||
tls: cfg.GetDoltServerTLS(),
|
||||
}
|
||||
if !retryTransient {
|
||||
return checkBootstrapServerDB(probeCfg)
|
||||
}
|
||||
retryDelays := []time.Duration{10 * time.Second, 20 * time.Second, 40 * time.Second}
|
||||
var result bootstrapServerDBCheck
|
||||
for attempt := 0; ; attempt++ {
|
||||
result = checkBootstrapServerDB(probeCfg)
|
||||
if result.Err != nil || result.Exists || !result.Reachable {
|
||||
break
|
||||
}
|
||||
if attempt >= len(retryDelays) {
|
||||
break
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Database %s not found on reachable server (attempt %d/%d), retrying in %v (possible transient restart)\n",
|
||||
cfg.GetDoltDatabase(), attempt+1, len(retryDelays), retryDelays[attempt])
|
||||
bootstrapRetryDelay(retryDelays[attempt])
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func bootstrapSharedServerMode(beadsDir string) bool {
|
||||
|
|
@ -769,6 +927,21 @@ func printBootstrapPlan(plan BootstrapPlan) {
|
|||
case "init":
|
||||
fmt.Printf("Bootstrap plan: create fresh database\n")
|
||||
fmt.Printf(" Database: %s\n", plan.Database)
|
||||
case "refuse":
|
||||
// Deliberately the one-line summary, not refusalDetail: the full
|
||||
// explanation is the error executeBootstrapPlan returns, and printing
|
||||
// both would render it twice.
|
||||
//
|
||||
// Deliberately stdout, unlike the "none"+Blocked arm above: this is the
|
||||
// plan the command was asked to compute, and the one-line Reason rides
|
||||
// with it (pinned by TestPrintBootstrapPlan_RefusePrintsSummaryNotDetail)
|
||||
// so a stdout-only consumer is never left with a bare "refuse". It is
|
||||
// not the #5743 false-success class either — a real refuse run exits
|
||||
// non-zero through executeBootstrapPlan, so nothing reads this as
|
||||
// success.
|
||||
fmt.Printf("Bootstrap plan: refuse — will NOT create a database\n")
|
||||
fmt.Printf(" Database: %s\n", plan.Database)
|
||||
fmt.Printf(" Reason: %s\n", plan.Reason)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -792,6 +965,16 @@ func executeBootstrapPlan(plan BootstrapPlan, cfg *configfile.Config, nonInterac
|
|||
if err := requireBootstrapDoltBackend(cfg, plan.BeadsDir); err != nil {
|
||||
return err
|
||||
}
|
||||
// A refusal is a decision, not an action awaiting approval: surface it
|
||||
// before confirmPrompt so the operator is never asked to approve it, and
|
||||
// before the workspace gates below so no state is touched.
|
||||
if plan.Action == "refuse" {
|
||||
detail := plan.refusalDetail
|
||||
if detail == "" {
|
||||
detail = plan.Reason
|
||||
}
|
||||
return errors.New(detail)
|
||||
}
|
||||
if !confirmPrompt("Proceed?", nonInteractive) {
|
||||
fmt.Fprintf(os.Stderr, "Aborted.\n")
|
||||
return nil
|
||||
|
|
@ -836,6 +1019,10 @@ func executeBootstrapPlan(plan BootstrapPlan, cfg *configfile.Config, nonInterac
|
|||
}
|
||||
|
||||
func executeInitAction(ctx context.Context, plan BootstrapPlan, cfg *configfile.Config) error {
|
||||
if err := refuseServerModeInitForExistingProject(plan, cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
prefix := inferPrefix(cfg)
|
||||
dbName := cfg.GetDoltDatabase()
|
||||
|
||||
|
|
@ -884,6 +1071,86 @@ func wireBootstrapDoltRemote(ctx context.Context, s storage.DoltStorage, plan Bo
|
|||
configureInitDoltRemote(ctx, s, doltRemoteURL(plan.SyncRemote), false)
|
||||
}
|
||||
|
||||
// refuseServerModeInitForExistingProject is the belt-and-braces half of the
|
||||
// guard whose real decision is made at plan time by refuseServerModeInitPlan.
|
||||
// It re-checks, at the last moment before a database would actually be
|
||||
// created, that this workspace is not an already-initialized project
|
||||
// (ProjectID set) whose server-mode database cannot be confirmed to exist —
|
||||
// covering any caller that reaches executeInitAction with a plan that did not
|
||||
// come from detectBootstrapAction.
|
||||
//
|
||||
// It deliberately probes ONCE. The transient-restart backoff belongs to the
|
||||
// plan-time probe; repeating it here would charge a second 70s to a decision
|
||||
// that has already been made, and refusing is the safe direction anyway.
|
||||
func refuseServerModeInitForExistingProject(plan BootstrapPlan, cfg *configfile.Config) error {
|
||||
isSharedServer := bootstrapSharedServerMode(plan.BeadsDir)
|
||||
if (!cfg.IsDoltServerMode() && !isSharedServer) || cfg.ProjectID == "" {
|
||||
return nil
|
||||
}
|
||||
result := probeBootstrapServerDB(plan.BeadsDir, cfg, isSharedServer, false)
|
||||
if result.Exists {
|
||||
return nil
|
||||
}
|
||||
host := cfg.GetDoltServerHost()
|
||||
port := bootstrapServerPort(plan.BeadsDir, cfg, isSharedServer)
|
||||
return bootstrapMissingServerDBRefusal(cfg.GetDoltDatabase(), host, port, result.Err)
|
||||
}
|
||||
|
||||
// bootstrapMissingServerDBSummary is the single-line, unstyled form of
|
||||
// bootstrapMissingServerDBRefusal, used as BootstrapPlan.Reason so --json
|
||||
// consumers get the explanation without ANSI escapes.
|
||||
func bootstrapMissingServerDBSummary(dbName, host string, port int, probeErr error) string {
|
||||
if probeErr != nil {
|
||||
return fmt.Sprintf("Could not verify database %q on Dolt server at %s:%d (%v); workspace already initialized (project_id set) — refusing to create an empty database", dbName, host, port, probeErr)
|
||||
}
|
||||
return fmt.Sprintf("Database %q not found on server at %s:%d; workspace already initialized (project_id set) — refusing to create an empty database", dbName, host, port)
|
||||
}
|
||||
|
||||
// bootstrapMissingServerDBRefusal builds the refusal error shown when bd
|
||||
// bootstrap would otherwise create a fresh, empty server-mode database for a
|
||||
// workspace that was already initialized elsewhere. Per GH#2363, this must
|
||||
// never suggest a destructive "recreate" action as an actionable next step.
|
||||
//
|
||||
// The equivalent guard for `bd init` is proposed in PR #5791, which is open
|
||||
// and not yet merged; this wording is kept deliberately close to it so the
|
||||
// two can share one message once that lands.
|
||||
func bootstrapMissingServerDBRefusal(dbName, host string, port int, probeErr error) error {
|
||||
var b strings.Builder
|
||||
if probeErr != nil {
|
||||
fmt.Fprintf(&b, "\n%s Could not verify database %q on Dolt server at %s:%d: %v\n", ui.RenderWarn("⚠"), dbName, host, port, probeErr)
|
||||
} else {
|
||||
fmt.Fprintf(&b, "\n%s Database %q not found on server at %s:%d.\n", ui.RenderWarn("⚠"), dbName, host, port)
|
||||
}
|
||||
b.WriteString("This workspace was already initialized (metadata.json has a project_id from a prior\n")
|
||||
b.WriteString("bd init/bootstrap), so this looks like a recovery situation, not a fresh clone.\n")
|
||||
|
||||
b.WriteString("\nbd bootstrap will NOT create an empty database here — that would strand any existing\n")
|
||||
b.WriteString("issue data behind a new, empty database of the same name.\n")
|
||||
|
||||
b.WriteString("\nDiagnose with:\n")
|
||||
b.WriteString(" bd doctor # check project health\n")
|
||||
b.WriteString(" bd dolt status # inspect Dolt server state\n")
|
||||
|
||||
// Every route here must be followable FROM this state. `bd backup restore`
|
||||
// alone is not: it restores a Dolt-native snapshot, not a `bd export`
|
||||
// JSONL, and it requires an initialized database — so it silently routes
|
||||
// the operator back through `bd init`, the very unguarded door this
|
||||
// refusal exists to keep shut (PR #5791). Name that precondition instead
|
||||
// of implying it, and lead with the routes that need no init at all.
|
||||
b.WriteString("\nTo recover existing data, repopulate the database rather than creating fresh.\n")
|
||||
b.WriteString("Routes that work from this state:\n")
|
||||
b.WriteString(" bd dolt push # from another clone that still has the data\n")
|
||||
b.WriteString(" bd config set sync.remote <url> # then re-run bd bootstrap to clone from it\n")
|
||||
b.WriteString(" bd init && bd backup restore # ONLY with a Dolt-native backup snapshot:\n")
|
||||
b.WriteString(" # bd backup restore needs an initialized\n")
|
||||
b.WriteString(" # database and will not read a bd export JSONL\n")
|
||||
b.WriteString("\nbd bootstrap only auto-restores .beads/backup/issues.jsonl, so a timestamped or\n")
|
||||
b.WriteString("otherwise-named export under .beads/backup/ is still yours to import by hand.\n")
|
||||
|
||||
b.WriteString("\nAborting.")
|
||||
return errors.New(b.String())
|
||||
}
|
||||
|
||||
func executeRestoreAction(ctx context.Context, plan BootstrapPlan, cfg *configfile.Config) error {
|
||||
prefix := inferPrefix(cfg)
|
||||
dbName := cfg.GetDoltDatabase()
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
|
@ -1839,3 +1842,545 @@ func TestFinalizeSyncedBootstrapSharedServerSetsServerMode(t *testing.T) {
|
|||
t.Errorf("dolt_mode = %q, want %q — shared server should set server mode", loaded.GetDoltMode(), configfile.DoltModeServer)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDetectBootstrapAction_NoLocalShadowDirStillLiveChecksExisting reproduces
|
||||
// be-cy41 bug #1: existingBootstrapDBPlan returned BootstrapPlan{}, false (and
|
||||
// detectBootstrapAction fell through toward Action="init") purely because no
|
||||
// local shadow dolt-data directory existed — but in server mode that is the
|
||||
// NORMAL state for a fresh clone of an already-initialized project. When
|
||||
// metadata.json carries a ProjectID (proving this workspace was previously
|
||||
// initialized), the server-side existence check must still run instead of
|
||||
// being short-circuited by local filesystem state that a legitimate clone
|
||||
// will never have (the same ambiguity PR #5791 addresses for bd init; that
|
||||
// PR is open and not yet merged, so nothing it adds is referenced here).
|
||||
func TestDetectBootstrapAction_NoLocalShadowDirStillLiveChecksExisting(t *testing.T) {
|
||||
t.Setenv("BEADS_DOLT_DATA_DIR", "")
|
||||
t.Setenv("BEADS_DOLT_SHARED_SERVER", "")
|
||||
t.Setenv("BEADS_DOLT_SERVER_DATABASE", "")
|
||||
t.Setenv("BEADS_DOLT_SERVER_HOST", "")
|
||||
t.Setenv("BEADS_DOLT_SERVER_PORT", "")
|
||||
tmpDir := t.TempDir()
|
||||
beadsDir := filepath.Join(tmpDir, ".beads")
|
||||
if err := os.MkdirAll(beadsDir, 0o750); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Deliberately do NOT create doltDataDir at all — no local shadow
|
||||
// directory, which is the normal state for a fresh clone of a
|
||||
// pre-existing server-mode project.
|
||||
doltDataDir := filepath.Join(tmpDir, "dolt-data")
|
||||
|
||||
oldWd, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() { _ = os.Chdir(oldWd) }()
|
||||
if err := os.Chdir(tmpDir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cfg := configfile.DefaultConfig()
|
||||
cfg.DoltMode = configfile.DoltModeServer
|
||||
cfg.DoltDatabase = "project_exists"
|
||||
cfg.DoltDataDir = doltDataDir
|
||||
cfg.ProjectID = "proj-already-initialized-456"
|
||||
t.Setenv("BEADS_DOLT_DATA_DIR", doltDataDir)
|
||||
|
||||
probed := false
|
||||
origCheck := checkBootstrapServerDB
|
||||
checkBootstrapServerDB = func(probeCfg bootstrapServerProbeConfig) bootstrapServerDBCheck {
|
||||
probed = true
|
||||
if probeCfg.database != "project_exists" {
|
||||
t.Fatalf("unexpected dbName: %s", probeCfg.database)
|
||||
}
|
||||
return bootstrapServerDBCheck{Exists: true, Reachable: true}
|
||||
}
|
||||
defer func() { checkBootstrapServerDB = origCheck }()
|
||||
origDelay := bootstrapRetryDelay
|
||||
bootstrapRetryDelay = func(time.Duration) {}
|
||||
defer func() { bootstrapRetryDelay = origDelay }()
|
||||
|
||||
plan := detectBootstrapAction(beadsDir, cfg)
|
||||
|
||||
if !probed {
|
||||
t.Fatal("checkBootstrapServerDB was never called — a local-shadow-directory gate short-circuited the real server-side existence check before it could run")
|
||||
}
|
||||
if plan.Action != "none" {
|
||||
t.Fatalf("action = %q, want %q — bootstrap must not plan to recreate a database that already exists on the server just because no local shadow directory is present", plan.Action, "none")
|
||||
}
|
||||
if !plan.HasExisting {
|
||||
t.Error("HasExisting = false, want true")
|
||||
}
|
||||
}
|
||||
|
||||
// TestExecuteInitAction_ServerModeExistingProjectMissingDBRefuses reproduces
|
||||
// be-cy41 bug #2: executeInitAction is mode-blind — it always builds a
|
||||
// dolt.Config with CreateIfMissing:true, AutoStart:true, and no server
|
||||
// host/port/mode fields, so it silently creates an embedded-style database
|
||||
// even for a server-mode workspace. When the workspace was already
|
||||
// initialized (metadata.json has a project_id — the same signal PR #5791 uses) but
|
||||
// the configured database is missing on the server, this silently strands any
|
||||
// existing issue data behind a new, empty database of the same name.
|
||||
// executeInitAction must refuse instead (the same root cause as PR #5791's
|
||||
// proposed bd init guard, which is still open).
|
||||
func TestExecuteInitAction_ServerModeExistingProjectMissingDBRefuses(t *testing.T) {
|
||||
t.Setenv("BEADS_DOLT_DATA_DIR", "")
|
||||
t.Setenv("BEADS_DOLT_SHARED_SERVER", "")
|
||||
t.Setenv("BEADS_DOLT_SERVER_DATABASE", "")
|
||||
t.Setenv("BEADS_DOLT_SERVER_HOST", "")
|
||||
t.Setenv("BEADS_DOLT_SERVER_PORT", "")
|
||||
tmpDir := t.TempDir()
|
||||
beadsDir := filepath.Join(tmpDir, ".beads")
|
||||
if err := os.MkdirAll(beadsDir, 0o750); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
oldWd, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() { _ = os.Chdir(oldWd) }()
|
||||
if err := os.Chdir(tmpDir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cfg := configfile.DefaultConfig()
|
||||
cfg.DoltMode = configfile.DoltModeServer
|
||||
cfg.DoltDatabase = "myproj"
|
||||
cfg.ProjectID = "proj-existing-123"
|
||||
|
||||
origCheck := checkBootstrapServerDB
|
||||
checkBootstrapServerDB = func(probeCfg bootstrapServerProbeConfig) bootstrapServerDBCheck {
|
||||
return bootstrapServerDBCheck{Exists: false, Reachable: true}
|
||||
}
|
||||
defer func() { checkBootstrapServerDB = origCheck }()
|
||||
origDelay := bootstrapRetryDelay
|
||||
bootstrapRetryDelay = func(time.Duration) {}
|
||||
defer func() { bootstrapRetryDelay = origDelay }()
|
||||
|
||||
plan := BootstrapPlan{BeadsDir: beadsDir, Database: "myproj", Action: "init"}
|
||||
err = executeInitAction(context.Background(), plan, cfg)
|
||||
|
||||
if err == nil {
|
||||
t.Fatal("executeInitAction succeeded silently for an existing project with a missing server-mode database — want a refusal error")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "myproj") {
|
||||
t.Errorf("error %q does not mention the missing database name %q", err.Error(), "myproj")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "will NOT create") && !strings.Contains(err.Error(), "not found on server") {
|
||||
t.Errorf("error %q does not read as a refusal to auto-create", err.Error())
|
||||
}
|
||||
if _, statErr := os.Stat(filepath.Join(beadsDir, "embeddeddolt")); statErr == nil {
|
||||
t.Error("executeInitAction created an embedded database as a side effect of a refused server-mode init — no database should have been created at all")
|
||||
}
|
||||
}
|
||||
|
||||
// freshServerModeCloneFixture builds the state a fresh clone of an
|
||||
// already-bootstrapped server-mode project is actually in: .beads/ present
|
||||
// with a configured sync.remote, metadata.json carrying a ProjectID, and no
|
||||
// local shadow dolt-data directory (a clone never has one).
|
||||
func freshServerModeCloneFixture(t *testing.T) (beadsDir string, cfg *configfile.Config) {
|
||||
t.Helper()
|
||||
snapshotBootstrapEnv(t)
|
||||
config.ResetForTesting()
|
||||
t.Cleanup(config.ResetForTesting)
|
||||
t.Setenv("BEADS_DOLT_SHARED_SERVER", "")
|
||||
t.Setenv("BEADS_DOLT_SERVER_HOST", "")
|
||||
t.Setenv("BEADS_DOLT_SERVER_PORT", "")
|
||||
tmpDir := t.TempDir()
|
||||
beadsDir = filepath.Join(tmpDir, ".beads")
|
||||
if err := os.MkdirAll(beadsDir, 0o750); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(beadsDir, "config.yaml"), []byte("sync.remote: http://myserver:7007/mydb\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv("BEADS_DIR", beadsDir)
|
||||
t.Setenv("BEADS_TEST_IGNORE_REPO_CONFIG", "1")
|
||||
if err := config.Initialize(); err != nil {
|
||||
t.Fatalf("config.Initialize failed: %v", err)
|
||||
}
|
||||
t.Chdir(tmpDir)
|
||||
cfg = configfile.DefaultConfig()
|
||||
cfg.DoltMode = configfile.DoltModeServer
|
||||
cfg.DoltDatabase = "mydb"
|
||||
cfg.DoltDataDir = filepath.Join(tmpDir, "dolt-data") // never created: fresh clone
|
||||
cfg.ProjectID = "proj-fresh-clone-789"
|
||||
t.Setenv("BEADS_DOLT_DATA_DIR", cfg.DoltDataDir)
|
||||
return beadsDir, cfg
|
||||
}
|
||||
|
||||
// TestDetectBootstrapAction_FreshCloneUnreachableServerStillSyncs pins the
|
||||
// rule that an unverifiable probe means UNKNOWN, not "exists". A fresh clone
|
||||
// of a locally-managed server-mode project has nothing running yet, so
|
||||
// "connection refused" is its NORMAL state — it must not be converted into
|
||||
// Action="none" ("nothing to do"), which would hide sync.remote,
|
||||
// refs/dolt/data, .beads/backup/ and issues.jsonl behind a dead server.
|
||||
func TestDetectBootstrapAction_FreshCloneUnreachableServerStillSyncs(t *testing.T) {
|
||||
beadsDir, cfg := freshServerModeCloneFixture(t)
|
||||
orig := checkBootstrapServerDB
|
||||
checkBootstrapServerDB = func(bootstrapServerProbeConfig) bootstrapServerDBCheck {
|
||||
return bootstrapServerDBCheck{Reachable: false, Err: errors.New("dial tcp 127.0.0.1:3307: connect: connection refused")}
|
||||
}
|
||||
defer func() { checkBootstrapServerDB = orig }()
|
||||
origDelay := bootstrapRetryDelay
|
||||
bootstrapRetryDelay = func(time.Duration) {}
|
||||
defer func() { bootstrapRetryDelay = origDelay }()
|
||||
|
||||
plan := detectBootstrapAction(beadsDir, cfg)
|
||||
if plan.Action != "sync" {
|
||||
t.Errorf("action = %q (reason %q), want sync: an unreachable server must not veto sync.remote recovery on a fresh clone", plan.Action, plan.Reason)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDetectBootstrapAction_FreshCloneReachableAbsentSkipsTransientBackoff
|
||||
// pins that the 10/20/40s transient-restart budget is only spent when a local
|
||||
// shadow directory says the database really does live here. A fresh clone has
|
||||
// no shadow directory by design, so "reachable but absent" is simply "not
|
||||
// synced yet" and must cost one probe, not 70 seconds.
|
||||
func TestDetectBootstrapAction_FreshCloneReachableAbsentSkipsTransientBackoff(t *testing.T) {
|
||||
beadsDir, cfg := freshServerModeCloneFixture(t)
|
||||
probes := 0
|
||||
orig := checkBootstrapServerDB
|
||||
checkBootstrapServerDB = func(bootstrapServerProbeConfig) bootstrapServerDBCheck {
|
||||
probes++
|
||||
return bootstrapServerDBCheck{Reachable: true, Exists: false}
|
||||
}
|
||||
defer func() { checkBootstrapServerDB = orig }()
|
||||
var slept time.Duration
|
||||
origDelay := bootstrapRetryDelay
|
||||
bootstrapRetryDelay = func(d time.Duration) { slept += d }
|
||||
defer func() { bootstrapRetryDelay = origDelay }()
|
||||
|
||||
plan := detectBootstrapAction(beadsDir, cfg)
|
||||
if plan.Action != "sync" {
|
||||
t.Errorf("action = %q, want sync", plan.Action)
|
||||
}
|
||||
if slept > 0 {
|
||||
t.Errorf("fresh clone with no local DB paid %v of transient-restart backoff before sync", slept)
|
||||
}
|
||||
if probes != 1 {
|
||||
t.Errorf("probes = %d, want exactly 1 — a clone with no local shadow dir has nothing to be transiently missing", probes)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDetectBootstrapAction_ShadowDirUnreachableServerStillReportsNone pins
|
||||
// the other side of that rule: with a populated local shadow directory there
|
||||
// IS local evidence the database lives here, so an unreachable server is a
|
||||
// live database we cannot see right now and "nothing to do" remains the
|
||||
// correct answer. This is main's long-standing behavior and must survive the
|
||||
// narrowing above.
|
||||
func TestDetectBootstrapAction_ShadowDirUnreachableServerStillReportsNone(t *testing.T) {
|
||||
beadsDir, cfg := freshServerModeCloneFixture(t)
|
||||
if err := os.MkdirAll(filepath.Join(cfg.DoltDataDir, "mydb"), 0o750); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
orig := checkBootstrapServerDB
|
||||
checkBootstrapServerDB = func(bootstrapServerProbeConfig) bootstrapServerDBCheck {
|
||||
return bootstrapServerDBCheck{Reachable: false, Err: errors.New("dial tcp 127.0.0.1:3307: connect: connection refused")}
|
||||
}
|
||||
defer func() { checkBootstrapServerDB = orig }()
|
||||
origDelay := bootstrapRetryDelay
|
||||
bootstrapRetryDelay = func(time.Duration) {}
|
||||
defer func() { bootstrapRetryDelay = origDelay }()
|
||||
|
||||
plan := detectBootstrapAction(beadsDir, cfg)
|
||||
if plan.Action != "none" {
|
||||
t.Errorf("action = %q, want none — a populated shadow dir is local evidence the DB exists, so a down server means 'do nothing', not 'recover'", plan.Action)
|
||||
}
|
||||
if !strings.Contains(plan.Reason, "Could not verify") {
|
||||
t.Errorf("reason = %q, want the 'Could not verify' wording", plan.Reason)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDetectBootstrapAction_ExistingProjectMissingServerDBRefusesAtPlanTime
|
||||
// pins that the refusal is a PLAN, not an execute-time surprise. With every
|
||||
// recovery source absent the fall-through would be a fresh, empty database;
|
||||
// because metadata.json proves the workspace was already initialized, the
|
||||
// plan itself must say "refuse" so --dry-run and --json report it and
|
||||
// printBootstrapPlan never advertises "will create fresh database".
|
||||
func TestDetectBootstrapAction_ExistingProjectMissingServerDBRefusesAtPlanTime(t *testing.T) {
|
||||
snapshotBootstrapEnv(t)
|
||||
config.ResetForTesting()
|
||||
t.Cleanup(config.ResetForTesting)
|
||||
t.Setenv("BEADS_DOLT_SHARED_SERVER", "")
|
||||
t.Setenv("BEADS_DOLT_SERVER_HOST", "")
|
||||
t.Setenv("BEADS_DOLT_SERVER_PORT", "")
|
||||
tmpDir := t.TempDir()
|
||||
beadsDir := filepath.Join(tmpDir, ".beads")
|
||||
if err := os.MkdirAll(beadsDir, 0o750); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// No sync.remote, no backup, no issues.jsonl: nothing to recover from.
|
||||
t.Setenv("BEADS_DIR", beadsDir)
|
||||
t.Setenv("BEADS_TEST_IGNORE_REPO_CONFIG", "1")
|
||||
if err := config.Initialize(); err != nil {
|
||||
t.Fatalf("config.Initialize failed: %v", err)
|
||||
}
|
||||
t.Chdir(tmpDir)
|
||||
cfg := configfile.DefaultConfig()
|
||||
cfg.DoltMode = configfile.DoltModeServer
|
||||
cfg.DoltDatabase = "mydb"
|
||||
cfg.DoltDataDir = filepath.Join(tmpDir, "dolt-data")
|
||||
cfg.ProjectID = "proj-already-initialized-456"
|
||||
t.Setenv("BEADS_DOLT_DATA_DIR", cfg.DoltDataDir)
|
||||
|
||||
probes := 0
|
||||
orig := checkBootstrapServerDB
|
||||
checkBootstrapServerDB = func(bootstrapServerProbeConfig) bootstrapServerDBCheck {
|
||||
probes++
|
||||
return bootstrapServerDBCheck{Reachable: true, Exists: false}
|
||||
}
|
||||
defer func() { checkBootstrapServerDB = orig }()
|
||||
origDelay := bootstrapRetryDelay
|
||||
bootstrapRetryDelay = func(time.Duration) {}
|
||||
defer func() { bootstrapRetryDelay = origDelay }()
|
||||
|
||||
plan := detectBootstrapAction(beadsDir, cfg)
|
||||
|
||||
if plan.Action != "refuse" {
|
||||
t.Fatalf("action = %q (reason %q), want refuse — an already-initialized workspace must never plan a fresh empty database", plan.Action, plan.Reason)
|
||||
}
|
||||
if probes != 1 {
|
||||
t.Errorf("probes = %d, want exactly 1 — the refusal must reuse the plan-time probe, not dial again", probes)
|
||||
}
|
||||
if !strings.Contains(plan.Reason, "mydb") {
|
||||
t.Errorf("reason = %q does not name the database", plan.Reason)
|
||||
}
|
||||
if strings.Contains(plan.Reason, "\x1b[") {
|
||||
t.Errorf("reason = %q carries ANSI escapes; --json consumers must get plain text", plan.Reason)
|
||||
}
|
||||
if plan.refusalDetail == "" {
|
||||
t.Error("refusalDetail is empty — the operator-facing explanation is lost")
|
||||
}
|
||||
if !strings.Contains(plan.refusalDetail, "will NOT create") {
|
||||
t.Errorf("refusalDetail = %q does not read as a refusal", plan.refusalDetail)
|
||||
}
|
||||
|
||||
// The machine-readable surface is what provisioning scripts consume, and
|
||||
// "blocked" — not the action string — is the discriminator they are
|
||||
// documented to switch on (see the BootstrapPlan.Blocked comment). A
|
||||
// refusal produced no database, so it must carry the flag; otherwise it is
|
||||
// the one no-database outcome a "blocked"-keyed consumer reads as success.
|
||||
if !plan.Blocked {
|
||||
t.Error("Blocked = false on a refuse plan — a run that produced no database must set the flag scripts key on")
|
||||
}
|
||||
raw, err := json.Marshal(plan)
|
||||
if err != nil {
|
||||
t.Fatalf("json.Marshal(plan): %v", err)
|
||||
}
|
||||
var decoded map[string]any
|
||||
if err := json.Unmarshal(raw, &decoded); err != nil {
|
||||
t.Fatalf("unmarshal plan JSON %s: %v", raw, err)
|
||||
}
|
||||
if decoded["action"] != "refuse" {
|
||||
t.Errorf("json action = %v, want refuse", decoded["action"])
|
||||
}
|
||||
// "blocked" is omitempty, so a false flag does not render as false — the
|
||||
// key vanishes entirely and the consumer cannot tell this run from a
|
||||
// successful one.
|
||||
if decoded["blocked"] != true {
|
||||
t.Errorf("json blocked = %v, want true; full plan JSON: %s", decoded["blocked"], raw)
|
||||
}
|
||||
if strings.Contains(string(raw), "\x1b[") {
|
||||
t.Errorf("plan JSON carries ANSI escapes, which --json consumers must never receive: %s", raw)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDetectBootstrapAction_RefusePlanDropsUnverifiedSyncRemote pins that a
|
||||
// refusal honours SyncRemote's documented "empty on a Blocked plan" contract.
|
||||
// A forge sync.remote with no Dolt data yet is recorded on the plan for the
|
||||
// workspace bootstrap expected to create (planConfiguredSyncRemote keeps it
|
||||
// and returns done=false), and the refusal is downstream of that — so without
|
||||
// explicit clearing the credential-bearing URL rides out in --json for a run
|
||||
// that wired up nothing, cloned nothing and pushed nothing.
|
||||
func TestDetectBootstrapAction_RefusePlanDropsUnverifiedSyncRemote(t *testing.T) {
|
||||
beadsDir := newForgeSyncRemoteWorkspace(t, "https://github.com/org/repo.git")
|
||||
// Forge repo reachable, but no refs/dolt/data yet: sync.remote is recorded
|
||||
// and bootstrap keeps looking rather than cloning.
|
||||
stubProbeGitRemoteDoltData(t, func(string) (bool, error) { return false, nil })
|
||||
|
||||
cfg := configfile.DefaultConfig()
|
||||
cfg.DoltMode = configfile.DoltModeServer
|
||||
cfg.DoltDatabase = "mydb"
|
||||
// Never created: a fresh clone has no local shadow directory.
|
||||
cfg.DoltDataDir = filepath.Join(filepath.Dir(beadsDir), "dolt-data")
|
||||
cfg.ProjectID = "proj-already-initialized-456"
|
||||
t.Setenv("BEADS_DOLT_DATA_DIR", cfg.DoltDataDir)
|
||||
|
||||
orig := checkBootstrapServerDB
|
||||
checkBootstrapServerDB = func(bootstrapServerProbeConfig) bootstrapServerDBCheck {
|
||||
return bootstrapServerDBCheck{Reachable: true, Exists: false}
|
||||
}
|
||||
defer func() { checkBootstrapServerDB = orig }()
|
||||
origDelay := bootstrapRetryDelay
|
||||
bootstrapRetryDelay = func(time.Duration) {}
|
||||
defer func() { bootstrapRetryDelay = origDelay }()
|
||||
|
||||
plan := detectBootstrapAction(beadsDir, cfg)
|
||||
|
||||
if plan.Action != "refuse" {
|
||||
t.Fatalf("action = %q (reason %q), want refuse", plan.Action, plan.Reason)
|
||||
}
|
||||
if !plan.Blocked {
|
||||
t.Fatal("Blocked = false on a refuse plan")
|
||||
}
|
||||
if plan.SyncRemote != "" {
|
||||
t.Errorf("SyncRemote = %q on a Blocked plan, want empty — the refusal creates no workspace, so nothing may be cloned from or pushed to that remote", plan.SyncRemote)
|
||||
}
|
||||
raw, err := json.Marshal(plan)
|
||||
if err != nil {
|
||||
t.Fatalf("json.Marshal(plan): %v", err)
|
||||
}
|
||||
var decoded map[string]any
|
||||
if err := json.Unmarshal(raw, &decoded); err != nil {
|
||||
t.Fatalf("unmarshal plan JSON %s: %v", raw, err)
|
||||
}
|
||||
if got, ok := decoded["sync_remote"]; ok {
|
||||
t.Errorf("plan JSON carries sync_remote = %v on a Blocked plan; full JSON: %s", got, raw)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPrintBootstrapPlan_RefusePrintsSummaryNotDetail covers the refuse arm of
|
||||
// printBootstrapPlan, which no test reached. The full explanation is the error
|
||||
// executeBootstrapPlan returns, so printing refusalDetail here too would render
|
||||
// it twice — a regression a future edit could reintroduce silently.
|
||||
func TestPrintBootstrapPlan_RefusePrintsSummaryNotDetail(t *testing.T) {
|
||||
plan := BootstrapPlan{
|
||||
Action: "refuse",
|
||||
Database: "mydb",
|
||||
Reason: `Database "mydb" not found on server at 127.0.0.1:3307; workspace already initialized (project_id set) — refusing to create an empty database`,
|
||||
// A marker no production string can produce, so a match is proof the
|
||||
// detail field itself was printed rather than wording that overlaps.
|
||||
refusalDetail: "REFUSAL-DETAIL-MARKER: bd bootstrap will NOT create an empty database here",
|
||||
Blocked: true,
|
||||
}
|
||||
|
||||
out := captureStdout(t, func() error {
|
||||
printBootstrapPlan(plan)
|
||||
return nil
|
||||
})
|
||||
|
||||
if !strings.Contains(out, "refuse — will NOT create a database") {
|
||||
t.Errorf("output does not announce the refusal:\n%s", out)
|
||||
}
|
||||
if !strings.Contains(out, plan.Reason) {
|
||||
t.Errorf("output omits the one-line reason:\n%s", out)
|
||||
}
|
||||
if strings.Contains(out, "REFUSAL-DETAIL-MARKER") {
|
||||
t.Errorf("printBootstrapPlan printed refusalDetail; executeBootstrapPlan already returns it, so the operator would read the whole explanation twice:\n%s", out)
|
||||
}
|
||||
}
|
||||
|
||||
// TestExecuteBootstrapPlan_RefuseErrsWithoutPrompting pins that a refuse plan
|
||||
// never reaches confirmPrompt or the workspace gates: it is a decision, not an
|
||||
// action awaiting approval. Before this, the refusal was discovered inside
|
||||
// executeInitAction — i.e. after the operator had already answered "Proceed?"
|
||||
// to a plan that said the opposite.
|
||||
func TestExecuteBootstrapPlan_RefuseErrsWithoutPrompting(t *testing.T) {
|
||||
snapshotBootstrapEnv(t)
|
||||
config.ResetForTesting()
|
||||
t.Cleanup(config.ResetForTesting)
|
||||
tmpDir := t.TempDir()
|
||||
beadsDir := filepath.Join(tmpDir, ".beads")
|
||||
if err := os.MkdirAll(beadsDir, 0o750); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfg := configfile.DefaultConfig()
|
||||
cfg.DoltMode = configfile.DoltModeServer
|
||||
cfg.DoltDatabase = "mydb"
|
||||
cfg.ProjectID = "proj-existing-123"
|
||||
|
||||
probes := 0
|
||||
orig := checkBootstrapServerDB
|
||||
checkBootstrapServerDB = func(bootstrapServerProbeConfig) bootstrapServerDBCheck {
|
||||
probes++
|
||||
return bootstrapServerDBCheck{Reachable: true, Exists: false}
|
||||
}
|
||||
defer func() { checkBootstrapServerDB = orig }()
|
||||
|
||||
plan := BootstrapPlan{
|
||||
BeadsDir: beadsDir,
|
||||
Database: "mydb",
|
||||
Action: "refuse",
|
||||
Reason: "short summary",
|
||||
refusalDetail: "long refusal: bd bootstrap will NOT create an empty database here",
|
||||
}
|
||||
// nonInteractive=false so a confirmPrompt would be reached if one ran.
|
||||
err := executeBootstrapPlan(plan, cfg, false)
|
||||
if err == nil {
|
||||
t.Fatal("executeBootstrapPlan returned nil for a refuse plan — bootstrap would exit 0 having done nothing, hiding the refusal")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "will NOT create") {
|
||||
t.Errorf("error = %q, want the refusalDetail text", err.Error())
|
||||
}
|
||||
if probes != 0 {
|
||||
t.Errorf("probes = %d, want 0 — the decision was already made at plan time", probes)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDetectBootstrapAction_FreshCloneServerNameMatchStillSyncs pins the
|
||||
// POSITIVE half of the widened probe. Unlocking the server-side existence
|
||||
// check for ProjectID-bearing workspaces also unlocked its Exists==true arm,
|
||||
// and a reachable server merely holding a database of the configured NAME is
|
||||
// not proof that this workspace is bound to it — nothing checks project_id or
|
||||
// content. Before the widening such a clone never probed at all and always
|
||||
// fell through to sync.remote, so a stale or unrelated same-named database
|
||||
// (including one left behind by the very bug this guard fixes) must not
|
||||
// silently settle the plan as "nothing to do" and suppress the configured
|
||||
// recovery clone. The name match survives only as the fallback verdict, which
|
||||
// TestDetectBootstrapAction_NoLocalShadowDirStillLiveChecksExisting pins.
|
||||
func TestDetectBootstrapAction_FreshCloneServerNameMatchStillSyncs(t *testing.T) {
|
||||
beadsDir, cfg := freshServerModeCloneFixture(t)
|
||||
orig := checkBootstrapServerDB
|
||||
checkBootstrapServerDB = func(bootstrapServerProbeConfig) bootstrapServerDBCheck {
|
||||
return bootstrapServerDBCheck{Reachable: true, Exists: true}
|
||||
}
|
||||
defer func() { checkBootstrapServerDB = orig }()
|
||||
origDelay := bootstrapRetryDelay
|
||||
bootstrapRetryDelay = func(time.Duration) {}
|
||||
defer func() { bootstrapRetryDelay = origDelay }()
|
||||
|
||||
plan := detectBootstrapAction(beadsDir, cfg)
|
||||
if plan.Action != "sync" {
|
||||
t.Errorf("action = %q (reason %q), want sync — a server-side name match with no local evidence binding this workspace to that database must not mask configured sync.remote recovery", plan.Action, plan.Reason)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDetectBootstrapAction_ShadowDirServerNameMatchSettlesNone pins the other
|
||||
// half of the same gate: a populated local shadow directory IS evidence this
|
||||
// workspace is bound to the database the server confirmed, so the Exists
|
||||
// verdict must settle the plan immediately instead of being deferred behind
|
||||
// sync.remote. Deferring it would re-clone over a database that already exists
|
||||
// — GH#5037's Error 1007, which the comment above the settle gate exists to
|
||||
// prevent — and the fixture configures a sync.remote precisely so the
|
||||
// assertion discriminates: without the local-evidence half of
|
||||
// settledOnNameAlone, sync.remote wins and the action becomes "sync". The
|
||||
// Err-arm twin is TestDetectBootstrapAction_ShadowDirUnreachableServerStillReportsNone;
|
||||
// this is the Exists-arm one, which nothing covered.
|
||||
func TestDetectBootstrapAction_ShadowDirServerNameMatchSettlesNone(t *testing.T) {
|
||||
beadsDir, cfg := freshServerModeCloneFixture(t)
|
||||
if err := os.MkdirAll(filepath.Join(cfg.DoltDataDir, "mydb"), 0o750); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
orig := checkBootstrapServerDB
|
||||
checkBootstrapServerDB = func(bootstrapServerProbeConfig) bootstrapServerDBCheck {
|
||||
return bootstrapServerDBCheck{Reachable: true, Exists: true}
|
||||
}
|
||||
defer func() { checkBootstrapServerDB = orig }()
|
||||
origDelay := bootstrapRetryDelay
|
||||
bootstrapRetryDelay = func(time.Duration) {}
|
||||
defer func() { bootstrapRetryDelay = origDelay }()
|
||||
|
||||
plan := detectBootstrapAction(beadsDir, cfg)
|
||||
if plan.Action != "none" {
|
||||
t.Errorf("action = %q (reason %q), want none — with local evidence binding this workspace to the database the server reports, re-cloning it is GH#5037's Error 1007", plan.Action, plan.Reason)
|
||||
}
|
||||
if !plan.HasExisting {
|
||||
t.Error("HasExisting = false on a confirmed server-side database with local evidence")
|
||||
}
|
||||
// Discriminates the Exists arm from the Err arm's "Could not verify"
|
||||
// settle, which the same populated shadow directory also unlocks.
|
||||
if !strings.Contains(plan.Reason, "already exists on server") {
|
||||
t.Errorf("reason = %q, want the Exists-arm wording — a 'Could not verify' reason here means the probe result, not the local evidence, is what settled the plan", plan.Reason)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -324,12 +324,13 @@ var proxyCapabilityRegistry = []capabilityRow{
|
|||
refusedPath("repo sync", "proxy.repo.unsupported", ProxyReasonDesign, ""),
|
||||
|
||||
// --- dolt version-control verbs -----------------------------------------
|
||||
// CALL DOLT_PUSH/DOLT_PULL/DOLT_COMMIT are SQL procedures and the generic
|
||||
// repository that wraps them is already written; these need a use case and
|
||||
// a route, not proxy work. `dolt remote remove` is already routed, which is
|
||||
// the precedent.
|
||||
refusedPath("dolt commit", "proxy.dolt_commit.unsupported", ProxyReasonUnimplemented, trackVersionCtl).
|
||||
withHistory(HistoryDirectOnly),
|
||||
// CALL DOLT_PUSH/DOLT_PULL are SQL procedures and the generic repository
|
||||
// that wraps them is already written; these need a use case and a route,
|
||||
// not proxy work. `dolt remote remove` is already routed, which is the
|
||||
// precedent — and `dolt commit` has now followed it: GH#4995 supplied the
|
||||
// use case (it is the flush point dolt.auto-commit=batch/off defers to) and
|
||||
// runDoltCommitProxiedServer supplied the route, so its row moved to the
|
||||
// routed-history block below.
|
||||
refusedPath("dolt push", "proxy.dolt_push.unsupported", ProxyReasonUnimplemented, trackVersionCtl).
|
||||
withHistory(HistoryDirectOnly),
|
||||
refusedPath("dolt pull", "proxy.dolt_pull.unsupported", ProxyReasonUnimplemented, trackVersionCtl).
|
||||
|
|
@ -441,10 +442,14 @@ var proxyCapabilityRegistry = []capabilityRow{
|
|||
{Path: "duplicates", ArgSet: "--auto-merge --dry-run", Rule: proxyCapabilityRule{Outcome: ProxyOutcomeHonored}},
|
||||
|
||||
// --- routed history -----------------------------------------------------
|
||||
// The two paths that already have a proxied route, recorded so the class is
|
||||
// The paths that already have a proxied route, recorded so the class is
|
||||
// asserted rather than remembered.
|
||||
permitted("history").withHistory(HistoryProxySupported),
|
||||
permitted("dolt remote remove").withHistory(HistoryProxySupported),
|
||||
// `dolt commit` is routed by runDoltCommitProxiedServer. It is also the
|
||||
// flush point dolt.auto-commit=batch/off defers to (GH#4995), so refusing it
|
||||
// at the front door would leave those modes with no way to flush.
|
||||
permitted("dolt commit").withHistory(HistoryProxySupported),
|
||||
|
||||
// --- untyped refusals inside RunE ---------------------------------------
|
||||
// The gate permits these paths and the command refuses itself with a bare
|
||||
|
|
@ -488,7 +493,7 @@ var proxyPermittedPaths = []string{
|
|||
"comments", "comments add", "comments list",
|
||||
"dep", "dep add", "dep cycles", "dep list", "dep relate", "dep remove", "dep tree", "dep unrelate",
|
||||
"kv clear", "kv get", "kv list", "kv set",
|
||||
"label add", "label list", "label list-all", "label propagate", "label remove",
|
||||
"label add", "label list", "label list-all", "label propagate", "label remove", "label rename",
|
||||
|
||||
// molecules, epics, todos, state
|
||||
"epic close-eligible", "epic status",
|
||||
|
|
|
|||
|
|
@ -14,13 +14,17 @@ func TestHistoryCapabilityMatrixExactPaths(t *testing.T) {
|
|||
if got, ok := LookupHistoryCapability("history"); !ok || got != HistoryProxySupported {
|
||||
t.Fatalf("history = %q, %v; want proxy-supported", got, ok)
|
||||
}
|
||||
for _, path := range []string{"branch", "conflicts", "repo", "federation", "vc", "flatten", "dolt push", "dolt pull", "dolt commit", "dolt remote", "sync"} {
|
||||
for _, path := range []string{"branch", "conflicts", "repo", "federation", "vc", "flatten", "dolt push", "dolt pull", "dolt remote", "sync"} {
|
||||
if got, ok := LookupHistoryCapability(path); !ok || got != HistoryDirectOnly {
|
||||
t.Errorf("%q = %q, %v; want direct-only", path, got, ok)
|
||||
}
|
||||
}
|
||||
if got, ok := LookupHistoryCapability("dolt remote remove"); !ok || got != HistoryProxySupported {
|
||||
t.Fatalf("dolt remote remove = %q, %v; want proxy-supported", got, ok)
|
||||
// dolt commit is the flush point dolt.auto-commit=batch/off defers to
|
||||
// (GH#4995), so it must stay reachable on the proxied route.
|
||||
for _, path := range []string{"dolt remote remove", "dolt commit"} {
|
||||
if got, ok := LookupHistoryCapability(path); !ok || got != HistoryProxySupported {
|
||||
t.Fatalf("%s = %q, %v; want proxy-supported", path, got, ok)
|
||||
}
|
||||
}
|
||||
for _, path := range []string{"dolt remote add", "dolt remote list", "dolt remote reset-data"} {
|
||||
if got, ok := LookupHistoryCapability(path); !ok || got != HistoryDirectOnly {
|
||||
|
|
@ -52,7 +56,6 @@ func TestHistoryDirectOnlyRefusalContract(t *testing.T) {
|
|||
"flatten": {"proxy.flatten.unsupported", "flatten is not supported in proxied-server mode"},
|
||||
"dolt push": {"proxy.dolt_push.unsupported", "dolt push is not supported in proxied-server mode"},
|
||||
"dolt pull": {"proxy.dolt_pull.unsupported", "dolt pull is not supported in proxied-server mode"},
|
||||
"dolt commit": {"proxy.dolt_commit.unsupported", "dolt commit is not supported in proxied-server mode"},
|
||||
"dolt remote add": {"proxy.dolt_remote.unsupported", "dolt remote add is not supported in proxied-server mode"},
|
||||
"dolt remote list": {"proxy.dolt_remote.unsupported", "dolt remote list is not supported in proxied-server mode"},
|
||||
"dolt remote reset-data": {"proxy.dolt_remote.unsupported", "dolt remote reset-data is not supported in proxied-server mode"},
|
||||
|
|
@ -99,7 +102,7 @@ func TestHistoryNestedFrontDoorsRefuseAndSupportedPathsPass(t *testing.T) {
|
|||
"conflicts resolve": {"proxy.conflicts.unsupported", "conflicts resolve is not supported in proxied-server mode"},
|
||||
"federation sync": {"proxy.federation.unsupported", "federation sync is not supported in proxied-server mode"},
|
||||
}
|
||||
for _, path := range []string{"vc merge", "vc commit", "repo add", "conflicts resolve", "federation sync", "dolt remote remove"} {
|
||||
for _, path := range []string{"vc merge", "vc commit", "repo add", "conflicts resolve", "federation sync", "dolt remote remove", "dolt commit"} {
|
||||
parts := strings.Split(path, " ")
|
||||
root := &cobra.Command{Use: "bd"}
|
||||
cmd := &cobra.Command{Use: parts[0]}
|
||||
|
|
@ -110,7 +113,7 @@ func TestHistoryNestedFrontDoorsRefuseAndSupportedPathsPass(t *testing.T) {
|
|||
cmd = child
|
||||
}
|
||||
err := validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal)
|
||||
if path == "dolt remote remove" {
|
||||
if path == "dolt remote remove" || path == "dolt commit" {
|
||||
if err != nil {
|
||||
t.Fatalf("supported %s refused: %v", path, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ import (
|
|||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/steveyegge/beads/internal/testutil/bazeltest"
|
||||
)
|
||||
|
||||
// Fast CLI tests converted from scripttest suite
|
||||
|
|
@ -1016,13 +1018,11 @@ func init() {
|
|||
// Prebuilt fast path (scripts/test.sh and CI export this), else build
|
||||
// once. No repo-root ./bd reuse: a stale checkout-root binary silently
|
||||
// substitutes itself for the source under test (wy-4mtr0).
|
||||
if prebuilt := os.Getenv("BEADS_TEST_BD_BINARY"); prebuilt != "" {
|
||||
if abs, err := filepath.Abs(prebuilt); err == nil {
|
||||
if _, statErr := os.Stat(abs); statErr == nil {
|
||||
testBD = abs
|
||||
return
|
||||
}
|
||||
}
|
||||
if prebuilt, err := findPrebuiltBDBinary(); err == nil && prebuilt != "" {
|
||||
testBD = prebuilt
|
||||
return
|
||||
} else if bazeltest.IsBazel() {
|
||||
panic(fmt.Sprintf("bd binary for tests: %v", err))
|
||||
}
|
||||
bdBinary := "bd"
|
||||
if runtime.GOOS == "windows" {
|
||||
|
|
|
|||
|
|
@ -134,6 +134,76 @@ func TestEmbeddedClose(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
// The direct-route twin of TestProxiedClose/
|
||||
// close_partial_failure_json_names_the_failed_ids. Two things were asserted
|
||||
// on the proxied route only: that exit 1 comes with a payload naming the
|
||||
// failed ids while stdout keeps the success-shaped closed-issues array, and
|
||||
// that failed[].error is the TYPED error rather than the decorated line
|
||||
// stderr shows a person. This is the default route — what most scripts and
|
||||
// the parity harness exercise — so a regression in reportCloseFailures'
|
||||
// jsonOut branch was previously invisible to CI on the route most callers
|
||||
// are on, and the two routes could drift on the field's contents with
|
||||
// nothing failing.
|
||||
t.Run("close_partial_failure_json_names_the_failed_ids", func(t *testing.T) {
|
||||
jdir, _, _ := bdInit(t, bd, "--prefix", "jf")
|
||||
closable := bdCreate(t, bd, jdir, "JSON closable", "--type", "task")
|
||||
blocker := bdCreate(t, bd, jdir, "JSON blocker", "--type", "task")
|
||||
blocked := bdCreate(t, bd, jdir, "JSON blocked", "--type", "task")
|
||||
bdDepAdd(t, bd, jdir, blocked.ID, blocker.ID)
|
||||
|
||||
cmd := exec.Command(bd, "close", "--json", closable.ID, blocked.ID)
|
||||
cmd.Dir = jdir
|
||||
cmd.Env = bdEnv(jdir)
|
||||
stdoutBuf, stderrBuf, err := runCommandBuffers(t, cmd)
|
||||
stdout, stderr := stdoutBuf.String(), stderrBuf.String()
|
||||
if err == nil {
|
||||
t.Fatalf("expected a partial batch close to exit nonzero\nstdout:\n%s\nstderr:\n%s", stdout, stderr)
|
||||
}
|
||||
|
||||
// stdout keeps the success shape: just the survivor.
|
||||
start := strings.Index(stdout, "[")
|
||||
if start < 0 {
|
||||
t.Fatalf("expected the closed-issues array on stdout, got:\n%s", stdout)
|
||||
}
|
||||
var closed []*types.Issue
|
||||
if jsonErr := json.Unmarshal([]byte(stdout[start:]), &closed); jsonErr != nil {
|
||||
t.Fatalf("parse closed array: %v\nraw: %s", jsonErr, stdout[start:])
|
||||
}
|
||||
if len(closed) != 1 || closed[0].ID != closable.ID {
|
||||
t.Fatalf("stdout closed array = %d issue(s), want only the survivor %s\nraw: %s", len(closed), closable.ID, stdout[start:])
|
||||
}
|
||||
|
||||
// stderr's last line is the failure report.
|
||||
line := lastJSONObjectLine(stderr)
|
||||
if line == "" {
|
||||
t.Fatalf("expected a compact JSON failure line on stderr, got:\n%s", stderr)
|
||||
}
|
||||
var report struct {
|
||||
Error string `json:"error"`
|
||||
Failed []struct {
|
||||
ID string `json:"id"`
|
||||
Error string `json:"error"`
|
||||
} `json:"failed"`
|
||||
}
|
||||
if jsonErr := json.Unmarshal([]byte(line), &report); jsonErr != nil {
|
||||
t.Fatalf("parse failure report: %v\nraw: %s", jsonErr, line)
|
||||
}
|
||||
if report.Error != "1 of 2 issues failed to close" {
|
||||
t.Errorf("failure report error = %q, want the N of M summary", report.Error)
|
||||
}
|
||||
if len(report.Failed) != 1 || report.Failed[0].ID != blocked.ID {
|
||||
t.Fatalf("failure report named %+v, want exactly the refused id %s", report.Failed, blocked.ID)
|
||||
}
|
||||
assertCloseFailedErrorIsTyped(t, report.Failed[0].Error, stderr)
|
||||
|
||||
if got := bdShow(t, bd, jdir, closable.ID); got.Status != types.StatusClosed {
|
||||
t.Errorf("closable issue status = %s, want closed despite the refused sibling", got.Status)
|
||||
}
|
||||
if got := bdShow(t, bd, jdir, blocked.ID); got.Status != types.StatusOpen {
|
||||
t.Errorf("blocked issue status = %s, want open", got.Status)
|
||||
}
|
||||
})
|
||||
|
||||
// The --claim-next × partial-failure interaction, adjudicated rather than
|
||||
// left implicit (#6648). --claim-next rides inside the batch transaction
|
||||
// and fires whenever something LANDED, so a mixed batch claims and then
|
||||
|
|
|
|||
281
cmd/bd/close_failure_report_test.go
Normal file
281
cmd/bd/close_failure_report_test.go
Normal file
|
|
@ -0,0 +1,281 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/issueops"
|
||||
)
|
||||
|
||||
// assertCloseFailedErrorIsTyped checks one failed[].error entry against the
|
||||
// route-parity contract both close routes owe a --json consumer: the field
|
||||
// carries the typed error, while the line a person reads keeps the --force hint.
|
||||
//
|
||||
// The two integration suites share it, which is the point — a contract that is
|
||||
// supposed to be identical per route should be asserted by identical code. It is
|
||||
// written against the RELATIONSHIP between the two spellings rather than a
|
||||
// transcribed sentence so neither suite has to hardcode how the engine renders a
|
||||
// blocker list: closeDirectRefusal and closeProxiedRefusal both produce exactly
|
||||
// the typed error plus the hint, so the typed error must appear on stderr with
|
||||
// the hint appended and must not contain the hint itself.
|
||||
//
|
||||
// Lives in an untagged file so it is compiled in the CGO_ENABLED=0 lane too,
|
||||
// alongside the pins below; its callers are the cgo-gated suites.
|
||||
func assertCloseFailedErrorIsTyped(t *testing.T, failedError, stderr string) {
|
||||
t.Helper()
|
||||
const hint = " (use --force to override)"
|
||||
if !strings.HasPrefix(failedError, "cannot close blocked issue:") {
|
||||
t.Errorf("failed[].error = %q, want the engine's typed ErrCloseBlocked vocabulary: both routes must spell one refusal one way",
|
||||
failedError)
|
||||
}
|
||||
if strings.Contains(failedError, hint) {
|
||||
t.Errorf("failed[].error = %q carries the --force hint; that decoration is advice for a human reader and belongs on the stderr line only",
|
||||
failedError)
|
||||
}
|
||||
if want := failedError + hint; !strings.Contains(stderr, want) {
|
||||
t.Errorf("stderr is missing the decorated refusal %q; the hint must still reach the person reading it\nstderr:\n%s",
|
||||
want, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// The route-parity contract for the machine-readable half of the partial-failure
|
||||
// report: `failed[].error` carries the TYPED error on both routes, and the
|
||||
// decorated display line stays on stderr where a human reads it.
|
||||
//
|
||||
// The direct route already splits the two (close.go records res.Err.Error() in
|
||||
// closeIDFailure while printing closeDirectRefusal's decorated line). The proxied
|
||||
// route used to copy pre.errors — the display line — into the JSON field, so the
|
||||
// same blocked-id refusal answered "cannot close blocked issue: X is blocked by
|
||||
// [Y]" embedded and "... (use --force to override)" proxied. These live here
|
||||
// rather than in the proxied integration suite because nothing in the split needs
|
||||
// a server: the refusal slots are filled by closeProxiedOutcomes and read by
|
||||
// closeProxiedFailures, both pure.
|
||||
func TestCloseProxiedFailuresRecordTheTypedErrorNotTheDisplayLine(t *testing.T) {
|
||||
blockedErr := fmt.Errorf("%w: pb-2 is blocked by [pb-1]", storage.ErrCloseBlocked)
|
||||
|
||||
// arg 0 closes, arg 1 is refused by the engine.
|
||||
args := []string{"pb-3", "pb-2"}
|
||||
pre := closeProxiedPreflight{
|
||||
items: []issueops.BatchCloseItem{
|
||||
{IssueID: "pb-3", Reason: "done"},
|
||||
{IssueID: "pb-2", Reason: "done"},
|
||||
},
|
||||
itemArgs: []int{0, 1},
|
||||
before: map[string]*types.Issue{"pb-3": {ID: "pb-3"}},
|
||||
errors: make([]string, len(args)),
|
||||
failureErrors: make([]string, len(args)),
|
||||
}
|
||||
outcomes, _ := closeProxiedOutcomes(&pre, issueops.CloseBatchResult{
|
||||
Outcomes: []issueops.CloseOutcome{
|
||||
{IssueID: "pb-3", Issue: &types.Issue{ID: "pb-3"}, Changed: true},
|
||||
{IssueID: "pb-2", Err: blockedErr},
|
||||
},
|
||||
})
|
||||
if len(outcomes) != 1 || outcomes[0].id != "pb-3" {
|
||||
t.Fatalf("outcomes = %+v, want only the survivor pb-3", outcomes)
|
||||
}
|
||||
|
||||
failures := closeProxiedFailures(&pre, args)
|
||||
if len(failures) != 1 || failures[0].ID != "pb-2" {
|
||||
t.Fatalf("failures = %+v, want exactly the refused id pb-2", failures)
|
||||
}
|
||||
|
||||
// The machine field is the typed error, byte for byte.
|
||||
if failures[0].Error != blockedErr.Error() {
|
||||
t.Errorf("failed[].error = %q, want the typed error %q: a --json consumer keying off this field must see the same string on both routes",
|
||||
failures[0].Error, blockedErr.Error())
|
||||
}
|
||||
if strings.Contains(failures[0].Error, "use --force to override") {
|
||||
t.Errorf("failed[].error = %q, must not carry the --force hint: that is advice for a human reader, and the direct route records res.Err.Error() here",
|
||||
failures[0].Error)
|
||||
}
|
||||
|
||||
// ...and the human line keeps the decoration. Without this half the fix
|
||||
// could have passed by stripping the hint from stderr too, which is a
|
||||
// different regression.
|
||||
if want := closeProxiedRefusal("pb-2", blockedErr); pre.errors[1] != want {
|
||||
t.Errorf("stderr line = %q, want the decorated refusal %q", pre.errors[1], want)
|
||||
}
|
||||
if !strings.Contains(pre.errors[1], "use --force to override") {
|
||||
t.Errorf("stderr line = %q, want it to keep the --force hint for the person reading it", pre.errors[1])
|
||||
}
|
||||
}
|
||||
|
||||
// Every engine refusal class closeProxiedRefusal decorates, checked against the
|
||||
// typed error it decorates. ErrCloseOpenChildren is in the table on purpose: it
|
||||
// passes through undecorated, so it is the row that would still pass if the fix
|
||||
// had been written as "special-case the blocked hint" instead of "record the
|
||||
// typed error".
|
||||
func TestCloseProxiedFailuresTypedErrorPerRefusalClass(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
err error
|
||||
}{
|
||||
{
|
||||
name: "blocked gains the force hint on stderr",
|
||||
err: fmt.Errorf("%w: rc-1 is blocked by [rc-9]", storage.ErrCloseBlocked),
|
||||
},
|
||||
{
|
||||
name: "not found is rewritten on stderr",
|
||||
err: fmt.Errorf("%w: rc-1", storage.ErrNotFound),
|
||||
},
|
||||
{
|
||||
name: "default class is wrapped on stderr",
|
||||
err: fmt.Errorf("dolt: connection reset"),
|
||||
},
|
||||
{
|
||||
name: "open children passes through undecorated",
|
||||
err: &storage.CloseOpenChildrenError{IssueID: "rc-1", OpenChildren: 2},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
args := []string{"rc-1"}
|
||||
pre := closeProxiedPreflight{
|
||||
items: []issueops.BatchCloseItem{{IssueID: "rc-1", Reason: "done"}},
|
||||
itemArgs: []int{0},
|
||||
before: map[string]*types.Issue{},
|
||||
errors: make([]string, len(args)),
|
||||
failureErrors: make([]string, len(args)),
|
||||
}
|
||||
closeProxiedOutcomes(&pre, issueops.CloseBatchResult{
|
||||
Outcomes: []issueops.CloseOutcome{{IssueID: "rc-1", Err: tc.err}},
|
||||
})
|
||||
|
||||
failures := closeProxiedFailures(&pre, args)
|
||||
if len(failures) != 1 {
|
||||
t.Fatalf("failures = %+v, want one", failures)
|
||||
}
|
||||
if failures[0].Error != tc.err.Error() {
|
||||
t.Errorf("failed[].error = %q, want the typed error %q", failures[0].Error, tc.err.Error())
|
||||
}
|
||||
if pre.errors[0] != closeProxiedRefusal("rc-1", tc.err) {
|
||||
t.Errorf("stderr line = %q, want closeProxiedRefusal's spelling %q", pre.errors[0], closeProxiedRefusal("rc-1", tc.err))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// The second half of the route-parity contract, and the one the decoration fix
|
||||
// alone does not deliver: a refusal that reached the proxied route arrives
|
||||
// wrapped by the layers it travelled through, so even the undecorated typed
|
||||
// error read differently per route until closeProxiedTypedRefusal unwrapped it.
|
||||
//
|
||||
// The wrapper strings here are transcribed from the two production sites named
|
||||
// in that function's comment, and the "want" column is the byte-identical
|
||||
// string the direct route records for the same refusal.
|
||||
func TestCloseProxiedTypedRefusalUnwrapsTheRoleWrappers(t *testing.T) {
|
||||
blocked := fmt.Errorf("%w: wr-1 is blocked by [wr-2]", storage.ErrCloseBlocked)
|
||||
openChildren := &storage.CloseOpenChildrenError{IssueID: "wr-1", OpenChildren: 3}
|
||||
unexpected := fmt.Errorf("dolt: connection reset")
|
||||
|
||||
// What the role actually hands back: db/issue.go wraps, then issue.go wraps.
|
||||
roleWrapped := func(inner error) error {
|
||||
return fmt.Errorf("close wr-1: %w", fmt.Errorf("db: IssueSQLRepository.CloseChecked wr-1: %w", inner))
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
err error
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "blocked, unwrapped",
|
||||
err: blocked,
|
||||
want: blocked.Error(),
|
||||
},
|
||||
{
|
||||
name: "blocked, wrapped by the role",
|
||||
err: roleWrapped(blocked),
|
||||
want: blocked.Error(),
|
||||
},
|
||||
{
|
||||
name: "open children, wrapped by the role",
|
||||
err: roleWrapped(openChildren),
|
||||
want: openChildren.Error(),
|
||||
},
|
||||
{
|
||||
// No sentinel to converge on, and the chain is the only thing that
|
||||
// says where the failure came from, so it is kept whole.
|
||||
name: "unexpected error keeps its whole chain",
|
||||
err: roleWrapped(unexpected),
|
||||
want: "close wr-1: db: IssueSQLRepository.CloseChecked wr-1: dolt: connection reset",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := closeProxiedTypedRefusal(tc.err); got != tc.want {
|
||||
t.Errorf("closeProxiedTypedRefusal = %q, want %q", got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// The walk must stop AT the refusal, not at the bare sentinel underneath
|
||||
// it: unwrapping one link too far would drop the subject and leave every
|
||||
// blocked id reporting the same reasonless sentence.
|
||||
if got := closeProxiedTypedRefusal(roleWrapped(blocked)); got == storage.ErrCloseBlocked.Error() {
|
||||
t.Errorf("closeProxiedTypedRefusal = %q, which is the bare sentinel: the id and its blockers were unwrapped away", got)
|
||||
}
|
||||
}
|
||||
|
||||
// A refusal decided by the CLI's own close policy has no separate display form,
|
||||
// so both fields hold the one sentence closeProxiedCheckOne returned — and the
|
||||
// failures still come back in the order the caller typed the ids, across a mix
|
||||
// of policy and engine refusals. errors is what decides WHICH arguments failed,
|
||||
// so a policy slot with an empty failureErrors twin would be a silent
|
||||
// reason-less entry; this pins that it is not.
|
||||
func TestCloseProxiedFailuresKeepPolicyRefusalsAndTypedOrder(t *testing.T) {
|
||||
policyRefusal := "cannot close mx-1: gate not satisfied"
|
||||
engineErr := fmt.Errorf("%w: mx-3 is blocked by [mx-9]", storage.ErrCloseBlocked)
|
||||
|
||||
// arg 0 refused by policy, arg 1 closes, arg 2 refused by the engine.
|
||||
args := []string{"mx-1", "mx-2", "mx-3"}
|
||||
pre := closeProxiedPreflight{
|
||||
items: []issueops.BatchCloseItem{
|
||||
{IssueID: "mx-2", Reason: "done"},
|
||||
{IssueID: "mx-3", Reason: "done"},
|
||||
},
|
||||
itemArgs: []int{1, 2},
|
||||
before: map[string]*types.Issue{"mx-2": {ID: "mx-2"}},
|
||||
errors: make([]string, len(args)),
|
||||
failureErrors: make([]string, len(args)),
|
||||
}
|
||||
// closeProxiedRunPreflight fills both slots for a policy refusal.
|
||||
pre.errors[0] = policyRefusal
|
||||
pre.failureErrors[0] = policyRefusal
|
||||
|
||||
closeProxiedOutcomes(&pre, issueops.CloseBatchResult{
|
||||
Outcomes: []issueops.CloseOutcome{
|
||||
{IssueID: "mx-2", Issue: &types.Issue{ID: "mx-2"}, Changed: true},
|
||||
{IssueID: "mx-3", Err: engineErr},
|
||||
},
|
||||
})
|
||||
|
||||
failures := closeProxiedFailures(&pre, args)
|
||||
want := []closeIDFailure{
|
||||
{ID: "mx-1", Error: policyRefusal},
|
||||
{ID: "mx-3", Error: engineErr.Error()},
|
||||
}
|
||||
if len(failures) != len(want) {
|
||||
t.Fatalf("failures = %+v, want %+v", failures, want)
|
||||
}
|
||||
for i := range want {
|
||||
if failures[i] != want[i] {
|
||||
t.Errorf("failures[%d] = %+v, want %+v", i, failures[i], want[i])
|
||||
}
|
||||
}
|
||||
|
||||
// An entry never goes out reason-less. No production writer can reach this
|
||||
// state — both fill the twin — but the degradation is defined rather than
|
||||
// accidental, because an empty reason is the one answer a caller asking why
|
||||
// an id failed cannot use.
|
||||
pre.failureErrors[0] = ""
|
||||
if got := closeProxiedFailures(&pre, args); got[0].Error != policyRefusal {
|
||||
t.Errorf("failures[0].Error = %q, want the display line %q as the fallback", got[0].Error, policyRefusal)
|
||||
}
|
||||
}
|
||||
84
cmd/bd/close_fanin_proxied_integration_test.go
Normal file
84
cmd/bd/close_fanin_proxied_integration_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,8 @@ import (
|
|||
// pollute parsed values (e.g. an issue ID from `bd q`).
|
||||
func runBDStdout(t *testing.T, binPath, workDir string, args ...string) string {
|
||||
t.Helper()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
// 2m, not 30s: a -race bd under a loaded CI host has taken >30s for one init.
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
||||
defer cancel()
|
||||
cmd := exec.CommandContext(ctx, binPath, args...)
|
||||
cmd.Dir = workDir
|
||||
|
|
|
|||
|
|
@ -449,6 +449,15 @@ func TestProxiedServerClose(t *testing.T) {
|
|||
if report.Failed[0].Error == "" {
|
||||
t.Errorf("failure report for %s carried no reason", blocked.ID)
|
||||
}
|
||||
|
||||
// failed[].error is the TYPED error, the same on this route as on the
|
||||
// direct one — see the twin assertions in TestEmbeddedClose/
|
||||
// close_partial_failure_json_names_the_failed_ids. The --force hint is
|
||||
// advice for a human reader, so it belongs on the stderr line above and
|
||||
// not in the field a --json consumer keys off; recording the decorated
|
||||
// display line here gave the identical refusal two spellings depending
|
||||
// on which route the caller was on.
|
||||
assertCloseFailedErrorIsTyped(t, report.Failed[0].Error, stderr)
|
||||
})
|
||||
|
||||
t.Run("close_pinned_refuses_without_force", func(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -39,11 +39,22 @@ type closeProxiedInput struct {
|
|||
// errors is indexed by ARGUMENT position, not by item, so a refusal reported
|
||||
// here and one reported by the batch still print in the order the caller typed
|
||||
// the ids.
|
||||
//
|
||||
// failureErrors is the same list at the same indices, but carries what a --json
|
||||
// consumer reads instead of what a person reads: the TYPED error for an engine
|
||||
// refusal, where errors holds closeProxiedRefusal's decorated display line. The
|
||||
// direct route makes exactly this split (close.go records res.Err.Error() in
|
||||
// closeIDFailure while printing closeDirectRefusal), and keeping the decorated
|
||||
// line in the machine-readable field made the same refusal answer differently
|
||||
// per route — which is the drift this whole close rewire exists to remove. A
|
||||
// policy refusal decided here has no separate display form, so both slots hold
|
||||
// the one sentence closeProxiedCheckOne returned.
|
||||
type closeProxiedPreflight struct {
|
||||
items []issueops.BatchCloseItem
|
||||
itemArgs []int
|
||||
before map[string]*types.Issue
|
||||
errors []string
|
||||
items []issueops.BatchCloseItem
|
||||
itemArgs []int
|
||||
before map[string]*types.Issue
|
||||
errors []string
|
||||
failureErrors []string
|
||||
}
|
||||
|
||||
type closeProxiedOutcome struct {
|
||||
|
|
@ -122,15 +133,12 @@ func runCloseProxiedServer(cmd *cobra.Command, ctx context.Context, args []strin
|
|||
outcomes, closeReasons := closeProxiedOutcomes(&pre, result)
|
||||
post := closeProxiedRunPostClose(ctx, args, in, outcomes)
|
||||
|
||||
// pre.errors is indexed by argument position, so args[i] is the id this
|
||||
// refusal belongs to.
|
||||
var failures []closeIDFailure
|
||||
for i, e := range pre.errors {
|
||||
for _, e := range pre.errors {
|
||||
if e != "" {
|
||||
fmt.Fprintln(os.Stderr, e)
|
||||
failures = append(failures, closeIDFailure{ID: args[i], Error: e})
|
||||
}
|
||||
}
|
||||
failures := closeProxiedFailures(&pre, args)
|
||||
for _, w := range post.warnings {
|
||||
fmt.Fprintf(os.Stderr, "Warning: %s\n", w)
|
||||
}
|
||||
|
|
@ -230,14 +238,19 @@ func proxiedBatchCloser() (issueops.BatchCloser, error) {
|
|||
// close policy to it, in one read-only unit of work.
|
||||
func closeProxiedRunPreflight(ctx context.Context, args, reasons []string, in closeProxiedInput) (closeProxiedPreflight, error) {
|
||||
pre := closeProxiedPreflight{
|
||||
errors: make([]string, len(args)),
|
||||
before: make(map[string]*types.Issue, len(args)),
|
||||
errors: make([]string, len(args)),
|
||||
failureErrors: make([]string, len(args)),
|
||||
before: make(map[string]*types.Issue, len(args)),
|
||||
}
|
||||
_, err := uow.RunTxRead(ctx, uowProvider, func(ctx context.Context, uw uow.UnitOfWork) (struct{}, error) {
|
||||
for i, id := range args {
|
||||
refusal, current := closeProxiedCheckOne(ctx, uw, id, in)
|
||||
if refusal != "" {
|
||||
pre.errors[i] = refusal
|
||||
// A policy refusal is already the bare sentence, so the human
|
||||
// and machine fields agree; only the engine refusals below have
|
||||
// a decorated display form to strip.
|
||||
pre.failureErrors[i] = refusal
|
||||
continue
|
||||
}
|
||||
pre.before[id] = current
|
||||
|
|
@ -299,6 +312,10 @@ func closeProxiedOutcomes(pre *closeProxiedPreflight, result issueops.CloseBatch
|
|||
item := pre.items[j]
|
||||
if outcome.Err != nil {
|
||||
pre.errors[pre.itemArgs[j]] = closeProxiedRefusal(item.IssueID, outcome.Err)
|
||||
// The typed error, not the decorated display line: the --force hint
|
||||
// closeProxiedRefusal appends is advice for a human reader, and the
|
||||
// id already has its own field. Same split as the direct route.
|
||||
pre.failureErrors[pre.itemArgs[j]] = closeProxiedTypedRefusal(outcome.Err)
|
||||
continue
|
||||
}
|
||||
before := pre.before[item.IssueID]
|
||||
|
|
@ -326,6 +343,82 @@ func closeProxiedOutcomes(pre *closeProxiedPreflight, result issueops.CloseBatch
|
|||
return outcomes, reasons
|
||||
}
|
||||
|
||||
// closeProxiedFailures pairs every refused argument with the id it belongs to,
|
||||
// for the machine-readable half of the partial-failure report.
|
||||
//
|
||||
// Both slices are indexed by ARGUMENT position, so args[i] is the id that earned
|
||||
// pre.errors[i], and the failures come back in the order the caller typed the
|
||||
// ids. errors decides WHICH arguments failed — it is the slot the stderr print
|
||||
// consults too, so the two halves of the report can never disagree about that —
|
||||
// while failureErrors supplies the reason, because that is the field where the
|
||||
// typed error belongs.
|
||||
//
|
||||
// Every writer of an errors slot fills its failureErrors twin, so the fallback
|
||||
// below is unreachable today. It is here because the cost of getting that wrong
|
||||
// is asymmetric: a caller that asked why an id failed is better served by the
|
||||
// decorated line than by an empty string, so a future writer that forgets the
|
||||
// twin degrades the wording instead of dropping the reason.
|
||||
func closeProxiedFailures(pre *closeProxiedPreflight, args []string) []closeIDFailure {
|
||||
var failures []closeIDFailure
|
||||
for i, e := range pre.errors {
|
||||
if e == "" {
|
||||
continue
|
||||
}
|
||||
reason := pre.failureErrors[i]
|
||||
if reason == "" {
|
||||
reason = e
|
||||
}
|
||||
failures = append(failures, closeIDFailure{ID: args[i], Error: reason})
|
||||
}
|
||||
return failures
|
||||
}
|
||||
|
||||
// closeProxiedTypedRefusal is the reason a --json consumer reads for one
|
||||
// refused id: the typed error, spelled the way the direct route spells it.
|
||||
//
|
||||
// Stripping closeProxiedRefusal's decoration is not enough on its own to make
|
||||
// the two routes agree, because a refusal reaching this route has also been
|
||||
// wrapped by the layers it traveled through — the use case adds "close <id>: "
|
||||
// (storage/domain/issue.go) and the SQL repository adds
|
||||
// "db: IssueSQLRepository.CloseChecked <id>: " (storage/domain/db/issue.go) —
|
||||
// while the direct route hands back the refusal exactly as the engine minted
|
||||
// it. So the same blocked id reads
|
||||
//
|
||||
// cannot close blocked issue: x-1 is blocked by [x-2] (direct)
|
||||
// close x-1: db: IssueSQLRepository.CloseChecked x-1: cannot close blocked … (proxied)
|
||||
//
|
||||
// For the refusal classes the CLI already names by sentinel, we report the
|
||||
// outermost error that the sentinel itself explains: that is the sentence the
|
||||
// engine wrote, and it is byte-identical to the direct route's. Neither wrap
|
||||
// tells a caller anything it does not know — it asked to close that id — and
|
||||
// one of them leaks an internal repository type name into an operator-facing
|
||||
// field.
|
||||
//
|
||||
// Anything outside those classes keeps its whole chain. There the wrapping is
|
||||
// not noise, it is the only thing that says where an unexpected failure came
|
||||
// from, and there is no engine sentence to converge on.
|
||||
func closeProxiedTypedRefusal(err error) string {
|
||||
for _, sentinel := range []error{storage.ErrCloseBlocked, storage.ErrCloseOpenChildren} {
|
||||
if !errors.Is(err, sentinel) {
|
||||
continue
|
||||
}
|
||||
// Walk in until the next link IS the bare sentinel: that link's parent
|
||||
// is the refusal with its subject filled in ("… x-1 is blocked by
|
||||
// [x-2]"), where the sentinel alone would say only "cannot close
|
||||
// blocked issue".
|
||||
refusal := err
|
||||
for {
|
||||
next := errors.Unwrap(refusal)
|
||||
if next == nil || next == sentinel || !errors.Is(next, sentinel) {
|
||||
break
|
||||
}
|
||||
refusal = next
|
||||
}
|
||||
return refusal.Error()
|
||||
}
|
||||
return err.Error()
|
||||
}
|
||||
|
||||
// closeProxiedRefusal spells one item's typed refusal the way this route has
|
||||
// always spelled it. The vocabulary is matched with errors.Is rather than by
|
||||
// reading the message, which is the point of the outcome carrying a typed
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
|
@ -60,7 +61,7 @@ Dolt Garbage Collection:
|
|||
With auto-commit per mutation, Dolt commit history grows over time. Use
|
||||
--dolt to run Dolt garbage collection and reclaim disk space.
|
||||
|
||||
--dolt: Run Dolt GC on .beads/dolt directory to free disk space.
|
||||
--dolt: Run Dolt GC on the active database to free disk space.
|
||||
This removes unreachable commits and compacts storage.
|
||||
|
||||
Examples:
|
||||
|
|
@ -111,7 +112,7 @@ Examples:
|
|||
|
||||
// Handle dolt GC mode
|
||||
if compactDolt {
|
||||
return runCompactDolt()
|
||||
return runCompactDolt(ctx)
|
||||
}
|
||||
|
||||
// Count active modes
|
||||
|
|
@ -743,8 +744,8 @@ func runCompactApply(ctx context.Context, store storage.DoltStorage) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// runCompactDolt runs Dolt garbage collection on the .beads/dolt directory
|
||||
func runCompactDolt() error {
|
||||
// runCompactDolt runs external Dolt GC in the locally owned active database.
|
||||
func runCompactDolt(ctx context.Context) error {
|
||||
start := time.Now()
|
||||
|
||||
// Find beads directory
|
||||
|
|
@ -753,14 +754,34 @@ func runCompactDolt() error {
|
|||
return HandleErrorWithHint(activeWorkspaceNotFoundError(), diagHint())
|
||||
}
|
||||
|
||||
// Check for dolt directory
|
||||
doltPath := filepath.Join(beadsDir, "dolt")
|
||||
if _, err := os.Stat(doltPath); os.IsNotExist(err) {
|
||||
if compactDryRun {
|
||||
// Resolve operation authority from the opened store, never a stale project
|
||||
// directory, general CLI path, or advisory size measurement.
|
||||
var doltPath string
|
||||
var pathErr error
|
||||
if locator, ok := storage.UnwrapStore(store).(storage.ExternalGCLocator); ok {
|
||||
doltPath, pathErr = locator.ExternalGCPath(ctx)
|
||||
} else {
|
||||
pathErr = &storage.ErrUnsupported{Op: "ExternalGCPath", Backend: "active store"}
|
||||
}
|
||||
if pathErr != nil {
|
||||
// Classify cancellation before formatting. ExternalGCPath probes ctx, so an
|
||||
// interrupt or deadline surfaces here as a bare context error, and it is not
|
||||
// an authority refusal: without this arm a SIGINT renders as the permanent
|
||||
// "cannot select a local database" message plus the four-cause hint about
|
||||
// port overrides and proxied servers, none of which applies. The ctx probe
|
||||
// stays in ExternalGCPath deliberately — it is the only cancellation
|
||||
// checkpoint before the uninterruptible external `dolt gc` below.
|
||||
if errors.Is(pathErr, context.Canceled) || errors.Is(pathErr, context.DeadlineExceeded) {
|
||||
return HandleErrorWithHint(
|
||||
fmt.Sprintf("external Dolt garbage collection was interrupted: %v", pathErr),
|
||||
"the command stopped before the active database was resolved, so no garbage collection ran. "+
|
||||
"Re-run 'bd admin compact --dolt' to collect.")
|
||||
}
|
||||
var unsupported *storage.ErrUnsupported
|
||||
if compactDryRun && errors.As(pathErr, &unsupported) {
|
||||
if jsonOutput {
|
||||
output := map[string]interface{}{
|
||||
"dry_run": true,
|
||||
"dolt_path": doltPath,
|
||||
"available": false,
|
||||
}
|
||||
if err := outputJSON(output); err != nil {
|
||||
|
|
@ -769,27 +790,46 @@ func runCompactDolt() error {
|
|||
return nil
|
||||
}
|
||||
fmt.Printf("DRY RUN - Dolt garbage collection\n\n")
|
||||
fmt.Printf("Dolt directory: %s\n", doltPath)
|
||||
fmt.Printf("No local Dolt directory found; nothing to collect.\n")
|
||||
fmt.Printf("The active database is not available for local external garbage collection.\n")
|
||||
return nil
|
||||
}
|
||||
return HandleErrorWithHint(fmt.Sprintf("Dolt directory not found at %s", doltPath), "--dolt flag is only for repositories using the Dolt backend")
|
||||
return HandleErrorWithHint(
|
||||
fmt.Sprintf("cannot select a local database for external Dolt garbage collection: %v", pathErr),
|
||||
"--dolt requires a locally managed owned/shared Dolt database. Port overrides (BEADS_DOLT_SERVER_PORT/BEADS_DOLT_PORT), "+
|
||||
"external/gateway/proxied servers, and socket/TLS connections do not authorize local GC; owned mode also requires "+
|
||||
"auto-start, so a hand-started owned server needs 'bd config set dolt.auto-start true'. "+
|
||||
"Run 'bd doctor' to inspect the connection or ask the server administrator to run GC.")
|
||||
}
|
||||
if !filepath.IsAbs(doltPath) {
|
||||
return HandleErrorWithHint(
|
||||
fmt.Sprintf("external Dolt garbage collection requires an absolute active database directory, got %q", doltPath),
|
||||
"run 'bd doctor' and correct the active database configuration to use an absolute directory")
|
||||
}
|
||||
info, err := os.Stat(doltPath)
|
||||
if err != nil {
|
||||
return HandleErrorWithHint(
|
||||
fmt.Sprintf("active Dolt database directory is unavailable: %v", err),
|
||||
"check that the active database directory exists and is accessible; run 'bd doctor' to inspect the database configuration")
|
||||
}
|
||||
if !info.IsDir() {
|
||||
return HandleErrorWithHint(
|
||||
fmt.Sprintf("active Dolt database path %q is not a directory", doltPath),
|
||||
"run 'bd doctor' and correct the active database configuration to point to a directory, not a file")
|
||||
}
|
||||
|
||||
// Get size before GC
|
||||
sizeBefore, err := getDirSize(doltPath)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: could not calculate directory size: %v\n", err)
|
||||
sizeBefore = 0
|
||||
}
|
||||
// Measure only the active database. The shared .beads/dolt root may contain
|
||||
// sibling databases unrelated to this GC operation.
|
||||
sizeBefore := storeSizeBytes(ctx)
|
||||
|
||||
if compactDryRun {
|
||||
if jsonOutput {
|
||||
output := map[string]interface{}{
|
||||
"dry_run": true,
|
||||
"dolt_path": doltPath,
|
||||
"size_before": sizeBefore,
|
||||
"size_display": formatBytes(sizeBefore),
|
||||
"dry_run": true,
|
||||
"dolt_path": doltPath,
|
||||
}
|
||||
if sizeBefore >= 0 {
|
||||
output["size_before"] = sizeBefore
|
||||
output["size_display"] = formatBytes(sizeBefore)
|
||||
}
|
||||
if err := outputJSON(output); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
|
|
@ -798,7 +838,9 @@ func runCompactDolt() error {
|
|||
}
|
||||
fmt.Printf("DRY RUN - Dolt garbage collection\n\n")
|
||||
fmt.Printf("Dolt directory: %s\n", doltPath)
|
||||
fmt.Printf("Current size: %s\n", formatBytes(sizeBefore))
|
||||
if sizeBefore >= 0 {
|
||||
fmt.Printf("Current size: %s\n", formatBytes(sizeBefore))
|
||||
}
|
||||
fmt.Printf("\nRun without --dry-run to perform garbage collection.\n")
|
||||
return nil
|
||||
}
|
||||
|
|
@ -839,28 +881,32 @@ func runCompactDolt() error {
|
|||
return SilentExit()
|
||||
}
|
||||
|
||||
// Get size after GC
|
||||
sizeAfter, err := getDirSize(doltPath)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: could not calculate directory size after GC: %v\n", err)
|
||||
sizeAfter = 0
|
||||
}
|
||||
// Measure the same active-database scope after GC.
|
||||
sizeAfter := storeSizeBytes(ctx)
|
||||
|
||||
elapsed := time.Since(start)
|
||||
freed := sizeBefore - sizeAfter
|
||||
if freed < 0 {
|
||||
freed = 0 // GC may not always reduce size
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
// Preserve compact's legacy size_before/size_after field names;
|
||||
// addGCSizeJSON uses a different schema and is not interchangeable.
|
||||
result := map[string]interface{}{
|
||||
"success": true,
|
||||
"dolt_path": doltPath,
|
||||
"size_before": sizeBefore,
|
||||
"size_after": sizeAfter,
|
||||
"freed_bytes": freed,
|
||||
"freed_display": formatBytes(freed),
|
||||
"elapsed_ms": elapsed.Milliseconds(),
|
||||
"success": true,
|
||||
"dolt_path": doltPath,
|
||||
"elapsed_ms": elapsed.Milliseconds(),
|
||||
}
|
||||
if sizeBefore >= 0 {
|
||||
result["size_before"] = sizeBefore
|
||||
}
|
||||
if sizeAfter >= 0 {
|
||||
result["size_after"] = sizeAfter
|
||||
}
|
||||
if sizeBefore >= 0 && sizeAfter >= 0 {
|
||||
freed := sizeBefore - sizeAfter
|
||||
if freed < 0 {
|
||||
freed = 0 // GC may not always reduce size
|
||||
}
|
||||
result["freed_bytes"] = freed
|
||||
result["freed_display"] = formatBytes(freed)
|
||||
}
|
||||
if err := outputJSON(result); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
|
|
@ -869,7 +915,9 @@ func runCompactDolt() error {
|
|||
}
|
||||
|
||||
fmt.Printf("✓ Dolt garbage collection complete\n")
|
||||
fmt.Printf(" %s → %s (freed %s)\n", formatBytes(sizeBefore), formatBytes(sizeAfter), formatBytes(freed))
|
||||
if line := gcSizeLine(sizeBefore, sizeAfter); line != "" {
|
||||
fmt.Printf(" %s\n", line)
|
||||
}
|
||||
fmt.Printf(" Time: %v\n", elapsed)
|
||||
return nil
|
||||
}
|
||||
|
|
@ -897,21 +945,6 @@ func isUnknownArchiveLevelFlagError(output string) bool {
|
|||
strings.Contains(lower, "flag provided but not defined")
|
||||
}
|
||||
|
||||
// getDirSize calculates the total size of a directory recursively
|
||||
func getDirSize(path string) (int64, error) {
|
||||
var size int64
|
||||
err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !info.IsDir() {
|
||||
size += info.Size()
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return size, err
|
||||
}
|
||||
|
||||
// formatBytes formats a byte count as a human-readable string
|
||||
func formatBytes(b int64) string {
|
||||
const unit = 1024
|
||||
|
|
@ -962,7 +995,7 @@ func init() {
|
|||
compactCmd.Flags().StringVar(&compactSummary, "summary", "", "Path to summary file (use '-' for stdin)")
|
||||
compactCmd.Flags().StringVar(&compactActor, "actor", "agent", "Actor name for audit trail")
|
||||
compactCmd.Flags().IntVar(&compactLimit, "limit", 0, "Limit number of candidates (0 = no limit)")
|
||||
compactCmd.Flags().BoolVar(&compactDolt, "dolt", false, "Dolt mode: run Dolt garbage collection on .beads/dolt")
|
||||
compactCmd.Flags().BoolVar(&compactDolt, "dolt", false, "Dolt mode: run Dolt garbage collection on the active database")
|
||||
|
||||
// Note: compactCmd is added to adminCmd in admin.go
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,30 +91,9 @@ Examples:
|
|||
|
||||
cutoff := time.Now().AddDate(0, 0, -compactDoltDays)
|
||||
|
||||
var oldCommits int
|
||||
var recentHashes []string
|
||||
var initialHash, boundaryHash string
|
||||
|
||||
for _, entry := range logEntries {
|
||||
if entry.Date.Before(cutoff) {
|
||||
oldCommits++
|
||||
boundaryHash = entry.Hash
|
||||
} else {
|
||||
recentHashes = append(recentHashes, entry.Hash)
|
||||
}
|
||||
}
|
||||
initialHash = logEntries[totalCommits-1].Hash
|
||||
boundaryHash = ""
|
||||
for _, entry := range logEntries {
|
||||
if entry.Date.Before(cutoff) {
|
||||
boundaryHash = entry.Hash
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
for i, j := 0, len(recentHashes)-1; i < j; i, j = i+1, j-1 {
|
||||
recentHashes[i], recentHashes[j] = recentHashes[j], recentHashes[i]
|
||||
}
|
||||
plan := planCompaction(logEntries, cutoff)
|
||||
oldCommits, recentHashes := plan.oldCommits, plan.recentHashes
|
||||
initialHash, boundaryHash := plan.initialHash, plan.boundaryHash
|
||||
|
||||
recentCommits := len(recentHashes)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,9 +6,14 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/steveyegge/beads/internal/configfile"
|
||||
"github.com/steveyegge/beads/internal/storage/embeddeddolt"
|
||||
)
|
||||
|
||||
// bdCompact runs "bd compact" with the given args and returns stdout.
|
||||
|
|
@ -190,3 +195,62 @@ func TestEmbeddedCompactConcurrent(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestEmbeddedCompactMisdatedChild reproduces #6516: two commits editing the
|
||||
// same row where the child is dated before its parent. Compact must replay the
|
||||
// preserved commits in graph order (dolt_log.commit_order), not date order,
|
||||
// or the cherry-pick of the child conflicts.
|
||||
func TestEmbeddedCompactMisdatedChild(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", "md")
|
||||
issue := bdCreate(t, bd, dir, "Misdated bead", "--type", "task")
|
||||
bdCreate(t, bd, dir, "Filler bead", "--type", "task")
|
||||
|
||||
cfg, _ := configfile.Load(beadsDir)
|
||||
database := ""
|
||||
if cfg != nil {
|
||||
database = cfg.GetDoltDatabase()
|
||||
}
|
||||
db, cleanup, err := embeddeddolt.OpenSQL(t.Context(), filepath.Join(beadsDir, "embeddeddolt"), database, "main")
|
||||
if err != nil {
|
||||
t.Fatalf("OpenSQL: %v", err)
|
||||
}
|
||||
conn, err := db.Conn(t.Context())
|
||||
if err != nil {
|
||||
t.Fatalf("db.Conn: %v", err)
|
||||
}
|
||||
// Both commits are dated in the future so --days 0 preserves them; the
|
||||
// child (edit B) is dated 20 minutes before its parent (edit A).
|
||||
now := time.Now()
|
||||
edits := []struct {
|
||||
title string
|
||||
date time.Time
|
||||
}{
|
||||
{"edit A", now.Add(40 * time.Minute)},
|
||||
{"edit B", now.Add(20 * time.Minute)},
|
||||
}
|
||||
for _, e := range edits {
|
||||
if _, err := conn.ExecContext(t.Context(), "UPDATE issues SET title = ? WHERE id = ?", e.title, issue.ID); err != nil {
|
||||
t.Fatalf("update title %q: %v", e.title, err)
|
||||
}
|
||||
if _, err := conn.ExecContext(t.Context(), "CALL DOLT_COMMIT('-Am', ?, '--date', ?)",
|
||||
"repro: "+e.title, e.date.Format(time.RFC3339)); err != nil {
|
||||
t.Fatalf("dolt commit %q: %v", e.title, err)
|
||||
}
|
||||
}
|
||||
conn.Close()
|
||||
if err := cleanup(); err != nil {
|
||||
t.Fatalf("cleanup: %v", err)
|
||||
}
|
||||
|
||||
bdCompact(t, bd, dir, "--force", "--days", "0")
|
||||
|
||||
if got := bdShow(t, bd, dir, issue.ID).Title; got != "edit B" {
|
||||
t.Errorf("title after compact = %q, want %q", got, "edit B")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
88
cmd/bd/compact_gc_size_test.go
Normal file
88
cmd/bd/compact_gc_size_test.go
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
)
|
||||
|
||||
func TestRunCompactDoltDryRunUsesActiveDatabaseSizer(t *testing.T) {
|
||||
output := runCompactDoltDryRunForTest(t, &gcSizeStoreStub{size: 42}, true)
|
||||
|
||||
var result map[string]interface{}
|
||||
if err := json.Unmarshal([]byte(output), &result); err != nil {
|
||||
t.Fatalf("decode dry-run JSON: %v\noutput: %s", err, output)
|
||||
}
|
||||
if got := result["size_before"]; got != float64(42) {
|
||||
t.Fatalf("size_before = %#v, want 42 from ActiveDatabaseSizer", got)
|
||||
}
|
||||
if got := result["size_display"]; got != "42 B" {
|
||||
t.Fatalf("size_display = %#v, want %q", got, "42 B")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunCompactDoltDryRunOmitsUnsupportedSize(t *testing.T) {
|
||||
unsupported := &gcSizeStoreStub{err: &storage.ErrUnsupported{
|
||||
Op: "ActiveDatabaseSize",
|
||||
Backend: "external",
|
||||
}}
|
||||
|
||||
t.Run("JSON", func(t *testing.T) {
|
||||
output := runCompactDoltDryRunForTest(t, unsupported, true)
|
||||
var result map[string]interface{}
|
||||
if err := json.Unmarshal([]byte(output), &result); err != nil {
|
||||
t.Fatalf("decode dry-run JSON: %v\noutput: %s", err, output)
|
||||
}
|
||||
for _, key := range []string{"size_before", "size_display"} {
|
||||
if got, ok := result[key]; ok {
|
||||
t.Fatalf("unsupported measurement emitted %s=%#v", key, got)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("text", func(t *testing.T) {
|
||||
output := runCompactDoltDryRunForTest(t, unsupported, false)
|
||||
if strings.Contains(output, "Current size:") {
|
||||
t.Fatalf("unsupported measurement emitted a text size line:\n%s", output)
|
||||
}
|
||||
if !strings.Contains(output, "Run without --dry-run") {
|
||||
t.Fatalf("dry-run completion guidance missing:\n%s", output)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func runCompactDoltDryRunForTest(t *testing.T, candidate storage.DoltStorage, asJSON bool) string {
|
||||
t.Helper()
|
||||
|
||||
oldStore, oldDryRun, oldJSON := store, compactDryRun, jsonOutput
|
||||
t.Cleanup(func() {
|
||||
store, compactDryRun, jsonOutput = oldStore, oldDryRun, oldJSON
|
||||
})
|
||||
|
||||
beadsDir := filepath.Join(t.TempDir(), ".beads")
|
||||
doltDir := filepath.Join(beadsDir, "dolt")
|
||||
if err := os.MkdirAll(doltDir, 0o755); err != nil {
|
||||
t.Fatalf("create shared Dolt root: %v", err)
|
||||
}
|
||||
// This sibling-root content makes the old recursive-walk behavior return a
|
||||
// value distinct from the fake active database measurement.
|
||||
if err := os.WriteFile(filepath.Join(doltDir, "sibling-data"), make([]byte, 128), 0o644); err != nil {
|
||||
t.Fatalf("seed sibling data: %v", err)
|
||||
}
|
||||
t.Setenv("BEADS_DIR", beadsDir)
|
||||
|
||||
active := filepath.Join(doltDir, "active")
|
||||
if err := os.Mkdir(active, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store = &compactGCStoreStub{DoltStorage: candidate, directory: active}
|
||||
compactDryRun = true
|
||||
jsonOutput = asJSON
|
||||
return captureStdout(t, func() error {
|
||||
return runCompactDolt(t.Context())
|
||||
})
|
||||
}
|
||||
325
cmd/bd/compact_gc_target_test.go
Normal file
325
cmd/bd/compact_gc_target_test.go
Normal file
|
|
@ -0,0 +1,325 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/beads"
|
||||
"github.com/steveyegge/beads/internal/hooks"
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
)
|
||||
|
||||
type compactGCStoreStub struct {
|
||||
storage.DoltStorage
|
||||
directory string
|
||||
err error
|
||||
}
|
||||
|
||||
func (s *compactGCStoreStub) ExternalGCPath(context.Context) (string, error) {
|
||||
return s.directory, s.err
|
||||
}
|
||||
|
||||
func (s *compactGCStoreStub) ActiveDatabaseSize(ctx context.Context) (int64, error) {
|
||||
if sizer, ok := s.DoltStorage.(storage.ActiveDatabaseSizer); ok {
|
||||
return sizer.ActiveDatabaseSize(ctx)
|
||||
}
|
||||
return 0, &storage.ErrUnsupported{Op: "ActiveDatabaseSize", Backend: "fixture"}
|
||||
}
|
||||
|
||||
func TestRunCompactDoltTargetsOnlyAuthorizedActiveDatabase(t *testing.T) {
|
||||
clearTelemetryEnv(t)
|
||||
t.Setenv("BD_JSON_ENVELOPE", "0")
|
||||
toolDir := buildCompactGCFixture(t)
|
||||
// wantBackend pins which ErrUnsupported.Backend the refusal names, which is
|
||||
// the only observable that distinguishes "the active store refused" (the
|
||||
// store's own "external" sentinel, reached through storage.UnwrapStore) from
|
||||
// "the interface assertion missed" ("active store"). Both render the same
|
||||
// top-level message, so the *through decorators* rows are vacuous for the
|
||||
// decorator claim without it.
|
||||
//
|
||||
// Known residual: "unsupported dry run through decorators" still cannot
|
||||
// discriminate. Its benign dry-run preview is byte-identical for both error
|
||||
// origins and carries no backend, so no CLI-level assertion distinguishes
|
||||
// them; the non-dry-run decorator row is what pins that path.
|
||||
for _, tc := range []struct {
|
||||
name, mode, pathKind string
|
||||
shared, dry, unsupported bool
|
||||
decorated bool
|
||||
plain, envelope bool
|
||||
calls int
|
||||
wantErr bool
|
||||
wantMessage string
|
||||
wantBackend string
|
||||
wantHint string
|
||||
}{
|
||||
{name: "owned active", calls: 1},
|
||||
{name: "shared active despite stale project root", shared: true, calls: 1},
|
||||
{name: "owned active through decorators", decorated: true, calls: 1},
|
||||
{name: "shared active through decorators", decorated: true, shared: true, calls: 1},
|
||||
{name: "older CLI fallback", mode: "fallback", calls: 2},
|
||||
{name: "real failure is not retried", mode: "failure", calls: 1, wantErr: true},
|
||||
{name: "dry run", dry: true},
|
||||
{name: "unsupported with plausible local path", unsupported: true, wantErr: true, wantBackend: "external"},
|
||||
{name: "unsupported text output", unsupported: true, plain: true, wantErr: true, wantBackend: "external"},
|
||||
{name: "unsupported enveloped output", unsupported: true, envelope: true, wantErr: true, wantBackend: "external"},
|
||||
{name: "unsupported dry run", unsupported: true, dry: true},
|
||||
{name: "unsupported through decorators", decorated: true, unsupported: true, wantErr: true, wantBackend: "external"},
|
||||
{name: "unsupported dry run through decorators", decorated: true, unsupported: true, dry: true},
|
||||
{name: "cancelled before the active database is resolved", pathKind: "cancelled", wantErr: true,
|
||||
wantMessage: "external Dolt garbage collection was interrupted", wantHint: "Re-run 'bd admin compact --dolt'"},
|
||||
{name: "cancelled in dry run", pathKind: "cancelled", dry: true, wantErr: true,
|
||||
wantMessage: "external Dolt garbage collection was interrupted", wantHint: "Re-run 'bd admin compact --dolt'"},
|
||||
{name: "deadline exceeded before the active database is resolved", pathKind: "deadline", wantErr: true,
|
||||
wantMessage: "external Dolt garbage collection was interrupted", wantHint: "Re-run 'bd admin compact --dolt'"},
|
||||
{name: "size capability is insufficient", pathKind: "size-only", wantErr: true, wantBackend: "active store"},
|
||||
{name: "general locator is insufficient", pathKind: "locator-only", wantErr: true, wantBackend: "active store"},
|
||||
{name: "missing declared path", pathKind: "missing", wantErr: true, wantMessage: "active Dolt database directory is unavailable"},
|
||||
{name: "missing declared path in dry run", pathKind: "missing", dry: true, wantErr: true, wantMessage: "active Dolt database directory is unavailable"},
|
||||
{name: "file is not a database directory", pathKind: "file", wantErr: true, wantMessage: "is not a directory"},
|
||||
{name: "empty declared path", pathKind: "empty", wantErr: true, wantMessage: "requires an absolute active database directory"},
|
||||
{name: "relative declared path", pathKind: "relative", wantErr: true, wantMessage: "requires an absolute active database directory"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
oldStore, oldDry, oldJSON := store, compactDryRun, jsonOutput
|
||||
beads.ResetCaches()
|
||||
t.Cleanup(func() { store, compactDryRun, jsonOutput = oldStore, oldDry, oldJSON; beads.ResetCaches() })
|
||||
project := t.TempDir()
|
||||
beadsDir := filepath.Join(project, ".beads")
|
||||
stale := filepath.Join(beadsDir, "dolt")
|
||||
root := stale
|
||||
if tc.shared {
|
||||
root = filepath.Join(t.TempDir(), "central", "dolt")
|
||||
}
|
||||
active := filepath.Join(root, "active")
|
||||
sibling := filepath.Join(root, "sibling")
|
||||
for _, dir := range []string{stale, active, sibling} {
|
||||
if err := os.MkdirAll(dir, 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, "keep"), []byte("unchanged"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
t.Setenv("BEADS_DIR", beadsDir)
|
||||
t.Setenv("PATH", toolDir+string(os.PathListSeparator)+os.Getenv("PATH"))
|
||||
logPath := filepath.Join(t.TempDir(), "calls.jsonl")
|
||||
t.Setenv("BEADS_COMPACT_GC_FIXTURE_LOG", logPath)
|
||||
t.Setenv("BEADS_COMPACT_GC_FIXTURE_MODE", tc.mode)
|
||||
candidate := &compactGCStoreStub{DoltStorage: &gcSizeStoreStub{size: 42}, directory: active}
|
||||
if tc.unsupported {
|
||||
candidate.err = &storage.ErrUnsupported{Op: "ExternalGCPath", Backend: "external"}
|
||||
}
|
||||
store = candidate
|
||||
switch tc.pathKind {
|
||||
case "size-only":
|
||||
store = &gcSizeStoreStub{size: 42}
|
||||
case "locator-only":
|
||||
store = &gcLocatorOnlyStoreStub{path: active}
|
||||
case "missing":
|
||||
candidate.directory = filepath.Join(root, "missing")
|
||||
case "file":
|
||||
candidate.directory = filepath.Join(active, "keep")
|
||||
case "empty":
|
||||
candidate.directory = ""
|
||||
case "relative":
|
||||
candidate.directory = "relative-database"
|
||||
case "cancelled":
|
||||
// What the real DoltStore.ExternalGCPath returns for a cancelled
|
||||
// ctx: the bare context error, not an ErrUnsupported.
|
||||
candidate.err = context.Canceled
|
||||
case "deadline":
|
||||
candidate.err = context.DeadlineExceeded
|
||||
}
|
||||
if tc.decorated {
|
||||
t.Setenv("BD_OTEL_STDOUT", "true")
|
||||
store = wireStorageDecorators(store, hooks.NewRunner(filepath.Join(project, "missing-hooks")), false)
|
||||
if storage.UnwrapStore(store) != candidate {
|
||||
t.Fatal("production decorator chain lost the active store")
|
||||
}
|
||||
}
|
||||
compactDryRun, jsonOutput = tc.dry, !tc.plain
|
||||
if tc.envelope {
|
||||
t.Setenv("BD_JSON_ENVELOPE", "1")
|
||||
}
|
||||
var runErr error
|
||||
var output string
|
||||
if tc.wantErr {
|
||||
output = captureStderr(t, func() { runErr = runCompactDolt(t.Context()) })
|
||||
} else {
|
||||
output = captureStdout(t, func() error { runErr = runCompactDolt(t.Context()); return nil })
|
||||
}
|
||||
if (runErr != nil) != tc.wantErr {
|
||||
t.Fatalf("runCompactDolt error = %v, wantErr %v", runErr, tc.wantErr)
|
||||
}
|
||||
if tc.wantErr {
|
||||
if code, ok := exitCodeFromError(runErr); !ok || code != 1 {
|
||||
t.Fatalf("refusal exit code = %d, recognized %v; error %v", code, ok, runErr)
|
||||
}
|
||||
}
|
||||
if tc.wantErr && tc.mode != "failure" {
|
||||
message, hint := output, output
|
||||
if tc.plain {
|
||||
if !strings.HasPrefix(output, "Error: ") || !strings.Contains(output, "\nHint: ") {
|
||||
t.Fatalf("missing text error/hint: %q", output)
|
||||
}
|
||||
} else {
|
||||
var result map[string]interface{}
|
||||
if err := json.Unmarshal([]byte(output), &result); err != nil {
|
||||
t.Fatalf("error stderr is not JSON: %v: %s", err, output)
|
||||
}
|
||||
if result["schema_version"] != float64(JSONSchemaVersion) {
|
||||
t.Fatalf("missing error schema version: %v", result)
|
||||
}
|
||||
if tc.envelope {
|
||||
var ok bool
|
||||
result, ok = result["data"].(map[string]interface{})
|
||||
if !ok {
|
||||
t.Fatalf("missing error envelope data: %s", output)
|
||||
}
|
||||
}
|
||||
message, _ = result["error"].(string)
|
||||
hint, _ = result["hint"].(string)
|
||||
}
|
||||
wantMessage := tc.wantMessage
|
||||
if wantMessage == "" {
|
||||
wantMessage = "cannot select a local database for external Dolt garbage collection"
|
||||
}
|
||||
wantHint := tc.wantHint
|
||||
if wantHint == "" {
|
||||
wantHint = "bd doctor"
|
||||
}
|
||||
if !strings.Contains(message, wantMessage) || !strings.Contains(hint, wantHint) {
|
||||
t.Fatalf("refusal lost its cause or actionable hint: %s", output)
|
||||
}
|
||||
// A cancellation must not be dressed as a permanent authority
|
||||
// refusal: neither the refusal message nor its four-cause hint may
|
||||
// appear, in dry-run or otherwise.
|
||||
if tc.pathKind == "cancelled" || tc.pathKind == "deadline" {
|
||||
for _, forbidden := range []string{"cannot select a local database", "BEADS_DOLT_SERVER_PORT", "server administrator"} {
|
||||
if strings.Contains(message, forbidden) || strings.Contains(hint, forbidden) {
|
||||
t.Errorf("cancellation reported as an authority refusal (%q present): %s", forbidden, output)
|
||||
}
|
||||
}
|
||||
}
|
||||
if tc.wantBackend != "" {
|
||||
wantBackend := "not supported by the " + tc.wantBackend + " backend"
|
||||
if !strings.Contains(message, wantBackend) {
|
||||
t.Errorf("refusal names the wrong origin: want %q in %q", wantBackend, message)
|
||||
}
|
||||
}
|
||||
if tc.unsupported {
|
||||
for _, condition := range []string{"BEADS_DOLT_SERVER_PORT", "BEADS_DOLT_PORT", "auto-start", "external", "gateway", "proxied", "socket", "TLS", "server administrator"} {
|
||||
if !strings.Contains(hint, condition) {
|
||||
t.Errorf("unsupported hint omits %q: %s", condition, hint)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
data, err := os.ReadFile(logPath)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var calls []struct {
|
||||
Dir string
|
||||
Args []string
|
||||
}
|
||||
for _, line := range strings.Split(strings.TrimSpace(string(data)), "\n") {
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
var call struct {
|
||||
Dir string
|
||||
Args []string
|
||||
}
|
||||
if err := json.Unmarshal([]byte(line), &call); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
calls = append(calls, call)
|
||||
}
|
||||
if len(calls) != tc.calls {
|
||||
t.Fatalf("external GC calls = %v, want %d", calls, tc.calls)
|
||||
}
|
||||
for i, call := range calls {
|
||||
wantArgs := []string{"gc", "--archive-level", "0"}
|
||||
if i == 1 {
|
||||
wantArgs = []string{"gc"}
|
||||
}
|
||||
gotInfo, err := os.Stat(call.Dir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wantInfo, err := os.Stat(active)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !os.SameFile(gotInfo, wantInfo) || !reflect.DeepEqual(call.Args, wantArgs) {
|
||||
t.Fatalf("GC call = %+v, want directory %q, args %v", call, active, wantArgs)
|
||||
}
|
||||
}
|
||||
for _, dir := range []string{stale, active, sibling} {
|
||||
data, err := os.ReadFile(filepath.Join(dir, "keep"))
|
||||
if err != nil || string(data) != "unchanged" {
|
||||
t.Fatalf("changed sentinel in %q: %q, %v", dir, data, err)
|
||||
}
|
||||
_, err = os.Stat(filepath.Join(dir, "gc-ran"))
|
||||
wantMarker := dir == active && tc.calls > 0 && !tc.wantErr
|
||||
if (err == nil) != wantMarker {
|
||||
t.Fatalf("GC marker in %q: %v, want marker %v", dir, err, wantMarker)
|
||||
}
|
||||
}
|
||||
if !tc.wantErr {
|
||||
var result map[string]interface{}
|
||||
if err := json.Unmarshal([]byte(output), &result); err != nil {
|
||||
t.Fatalf("JSON: %v: %s", err, output)
|
||||
}
|
||||
if tc.unsupported {
|
||||
_, hasDoltPath := result["dolt_path"]
|
||||
if result["available"] != false || hasDoltPath {
|
||||
t.Fatalf("unsupported target was guessed: %v", result)
|
||||
}
|
||||
} else if result["dolt_path"] != active || result["size_before"] != float64(42) {
|
||||
t.Fatalf("reported scope = %v, want active %q and size42", result, active)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func buildCompactGCFixture(t *testing.T) string {
|
||||
t.Helper()
|
||||
dir := t.TempDir()
|
||||
const source = `package main
|
||||
import ("encoding/json"; "fmt"; "os")
|
||||
func main() {
|
||||
dir, err := os.Getwd(); if err != nil { panic(err) }
|
||||
log, err := os.OpenFile(os.Getenv("BEADS_COMPACT_GC_FIXTURE_LOG"), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600); if err != nil { panic(err) }
|
||||
if err := json.NewEncoder(log).Encode(struct { Dir string; Args []string }{dir, os.Args[1:]}); err != nil { panic(err) }; if err := log.Close(); err != nil { panic(err) }
|
||||
mode := os.Getenv("BEADS_COMPACT_GC_FIXTURE_MODE")
|
||||
if mode == "fallback" && len(os.Args) == 4 { fmt.Fprintln(os.Stderr, "unknown flag: --archive-level"); os.Exit(23) }
|
||||
if mode == "failure" { fmt.Fprintln(os.Stderr, "genuine GC failure"); os.Exit(23) }
|
||||
if err := os.WriteFile("gc-ran", []byte("collected"), 0600); err != nil { panic(err) }
|
||||
}
|
||||
`
|
||||
path := filepath.Join(dir, "fixture.go")
|
||||
if err := os.WriteFile(path, []byte(source), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
name := "dolt"
|
||||
if runtime.GOOS == "windows" {
|
||||
name += ".exe"
|
||||
}
|
||||
cmd := exec.Command("go", "build", "-o", filepath.Join(dir, name), path)
|
||||
cmd.Dir = dir
|
||||
cmd.Env = append(os.Environ(), "CGO_ENABLED=0", "GOWORK=off")
|
||||
if output, err := cmd.CombinedOutput(); err != nil {
|
||||
t.Fatalf("build owned GC fixture: %v\n%s", err, output)
|
||||
}
|
||||
return dir
|
||||
}
|
||||
53
cmd/bd/compact_plan.go
Normal file
53
cmd/bd/compact_plan.go
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
)
|
||||
|
||||
// compactPlan is the old/recent partition of a Dolt commit history used by
|
||||
// `bd compact --days N`.
|
||||
type compactPlan struct {
|
||||
// oldCommits is the number of commits dated before the cutoff.
|
||||
oldCommits int
|
||||
// recentHashes are the commits to preserve, in ascending graph
|
||||
// (commit_order) order so a cherry-pick replay applies every parent before
|
||||
// its children.
|
||||
recentHashes []string
|
||||
// initialHash and boundaryHash are the soft-reset target and the temp
|
||||
// branch point for the squashed base.
|
||||
initialHash, boundaryHash string
|
||||
}
|
||||
|
||||
// planCompaction partitions logEntries (as returned by Log: newest commit date
|
||||
// first, non-empty) around cutoff. Old/recent membership, initialHash and
|
||||
// boundaryHash are selected by commit date as before. The replay order of the
|
||||
// recent commits is by Dolt's commit_order, not by date: commit dates are not
|
||||
// required to be monotonic along the parent chain, so a child dated before its
|
||||
// parent would otherwise be cherry-picked first and conflict (#6516).
|
||||
func planCompaction(logEntries []storage.CommitInfo, cutoff time.Time) compactPlan {
|
||||
var plan compactPlan
|
||||
recent := make([]storage.CommitInfo, 0, len(logEntries))
|
||||
for _, entry := range logEntries {
|
||||
if entry.Date.Before(cutoff) {
|
||||
plan.oldCommits++
|
||||
if plan.boundaryHash == "" {
|
||||
plan.boundaryHash = entry.Hash
|
||||
}
|
||||
} else {
|
||||
recent = append(recent, entry)
|
||||
}
|
||||
}
|
||||
plan.initialHash = logEntries[len(logEntries)-1].Hash
|
||||
|
||||
sort.SliceStable(recent, func(i, j int) bool {
|
||||
return recent[i].CommitOrder < recent[j].CommitOrder
|
||||
})
|
||||
plan.recentHashes = make([]string, 0, len(recent))
|
||||
for _, entry := range recent {
|
||||
plan.recentHashes = append(plan.recentHashes, entry.Hash)
|
||||
}
|
||||
return plan
|
||||
}
|
||||
51
cmd/bd/compact_plan_test.go
Normal file
51
cmd/bd/compact_plan_test.go
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
)
|
||||
|
||||
// TestPlanCompactionReplaysInCommitOrder covers #6516: a child dated before its
|
||||
// parent must still be replayed after it. Entries are in Log order (date DESC).
|
||||
func TestPlanCompactionReplaysInCommitOrder(t *testing.T) {
|
||||
now := time.Now()
|
||||
cutoff := now.Add(-time.Hour)
|
||||
entries := []storage.CommitInfo{
|
||||
{Hash: "parent", Date: now.Add(40 * time.Minute), CommitOrder: 4},
|
||||
{Hash: "child", Date: now.Add(20 * time.Minute), CommitOrder: 5}, // dated before its parent
|
||||
{Hash: "mid", Date: now.Add(-30 * time.Minute), CommitOrder: 3},
|
||||
{Hash: "old2", Date: now.Add(-2 * time.Hour), CommitOrder: 2},
|
||||
{Hash: "old1", Date: now.Add(-3 * time.Hour), CommitOrder: 1},
|
||||
}
|
||||
// Log order is date DESC: parent(+40m), child(+20m), mid, old2, old1.
|
||||
plan := planCompaction(entries, cutoff)
|
||||
|
||||
want := []string{"mid", "parent", "child"}
|
||||
if !reflect.DeepEqual(plan.recentHashes, want) {
|
||||
t.Errorf("recentHashes = %v, want %v (ascending commit_order)", plan.recentHashes, want)
|
||||
}
|
||||
if plan.oldCommits != 2 {
|
||||
t.Errorf("oldCommits = %d, want 2", plan.oldCommits)
|
||||
}
|
||||
// Partition selection stays date-based.
|
||||
if plan.boundaryHash != "old2" {
|
||||
t.Errorf("boundaryHash = %q, want old2", plan.boundaryHash)
|
||||
}
|
||||
if plan.initialHash != "old1" {
|
||||
t.Errorf("initialHash = %q, want old1", plan.initialHash)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlanCompactionNoRecent(t *testing.T) {
|
||||
now := time.Now()
|
||||
plan := planCompaction([]storage.CommitInfo{
|
||||
{Hash: "b", Date: now.Add(-time.Hour), CommitOrder: 2},
|
||||
{Hash: "a", Date: now.Add(-2 * time.Hour), CommitOrder: 1},
|
||||
}, now)
|
||||
if len(plan.recentHashes) != 0 || plan.oldCommits != 2 || plan.boundaryHash != "b" || plan.initialHash != "a" {
|
||||
t.Errorf("unexpected plan: %+v", plan)
|
||||
}
|
||||
}
|
||||
|
|
@ -52,27 +52,10 @@ func runCompactProxiedServer(ctx context.Context) error {
|
|||
|
||||
cutoff := time.Now().AddDate(0, 0, -compactDoltDays)
|
||||
|
||||
var oldCommits int
|
||||
var recentHashes []string
|
||||
for _, entry := range logEntries {
|
||||
if entry.Date.Before(cutoff) {
|
||||
oldCommits++
|
||||
} else {
|
||||
recentHashes = append(recentHashes, entry.Hash)
|
||||
}
|
||||
}
|
||||
initialHash := logEntries[totalCommits-1].Hash
|
||||
boundaryHash := ""
|
||||
for _, entry := range logEntries {
|
||||
if entry.Date.Before(cutoff) {
|
||||
boundaryHash = entry.Hash
|
||||
break
|
||||
}
|
||||
}
|
||||
plan := planCompaction(logEntries, cutoff)
|
||||
oldCommits, recentHashes := plan.oldCommits, plan.recentHashes
|
||||
initialHash, boundaryHash := plan.initialHash, plan.boundaryHash
|
||||
|
||||
for i, j := 0, len(recentHashes)-1; i < j; i, j = i+1, j-1 {
|
||||
recentHashes[i], recentHashes[j] = recentHashes[j], recentHashes[i]
|
||||
}
|
||||
recentCommits := len(recentHashes)
|
||||
|
||||
if compactDoltDryRun {
|
||||
|
|
|
|||
358
cmd/bd/config.go
358
cmd/bd/config.go
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
|
@ -12,6 +13,7 @@ import (
|
|||
"github.com/spf13/viper"
|
||||
"github.com/steveyegge/beads/cmd/bd/doctor"
|
||||
"github.com/steveyegge/beads/internal/beads"
|
||||
"github.com/steveyegge/beads/internal/ceiling"
|
||||
"github.com/steveyegge/beads/internal/config"
|
||||
"github.com/steveyegge/beads/internal/git"
|
||||
"github.com/steveyegge/beads/internal/gitenv"
|
||||
|
|
@ -116,6 +118,44 @@ Examples:
|
|||
|
||||
var forceGitTracked bool
|
||||
|
||||
// newRoleConfigWriter captures fresh cwd and scrubbed routing once per write
|
||||
// operation. The process-wide Git cache and Beads storage do not select it.
|
||||
// Routing is scrubbed along with the suppression ScrubRouting deliberately
|
||||
// keeps: beads.role is an authority value, and the reader it feeds treats a
|
||||
// missing value as maintainer, so a suppressed config file would fail open.
|
||||
func newRoleConfigWriter() (func(...string) error, error) {
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
env := gitenv.ScrubRoutingAndSuppression(os.Environ())
|
||||
probe := exec.Command("git", "rev-parse", "--git-common-dir")
|
||||
probe.Dir, probe.Env = dir, env
|
||||
out, err := probe.Output()
|
||||
if err != nil {
|
||||
if exit, ok := err.(*exec.ExitError); ok && len(exit.Stderr) > 0 {
|
||||
err = fmt.Errorf("%w: %s", err, strings.TrimSpace(string(exit.Stderr)))
|
||||
}
|
||||
return nil, fmt.Errorf("resolving common Git config: %w", err)
|
||||
}
|
||||
commonDir := git.NormalizePath(strings.TrimSpace(string(out)))
|
||||
if commonDir == "" {
|
||||
return nil, fmt.Errorf("Git returned an empty common directory")
|
||||
}
|
||||
if !filepath.IsAbs(commonDir) {
|
||||
commonDir = filepath.Join(dir, commonDir)
|
||||
}
|
||||
return func(args ...string) error {
|
||||
// Callers supply only the fixed role key, validated values and unset flag.
|
||||
cmd := exec.Command("git", append([]string{"--git-dir", commonDir, "config", "--local"}, args...)...) //nolint:gosec // private validated config operations
|
||||
cmd.Dir, cmd.Env = dir, env
|
||||
if output, err := cmd.CombinedOutput(); err != nil {
|
||||
return fmt.Errorf("%w: %s", err, strings.TrimSpace(string(output)))
|
||||
}
|
||||
return nil
|
||||
}, nil
|
||||
}
|
||||
|
||||
var configSetCmd = &cobra.Command{
|
||||
Use: "set <key> <value>",
|
||||
Short: "Set a configuration value",
|
||||
|
|
@ -199,22 +239,21 @@ var configSetCmd = &cobra.Command{
|
|||
if !validRoles[value] {
|
||||
return HandleError("invalid role %q (valid values: maintainer, contributor)", value)
|
||||
}
|
||||
// This write discards inherited Git routing so it cannot be retargeted
|
||||
// at another repository. The boundary covers the role writers in this
|
||||
// file only. Still following inherited routing, and hardened in
|
||||
// follow-ups (bd-dz16y): the readers that resolve
|
||||
// maintainer-vs-contributor (internal/routing, beads.RepoContext,
|
||||
// bd config show, bd doctor role, bd hooks), and bd init's own role
|
||||
// accessors -- getBeadsRole/setBeadsRole in init.go plus the
|
||||
// contributor-routing write in init_contributor.go. Because one of the
|
||||
// uncovered planes is itself a writer, a poisoned environment can make
|
||||
// not only a scrubbed write and an unscrubbed read disagree, but two
|
||||
// writes: `bd init --role` can persist beads.role into the inherited
|
||||
// routing target while this site writes the scrubbed one, so a later
|
||||
// `bd config get` reads a value bd init never wrote.
|
||||
cmd := exec.Command("git", "config", "beads.role", value) //nolint:gosec // value is validated against allowlist above
|
||||
cmd.Env = gitenv.ScrubRouting(os.Environ())
|
||||
if err := cmd.Run(); err != nil {
|
||||
// bd config get/set/unset/set-many beads.role ignore inherited Git
|
||||
// routing, including GIT_CONFIG_GLOBAL, so the value lands in the
|
||||
// repository this command selected. beads.role is an authority
|
||||
// value and the reader it feeds treats a missing value as
|
||||
// maintainer, so these planes also discard the explicit suppression
|
||||
// ScrubRouting deliberately keeps -- otherwise a blinded read fails
|
||||
// open instead of erroring. That boundary is uniform across
|
||||
// routing.DetectUserRole, `bd config show`, `bd doctor`,
|
||||
// `bd hooks uninstall` and beads.RepoContext.Role, which re-pins
|
||||
// GIT_DIR/GIT_WORK_TREE last-wins on top of it.
|
||||
write, err := newRoleConfigWriter()
|
||||
if err != nil {
|
||||
return HandleError("setting beads.role in git config: %v", err)
|
||||
}
|
||||
if err := write("beads.role", value); err != nil {
|
||||
return HandleError("setting beads.role in git config: %v", err)
|
||||
}
|
||||
if jsonOutput {
|
||||
|
|
@ -277,6 +316,182 @@ func openWorkspaceConfig(directRequirement string) (issueops.WorkspaceConfig, er
|
|||
return store.WorkspaceConfig()
|
||||
}
|
||||
|
||||
// secretRowCleanup is what the best-effort database half of `bd config unset`
|
||||
// achieved, kept apart from the config.yaml half because the two removals are
|
||||
// independent. The YAML edit is the command's contract; the row is a credential
|
||||
// the database replicated to every remote it was pushed to, so "I deleted it",
|
||||
// "it is still there and I could not delete it" and "I could not look" are
|
||||
// three different things to tell the user, and only the middle one is certain.
|
||||
type secretRowCleanup struct {
|
||||
present bool // a row was there when we read it
|
||||
removed bool
|
||||
err error
|
||||
}
|
||||
|
||||
// describe writes the database half of the report. It says nothing at all for
|
||||
// the overwhelmingly common workspace that never leaked: `config unset` is
|
||||
// otherwise a one-line command and this is a footnote about a key's history.
|
||||
func (c secretRowCleanup) describe(key, location string) {
|
||||
switch {
|
||||
case c.removed:
|
||||
fmt.Printf("Also removed a stored %s row from the database, left by a bd that predates the key moving to %s.\n", key, location)
|
||||
fmt.Printf("⚠ Rotate this credential: the row was replicated to every Dolt remote this workspace pushed to, and deleting it here does not unpublish it.\n")
|
||||
case c.err != nil && c.present:
|
||||
// The one case that is not a maybe: the read found the row and the
|
||||
// delete failed, so bd knows a live credential is still in the table.
|
||||
fmt.Fprintf(os.Stderr, "⚠ A stored %s row is still in the database: removing it failed (%v).\n", key, c.err)
|
||||
fmt.Fprintf(os.Stderr, "⚠ Rotate this credential: the row was replicated to every Dolt remote this workspace pushed to.\n")
|
||||
case c.err != nil:
|
||||
fmt.Fprintf(os.Stderr, "⚠ Could not check the database for a leaked %s row (%v). An older bd may have stored one there; re-run this command with the database reachable.\n", key, c.err)
|
||||
}
|
||||
}
|
||||
|
||||
// jsonFields carries the same three-way distinction to machine consumers.
|
||||
// database_row_removed is always present for a secret key so a script can tell
|
||||
// "nothing leaked" from "the field is missing because bd is older".
|
||||
func (c secretRowCleanup) jsonFields(payload map[string]interface{}) {
|
||||
payload["database_row_removed"] = c.removed
|
||||
switch {
|
||||
case c.err != nil && c.present:
|
||||
payload["database_row_present"] = true
|
||||
payload["database_delete_failed"] = c.err.Error()
|
||||
case c.err != nil:
|
||||
payload["database_unreachable"] = c.err.Error()
|
||||
}
|
||||
}
|
||||
|
||||
// rowNote is the database half folded into the error the YAML half returns, so
|
||||
// a failed `config unset` still tells the user where the credential stands. It
|
||||
// goes on stderr with that error rather than to stdout, which `--json` owns.
|
||||
func (c secretRowCleanup) rowNote(key string) string {
|
||||
switch {
|
||||
case c.removed:
|
||||
return fmt.Sprintf("\nA stored %s row WAS removed from the database; rotate that credential — it was replicated to every Dolt remote this workspace pushed to.", key)
|
||||
case c.err != nil && c.present:
|
||||
return fmt.Sprintf("\nA stored %s row is still in the database: removing it failed (%v).", key, c.err)
|
||||
case c.err != nil:
|
||||
return fmt.Sprintf("\nThe database could not be checked for a leaked %s row (%v).", key, c.err)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// mayProvisionDatabase reports whether reaching the store from here could have
|
||||
// to CREATE a database, which is the only thing unsetLeakedSecretRow's skip
|
||||
// exists to avoid. Each arm that returns false is a route on which the database
|
||||
// is already there, so consulting it provisions nothing:
|
||||
//
|
||||
// - the proxied route opens no local storage at all — proxiedWorkspaceConfig
|
||||
// reaches an already-connected provider;
|
||||
// - a store that is already open and tracked is ensureStoreActive's own
|
||||
// no-op arm: it returns before newDoltStoreFromConfig ever runs. This is
|
||||
// the state PersistentPreRun leaves a connected server-mode workspace in,
|
||||
// and it is the only thing that tells the metadata-less server shape —
|
||||
// `dolt.mode: server` or BEADS_DOLT_SERVER_HOST with no local database
|
||||
// directory, routed deliberately at main.go, GH#3545 — apart from a
|
||||
// workspace that genuinely has no database. beads.FindDatabasePath answers
|
||||
// on metadata.json plus embeddeddolt/ and dolt/, so for that shape it
|
||||
// reports "" while the row itself sits on the shared server, replicated to
|
||||
// every remote the workspace ever pushed to. Skipping there would strand
|
||||
// the leaked credential in the population that holds the most copies of it.
|
||||
//
|
||||
// Only when neither of those holds does the on-disk answer decide, and there
|
||||
// the open really is open-OR-CREATE.
|
||||
func mayProvisionDatabase() bool {
|
||||
if usesProxiedServer() {
|
||||
return false
|
||||
}
|
||||
lockStore()
|
||||
active := isStoreActive() && getStore() != nil
|
||||
unlockStore()
|
||||
if active {
|
||||
return false
|
||||
}
|
||||
return beads.FindDatabasePath() == ""
|
||||
}
|
||||
|
||||
// unsetLeakedSecretRow deletes a yaml-only SECRET key's leftover row from the
|
||||
// config table, reporting what it found and what it removed.
|
||||
//
|
||||
// WHY THE YAML UNSET IS NOT THE WHOLE JOB. A key becomes yaml-only at some
|
||||
// point in bd's history, not at the beginning: `notion.token` moved in GH#6676,
|
||||
// and every workspace configured before the move still has the value in the
|
||||
// config table — a table whose contents `bd dolt push` replicates to every
|
||||
// remote. `config unset`'s yaml-only branch returns before the store, so
|
||||
// without this the only bd-side remover of that row would be gone for embedded
|
||||
// workspaces, which are exactly the population the move protects. The row would
|
||||
// keep authenticating (ResolveAuth reads it as the upgrade path) while the user
|
||||
// who just ran `bd config unset` believes they are clean.
|
||||
//
|
||||
// IT IS BEST EFFORT, AND ONLY FOR SECRETS. The caller has already removed the
|
||||
// value from config.yaml, which is the command's contract; a workspace with no
|
||||
// reachable store must not be told that succeeded work failed. Non-secret
|
||||
// yaml-only keys are skipped rather than merely unreported, so the ordinary
|
||||
// `bd config unset routing.mode` keeps costing no database open at all — this
|
||||
// pays the store-open only where a leaked credential could be sitting.
|
||||
//
|
||||
// The predicates, not a list of key names: `IsYamlOnlyKey` matches whole
|
||||
// prefixes (`ai.`, `sync.`, `federation.`, ...), so the affected set is
|
||||
// open-ended and grows whenever a tracker adds a credential. Measured at the
|
||||
// time of writing, YamlOnlyKeys alone contributes seven — ado.pat,
|
||||
// github.token, gitlab.token, jira.api_token, linear.api_key,
|
||||
// linear.oauth_client_secret, notion.token — plus whatever the prefixes cover.
|
||||
//
|
||||
// IT NEVER PROVISIONS ONE. `config unset <yaml-only key>` is deliberately
|
||||
// classified as runnable with no store (configCommandCanRunWithoutStore in
|
||||
// main.go, GH#536 / bd-934 / bd-3rw), and the direct open below is
|
||||
// open-OR-CREATE (ensureDirectMode → ensureStoreActive →
|
||||
// newDoltStoreFromConfig), so without a gate editing a YAML file would
|
||||
// materialize a database in a workspace that never had one and flip it out of
|
||||
// its db-less mode for every later command. mayProvisionDatabase is that gate,
|
||||
// and it asks about the store before the disk: "no local database directory" is
|
||||
// not the same question as "no database", and the workspaces where the two
|
||||
// answers differ are the ones whose row traveled furthest.
|
||||
func unsetLeakedSecretRow(key string) secretRowCleanup {
|
||||
// Gate BEFORE opening the store, not inside removeStoredSecretRow: this is
|
||||
// what keeps `bd config unset routing.mode` from paying a database open it
|
||||
// has no use for.
|
||||
if !config.IsSecretKey(key) {
|
||||
return secretRowCleanup{}
|
||||
}
|
||||
if mayProvisionDatabase() {
|
||||
return secretRowCleanup{}
|
||||
}
|
||||
settings, err := openWorkspaceConfig("config unset requires direct database access")
|
||||
if err != nil {
|
||||
return secretRowCleanup{err: err}
|
||||
}
|
||||
present, removed, err := removeStoredSecretRow(rootCtx, settings, key)
|
||||
if removed {
|
||||
noteDirectConfigWrite()
|
||||
}
|
||||
return secretRowCleanup{present: present, removed: removed, err: err}
|
||||
}
|
||||
|
||||
// removeStoredSecretRow deletes key's row, reporting whether one was there and
|
||||
// whether it is gone. Those are two bits, not one: a failed delete on a row the
|
||||
// read found is the single outcome that means "a live credential is still in
|
||||
// the table bd pushes", and collapsing it into the error alone renders it as an
|
||||
// unreachable database — the one case that needs no hedging.
|
||||
//
|
||||
// It READS BEFORE DELETING because UnsetSetting deliberately has no "removed"
|
||||
// flag and deleting an absent key is a success — so a blind delete could not
|
||||
// tell the caller whether anything had leaked, and the overwhelmingly common
|
||||
// case (a workspace that never stored the key) has to stay silent rather than
|
||||
// announce a removal that did not happen.
|
||||
func removeStoredSecretRow(ctx context.Context, settings issueops.WorkspaceConfig, key string) (present bool, removed bool, err error) {
|
||||
stored, err := settings.GetSetting(ctx, issueops.GetSettingRequest{Key: key})
|
||||
if err != nil {
|
||||
return false, false, err
|
||||
}
|
||||
if strings.TrimSpace(stored.Value) == "" {
|
||||
return false, false, nil
|
||||
}
|
||||
if _, err := settings.UnsetSetting(ctx, issueops.UnsetSettingRequest{Key: key}); err != nil {
|
||||
return true, false, err
|
||||
}
|
||||
return true, true, nil
|
||||
}
|
||||
|
||||
// noteDirectConfigWrite marks the invocation as having written, which is what
|
||||
// the auto-commit epilogue in main.go keys on.
|
||||
//
|
||||
|
|
@ -358,8 +573,9 @@ var configGetCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
if key == "beads.role" {
|
||||
// Same role-authority boundary as `bd config set` above.
|
||||
cmd := exec.Command("git", "config", "--get", "beads.role")
|
||||
cmd.Env = gitenv.ScrubRouting(os.Environ())
|
||||
cmd.Env = gitenv.ScrubRoutingAndSuppression(os.Environ())
|
||||
output, err := cmd.Output()
|
||||
value := strings.TrimSpace(string(output))
|
||||
if err != nil {
|
||||
|
|
@ -568,6 +784,53 @@ func showConfigYAMLOverrides(dbConfig map[string]string) {
|
|||
fmt.Println("\nTip: Run 'bd config show' for all effective config with provenance.")
|
||||
}
|
||||
|
||||
// runConfigUnsetYamlOnly removes a yaml-only key from config.yaml and, for a
|
||||
// secret key, the row a bd that predates the key's move to YAML may have left
|
||||
// in the config table.
|
||||
//
|
||||
// THE TWO REMOVALS ARE INDEPENDENT, AND SO IS THEIR REPORTING. Running the row
|
||||
// cleanup only after a successful YAML edit would skip it for exactly the
|
||||
// workspaces the cleanup exists for: one whose config.yaml is missing, or whose
|
||||
// notion.token sits in a shape the unset refuses, gets an error about
|
||||
// config.yaml and keeps the credential in the table `bd dolt push` replicates —
|
||||
// while `bd notion status` names this very command as the remover. So the
|
||||
// cleanup runs either way, and a failed YAML unset carries the row's fate in
|
||||
// its error rather than dropping it.
|
||||
func runConfigUnsetYamlOnly(key string) error {
|
||||
location := "config.yaml"
|
||||
var unsetErr error
|
||||
if config.IsUserGlobalKey(key) {
|
||||
unsetErr = config.UnsetUserYamlConfig(key)
|
||||
location = config.UserConfigYamlDisplayPath()
|
||||
} else {
|
||||
unsetErr = config.UnsetYamlConfig(key)
|
||||
}
|
||||
|
||||
cleanup := unsetLeakedSecretRow(key)
|
||||
|
||||
if unsetErr != nil {
|
||||
return HandleError("unsetting config: %v%s", unsetErr, cleanup.rowNote(key))
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
payload := map[string]interface{}{
|
||||
"key": key,
|
||||
"location": location,
|
||||
}
|
||||
if config.IsSecretKey(key) {
|
||||
cleanup.jsonFields(payload)
|
||||
}
|
||||
if err := outputJSON(payload); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("Unset %s (in %s)\n", key, location)
|
||||
cleanup.describe(key, location)
|
||||
}
|
||||
printConfigSideEffects(checkConfigUnsetSideEffects(key))
|
||||
return nil
|
||||
}
|
||||
|
||||
var configUnsetCmd = &cobra.Command{
|
||||
Use: "unset <key>",
|
||||
Short: "Delete a configuration value",
|
||||
|
|
@ -585,36 +848,18 @@ var configUnsetCmd = &cobra.Command{
|
|||
key := args[0]
|
||||
|
||||
if config.IsYamlOnlyKey(key) {
|
||||
location := "config.yaml"
|
||||
var unsetErr error
|
||||
if config.IsUserGlobalKey(key) {
|
||||
unsetErr = config.UnsetUserYamlConfig(key)
|
||||
location = config.UserConfigYamlDisplayPath()
|
||||
} else {
|
||||
unsetErr = config.UnsetYamlConfig(key)
|
||||
}
|
||||
if unsetErr != nil {
|
||||
return HandleError("unsetting config: %v", unsetErr)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
if err := outputJSON(map[string]interface{}{
|
||||
"key": key,
|
||||
"location": location,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("Unset %s (in %s)\n", key, location)
|
||||
}
|
||||
printConfigSideEffects(checkConfigUnsetSideEffects(key))
|
||||
return nil
|
||||
return runConfigUnsetYamlOnly(key)
|
||||
}
|
||||
|
||||
if key == "beads.role" {
|
||||
gitCmd := exec.Command("git", "config", "--unset", "beads.role")
|
||||
gitCmd.Env = gitenv.ScrubRouting(os.Environ())
|
||||
if err := gitCmd.Run(); err != nil {
|
||||
// Same role-authority boundary as `bd config set`/`get` above: every
|
||||
// spelling of a beads.role mutation resolves the repository the same
|
||||
// way, so the next reader has one boundary to reason about.
|
||||
write, err := newRoleConfigWriter()
|
||||
if err != nil {
|
||||
return HandleError("unsetting beads.role in git config: %v", err)
|
||||
}
|
||||
if err := write("--unset", "beads.role"); err != nil {
|
||||
return HandleError("unsetting beads.role in git config: %v", err)
|
||||
}
|
||||
if jsonOutput {
|
||||
|
|
@ -778,7 +1023,8 @@ func isValidRemoteURL(rawURL string) bool {
|
|||
// findBeadsRepoRoot walks up from the given path to find the repo root (containing .beads)
|
||||
func findBeadsRepoRoot(startPath string) string {
|
||||
path := startPath
|
||||
for {
|
||||
bound := ceiling.For(startPath)
|
||||
for !bound.Excludes(path) {
|
||||
beadsDir := filepath.Join(path, ".beads")
|
||||
if info, err := os.Stat(beadsDir); err == nil && info.IsDir() {
|
||||
return path
|
||||
|
|
@ -904,11 +1150,17 @@ Examples:
|
|||
}
|
||||
}
|
||||
|
||||
for _, p := range gitPairs {
|
||||
cmd := exec.Command("git", "config", "beads.role", p.value) //nolint:gosec // value is validated against allowlist above
|
||||
cmd.Env = gitenv.ScrubRouting(os.Environ())
|
||||
if err := cmd.Run(); err != nil {
|
||||
return HandleError("setting %s in git config: %v", p.key, err)
|
||||
if len(gitPairs) > 0 {
|
||||
// set-many is the batch alias for `bd config set`, so it runs on the
|
||||
// same role-authority boundary that verb does.
|
||||
write, err := newRoleConfigWriter()
|
||||
if err != nil {
|
||||
return HandleError("setting beads.role in git config: %v", err)
|
||||
}
|
||||
for _, p := range gitPairs {
|
||||
if err := write("beads.role", p.value); err != nil {
|
||||
return HandleError("setting %s in git config: %v", p.key, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1012,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 {
|
||||
|
|
|
|||
633
cmd/bd/config_leaked_secret_test.go
Normal file
633
cmd/bd/config_leaked_secret_test.go
Normal file
|
|
@ -0,0 +1,633 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/config"
|
||||
"github.com/steveyegge/beads/internal/notion"
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/issueops"
|
||||
)
|
||||
|
||||
// recordingWorkspaceConfig is the config plane reduced to the two verbs
|
||||
// removeStoredSecretRow uses, so a test can assert what it did NOT call.
|
||||
type recordingWorkspaceConfig struct {
|
||||
issueops.WorkspaceConfig
|
||||
|
||||
stored map[string]string
|
||||
getErr error
|
||||
unsetErr error
|
||||
|
||||
gets []string
|
||||
unsets []string
|
||||
}
|
||||
|
||||
func (c *recordingWorkspaceConfig) GetSetting(_ context.Context, req issueops.GetSettingRequest) (issueops.SettingResult, error) {
|
||||
c.gets = append(c.gets, req.Key)
|
||||
if c.getErr != nil {
|
||||
return issueops.SettingResult{}, c.getErr
|
||||
}
|
||||
return issueops.SettingResult{Key: req.Key, Value: c.stored[req.Key]}, nil
|
||||
}
|
||||
|
||||
func (c *recordingWorkspaceConfig) UnsetSetting(_ context.Context, req issueops.UnsetSettingRequest) (issueops.UnsetSettingResult, error) {
|
||||
c.unsets = append(c.unsets, req.Key)
|
||||
if c.unsetErr != nil {
|
||||
return issueops.UnsetSettingResult{}, c.unsetErr
|
||||
}
|
||||
delete(c.stored, req.Key)
|
||||
return issueops.UnsetSettingResult{Key: req.Key}, nil
|
||||
}
|
||||
|
||||
// TestRemoveStoredSecretRowDeletesTheLeakedRow is the GH#6676 regression: a
|
||||
// workspace configured before notion.token became yaml-only has the token in
|
||||
// the config table, which `bd dolt push` replicated. Moving the key to
|
||||
// config.yaml made `bd config unset` return before the store, which left that
|
||||
// row with no remover at all in embedded mode.
|
||||
func TestRemoveStoredSecretRowDeletesTheLeakedRow(t *testing.T) {
|
||||
settings := &recordingWorkspaceConfig{stored: map[string]string{"notion.token": "secret-ntn-abc"}}
|
||||
|
||||
present, removed, err := removeStoredSecretRow(context.Background(), settings, "notion.token")
|
||||
if err != nil {
|
||||
t.Fatalf("removeStoredSecretRow: %v", err)
|
||||
}
|
||||
if !present {
|
||||
t.Error("present = false, want true — the row was there to read")
|
||||
}
|
||||
if !removed {
|
||||
t.Error("removed = false, want true — the caller reports nothing to the user when this is false, so the leaked row would be deleted silently or not at all")
|
||||
}
|
||||
if got := settings.unsets; len(got) != 1 || got[0] != "notion.token" {
|
||||
t.Errorf("unset calls = %v, want exactly [notion.token]", got)
|
||||
}
|
||||
if _, still := settings.stored["notion.token"]; still {
|
||||
t.Error("the row survived the removal")
|
||||
}
|
||||
}
|
||||
|
||||
// TestRemoveStoredSecretRowIsSilentWhenNothingLeaked pins the read-before-delete.
|
||||
// Deleting an absent key is a success that reports no miss, so without the read
|
||||
// every `bd config unset notion.token` would claim it had cleaned up a database
|
||||
// row — on the overwhelmingly common workspace that never had one.
|
||||
func TestRemoveStoredSecretRowIsSilentWhenNothingLeaked(t *testing.T) {
|
||||
for name, stored := range map[string]map[string]string{
|
||||
"no row at all": {},
|
||||
"row stored empty": {"notion.token": ""},
|
||||
"row of whitespace": {"notion.token": " \n"},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
settings := &recordingWorkspaceConfig{stored: stored}
|
||||
|
||||
present, removed, err := removeStoredSecretRow(context.Background(), settings, "notion.token")
|
||||
if err != nil {
|
||||
t.Fatalf("removeStoredSecretRow: %v", err)
|
||||
}
|
||||
if present {
|
||||
t.Error("present = true, want false — nothing usable was stored, so nothing is still in the database")
|
||||
}
|
||||
if removed {
|
||||
t.Error("removed = true, want false — this would tell the user a credential was deleted from the database when none was there")
|
||||
}
|
||||
if len(settings.unsets) != 0 {
|
||||
t.Errorf("unset calls = %v, want none: the row was already absent", settings.unsets)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestRemoveStoredSecretRowPropagatesFailures keeps a failed cleanup
|
||||
// distinguishable from a clean workspace. Both report removed=false, so only
|
||||
// the error tells the caller to warn instead of staying quiet — reporting
|
||||
// success here is the exact harm GH#6676 is about: the user believes the
|
||||
// secret is gone while it is still in the pushed database.
|
||||
//
|
||||
// The two failures are NOT the same warning. A failed read means bd does not
|
||||
// know whether anything leaked; a failed delete means it does, and the
|
||||
// credential is still in the table `bd dolt push` replicates. That is what the
|
||||
// `present` bit carries out to the caller.
|
||||
func TestRemoveStoredSecretRowPropagatesFailures(t *testing.T) {
|
||||
readFailed := errors.New("store unreachable")
|
||||
deleteFailed := errors.New("delete rejected")
|
||||
|
||||
t.Run("read fails", func(t *testing.T) {
|
||||
settings := &recordingWorkspaceConfig{stored: map[string]string{}, getErr: readFailed}
|
||||
|
||||
present, removed, err := removeStoredSecretRow(context.Background(), settings, "notion.token")
|
||||
if !errors.Is(err, readFailed) {
|
||||
t.Fatalf("err = %v, want %v", err, readFailed)
|
||||
}
|
||||
if present {
|
||||
t.Error("present = true after a failed read — the read is what would have told us, so this claims knowledge bd does not have")
|
||||
}
|
||||
if removed {
|
||||
t.Error("removed = true after a failed read")
|
||||
}
|
||||
if len(settings.unsets) != 0 {
|
||||
t.Errorf("deleted %v despite not knowing what was there", settings.unsets)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("delete fails", func(t *testing.T) {
|
||||
settings := &recordingWorkspaceConfig{
|
||||
stored: map[string]string{"notion.token": "secret-ntn-abc"},
|
||||
unsetErr: deleteFailed,
|
||||
}
|
||||
|
||||
present, removed, err := removeStoredSecretRow(context.Background(), settings, "notion.token")
|
||||
if !errors.Is(err, deleteFailed) {
|
||||
t.Fatalf("err = %v, want %v", err, deleteFailed)
|
||||
}
|
||||
if !present {
|
||||
t.Error("present = false, want true — the read found the row, so this is the certain case, not an inconclusive lookup")
|
||||
}
|
||||
if removed {
|
||||
t.Error("removed = true, want false — the row is still in the database")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestYamlOnlySecretKeysAreTheWholeClass pins the population the unset branch
|
||||
// cleans up. The fix is deliberately keyed on the IsYamlOnlyKey/IsSecretKey
|
||||
// pair rather than on "notion.token", because every tracker credential reached
|
||||
// yaml-only status the same way and would otherwise each need their own fix.
|
||||
//
|
||||
// IsYamlOnlyKey also matches whole prefixes (`ai.`, `sync.`, `federation.`,
|
||||
// ...), so this list is a floor, not a census.
|
||||
func TestYamlOnlySecretKeysAreTheWholeClass(t *testing.T) {
|
||||
for _, key := range []string{
|
||||
"notion.token",
|
||||
"github.token",
|
||||
"gitlab.token",
|
||||
"jira.api_token",
|
||||
"linear.api_key",
|
||||
"linear.oauth_client_secret",
|
||||
"ado.pat",
|
||||
"ai.api_key",
|
||||
} {
|
||||
if !config.IsYamlOnlyKey(key) {
|
||||
t.Errorf("%s: IsYamlOnlyKey = false, so config unset never reaches the branch this fix lives in", key)
|
||||
}
|
||||
if !config.IsSecretKey(key) {
|
||||
t.Errorf("%s: IsSecretKey = false, so its leaked database row would be left behind", key)
|
||||
}
|
||||
}
|
||||
|
||||
// The other side of the gate: an ordinary yaml-only key must not drag a
|
||||
// database open into a command that has no row to clean up.
|
||||
for _, key := range []string{"routing.mode", "backup.enabled", "no-db"} {
|
||||
if !config.IsYamlOnlyKey(key) {
|
||||
t.Errorf("%s: expected a yaml-only key for this half of the test", key)
|
||||
}
|
||||
if config.IsSecretKey(key) {
|
||||
t.Errorf("%s: IsSecretKey = true, which would open the store on an ordinary unset", key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestNotionStatusWarnsOnlyForTheLeakedSource is the user-visible half of the
|
||||
// same GH#6676 gap. The distinct auth source is only worth having if something
|
||||
// acts on it: this is the one place a workspace is told that the token it is
|
||||
// authenticating with sits in a table `bd dolt push` replicates.
|
||||
//
|
||||
// The negative cases matter as much as the positive one — warning a workspace
|
||||
// whose token is in config.yaml or the environment would train users to ignore
|
||||
// the line that matters.
|
||||
func TestNotionStatusWarnsOnlyForTheLeakedSource(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
source notion.AuthSource
|
||||
wantWarn bool
|
||||
}{
|
||||
{"legacy database row", notion.AuthSourceDatabaseLegacy, true},
|
||||
{"config.yaml", notion.AuthSourceConfigToken, false},
|
||||
{"environment", notion.AuthSourceEnv, false},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
var out bytes.Buffer
|
||||
cmd := &cobra.Command{}
|
||||
cmd.SetOut(&out)
|
||||
|
||||
renderNotionStatus(cmd,
|
||||
¬ion.ResolvedAuth{Token: "secret-ntn-abcdef", Source: tc.source},
|
||||
notionConfig{DataSourceID: "ds-1"},
|
||||
¬ion.StatusResponse{})
|
||||
|
||||
got := out.String()
|
||||
if warned := strings.Contains(got, "bd config unset notion.token"); warned != tc.wantWarn {
|
||||
t.Errorf("rotation warning present = %v, want %v; output:\n%s", warned, tc.wantWarn, got)
|
||||
}
|
||||
if !strings.Contains(got, "Auth source: "+string(tc.source)) {
|
||||
t.Errorf("auth source line missing for %q; output:\n%s", tc.source, got)
|
||||
}
|
||||
if strings.Contains(got, "secret-ntn-abcdef") {
|
||||
t.Errorf("status printed the raw token; output:\n%s", got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// leakedRowStore is the production store reduced to the one accessor the
|
||||
// cleanup reaches through. Its nil embedded storage makes any other call panic,
|
||||
// so these tests cannot silently exercise more of the store than the seam.
|
||||
type leakedRowStore struct {
|
||||
storage.DoltStorage
|
||||
settings *recordingWorkspaceConfig
|
||||
}
|
||||
|
||||
func (s *leakedRowStore) WorkspaceConfig() (issueops.WorkspaceConfig, error) {
|
||||
return s.settings, nil
|
||||
}
|
||||
|
||||
// newLeakedSecretWorkspace builds the workspace shapes GH#6676 produced: a
|
||||
// .beads directory that may or may not hold a config.yaml, and may or may not
|
||||
// hold a database directory — which is what FindDatabasePath answers on, and
|
||||
// therefore what decides whether the cleanup may open a store at all.
|
||||
func newLeakedSecretWorkspace(t *testing.T, configYAML string, withDatabase bool) string {
|
||||
t.Helper()
|
||||
beadsDir := filepath.Join(t.TempDir(), ".beads")
|
||||
if err := os.MkdirAll(beadsDir, 0o755); err != nil {
|
||||
t.Fatalf("create .beads: %v", err)
|
||||
}
|
||||
if configYAML != "" {
|
||||
if err := os.WriteFile(filepath.Join(beadsDir, "config.yaml"), []byte(configYAML), 0o600); err != nil {
|
||||
t.Fatalf("write config.yaml: %v", err)
|
||||
}
|
||||
}
|
||||
if withDatabase {
|
||||
if err := os.MkdirAll(filepath.Join(beadsDir, "embeddeddolt"), 0o755); err != nil {
|
||||
t.Fatalf("create embeddeddolt: %v", err)
|
||||
}
|
||||
}
|
||||
t.Setenv("BEADS_DIR", beadsDir)
|
||||
initConfigForTest(t)
|
||||
return beadsDir
|
||||
}
|
||||
|
||||
// installLeakedRowSettings puts the recording config plane behind the store
|
||||
// accessor and marks the store active, so openWorkspaceConfig hands it back
|
||||
// without opening — or creating — anything.
|
||||
func installLeakedRowSettings(t *testing.T, settings *recordingWorkspaceConfig) {
|
||||
t.Helper()
|
||||
saveAndRestoreGlobals(t)
|
||||
store = &leakedRowStore{settings: settings}
|
||||
setStoreActive(true)
|
||||
}
|
||||
|
||||
// runConfigUnset drives the real cobra command, which is the point: every other
|
||||
// test in this file stubs in below the wiring.
|
||||
func runConfigUnset(t *testing.T, key string, asJSON bool) (stdout, stderr string, err error) {
|
||||
t.Helper()
|
||||
savedJSON := jsonOutput
|
||||
jsonOutput = asJSON
|
||||
t.Cleanup(func() { jsonOutput = savedJSON })
|
||||
|
||||
stdout, stderr = captureStdio(t, func() {
|
||||
err = configUnsetCmd.RunE(configUnsetCmd, []string{key})
|
||||
})
|
||||
return stdout, stderr, err
|
||||
}
|
||||
|
||||
func captureStdio(t *testing.T, fn func()) (string, string) {
|
||||
t.Helper()
|
||||
rOut, wOut, err := os.Pipe()
|
||||
if err != nil {
|
||||
t.Fatalf("pipe: %v", err)
|
||||
}
|
||||
rErr, wErr, err := os.Pipe()
|
||||
if err != nil {
|
||||
t.Fatalf("pipe: %v", err)
|
||||
}
|
||||
savedOut, savedErr := os.Stdout, os.Stderr
|
||||
os.Stdout, os.Stderr = wOut, wErr
|
||||
func() {
|
||||
defer func() { os.Stdout, os.Stderr = savedOut, savedErr }()
|
||||
fn()
|
||||
}()
|
||||
_ = wOut.Close()
|
||||
_ = wErr.Close()
|
||||
|
||||
var outBuf, errBuf bytes.Buffer
|
||||
if _, err := io.Copy(&outBuf, rOut); err != nil {
|
||||
t.Fatalf("read stdout: %v", err)
|
||||
}
|
||||
if _, err := io.Copy(&errBuf, rErr); err != nil {
|
||||
t.Fatalf("read stderr: %v", err)
|
||||
}
|
||||
_ = rOut.Close()
|
||||
_ = rErr.Close()
|
||||
return outBuf.String(), errBuf.String()
|
||||
}
|
||||
|
||||
// snapshotBeadsStorage is the "did this command create a database" probe: every
|
||||
// path under .beads with its size, so a new embeddeddolt/ directory, a gate
|
||||
// lock or a grown file shows up as a difference instead of having to be
|
||||
// predicted.
|
||||
//
|
||||
// config.yaml is excluded because editing it IS the command's contract; every
|
||||
// other byte under .beads is storage that `bd config unset` has no business
|
||||
// bringing into existence. removed_backend_heal_embedded_test.go has a
|
||||
// `cgo`-tagged twin of this walk; this file must also compile in the
|
||||
// CGO_ENABLED=0 lane, which does not see that one.
|
||||
func snapshotBeadsStorage(t *testing.T, beadsDir string) []string {
|
||||
t.Helper()
|
||||
var entries []string
|
||||
if err := filepath.Walk(beadsDir, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rel, relErr := filepath.Rel(beadsDir, path)
|
||||
if relErr != nil {
|
||||
return relErr
|
||||
}
|
||||
if info.IsDir() {
|
||||
entries = append(entries, rel+"/")
|
||||
return nil
|
||||
}
|
||||
if rel == "config.yaml" {
|
||||
return nil
|
||||
}
|
||||
entries = append(entries, fmt.Sprintf("%s (%d bytes)", rel, info.Size()))
|
||||
return nil
|
||||
}); err != nil {
|
||||
t.Fatalf("walk %s: %v", beadsDir, err)
|
||||
}
|
||||
sort.Strings(entries)
|
||||
return entries
|
||||
}
|
||||
|
||||
// TestConfigUnsetCommandCleansTheLeakedRow pins the wiring, which is the one
|
||||
// thing the unit tests above cannot see: they call removeStoredSecretRow
|
||||
// directly, so deleting the cleanup call in the command left them all green.
|
||||
//
|
||||
// The negative half is the same assertion the cleanup's comment makes about
|
||||
// itself — an ordinary yaml-only key must not reach the store at all — and it
|
||||
// is checked against a recorder that fails on any unexpected call.
|
||||
func TestConfigUnsetCommandCleansTheLeakedRow(t *testing.T) {
|
||||
t.Run("secret key: the row is read, deleted and reported", func(t *testing.T) {
|
||||
beadsDir := newLeakedSecretWorkspace(t, "notion:\n token: yaml-copy\n", true)
|
||||
settings := &recordingWorkspaceConfig{stored: map[string]string{"notion.token": "leaked-db-value"}}
|
||||
installLeakedRowSettings(t, settings)
|
||||
|
||||
stdout, _, err := runConfigUnset(t, "notion.token", false)
|
||||
if err != nil {
|
||||
t.Fatalf("config unset notion.token: %v", err)
|
||||
}
|
||||
if got := settings.gets; len(got) != 1 || got[0] != "notion.token" {
|
||||
t.Errorf("GetSetting calls = %v, want exactly [notion.token]", got)
|
||||
}
|
||||
if got := settings.unsets; len(got) != 1 || got[0] != "notion.token" {
|
||||
t.Errorf("UnsetSetting calls = %v, want exactly [notion.token] — the command never reached the cleanup", got)
|
||||
}
|
||||
if !strings.Contains(stdout, "Also removed a stored notion.token row") {
|
||||
t.Errorf("the removal was not reported; stdout:\n%s", stdout)
|
||||
}
|
||||
if !strings.Contains(stdout, "Rotate this credential") {
|
||||
t.Errorf("the rotation obligation was not reported; stdout:\n%s", stdout)
|
||||
}
|
||||
if yaml := readWorkspaceYAML(t, beadsDir); strings.Contains(yaml, "\n token: yaml-copy") {
|
||||
t.Errorf("the config.yaml copy survived:\n%s", yaml)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("non-secret yaml-only key: the store is never reached", func(t *testing.T) {
|
||||
newLeakedSecretWorkspace(t, "routing:\n mode: hybrid\n", true)
|
||||
settings := &recordingWorkspaceConfig{stored: map[string]string{"notion.token": "leaked-db-value"}}
|
||||
installLeakedRowSettings(t, settings)
|
||||
|
||||
if _, _, err := runConfigUnset(t, "routing.mode", false); err != nil {
|
||||
t.Fatalf("config unset routing.mode: %v", err)
|
||||
}
|
||||
if len(settings.gets)+len(settings.unsets) != 0 {
|
||||
t.Errorf("an ordinary yaml-only unset touched the config plane: gets=%v unsets=%v", settings.gets, settings.unsets)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("--json carries the database half", func(t *testing.T) {
|
||||
newLeakedSecretWorkspace(t, "notion:\n token: yaml-copy\n", true)
|
||||
settings := &recordingWorkspaceConfig{stored: map[string]string{"notion.token": "leaked-db-value"}}
|
||||
installLeakedRowSettings(t, settings)
|
||||
|
||||
stdout, _, err := runConfigUnset(t, "notion.token", true)
|
||||
if err != nil {
|
||||
t.Fatalf("config unset --json: %v", err)
|
||||
}
|
||||
var payload map[string]interface{}
|
||||
if err := json.Unmarshal([]byte(stdout), &payload); err != nil {
|
||||
t.Fatalf("unmarshal %q: %v", stdout, err)
|
||||
}
|
||||
if payload["database_row_removed"] != true {
|
||||
t.Errorf("database_row_removed = %v, want true; payload: %v", payload["database_row_removed"], payload)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestConfigUnsetDoesNotProvisionADatabase is the store-creation regression.
|
||||
// `config unset <yaml-only key>` is classified runnable with no store, and the
|
||||
// direct open is open-OR-CREATE, so a best-effort cleanup that reaches for the
|
||||
// store unconditionally turns a YAML edit into a 2.1 MB embedded database in a
|
||||
// workspace that never had one.
|
||||
//
|
||||
// Both assertions are load-bearing, because removing the gate can fail either
|
||||
// way: the open succeeds and materializes the database (caught by the directory
|
||||
// snapshot), or it fails and the command reports an unreachable database
|
||||
// (caught by the stderr assertion). Nothing about a workspace with no database
|
||||
// warrants either.
|
||||
func TestConfigUnsetDoesNotProvisionADatabase(t *testing.T) {
|
||||
beadsDir := newLeakedSecretWorkspace(t, "notion:\n token: yaml-copy\n", false)
|
||||
saveAndRestoreGlobals(t)
|
||||
store = nil
|
||||
setStoreActive(false)
|
||||
|
||||
before := snapshotBeadsStorage(t, beadsDir)
|
||||
|
||||
stdout, stderr, err := runConfigUnset(t, "notion.token", false)
|
||||
if err != nil {
|
||||
t.Fatalf("config unset notion.token: %v", err)
|
||||
}
|
||||
if after := snapshotBeadsStorage(t, beadsDir); !reflect.DeepEqual(before, after) {
|
||||
t.Errorf("unsetting a yaml-only secret changed .beads/:\nbefore: %v\nafter: %v", before, after)
|
||||
}
|
||||
if strings.Contains(stderr, "Could not check the database") {
|
||||
t.Errorf("the command tried to reach a database that does not exist; stderr:\n%s", stderr)
|
||||
}
|
||||
if !strings.Contains(stdout, "Unset notion.token") {
|
||||
t.Errorf("the YAML half did not run; stdout:\n%s", stdout)
|
||||
}
|
||||
}
|
||||
|
||||
// TestConfigUnsetCleansTheRowWithNoLocalDatabaseDirectory pins the two arms of
|
||||
// the provisioning gate that the snapshot test above cannot see. It is that
|
||||
// test's mirror: "no local database directory" is the state the three share, so
|
||||
// the route to the database is the only thing that distinguishes them, and
|
||||
// neither arm had a behavioral test — the clause a later simplification is most
|
||||
// likely to read as redundant was the one clause nothing defended.
|
||||
//
|
||||
// Both shapes are workspaces whose database is real and remote. That is the
|
||||
// population whose row `bd dolt push` replicated the furthest, so a gate that
|
||||
// answers "no database here" from the local disk silently skips the cleanup
|
||||
// exactly where it matters most, and exits 0 while it does.
|
||||
func TestConfigUnsetCleansTheRowWithNoLocalDatabaseDirectory(t *testing.T) {
|
||||
// The metadata-less server workspace: config.yaml names the server, there is
|
||||
// nothing on disk to discover (FindDatabasePath answers on metadata.json,
|
||||
// embeddeddolt/ and dolt/ — none of which exist here), and PersistentPreRun
|
||||
// has already connected the store. gc provisions exactly this shape on every
|
||||
// `gc-beads-bd start` — see metadataless_server_workspace_test.go.
|
||||
t.Run("server mode, store already connected: the row is read and deleted", func(t *testing.T) {
|
||||
beadsDir := newLeakedSecretWorkspace(t, "dolt:\n mode: server\n server_host: 127.0.0.1\nnotion:\n token: yaml-copy\n", false)
|
||||
settings := &recordingWorkspaceConfig{stored: map[string]string{"notion.token": "leaked-db-value"}}
|
||||
installLeakedRowSettings(t, settings)
|
||||
|
||||
before := snapshotBeadsStorage(t, beadsDir)
|
||||
|
||||
stdout, _, err := runConfigUnset(t, "notion.token", false)
|
||||
if err != nil {
|
||||
t.Fatalf("config unset notion.token: %v", err)
|
||||
}
|
||||
if got := settings.gets; len(got) != 1 || got[0] != "notion.token" {
|
||||
t.Errorf("GetSetting calls = %v, want exactly [notion.token] — the cleanup was skipped for a server workspace whose row is on the server", got)
|
||||
}
|
||||
if got := settings.unsets; len(got) != 1 || got[0] != "notion.token" {
|
||||
t.Errorf("UnsetSetting calls = %v, want exactly [notion.token] — the leaked row was left on the shared server", got)
|
||||
}
|
||||
if !strings.Contains(stdout, "Also removed a stored notion.token row") {
|
||||
t.Errorf("the removal was not reported; stdout:\n%s", stdout)
|
||||
}
|
||||
// The gate's purpose still has to hold on this arm: reaching an
|
||||
// already-connected store must not bring a local database into being.
|
||||
if after := snapshotBeadsStorage(t, beadsDir); !reflect.DeepEqual(before, after) {
|
||||
t.Errorf("cleaning the row provisioned local storage:\nbefore: %v\nafter: %v", before, after)
|
||||
}
|
||||
})
|
||||
|
||||
// The proxied route, which has no local database directory by construction.
|
||||
// The store is deliberately left inactive so this subtest exercises the
|
||||
// proxied arm alone rather than the connected-store arm above; the proxied
|
||||
// provider is not initialized in-process, so "reached" shows up as the
|
||||
// best-effort could-not-check report. Silence is the failure being pinned.
|
||||
t.Run("proxied server: the cleanup is reached, not silently skipped", func(t *testing.T) {
|
||||
newLeakedSecretWorkspace(t, "notion:\n token: yaml-copy\n", false)
|
||||
saveAndRestoreGlobals(t)
|
||||
store = nil
|
||||
setStoreActive(false)
|
||||
origProxied := proxiedServerMode
|
||||
t.Cleanup(func() { proxiedServerMode = origProxied })
|
||||
proxiedServerMode = true
|
||||
|
||||
stdout, stderr, err := runConfigUnset(t, "notion.token", false)
|
||||
if err != nil {
|
||||
t.Fatalf("config unset notion.token: %v", err)
|
||||
}
|
||||
if !strings.Contains(stderr, "Could not check the database") {
|
||||
t.Errorf("the proxied workspace's row was never looked for; stderr:\n%s", stderr)
|
||||
}
|
||||
if !strings.Contains(stdout, "Unset notion.token") {
|
||||
t.Errorf("the YAML half did not run; stdout:\n%s", stdout)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestConfigUnsetCleansTheRowWhenTheYamlUnsetFails covers the population the
|
||||
// cleanup exists for and the YAML half cannot serve: a workspace whose token
|
||||
// leaked into the database and whose config.yaml is gone (or holds a shape the
|
||||
// unset refuses). Gating the cleanup on the YAML edit succeeding leaves the
|
||||
// credential in the table `bd dolt push` replicates while telling the user to
|
||||
// run `bd init` — and `bd notion status` points at this very command.
|
||||
func TestConfigUnsetCleansTheRowWhenTheYamlUnsetFails(t *testing.T) {
|
||||
newLeakedSecretWorkspace(t, "", true)
|
||||
settings := &recordingWorkspaceConfig{stored: map[string]string{"notion.token": "leaked-db-value"}}
|
||||
installLeakedRowSettings(t, settings)
|
||||
|
||||
_, stderr, err := runConfigUnset(t, "notion.token", false)
|
||||
if err == nil {
|
||||
t.Fatal("config unset succeeded with no config.yaml, want the YAML failure to still be reported")
|
||||
}
|
||||
if got := settings.unsets; len(got) != 1 || got[0] != "notion.token" {
|
||||
t.Errorf("UnsetSetting calls = %v, want exactly [notion.token] — the leaked row survived a failure on the other copy", got)
|
||||
}
|
||||
if !strings.Contains(stderr, "stored notion.token row WAS removed") {
|
||||
t.Errorf("the error never mentions the database row; stderr:\n%s", stderr)
|
||||
}
|
||||
if !strings.Contains(stderr, "rotate that credential") {
|
||||
t.Errorf("the rotation obligation was dropped on the failure path; stderr:\n%s", stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// TestConfigUnsetDistinguishesADeleteFailure keeps the one certain case out of
|
||||
// the hedged one. A failed read means bd does not know whether anything leaked;
|
||||
// a failed delete means it read the row and it is still there — the single
|
||||
// outcome that warrants "a live credential is in the pushed table", and the one
|
||||
// that was being rendered as an unreachable database.
|
||||
func TestConfigUnsetDistinguishesADeleteFailure(t *testing.T) {
|
||||
deleteFailed := errors.New("delete rejected")
|
||||
|
||||
t.Run("human output names the surviving row", func(t *testing.T) {
|
||||
newLeakedSecretWorkspace(t, "notion:\n token: yaml-copy\n", true)
|
||||
settings := &recordingWorkspaceConfig{
|
||||
stored: map[string]string{"notion.token": "leaked-db-value"},
|
||||
unsetErr: deleteFailed,
|
||||
}
|
||||
installLeakedRowSettings(t, settings)
|
||||
|
||||
_, stderr, err := runConfigUnset(t, "notion.token", false)
|
||||
if err != nil {
|
||||
t.Fatalf("config unset notion.token: %v", err)
|
||||
}
|
||||
if !strings.Contains(stderr, "still in the database") {
|
||||
t.Errorf("a failed delete was not reported as a surviving row; stderr:\n%s", stderr)
|
||||
}
|
||||
if strings.Contains(stderr, "Could not check the database") {
|
||||
t.Errorf("a failed delete was reported as an inconclusive lookup; stderr:\n%s", stderr)
|
||||
}
|
||||
if !strings.Contains(stderr, "Rotate this credential") {
|
||||
t.Errorf("the rotation obligation was dropped; stderr:\n%s", stderr)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("--json separates present-but-undeleted from unreachable", func(t *testing.T) {
|
||||
newLeakedSecretWorkspace(t, "notion:\n token: yaml-copy\n", true)
|
||||
settings := &recordingWorkspaceConfig{
|
||||
stored: map[string]string{"notion.token": "leaked-db-value"},
|
||||
unsetErr: deleteFailed,
|
||||
}
|
||||
installLeakedRowSettings(t, settings)
|
||||
|
||||
stdout, _, err := runConfigUnset(t, "notion.token", true)
|
||||
if err != nil {
|
||||
t.Fatalf("config unset --json: %v", err)
|
||||
}
|
||||
var payload map[string]interface{}
|
||||
if err := json.Unmarshal([]byte(stdout), &payload); err != nil {
|
||||
t.Fatalf("unmarshal %q: %v", stdout, err)
|
||||
}
|
||||
if payload["database_row_present"] != true {
|
||||
t.Errorf("database_row_present = %v, want true; payload: %v", payload["database_row_present"], payload)
|
||||
}
|
||||
if _, claimed := payload["database_unreachable"]; claimed {
|
||||
t.Errorf("a reachable database that refused the delete was reported unreachable; payload: %v", payload)
|
||||
}
|
||||
if got, ok := payload["database_delete_failed"].(string); !ok || !strings.Contains(got, "delete rejected") {
|
||||
t.Errorf("database_delete_failed = %v, want the delete error; payload: %v", payload["database_delete_failed"], payload)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func readWorkspaceYAML(t *testing.T, beadsDir string) string {
|
||||
t.Helper()
|
||||
content, err := os.ReadFile(filepath.Join(beadsDir, "config.yaml"))
|
||||
if err != nil {
|
||||
t.Fatalf("read config.yaml: %v", err)
|
||||
}
|
||||
return string(content)
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/steveyegge/beads/internal/beads"
|
||||
"github.com/steveyegge/beads/internal/config"
|
||||
"github.com/steveyegge/beads/internal/configfile"
|
||||
"github.com/steveyegge/beads/internal/gitenv"
|
||||
"github.com/steveyegge/beads/internal/metrics"
|
||||
"github.com/steveyegge/beads/internal/workapi"
|
||||
)
|
||||
|
|
@ -334,6 +335,7 @@ func collectGitConfigEntries() []configEntry {
|
|||
|
||||
// beads.role is the only git config key currently
|
||||
cmd := exec.Command("git", "config", "--get", "beads.role")
|
||||
cmd.Env = gitenv.ScrubRoutingAndSuppression(os.Environ())
|
||||
output, err := cmd.Output()
|
||||
if err == nil {
|
||||
value := strings.TrimSpace(string(output))
|
||||
|
|
|
|||
|
|
@ -3,11 +3,14 @@ package main
|
|||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/config"
|
||||
"github.com/steveyegge/beads/internal/gitenv"
|
||||
)
|
||||
|
||||
// TestViperSourceLabel verifies source label formatting for different config sources.
|
||||
|
|
@ -437,3 +440,79 @@ func TestCollectViperEntriesMetricsUserGlobalProvenance(t *testing.T) {
|
|||
t.Errorf("config show --json entry %s misattributes user-global value to project config.yaml", encoded)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCollectGitConfigEntriesIgnoresInheritedRouting(t *testing.T) {
|
||||
for _, entry := range os.Environ() {
|
||||
key := gitenv.EntryKey(entry)
|
||||
if gitenv.IsRoutingKeyForOS(key, runtime.GOOS) {
|
||||
t.Setenv(key, "")
|
||||
if err := os.Unsetenv(key); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
pinJSONOutput(t, false)
|
||||
runGit := func(t *testing.T, repo string, args ...string) {
|
||||
t.Helper()
|
||||
cmd := exec.Command("git", args...)
|
||||
cmd.Dir = repo
|
||||
cmd.Env = gitenv.ScrubRouting(os.Environ())
|
||||
if out, err := cmd.CombinedOutput(); err != nil {
|
||||
t.Fatalf("fixture git %v: %v: %s", args, err, out)
|
||||
}
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
name, local, global, want string
|
||||
}{
|
||||
{"repository", "maintainer", "", "maintainer"},
|
||||
{"inline", "maintainer", "", "maintainer"},
|
||||
{"default_global", "", "contributor", "contributor"},
|
||||
{"absent", "", "", ""},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
home, target, decoy := t.TempDir(), t.TempDir(), t.TempDir()
|
||||
for _, key := range []string{"HOME", "USERPROFILE", "XDG_CONFIG_HOME"} {
|
||||
t.Setenv(key, home)
|
||||
}
|
||||
if tc.global != "" {
|
||||
if err := os.WriteFile(filepath.Join(home, ".gitconfig"), []byte("[beads]\nrole = "+tc.global+"\n"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
for _, repo := range []string{target, decoy} {
|
||||
runGit(t, repo, "init", "--quiet")
|
||||
}
|
||||
runGit(t, decoy, "config", "beads.role", "decoy-role")
|
||||
if tc.local != "" {
|
||||
runGit(t, target, "config", "beads.role", tc.local)
|
||||
}
|
||||
t.Chdir(target)
|
||||
poison := map[string]string{"GIT_CONFIG_COUNT": "1", "GIT_CONFIG_KEY_0": "beads.role", "GIT_CONFIG_VALUE_0": "injected-role"}
|
||||
if tc.name == "repository" {
|
||||
poison = map[string]string{"GIT_DIR": filepath.Join(decoy, ".git"), "GIT_WORK_TREE": decoy}
|
||||
}
|
||||
for key, value := range poison {
|
||||
t.Setenv(key, value)
|
||||
}
|
||||
entries := collectGitConfigEntries()
|
||||
wantGet := tc.want
|
||||
if tc.want == "" {
|
||||
wantGet = "beads.role (not set in git config)"
|
||||
if len(entries) != 0 {
|
||||
t.Errorf("absent role produced entries: %+v", entries)
|
||||
}
|
||||
} else if len(entries) != 1 || entries[0] != (configEntry{Key: "beads.role", Value: tc.want, Source: "git"}) {
|
||||
t.Errorf("Git entries = %+v; want role=%q with source=git", entries, tc.want)
|
||||
}
|
||||
out := captureStdout(t, func() error { return configGetCmd.RunE(configGetCmd, []string{"beads.role"}) })
|
||||
if strings.TrimSpace(out) != wantGet {
|
||||
t.Errorf("config get = %q; want %q", out, wantGet)
|
||||
}
|
||||
for key, value := range poison {
|
||||
if os.Getenv(key) != value {
|
||||
t.Errorf("reader changed parent environment %s", key)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import (
|
|||
"github.com/steveyegge/beads/internal/gitenv"
|
||||
"github.com/steveyegge/beads/internal/storage/dolt"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestConfigCommands(t *testing.T) {
|
||||
|
|
@ -409,6 +410,83 @@ func TestBeadsRoleCommandsIgnoreInheritedGitRouting(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestBeadsRoleWritesUseFreshCommonConfig(t *testing.T) {
|
||||
for _, entry := range os.Environ() {
|
||||
key := gitenv.EntryKey(entry)
|
||||
if gitenv.IsRoutingKeyForOS(key, runtime.GOOS) {
|
||||
t.Setenv(key, "")
|
||||
require.NoError(t, os.Unsetenv(key))
|
||||
}
|
||||
}
|
||||
pinJSONOutput(t, false)
|
||||
t.Cleanup(git.ResetCaches)
|
||||
for _, kind := range []string{"linked", "bare", "separate", "nonrepo"} {
|
||||
t.Run(kind, func(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
for _, key := range []string{"HOME", "USERPROFILE", "XDG_CONFIG_HOME"} {
|
||||
t.Setenv(key, home)
|
||||
}
|
||||
run := func(dir string, args ...string) string {
|
||||
cmd := exec.Command("git", args...)
|
||||
cmd.Dir, cmd.Env = dir, gitenv.ScrubRouting(os.Environ())
|
||||
out, err := cmd.CombinedOutput()
|
||||
require.NoError(t, err, "fixture git %v: %s", args, out)
|
||||
return strings.TrimSpace(string(out))
|
||||
}
|
||||
main, decoy, target := t.TempDir(), t.TempDir(), t.TempDir()
|
||||
for _, dir := range []string{main, decoy} {
|
||||
run(dir, "init", "--quiet")
|
||||
run(dir, "config", "--local", "core.hooksPath", ".git/hooks")
|
||||
}
|
||||
switch kind {
|
||||
case "linked":
|
||||
run(main, "-c", "user.name=Fixture", "-c", "user.email=fixture@example.test", "-c", "commit.gpgSign=false", "commit", "--allow-empty", "-m", "seed")
|
||||
run(main, "config", "extensions.worktreeConfig", "true")
|
||||
run(main, "worktree", "add", "--detach", target)
|
||||
run(target, "config", "--worktree", "beads.role", "private-role")
|
||||
case "bare":
|
||||
run(home, "init", "--bare", target)
|
||||
case "separate":
|
||||
run(home, "init", "--separate-git-dir", filepath.Join(home, "external git"), target)
|
||||
}
|
||||
t.Chdir(decoy)
|
||||
git.ResetCaches()
|
||||
cached, err := git.GetGitCommonDir()
|
||||
require.NoError(t, err)
|
||||
t.Chdir(target)
|
||||
t.Setenv("GIT_DIR", filepath.Join(decoy, ".git"))
|
||||
t.Setenv("GIT_CONFIG", filepath.Join(decoy, ".git", "config"))
|
||||
before, err := os.ReadFile(filepath.Join(decoy, ".git", "config"))
|
||||
require.NoError(t, err)
|
||||
for _, command := range []struct {
|
||||
cmd *cobra.Command
|
||||
args []string
|
||||
}{
|
||||
{configSetCmd, []string{"beads.role", "contributor"}},
|
||||
{configSetManyCmd, []string{"beads.role=maintainer", "beads.role=contributor"}},
|
||||
{configUnsetCmd, []string{"beads.role"}},
|
||||
} {
|
||||
if kind == "nonrepo" {
|
||||
captureStderr(t, func() { require.Error(t, command.cmd.RunE(command.cmd, command.args)) })
|
||||
continue
|
||||
}
|
||||
captureStdout(t, func() error { return command.cmd.RunE(command.cmd, command.args) })
|
||||
role := run(target, "config", "--local", "--list")
|
||||
require.Equal(t, command.cmd != configUnsetCmd, strings.Contains(role, "beads.role=contributor"))
|
||||
if kind == "linked" {
|
||||
require.Equal(t, "private-role", run(target, "config", "--worktree", "--get", "beads.role"))
|
||||
}
|
||||
}
|
||||
after, err := os.ReadFile(filepath.Join(decoy, ".git", "config"))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, before, after)
|
||||
stillCached, err := git.GetGitCommonDir()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, cached, stillCached)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestIsValidRemoteURL tests the remote URL validation function
|
||||
func TestIsValidRemoteURL(t *testing.T) {
|
||||
tests := []struct {
|
||||
|
|
@ -1055,3 +1133,63 @@ func TestConfigSetManyValidationIntegration(t *testing.T) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestBeadsRoleWriteErrorsRetainGitDiagnostics(t *testing.T) {
|
||||
t.Setenv("LC_ALL", "C")
|
||||
pinJSONOutput(t, false)
|
||||
for _, entry := range os.Environ() {
|
||||
key := gitenv.EntryKey(entry)
|
||||
if gitenv.IsRoutingKeyForOS(key, runtime.GOOS) {
|
||||
t.Setenv(key, "")
|
||||
require.NoError(t, os.Unsetenv(key))
|
||||
}
|
||||
}
|
||||
for _, operation := range []struct {
|
||||
name string
|
||||
cmd *cobra.Command
|
||||
args []string
|
||||
}{
|
||||
{"set", configSetCmd, []string{"beads.role", "contributor"}},
|
||||
{"set-many", configSetManyCmd, []string{"beads.role=contributor"}},
|
||||
{"unset", configUnsetCmd, []string{"beads.role"}},
|
||||
} {
|
||||
for _, failure := range []string{"nonrepo", "config_lock", "duplicate"} {
|
||||
t.Run(operation.name+"/"+failure, func(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
for _, key := range []string{"HOME", "USERPROFILE", "XDG_CONFIG_HOME"} {
|
||||
t.Setenv(key, home)
|
||||
}
|
||||
repo := newGitRepo(t)
|
||||
t.Chdir(repo)
|
||||
run := func(args ...string) {
|
||||
cmd := exec.Command("git", args...)
|
||||
out, err := cmd.CombinedOutput()
|
||||
require.NoError(t, err, "%s", out)
|
||||
}
|
||||
run("config", "--local", "beads.role", "maintainer")
|
||||
want := "not a git repository"
|
||||
switch failure {
|
||||
case "nonrepo":
|
||||
t.Chdir(t.TempDir())
|
||||
case "config_lock":
|
||||
require.NoError(t, os.WriteFile(filepath.Join(repo, ".git", "config.lock"), []byte("owned lock"), 0600))
|
||||
want = "could not lock config file"
|
||||
case "duplicate":
|
||||
run("config", "--local", "--add", "beads.role", "contributor")
|
||||
want = "multiple values"
|
||||
}
|
||||
configPath := filepath.Join(repo, ".git", "config")
|
||||
before, err := os.ReadFile(configPath)
|
||||
require.NoError(t, err)
|
||||
stderr := captureStderr(t, func() { err = operation.cmd.RunE(operation.cmd, operation.args) })
|
||||
code, ok := exitCodeFromError(err)
|
||||
require.True(t, ok)
|
||||
require.Equal(t, 1, code)
|
||||
require.Contains(t, stderr, want)
|
||||
after, readErr := os.ReadFile(configPath)
|
||||
require.NoError(t, readErr)
|
||||
require.Equal(t, before, after, "failed role write changed config")
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
"github.com/steveyegge/beads/internal/beads"
|
||||
"github.com/steveyegge/beads/internal/configfile"
|
||||
"github.com/steveyegge/beads/internal/git"
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/storage/backends"
|
||||
"github.com/steveyegge/beads/internal/storage/contextinfo"
|
||||
|
|
@ -83,8 +84,13 @@ func TestContextRoutesNameOneWorkspaceTheSameWay(t *testing.T) {
|
|||
}
|
||||
t.Chdir(dir)
|
||||
t.Setenv("BEADS_DIR", beadsDir)
|
||||
// git caches the cwd's repository context process-wide; a test
|
||||
// that ran earlier from a non-repo directory would otherwise make
|
||||
// this fresh repo look like "not a git repository".
|
||||
git.ResetCaches()
|
||||
beads.ResetCaches()
|
||||
t.Cleanup(beads.ResetCaches)
|
||||
t.Cleanup(git.ResetCaches)
|
||||
|
||||
provider, err := contextinfo.NewContextProvider(dir, Version).ContextUseCase().GetContextInfo(t.Context())
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ Examples:
|
|||
bd count --by-label # Group count by label
|
||||
bd count --assignee alice --by-status # Count alice's issues by status
|
||||
bd count --include-infra # Count issues + wisps tier (matches 'bd list --include-infra --all' cardinality)
|
||||
bd count --type task --include-ephemeral # Count tasks in the durable AND wisps tiers
|
||||
`,
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
|
|
@ -91,6 +92,7 @@ func parseCountRequest(cmd *cobra.Command) (issueops.CountRequest, issueops.Coun
|
|||
noLabels, _ := cmd.Flags().GetBool("no-labels")
|
||||
includeInfra, _ := cmd.Flags().GetBool("include-infra")
|
||||
metadataFieldFlags, _ := cmd.Flags().GetStringArray("metadata-field")
|
||||
includeEphemeral, _ := cmd.Flags().GetBool("include-ephemeral")
|
||||
|
||||
request := issueops.CountRequest{
|
||||
Status: status,
|
||||
|
|
@ -107,6 +109,8 @@ func parseCountRequest(cmd *cobra.Command) (issueops.CountRequest, issueops.Coun
|
|||
NoAssignee: noAssignee,
|
||||
NoLabels: noLabels,
|
||||
IncludeInfra: includeInfra,
|
||||
|
||||
IncludeEphemeral: includeEphemeral,
|
||||
}
|
||||
if len(metadataFieldFlags) > 0 {
|
||||
request.MetadataFields = make(map[string]string, len(metadataFieldFlags))
|
||||
|
|
@ -121,6 +125,12 @@ func parseCountRequest(cmd *cobra.Command) (issueops.CountRequest, issueops.Coun
|
|||
request.MetadataFields[k] = v
|
||||
}
|
||||
}
|
||||
if k, _ := cmd.Flags().GetString("has-metadata-key"); k != "" {
|
||||
if err := storage.ValidateMetadataKey(k); err != nil {
|
||||
return issueops.CountRequest{}, "", HandleErrorRespectJSON("invalid --has-metadata-key: %v", err)
|
||||
}
|
||||
request.HasMetadataKey = k
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("priority") {
|
||||
priority, _ := cmd.Flags().GetInt("priority")
|
||||
|
|
@ -279,6 +289,7 @@ func registerCountFlags(cmd *cobra.Command) {
|
|||
cmd.Flags().Bool("no-assignee", false, "Filter issues with no assignee")
|
||||
cmd.Flags().Bool("no-labels", false, "Filter issues with no labels")
|
||||
cmd.Flags().StringArray("metadata-field", nil, "Filter by metadata field (key=value, repeatable)")
|
||||
cmd.Flags().String("has-metadata-key", "", "Filter issues that have this metadata key set")
|
||||
|
||||
// Priority ranges
|
||||
cmd.Flags().Int("priority-min", 0, "Filter by minimum priority (inclusive)")
|
||||
|
|
@ -289,6 +300,18 @@ func registerCountFlags(cmd *cobra.Command) {
|
|||
// `bd list --include-infra <filters> --all`.
|
||||
cmd.Flags().Bool("include-infra", false, "Include infrastructure beads and the wisps tier (matches 'bd list --include-infra --all' cardinality)")
|
||||
|
||||
// The plane knob alone: admits the wisps tier WITHOUT lifting any type
|
||||
// exclusion, which --include-infra cannot do (it bundles four changes, and
|
||||
// its template exclusion silently drops template rows of a named type).
|
||||
//
|
||||
// The sibling on `bd list` landed in #6098 (cmd/bd/list.go); the name and
|
||||
// the help text deliberately follow its shape so the two halves of the
|
||||
// pair read alike. The trailing clause is the one addition: on `bd count`
|
||||
// the wider `--include-infra` sits right beside this flag and advertises
|
||||
// cardinality matching, so the contrast has to be legible in `--help` and
|
||||
// not only in this comment.
|
||||
cmd.Flags().Bool("include-ephemeral", false, "Include ephemeral wisp-plane rows in the count (normally hidden), without lifting type exclusions")
|
||||
|
||||
// Grouping flags
|
||||
cmd.Flags().Bool("by-status", false, "Group count by status")
|
||||
cmd.Flags().Bool("by-priority", false, "Group count by priority")
|
||||
|
|
|
|||
|
|
@ -90,12 +90,16 @@ func TestEmbeddedCount(t *testing.T) {
|
|||
bdCreate(t, bd, dir, "Count labeled two", "--type", "task", "--label", "backend")
|
||||
bdCreate(t, bd, dir, "Count notes issue", "--type", "task", "--description", "notes keyword here")
|
||||
bdCreate(t, bd, dir, "Count metadata issue", "--type", "task", "--metadata", `{"count_scope":"matching"}`)
|
||||
// The same key with a different value: --has-metadata-key matches both
|
||||
// fixtures where --metadata-field matches one, so the two filters cannot
|
||||
// pass by answering the same number.
|
||||
bdCreate(t, bd, dir, "Count metadata key issue", "--type", "task", "--metadata", `{"count_scope":"other"}`)
|
||||
|
||||
// ===== Basic count =====
|
||||
|
||||
t.Run("basic_count_no_filters", func(t *testing.T) {
|
||||
out := strings.TrimSpace(bdCount(t, bd, dir))
|
||||
// Should return a number >= 9 (we created 9 issues)
|
||||
// Should return a number >= 10 (we created 10 issues)
|
||||
if out == "0" {
|
||||
t.Error("expected non-zero count")
|
||||
}
|
||||
|
|
@ -179,6 +183,14 @@ func TestEmbeddedCount(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
t.Run("filter_by_has_metadata_key", func(t *testing.T) {
|
||||
got := int(bdCountJSON(t, bd, dir, "--has-metadata-key", "count_scope")["count"].(float64))
|
||||
want := len(bdListJSON(t, bd, dir, "--all", "--limit", "0", "--has-metadata-key", "count_scope"))
|
||||
if got != want || got != 2 {
|
||||
t.Errorf("count --has-metadata-key = %d, want list cardinality %d and fixture count 2", got, want)
|
||||
}
|
||||
})
|
||||
|
||||
// ===== Title filter =====
|
||||
|
||||
t.Run("filter_by_title", func(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -65,10 +65,12 @@ func TestParseCountRequestCarriesEveryFilterFlag(t *testing.T) {
|
|||
"no-assignee": "true",
|
||||
"no-labels": "true",
|
||||
"metadata-field": "team=platform",
|
||||
"has-metadata-key": "audit_ref",
|
||||
"priority": "1",
|
||||
"priority-min": "0",
|
||||
"priority-max": "4",
|
||||
"include-infra": "true",
|
||||
"include-ephemeral": "true",
|
||||
} {
|
||||
if err := flags.Flags().Set(flag, value); err != nil {
|
||||
t.Fatalf("set --%s=%s: %v", flag, value, err)
|
||||
|
|
@ -95,30 +97,32 @@ func TestParseCountRequestCarriesEveryFilterFlag(t *testing.T) {
|
|||
}
|
||||
priority, min, max := 1, 0, 4
|
||||
want := issueops.CountRequest{
|
||||
Status: "closed",
|
||||
IssueType: "bug",
|
||||
Assignee: "alice",
|
||||
Priority: &priority,
|
||||
PriorityMin: &min,
|
||||
PriorityMax: &max,
|
||||
Labels: []string{"alpha", "beta"},
|
||||
LabelsAny: []string{"gamma"},
|
||||
TitleSearch: "needle",
|
||||
IDFilter: "bd-1,bd-2",
|
||||
TitleContains: "tc",
|
||||
DescContains: "dc",
|
||||
NotesContains: "nc",
|
||||
CreatedAfter: day(1),
|
||||
CreatedBefore: day(2),
|
||||
UpdatedAfter: day(3),
|
||||
UpdatedBefore: day(4),
|
||||
ClosedAfter: day(5),
|
||||
ClosedBefore: day(6),
|
||||
EmptyDesc: true,
|
||||
NoAssignee: true,
|
||||
NoLabels: true,
|
||||
MetadataFields: map[string]string{"team": "platform"},
|
||||
IncludeInfra: true,
|
||||
Status: "closed",
|
||||
IssueType: "bug",
|
||||
Assignee: "alice",
|
||||
Priority: &priority,
|
||||
PriorityMin: &min,
|
||||
PriorityMax: &max,
|
||||
Labels: []string{"alpha", "beta"},
|
||||
LabelsAny: []string{"gamma"},
|
||||
TitleSearch: "needle",
|
||||
IDFilter: "bd-1,bd-2",
|
||||
TitleContains: "tc",
|
||||
DescContains: "dc",
|
||||
NotesContains: "nc",
|
||||
CreatedAfter: day(1),
|
||||
CreatedBefore: day(2),
|
||||
UpdatedAfter: day(3),
|
||||
UpdatedBefore: day(4),
|
||||
ClosedAfter: day(5),
|
||||
ClosedBefore: day(6),
|
||||
EmptyDesc: true,
|
||||
NoAssignee: true,
|
||||
NoLabels: true,
|
||||
MetadataFields: map[string]string{"team": "platform"},
|
||||
HasMetadataKey: "audit_ref",
|
||||
IncludeInfra: true,
|
||||
IncludeEphemeral: true,
|
||||
}
|
||||
if !reflect.DeepEqual(request, want) {
|
||||
t.Errorf("parseCountRequest built\n %#v\nwant\n %#v", request, want)
|
||||
|
|
@ -139,6 +143,16 @@ func TestParseCountRequestRejectsInvalidMetadataField(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestParseCountRequestRejectsInvalidHasMetadataKey(t *testing.T) {
|
||||
flags := newCountFlagSet(t)
|
||||
if err := flags.Flags().Set("has-metadata-key", "1bad"); err != nil {
|
||||
t.Fatalf("set --has-metadata-key: %v", err)
|
||||
}
|
||||
if _, _, err := parseCountRequest(flags); err == nil {
|
||||
t.Fatal("parseCountRequest accepted --has-metadata-key 1bad")
|
||||
}
|
||||
}
|
||||
|
||||
// TestParseCountRequestResolvesTheGroupingFlags pins each --by-* flag to its
|
||||
// dimension and the refusal for two at once. The exclusivity check cannot live
|
||||
// behind the role — by then only one dimension is left — so it is checked here.
|
||||
|
|
|
|||
79
cmd/bd/count_include_ephemeral_embedded_test.go
Normal file
79
cmd/bd/count_include_ephemeral_embedded_test.go
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
//go:build cgo
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestEmbeddedCountIncludeEphemeral covers the plane knob end to end, on the
|
||||
// same fixture shape TestEmbeddedCountIncludeInfra uses.
|
||||
//
|
||||
// It is a SEPARATE file rather than a subtest of that function on purpose:
|
||||
// TestEmbeddedCountIncludeInfra pins the existing --include-infra contract and
|
||||
// is left byte-for-byte untouched, so a reader can see at a glance that this
|
||||
// flag changed nothing it asserts.
|
||||
//
|
||||
// The distinction being pinned: --include-infra bundles four changes (see
|
||||
// issueops.CountRequest.IncludeInfra) and its template exclusion silently drops
|
||||
// template rows of the named type. --include-ephemeral admits the plane and
|
||||
// nothing else.
|
||||
func TestEmbeddedCountIncludeEphemeral(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, _, _ := bdInit(t, bd, "--prefix", "ie")
|
||||
|
||||
// 3 durable tasks (one closed), 2 no_history tasks, 1 ephemeral task.
|
||||
bdCreate(t, bd, dir, "durable task one", "--type", "task")
|
||||
bdCreate(t, bd, dir, "durable task two", "--type", "task")
|
||||
closed := bdCreate(t, bd, dir, "durable task closed", "--type", "task")
|
||||
bdClose(t, bd, dir, closed.ID)
|
||||
bdCreate(t, bd, dir, "nohistory task one", "--type", "task", "--no-history")
|
||||
bdCreate(t, bd, dir, "nohistory task two", "--type", "task", "--no-history")
|
||||
bdCreate(t, bd, dir, "ephemeral task", "--type", "task", "--ephemeral")
|
||||
|
||||
countOf := func(args ...string) int {
|
||||
t.Helper()
|
||||
m := bdCountJSON(t, bd, dir, args...)
|
||||
return int(m["count"].(float64))
|
||||
}
|
||||
|
||||
t.Run("default stays durable-only", func(t *testing.T) {
|
||||
if got := countOf("--type", "task"); got != 3 {
|
||||
t.Errorf("bd count --type task = %d, want 3 (the default before this change, unchanged)", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("include-ephemeral reaches the wisps tier", func(t *testing.T) {
|
||||
if got := countOf("--type", "task", "--include-ephemeral"); got != 6 {
|
||||
t.Errorf("bd count --type task --include-ephemeral = %d, want 6 "+
|
||||
"(3 durable + 2 no_history + 1 ephemeral)", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("count and list read the same plane", func(t *testing.T) {
|
||||
// The property is that both reach the wisps tier under the flag — NOT
|
||||
// that the two numbers are equal. A count includes template rows and a
|
||||
// listing does not, with or without this flag (see
|
||||
// issueops.CountRequest.IncludeEphemeral), and this fixture has no
|
||||
// templates only because it does not need any. Asserting raw equality
|
||||
// here would pass by accident and break the day someone adds one.
|
||||
durable := len(bdListJSON(t, bd, dir,
|
||||
"--type", "task", "--status", "all", "--limit", "0"))
|
||||
withPlane := len(bdListJSON(t, bd, dir,
|
||||
"--type", "task", "--include-ephemeral", "--status", "all", "--limit", "0"))
|
||||
if withPlane-durable != 3 {
|
||||
t.Errorf("list gained %d rows from the plane, want 3 (2 no_history + 1 ephemeral)",
|
||||
withPlane-durable)
|
||||
}
|
||||
if got := countOf("--type", "task", "--include-ephemeral") - countOf("--type", "task"); got != 3 {
|
||||
t.Errorf("count gained %d rows from the plane, want 3 — count and list "+
|
||||
"must admit the same tier even where their totals differ", got)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -31,6 +31,9 @@ func TestProxiedServerCount(t *testing.T) {
|
|||
bdProxiedCreate(t, bd, p.dir, "Count labeled two", "--type", "task", "--label", "backend")
|
||||
bdProxiedCreate(t, bd, p.dir, "Count notes issue", "--type", "task", "--description", "notes keyword here")
|
||||
bdProxiedCreate(t, bd, p.dir, "Count metadata issue", "--type", "task", "--metadata", `{"count_scope":"matching"}`)
|
||||
// The same key with a different value, so --has-metadata-key and
|
||||
// --metadata-field cannot pass by answering the same number.
|
||||
bdProxiedCreate(t, bd, p.dir, "Count metadata key issue", "--type", "task", "--metadata", `{"count_scope":"other"}`)
|
||||
|
||||
// countInt runs "count <args>" and parses the plain integer stdout.
|
||||
countInt := func(t *testing.T, args ...string) int {
|
||||
|
|
@ -129,6 +132,13 @@ func TestProxiedServerCount(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
t.Run("filter_by_has_metadata_key", func(t *testing.T) {
|
||||
got := countJSONInt(t, "--has-metadata-key", "count_scope")
|
||||
if want := listCount("--has-metadata-key", "count_scope"); got != want || got != 2 {
|
||||
t.Errorf("count --has-metadata-key = %d, want list cardinality %d and fixture count 2", got, want)
|
||||
}
|
||||
})
|
||||
|
||||
// ===== Priority filter =====
|
||||
|
||||
t.Run("filter_by_priority", func(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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() }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/beads"
|
||||
"github.com/steveyegge/beads/internal/git"
|
||||
)
|
||||
|
||||
// TestCreateRemoteRepoSkipsLocalDatabaseGuard is a regression test for a gap
|
||||
|
|
@ -54,6 +57,18 @@ func TestCreateRemoteRepoSkipsLocalDatabaseGuard(t *testing.T) {
|
|||
t.Fatalf("chdir(%q): %v", noBeadsCwd, err)
|
||||
}
|
||||
t.Cleanup(func() { _ = os.Chdir(originalWD) })
|
||||
// git and beads cache the cwd's repository and workspace process-wide. Start
|
||||
// from caches that describe noBeadsCwd: a cache an earlier test filled from
|
||||
// the package directory (a checkout, or a worktree whose main repository has
|
||||
// a .beads) would hand create that workspace instead. Reset again on the
|
||||
// way out, before the cwd is restored, so the next test does not inherit
|
||||
// this directory's answers.
|
||||
git.ResetCaches()
|
||||
beads.ResetCaches()
|
||||
t.Cleanup(func() {
|
||||
git.ResetCaches()
|
||||
beads.ResetCaches()
|
||||
})
|
||||
|
||||
// Hide the `dolt` CLI so remotecache.Ensure fails fast and
|
||||
// deterministically in CGO-enabled builds, without attempting a real network
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
128
cmd/bd/dep.go
128
cmd/bd/dep.go
|
|
@ -107,6 +107,112 @@ func resolveIDForMutation(ctx context.Context, localStore storage.DoltStorage, i
|
|||
return result.ResolvedID, s, func() { result.Close() }, nil
|
||||
}
|
||||
|
||||
// refuseMalformedDepTarget refuses a dep add target that contains ":" but is
|
||||
// not an "external:" ref. This is the half of the target decision that needs no
|
||||
// ID resolution, so it is the half every dep add surface can share — including
|
||||
// the proxied-server paths, which deliberately resolve nothing and so cannot
|
||||
// call resolveUnresolvedDepTarget. A colon-free target is not this helper's
|
||||
// business and returns nil; the caller still owns the resolve/cross-prefix
|
||||
// decision. Refusing here rather than per-surface is what keeps `bd dep add`
|
||||
// from being mode-dependently correct (be-gmdx5 survived in proxied mode and on
|
||||
// --file until every site routed through this). The five sites are: the
|
||||
// positional and --file direct routes (both via resolveUnresolvedDepTarget),
|
||||
// their two proxied twins, and runDepBlocksProxiedServer — the `bd dep <a>
|
||||
// --blocks <b>` alias the dep help documents as equivalent to dep add, which
|
||||
// passes the blocker as the target and so inverts the operands.
|
||||
//
|
||||
// The refused shape is be-gmdx5 itself: a "type:id" positional arg (e.g.
|
||||
// "discovered-from:ga-x", the spec syntax `bd create --deps` accepts) was read
|
||||
// as a foreign-store ID, because ExtractPrefix stops at the first "-" and so
|
||||
// returns "discovered-". The type keyword was silently dropped (the edge
|
||||
// defaulted to blocks) and the whole string was stored as a bogus external ref.
|
||||
// No bd ID contains ":", and callers take the only legal ":" shape
|
||||
// ("external:") first, so anything reaching here is malformed regardless of
|
||||
// prefix.
|
||||
//
|
||||
// Two details in the message:
|
||||
//
|
||||
// - The `bd create --deps` diagnosis is only asserted when the token before
|
||||
// the ":" is a type --type would actually accept. Otherwise an unrelated
|
||||
// colon-bearing typo ("https://example.com/x") is told a confidently wrong
|
||||
// cause and handed "--type https", which the next validation rejects.
|
||||
// - The suggested command respects direction. parseDepSpec reverses the
|
||||
// endpoints for the literal "blocks:" spelling only (create_deps.go sets
|
||||
// SwapDirection for rawType == DepBlocks), so `--deps blocks:B` on A stores
|
||||
// "B depends on A" and the equivalent dep add has to name B first. The
|
||||
// "depends-on"/"blocked-by" aliases are compared before
|
||||
// canonicalDependencyType and do not swap, so they keep the natural order.
|
||||
// Getting this backwards would hand the user a reversed bd ready/bd blocked
|
||||
// gate (Type.AffectsReadyWork), not just a cosmetically odd command.
|
||||
func refuseMalformedDepTarget(sourceID, dependsOnArg string) error {
|
||||
idx := strings.Index(dependsOnArg, ":")
|
||||
if idx < 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Trim both halves the way parseDepSpec does (create_deps.go), or the
|
||||
// diagnosis this branch exists to give degrades on exactly the specs
|
||||
// `bd create --deps` accepts: "blocks : bd-2" parses there, but read
|
||||
// verbatim here the type is "blocks " — neither types.DepBlocks (so the
|
||||
// direction swap is never considered) nor well-known (so the suggestion is
|
||||
// suppressed), and the user is handed the generic refusal instead of the
|
||||
// translation. The refusal itself is correct either way; only the message
|
||||
// is at stake, and it must name a command that actually runs.
|
||||
depType, target := strings.TrimSpace(dependsOnArg[:idx]), strings.TrimSpace(dependsOnArg[idx+1:])
|
||||
if depType == "" || target == "" ||
|
||||
validateDependencyType(canonicalDependencyType(types.DependencyType(depType))) != nil {
|
||||
return fmt.Errorf("invalid dependency target %q: not a bd ID and not a well-formed external:<project>:<capability> reference", dependsOnArg)
|
||||
}
|
||||
|
||||
first, second := sourceID, target
|
||||
if types.DependencyType(depType) == types.DepBlocks {
|
||||
first, second = target, sourceID
|
||||
}
|
||||
return fmt.Errorf("invalid dependency target %q: that is `bd create --deps` <type>:<id> syntax, not a target ID; use: bd dep add %s %s --type %s",
|
||||
dependsOnArg, first, second, depType)
|
||||
}
|
||||
|
||||
// resolveUnresolvedDepTarget decides what to do when a dep add target could
|
||||
// not be resolved locally or via cross-store routing (resolveIDWithRouting's
|
||||
// error). Three outcomes, in order:
|
||||
//
|
||||
// 1. An "external:" ref is validated and passed through, as before.
|
||||
// 2. Anything else containing ":" is refused by name, by
|
||||
// refuseMalformedDepTarget — see there for the be-gmdx5 mechanism and the
|
||||
// message's direction/type rules.
|
||||
// 3. A bare, differently-prefixed target is passed through unchanged. This is
|
||||
// NOT malformed: issueops.IsExternalDepTarget defines a target "whose id
|
||||
// prefix names ANOTHER REPOSITORY" as belonging in depends_on_external
|
||||
// alongside "external:" refs, and calls that the single rule every backend
|
||||
// classifies by (db.pickDepTargetColumn restates it). It is the multi-rig
|
||||
// "add now, route later" shape — a gt- bead depending on a bd- bead whose
|
||||
// rig is not in routes.jsonl yet — and dep remove (the ExtractPrefix
|
||||
// fallback further down this file) still addresses such an edge. Refusing
|
||||
// it here would make dep add reject an edge the store holds and dep remove
|
||||
// can still delete.
|
||||
//
|
||||
// A same-prefix target that resolves nowhere is still an error, unchanged.
|
||||
func resolveUnresolvedDepTarget(sourceID, dependsOnArg string, resolveErr error) (string, error) {
|
||||
if IsExternalRef(dependsOnArg) {
|
||||
if err := validateExternalRef(dependsOnArg); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return dependsOnArg, nil
|
||||
}
|
||||
|
||||
if err := refuseMalformedDepTarget(sourceID, dependsOnArg); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
srcPrefix := types.ExtractPrefix(sourceID)
|
||||
tgtPrefix := types.ExtractPrefix(dependsOnArg)
|
||||
if srcPrefix != "" && tgtPrefix != "" && srcPrefix != tgtPrefix {
|
||||
return dependsOnArg, nil
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("resolving dependency ID %s: %v", dependsOnArg, resolveErr)
|
||||
}
|
||||
|
||||
// isChildOf returns true if childID is a hierarchical child of parentID.
|
||||
// For example, "bd-abc.1" is a child of "bd-abc", and "bd-abc.1.2" is a child of "bd-abc.1".
|
||||
func isChildOf(childID, parentID string) bool {
|
||||
|
|
@ -382,12 +488,9 @@ Examples:
|
|||
var toCleanup func()
|
||||
toID, _, toCleanup, err = resolveIDWithRouting(ctx, store, dependsOnArg)
|
||||
if err != nil {
|
||||
srcPrefix := types.ExtractPrefix(fromID)
|
||||
tgtPrefix := types.ExtractPrefix(dependsOnArg)
|
||||
if srcPrefix != "" && tgtPrefix != "" && srcPrefix != tgtPrefix {
|
||||
toID = dependsOnArg
|
||||
} else {
|
||||
return HandleErrorRespectJSON("resolving dependency ID %s: %v", dependsOnArg, err)
|
||||
toID, err = resolveUnresolvedDepTarget(fromID, dependsOnArg, err)
|
||||
if err != nil {
|
||||
return HandleErrorRespectJSON("%v", err)
|
||||
}
|
||||
} else {
|
||||
defer toCleanup()
|
||||
|
|
@ -708,12 +811,13 @@ func validateBulkDepEdges(ctx context.Context, edges []bulkDepEdge) ([]bulkDepEd
|
|||
} else {
|
||||
toID, _, toCleanup, err := resolveIDWithRouting(ctx, store, edge.DependsOnID)
|
||||
if err != nil {
|
||||
srcPrefix := types.ExtractPrefix(current.IssueID)
|
||||
tgtPrefix := types.ExtractPrefix(edge.DependsOnID)
|
||||
if srcPrefix != "" && tgtPrefix != "" && srcPrefix != tgtPrefix {
|
||||
toID = edge.DependsOnID
|
||||
} else {
|
||||
errs = append(errs, fmt.Sprintf("line %d: resolving dependency ID %s: %v", edge.Line, edge.DependsOnID, err))
|
||||
// Same decision as the single-edge add, through the same helper:
|
||||
// --file used to carry its own copy of the cross-prefix ladder,
|
||||
// which left the be-gmdx5 "type:id" shape accepted and stored
|
||||
// here after the positional path started refusing it.
|
||||
toID, err = resolveUnresolvedDepTarget(current.IssueID, edge.DependsOnID, err)
|
||||
if err != nil {
|
||||
errs = append(errs, fmt.Sprintf("line %d: %v", edge.Line, err))
|
||||
resolved = append(resolved, current)
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
377
cmd/bd/dep_add_target_test.go
Normal file
377
cmd/bd/dep_add_target_test.go
Normal file
|
|
@ -0,0 +1,377 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
storeissueops "github.com/steveyegge/beads/internal/storage/issueops"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
// resolveUnresolvedDepTarget is the decision point `bd dep add` reaches when
|
||||
// its depends-on target could not be resolved locally or via cross-store
|
||||
// routing (resolveIDWithRouting's error return). It has to separate two things
|
||||
// the old prefix-comparison heuristic conflated:
|
||||
//
|
||||
// - A "type:id"-shaped positional argument (e.g. "discovered-from:ga-dguvnb",
|
||||
// the syntax `bd create --deps` accepts via parseDepSpec) was misparsed:
|
||||
// types.ExtractPrefix takes everything up to the first "-", so it read
|
||||
// "discovered-" as a bd ID prefix instead of recognizing "discovered-from"
|
||||
// as a dependency-type keyword. The intended type was silently dropped
|
||||
// (defaulting to blocks) and the whole "type:id" string was stored as a
|
||||
// bogus external reference. That is bd-gmdx5, and it is a real bug.
|
||||
//
|
||||
// - A bare, differently-prefixed target (e.g. "xy-999" from a "be-" issue) is
|
||||
// NOT a bug. storeissueops.IsExternalDepTarget defines exactly this shape as
|
||||
// belonging in depends_on_external, and calls that the single rule every
|
||||
// backend classifies by. It is the multi-rig "add now, route later" shape,
|
||||
// and `bd dep remove` still addresses such an edge. dep add must keep
|
||||
// accepting it, or it would refuse to create an edge the store holds and
|
||||
// dep remove can still delete.
|
||||
func TestResolveUnresolvedDepTarget(t *testing.T) {
|
||||
resolveErr := errors.New("issue not found")
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
sourceID string
|
||||
dependsOnArg string
|
||||
wantToID string
|
||||
wantErr bool
|
||||
wantErrContains string
|
||||
// wantErrOmits is the direction/diagnosis guard: for the reversing
|
||||
// spelling it holds the operand order the message must NOT suggest, so a
|
||||
// refusal that merely names the target cannot pass by accident.
|
||||
wantErrOmits string
|
||||
}{
|
||||
{
|
||||
name: "bare cross-prefix target is passed through as a cross-store edge",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "xy-999",
|
||||
wantToID: "xy-999",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "type:id-shaped positional arg is rejected, not silently misparsed",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "discovered-from:ga-dguvnb",
|
||||
wantErr: true,
|
||||
wantErrContains: "discovered-from:ga-dguvnb",
|
||||
},
|
||||
{
|
||||
name: "type:id rejection names the flag form that would have worked",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "discovered-from:ga-dguvnb",
|
||||
wantErr: true,
|
||||
wantErrContains: "bd dep add be-abc ga-dguvnb --type discovered-from",
|
||||
},
|
||||
{
|
||||
// `bd create --deps blocks:B` on A stores "B depends on A":
|
||||
// parseDepSpec sets SwapDirection for the literal "blocks" spelling
|
||||
// and both consumers swap the endpoints. The equivalent dep add
|
||||
// therefore names the target first. Suggesting the natural order
|
||||
// here would hand the user a reversed bd ready/bd blocked gate.
|
||||
name: "blocks: is the reversing spelling, so the suggestion swaps the operands",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "blocks:xy-999",
|
||||
wantErr: true,
|
||||
wantErrContains: "bd dep add xy-999 be-abc --type blocks",
|
||||
wantErrOmits: "bd dep add be-abc xy-999",
|
||||
},
|
||||
{
|
||||
// The documented aliases are compared before canonicalDependencyType,
|
||||
// so they do not swap — the operand order stays natural. This is the
|
||||
// twin that stops the blocks: fix from swapping everything.
|
||||
name: "depends-on: alias keeps direction, so the suggestion keeps the operand order",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "depends-on:xy-999",
|
||||
wantErr: true,
|
||||
wantErrContains: "bd dep add be-abc xy-999 --type depends-on",
|
||||
wantErrOmits: "bd dep add xy-999 be-abc",
|
||||
},
|
||||
{
|
||||
// parseDepSpec TrimSpaces both halves, so `bd create --deps
|
||||
// "blocks : xy-999"` is accepted there. Read verbatim here the type
|
||||
// would be "blocks " — neither DepBlocks nor well-known — and the
|
||||
// paste of that same spec into dep add would lose the translation
|
||||
// and fall to the generic refusal. wantErrOmits is what pins that:
|
||||
// the message must still be the actionable one, and still swapped.
|
||||
name: "whitespace-bearing spec keeps the actionable diagnosis, matching parseDepSpec",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "blocks : xy-999",
|
||||
wantErr: true,
|
||||
wantErrContains: "bd dep add xy-999 be-abc --type blocks",
|
||||
wantErrOmits: "not a bd ID and not a well-formed external:",
|
||||
},
|
||||
{
|
||||
// The `--deps` diagnosis is a claim about the token before the ":".
|
||||
// An unrelated colon-bearing typo must not be told that cause and
|
||||
// handed a --type the next validation rejects.
|
||||
name: "colon-bearing target whose prefix is not a dependency type gets the generic refusal",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "https://example.com/x",
|
||||
wantErr: true,
|
||||
wantErrContains: "not a bd ID and not a well-formed external:",
|
||||
wantErrOmits: "--type https",
|
||||
},
|
||||
{
|
||||
name: "well-formed external ref is still accepted",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "external:otherproj:some-capability",
|
||||
wantToID: "external:otherproj:some-capability",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "malformed external-looking ref missing capability is rejected",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "external:otherproj",
|
||||
wantErr: true,
|
||||
wantErrContains: "external:otherproj",
|
||||
},
|
||||
{
|
||||
name: "same-prefix target that resolves nowhere is still an error",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "be-nosuchbead",
|
||||
wantErr: true,
|
||||
wantErrContains: "be-nosuchbead",
|
||||
},
|
||||
{
|
||||
name: "target with no prefix at all is rejected",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "nodashhere",
|
||||
wantErr: true,
|
||||
wantErrContains: "nodashhere",
|
||||
},
|
||||
{
|
||||
name: "empty target is rejected",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "",
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
toID, err := resolveUnresolvedDepTarget(tt.sourceID, tt.dependsOnArg, resolveErr)
|
||||
|
||||
if tt.wantErr {
|
||||
if err == nil {
|
||||
t.Fatalf("resolveUnresolvedDepTarget(%q, %q): got nil error, want error naming the unresolved target", tt.sourceID, tt.dependsOnArg)
|
||||
}
|
||||
if tt.wantErrContains != "" && !strings.Contains(err.Error(), tt.wantErrContains) {
|
||||
t.Errorf("resolveUnresolvedDepTarget(%q, %q): error %q does not contain %q", tt.sourceID, tt.dependsOnArg, err.Error(), tt.wantErrContains)
|
||||
}
|
||||
if tt.wantErrOmits != "" && strings.Contains(err.Error(), tt.wantErrOmits) {
|
||||
t.Errorf("resolveUnresolvedDepTarget(%q, %q): error %q must not contain %q", tt.sourceID, tt.dependsOnArg, err.Error(), tt.wantErrOmits)
|
||||
}
|
||||
if toID != "" {
|
||||
t.Errorf("resolveUnresolvedDepTarget(%q, %q): got toID %q on error, want empty", tt.sourceID, tt.dependsOnArg, toID)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("resolveUnresolvedDepTarget(%q, %q): unexpected error: %v", tt.sourceID, tt.dependsOnArg, err)
|
||||
}
|
||||
if toID != tt.wantToID {
|
||||
t.Errorf("resolveUnresolvedDepTarget(%q, %q) = %q, want %q", tt.sourceID, tt.dependsOnArg, toID, tt.wantToID)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestResolveUnresolvedDepTargetMatchesStorageClassification pins the CLI's
|
||||
// accept/refuse decision to the storage layer's own definition of an external
|
||||
// dependency target. Every target dep add passes through here must be one
|
||||
// IsExternalDepTarget classifies as external — i.e. one depends_on_external can
|
||||
// actually hold. If these two ever disagree, dep add is writing edges a backend
|
||||
// will route to the wrong column (or refusing edges it would have held fine),
|
||||
// which is the failure this whole change is about.
|
||||
func TestResolveUnresolvedDepTargetMatchesStorageClassification(t *testing.T) {
|
||||
resolveErr := errors.New("issue not found")
|
||||
|
||||
const sourceID = "be-abc"
|
||||
accepted := []string{
|
||||
"xy-999",
|
||||
"external:otherproj:some-capability",
|
||||
}
|
||||
|
||||
for _, target := range accepted {
|
||||
t.Run(target, func(t *testing.T) {
|
||||
toID, err := resolveUnresolvedDepTarget(sourceID, target, resolveErr)
|
||||
if err != nil {
|
||||
t.Fatalf("resolveUnresolvedDepTarget(%q, %q): unexpected error: %v", sourceID, target, err)
|
||||
}
|
||||
if !storeissueops.IsExternalDepTarget(sourceID, toID) {
|
||||
t.Errorf("dep add accepted %q but storage would not classify it as an external dep target; "+
|
||||
"the edge would be written to a column that cannot hold it", toID)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// newDepAddCommandForTest mirrors depAddCmd's flag set (dep.go's init) so the
|
||||
// proxied RunE helpers can be driven directly. Only the flags read before the
|
||||
// target decision matter, but registering all of them keeps the fixture honest
|
||||
// if that order ever changes.
|
||||
func newDepAddCommandForTest() *cobra.Command {
|
||||
cmd := &cobra.Command{Use: "add"}
|
||||
cmd.Flags().StringP("type", "t", "blocks", "")
|
||||
cmd.Flags().String("blocked-by", "", "")
|
||||
cmd.Flags().String("depends-on", "", "")
|
||||
cmd.Flags().String("file", "", "")
|
||||
cmd.Flags().Bool("no-cycle-check", false, "")
|
||||
return cmd
|
||||
}
|
||||
|
||||
// TestDepAddProxiedServerRefusesDepsSpecTarget pins the refusal on the proxied
|
||||
// route, where be-gmdx5 survived the original fix: usesProxiedServer() is
|
||||
// consulted before any flag handling (dep.go), this path resolves no IDs, and
|
||||
// nothing below it validates target shape — ExecuteAddDependencies classifies by
|
||||
// ExtractPrefix alone (internal/storage/issueops/dependency_editor.go). Without
|
||||
// the refusal the identical invocation that now errors in direct mode stores the
|
||||
// bogus external ref with the type dropped, so `bd dep add` would be
|
||||
// mode-dependently correct.
|
||||
//
|
||||
// The assertion is on the message, not merely on "an error came back": the
|
||||
// unguarded path also fails here (it reaches proxiedDependencyEditor with no
|
||||
// server configured), so only the refusal text distinguishes the two.
|
||||
func TestDepAddProxiedServerRefusesDepsSpecTarget(t *testing.T) {
|
||||
var err error
|
||||
stderr := captureStderr(t, func() {
|
||||
err = runDepAddProxiedServer(newDepAddCommandForTest(), context.Background(),
|
||||
[]string{"be-abc", "discovered-from:ga-dguvnb"})
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
t.Fatal("proxied dep add accepted discovered-from:ga-dguvnb; the be-gmdx5 edge would be stored with its type dropped")
|
||||
}
|
||||
if !strings.Contains(stderr, "bd dep add be-abc ga-dguvnb --type discovered-from") {
|
||||
t.Errorf("proxied refusal = %q, want the same target refusal the direct route emits", stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDepAddBulkProxiedRefusesDepsSpecTarget covers the fourth decision site.
|
||||
// The bulk format carries an explicit "type" field, so a "type:id" value in
|
||||
// "to" is precisely the malformed input — and it was accepted and stored.
|
||||
func TestDepAddBulkProxiedRefusesDepsSpecTarget(t *testing.T) {
|
||||
file := filepath.Join(t.TempDir(), "edges.jsonl")
|
||||
if err := os.WriteFile(file, []byte(`{"from":"be-abc","to":"discovered-from:ga-dguvnb"}`+"\n"), 0o600); err != nil {
|
||||
t.Fatalf("write bulk edge file: %v", err)
|
||||
}
|
||||
|
||||
var err error
|
||||
stderr := captureStderr(t, func() {
|
||||
err = runDepAddBulkProxied(newDepAddCommandForTest(), context.Background(), file, "blocks")
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
t.Fatal("proxied bulk dep add accepted discovered-from:ga-dguvnb in \"to\"")
|
||||
}
|
||||
if !strings.Contains(stderr, "line 1:") ||
|
||||
!strings.Contains(stderr, "bd dep add be-abc ga-dguvnb --type discovered-from") {
|
||||
t.Errorf("proxied bulk refusal = %q, want the per-line target refusal", stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// bulkDepStubStore resolves exactly one issue ID and nothing else, which is
|
||||
// all validateBulkDepEdges needs to reach its target decision: the source has
|
||||
// to resolve (or the line fails earlier with "resolving issue ID"), and the
|
||||
// target has to not resolve anywhere (or the decision point is skipped).
|
||||
// Four methods carry that. SearchIssues is ResolvePartialID's fast path and
|
||||
// GetIssue is resolveAndGetFromStore's follow-up; GetConfig and GetAllConfig
|
||||
// are consulted by the prefix-routing and auto-routing fallbacks the target
|
||||
// falls through on its way to failing. Nothing here opens a store, so this
|
||||
// needs no cgo build tag and no container — the same reason the proxied pins
|
||||
// above are cheap.
|
||||
type bulkDepStubStore struct {
|
||||
storage.DoltStorage
|
||||
resolvableID string
|
||||
}
|
||||
|
||||
func (s *bulkDepStubStore) SearchIssues(_ context.Context, _ string, filter types.IssueFilter) ([]*types.Issue, error) {
|
||||
for _, id := range filter.IDs {
|
||||
if id == s.resolvableID {
|
||||
return []*types.Issue{{ID: s.resolvableID}}, nil
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *bulkDepStubStore) GetIssue(_ context.Context, id string) (*types.Issue, error) {
|
||||
if id == s.resolvableID {
|
||||
return &types.Issue{ID: s.resolvableID}, nil
|
||||
}
|
||||
return nil, storage.ErrNotFound
|
||||
}
|
||||
|
||||
func (s *bulkDepStubStore) GetConfig(_ context.Context, _ string) (string, error) {
|
||||
return "be", nil
|
||||
}
|
||||
|
||||
func (s *bulkDepStubStore) GetAllConfig(_ context.Context) (map[string]string, error) {
|
||||
return map[string]string{}, nil
|
||||
}
|
||||
|
||||
// TestValidateBulkDepEdgesRefusesDepsSpecTarget is the call-site pin for the
|
||||
// direct `bd dep add --file` route — the one converted site with the worst
|
||||
// regression history, because it is where the be-gmdx5 shape survived the
|
||||
// first fix by carrying its own private copy of the prefix ladder.
|
||||
//
|
||||
// TestResolveUnresolvedDepTarget pins the decision in isolation, but that is
|
||||
// coverage by construction: it stays green if a future change re-inlines a
|
||||
// prefix comparison at the call site, or short-circuits before reaching the
|
||||
// helper at all. This asserts on the per-line text the route actually emits,
|
||||
// so the wiring itself is what goes red.
|
||||
func TestValidateBulkDepEdgesRefusesDepsSpecTarget(t *testing.T) {
|
||||
oldStore := store
|
||||
t.Cleanup(func() { store = oldStore })
|
||||
store = &bulkDepStubStore{resolvableID: "be-abc"}
|
||||
|
||||
_, err := validateBulkDepEdges(context.Background(), []bulkDepEdge{
|
||||
{Line: 1, IssueID: "be-abc", DependsOnID: "discovered-from:ga-dguvnb", Type: types.DepBlocks},
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
t.Fatal("bulk dep add --file accepted discovered-from:ga-dguvnb; the be-gmdx5 edge would be stored with its type dropped")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "line 1:") ||
|
||||
!strings.Contains(err.Error(), "bd dep add be-abc ga-dguvnb --type discovered-from") {
|
||||
t.Errorf("bulk validation error = %q, want the per-line target refusal", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// TestDepBlocksProxiedServerRefusesDepsSpecTarget covers the fifth decision
|
||||
// site. `bd dep <blocker> --blocks <blocked>` is dispatched before any dep add
|
||||
// helper runs, and `bd dep --help` documents it as "equivalent to: bd dep add
|
||||
// <blocked-id> <blocker-id>" — so leaving it unguarded kept exactly the
|
||||
// be-gmdx5 mode-dependence this change exists to remove: the direct twin
|
||||
// hard-errors on the resolve, while the proxied twin built the edge straight
|
||||
// from the raw args and stored the bogus external ref with its type forced to
|
||||
// blocks.
|
||||
//
|
||||
// The operands are inverted here relative to dep add: the blocker is the
|
||||
// target (it becomes DependsOnID) and the blocked issue is the source, which
|
||||
// is why the suggested command still reads `bd dep add <blocked> <blocker>`.
|
||||
// As with the two pins above, the assertion is on the message — the unguarded
|
||||
// path errors too, just from the missing proxied UOW provider.
|
||||
func TestDepBlocksProxiedServerRefusesDepsSpecTarget(t *testing.T) {
|
||||
var err error
|
||||
stderr := captureStderr(t, func() {
|
||||
err = runDepBlocksProxiedServer(newDepAddCommandForTest(), context.Background(),
|
||||
"discovered-from:ga-dguvnb", "be-abc")
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
t.Fatal("proxied dep --blocks accepted discovered-from:ga-dguvnb as the blocker; the be-gmdx5 edge would be stored")
|
||||
}
|
||||
if !strings.Contains(stderr, "bd dep add be-abc ga-dguvnb --type discovered-from") {
|
||||
t.Errorf("proxied --blocks refusal = %q, want the same target refusal the dep add surfaces emit", stderr)
|
||||
}
|
||||
}
|
||||
|
|
@ -160,6 +160,23 @@ func proxiedLookupTitle(ctx context.Context, uw uow.UnitOfWork, id string) strin
|
|||
}
|
||||
|
||||
func runDepBlocksProxiedServer(cmd *cobra.Command, ctx context.Context, blockerID, blockedID string) error {
|
||||
// `bd dep <blocker> --blocks <blocked>` is the fifth dep add surface: this
|
||||
// command's own help calls it "equivalent to: bd dep add <blocked-id>
|
||||
// <blocker-id>", and it lands here before any of the dep add helpers run.
|
||||
// The target endpoint is the blocker (it becomes DependsOnID below), and
|
||||
// the source is the blocked issue — the operands are inverted relative to
|
||||
// dep add, so the suggested command comes out in the order the help
|
||||
// documents. Without this the alias stays mode-dependently correct: the
|
||||
// direct twin hard-errors on resolveIDWithRouting, while this path builds
|
||||
// the edge from raw args and stores the be-gmdx5 external ref.
|
||||
if strings.HasPrefix(blockerID, "external:") {
|
||||
if err := validateExternalRef(blockerID); err != nil {
|
||||
return HandleErrorRespectJSON("%v", err)
|
||||
}
|
||||
} else if err := refuseMalformedDepTarget(blockedID, blockerID); err != nil {
|
||||
return HandleErrorRespectJSON("%v", err)
|
||||
}
|
||||
|
||||
if isDisallowedHierarchicalDependency(blockedID, blockerID, types.DepBlocks) {
|
||||
return HandleErrorRespectJSON("cannot add dependency: %s is already a child of %s. Children inherit dependency on parent completion via hierarchy. Adding an explicit dependency would create a deadlock", blockedID, blockerID)
|
||||
}
|
||||
|
|
@ -219,10 +236,15 @@ func runDepAddProxiedServer(cmd *cobra.Command, ctx context.Context, args []stri
|
|||
if err := validateExternalRef(dependsOnArg); err != nil {
|
||||
return HandleErrorRespectJSON("%v", err)
|
||||
}
|
||||
toID = dependsOnArg
|
||||
} else {
|
||||
toID = dependsOnArg
|
||||
} else if err := refuseMalformedDepTarget(fromID, dependsOnArg); err != nil {
|
||||
// This path resolves no IDs, so the colon-shape refusal is the only
|
||||
// part of the direct route's target decision it can run — and it has to
|
||||
// run it, or the same `bd dep add` invocation is refused in direct mode
|
||||
// and silently stores the be-gmdx5 bogus external ref here (nothing in
|
||||
// ExecuteAddDependencies validates target shape).
|
||||
return HandleErrorRespectJSON("%v", err)
|
||||
}
|
||||
toID = dependsOnArg
|
||||
|
||||
dt := canonicalDependencyType(types.DependencyType(depType))
|
||||
if isDisallowedHierarchicalDependency(fromID, toID, dt) {
|
||||
|
|
@ -284,6 +306,8 @@ func runDepAddBulkProxied(cmd *cobra.Command, ctx context.Context, file, default
|
|||
if err := validateExternalRef(edge.DependsOnID); err != nil {
|
||||
return HandleErrorRespectJSON("line %d: %v", edge.Line, err)
|
||||
}
|
||||
} else if err := refuseMalformedDepTarget(edge.IssueID, edge.DependsOnID); err != nil {
|
||||
return HandleErrorRespectJSON("line %d: %v", edge.Line, err)
|
||||
}
|
||||
depEdges = append(depEdges, issueops.DependencyEdge{
|
||||
IssueID: edge.IssueID,
|
||||
|
|
|
|||
|
|
@ -66,6 +66,135 @@ func TestResolveChangeDirBeadsDirRejectsDirectoryWithoutProject(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
const primeTestMetadata = `{"backend":"dolt"}`
|
||||
|
||||
// primeTestWorkspace creates a workspace root (symlinks resolved, so paths
|
||||
// compare equal to what -C resolution yields) holding an empty .beads/ plus
|
||||
// the given files, keyed by path relative to the root.
|
||||
func primeTestWorkspace(t *testing.T, files map[string]string) string {
|
||||
t.Helper()
|
||||
dir := t.TempDir()
|
||||
if resolved, err := filepath.EvalSymlinks(dir); err == nil {
|
||||
dir = resolved
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Join(dir, ".beads"), 0o755); err != nil {
|
||||
t.Fatalf("mkdir .beads: %v", err)
|
||||
}
|
||||
for rel, content := range files {
|
||||
path := filepath.Join(dir, rel)
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||
t.Fatalf("mkdir %s: %v", filepath.Dir(path), err)
|
||||
}
|
||||
if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
|
||||
t.Fatalf("write %s: %v", path, err)
|
||||
}
|
||||
}
|
||||
return dir
|
||||
}
|
||||
|
||||
func TestPrimeWorkspaceDir(t *testing.T) {
|
||||
t.Cleanup(func() {
|
||||
changeDir = ""
|
||||
})
|
||||
parent := primeTestWorkspace(t, map[string]string{"target/.beads/metadata.json": primeTestMetadata})
|
||||
target := filepath.Join(parent, "target")
|
||||
t.Chdir(parent)
|
||||
|
||||
for _, tc := range []struct{ changeDir, want string }{
|
||||
{"", ""}, // no -C: workspace-relative reads stay on the cwd
|
||||
{" ", ""}, // blank -C is treated as unset, as applyChangeDirSelection does
|
||||
{target, target}, // absolute -C
|
||||
{"target", target}, // relative -C, like `bd -C target prime`
|
||||
} {
|
||||
changeDir = tc.changeDir
|
||||
if got := primeWorkspaceDir(); got != tc.want {
|
||||
t.Errorf("changeDir=%q: primeWorkspaceDir() = %q, want %q", tc.changeDir, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadCustomPrimeContent_ChangeDirPrefersTarget(t *testing.T) {
|
||||
const cwdPrime = "# CWD local PRIME\ncwd-local-custom\n"
|
||||
const targetPrime = "# Target workspace PRIME\ntarget-workspace-custom\n"
|
||||
cwd := primeTestWorkspace(t, map[string]string{".beads/PRIME.md": cwdPrime})
|
||||
target := primeTestWorkspace(t, map[string]string{".beads/PRIME.md": targetPrime})
|
||||
t.Chdir(cwd)
|
||||
|
||||
// bd -C target prime: the workspace is the -C target, so its clone-local
|
||||
// PRIME.md wins over the cwd's.
|
||||
got, ok := readCustomPrimeContent(target, filepath.Join(target, ".beads"))
|
||||
if !ok {
|
||||
t.Fatal("expected a custom PRIME.md, got none")
|
||||
}
|
||||
if got != targetPrime {
|
||||
t.Fatalf("with -C target, readCustomPrimeContent = %q, want target %q", got, targetPrime)
|
||||
}
|
||||
}
|
||||
|
||||
// Without -C the workspace is the cwd even when BEADS_DIR points elsewhere: the
|
||||
// cwd's clone-local PRIME.md keeps winning (GH#876), and the redirected
|
||||
// workspace's file is only the second tier.
|
||||
func TestReadCustomPrimeContent_EnvRedirectStillLocalFirst(t *testing.T) {
|
||||
const cwdPrime = "# CWD local PRIME\nenv-redirect-local-wins\n"
|
||||
const redirectedPrime = "# Redirected workspace PRIME\nenv-redirect-shared\n"
|
||||
cwd := primeTestWorkspace(t, map[string]string{".beads/PRIME.md": cwdPrime})
|
||||
redirected := primeTestWorkspace(t, map[string]string{".beads/PRIME.md": redirectedPrime})
|
||||
t.Chdir(cwd)
|
||||
|
||||
got, ok := readCustomPrimeContent("", filepath.Join(redirected, ".beads"))
|
||||
if !ok {
|
||||
t.Fatal("expected a custom PRIME.md, got none")
|
||||
}
|
||||
if got != cwdPrime {
|
||||
t.Fatalf("env-only redirect must keep local-first: got %q, want local %q", got, cwdPrime)
|
||||
}
|
||||
}
|
||||
|
||||
// -C target is a redirect clone (.beads/redirect -> external store) that also
|
||||
// carries its own clone-local .beads/PRIME.md. `cd target && bd prime` reads the
|
||||
// clone-local file ahead of the shared one; `bd -C target prime` must match it,
|
||||
// not fall through to the external store's PRIME.md and not read the cwd's.
|
||||
func TestReadCustomPrimeContent_ChangeDirRedirectClonePrefersCloneLocal(t *testing.T) {
|
||||
const cwdPrime = "# CWD-LOCAL\n"
|
||||
const clonePrime = "# TARGET-CLONE-LOCAL\n"
|
||||
const sharedPrime = "# EXTERNAL-SHARED\n"
|
||||
cwd := primeTestWorkspace(t, map[string]string{".beads/PRIME.md": cwdPrime})
|
||||
external := primeTestWorkspace(t, map[string]string{
|
||||
".beads/metadata.json": primeTestMetadata,
|
||||
".beads/PRIME.md": sharedPrime,
|
||||
})
|
||||
externalBeads := filepath.Join(external, ".beads")
|
||||
target := primeTestWorkspace(t, map[string]string{
|
||||
".beads/redirect": externalBeads + "\n",
|
||||
".beads/PRIME.md": clonePrime,
|
||||
})
|
||||
|
||||
resolvedBeads, err := resolveChangeDirBeadsDir(target)
|
||||
if err != nil {
|
||||
t.Fatalf("resolveChangeDirBeadsDir: %v", err)
|
||||
}
|
||||
if filepath.Clean(resolvedBeads) != filepath.Clean(externalBeads) {
|
||||
t.Fatalf("resolved beads = %q, want external %q", resolvedBeads, externalBeads)
|
||||
}
|
||||
|
||||
// Reference: cd target && bd prime.
|
||||
t.Chdir(target)
|
||||
want, ok := readCustomPrimeContent("", resolvedBeads)
|
||||
if !ok || want != clonePrime {
|
||||
t.Fatalf("reference (cd target): got %q, %v; want clone-local %q", want, ok, clonePrime)
|
||||
}
|
||||
|
||||
// Under test: bd -C target prime from an unrelated cwd with its own PRIME.md.
|
||||
t.Chdir(cwd)
|
||||
got, ok := readCustomPrimeContent(target, resolvedBeads)
|
||||
if !ok {
|
||||
t.Fatal("expected a custom PRIME.md, got none")
|
||||
}
|
||||
if got != want {
|
||||
t.Fatalf("bd -C target must match cd target: got %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsPreviewCommand(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
|
|||
183
cmd/bd/doctor/BUILD.bazel
Normal file
183
cmd/bd/doctor/BUILD.bazel
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
load("@rules_go//go:def.bzl", "go_library", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "doctor",
|
||||
srcs = [
|
||||
"agent.go",
|
||||
"artifacts.go",
|
||||
"backend.go",
|
||||
"blocked.go",
|
||||
"circuit.go",
|
||||
"claude.go",
|
||||
"clone_local_fks.go",
|
||||
"config_values.go",
|
||||
"cross_table.go",
|
||||
"cursor.go",
|
||||
"database.go",
|
||||
"deep.go",
|
||||
"dep_keys.go",
|
||||
"dependency_sql.go",
|
||||
"dolt.go",
|
||||
"federation.go",
|
||||
"fresh_clone_server.go",
|
||||
"git.go",
|
||||
"gitignore.go",
|
||||
"hooks_migration.go",
|
||||
"installation.go",
|
||||
"integrity.go",
|
||||
"kv.go",
|
||||
"label_whitespace.go",
|
||||
"legacy.go",
|
||||
"locks.go",
|
||||
"maintenance.go",
|
||||
"managed_handoff.go",
|
||||
"migration.go",
|
||||
"migration_skew.go",
|
||||
"migration_validation.go",
|
||||
"multirepo.go",
|
||||
"nocow.go",
|
||||
"nocow_linux.go",
|
||||
"nocow_other.go",
|
||||
"perf.go",
|
||||
"perf_dolt.go",
|
||||
"quick.go",
|
||||
"remotes.go",
|
||||
"role.go",
|
||||
"server.go",
|
||||
"shared_store.go",
|
||||
"suppress.go",
|
||||
"tracked_runtime.go",
|
||||
"types.go",
|
||||
"validation.go",
|
||||
"version.go",
|
||||
],
|
||||
importpath = "github.com/steveyegge/beads/cmd/bd/doctor",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//cmd/bd/doctor/fix",
|
||||
"//cmd/bd/setup",
|
||||
"//internal/beads",
|
||||
"//internal/config",
|
||||
"//internal/configfile",
|
||||
"//internal/doltremote",
|
||||
"//internal/doltserver",
|
||||
"//internal/git",
|
||||
"//internal/gitenv",
|
||||
"//internal/gitignore",
|
||||
"//internal/storage",
|
||||
"//internal/storage/dberrors",
|
||||
"//internal/storage/dolt",
|
||||
"//internal/storage/doltutil",
|
||||
"//internal/storage/embeddeddolt",
|
||||
"//internal/storage/issueops",
|
||||
"//internal/storage/kvkeys",
|
||||
"//internal/storage/schema",
|
||||
"//internal/types",
|
||||
"//internal/utils",
|
||||
"@com_github_go_sql_driver_mysql//:mysql",
|
||||
"@com_github_spf13_viper//:viper",
|
||||
"@in_gopkg_yaml_v3//:yaml_v3",
|
||||
] + select({
|
||||
"@rules_go//go/platform:android": [
|
||||
"@org_golang_x_sys//unix",
|
||||
],
|
||||
"@rules_go//go/platform:linux": [
|
||||
"@org_golang_x_sys//unix",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "doctor_test",
|
||||
srcs = [
|
||||
"agent_test.go",
|
||||
"artifacts_test.go",
|
||||
"bare_parent_fallback_test.go",
|
||||
"claude_test.go",
|
||||
"config_values_test.go",
|
||||
"cursor_test.go",
|
||||
"database_test.go",
|
||||
"deep_test.go",
|
||||
"dependency_sql_test.go",
|
||||
"doctor_worktree_test.go",
|
||||
"dolt_e2e_test.go",
|
||||
"dolt_phantom_test.go",
|
||||
"dolt_test.go",
|
||||
"federation_test.go",
|
||||
"fresh_clone_server_test.go",
|
||||
"git_hygiene_test.go",
|
||||
"git_repo_template_test.go",
|
||||
"git_test.go",
|
||||
"git_test_helpers_test.go",
|
||||
"gitignore_test.go",
|
||||
"hooks_migration_test.go",
|
||||
"hooks_path_test.go",
|
||||
"installation_test.go",
|
||||
"integrity_cycles_db_test.go",
|
||||
"integrity_cycles_mock_test.go",
|
||||
"integrity_cycles_test.go",
|
||||
"integrity_path_cgo_test.go",
|
||||
"integrity_test.go",
|
||||
"legacy_test.go",
|
||||
"locks_test.go",
|
||||
"maintenance_cgo_test.go",
|
||||
"maintenance_test.go",
|
||||
"managed_handoff_test.go",
|
||||
"migration_hooks_test.go",
|
||||
"migration_skew_dolt_test.go",
|
||||
"migration_skew_embedded_test.go",
|
||||
"migration_skew_test.go",
|
||||
"migration_test.go",
|
||||
"migration_validation_test.go",
|
||||
"multirepo_test.go",
|
||||
"nocow_test.go",
|
||||
"perf_dolt_test.go",
|
||||
"quick_test.go",
|
||||
"role_test.go",
|
||||
"server_backend_test.go",
|
||||
"server_test.go",
|
||||
"shared_store_test.go",
|
||||
"suite_temp_test.go",
|
||||
"suppress_test.go",
|
||||
"test_helpers_test.go",
|
||||
"testmain_nocgo_test.go",
|
||||
"tracked_runtime_test.go",
|
||||
"types_test.go",
|
||||
"validation_test.go",
|
||||
"version_test.go",
|
||||
],
|
||||
data = ["//cmd/bd:bd_for_tests"],
|
||||
embed = [":doctor"],
|
||||
env = {"BEADS_TEST_BD_BINARY": "$(rlocationpath //cmd/bd:bd_for_tests)"},
|
||||
deps = [
|
||||
"//internal/beads",
|
||||
"//internal/configfile",
|
||||
"//internal/doltserver",
|
||||
"//internal/git",
|
||||
"//internal/gitenv",
|
||||
"//internal/storage/dolt",
|
||||
"//internal/storage/doltutil",
|
||||
"//internal/storage/embeddeddolt",
|
||||
"//internal/storage/issueops",
|
||||
"//internal/testutil",
|
||||
"//internal/testutil/bazeltest",
|
||||
"//internal/types",
|
||||
"//internal/utils",
|
||||
"@com_github_data_dog_go_sqlmock//:go-sqlmock",
|
||||
"@com_github_go_sql_driver_mysql//:mysql",
|
||||
],
|
||||
)
|
||||
|
||||
# --- begin go_srcs (managed by tools/bazel/go_srcs.py; run `make bazel-sync`) ---
|
||||
|
||||
filegroup(
|
||||
name = "go_srcs",
|
||||
srcs = glob(
|
||||
["**/*.go"],
|
||||
allow_empty = True,
|
||||
),
|
||||
visibility = ["//:__subpackages__"],
|
||||
)
|
||||
|
||||
# --- end go_srcs ---
|
||||
|
|
@ -38,6 +38,26 @@ func resolveBeadsDirForRepoUncached(repoPath string) string {
|
|||
return beads.ResolveBeadsDirForRepo(repoPath)
|
||||
}
|
||||
|
||||
// BeadsManagedStorageHooksDir returns the hooks directory that
|
||||
// `bd hooks install --beads` writes to core.hooksPath — <effective .beads>/hooks
|
||||
// — or "" when no beads storage resolves.
|
||||
//
|
||||
// install resolves that directory with beads.FindBeadsDir, which honors
|
||||
// BEADS_DIR and .beads/redirect and can therefore land outside the repository.
|
||||
// Uninstall and `bd doctor --fix` must resolve it exactly the same way: a value
|
||||
// they cannot recognize is a value they cannot clear, which leaves
|
||||
// core.hooksPath pointing at a hooks directory whose files uninstall just
|
||||
// deleted (every hook silently disabled, beads-managed config still installed —
|
||||
// the GH#4440 contract). Deliberately not ResolveBeadsDirForRepo, which is
|
||||
// repo-anchored and blind to BEADS_DIR.
|
||||
func BeadsManagedStorageHooksDir() string {
|
||||
beadsDir := beads.FindBeadsDir()
|
||||
if beadsDir == "" {
|
||||
return ""
|
||||
}
|
||||
return filepath.Join(beadsDir, "hooks")
|
||||
}
|
||||
|
||||
func resolvedBeadsRepoRoot(repoPath string) string {
|
||||
return filepath.Dir(ResolveBeadsDirForRepo(repoPath))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,11 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/gitenv"
|
||||
"github.com/steveyegge/beads/internal/utils"
|
||||
)
|
||||
|
||||
|
|
@ -155,3 +157,66 @@ func runGitInDirForDoctorTest(t *testing.T, dir string, args ...string) string {
|
|||
|
||||
return strings.TrimSpace(string(output))
|
||||
}
|
||||
|
||||
func TestDoctorWorktreeFallbackIgnoresInheritedRouting(t *testing.T) {
|
||||
clearResolveBeadsDirCache()
|
||||
t.Cleanup(clearResolveBeadsDirCache)
|
||||
for _, entry := range os.Environ() {
|
||||
key := gitenv.EntryKey(entry)
|
||||
if gitenv.IsRoutingKeyForOS(key, runtime.GOOS) {
|
||||
t.Setenv(key, "")
|
||||
if err := os.Unsetenv(key); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, key := range []string{"HOME", "USERPROFILE", "XDG_CONFIG_HOME"} {
|
||||
t.Setenv(key, t.TempDir())
|
||||
}
|
||||
// Production ScrubRouting retains this explicit system-config suppression.
|
||||
t.Setenv("GIT_CONFIG_NOSYSTEM", "1")
|
||||
targetParent, target := setupBareParentWorktreeForDoctorTest(t)
|
||||
decoyParent, decoy := setupBareParentWorktreeForDoctorTest(t)
|
||||
want := utils.CanonicalizePath(filepath.Join(targetParent, ".beads"))
|
||||
for _, dir := range []string{want, filepath.Join(decoyParent, ".beads")} {
|
||||
if err := os.MkdirAll(dir, 0o750); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(target, ".beads")); !os.IsNotExist(err) {
|
||||
t.Fatalf("fixture must require common-parent fallback: %v", err)
|
||||
}
|
||||
decoyGitDir := runGitInDirForDoctorTest(t, decoy, "rev-parse", "--absolute-git-dir")
|
||||
for _, name := range []string{"decoy", "invalid_git_dir"} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
gitDir := decoyGitDir
|
||||
if name == "invalid_git_dir" {
|
||||
gitDir = filepath.Join(t.TempDir(), "missing.git")
|
||||
}
|
||||
t.Setenv("GIT_DIR", gitDir)
|
||||
t.Setenv("GIT_WORK_TREE", decoy)
|
||||
t.Setenv("GIT_COMMON_DIR", decoyParent)
|
||||
before := strings.Join(os.Environ(), "\x00")
|
||||
clearResolveBeadsDirCache()
|
||||
if got := ResolveBeadsDirForRepo(target); !utils.PathsEqual(got, want) {
|
||||
t.Errorf("cold ResolveBeadsDirForRepo() = %q, want target %q", got, want)
|
||||
}
|
||||
clearResolveBeadsDirCache() // Exercise the constructor's own cold resolution.
|
||||
ss := NewSharedStore(target)
|
||||
defer ss.Close()
|
||||
if got := ss.BeadsDir(); !utils.PathsEqual(got, want) {
|
||||
t.Errorf("cold NewSharedStore().BeadsDir() = %q, want target %q", got, want)
|
||||
}
|
||||
// Empty .beads proves path selection only, not a database or role read.
|
||||
if ss.Store() != nil {
|
||||
t.Error("empty fixture unexpectedly opened a database")
|
||||
}
|
||||
if entries, err := os.ReadDir(want); err != nil || len(entries) != 0 {
|
||||
t.Errorf("empty target .beads changed: entries=%v, err=%v", entries, err)
|
||||
}
|
||||
if strings.Join(os.Environ(), "\x00") != before {
|
||||
t.Error("doctor changed inherited environment")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import (
|
|||
"github.com/steveyegge/beads/internal/doltserver"
|
||||
"github.com/steveyegge/beads/internal/storage/dolt"
|
||||
"github.com/steveyegge/beads/internal/testutil"
|
||||
"github.com/steveyegge/beads/internal/testutil/bazeltest"
|
||||
)
|
||||
|
||||
// e2eDoctorResult mirrors the JSON output struct from cmd/bd/doctor.go.
|
||||
|
|
@ -88,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()
|
||||
|
|
@ -169,6 +172,12 @@ func buildTestBD(t *testing.T) string {
|
|||
t.Helper()
|
||||
|
||||
testBDOnce.Do(func() {
|
||||
// Under Bazel the binary is injected (//cmd/bd:bd_for_tests); there is
|
||||
// no toolchain or module tree to build from. Plain go test is unchanged.
|
||||
if bazeltest.IsBazel() {
|
||||
testBDPath, testBDErr = bazeltest.PrebuiltBD()
|
||||
return
|
||||
}
|
||||
bdBinary := "bd-test"
|
||||
if runtime.GOOS == "windows" {
|
||||
bdBinary = "bd-test.exe"
|
||||
|
|
@ -210,6 +219,9 @@ func buildTestBD(t *testing.T) string {
|
|||
}
|
||||
})
|
||||
|
||||
if testBDErr != nil && bazeltest.IsBazel() {
|
||||
t.Fatalf("bd binary for tests: %v", testBDErr) // a wiring bug, never a skip
|
||||
}
|
||||
if testBDErr != nil {
|
||||
t.Skipf("skipping E2E test: failed to build bd binary: %v", testBDErr)
|
||||
}
|
||||
|
|
|
|||
169
cmd/bd/doctor/fix/BUILD.bazel
Normal file
169
cmd/bd/doctor/fix/BUILD.bazel
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
load("@rules_go//go:def.bzl", "go_library", "go_test")
|
||||
load("@rules_shell//shell:sh_test.bzl", "sh_test")
|
||||
|
||||
go_library(
|
||||
name = "fix",
|
||||
srcs = [
|
||||
"artifacts.go",
|
||||
"blocked.go",
|
||||
"clone_local_fks.go",
|
||||
"common.go",
|
||||
"config_values.go",
|
||||
"database_config.go",
|
||||
"database_integrity.go",
|
||||
"dep_keys.go",
|
||||
"dependency_sql.go",
|
||||
"dolt_format.go",
|
||||
"fs.go",
|
||||
"hooks.go",
|
||||
"label_whitespace.go",
|
||||
"locks.go",
|
||||
"maintenance.go",
|
||||
"metadata.go",
|
||||
"metadata_json.go",
|
||||
"migrate.go",
|
||||
"permissions.go",
|
||||
"remotes.go",
|
||||
"repo_fingerprint.go",
|
||||
"store.go",
|
||||
"untracked.go",
|
||||
"validation.go",
|
||||
],
|
||||
importpath = "github.com/steveyegge/beads/cmd/bd/doctor/fix",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//internal/beads",
|
||||
"//internal/configfile",
|
||||
"//internal/doltserver",
|
||||
"//internal/eventsjournal",
|
||||
"//internal/storage",
|
||||
"//internal/storage/depid",
|
||||
"//internal/storage/dolt",
|
||||
"//internal/storage/doltutil",
|
||||
"//internal/storage/issueops",
|
||||
"//internal/types",
|
||||
"//internal/utils",
|
||||
"@com_github_burntsushi_toml//:toml",
|
||||
"@com_github_go_sql_driver_mysql//:mysql",
|
||||
"@in_gopkg_yaml_v3//:yaml_v3",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "fix_test",
|
||||
srcs = [
|
||||
"artifacts_test.go",
|
||||
"clone_local_fks_cgo_test.go",
|
||||
"common_test.go",
|
||||
"database_config_test.go",
|
||||
"database_integrity_test.go",
|
||||
"dep_keys_test.go",
|
||||
"dependency_sql_test.go",
|
||||
"e2e_test.go",
|
||||
"fix_edge_cases_test.go",
|
||||
"fix_test.go",
|
||||
"fs_test.go",
|
||||
"git_repo_template_test.go",
|
||||
"hooks_test.go",
|
||||
"journal_cgo_test.go",
|
||||
"label_whitespace_test.go",
|
||||
"locks_test.go",
|
||||
"maintenance_cgo_test.go",
|
||||
"maintenance_test.go",
|
||||
"metadata_dolt_test.go",
|
||||
"metadata_probe_test.go",
|
||||
"metadata_test.go",
|
||||
"migrate_import_test.go",
|
||||
"remotes_test.go",
|
||||
"repo_fingerprint_test.go",
|
||||
"suite_temp_test.go",
|
||||
"symlink_test.go",
|
||||
"testmain_cgo_test.go",
|
||||
"testmain_nocgo_test.go",
|
||||
"validation_test.go",
|
||||
],
|
||||
embed = [":fix"],
|
||||
deps = [
|
||||
"//internal/configfile",
|
||||
"//internal/doltserver",
|
||||
"//internal/storage/depid",
|
||||
"//internal/storage/dolt",
|
||||
"//internal/storage/doltutil",
|
||||
"//internal/storage/issueops",
|
||||
"//internal/testutil",
|
||||
"//internal/types",
|
||||
"@com_github_data_dog_go_sqlmock//:go-sqlmock",
|
||||
"@com_github_go_sql_driver_mysql//:mysql",
|
||||
],
|
||||
)
|
||||
|
||||
# The Dolt-backed half of fix_test, as pr.yml's "Test doctor/fix (Dolt-backed,
|
||||
# hard-require container)" job runs it: TestMain starts a dolt sql-server
|
||||
# container through testcontainers, and BEADS_FIX_REQUIRE_DOLT=1 turns a
|
||||
# missing container into a failure instead of a silent skip. fix_test itself
|
||||
# stays untagged: under --config=prcore (BEADS_TEST_SKIP=dolt, like pr-core's
|
||||
# `go test`) it never touches docker and runs anywhere.
|
||||
#
|
||||
# Tags:
|
||||
# requires-docker: needs a docker daemon; excluded from --config=prcore/ci,
|
||||
# selected by --config=docker.
|
||||
# no-remote-exec: the daemon is on the host, not on remote workers.
|
||||
sh_test(
|
||||
name = "fix_docker_test",
|
||||
size = "large",
|
||||
srcs = ["//tools/bazel:go_test_variant.sh"],
|
||||
args = ["$(rootpath :fix_test)"],
|
||||
data = [":fix_test"],
|
||||
# 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(
|
||||
name = "go_srcs",
|
||||
srcs = glob(
|
||||
["**/*.go"],
|
||||
allow_empty = True,
|
||||
),
|
||||
visibility = ["//:__subpackages__"],
|
||||
)
|
||||
|
||||
# --- end go_srcs ---
|
||||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/beads"
|
||||
)
|
||||
|
|
@ -38,9 +39,8 @@ func getBdBinary() (string, error) {
|
|||
}
|
||||
|
||||
// Check if we're running as a test binary - this prevents fork bombs
|
||||
// when tests call functions that execute bd subcommands
|
||||
baseName := filepath.Base(exe)
|
||||
if strings.HasSuffix(baseName, ".test") || strings.Contains(baseName, ".test.") {
|
||||
// when tests call functions that execute bd subcommands.
|
||||
if isTestBinary(exe) {
|
||||
return "", ErrTestBinary
|
||||
}
|
||||
|
||||
|
|
@ -56,6 +56,18 @@ func getBdBinary() (string, error) {
|
|||
return bdPath, nil
|
||||
}
|
||||
|
||||
// isTestBinary reports whether exe is a Go test binary. testing.Testing() is
|
||||
// the authoritative signal: both `go test` and rules_go link test binaries with
|
||||
// it set, whatever the file is called (Bazel names them <target>_test, not
|
||||
// <pkg>.test). The name check is kept for binaries built by other means.
|
||||
func isTestBinary(exe string) bool {
|
||||
if testing.Testing() {
|
||||
return true
|
||||
}
|
||||
baseName := filepath.Base(exe)
|
||||
return strings.HasSuffix(baseName, ".test") || strings.Contains(baseName, ".test.")
|
||||
}
|
||||
|
||||
// validateBeadsWorkspace ensures the path is a valid beads workspace before
|
||||
// attempting any fix operations. This prevents path traversal attacks.
|
||||
func validateBeadsWorkspace(path string) error {
|
||||
|
|
|
|||
|
|
@ -103,6 +103,21 @@ func TestGetBdBinary_Errors(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
// TestGetBdBinary_DetectsTestBinaryByAnyName guards against a fork bomb: a test
|
||||
// binary must never be returned as "bd", whatever it is named. Bazel names
|
||||
// test binaries <target>_test (no ".test" suffix); before the guard used
|
||||
// testing.Testing(), each fix test re-ran the whole suite recursively there.
|
||||
func TestGetBdBinary_DetectsTestBinaryByAnyName(t *testing.T) {
|
||||
if _, err := getBdBinary(); !errors.Is(err, ErrTestBinary) {
|
||||
t.Fatalf("getBdBinary() in a test binary: got err %v, want ErrTestBinary", err)
|
||||
}
|
||||
for _, name := range []string{"/x/fix.test", "/x/fix_test", "/x/bd"} {
|
||||
if !isTestBinary(name) {
|
||||
t.Errorf("isTestBinary(%q) = false inside a test binary", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestFilePermissionErrors tests handling of file permission issues
|
||||
func TestFilePermissionErrors(t *testing.T) {
|
||||
if os.Getuid() == 0 {
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue