Compare commits
59 commits
main
...
hotfix/1.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
53637a74ad |
||
|
|
3d470c4a1b | ||
|
|
ce766f2a60 |
||
|
|
382cf6a7ef |
||
|
|
1d71e70fe4 | ||
|
|
65b406fe56 | ||
|
|
e29f0509c1 | ||
|
|
bb18223fbd | ||
|
|
3fdced064c |
||
|
|
a5f0707347 |
||
|
|
af9d553565 | ||
|
|
711d238b96 | ||
|
|
d9a09105bc | ||
|
|
adf91f2dc0 |
||
|
|
09e6397f1e | ||
|
|
97bfa4c149 | ||
|
|
35fea9b049 | ||
|
|
d1840c043f | ||
|
|
c1c4b642ac |
||
|
|
498742a275 | ||
|
|
696e3967be |
||
|
|
f83654b118 | ||
|
|
655dc0827d |
||
|
|
4b49bf2e80 | ||
|
|
0cba03281c |
||
|
|
b4d81fdf5b | ||
|
|
b2faf48e84 | ||
|
|
e25e5a71d3 | ||
|
|
a8e5ccfc10 | ||
|
|
66c6a0c9b3 | ||
|
|
84e6faaa2d | ||
|
|
dac1e6e91f |
||
|
|
70867888ff | ||
|
|
d15081d60e | ||
|
|
48be70fb7e | ||
|
|
4d512abbc2 | ||
|
|
98d9675f5e | ||
|
|
cf08d4e3f9 | ||
|
|
26467a8d02 | ||
|
|
0144dbe76b | ||
|
|
c296fc9205 | ||
|
|
d79ef48048 | ||
|
|
e352b96d60 | ||
|
|
f5a9402790 |
||
|
|
2b27259cb4 | ||
|
|
7c2568c323 | ||
|
|
74dc7154c2 | ||
|
|
ca37d8f9fc | ||
|
|
eac2597557 | ||
|
|
aa3c43b6bd |
||
|
|
bb03a310a9 |
||
|
|
1e754a0156 |
||
|
|
e1e1158dd9 |
||
|
|
d0063ac894 |
||
|
|
d487b9796e |
||
|
|
fa95439006 |
||
|
|
76860ebdfb |
||
|
|
87c7375d5f |
||
|
|
f62cc4f072 |
263 changed files with 21299 additions and 1460 deletions
|
|
@ -9,7 +9,7 @@
|
|||
"name": "beads",
|
||||
"source": "./plugins/beads",
|
||||
"description": "AI-supervised issue tracker for coding workflows",
|
||||
"version": "1.3.0"
|
||||
"version": "1.3.2-rc.2"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env sh
|
||||
# --- BEGIN BEADS INTEGRATION v1.3.0 ---
|
||||
# --- BEGIN BEADS INTEGRATION v1.3.2-rc.2 ---
|
||||
# This section is managed by beads. Do not remove these markers.
|
||||
if command -v bd >/dev/null 2>&1; then
|
||||
export BD_GIT_HOOK=1
|
||||
|
|
@ -56,4 +56,4 @@ if command -v bd >/dev/null 2>&1; then
|
|||
fi
|
||||
if [ "$_bd_exit" -ne 0 ]; then exit "$_bd_exit"; fi
|
||||
fi
|
||||
# --- END BEADS INTEGRATION v1.3.0 ---
|
||||
# --- END BEADS INTEGRATION v1.3.2-rc.2 ---
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env sh
|
||||
# --- BEGIN BEADS INTEGRATION v1.3.0 ---
|
||||
# --- BEGIN BEADS INTEGRATION v1.3.2-rc.2 ---
|
||||
# This section is managed by beads. Do not remove these markers.
|
||||
if command -v bd >/dev/null 2>&1; then
|
||||
export BD_GIT_HOOK=1
|
||||
|
|
@ -56,4 +56,4 @@ if command -v bd >/dev/null 2>&1; then
|
|||
fi
|
||||
if [ "$_bd_exit" -ne 0 ]; then exit "$_bd_exit"; fi
|
||||
fi
|
||||
# --- END BEADS INTEGRATION v1.3.0 ---
|
||||
# --- END BEADS INTEGRATION v1.3.2-rc.2 ---
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ if [ -n "$staged_go_files" ]; then
|
|||
echo "$staged_go_files" | xargs git add
|
||||
fi
|
||||
|
||||
# --- BEGIN BEADS INTEGRATION v1.3.0 ---
|
||||
# --- BEGIN BEADS INTEGRATION v1.3.2-rc.2 ---
|
||||
# This section is managed by beads. Do not remove these markers.
|
||||
if command -v bd >/dev/null 2>&1; then
|
||||
export BD_GIT_HOOK=1
|
||||
|
|
@ -97,4 +97,4 @@ if command -v bd >/dev/null 2>&1; then
|
|||
fi
|
||||
if [ "$_bd_exit" -ne 0 ]; then exit "$_bd_exit"; fi
|
||||
fi
|
||||
# --- END BEADS INTEGRATION v1.3.0 ---
|
||||
# --- END BEADS INTEGRATION v1.3.2-rc.2 ---
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ fi
|
|||
|
||||
exec < <(printf '%s\n' "$push_refs")
|
||||
|
||||
# --- BEGIN BEADS INTEGRATION v1.3.0 ---
|
||||
# --- BEGIN BEADS INTEGRATION v1.3.2-rc.2 ---
|
||||
# This section is managed by beads. Do not remove these markers.
|
||||
if command -v bd >/dev/null 2>&1; then
|
||||
export BD_GIT_HOOK=1
|
||||
|
|
@ -96,4 +96,4 @@ if command -v bd >/dev/null 2>&1; then
|
|||
fi
|
||||
if [ "$_bd_exit" -ne 0 ]; then exit "$_bd_exit"; fi
|
||||
fi
|
||||
# --- END BEADS INTEGRATION v1.3.0 ---
|
||||
# --- END BEADS INTEGRATION v1.3.2-rc.2 ---
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env sh
|
||||
# --- BEGIN BEADS INTEGRATION v1.3.0 ---
|
||||
# --- BEGIN BEADS INTEGRATION v1.3.2-rc.2 ---
|
||||
# This section is managed by beads. Do not remove these markers.
|
||||
if command -v bd >/dev/null 2>&1; then
|
||||
export BD_GIT_HOOK=1
|
||||
|
|
@ -56,4 +56,4 @@ if command -v bd >/dev/null 2>&1; then
|
|||
fi
|
||||
if [ "$_bd_exit" -ne 0 ]; then exit "$_bd_exit"; fi
|
||||
fi
|
||||
# --- END BEADS INTEGRATION v1.3.0 ---
|
||||
# --- END BEADS INTEGRATION v1.3.2-rc.2 ---
|
||||
|
|
|
|||
2
.github/workflows/conformance.yml
vendored
2
.github/workflows/conformance.yml
vendored
|
|
@ -5,7 +5,7 @@ name: Conformance
|
|||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [ main, 'release/**' ]
|
||||
branches: [ main, 'release/**', 'hotfix/**' ]
|
||||
merge_group:
|
||||
|
||||
concurrency:
|
||||
|
|
|
|||
2
.github/workflows/cross-version-smoke.yml
vendored
2
.github/workflows/cross-version-smoke.yml
vendored
|
|
@ -10,7 +10,7 @@ on:
|
|||
# feedback. Release-targeted PRs are exactly the ones where cross-version
|
||||
# upgrade breakage is most expensive to discover at tag time.
|
||||
pull_request:
|
||||
branches: [ main, 'release/**' ]
|
||||
branches: [ main, 'release/**', 'hotfix/**' ]
|
||||
|
||||
# Allow manual trigger with custom version count
|
||||
workflow_dispatch:
|
||||
|
|
|
|||
2
.github/workflows/pr-risk.yml
vendored
2
.github/workflows/pr-risk.yml
vendored
|
|
@ -2,7 +2,7 @@ name: PR Risk
|
|||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [ main, 'release/**' ]
|
||||
branches: [ main, 'release/**', 'hotfix/**' ]
|
||||
merge_group:
|
||||
|
||||
concurrency:
|
||||
|
|
|
|||
18
.github/workflows/pr.yml
vendored
18
.github/workflows/pr.yml
vendored
|
|
@ -5,7 +5,7 @@ on:
|
|||
# release/** is here because release-prep and release-fix PRs are based on
|
||||
# the release branch, not on main. Without it they run almost no CI and the
|
||||
# first full signal is the tag build, where a failure burns the tag.
|
||||
branches: [ main, 'release/**' ]
|
||||
branches: [ main, 'release/**', 'hotfix/**' ]
|
||||
merge_group:
|
||||
|
||||
concurrency:
|
||||
|
|
@ -1014,14 +1014,20 @@ jobs:
|
|||
go-version-file: 'go.mod'
|
||||
cache: false
|
||||
|
||||
# golangci/golangci-lint-action is not on this repository's allowed-actions
|
||||
# list, so a workflow that names it fails at startup. Install the pinned
|
||||
# release binary (the same script main uses) and report only issues new
|
||||
# relative to the PR base, as only-new-issues did.
|
||||
- name: Install golangci-lint
|
||||
run: ./scripts/ci/install-golangci-lint.sh
|
||||
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9
|
||||
env:
|
||||
GOWORK: "off"
|
||||
with:
|
||||
version: v2.10.1
|
||||
only-new-issues: true
|
||||
args: --config=.golangci.yml --modules-download-mode=readonly --timeout=5m --build-tags=gms_pure_go
|
||||
NEW_FROM_REV: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}
|
||||
run: >-
|
||||
golangci-lint run --config=.golangci.yml --modules-download-mode=readonly
|
||||
--timeout=5m --build-tags=gms_pure_go --new-from-rev="$NEW_FROM_REV"
|
||||
|
||||
windows-make-shell:
|
||||
name: Windows Make shell (${{ matrix.host }})
|
||||
|
|
|
|||
24
.github/workflows/proxied-local-smoke.yml
vendored
24
.github/workflows/proxied-local-smoke.yml
vendored
|
|
@ -21,7 +21,10 @@ on:
|
|||
paths:
|
||||
- 'cmd/bd/proxied_local_*'
|
||||
- 'cmd/bd/proxied_server*.go'
|
||||
- 'cmd/bd/dolt*.go'
|
||||
- 'cmd/bd/*_proxied_server.go'
|
||||
- 'cmd/bd/backup*.go'
|
||||
- 'cmd/bd/purge*.go'
|
||||
- 'cmd/bd/db_proxy_child.go'
|
||||
- 'cmd/bd/init*.go'
|
||||
- 'cmd/bd/proxied_integration_helpers_test.go'
|
||||
|
|
@ -39,7 +42,10 @@ on:
|
|||
paths:
|
||||
- 'cmd/bd/proxied_local_*'
|
||||
- 'cmd/bd/proxied_server*.go'
|
||||
- 'cmd/bd/dolt*.go'
|
||||
- 'cmd/bd/*_proxied_server.go'
|
||||
- 'cmd/bd/backup*.go'
|
||||
- 'cmd/bd/purge*.go'
|
||||
- 'cmd/bd/db_proxy_child.go'
|
||||
- 'cmd/bd/init*.go'
|
||||
- 'cmd/bd/proxied_integration_helpers_test.go'
|
||||
|
|
@ -65,8 +71,10 @@ jobs:
|
|||
env:
|
||||
CGO_ENABLED: "1"
|
||||
# Pinned so the lane tests a known dolt CLI, not whatever the installer
|
||||
# resolves on a given day. Bump deliberately.
|
||||
DOLT_VERSION: 2.2.2
|
||||
# resolves on a given day. Bump deliberately, and only in lockstep with
|
||||
# the measured pin in scripts/ci/install-dolt.sh (see "Which Dolt
|
||||
# version to install" in docs/architecture/dolt.md).
|
||||
DOLT_VERSION: 2.2.0
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
|
||||
|
||||
|
|
@ -102,7 +110,17 @@ jobs:
|
|||
TestManagedLocalProxiedLegacyRecordFailClosed \
|
||||
TestManagedLocalProxiedOrphanBackendReaped \
|
||||
TestManagedLocalProxiedNProcessColdStartConvergence \
|
||||
TestManagedLocalProxiedStopStartInterleave
|
||||
TestManagedLocalProxiedStopStartInterleave \
|
||||
TestManagedLocalProxiedDoltStatusReportsLiveTopology \
|
||||
TestManagedLocalProxiedDoltStartRefusesOverLiveProxy \
|
||||
TestManagedLocalProxiedDoltStartRefusesWithProxyDown \
|
||||
TestManagedLocalProxiedDoltLifecycleLeavesOtherTopologiesAlone \
|
||||
TestManagedLocalProxiedPurgeWispsPlaneRetention \
|
||||
TestManagedLocalProxiedCapabilityMatrix \
|
||||
TestManagedLocalProxiedBackupRoundTrip \
|
||||
TestManagedLocalProxiedAutoBackup \
|
||||
TestManagedLocalProxiedBackupRestoreRefusedWhileAttached \
|
||||
TestManagedLocalProxiedBackendCleanExitRetiresProxy
|
||||
do
|
||||
if ! grep -qx "$test_name" <<<"$listed"; then
|
||||
echo "managed-local lifecycle test $test_name is missing; got: '$listed'" >&2
|
||||
|
|
|
|||
2
.github/workflows/regression.yml
vendored
2
.github/workflows/regression.yml
vendored
|
|
@ -5,7 +5,7 @@ on:
|
|||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
branches: [main, 'release/**']
|
||||
branches: [main, 'release/**', 'hotfix/**']
|
||||
# Allow manual trigger
|
||||
workflow_dispatch:
|
||||
|
||||
|
|
|
|||
824
CHANGELOG.md
824
CHANGELOG.md
|
|
@ -7,6 +7,830 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
## [1.3.2-rc.2] - 2026-10-10
|
||||
|
||||
Second release candidate for 1.3.2. Like rc.1 it has **no schema migration**:
|
||||
upgrading from 1.3.1 or 1.3.2-rc.1 is a binary swap. It adds one fix on top of
|
||||
rc.1, the backport of [#6876](https://github.com/gastownhall/beads/pull/6876),
|
||||
which keeps the post-commit blocked-state recheck from reverting concurrent
|
||||
writes. The rc.1 upgrade note (run `bd recompute-blocked` once per workspace
|
||||
after upgrading from bd ≤1.3.0, [#7037](https://github.com/gastownhall/beads/issues/7037))
|
||||
still applies.
|
||||
|
||||
### Fixed
|
||||
|
||||
- **The post-commit blocked-state recheck no longer reverts concurrent
|
||||
writes** ([#7146](https://github.com/gastownhall/beads/pull/7146), backport
|
||||
of [#6876](https://github.com/gastownhall/beads/pull/6876), fixes
|
||||
[#7030](https://github.com/gastownhall/beads/issues/7030)). The 1.3.1 line
|
||||
carried the #6716 fan-in fix
|
||||
([#6719](https://github.com/gastownhall/beads/pull/6719)/[#6936](https://github.com/gastownhall/beads/pull/6936),
|
||||
[#6942](https://github.com/gastownhall/beads/pull/6942)/[#6947](https://github.com/gastownhall/beads/pull/6947))
|
||||
in the form #6876 later corrected on `main`: on the Dolt server backend the
|
||||
recheck minted its Dolt commit while its own SQL transaction was still open.
|
||||
`DOLT_ADD` stages the table from the session's BEGIN-time root, so that
|
||||
commit could write `issues` rows that other sessions had just committed back
|
||||
to their BEGIN-time values. The recheck runs only when unblocking writes
|
||||
(closes, dependency removals, deletes) race on `issues`, which is exactly
|
||||
when this matters. The recompute now runs alone in its own retried
|
||||
transaction and the Dolt commit is published after it commits. A failed
|
||||
trailing commit is counted as `post_tx_commit_dropped` and logged, instead
|
||||
of being reported as a recheck failure, because the flag repair itself is
|
||||
already committed.
|
||||
|
||||
## [1.3.2-rc.1] - 2026-10-05
|
||||
|
||||
First release candidate for 1.3.2, a patch on top of 1.3.1 with **no schema
|
||||
migration**: upgrading from 1.3.1 is a binary swap. It fixes `bd purge`
|
||||
deleting the closed root of a chain that still has live work under it, and an
|
||||
auto-backup watermark that could claim a commit the snapshot does not contain.
|
||||
It also carries an upgrade note for stores migrated by 1.3.0 or 1.3.1
|
||||
([#7037](https://github.com/gastownhall/beads/issues/7037)).
|
||||
|
||||
### Upgrade notes
|
||||
|
||||
- **After upgrading from bd ≤1.3.0, run `bd recompute-blocked` once per
|
||||
workspace** ([#7037](https://github.com/gastownhall/beads/issues/7037)).
|
||||
Migration 0059, first shipped in 1.3.0, recomputes the denormalized
|
||||
`is_blocked` flag with a recursive query. On Dolt servers older than 2.4.0,
|
||||
and on the embedded engine, a query-planner bug
|
||||
([dolthub/dolt#11886](https://github.com/dolthub/dolt/issues/11886), fixed
|
||||
in Dolt 2.4.0) drops the query's `parent-child` edge filter. Blockedness then
|
||||
spreads across every dependency type, including `relates-to`,
|
||||
`discovered-from` and `tracks`. Beads that are not actually blocked are
|
||||
marked blocked and silently disappear from `bd ready` and `bd list --ready`.
|
||||
The flag is stored, so the damage persists until it is recomputed: nothing in
|
||||
1.3.2 repairs it automatically.
|
||||
|
||||
`bd recompute-blocked` rebuilds the flag from the dependency graph. It is
|
||||
idempotent and reports `rows_corrected`. It applies to every workspace whose
|
||||
store crossed migration 0059 under bd 1.3.0 or later, which includes a
|
||||
workspace now on 1.3.1 that was originally created by 1.2.x or earlier.
|
||||
Running it on a workspace that was not affected changes nothing.
|
||||
|
||||
### Fixed
|
||||
|
||||
- **`bd purge` keeps the whole closed chain above a live bead, not just its
|
||||
direct parent** ([#7041](https://github.com/gastownhall/beads/pull/7041),
|
||||
fixes [#7031](https://github.com/gastownhall/beads/issues/7031)). The
|
||||
live-dependent protection added in 1.3.1 only protected a closed candidate
|
||||
that a not-done bead pointed at directly. Take a closed root R, a closed child
|
||||
S1 and an open grandchild S2. S1 was protected because S2 is live, but R was
|
||||
not, because its only dependent S1 is closed. Purge deleted R, which orphaned
|
||||
S1 and S2, and `--dry-run` reported the same deletion. Protection now
|
||||
propagates through closed candidates until nothing changes, on every backend
|
||||
(dolt server, embedded, proxied/uow). An orchestrator retention sweep
|
||||
(`bd purge --wisps-plane --older-than ...`) is the common way to hit this.
|
||||
- **The backup watermark no longer runs ahead of the snapshot**
|
||||
([#7044](https://github.com/gastownhall/beads/pull/7044), fixes
|
||||
[#7032](https://github.com/gastownhall/beads/issues/7032)). Auto-backup read
|
||||
Dolt HEAD *after* the sync and recorded that as the newest commit backed up.
|
||||
A commit that landed during the sync was therefore recorded as backed up even
|
||||
though the snapshot did not contain it, and auto-backup reported "no changes
|
||||
since last backup" until HEAD moved again. HEAD is now read before the sync,
|
||||
so such a commit stays pending for the next backup. Only opted-in auto-backup
|
||||
(`backup.enabled: true`) was affected; `bd backup sync` does not record a
|
||||
commit watermark.
|
||||
|
||||
### CI
|
||||
|
||||
- PRs into `hotfix/**` branches now run full CI, including the required
|
||||
`CI Gate / Required` check
|
||||
([#7198](https://github.com/gastownhall/beads/pull/7198), fixes
|
||||
[#7148](https://github.com/gastownhall/beads/issues/7148); ported to this
|
||||
branch in [#7217](https://github.com/gastownhall/beads/pull/7217)).
|
||||
|
||||
## [1.3.1] - 2026-09-30
|
||||
|
||||
First stable release of the 1.3.1 patch line. It ships the same code as
|
||||
[1.3.1-rc.2]; the only change since that candidate is the version stamp. The
|
||||
full notes are in the [1.3.1-rc.2] and [1.3.1-rc.1] sections below, which
|
||||
together cover everything since [1.3.0].
|
||||
|
||||
There is **no schema migration**: upgrading from 1.3.0, 1.3.1-rc.1 or
|
||||
1.3.1-rc.2 is a binary swap.
|
||||
|
||||
### Upgrade notes
|
||||
|
||||
- Coming from 1.3.0, read the upgrade notes in [1.3.1-rc.2] and the
|
||||
**Changed** entries in [1.3.1-rc.1]. The rc.1 change most likely to affect
|
||||
scripts is the new `bd dolt status --json` shape on a proxied workspace
|
||||
([#6580](https://github.com/gastownhall/beads/pull/6580)).
|
||||
- Coming from 1.3.1-rc.2, nothing changes in behaviour.
|
||||
|
||||
## [1.3.1-rc.2] - 2026-09-29
|
||||
|
||||
Second release candidate for 1.3.1, still a patch line on top of 1.3.0 with
|
||||
**no schema migration**: upgrading from 1.3.0 or 1.3.1-rc.1 is a binary swap.
|
||||
It adds the proxied-server `bd backup` family and opt-in auto-backup on
|
||||
managed-local workspaces, a `bd purge` that can run an orchestrator's wisp
|
||||
retention sweep, and fixes for the #6716 fan-in stall, partial batch closes,
|
||||
`bd sql` result sets, `bd show --watch`, `bd types`, `BEADS_DIR` discovery and
|
||||
proxy liveness, plus eleven fixes from `main` ([#6653](https://github.com/gastownhall/beads/pull/6653)) and the smart-gate
|
||||
data-behind stop ([#6659](https://github.com/gastownhall/beads/pull/6659), [#6695](https://github.com/gastownhall/beads/pull/6695)). Engineering notes for embedders
|
||||
reading proxied-server surfaces are in `engdocs/` ([#6652](https://github.com/gastownhall/beads/pull/6652)).
|
||||
|
||||
### Upgrade notes
|
||||
|
||||
These behaviour changes can affect scripts; each is detailed below.
|
||||
|
||||
- `bd show --watch <id>` exits 1 when the id cannot be found (it used to exit
|
||||
0), on both the direct and proxied routes.
|
||||
- `bd sql` in direct server mode prints `OK` / `{"status":"ok"}` for a
|
||||
multi-statement write or a write the parser cannot classify, instead of
|
||||
`OK, N rows affected` / `{"rows_affected":N}`. `bd sql --readonly` refuses
|
||||
statements it cannot parse (for example `PRAGMA`) instead of running them
|
||||
as reads.
|
||||
- A failure to read the custom issue types now fails `bd types`,
|
||||
`bd create --graph` and `bd config set storage-class.*` instead of being
|
||||
treated as "no custom types".
|
||||
- `BEADS_DIR` must point at the `.beads` directory itself. A `BEADS_DIR` that
|
||||
names a project root, or a `.beads` that does not exist yet, now fails with
|
||||
"no beads database found" instead of silently resolving to the nearest
|
||||
workspace above the current directory.
|
||||
- `bd purge` always keeps closed beads a live bead depends on
|
||||
(`live_dependent_skipped`); there is no flag to turn this off.
|
||||
- `--older-than` on `bd purge` and `bd prune` is exact at hour precision:
|
||||
`12h` no longer rounds up to a day, so `bd prune --older-than 12h` deletes
|
||||
rows it used to keep.
|
||||
- `bd close` with several ids exits non-zero when any of them fails to close.
|
||||
- Unflagged piped `bd query` is no longer capped at 50 rows.
|
||||
- On a proxied workspace with `dolt.auto-commit` set to `batch` or `off`,
|
||||
writes are no longer committed to Dolt history one by one; run
|
||||
`bd dolt commit` to flush them.
|
||||
- `bd backup sync` fails after waiting 5 seconds if another backup of the same
|
||||
workspace is running.
|
||||
- `bd ready` / `bd list --ready` include issues in custom `active`-category
|
||||
statuses, and a store open against an unreachable Dolt server on a
|
||||
proxied-server workspace or under `bd serve` retries for up to ~40s before
|
||||
failing. Both come from [#6653](https://github.com/gastownhall/beads/pull/6653); see **Changed**.
|
||||
|
||||
### Added
|
||||
|
||||
- **`bd backup` works on a proxied-server workspace bd runs the Dolt server
|
||||
for** ([#6584](https://github.com/gastownhall/beads/pull/6584)). `bd backup init`, `sync`, `remove`, `status` and `restore` are routed
|
||||
over the proxied provider; before this, a proxied workspace — the default
|
||||
topology since 1.3.0 — had no backup path at all. `bd backup restore` stops
|
||||
the proxy and its Dolt child before replacing the database and leaves the
|
||||
workspace quiescent, so the next command relaunches against the restored
|
||||
data.
|
||||
|
||||
The family stays **refused by design** on a proxied workspace pointed at a
|
||||
Dolt server bd does not own (an external host, socket, or a beads-team-server
|
||||
database): `CALL DOLT_BACKUP('add', …)` registers the backup remote on the
|
||||
*server*, where it is global to every client connected to it, so one
|
||||
workspace's backup decision would silently become everyone's — the shape
|
||||
`bd backup`'s own help text already warns about for auto-backup. A `file://`
|
||||
destination has a second problem on top, since the server resolves that path
|
||||
on its own filesystem. The refusal keeps the `proxy.backup.unsupported` code
|
||||
and now carries `"reason": "design"`; a backup story for those deployments
|
||||
belongs to whoever runs the server. Whether a *remote-scheme* destination
|
||||
(DoltHub, `aws://`, `gs://`) should eventually be allowed there is recorded as
|
||||
an open question rather than settled — the server pushes those over the
|
||||
network from its own environment, which is the same credential question the
|
||||
next slice has to answer for `dolt push`.
|
||||
|
||||
`bd backup status` and `bd backup` help no longer attribute auto-backup being
|
||||
OFF on a server topology to a missing git remote, which was never the reason
|
||||
there ([#6694](https://github.com/gastownhall/beads/pull/6694)). Auto-backup
|
||||
itself is opt-in on this topology; see the next entry.
|
||||
|
||||
- **Auto-backup runs on a managed-local proxied-server workspace**
|
||||
([#6879](https://github.com/gastownhall/beads/pull/6879)). 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**
|
||||
([#6883](https://github.com/gastownhall/beads/pull/6883)). 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.
|
||||
|
||||
### Changed
|
||||
|
||||
- **Proxied-server refusals now say *why* they refuse** ([#6582](https://github.com/gastownhall/beads/pull/6582)). 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
|
||||
history, multi-repo routing, destructive admin, strict `--readonly`) and
|
||||
`unimplemented` for a capability gap with a named owner. Every existing code,
|
||||
message and exit status is unchanged, and `reason` is absent on refusals that
|
||||
report a runtime state rather than a policy, so existing consumers are
|
||||
unaffected. The policy behind it moved into one registry
|
||||
(`cmd/bd/capability_registry.go`) that every command must appear in.
|
||||
- **A command with no proxied-server route now fails with a typed error**
|
||||
(`proxy.store.unrouted`) instead of the bare string `proxy server store
|
||||
should be uow provider`.
|
||||
|
||||
- **`bd backup restore --json` prints a result object on every topology**
|
||||
(`{"restored": true, "source": "<dir>"}`). It previously printed nothing at
|
||||
all, which left a caller unable to tell a completed restore from a silently
|
||||
skipped one. This applies to direct/embedded workspaces too, not only proxied
|
||||
ones.
|
||||
- **`bd backup init`, `sync`, `remove` and `restore` no longer print a usage
|
||||
block after a failure.** They now silence cobra's own error and usage
|
||||
rendering like the rest of the CLI, so a failure is one error line on stderr
|
||||
instead of the message followed by `Error: exit code 1` and the full usage
|
||||
text. Exit statuses are unchanged; this applies on every topology.
|
||||
|
||||
- **`bd purge` keeps closed beads a live bead depends on, always**
|
||||
([#6883](https://github.com/gastownhall/beads/pull/6883)). 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. There is no flag to turn this off.
|
||||
See the `--wisps-plane` entry under Added.
|
||||
|
||||
- **`--older-than` on `bd purge` and `bd prune` is taken at hour precision**
|
||||
([#6883](https://github.com/gastownhall/beads/pull/6883)). An `Nh` value is no longer rounded to whole days: `12h` used to
|
||||
round UP to one day and now means 12 hours, so `bd prune --older-than 12h`
|
||||
deletes rows closed 12–24 hours ago that it used to keep; `36h` used to floor
|
||||
to one day and now means 36 hours. Day values (`7`, `7d`, `2w`) are
|
||||
unchanged. See the `bd purge` entry under Added.
|
||||
|
||||
- **`dolt.auto-commit=batch` and `off` now take effect on a proxied-server
|
||||
workspace, and `bd dolt commit` works there** ([#6499](https://github.com/gastownhall/beads/pull/6499),
|
||||
[#4995](https://github.com/gastownhall/beads/issues/4995)). Every proxied write used to mint a Dolt history commit
|
||||
whatever `dolt.auto-commit` said, and `bd dolt commit` was refused with
|
||||
`proxy.dolt_commit.unsupported`. Under `batch`/`off` a proxied write now
|
||||
lands in the server's working set without advancing Dolt history, and
|
||||
`bd dolt commit` is the flush point, as on the direct route. Commands that
|
||||
are explicit commit points (`bd batch`, `bd mol bond`/`pour`/`squash`,
|
||||
`bd mol wisp create`, and the wisp half of `bd mol burn`) still commit, and
|
||||
`bd serve` writes still commit per write. `on`, the default, is unchanged.
|
||||
**Behaviour change:** a proxied workspace that set `batch` or `off` and was
|
||||
getting per-write commits anyway now accumulates uncommitted changes until
|
||||
`bd dolt commit`, and `dolt log`, `dolt push` and backups do not see them
|
||||
before that. `bd vc commit`'s proxied refusal now points at `bd dolt commit`.
|
||||
|
||||
- **`bd ready` and `bd list --ready` now return issues whose custom status is in
|
||||
the `active` category** ([#5918](https://github.com/gastownhall/beads/pull/5918),
|
||||
[#5831](https://github.com/gastownhall/beads/issues/5831)). The ready query
|
||||
treated its `open` pin as an exact match, so a workspace that defined, say,
|
||||
`triaged:active` never saw those issues in ready work — even though
|
||||
`bd statuses`, the `ready_issues` view, and claim eligibility all already
|
||||
counted that category as ready. **The ready set grows on upgrade** for any
|
||||
workspace using custom active statuses: counts and dashboards will read higher,
|
||||
and `bd ready` can hand out issues it used to withhold. Custom
|
||||
`wip`/`done`/`frozen`/unspecified statuses stay out, and `in_progress` stays
|
||||
out, both unchanged.
|
||||
|
||||
- **`bd list --wisp-type <t>` with no plane admitted is now a refusal instead of
|
||||
an empty listing** ([#6098](https://github.com/gastownhall/beads/pull/6098)).
|
||||
`--wisp-type` narrows an admitted plane rather than admitting one, so alone it
|
||||
could not match any row and exited 0 with an empty result for every input. It
|
||||
now fails with a hint naming `--include-ephemeral`. A script that ran it and
|
||||
read the empty output as "no such wisps" now sees an error — which is the
|
||||
point: the old success answered a question it had not asked. The refusal is
|
||||
CLI-only; the equivalent API request stays lawful and still composes to an
|
||||
empty page.
|
||||
|
||||
- **The `--ready` footer names the status pin that actually applied**
|
||||
([#5924](https://github.com/gastownhall/beads/pull/5924)). With no `--status`
|
||||
(or `--status all`) the line is unchanged: `open only — --ready excludes
|
||||
in_progress`. With an explicit `--status` it now reads `<selector> only`
|
||||
instead of reusing the default-open sentence, which is no longer true once the
|
||||
selector is honored (see **Fixed**). Anything scraping that parenthetical for
|
||||
a `--status`-plus-`--ready` run sees new text — though that combination also
|
||||
returned the wrong rows before this release. Note that the default sentence now
|
||||
understates the set, since custom active statuses join it (above); the footer
|
||||
and `--ready` help text are corrected upstream on main
|
||||
([#6187](https://github.com/gastownhall/beads/issues/6187),
|
||||
[#6188](https://github.com/gastownhall/beads/issues/6188)).
|
||||
|
||||
- **`bd doctor` reports a new missing gitignore pattern on every workspace
|
||||
created before this release, until `bd doctor --fix` is run**
|
||||
([#5978](https://github.com/gastownhall/beads/pull/5978)).
|
||||
`.beads/dolt-server-config.yaml` joined the required `.beads/.gitignore`
|
||||
patterns (see **Fixed**), so a workspace that was clean a moment ago now
|
||||
warns. `bd doctor --fix` appends the rule and silences it; workspaces
|
||||
initialised after this release get it from the template and never warn.
|
||||
|
||||
- **Opening a store against an unreachable Dolt server now takes up to ~40s to
|
||||
fail instead of failing at once — on proxied-server workspaces, and under
|
||||
`bd serve`** ([#6003](https://github.com/gastownhall/beads/pull/6003)). The
|
||||
bootstrap ping is retried for up to 30 seconds, each attempt capped at 10s, so
|
||||
a server still coming up is waited out rather than turned into a hard failure
|
||||
(see **Fixed**). The cost is that a genuinely dead or misconfigured endpoint no
|
||||
longer errors immediately: an interactive command against a stopped server, and
|
||||
any script or CI step that counted on a fast failure, now waits out the retry
|
||||
budget first. Durable rejections — bad credentials, unknown database, a
|
||||
hostname that does not resolve — are still reported immediately without
|
||||
retrying.
|
||||
|
||||
Only the paths that build a unit-of-work provider take that ping, so this is a
|
||||
minority of topologies: every command in a proxied-server workspace, local or
|
||||
external, and `bd serve` in a server, external-server or shared-server
|
||||
workspace, which builds its own provider through the same funnel. **Embedded —
|
||||
the default — is unaffected entirely**; `bd serve` refuses it outright, and no
|
||||
embedded command can slow down here. An ordinary CLI command in a server or
|
||||
shared-server workspace is also unaffected: it opens a Dolt store, which does
|
||||
not take this ping. Only that mode's `bd serve` startup does.
|
||||
|
||||
The 30s figure is the retry budget, not the wall-clock bound. It stops
|
||||
*scheduling* attempts at 30s but cannot cancel one already in flight, and each
|
||||
attempt carries its own 10s cap, so ~40s is the honest worst case for a single
|
||||
open. A provider open pings twice — once for the schema-init connection, once
|
||||
for the database pool — each with a fresh budget, so a backend that satisfies
|
||||
the first ping and the schema init and is then unreachable for the second can
|
||||
push one command to ~80s. That ordering is narrow, but it is reachable.
|
||||
|
||||
- **A backup sync that would leave the backup's manifest ahead of its chunk
|
||||
files now fails at that point instead of corrupting the backup quietly**
|
||||
([#5931](https://github.com/gastownhall/beads/pull/5931),
|
||||
[#4070](https://github.com/gastownhall/beads/issues/4070)). The Dolt bump
|
||||
brings upstream's defense, which rejects a manifest update referencing a
|
||||
missing table file. Previously that update was accepted and only some later
|
||||
sync failed, confusingly, with `table file not found` — and stayed broken. A
|
||||
sync that used to appear to succeed can now report a failure; that failure is
|
||||
the corruption being caught at the moment it happens. This is a mitigation,
|
||||
not a root-cause fix: backup file-and-manifest publish is still non-atomic,
|
||||
and **backups already in the manifest-ahead state are not repaired** by
|
||||
upgrading — they surface as a failing sync and have to be re-seeded.
|
||||
|
||||
### Fixed
|
||||
|
||||
- **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 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 1 instead of 0 ([#6933](https://github.com/gastownhall/beads/pull/6933)).
|
||||
|
||||
- **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 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 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.
|
||||
|
||||
- **Unblocking two blockers of one dependent at the same time no longer leaves
|
||||
the dependent stuck as blocked** ([#6716](https://github.com/gastownhall/beads/issues/6716); [#6719](https://github.com/gastownhall/beads/pull/6719), [#6942](https://github.com/gastownhall/beads/pull/6942)).
|
||||
Closing both blockers in parallel (formula fan-in with parallel workers), 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`. A write that takes a blocker away (a close, an update
|
||||
to an inactive status, a dependency removal, a delete) now rechecks the
|
||||
dependents it recomputed once its transaction has committed. This covers the
|
||||
Dolt store write transactions, every write the proxied-server (uow/domain-db)
|
||||
route serves — under `--proxied-server`, the default topology, that is
|
||||
`bd close` (single and batch), `bd update --status`, `bd dep remove`,
|
||||
`bd delete`, `bd batch` and `bd serve` — `RunInTransaction` (`bd batch`
|
||||
direct, `bd cook`, `bd mol squash`/`burn`, and SDK callers that close or
|
||||
update inside a transaction), 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.
|
||||
|
||||
- **`bd close` now exits non-zero when any issue in a batch fails to close**
|
||||
([#6648](https://github.com/gastownhall/beads/issues/6648); [#6740](https://github.com/gastownhall/beads/pull/6740), [#6771](https://github.com/gastownhall/beads/pull/6771)). A batch with one
|
||||
refused id used to exit 0 as long as another id closed, so scripts could not
|
||||
tell that part of the batch was left open. The closable ids still close, the
|
||||
refusals are still printed, and a final `Error: N of M issues failed to close`
|
||||
line is added; ids that were already closed still count as success. Both the
|
||||
direct and proxied-server routes behave this way for ids the close policy or
|
||||
the engine refuses. (An id that cannot be *resolved* at all is unchanged and
|
||||
still differs by route: the direct route aborts the whole command before any
|
||||
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. 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.
|
||||
|
||||
- **`bd query` no longer silently stops at 50 rows when its output is piped**
|
||||
([#6229](https://github.com/gastownhall/beads/issues/6229), [#6744](https://github.com/gastownhall/beads/pull/6744)). `bd list` has
|
||||
treated piped stdout as unlimited since GH#4094, but `bd query` read its
|
||||
`--limit` default of 50 straight through, so `bd query '...' | consumer`
|
||||
dropped every row past 50 with no hint. An unflagged `bd query` now resolves
|
||||
through the same policy as `bd list`: an explicit `--limit` wins, piped
|
||||
stdout is unlimited, agent mode on a terminal gets 20, and a terminal gets 50.
|
||||
|
||||
- **Deleting or purging a wisp no longer leaves orphan rows behind on stores
|
||||
without the wisp foreign keys** ([#6563](https://github.com/gastownhall/beads/pull/6563), [#6627](https://github.com/gastownhall/beads/pull/6627), [#6487](https://github.com/gastownhall/beads/issues/6487)).
|
||||
On a store whose `wisp_dependencies` and wisp auxiliary tables lack the
|
||||
migration-0047 FK constraints, every wisp delete (including `bd purge`,
|
||||
`bd mol burn` and wisp GC) left its `wisp_dependencies` edges on both sides
|
||||
and its `wisp_labels`, `wisp_events`, `wisp_comments` and
|
||||
`wisp_child_counters` rows in place, which showed up as dangling parent
|
||||
references and store bloat. The delete paths now remove them. This is a
|
||||
forward fix: orphans already in a store are not cleaned up.
|
||||
|
||||
- **A clone missing its local `events`, `bd_events_journal` or `bd_events_seq`
|
||||
table recreates it on open** ([#6547](https://github.com/gastownhall/beads/pull/6547)). Those tables are dolt-ignored, so
|
||||
a fresh clone can arrive at the latest schema version without them, and bd
|
||||
then treated the schema as complete and never created them. Their absence
|
||||
now makes the migration runner replay the migrations that create them, from
|
||||
each table's own floor rather than from zero.
|
||||
|
||||
- **The smart migrate gate no longer auto-migrates a clone whose data is behind
|
||||
the remote** ([#6575](https://github.com/gastownhall/beads/issues/6575)). The
|
||||
gate's first-mover verdict was computed from schema facts alone — equal
|
||||
migration content hashes against the cached remote ref, at the same version,
|
||||
at or above the convergence floor — and none of those say where the clone's
|
||||
branch sits relative to that ref. A clone level with the remote on *schema*
|
||||
but behind it in unpulled *data* commits satisfied every precondition, was
|
||||
classified a safe first-mover, and migrated in place, minting local-only
|
||||
schema commits on a HEAD missing those commits. When the pending batch moves
|
||||
a tracked table onto the `dolt_ignore` plane, every later `bd dolt pull` then
|
||||
refuses with `local changes would be stomped by merge: events`
|
||||
([#6368](https://github.com/gastownhall/beads/issues/6368)) while `dolt
|
||||
status` reads clean — and the clone can no longer fetch the very commits it
|
||||
was behind on. Upgrading from a 1.1-era database is the ordinary way in, so
|
||||
this release's upgrade audience is the exposed one. The gate now reads the
|
||||
branch position its callers already supply and stops with guidance naming the
|
||||
remedy: run `bd dolt pull`, then re-run what you were blocked on, and the
|
||||
migrate proceeds as a true first-mover.
|
||||
|
||||
The stop applies whenever the clone has commits left to pull, whether or not
|
||||
it also has commits of its own. bd auto-commits every write, so a clone that
|
||||
is both behind and ahead is the ordinary multi-machine state, and it reaches
|
||||
the same wedge; it is told its pull will *merge* rather than fast-forward, and
|
||||
how to resolve conflicts if it reports them. A clone that is level with the
|
||||
remote, or that only has unpushed local commits with nothing to pull, still
|
||||
auto-migrates exactly as before.
|
||||
|
||||
**`bd dolt pull` works from the refused state.** It opens the store too, so
|
||||
on a refused clone it would otherwise hit the very refusal that prescribes
|
||||
it — and an embedded workspace has no external `dolt` binary to fall back to,
|
||||
which would leave `BD_ALLOW_REMOTE_MIGRATE=1` (performing the migration the
|
||||
stop exists to prevent) as the only way forward. `bd dolt pull` now opens
|
||||
leniently for this one refusal, the way `bd dolt commit` does for the
|
||||
dirty-working-set refusal
|
||||
([#4566](https://github.com/gastownhall/beads/issues/4566)); every other gate
|
||||
refusal still fails that open. This supersedes the [1.3.0] upgrade note's
|
||||
statement that the pending-migration gate refuses `bd dolt pull` as well as
|
||||
`bd dolt push`: for the data-behind stop it does not, by design.
|
||||
|
||||
Commands that keep working through the stop say the same thing. `bd list`,
|
||||
`bd ready` and `bd show` succeed against the old schema, and `bd dolt commit`
|
||||
still commits the working set; on embedded storage all of them used to print
|
||||
the blunt migrate-or-adopt coordination bullets while doing so — naming
|
||||
`bd migrate --force && bd dolt push`, which on a data-behind clone applies
|
||||
the migration this stop exists to prevent and then fails the push
|
||||
non-fast-forward, and `bd bootstrap`, which no-ops against an existing
|
||||
workspace. They now print the pull-first guidance, shape-branched the same
|
||||
way the fatal refusal is, alongside the note that the command in hand
|
||||
continued at the current schema. Refusals that are *not* the data-behind stop
|
||||
keep the coordination bullets, which are right for them.
|
||||
|
||||
`--json` callers get the same remedy the terminal does: `observed`,
|
||||
`expected` and `options` describe the pull (a single `pull-first` option)
|
||||
rather than the migrate-or-adopt decision that does not apply here, plus a
|
||||
`data_behind_shape` of `fast-forward` or `diverged`. `fallback_reason` stays
|
||||
`data-behind`. For the fast-forward shape on a non-shared store — one
|
||||
unconditional option, no local commits, nothing discarded —
|
||||
`human_decision_required` is now `false`, so an agent can run the pull
|
||||
instead of stalling for approval of a step the same payload calls riskless.
|
||||
It stays `true` for the diverged shape (the pull merges and can need conflict
|
||||
resolution) and on a shared store (the follow-up consent step needs an
|
||||
operator who can confirm every co-resident client is upgraded). On a shared
|
||||
Dolt sql-server the guidance carries #5920's consequence — migrating promotes
|
||||
the schema for every co-resident client, and clients still on an older bd
|
||||
refuse the database until upgraded — and names the consent step the retry
|
||||
needs there: `bd migrate schema --force`. It is the forced form because this
|
||||
stop always has a remote configured (behind-ness is read from the
|
||||
remote-tracking ref), and the bare `bd migrate schema` consent is only read
|
||||
for a shared database with *no* remote; the flag consents to migrating a
|
||||
remote-backed shared store, and by then the pull has landed the commits the
|
||||
clone was missing.
|
||||
|
||||
**Proxied-server mode reaches the stop too, and is told where to run the
|
||||
remedy.** The store-open gate on that path supplied no branch-position
|
||||
callback, so a proxied clone that was level on schema and behind in data
|
||||
could never be classified data-behind: it got the blunt shared-store refusal,
|
||||
whose body is the designated-migrator recipe — `bd migrate --force` then
|
||||
`bd dolt push` — which in this state is the wedge the stop exists to prevent.
|
||||
It now routes to the same data-behind stop as every other topology. Because
|
||||
`bd dolt pull` is refused at the proxied front door
|
||||
(`proxy.dolt_pull.unsupported`), along with `bd dolt push`, the bare
|
||||
`bd migrate` and `bd conflicts`, the guidance there names the machine the pull
|
||||
has to run on rather than printing a command this binary rejects; the `--json`
|
||||
option is `pull-first-on-server-host`, and `expected` carries the same
|
||||
qualifier so a single-field reader is not handed a locally-refused command.
|
||||
The shared-store consent step is the other way round: `bd migrate schema
|
||||
--force` is *not* refused here — the refusal table keys on the command path
|
||||
and has no `migrate schema` row — so the guidance says it can be run from this
|
||||
workspace but only after the pull lands on the server host, and the warning
|
||||
against forcing past the stop names it alongside `BD_ALLOW_REMOTE_MIGRATE=1`
|
||||
as the two consent surfaces this topology can still reach. Read-only proxied
|
||||
opens print the same pull-first block instead of the shared-consent template.
|
||||
|
||||
Both existing workarounds keep working unchanged: `BD_SMART_GATE=0` opts out
|
||||
of the smart gate entirely (which means the blunt gate applies to `bd dolt
|
||||
pull` too — that is what opting out is), and running `bd dolt pull` before the
|
||||
first open after upgrading avoids the state to begin with. `bd migrate
|
||||
--force` / `BD_ALLOW_REMOTE_MIGRATE=1` are still consulted before the gate and
|
||||
still override it.
|
||||
|
||||
- **`bd list --status <s> --ready` honors `--status`**
|
||||
([#5924](https://github.com/gastownhall/beads/pull/5924),
|
||||
[#5832](https://github.com/gastownhall/beads/issues/5832)). Combining the two
|
||||
silently dropped `--status` and returned the unfiltered ready set, because the
|
||||
ready path pinned `open` in two places regardless of what was asked for, so a
|
||||
custom status or `in_progress` never reached the ready query. An explicit
|
||||
`--status` is now the ready-work status selector, matching how the other list
|
||||
filters already compose with `--ready`. `--ready` with no `--status` still
|
||||
defaults to open, and `--status all` remains the no-filter spelling. The footer
|
||||
wording moves with it — see **Changed**.
|
||||
|
||||
- **`bd list --wisp-type` can reach rows at all**
|
||||
([#6098](https://github.com/gastownhall/beads/pull/6098)). `bd list` now
|
||||
registers `--include-ephemeral`, the plane knob `--wisp-type` needs, off by
|
||||
default so the default listing is byte-identical. `bd list
|
||||
--include-ephemeral --wisp-type heartbeat` is the working spelling. Before
|
||||
this, the only way to admit the wisp plane from `bd list` was `--type
|
||||
<infra-type>`, which also lifts the infra-type exclusions and changes template
|
||||
treatment — three decisions for a caller who wanted one classification. Bare
|
||||
`--wisp-type` is now refused rather than empty; see **Changed**.
|
||||
|
||||
- **`bd doctor` knows about the generated `.beads/dolt-server-config.yaml`**
|
||||
([#5978](https://github.com/gastownhall/beads/pull/5978)).
|
||||
`doltserver.Start()` writes that file when the resolved dolt binary supports
|
||||
`auto_gc_behavior.archive_level`, but the hyphenated name falls outside the
|
||||
`dolt-server.` prefix its five sibling server-state entries share, so neither
|
||||
the gitignore template nor the required-pattern list covered it. It holds an
|
||||
absolute `cfg_dir` and a per-machine port, so committing it breaks every other
|
||||
clone — the same reason the template already gives for `redirect`. It shows up
|
||||
as untracked in every consumer repo whose dolt supports `archive_level`. It is
|
||||
now in both lists: the template covers new workspaces, and the required
|
||||
patterns are what `bd doctor --fix` appends to an existing
|
||||
`.beads/.gitignore` — see **Changed** for the warning that implies.
|
||||
|
||||
- **The missing-prefix error stops recommending a config key that does nothing**
|
||||
([#5936](https://github.com/gastownhall/beads/pull/5936),
|
||||
[#5916](https://github.com/gastownhall/beads/issues/5916)). When the database's
|
||||
`issue_prefix` config row was absent, the error advised using the
|
||||
`issue-prefix` key in `config.yaml` — but that gate only reads the database's
|
||||
config table, so following the advice produced a tracked config field that
|
||||
changed nothing and misled the next reader. The message now points at
|
||||
`bd init --prefix` or `bd bootstrap`, which is what writes the row, and says
|
||||
plainly which store the check reads. Error text only; resolution behaviour is
|
||||
unchanged.
|
||||
|
||||
- **`bd create --file` says that it creates one issue per `##` heading**
|
||||
([#5921](https://github.com/gastownhall/beads/pull/5921)). The usage string was
|
||||
"Create multiple issues from markdown file", which named neither the per-H2
|
||||
semantics nor `--body-file`. Someone wanting "one issue, description loaded
|
||||
from a file" reached for the shortest flag and got a silent bulk import — a
|
||||
briefing file with `## Problem` / `## Context` / `## Acceptance Criteria`
|
||||
became three issues. The usage now names the behaviour, and the existing
|
||||
rejection of a positional title combined with `--file` carries a `--body-file`
|
||||
hint. `--file` alone on a section-headed file is unchanged: bd cannot tell that
|
||||
apart from a genuine batch file by content.
|
||||
|
||||
- **The list truncation hint no longer leaves a padded blank line under the
|
||||
shell prompt** ([#5927](https://github.com/gastownhall/beads/pull/5927),
|
||||
[#5685](https://github.com/gastownhall/beads/issues/5685)). The hint passed its
|
||||
surrounding newlines through the warning renderer, which treats them as a
|
||||
block, pads the blank lines out to the widest line's width, and drops the
|
||||
trailing newline — so the next prompt printed on top of a run of spaces. The
|
||||
newlines are kept outside the renderer now, leaving one coloured line with a
|
||||
real trailing newline.
|
||||
|
||||
- **`bd setup claude` and `bd init` stop rewriting `.claude/settings.json` on
|
||||
every run** ([#5944](https://github.com/gastownhall/beads/pull/5944),
|
||||
[#5693](https://github.com/gastownhall/beads/issues/5693)). The settings map
|
||||
was marshaled without a trailing newline and written unconditionally, so each
|
||||
run stripped the newline Claude Code's own writes leave behind and rewrote the
|
||||
file even when no hook had changed. Because `bd init` git-adds that file, it
|
||||
surfaced as a staged diff with no semantic content. The write now keeps the
|
||||
trailing newline and is skipped when the bytes match what is already on disk,
|
||||
at all four call sites — the settings write and the `settings.local.json`
|
||||
migration on install, and both again on remove.
|
||||
|
||||
- **`bd gate check` resolves bead gates whose target lives in a prefix-routed
|
||||
rig** ([#5859](https://github.com/gastownhall/beads/pull/5859)). After a local
|
||||
miss, the evaluator follows the target bead ID through `routes.jsonl` and reads
|
||||
the owning store without writing to it; previously such a gate stayed pending
|
||||
until someone resolved it manually. This covers explicit gate checks in
|
||||
embedded, server, and proxied-server command paths. The legacy
|
||||
`<rig>:<bead-id>` await value remains accepted for compatibility, a malformed
|
||||
cross-rig value is rejected, and when prefix routing is unavailable the original
|
||||
local not-found error is preserved.
|
||||
|
||||
- **A transient connection drop while opening a Dolt store is retried instead of
|
||||
failing the command**
|
||||
([#6003](https://github.com/gastownhall/beads/pull/6003)). The bootstrap ping
|
||||
in the unit-of-work provider was unretried, so a server still finishing startup
|
||||
— or one that reset the connection mid-handshake — became a hard failure.
|
||||
Connection-level shapes (`driver.ErrBadConn`, `mysql.ErrInvalidConn`, EOF, any
|
||||
`*net.OpError`) are now retried for up to 30s, each attempt capped at 10s so a
|
||||
server that accepts TCP and then stalls cannot block for the caller's whole
|
||||
context. Durable rejections and an unresolvable hostname still fail without
|
||||
retrying. See **Changed** for the latency this adds against a dead endpoint.
|
||||
|
||||
## [1.3.1-rc.1] - 2026-09-16
|
||||
|
||||
### Changed
|
||||
|
||||
- **`bd dolt status --json` changes shape on a proxied workspace**
|
||||
([#6580](https://github.com/gastownhall/beads/pull/6580)). It now emits
|
||||
`{"mode": "proxied-server", "root": ..., "running": <proxy up>, "proxy_pid":
|
||||
..., "proxy_port": ..., "backend_managed": ..., "backend_running": ...,
|
||||
"backend_pid": ..., "backend_port": ..., "backend_endpoint": ...,
|
||||
"idle_timeout": ...}` instead of the always-false `{"running": false, "pid":
|
||||
0, "port": 0}` — `pid` and `port` are gone, replaced by the `proxy_*` and
|
||||
`backend_*` pairs. `running` no longer reports a bd-managed dolt PID file; it
|
||||
describes the proxy, the endpoint every bd command connects through, so it is
|
||||
now usually true where it used to be always false. `backend_managed` is false
|
||||
on external proxied topologies, where the dolt server is not bd's process to
|
||||
report on and `backend_endpoint` names it instead. Anything parsing the old
|
||||
payload changes behaviour on upgrade. Direct-server, shared, embedded and
|
||||
externally-managed workspaces keep the output they had.
|
||||
|
||||
- **`bd config set <dotted.key>` deletes a flat top-level key of the same
|
||||
literal name** ([#6578](https://github.com/gastownhall/beads/pull/6578)).
|
||||
Dotted keys are now written as a nested mapping (see **Fixed** below for why),
|
||||
and where the file already carried the flat spelling — a top-level key whose
|
||||
*name* contains the dot, such as `dolt.host: "10.0.0.1"` — that entry is
|
||||
removed and the value re-emitted under `dolt:`. Only the key being written is
|
||||
touched; other dotted keys, including ones bd did not write, are left exactly
|
||||
as they are.
|
||||
|
||||
`.beads/config.yaml` is not exclusively bd's, so this can be visible outside
|
||||
bd: an external tool that both writes *and* reads flat dotted keys there will
|
||||
stop seeing any value bd migrates this way. Any dotted key bd stores in
|
||||
`config.yaml` rather than the database can collide; in practice that means
|
||||
`dolt.*`, `export.auto`, and `backup.enabled`. If the other writer then
|
||||
re-adds its flat key, the file carries both spellings and bd's own readers
|
||||
disagree — Viper-backed reads (`bd config get`, and the `dolt.auto-start`
|
||||
lookup on the store-open path) return the **flat** value, while
|
||||
`GetStringFromDir` returns the **nested** one, so a `bd config set` can be
|
||||
shadowed by a stale flat entry. Tracked as
|
||||
[#6594](https://github.com/gastownhall/beads/issues/6594). Until that lands,
|
||||
in a workspace whose config another tool maintains, let that tool own its
|
||||
keys, or check `.beads/config.yaml` for a duplicated key after running
|
||||
`bd config set`.
|
||||
|
||||
- **Two `bd config set` writes that used to exit 0 now exit 1**
|
||||
([#6578](https://github.com/gastownhall/beads/pull/6578)), because both wrote
|
||||
a value no reader could see: setting a dotted key under a parent that already
|
||||
holds a scalar (`sync: enabled`, then `bd config set sync.remote`), and
|
||||
setting one in a file whose top level is not a mapping. A script that
|
||||
tolerated the old exit 0 now has to handle the failure.
|
||||
|
||||
### Fixed
|
||||
|
||||
- **`bd dolt start` no longer puts a second sql-server over a proxied
|
||||
workspace's data directory.** On a proxied-server workspace the default root
|
||||
IS `.beads/dolt`, and `bd dolt start` knew nothing about proxied mode: with
|
||||
the proxy quiesced it launched an unsupervised `dolt sql-server` directly
|
||||
over that root, after which ordinary bd commands failed (`invalid
|
||||
connection`) because the relaunched proxy found a foreign server on its
|
||||
port; with the proxy live it instead adopted the proxy's own dolt child into
|
||||
bd's classic PID/port records, leaving two managers for one process. It is
|
||||
now a typed refusal with code `proxy.dolt_start.conflict`. The proxy owns
|
||||
its backend's lifecycle — it starts on demand and `bd dolt stop` shuts it
|
||||
down. Direct-server and embedded workspaces are unaffected.
|
||||
|
||||
- **`bd dolt status` tells the truth on a proxied workspace.** It read the
|
||||
classic PID file, which proxied mode never writes, and so reported `Dolt
|
||||
server: not running` while the proxy was serving CRUD — the wrong answer
|
||||
that sent operators to `bd dolt start` in the first place. It now reads the
|
||||
proxy's own records and reports the proxy and its dolt backend separately,
|
||||
without starting either. The `--json` payload changes shape to carry that —
|
||||
see **Changed** above before parsing it.
|
||||
|
||||
- **A dotted config key now round-trips: what `bd config set` writes,
|
||||
`bd config get` and bd's own readers find**
|
||||
([#6578](https://github.com/gastownhall/beads/pull/6578), bd-zj95). Setting a
|
||||
key like `sync.remote` or `dolt.host` into a `config.yaml` with no matching
|
||||
section appended a key whose *name* contained the dot — a top-level
|
||||
`sync.remote: "..."` — instead of nesting it under `sync:`. Viper finds a key
|
||||
spelled that way; the direct reader `GetStringFromDir` splits on the dot and
|
||||
walks nested mappings, so it does not. The value was set and invisible at the
|
||||
same time depending on which reader asked, and `bd init --remote` in a fresh
|
||||
workspace was the ordinary way in: the remote was recorded and then not found.
|
||||
Dotted keys are written nested now, and `bd config unset` removes the nested
|
||||
form — it only ever matched the flat spelling, so unsetting
|
||||
`sync.remote` silently left the remote live. Keys the write does not own,
|
||||
including dotted ones somebody else put there, are left exactly as they are.
|
||||
Two consequences of the nested write — the flat-key migration and two new
|
||||
failure exits — are under **Changed** above.
|
||||
|
||||
## [1.3.0] - 2026-09-15
|
||||
|
||||
The first tested release off `main` since the 1.1 line. [1.2.2] was a recovery
|
||||
|
|
|
|||
|
|
@ -385,27 +385,28 @@ func testAuditReadyTypeAndPinnedExclusions(t *testing.T, f Factory) {
|
|||
// Statuses, the legacy open/in_progress default when both are empty, and a
|
||||
// custom (non-built-in) status flowing through the same IN clause.
|
||||
//
|
||||
// THIS IS THE ONLY OBSERVER OF THE OR-SET ARM, AND IT COVERS EVERY SEAM THE ARM
|
||||
// IS REACHABLE FROM. No role can ask for it — publicops.ReadyRequest carries no
|
||||
// status field of any kind, which RunReadyCounterCountsOnlyTheOpenRowsItsListingLists
|
||||
// says from the other side — and no in-tree caller sets it either. Every builder
|
||||
// that renders a ready query sends the SINGULAR status: workapi.BuildReadyFilter
|
||||
// and BuildReadyCountFilter send StatusOpen, and ReadyFilterFromIssueFilter sends
|
||||
// StatusOpen while dropping IssueFilter.Statuses, which BuildListFilter has
|
||||
// already resolved to open under --ready (issueops/reader_ready_scope.go states
|
||||
// that override and why the projection has nothing to drop). What is left is the
|
||||
// storage seam this file runs against, which backend.DoltStorage publishes to
|
||||
// out-of-tree backends — so Statuses is a public filter field whose only reachable
|
||||
// consumer class is exactly the one RunAll is the proof obligation for.
|
||||
// THE OR-SET ARM IS REACHABLE FROM `bd list --status a,b --ready`.
|
||||
// ReadyFilterFromIssueFilter copies IssueFilter.Statuses onto the ready-work
|
||||
// filter instead of dropping it, and BuildListFilter no longer always
|
||||
// resolves --ready to open: an explicit selector is the intersection
|
||||
// (GH#5832; issueops/reader_ready_scope.go states the honor path).
|
||||
// publicops.ReadyRequest still carries no status field of any kind, which
|
||||
// RunReadyCounterCountsOnlyTheOpenRowsItsListingLists says from the other
|
||||
// side, so `bd ready` — workapi.BuildReadyFilter and BuildReadyCountFilter —
|
||||
// still send the SINGULAR StatusOpen. The list --ready path is the in-tree
|
||||
// caller that sets Statuses. This file remains the storage-seam observer
|
||||
// for the OR-set arm against backend.DoltStorage, which publishes the field
|
||||
// to out-of-tree backends; RunAll is still the proof obligation for that
|
||||
// seam.
|
||||
//
|
||||
// The unit-of-work provider's ready union renders this arm from the same shared
|
||||
// builder (sqlbuild.BuildReadyWorkWhere), applied to the wisps table as well as
|
||||
// issues where the classic stack projects the wisp plane onto a types.IssueFilter
|
||||
// instead. Its copy is deliberately unpinned rather than overlooked: that provider
|
||||
// is not a storage.DoltStorage, so no external caller reaches it, and no in-tree
|
||||
// caller sets Statuses at all. Promoting a status set onto ReadyRequest is what
|
||||
// would make it reachable, and would move this case to reader_contract.go beside
|
||||
// RunReaderReadySetOwnsItsStatusPinnedAndTemplateDecisions, where all three
|
||||
// is not a storage.DoltStorage, so no external caller reaches it. A status set on
|
||||
// ReadyRequest would additionally make `bd ready` vote on this case, and would
|
||||
// move it to reader_contract.go beside
|
||||
// RunReaderReadySetOwnsItsStatusPinnedAndTemplateDecisions, where the ready-role
|
||||
// wirings would vote on it.
|
||||
func testAuditReadyMultiStatusFilter(t *testing.T, f Factory) {
|
||||
s := f(t)
|
||||
|
|
|
|||
|
|
@ -637,6 +637,12 @@ var roleContractCases = []roleContract{
|
|||
RunSweeperEmptyMatchIsZeroAndNil,
|
||||
RunSweeperRecordsExactlyOneHistoryEntry,
|
||||
RunSweeperDoesNotMutateTheCallerRequest,
|
||||
RunSweeperWispsPlaneClearsTheWholeWispsTable,
|
||||
RunSweeperWispsPlaneRequiresAFilter,
|
||||
RunSweeperProtectsLiveDependents,
|
||||
RunSweeperProtectsTransitiveLiveDependents,
|
||||
RunSweeperProtectsLiveDependentsAcrossPlanes,
|
||||
RunSweeperLimitTakesTheOldestClosedFirst,
|
||||
),
|
||||
|
||||
roleCases("TreeWalker", "TreeWalker()", oncePerRole,
|
||||
|
|
|
|||
|
|
@ -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,273 @@ 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)
|
||||
}
|
||||
|
||||
// RunSweeperProtectsTransitiveLiveDependents pins that protection propagates
|
||||
// through closed candidates: an open grandchild keeps both its closed parent
|
||||
// and closed grandparent. Otherwise sweeping the grandparent orphans a live
|
||||
// hierarchy even though the direct parent was correctly retained.
|
||||
func RunSweeperProtectsTransitiveLiveDependents(t *testing.T, ctx context.Context, fixture SweeperFixture) {
|
||||
t.Helper()
|
||||
if fixture.AddDependencies == nil {
|
||||
t.Skip("fixture has no AddDependencies hook; cannot wire the hierarchy this case needs")
|
||||
}
|
||||
root := sweeperSeed(t, ctx, fixture, sweeperIssue(fixture, "transitive", "root", true), nil)
|
||||
middle := sweeperSeed(t, ctx, fixture, sweeperIssue(fixture, "transitive", "middle", true), nil)
|
||||
leafIssue := sweeperIssue(fixture, "transitive", "leaf", true)
|
||||
leafIssue.Status = types.StatusOpen
|
||||
leafIssue.ClosedAt = nil
|
||||
leaf := sweeperSeed(t, ctx, fixture, leafIssue, nil)
|
||||
|
||||
if err := fixture.AddDependencies(ctx, publicops.AddDependenciesRequest{
|
||||
Actor: "sweeper-seed",
|
||||
Edges: []publicops.DependencyEdge{
|
||||
{IssueID: middle, DependsOnID: root, Type: publicops.DepParentChild},
|
||||
{IssueID: leaf, DependsOnID: middle, Type: publicops.DepParentChild},
|
||||
},
|
||||
}); err != nil {
|
||||
t.Fatalf("wiring transitive hierarchy: %v", err)
|
||||
}
|
||||
|
||||
request := publicops.SweepRequest{
|
||||
Tier: publicops.SweepWispsPlane,
|
||||
IDPattern: sweeperPattern(fixture, "transitive"),
|
||||
ClosedBefore: &sweeperCutoff,
|
||||
ProtectLiveDependents: true,
|
||||
}
|
||||
preview := sweeperSweep(t, ctx, fixture, sweeperAsDryRun(request))
|
||||
if preview.Swept != 0 || preview.Skipped.LiveDependent != 2 {
|
||||
t.Fatalf("dry run: Swept = %d, LiveDependent = %d; want 0 and 2", preview.Swept, preview.Skipped.LiveDependent)
|
||||
}
|
||||
result := sweeperSweep(t, ctx, fixture, request)
|
||||
if result.Swept != 0 || result.Skipped.LiveDependent != 2 {
|
||||
t.Fatalf("sweep: Swept = %d, LiveDependent = %d; want 0 and 2", result.Swept, result.Skipped.LiveDependent)
|
||||
}
|
||||
sweeperAssertWispRows(t, ctx, fixture, 3, root, middle, leaf)
|
||||
}
|
||||
|
||||
// RunSweeperProtectsLiveDependentsAcrossPlanes pins that the live-dependent
|
||||
// protection reads BOTH dependency tables: a closed wisp that a live DURABLE
|
||||
// (issues-table) bead depends on through parent-child, tracks or blocks is
|
||||
// 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 +936,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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,12 @@ Auto-backup default:
|
|||
dir and full-sync the whole database — a self-amplifying storm. To back up
|
||||
a shared server, run 'bd backup' explicitly (or set backup.enabled=true and
|
||||
coordinate destinations). 'bd config get backup.enabled' shows the effective
|
||||
value and its source.`,
|
||||
value and its source.
|
||||
|
||||
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",
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +61,9 @@ func newBackupStatusCommand(sizeDatabase backupSizeFunc) *cobra.Command {
|
|||
SilenceErrors: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if usesProxiedServer() {
|
||||
return HandleErrorRespectJSON("backup status is not supported in proxied-server mode")
|
||||
if err := requireLocalProxiedBackup("backup status"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
evt := metrics.NewCommandEvent("backup-status")
|
||||
defer func() {
|
||||
|
|
@ -124,14 +131,9 @@ func newBackupStatusCommand(sizeDatabase backupSizeFunc) *cobra.Command {
|
|||
// Show config (effective values with source)
|
||||
enabled := isBackupAutoEnabled()
|
||||
interval := config.GetDuration("backup.interval")
|
||||
enabledSource := config.GetValueSource("backup.enabled")
|
||||
enabledNote := ""
|
||||
if enabledSource == config.SourceDefault {
|
||||
if enabled {
|
||||
enabledNote = " (auto: git remote detected)"
|
||||
} else {
|
||||
enabledNote = " (auto: no git remote)"
|
||||
}
|
||||
if note := backupAutoStatusNote(enabled); note != "" {
|
||||
enabledNote = " (" + note + ")"
|
||||
}
|
||||
fmt.Printf("\nConfig: enabled=%v%s interval=%s\n",
|
||||
enabled, enabledNote, interval)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
|
@ -40,6 +41,36 @@ func isBackupAutoEnabled() bool {
|
|||
return primeHasGitRemote()
|
||||
}
|
||||
|
||||
// backupAutoStatusNote returns the parenthetical `bd backup status`
|
||||
// prints after the effective backup.enabled value, or "" when the value
|
||||
// speaks for itself. Callers pass the value isBackupAutoEnabled()
|
||||
// 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. 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 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"
|
||||
}
|
||||
if enabled {
|
||||
return "auto: git remote detected"
|
||||
}
|
||||
return "auto: no git remote"
|
||||
}
|
||||
|
||||
// clientServerShareFilesystem reports whether the configured Dolt
|
||||
// server runs on a filesystem the bd client can also see — i.e.
|
||||
// whether a file:// URL constructed on the client is meaningful to
|
||||
|
|
@ -88,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) {
|
||||
|
|
@ -102,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
|
||||
}
|
||||
|
||||
|
|
@ -115,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,
|
||||
|
|
@ -153,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
|
||||
|
|
@ -163,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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -123,6 +123,147 @@ func TestIsBackupAutoEnabled(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestBackupAutoStatusNote pins the reason `bd backup status` prints beside
|
||||
// the effective backup.enabled value against the reason isBackupAutoEnabled
|
||||
// actually used — the two are computed in different files and drifted apart
|
||||
// once already.
|
||||
//
|
||||
// The regression this locks down arrived with the proxied-parity S3 slice
|
||||
// (PR #6584): honoring the backup family on managed-local made `bd backup
|
||||
// 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. 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.
|
||||
func TestBackupAutoStatusNote(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
envVal string // "\x00" = not set, otherwise explicit backup.enabled
|
||||
hasRemote bool
|
||||
sharedServer bool // BEADS_DOLT_SHARED_SERVER=1 → usesSQLServer() true
|
||||
proxied bool // proxiedServerMode → usesProxiedServer() true
|
||||
wantEnabled bool
|
||||
wantNote string
|
||||
}{
|
||||
{
|
||||
name: "embedded default + git remote → unchanged",
|
||||
envVal: "\x00",
|
||||
hasRemote: true,
|
||||
wantEnabled: true,
|
||||
wantNote: "auto: git remote detected",
|
||||
},
|
||||
{
|
||||
name: "embedded default + no git remote → unchanged",
|
||||
envVal: "\x00",
|
||||
hasRemote: false,
|
||||
wantEnabled: false,
|
||||
wantNote: "auto: no git remote",
|
||||
},
|
||||
{
|
||||
name: "embedded explicit → no note, the source explains it",
|
||||
envVal: "true",
|
||||
hasRemote: false,
|
||||
wantEnabled: true,
|
||||
wantNote: "",
|
||||
},
|
||||
{
|
||||
// Pre-fix this case printed "auto: no git remote" even with a
|
||||
// remote configured: server mode, not the remote, is the reason.
|
||||
name: "sql-server default + git remote → server mode, not the remote",
|
||||
envVal: "\x00",
|
||||
hasRemote: true,
|
||||
sharedServer: true,
|
||||
wantEnabled: false,
|
||||
wantNote: "auto: off in sql-server mode",
|
||||
},
|
||||
{
|
||||
// Non-proxied server mode keeps its post-run hook, so an explicit
|
||||
// opt-in really does work there and needs no caveat.
|
||||
name: "sql-server explicit opt-in → no note",
|
||||
envVal: "true",
|
||||
hasRemote: false,
|
||||
sharedServer: true,
|
||||
wantEnabled: true,
|
||||
wantNote: "",
|
||||
},
|
||||
{
|
||||
// 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: off in proxied-server mode; set backup.enabled=true to opt in",
|
||||
},
|
||||
{
|
||||
// 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: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Same isolation as TestIsBackupAutoEnabled: a leaked BEADS_DIR or
|
||||
// a cwd inside the repo tree lets Initialize() load an ambient
|
||||
// config.yaml whose explicit backup.enabled wins over the computed
|
||||
// default these cases assert on (be-yjp4z).
|
||||
t.Chdir(t.TempDir())
|
||||
t.Setenv("BEADS_DIR", "")
|
||||
t.Setenv("BEADS_TEST_IGNORE_REPO_CONFIG", "1")
|
||||
|
||||
orig := primeHasGitRemote
|
||||
primeHasGitRemote = func() bool { return tt.hasRemote }
|
||||
t.Cleanup(func() { primeHasGitRemote = orig })
|
||||
|
||||
origProxied := proxiedServerMode
|
||||
proxiedServerMode = tt.proxied
|
||||
t.Cleanup(func() { proxiedServerMode = origProxied })
|
||||
|
||||
if tt.sharedServer {
|
||||
t.Setenv("BEADS_DOLT_SHARED_SERVER", "1")
|
||||
} else {
|
||||
os.Unsetenv("BEADS_DOLT_SHARED_SERVER")
|
||||
t.Cleanup(func() { os.Unsetenv("BEADS_DOLT_SHARED_SERVER") })
|
||||
}
|
||||
|
||||
if tt.envVal == "\x00" {
|
||||
os.Unsetenv("BD_BACKUP_ENABLED")
|
||||
t.Cleanup(func() { os.Unsetenv("BD_BACKUP_ENABLED") })
|
||||
} else {
|
||||
t.Setenv("BD_BACKUP_ENABLED", tt.envVal)
|
||||
}
|
||||
|
||||
config.ResetForTesting()
|
||||
t.Cleanup(func() { config.ResetForTesting() })
|
||||
if err := config.Initialize(); err != nil {
|
||||
t.Fatalf("config.Initialize: %v", err)
|
||||
}
|
||||
|
||||
// Take the value the way backup status does, so the note is pinned
|
||||
// against the number it is printed beside rather than a literal.
|
||||
enabled := isBackupAutoEnabled()
|
||||
if enabled != tt.wantEnabled {
|
||||
t.Fatalf("isBackupAutoEnabled() = %v, want %v", enabled, tt.wantEnabled)
|
||||
}
|
||||
if got := backupAutoStatusNote(enabled); got != tt.wantNote {
|
||||
t.Errorf("backupAutoStatusNote(%v) = %q, want %q", enabled, got, tt.wantNote)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestClientServerShareFilesystem_GH3523 pins the gating logic that
|
||||
// suppresses auto-backup's file:// register when the Dolt server
|
||||
// runs on a different filesystem from the client. Pre-fix every
|
||||
|
|
|
|||
|
|
@ -46,10 +46,13 @@ DoltHub (recommended for cloud backup):
|
|||
|
||||
After adding, run 'bd backup sync' to push your data.`,
|
||||
Args: cobra.ExactArgs(1),
|
||||
// As on `backup status`: the failures here are configuration and I/O
|
||||
// errors, not usage errors, and cobra's default prints the message, then
|
||||
// "Error: exit code 1", then the whole usage block — three things where one
|
||||
// was wanted, and on --json it lands after the JSON object.
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if usesProxiedServer() {
|
||||
return HandleErrorRespectJSON("backup init is not supported in proxied-server mode")
|
||||
}
|
||||
evt := metrics.NewCommandEvent("backup-init")
|
||||
defer func() {
|
||||
if c := metrics.Global(); c != nil {
|
||||
|
|
@ -60,6 +63,10 @@ After adding, run 'bd backup sync' to push your data.`,
|
|||
ctx := rootCtx
|
||||
rawPath := args[0]
|
||||
|
||||
if usesProxiedServer() {
|
||||
return runBackupInitProxied(ctx, rawPath)
|
||||
}
|
||||
|
||||
if store == nil {
|
||||
return fmt.Errorf("no store available")
|
||||
}
|
||||
|
|
@ -124,10 +131,9 @@ backup location configured with 'bd backup init'.
|
|||
The backup is atomic — if the sync fails, the previous backup state is preserved.
|
||||
|
||||
Run 'bd backup init <path>' first to configure a destination.`,
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if usesProxiedServer() {
|
||||
return HandleErrorRespectJSON("backup sync is not supported in proxied-server mode")
|
||||
}
|
||||
evt := metrics.NewCommandEvent("backup-sync")
|
||||
defer func() {
|
||||
if c := metrics.Global(); c != nil {
|
||||
|
|
@ -136,6 +142,23 @@ 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)
|
||||
}
|
||||
if store == nil {
|
||||
return fmt.Errorf("no store available")
|
||||
}
|
||||
|
|
@ -358,7 +381,14 @@ func showDoltBackupStatusJSON() map[string]interface{} {
|
|||
// doltBackupSize returns the active database size when the current store
|
||||
// instance can measure its storage locally. Unsupported backends preserve the
|
||||
// optional status-field contract instead of failing the command.
|
||||
//
|
||||
// Proxied mode has no store to ask — the provider owns the connection — so the
|
||||
// fork lives here, where "which backend measures this database" is already the
|
||||
// question being answered.
|
||||
func doltBackupSize(ctx context.Context) (int64, bool, error) {
|
||||
if usesProxiedServer() {
|
||||
return doltBackupSizeProxied(ctx)
|
||||
}
|
||||
if store == nil {
|
||||
return 0, false, fmt.Errorf("no storage backend is open")
|
||||
}
|
||||
|
|
@ -405,11 +435,10 @@ var backupRemoveCmd = &cobra.Command{
|
|||
|
||||
This unregisters the backup remote from Dolt and removes the local
|
||||
backup configuration. The backup data at the destination is not deleted.`,
|
||||
Aliases: []string{"rm"},
|
||||
Aliases: []string{"rm"},
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if usesProxiedServer() {
|
||||
return HandleErrorRespectJSON("backup remove is not supported in proxied-server mode")
|
||||
}
|
||||
evt := metrics.NewCommandEvent("backup-remove")
|
||||
defer func() {
|
||||
if c := metrics.Global(); c != nil {
|
||||
|
|
@ -418,6 +447,9 @@ backup configuration. The backup data at the destination is not deleted.`,
|
|||
}()
|
||||
|
||||
ctx := rootCtx
|
||||
if usesProxiedServer() {
|
||||
return runBackupRemoveProxied(ctx)
|
||||
}
|
||||
if store == nil {
|
||||
return fmt.Errorf("no store available")
|
||||
}
|
||||
|
|
@ -435,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
|
||||
|
|
@ -135,24 +161,23 @@ func runBackupExport(ctx context.Context, force bool) (*backupState, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// Read the watermark before the sync. A concurrent commit may land while
|
||||
// BackupToDir is running; recording a later HEAD would claim that commit is
|
||||
// present in a snapshot that started before it existed.
|
||||
currentCommit, err := backend.CurrentCommit(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get current commit: %w", err)
|
||||
}
|
||||
|
||||
// Change detection: skip if nothing changed (unless forced)
|
||||
if !force {
|
||||
currentCommit, err := store.GetCurrentCommit(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get current commit: %w", err)
|
||||
}
|
||||
if currentCommit == state.LastDoltCommit && state.LastDoltCommit != "" {
|
||||
debug.Logf("backup: no changes since last backup (commit %s)\n", truncateHash(currentCommit))
|
||||
return state, nil
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
|
@ -169,11 +194,8 @@ func runBackupExport(ctx context.Context, force bool) (*backupState, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// Update watermarks
|
||||
currentCommit, err := store.GetCurrentCommit(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get current commit for state: %w", err)
|
||||
}
|
||||
// The pre-sync commit is the newest commit this backup is guaranteed to
|
||||
// contain. If HEAD moved during the sync, the next backup must see it.
|
||||
state.LastDoltCommit = currentCommit
|
||||
state.Timestamp = time.Now().UTC()
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
55
cmd/bd/backup_export_watermark_test.go
Normal file
55
cmd/bd/backup_export_watermark_test.go
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/config"
|
||||
)
|
||||
|
||||
type advancingBackupBackend struct {
|
||||
commit string
|
||||
backupCommit string
|
||||
commitAfterSync string
|
||||
}
|
||||
|
||||
func (b *advancingBackupBackend) CurrentCommit(context.Context) (string, error) {
|
||||
return b.commit, nil
|
||||
}
|
||||
|
||||
func (b *advancingBackupBackend) BackupToDir(context.Context, string) error {
|
||||
b.backupCommit = b.commit
|
||||
b.commit = b.commitAfterSync
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestRunBackupExportWatermarkDoesNotAdvancePastSnapshot(t *testing.T) {
|
||||
for _, force := range []bool{false, true} {
|
||||
t.Run(map[bool]string{false: "changed", true: "forced"}[force], func(t *testing.T) {
|
||||
repo := t.TempDir()
|
||||
if err := os.MkdirAll(filepath.Join(repo, ".git"), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv("BD_BACKUP_GIT_REPO", repo)
|
||||
config.ResetForTesting()
|
||||
t.Cleanup(config.ResetForTesting)
|
||||
if err := config.Initialize(); err != nil {
|
||||
t.Fatalf("config.Initialize: %v", err)
|
||||
}
|
||||
|
||||
backend := &advancingBackupBackend{commit: "head-before-sync", commitAfterSync: "head-after-sync"}
|
||||
state, err := runBackupExport(context.Background(), backend, force)
|
||||
if err != nil {
|
||||
t.Fatalf("runBackupExport: %v", err)
|
||||
}
|
||||
if backend.backupCommit != "head-before-sync" {
|
||||
t.Fatalf("backup captured %q, want head-before-sync", backend.backupCommit)
|
||||
}
|
||||
if state.LastDoltCommit != backend.backupCommit {
|
||||
t.Fatalf("watermark = %q, backup captured %q; a commit that landed during sync must remain pending", state.LastDoltCommit, backend.backupCommit)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
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])
|
||||
}
|
||||
107
cmd/bd/backup_proxied_external_integration_test.go
Normal file
107
cmd/bd/backup_proxied_external_integration_test.go
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
//go:build cgo
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage/dbproxy/proxy"
|
||||
"github.com/steveyegge/beads/internal/storage/dbproxy/server"
|
||||
)
|
||||
|
||||
// TestProxiedServerBackupRefusedOnExternalTopology is the other half of slice
|
||||
// S3: the backup family is honored on managed-local and refused BY DESIGN
|
||||
// against a Dolt server bd does not own.
|
||||
//
|
||||
// The refusal matters more than the capability. `CALL DOLT_BACKUP('add', …)`
|
||||
// registers the remote on the server, where it is global to every client of
|
||||
// that server, so one workspace's backup decision becomes everyone's. With a
|
||||
// file:/// destination there is a second problem on top: the server resolves
|
||||
// that path on its own filesystem, so honoring it here would either fail at the
|
||||
// point of use or write the backup to a directory on the server's host that the
|
||||
// operator asking for it will never look in. The second outcome is worse than
|
||||
// any refusal.
|
||||
//
|
||||
// Named TestProxiedServer* so .github/scripts/proxied-test-shard.sh runs it in
|
||||
// the external lane, which is the only one with an external Dolt server.
|
||||
func TestProxiedServerBackupRefusedOnExternalTopology(t *testing.T) {
|
||||
requireProxiedServerEnv(t)
|
||||
|
||||
bd := buildEmbeddedBD(t)
|
||||
p := newSharedProxiedProject(t, bd, "bkext")
|
||||
dest := filepath.Join(t.TempDir(), "dolt-backup")
|
||||
|
||||
// Refusals are decided before the provider is constructed, so take the
|
||||
// topology down first: a pidfile appearing during one of these commands
|
||||
// would mean the refusal came too late to have cost nothing.
|
||||
if err := proxy.Shutdown(p.proxyRoot); err != nil {
|
||||
t.Logf("proxy.Shutdown(%s) before the refusal probes: %v", p.proxyRoot, err)
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
args []string
|
||||
}{
|
||||
{"status", []string{"backup", "status"}},
|
||||
{"init", []string{"backup", "init", dest}},
|
||||
{"sync", []string{"backup", "sync"}},
|
||||
{"remove", []string{"backup", "remove"}},
|
||||
{"restore", []string{"backup", "restore", dest}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
args := append([]string{"--json"}, tc.args...)
|
||||
out, err := bdProxiedRun(t, bd, p.dir, args...)
|
||||
if err == nil {
|
||||
t.Fatalf("bd %s succeeded on an external proxied topology:\n%s",
|
||||
strings.Join(tc.args, " "), out)
|
||||
}
|
||||
|
||||
var refusal struct {
|
||||
Code string `json:"code"`
|
||||
Error string `json:"error"`
|
||||
Mutates bool `json:"mutates"`
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
start := strings.Index(string(out), "{")
|
||||
if start < 0 {
|
||||
t.Fatalf("no typed refusal JSON:\n%s", out)
|
||||
}
|
||||
if err := json.Unmarshal(out[start:], &refusal); err != nil {
|
||||
t.Fatalf("parse refusal JSON: %v\n%s", err, out)
|
||||
}
|
||||
if refusal.Code != "proxy.backup.unsupported" {
|
||||
t.Errorf("code = %q, want proxy.backup.unsupported", refusal.Code)
|
||||
}
|
||||
if refusal.Mutates {
|
||||
t.Errorf("refusal reported mutates=true")
|
||||
}
|
||||
// design, not unimplemented: no later slice is going to lift this.
|
||||
if refusal.Reason != string(ProxyReasonDesign) {
|
||||
t.Errorf("reason = %q, want design", refusal.Reason)
|
||||
}
|
||||
// The reason has to be the one that is true of every destination
|
||||
// scheme. "resolved on the server's filesystem" is a file://
|
||||
// property, and `bd backup init` also takes https/aws/gs.
|
||||
if !strings.Contains(refusal.Error, "the backup remote is registered on the server, where it is global to every client") {
|
||||
t.Errorf("refusal message does not say why: %q", refusal.Error)
|
||||
}
|
||||
|
||||
// Nothing was started and nothing was written: the refusal is free.
|
||||
for _, name := range []string{proxy.PIDFileName, server.PIDFileName} {
|
||||
if _, err := os.Stat(filepath.Join(p.proxyRoot, name)); err == nil {
|
||||
t.Errorf("a refused backup command started the topology (%s)", name)
|
||||
}
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(p.beadsDir, "dolt-backup.json")); err == nil {
|
||||
t.Errorf("a refused backup command wrote the local backup config")
|
||||
}
|
||||
if _, err := os.Stat(dest); err == nil {
|
||||
t.Errorf("a refused backup command created %s", dest)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
208
cmd/bd/backup_proxied_local_integration_test.go
Normal file
208
cmd/bd/backup_proxied_local_integration_test.go
Normal file
|
|
@ -0,0 +1,208 @@
|
|||
//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/storage/versioncontrolops"
|
||||
)
|
||||
|
||||
// TestManagedLocalProxiedBackupRoundTrip is the claim slice S3 makes: a
|
||||
// managed-local proxied workspace can take a Dolt-native backup and get its
|
||||
// data back from it.
|
||||
//
|
||||
// It is deliberately a ROUND TRIP rather than a pair of exit-code assertions.
|
||||
// A backup command that reports success without producing a restorable
|
||||
// artifact is the failure that matters here, and the only way to rule it out is
|
||||
// to restore the artifact and look at the issues that come back: the issue
|
||||
// created BEFORE the backup must survive, and the one created AFTER it must be
|
||||
// gone. Both directions are load-bearing — a restore that changed nothing would
|
||||
// pass the first check alone.
|
||||
//
|
||||
// Named TestManagedLocalProxied* so the proxied-local smoke lane
|
||||
// (.github/workflows/proxied-local-smoke.yml) runs it; that lane is the only
|
||||
// one that sets BEADS_TEST_PROXIED_LOCAL.
|
||||
func TestManagedLocalProxiedBackupRoundTrip(t *testing.T) {
|
||||
requireManagedLocalProxiedEnv(t)
|
||||
|
||||
bd := buildEmbeddedBD(t)
|
||||
p := bdManagedLocalInit(t, bd, "bkrt", 5*time.Minute)
|
||||
|
||||
before := bdProxiedCreate(t, bd, p.dir, "survives the restore", "-p", "1")
|
||||
|
||||
// Status first: it is the read-only probe that proves the route exists at
|
||||
// all, and it must answer with a real measured size rather than the
|
||||
// "optional field omitted" the external topologies produce.
|
||||
status := readProxiedBackupStatus(t, bd, p)
|
||||
if status.Dolt.Configured {
|
||||
t.Fatalf("fresh workspace reports a configured backup: %+v", status.Dolt)
|
||||
}
|
||||
if status.DatabaseSize.Bytes <= 0 {
|
||||
t.Fatalf("backup status measured no database: %+v", status.DatabaseSize)
|
||||
}
|
||||
|
||||
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 %s: %v\n%s", dest, err, out)
|
||||
}
|
||||
if out, err := bdProxiedRun(t, bd, p.dir, "backup", "sync"); err != nil {
|
||||
t.Fatalf("bd backup sync: %v\n%s", err, out)
|
||||
}
|
||||
// A Dolt backup is a chunk store with a manifest; an empty directory here
|
||||
// would mean the command reported a success it did not perform.
|
||||
if _, err := os.Stat(filepath.Join(dest, "manifest")); err != nil {
|
||||
t.Fatalf("backup sync produced no manifest at %s: %v", dest, err)
|
||||
}
|
||||
|
||||
after := bdProxiedCreate(t, bd, p.dir, "must not survive the restore", "-p", "1")
|
||||
|
||||
out, err := bdProxiedRun(t, bd, p.dir, "backup", "restore", dest, "--force", "--json")
|
||||
if err != nil {
|
||||
t.Fatalf("bd backup restore %s --force: %v\n%s", dest, err, out)
|
||||
}
|
||||
var result struct {
|
||||
Restored bool `json:"restored"`
|
||||
Source string `json:"source"`
|
||||
}
|
||||
if err := json.Unmarshal(out, &result); err != nil {
|
||||
t.Fatalf("parse restore JSON: %v\n%s", err, out)
|
||||
}
|
||||
if !result.Restored || result.Source != dest {
|
||||
t.Fatalf("unexpected restore result: %+v; want restored=true, source=%s", result, dest)
|
||||
}
|
||||
|
||||
// The restore quiesces the topology and leaves it down, so the next command
|
||||
// relaunches against the restored data. Assert that rather than assume it:
|
||||
// a restore that ran with the old server still up would be the undefined
|
||||
// case this design exists to avoid.
|
||||
for _, name := range []string{proxy.PIDFileName, server.PIDFileName} {
|
||||
if _, err := os.Stat(filepath.Join(p.proxyRoot, name)); err == nil {
|
||||
t.Fatalf("restore left %s in place; the topology should be quiescent afterwards", name)
|
||||
}
|
||||
}
|
||||
|
||||
issues := bdProxiedListJSON(t, bd, p)
|
||||
var ids []string
|
||||
for _, issue := range issues {
|
||||
ids = append(ids, issue.ID)
|
||||
}
|
||||
if !slices.Contains(ids, before.ID) {
|
||||
t.Fatalf("restore lost the issue the backup contained (%s); got %v", before.ID, ids)
|
||||
}
|
||||
if slices.Contains(ids, after.ID) {
|
||||
t.Fatalf("restore did not replace the database: %s was created after the backup and is still here; got %v",
|
||||
after.ID, ids)
|
||||
}
|
||||
|
||||
// The restore registers its source as the backup destination, so a plain
|
||||
// `bd backup sync` works straight afterwards with no second init.
|
||||
restored := readProxiedBackupStatus(t, bd, p)
|
||||
if !restored.Dolt.Configured || !strings.HasSuffix(restored.Dolt.BackupURL, dest) {
|
||||
t.Fatalf("restore did not register %s as the backup destination: %+v", dest, restored.Dolt)
|
||||
}
|
||||
if out, err := bdProxiedRun(t, bd, p.dir, "backup", "sync"); err != nil {
|
||||
t.Fatalf("bd backup sync after restore: %v\n%s", err, out)
|
||||
}
|
||||
|
||||
if out, err := bdProxiedRun(t, bd, p.dir, "backup", "remove"); err != nil {
|
||||
t.Fatalf("bd backup remove: %v\n%s", err, out)
|
||||
}
|
||||
removed := readProxiedBackupStatus(t, bd, p)
|
||||
if removed.Dolt.Configured {
|
||||
t.Fatalf("backup remove left the destination configured: %+v", removed.Dolt)
|
||||
}
|
||||
// Removing the destination unregisters the remote; it does not delete the
|
||||
// backup, which is what makes `bd backup remove` safe to run.
|
||||
if _, err := os.Stat(filepath.Join(dest, "manifest")); err != nil {
|
||||
t.Fatalf("backup remove deleted the backup data at %s: %v", dest, err)
|
||||
}
|
||||
if out, err := bdProxiedRun(t, bd, p.dir, "backup", "sync"); err == nil {
|
||||
t.Fatalf("bd backup sync succeeded with no destination configured:\n%s", out)
|
||||
}
|
||||
}
|
||||
|
||||
// A backup with a malformed migration table can replace the database but fail
|
||||
// the following provider construction at schema initialization. That failure must
|
||||
// still leave both processes down, even though no provider was returned.
|
||||
func TestManagedLocalProxiedBackupRestoreReopenFailure(t *testing.T) {
|
||||
requireManagedLocalProxiedEnv(t)
|
||||
bd := buildEmbeddedBD(t)
|
||||
p := bdManagedLocalInit(t, bd, "bkrf", 5*time.Minute)
|
||||
dest := filepath.Join(t.TempDir(), "malformed-backup")
|
||||
if out, err := bdProxiedRun(t, bd, p.dir, "backup", "init", dest); err != nil {
|
||||
t.Fatalf("backup init: %v\n%s", err, out)
|
||||
}
|
||||
|
||||
// Damage the migration table in the backup, then repair the live table so
|
||||
// the command's initial provider can open normally. Only its post-restore
|
||||
// constructor will see the malformed table and fail after starting Dolt.
|
||||
held := openHeldManagedProxiedConn(t, bd, p)
|
||||
ctx := context.Background()
|
||||
if _, err := held.Conn.ExecContext(ctx, "ALTER TABLE schema_migrations RENAME COLUMN version TO broken_version"); err != nil {
|
||||
t.Fatalf("damage migration table: %v", err)
|
||||
}
|
||||
if _, err := held.Conn.ExecContext(ctx, "CALL DOLT_COMMIT('-Am', 'Simulate a malformed migration table in the backup')"); err != nil {
|
||||
t.Fatalf("commit malformed migration table: %v", err)
|
||||
}
|
||||
if err := versioncontrolops.BackupSync(ctx, held.Conn, proxiedBackupTargetName); err != nil {
|
||||
t.Fatalf("back up malformed schema: %v", err)
|
||||
}
|
||||
if _, err := held.Conn.ExecContext(ctx, "ALTER TABLE schema_migrations RENAME COLUMN broken_version TO version"); err != nil {
|
||||
t.Fatalf("repair live migration table: %v", err)
|
||||
}
|
||||
held.Release()
|
||||
|
||||
out, err := bdProxiedRun(t, bd, p.dir, "backup", "restore", dest, "--force")
|
||||
if err == nil {
|
||||
t.Fatalf("restore unexpectedly reopened a malformed schema:\n%s", out)
|
||||
}
|
||||
if !strings.Contains(string(out), "the restored database did not reopen") || !strings.Contains(string(out), "schema") {
|
||||
t.Fatalf("expected post-restore schema initialization failure, got:\n%s", out)
|
||||
}
|
||||
if strings.Contains(string(out), "restored and reconciled") {
|
||||
t.Fatalf("failed reopen reported successful reconciliation:\n%s", out)
|
||||
}
|
||||
for _, name := range []string{proxy.PIDFileName, server.PIDFileName} {
|
||||
if _, err := os.Stat(filepath.Join(p.proxyRoot, name)); !os.IsNotExist(err) {
|
||||
t.Errorf("failed reopen should remove %s; stat error: %v", name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type proxiedBackupStatus struct {
|
||||
Dolt struct {
|
||||
Configured bool `json:"configured"`
|
||||
BackupURL string `json:"backup_url"`
|
||||
BackupName string `json:"backup_name"`
|
||||
} `json:"dolt"`
|
||||
DatabaseSize struct {
|
||||
Bytes int64 `json:"bytes"`
|
||||
} `json:"database_size"`
|
||||
}
|
||||
|
||||
func readProxiedBackupStatus(t *testing.T, bd string, p proxiedProject) proxiedBackupStatus {
|
||||
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 proxiedBackupStatus
|
||||
if err := json.Unmarshal(out[start:], &status); err != nil {
|
||||
t.Fatalf("parse backup status JSON: %v\n%s", err, out)
|
||||
}
|
||||
return status
|
||||
}
|
||||
285
cmd/bd/backup_proxied_policy_test.go
Normal file
285
cmd/bd/backup_proxied_policy_test.go
Normal file
|
|
@ -0,0 +1,285 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/configfile"
|
||||
)
|
||||
|
||||
// TestProxiedRestoreFailureMessage pins the one distinction the operator acts
|
||||
// on: whether the data came back. A teardown failure happens after the step
|
||||
// succeeded, so reporting it as "restore failed" is not a wording nit — it
|
||||
// tells someone whose database IS restored to restore it again.
|
||||
func TestProxiedRestoreFailureMessage(t *testing.T) {
|
||||
boom := errors.New("proxy shutdown: connection refused")
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
afterReconcile bool
|
||||
err error
|
||||
wantContains []string
|
||||
wantMissing []string
|
||||
}{
|
||||
{
|
||||
name: "restore itself failed",
|
||||
err: errors.New("DOLT_BACKUP: no such backup"),
|
||||
// No claim that anything was restored.
|
||||
wantContains: []string{"restore failed", "no such backup"},
|
||||
wantMissing: []string{"the data is restored"},
|
||||
},
|
||||
{
|
||||
name: "restore succeeded, teardown failed",
|
||||
err: &proxiedTeardownError{err: boom},
|
||||
wantContains: []string{"the data is restored", "bd dolt stop --force", "bd backup init"},
|
||||
wantMissing: []string{"restore failed"},
|
||||
},
|
||||
{
|
||||
name: "reconcile failed for real",
|
||||
afterReconcile: true,
|
||||
err: errors.New("open provider: schema is behind"),
|
||||
wantContains: []string{"the restored database did not reopen", "schema is behind"},
|
||||
wantMissing: []string{"restore failed"},
|
||||
},
|
||||
{
|
||||
name: "reconcile succeeded, teardown failed",
|
||||
afterReconcile: true,
|
||||
err: &proxiedTeardownError{err: boom},
|
||||
wantContains: []string{"the data is restored and reconciled", "bd dolt stop --force"},
|
||||
// Nothing left to re-register: the reconcile already ran.
|
||||
wantMissing: []string{"restore failed", "bd backup init"},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got := proxiedRestoreFailureMessage("/tmp/backup", tc.afterReconcile, tc.err)
|
||||
for _, want := range tc.wantContains {
|
||||
if !strings.Contains(got, want) {
|
||||
t.Errorf("message %q does not contain %q", got, want)
|
||||
}
|
||||
}
|
||||
for _, unwanted := range tc.wantMissing {
|
||||
if strings.Contains(got, unwanted) {
|
||||
t.Errorf("message %q must not contain %q", got, unwanted)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// backupFamilyPaths is every registry path the backup family owns. Keeping the
|
||||
// list in one place is what makes "the whole family moves together" an
|
||||
// assertion rather than a convention.
|
||||
var backupFamilyPaths = []string{
|
||||
"backup", "backup init", "backup sync", "backup remove", "backup status", "backup restore",
|
||||
}
|
||||
|
||||
// TestProxiedBackupHonoredOnlyOnManagedLocal is the locality policy.
|
||||
//
|
||||
// A Dolt backup destination is resolved by the SERVER: CALL DOLT_BACKUP('add',
|
||||
// name, 'file:///…') names a path on the machine running dolt, not on the
|
||||
// machine running bd. On managed-local that is the same machine and the same
|
||||
// user, because bd spawned the child itself. On every other proxied shape it is
|
||||
// somebody else's filesystem, so honoring the command would either fail at the
|
||||
// point of use or — much worse — succeed and write the backup somewhere the
|
||||
// operator cannot see. That is why these stay refused with Reason=design.
|
||||
func TestProxiedBackupHonoredOnlyOnManagedLocal(t *testing.T) {
|
||||
for _, path := range backupFamilyPaths {
|
||||
row, ok := LookupCapabilityRow(path, "")
|
||||
if !ok {
|
||||
t.Fatalf("%q has no registry row", path)
|
||||
}
|
||||
|
||||
if got := row.ruleFor(ProxyTopologyManagedLocal); got.Outcome != ProxyOutcomeHonored {
|
||||
t.Errorf("%q on managed-local: outcome %q, want honored", path, got.Outcome)
|
||||
}
|
||||
|
||||
for _, topology := range []ProxyTopology{
|
||||
ProxyTopologyExternalTCP, ProxyTopologyExternalUnix,
|
||||
ProxyTopologyTeamServer, ProxyTopologyUnknown,
|
||||
} {
|
||||
got := row.ruleFor(topology)
|
||||
if got.Outcome != ProxyOutcomeRefused {
|
||||
t.Errorf("%q on %s: outcome %q, want refused", path, topology, got.Outcome)
|
||||
}
|
||||
if got.Reason != ProxyReasonDesign {
|
||||
t.Errorf("%q on %s: reason %q, want design", path, topology, got.Reason)
|
||||
}
|
||||
if got.Code != "proxy.backup.unsupported" {
|
||||
t.Errorf("%q on %s: code %q, want the frozen proxy.backup.unsupported", path, topology, got.Code)
|
||||
}
|
||||
if !strings.Contains(got.Message, "is not supported in proxied-server mode") {
|
||||
t.Errorf("%q on %s: message %q dropped the frozen prefix", path, topology, got.Message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestProxiedBackupGateRefusesByTopology exercises the gate itself rather than
|
||||
// the table, so a row that is right while the validator ignores the topology
|
||||
// still fails.
|
||||
func TestProxiedBackupGateRefusesByTopology(t *testing.T) {
|
||||
newBackupCmd := func(sub string) *cobra.Command {
|
||||
root := &cobra.Command{Use: "bd"}
|
||||
parent := &cobra.Command{Use: "backup"}
|
||||
child := &cobra.Command{Use: sub}
|
||||
parent.AddCommand(child)
|
||||
root.AddCommand(parent)
|
||||
return child
|
||||
}
|
||||
|
||||
for _, sub := range []string{"init", "sync", "remove", "status", "restore"} {
|
||||
t.Run(sub, func(t *testing.T) {
|
||||
if err := validateProxyRegistryBeforeProvider(newBackupCmd(sub), ProxyTopologyManagedLocal); err != nil {
|
||||
t.Fatalf("managed-local: gate refused %q: %v", sub, err)
|
||||
}
|
||||
err := validateProxyRegistryBeforeProvider(newBackupCmd(sub), ProxyTopologyExternalTCP)
|
||||
if err == nil {
|
||||
t.Fatalf("external-tcp: gate permitted %q", sub)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestProxiedBackupRefusalJSONCarriesDesignReason pins what a consumer sees.
|
||||
// The three frozen fields are unchanged and reason now says "design", which is
|
||||
// the difference that matters: this refusal is not waiting on a later slice.
|
||||
func TestProxiedBackupRefusalJSONCarriesDesignReason(t *testing.T) {
|
||||
t.Setenv("BD_JSON_ENVELOPE", "")
|
||||
oldJSON := jsonOutput
|
||||
jsonOutput = true
|
||||
t.Cleanup(func() { jsonOutput = oldJSON })
|
||||
|
||||
root := &cobra.Command{Use: "bd"}
|
||||
parent := &cobra.Command{Use: "backup"}
|
||||
child := &cobra.Command{Use: "sync"}
|
||||
parent.AddCommand(child)
|
||||
root.AddCommand(parent)
|
||||
|
||||
out := captureStdout(t, func() error {
|
||||
_ = validateProxyRegistryBeforeProvider(child, ProxyTopologyExternalTCP)
|
||||
return nil
|
||||
})
|
||||
for _, want := range []string{
|
||||
`"code": "proxy.backup.unsupported"`,
|
||||
`"mutates": false`,
|
||||
`"reason": "design"`,
|
||||
} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Fatalf("refusal JSON missing %s:\n%s", want, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestResolveProxiedTopology covers the resolution the gate depends on. The
|
||||
// team-server case is the one worth reading twice: ownership beats transport,
|
||||
// because a bts-managed database is somebody else's store whether bd reaches it
|
||||
// over a socket, a port, or a child it spawned itself.
|
||||
func TestResolveProxiedTopology(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
cfg configfile.Config
|
||||
sidecar *configfile.ProxiedServerClientInfo
|
||||
rawCfg string // when set, written verbatim instead of cfg
|
||||
rawCar string // when set, written verbatim instead of sidecar
|
||||
want ProxyTopology
|
||||
}{
|
||||
{
|
||||
name: "managed local has no external block",
|
||||
cfg: configfile.Config{DoltMode: configfile.DoltModeProxiedServer},
|
||||
sidecar: &configfile.ProxiedServerClientInfo{},
|
||||
want: ProxyTopologyManagedLocal,
|
||||
},
|
||||
{
|
||||
name: "no sidecar at all is still managed local",
|
||||
cfg: configfile.Config{DoltMode: configfile.DoltModeProxiedServer},
|
||||
sidecar: nil,
|
||||
want: ProxyTopologyManagedLocal,
|
||||
},
|
||||
{
|
||||
name: "external host and port",
|
||||
cfg: configfile.Config{DoltMode: configfile.DoltModeProxiedServer},
|
||||
sidecar: &configfile.ProxiedServerClientInfo{
|
||||
External: &configfile.ExternalDoltConfig{Host: "db.example.com", Port: 3306},
|
||||
},
|
||||
want: ProxyTopologyExternalTCP,
|
||||
},
|
||||
{
|
||||
name: "external unix socket",
|
||||
cfg: configfile.Config{DoltMode: configfile.DoltModeProxiedServer},
|
||||
sidecar: &configfile.ProxiedServerClientInfo{
|
||||
External: &configfile.ExternalDoltConfig{Socket: "/var/run/dolt.sock"},
|
||||
},
|
||||
want: ProxyTopologyExternalUnix,
|
||||
},
|
||||
{
|
||||
name: "team server beats the transport",
|
||||
cfg: configfile.Config{DoltMode: configfile.DoltModeProxiedServer, DoltTeamServer: true},
|
||||
sidecar: &configfile.ProxiedServerClientInfo{
|
||||
External: &configfile.ExternalDoltConfig{Host: "bts.example.com", Port: 3306},
|
||||
},
|
||||
want: ProxyTopologyTeamServer,
|
||||
},
|
||||
{
|
||||
name: "team server on a local child is still team server",
|
||||
cfg: configfile.Config{DoltMode: configfile.DoltModeProxiedServer, DoltTeamServer: true},
|
||||
sidecar: &configfile.ProxiedServerClientInfo{},
|
||||
want: ProxyTopologyTeamServer,
|
||||
},
|
||||
{
|
||||
name: "unreadable sidecar fails closed",
|
||||
cfg: configfile.Config{DoltMode: configfile.DoltModeProxiedServer},
|
||||
rawCar: "{ not json",
|
||||
want: ProxyTopologyUnknown,
|
||||
},
|
||||
{
|
||||
name: "unreadable workspace config fails closed",
|
||||
rawCfg: "{ not json",
|
||||
want: ProxyTopologyUnknown,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
beadsDir := filepath.Join(t.TempDir(), ".beads")
|
||||
if err := os.MkdirAll(beadsDir, 0o750); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
switch {
|
||||
case tc.rawCfg != "":
|
||||
writeTestFile(t, configfile.ConfigPath(beadsDir), tc.rawCfg)
|
||||
default:
|
||||
cfg := tc.cfg
|
||||
cfg.Backend = configfile.BackendDolt
|
||||
data, err := json.Marshal(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeTestFile(t, configfile.ConfigPath(beadsDir), string(data))
|
||||
}
|
||||
switch {
|
||||
case tc.rawCar != "":
|
||||
writeTestFile(t, configfile.ProxiedServerClientInfoPath(beadsDir), tc.rawCar)
|
||||
case tc.sidecar != nil:
|
||||
data, err := json.Marshal(tc.sidecar)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeTestFile(t, configfile.ProxiedServerClientInfoPath(beadsDir), string(data))
|
||||
}
|
||||
|
||||
if got := resolveProxiedTopology(beadsDir); got != tc.want {
|
||||
t.Fatalf("resolveProxiedTopology = %q, want %q", got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func writeTestFile(t *testing.T, path, body string) {
|
||||
t.Helper()
|
||||
if err := os.WriteFile(path, []byte(body), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
542
cmd/bd/backup_proxied_server.go
Normal file
542
cmd/bd/backup_proxied_server.go
Normal file
|
|
@ -0,0 +1,542 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
"github.com/steveyegge/beads/internal/storage/uow"
|
||||
"github.com/steveyegge/beads/internal/storage/versioncontrolops"
|
||||
)
|
||||
|
||||
// Dolt-native backup over the proxied-server provider.
|
||||
//
|
||||
// The mechanism needed no proxy work at all: CALL DOLT_BACKUP(...) is ordinary
|
||||
// SQL, RunNonTx already hands out a raw pinned connection (the seam `compact
|
||||
// --dolt` and `gc` run on), the UOW DSN sets a connect timeout but no read
|
||||
// deadline, and an active connection keeps the idle reaper from arming — so a
|
||||
// backup that takes minutes is safe from both the driver and the 30s reaper.
|
||||
//
|
||||
// What the family DID need is the locality policy, which lives in the registry
|
||||
// (see capability_registry.go's backup rows) because it is what the front door
|
||||
// enforces. The guard below repeats it at the route because these functions are
|
||||
// reachable from RunE, and a route that trusts the gate is one refactor away
|
||||
// from writing a backup onto a host it does not own.
|
||||
//
|
||||
// None of these routes touch commandDidWrite or commandDidExplicitDoltCommit.
|
||||
// Those two drive the post-run Dolt auto-commit, which is an embedded/direct
|
||||
// concern — PersistentPostRunE's proxied branch never reads them — and the
|
||||
// other proxied routes leave them alone for the same reason.
|
||||
|
||||
// proxiedBackupTargetName is the Dolt backup remote bd registers. Same name the
|
||||
// direct path uses, so a workspace that changes topology still finds its
|
||||
// destination.
|
||||
const proxiedBackupTargetName = defaultDoltBackupName
|
||||
|
||||
// requireLocalProxiedBackup re-checks the locality policy at the route.
|
||||
// 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 {
|
||||
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)
|
||||
}
|
||||
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
|
||||
// ladder here would be a second answer waiting to disagree with it.
|
||||
func proxiedActiveDatabase(ctx context.Context) (string, error) {
|
||||
var database string
|
||||
err := runProxiedNonTx(ctx, func(ctx context.Context, conn *sql.Conn) error {
|
||||
var name sql.NullString
|
||||
if err := conn.QueryRowContext(ctx, "SELECT DATABASE()").Scan(&name); err != nil {
|
||||
return fmt.Errorf("resolve active database: %w", err)
|
||||
}
|
||||
if !name.Valid || name.String == "" {
|
||||
return fmt.Errorf("the proxied connection has no database selected")
|
||||
}
|
||||
database = name.String
|
||||
return nil
|
||||
})
|
||||
return database, err
|
||||
}
|
||||
|
||||
// runBackupInitProxied registers the backup destination, mirroring the direct
|
||||
// path's conflict handling: Dolt refuses a second remote at an address another
|
||||
// one already holds, and a re-init to a new path has to replace the old entry
|
||||
// rather than fail.
|
||||
func runBackupInitProxied(ctx context.Context, rawPath string) error {
|
||||
if err := requireLocalProxiedBackup("backup init"); err != nil {
|
||||
return err
|
||||
}
|
||||
backupURL := resolveDoltBackupURL(rawPath)
|
||||
|
||||
err := runProxiedNonTx(ctx, func(ctx context.Context, conn *sql.Conn) error {
|
||||
addErr := versioncontrolops.BackupAdd(ctx, conn, proxiedBackupTargetName, backupURL)
|
||||
if addErr == nil {
|
||||
return nil
|
||||
}
|
||||
switch {
|
||||
case strings.Contains(addErr.Error(), "already exists"):
|
||||
// Same name, different URL: replace it.
|
||||
_ = versioncontrolops.BackupRemove(ctx, conn, proxiedBackupTargetName)
|
||||
case versioncontrolops.ExtractAddressConflictName(addErr) != "":
|
||||
// A different name (auto-export registers "backup_export") already
|
||||
// points at this URL; take the address over.
|
||||
_ = versioncontrolops.BackupRemove(ctx, conn, versioncontrolops.ExtractAddressConflictName(addErr))
|
||||
default:
|
||||
return addErr
|
||||
}
|
||||
return versioncontrolops.BackupAdd(ctx, conn, proxiedBackupTargetName, backupURL)
|
||||
})
|
||||
if err != nil {
|
||||
return HandleErrorRespectJSON("failed to add backup destination: %v", err)
|
||||
}
|
||||
|
||||
if err := saveDoltBackupConfig(backupURL); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: backup registered but failed to save config: %v\n", err)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
return outputJSON(map[string]interface{}{
|
||||
"backup_url": backupURL,
|
||||
"backup_name": proxiedBackupTargetName,
|
||||
"initialized": true,
|
||||
})
|
||||
}
|
||||
fmt.Printf("Backup destination configured: %s\n", backupURL)
|
||||
fmt.Println("Run 'bd backup sync' to push your data.")
|
||||
return nil
|
||||
}
|
||||
|
||||
// runBackupSyncProxied pushes the database to the configured destination.
|
||||
func runBackupSyncProxied(ctx context.Context) error {
|
||||
if err := requireLocalProxiedBackup("backup sync"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
err := runProxiedNonTx(ctx, func(ctx context.Context, conn *sql.Conn) error {
|
||||
if err := commitWorkingSetBeforeBackup(ctx, conn); err != nil {
|
||||
// Same posture as the direct path: a failed pre-backup commit
|
||||
// means the backup may miss the newest writes, which is worth
|
||||
// saying out loud and is not worth refusing to back up over.
|
||||
fmt.Fprintf(os.Stderr, "Warning: failed to commit pending changes: %v\n", err)
|
||||
}
|
||||
return versioncontrolops.BackupSync(ctx, conn, proxiedBackupTargetName)
|
||||
})
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "no backup") || strings.Contains(err.Error(), "not found") {
|
||||
return HandleErrorRespectJSON("no backup destination configured. Run 'bd backup init <path>' first")
|
||||
}
|
||||
return HandleErrorRespectJSON("backup sync failed: %v", err)
|
||||
}
|
||||
|
||||
elapsed := time.Since(start)
|
||||
if err := updateDoltBackupState(elapsed); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: backup synced but failed to update state: %v\n", err)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
return outputJSON(map[string]interface{}{
|
||||
"synced": true,
|
||||
"duration": elapsed.String(),
|
||||
})
|
||||
}
|
||||
fmt.Printf("Backup synced in %s\n", elapsed.Round(time.Millisecond))
|
||||
return nil
|
||||
}
|
||||
|
||||
// commitWorkingSetBeforeBackup is the proxied twin of the direct path's
|
||||
// "bd: pre-backup commit". DOLT_BACKUP syncs COMMITTED history, so anything
|
||||
// still in the working set would silently be missing from the backup.
|
||||
//
|
||||
// It is normally a no-op: every proxied write transaction ends in
|
||||
// DOLT_COMMIT('-Am') (uow doltServerTx.Commit), so the working set is already
|
||||
// clean. The pending check is what keeps this from minting an empty commit on
|
||||
// every sync — Dolt rejects those server-side and logs each one.
|
||||
func commitWorkingSetBeforeBackup(ctx context.Context, conn *sql.Conn) error {
|
||||
pending, err := issueops.HasPendingChanges(ctx, conn)
|
||||
if err != nil {
|
||||
return fmt.Errorf("check pending changes: %w", err)
|
||||
}
|
||||
if !pending {
|
||||
return nil
|
||||
}
|
||||
if _, err := conn.ExecContext(ctx, "CALL DOLT_COMMIT('-Am', ?)", "bd: pre-backup commit"); err != nil {
|
||||
if issueops.IsNothingToCommitError(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// runBackupRemoveProxied unregisters the destination and drops the local
|
||||
// sidecars. The backup data itself is left alone, as in direct mode.
|
||||
func runBackupRemoveProxied(ctx context.Context) error {
|
||||
if err := requireLocalProxiedBackup("backup remove"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err := runProxiedNonTx(ctx, func(ctx context.Context, conn *sql.Conn) error {
|
||||
if err := versioncontrolops.BackupRemove(ctx, conn, proxiedBackupTargetName); err != nil {
|
||||
return err
|
||||
}
|
||||
// auto-export may have registered a second remote at the same URL.
|
||||
_ = versioncontrolops.BackupRemove(ctx, conn, versioncontrolops.ExportBackupName)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "not found") || strings.Contains(err.Error(), "no backup") {
|
||||
return HandleErrorRespectJSON("no backup destination configured")
|
||||
}
|
||||
return HandleErrorRespectJSON("failed to remove backup: %v", err)
|
||||
}
|
||||
|
||||
if path, err := doltBackupConfigPath(); err == nil {
|
||||
_ = os.Remove(path)
|
||||
}
|
||||
if path, err := doltBackupStatePath(); err == nil {
|
||||
_ = os.Remove(path)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
return outputJSON(map[string]interface{}{"removed": true})
|
||||
}
|
||||
fmt.Println("Backup destination removed.")
|
||||
return nil
|
||||
}
|
||||
|
||||
// doltBackupSizeProxied measures the managed-local database on disk, which is
|
||||
// what `bd backup status` reports on every other topology that can answer.
|
||||
//
|
||||
// It reads the directory rather than asking Dolt because that is what the
|
||||
// direct stores do (DoltStore.ActiveDatabaseSize measures
|
||||
// localActiveDatabaseDir), so the number means the same thing in both modes.
|
||||
// The database NAME still comes from the server, so the directory measured is
|
||||
// the one this connection is actually using.
|
||||
func doltBackupSizeProxied(ctx context.Context) (int64, bool, error) {
|
||||
beadsDir := beads.FindBeadsDir()
|
||||
if beadsDir == "" {
|
||||
return 0, false, nil
|
||||
}
|
||||
root, err := resolveProxiedServerRootPath(beadsDir)
|
||||
if err != nil {
|
||||
return 0, false, nil
|
||||
}
|
||||
|
||||
database, err := proxiedActiveDatabase(ctx)
|
||||
if err != nil {
|
||||
return 0, false, err
|
||||
}
|
||||
|
||||
dir := filepath.Join(root, database)
|
||||
if _, err := os.Stat(dir); err != nil {
|
||||
// No local directory means nothing bd can measure; the status contract
|
||||
// treats size as optional rather than failing the command.
|
||||
return 0, false, nil
|
||||
}
|
||||
size, err := storage.MeasureDirectorySize(ctx, dir)
|
||||
if err != nil {
|
||||
return 0, false, fmt.Errorf("measure active database directory %q: %w", dir, err)
|
||||
}
|
||||
return size, true, nil
|
||||
}
|
||||
|
||||
// runBackupRestoreProxied restores the database from a Dolt backup, quiescing
|
||||
// the topology first.
|
||||
//
|
||||
// DOLT_BACKUP('restore') REPLACES the database under the server. Doing that
|
||||
// while clients hold connections to it is undefined, so the restore runs with
|
||||
// bd as the only client and nothing else pointed at the store:
|
||||
//
|
||||
// 1. `bd backup restore` already holds the workspace and physical-root gates
|
||||
// EXCLUSIVELY (commandNeedsExclusiveGate), so no other gated bd command —
|
||||
// including `bd serve` — is using this workspace.
|
||||
// 2. This function closes the provider the root pre-run opened and shuts the
|
||||
// proxy and its dolt child down, so no connection survives into the
|
||||
// replace.
|
||||
// 3. It reopens a provider of its own, which relaunches the topology with
|
||||
// exactly one client, and runs the restore on that.
|
||||
// 4. It shuts the topology down again and reopens once more to finish: the
|
||||
// reopen proves the restored database is serviceable, and it is where the
|
||||
// project identity and the backup remote are reconciled. A connection
|
||||
// pinned across the replace would be reading a database that no longer
|
||||
// exists underneath it.
|
||||
//
|
||||
// The final shutdown leaves the workspace quiescent, so the next bd command
|
||||
// relaunches lazily against the restored data.
|
||||
func runBackupRestoreProxied(ctx context.Context, dir string, force bool) error {
|
||||
if err := requireLocalProxiedBackup("backup restore"); err != nil {
|
||||
return err
|
||||
}
|
||||
beadsDir := beads.FindBeadsDir()
|
||||
if beadsDir == "" {
|
||||
return HandleErrorRespectJSON("%s", activeWorkspaceNotFoundError())
|
||||
}
|
||||
root, err := resolveProxiedServerRootPath(beadsDir)
|
||||
if err != nil {
|
||||
return HandleErrorRespectJSON("%v", err)
|
||||
}
|
||||
backupURL, err := versioncontrolops.DirToFileURL(dir)
|
||||
if err != nil {
|
||||
return HandleErrorRespectJSON("%v", err)
|
||||
}
|
||||
|
||||
// Ask the live provider which database to replace before taking it away.
|
||||
database, err := proxiedActiveDatabase(ctx)
|
||||
if err != nil {
|
||||
return HandleErrorRespectJSON("%v", err)
|
||||
}
|
||||
|
||||
if err := quiesceProxiedTopology(ctx, root); err != nil {
|
||||
return HandleErrorRespectJSON("%v", err)
|
||||
}
|
||||
|
||||
if err := withQuiescedProxiedProvider(ctx, beadsDir, database, root, func(ctx context.Context, conn *sql.Conn) error {
|
||||
return versioncontrolops.BackupRestore(ctx, conn, backupURL, database, force)
|
||||
}); err != nil {
|
||||
return HandleErrorRespectJSON("%s", proxiedRestoreFailureMessage(dir, false, err))
|
||||
}
|
||||
|
||||
if err := withQuiescedProxiedProvider(ctx, beadsDir, database, root, func(ctx context.Context, conn *sql.Conn) error {
|
||||
return reconcileRestoredProxiedWorkspace(ctx, conn, beadsDir, dir, force)
|
||||
}); err != nil {
|
||||
return HandleErrorRespectJSON("%s", proxiedRestoreFailureMessage(dir, true, err))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// proxiedRestoreFailureMessage renders what the operator is told when one of
|
||||
// the two quiesced steps fails.
|
||||
//
|
||||
// The distinction it makes is the only one that matters here: DID THE DATA COME
|
||||
// BACK. A teardown failure happens after the step succeeded, so saying "restore
|
||||
// failed" would be false, and the obvious response to it — run the restore
|
||||
// again — is the wrong one. Split out from the call sites so that judgement is
|
||||
// something a test can hold still (TestProxiedRestoreFailureMessage).
|
||||
//
|
||||
// afterReconcile distinguishes the two steps, because a teardown failure costs
|
||||
// the operator different follow-up work either side of the reconcile: before
|
||||
// it, the backup destination has not been re-registered yet.
|
||||
func proxiedRestoreFailureMessage(dir string, afterReconcile bool, err error) string {
|
||||
var teardown *proxiedTeardownError
|
||||
if errors.As(err, &teardown) {
|
||||
if afterReconcile {
|
||||
return fmt.Sprintf("restored from %s, but shutting the proxied server down afterwards failed: %v; "+
|
||||
"the data is restored and reconciled — run 'bd dolt stop --force' before the next command", dir, teardown)
|
||||
}
|
||||
return fmt.Sprintf("restored from %s, but shutting the proxied server down afterwards failed: %v; "+
|
||||
"the data is restored — run 'bd dolt stop --force', then 'bd backup init %s' to re-register the "+
|
||||
"backup destination, which this run did not reach", dir, teardown, dir)
|
||||
}
|
||||
if afterReconcile {
|
||||
return fmt.Sprintf("restored from %s, but the restored database did not reopen: %v", dir, err)
|
||||
}
|
||||
return fmt.Sprintf("restore failed: %v", err)
|
||||
}
|
||||
|
||||
// quiesceProxiedTopology drops this process's provider and stops the proxy and
|
||||
// its dolt child, so nothing holds the database that is about to be replaced.
|
||||
func quiesceProxiedTopology(ctx context.Context, root string) error {
|
||||
if uowProvider != nil {
|
||||
if err := uowProvider.Close(ctx); err != nil {
|
||||
return fmt.Errorf("close the proxied provider before restoring: %w", err)
|
||||
}
|
||||
uowProvider = nil
|
||||
}
|
||||
if err := proxy.Shutdown(root); err != nil {
|
||||
return fmt.Errorf("stop the proxied server before restoring: %w; "+
|
||||
"run 'bd dolt stop --force' and retry", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// proxiedTeardownError marks a failure that happened AFTER the operation
|
||||
// succeeded, while putting the topology back down. It exists so the caller can
|
||||
// tell the two apart in what it prints. Flattening them is what made a restore
|
||||
// that completed and then failed to shut the proxy down report "restore
|
||||
// failed": the operator is told their data did not come back when it did, and
|
||||
// the obvious response — run the restore again — is the wrong one.
|
||||
type proxiedTeardownError struct{ err error }
|
||||
|
||||
func (e *proxiedTeardownError) Error() string { return e.err.Error() }
|
||||
func (e *proxiedTeardownError) Unwrap() error { return e.err }
|
||||
|
||||
// withQuiescedProxiedProvider relaunches the topology for one operation and
|
||||
// puts it back down afterwards, so each step either side of the replace runs on
|
||||
// a connection that was opened after it.
|
||||
//
|
||||
// The provider ADOPTS whatever identity the database carries: a restore is
|
||||
// precisely the operation after which the workspace's recorded project id and
|
||||
// the database's may legitimately differ, and asserting the old one would
|
||||
// refuse the connection that is supposed to reconcile them. That makes this the
|
||||
// third caller of newProxiedServerUOWProviderAdopting; its doc comment is the
|
||||
// register of identity-assertion bypasses and names this one.
|
||||
//
|
||||
// A teardown failure is returned wrapped in *proxiedTeardownError, and only
|
||||
// when the operation itself succeeded. If opening or running the operation
|
||||
// failed, preserve that error and append any cleanup failure without the
|
||||
// success marker. Shutdown is attempted even if construction fails after
|
||||
// starting the topology but before returning a provider.
|
||||
func withQuiescedProxiedProvider(ctx context.Context, beadsDir, database, root string, fn func(context.Context, *sql.Conn) error) (err error) {
|
||||
var provider uow.UnitOfWorkProvider
|
||||
defer func() {
|
||||
var closeErr error
|
||||
if provider != nil {
|
||||
closeErr = provider.Close(ctx)
|
||||
}
|
||||
stopErr := proxy.Shutdown(root)
|
||||
if teardownErr := errors.Join(closeErr, stopErr); teardownErr != nil {
|
||||
if err != nil {
|
||||
err = errors.Join(err, fmt.Errorf("shut down the proxied server after failure: %w", teardownErr))
|
||||
} else {
|
||||
err = &proxiedTeardownError{err: teardownErr}
|
||||
}
|
||||
}
|
||||
}()
|
||||
provider, err = newProxiedServerUOWProviderAdopting(ctx, beadsDir, database)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
maintenance, ok := provider.(uow.MaintenanceProvider)
|
||||
if !ok {
|
||||
return fmt.Errorf("the proxied provider does not support maintenance operations")
|
||||
}
|
||||
return maintenance.RunNonTx(ctx, fn)
|
||||
}
|
||||
|
||||
// reconcileRestoredProxiedWorkspace is the post-restore bookkeeping, mirroring
|
||||
// the direct path: adopt the restored database's project identity when the
|
||||
// restore overwrote one, and register the restore source as the backup
|
||||
// destination so `bd backup sync` works without a separate init.
|
||||
//
|
||||
// Both are best-effort with a warning, as in direct mode. The restore itself
|
||||
// has already succeeded by this point, and failing the command over bookkeeping
|
||||
// would tell the operator their data did not come back when it did.
|
||||
func reconcileRestoredProxiedWorkspace(ctx context.Context, conn *sql.Conn, beadsDir, dir string, force bool) error {
|
||||
if force {
|
||||
if err := syncProjectIDFromProxiedDB(ctx, conn, beadsDir); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: failed to sync project ID after restore: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
backupURL := resolveDoltBackupURL(dir)
|
||||
_ = versioncontrolops.BackupRemove(ctx, conn, proxiedBackupTargetName)
|
||||
if err := versioncontrolops.BackupAdd(ctx, conn, proxiedBackupTargetName, backupURL); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: failed to register backup remote: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
if err := saveDoltBackupConfig(backupURL); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: backup registered but failed to save config: %v\n", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// syncProjectIDFromProxiedDB copies the restored database's _project_id into
|
||||
// metadata.json, so the identity check does not reject later connections. The
|
||||
// direct path reads it through the store; there is no store in proxied mode, so
|
||||
// it goes through the same issueops accessor the store itself uses rather than
|
||||
// a second copy of the query.
|
||||
func syncProjectIDFromProxiedDB(ctx context.Context, conn *sql.Conn, beadsDir string) error {
|
||||
dbID, err := issueops.GetMetadataInTx(ctx, conn, "_project_id")
|
||||
if err != nil || dbID == "" {
|
||||
return err
|
||||
}
|
||||
cfg, err := configfile.Load(beadsDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if cfg == nil || cfg.ProjectID == dbID {
|
||||
return nil
|
||||
}
|
||||
cfg.ProjectID = dbID
|
||||
return cfg.Save(beadsDir)
|
||||
}
|
||||
|
|
@ -30,11 +30,10 @@ Use --force to overwrite an existing database with the backup contents.
|
|||
|
||||
The database must already be initialized (run 'bd init' first if needed).
|
||||
To initialize and restore in one step, use: bd init && bd backup restore`,
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if usesProxiedServer() {
|
||||
return HandleErrorRespectJSON("backup restore is not supported in proxied-server mode")
|
||||
}
|
||||
evt := metrics.NewCommandEvent("backup-restore")
|
||||
defer func() {
|
||||
if c := metrics.Global(); c != nil {
|
||||
|
|
@ -61,14 +60,24 @@ To initialize and restore in one step, use: bd init && bd backup restore`,
|
|||
|
||||
force, _ := cmd.Flags().GetBool("force")
|
||||
|
||||
if err := runBackupRestore(ctx, store, dir, force); err != nil {
|
||||
if usesProxiedServer() {
|
||||
if err := runBackupRestoreProxied(ctx, dir, force); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if err := runBackupRestore(ctx, store, dir, force); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !jsonOutput {
|
||||
fmt.Printf("%s Restore complete\n", ui.RenderPass("✓"))
|
||||
// One success report for both topologies. Under --json this used to
|
||||
// print nothing at all, which left a caller unable to tell a completed
|
||||
// restore from a silently skipped one.
|
||||
if jsonOutput {
|
||||
return outputJSON(map[string]interface{}{
|
||||
"restored": true,
|
||||
"source": dir,
|
||||
})
|
||||
}
|
||||
|
||||
fmt.Printf("%s Restore complete\n", ui.RenderPass("✓"))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/configfile"
|
||||
)
|
||||
|
||||
func TestBackupStatusSizeErrorRespectsOutputMode(t *testing.T) {
|
||||
|
|
@ -159,25 +160,62 @@ func TestBackupStatusIncludesAvailableDatabaseSize(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestBackupStatusProxiedGuardDoesNotMeasureSize(t *testing.T) {
|
||||
prepareBackupStatusTest(t)
|
||||
proxiedServerMode = true
|
||||
called := false
|
||||
sizeDatabase := func(context.Context) (int64, bool, error) {
|
||||
called = true
|
||||
return 1, true, nil
|
||||
}
|
||||
// TestBackupStatusProxiedGuardFollowsLocality replaces a test that asserted a
|
||||
// blanket proxied refusal. Since slice S3 the guard is scoped to locality: bd
|
||||
// owns the dolt process on a managed-local workspace and can honor the command
|
||||
// there, while an external one is still refused — and a refused command must
|
||||
// not go on to measure anything, because the directory it would measure belongs
|
||||
// to a server on another host.
|
||||
func TestBackupStatusProxiedGuardFollowsLocality(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
sidecar string
|
||||
wantMeasure bool
|
||||
}{
|
||||
{
|
||||
name: "external topology is refused without measuring",
|
||||
sidecar: `{"external":{"host":"db.example.com","port":3306}}`,
|
||||
wantMeasure: false,
|
||||
},
|
||||
{
|
||||
name: "managed local is honored and measures",
|
||||
sidecar: `{}`,
|
||||
wantMeasure: true,
|
||||
},
|
||||
} {
|
||||
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)
|
||||
}
|
||||
|
||||
cmd := newBackupStatusTestRoot(sizeDatabase)
|
||||
cmd.SetArgs([]string{"backup", "status"})
|
||||
_, _, err := executeBackupStatusCommand(t, cmd)
|
||||
assertExitCode(t, err, 1)
|
||||
if called {
|
||||
t.Fatal("proxied-server guard called database size provider")
|
||||
measured := false
|
||||
sizeDatabase := func(context.Context) (int64, bool, error) {
|
||||
measured = true
|
||||
return 1, true, nil
|
||||
}
|
||||
|
||||
cmd := newBackupStatusTestRoot(sizeDatabase)
|
||||
cmd.SetArgs([]string{"backup", "status"})
|
||||
_, _, err := executeBackupStatusCommand(t, cmd)
|
||||
if tc.wantMeasure {
|
||||
if err != nil {
|
||||
t.Fatalf("backup status on managed-local: %v", err)
|
||||
}
|
||||
} else {
|
||||
assertExitCode(t, err, 1)
|
||||
}
|
||||
if measured != tc.wantMeasure {
|
||||
t.Fatalf("size provider called = %v, want %v", measured, tc.wantMeasure)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func prepareBackupStatusTest(t *testing.T) {
|
||||
// prepareBackupStatusTest builds a throwaway workspace and returns its .beads
|
||||
// directory, so a caller can drop workspace files (the proxied sidecar) into it.
|
||||
func prepareBackupStatusTest(t *testing.T) string {
|
||||
t.Helper()
|
||||
|
||||
beadsDir := filepath.Join(t.TempDir(), ".beads")
|
||||
|
|
@ -198,6 +236,7 @@ func prepareBackupStatusTest(t *testing.T) {
|
|||
proxiedServerMode = oldProxiedServerMode
|
||||
resetCommandContext()
|
||||
})
|
||||
return beadsDir
|
||||
}
|
||||
|
||||
func newBackupStatusTestRoot(sizeDatabase backupSizeFunc) *cobra.Command {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -186,7 +186,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()
|
||||
|
|
|
|||
|
|
@ -79,13 +79,7 @@ func TestIsGitCodeRepoURL(t *testing.T) {
|
|||
// Returns a cleanup function that resets config state.
|
||||
func setupSyncRemoteConfig(t *testing.T, beadsDir, remote string) func() {
|
||||
t.Helper()
|
||||
if err := os.WriteFile(
|
||||
filepath.Join(beadsDir, "config.yaml"),
|
||||
[]byte("sync.remote: "+remote+"\n"),
|
||||
0o644,
|
||||
); err != nil {
|
||||
t.Fatalf("write config.yaml: %v", err)
|
||||
}
|
||||
seedSyncRemote(t, beadsDir, remote)
|
||||
config.ResetForTesting()
|
||||
t.Setenv("BEADS_DIR", beadsDir)
|
||||
t.Setenv("BEADS_TEST_IGNORE_REPO_CONFIG", "1")
|
||||
|
|
|
|||
|
|
@ -355,9 +355,7 @@ func TestDetectBootstrapAction_ExplicitSyncRemotePreservesRemotesAPIURL(t *testi
|
|||
t.Fatal(err)
|
||||
}
|
||||
const syncRemote = "http://myserver:7007/mydb"
|
||||
if err := os.WriteFile(filepath.Join(beadsDir, "config.yaml"), []byte("sync.remote: "+syncRemote+"\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
seedSyncRemote(t, beadsDir, syncRemote)
|
||||
t.Setenv("BEADS_DIR", beadsDir)
|
||||
t.Setenv("BEADS_TEST_IGNORE_REPO_CONFIG", "1")
|
||||
if err := config.Initialize(); err != nil {
|
||||
|
|
@ -407,9 +405,7 @@ func TestDetectBootstrapAction_ExistingEmbeddedDBWithSyncRemoteIsNoOp(t *testing
|
|||
t.Fatal(err)
|
||||
}
|
||||
const syncRemote = "http://myserver:7007/mydb"
|
||||
if err := os.WriteFile(filepath.Join(beadsDir, "config.yaml"), []byte("sync.remote: "+syncRemote+"\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
seedSyncRemote(t, beadsDir, syncRemote)
|
||||
t.Setenv("BEADS_DIR", beadsDir)
|
||||
t.Setenv("BEADS_TEST_IGNORE_REPO_CONFIG", "1")
|
||||
if err := config.Initialize(); err != nil {
|
||||
|
|
@ -1327,8 +1323,18 @@ func TestFinalizeSyncedBootstrapWritesConfigFiles(t *testing.T) {
|
|||
// sync.remote must be persisted so subsequent fresh clones (and
|
||||
// bootstrap retries) can rediscover the remote without re-probing
|
||||
// origin refs.
|
||||
if !strings.Contains(yaml, "sync.remote: ") && !strings.Contains(yaml, "sync-remote: ") {
|
||||
t.Errorf("config.yaml does not contain sync.remote entry:\n%s", yaml)
|
||||
//
|
||||
// Asserted by READING it back rather than by matching a spelling. This used
|
||||
// to require a literal `sync.remote: ` line, which is a key whose name
|
||||
// contains a dot — the shape config.GetStringFromDir and viper can never
|
||||
// find, because both split on the dot and walk nested mappings. The writer
|
||||
// now nests (bd-zj95), so the old assertion passed for exactly as long as
|
||||
// the value was unreadable and failed the moment it became readable. What
|
||||
// bootstrap owes its caller is a remote that can be read back, so that is
|
||||
// what this checks.
|
||||
if got := config.GetStringFromDir(beadsDir, "sync.remote"); got != syncRemote {
|
||||
t.Errorf("config.GetStringFromDir(%q, \"sync.remote\") = %q, want %q:\n%s",
|
||||
beadsDir, got, syncRemote, yaml)
|
||||
}
|
||||
if !strings.Contains(yaml, syncRemote) {
|
||||
t.Errorf("config.yaml does not contain sync remote URL %q:\n%s", syncRemote, yaml)
|
||||
|
|
|
|||
676
cmd/bd/capability_registry.go
Normal file
676
cmd/bd/capability_registry.go
Normal file
|
|
@ -0,0 +1,676 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
// The proxied-server capability registry: one table for every command path.
|
||||
//
|
||||
// Before this file the policy lived in three separate tables — a maintenance
|
||||
// refusal map, a history classification map, and a transform row list — each
|
||||
// with its own lookup and its own front-door validator. Nothing forced a new
|
||||
// command to appear in any of them, so an unclassified command sailed past the
|
||||
// gate and died deep in the store factory with an untyped error. The fix is not
|
||||
// a fourth table: it is one table plus a test that fails when a command is
|
||||
// missing from it (TestProxyCapabilityRegistryCoversCommandTree).
|
||||
//
|
||||
// WHAT A ROW MEANS. Outcome describes what the PRE-PROVIDER GATE does with the
|
||||
// path on a proxied-server workspace, nothing more:
|
||||
//
|
||||
// ProxyOutcomeRefused the gate refuses with a typed ProxyCapabilityError
|
||||
// before any workspace side effect
|
||||
// ProxyOutcomeRefusedInRunE the gate lets the path through and the command
|
||||
// refuses inside its own RunE with an untyped
|
||||
// string; recorded here so the untyped surface is
|
||||
// inventoried rather than invisible. Not enforced.
|
||||
// ProxyOutcomeHonored the gate lets the path through. It does NOT
|
||||
// promise a proxied route exists: a permitted
|
||||
// command with no route still fails at the store
|
||||
// factory with proxy.store.unrouted.
|
||||
//
|
||||
// Permitting a path also COSTS something, and the cost is invisible from this
|
||||
// table: unless the command is on one of main.go's store-init skip lists, the
|
||||
// root pre-run opens the proxied provider before RunE runs — which starts the
|
||||
// proxy and its dolt child, creates the database and migrates the schema. For a
|
||||
// command that genuinely uses the store that is the point. For a store-free one
|
||||
// it is pure side effect, and on a workspace whose topology cannot be resolved
|
||||
// it turns a clean typed refusal into a provider-open error. So "this command
|
||||
// touches no store" is an argument for permitting it only once the command is
|
||||
// also off the store-init path; see the `migrate hooks` row. Nothing here
|
||||
// asserts that, and TestProxyCapabilityRegistryCoversCommandTree cannot see it.
|
||||
//
|
||||
// REASON is the load-bearing field. "design" means refusing is correct and is
|
||||
// expected to stay that way — the semantics are undefined or unsafe against a
|
||||
// backend that may be shared. "unimplemented" means the refusal is a capability
|
||||
// gap with a named slice that closes it, and Tracking says which. Every later
|
||||
// slice measures itself by turning "unimplemented" rows into honored ones; the
|
||||
// count of remaining "unimplemented" rows is the completion signal for the whole
|
||||
// proxied-parity effort. Assign the field row by row, from the command's actual
|
||||
// semantics — a bulk assignment would destroy the only information it carries.
|
||||
//
|
||||
// The reason also renders in the refusal JSON, additive to the frozen
|
||||
// {code, error, mutates} contract (see buildJSONCapabilityError). Codes are
|
||||
// frozen; messages are informative-only.
|
||||
|
||||
// ProxyRefusalReason distinguishes a deliberate policy refusal from a
|
||||
// not-yet-built one.
|
||||
type ProxyRefusalReason string
|
||||
|
||||
const (
|
||||
// ProxyReasonDesign: the command is refused on purpose and is expected to
|
||||
// stay refused. Lifting it would need a semantic decision, not plumbing.
|
||||
ProxyReasonDesign ProxyRefusalReason = "design"
|
||||
// ProxyReasonUnimplemented: the command could work over the proxied
|
||||
// provider; nobody has routed it yet. Tracking names the work item.
|
||||
ProxyReasonUnimplemented ProxyRefusalReason = "unimplemented"
|
||||
)
|
||||
|
||||
// Tracking values name the plan-of-record work item for an unimplemented
|
||||
// refusal. These are the slices of the proxied-parity plan; a row gets a GitHub
|
||||
// issue or bead ID instead once one is filed for it.
|
||||
// S3 has no entry: it landed, and its rows carry Reason=design rather than a
|
||||
// tracking item.
|
||||
const (
|
||||
trackVersionCtl = "proxied-parity S4 (dolt commit/push/pull/remote)"
|
||||
trackSync = "proxied-parity S5 (bd sync)"
|
||||
trackDegradation = "proxied-parity S6 (doctor, config show, degradations)"
|
||||
trackLongTail = "proxied-parity S7 (long-tail policy pass)"
|
||||
)
|
||||
|
||||
// capabilityRow is one command-path policy row. ArgSet is the sorted set of
|
||||
// execution-altering flags that were set (for example "--auto-merge --dry-run"),
|
||||
// empty for the bare path; a row keyed on an ArgSet wins over the bare row, which
|
||||
// is how `duplicates --auto-merge --dry-run` stays honored while
|
||||
// `duplicates --auto-merge` is refused.
|
||||
//
|
||||
// Topology overrides Rule on the proxied shapes named in it and is empty for
|
||||
// every row whose answer is the same everywhere — which is all of them but the
|
||||
// backup family. See honoredOn.
|
||||
type capabilityRow struct {
|
||||
Path string
|
||||
ArgSet string
|
||||
Rule proxyCapabilityRule
|
||||
Topology map[ProxyTopology]proxyCapabilityRule
|
||||
History HistoryCapabilityClass
|
||||
Note string
|
||||
}
|
||||
|
||||
// ruleFor resolves the row's policy on one proxied topology.
|
||||
func (r capabilityRow) ruleFor(topology ProxyTopology) proxyCapabilityRule {
|
||||
if rule, ok := r.Topology[topology]; ok {
|
||||
return rule
|
||||
}
|
||||
return r.Rule
|
||||
}
|
||||
|
||||
// honoredOn narrows a refusal to the shapes where it is actually true: the row
|
||||
// goes on refusing everywhere except the topologies named here.
|
||||
//
|
||||
// The direction is deliberate. A row states its refusal first and then lists
|
||||
// the exceptions, so a shape nobody thought about — a new transport, or the
|
||||
// unknown a corrupt sidecar produces — inherits the refusal rather than the
|
||||
// exemption.
|
||||
func (r capabilityRow) honoredOn(topologies ...ProxyTopology) capabilityRow {
|
||||
r.Topology = make(map[ProxyTopology]proxyCapabilityRule, len(topologies))
|
||||
for _, topology := range topologies {
|
||||
r.Topology[topology] = proxyCapabilityRule{Outcome: ProxyOutcomeHonored}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// display renders the row's key the way its refusal message names it.
|
||||
func (r capabilityRow) display() string {
|
||||
if r.ArgSet == "" {
|
||||
return r.Path
|
||||
}
|
||||
return r.Path + " " + r.ArgSet
|
||||
}
|
||||
|
||||
func (r capabilityRow) withHistory(class HistoryCapabilityClass) capabilityRow {
|
||||
r.History = class
|
||||
return r
|
||||
}
|
||||
|
||||
// asParentGroup marks a row whose path is a command GROUP. Cobra answers a
|
||||
// non-runnable parent with its help text before PersistentPreRunE, so the gate
|
||||
// never sees it; the row is kept because it is the parent every child row
|
||||
// inherits its code from, and because a parent that later gains a Run must not
|
||||
// silently become permitted.
|
||||
func (r capabilityRow) asParentGroup() capabilityRow {
|
||||
r.Note = "parent group: cobra shows help instead of reaching the gate"
|
||||
return r
|
||||
}
|
||||
|
||||
func (r capabilityRow) withMessage(message string) capabilityRow {
|
||||
r.Rule.Message = message
|
||||
return r
|
||||
}
|
||||
|
||||
// refusedPath builds a typed front-door refusal for a bare command path.
|
||||
func refusedPath(path, code string, reason ProxyRefusalReason, tracking string) capabilityRow {
|
||||
return refusedArgs(path, "", code, reason, tracking)
|
||||
}
|
||||
|
||||
// refusedArgs builds a typed front-door refusal keyed on a flag set.
|
||||
func refusedArgs(path, argSet, code string, reason ProxyRefusalReason, tracking string) capabilityRow {
|
||||
row := capabilityRow{Path: path, ArgSet: argSet}
|
||||
row.Rule = proxyCapabilityRule{
|
||||
Outcome: ProxyOutcomeRefused,
|
||||
Code: code,
|
||||
Message: row.display() + " is not supported in proxied-server mode",
|
||||
ExitCode: 1,
|
||||
Reason: reason,
|
||||
Tracking: tracking,
|
||||
}
|
||||
return row
|
||||
}
|
||||
|
||||
// refusedInRunE records a command that the gate permits and that then refuses
|
||||
// itself with an untyped string from RunE. The row carries no message: the
|
||||
// string lives in the command, and duplicating it here would rot. The scan in
|
||||
// TestProxyCapabilityRegistryCoversInlineRefusals keeps the two in step.
|
||||
//
|
||||
// The reason is always "unimplemented" and the owner is always the long-tail
|
||||
// slice, because an untyped string inside RunE is not a considered policy
|
||||
// statement: a refusal decided on purpose belongs in the gate, typed, where a
|
||||
// consumer can read it. Anything here is a family nobody has routed yet.
|
||||
func refusedInRunE(path, site string) capabilityRow {
|
||||
return capabilityRow{
|
||||
Path: path,
|
||||
Rule: proxyCapabilityRule{
|
||||
Outcome: ProxyOutcomeRefusedInRunE, ExitCode: 1,
|
||||
Reason: ProxyReasonUnimplemented, Tracking: trackLongTail,
|
||||
},
|
||||
Note: "untyped refusal in " + site,
|
||||
}
|
||||
}
|
||||
|
||||
// permitted records that the gate lets a path through. See the header: this is
|
||||
// a statement about the gate, not a promise that a proxied route exists.
|
||||
func permitted(path string) capabilityRow {
|
||||
return capabilityRow{Path: path, Rule: proxyCapabilityRule{Outcome: ProxyOutcomeHonored}}
|
||||
}
|
||||
|
||||
// backupRefusal builds one backup-family row: honored where bd owns the Dolt
|
||||
// server, refused by design everywhere else. The code stays
|
||||
// proxy.backup.unsupported — consumers have been keying on it since 1.3.0 and
|
||||
// the refusal it names has not changed, only its reason and its scope — and the
|
||||
// message keeps the frozen "<path> is not supported in proxied-server mode"
|
||||
// prefix, with the reason appended.
|
||||
//
|
||||
// The message leads with SERVER-GLOBAL STATE rather than with the filesystem,
|
||||
// because only the filesystem half is scheme-specific. `bd backup init` accepts
|
||||
// https/aws/gs as well as file:// (resolveDoltBackupURL) and the help text
|
||||
// recommends DoltHub; for those a server-side push over the network with the
|
||||
// server's own credentials is a coherent thing to ask for, and "the destination
|
||||
// is on the server's disk" says nothing about it. What is true of every scheme
|
||||
// is that `CALL DOLT_BACKUP('add', …)` registers the remote ON THE SERVER,
|
||||
// where it is global to every client of that server — one workspace's backup
|
||||
// decision silently becomes everyone's, which is the shape of the auto-backup
|
||||
// storm this command's own help text warns about.
|
||||
//
|
||||
// backupRemoteSchemeTracking is why these rows carry a Tracking item despite
|
||||
// being Reason=design: the outcome is settled, the remote-scheme CASE is not.
|
||||
func backupRefusal(path string) capabilityRow {
|
||||
return refusedPath(path, "proxy.backup.unsupported", ProxyReasonDesign, backupRemoteSchemeTracking).
|
||||
withMessage(path + " is not supported in proxied-server mode against a Dolt server bd does not own: " +
|
||||
"the backup remote is registered on the server, where it is global to every client, " +
|
||||
"and a file:// destination names a filesystem this client cannot see").
|
||||
honoredOn(ProxyTopologyManagedLocal)
|
||||
}
|
||||
|
||||
// backupRemoteSchemeTracking records the one part of the backup refusal that is
|
||||
// a question rather than a verdict, so refusing the family off-host does not
|
||||
// silently foreclose it. A remote-scheme destination (DoltHub, aws://, gs://)
|
||||
// needs no filesystem bd can see — the server pushes it over the network from
|
||||
// its own environment, which is exactly the credential story S4 has to settle
|
||||
// for `dolt push` on these same topologies. Whether a per-client backup remote
|
||||
// on a shared server is ever acceptable is the open part; the plumbing is not.
|
||||
//
|
||||
// Note also that the DoltHub story is already half-built in DIRECT mode:
|
||||
// `bd backup init https://…` and `bd backup sync` work, but
|
||||
// `bd backup restore https://…` does not, because validateBackupRestoreDir
|
||||
// os.Stats its argument and rejects anything that is not an existing directory
|
||||
// on every topology. Pre-existing, not something this slice changed.
|
||||
const backupRemoteSchemeTracking = "open question, not a verdict: remote-scheme (DoltHub/aws/gs) backup on a server " +
|
||||
"bd does not own — revisit with S4, which settles the same server-env credential question for dolt push"
|
||||
|
||||
// proxyCapabilityRegistry is the whole path-keyed policy. Rows for permitted
|
||||
// paths are appended from proxyPermittedPaths by init.
|
||||
var proxyCapabilityRegistry = []capabilityRow{
|
||||
// --- doctor -------------------------------------------------------------
|
||||
// Diagnosis needs no version-control surface; the checks simply have no
|
||||
// proxied dual yet. S6 splits them into client-local and store-backed.
|
||||
refusedPath("doctor", "proxy.doctor.unsupported", ProxyReasonUnimplemented, trackDegradation),
|
||||
|
||||
// --- backup / restore ---------------------------------------------------
|
||||
// CALL DOLT_BACKUP(...) is pure SQL over a connection proxied mode already
|
||||
// owns, so routing this family needed no proxy work at all — see
|
||||
// backup_proxied_server.go.
|
||||
//
|
||||
// What it did need is the ownership policy, which is the first genuinely
|
||||
// topology-differentiated rule in this table. A backup remote belongs to the
|
||||
// SERVER, not to the client that asked for it: `CALL DOLT_BACKUP('add', …)`
|
||||
// registers it in the server's own configuration, where it is global to
|
||||
// every client connected to that server. On managed-local "every client" is
|
||||
// this workspace, because bd spawned the child itself. Anywhere else one
|
||||
// operator's backup decision silently becomes everyone's — the same shape as
|
||||
// the auto-backup storm this command's help text already warns about, and
|
||||
// the reason team-server is the sharpest case: bts owns the store.
|
||||
//
|
||||
// A file:// destination adds a second, scheme-specific problem on top: it
|
||||
// names a path on the machine running dolt, so off-host the command either
|
||||
// fails at the point of use or, far worse, reports success having written
|
||||
// the backup somewhere the operator will never look for it.
|
||||
//
|
||||
// Hence: honored on managed-local, refused by design everywhere else. The
|
||||
// OUTCOME is design — server-global state is not something plumbing on this
|
||||
// side can make per-client, and a backup story for those shapes belongs to
|
||||
// whoever runs the server. The remote-scheme case (DoltHub, aws://, gs://,
|
||||
// which resolveDoltBackupURL accepts and backup.go recommends) is the part
|
||||
// that is a question rather than a verdict, and it is not silently
|
||||
// foreclosed: see backupRemoteSchemeTracking, which every row below carries.
|
||||
backupRefusal("backup").asParentGroup(),
|
||||
backupRefusal("backup init"),
|
||||
backupRefusal("backup sync"),
|
||||
backupRefusal("backup remove"),
|
||||
backupRefusal("backup status"),
|
||||
backupRefusal("backup restore"),
|
||||
|
||||
// --- version control over a shared history ------------------------------
|
||||
// Refused by design: these mutate or traverse a history that several
|
||||
// clients share through one connection, and the per-client semantics
|
||||
// (whose working set? whose branch head?) are undefined. `diff` is the one
|
||||
// plausible 1.4 candidate, via the dolt_diff system tables.
|
||||
refusedPath("branch", "proxy.branch.unsupported", ProxyReasonDesign, "").
|
||||
withHistory(HistoryDirectOnly),
|
||||
refusedPath("diff", "proxy.diff.unsupported", ProxyReasonDesign, "1.4 candidate: dolt_diff system tables"),
|
||||
refusedPath("flatten", "proxy.flatten.unsupported", ProxyReasonDesign, "").
|
||||
withHistory(HistoryDirectOnly),
|
||||
refusedPath("conflicts", "proxy.conflicts.unsupported", ProxyReasonDesign, "").
|
||||
withHistory(HistoryDirectOnly).
|
||||
asParentGroup(),
|
||||
refusedPath("conflicts list", "proxy.conflicts.unsupported", ProxyReasonDesign, ""),
|
||||
refusedPath("conflicts show", "proxy.conflicts.unsupported", ProxyReasonDesign, ""),
|
||||
refusedPath("conflicts resolve", "proxy.conflicts.unsupported", ProxyReasonDesign, ""),
|
||||
refusedPath("vc", "proxy.vc.unsupported", ProxyReasonDesign, "").
|
||||
withHistory(HistoryDirectOnly).
|
||||
asParentGroup(),
|
||||
refusedPath("vc merge", "proxy.vc.unsupported", ProxyReasonDesign, ""),
|
||||
refusedPath("vc commit", "proxy.vc.unsupported", ProxyReasonDesign, ""),
|
||||
refusedPath("vc status", "proxy.vc.unsupported", ProxyReasonDesign, ""),
|
||||
refusedPath("federation", "proxy.federation.unsupported", ProxyReasonDesign, "").
|
||||
withHistory(HistoryDirectOnly).
|
||||
asParentGroup(),
|
||||
refusedPath("federation sync", "proxy.federation.unsupported", ProxyReasonDesign, ""),
|
||||
refusedPath("federation status", "proxy.federation.unsupported", ProxyReasonDesign, ""),
|
||||
refusedPath("federation add-peer", "proxy.federation.unsupported", ProxyReasonDesign, ""),
|
||||
refusedPath("federation remove-peer", "proxy.federation.unsupported", ProxyReasonDesign, ""),
|
||||
refusedPath("federation list-peers", "proxy.federation.unsupported", ProxyReasonDesign, ""),
|
||||
|
||||
// --- multi-repo routing -------------------------------------------------
|
||||
// Routing to another workspace bypasses the proxied root entirely, which is
|
||||
// the same reason --repo is N/A mode-wide.
|
||||
refusedPath("repo", "proxy.repo.unsupported", ProxyReasonDesign, "").
|
||||
withHistory(HistoryDirectOnly).
|
||||
asParentGroup(),
|
||||
refusedPath("repo add", "proxy.repo.unsupported", ProxyReasonDesign, ""),
|
||||
refusedPath("repo remove", "proxy.repo.unsupported", ProxyReasonDesign, ""),
|
||||
refusedPath("repo list", "proxy.repo.unsupported", ProxyReasonDesign, ""),
|
||||
refusedPath("repo sync", "proxy.repo.unsupported", ProxyReasonDesign, ""),
|
||||
|
||||
// --- dolt version-control verbs -----------------------------------------
|
||||
// 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).
|
||||
withHistory(HistoryDirectOnly),
|
||||
refusedPath("dolt remote", "proxy.dolt_remote.unsupported", ProxyReasonUnimplemented, trackVersionCtl).
|
||||
withHistory(HistoryDirectOnly).
|
||||
asParentGroup(),
|
||||
refusedPath("dolt remote add", "proxy.dolt_remote.unsupported", ProxyReasonUnimplemented, trackVersionCtl).
|
||||
withHistory(HistoryDirectOnly),
|
||||
refusedPath("dolt remote list", "proxy.dolt_remote.unsupported", ProxyReasonUnimplemented, trackVersionCtl).
|
||||
withHistory(HistoryDirectOnly),
|
||||
refusedPath("dolt remote reset-data", "proxy.dolt_remote.unsupported", ProxyReasonUnimplemented, trackVersionCtl).
|
||||
withHistory(HistoryDirectOnly),
|
||||
refusedPath("sync", "proxy.sync.unsupported", ProxyReasonUnimplemented, trackSync).
|
||||
withHistory(HistoryDirectOnly),
|
||||
|
||||
// --- migration and workspace surgery ------------------------------------
|
||||
// Storage-format and workspace surgery against a store other clients may be
|
||||
// holding open. `migrate schema` is the exception and is already routed:
|
||||
// the provider open runs it under the migration gate.
|
||||
//
|
||||
// S7 MUST RE-EXAMINE THE ROWS BELOW PER TOPOLOGY. "A store other clients may
|
||||
// be holding open" describes external and team-server workspaces; it does
|
||||
// not describe managed-local, which is 1:1 and bd-owned — bd spawned the
|
||||
// dolt child itself. A row cannot yet say "refused, except on managed-local"
|
||||
// (S3's backup locality policy is the slice that adds per-topology rules),
|
||||
// so the blanket refusal is the only thing this table can express today.
|
||||
// These rows keep it because nobody has done the semantic work to narrow
|
||||
// them, not because the work has been done and come out this way.
|
||||
refusedPath("migrate", "proxy.migrate.unsupported", ProxyReasonDesign, ""),
|
||||
refusedPath("migrate sync", "proxy.migrate.unsupported", ProxyReasonDesign, ""),
|
||||
// `migrate hooks` is the one row in this block the surgery rationale never
|
||||
// described: it plans and applies GIT HOOK FILE migration (migrate_hooks.go
|
||||
// -> doctor.PlanHookMigration) on the local filesystem and opens no store at
|
||||
// all. It is refused for a structural reason instead — the command is wired
|
||||
// into the store-opening path it does not need. It is on none of main.go's
|
||||
// store-init skip lists, so permitting it makes the root pre-run open the
|
||||
// proxied provider before RunE ever runs. Measured, not assumed: with this
|
||||
// row flipped to permitted, `bd migrate hooks --dry-run` on a managed-local
|
||||
// workspace started the proxy AND its dolt child (both pidfiles present) to
|
||||
// print a hook plan, and on a workspace with an unreadable sidecar it exited
|
||||
// 1 with "failed to open uow provider: corrupt proxied-server sidecar ..."
|
||||
// where it had cleanly refused before. Trading a typed refusal for a
|
||||
// connection error is not a lift. The honest fix is to take the command off
|
||||
// the store path first, which is S7's job, not this slice's.
|
||||
refusedPath("migrate hooks", "proxy.migrate.unsupported", ProxyReasonUnimplemented,
|
||||
trackLongTail+" (specifically: put `migrate hooks` on main.go's store-init skip list, then permit it)"),
|
||||
refusedPath("migrate issues", "proxy.migrate.unsupported", ProxyReasonDesign, ""),
|
||||
refusedPath("migrate-issues", "proxy.migrate.unsupported", ProxyReasonDesign, ""),
|
||||
refusedPath("migrate-personal", "proxy.migrate.unsupported", ProxyReasonDesign, ""),
|
||||
|
||||
// --- destructive admin --------------------------------------------------
|
||||
// Same topology-blind rationale as the migrate block above, and the same
|
||||
// instruction to S7: "destructive against a possibly-shared store" is a
|
||||
// claim about external and team-server shapes. On managed-local the store is
|
||||
// this workspace's alone, and `bd admin reset` there is no more shared than
|
||||
// it is in embedded mode, where it is honored. Re-examine per topology.
|
||||
refusedPath("admin cleanup", "proxy.admin.unsupported", ProxyReasonDesign, ""),
|
||||
refusedPath("admin reset", "proxy.admin.unsupported", ProxyReasonDesign, ""),
|
||||
// --- issue compaction ---------------------------------------------------
|
||||
// `bd admin compact` without --dolt is the description-rewriting pass; only
|
||||
// the --dolt arm has a proxied route (runCompactDoltProxiedServer). The
|
||||
// --dolt arm is decided by flag VALUE, so the gate keeps a value-aware
|
||||
// branch for it and lands here when the flag is off.
|
||||
refusedPath("admin compact", "proxy.compact.unsupported", ProxyReasonUnimplemented, trackLongTail).
|
||||
withMessage("only 'compact --dolt' is supported in proxied-server mode"),
|
||||
// `bd restore` recovers a COMPACTED ISSUE's original text, not a backup —
|
||||
// the backup verb is `bd backup restore`. Its snapshot read is ordinary
|
||||
// CRUD; only its fallback path (reconstructing from Dolt history when no
|
||||
// snapshot was archived) touches version control.
|
||||
refusedPath("restore", "proxy.restore.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
||||
|
||||
// --- gates, formulas, swarm, merge slots --------------------------------
|
||||
// Ordinary CRUD over a store with no version-control surface. They stay
|
||||
// refused because nothing downstream has asked for them, which is this
|
||||
// codebase's standing rule for lifting a refusal — not because the proxied
|
||||
// topology makes them wrong.
|
||||
refusedPath("gate discover", "proxy.gate.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
||||
refusedPath("cook", "proxy.formula.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
||||
refusedPath("ship", "proxy.formula.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
||||
refusedPath("swarm create", "proxy.swarm.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
||||
refusedPath("swarm list", "proxy.swarm.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
||||
refusedPath("merge-slot create", "proxy.merge_slot.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
||||
refusedPath("merge-slot check", "proxy.merge_slot.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
||||
refusedPath("merge-slot acquire", "proxy.merge_slot.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
||||
refusedPath("merge-slot release", "proxy.merge_slot.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
||||
|
||||
// --- transforms ---------------------------------------------------------
|
||||
// ID rewrites walk every reference in the store. They need a routed
|
||||
// multi-statement transaction, which the UOW can express; nobody has
|
||||
// written it. The arg-set rows are what let the read-only preview of a
|
||||
// duplicate merge stay honored while the merge itself is refused.
|
||||
refusedPath("rename", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
||||
refusedPath("rename-prefix", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
||||
refusedArgs("rename-prefix", "--dry-run", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
||||
refusedArgs("rename-prefix", "--repair", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
||||
refusedArgs("rename-prefix", "--dry-run --repair", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
||||
refusedPath("duplicate", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
||||
refusedArgs("duplicate", "--of", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
||||
refusedPath("supersede", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
||||
refusedArgs("supersede", "--with", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
||||
refusedArgs("duplicates", "--auto-merge", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
||||
// The dry run reports what the merge WOULD do without writing anything, so
|
||||
// it rides the read path plain `duplicates` already uses.
|
||||
{Path: "duplicates", ArgSet: "--auto-merge --dry-run", Rule: proxyCapabilityRule{Outcome: ProxyOutcomeHonored}},
|
||||
|
||||
// --- routed history -----------------------------------------------------
|
||||
// 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
|
||||
// string, so a JSON consumer gets no code and no mutates flag. They are
|
||||
// listed to inventory that surface, not to enforce it: converting them to
|
||||
// typed refusals changes observable output and belongs to the slice that
|
||||
// owns each family. Tracker verbs are ordinary store reads plus a network
|
||||
// call; nothing about the proxied topology makes them wrong.
|
||||
refusedInRunE("ado status", "ado.go"),
|
||||
refusedInRunE("ado projects", "ado.go"),
|
||||
refusedInRunE("ado sync", "ado.go"),
|
||||
refusedInRunE("github status", "github.go"),
|
||||
refusedInRunE("github repos", "github.go"),
|
||||
refusedInRunE("github sync", "github.go"),
|
||||
refusedInRunE("gitlab status", "gitlab.go"),
|
||||
refusedInRunE("gitlab projects", "gitlab.go"),
|
||||
refusedInRunE("gitlab sync", "gitlab.go"),
|
||||
refusedInRunE("notion status", "notion.go"),
|
||||
refusedInRunE("notion init", "notion.go"),
|
||||
refusedInRunE("notion connect", "notion.go"),
|
||||
refusedInRunE("notion sync", "notion.go"),
|
||||
refusedInRunE("create-form", "create_form.go"),
|
||||
}
|
||||
|
||||
// proxyPermittedPaths lists every command path the proxied front door lets
|
||||
// through. It exists so that a command added without a policy decision fails
|
||||
// TestProxyCapabilityRegistryCoversCommandTree instead of shipping — the whole
|
||||
// point of the registry. Being listed here says the GATE permits the path; a
|
||||
// permitted command with no proxied route still fails at the store factory with
|
||||
// proxy.store.unrouted.
|
||||
var proxyPermittedPaths = []string{
|
||||
// issue CRUD and queries
|
||||
"assign", "batch", "blocked", "children", "close", "comment", "count", "create",
|
||||
"defer", "delete", "duplicates", "edit", "export", "find-duplicates", "forget",
|
||||
"gc", "graph", "graph check", "heartbeat", "import", "info", "lint", "link",
|
||||
"list", "note", "orphans", "priority", "promote", "prune", "purge", "q", "query",
|
||||
"ready", "recompute-blocked", "reclaim", "reopen", "search", "set-state", "show",
|
||||
"stale", "status", "statuses", "tag", "types", "unclaim", "undefer", "update",
|
||||
|
||||
// comments, dependencies, labels, key-value
|
||||
"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",
|
||||
|
||||
// molecules, epics, todos, state
|
||||
"epic close-eligible", "epic status",
|
||||
"mol bond", "mol burn", "mol current", "mol distill", "mol last-activity", "mol pour",
|
||||
"mol progress", "mol ready", "mol seed", "mol show", "mol squash", "mol stale",
|
||||
"mol wisp", "mol wisp create", "mol wisp gc", "mol wisp list",
|
||||
"state", "state list", "todo", "todo add", "todo done", "todo list",
|
||||
|
||||
// gates, rules, provenance, audit, upgrade review
|
||||
"audit label", "audit record",
|
||||
"gate add-waiter", "gate check", "gate create", "gate list", "gate resolve", "gate show",
|
||||
"provenance by-ref", "provenance log", "provenance record",
|
||||
"rules audit", "rules compact",
|
||||
"upgrade ack", "upgrade review", "upgrade status",
|
||||
|
||||
// workspace lifecycle and configuration
|
||||
"bootstrap", "config apply", "config drift", "config get", "config list", "config set",
|
||||
"config set-many", "config show", "config unset", "config validate", "context",
|
||||
"init", "init-safety", "onboard", "preflight", "quickstart", "schema", "setup", "where",
|
||||
"version", "worktree create", "worktree info", "worktree list", "worktree remove",
|
||||
|
||||
// storage, history and migration paths that are already routed or store-free
|
||||
"compact", "events export", "events prune", "events tail",
|
||||
"dolt clean-databases", "dolt killall", "dolt set", "dolt show", "dolt status",
|
||||
"dolt start", "dolt stop", "dolt test",
|
||||
"migrate from-proxied-server-to-server", "migrate from-proxied-server-to-shared-server",
|
||||
"migrate from-server-to-proxied-server", "migrate from-shared-server-to-proxied-server",
|
||||
"migrate legacy-sqlite", "migrate schema",
|
||||
|
||||
// formulas (parser-only), agent memory, swarm reads
|
||||
"formula convert", "formula list", "formula schema", "formula show",
|
||||
"mail", "memories", "ping", "prime", "recall", "remember",
|
||||
"swarm status", "swarm validate",
|
||||
|
||||
// human-in-the-loop queue
|
||||
"human", "human dismiss", "human list", "human respond", "human stats",
|
||||
|
||||
// trackers: the verbs with no proxied refusal of any kind
|
||||
"ado pull", "ado push", "github pull", "github push", "gitlab pull", "gitlab push",
|
||||
"jira pull", "jira push", "jira status", "jira sync",
|
||||
"linear pull", "linear push", "linear status", "linear sync", "linear teams",
|
||||
"notion pull", "notion push",
|
||||
|
||||
// hooks, metrics, serving and internal entry points
|
||||
"hooks install", "hooks list", "hooks run", "hooks uninstall",
|
||||
"metrics", "metrics example", "metrics off", "metrics on",
|
||||
"serve", "sql",
|
||||
"codex-hook", "cursor-hook", "db-proxy-child", "send-metrics",
|
||||
}
|
||||
|
||||
func init() {
|
||||
for _, path := range proxyPermittedPaths {
|
||||
proxyCapabilityRegistry = append(proxyCapabilityRegistry, permitted(path))
|
||||
}
|
||||
proxyCapabilityIndex = make(map[string]capabilityRow, len(proxyCapabilityRegistry))
|
||||
for _, row := range proxyCapabilityRegistry {
|
||||
proxyCapabilityIndex[capabilityKey(row.Path, row.ArgSet)] = row
|
||||
}
|
||||
}
|
||||
|
||||
// proxyCapabilityIndex is proxyCapabilityRegistry keyed for lookup. Duplicate
|
||||
// keys are rejected by TestProxyCapabilityRegistryHasNoDuplicateRows rather
|
||||
// than by a panic here: a typo must fail the build, not every bd invocation.
|
||||
var proxyCapabilityIndex map[string]capabilityRow
|
||||
|
||||
func capabilityKey(path, argSet string) string { return path + "\x00" + argSet }
|
||||
|
||||
// LookupCapabilityRow returns the row for an exact path/arg-set key.
|
||||
func LookupCapabilityRow(path, argSet string) (capabilityRow, bool) {
|
||||
row, ok := proxyCapabilityIndex[capabilityKey(path, argSet)]
|
||||
return row, ok
|
||||
}
|
||||
|
||||
// capabilityRowFor resolves a command to its row, preferring the row keyed on
|
||||
// the flags the invocation actually set over the bare path.
|
||||
//
|
||||
// The fallback to the bare row is what lets one table serve both halves of the
|
||||
// old policy: a path row refuses whatever flags were passed unless a more
|
||||
// specific row says otherwise, so `backup sync --dry-run` is still refused by
|
||||
// the `backup sync` row. The predecessor of the arg-set half matched exactly or
|
||||
// not at all, which meant an unlisted flag combination on a refused path
|
||||
// slipped through; no such combination exists among the commands that carry
|
||||
// these flags, so nothing changes today, and the fallback is why none can
|
||||
// appear later.
|
||||
func capabilityRowFor(cmd *cobra.Command) (capabilityRow, bool) {
|
||||
path := commandRegistryPath(cmd)
|
||||
if argSet := commandPolicyArgSet(cmd); argSet != "" {
|
||||
if row, ok := LookupCapabilityRow(path, argSet); ok {
|
||||
return row, true
|
||||
}
|
||||
}
|
||||
return LookupCapabilityRow(path, "")
|
||||
}
|
||||
|
||||
// commandRegistryPath is the registry key for a command: its full path with the
|
||||
// root name removed, for example "dolt remote add".
|
||||
func commandRegistryPath(cmd *cobra.Command) string {
|
||||
return strings.TrimSpace(strings.TrimPrefix(cmd.CommandPath(), cmd.Root().Name()))
|
||||
}
|
||||
|
||||
// proxyPolicyArgFlags are the flags that take part in a capability key. Only
|
||||
// flags that alter a command's execution belong here: output, tracing and other
|
||||
// inherited root flags must never bypass a refusal by changing the key.
|
||||
var proxyPolicyArgFlags = map[string]bool{
|
||||
"auto-merge": true, "dry-run": true, "repair": true, "of": true, "with": true,
|
||||
}
|
||||
|
||||
// commandPolicyArgSet renders the set flags that take part in the key, sorted so
|
||||
// the key does not depend on the order the user typed them.
|
||||
func commandPolicyArgSet(cmd *cobra.Command) string {
|
||||
var args []string
|
||||
cmd.Flags().Visit(func(f *pflag.Flag) {
|
||||
if proxyPolicyArgFlags[f.Name] {
|
||||
args = append(args, "--"+f.Name)
|
||||
}
|
||||
})
|
||||
sort.Strings(args)
|
||||
return strings.Join(args, " ")
|
||||
}
|
||||
|
||||
// validateProxyRegistryBeforeProvider is the path-keyed half of the proxied
|
||||
// front door: it rejects direct-only commands before migrations, auto-start or
|
||||
// provider construction, so a refusal leaves the workspace untouched. The
|
||||
// flag-keyed half is validateProxyCapabilitiesBeforeProvider.
|
||||
//
|
||||
// topology is the workspace's proxied shape (resolveProxiedTopology). It is a
|
||||
// parameter rather than a lookup inside so the gate can be exercised for every
|
||||
// shape without a workspace on disk.
|
||||
func validateProxyRegistryBeforeProvider(cmd *cobra.Command, topology ProxyTopology) error {
|
||||
if cmd == nil {
|
||||
return nil
|
||||
}
|
||||
// `compact` is the one rule that a flag VALUE decides rather than a flag's
|
||||
// presence, so it cannot be expressed as an arg-set row. `bd compact` and
|
||||
// `bd rules compact` have no --dolt flag at all and are never refused here;
|
||||
// `bd admin compact --dolt` has a proxied route and falls through to it.
|
||||
if cmd.Name() == "compact" {
|
||||
if cmd.Flags().Lookup("dolt") == nil {
|
||||
return nil
|
||||
}
|
||||
if dolt, _ := cmd.Flags().GetBool("dolt"); dolt {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
row, ok := capabilityRowFor(cmd)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
rule := row.ruleFor(topology)
|
||||
if rule.Outcome != ProxyOutcomeRefused {
|
||||
return nil
|
||||
}
|
||||
return HandleProxyCapabilityError(proxyCapabilityErrorFor(rule))
|
||||
}
|
||||
|
||||
func proxyCapabilityErrorFor(rule proxyCapabilityRule) *ProxyCapabilityError {
|
||||
return &ProxyCapabilityError{
|
||||
Code: rule.Code,
|
||||
Message: rule.Message,
|
||||
ExitCode: rule.ExitCode,
|
||||
Mutates: rule.Mutates,
|
||||
Reason: rule.Reason,
|
||||
}
|
||||
}
|
||||
|
||||
// HistoryCapabilityClass classifies history/version-control commands on the
|
||||
// proxied topology without coupling them to a particular backend engine.
|
||||
type HistoryCapabilityClass string
|
||||
|
||||
const (
|
||||
HistoryProxySupported HistoryCapabilityClass = "proxy-supported"
|
||||
HistoryDirectOnly HistoryCapabilityClass = "direct-only"
|
||||
)
|
||||
|
||||
// LookupHistoryCapability classifies an exact command path. Paths with no
|
||||
// history classification are intentionally absent so callers cannot
|
||||
// accidentally advertise support.
|
||||
func LookupHistoryCapability(commandPath string) (HistoryCapabilityClass, bool) {
|
||||
row, ok := LookupCapabilityRow(commandPath, "")
|
||||
if !ok || row.History == "" {
|
||||
return "", false
|
||||
}
|
||||
return row.History, true
|
||||
}
|
||||
|
|
@ -12,13 +12,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 {
|
||||
|
|
@ -31,7 +35,7 @@ func TestSyncRefusesBeforeProvider(t *testing.T) {
|
|||
root := &cobra.Command{Use: "bd"}
|
||||
cmd := &cobra.Command{Use: "sync"}
|
||||
root.AddCommand(cmd)
|
||||
err := validateProxyMaintenanceBeforeProvider(cmd)
|
||||
err := validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal)
|
||||
if err == nil {
|
||||
t.Fatalf("sync refusal = %#v", err)
|
||||
}
|
||||
|
|
@ -50,7 +54,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"},
|
||||
|
|
@ -59,7 +62,7 @@ func TestHistoryDirectOnlyRefusalContract(t *testing.T) {
|
|||
oldProvider := uowProvider
|
||||
oldJSON := jsonOutput
|
||||
t.Cleanup(func() { uowProvider = oldProvider; jsonOutput = oldJSON })
|
||||
for _, path := range []string{"branch", "conflicts", "repo", "federation", "vc", "flatten", "dolt push", "dolt pull", "dolt commit", "dolt remote add", "sync"} {
|
||||
for _, path := range []string{"branch", "conflicts", "repo", "federation", "vc", "flatten", "dolt push", "dolt pull", "dolt remote add", "sync"} {
|
||||
parts := strings.Split(path, " ")
|
||||
root := &cobra.Command{Use: "bd"}
|
||||
cmd := &cobra.Command{Use: parts[0]}
|
||||
|
|
@ -71,7 +74,7 @@ func TestHistoryDirectOnlyRefusalContract(t *testing.T) {
|
|||
}
|
||||
uowProvider = nil
|
||||
jsonOutput = true
|
||||
out := captureStdout(t, func() error { _ = validateProxyMaintenanceBeforeProvider(cmd); return nil })
|
||||
out := captureStdout(t, func() error { _ = validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal); return nil })
|
||||
var got map[string]any
|
||||
want := expected[path]
|
||||
if err := json.Unmarshal([]byte(out), &got); err != nil || got["code"] != want.code || got["error"] != want.message || got["mutates"] != false {
|
||||
|
|
@ -94,7 +97,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]}
|
||||
|
|
@ -104,8 +107,8 @@ func TestHistoryNestedFrontDoorsRefuseAndSupportedPathsPass(t *testing.T) {
|
|||
cmd.AddCommand(child)
|
||||
cmd = child
|
||||
}
|
||||
err := validateProxyMaintenanceBeforeProvider(cmd)
|
||||
if path == "dolt remote remove" {
|
||||
err := validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal)
|
||||
if path == "dolt remote remove" || path == "dolt commit" {
|
||||
if err != nil {
|
||||
t.Fatalf("supported %s refused: %v", path, err)
|
||||
}
|
||||
|
|
@ -118,9 +121,9 @@ func TestHistoryNestedFrontDoorsRefuseAndSupportedPathsPass(t *testing.T) {
|
|||
t.Fatalf("%s exit=%v, want 1", path, err)
|
||||
}
|
||||
var got map[string]any
|
||||
// validateProxyMaintenanceBeforeProvider renders the typed refusal to
|
||||
// validateProxyRegistryBeforeProvider renders the typed refusal to
|
||||
// stdout in JSON mode; the command must retain its nested path.
|
||||
out := captureStdout(t, func() error { _ = validateProxyMaintenanceBeforeProvider(cmd); return nil })
|
||||
out := captureStdout(t, func() error { _ = validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal); return nil })
|
||||
if err := json.Unmarshal([]byte(out), &got); err != nil {
|
||||
t.Fatalf("%s refusal JSON: %v (%q)", path, err, out)
|
||||
}
|
||||
|
|
@ -132,7 +135,7 @@ func TestHistoryNestedFrontDoorsRefuseAndSupportedPathsPass(t *testing.T) {
|
|||
root := &cobra.Command{Use: "bd"}
|
||||
history := &cobra.Command{Use: "history"}
|
||||
root.AddCommand(history)
|
||||
if err := validateProxyMaintenanceBeforeProvider(history); err != nil {
|
||||
if err := validateProxyRegistryBeforeProvider(history, ProxyTopologyManagedLocal); err != nil {
|
||||
t.Fatalf("history --events supported path refused: %v", err)
|
||||
}
|
||||
}
|
||||
423
cmd/bd/capability_registry_test.go
Normal file
423
cmd/bd/capability_registry_test.go
Normal file
|
|
@ -0,0 +1,423 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// cobraBuiltinCommands are added to the tree by cobra itself, not by bd, and
|
||||
// only once something calls Execute — which another test in this package does
|
||||
// (completions_test.go runs __complete). Without this set the completeness test
|
||||
// below would pass or fail depending on test ORDER, which is the worst possible
|
||||
// property for a policy gate.
|
||||
var cobraBuiltinCommands = map[string]bool{
|
||||
"help": true, "completion": true, "__complete": true, "__completeNoDesc": true,
|
||||
}
|
||||
|
||||
// walkCommandPaths returns every command path in the tree, with the runnable
|
||||
// ones flagged. Runnable is the property that matters: cobra returns ErrHelp
|
||||
// for a non-runnable parent before PersistentPreRunE, so a group command never
|
||||
// reaches the capability gate at all.
|
||||
func walkCommandPaths(root *cobra.Command) map[string]bool {
|
||||
paths := map[string]bool{}
|
||||
var walk func(c *cobra.Command)
|
||||
walk = func(c *cobra.Command) {
|
||||
if cobraBuiltinCommands[c.Name()] {
|
||||
return
|
||||
}
|
||||
if path := commandRegistryPath(c); path != "" {
|
||||
paths[path] = c.Runnable()
|
||||
}
|
||||
for _, sub := range c.Commands() {
|
||||
walk(sub)
|
||||
}
|
||||
}
|
||||
walk(root)
|
||||
return paths
|
||||
}
|
||||
|
||||
// TestProxyCapabilityRegistryCoversCommandTree is the reason this registry
|
||||
// exists. Every command that can actually run must state what the proxied front
|
||||
// door does with it. A new command with no row fails here, at build time, rather
|
||||
// than shipping and dying in the store factory with an untyped error — which is
|
||||
// how every scattered refusal in this codebase got there.
|
||||
//
|
||||
// Adding a row is not a formality: choose the outcome deliberately.
|
||||
// - the command works over the proxied provider, or never opens a store at
|
||||
// all => add its path to proxyPermittedPaths
|
||||
// - the command must not run on a shared/proxied store => add a refusedPath
|
||||
// row with Reason=design and say why in a comment
|
||||
// - the command could work but nobody has routed it => add a refusedPath row
|
||||
// with Reason=unimplemented and a Tracking item
|
||||
func TestProxyCapabilityRegistryCoversCommandTree(t *testing.T) {
|
||||
var missing []string
|
||||
for path, runnable := range walkCommandPaths(rootCmd) {
|
||||
if !runnable {
|
||||
continue
|
||||
}
|
||||
if _, ok := LookupCapabilityRow(path, ""); !ok {
|
||||
missing = append(missing, path)
|
||||
}
|
||||
}
|
||||
sort.Strings(missing)
|
||||
if len(missing) > 0 {
|
||||
t.Fatalf("%d command(s) have no proxied-server capability row:\n %s\n\n"+
|
||||
"Add each to cmd/bd/capability_registry.go: proxyPermittedPaths if the proxied "+
|
||||
"front door should let it through, or a refusedPath row with a Reason if it should not.",
|
||||
len(missing), strings.Join(missing, "\n "))
|
||||
}
|
||||
}
|
||||
|
||||
// TestProxyCapabilityRegistryHasNoStaleRows is the other direction: a row whose
|
||||
// command no longer exists is policy for nothing, and would hide the renamed
|
||||
// command's own missing row behind a green test.
|
||||
func TestProxyCapabilityRegistryHasNoStaleRows(t *testing.T) {
|
||||
tree := walkCommandPaths(rootCmd)
|
||||
var stale []string
|
||||
for _, row := range proxyCapabilityRegistry {
|
||||
if _, ok := tree[row.Path]; !ok {
|
||||
stale = append(stale, row.display())
|
||||
}
|
||||
}
|
||||
sort.Strings(stale)
|
||||
if len(stale) > 0 {
|
||||
t.Fatalf("registry rows for commands that do not exist:\n %s", strings.Join(stale, "\n "))
|
||||
}
|
||||
}
|
||||
|
||||
func TestProxyCapabilityRegistryHasNoDuplicateRows(t *testing.T) {
|
||||
seen := map[string]bool{}
|
||||
for _, row := range proxyCapabilityRegistry {
|
||||
key := capabilityKey(row.Path, row.ArgSet)
|
||||
if seen[key] {
|
||||
t.Errorf("duplicate registry row for %q: one of them is dead and the lookup silently picks the last", row.display())
|
||||
}
|
||||
seen[key] = true
|
||||
}
|
||||
}
|
||||
|
||||
// TestProxyCapabilityRegistryRowInvariants pins the contract every row must
|
||||
// satisfy. The Reason rules are the load-bearing ones: a refusal with no reason
|
||||
// is exactly the tribal knowledge this registry replaces, and an unimplemented
|
||||
// refusal with no tracking item is a gap nobody owns.
|
||||
func TestProxyCapabilityRegistryRowInvariants(t *testing.T) {
|
||||
for _, row := range proxyCapabilityRegistry {
|
||||
assertCapabilityRuleInvariants(t, row.display(), row.Rule)
|
||||
for topology, rule := range row.Topology {
|
||||
assertCapabilityRuleInvariants(t, row.display()+" on "+string(topology), rule)
|
||||
if topology == ProxyTopologyUnknown {
|
||||
t.Errorf("%s: a row must not name the unknown topology; unknown exists so an unclassifiable "+
|
||||
"workspace INHERITS the refusal, and exempting it would invert that", row.display())
|
||||
}
|
||||
}
|
||||
if row.History == HistoryDirectOnly && row.Rule.Outcome != ProxyOutcomeRefused {
|
||||
t.Errorf("%s: classified direct-only but the gate does not refuse it", row.display())
|
||||
}
|
||||
if row.History == HistoryProxySupported && row.Rule.Outcome != ProxyOutcomeHonored {
|
||||
t.Errorf("%s: classified proxy-supported but the gate refuses it", row.display())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// assertCapabilityRuleInvariants checks one rule — a row's default or one of
|
||||
// its per-topology overrides. Both have to satisfy the same contract: a
|
||||
// topology override is policy a consumer sees, not a footnote.
|
||||
func assertCapabilityRuleInvariants(t *testing.T, where string, rule proxyCapabilityRule) {
|
||||
t.Helper()
|
||||
switch rule.Outcome {
|
||||
case ProxyOutcomeRefused:
|
||||
if rule.Code == "" || rule.Message == "" || rule.ExitCode != 1 {
|
||||
t.Errorf("%s: refusal must carry a code, a message and exit 1, got %#v", where, rule)
|
||||
}
|
||||
if rule.Mutates {
|
||||
t.Errorf("%s: a refusal never mutates", where)
|
||||
}
|
||||
if !strings.HasPrefix(rule.Code, "proxy.") {
|
||||
t.Errorf("%s: code %q must be in the stable proxy.* namespace", where, rule.Code)
|
||||
}
|
||||
case ProxyOutcomeRefusedInRunE:
|
||||
if rule.Code != "" {
|
||||
t.Errorf("%s: an untyped RunE refusal has no code; if it has one it belongs in the gate", where)
|
||||
}
|
||||
case ProxyOutcomeHonored:
|
||||
if rule.Reason != "" {
|
||||
t.Errorf("%s: Reason explains a refusal; an honored row must not carry one", where)
|
||||
}
|
||||
default:
|
||||
t.Errorf("%s: unexpected outcome %q", where, rule.Outcome)
|
||||
}
|
||||
|
||||
if rule.Outcome == ProxyOutcomeRefused || rule.Outcome == ProxyOutcomeRefusedInRunE {
|
||||
switch rule.Reason {
|
||||
case ProxyReasonDesign, ProxyReasonUnimplemented:
|
||||
default:
|
||||
t.Errorf("%s: refusal must declare Reason design or unimplemented, got %q", where, rule.Reason)
|
||||
}
|
||||
if rule.Reason == ProxyReasonUnimplemented && rule.Tracking == "" {
|
||||
t.Errorf("%s: an unimplemented refusal needs a Tracking item naming who closes it", where)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// inlineProxiedRefusal matches the untyped refusals commands raise from their
|
||||
// own RunE, e.g. HandleErrorRespectJSON("gitlab sync is not supported in
|
||||
// proxied-server mode").
|
||||
var inlineProxiedRefusal = regexp.MustCompile(`HandleErrorRespectJSON\("([^"]*proxied-server mode)"\)`)
|
||||
|
||||
// inlineProxiedMessages classifies the messages that do not name their command
|
||||
// path in the standard "<path> is not supported ..." shape. A path maps the
|
||||
// message to its registry row; an empty string records a message that mentions
|
||||
// proxied mode without being a capability refusal at all. Keeping both explicit
|
||||
// is what lets the scan below be exhaustive rather than best-effort.
|
||||
var inlineProxiedMessages = map[string]string{
|
||||
"only 'compact --dolt' is supported in proxied-server mode": "admin compact",
|
||||
// Not a refusal: --database is the flag that only MAKES SENSE on a proxied
|
||||
// workspace, so this fires on the direct topologies.
|
||||
"--database (or a --db value naming a database) is only supported in proxied-server mode": "",
|
||||
}
|
||||
|
||||
// TestProxyCapabilityRegistryCoversInlineRefusals scans the package for
|
||||
// refusals raised inside RunE and requires each one to resolve to a registry
|
||||
// row. Those strings are the untyped half of the refusal surface — no code, no
|
||||
// mutates flag, nothing a JSON consumer can classify — and before the registry
|
||||
// they were discoverable only by grep.
|
||||
//
|
||||
// The scan runs in both directions on purpose: a new inline refusal must be
|
||||
// registered, and a ProxyOutcomeRefusedInRunE row whose string has been deleted
|
||||
// must be flipped to its new outcome by the slice that deleted it.
|
||||
func TestProxyCapabilityRegistryCoversInlineRefusals(t *testing.T) {
|
||||
entries, err := os.ReadDir(".")
|
||||
if err != nil {
|
||||
t.Fatalf("read package dir: %v", err)
|
||||
}
|
||||
|
||||
found := map[string]string{} // registry path -> file it was found in
|
||||
for _, entry := range entries {
|
||||
name := entry.Name()
|
||||
if entry.IsDir() || !strings.HasSuffix(name, ".go") || strings.HasSuffix(name, "_test.go") {
|
||||
continue
|
||||
}
|
||||
src, err := os.ReadFile(filepath.Clean(name))
|
||||
if err != nil {
|
||||
t.Fatalf("read %s: %v", name, err)
|
||||
}
|
||||
for _, match := range inlineProxiedRefusal.FindAllStringSubmatch(string(src), -1) {
|
||||
message := match[1]
|
||||
path, ok := inlineRefusalPath(message)
|
||||
if !ok {
|
||||
t.Errorf("%s: %q mentions proxied-server mode but does not name a command path; "+
|
||||
"add it to inlineProxiedMessages so it can be checked against the registry "+
|
||||
"(map it to \"\" if it is not a capability refusal)", name, message)
|
||||
continue
|
||||
}
|
||||
if path == "" {
|
||||
continue // documented non-refusal
|
||||
}
|
||||
found[path] = name
|
||||
}
|
||||
}
|
||||
|
||||
for path, file := range found {
|
||||
argSet := ""
|
||||
if base, args, split := strings.Cut(path, " --"); split {
|
||||
argSet = "--" + args
|
||||
path = base
|
||||
}
|
||||
row, ok := LookupCapabilityRow(path, argSet)
|
||||
if !ok {
|
||||
t.Errorf("%s refuses %q inside RunE with no registry row; the front door and the command disagree about what bd supports",
|
||||
file, strings.TrimSpace(path+" "+argSet))
|
||||
continue
|
||||
}
|
||||
if row.Rule.Outcome == ProxyOutcomeHonored {
|
||||
t.Errorf("%s refuses %q inside RunE, but the registry says the front door honors it", file, row.display())
|
||||
}
|
||||
}
|
||||
|
||||
for _, row := range proxyCapabilityRegistry {
|
||||
if row.Rule.Outcome != ProxyOutcomeRefusedInRunE {
|
||||
continue
|
||||
}
|
||||
if _, ok := found[row.Path]; !ok {
|
||||
t.Errorf("%s is recorded as an untyped RunE refusal but no such refusal exists in the package any more (%s); "+
|
||||
"flip the row to its new outcome", row.display(), row.Note)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func inlineRefusalPath(message string) (string, bool) {
|
||||
if path, ok := inlineProxiedMessages[message]; ok {
|
||||
return path, true
|
||||
}
|
||||
path, ok := strings.CutSuffix(message, " is not supported in proxied-server mode")
|
||||
if !ok {
|
||||
return "", false
|
||||
}
|
||||
// conflicts.go says "bd conflicts ..."; the registry keys on the path.
|
||||
return strings.TrimPrefix(path, "bd "), true
|
||||
}
|
||||
|
||||
// TestProxyCapabilityRegistryReasonsAreAssignedIndividually guards the one way
|
||||
// this registry could become useless while staying green: reasons assigned in
|
||||
// bulk. Every later slice reads these to decide what is left to do, so both
|
||||
// values have to be genuinely represented, and the design refusals — the claim
|
||||
// a reviewer will challenge — are listed here by name.
|
||||
func TestProxyCapabilityRegistryReasonsAreAssignedIndividually(t *testing.T) {
|
||||
wantDesign := map[string]bool{
|
||||
"branch": true, "diff": true, "flatten": true,
|
||||
"conflicts": true, "conflicts list": true, "conflicts show": true, "conflicts resolve": true,
|
||||
"vc": true, "vc merge": true, "vc commit": true, "vc status": true,
|
||||
"federation": true, "federation sync": true, "federation status": true,
|
||||
"federation add-peer": true, "federation remove-peer": true, "federation list-peers": true,
|
||||
"repo": true, "repo add": true, "repo remove": true, "repo list": true, "repo sync": true,
|
||||
// `migrate hooks` is deliberately NOT here: it migrates git hook files
|
||||
// and opens no store, so the surgery rationale the rest of this block
|
||||
// rests on does not describe it. Its refusal is structural — the
|
||||
// command is on none of main.go's store-init skip lists — which makes
|
||||
// it unimplemented with a tracking item, not design.
|
||||
"migrate": true, "migrate sync": true, "migrate issues": true,
|
||||
"migrate-issues": true, "migrate-personal": true,
|
||||
"admin cleanup": true, "admin reset": true,
|
||||
// The backup family's DEFAULT rule is the design refusal; managed-local
|
||||
// overrides it to honored (TestProxiedBackupHonoredOnlyOnManagedLocal).
|
||||
// It is design because a backup remote is registered on the SERVER,
|
||||
// where it is global to every client of that server — true of every
|
||||
// destination scheme, unlike the filesystem half, which is a file://
|
||||
// property only. These rows carry a Tracking item anyway
|
||||
// (backupRemoteSchemeTracking): the outcome is settled, the
|
||||
// remote-scheme case is an open question and must not read as closed.
|
||||
"backup": true, "backup init": true, "backup sync": true,
|
||||
"backup remove": true, "backup status": true, "backup restore": true,
|
||||
}
|
||||
|
||||
gotDesign := map[string]bool{}
|
||||
unimplemented := 0
|
||||
for _, row := range proxyCapabilityRegistry {
|
||||
switch row.Rule.Reason {
|
||||
case ProxyReasonDesign:
|
||||
gotDesign[row.display()] = true
|
||||
case ProxyReasonUnimplemented:
|
||||
unimplemented++
|
||||
}
|
||||
}
|
||||
|
||||
for path := range wantDesign {
|
||||
if !gotDesign[path] {
|
||||
t.Errorf("%q is no longer refused by design; if that is intended, update this test and say why in the PR", path)
|
||||
}
|
||||
}
|
||||
for path := range gotDesign {
|
||||
if !wantDesign[path] {
|
||||
t.Errorf("%q claims Reason=design and is not in the reviewed list; a design refusal is a semantic claim that needs review", path)
|
||||
}
|
||||
}
|
||||
if unimplemented == 0 {
|
||||
t.Error("no unimplemented refusals left — either the work is done or the reasons were bulk-assigned")
|
||||
}
|
||||
}
|
||||
|
||||
// TestProxyCapabilityArgSetFallsBackToBarePath pins the lookup rule that lets
|
||||
// one table carry both the path policy and the flag policy: a flag combination
|
||||
// with no row of its own inherits the bare path's verdict rather than escaping
|
||||
// it. Written against the real command tree so it exercises the flags these
|
||||
// commands actually declare.
|
||||
func TestProxyCapabilityArgSetFallsBackToBarePath(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
path string
|
||||
flags []string
|
||||
want ProxyCapabilityOutcome
|
||||
wantMsg string
|
||||
}{
|
||||
// Covered by an explicit row: the message names the flags.
|
||||
{"rename-prefix", []string{"dry-run"}, ProxyOutcomeRefused, "rename-prefix --dry-run is not supported in proxied-server mode"},
|
||||
// No row for this combination: it inherits the refused bare row rather
|
||||
// than slipping past the gate.
|
||||
{"rename-prefix", []string{"dry-run", "auto-merge"}, ProxyOutcomeRefused, "rename-prefix is not supported in proxied-server mode"},
|
||||
// Inheriting an honored bare row is equally load-bearing: this is the
|
||||
// read-only preview and it must keep working.
|
||||
{"duplicates", []string{"dry-run"}, ProxyOutcomeHonored, ""},
|
||||
} {
|
||||
t.Run(tc.path+" "+strings.Join(tc.flags, " "), func(t *testing.T) {
|
||||
root := &cobra.Command{Use: "bd"}
|
||||
cmd := &cobra.Command{Use: tc.path}
|
||||
root.AddCommand(cmd)
|
||||
for _, flag := range tc.flags {
|
||||
cmd.Flags().Bool(flag, false, "")
|
||||
if err := cmd.Flags().Set(flag, "true"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
row, ok := capabilityRowFor(cmd)
|
||||
if !ok {
|
||||
t.Fatalf("no row resolved for %q with %v", tc.path, tc.flags)
|
||||
}
|
||||
if row.Rule.Outcome != tc.want || row.Rule.Message != tc.wantMsg {
|
||||
t.Fatalf("row = outcome %q message %q, want %q / %q",
|
||||
row.Rule.Outcome, row.Rule.Message, tc.want, tc.wantMsg)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestProxyRefusalJSONCarriesReason pins the additive half of the JSON
|
||||
// contract. {code, error, mutates} is frozen and parsed downstream; reason is
|
||||
// new, and it must appear without disturbing the three fields that were already
|
||||
// there.
|
||||
func TestProxyRefusalJSONCarriesReason(t *testing.T) {
|
||||
t.Setenv("BD_JSON_ENVELOPE", "")
|
||||
oldJSON := jsonOutput
|
||||
jsonOutput = true
|
||||
t.Cleanup(func() { jsonOutput = oldJSON })
|
||||
|
||||
for _, tc := range []struct {
|
||||
path, code string
|
||||
reason ProxyRefusalReason
|
||||
}{
|
||||
{"branch", "proxy.branch.unsupported", ProxyReasonDesign},
|
||||
{"sync", "proxy.sync.unsupported", ProxyReasonUnimplemented},
|
||||
} {
|
||||
t.Run(tc.path, func(t *testing.T) {
|
||||
root := &cobra.Command{Use: "bd"}
|
||||
cmd := &cobra.Command{Use: tc.path}
|
||||
root.AddCommand(cmd)
|
||||
out := captureStdout(t, func() error {
|
||||
_ = validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal)
|
||||
return nil
|
||||
})
|
||||
for _, want := range []string{
|
||||
`"code": "` + tc.code + `"`,
|
||||
`"error": "` + tc.path + ` is not supported in proxied-server mode"`,
|
||||
`"mutates": false`,
|
||||
`"reason": "` + string(tc.reason) + `"`,
|
||||
} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Fatalf("refusal JSON missing %s:\n%s", want, out)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestProxiedStoreUnroutedIsTyped covers the backstop: a permitted command with
|
||||
// no proxied route used to die with a bare string that no consumer could tell
|
||||
// from a real store failure.
|
||||
func TestProxiedStoreUnroutedIsTyped(t *testing.T) {
|
||||
var typed *ProxyCapabilityError
|
||||
err := errProxiedStoreUnrouted()
|
||||
if !errors.As(err, &typed) {
|
||||
t.Fatalf("store backstop error = %#v, want *ProxyCapabilityError", err)
|
||||
}
|
||||
if typed.Code != "proxy.store.unrouted" || typed.ExitCode != 1 || typed.Mutates {
|
||||
t.Fatalf("store backstop = %#v", typed)
|
||||
}
|
||||
if typed.Reason != ProxyReasonUnimplemented {
|
||||
t.Fatalf("store backstop reason = %q, want unimplemented", typed.Reason)
|
||||
}
|
||||
}
|
||||
|
|
@ -58,24 +58,25 @@ func TestProxyTransformCapabilityRows(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
row, ok := lookupTransformCapability(cmd)
|
||||
row, ok := capabilityRowFor(cmd)
|
||||
if !ok {
|
||||
t.Fatalf("lookup(%q, %q) missing row", tc.path, tc.argument)
|
||||
}
|
||||
if row.Path != tc.path || row.Argument != tc.argument || row.Outcome != tc.outcome {
|
||||
if row.Path != tc.path || row.ArgSet != tc.argument || row.Rule.Outcome != tc.outcome {
|
||||
t.Fatalf("row = %#v, want path=%q argument=%q outcome=%q", row, tc.path, tc.argument, tc.outcome)
|
||||
}
|
||||
if tc.outcome == ProxyOutcomeRefused {
|
||||
if row.Code != tc.code || row.Message != tc.message || row.ExitCode != tc.exit || row.Mutates != tc.mutates {
|
||||
t.Fatalf("refusal fields = code=%q message=%q exit=%d mutates=%t", row.Code, row.Message, row.ExitCode, row.Mutates)
|
||||
if row.Rule.Code != tc.code || row.Rule.Message != tc.message || row.Rule.ExitCode != tc.exit || row.Rule.Mutates != tc.mutates {
|
||||
t.Fatalf("refusal fields = code=%q message=%q exit=%d mutates=%t",
|
||||
row.Rule.Code, row.Rule.Message, row.Rule.ExitCode, row.Rule.Mutates)
|
||||
}
|
||||
typed := transformCapabilityError(row)
|
||||
var typed error = proxyCapabilityErrorFor(row.Rule)
|
||||
var got *ProxyCapabilityError
|
||||
if !errors.As(typed, &got) || got.Code != tc.code || got.ExitCode != 1 || got.Mutates {
|
||||
t.Fatalf("typed refusal = %#v", typed)
|
||||
}
|
||||
}
|
||||
if err := validateProxyTransformBeforeProvider(cmd); tc.outcome == ProxyOutcomeHonored && err != nil {
|
||||
if err := validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal); tc.outcome == ProxyOutcomeHonored && err != nil {
|
||||
t.Fatalf("honored transform refused: %v", err)
|
||||
}
|
||||
})
|
||||
|
|
@ -85,11 +86,11 @@ func TestProxyTransformCapabilityRows(t *testing.T) {
|
|||
func TestProxyDuplicatesAutoMergeDryRunMatrix(t *testing.T) {
|
||||
cmd := transformTestCommand("duplicates", "auto-merge", "dry-run")
|
||||
_ = cmd.Flags().Set("auto-merge", "true")
|
||||
if err := validateProxyTransformBeforeProvider(cmd); err == nil {
|
||||
if err := validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal); err == nil {
|
||||
t.Fatalf("non-dry auto-merge error = %v", err)
|
||||
}
|
||||
_ = cmd.Flags().Set("dry-run", "true")
|
||||
if err := validateProxyTransformBeforeProvider(cmd); err != nil {
|
||||
if err := validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal); err != nil {
|
||||
t.Fatalf("dry-run auto-merge refused: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -103,7 +104,7 @@ func TestProxyTransformRefusalRendering(t *testing.T) {
|
|||
jsonOutput = false
|
||||
var textErr string
|
||||
stderr := captureStderr(t, func() {
|
||||
err := validateProxyTransformBeforeProvider(cmd)
|
||||
err := validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal)
|
||||
if code, ok := exitCodeFromError(err); !ok || code != 1 {
|
||||
t.Fatalf("exit = %v, want 1", err)
|
||||
}
|
||||
|
|
@ -115,7 +116,7 @@ func TestProxyTransformRefusalRendering(t *testing.T) {
|
|||
|
||||
jsonOutput = true
|
||||
stdout := captureStdout(t, func() error {
|
||||
_ = validateProxyTransformBeforeProvider(cmd)
|
||||
_ = validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal)
|
||||
return nil
|
||||
})
|
||||
var envelope map[string]any
|
||||
|
|
@ -140,8 +141,8 @@ func TestProxyTransformMatcherIgnoresInheritedOutputFlags(t *testing.T) {
|
|||
if err := root.PersistentFlags().Set("json", "true"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
row, ok := lookupTransformCapability(cmd)
|
||||
if !ok || row.Argument != "--auto-merge" || row.Outcome != ProxyOutcomeRefused {
|
||||
row, ok := capabilityRowFor(cmd)
|
||||
if !ok || row.ArgSet != "--auto-merge" || row.Rule.Outcome != ProxyOutcomeRefused {
|
||||
t.Fatalf("row with inherited --json = %#v, ok=%v", row, ok)
|
||||
}
|
||||
}
|
||||
|
|
@ -163,7 +164,7 @@ func TestProxyTransformRefusalHasNoProviderOrFileMutation(t *testing.T) {
|
|||
t.Cleanup(func() { uowProvider = oldProvider })
|
||||
|
||||
cmd := transformTestCommand("supersede")
|
||||
err := validateProxyTransformBeforeProvider(cmd)
|
||||
err := validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal)
|
||||
if err == nil {
|
||||
t.Fatal("expected transform refusal")
|
||||
}
|
||||
105
cmd/bd/close.go
105
cmd/bd/close.go
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
|
@ -145,6 +146,7 @@ the flags appear in the command line.`,
|
|||
closedIssues := []*types.Issue{}
|
||||
closedCount := 0
|
||||
alreadyClosed := 0
|
||||
var failures []closeIDFailure
|
||||
firstSettledID := ""
|
||||
|
||||
for i, id := range resolvedIDs {
|
||||
|
|
@ -153,10 +155,15 @@ the flags appear in the command line.`,
|
|||
// The CLI's own close policy refused this argument, so the
|
||||
// batch never saw it.
|
||||
fmt.Fprintln(os.Stderr, plan.refusals[i])
|
||||
failures = append(failures, closeIDFailure{ID: id, Error: plan.refusals[i]})
|
||||
continue
|
||||
}
|
||||
if res.Err != nil {
|
||||
fmt.Fprintln(os.Stderr, closeDirectRefusal(id, res.Err))
|
||||
// The typed error, not the decorated display line: the --force
|
||||
// hint closeDirectRefusal appends is advice for a human reader,
|
||||
// and the id already has its own field.
|
||||
failures = append(failures, closeIDFailure{ID: id, Error: res.Err.Error()})
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -318,6 +325,17 @@ the flags appear in the command line.`,
|
|||
// claimed store anyway: the batch committed the claim, but the sweep
|
||||
// below still has to name it if a molecule auto-close made the store
|
||||
// dirty again.
|
||||
//
|
||||
// A batch that also REFUSED an id still reports its claim here, and
|
||||
// that is deliberate (#6648). The claim landed inside the batch's
|
||||
// transaction alongside the survivors and a sibling's refusal does not
|
||||
// roll it back, so suppressing the report would not un-claim anything —
|
||||
// it would only leave an issue assigned to this actor with nothing on
|
||||
// stdout or stderr saying so. The claim is announced here and named
|
||||
// again in reportCloseFailures' summary, so a caller that exits on the
|
||||
// nonzero status can still see what it owns. Retrying the same command
|
||||
// does not stack claims: the survivor is already closed the second time
|
||||
// round, nothing lands, and an empty batch earns no claim.
|
||||
var claimedNextIssue *types.Issue
|
||||
if claimNext && closedForCommand && !continueFlag {
|
||||
if claimedNext != nil {
|
||||
|
|
@ -370,6 +388,9 @@ the flags appear in the command line.`,
|
|||
}
|
||||
|
||||
totalAttempted := len(resolvedIDs)
|
||||
if len(failures) > 0 {
|
||||
return reportCloseFailures(failures, totalAttempted, closeClaimedID(claimedNextIssue), jsonOutput)
|
||||
}
|
||||
if totalAttempted > 0 && closedCount == 0 && alreadyClosed == 0 {
|
||||
return SilentExit()
|
||||
}
|
||||
|
|
@ -377,6 +398,88 @@ the flags appear in the command line.`,
|
|||
},
|
||||
}
|
||||
|
||||
// closeIDFailure records one issue id a batch close refused, and why. It
|
||||
// mirrors updateIDFailure (update.go) on purpose: `bd close` and `bd update`
|
||||
// are the two write verbs that take a list of ids, so a caller that learned to
|
||||
// read one partial-failure report should not have to learn a second shape.
|
||||
type closeIDFailure struct {
|
||||
ID string `json:"id"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
// closeClaimedID names the issue --claim-next claimed on this run, or "" when
|
||||
// the run claimed nothing.
|
||||
func closeClaimedID(claimed *types.Issue) string {
|
||||
if claimed == nil {
|
||||
return ""
|
||||
}
|
||||
return claimed.ID
|
||||
}
|
||||
|
||||
// reportCloseFailures emits the partial-failure summary both close routes end
|
||||
// on and returns the nonzero exit that #6648 added. Every refusal has already
|
||||
// been printed inline, in the order the ids were typed; this is the summary
|
||||
// that says how much of the batch was left open.
|
||||
//
|
||||
// Both routes report through here so the wording and the JSON shape are stated
|
||||
// once instead of hand-rolled per route. Each route still passes its own
|
||||
// denominator, because only it knows what it attempted — the direct route
|
||||
// counts resolved ids, the proxied one counts arguments.
|
||||
//
|
||||
// The summary is suppressed for a single-id batch deliberately: one inline
|
||||
// refusal is already unambiguous about which id failed, and suppressing it
|
||||
// keeps single-id stderr byte-identical to what it was before close learned to
|
||||
// fail a partial batch.
|
||||
//
|
||||
// In --json mode the summary is one compact JSON line on stderr — the shape
|
||||
// reportUpdateFailures established — so a consumer that sees exit 1 can read
|
||||
// WHICH ids failed instead of scraping English prose, while stdout keeps the
|
||||
// plain closed-issues array a successful close emits. claimedNextID names the
|
||||
// issue --claim-next claimed on this run, if any: that claim is committed
|
||||
// inside the batch's own transaction and a sibling's refusal does not roll it
|
||||
// back, so the report names it rather than pretending it did not happen.
|
||||
func reportCloseFailures(failures []closeIDFailure, total int, claimedNextID string, jsonOut bool) error {
|
||||
if total <= 1 {
|
||||
return SilentExit()
|
||||
}
|
||||
msg := fmt.Sprintf("%d of %d issues failed to close", len(failures), total)
|
||||
|
||||
if !jsonOut {
|
||||
fmt.Fprintf(os.Stderr, "Error: %s\n", msg)
|
||||
if claimedNextID != "" {
|
||||
fmt.Fprintf(os.Stderr, "Note: --claim-next already claimed %s; it stays assigned to you.\n", claimedNextID)
|
||||
}
|
||||
return SilentExit()
|
||||
}
|
||||
|
||||
inner := map[string]interface{}{
|
||||
"error": msg,
|
||||
"failed": failures,
|
||||
}
|
||||
if claimedNextID != "" {
|
||||
inner["claimed"] = claimedNextID
|
||||
}
|
||||
var payload interface{}
|
||||
if jsonEnvelopeEnabled() {
|
||||
payload = map[string]interface{}{
|
||||
"schema_version": JSONSchemaVersion,
|
||||
"data": inner,
|
||||
}
|
||||
} else {
|
||||
inner["schema_version"] = JSONSchemaVersion
|
||||
payload = inner
|
||||
}
|
||||
data, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
// Marshaling flat strings cannot realistically fail; fall back to the
|
||||
// text summary rather than exiting with nothing said at all.
|
||||
fmt.Fprintf(os.Stderr, "Error: %s\n", msg)
|
||||
} else {
|
||||
fmt.Fprintln(os.Stderr, string(data))
|
||||
}
|
||||
return SilentExit()
|
||||
}
|
||||
|
||||
func init() {
|
||||
registerCloseReasonFlag(closeCmd)
|
||||
closeCmd.Flags().String("resolution", "", "Alias for --reason (Jira CLI convention)")
|
||||
|
|
@ -568,7 +671,7 @@ func checkGateSatisfaction(issue *types.Issue) error {
|
|||
case issue.AwaitType == "timer":
|
||||
resolved, escalated, reason, err = checkTimer(issue, time.Now())
|
||||
case issue.AwaitType == "bead":
|
||||
resolved, reason = checkBeadGate(rootCtx, store, issue.AwaitID)
|
||||
resolved, reason = checkBeadGate(rootCtx, routedBeadGateGetter{localStore: store}, issue.AwaitID)
|
||||
if resolved {
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,6 +113,154 @@ func TestEmbeddedClose(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
// A batch still closes the IDs it can close, but a caller must receive a
|
||||
// nonzero exit when any sibling was refused. Otherwise an orchestrator can
|
||||
// record the whole batch as complete while a blocked issue remains open.
|
||||
t.Run("mixed_batch_refusal_exits_nonzero_after_closing_survivor", func(t *testing.T) {
|
||||
blocker := bdCreate(t, bd, dir, "Mixed batch blocker", "--type", "task")
|
||||
blocked := bdCreate(t, bd, dir, "Mixed batch blocked", "--type", "task")
|
||||
closable := bdCreate(t, bd, dir, "Mixed batch closable", "--type", "task")
|
||||
bdDepAdd(t, bd, dir, blocked.ID, blocker.ID)
|
||||
|
||||
out := bdCloseFail(t, bd, dir, closable.ID, blocked.ID)
|
||||
if !strings.Contains(out, "1 of 2 issues failed to close") {
|
||||
t.Errorf("expected partial-close summary, got: %s", out)
|
||||
}
|
||||
if got := bdShow(t, bd, dir, closable.ID); got.Status != types.StatusClosed {
|
||||
t.Errorf("closable issue status = %s, want closed", got.Status)
|
||||
}
|
||||
if got := bdShow(t, bd, dir, blocked.ID); got.Status != types.StatusOpen {
|
||||
t.Errorf("blocked issue status = %s, want open", got.Status)
|
||||
}
|
||||
})
|
||||
|
||||
// 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
|
||||
// exits 1. The claim is durable — the refused sibling does not roll it back
|
||||
// — so the contract pinned here is "the claim stands and the failure
|
||||
// summary names it", NOT "the claim is silently suppressed": suppressing
|
||||
// only the report would leave an issue assigned to this actor with nothing
|
||||
// saying so, which is strictly worse than announcing it.
|
||||
//
|
||||
// Its own project, because the assertion depends on exactly which issue is
|
||||
// ready at claim time: once `closable` closes, `blocker` is the only ready
|
||||
// issue left (`blocked` still depends on it), so the claim is deterministic.
|
||||
t.Run("mixed_batch_claim_next_names_the_claim_it_kept", func(t *testing.T) {
|
||||
kdir, _, _ := bdInit(t, bd, "--prefix", "kn")
|
||||
closable := bdCreate(t, bd, kdir, "Claim-next batch closable", "--type", "task")
|
||||
blocker := bdCreate(t, bd, kdir, "Claim-next batch blocker", "--type", "task")
|
||||
blocked := bdCreate(t, bd, kdir, "Claim-next batch blocked", "--type", "task")
|
||||
bdDepAdd(t, bd, kdir, blocked.ID, blocker.ID)
|
||||
|
||||
out := bdCloseFail(t, bd, kdir, closable.ID, blocked.ID, "--claim-next")
|
||||
if !strings.Contains(out, "1 of 2 issues failed to close") {
|
||||
t.Errorf("expected the partial-close summary, got: %s", out)
|
||||
}
|
||||
if !strings.Contains(out, "already claimed "+blocker.ID) {
|
||||
t.Errorf("expected the failure summary to name the claim it kept (%s), got: %s", blocker.ID, out)
|
||||
}
|
||||
if got := bdShow(t, bd, kdir, closable.ID); got.Status != types.StatusClosed {
|
||||
t.Errorf("closable issue status = %s, want closed", got.Status)
|
||||
}
|
||||
if got := bdShow(t, bd, kdir, blocked.ID); got.Status != types.StatusOpen {
|
||||
t.Errorf("blocked issue status = %s, want open", got.Status)
|
||||
}
|
||||
// The claim really landed: the report is not describing a claim that
|
||||
// was rolled back with the refusal.
|
||||
if got := bdShow(t, bd, kdir, blocker.ID); got.Assignee == "" {
|
||||
t.Errorf("claimed issue %s assignee = %q, want it assigned: the claim commits inside the batch transaction and the refused sibling does not undo it",
|
||||
blocker.ID, got.Assignee)
|
||||
}
|
||||
|
||||
// And retrying does NOT stack a second claim, which is what makes
|
||||
// keeping the first one safe. `closable` is already closed on the way
|
||||
// back through, so the batch lands nothing and an empty batch earns no
|
||||
// claim (see the already-closed re-close subtest below). `spare` is
|
||||
// created only now, so it is the one ready issue a repeat claim could
|
||||
// take — without it this assertion would pass vacuously, since the
|
||||
// first run left nothing else ready.
|
||||
spare := bdCreate(t, bd, kdir, "Claim-next batch spare", "--type", "task")
|
||||
out = bdCloseFail(t, bd, kdir, closable.ID, blocked.ID, "--claim-next")
|
||||
if strings.Contains(out, "already claimed "+spare.ID) {
|
||||
t.Errorf("a retry claimed %s as well, got: %s", spare.ID, out)
|
||||
}
|
||||
if got := bdShow(t, bd, kdir, spare.ID); got.Assignee != "" {
|
||||
t.Errorf("retrying the same failed batch claimed a second issue (%s assignee = %q); the leak must be bounded at the one claim the first run earned",
|
||||
spare.ID, got.Assignee)
|
||||
}
|
||||
})
|
||||
|
||||
// Proves the S7 delegation: `bd close` on a blocked issue now surfaces the
|
||||
// engine's atomic guard (storage.ErrCloseBlocked) rather than a duplicated
|
||||
// CLI pre-check. The refusal must be atomic — the issue stays open because the
|
||||
|
|
|
|||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -42,6 +42,19 @@ func bdProxiedCloseFail(t *testing.T, bd, dir string, args ...string) string {
|
|||
return stdout + stderr
|
||||
}
|
||||
|
||||
// lastJSONObjectLine returns the last line of s that looks like a compact JSON
|
||||
// object, or "". Partial-failure stderr is the per-id refusal prose followed by
|
||||
// the machine-readable summary, so the report is the last such line.
|
||||
func lastJSONObjectLine(s string) string {
|
||||
lines := strings.Split(strings.TrimSpace(s), "\n")
|
||||
for i := len(lines) - 1; i >= 0; i-- {
|
||||
if line := strings.TrimSpace(lines[i]); strings.HasPrefix(line, "{") {
|
||||
return line
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func bdProxiedCloseJSON(t *testing.T, bd, dir string, args ...string) []*types.Issue {
|
||||
t.Helper()
|
||||
fullArgs := append([]string{"close", "--json"}, args...)
|
||||
|
|
@ -363,6 +376,90 @@ func TestProxiedServerClose(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
t.Run("close_partial_failure_exits_nonzero", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
p := newSharedProxiedProject(t, bd, "cpf")
|
||||
closable := bdProxiedCreate(t, bd, p.dir, "Closable")
|
||||
blocker := bdProxiedCreate(t, bd, p.dir, "Blocker")
|
||||
blocked := bdProxiedCreate(t, bd, p.dir, "Blocked", "--deps", "depends-on:"+blocker.ID)
|
||||
out := bdProxiedCloseFail(t, bd, p.dir, closable.ID, blocked.ID)
|
||||
if !strings.Contains(out, "1 of 2 issues failed to close") {
|
||||
t.Errorf("expected partial-failure summary, got: %s", out)
|
||||
}
|
||||
db := openProxiedDB(t, p)
|
||||
if got := readStatus(t, db, closable.ID); got != types.StatusClosed {
|
||||
t.Errorf("closable issue status = %q, want closed despite the refused sibling", got)
|
||||
}
|
||||
if got := readStatus(t, db, blocked.ID); got == types.StatusClosed {
|
||||
t.Error("blocked issue should remain open without --force")
|
||||
}
|
||||
})
|
||||
|
||||
// The machine-readable half of the #6648 contract. A JSON consumer is
|
||||
// exactly the caller the issue was filed for, so exit 1 must come with a
|
||||
// payload naming the failed ids instead of prose it would have to scrape —
|
||||
// while stdout keeps the success-shaped closed-issues array, the way
|
||||
// bd update's reportUpdateFailures already splits them.
|
||||
t.Run("close_partial_failure_json_names_the_failed_ids", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
p := newSharedProxiedProject(t, bd, "cpj")
|
||||
closable := bdProxiedCreate(t, bd, p.dir, "JSON closable")
|
||||
blocker := bdProxiedCreate(t, bd, p.dir, "JSON blocker")
|
||||
blocked := bdProxiedCreate(t, bd, p.dir, "JSON blocked", "--deps", "depends-on:"+blocker.ID)
|
||||
|
||||
stdout, stderr, err := bdProxiedRunBuffers(t, bd, p.dir, "close", "--json", closable.ID, blocked.ID)
|
||||
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) %v, want only the survivor %s", len(closed), closed, closable.ID)
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
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) {
|
||||
t.Parallel()
|
||||
p := newSharedProxiedProject(t, bd, "cpr")
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
@ -127,6 +138,7 @@ func runCloseProxiedServer(cmd *cobra.Command, ctx context.Context, args []strin
|
|||
fmt.Fprintln(os.Stderr, e)
|
||||
}
|
||||
}
|
||||
failures := closeProxiedFailures(&pre, args)
|
||||
for _, w := range post.warnings {
|
||||
fmt.Fprintf(os.Stderr, "Warning: %s\n", w)
|
||||
}
|
||||
|
|
@ -182,6 +194,9 @@ func runCloseProxiedServer(cmd *cobra.Command, ctx context.Context, args []strin
|
|||
}
|
||||
}
|
||||
|
||||
if len(failures) > 0 {
|
||||
return reportCloseFailures(failures, len(args), closeClaimedID(claimedNextIssue), in.jsonOut)
|
||||
}
|
||||
if len(args) > 0 && len(outcomes) == 0 {
|
||||
return SilentExit()
|
||||
}
|
||||
|
|
@ -223,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
|
||||
|
|
@ -292,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]
|
||||
|
|
@ -319,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
|
||||
|
|
|
|||
|
|
@ -994,7 +994,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 {
|
||||
|
|
|
|||
|
|
@ -915,7 +915,7 @@ func createDepsAcceptedTypeList() string {
|
|||
}
|
||||
|
||||
func init() {
|
||||
createCmd.Flags().StringP("file", "f", "", "Create multiple issues from markdown file")
|
||||
createCmd.Flags().StringP("file", "f", "", "Create one issue per ## heading (### fields attach to that issue); for title plus description-from-file, use --body-file")
|
||||
createCmd.Flags().String("graph", "", "Create a graph of issues with dependencies from JSON plan file")
|
||||
createCmd.Flags().String("title", "", "Issue title (alternative to positional argument)")
|
||||
createCmd.Flags().Bool("silent", false, "Output only the issue ID (for scripting)")
|
||||
|
|
|
|||
|
|
@ -171,3 +171,46 @@ func TestCreateSingleIssueAllowEmptyDescriptionRoundTrip(t *testing.T) {
|
|||
t.Fatalf("expected issue %q to be created via --allow-empty-description opt-in", title)
|
||||
}
|
||||
}
|
||||
|
||||
// TestCreateFileDispatchRejectsPositionalTitle is a regression test for
|
||||
// gastownhall/beads#4643: --file is a batch-import route, so a positional
|
||||
// title has nowhere to go once createIssuesFromMarkdown takes over. This
|
||||
// asserts gatherCreateInput's existing guard still rejects the combination
|
||||
// before any issue is written, rather than silently discarding the title.
|
||||
func TestCreateFileDispatchRejectsPositionalTitle(t *testing.T) {
|
||||
saveAndRestoreGlobals(t)
|
||||
ensureCleanGlobalState(t)
|
||||
|
||||
readonlyMode = false
|
||||
t.Cleanup(func() { readonlyMode = false })
|
||||
|
||||
fileFlag := createCmd.Flags().Lookup("file")
|
||||
t.Cleanup(func() {
|
||||
_ = fileFlag.Value.Set("")
|
||||
fileFlag.Changed = false
|
||||
})
|
||||
|
||||
tmpDir := t.TempDir()
|
||||
mdPath := filepath.Join(tmpDir, "single.md")
|
||||
if err := os.WriteFile(mdPath, []byte("## My Bead\n\nBody text.\n"), 0644); err != nil {
|
||||
t.Fatalf("write markdown fixture: %v", err)
|
||||
}
|
||||
|
||||
if err := createCmd.Flags().Set("file", mdPath); err != nil {
|
||||
t.Fatalf("set --file: %v", err)
|
||||
}
|
||||
|
||||
var err error
|
||||
stderr := captureStderr(t, func() {
|
||||
err = createCmd.RunE(createCmd, []string{"my new bead"})
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("expected --file dispatch with a positional title to be rejected")
|
||||
}
|
||||
if !strings.Contains(stderr, "cannot specify both title and --file flag") {
|
||||
t.Fatalf("expected title/--file conflict message on stderr, got: %v (err: %v)", stderr, err)
|
||||
}
|
||||
if !strings.Contains(stderr, "--body-file") {
|
||||
t.Fatalf("expected title/--file conflict to hint at --body-file, got: %v (err: %v)", stderr, err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ func gatherCreateInput(cmd *cobra.Command, args []string) (createInput, error) {
|
|||
}
|
||||
if in.markdownFile != "" {
|
||||
if len(args) > 0 {
|
||||
return in, HandleError("cannot specify both title and --file flag")
|
||||
return in, HandleError("cannot specify both title and --file flag; for a single issue's description from a file, use --body-file")
|
||||
}
|
||||
if in.dryRun {
|
||||
return in, HandleError("--dry-run is not supported with --file flag")
|
||||
|
|
|
|||
|
|
@ -40,6 +40,36 @@ func TestCreateCommandRegistersEmptyDescriptionOptIn(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestCreateFileFlagHelpDoesNotClaimSingleIssueGH4643(t *testing.T) {
|
||||
f := createCmd.Flags().Lookup("file")
|
||||
if f == nil {
|
||||
t.Fatal("expected create to register --file")
|
||||
}
|
||||
if !strings.Contains(f.Usage, "one issue per") {
|
||||
t.Fatalf("expected --file help text to name its per-heading batch behavior, got: %q", f.Usage)
|
||||
}
|
||||
if !strings.Contains(f.Usage, "--body-file") {
|
||||
t.Fatalf("expected --file help text to point single-issue callers at --body-file, got: %q", f.Usage)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGatherCreateInputRejectsTitleWithFile(t *testing.T) {
|
||||
cmd := newCreateFlagsCommand(t, "--file", "issues.md")
|
||||
var err error
|
||||
stderr := captureStderr(t, func() {
|
||||
_, err = gatherCreateInput(cmd, []string{"Some title"})
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("expected gatherCreateInput to reject a positional title with --file")
|
||||
}
|
||||
if !strings.Contains(stderr, "cannot specify both title and --file flag") {
|
||||
t.Fatalf("expected title/--file conflict on stderr, got stderr=%q err=%v", stderr, err)
|
||||
}
|
||||
if !strings.Contains(stderr, "--body-file") {
|
||||
t.Fatalf("expected title/--file conflict to hint at --body-file, got stderr=%q err=%v", stderr, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGatherCreateInputRejectsEmptyBodyFile(t *testing.T) {
|
||||
filePath := filepath.Join(t.TempDir(), "empty.md")
|
||||
if err := os.WriteFile(filePath, nil, 0644); err != nil {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
return HandleProxyCapabilityError(AssertProxyCapability(ProxyModeProxied, ProxyCapRepo))
|
||||
|
|
@ -390,7 +382,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() }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ dolt-server.log
|
|||
dolt-server.lock
|
||||
dolt-server.port
|
||||
dolt-server.activity
|
||||
dolt-server-config.yaml
|
||||
|
||||
# Debug-mode pprof artifacts (written when dolt.debug: true in config.yaml)
|
||||
dolt-pprof/
|
||||
|
|
@ -129,6 +130,7 @@ var requiredPatterns = []string{
|
|||
"dolt-server.lock",
|
||||
"dolt-server.port",
|
||||
"dolt-server.activity",
|
||||
"dolt-server-config.yaml",
|
||||
"daemon.*",
|
||||
"*.lock",
|
||||
"*.corrupt.backup/",
|
||||
|
|
|
|||
|
|
@ -1522,6 +1522,39 @@ func TestRequiredPatterns_ContainsSyncStatePatterns(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestGitignore_ContainsDoltServerConfig verifies that the generated Dolt
|
||||
// server config is ignored like the other dolt-server.* runtime state files
|
||||
// it sits beside. doltserver.Start() writes .beads/dolt-server-config.yaml
|
||||
// when the resolved dolt binary supports auto_gc_behavior.archive_level, and
|
||||
// it holds an absolute cfg_dir plus a per-machine port, so committing it
|
||||
// would break every other clone.
|
||||
//
|
||||
// The hyphenated name falls outside the "dolt-server." prefix shared by the
|
||||
// other five entries, so it was missed by both lists. It must be in
|
||||
// requiredPatterns too, otherwise bd doctor --fix cannot heal an existing
|
||||
// .beads/.gitignore.
|
||||
func TestGitignore_ContainsDoltServerConfig(t *testing.T) {
|
||||
// Keep this in sync with doltserver.doltServerConfigFileName. It is not
|
||||
// imported here because cmd/bd/doctor must not depend on the server
|
||||
// package for a string constant.
|
||||
const pattern = "dolt-server-config.yaml"
|
||||
|
||||
if !containsGitignorePattern(GitignoreTemplate, pattern) {
|
||||
t.Errorf("GitignoreTemplate should contain %q", pattern)
|
||||
}
|
||||
|
||||
found := false
|
||||
for _, p := range requiredPatterns {
|
||||
if p == pattern {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Errorf("requiredPatterns should include %q", pattern)
|
||||
}
|
||||
}
|
||||
|
||||
// TestCheckLastTouchedNotTracked_NoFile verifies that check passes when no last-touched file exists
|
||||
func TestCheckLastTouchedNotTracked_NoFile(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
|
|
|
|||
100
cmd/bd/dolt.go
100
cmd/bd/dolt.go
|
|
@ -728,26 +728,47 @@ For more options (--stdin, custom messages), see: bd vc commit`,
|
|||
SilenceErrors: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
ctx := context.Background()
|
||||
st := getStore()
|
||||
if st == nil {
|
||||
return HandleError("no store available")
|
||||
}
|
||||
msg, _ := cmd.Flags().GetString("message")
|
||||
if msg == "" {
|
||||
msg = fmt.Sprintf("bd: dolt commit (auto-commit) by %s", getActor())
|
||||
}
|
||||
// CommitAll, not Commit: this command's contract is "any uncommitted
|
||||
// changes in the working set", including changes made externally and
|
||||
// the config table — which server-mode Commit excludes (GH#2455), so
|
||||
// out-of-band config dirt used to survive this command forever. Its
|
||||
// committed bool also replaces the HEAD-before/HEAD-after comparison
|
||||
// this command used to detect tolerated no-ops with, which cost two
|
||||
// extra HEAD reads and raced against concurrent writers.
|
||||
committed, err := st.CommitAll(ctx, msg)
|
||||
|
||||
var (
|
||||
committed bool
|
||||
err error
|
||||
)
|
||||
if usesProxiedServer() {
|
||||
// Proxied mode never opens a store — the root pre-run returns
|
||||
// before newDoltStore — so getStore() is nil here and the UOW
|
||||
// provider is the only handle on the server. This is the flush
|
||||
// point dolt.auto-commit=batch/off defers to on that route
|
||||
// (GH#4995). The message is built above so both routes name the
|
||||
// same default.
|
||||
committed, err = runDoltCommitProxiedServer(ctx, msg)
|
||||
} else {
|
||||
st := getStore()
|
||||
if st == nil {
|
||||
return HandleError("no store available")
|
||||
}
|
||||
// CommitAll, not Commit: this command's contract is "any uncommitted
|
||||
// changes in the working set", including changes made externally and
|
||||
// the config table — which server-mode Commit excludes (GH#2455), so
|
||||
// out-of-band config dirt used to survive this command forever. Its
|
||||
// committed bool also replaces the HEAD-before/HEAD-after comparison
|
||||
// this command used to detect tolerated no-ops with, which cost two
|
||||
// extra HEAD reads and raced against concurrent writers.
|
||||
committed, err = st.CommitAll(ctx, msg)
|
||||
}
|
||||
if err != nil {
|
||||
if isDoltNothingToCommit(err) {
|
||||
switch {
|
||||
case isDoltNothingToCommit(err):
|
||||
committed = false
|
||||
} else {
|
||||
case isReportedExit(err):
|
||||
// The proxied route reports provider failures itself, through
|
||||
// HandleErrorRespectJSON, so the JSON envelope is already on
|
||||
// stdout; re-wrapping would print a second, plain Error line.
|
||||
return err
|
||||
default:
|
||||
return HandleError("%v", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -773,7 +794,12 @@ The server runs in the background on a per-project port derived from the
|
|||
project path. PID and logs are stored in .beads/.
|
||||
|
||||
The server auto-starts transparently when needed, so manual start is rarely
|
||||
required. Use this command for explicit control or diagnostics.`,
|
||||
required. Use this command for explicit control or diagnostics.
|
||||
|
||||
Not available in proxied-server mode: there the proxy owns its dolt backend's
|
||||
lifecycle and starts it on demand, so a server started here would be a second,
|
||||
unsupervised one over the same data directory. Use 'bd dolt status' to see what
|
||||
is running and 'bd dolt stop' to shut it down.`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
beadsDir := selectedDoltBeadsDir()
|
||||
if beadsDir == "" {
|
||||
|
|
@ -783,6 +809,26 @@ required. Use this command for explicit control or diagnostics.`,
|
|||
if err != nil {
|
||||
return HandleError("%v", err)
|
||||
}
|
||||
// A proxied workspace already has a server manager. The proxy spawns
|
||||
// its dolt child on demand and reaps the whole tree when idle, so
|
||||
// there is no state for bd to add here — only a second one to
|
||||
// collide with. With the tree down, doltserver.Start resolves the
|
||||
// proxied root's own configured port and launches an unsupervised
|
||||
// sql-server directly over .beads/dolt, and the next ordinary bd
|
||||
// command then fails because the relaunched proxy finds a foreign
|
||||
// server on its port; with the tree up, Start instead adopts the
|
||||
// proxy's child into bd's classic PID/port records, leaving two
|
||||
// managers for one process. Refused rather than routed: the proxy
|
||||
// owns its child's lifecycle, and an idle reaper means a "started"
|
||||
// postcondition bd cannot honor for more than the idle window.
|
||||
//
|
||||
// Both the process-wide mode and the selected workspace's own
|
||||
// metadata are consulted, and this runs before the embedded guard:
|
||||
// over-refusing costs an operator one error message, under-refusing
|
||||
// costs them the datastore.
|
||||
if usesProxiedServer() || fileCfg.IsDoltProxiedServerMode() {
|
||||
return HandleProxyCapabilityError(proxiedDoltStartRefusal())
|
||||
}
|
||||
if !usesSQLServer() {
|
||||
return HandleError("'bd dolt start' is not supported in embedded mode (no Dolt server)")
|
||||
}
|
||||
|
|
@ -790,7 +836,7 @@ required. Use this command for explicit control or diagnostics.`,
|
|||
// server lifecycle (GH#3545/GH#3518): starting a repo-local
|
||||
// server here would write local PID/port state that shadows the
|
||||
// configured remote endpoint.
|
||||
if host := fileCfg.GetDoltServerHost(); !usesProxiedServer() && !configfile.IsLocalHostString(host) {
|
||||
if host := fileCfg.GetDoltServerHost(); !configfile.IsLocalHostString(host) {
|
||||
return HandleError("the configured Dolt server host is remote (%s); 'bd dolt start' only manages a local server.\nStart the server on that host, or clear dolt_server_host / dolt.host / BEADS_DOLT_SERVER_HOST to run one locally", host)
|
||||
}
|
||||
serverDir := doltserver.ResolveServerDir(beadsDir)
|
||||
|
|
@ -1067,7 +1113,12 @@ PID, port, and data directory from the local PID file. For externally-
|
|||
managed servers — a shared server (dolt.shared-server: true), a remote
|
||||
dolt_server_host, or a local server managed outside bd (dolt.auto-start:
|
||||
false, e.g. an orchestrator-shared sql-server) — pings the configured
|
||||
endpoint via SQL and reports reachability, server version, and database.`,
|
||||
endpoint via SQL and reports reachability, server version, and database.
|
||||
|
||||
In proxied-server mode, reports the proxy (the endpoint every bd command
|
||||
connects through) and the dolt backend behind it separately, read from the
|
||||
proxy's own process records. Reporting starts nothing: a quiesced workspace
|
||||
is shown as not running, and the next bd command launches it.`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
beadsDir := selectedDoltBeadsDir()
|
||||
if beadsDir == "" {
|
||||
|
|
@ -1090,6 +1141,21 @@ endpoint via SQL and reports reachability, server version, and database.`,
|
|||
fmt.Printf("Backend: %s (no Dolt engine)\n", cfg.GetBackend())
|
||||
return nil
|
||||
}
|
||||
// Neither branch below describes a proxied workspace. It writes no
|
||||
// classic PID file, so the bd-managed path reports "not running"
|
||||
// while the proxy is serving CRUD, and shouldUseExternalDoltStatus
|
||||
// deliberately excludes proxied so the SQL-probe path never sees it
|
||||
// either. Keyed on the loaded config rather than the process-wide
|
||||
// mode so `bd --db <proxied workspace> dolt status` describes the
|
||||
// workspace it was pointed at.
|
||||
if cfg.IsDoltProxiedServerMode() {
|
||||
status, err := collectProxiedDoltStatus(beadsDir)
|
||||
if err != nil {
|
||||
return HandleError("%v", err)
|
||||
}
|
||||
renderProxiedDoltStatus(status)
|
||||
return nil
|
||||
}
|
||||
if !usesSQLServer() {
|
||||
showEmbeddedDoltStatus(beadsDir)
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -91,6 +91,35 @@ func issueOpsContext(ctx context.Context) (context.Context, error) {
|
|||
return issueops.WithDeferredVersionCommit(ctx), nil
|
||||
}
|
||||
|
||||
// explicitCommitPointContext clears the dolt.auto-commit deferral for a proxied
|
||||
// dual whose direct-route twin is an explicit commit point.
|
||||
//
|
||||
// The direct route encodes two commit classes, and it encodes them by which
|
||||
// wrapper a verb picks: writes whose Dolt commit is auto-commit policy go
|
||||
// through transactHonoringAutoCommit or issueOpsContext above, while the
|
||||
// explicit commit points go through transact and mint a Dolt commit carrying
|
||||
// the caller's message whatever the policy says. The proxied route has no such
|
||||
// choice to make per verb — it applies the policy ONCE, to rootCtx in the root
|
||||
// pre-run (GH#4995) — so the second class has to opt back out here, or
|
||||
// doltServerTx.Commit blanks the message it was given: a proxied
|
||||
// `bd batch -m "release batch"` under dolt.auto-commit=batch would persist the
|
||||
// rows, discard the message and mint nothing, while the identical command and
|
||||
// config on the direct route commits it.
|
||||
//
|
||||
// Scope is the intersection of two in-tree lists: the transact() call sites,
|
||||
// and the paths the proxied front door permits (proxyPermittedPaths in
|
||||
// capability_registry.go). That is batch, mol bond/pour/squash, mol wisp create
|
||||
// and the WISP half of mol burn; cook and migrate issues also call transact but
|
||||
// are refused in proxied mode, so they have no dual to exempt.
|
||||
//
|
||||
// Membership is per commit site, not per command: mol burn's persistent half
|
||||
// reaches deleteBatch -> issueOpsContext on the direct route, which is the
|
||||
// policy-honoring class, so runMolBurnProxiedServer exempts only the wisp
|
||||
// transaction. TestProxiedDualsExemptTheirExplicitCommitPoints pins both arms.
|
||||
func explicitCommitPointContext(ctx context.Context) context.Context {
|
||||
return issueops.WithImmediateVersionCommit(ctx)
|
||||
}
|
||||
|
||||
type doltAutoCommitParams struct {
|
||||
// Command is the top-level bd command name (e.g., "create", "update").
|
||||
Command string
|
||||
|
|
|
|||
238
cmd/bd/dolt_autocommit_exemption_wiring_test.go
Normal file
238
cmd/bd/dolt_autocommit_exemption_wiring_test.go
Normal file
|
|
@ -0,0 +1,238 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/storage/domain"
|
||||
"github.com/steveyegge/beads/internal/storage/issueops"
|
||||
"github.com/steveyegge/beads/internal/storage/uow"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
// The tests below pin the WIRING half of the GH#4995 exemption. The mechanism
|
||||
// half — that WithImmediateVersionCommit defeats the route-wide deferral —
|
||||
// is pinned in internal/storage/uow; what is pinned here is that each proxied
|
||||
// dual whose direct twin is an explicit commit point actually hands that
|
||||
// exemption to its transaction, and that the duals whose twin is NOT one do
|
||||
// not. Without this, deleting explicitCommitPointContext from a dual is green
|
||||
// in every lane that does not have a real proxied server.
|
||||
//
|
||||
// The seam is uow.RunTxResult's own first act: it asks the provider for a unit
|
||||
// of work, passing the caller's context. A provider that records that context
|
||||
// and then refuses observes exactly "the context this dual hands its
|
||||
// transaction", with no server, no store and no fixture beyond the reads the
|
||||
// dual makes to decide what to write.
|
||||
|
||||
var errStopBeforeProbeTx = errors.New("exemption wiring probe: stop before the transaction")
|
||||
|
||||
// exemptionProbeProvider serves readUOW to the first `reads` NewUOW calls (the
|
||||
// dual's own read phase) and refuses the rest, recording every context it was
|
||||
// handed. The refusal is not a serialization error, so RunTxResult treats it as
|
||||
// permanent and makes exactly one NewUOW call per transaction.
|
||||
type exemptionProbeProvider struct {
|
||||
readUOW uow.UnitOfWork
|
||||
reads int
|
||||
ctxs []context.Context
|
||||
}
|
||||
|
||||
func (p *exemptionProbeProvider) NewUOW(ctx context.Context) (uow.UnitOfWork, error) {
|
||||
p.ctxs = append(p.ctxs, ctx)
|
||||
if len(p.ctxs) <= p.reads {
|
||||
return p.readUOW, nil
|
||||
}
|
||||
return nil, errStopBeforeProbeTx
|
||||
}
|
||||
|
||||
func (p *exemptionProbeProvider) Close(context.Context) error { return nil }
|
||||
|
||||
// txCtxs is the contexts handed to RunTx*, in call order: everything after the
|
||||
// leading read opens.
|
||||
func (p *exemptionProbeProvider) txCtxs() []context.Context {
|
||||
if len(p.ctxs) <= p.reads {
|
||||
return nil
|
||||
}
|
||||
return p.ctxs[p.reads:]
|
||||
}
|
||||
|
||||
// installExemptionProbe points the package's proxied provider at the probe for
|
||||
// the duration of one test.
|
||||
func installExemptionProbe(t *testing.T, p *exemptionProbeProvider) {
|
||||
t.Helper()
|
||||
prev := uowProvider
|
||||
uowProvider = p
|
||||
t.Cleanup(func() { uowProvider = prev })
|
||||
}
|
||||
|
||||
// exemptionProbeUOW embeds the interface without implementing it: anything a
|
||||
// dual's read phase needs beyond the three use cases below panics and names
|
||||
// itself, rather than being silently satisfied.
|
||||
type exemptionProbeUOW struct {
|
||||
uow.UnitOfWork
|
||||
issues domain.IssueUseCase
|
||||
labels domain.LabelUseCase
|
||||
deps domain.DependencyUseCase
|
||||
}
|
||||
|
||||
func (u exemptionProbeUOW) Close(context.Context) {}
|
||||
func (u exemptionProbeUOW) IssueUseCase() domain.IssueUseCase { return u.issues }
|
||||
func (u exemptionProbeUOW) LabelUseCase() domain.LabelUseCase { return u.labels }
|
||||
func (u exemptionProbeUOW) DependencyUseCase() domain.DependencyUseCase { return u.deps }
|
||||
|
||||
// CommentUseCase is collected by workapi.NewUOWDetailSource when the read
|
||||
// phase resolves an id; nothing on that path calls it.
|
||||
func (u exemptionProbeUOW) CommentUseCase() domain.CommentUseCase { return nil }
|
||||
|
||||
type exemptionProbeIssues struct {
|
||||
domain.IssueUseCase
|
||||
byID map[string]*types.Issue
|
||||
}
|
||||
|
||||
func (s exemptionProbeIssues) GetIssue(_ context.Context, id string) (*types.Issue, error) {
|
||||
if issue, ok := s.byID[id]; ok && !issue.Ephemeral {
|
||||
return issue, nil
|
||||
}
|
||||
return nil, storage.ErrNotFound
|
||||
}
|
||||
|
||||
func (s exemptionProbeIssues) GetWisp(_ context.Context, id string) (*types.Issue, error) {
|
||||
if issue, ok := s.byID[id]; ok && issue.Ephemeral {
|
||||
return issue, nil
|
||||
}
|
||||
return nil, storage.ErrNotFound
|
||||
}
|
||||
|
||||
func (s exemptionProbeIssues) SearchIssues(_ context.Context, _ string, filter types.IssueFilter) (domain.SearchPage, error) {
|
||||
var page domain.SearchPage
|
||||
for _, id := range filter.IDs {
|
||||
if issue, ok := s.byID[id]; ok {
|
||||
page.Items = append(page.Items, issue)
|
||||
}
|
||||
}
|
||||
return page, nil
|
||||
}
|
||||
|
||||
type exemptionProbeLabels struct {
|
||||
domain.LabelUseCase
|
||||
}
|
||||
|
||||
func (exemptionProbeLabels) GetLabels(context.Context, string) ([]string, error) { return nil, nil }
|
||||
func (exemptionProbeLabels) GetWispLabels(context.Context, string) ([]string, error) { return nil, nil }
|
||||
|
||||
type exemptionProbeDeps struct {
|
||||
domain.DependencyUseCase
|
||||
}
|
||||
|
||||
func (exemptionProbeDeps) ListWithIssueMetadata(context.Context, string, domain.DepListFilter) ([]*types.IssueWithDependencyMetadata, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (exemptionProbeDeps) GetForIssueIDs(context.Context, []string) (map[string][]*types.Dependency, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func newExemptionProbeUOW(issues ...*types.Issue) uow.UnitOfWork {
|
||||
byID := make(map[string]*types.Issue, len(issues))
|
||||
for _, issue := range issues {
|
||||
byID[issue.ID] = issue
|
||||
}
|
||||
return exemptionProbeUOW{
|
||||
issues: exemptionProbeIssues{byID: byID},
|
||||
labels: exemptionProbeLabels{},
|
||||
deps: exemptionProbeDeps{},
|
||||
}
|
||||
}
|
||||
|
||||
// deferredRouteContext is what the proxied root pre-run hands every dispatch
|
||||
// under dolt.auto-commit=batch/off.
|
||||
func deferredRouteContext() context.Context {
|
||||
return issueops.WithDeferredVersionCommit(context.Background())
|
||||
}
|
||||
|
||||
// TestProxiedDualsExemptTheirExplicitCommitPoints pins the duals that reach
|
||||
// their transaction directly. Deleting explicitCommitPointContext from any of
|
||||
// them reds its row here.
|
||||
func TestProxiedDualsExemptTheirExplicitCommitPoints(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
call func(context.Context)
|
||||
}{
|
||||
{
|
||||
name: "batch",
|
||||
call: func(ctx context.Context) {
|
||||
_, _ = runBatchProxiedServer(ctx, nil, "bd: batch probe")
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "mol bond",
|
||||
call: func(ctx context.Context) {
|
||||
_ = runMolBondProxiedServer(ctx, molBondInput{argA: "bd-a", argB: "bd-b"})
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "mol squash",
|
||||
call: func(ctx context.Context) {
|
||||
_ = runMolSquashProxiedServer(ctx, molSquashInput{moleculeArg: "bd-mol"})
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
probe := &exemptionProbeProvider{}
|
||||
installExemptionProbe(t, probe)
|
||||
|
||||
tc.call(deferredRouteContext())
|
||||
|
||||
txCtxs := probe.txCtxs()
|
||||
if len(txCtxs) != 1 {
|
||||
t.Fatalf("%s: got %d transaction context(s), want 1 — the dual never reached RunTx*", tc.name, len(txCtxs))
|
||||
}
|
||||
if issueops.VersionCommitDeferred(txCtxs[0]) {
|
||||
t.Errorf("%s: the context handed to RunTx* still defers the version commit; "+
|
||||
"its direct twin is an explicit commit point, so this dual must clear the deferral "+
|
||||
"(doltServerTx.Commit blanks the message and mints nothing)", tc.name)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestProxiedMolBurnExemptsOnlyTheWispHalf pins the split. bd mol burn is two
|
||||
// commit classes on the direct route: wisps go through burnWisps -> `transact`
|
||||
// (explicit), persistent molecules go through deleteBatch -> issueOpsContext,
|
||||
// whose deferral dolt's deleter honors by returning before DOLT_COMMIT. A
|
||||
// command-wide exemption mints one commit per persistent molecule under
|
||||
// batch/off, where the identical direct-route command defers them all.
|
||||
func TestProxiedMolBurnExemptsOnlyTheWispHalf(t *testing.T) {
|
||||
wisp := &types.Issue{ID: "bd-wisp1", Ephemeral: true}
|
||||
persistent := &types.Issue{ID: "bd-mol1"}
|
||||
|
||||
probe := &exemptionProbeProvider{
|
||||
reads: 1, // runMolBurnProxiedServer's classification read
|
||||
readUOW: newExemptionProbeUOW(wisp, persistent),
|
||||
}
|
||||
installExemptionProbe(t, probe)
|
||||
|
||||
// force=true skips the interactive confirmation; dryRun=false so both
|
||||
// halves reach their transaction.
|
||||
_ = runMolBurnProxiedServer(deferredRouteContext(), []string{wisp.ID, persistent.ID}, false, true)
|
||||
|
||||
txCtxs := probe.txCtxs()
|
||||
if len(txCtxs) != 2 {
|
||||
t.Fatalf("got %d transaction context(s), want 2 (the wisp half then the persistent half); "+
|
||||
"the classification read did not produce one of each", len(txCtxs))
|
||||
}
|
||||
|
||||
if issueops.VersionCommitDeferred(txCtxs[0]) {
|
||||
t.Errorf("wisp half: the context handed to RunTxResult still defers the version commit, " +
|
||||
"but its direct twin (burnWisps -> transact) commits whatever dolt.auto-commit says")
|
||||
}
|
||||
if !issueops.VersionCommitDeferred(txCtxs[1]) {
|
||||
t.Errorf("persistent half: the context handed to RunTxResult no longer defers the version commit, " +
|
||||
"so a proxied `bd mol burn` mints one Dolt commit per persistent molecule under " +
|
||||
"dolt.auto-commit=batch/off — its direct twin (deleteBatch -> issueOpsContext) defers them " +
|
||||
"all to `bd dolt commit`")
|
||||
}
|
||||
}
|
||||
|
|
@ -284,3 +284,37 @@ func TestTransactHonoringAutoCommitBlanksMessageInServerBatch(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestIssueOpsContextDefersByModePolicyTable pins the policy half of GH#4995:
|
||||
// issueOpsContext defers the Dolt version commit for batch/off and does not for
|
||||
// on/unset. It deliberately does not claim to cover the proxied-server wiring —
|
||||
// issueOpsContext branches only on writesCommitNow(), never on the storage
|
||||
// mode, so setting proxiedServerMode here would prove nothing. The proxied
|
||||
// wiring is pinned by TestProxiedServerBatchDefersThenDoltCommitAdvancesHeadOnce
|
||||
// and the deferral itself by the doltserver_tx tests.
|
||||
func TestIssueOpsContextDefersByModePolicyTable(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
mode string
|
||||
wantDeferred bool
|
||||
}{
|
||||
{mode: string(doltAutoCommitOn), wantDeferred: false},
|
||||
{mode: string(doltAutoCommitBatch), wantDeferred: true},
|
||||
{mode: string(doltAutoCommitOff), wantDeferred: true},
|
||||
{mode: "", wantDeferred: false},
|
||||
} {
|
||||
t.Run("mode="+tc.mode, func(t *testing.T) {
|
||||
saveStorageMode(t)
|
||||
serverMode = false
|
||||
proxiedServerMode = false
|
||||
doltAutoCommit = tc.mode
|
||||
|
||||
ctx, err := issueOpsContext(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("issueOpsContext: %v", err)
|
||||
}
|
||||
if got := storageissueops.VersionCommitDeferred(ctx); got != tc.wantDeferred {
|
||||
t.Fatalf("VersionCommitDeferred = %v, want %v for mode %q", got, tc.wantDeferred, tc.mode)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
191
cmd/bd/dolt_commit_proxied_integration_test.go
Normal file
191
cmd/bd/dolt_commit_proxied_integration_test.go
Normal file
|
|
@ -0,0 +1,191 @@
|
|||
//go:build cgo
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// sqlCountValue extracts a COUNT(*) cell from bdProxiedSQLJSON. sqlValueEquals
|
||||
// only answers "is it this number"; the batch-flush assertions need the number
|
||||
// itself so a failure can report how far HEAD actually moved.
|
||||
func sqlCountValue(v any) (float64, bool) {
|
||||
switch x := v.(type) {
|
||||
case float64:
|
||||
return x, true
|
||||
case string:
|
||||
f, err := strconv.ParseFloat(x, 64)
|
||||
return f, err == nil
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
||||
// TestProxiedServerBatchDefersThenDoltCommitAdvancesHeadOnce pins every half of
|
||||
// GH#4995 on the proxied route: dolt.auto-commit=batch must leave policy writes
|
||||
// in the working set (no Dolt commit per write), `bd dolt commit` must mint
|
||||
// exactly one commit for the whole batch and attribute it to the actor, and the
|
||||
// explicit commit points must keep minting their own commit with the caller's
|
||||
// message despite the route-wide deferral.
|
||||
//
|
||||
// Before the proxied flush point existed, step 3 below failed with
|
||||
// "no store available": proxied mode returns from the root pre-run before
|
||||
// newDoltStore runs, so getStore() is nil and `bd dolt commit` had nothing to
|
||||
// commit through. batch/off therefore meant "never commit" on this route.
|
||||
func TestProxiedServerBatchDefersThenDoltCommitAdvancesHeadOnce(t *testing.T) {
|
||||
requireProxiedServerEnv(t)
|
||||
|
||||
bd := buildEmbeddedBD(t)
|
||||
p := bdProxiedInit(t, bd, "batchflush")
|
||||
|
||||
doltLogCount := func(t *testing.T) float64 {
|
||||
t.Helper()
|
||||
rows := bdProxiedSQLJSON(t, bd, p.dir, "SELECT COUNT(*) AS count FROM dolt_log")
|
||||
if len(rows) != 1 {
|
||||
t.Fatalf("expected one row from dolt_log count, got %d: %v", len(rows), rows)
|
||||
}
|
||||
n, ok := sqlCountValue(rows[0]["count"])
|
||||
if !ok {
|
||||
t.Fatalf("dolt_log count is not numeric: %#v", rows[0]["count"])
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
headCommit := func(t *testing.T) map[string]interface{} {
|
||||
t.Helper()
|
||||
rows := bdProxiedSQLJSON(t, bd, p.dir,
|
||||
"SELECT message, committer, email FROM dolt_log ORDER BY date DESC LIMIT 1")
|
||||
if len(rows) != 1 {
|
||||
t.Fatalf("expected one dolt_log row for HEAD, got %d: %v", len(rows), rows)
|
||||
}
|
||||
return rows[0]
|
||||
}
|
||||
|
||||
head0 := doltLogCount(t)
|
||||
|
||||
// 1. Three writes under the batch policy must not mint any Dolt commit.
|
||||
for i := 1; i <= 3; i++ {
|
||||
title := fmt.Sprintf("batch write %d", i)
|
||||
stdout, stderr, err := bdProxiedRunBuffers(t, bd, p.dir,
|
||||
"--dolt-auto-commit", "batch", "create", title, "-p", "1")
|
||||
if err != nil {
|
||||
t.Fatalf("bd create %q failed: %v\nstdout:\n%s\nstderr:\n%s", title, err, stdout, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
if got := doltLogCount(t); got != head0 {
|
||||
t.Fatalf("batch writes minted Dolt commits: dolt_log went %v -> %v (want unchanged)", head0, got)
|
||||
}
|
||||
|
||||
// 2. The writes are in the working set, not rolled back.
|
||||
listOut, listErr, err := bdProxiedRunBuffers(t, bd, p.dir, "list", "--json")
|
||||
if err != nil {
|
||||
t.Fatalf("bd list --json failed: %v\nstdout:\n%s\nstderr:\n%s", err, listOut, listErr)
|
||||
}
|
||||
for i := 1; i <= 3; i++ {
|
||||
title := fmt.Sprintf("batch write %d", i)
|
||||
if !strings.Contains(listOut, title) {
|
||||
t.Fatalf("deferred write %q is not readable after batch create:\n%s", title, listOut)
|
||||
}
|
||||
}
|
||||
|
||||
// 3. The explicit flush point mints exactly one commit for the batch.
|
||||
stdout, stderr, err := bdProxiedRunBuffers(t, bd, p.dir,
|
||||
"--actor", "flush-actor", "dolt", "commit", "-m", "batch flush")
|
||||
if err != nil {
|
||||
t.Fatalf("bd dolt commit failed in proxied mode: %v\nstdout:\n%s\nstderr:\n%s", err, stdout, stderr)
|
||||
}
|
||||
if !strings.Contains(stdout, "Committed.") {
|
||||
t.Fatalf("bd dolt commit did not report a commit:\nstdout:\n%s\nstderr:\n%s", stdout, stderr)
|
||||
}
|
||||
if got, want := doltLogCount(t), head0+1; got != want {
|
||||
t.Fatalf("bd dolt commit did not advance HEAD exactly once: dolt_log %v -> %v (want %v)", head0, got, want)
|
||||
}
|
||||
|
||||
// 3b. The flush is attributed to the bd actor, not the SQL session user.
|
||||
// Under batch mode this is the only commit a whole batch of writes leaves
|
||||
// behind, so `dolt log` has to be able to say whose batch it was — the
|
||||
// '--author' DoltStorage.CommitAll passes on the direct route.
|
||||
head := headCommit(t)
|
||||
if got := head["message"]; got != "batch flush" {
|
||||
t.Fatalf("flush commit message = %v, want %q (row: %v)", got, "batch flush", head)
|
||||
}
|
||||
if got := head["committer"]; got != "flush-actor" {
|
||||
t.Fatalf("flush commit is not attributed to the actor: committer = %v, want %q (row: %v)", got, "flush-actor", head)
|
||||
}
|
||||
if got := head["email"]; got != "test@test.com" {
|
||||
t.Fatalf("flush commit email = %v, want the git identity %q (row: %v)", got, "test@test.com", head)
|
||||
}
|
||||
|
||||
// 4. A second flush with nothing pending is a no-op, not a second commit.
|
||||
stdout, stderr, err = bdProxiedRunBuffers(t, bd, p.dir, "dolt", "commit", "-m", "second flush")
|
||||
if err != nil {
|
||||
t.Fatalf("second bd dolt commit failed: %v\nstdout:\n%s\nstderr:\n%s", err, stdout, stderr)
|
||||
}
|
||||
if !strings.Contains(stdout, "Nothing to commit.") {
|
||||
t.Fatalf("second bd dolt commit did not report an empty working set:\nstdout:\n%s\nstderr:\n%s", stdout, stderr)
|
||||
}
|
||||
if got, want := doltLogCount(t), head0+1; got != want {
|
||||
t.Fatalf("second bd dolt commit advanced HEAD: dolt_log = %v (want %v)", got, want)
|
||||
}
|
||||
|
||||
// 5. The deferral is policy-driven, not unconditional: with the default
|
||||
// "on" policy a single create advances dolt_log by one on its own.
|
||||
before := doltLogCount(t)
|
||||
stdout, stderr, err = bdProxiedRunBuffers(t, bd, p.dir,
|
||||
"--dolt-auto-commit", "on", "create", "immediate write", "-p", "1")
|
||||
if err != nil {
|
||||
t.Fatalf("bd create with --dolt-auto-commit on failed: %v\nstdout:\n%s\nstderr:\n%s", err, stdout, stderr)
|
||||
}
|
||||
if got, want := doltLogCount(t), before+1; got != want {
|
||||
t.Fatalf("auto-commit=on did not commit per write: dolt_log %v -> %v (want %v)", before, got, want)
|
||||
}
|
||||
|
||||
// 6. The deferral is per commit CLASS, not per route: `bd batch -m` is an
|
||||
// explicit commit point (its direct-route twin calls transact, which mints
|
||||
// regardless of policy), so under batch it must still commit, carrying the
|
||||
// caller's message. A plain create in the same policy is the control.
|
||||
before = doltLogCount(t)
|
||||
stdout, stderr, err = bdProxiedRunBuffers(t, bd, p.dir,
|
||||
"--dolt-auto-commit", "batch", "create", "deferred control write", "-p", "1")
|
||||
if err != nil {
|
||||
t.Fatalf("control create under batch failed: %v\nstdout:\n%s\nstderr:\n%s", err, stdout, stderr)
|
||||
}
|
||||
if got := doltLogCount(t); got != before {
|
||||
t.Fatalf("control create minted a commit under batch: dolt_log %v -> %v (want unchanged)", before, got)
|
||||
}
|
||||
|
||||
script := filepath.Join(p.dir, "explicit-batch.txt")
|
||||
if err := os.WriteFile(script, []byte("create task 1 explicit batch write\n"), 0o600); err != nil {
|
||||
t.Fatalf("write batch script: %v", err)
|
||||
}
|
||||
stdout, stderr, err = bdProxiedRunBuffers(t, bd, p.dir,
|
||||
"--dolt-auto-commit", "batch", "batch", "-f", script, "-m", "explicit batch commit")
|
||||
if err != nil {
|
||||
t.Fatalf("bd batch under batch policy failed: %v\nstdout:\n%s\nstderr:\n%s", err, stdout, stderr)
|
||||
}
|
||||
if got, want := doltLogCount(t), before+1; got != want {
|
||||
t.Fatalf("explicit batch commit did not mint exactly one commit under batch: dolt_log %v -> %v (want %v)", before, got, want)
|
||||
}
|
||||
// The message is the half a route-wide deferral silently drops: blanking it
|
||||
// selects the plain-COMMIT form, which persists the rows and records nothing.
|
||||
if got := headCommit(t)["message"]; got != "explicit batch commit" {
|
||||
t.Fatalf("explicit batch commit lost the caller's message: %v (want %q)", got, "explicit batch commit")
|
||||
}
|
||||
|
||||
// 7. That commit swept the deferred control write with it (DOLT_COMMIT
|
||||
// '-Am'), so the working set is clean and a flush now has nothing to do —
|
||||
// the exemption does not strand the writes the policy deferred.
|
||||
stdout, stderr, err = bdProxiedRunBuffers(t, bd, p.dir, "dolt", "commit", "-m", "post-batch flush")
|
||||
if err != nil {
|
||||
t.Fatalf("flush after explicit batch commit failed: %v\nstdout:\n%s\nstderr:\n%s", err, stdout, stderr)
|
||||
}
|
||||
if !strings.Contains(stdout, "Nothing to commit.") {
|
||||
t.Fatalf("flush after explicit batch commit found pending work:\nstdout:\n%s\nstderr:\n%s", stdout, stderr)
|
||||
}
|
||||
}
|
||||
88
cmd/bd/dolt_commit_proxied_server.go
Normal file
88
cmd/bd/dolt_commit_proxied_server.go
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage/issueops"
|
||||
)
|
||||
|
||||
// runDoltCommitProxiedServer is the proxied dual of `bd dolt commit`: the
|
||||
// explicit commit point that discharges dolt.auto-commit=batch/off on this
|
||||
// route (GH#4995). Proxied mode returns from the root pre-run before
|
||||
// newDoltStore ever runs, so getStore() is nil here and the UOW provider is the
|
||||
// only handle on the server — without this dual, batch/off on a proxied
|
||||
// checkout meant "never commit" and writes piled up in the working set forever.
|
||||
//
|
||||
// It deliberately does not open a unit of work: doltServerTx.Commit blanks its
|
||||
// message under a deferred context (that is the deferral this command exists to
|
||||
// discharge), so routing the flush through it would make the flush itself a
|
||||
// no-op. It runs DOLT_COMMIT('-Am') on a pinned maintenance connection instead,
|
||||
// which is the uow-side equivalent of DoltStorage.CommitAll: "everything in the
|
||||
// working set", including out-of-band and config-table dirt, attributed to the
|
||||
// same actor with '--author'.
|
||||
func runDoltCommitProxiedServer(ctx context.Context, message string) (bool, error) {
|
||||
committed := false
|
||||
// runProxiedNonTx, not an open-coded provider assertion: it is the shared
|
||||
// maintenance escape hatch (backup, compact, clean-databases) and it reports
|
||||
// provider failures through HandleErrorRespectJSON, so `bd --json dolt
|
||||
// commit` keeps emitting the JSON error envelope the rest of the proxied
|
||||
// surface emits.
|
||||
err := runProxiedNonTx(ctx, func(ctx context.Context, conn *sql.Conn) error {
|
||||
// The same gate doltServerTx.Commit uses, and for the same reason: an
|
||||
// empty DOLT_COMMIT is rejected server-side with "nothing to commit"
|
||||
// and floods the server log.
|
||||
pending, err := issueops.HasPendingChanges(ctx, conn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !pending {
|
||||
return nil
|
||||
}
|
||||
if _, err := conn.ExecContext(ctx, "CALL DOLT_COMMIT('-Am', ?, '--author', ?);", message, proxiedCommitAuthor()); err != nil {
|
||||
if isDoltNothingToCommit(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
committed = true
|
||||
return nil
|
||||
})
|
||||
return committed, err
|
||||
}
|
||||
|
||||
// proxiedCommitAuthor is the '--author' identity for the proxied flush, the
|
||||
// counterpart of DoltStorage.commitAuthorString on the direct route. Without it
|
||||
// the commit is attributed to the SQL session user, and under batch mode this is
|
||||
// the ONE commit that survives a whole batch of writes — so on a multi-agent
|
||||
// deployment `dolt log` could not say whose batch was flushed.
|
||||
//
|
||||
// The actor half is the same getActor() the default commit message names; the
|
||||
// address half comes from git, as it does for the committer identity the store
|
||||
// resolves for its own commits.
|
||||
func proxiedCommitAuthor() string {
|
||||
name, email := proxiedServerCommitter()
|
||||
if a := strings.TrimSpace(getActor()); a != "" {
|
||||
name = a
|
||||
}
|
||||
return renderDoltCommitAuthor(name, email)
|
||||
}
|
||||
|
||||
// renderDoltCommitAuthor formats a Dolt '--author' argument. Dolt parses the
|
||||
// git "Name <email>" grammar and rejects anything else, so the angle brackets
|
||||
// and newlines an actor name could carry are stripped rather than passed
|
||||
// through to fail the flush.
|
||||
func renderDoltCommitAuthor(name, email string) string {
|
||||
clean := strings.NewReplacer("<", "", ">", "", "\n", " ", "\r", " ")
|
||||
name = strings.TrimSpace(clean.Replace(name))
|
||||
email = strings.TrimSpace(clean.Replace(email))
|
||||
if name == "" {
|
||||
name = "beads"
|
||||
}
|
||||
if email == "" {
|
||||
email = "beads@localhost"
|
||||
}
|
||||
return fmt.Sprintf("%s <%s>", name, email)
|
||||
}
|
||||
29
cmd/bd/dolt_commit_proxied_server_test.go
Normal file
29
cmd/bd/dolt_commit_proxied_server_test.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
// TestRenderDoltCommitAuthor pins the '--author' argument the proxied flush
|
||||
// passes to DOLT_COMMIT (GH#4995). Dolt parses the git "Name <email>" grammar
|
||||
// and rejects anything else, and the name half is an actor string the caller
|
||||
// controls, so a stray bracket or newline must be stripped rather than turned
|
||||
// into a failed flush — the flush is the only commit batch mode keeps.
|
||||
func TestRenderDoltCommitAuthor(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
actor string
|
||||
email string
|
||||
want string
|
||||
}{
|
||||
{name: "actor and email", actor: "agent-7", email: "agent7@example.com", want: "agent-7 <agent7@example.com>"},
|
||||
{name: "trims surrounding space", actor: " agent-7 ", email: " agent7@example.com\n", want: "agent-7 <agent7@example.com>"},
|
||||
{name: "strips brackets the grammar owns", actor: "agent <7>", email: "a@b", want: "agent 7 <a@b>"},
|
||||
{name: "strips embedded newline", actor: "agent\n7", email: "a@b", want: "agent 7 <a@b>"},
|
||||
{name: "defaults an empty identity", actor: "", email: "", want: "beads <beads@localhost>"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := renderDoltCommitAuthor(tc.actor, tc.email); got != tc.want {
|
||||
t.Fatalf("renderDoltCommitAuthor(%q, %q) = %q, want %q", tc.actor, tc.email, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
108
cmd/bd/dolt_lifecycle_proxied_server_test.go
Normal file
108
cmd/bd/dolt_lifecycle_proxied_server_test.go
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
//go:build cgo
|
||||
|
||||
package main
|
||||
|
||||
// The external-tcp half of the `bd dolt status` / `bd dolt start` coverage.
|
||||
// It lives in the TestProxiedServer* lane, which runs on every PR, so the
|
||||
// corruption guard is enforced there and not only in the path-filtered
|
||||
// managed-local lane.
|
||||
//
|
||||
// The distinction this topology exercises: bd runs a proxy but spawns no dolt,
|
||||
// so "the backend is not running" is a claim bd has no standing to make.
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/doltserver"
|
||||
"github.com/steveyegge/beads/internal/storage/dbproxy/proxy"
|
||||
)
|
||||
|
||||
func TestProxiedServerDoltLifecycle(t *testing.T) {
|
||||
bd := buildEmbeddedBD(t)
|
||||
p := newSharedProxiedProject(t, bd, "extdolt")
|
||||
t.Cleanup(func() {
|
||||
serverDir := doltserver.ResolveServerDir(p.beadsDir)
|
||||
if _, err := os.Stat(filepath.Join(serverDir, doltserver.PIDFileName)); err != nil {
|
||||
return
|
||||
}
|
||||
t.Logf("stray classic dolt-server.pid under %s; stopping it", serverDir)
|
||||
if err := doltserver.Stop(serverDir); err != nil {
|
||||
t.Logf("doltserver.Stop(%s): %v", serverDir, err)
|
||||
}
|
||||
})
|
||||
bdProxiedCreate(t, bd, p.dir, "external lifecycle sentinel")
|
||||
|
||||
proxyPid := readProxyPidFileOrFail(t, p)
|
||||
|
||||
t.Run("status reports the proxy and disclaims the backend", func(t *testing.T) {
|
||||
stdout, stderr, err := bdProxiedRunBuffersWithEnv(t, bd, p.dir, []string{"BEADS_JSON=1"}, "--json", "dolt", "status")
|
||||
if err != nil {
|
||||
t.Fatalf("bd dolt status failed: %v\nstdout:\n%s\nstderr:\n%s", err, stdout, stderr)
|
||||
}
|
||||
var got struct {
|
||||
Mode string `json:"mode"`
|
||||
Running bool `json:"running"`
|
||||
ProxyPID int `json:"proxy_pid"`
|
||||
BackendManaged bool `json:"backend_managed"`
|
||||
BackendRunning bool `json:"backend_running"`
|
||||
BackendEndpoint string `json:"backend_endpoint"`
|
||||
}
|
||||
if jsonErr := json.Unmarshal([]byte(strings.TrimSpace(stdout)), &got); jsonErr != nil {
|
||||
t.Fatalf("decode dolt status JSON: %v\nstdout:\n%s", jsonErr, stdout)
|
||||
}
|
||||
if got.Mode != "proxied-server" || !got.Running {
|
||||
t.Errorf("status=%+v, want mode=proxied-server running=true", got)
|
||||
}
|
||||
if got.ProxyPID != proxyPid {
|
||||
t.Errorf("proxy_pid=%d, want %d", got.ProxyPID, proxyPid)
|
||||
}
|
||||
if got.BackendManaged {
|
||||
t.Error("backend_managed=true on an external topology; bd spawns no dolt there")
|
||||
}
|
||||
if got.BackendRunning {
|
||||
t.Error("backend_running=true on an external topology; bd has no record to claim that from")
|
||||
}
|
||||
if !strings.HasPrefix(got.BackendEndpoint, "127.0.0.1:") {
|
||||
t.Errorf("backend_endpoint=%q, want the configured external endpoint", got.BackendEndpoint)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("start is refused", func(t *testing.T) {
|
||||
stdout, stderr, err := bdProxiedRunBuffersWithEnv(t, bd, p.dir, []string{"BEADS_JSON=1"}, "--json", "dolt", "start")
|
||||
if err == nil {
|
||||
t.Errorf("bd dolt start succeeded on an external proxied workspace:\nstdout:\n%s\nstderr:\n%s", stdout, stderr)
|
||||
}
|
||||
var got struct {
|
||||
Code string `json:"code"`
|
||||
Mutates bool `json:"mutates"`
|
||||
}
|
||||
if jsonErr := json.Unmarshal([]byte(strings.TrimSpace(stdout)), &got); jsonErr != nil {
|
||||
t.Fatalf("refusal is not typed JSON (%v)\nstdout:\n%s\nstderr:\n%s", jsonErr, stdout, stderr)
|
||||
}
|
||||
if got.Code != proxyDoltStartConflictCode || got.Mutates {
|
||||
t.Errorf("refusal=%+v, want code=%q mutates=false", got, proxyDoltStartConflictCode)
|
||||
}
|
||||
for _, name := range []string{doltserver.PIDFileName, doltserver.PortFileName} {
|
||||
if _, statErr := os.Stat(filepath.Join(p.beadsDir, name)); statErr == nil {
|
||||
t.Errorf("%s exists after a refused start", name)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if out, err := bdProxiedRun(t, bd, p.dir, "create", "--json", "post-refusal write"); err != nil {
|
||||
t.Fatalf("workspace unusable after the lifecycle probes: %v\n%s", err, out)
|
||||
}
|
||||
}
|
||||
|
||||
func readProxyPidFileOrFail(t *testing.T, p proxiedProject) int {
|
||||
t.Helper()
|
||||
running, pid := proxy.IsRunning(p.proxyRoot)
|
||||
if !running {
|
||||
t.Fatalf("expected a live proxy under %s after a create", p.proxyRoot)
|
||||
}
|
||||
return pid
|
||||
}
|
||||
167
cmd/bd/dolt_proxied_lifecycle.go
Normal file
167
cmd/bd/dolt_proxied_lifecycle.go
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
package main
|
||||
|
||||
// `bd dolt start` and `bd dolt status` for proxied-server workspaces.
|
||||
//
|
||||
// Both commands predate proxied mode and assume bd owns the sql-server: they
|
||||
// read and write .beads/dolt-server.pid. A proxied workspace never has one —
|
||||
// the proxy writes proxy.pid and proxy-child.pid under the proxied root — so
|
||||
// status used to report "not running" against a healthy backend, and start
|
||||
// used to act on that by putting a second sql-server over the live data
|
||||
// directory. This file is the proxied-aware half of both.
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/steveyegge/beads/internal/configfile"
|
||||
"github.com/steveyegge/beads/internal/storage/dbproxy/proxy"
|
||||
)
|
||||
|
||||
// Stable identity of the `bd dolt start` refusal on a proxied workspace.
|
||||
// Codes are the part of the refusal contract downstream consumers branch on,
|
||||
// so this one is frozen; the message beside it is informative.
|
||||
const proxyDoltStartConflictCode = "proxy.dolt_start.conflict"
|
||||
|
||||
const proxyDoltStartConflictMessage = "dolt start is not supported in proxied-server mode: " +
|
||||
"the proxy owns its dolt backend, and a second sql-server over the same data directory risks corrupting it; " +
|
||||
"the proxy starts on demand — run 'bd dolt status' to see what is running, or 'bd dolt stop' to shut it down"
|
||||
|
||||
// proxiedDoltStartRefusal is enforced inside the command rather than by the
|
||||
// pre-provider capability gate because `bd dolt` is a noDbCommands entry: its
|
||||
// subcommands skip store init and so never reach the gate in main.go. Folding
|
||||
// this row into the consolidated registry is S2's job; the corruption guard
|
||||
// should not wait for it.
|
||||
func proxiedDoltStartRefusal() *ProxyCapabilityError {
|
||||
return &ProxyCapabilityError{
|
||||
Code: proxyDoltStartConflictCode,
|
||||
Message: proxyDoltStartConflictMessage,
|
||||
ExitCode: 1,
|
||||
}
|
||||
}
|
||||
|
||||
// proxiedDoltStatus is the `bd dolt status --json` payload for a proxied
|
||||
// workspace. It reports the two processes separately because they fail
|
||||
// separately and an operator's next move differs: Running says whether the
|
||||
// workspace is serving (a live proxy, and on a managed topology a live dolt
|
||||
// behind it), Proxy* describe the proxy every bd command connects through, and
|
||||
// the Backend* fields describe the dolt server behind it. A proxy left in front
|
||||
// of a dead managed backend (possible with proxies started by an older bd)
|
||||
// therefore reports running=false with proxy_pid still set.
|
||||
type proxiedDoltStatus struct {
|
||||
Mode string `json:"mode"`
|
||||
Root string `json:"root"`
|
||||
Running bool `json:"running"`
|
||||
ProxyPID int `json:"proxy_pid,omitempty"`
|
||||
ProxyPort int `json:"proxy_port,omitempty"`
|
||||
// BackendManaged is false on an external proxied topology, where the
|
||||
// dolt server is somebody else's process and BackendRunning says nothing
|
||||
// about it. Without this flag a caller cannot tell "the backend is down"
|
||||
// from "bd never had a backend to report".
|
||||
BackendManaged bool `json:"backend_managed"`
|
||||
BackendRunning bool `json:"backend_running"`
|
||||
BackendPID int `json:"backend_pid,omitempty"`
|
||||
BackendPort int `json:"backend_port,omitempty"`
|
||||
BackendEndpoint string `json:"backend_endpoint,omitempty"`
|
||||
IdleTimeout string `json:"idle_timeout,omitempty"`
|
||||
}
|
||||
|
||||
func collectProxiedDoltStatus(beadsDir string) (proxiedDoltStatus, error) {
|
||||
root, err := resolveProxiedServerRootPath(beadsDir)
|
||||
if err != nil {
|
||||
return proxiedDoltStatus{}, err
|
||||
}
|
||||
live := proxy.ReadStatus(root)
|
||||
status := proxiedDoltStatus{
|
||||
Mode: configfile.DoltModeProxiedServer,
|
||||
Root: root,
|
||||
Running: live.ProxyRunning,
|
||||
ProxyPID: live.ProxyPID,
|
||||
ProxyPort: live.ProxyPort,
|
||||
BackendManaged: true,
|
||||
BackendRunning: live.BackendRunning,
|
||||
BackendPID: live.BackendPID,
|
||||
BackendPort: live.BackendPort,
|
||||
}
|
||||
|
||||
info, err := configfile.LoadProxiedServerClientInfo(beadsDir)
|
||||
if err != nil {
|
||||
return proxiedDoltStatus{}, err
|
||||
}
|
||||
// A missing sidecar means the workspace predates it or was hand-edited;
|
||||
// managed-local is the default topology, and the pid records already read
|
||||
// above are the authority on what is actually running either way.
|
||||
if info != nil {
|
||||
if info.IdleTimeout > 0 {
|
||||
status.IdleTimeout = info.IdleTimeout.String()
|
||||
}
|
||||
if info.External != nil {
|
||||
status.BackendManaged = false
|
||||
status.BackendEndpoint = externalDoltEndpoint(*info.External)
|
||||
}
|
||||
}
|
||||
status.Running = proxiedStatusServing(live.ProxyRunning, status.BackendManaged, status.BackendRunning)
|
||||
return status, nil
|
||||
}
|
||||
|
||||
// proxiedStatusServing reports whether a proxied workspace is serving: its
|
||||
// proxy is live and, when bd manages the backend, that dolt server is live
|
||||
// too. A proxy in front of a dead managed backend serves nothing.
|
||||
func proxiedStatusServing(proxyRunning, backendManaged, backendRunning bool) bool {
|
||||
return proxyRunning && (!backendManaged || backendRunning)
|
||||
}
|
||||
|
||||
func externalDoltEndpoint(cfg configfile.ExternalDoltConfig) string {
|
||||
if cfg.Socket != "" {
|
||||
return "unix:" + cfg.Socket
|
||||
}
|
||||
return net.JoinHostPort(cfg.Host, strconv.Itoa(cfg.Port))
|
||||
}
|
||||
|
||||
func renderProxiedDoltStatus(status proxiedDoltStatus) {
|
||||
if jsonOutput {
|
||||
if err := outputJSON(status); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// A live proxy in front of a managed backend that is gone serves nothing,
|
||||
// so do not call it running. The proxy retires itself once it notices
|
||||
// the backend exit; a proxy from an older bd may not.
|
||||
backendDown := !status.Running && status.ProxyPID != 0 && status.BackendManaged && !status.BackendRunning
|
||||
switch {
|
||||
case backendDown:
|
||||
fmt.Printf("Dolt server: not serving (%s): proxy is up but its dolt backend is not running\n", status.Mode)
|
||||
fmt.Printf(" Proxy PID: %d\n", status.ProxyPID)
|
||||
fmt.Printf(" Proxy port: %d\n", status.ProxyPort)
|
||||
case status.Running:
|
||||
fmt.Printf("Dolt server: running (%s)\n", status.Mode)
|
||||
fmt.Printf(" Proxy PID: %d\n", status.ProxyPID)
|
||||
fmt.Printf(" Proxy port: %d\n", status.ProxyPort)
|
||||
default:
|
||||
fmt.Printf("Dolt server: not running (%s)\n", status.Mode)
|
||||
}
|
||||
fmt.Printf(" Root: %s\n", status.Root)
|
||||
switch {
|
||||
case !status.BackendManaged:
|
||||
fmt.Printf(" Backend: external at %s (not managed by bd)\n", status.BackendEndpoint)
|
||||
case status.BackendRunning:
|
||||
fmt.Printf(" Backend: running (dolt PID %d, port %d)\n", status.BackendPID, status.BackendPort)
|
||||
default:
|
||||
fmt.Println(" Backend: not running")
|
||||
}
|
||||
if status.IdleTimeout != "" {
|
||||
fmt.Printf(" Idle timeout: %s\n", status.IdleTimeout)
|
||||
}
|
||||
if !status.Running && !backendDown {
|
||||
fmt.Println(" The proxy starts on demand; the next bd command launches it.")
|
||||
}
|
||||
if backendDown {
|
||||
fmt.Println(" Run 'bd dolt stop' to retire the proxy; the next bd command starts a fresh proxy and backend.")
|
||||
}
|
||||
if isDoltLocalOnly() {
|
||||
fmt.Println(" Remote sync: disabled (dolt.local-only=true)")
|
||||
}
|
||||
}
|
||||
227
cmd/bd/dolt_proxied_lifecycle_test.go
Normal file
227
cmd/bd/dolt_proxied_lifecycle_test.go
Normal file
|
|
@ -0,0 +1,227 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/steveyegge/beads/internal/configfile"
|
||||
)
|
||||
|
||||
// TestProxiedDoltStartRefusalContract pins the parts downstream consumers
|
||||
// branch on. The code is frozen; the message is informative and may be
|
||||
// reworded, but it has to keep naming the mode and pointing somewhere useful,
|
||||
// because "start refused" with no onward path is what sends an operator
|
||||
// looking for a manual workaround.
|
||||
func TestProxiedDoltStartRefusalContract(t *testing.T) {
|
||||
err := proxiedDoltStartRefusal()
|
||||
if err.Code != "proxy.dolt_start.conflict" {
|
||||
t.Errorf("code = %q, want %q", err.Code, "proxy.dolt_start.conflict")
|
||||
}
|
||||
if err.ExitCode != 1 {
|
||||
t.Errorf("exit code = %d, want 1", err.ExitCode)
|
||||
}
|
||||
if err.Mutates {
|
||||
t.Error("mutates = true; a refused start changes nothing")
|
||||
}
|
||||
for _, want := range []string{"proxied-server mode", "bd dolt status", "bd dolt stop"} {
|
||||
if !strings.Contains(err.Message, want) {
|
||||
t.Errorf("message does not mention %q: %q", want, err.Message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExternalDoltEndpoint(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
cfg configfile.ExternalDoltConfig
|
||||
want string
|
||||
}{
|
||||
{"tcp", configfile.ExternalDoltConfig{Host: "127.0.0.1", Port: 3310}, "127.0.0.1:3310"},
|
||||
{"ipv6", configfile.ExternalDoltConfig{Host: "::1", Port: 3310}, "[::1]:3310"},
|
||||
{"socket wins", configfile.ExternalDoltConfig{Socket: "/tmp/dolt.sock"}, "unix:/tmp/dolt.sock"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := externalDoltEndpoint(tc.cfg); got != tc.want {
|
||||
t.Errorf("externalDoltEndpoint = %q, want %q", got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestCollectProxiedDoltStatusQuiescentRoot covers the case an operator hits
|
||||
// most: nothing is running yet. The answer has to be "not running" WITHOUT
|
||||
// starting anything — a status command that spawns the topology it is
|
||||
// reporting on would defeat the idle reaper it is reporting about.
|
||||
func TestCollectProxiedDoltStatusQuiescentRoot(t *testing.T) {
|
||||
beadsDir := t.TempDir()
|
||||
root := filepath.Join(beadsDir, "dolt")
|
||||
t.Setenv("BEADS_PROXIED_SERVER_ROOT_PATH", root)
|
||||
|
||||
status, err := collectProxiedDoltStatus(beadsDir)
|
||||
if err != nil {
|
||||
t.Fatalf("collectProxiedDoltStatus: %v", err)
|
||||
}
|
||||
if status.Mode != "proxied-server" {
|
||||
t.Errorf("mode = %q, want %q", status.Mode, "proxied-server")
|
||||
}
|
||||
if status.Root != root {
|
||||
t.Errorf("root = %q, want %q", status.Root, root)
|
||||
}
|
||||
if status.Running || status.BackendRunning {
|
||||
t.Errorf("reported something running for an empty root: %+v", status)
|
||||
}
|
||||
if !status.BackendManaged {
|
||||
t.Error("backend_managed = false with no external sidecar; managed-local is the default topology")
|
||||
}
|
||||
if entries, _ := filepath.Glob(filepath.Join(root, "*")); len(entries) != 0 {
|
||||
t.Errorf("reading status created %v under the proxied root", entries)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCollectProxiedDoltStatusExternalTopology(t *testing.T) {
|
||||
beadsDir := t.TempDir()
|
||||
root := filepath.Join(beadsDir, "dolt")
|
||||
t.Setenv("BEADS_PROXIED_SERVER_ROOT_PATH", root)
|
||||
if err := configfile.SaveProxiedServerClientInfo(beadsDir, &configfile.ProxiedServerClientInfo{
|
||||
IdleTimeout: 45 * time.Second,
|
||||
External: &configfile.ExternalDoltConfig{Host: "10.0.0.5", Port: 3306},
|
||||
}); err != nil {
|
||||
t.Fatalf("SaveProxiedServerClientInfo: %v", err)
|
||||
}
|
||||
|
||||
status, err := collectProxiedDoltStatus(beadsDir)
|
||||
if err != nil {
|
||||
t.Fatalf("collectProxiedDoltStatus: %v", err)
|
||||
}
|
||||
if status.BackendManaged {
|
||||
t.Error("backend_managed = true for an external topology; bd spawns no dolt there")
|
||||
}
|
||||
if status.BackendEndpoint != "10.0.0.5:3306" {
|
||||
t.Errorf("backend_endpoint = %q, want %q", status.BackendEndpoint, "10.0.0.5:3306")
|
||||
}
|
||||
if status.IdleTimeout != "45s" {
|
||||
t.Errorf("idle_timeout = %q, want %q", status.IdleTimeout, "45s")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderProxiedDoltStatus(t *testing.T) {
|
||||
running := proxiedDoltStatus{
|
||||
Mode: "proxied-server", Root: "/w/.beads/dolt", Running: true,
|
||||
ProxyPID: 111, ProxyPort: 40001,
|
||||
BackendManaged: true, BackendRunning: true, BackendPID: 222, BackendPort: 40002,
|
||||
IdleTimeout: "30s",
|
||||
}
|
||||
|
||||
t.Run("text reports both processes", func(t *testing.T) {
|
||||
defer restoreJSONOutput(t)()
|
||||
jsonOutput = false
|
||||
out := captureStdout(t, func() error { renderProxiedDoltStatus(running); return nil })
|
||||
for _, want := range []string{
|
||||
"Dolt server: running (proxied-server)",
|
||||
"Proxy PID: 111",
|
||||
"Proxy port: 40001",
|
||||
"Root: /w/.beads/dolt",
|
||||
"Backend: running (dolt PID 222, port 40002)",
|
||||
"Idle timeout: 30s",
|
||||
} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Errorf("missing %q in:\n%s", want, out)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("text says how to start it when down", func(t *testing.T) {
|
||||
defer restoreJSONOutput(t)()
|
||||
jsonOutput = false
|
||||
down := running
|
||||
down.Running, down.ProxyPID, down.ProxyPort = false, 0, 0
|
||||
down.BackendRunning, down.BackendPID, down.BackendPort = false, 0, 0
|
||||
out := captureStdout(t, func() error { renderProxiedDoltStatus(down); return nil })
|
||||
for _, want := range []string{
|
||||
"Dolt server: not running (proxied-server)",
|
||||
"Backend: not running",
|
||||
"The proxy starts on demand",
|
||||
} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Errorf("missing %q in:\n%s", want, out)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("text does not call a proxy over a dead managed backend running", func(t *testing.T) {
|
||||
defer restoreJSONOutput(t)()
|
||||
jsonOutput = false
|
||||
stranded := running
|
||||
stranded.Running = false
|
||||
stranded.BackendRunning, stranded.BackendPID, stranded.BackendPort = false, 0, 0
|
||||
out := captureStdout(t, func() error { renderProxiedDoltStatus(stranded); return nil })
|
||||
if strings.Contains(out, "Dolt server: running") {
|
||||
t.Errorf("proxy with a dead backend reported as running:\n%s", out)
|
||||
}
|
||||
for _, want := range []string{
|
||||
"Dolt server: not serving (proxied-server)",
|
||||
"Proxy PID: 111",
|
||||
"Backend: not running",
|
||||
"bd dolt stop",
|
||||
} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Errorf("missing %q in:\n%s", want, out)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("text marks an external backend as somebody else's", func(t *testing.T) {
|
||||
defer restoreJSONOutput(t)()
|
||||
jsonOutput = false
|
||||
external := running
|
||||
external.BackendManaged, external.BackendRunning = false, false
|
||||
external.BackendEndpoint = "10.0.0.5:3306"
|
||||
out := captureStdout(t, func() error { renderProxiedDoltStatus(external); return nil })
|
||||
if !strings.Contains(out, "Backend: external at 10.0.0.5:3306 (not managed by bd)") {
|
||||
t.Errorf("external backend not described:\n%s", out)
|
||||
}
|
||||
if strings.Contains(out, "Backend: not running") {
|
||||
t.Errorf("external backend reported as down; bd has no record to say that from:\n%s", out)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("json carries the process records", func(t *testing.T) {
|
||||
defer restoreJSONOutput(t)()
|
||||
jsonOutput = true
|
||||
out := captureStdout(t, func() error { renderProxiedDoltStatus(running); return nil })
|
||||
var got proxiedDoltStatus
|
||||
if err := json.Unmarshal([]byte(strings.TrimSpace(out)), &got); err != nil {
|
||||
t.Fatalf("decode %q: %v", out, err)
|
||||
}
|
||||
if got != running {
|
||||
t.Errorf("round-trip mismatch:\ngot %+v\nwant %+v", got, running)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestProxiedStatusServing(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
proxyRunning, managed, backendRunning bool
|
||||
want bool
|
||||
}{
|
||||
{"managed pair live", true, true, true, true},
|
||||
{"proxy over dead managed backend", true, true, false, false},
|
||||
{"external backend", true, false, false, true},
|
||||
{"proxy down", false, true, true, false},
|
||||
{"nothing running", false, true, false, false},
|
||||
} {
|
||||
if got := proxiedStatusServing(tc.proxyRunning, tc.managed, tc.backendRunning); got != tc.want {
|
||||
t.Errorf("%s: proxiedStatusServing(%v, %v, %v) = %v, want %v", tc.name, tc.proxyRunning, tc.managed, tc.backendRunning, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func restoreJSONOutput(t *testing.T) func() {
|
||||
t.Helper()
|
||||
orig := jsonOutput
|
||||
return func() { jsonOutput = orig }
|
||||
}
|
||||
|
|
@ -8,9 +8,9 @@ import (
|
|||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/config"
|
||||
"github.com/steveyegge/beads/internal/testutil"
|
||||
)
|
||||
|
||||
|
|
@ -47,13 +47,21 @@ func TestDoltRemoteAddPersistsSyncRemoteToSharedWorktreeConfig(t *testing.T) {
|
|||
t.Fatalf("bd dolt remote add from bare-parent worktree failed: %v\n%s", err, out)
|
||||
}
|
||||
|
||||
// Asserted by reading it back, not by matching YAML text. The literal
|
||||
// `sync.remote: "<url>"` this used to require is a key whose NAME contains
|
||||
// a dot — the shape config.GetStringFromDir can never find, because it
|
||||
// splits on the dot and walks nested mappings. Viper finds a dotted key
|
||||
// either way, so this assertion was green while the value was invisible to
|
||||
// bd's other reader; it passed BECAUSE bd-zj95 was present. What the remote
|
||||
// add owes its caller is a remote that reads back, so that is what this
|
||||
// checks.
|
||||
configPath := filepath.Join(bareBeadsDir, "config.yaml")
|
||||
content, err := os.ReadFile(configPath)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to read shared config.yaml: %v", err)
|
||||
}
|
||||
if !strings.Contains(string(content), `sync.remote: "`+remoteURL+`"`) {
|
||||
t.Fatalf("expected shared config.yaml to contain sync.remote, got:\n%s", string(content))
|
||||
if got := config.GetStringFromDir(bareBeadsDir, "sync.remote"); got != remoteURL {
|
||||
t.Fatalf("shared config.yaml sync.remote = %q, want %q; contents:\n%s", got, remoteURL, content)
|
||||
}
|
||||
|
||||
if _, err := os.Stat(filepath.Join(worktreeDir, ".beads")); !os.IsNotExist(err) {
|
||||
|
|
|
|||
|
|
@ -30,6 +30,15 @@ func exitCodeFromError(err error) (int, bool) {
|
|||
return 0, false
|
||||
}
|
||||
|
||||
// isReportedExit reports whether err is an already-rendered failure — the
|
||||
// *exitError every Handle*Error returns after writing the message (or the JSON
|
||||
// error envelope) itself. A caller that re-wraps one prints a second Error line
|
||||
// and, in --json mode, a plain line after the envelope.
|
||||
func isReportedExit(err error) bool {
|
||||
_, reported := exitCodeFromError(err)
|
||||
return reported
|
||||
}
|
||||
|
||||
func activeWorkspaceNotFoundError() string {
|
||||
return "no active beads workspace found"
|
||||
}
|
||||
|
|
@ -76,8 +85,16 @@ func buildJSONError(message, hint string) interface{} {
|
|||
return inner
|
||||
}
|
||||
|
||||
// buildJSONCapabilityError renders a typed refusal. {code, error, mutates} is a
|
||||
// frozen contract that downstream consumers parse; `reason` is additive and
|
||||
// appears only on refusals that came from the capability registry, which is why
|
||||
// it is omitted rather than emitted empty — a consumer that keys on its presence
|
||||
// must not be told "" by a runtime state error that has no policy reason.
|
||||
func buildJSONCapabilityError(e *ProxyCapabilityError) interface{} {
|
||||
inner := map[string]interface{}{"error": e.Message, "code": e.Code, "mutates": e.Mutates}
|
||||
if e.Reason != "" {
|
||||
inner["reason"] = string(e.Reason)
|
||||
}
|
||||
if jsonEnvelopeEnabled() {
|
||||
return map[string]interface{}{"schema_version": JSONSchemaVersion, "data": inner}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ var storeConstructors = map[string]map[string]bool{
|
|||
"OpenForReadOnlyCommand": true,
|
||||
"OpenForPreviewCommand": true,
|
||||
"OpenForWorkingSetReconcile": true,
|
||||
"OpenForRemoteSync": true,
|
||||
},
|
||||
"github.com/steveyegge/beads/internal/storage/uow": {
|
||||
"NewDoltServerUOWProvider": true,
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import (
|
|||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/metrics"
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
)
|
||||
|
|
@ -33,9 +34,9 @@ Gate types:
|
|||
gh:pr - Waits for PR merge (Phase 3)
|
||||
bead - Waits for another bead to close (Phase 4)
|
||||
|
||||
For bead gates, await_id is a bead ID in this rig's database (e.g., "bd-abc123").
|
||||
The historical cross-rig form <rig>:<bead-id> can no longer be evaluated
|
||||
(multi-rig routing removed) and stays pending until resolved manually.
|
||||
For bead gates, await_id may be a bead ID in this rig's database (e.g.,
|
||||
"bd-abc123") or the historical cross-rig form <rig>:<bead-id>. Cross-rig
|
||||
targets resolve through the bead ID's prefix route in routes.jsonl.
|
||||
|
||||
Examples:
|
||||
bd gate list # Show all open gates
|
||||
|
|
@ -669,7 +670,7 @@ Examples:
|
|||
}
|
||||
}
|
||||
|
||||
results := evaluateGates(ctx, filteredGates, time.Now(), store, persistAwaitID)
|
||||
results := evaluateGates(ctx, filteredGates, time.Now(), routedBeadGateGetter{localStore: store}, persistAwaitID)
|
||||
|
||||
resolvedCount, escalatedCount, errorCount := applyGateCheckResults(
|
||||
results, dryRun, escalateFlag,
|
||||
|
|
@ -1182,27 +1183,48 @@ type issueGetter interface {
|
|||
GetIssue(ctx context.Context, id string) (*types.Issue, error)
|
||||
}
|
||||
|
||||
// routedBeadGateGetter gives direct-mode gate checks the same local -> prefix
|
||||
// route -> contributor fallback used by other read commands. Routed stores are
|
||||
// opened read-only and closed before the result is returned.
|
||||
type routedBeadGateGetter struct {
|
||||
localStore storage.DoltStorage
|
||||
}
|
||||
|
||||
func (g routedBeadGateGetter) GetIssue(ctx context.Context, id string) (*types.Issue, error) {
|
||||
if g.localStore == nil {
|
||||
return nil, fmt.Errorf("no local store available")
|
||||
}
|
||||
result, err := getIssueWithRouting(ctx, g.localStore, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer result.Close()
|
||||
return result.Issue, nil
|
||||
}
|
||||
|
||||
// checkBeadGate checks if a bead gate is satisfied.
|
||||
// Returns (satisfied, reason).
|
||||
//
|
||||
// A plain await_id (no colon) names a bead in THIS rig's database: the gate
|
||||
// resolves once that bead closes — the common case, an agent idle-waiting on
|
||||
// local work (wy-hgms2; the old unconditional cross-rig refusal left every
|
||||
// local bead gate permanently pending and its waiters asleep).
|
||||
//
|
||||
// The historical cross-rig form <rig>:<bead-id> cannot be evaluated since
|
||||
// multi-rig routing was removed; it stays pending with a descriptive message.
|
||||
// A plain await_id names a bead in this rig. The historical
|
||||
// <rig>:<bead-id> form uses the bead ID as the routed lookup key; the rig
|
||||
// component is retained for compatibility while routes.jsonl remains keyed by
|
||||
// bead prefix. The supplied getter owns local-versus-routed lookup policy.
|
||||
func checkBeadGate(ctx context.Context, st issueGetter, awaitID string) (bool, string) {
|
||||
if awaitID == "" {
|
||||
return false, "bead gate has no await_id"
|
||||
}
|
||||
targetID := awaitID
|
||||
if strings.Contains(awaitID, ":") {
|
||||
return false, fmt.Sprintf("cross-rig bead gate %q cannot be checked (multi-rig routing removed)", awaitID)
|
||||
parts := strings.SplitN(awaitID, ":", 2)
|
||||
if parts[0] == "" || parts[1] == "" {
|
||||
return false, fmt.Sprintf("invalid cross-rig bead gate %q: expected <rig>:<bead-id>", awaitID)
|
||||
}
|
||||
targetID = parts[1]
|
||||
}
|
||||
if st == nil {
|
||||
return false, fmt.Sprintf("bead gate %q: no local store available", awaitID)
|
||||
}
|
||||
issue, err := st.GetIssue(ctx, awaitID)
|
||||
issue, err := st.GetIssue(ctx, targetID)
|
||||
if err != nil {
|
||||
return false, fmt.Sprintf("bead gate %q: %v", awaitID, err)
|
||||
}
|
||||
|
|
@ -1210,9 +1232,9 @@ func checkBeadGate(ctx context.Context, st issueGetter, awaitID string) (bool, s
|
|||
return false, fmt.Sprintf("bead gate %q: bead not found", awaitID)
|
||||
}
|
||||
if issue.Status == types.StatusClosed {
|
||||
return true, fmt.Sprintf("bead %s closed", awaitID)
|
||||
return true, fmt.Sprintf("bead %s closed", targetID)
|
||||
}
|
||||
return false, fmt.Sprintf("bead %s is %s", awaitID, issue.Status)
|
||||
return false, fmt.Sprintf("bead %s is %s", targetID, issue.Status)
|
||||
}
|
||||
|
||||
// closeGate closes a gate issue with the given reason
|
||||
|
|
|
|||
|
|
@ -39,8 +39,21 @@ func (proxiedFreshReadGetter) GetIssue(ctx context.Context, id string) (*types.I
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer uw.Close(ctx)
|
||||
return uw.IssueUseCase().GetIssue(ctx, id)
|
||||
issue, localErr := uw.IssueUseCase().GetIssue(ctx, id)
|
||||
uw.Close(ctx)
|
||||
if localErr == nil {
|
||||
return issue, nil
|
||||
}
|
||||
if !gateProxiedNotFound(localErr) {
|
||||
return nil, localErr
|
||||
}
|
||||
|
||||
result, routeErr := resolveViaPrefixRouting(ctx, id)
|
||||
if routeErr != nil {
|
||||
return nil, localErr
|
||||
}
|
||||
defer result.Close()
|
||||
return result.Issue, nil
|
||||
}
|
||||
|
||||
func runGateCheckProxiedServer(cmd *cobra.Command, ctx context.Context) error {
|
||||
|
|
|
|||
77
cmd/bd/gate_routing_test.go
Normal file
77
cmd/bd/gate_routing_test.go
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
//go:build cgo
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
// TestCheckBeadGateCrossRigPrefixRoute proves the full evaluator seam: the
|
||||
// historical rig:id value is reduced to the target bead ID, the current
|
||||
// routes.jsonl prefix router opens the foreign store read-only, and target
|
||||
// lifecycle state determines whether the gate resolves.
|
||||
//
|
||||
// NOTE: This test uses os.Chdir and cannot run in parallel with other tests.
|
||||
func TestCheckBeadGateCrossRigPrefixRoute(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
townRoot := t.TempDir()
|
||||
townBeadsDir := filepath.Join(townRoot, ".beads")
|
||||
rigBeadsDir := filepath.Join(townRoot, "rig", ".beads")
|
||||
if err := os.MkdirAll(townBeadsDir, 0o755); err != nil {
|
||||
t.Fatalf("create town beads dir: %v", err)
|
||||
}
|
||||
if err := os.MkdirAll(rigBeadsDir, 0o755); err != nil {
|
||||
t.Fatalf("create rig beads dir: %v", err)
|
||||
}
|
||||
|
||||
townDBPath := filepath.Join(townBeadsDir, "dolt")
|
||||
townStore := newTestStoreIsolatedDB(t, townDBPath, "hq")
|
||||
rigStore := newTestStoreIsolatedDB(t, filepath.Join(rigBeadsDir, "dolt"), "gt")
|
||||
for _, issue := range []*types.Issue{
|
||||
{ID: "gt-closed", Title: "Closed routed target", Status: types.StatusClosed, Priority: 2, IssueType: types.TypeTask},
|
||||
{ID: "gt-open", Title: "Open routed target", Status: types.StatusOpen, Priority: 2, IssueType: types.TypeTask},
|
||||
} {
|
||||
if err := rigStore.CreateIssue(ctx, issue, "test"); err != nil {
|
||||
t.Fatalf("create routed issue %s: %v", issue.ID, err)
|
||||
}
|
||||
}
|
||||
if err := rigStore.Close(); err != nil {
|
||||
t.Fatalf("close rig store: %v", err)
|
||||
}
|
||||
|
||||
routesPath := filepath.Join(townBeadsDir, "routes.jsonl")
|
||||
if err := os.WriteFile(routesPath, []byte(`{"prefix":"gt-","path":"rig"}`), 0o644); err != nil {
|
||||
t.Fatalf("write routes.jsonl: %v", err)
|
||||
}
|
||||
|
||||
oldDBPath := dbPath
|
||||
dbPath = townDBPath
|
||||
t.Cleanup(func() { dbPath = oldDBPath })
|
||||
oldWD, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatalf("get working directory: %v", err)
|
||||
}
|
||||
if err := os.Chdir(townRoot); err != nil {
|
||||
t.Fatalf("change to town root: %v", err)
|
||||
}
|
||||
t.Cleanup(func() { _ = os.Chdir(oldWD) })
|
||||
|
||||
getter := routedBeadGateGetter{localStore: townStore}
|
||||
resolved, reason := checkBeadGate(ctx, getter, "rig:gt-closed")
|
||||
if !resolved {
|
||||
t.Fatalf("closed cross-rig target did not resolve gate: %s", reason)
|
||||
}
|
||||
|
||||
resolved, reason = checkBeadGate(ctx, getter, "rig:gt-open")
|
||||
if resolved {
|
||||
t.Fatalf("open cross-rig target unexpectedly resolved gate: %s", reason)
|
||||
}
|
||||
if !gateTestContainsIgnoreCase(reason, "open") {
|
||||
t.Fatalf("pending reason %q does not report target status", reason)
|
||||
}
|
||||
}
|
||||
|
|
@ -3,10 +3,12 @@ package main
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"sync"
|
||||
"testing"
|
||||
|
|
@ -154,28 +156,53 @@ func TestShouldCheckGate(t *testing.T) {
|
|||
type fakeBeadGateGetter struct {
|
||||
issues map[string]*types.Issue
|
||||
err error
|
||||
gotID string
|
||||
}
|
||||
|
||||
func (f *fakeBeadGateGetter) GetIssue(_ context.Context, id string) (*types.Issue, error) {
|
||||
f.gotID = id
|
||||
if f.err != nil {
|
||||
return nil, f.err
|
||||
}
|
||||
return f.issues[id], nil
|
||||
}
|
||||
|
||||
func TestCheckBeadGate_CrossRigStaysPending(t *testing.T) {
|
||||
func TestCheckBeadGate_CrossRigUsesBeadIDForRoutedLookup(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
st := &fakeBeadGateGetter{issues: map[string]*types.Issue{
|
||||
"gt-abc": {ID: "gt-abc", Status: types.StatusClosed},
|
||||
}}
|
||||
|
||||
// The cross-rig <rig>:<bead-id> form cannot be evaluated since multi-rig
|
||||
// routing was removed; it must stay pending with the explanatory message,
|
||||
// never consult the store, and never resolve.
|
||||
satisfied, reason := checkBeadGate(ctx, st, "gastown:gt-abc")
|
||||
if !satisfied {
|
||||
t.Fatalf("expected closed routed bead to satisfy gate, got reason %q", reason)
|
||||
}
|
||||
if st.gotID != "gt-abc" {
|
||||
t.Fatalf("routed lookup ID = %q, want %q", st.gotID, "gt-abc")
|
||||
}
|
||||
}
|
||||
|
||||
func TestProxiedFreshReadGetterPreservesLocalNotFoundWhenRoutingUnavailable(t *testing.T) {
|
||||
withStubbedProxiedLookup(t, nil)
|
||||
|
||||
oldDBPath := dbPath
|
||||
dbPath = filepath.Join(t.TempDir(), ".beads", "dolt")
|
||||
t.Cleanup(func() { dbPath = oldDBPath })
|
||||
|
||||
_, err := (proxiedFreshReadGetter{}).GetIssue(context.Background(), "bd-missing")
|
||||
if !errors.Is(err, sql.ErrNoRows) {
|
||||
t.Fatalf("GetIssue error = %v, want original local not-found", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckBeadGate_InvalidCrossRigFormat(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tests := []struct {
|
||||
name string
|
||||
awaitID string
|
||||
}{
|
||||
{name: "missing rig", awaitID: ":gt-abc"},
|
||||
{name: "missing bead", awaitID: "my-project:"},
|
||||
{name: "well-formed cross-rig", awaitID: "nonexistent:some-id"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
@ -184,8 +211,8 @@ func TestCheckBeadGate_CrossRigStaysPending(t *testing.T) {
|
|||
if satisfied {
|
||||
t.Errorf("expected not satisfied for %q", tt.awaitID)
|
||||
}
|
||||
if !gateTestContainsIgnoreCase(reason, "multi-rig routing removed") {
|
||||
t.Errorf("reason %q does not contain %q", reason, "multi-rig routing removed")
|
||||
if !gateTestContainsIgnoreCase(reason, "expected <rig>:<bead-id>") {
|
||||
t.Errorf("reason %q does not describe the expected format", reason)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/steveyegge/beads/internal/config"
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/validation"
|
||||
|
|
@ -305,15 +304,6 @@ func warnUnknownGraphFields(w io.Writer, unknown map[string][]string) []string {
|
|||
return hintFields
|
||||
}
|
||||
|
||||
func loadEmbeddedCustomTypes() []string {
|
||||
if store != nil {
|
||||
if ct, err := store.GetCustomTypes(rootCtx); err == nil && len(ct) > 0 {
|
||||
return ct
|
||||
}
|
||||
}
|
||||
return config.GetCustomTypesFromYAML()
|
||||
}
|
||||
|
||||
// loadEmbeddedCustomStatuses reads custom statuses from the store only — no
|
||||
// YAML fallback, matching single-issue create and loadListFilterConfig
|
||||
// (custom types fall back to YAML; custom statuses deliberately do not).
|
||||
|
|
@ -348,9 +338,13 @@ func createIssuesFromGraph(planFile string, dryRun bool, opts GraphApplyOptions)
|
|||
return HandleErrorRespectJSON("parsing graph plan: %v", err)
|
||||
}
|
||||
|
||||
customTypes, err := resolveWorkspaceCustomTypes(rootCtx)
|
||||
if err != nil {
|
||||
return HandleErrorRespectJSON("%v", err)
|
||||
}
|
||||
dbPrefix, allowedPrefixes := loadEmbeddedIDPrefixes()
|
||||
cfg := graphPlanConfig{
|
||||
customTypes: loadEmbeddedCustomTypes(),
|
||||
customTypes: customTypes,
|
||||
customStatuses: loadEmbeddedCustomStatuses(),
|
||||
dbPrefix: dbPrefix,
|
||||
allowedPrefixes: allowedPrefixes,
|
||||
|
|
|
|||
|
|
@ -1,28 +0,0 @@
|
|||
package main
|
||||
|
||||
// HistoryCapabilityClass classifies history/version-control commands on the
|
||||
// proxied topology without coupling them to a particular backend engine.
|
||||
type HistoryCapabilityClass string
|
||||
|
||||
const (
|
||||
HistoryProxySupported HistoryCapabilityClass = "proxy-supported"
|
||||
HistoryProxyAPI HistoryCapabilityClass = "proxy-api"
|
||||
HistoryDirectOnly HistoryCapabilityClass = "direct-only"
|
||||
)
|
||||
|
||||
var historyCapabilityMatrix = map[string]HistoryCapabilityClass{
|
||||
"history": HistoryProxySupported,
|
||||
"branch": HistoryDirectOnly, "conflicts": HistoryDirectOnly, "repo": HistoryDirectOnly,
|
||||
"federation": HistoryDirectOnly, "vc": HistoryDirectOnly, "flatten": HistoryDirectOnly,
|
||||
"dolt push": HistoryDirectOnly, "dolt pull": HistoryDirectOnly, "dolt commit": HistoryDirectOnly,
|
||||
"dolt remote": HistoryDirectOnly, "dolt remote add": HistoryDirectOnly, "dolt remote list": HistoryDirectOnly,
|
||||
"dolt remote reset-data": HistoryDirectOnly, "dolt remote remove": HistoryProxySupported,
|
||||
"sync": HistoryDirectOnly,
|
||||
}
|
||||
|
||||
// LookupHistoryCapability classifies an exact command path. Unknown paths are
|
||||
// intentionally absent so callers cannot accidentally advertise support.
|
||||
func LookupHistoryCapability(commandPath string) (HistoryCapabilityClass, bool) {
|
||||
c, ok := historyCapabilityMatrix[commandPath]
|
||||
return c, ok
|
||||
}
|
||||
|
|
@ -61,7 +61,6 @@ func TestHistoryRemoteRefusalFrontDoorMatrix(t *testing.T) {
|
|||
{"flatten", "proxy.flatten.unsupported", "flatten is not supported in proxied-server mode", []string{"flatten"}},
|
||||
{"dolt push", "proxy.dolt_push.unsupported", "dolt push is not supported in proxied-server mode", []string{"dolt", "push"}},
|
||||
{"dolt pull", "proxy.dolt_pull.unsupported", "dolt pull is not supported in proxied-server mode", []string{"dolt", "pull"}},
|
||||
{"dolt commit", "proxy.dolt_commit.unsupported", "dolt commit is not supported in proxied-server mode", []string{"dolt", "commit"}},
|
||||
{"dolt remote add", "proxy.dolt_remote.unsupported", "dolt remote add is not supported in proxied-server mode", []string{"dolt", "remote", "add", "backup", "https://example.invalid/backup"}},
|
||||
{"dolt remote list", "proxy.dolt_remote.unsupported", "dolt remote list is not supported in proxied-server mode", []string{"dolt", "remote", "list"}},
|
||||
{"dolt remote reset-data", "proxy.dolt_remote.unsupported", "dolt remote reset-data is not supported in proxied-server mode", []string{"dolt", "remote", "reset-data", "backup"}},
|
||||
|
|
@ -126,8 +125,10 @@ func snapshotHistoryArtifacts(t *testing.T, p proxiedProject) []byte {
|
|||
return out
|
||||
}
|
||||
|
||||
// TestHistoryRemoteSupportedFrontDoorParity checks the two operations that
|
||||
// are intentionally shared by direct and proxied providers.
|
||||
// TestHistoryRemoteSupportedFrontDoorParity checks the operations that are
|
||||
// intentionally shared by direct and proxied providers: history --events,
|
||||
// dolt remote remove, and dolt commit (the flush point dolt.auto-commit=batch/off
|
||||
// defers to, GH#4995).
|
||||
func TestHistoryRemoteSupportedFrontDoorParity(t *testing.T) {
|
||||
if os.Getenv("BEADS_TEST_PROXIED_SERVER") != "1" && os.Getenv(managedLocalProxiedEnvVar) != "1" {
|
||||
t.Skip("set a proxied test lane to run history parity")
|
||||
|
|
@ -162,6 +163,13 @@ func TestHistoryRemoteSupportedFrontDoorParity(t *testing.T) {
|
|||
if err != nil || !strings.Contains(string(out), "backup") {
|
||||
t.Fatalf("remote remove failed: %v\n%s", err, out)
|
||||
}
|
||||
// dolt commit must pass the front door rather than be refused. Exact
|
||||
// commit semantics are pinned by
|
||||
// TestProxiedServerBatchDefersThenDoltCommitAdvancesHeadOnce.
|
||||
out, err = bdProxiedRun(t, bd, p.dir, "--json", "dolt", "commit")
|
||||
if err != nil || strings.Contains(string(out), "proxy.dolt_commit.unsupported") {
|
||||
t.Fatalf("dolt commit refused or failed: %v\n%s", err, out)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -220,6 +220,68 @@ type VersionChange struct {
|
|||
|
||||
// versionChanges contains agent-actionable changes for recent versions
|
||||
var versionChanges = []VersionChange{
|
||||
{
|
||||
Version: "1.3.2-rc.2",
|
||||
Date: "2026-10-10",
|
||||
Changes: []string{
|
||||
"RC: second candidate for 1.3.2, rc.1 plus one fix, with no schema migration, so upgrading from 1.3.1 or 1.3.2-rc.1 is a binary swap. The rc.1 upgrade note still applies: after upgrading from bd <=1.3.0, run 'bd recompute-blocked' once per workspace (#7037).",
|
||||
"FIX: the post-commit blocked-state recheck publishes its Dolt commit after its own transaction commits (#7030, backport of #6876). Minted inside the transaction, DOLT_ADD staged issues from the BEGIN-time root and could write concurrently committed rows back to their old values while unblocking writes raced. A failed trailing commit now counts as post_tx_commit_dropped instead of a recheck failure.",
|
||||
},
|
||||
},
|
||||
{
|
||||
Version: "1.3.2-rc.1",
|
||||
Date: "2026-10-05",
|
||||
Changes: []string{
|
||||
"RC: first candidate for 1.3.2, a patch on top of 1.3.1 with no schema migration, so upgrading from 1.3.1 is a binary swap.",
|
||||
"UPGRADE: after upgrading from bd <=1.3.0, run 'bd recompute-blocked' once per workspace (#7037). Migration 0059 (first shipped in 1.3.0) recomputes is_blocked with a recursive query whose parent-child filter is dropped by a Dolt query-planner bug on Dolt servers older than 2.4.0 and on the embedded engine (dolthub/dolt#11886). Blockedness then spreads across relates-to, discovered-from, tracks and other edges, and unblocked beads silently vanish from 'bd ready'. The flag is stored, so the damage persists until recomputed. This includes a workspace now on 1.3.1 that was first created by 1.2.x or earlier. The command is idempotent and reports rows_corrected.",
|
||||
"FIX: 'bd purge' keeps every closed bead in a chain above a live bead, not just the one a live bead points at directly (#7031). A closed root over a closed child over an open grandchild used to lose its root, orphaning the rest; --wisps-plane retention sweeps hit this.",
|
||||
"FIX: auto-backup records the Dolt commit read before the sync as its watermark (#7032). A commit landing during the sync used to be recorded as backed up although the snapshot lacked it, and auto-backup then reported 'no changes' until HEAD moved again.",
|
||||
},
|
||||
},
|
||||
{
|
||||
Version: "1.3.1",
|
||||
Date: "2026-09-30",
|
||||
Changes: []string{
|
||||
"STABLE: first stable 1.3.1 release. Same code as 1.3.1-rc.2; only the version stamp changed. No schema migration, so upgrading from 1.3.0 or any 1.3.1 RC is a binary swap. Coming from 1.3.0, the 1.3.1-rc.2 and 1.3.1-rc.1 entries below both apply; read the [1.3.1-rc.2] upgrade notes in CHANGELOG.md.",
|
||||
},
|
||||
},
|
||||
{
|
||||
Version: "1.3.1-rc.2",
|
||||
Date: "2026-09-29",
|
||||
Changes: []string{
|
||||
"RC: second candidate for the 1.3.1 patch line. Still no schema migration, so upgrading from 1.3.0 or 1.3.1-rc.1 is a binary swap. The 1.3.1-rc.1 entry below still applies.",
|
||||
"NEW: on a proxied-server workspace whose Dolt server bd runs (managed-local, the default), 'bd backup init/sync/status/restore/remove' now work, and 'backup.enabled=true' turns on auto-backup (default stays OFF). On an external or team-server proxied topology the family stays refused with 'proxy.backup.unsupported' and \"reason\": \"design\". Proxied refusals now carry a 'reason' field ('design' or 'unimplemented'). A per-workspace '.beads/backup.lock' serializes backups: 'bd backup sync' fails after 5s if another backup is running.",
|
||||
"NEW: 'bd purge --wisps-plane --older-than <age> --force [--limit N] --json' can replace a raw DELETE FROM wisps retention step. With --limit it purges oldest-closed first and reports 'remaining' and 'has_more'; loop while has_more is true.",
|
||||
"CHANGE: 'bd purge' ALWAYS keeps a closed bead that a not-done bead depends on through parent-child, tracks or blocks, and reports the count as 'live_dependent_skipped'. There is no flag to disable it.",
|
||||
"CHANGE: '--older-than' on 'bd purge' and 'bd prune' takes hour values exactly: '12h' no longer rounds up to a day and '36h' no longer floors to one, so 'bd prune --older-than 12h' now deletes rows closed 12-24 hours ago. Day values (7, 7d, 2w) are unchanged; a value too large to represent is refused.",
|
||||
"CHANGE: 'bd show --watch <id>' works under --proxied-server, and on both routes a watch whose id cannot be found exits 1 instead of 0.",
|
||||
"CHANGE: 'bd sql' classifies statements with the SQL parser. Proxied CTE queries ('WITH ... AS (...) SELECT') return their rows instead of 'OK, 0 rows affected', and CALL result sets are printed. In direct server mode a multi-statement write, or a write the parser cannot classify, prints 'OK' / {\"status\":\"ok\"} instead of 'OK, N rows affected' / {\"rows_affected\":N}. 'bd sql --readonly' refuses statements it cannot parse (e.g. PRAGMA).",
|
||||
"CHANGE: 'bd types' lists exactly what 'bd create --type' accepts, with a new 'System types' section and an additive 'system_types' JSON field. A failure to read custom types now fails 'bd types', 'bd create --graph' and 'bd config set storage-class.*' instead of meaning 'no custom types'.",
|
||||
"CHANGE: an explicit BEADS_DIR is authoritative. Point it at the .beads directory itself: a BEADS_DIR naming a project root, or a .beads that does not exist yet, now fails with 'no beads database found' instead of resolving to the nearest workspace above the current directory. 'bd init' initializes the named directory.",
|
||||
"CHANGE: 'bd close' with several ids exits non-zero when any id fails to close (the rest still close). With --json, a summary naming the failed ids goes to stderr.",
|
||||
"CHANGE: an unflagged piped 'bd query' is no longer capped at 50 rows; it follows the 'bd list' limit policy.",
|
||||
"CHANGE: on a proxied workspace, dolt.auto-commit=batch/off now defers Dolt history commits and 'bd dolt commit' is supported as the flush point. Explicit commit points ('bd batch', 'bd mol bond/pour/squash', 'bd mol wisp create') still commit. The default 'on' is unchanged.",
|
||||
"CHANGE: 'bd ready' and 'bd list --ready' include issues whose custom status is in the 'active' category; 'bd list --status <s> --ready' honors --status; bare 'bd list --wisp-type' is refused (use --include-ephemeral); 'bd doctor' warns about a missing .beads/dolt-server-config.yaml gitignore pattern until 'bd doctor --fix'.",
|
||||
"CHANGE: on a proxied-server workspace or under 'bd serve', opening a store against an unreachable Dolt server retries for up to ~40s before failing, instead of failing at once.",
|
||||
"FIX: two blockers of one dependent removed at the same time (parallel closes, a close racing 'bd dep remove' or a delete) no longer leave the dependent stuck blocked and hidden from 'bd ready' (#6716), on every store route including --proxied-server.",
|
||||
"FIX: a proxy whose Dolt backend exits cleanly now retires, so the next command starts a fresh one; 'bd dolt status' reports it as not serving.",
|
||||
"FIX: a server workspace with an empty .beads/dolt is no longer refused as a legacy workspace; 'bd init' writes the version marker.",
|
||||
"FIX: the smart migrate gate no longer auto-migrates a clone whose data is behind its remote. It stops with 'run bd dolt pull, then retry', and 'bd dolt pull' works from that state.",
|
||||
"FIX: deleting or purging a wisp no longer orphans wisp_dependencies, wisp_labels, wisp_events, wisp_comments or wisp_child_counters rows on stores without the wisp foreign keys (existing orphans are not cleaned). A clone missing its dolt-ignored events tables recreates them on open.",
|
||||
},
|
||||
},
|
||||
{
|
||||
Version: "1.3.1-rc.1",
|
||||
Date: "2026-09-16",
|
||||
Changes: []string{
|
||||
"RC: first candidate for the 1.3.1 patch line, on top of 1.3.0. It carries fixes only — no schema migration, so upgrading from 1.3.0 is a binary swap. If you are coming from 1.2.2 or earlier, the [1.3.0] entry below still describes everything you meet, including the migration and backup notes; read it first.",
|
||||
"CHANGE: 'bd dolt start' on a PROXIED workspace is now a typed refusal with code 'proxy.dolt_start.conflict' instead of starting a second sql-server over the proxy's own data directory. It previously either stranded ordinary bd commands on 'invalid connection' or adopted the proxy's dolt child into bd's classic PID/port records, leaving two managers for one process. The proxy owns its backend's lifecycle: it starts on demand, and 'bd dolt stop' shuts it down. Direct-server and embedded workspaces are unaffected.",
|
||||
"CHANGE: 'bd dolt status --json' changes shape on a proxied workspace. It now reports the proxy and its dolt backend separately — {\"mode\": \"proxied-server\", \"running\": <proxy up>, \"proxy_pid\", \"proxy_port\", \"backend_managed\", \"backend_running\", \"backend_pid\", \"backend_port\", \"backend_endpoint\", \"idle_timeout\", \"root\"} — instead of the always-false {\"running\": false, \"pid\": 0, \"port\": 0} it emitted by reading a PID file proxied mode never writes. 'pid' and 'port' are gone, replaced by the proxy_*/backend_* pairs. 'running' now describes the proxy, the endpoint every bd command connects through, so it is usually true where it used to be always false; 'backend_managed' is false on external proxied topologies, where 'backend_endpoint' names the server bd does not manage. A script parsing the old payload changes behavior on upgrade.",
|
||||
"FIX: a dotted config key now round-trips — what 'bd config set' writes is what 'bd config get' and bd's own readers find. Setting a key like 'sync.remote' or 'dolt.host' into a config.yaml with no matching section used to append a top-level key whose NAME contained the dot, which Viper finds and the direct reader GetStringFromDir does not; 'bd init --remote' in a fresh workspace was the ordinary way in, recording a remote no reader could locate. Dotted keys are written nested now, an existing flat spelling is migrated, and 'bd config unset' removes the nested form (it only ever matched the flat one, so unsetting 'sync.remote' silently left the remote live).",
|
||||
"CHANGE: writing a dotted key nested has a consequence outside bd — 'bd config set <dotted.key>' DELETES a flat top-level key of the same literal name. Writing 'dolt.host' into a file that already carries a top-level 'dolt.host: \"10.0.0.1\"' removes that entry and re-emits the value under 'dolt:'; only the key being written is touched. .beads/config.yaml is not exclusively bd's, so an external tool that both writes AND reads flat dotted keys there stops seeing any value bd migrates this way. Realistic collisions are 'dolt.*', 'export.auto', and 'backup.enabled'. If that tool re-adds its flat key the file carries both spellings and bd's own readers disagree: Viper-backed reads ('bd config get', and the dolt.auto-start lookup on store open) return the FLAT value while GetStringFromDir returns the NESTED one, so a 'bd config set' can be shadowed by a stale flat entry. Tracked as #6594; until it lands, let the other tool own its keys, or check .beads/config.yaml for a duplicated key after running 'bd config set'.",
|
||||
"CHANGE: two config writes that used to exit 0 now exit 1, because both produced a value no reader could see — setting a dotted key under a parent that already holds a scalar ('sync: enabled', then 'bd config set sync.remote'), and setting one in a file whose top level is not a mapping.",
|
||||
},
|
||||
},
|
||||
{
|
||||
Version: "1.3.0",
|
||||
Date: "2026-09-15",
|
||||
|
|
|
|||
146
cmd/bd/init_explicit_beads_dir_embedded_test.go
Normal file
146
cmd/bd/init_explicit_beads_dir_embedded_test.go
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
//go:build cgo
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/configfile"
|
||||
"github.com/steveyegge/beads/internal/storage/dbproxy/proxy"
|
||||
)
|
||||
|
||||
// explicitBeadsDirMode describes how a storage mode's bd subprocesses are
|
||||
// initialized and run for the explicit-BEADS_DIR regression tests.
|
||||
type explicitBeadsDirMode struct {
|
||||
initArgs []string
|
||||
env func(home string) []string
|
||||
proxied bool
|
||||
}
|
||||
|
||||
// runExplicitBeadsDirBD runs bd in dir with the mode's isolated environment.
|
||||
// beadsDir, when non-empty, is passed as an explicit BEADS_DIR.
|
||||
func runExplicitBeadsDirBD(t *testing.T, bd string, mode explicitBeadsDirMode, home, dir, beadsDir string, args ...string) (string, string, error) {
|
||||
t.Helper()
|
||||
cmd := exec.Command(bd, args...)
|
||||
cmd.Dir = dir
|
||||
env := append(mode.env(home), "XDG_CONFIG_HOME="+filepath.Join(home, ".config"))
|
||||
if beadsDir != "" {
|
||||
env = append(env, "BEADS_DIR="+beadsDir)
|
||||
}
|
||||
cmd.Env = env
|
||||
var stdout, stderr bytes.Buffer
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
err := cmd.Run()
|
||||
return stdout.String(), stderr.String(), err
|
||||
}
|
||||
|
||||
// testExplicitBeadsDirIsAuthoritative covers the regression where an explicit
|
||||
// BEADS_DIR without project files was ignored during discovery: bd walked up
|
||||
// from CWD, bound the parent workspace, and `bd init` then refused ("already
|
||||
// initialized") while data commands read and wrote the parent's store.
|
||||
func testExplicitBeadsDirIsAuthoritative(t *testing.T, bd string, mode explicitBeadsDirMode) {
|
||||
t.Helper()
|
||||
home := t.TempDir()
|
||||
parent := t.TempDir()
|
||||
initGitRepoAt(t, parent)
|
||||
parentBeadsDir := filepath.Join(parent, ".beads")
|
||||
child := filepath.Join(parent, "child")
|
||||
explicit := filepath.Join(child, ".beads")
|
||||
if err := os.MkdirAll(child, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if mode.proxied {
|
||||
for _, root := range []string{filepath.Join(parentBeadsDir, "dolt"), filepath.Join(explicit, "dolt")} {
|
||||
root := root
|
||||
t.Cleanup(func() {
|
||||
if _, err := os.Stat(root); err != nil {
|
||||
return
|
||||
}
|
||||
if err := proxy.Shutdown(root); err != nil {
|
||||
t.Logf("proxy.Shutdown(%s): %v", root, err)
|
||||
}
|
||||
})
|
||||
shutdownProxyOnInterrupt(t, root)
|
||||
}
|
||||
}
|
||||
|
||||
initArgs := append([]string{"init", "--quiet", "--non-interactive", "--skip-agents", "--skip-hooks"}, mode.initArgs...)
|
||||
if stdout, stderr, err := runExplicitBeadsDirBD(t, bd, mode, home, parent, "", append(initArgs, "--prefix", "par")...); err != nil {
|
||||
t.Fatalf("parent bd init: %v\nstdout:\n%s\nstderr:\n%s", err, stdout, stderr)
|
||||
}
|
||||
parentID, stderr, err := runExplicitBeadsDirBD(t, bd, mode, home, parent, "", "create", "--silent", "parent issue")
|
||||
if err != nil {
|
||||
t.Fatalf("parent bd create: %v\nstderr:\n%s", err, stderr)
|
||||
}
|
||||
parentID = strings.TrimSpace(parentID)
|
||||
|
||||
// A data command against the uninitialized explicit dir must not fall
|
||||
// back to the parent workspace.
|
||||
stdout, stderr, err := runExplicitBeadsDirBD(t, bd, mode, home, child, explicit, "list", "--json")
|
||||
if err == nil || strings.Contains(stdout, parentID) {
|
||||
t.Errorf("bd list with BEADS_DIR=%s (no workspace yet) should fail without reading the parent store; err=%v\nstdout:\n%s\nstderr:\n%s", explicit, err, stdout, stderr)
|
||||
} else if !strings.Contains(stderr, "no beads database found") {
|
||||
t.Errorf("bd list with an uninitialized BEADS_DIR: want \"no beads database found\", got stderr:\n%s", stderr)
|
||||
}
|
||||
|
||||
// bd init must initialize the explicit dir (existing but empty, as a
|
||||
// caller that pre-creates it would leave it), not refuse because of the
|
||||
// parent workspace.
|
||||
if err := os.MkdirAll(explicit, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if stdout, stderr, err := runExplicitBeadsDirBD(t, bd, mode, home, child, explicit, append(initArgs, "--prefix", "kid")...); err != nil {
|
||||
t.Fatalf("bd init with BEADS_DIR=%s: %v\nstdout:\n%s\nstderr:\n%s", explicit, err, stdout, stderr)
|
||||
}
|
||||
childCfg, err := configfile.Load(explicit)
|
||||
if err != nil || childCfg == nil {
|
||||
t.Fatalf("load %s metadata: cfg=%v err=%v", explicit, childCfg, err)
|
||||
}
|
||||
if childCfg.DoltDatabase != "kid" {
|
||||
t.Fatalf("explicit BEADS_DIR dolt_database = %q, want %q", childCfg.DoltDatabase, "kid")
|
||||
}
|
||||
parentCfg, err := configfile.Load(parentBeadsDir)
|
||||
if err != nil || parentCfg == nil || parentCfg.DoltDatabase != "par" {
|
||||
t.Fatalf("parent metadata changed: cfg=%+v err=%v", parentCfg, err)
|
||||
}
|
||||
|
||||
// Writes through the explicit dir land in the new workspace only.
|
||||
childID, stderr, err := runExplicitBeadsDirBD(t, bd, mode, home, child, explicit, "create", "--silent", "child issue")
|
||||
if err != nil {
|
||||
t.Fatalf("bd create with BEADS_DIR=%s: %v\nstderr:\n%s", explicit, err, stderr)
|
||||
}
|
||||
childID = strings.TrimSpace(childID)
|
||||
if !strings.HasPrefix(childID, "kid-") {
|
||||
t.Fatalf("bd create with BEADS_DIR=%s minted %q, want a kid- ID", explicit, childID)
|
||||
}
|
||||
parentList, stderr, err := runExplicitBeadsDirBD(t, bd, mode, home, parent, "", "list", "--json")
|
||||
if err != nil {
|
||||
t.Fatalf("parent bd list: %v\nstderr:\n%s", err, stderr)
|
||||
}
|
||||
if strings.Contains(parentList, childID) || !strings.Contains(parentList, parentID) {
|
||||
t.Fatalf("parent store should hold only %s, got:\n%s", parentID, parentList)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmbeddedInitExplicitBeadsDirIsAuthoritative(t *testing.T) {
|
||||
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
|
||||
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt init tests")
|
||||
}
|
||||
t.Parallel()
|
||||
testExplicitBeadsDirIsAuthoritative(t, buildEmbeddedBD(t), explicitBeadsDirMode{env: bdEnv})
|
||||
}
|
||||
|
||||
func TestProxiedServerInitExplicitBeadsDirIsAuthoritative(t *testing.T) {
|
||||
requireProxiedServerEnv(t)
|
||||
testExplicitBeadsDirIsAuthoritative(t, buildEmbeddedBD(t), explicitBeadsDirMode{
|
||||
initArgs: []string{"--proxied-server"},
|
||||
env: bdProxiedEnv,
|
||||
proxied: true,
|
||||
})
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/config"
|
||||
"github.com/steveyegge/beads/internal/configfile"
|
||||
)
|
||||
|
||||
|
|
@ -125,9 +126,8 @@ func TestPersistInitSyncRemoteExplicitRemoteWritesTargetDir(t *testing.T) {
|
|||
}
|
||||
|
||||
callerConfig := filepath.Join(callerBeadsDir, "config.yaml")
|
||||
if err := os.WriteFile(callerConfig, []byte("sync.remote: git+ssh://git@example.com/wrong/repo.git\n"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
const callerRemote = "git+ssh://git@example.com/wrong/repo.git"
|
||||
seedSyncRemote(t, callerBeadsDir, callerRemote)
|
||||
targetConfig := filepath.Join(targetBeadsDir, "config.yaml")
|
||||
if err := os.WriteFile(targetConfig, []byte("# Beads Config\n"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
@ -162,6 +162,56 @@ func TestPersistInitSyncRemoteExplicitRemoteWritesTargetDir(t *testing.T) {
|
|||
if strings.Contains(string(callerBytes), remote) {
|
||||
t.Fatalf("caller config.yaml was modified instead of target:\n%s", callerBytes)
|
||||
}
|
||||
// Stronger than the absence above: the caller still resolves to what it had.
|
||||
// A write that landed somewhere unreadable would satisfy "does not contain
|
||||
// the new remote" while having quietly destroyed the old one.
|
||||
if got := config.GetStringFromDir(callerBeadsDir, "sync.remote"); got != callerRemote {
|
||||
t.Fatalf("caller sync.remote = %q, want it untouched at %q:\n%s", got, callerRemote, callerBytes)
|
||||
}
|
||||
}
|
||||
|
||||
// `bd init --remote` runs createConfigYaml and then immediately writes
|
||||
// sync.remote into what it just created. That template is comments and nothing
|
||||
// else, which is the one document shape yaml.v3 parses to no nodes at all — so a
|
||||
// writer that round-trips a node tree has nothing to write back but the key it
|
||||
// added, and the operator's first commit after init carries a config.yaml with
|
||||
// its entire documentation deleted. It is git-tracked, so they see it.
|
||||
//
|
||||
// This runs the real pair in the real order rather than asserting on a replica
|
||||
// of the template, so it stays true if either side moves.
|
||||
func TestInitPersistingSyncRemoteKeepsTheConfigTemplate(t *testing.T) {
|
||||
beadsDir := filepath.Join(t.TempDir(), ".beads")
|
||||
if err := os.MkdirAll(beadsDir, 0o750); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := createConfigYaml(beadsDir, false, ""); err != nil {
|
||||
t.Fatalf("createConfigYaml: %v", err)
|
||||
}
|
||||
template, err := os.ReadFile(filepath.Join(beadsDir, "config.yaml"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
const remote = "git+ssh://git@example.com/right/repo.git"
|
||||
if err := persistInitSyncRemote(beadsDir, remote, remote, false, true, false); err != nil {
|
||||
t.Fatalf("persistInitSyncRemote: %v", err)
|
||||
}
|
||||
|
||||
body, err := os.ReadFile(filepath.Join(beadsDir, "config.yaml"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, line := range strings.Split(string(template), "\n") {
|
||||
if strings.TrimSpace(line) == "" {
|
||||
continue
|
||||
}
|
||||
if !strings.Contains(string(body), line) {
|
||||
t.Errorf("init dropped a line of its own config template: %q\ngot:\n%s", line, body)
|
||||
}
|
||||
}
|
||||
if got := config.GetStringFromDir(beadsDir, "sync.remote"); got != remote {
|
||||
t.Errorf("sync.remote = %q, want %q\n%s", got, remote, body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInitTimeCloneConfigExternalDefaultsAreSelfContained(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -75,6 +75,20 @@ func guardLegacyUpgradeWorkspace(beadsDir string) error {
|
|||
return nil
|
||||
}
|
||||
if serverMode {
|
||||
if !present && isEmptyDirectory(filepath.Join(beadsDir, "dolt")) {
|
||||
// An empty .beads/dolt holds no Dolt data, so no legacy release
|
||||
// could have left anything in it to protect: it carries no more
|
||||
// evidence than a server workspace without that directory, which
|
||||
// is admitted above. bd creates exactly this shape itself — the
|
||||
// local Dolt root is made on use even when the data lives on an
|
||||
// external server — so refusing it made `bd init --server
|
||||
// --external` fail over a provisioner's empty root, and made a
|
||||
// workspace that lost its gitignored witness unusable with no bd
|
||||
// command able to repair it. Admitting it lets the command re-seed
|
||||
// the witness. A present pre-1.0 witness was refused above, and a
|
||||
// root holding anything at all still refuses below.
|
||||
return nil
|
||||
}
|
||||
if present && classifyVersionWitness(version) == witnessEraUnknown {
|
||||
// A witness that is present but unreadable — including one left
|
||||
// blank or whitespace-only by an interrupted or disk-full
|
||||
|
|
@ -265,6 +279,22 @@ func hasLegacyDoltRoot(beadsDir string) bool {
|
|||
return err == nil && info.IsDir() && info.Mode()&os.ModeSymlink == 0
|
||||
}
|
||||
|
||||
// isEmptyDirectory reports whether path is a real (non-symlink) directory with
|
||||
// no entries. Any error reading it answers false, so callers fail closed.
|
||||
func isEmptyDirectory(path string) bool {
|
||||
info, err := os.Lstat(path)
|
||||
if err != nil || !info.IsDir() || info.Mode()&os.ModeSymlink != 0 {
|
||||
return false
|
||||
}
|
||||
dir, err := os.Open(path) // #nosec G304 -- bounded probe beneath selected workspace
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer func() { _ = dir.Close() }()
|
||||
names, err := dir.Readdirnames(1)
|
||||
return len(names) == 0 && err == io.EOF
|
||||
}
|
||||
|
||||
func isNonEmptyRegularFile(path string) bool {
|
||||
info, err := os.Lstat(path)
|
||||
return err == nil && info.Mode().IsRegular() && info.Size() > 0
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ func bindSelectedWorkspaceConfig(t *testing.T, beadsDir string) {
|
|||
}
|
||||
|
||||
// writeDoltRootWorkspace lays down the ambiguous shape the guard classifies: a
|
||||
// .beads directory that owns a local Dolt root, plus whatever metadata.json,
|
||||
// .beads directory that owns a populated local Dolt root, plus whatever metadata.json,
|
||||
// config.yaml and version witness the case needs. An empty string means "do not
|
||||
// write this file at all".
|
||||
func writeDoltRootWorkspace(t *testing.T, metadata, configYaml, version string) string {
|
||||
|
|
@ -52,9 +52,7 @@ func writeDoltRootWorkspace(t *testing.T, metadata, configYaml, version string)
|
|||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := os.Mkdir(filepath.Join(beadsDir, "dolt"), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
populateLegacyDoltRoot(t, beadsDir)
|
||||
bindSelectedWorkspaceConfig(t, beadsDir)
|
||||
return beadsDir
|
||||
}
|
||||
|
|
|
|||
|
|
@ -490,7 +490,7 @@ func TestLegacyGuardUsesSelectedTargetSharedServerConfig(t *testing.T) {
|
|||
|
||||
// TestLegacyGuardAdmitsConfigYamlServerWorkspace runs the real binary against
|
||||
// the workspace shape gc provisions — `dolt.mode: server` in
|
||||
// .beads/config.yaml, a local .beads/dolt root, a metadata.json that names no
|
||||
// .beads/config.yaml, a populated local .beads/dolt root, a metadata.json that names no
|
||||
// dolt_mode — and pins that the guard no longer calls it legacy. The in-process
|
||||
// guard tests bind the workspace config themselves; only a subprocess proves
|
||||
// that PersistentPreRunE's own binding puts the selected workspace's
|
||||
|
|
@ -518,9 +518,7 @@ func TestLegacyGuardAdmitsConfigYamlServerWorkspace(t *testing.T) {
|
|||
repoDir := t.TempDir()
|
||||
initGitRepo(t, repoDir)
|
||||
beadsDir := filepath.Join(repoDir, ".beads")
|
||||
if err := os.MkdirAll(filepath.Join(beadsDir, "dolt"), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
populateLegacyDoltRoot(t, beadsDir)
|
||||
writeFile(t, filepath.Join(beadsDir, "metadata.json"), []byte(`{"backend":"dolt","dolt_database":"hq"}`))
|
||||
writeFile(t, filepath.Join(beadsDir, "config.yaml"), []byte("dolt:\n mode: server\n auto-start: false\n"))
|
||||
if tt.version != "" {
|
||||
|
|
|
|||
143
cmd/bd/legacy_upgrade_guard_empty_root_test.go
Normal file
143
cmd/bd/legacy_upgrade_guard_empty_root_test.go
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// populateLegacyDoltRoot lays down a .beads/dolt root that holds a Dolt
|
||||
// database, the shape a historical local sql-server left behind. The guard has
|
||||
// to treat such a root as evidence worth protecting.
|
||||
func populateLegacyDoltRoot(t *testing.T, beadsDir string) {
|
||||
t.Helper()
|
||||
if err := os.MkdirAll(filepath.Join(beadsDir, "dolt", "beads", ".dolt"), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// writeEmptyDoltRootServerWorkspace lays down the shape a current bd leaves
|
||||
// behind after `bd init --server --external`: server mode selected, a
|
||||
// .beads/dolt directory that bd created on use but that holds nothing because
|
||||
// the data lives on the external server, and — once the gitignored witness has
|
||||
// been lost, or when a provisioner created the empty root before bd init —
|
||||
// no .local_version.
|
||||
func writeEmptyDoltRootServerWorkspace(t *testing.T, metadata, configYaml, version string) string {
|
||||
t.Helper()
|
||||
beadsDir := t.TempDir()
|
||||
for name, contents := range map[string]string{
|
||||
"metadata.json": metadata,
|
||||
"config.yaml": configYaml,
|
||||
} {
|
||||
if contents == "" {
|
||||
continue
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(beadsDir, name), []byte(contents), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if version != "" {
|
||||
if err := writeLocalVersion(filepath.Join(beadsDir, localVersionFile), version); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := os.Mkdir(filepath.Join(beadsDir, "dolt"), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bindSelectedWorkspaceConfig(t, beadsDir)
|
||||
return beadsDir
|
||||
}
|
||||
|
||||
const externalServerMetadata = `{"backend":"dolt","dolt_mode":"server","dolt_server_host":"db.example.test","dolt_database":"ext_db"}`
|
||||
|
||||
// TestLegacyUpgradeGuardAdmitsServerWorkspaceWithEmptyDoltRoot pins the
|
||||
// external-host recovery: a server-mode workspace whose .beads/dolt is empty
|
||||
// and whose witness is missing holds no local Dolt data a legacy release could
|
||||
// have left there, so it carries no more evidence than a workspace with no
|
||||
// .beads/dolt at all — which the guard already admits. Refusing it made the
|
||||
// workspace unusable after `bd init --server --external` whenever the witness
|
||||
// was absent, with no bd command able to repair it.
|
||||
func TestLegacyUpgradeGuardAdmitsServerWorkspaceWithEmptyDoltRoot(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
metadata string
|
||||
configYaml string
|
||||
}{
|
||||
{name: "metadata.json external server", metadata: externalServerMetadata},
|
||||
{name: "metadata.json server", metadata: `{"backend":"dolt","dolt_mode":"server"}`},
|
||||
{name: "config.yaml server mode", configYaml: configYamlServerMode},
|
||||
// Proxied-server does not select server mode, so it never reaches the
|
||||
// empty-root branch; it is admitted by the final non-embedded arm. Pin
|
||||
// that so a later change to either arm cannot start refusing it.
|
||||
{name: "metadata.json proxied server", metadata: `{"backend":"dolt","dolt_mode":"proxied-server"}`},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
warnings := captureLegacyUpgradeWarnings(t)
|
||||
beadsDir := writeEmptyDoltRootServerWorkspace(t, tc.metadata, tc.configYaml, "")
|
||||
|
||||
if err := guardLegacyUpgradeWorkspace(beadsDir); err != nil {
|
||||
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want nil", err)
|
||||
}
|
||||
if warnings.Len() != 0 {
|
||||
t.Fatalf("guard warned about an absent witness: %q", warnings.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestLegacyUpgradeGuardEmptyDoltRootAdmissionStaysNarrow proves the empty-root
|
||||
// admission relaxes nothing else: pre-1.0 evidence still refuses, a root that
|
||||
// holds anything still refuses, and outside server mode an empty root is still
|
||||
// the legacy embedded shape.
|
||||
func TestLegacyUpgradeGuardEmptyDoltRootAdmissionStaysNarrow(t *testing.T) {
|
||||
t.Run("historical server witness", func(t *testing.T) {
|
||||
captureLegacyUpgradeWarnings(t)
|
||||
beadsDir := writeEmptyDoltRootServerWorkspace(t, externalServerMetadata, "", "0.62.0")
|
||||
|
||||
if err := guardLegacyUpgradeWorkspace(beadsDir); !isLegacyUpgradeRefusal(err) {
|
||||
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want migration refusal", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("historical embedded witness", func(t *testing.T) {
|
||||
captureLegacyUpgradeWarnings(t)
|
||||
beadsDir := writeEmptyDoltRootServerWorkspace(t, externalServerMetadata, "", "0.49.6")
|
||||
|
||||
if err := guardLegacyUpgradeWorkspace(beadsDir); !isLegacyUpgradeRefusal(err) {
|
||||
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want migration refusal", err)
|
||||
}
|
||||
})
|
||||
|
||||
for _, entry := range []string{"beads", ".dolt", "stray-file"} {
|
||||
t.Run("root holding "+entry, func(t *testing.T) {
|
||||
captureLegacyUpgradeWarnings(t)
|
||||
beadsDir := writeEmptyDoltRootServerWorkspace(t, externalServerMetadata, "", "")
|
||||
path := filepath.Join(beadsDir, "dolt", entry)
|
||||
var err error
|
||||
if entry == "stray-file" {
|
||||
err = os.WriteFile(path, nil, 0o600)
|
||||
} else {
|
||||
err = os.Mkdir(path, 0o700)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := guardLegacyUpgradeWorkspace(beadsDir); !isLegacyUpgradeRefusal(err) {
|
||||
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want migration refusal", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
for _, metadata := range []string{`{"backend":"dolt"}`, `{"backend":"dolt","dolt_mode":"embedded"}`} {
|
||||
t.Run("embedded "+metadata, func(t *testing.T) {
|
||||
captureLegacyUpgradeWarnings(t)
|
||||
beadsDir := writeEmptyDoltRootServerWorkspace(t, metadata, "", "")
|
||||
|
||||
if err := guardLegacyUpgradeWorkspace(beadsDir); !isLegacyUpgradeRefusal(err) {
|
||||
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want migration refusal", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
141
cmd/bd/legacy_upgrade_guard_external_server_test.go
Normal file
141
cmd/bd/legacy_upgrade_guard_external_server_test.go
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
//go:build cgo
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// runExternalServerBD runs the bd binary under test in repoDir with env and
|
||||
// returns its combined output.
|
||||
func runExternalServerBD(t *testing.T, repoDir string, env []string, args ...string) (string, error) {
|
||||
t.Helper()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
||||
defer cancel()
|
||||
cmd := exec.CommandContext(ctx, buildBDUnderTest(t), args...)
|
||||
cmd.Dir = repoDir
|
||||
cmd.Env = env
|
||||
out, err := cmd.CombinedOutput()
|
||||
if ctxErr := ctx.Err(); ctxErr != nil {
|
||||
t.Fatalf("bd %s did not finish before the deadline: %v\n%s", strings.Join(args, " "), ctxErr, out)
|
||||
}
|
||||
return string(out), err
|
||||
}
|
||||
|
||||
// externalServerTestEnv isolates a bd child from the developer's home and
|
||||
// config (a real ~/.beads may select a shared server) and from the ambient
|
||||
// BEADS_DOLT_* endpoint this package's TestMain exports, so only the flags and
|
||||
// files under test choose the target.
|
||||
func externalServerTestEnv(t *testing.T) []string {
|
||||
t.Helper()
|
||||
home := t.TempDir()
|
||||
return append(envWithoutBeadsStorageSettings(),
|
||||
"HOME="+home,
|
||||
"XDG_CONFIG_HOME="+filepath.Join(home, ".config"),
|
||||
"BEADS_TEST_IGNORE_REPO_CONFIG=1",
|
||||
"BD_DISABLE_METRICS=1",
|
||||
"BEADS_DOLT_AUTO_START=0",
|
||||
)
|
||||
}
|
||||
|
||||
func externalServerInitArgs(database string, extra ...string) []string {
|
||||
args := []string{
|
||||
"init", "--quiet", "--server", "--external",
|
||||
"--server-host", "127.0.0.1",
|
||||
"--server-port", fmt.Sprintf("%d", testDoltServerPort),
|
||||
"--database", database,
|
||||
"--prefix", "ext",
|
||||
"--skip-hooks", "--skip-agents",
|
||||
}
|
||||
return append(args, extra...)
|
||||
}
|
||||
|
||||
func assertCurrentVersionWitness(t *testing.T, beadsDir string) {
|
||||
t.Helper()
|
||||
data, err := os.ReadFile(filepath.Join(beadsDir, localVersionFile))
|
||||
if err != nil {
|
||||
t.Fatalf("expected %s after the command: %v", localVersionFile, err)
|
||||
}
|
||||
if got := strings.TrimSpace(string(data)); got != Version {
|
||||
t.Fatalf("%s = %q, want %q", localVersionFile, got, Version)
|
||||
}
|
||||
}
|
||||
|
||||
// TestExternalServerInitWritesWitnessOverEmptyDoltRoot reproduces the
|
||||
// provisioner shape: config.yaml already selects server mode and an empty
|
||||
// .beads/dolt exists before `bd init --server --external` runs. The legacy
|
||||
// guard used to refuse that init as a "legacy Dolt server workspace", so the
|
||||
// scope never got a witness and every later command was refused too.
|
||||
func TestExternalServerInitWritesWitnessOverEmptyDoltRoot(t *testing.T) {
|
||||
skipIfNoDolt(t)
|
||||
env := externalServerTestEnv(t)
|
||||
|
||||
repoDir := t.TempDir()
|
||||
initGitRepo(t, repoDir)
|
||||
beadsDir := filepath.Join(repoDir, ".beads")
|
||||
if err := os.MkdirAll(filepath.Join(beadsDir, "dolt"), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeFile(t, filepath.Join(beadsDir, "config.yaml"), []byte("dolt.mode: server\n"))
|
||||
|
||||
database := uniqueTestDBName(t)
|
||||
t.Cleanup(func() { dropTestDatabase(database, testDoltServerPort) })
|
||||
|
||||
out, err := runExternalServerBD(t, repoDir, append(env, "BEADS_DIR="+beadsDir),
|
||||
externalServerInitArgs(database, "--init-if-missing")...)
|
||||
if err != nil {
|
||||
t.Fatalf("bd init --server --external over an empty .beads/dolt failed: %v\n%s", err, out)
|
||||
}
|
||||
assertCurrentVersionWitness(t, beadsDir)
|
||||
}
|
||||
|
||||
// TestExternalServerWorkspaceRecoversMissingWitness covers a workspace already
|
||||
// in the broken state: initialized against an external server, then left
|
||||
// without .local_version (it is gitignored, so a fresh checkout or a cleanup
|
||||
// drops it) while bd's own empty .beads/dolt remains. The next ordinary
|
||||
// command must open the workspace and re-seed the witness with no manual
|
||||
// steps.
|
||||
func TestExternalServerWorkspaceRecoversMissingWitness(t *testing.T) {
|
||||
skipIfNoDolt(t)
|
||||
env := externalServerTestEnv(t)
|
||||
|
||||
repoDir := t.TempDir()
|
||||
initGitRepo(t, repoDir)
|
||||
beadsDir := filepath.Join(repoDir, ".beads")
|
||||
|
||||
database := uniqueTestDBName(t)
|
||||
t.Cleanup(func() { dropTestDatabase(database, testDoltServerPort) })
|
||||
|
||||
out, err := runExternalServerBD(t, repoDir, env, externalServerInitArgs(database)...)
|
||||
if err != nil {
|
||||
t.Fatalf("bd init --server --external failed: %v\n%s", err, out)
|
||||
}
|
||||
assertCurrentVersionWitness(t, beadsDir)
|
||||
|
||||
entries, err := os.ReadDir(filepath.Join(beadsDir, "dolt"))
|
||||
if err != nil {
|
||||
t.Fatalf("precondition: expected bd init to leave a .beads/dolt directory: %v", err)
|
||||
}
|
||||
if len(entries) != 0 {
|
||||
t.Fatalf("precondition: expected an empty .beads/dolt for an external server, found %d entries", len(entries))
|
||||
}
|
||||
if err := os.Remove(filepath.Join(beadsDir, localVersionFile)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
out, err = runExternalServerBD(t, repoDir, env, "list", "--json", "--all")
|
||||
if err != nil {
|
||||
t.Fatalf("bd list on an external-server workspace without a witness failed: %v\n%s", err, out)
|
||||
}
|
||||
if strings.Contains(out, "explicit migration is required") {
|
||||
t.Fatalf("bd list reported a legacy-upgrade refusal:\n%s", out)
|
||||
}
|
||||
assertCurrentVersionWitness(t, beadsDir)
|
||||
}
|
||||
|
|
@ -206,14 +206,12 @@ func TestLegacyUpgradeGuardMetadataLessSQLiteAndCurrentEmbeddedPrecedence(t *tes
|
|||
}
|
||||
})
|
||||
|
||||
t.Run("explicit server metadata with missing version witness and local Dolt root is refused", func(t *testing.T) {
|
||||
t.Run("explicit server metadata with missing version witness and populated local Dolt root is refused", func(t *testing.T) {
|
||||
beadsDir := t.TempDir()
|
||||
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), []byte(`{"backend":"dolt","dolt_mode":"server"}`), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Mkdir(filepath.Join(beadsDir, "dolt"), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
populateLegacyDoltRoot(t, beadsDir)
|
||||
if err := guardLegacyUpgradeWorkspace(beadsDir); !isLegacyUpgradeRefusal(err) {
|
||||
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want migration refusal", err)
|
||||
}
|
||||
|
|
@ -290,9 +288,7 @@ func TestLegacyUpgradeGuardServerSelectionBeatsStaleEmbeddedRepository(t *testin
|
|||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := os.Mkdir(filepath.Join(beadsDir, "dolt"), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
populateLegacyDoltRoot(t, beadsDir)
|
||||
staleRepo := filepath.Join(beadsDir, "embeddeddolt", "stale", ".dolt")
|
||||
if err := os.MkdirAll(staleRepo, 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
|
|||
|
|
@ -84,7 +84,8 @@ func TestLegacyServerVersionSpansHistoricalServerEra(t *testing.T) {
|
|||
}
|
||||
|
||||
// writeSelectedServerWorkspace lays down the ambiguous shape the guard has to
|
||||
// classify: a selected Dolt server workspace that still owns a local Dolt root.
|
||||
// classify: a selected Dolt server workspace that still owns a populated local
|
||||
// Dolt root.
|
||||
func writeSelectedServerWorkspace(t *testing.T, version string) string {
|
||||
t.Helper()
|
||||
beadsDir := t.TempDir()
|
||||
|
|
@ -97,9 +98,7 @@ func writeSelectedServerWorkspace(t *testing.T, version string) string {
|
|||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := os.Mkdir(filepath.Join(beadsDir, "dolt"), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
populateLegacyDoltRoot(t, beadsDir)
|
||||
return beadsDir
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -240,7 +240,7 @@ func runListCore(cmd *cobra.Command, _ []string) error {
|
|||
}
|
||||
|
||||
if in.watchMode {
|
||||
if err := watchIssues(ctx, activeStore, filter, in.ReadyFlag, in.ParentID, in.SortBy, in.Reverse, in.effectiveLimit); err != nil {
|
||||
if err := watchIssues(ctx, activeStore, filter, in.ReadyFlag, in.ParentID, in.SortBy, in.Reverse, in.effectiveLimit, in.Status); err != nil {
|
||||
if capErr := handleMaxRowsError(err); capErr != nil {
|
||||
return capErr
|
||||
}
|
||||
|
|
@ -315,7 +315,7 @@ func runListCore(cmd *cobra.Command, _ []string) error {
|
|||
return HandleError("loading dependencies for --deps: %v", depErr)
|
||||
}
|
||||
// Hierarchical --parent walks use an unlimited per-level query, so the tree is never page-truncated.
|
||||
displayPrettyListWithDepsMode(treeIssues, false, allDeps, in.depsMode, false, in.ReadyFlag)
|
||||
displayPrettyListWithDepsMode(treeIssues, false, allDeps, in.depsMode, false, in.ReadyFlag, in.Status)
|
||||
printSkipLabelsFooter(in.SkipLabels)
|
||||
return nil
|
||||
}
|
||||
|
|
@ -324,7 +324,7 @@ func runListCore(cmd *cobra.Command, _ []string) error {
|
|||
if depErr != nil && in.depsMode != "" {
|
||||
return HandleError("loading dependencies for --deps: %v", depErr)
|
||||
}
|
||||
displayPrettyListWithDepsMode(issues, false, allDeps, in.depsMode, truncated, in.ReadyFlag)
|
||||
displayPrettyListWithDepsMode(issues, false, allDeps, in.depsMode, truncated, in.ReadyFlag, in.Status)
|
||||
printTruncationHint(truncated, in.effectiveLimit)
|
||||
printSkipLabelsFooter(in.SkipLabels)
|
||||
return nil
|
||||
|
|
@ -470,6 +470,14 @@ func init() {
|
|||
// Infra type filtering: exclude agent/role/message by default
|
||||
listCmd.Flags().Bool("include-infra", false, "Include infrastructure beads (agent/role/message) in output")
|
||||
|
||||
// Ephemeral plane: the wisps table is suppressed by default. This is the
|
||||
// PLANE knob on its own — ListRequest.IncludeEphemeral — as distinct from
|
||||
// --include-infra, which admits the plane AND lifts the infra-type
|
||||
// exclusions above. Without it the plane is reachable from the CLI only
|
||||
// through --include-infra's wider bundle, which leaves --wisp-type below
|
||||
// with no narrow way to match anything.
|
||||
listCmd.Flags().Bool("include-ephemeral", false, "Include ephemeral wisp-plane rows in output (normally hidden)")
|
||||
|
||||
// Explicit type exclusion
|
||||
listCmd.Flags().StringSlice("exclude-type", nil, "Exclude issue types from results (comma-separated or repeatable, e.g., --exclude-type=convoy,epic)")
|
||||
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ func TestListFooterLineCountsAreJustified(t *testing.T) {
|
|||
name string
|
||||
total, open, inProgress int
|
||||
truncated, readyFiltered bool
|
||||
statusSelector string
|
||||
facts footerFacts
|
||||
}{
|
||||
{
|
||||
|
|
@ -90,11 +91,19 @@ func TestListFooterLineCountsAreJustified(t *testing.T) {
|
|||
total: 0, open: 0, inProgress: 0,
|
||||
facts: footerFacts{"total": 0, "open": 0, "in_progress": 0},
|
||||
},
|
||||
{
|
||||
// Explicit --status under --ready is a different pin. The footer
|
||||
// names that selector and must not reuse the default-open sentence.
|
||||
name: "ready-filtered, explicit in_progress",
|
||||
total: 3, open: 0, inProgress: 3, readyFiltered: true,
|
||||
statusSelector: "in_progress",
|
||||
facts: footerFacts{"total": 3},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
line := listFooterLine(tt.total, tt.open, tt.inProgress, tt.truncated, tt.readyFiltered)
|
||||
line := listFooterLine(tt.total, tt.open, tt.inProgress, tt.truncated, tt.readyFiltered, tt.statusSelector)
|
||||
assertEveryNumberIsJustified(t, line, tt.facts)
|
||||
|
||||
// The headline count always describes the rows actually rendered.
|
||||
|
|
@ -110,7 +119,7 @@ func TestListFooterLineCountsAreJustified(t *testing.T) {
|
|||
// reader cannot distinguish "none exist" from "none survived the filter".
|
||||
func TestListFooterLineReadyOmitsVacuousInProgressCount(t *testing.T) {
|
||||
// 40 in-progress issues match the same query; --ready removed them all.
|
||||
line := listFooterLine(6, 6, 0, false, true)
|
||||
line := listFooterLine(6, 6, 0, false, true, "")
|
||||
|
||||
if strings.Contains(line, "in progress)") {
|
||||
t.Errorf("--ready summary asserts an in-progress count that the filter forced to zero: %q", line)
|
||||
|
|
@ -126,7 +135,7 @@ func TestListFooterLineReadyOmitsVacuousInProgressCount(t *testing.T) {
|
|||
// Without --ready the breakdown is a genuine finding and must survive: this is
|
||||
// the half of the behaviour the fix must not regress.
|
||||
func TestListFooterLineUnfilteredKeepsBreakdown(t *testing.T) {
|
||||
line := listFooterLine(9, 6, 3, false, false)
|
||||
line := listFooterLine(9, 6, 3, false, false, "")
|
||||
for _, want := range []string{"Total: 9 issues", "6 open", "3 in progress"} {
|
||||
if !strings.Contains(line, want) {
|
||||
t.Errorf("unfiltered summary lost %q, got: %q", want, line)
|
||||
|
|
@ -157,7 +166,7 @@ func TestDisplayWatchedIssueListReadyFooterDisclosesFilter(t *testing.T) {
|
|||
// for; the footer is what is under test, and this keeps the file free of
|
||||
// the cgo-tagged stub so it still compiles under CGO_ENABLED=0.
|
||||
out := captureStdout(t, func() error {
|
||||
displayWatchedIssueList(context.Background(), nil, issues, false, true)
|
||||
displayWatchedIssueList(context.Background(), nil, issues, false, true, "")
|
||||
return nil
|
||||
})
|
||||
|
||||
|
|
@ -177,7 +186,7 @@ func TestDisplayPrettyListWithDepsReadyFooterDisclosesFilter(t *testing.T) {
|
|||
}
|
||||
|
||||
out := captureStdout(t, func() error {
|
||||
displayPrettyListWithDeps(issues, false, nil, false, true)
|
||||
displayPrettyListWithDeps(issues, false, nil, false, true, "")
|
||||
return nil
|
||||
})
|
||||
if strings.Contains(out, "in progress)") {
|
||||
|
|
@ -190,7 +199,7 @@ func TestDisplayPrettyListWithDepsReadyFooterDisclosesFilter(t *testing.T) {
|
|||
// The other half: without --ready the same wrapper must keep the breakdown,
|
||||
// so the fix cannot be "never print counts".
|
||||
plain := captureStdout(t, func() error {
|
||||
displayPrettyListWithDeps(issues, false, nil, false, false)
|
||||
displayPrettyListWithDeps(issues, false, nil, false, false, "")
|
||||
return nil
|
||||
})
|
||||
if !strings.Contains(plain, "in progress)") {
|
||||
|
|
@ -201,7 +210,7 @@ func TestDisplayPrettyListWithDepsReadyFooterDisclosesFilter(t *testing.T) {
|
|||
// Truncation and readiness are independent scopes and both must be disclosed
|
||||
// when both apply — neither may silently mask the other.
|
||||
func TestListFooterLineTruncationDisclosedAlongsideReady(t *testing.T) {
|
||||
line := listFooterLine(5, 5, 0, true, true)
|
||||
line := listFooterLine(5, 5, 0, true, true, "")
|
||||
if !strings.Contains(line, "truncated by --limit") {
|
||||
t.Errorf("truncated page must say so even under --ready, got: %q", line)
|
||||
}
|
||||
|
|
@ -212,3 +221,65 @@ func TestListFooterLineTruncationDisclosedAlongsideReady(t *testing.T) {
|
|||
t.Errorf("a truncated page must never be labelled Total: %q", line)
|
||||
}
|
||||
}
|
||||
|
||||
// GH#5832: an explicit --status under --ready is a different pin. The default
|
||||
// "open only — --ready excludes in_progress" sentence must not be reused.
|
||||
func TestListFooterLineReadyExplicitStatusNamesSelector(t *testing.T) {
|
||||
line := listFooterLine(3, 0, 3, false, true, "in_progress")
|
||||
if strings.Contains(line, "open only") || strings.Contains(line, "excludes in_progress") {
|
||||
t.Errorf("explicit --status must not reuse the default-open sentence: %q", line)
|
||||
}
|
||||
if !strings.Contains(line, "in_progress only") {
|
||||
t.Errorf("explicit --status footer must name the selected status, got: %q", line)
|
||||
}
|
||||
if strings.Contains(line, "in progress)") {
|
||||
t.Errorf("--ready summary must still omit the vacuous in-progress count: %q", line)
|
||||
}
|
||||
}
|
||||
|
||||
// --pretty/--tree/--deps share displayPrettyListWithDepsMode; --watch uses
|
||||
// displayWatchedIssueList. Both must thread the explicit selector so the
|
||||
// default-open sentence cannot leak through a wrapper.
|
||||
func TestDisplayPrettyListWithDepsReadyExplicitStatusFooter(t *testing.T) {
|
||||
issues := []*types.Issue{
|
||||
{ID: "bd-1", Title: "A", Status: types.StatusInProgress, Priority: 1, IssueType: types.TypeTask},
|
||||
}
|
||||
|
||||
out := captureStdout(t, func() error {
|
||||
displayPrettyListWithDeps(issues, false, nil, false, true, "in_progress")
|
||||
return nil
|
||||
})
|
||||
if strings.Contains(out, "open only") || strings.Contains(out, "excludes in_progress") {
|
||||
t.Errorf("--status in_progress --ready --pretty reused the default-open sentence: %q", out)
|
||||
}
|
||||
if !strings.Contains(out, "in_progress only") {
|
||||
t.Errorf("--status in_progress --ready --pretty must name the selected status, got: %q", out)
|
||||
}
|
||||
|
||||
depsOut := captureStdout(t, func() error {
|
||||
displayPrettyListWithDepsMode(issues, false, nil, "scheduling", false, true, "in_progress")
|
||||
return nil
|
||||
})
|
||||
if strings.Contains(depsOut, "open only") || strings.Contains(depsOut, "excludes in_progress") {
|
||||
t.Errorf("--status in_progress --ready --deps reused the default-open sentence: %q", depsOut)
|
||||
}
|
||||
if !strings.Contains(depsOut, "in_progress only") {
|
||||
t.Errorf("--status in_progress --ready --deps must name the selected status, got: %q", depsOut)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDisplayWatchedIssueListReadyExplicitStatusFooter(t *testing.T) {
|
||||
issues := []*types.Issue{
|
||||
{ID: "bd-1", Title: "A", Status: types.StatusInProgress, Priority: 1, IssueType: types.TypeTask},
|
||||
}
|
||||
out := captureStdout(t, func() error {
|
||||
displayWatchedIssueList(context.Background(), nil, issues, false, true, "in_progress")
|
||||
return nil
|
||||
})
|
||||
if strings.Contains(out, "open only") || strings.Contains(out, "excludes in_progress") {
|
||||
t.Errorf("--status in_progress --ready --watch reused the default-open sentence: %q", out)
|
||||
}
|
||||
if !strings.Contains(out, "in_progress only") {
|
||||
t.Errorf("--status in_progress --ready --watch must name the selected status, got: %q", out)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -317,7 +317,7 @@ func TestListDisplayPrettyList_TruncatedSummary(t *testing.T) {
|
|||
}
|
||||
|
||||
out := captureStdout(t, func() error {
|
||||
displayPrettyListWithDepsMode(issues, false, nil, "", true, false)
|
||||
displayPrettyListWithDepsMode(issues, false, nil, "", true, false, "")
|
||||
return nil
|
||||
})
|
||||
if !strings.Contains(out, "Showing 2 issues") {
|
||||
|
|
@ -343,7 +343,7 @@ func TestDisplayWatchedIssueList_UsesDependencyHierarchy(t *testing.T) {
|
|||
}
|
||||
|
||||
out := captureStdout(t, func() error {
|
||||
displayWatchedIssueList(context.Background(), store, []*types.Issue{child, parent}, false, false)
|
||||
displayWatchedIssueList(context.Background(), store, []*types.Issue{child, parent}, false, false, "")
|
||||
return nil
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ func gatherListInput(cmd *cobra.Command) (listInput, error) {
|
|||
in.IncludeTemplates, _ = cmd.Flags().GetBool("include-templates")
|
||||
in.IncludeGates, _ = cmd.Flags().GetBool("include-gates")
|
||||
in.IncludeInfra, _ = cmd.Flags().GetBool("include-infra")
|
||||
in.IncludeEphemeral, _ = cmd.Flags().GetBool("include-ephemeral")
|
||||
in.ExcludeTypes, _ = cmd.Flags().GetStringSlice("exclude-type")
|
||||
|
||||
in.ParentID, _ = cmd.Flags().GetString("parent")
|
||||
|
|
@ -158,6 +159,28 @@ func gatherListInput(cmd *cobra.Command) (listInput, error) {
|
|||
return in, HandleError("invalid wisp-type %q (must be %s)", s, types.ValidWispTypeNames())
|
||||
}
|
||||
in.WispType = &wt
|
||||
|
||||
// wisp_type is a PREDICATE, not a plane selector (see
|
||||
// issueops.ListRequest.WispType): it narrows whatever the rest of the
|
||||
// request admitted. On a default listing that is the durable rows,
|
||||
// which carry no classification — so this request cannot match a row
|
||||
// for ANY input, and would report an empty listing rather than the
|
||||
// unread plane that actually holds the answer.
|
||||
//
|
||||
// The request stays LAWFUL at the API layer, where composing to empty
|
||||
// is the pinned contract. Refusing it belongs HERE, at the CLI, where
|
||||
// the only thing a human can have meant is the combination that
|
||||
// answers with rows.
|
||||
//
|
||||
// An explicit --type is left alone: an infra type routes to the plane
|
||||
// by itself, so the request may be satisfiable and this cannot tell
|
||||
// without the workspace's infra vocabulary, which this layer does not
|
||||
// load.
|
||||
if !in.IncludeEphemeral && !in.IncludeInfra && in.IssueType == "" {
|
||||
return in, HandleErrorWithHint(
|
||||
fmt.Sprintf("--wisp-type %s cannot match anything here: it filters the wisp_type column, and this listing admits only durable rows, which never carry one", s),
|
||||
"add --include-ephemeral to admit the ephemeral plane (or --include-infra, which admits it as part of a wider bundle)")
|
||||
}
|
||||
}
|
||||
|
||||
in.DeferredFlag, _ = cmd.Flags().GetBool("deferred")
|
||||
|
|
@ -308,10 +331,8 @@ func gatherListInput(cmd *cobra.Command) (listInput, error) {
|
|||
in.effectiveLimit = 0
|
||||
case listLimitConfigured:
|
||||
in.effectiveLimit = limit
|
||||
case !ui.IsTerminal():
|
||||
in.effectiveLimit = 0 // Piped stdout should not truncate (GH#4094)
|
||||
case ui.IsAgentMode():
|
||||
in.effectiveLimit = 20
|
||||
default:
|
||||
in.effectiveLimit = unflaggedLimit(limit)
|
||||
}
|
||||
// The request carries the limit the caller receives. Which row limit that
|
||||
// implies for the query - a sort SQL cannot express fetches everything and
|
||||
|
|
@ -366,3 +387,28 @@ func parseListTimeFlag(cmd *cobra.Command, name string) (*time.Time, error) {
|
|||
}
|
||||
return &t, nil
|
||||
}
|
||||
|
||||
// agentModeLimit is the page size an unflagged listing gets in agent mode on a
|
||||
// terminal: ultra-compact output for an LLM context window.
|
||||
const agentModeLimit = 20
|
||||
|
||||
// unflaggedLimit is the limit a listing command uses when the caller named
|
||||
// none: the part of the policy `bd list` and `bd query` share, so the two
|
||||
// cannot drift (GH#6229). Each command resolves its own earlier branches first
|
||||
// (an explicit --limit, `bd list`'s --all and list.limit) and hands its own
|
||||
// default here as fallback.
|
||||
func unflaggedLimit(fallback int) int {
|
||||
return resolveUnflaggedLimit(fallback, ui.IsTerminal(), ui.IsAgentMode())
|
||||
}
|
||||
|
||||
// resolveUnflaggedLimit is unflaggedLimit with the environment passed in, so
|
||||
// the terminal and agent-mode branches are testable from a piped `go test`.
|
||||
func resolveUnflaggedLimit(fallback int, stdoutIsTerminal, agentMode bool) int {
|
||||
switch {
|
||||
case !stdoutIsTerminal:
|
||||
return 0 // Piped stdout should not truncate (GH#4094)
|
||||
case agentMode:
|
||||
return agentModeLimit
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
|
|
@ -18,8 +19,23 @@ func printTruncationHint(truncated bool, effectiveLimit int) {
|
|||
if !truncated || effectiveLimit <= 0 || !ui.IsStderrTerminal() {
|
||||
return
|
||||
}
|
||||
msg := fmt.Sprintf("\nShowing %d issues; more results matched but were hidden by --limit. Use --limit 0 for all, or --limit N to raise the cap.\n", effectiveLimit)
|
||||
fmt.Fprint(os.Stderr, ui.RenderWarn(msg))
|
||||
fmt.Fprint(os.Stderr, formatTruncationHint(effectiveLimit))
|
||||
}
|
||||
|
||||
func truncationHintText(effectiveLimit int) string {
|
||||
return fmt.Sprintf("Showing %d issues; more results matched but were hidden by --limit. Use --limit 0 for all, or --limit N to raise the cap.", effectiveLimit)
|
||||
}
|
||||
|
||||
func formatTruncationHint(effectiveLimit int) string {
|
||||
return composeTruncationHint(ui.RenderWarn, truncationHintText(effectiveLimit))
|
||||
}
|
||||
|
||||
// composeTruncationHint keeps newlines outside the renderer. lipgloss pads
|
||||
// blank lines to the widest-line width (alignTextHorizontal shortAmount =
|
||||
// widestLine - lineWidth) and drops the trailing newline (GH#5685).
|
||||
func composeTruncationHint(render func(string) string, text string) string {
|
||||
rendered := strings.TrimRight(render(text), " \t\r\n")
|
||||
return "\n" + rendered + "\n"
|
||||
}
|
||||
|
||||
func outputDotFormat(out io.Writer, issues []*types.Issue, depsByIssueID map[string][]*types.Dependency) error {
|
||||
|
|
|
|||
|
|
@ -4,9 +4,11 @@ import (
|
|||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
lipgloss "charm.land/lipgloss/v2"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
|
|
@ -167,3 +169,103 @@ func TestOutputFormattedListWithNoEdgesDoesNotWrite(t *testing.T) {
|
|||
t.Fatalf("zero-edge output made %d writes, want 0", writer.writes)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatTruncationHintExactBytes(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
got := formatTruncationHint(2)
|
||||
plain := stripANSIForTest(got)
|
||||
const want = "\nShowing 2 issues; more results matched but were hidden by --limit. Use --limit 0 for all, or --limit N to raise the cap.\n"
|
||||
if plain != want {
|
||||
t.Fatalf("truncation hint bytes differ\ngot:\n%q\nwant:\n%q", plain, want)
|
||||
}
|
||||
if !strings.HasSuffix(got, "\n") {
|
||||
t.Fatal("truncation hint missing trailing newline")
|
||||
}
|
||||
if strings.HasSuffix(got, "\n\n") {
|
||||
t.Fatal("truncation hint ended with a double newline")
|
||||
}
|
||||
assertNoWhitespaceOnlyLine(t, plain)
|
||||
|
||||
got10 := stripANSIForTest(formatTruncationHint(10))
|
||||
if !strings.Contains(got10, "Showing 10 issues;") {
|
||||
t.Fatalf("limit interpolation missing: %q", got10)
|
||||
}
|
||||
if strings.HasPrefix(got10, "\n\n") {
|
||||
t.Fatalf("leading double newline: %q", got10)
|
||||
}
|
||||
}
|
||||
|
||||
func TestComposeTruncationHintRejectsLipglossBlankLinePadding(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Empty lipgloss Style (props==0) is identity — the colorless test
|
||||
// default, and why RenderWarn("\n"+text+"\n") did not catch GH#5685.
|
||||
// Foreground sets props so alignTextHorizontal pads blank lines to
|
||||
// the widest-line width (not terminal width; no PTY required).
|
||||
style := lipgloss.NewStyle().Foreground(lipgloss.Color("3"))
|
||||
render := func(s string) string { return style.Render(s) }
|
||||
text := truncationHintText(2)
|
||||
|
||||
buggy := render("\n" + text + "\n")
|
||||
got := composeTruncationHint(render, text)
|
||||
|
||||
buggyPlain := stripANSIForTest(buggy)
|
||||
gotPlain := stripANSIForTest(got)
|
||||
|
||||
padWidth := whitespaceOnlyLineWidth(buggyPlain)
|
||||
if padWidth == 0 {
|
||||
t.Fatalf("fixture: styled Render of newline-wrapped text should pad a blank line; got %q", buggyPlain)
|
||||
}
|
||||
if padWidth != len(text) {
|
||||
t.Fatalf("lipgloss pad width = %d, want hint length %d (widest-line width, not terminal width)\nbuggy=%q", padWidth, len(text), buggyPlain)
|
||||
}
|
||||
widest := widestNonBlankLineWidth(buggyPlain)
|
||||
if padWidth != widest {
|
||||
t.Fatalf("lipgloss pad width = %d, want widest-line width %d\nbuggy=%q", padWidth, widest, buggyPlain)
|
||||
}
|
||||
|
||||
assertNoWhitespaceOnlyLine(t, gotPlain)
|
||||
if !strings.HasSuffix(got, "\n") {
|
||||
t.Fatalf("composeTruncationHint missing trailing newline: %q", got)
|
||||
}
|
||||
if strings.HasSuffix(got, "\n\n") {
|
||||
t.Fatal("composeTruncationHint ended with a double newline")
|
||||
}
|
||||
if got == buggy {
|
||||
t.Fatalf("composeTruncationHint still uses newline-inside-Render bytes:\n%q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func stripANSIForTest(s string) string {
|
||||
return regexp.MustCompile(`\x1b\[[0-9;]*m`).ReplaceAllString(s, "")
|
||||
}
|
||||
|
||||
func whitespaceOnlyLineWidth(s string) int {
|
||||
width := 0
|
||||
for _, line := range strings.Split(s, "\n") {
|
||||
if line != "" && strings.TrimSpace(line) == "" && len(line) > width {
|
||||
width = len(line)
|
||||
}
|
||||
}
|
||||
return width
|
||||
}
|
||||
|
||||
func widestNonBlankLineWidth(s string) int {
|
||||
width := 0
|
||||
for _, line := range strings.Split(s, "\n") {
|
||||
if strings.TrimSpace(line) != "" && len(line) > width {
|
||||
width = len(line)
|
||||
}
|
||||
}
|
||||
return width
|
||||
}
|
||||
|
||||
func assertNoWhitespaceOnlyLine(t *testing.T, s string) {
|
||||
t.Helper()
|
||||
for i, line := range strings.Split(s, "\n") {
|
||||
if line != "" && strings.TrimSpace(line) == "" {
|
||||
t.Fatalf("whitespace-only line at index %d (len=%d): %q", i, len(line), line)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ func runListProxiedWatch(_ *cobra.Command, ctx context.Context, in listInput) er
|
|||
if err != nil {
|
||||
return fmt.Errorf("initial query: %w", err)
|
||||
}
|
||||
displayPrettyListWithDeps(issues, true, deps, hasMore, in.ReadyFlag)
|
||||
displayPrettyListWithDeps(issues, true, deps, hasMore, in.ReadyFlag, in.Status)
|
||||
printTruncationHint(hasMore, in.effectiveLimit)
|
||||
lastSnapshot := issueSnapshot(issues)
|
||||
|
||||
|
|
@ -183,7 +183,7 @@ func runListProxiedWatch(_ *cobra.Command, ctx context.Context, in listInput) er
|
|||
snap := issueSnapshot(issues)
|
||||
if snap != lastSnapshot {
|
||||
lastSnapshot = snap
|
||||
displayPrettyListWithDeps(issues, true, deps, hasMore, in.ReadyFlag)
|
||||
displayPrettyListWithDeps(issues, true, deps, hasMore, in.ReadyFlag, in.Status)
|
||||
printTruncationHint(hasMore, in.effectiveLimit)
|
||||
fmt.Fprintf(os.Stderr, "\nWatching for changes... (Press Ctrl+C to exit)\n")
|
||||
}
|
||||
|
|
@ -239,7 +239,7 @@ func renderProxiedListText(ctx context.Context, out io.Writer, issues []*types.I
|
|||
printTruncationHint(truncated, in.effectiveLimit)
|
||||
return nil
|
||||
}
|
||||
displayPrettyListWithDepsMode(issues, false, depsByIssueID, in.depsMode, truncated, in.ReadyFlag)
|
||||
displayPrettyListWithDepsMode(issues, false, depsByIssueID, in.depsMode, truncated, in.ReadyFlag, in.Status)
|
||||
printTruncationHint(truncated, in.effectiveLimit)
|
||||
printSkipLabelsFooter(in.SkipLabels)
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ func loadWatchedIssues(ctx context.Context, store storage.DoltStorage, filter ty
|
|||
// names its scope instead of asserting an in-progress count the ready filter
|
||||
// forced to zero. A watch loop is where a stale "0 in progress" is most likely
|
||||
// to be read as a live fact, so this is the path that most needs it.
|
||||
func displayWatchedIssueList(ctx context.Context, store watchListDependencyStore, issues []*types.Issue, truncated, readyFiltered bool) {
|
||||
func displayWatchedIssueList(ctx context.Context, store watchListDependencyStore, issues []*types.Issue, truncated, readyFiltered bool, statusSelector string) {
|
||||
var allDeps map[string][]*types.Dependency
|
||||
if store != nil {
|
||||
deps, err := store.GetAllDependencyRecords(ctx)
|
||||
|
|
@ -164,7 +164,7 @@ func displayWatchedIssueList(ctx context.Context, store watchListDependencyStore
|
|||
allDeps = deps
|
||||
}
|
||||
}
|
||||
displayPrettyListWithDeps(issues, true, allDeps, truncated, readyFiltered)
|
||||
displayPrettyListWithDeps(issues, true, allDeps, truncated, readyFiltered, statusSelector)
|
||||
}
|
||||
|
||||
// watchIssues returns an error only for the initial query — a failure there
|
||||
|
|
@ -174,7 +174,7 @@ func displayWatchedIssueList(ctx context.Context, store watchListDependencyStore
|
|||
// runListCore route a MaxRows cap violation through handleMaxRowsError for
|
||||
// exit-code-2 semantics instead of watchIssues swallowing it and exiting 0
|
||||
// (be-x42v.4 follow-up, review MUST-FIX 5).
|
||||
func watchIssues(ctx context.Context, store storage.DoltStorage, filter types.IssueFilter, ready bool, parentID string, sortBy string, reverse bool, effectiveLimit int) error {
|
||||
func watchIssues(ctx context.Context, store storage.DoltStorage, filter types.IssueFilter, ready bool, parentID string, sortBy string, reverse bool, effectiveLimit int, statusSelector string) error {
|
||||
// Initial display
|
||||
issues, err := loadWatchedIssues(ctx, store, filter, ready, parentID, sortBy, reverse)
|
||||
if err != nil {
|
||||
|
|
@ -184,7 +184,7 @@ func watchIssues(ctx context.Context, store storage.DoltStorage, filter types.Is
|
|||
// below depends on; what is left is the cut and its verdict, and those are
|
||||
// the shared epilogue's on every other listing this command has.
|
||||
issues, truncated := workapi.FinishPage(issues, "", false, effectiveLimit, false)
|
||||
displayWatchedIssueList(ctx, store, issues, truncated, ready)
|
||||
displayWatchedIssueList(ctx, store, issues, truncated, ready, statusSelector)
|
||||
printTruncationHint(truncated, effectiveLimit)
|
||||
lastSnapshot := issueSnapshot(issues)
|
||||
|
||||
|
|
@ -214,7 +214,7 @@ func watchIssues(ctx context.Context, store storage.DoltStorage, filter types.Is
|
|||
snap := issueSnapshot(issues)
|
||||
if snap != lastSnapshot {
|
||||
lastSnapshot = snap
|
||||
displayWatchedIssueList(ctx, store, issues, truncated, ready)
|
||||
displayWatchedIssueList(ctx, store, issues, truncated, ready, statusSelector)
|
||||
printTruncationHint(truncated, effectiveLimit)
|
||||
fmt.Fprintf(os.Stderr, "\nWatching for changes... (Press Ctrl+C to exit)\n")
|
||||
}
|
||||
|
|
@ -256,7 +256,7 @@ func runListProxiedHierarchicalParent(ctx context.Context, uw uow.UnitOfWork, in
|
|||
}
|
||||
|
||||
// Hierarchical --parent walks use an unlimited per-level query; never page-truncated.
|
||||
displayPrettyListWithDepsMode(treeIssues, false, depsByIssueID, in.depsMode, false, in.ReadyFlag)
|
||||
displayPrettyListWithDepsMode(treeIssues, false, depsByIssueID, in.depsMode, false, in.ReadyFlag, in.Status)
|
||||
printSkipLabelsFooter(in.SkipLabels)
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,26 +147,28 @@ func printPrettyTree(childrenMap map[string][]*types.Issue, parentID string, pre
|
|||
// There is no --ready arm behind this one: it is the plain tree, so the
|
||||
// summary keeps its status breakdown.
|
||||
func displayPrettyList(issues []*types.Issue, showHeader bool) {
|
||||
displayPrettyListWithDeps(issues, showHeader, nil, false, false)
|
||||
displayPrettyListWithDeps(issues, showHeader, nil, false, false, "")
|
||||
}
|
||||
|
||||
// displayPrettyListWithDeps displays issues in tree format using dependency data.
|
||||
// readyFiltered must be threaded from the caller's --ready state rather than
|
||||
// defaulted here: the watch paths reach the summary through this wrapper, and a
|
||||
// hardcoded false silently restores the vacuous "(N open, 0 in progress)" that
|
||||
// listFooterLine exists to suppress.
|
||||
func displayPrettyListWithDeps(issues []*types.Issue, showHeader bool, allDeps map[string][]*types.Dependency, truncated, readyFiltered bool) {
|
||||
displayPrettyListWithDepsMode(issues, showHeader, allDeps, "", truncated, readyFiltered)
|
||||
// readyFiltered and statusSelector must be threaded from the caller's --ready
|
||||
// / --status state rather than defaulted here: the watch paths reach the
|
||||
// summary through this wrapper, and a hardcoded false silently restores the
|
||||
// vacuous "(N open, 0 in progress)" that listFooterLine exists to suppress.
|
||||
func displayPrettyListWithDeps(issues []*types.Issue, showHeader bool, allDeps map[string][]*types.Dependency, truncated, readyFiltered bool, statusSelector string) {
|
||||
displayPrettyListWithDepsMode(issues, showHeader, allDeps, "", truncated, readyFiltered, statusSelector)
|
||||
}
|
||||
|
||||
// listFooterLine renders the one-line summary under a text listing.
|
||||
//
|
||||
// The status breakdown is only meaningful when the query could have returned
|
||||
// more than one status. Under --ready it cannot: BuildListFilter pins
|
||||
// filter.Status to open (internal/workapi/list.go), so every row is open by
|
||||
// construction and the breakdown degenerates to a tautology — "(N open, 0 in
|
||||
// progress)" is what it prints for ANY database, including one with a thousand
|
||||
// in-progress issues matching the same label.
|
||||
// more than one status. Under --ready the query is status-pinned: the default
|
||||
// (no --status, or --status all) is still open, so "(N open, 0 in progress)"
|
||||
// is a tautology for ANY database, including one with a thousand in-progress
|
||||
// issues matching the same label. An explicit --status is the intersection
|
||||
// (GH#5832), and the same tautology applies to whatever selector was asked
|
||||
// for — the footer must name that selector rather than reuse the default-open
|
||||
// sentence.
|
||||
//
|
||||
// Printed next to a real count that number reads as a finding rather than an
|
||||
// artifact of the flag: "0 in progress" answers the question "is anything in
|
||||
|
|
@ -175,13 +177,14 @@ func displayPrettyListWithDeps(issues []*types.Issue, showHeader bool, allDeps m
|
|||
// construction, say what was excluded instead of asserting a count for it. This
|
||||
// is the same principle as the truncation arm below, which refuses to label a
|
||||
// cut-off page "Total" (GH#5362): a count is only honest alongside its scope.
|
||||
func listFooterLine(total, open, inProgress int, truncated, readyFiltered bool) string {
|
||||
func listFooterLine(total, open, inProgress int, truncated, readyFiltered bool, statusSelector string) string {
|
||||
if readyFiltered {
|
||||
// No status breakdown: --ready makes it vacuous. Name the scope instead.
|
||||
scope := readyFooterScope(statusSelector)
|
||||
if truncated {
|
||||
return fmt.Sprintf("Showing %d ready issues (open only — --ready excludes in_progress); more match (truncated by --limit). Use --limit 0 for all.", total)
|
||||
return fmt.Sprintf("Showing %d ready issues (%s); more match (truncated by --limit). Use --limit 0 for all.", total, scope)
|
||||
}
|
||||
return fmt.Sprintf("Ready: %d issues with no active blockers (open only — --ready excludes in_progress)", total)
|
||||
return fmt.Sprintf("Ready: %d issues with no active blockers (%s)", total, scope)
|
||||
}
|
||||
if truncated {
|
||||
return fmt.Sprintf("Showing %d issues (%d open, %d in progress); more match (truncated by --limit). Use --limit 0 for all.",
|
||||
|
|
@ -190,14 +193,31 @@ func listFooterLine(total, open, inProgress int, truncated, readyFiltered bool)
|
|||
return fmt.Sprintf("Total: %d issues (%d open, %d in progress)", total, open, inProgress)
|
||||
}
|
||||
|
||||
// readyFooterScope names the status pin a --ready listing actually used.
|
||||
// Empty / "all" still take the open default; an explicit selector is the
|
||||
// intersection and must not reuse "excludes in_progress" (GH#5832).
|
||||
func readyFooterScope(statusSelector string) string {
|
||||
var parts []string
|
||||
for _, part := range strings.Split(statusSelector, ",") {
|
||||
part = strings.TrimSpace(part)
|
||||
if part != "" {
|
||||
parts = append(parts, part)
|
||||
}
|
||||
}
|
||||
if len(parts) == 0 || (len(parts) == 1 && parts[0] == "all") {
|
||||
return "open only — --ready excludes in_progress"
|
||||
}
|
||||
return strings.Join(parts, ",") + " only"
|
||||
}
|
||||
|
||||
// displayPrettyListWithDepsMode displays issues in tree format. When depsMode is
|
||||
// "scheduling" or "all", the tree also annotates each node's dependency edges and
|
||||
// orders siblings by their scheduling dependencies (see orderSiblingsByDeps). An
|
||||
// empty depsMode is the plain parent-child tree. truncated means the page was cut
|
||||
// by --limit; the summary then says "Showing N" instead of "Total: N" (GH#5362).
|
||||
// readyFiltered means --ready was in force, which pins the query to open issues —
|
||||
// see listFooterLine for why the summary must say so.
|
||||
func displayPrettyListWithDepsMode(issues []*types.Issue, showHeader bool, allDeps map[string][]*types.Dependency, depsMode string, truncated, readyFiltered bool) {
|
||||
// readyFiltered means --ready was in force; statusSelector is the --status value
|
||||
// so the summary names the pin that actually applied — see listFooterLine.
|
||||
func displayPrettyListWithDepsMode(issues []*types.Issue, showHeader bool, allDeps map[string][]*types.Dependency, depsMode string, truncated, readyFiltered bool, statusSelector string) {
|
||||
if showHeader {
|
||||
// Clear screen and show header
|
||||
fmt.Print("\033[2J\033[H")
|
||||
|
|
@ -243,7 +263,7 @@ func displayPrettyListWithDepsMode(issues []*types.Issue, showHeader bool, allDe
|
|||
inProgressCount++
|
||||
}
|
||||
}
|
||||
fmt.Println(listFooterLine(len(issues), openCount, inProgressCount, truncated, readyFiltered))
|
||||
fmt.Println(listFooterLine(len(issues), openCount, inProgressCount, truncated, readyFiltered, statusSelector))
|
||||
fmt.Println()
|
||||
fmt.Println("Status: ○ open ◐ in_progress ● blocked ✓ closed ❄ deferred")
|
||||
fmt.Println("Priority: P0–P4 (label only; not a status icon)")
|
||||
|
|
|
|||
130
cmd/bd/list_wisp_type_reachability_test.go
Normal file
130
cmd/bd/list_wisp_type_reachability_test.go
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// newWispTypeInputCmd carries only the flags the --wisp-type reachability
|
||||
// check reads. gatherListInput reads many others, but GetString / GetBool on
|
||||
// an unregistered flag return zero values, so this stays minimal — the same
|
||||
// shape as newListInputTestCmd.
|
||||
func newWispTypeInputCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{Use: "list"}
|
||||
f := cmd.Flags()
|
||||
f.String("wisp-type", "", "")
|
||||
f.Bool("include-ephemeral", false, "")
|
||||
f.Bool("include-infra", false, "")
|
||||
f.StringP("type", "t", "", "")
|
||||
return cmd
|
||||
}
|
||||
|
||||
// TestListRegistersIncludeEphemeral pins the flag the guard below points at.
|
||||
//
|
||||
// It is the load-bearing half of this change: ListRequest.IncludeEphemeral is
|
||||
// the plane knob its own doc names as the combination that answers with rows,
|
||||
// and `bd list` did not register a flag for it. Without this the advice the
|
||||
// guard prints names a flag that does not exist, which is worse than the
|
||||
// silence it replaces.
|
||||
func TestListRegistersIncludeEphemeral(t *testing.T) {
|
||||
if listCmd.Flags().Lookup("include-ephemeral") == nil {
|
||||
t.Fatal("bd list must register --include-ephemeral: it is the only narrow way to admit the wisp plane, and --wisp-type's error message tells callers to use it")
|
||||
}
|
||||
}
|
||||
|
||||
// TestGatherListInput_WispTypeWithoutAPlaneIsRefused covers the request that
|
||||
// cannot match a row for ANY input: wisp_type narrows whatever the rest of the
|
||||
// request admitted, and a default listing admits only durable rows, which
|
||||
// carry no classification.
|
||||
//
|
||||
// The API layer keeps composing this to an empty page — that is its pinned
|
||||
// contract, and this does not touch it. The refusal is here, where the only
|
||||
// thing a human can have meant is the combination that returns rows.
|
||||
func TestGatherListInput_WispTypeWithoutAPlaneIsRefused(t *testing.T) {
|
||||
defer func(prev bool) { jsonOutput = prev }(jsonOutput)
|
||||
jsonOutput = false
|
||||
|
||||
cmd := newWispTypeInputCmd()
|
||||
if err := cmd.Flags().Set("wisp-type", "heartbeat"); err != nil {
|
||||
t.Fatalf("set wisp-type: %v", err)
|
||||
}
|
||||
var err error
|
||||
stderr := captureStderr(t, func() { _, err = gatherListInput(cmd) })
|
||||
if err == nil {
|
||||
t.Fatal("--wisp-type with no plane knob cannot match any row and must be refused, got nil error")
|
||||
}
|
||||
// The message has to carry the way out, or it is just a different silence.
|
||||
if !strings.Contains(stderr, "--include-ephemeral") {
|
||||
t.Errorf("the refusal must name the flag that makes the request answerable; got:\n%s", stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// TestGatherListInput_WispTypeWithAPlaneIsAccepted is the discriminating half:
|
||||
// a guard that refused everything would pass the test above on its own. Each
|
||||
// case here admits the plane by a different route, and all must survive.
|
||||
func TestGatherListInput_WispTypeWithAPlaneIsAccepted(t *testing.T) {
|
||||
defer func(prev bool) { jsonOutput = prev }(jsonOutput)
|
||||
jsonOutput = false
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
flag string
|
||||
val string
|
||||
}{
|
||||
{"the narrow plane knob", "include-ephemeral", "true"},
|
||||
{"the wider bundle that also admits it", "include-infra", "true"},
|
||||
// An explicit type is left alone: an infra type routes to the plane by
|
||||
// itself, and this layer cannot tell which types those are without the
|
||||
// workspace's infra vocabulary. Refusing here would reject a lawful,
|
||||
// answerable request.
|
||||
{"an explicit type, which may itself be infra", "type", "agent"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
cmd := newWispTypeInputCmd()
|
||||
if err := cmd.Flags().Set("wisp-type", "heartbeat"); err != nil {
|
||||
t.Fatalf("set wisp-type: %v", err)
|
||||
}
|
||||
if err := cmd.Flags().Set(tc.flag, tc.val); err != nil {
|
||||
t.Fatalf("set %s: %v", tc.flag, err)
|
||||
}
|
||||
in, err := gatherListInput(cmd)
|
||||
if err != nil {
|
||||
t.Fatalf("--wisp-type with --%s must be accepted, got: %v", tc.flag, err)
|
||||
}
|
||||
if in.WispType == nil || string(*in.WispType) != "heartbeat" {
|
||||
t.Errorf("WispType must survive onto the request, got %v", in.WispType)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestGatherListInput_IncludeEphemeralReachesTheRequest confirms the new flag
|
||||
// is wired through rather than merely registered — a flag that parses but is
|
||||
// never read would leave the plane just as unreachable.
|
||||
func TestGatherListInput_IncludeEphemeralReachesTheRequest(t *testing.T) {
|
||||
defer func(prev bool) { jsonOutput = prev }(jsonOutput)
|
||||
jsonOutput = false
|
||||
|
||||
cmd := newWispTypeInputCmd()
|
||||
if err := cmd.Flags().Set("include-ephemeral", "true"); err != nil {
|
||||
t.Fatalf("set include-ephemeral: %v", err)
|
||||
}
|
||||
in, err := gatherListInput(cmd)
|
||||
if err != nil {
|
||||
t.Fatalf("gatherListInput: %v", err)
|
||||
}
|
||||
if !in.IncludeEphemeral {
|
||||
t.Error("--include-ephemeral must set ListRequest.IncludeEphemeral, got false")
|
||||
}
|
||||
|
||||
// And the default stays off, so the durable-only listing is unchanged.
|
||||
bare, err := gatherListInput(newWispTypeInputCmd())
|
||||
if err != nil {
|
||||
t.Fatalf("gatherListInput (bare): %v", err)
|
||||
}
|
||||
if bare.IncludeEphemeral {
|
||||
t.Error("IncludeEphemeral must default to false; the default listing is durable-only")
|
||||
}
|
||||
}
|
||||
|
|
@ -229,13 +229,6 @@ func effectiveRootStorePolicy(cmdName string, strictReadonly bool) rootStorePoli
|
|||
}
|
||||
}
|
||||
|
||||
// backendSupportsStrictReadonly reports whether the live backend path can open
|
||||
// without provisioning or lifecycle changes. Unsupported SQL backends are
|
||||
// rejected earlier by validateConfiguredBackend; proxied Dolt remains writable-only.
|
||||
func backendSupportsStrictReadonly(cfg *configfile.Config) bool {
|
||||
return cfg == nil || !cfg.IsDoltProxiedServerMode()
|
||||
}
|
||||
|
||||
// runsPostCommandMaintenance reports whether PersistentPostRunE should run the
|
||||
// post-command maintenance net — Dolt auto-commit, the tip-metadata commit,
|
||||
// auto-backup, auto-export and auto-push.
|
||||
|
|
@ -324,6 +317,30 @@ func isWorkingSetReconcileCommand(cmd *cobra.Command) bool {
|
|||
return parent.Name() == "dolt" || parent.Name() == "vc"
|
||||
}
|
||||
|
||||
// isRemoteSyncCommand reports whether cmd is `bd dolt pull`: the one command
|
||||
// the #6575 data-behind migrate-gate refusal tells the operator to run.
|
||||
//
|
||||
// It is the same deadlock isWorkingSetReconcileCommand breaks for #4566, one
|
||||
// refusal over. The gate stops a data-behind clone from migrating and names
|
||||
// `bd dolt pull` as the remedy — but the pull opens the store too, so it hit
|
||||
// that refusal before it could clear its cause. On an embedded clone there is
|
||||
// no external `dolt` binary to fall back to, which left the refused clone with
|
||||
// exactly one exit: BD_ALLOW_REMOTE_MIGRATE=1, i.e. performing the migration
|
||||
// the refusal exists to prevent. Opening via embeddeddolt.OpenForRemoteSync /
|
||||
// dolt.Config.RemoteSyncOpen tolerates that ONE gate reason and nothing else.
|
||||
//
|
||||
// Deliberately just the pull, not `bd sync`: sync also pushes and can write
|
||||
// issue rows, and a write against a stale schema is the hazard the gate is
|
||||
// about. The pull only moves the commit graph, which is precisely the
|
||||
// precondition the refusal is waiting on.
|
||||
func isRemoteSyncCommand(cmd *cobra.Command) bool {
|
||||
if cmd.Name() != "pull" {
|
||||
return false
|
||||
}
|
||||
parent := cmd.Parent()
|
||||
return parent != nil && parent.Name() == "dolt"
|
||||
}
|
||||
|
||||
// isForcedMigrate reports whether cmd is `bd migrate` or `bd migrate schema`
|
||||
// invoked with --force: the operator confirming they are the single designated
|
||||
// migrator, so the remote-migrate gate (#4259) must not block this run's store
|
||||
|
|
@ -343,15 +360,27 @@ func isForcedMigrate(cmd *cobra.Command) bool {
|
|||
// open targets `beads_global`, so the block's `bd migrate schema` would
|
||||
// migrate the PROJECT database and leave the refusal in place — the working
|
||||
// remedy is the same verb with the same flag.
|
||||
func printGlobalDatabaseConsentHint(w io.Writer) {
|
||||
//
|
||||
// It takes the refusal because "the same verb" is not the same verb on every
|
||||
// arm: the #6575 data-behind stop on a shared store is remote-backed by
|
||||
// construction, and there the bare verb's consent is never read (see
|
||||
// schema.SharedConsentCommandForced), so retargeting the bare form would hand
|
||||
// the operator a global-scoped command that still cannot succeed. This mirrors
|
||||
// the retarget in handleRemoteMigrateGateJSON. A nil error keeps the
|
||||
// pre-existing bare-verb wording.
|
||||
func printGlobalDatabaseConsentHint(w io.Writer, e *schema.RemoteMigrateGateError) {
|
||||
if !globalFlag {
|
||||
return
|
||||
}
|
||||
consent := schema.SharedConsentCommandGlobal
|
||||
if e != nil && e.IsDataBehind() && e.Shared {
|
||||
consent = schema.SharedConsentCommandForcedGlobal
|
||||
}
|
||||
fmt.Fprintf(w,
|
||||
"\n This command targeted the global database (--global), so run the\n"+
|
||||
" migrate step with the same flag:\n"+
|
||||
" %s\n",
|
||||
schema.SharedConsentCommandGlobal)
|
||||
consent)
|
||||
}
|
||||
|
||||
// renderTypedOpenError prints the actionable block for the store-open failures
|
||||
|
|
@ -381,7 +410,7 @@ func renderTypedOpenError(err error) bool {
|
|||
handleRemoteMigrateGateJSON(gateErr)
|
||||
} else {
|
||||
fmt.Fprint(os.Stderr, gateErr.UserMessage())
|
||||
printGlobalDatabaseConsentHint(os.Stderr)
|
||||
printGlobalDatabaseConsentHint(os.Stderr, gateErr)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
@ -850,7 +879,7 @@ func init() {
|
|||
rootCmd.PersistentFlags().BoolVar(&sandboxMode, "sandbox", false, "Sandbox mode: disables Dolt auto-push")
|
||||
rootCmd.PersistentFlags().BoolVar(&readonlyMode, "readonly", false, "Read-only mode: block write operations (for worker sandboxes)")
|
||||
rootCmd.PersistentFlags().BoolVar(&globalFlag, "global", false, "Use the global shared-server database (beads_global)")
|
||||
rootCmd.PersistentFlags().StringVar(&doltAutoCommit, "dolt-auto-commit", "", "Dolt auto-commit policy (off|on|batch). 'on': commit after each write. 'batch': defer commits to bd dolt commit; uncommitted changes persist in the working set until then (a live batch-mode bd process also flushes on SIGTERM/SIGHUP). Applies to embedded and direct SQL-server modes; proxied-server routes are unaffected. Default: on. Override via config key dolt.auto-commit")
|
||||
rootCmd.PersistentFlags().StringVar(&doltAutoCommit, "dolt-auto-commit", "", "Dolt auto-commit policy (off|on|batch). 'on': commit after each write. 'batch': defer commits to bd dolt commit; uncommitted changes persist in the working set until then (a live batch-mode bd process also flushes on SIGTERM/SIGHUP, except in proxied-server mode, where bd dolt commit is the only flush point). In proxied-server mode the deferral covers the writes the CLI makes on that route, including config and version metadata; explicit commit points (bd batch, bd mol bond/pour/squash, bd mol wisp create, and the wisp half of bd mol burn) still commit, and a bd serve process on the same database is unaffected. Default: on. Override via config key dolt.auto-commit")
|
||||
rootCmd.PersistentFlags().BoolVar(&cpuProfileEnabled, "cpu-profile", false, "Generate CPU profile for performance analysis")
|
||||
rootCmd.PersistentFlags().StringVar(&memProfilePath, "mem-profile", "", "Write heap profile to FILE on exit (also respects BEADS_MEM_PROFILE)")
|
||||
rootCmd.PersistentFlags().BoolVarP(&verboseFlag, "verbose", "v", false, "Enable verbose/debug output")
|
||||
|
|
@ -1256,18 +1285,18 @@ var rootCmd = &cobra.Command{
|
|||
fmt.Fprintf(os.Stderr, "warning: %v\n", err)
|
||||
}
|
||||
}
|
||||
if beadsDir == "" {
|
||||
beadsDir = beads.FindBeadsDir()
|
||||
}
|
||||
if cmdName == "doctor" && usesProxiedServer() {
|
||||
// Refuse only on a real refusal. validateProxyMaintenance...
|
||||
// Refuse only on a real refusal. The registry validator
|
||||
// returns nil for doctor subcommands, and returning early on
|
||||
// that would skip the legacy-store guard and autocommit-mode
|
||||
// resolution every other skipsStoreInit command still runs.
|
||||
if err := validateProxyMaintenanceBeforeProvider(cmd); err != nil {
|
||||
if err := validateProxyRegistryBeforeProvider(cmd, resolveProxiedTopology(beadsDir)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if beadsDir == "" {
|
||||
beadsDir = beads.FindBeadsDir()
|
||||
}
|
||||
if err := guardLegacyNoStoreCommand(cmd, beadsDir); err != nil {
|
||||
isMigrationCommand := false
|
||||
for current := cmd; current != nil; current = current.Parent() {
|
||||
|
|
@ -1414,6 +1443,11 @@ var rootCmd = &cobra.Command{
|
|||
// would create a local database instead of using the redirect target.
|
||||
// (GH#bd-0qel)
|
||||
targetBeadsDir := beads.FindBeadsDir()
|
||||
if targetBeadsDir == "" {
|
||||
// An explicit BEADS_DIR is authoritative even
|
||||
// before it holds project files.
|
||||
targetBeadsDir = beads.ExplicitBeadsDir()
|
||||
}
|
||||
if targetBeadsDir == "" {
|
||||
targetBeadsDir = ".beads"
|
||||
}
|
||||
|
|
@ -1468,14 +1502,13 @@ var rootCmd = &cobra.Command{
|
|||
}
|
||||
// Reject proxy capability combinations before any workspace side effect
|
||||
// (version tracking, migration, auto-start, or provider construction).
|
||||
// Two validators, one for each half of the policy: flag-keyed rules and
|
||||
// the path-keyed capability registry.
|
||||
if cfg != nil && cfg.IsDoltProxiedServerMode() {
|
||||
if err := validateProxyCapabilitiesBeforeProvider(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateProxyMaintenanceBeforeProvider(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateProxyTransformBeforeProvider(cmd); err != nil {
|
||||
if err := validateProxyRegistryBeforeProvider(cmd, resolveProxiedTopology(beadsDir)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -1486,9 +1519,6 @@ var rootCmd = &cobra.Command{
|
|||
if readonlyMode && cfg != nil && cfg.IsDoltProxiedServerMode() {
|
||||
return HandleProxyCapabilityError(AssertProxyCapability(ProxyModeProxied, ProxyCapReadonly))
|
||||
}
|
||||
if readonlyMode && !backendSupportsStrictReadonly(cfg) {
|
||||
return HandleError("strict readonly is unavailable for dolt proxied-server backend; refusing to open a store that cannot guarantee mutation-free access")
|
||||
}
|
||||
|
||||
// Set actor for audit trail
|
||||
actor = getActorWithGit()
|
||||
|
|
@ -1622,6 +1652,7 @@ var rootCmd = &cobra.Command{
|
|||
DisableAutoStart: policy.disableAutoStart,
|
||||
BeadsDir: beadsDir,
|
||||
LenientOpen: isWorkingSetReconcileCommand(cmd),
|
||||
RemoteSyncOpen: isRemoteSyncCommand(cmd),
|
||||
}
|
||||
|
||||
// Load config to get database name and server connection settings.
|
||||
|
|
@ -1781,6 +1812,16 @@ var rootCmd = &cobra.Command{
|
|||
}
|
||||
uowProvider = uow.NewNotifyingProvider(p, uowSinks)
|
||||
|
||||
// Honor dolt.auto-commit for proxied writes the same way
|
||||
// issueOpsContext already does for the direct/SQL-server routes
|
||||
// (bd-4wamg): batch/off defer the Dolt version commit rather than
|
||||
// minting one per write (GH#4995). uow.issueOperations reads this
|
||||
// off the context for every Create/Update/Close/Reopen it runs.
|
||||
rootCtx, err = issueOpsContext(rootCtx)
|
||||
if err != nil {
|
||||
return HandleError("failed to resolve dolt auto-commit policy: %v", err)
|
||||
}
|
||||
|
||||
if !previewMode {
|
||||
reconcileVersionProxiedServer(rootCtx)
|
||||
}
|
||||
|
|
@ -1964,6 +2005,15 @@ var rootCmd = &cobra.Command{
|
|||
if shouldAutoPruneEventsJournal(cmd) {
|
||||
maybeAutoPruneEventsJournal(rootCtx, beads.FindBeadsDir())
|
||||
}
|
||||
// Auto-backup, through the provider this command opened. Same
|
||||
// gate as the direct arm's maintenance net below (strict
|
||||
// --readonly, `bd serve` and a migration freeze all skip it),
|
||||
// plus previews: a --dry-run must not register a backup remote
|
||||
// or write backup state. proxiedAutoBackupBackend decides the
|
||||
// topology, so this stays inert off managed-local.
|
||||
if runsPostCommandMaintenance(cmd.Name(), readonlyMode) && !isPreviewCommand(cmd) && !commandFreeze.Frozen() {
|
||||
runPostRunAutoBackup(rootCtx)
|
||||
}
|
||||
if uowProvider != nil {
|
||||
_ = uowProvider.Close(rootCtx)
|
||||
uowProvider = nil
|
||||
|
|
|
|||
|
|
@ -154,6 +154,38 @@ Just a title and description.
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "GH-4643 H2-per-section briefing file parses as three issues",
|
||||
content: `## Problem
|
||||
Something is broken.
|
||||
|
||||
## Context
|
||||
Extra background.
|
||||
|
||||
## Acceptance Criteria
|
||||
It should work.
|
||||
`,
|
||||
expected: []*IssueTemplate{
|
||||
{
|
||||
Title: "Problem",
|
||||
Description: "Something is broken.",
|
||||
Priority: 2,
|
||||
IssueType: "task",
|
||||
},
|
||||
{
|
||||
Title: "Context",
|
||||
Description: "Extra background.",
|
||||
Priority: 2,
|
||||
IssueType: "task",
|
||||
},
|
||||
{
|
||||
Title: "Acceptance Criteria",
|
||||
Description: "It should work.",
|
||||
Priority: 2,
|
||||
IssueType: "task",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
|
|||
|
|
@ -199,12 +199,17 @@ func migrateFault(phase migratePhase) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// externalMigrationRefusal is a policy refusal rather than a registry row: it
|
||||
// depends on the workspace's endpoint, not on which command was typed. The
|
||||
// reason is design because someone else owns that endpoint and its schema —
|
||||
// no amount of plumbing on this side makes migrating it bd's business.
|
||||
func externalMigrationRefusal(message string) error {
|
||||
return HandleProxyCapabilityError(&ProxyCapabilityError{
|
||||
Code: "proxy.migrate.external_endpoint",
|
||||
Message: message,
|
||||
ExitCode: 1,
|
||||
Mutates: false,
|
||||
Reason: ProxyReasonDesign,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ func runPourProxiedServer(ctx context.Context, in pourInput) error {
|
|||
if uowProvider == nil {
|
||||
return HandleError("proxied-server UOW provider not initialized")
|
||||
}
|
||||
// Explicit commit point, like the `transact` in cloneSubgraph the direct
|
||||
// route reaches through spawnMolecule (GH#4995).
|
||||
ctx = explicitCommitPointContext(ctx)
|
||||
|
||||
vars, err := parseVarFlags(in.varFlags)
|
||||
if err != nil {
|
||||
|
|
@ -372,6 +375,9 @@ func runMolBondProxiedServer(ctx context.Context, in molBondInput) error {
|
|||
if uowProvider == nil {
|
||||
return HandleErrorRespectJSON("proxied-server UOW provider not initialized")
|
||||
}
|
||||
// Explicit commit point, like `transact` in bondProtoMol/bondMolecules on
|
||||
// the direct route (GH#4995).
|
||||
ctx = explicitCommitPointContext(ctx)
|
||||
|
||||
if in.dryRun {
|
||||
uw, err := proxiedOpenReadUOW(ctx)
|
||||
|
|
@ -446,6 +452,9 @@ func runMolSquashProxiedServer(ctx context.Context, in molSquashInput) error {
|
|||
if uowProvider == nil {
|
||||
return HandleErrorRespectJSON("proxied-server UOW provider not initialized")
|
||||
}
|
||||
// Explicit commit point, like `transact` in runMolSquash on the direct
|
||||
// route (GH#4995).
|
||||
ctx = explicitCommitPointContext(ctx)
|
||||
|
||||
if in.dryRun {
|
||||
uw, err := proxiedOpenReadUOW(ctx)
|
||||
|
|
@ -516,6 +525,15 @@ func runMolBurnProxiedServer(ctx context.Context, args []string, dryRun, force b
|
|||
if uowProvider == nil {
|
||||
return HandleErrorRespectJSON("proxied-server UOW provider not initialized")
|
||||
}
|
||||
// Only the wisp half is an explicit commit point, so the exemption is
|
||||
// applied per commit site below rather than to this ctx (GH#4995).
|
||||
// runMolBurn splits on the direct route: wisps go through burnWisps ->
|
||||
// `transact`, which mints the commit whatever dolt.auto-commit says, while
|
||||
// persistent molecules go through deleteBatch -> issueOpsContext, the
|
||||
// policy-honoring class — dolt's deleter returns before DOLT_COMMIT when
|
||||
// that context defers. Exempting the whole command would mint one commit
|
||||
// per persistent molecule under batch/off, on a destructive verb, where the
|
||||
// identical direct-route command defers them all to `bd dolt commit`.
|
||||
|
||||
uw, err := proxiedOpenReadUOW(ctx)
|
||||
if err != nil {
|
||||
|
|
@ -617,7 +635,8 @@ func runMolBurnProxiedServer(ctx context.Context, args []string, dryRun, force b
|
|||
}
|
||||
|
||||
if len(wispIDs) > 0 {
|
||||
result, err := uow.RunTxResult(ctx, uowProvider, func(ctx context.Context, uw uow.UnitOfWork) (*BurnResult, string, error) {
|
||||
// The wisp half's direct twin is burnWisps -> `transact`.
|
||||
result, err := uow.RunTxResult(explicitCommitPointContext(ctx), uowProvider, func(ctx context.Context, uw uow.UnitOfWork) (*BurnResult, string, error) {
|
||||
r, err := burnWispsInto(ctx, newUOWMolWriter(uw), wispIDs, actor)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
|
|
@ -635,6 +654,10 @@ func runMolBurnProxiedServer(ctx context.Context, args []string, dryRun, force b
|
|||
}
|
||||
|
||||
for _, id := range persistentIDs {
|
||||
// No exemption: the persistent half's direct twin is deleteBatch ->
|
||||
// issueOpsContext, so this stays on the inherited policy context and
|
||||
// the message is blanked under batch/off, exactly as the direct route
|
||||
// leaves these deletions in the working set for `bd dolt commit`.
|
||||
result, err := uow.RunTxResult(ctx, uowProvider, func(ctx context.Context, uw uow.UnitOfWork) (BurnResult, string, error) {
|
||||
subgraph, err := loadTemplateSubgraph(ctx, newUOWMolWriter(uw), id)
|
||||
if err != nil {
|
||||
|
|
|
|||
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