Merge release/1.3.0 into main (post-tag forward-port)
Forward-ports the 38 commits that shipped on release/1.3.0 (tagged v1.3.0 at
f45b249ce) into main, as RELEASING.md mandates after a tag. None of them had
ever been forward-ported. Recorded as a merge so main becomes a superset of
the release branch and the lineage is in the history.
Migration ordinal collision (the reason this needed a human-shaped merge):
both branches independently claimed clone-local ignored slot 0026 under
different filenames, so git merged both in with no conflict and left the
series with two migrations at ordinal 26 — a single-integer cursor cannot
address that, and migrationSource.list() panics on it.
Main's ignored/0026_add_wisps_current_revision is renumbered to 0027.
Release's 0026_dep_rekey_dedup_marker is in the shipped v1.3.0 tag, so field
stores have already recorded it at 26 and it can never move; main's twin has
never shipped in any release, so it is the one that is free to move. 0027 was
unused in the ignored series (both sides topped out at 26).
This trips check-migration-hygiene.sh Check C (frozen migrations), which has
no exemption mechanism. That is expected and accepted: breaking the collision
requires a rename, and the ignored series' cursor table is itself dolt-ignored,
so its content hashes are clone-local and never participate in the cross-clone
ContentHashSkew comparison that Check C exists to protect. Main's 0067 body is
deliberately NOT edited for the same reason in reverse — it is main-plane and
its hash IS compared across clones.
Conflicts resolved:
CHANGELOG.md release's finalized [1.3.0] section kept
byte-identical; main's two unreleased
entries (#6023, #5859) moved up under
[Unreleased] where they belong
cmd/bd/init_safety.go union — release's added paragraph is
cmd/bd/init_safety_help.go accurate against the merged code (three
exit-12 sources, incl. init.go:3147)
internal/storage/uow/dolt_sql_provider.go
kept main's newProvider refactor AND
release's readOnly field/assertion;
newProvider gained readOnly: opts.readOnly
so release's read-through-refused-migration
behavior survives main's refactor
.github/workflows/main.yml single -timeout=30m per release's #6091
scripts/ci_workflow_test.go design (flag on the invocation, not in
matrix.test-flags); the shadowed 25m in
matrix.test-flags removed
scripts/migration-test/lib/versions.sh
union — main's darwin/arm64 corpus plus
release's v1.2.2 linux/amd64 entry
integrations/beads-mcp/uv.lock ruff 0.16.5 (release, newer); block is
internally consistent, uv lock --check ok
default.nix vendorHash left at main's value and is
KNOWN STALE — see below
Version stamp lands at 1.3.0 (main had been sitting at the previously-released
1.2.2, this project's between-releases pattern). check-versions.sh: 24/24.
Known follow-up: default.nix vendorHash. The merged go.mod/go.sum is a genuine
union (release's kin-openapi/oapi-codegen bumps + main's newer Dolt stack) and
matches neither side, so neither recorded hash is correct. It must be
regenerated with scripts/update-nix-vendorhash.sh. The repo's automatic fixer
(update-vendor-hash.yml) is dependabot-only and will not run on this PR.
This commit is contained in:
commit
b3d17caa6d
339 changed files with 30937 additions and 3307 deletions
|
|
@ -134,6 +134,20 @@ needs = ["preflight-git"]
|
|||
description = """
|
||||
Ensure we're up to date with origin and branch is properly synced.
|
||||
|
||||
**Every `origin/...` below means the branch you are RELEASING FROM, which is
|
||||
`release/x.y.z` — never `main`.** Resetting a release branch onto main's tip
|
||||
destroys the reviewed release-prep commit and leaves you tagging an untested
|
||||
main SHA, which is exactly the failure the release-branch policy exists to
|
||||
prevent. Pin the name first and use the variable:
|
||||
|
||||
```bash
|
||||
# The branch you are releasing from. For a prerelease this is still the BASE
|
||||
# version's branch: an RC for 1.3.0 is cut on release/1.3.0.
|
||||
REL_BRANCH="release/1.3.0"
|
||||
|
||||
git rev-parse --abbrev-ref HEAD # must equal $REL_BRANCH
|
||||
```
|
||||
|
||||
```bash
|
||||
# Fetch latest from origin
|
||||
git fetch origin
|
||||
|
|
@ -155,21 +169,20 @@ git pull --rebase
|
|||
Recovering from divergence:
|
||||
If your branch has diverged from origin (e.g., after a botched commit):
|
||||
```bash
|
||||
# Option 1: Reset to origin (loses local commits)
|
||||
git reset --hard origin/main
|
||||
|
||||
# Option 2: Rebase local commits on top of origin
|
||||
git rebase origin/main
|
||||
|
||||
# Option 3: Create a backup branch first
|
||||
# Option 1: Back up first, ALWAYS
|
||||
git branch backup-before-release
|
||||
git reset --hard origin/main
|
||||
|
||||
# Option 2: Reset to the release branch's origin (loses local commits)
|
||||
git reset --hard "origin/$REL_BRANCH"
|
||||
|
||||
# Option 3: Rebase local commits on top of it
|
||||
git rebase "origin/$REL_BRANCH"
|
||||
```
|
||||
|
||||
After pulling, verify sync:
|
||||
```bash
|
||||
git status -sb
|
||||
# Should show: "## main...origin/main" (no ahead/behind)
|
||||
# Should show: "## release/1.3.0...origin/release/1.3.0" (no ahead/behind)
|
||||
```
|
||||
"""
|
||||
|
||||
|
|
@ -326,158 +339,68 @@ Focus on workflow-impacting changes agents need to know.
|
|||
"""
|
||||
|
||||
[[steps]]
|
||||
id = "bump-version-go"
|
||||
title = "Bump version in version.go"
|
||||
id = "bump-versions"
|
||||
title = "Bump every version reference"
|
||||
needs = ["update-info-go"]
|
||||
description = """
|
||||
Update the Go version constant.
|
||||
Run the one script that owns every version reference.
|
||||
|
||||
```bash
|
||||
# macOS
|
||||
sed -i '' 's/Version = "[^"]*"/Version = "{{version}}"/' cmd/bd/version.go
|
||||
|
||||
# Linux
|
||||
sed -i 's/Version = "[^"]*"/Version = "{{version}}"/' cmd/bd/version.go
|
||||
./scripts/update-versions.sh {{version}}
|
||||
```
|
||||
|
||||
This is the ONLY sanctioned way to bump. Hand-rolled sed per file is how the
|
||||
set drifts: this formula used to carry its own copies and pointed at a
|
||||
`claude-plugin/` path that has not existed since the plugins moved under
|
||||
`plugins/beads/`, while missing the copilot plugin, the MCP lockfile and the
|
||||
tracked git-hook markers entirely — so it would have failed outright, or
|
||||
shipped inconsistent versions, on every step after the stale path.
|
||||
|
||||
`scripts/update-versions.sh` rewrites, in one pass:
|
||||
|
||||
- `cmd/bd/version.go` — the canonical version everything else is compared to
|
||||
- `plugins/beads/.claude-plugin/plugin.json`
|
||||
- `plugins/beads/.codex-plugin/plugin.json`
|
||||
- `plugins/beads/.copilot-plugin/plugin.json`
|
||||
- `.claude-plugin/marketplace.json`
|
||||
- `integrations/beads-mcp/pyproject.toml`
|
||||
- `integrations/beads-mcp/src/beads_mcp/__init__.py`
|
||||
- `integrations/beads-mcp/uv.lock` — via `uv lock`
|
||||
- `npm-package/package.json`
|
||||
- `.githooks/*` — the `BEGIN`/`END BEADS INTEGRATION v<version>` markers
|
||||
- `default.nix`
|
||||
- `cmd/bd/winres/winres.json`, `cmd/bd/winres/manifest.xml`
|
||||
- `README.md` — the static Alpha badge, if one is present (it is not today;
|
||||
README uses live npm/PyPI/GitHub badges)
|
||||
|
||||
Two of those have burned a release before, so check the script's output rather
|
||||
than assuming:
|
||||
|
||||
- **`uv` must be installed.** Without it the script WARNS and leaves
|
||||
`uv.lock` stale. The release workflow's MCP gate runs `uv sync --locked`,
|
||||
which fails only in the tag-triggered run — after the tag exists and can no
|
||||
longer be rewritten. That burned v1.1.1 and cost v1.1.0 and v1.1.2 their
|
||||
first runs. If you see `uv not found` or `uv lock failed`, stop and fix it:
|
||||
```bash
|
||||
uv lock --directory integrations/beads-mcp
|
||||
```
|
||||
- **The `.githooks/*` markers are rewritten wholesale**, not matched against
|
||||
the current version, because they can already be drifted when the bump runs
|
||||
(they still said v1.1.0 during the v1.2.0 bump).
|
||||
|
||||
Not covered here, by design: `CHANGELOG.md` and `cmd/bd/info.go` (earlier
|
||||
steps), and `default.nix`'s `vendorHash` (next step).
|
||||
|
||||
Verify:
|
||||
```bash
|
||||
grep 'Version = ' cmd/bd/version.go
|
||||
```
|
||||
"""
|
||||
|
||||
[[steps]]
|
||||
id = "bump-plugin-json"
|
||||
title = "Bump version in plugin JSON files"
|
||||
needs = ["bump-version-go"]
|
||||
description = """
|
||||
Update Claude plugin manifest versions.
|
||||
|
||||
```bash
|
||||
# macOS/Linux with jq
|
||||
jq '.version = "{{version}}"' claude-plugin/.claude-plugin/plugin.json > tmp && mv tmp claude-plugin/.claude-plugin/plugin.json
|
||||
jq '.plugins[0].version = "{{version}}"' .claude-plugin/marketplace.json > tmp && mv tmp .claude-plugin/marketplace.json
|
||||
```
|
||||
|
||||
Verify:
|
||||
```bash
|
||||
jq -r '.version' claude-plugin/.claude-plugin/plugin.json
|
||||
jq -r '.plugins[0].version' .claude-plugin/marketplace.json
|
||||
```
|
||||
"""
|
||||
|
||||
[[steps]]
|
||||
id = "bump-mcp-python"
|
||||
title = "Bump version in MCP Python package"
|
||||
needs = ["bump-plugin-json"]
|
||||
description = """
|
||||
Update the beads-mcp Python package version.
|
||||
|
||||
```bash
|
||||
# macOS
|
||||
sed -i '' 's/version = "[^"]*"/version = "{{version}}"/' integrations/beads-mcp/pyproject.toml
|
||||
sed -i '' 's/__version__ = "[^"]*"/__version__ = "{{version}}"/' integrations/beads-mcp/src/beads_mcp/__init__.py
|
||||
|
||||
# Linux
|
||||
sed -i 's/version = "[^"]*"/version = "{{version}}"/' integrations/beads-mcp/pyproject.toml
|
||||
sed -i 's/__version__ = "[^"]*"/__version__ = "{{version}}"/' integrations/beads-mcp/src/beads_mcp/__init__.py
|
||||
```
|
||||
|
||||
Verify:
|
||||
```bash
|
||||
grep 'version = ' integrations/beads-mcp/pyproject.toml | head -1
|
||||
grep '__version__ = ' integrations/beads-mcp/src/beads_mcp/__init__.py
|
||||
```
|
||||
"""
|
||||
|
||||
[[steps]]
|
||||
id = "bump-npm-package"
|
||||
title = "Bump version in npm package"
|
||||
needs = ["bump-mcp-python"]
|
||||
description = """
|
||||
Update the npm package version.
|
||||
|
||||
```bash
|
||||
# macOS/Linux with jq
|
||||
jq '.version = "{{version}}"' npm-package/package.json > tmp && mv tmp npm-package/package.json
|
||||
```
|
||||
|
||||
Verify:
|
||||
```bash
|
||||
jq -r '.version' npm-package/package.json
|
||||
```
|
||||
"""
|
||||
|
||||
[[steps]]
|
||||
id = "bump-winres"
|
||||
title = "Bump version in Windows resource metadata"
|
||||
needs = ["bump-npm-package"]
|
||||
description = """
|
||||
Update Windows PE resource metadata.
|
||||
|
||||
```bash
|
||||
# macOS
|
||||
sed -i '' 's/"file_version": "[^"]*"/"file_version": "{{version}}"/' cmd/bd/winres/winres.json
|
||||
sed -i '' 's/"product_version": "[^"]*"/"product_version": "{{version}}"/' cmd/bd/winres/winres.json
|
||||
sed -i '' 's/"FileVersion": "[^"]*"/"FileVersion": "{{version}}"/' cmd/bd/winres/winres.json
|
||||
sed -i '' 's/"ProductVersion": "[^"]*"/"ProductVersion": "{{version}}"/' cmd/bd/winres/winres.json
|
||||
sed -i '' 's/version="[0-9][^"]*\\.0"/version="{{version}}.0"/' cmd/bd/winres/manifest.xml
|
||||
|
||||
# Linux
|
||||
sed -i 's/"file_version": "[^"]*"/"file_version": "{{version}}"/' cmd/bd/winres/winres.json
|
||||
sed -i 's/"product_version": "[^"]*"/"product_version": "{{version}}"/' cmd/bd/winres/winres.json
|
||||
sed -i 's/"FileVersion": "[^"]*"/"FileVersion": "{{version}}"/' cmd/bd/winres/winres.json
|
||||
sed -i 's/"ProductVersion": "[^"]*"/"ProductVersion": "{{version}}"/' cmd/bd/winres/winres.json
|
||||
sed -i 's/version="[0-9][^"]*\\.0"/version="{{version}}.0"/' cmd/bd/winres/manifest.xml
|
||||
```
|
||||
|
||||
Verify:
|
||||
```bash
|
||||
grep '{{version}}' cmd/bd/winres/winres.json
|
||||
grep 'version="{{version}}.0"' cmd/bd/winres/manifest.xml
|
||||
```
|
||||
"""
|
||||
|
||||
[[steps]]
|
||||
id = "bump-readme"
|
||||
title = "Check README static version references"
|
||||
needs = ["bump-winres"]
|
||||
description = """
|
||||
README.md currently uses live npm/PyPI/GitHub release badges instead of a static
|
||||
Alpha version string. Verify no old static version badge needs updating.
|
||||
|
||||
```bash
|
||||
rg 'Alpha \\(v|v[0-9]+\\.[0-9]+\\.[0-9]+' README.md || true
|
||||
```
|
||||
|
||||
If a static release reference is reintroduced later, update it here.
|
||||
"""
|
||||
|
||||
[[steps]]
|
||||
id = "bump-default-nix"
|
||||
title = "Bump version in default.nix"
|
||||
needs = ["bump-readme"]
|
||||
description = """
|
||||
Update the Nix package version.
|
||||
|
||||
```bash
|
||||
# macOS
|
||||
sed -i '' 's/version = "[^"]*";/version = "{{version}}";/' default.nix
|
||||
|
||||
# Linux
|
||||
sed -i 's/version = "[^"]*";/version = "{{version}}";/' default.nix
|
||||
```
|
||||
|
||||
Verify:
|
||||
```bash
|
||||
grep 'version = ' default.nix
|
||||
git diff --stat
|
||||
```
|
||||
"""
|
||||
|
||||
[[steps]]
|
||||
id = "update-vendorhash"
|
||||
title = "Update Nix vendorHash if needed"
|
||||
needs = ["bump-default-nix"]
|
||||
needs = ["bump-versions"]
|
||||
description = """
|
||||
Update vendorHash if go.mod/go.sum changed since last release.
|
||||
|
||||
|
|
@ -533,21 +456,45 @@ id = "verify-versions"
|
|||
title = "Verify version consistency"
|
||||
needs = ["stamp-changelog"]
|
||||
description = """
|
||||
Confirm all versions match {{version}}.
|
||||
Run the gate, not a hand-listed grep pile — the grep list is what drifts.
|
||||
|
||||
```bash
|
||||
grep 'Version = ' cmd/bd/version.go
|
||||
jq -r '.version' claude-plugin/.claude-plugin/plugin.json
|
||||
jq -r '.plugins[0].version' .claude-plugin/marketplace.json
|
||||
jq -r '.version' npm-package/package.json
|
||||
grep 'version = ' integrations/beads-mcp/pyproject.toml
|
||||
grep '__version__ = ' integrations/beads-mcp/src/beads_mcp/__init__.py
|
||||
grep 'version = ' default.nix
|
||||
grep '{{version}}' cmd/bd/winres/winres.json
|
||||
grep 'version="{{version}}.0"' cmd/bd/winres/manifest.xml
|
||||
./scripts/check-versions.sh
|
||||
```
|
||||
|
||||
All should show {{version}}.
|
||||
`scripts/check-versions.sh` reads the canonical version out of
|
||||
`cmd/bd/version.go` and compares the gated files against it: all three plugin
|
||||
manifests (claude, codex, copilot), the marketplace, the MCP pyproject /
|
||||
`__init__.py` / `uv.lock` pin (plus `uv lock --check` for freshness when `uv`
|
||||
is present), the npm package, both `BEADS INTEGRATION` markers in every
|
||||
`.githooks/*` file, and the Windows PE metadata in `winres.json` and
|
||||
`manifest.xml`. It exits non-zero on any mismatch and names the file. This is
|
||||
the same script the release-tag pre-push hook and CI run, so a green run here
|
||||
is the real signal.
|
||||
|
||||
It must print `✓ Version files in sync at: {{version}}` before you continue.
|
||||
|
||||
**If it fails, do NOT just re-run the bump — that is a no-op here.**
|
||||
`update-versions.sh` derives the OLD version from `cmd/bd/version.go`, which by
|
||||
this point already reads `{{version}}`, so its substitutions rewrite
|
||||
`{{version}} -> {{version}}` and leave the drifted file exactly as it was while
|
||||
printing a green "Version constants updated". Only the `.githooks` markers
|
||||
(rewritten wholesale) and `uv.lock` (regenerated) heal on a re-run. The script
|
||||
prints the three remedies that do work; the usual one is to edit the named file
|
||||
to `{{version}}` and re-run the check.
|
||||
|
||||
`check-versions.sh` does NOT gate `default.nix` or `README.md`. Confirm
|
||||
`default.nix` yourself:
|
||||
|
||||
```bash
|
||||
grep 'version = ' default.nix # should be {{version}}
|
||||
```
|
||||
|
||||
(For a prerelease, do not expect the version string to appear uniformly in the
|
||||
winres files: `file_version`/`product_version` and the manifest's four-part
|
||||
version carry the BASE version because PE fields must be purely numeric, while
|
||||
`FileVersion`/`ProductVersion` carry the full `{{version}}`. check-versions.sh
|
||||
now encodes that split, so let it do the checking.)
|
||||
"""
|
||||
|
||||
[[steps]]
|
||||
|
|
@ -566,37 +513,74 @@ Review the commit to ensure all expected files are included.
|
|||
"""
|
||||
|
||||
[[steps]]
|
||||
id = "create-tag"
|
||||
title = "Create release tag"
|
||||
id = "push-main"
|
||||
title = "Land the release prep as a PR"
|
||||
needs = ["commit-release"]
|
||||
description = """
|
||||
Create annotated git tag.
|
||||
Releases are cut from `release/x.y.z`, not from the tip of `main` — see the
|
||||
"Release Branches" section of RELEASING.md. **Nothing is pushed straight to the
|
||||
release branch, and nothing is tagged before the PR merges.**
|
||||
|
||||
The branch is named for the BASE version: a `1.3.0-rc.1` run still targets
|
||||
`release/1.3.0`. Derive it rather than substituting `{{version}}` directly,
|
||||
which would name a branch nothing ever creates and fail with
|
||||
`src refspec ... does not match any`:
|
||||
|
||||
```bash
|
||||
BASE="$(printf '%s' "{{version}}" | sed 's/-.*//')"
|
||||
REL_BRANCH="release/$BASE"
|
||||
echo "$REL_BRANCH"
|
||||
```
|
||||
|
||||
Create the prep branch, push it, and open the PR:
|
||||
|
||||
```bash
|
||||
git checkout -b "release-prep/v{{version}}"
|
||||
git push -u origin "release-prep/v{{version}}"
|
||||
gh pr create --base "$REL_BRANCH" --label status/needs-review-auto
|
||||
```
|
||||
|
||||
Wait for it to merge, then take the merged state:
|
||||
|
||||
```bash
|
||||
git checkout "$REL_BRANCH" && git pull
|
||||
```
|
||||
|
||||
After the release ships, every commit that landed only on the release branch
|
||||
needs a forward-port PR to `main`, the version bump included:
|
||||
|
||||
```bash
|
||||
git log --oneline "main..$REL_BRANCH"
|
||||
```
|
||||
"""
|
||||
|
||||
[[steps]]
|
||||
id = "create-tag"
|
||||
title = "Create release tag on the merged commit"
|
||||
needs = ["push-main"]
|
||||
description = """
|
||||
Create the annotated tag on the MERGED commit, with the release branch checked
|
||||
out and pulled (previous step).
|
||||
|
||||
```bash
|
||||
git rev-parse --abbrev-ref HEAD # must be the release branch, not the prep branch
|
||||
git tag -a v{{version}} -m "Release v{{version}}"
|
||||
```
|
||||
|
||||
Tagging before the merge is the failure to avoid, in two shapes. With branch
|
||||
protection on, the direct push is rejected after the tag already exists
|
||||
locally. With a squash merge, the tag points at a commit that is not an
|
||||
ancestor of the release branch — and goreleaser packages `CHANGELOG.md` *from
|
||||
the tag* into every published archive, so the release would ship the
|
||||
pre-review notes.
|
||||
|
||||
Verify: `git tag -l | tail -5`
|
||||
"""
|
||||
|
||||
[[steps]]
|
||||
id = "push-main"
|
||||
title = "Push to main"
|
||||
needs = ["create-tag"]
|
||||
description = """
|
||||
Push the release commit to origin.
|
||||
|
||||
```bash
|
||||
git push origin main
|
||||
```
|
||||
|
||||
If rejected, someone else pushed. Pull, rebase, try again.
|
||||
"""
|
||||
|
||||
[[steps]]
|
||||
id = "push-tag"
|
||||
title = "Push release tag"
|
||||
needs = ["push-main"]
|
||||
needs = ["create-tag"]
|
||||
description = """
|
||||
Push the version tag to trigger CI release.
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
"name": "beads",
|
||||
"source": "./plugins/beads",
|
||||
"description": "AI-supervised issue tracker for coding workflows",
|
||||
"version": "1.2.2"
|
||||
"version": "1.3.0"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env sh
|
||||
# --- BEGIN BEADS INTEGRATION v1.2.2 ---
|
||||
# --- BEGIN BEADS INTEGRATION v1.3.0 ---
|
||||
# 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.2.2 ---
|
||||
# --- END BEADS INTEGRATION v1.3.0 ---
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env sh
|
||||
# --- BEGIN BEADS INTEGRATION v1.2.2 ---
|
||||
# --- BEGIN BEADS INTEGRATION v1.3.0 ---
|
||||
# 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.2.2 ---
|
||||
# --- END BEADS INTEGRATION v1.3.0 ---
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ if [ -n "$staged_go_files" ]; then
|
|||
echo "$staged_go_files" | xargs git add
|
||||
fi
|
||||
|
||||
# --- BEGIN BEADS INTEGRATION v1.2.2 ---
|
||||
# --- BEGIN BEADS INTEGRATION v1.3.0 ---
|
||||
# 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.2.2 ---
|
||||
# --- END BEADS INTEGRATION v1.3.0 ---
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ fi
|
|||
|
||||
exec < <(printf '%s\n' "$push_refs")
|
||||
|
||||
# --- BEGIN BEADS INTEGRATION v1.2.2 ---
|
||||
# --- BEGIN BEADS INTEGRATION v1.3.0 ---
|
||||
# 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.2.2 ---
|
||||
# --- END BEADS INTEGRATION v1.3.0 ---
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env sh
|
||||
# --- BEGIN BEADS INTEGRATION v1.2.2 ---
|
||||
# --- BEGIN BEADS INTEGRATION v1.3.0 ---
|
||||
# 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.2.2 ---
|
||||
# --- END BEADS INTEGRATION v1.3.0 ---
|
||||
|
|
|
|||
10
.github/workflows/ci-measurements.yml
vendored
10
.github/workflows/ci-measurements.yml
vendored
|
|
@ -86,7 +86,10 @@ jobs:
|
|||
ci_time "install golangci-lint" -- go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.10.1
|
||||
status=0
|
||||
ci_time "pr-policy wrapper" -- make ci-pr-policy || status=$?
|
||||
ci_time "pr-core gotestsum" -- gotestsum --junitfile artifacts/pr-core-junit.xml --format testdox -- -race -short -skip '^TestEmbedded' ./... || status=$?
|
||||
# -timeout=30m keeps this in step with the lane it measures
|
||||
# (scripts/ci/pr-core.sh). Without it ./cmd/bd can die on `go test`'s
|
||||
# 10m default and the measurement reports a panic instead of a duration.
|
||||
ci_time "pr-core gotestsum" -- gotestsum --junitfile artifacts/pr-core-junit.xml --format testdox -- -race -short -timeout=30m -skip '^TestEmbedded' ./... || status=$?
|
||||
ci_time "pr-lint wrapper" -- make ci-pr-lint || status=$?
|
||||
exit "$status"
|
||||
|
||||
|
|
@ -128,7 +131,10 @@ jobs:
|
|||
source scripts/ci/lib/timing.sh
|
||||
source ./.buildflags
|
||||
|
||||
ci_time "macos short go test" -- go test -v -race -short -skip '^TestEmbedded' ./...
|
||||
# -timeout=30m matches the macOS lanes this measures (pr.yml, main.yml).
|
||||
# This is the job that produced the ./cmd/bd duration distribution, and
|
||||
# at 10m it clips its own longest samples into timeout panics.
|
||||
ci_time "macos short go test" -- go test -v -race -short -timeout=30m -skip '^TestEmbedded' ./...
|
||||
|
||||
macos-candidates:
|
||||
name: Measure macOS no-short candidates
|
||||
|
|
|
|||
2
.github/workflows/conformance.yml
vendored
2
.github/workflows/conformance.yml
vendored
|
|
@ -5,7 +5,7 @@ name: Conformance
|
|||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
branches: [ main, 'release/**' ]
|
||||
merge_group:
|
||||
|
||||
concurrency:
|
||||
|
|
|
|||
6
.github/workflows/cross-version-smoke.yml
vendored
6
.github/workflows/cross-version-smoke.yml
vendored
|
|
@ -6,9 +6,11 @@ on:
|
|||
tags:
|
||||
- 'v*'
|
||||
|
||||
# On PR to main: test only the last 5 releases for fast feedback
|
||||
# On PR to main or a release branch: test only the last 5 releases for fast
|
||||
# feedback. Release-targeted PRs are exactly the ones where cross-version
|
||||
# upgrade breakage is most expensive to discover at tag time.
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
branches: [ main, 'release/**' ]
|
||||
|
||||
# Allow manual trigger with custom version count
|
||||
workflow_dispatch:
|
||||
|
|
|
|||
13
.github/workflows/main.yml
vendored
13
.github/workflows/main.yml
vendored
|
|
@ -483,7 +483,7 @@ jobs:
|
|||
# macOS: full test suite, no coverage (faster)
|
||||
- os: macos-latest
|
||||
coverage: false
|
||||
test-flags: '-v -race -short -timeout=25m'
|
||||
test-flags: '-v -race -short'
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
|
||||
|
||||
|
|
@ -557,6 +557,13 @@ jobs:
|
|||
GOCACHE: ${{ runner.temp }}/go-cache/non-race
|
||||
run: go build -v -tags gms_pure_go ./cmd/bd
|
||||
|
||||
# Both lanes below pass -timeout=30m explicitly. ./cmd/bd has outgrown
|
||||
# `go test`'s 10m per-package default (see scripts/ci/pr-core.sh and
|
||||
# #6091), and when it trips the alarm the panic names whichever test was
|
||||
# in flight, so it reads like a hang rather than the package running out
|
||||
# of clock. The flag lives on the invocation, not in matrix.test-flags,
|
||||
# so editing the matrix cannot silently drop it. 30m matches every other
|
||||
# -race lane here for this same code.
|
||||
- name: Test (with coverage + JUnit XML)
|
||||
if: matrix.coverage
|
||||
env:
|
||||
|
|
@ -566,14 +573,14 @@ jobs:
|
|||
gotestsum \
|
||||
--junitfile junit.xml \
|
||||
--format testdox \
|
||||
-- -tags gms_pure_go -race -short -timeout=25m -coverprofile=coverage.out -skip '^TestEmbedded' ./...
|
||||
-- -tags gms_pure_go -race -short -timeout=30m -coverprofile=coverage.out -skip '^TestEmbedded' ./...
|
||||
|
||||
- name: Test
|
||||
if: ${{ !matrix.coverage }}
|
||||
env:
|
||||
BEADS_TEST_BD_BINARY: ${{ github.workspace }}/bd
|
||||
GOCACHE: ${{ runner.temp }}/go-cache/race
|
||||
run: go test -tags gms_pure_go ${{ matrix.test-flags }} -skip '^TestEmbedded' ./...
|
||||
run: go test -tags gms_pure_go ${{ matrix.test-flags }} -timeout=30m -skip '^TestEmbedded' ./...
|
||||
|
||||
- name: Upload coverage to Codecov
|
||||
if: matrix.coverage && !cancelled()
|
||||
|
|
|
|||
10
.github/workflows/migration-test.yml
vendored
10
.github/workflows/migration-test.yml
vendored
|
|
@ -56,6 +56,11 @@ jobs:
|
|||
cache-identity: v1.1.0-b0f3dd607c3fb989ee08d0a6854fba80d0402971eb108f9af6170bc14d491a34
|
||||
- version: v1.1.2
|
||||
cache-identity: v1.1.2-a72d71ed374955dc9f83a0f90b54bd7b6a0016709dd1676ae2e368651ed401c2
|
||||
# The v1.1.2 tree re-tagged by the recovery release, so it adds no new
|
||||
# storage regime — but it is the tag field upgrades actually start
|
||||
# from, and it was never in this corpus.
|
||||
- version: v1.2.2
|
||||
cache-identity: v1.2.2-8140098a51d3b81d5548d1c5e6db1a2d9930e5d141efe2a4bff7d079c4d321e8
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
|
||||
|
|
@ -98,7 +103,10 @@ jobs:
|
|||
sudo timeout 180 apt-get install -y jq libicu74
|
||||
|
||||
- name: Install Dolt test runtime
|
||||
if: contains(fromJSON('["v0.55.4","v0.56.1","v0.57.0","v0.62.0"]'), matrix.version)
|
||||
# v0.55.4-v0.62.0 host their fixture on this server; v1.0.1-v1.1.2 use
|
||||
# the same pinned binary as a read-only oracle over the wisp plane,
|
||||
# which has no `bd dolt sql` equivalent.
|
||||
if: contains(fromJSON('["v0.55.4","v0.56.1","v0.57.0","v0.62.0","v1.0.1","v1.1.0","v1.1.2","v1.2.2"]'), matrix.version)
|
||||
run: |
|
||||
archive="$RUNNER_TEMP/dolt-linux-amd64.tar.gz"
|
||||
runtime="$RUNNER_TEMP/dolt-runtime"
|
||||
|
|
|
|||
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 ]
|
||||
branches: [ main, 'release/**' ]
|
||||
merge_group:
|
||||
|
||||
concurrency:
|
||||
|
|
|
|||
14
.github/workflows/pr.yml
vendored
14
.github/workflows/pr.yml
vendored
|
|
@ -2,7 +2,10 @@ name: PR
|
|||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
# 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/**' ]
|
||||
merge_group:
|
||||
|
||||
concurrency:
|
||||
|
|
@ -960,7 +963,14 @@ jobs:
|
|||
env:
|
||||
BEADS_TEST_BD_BINARY: ${{ github.workspace }}/bd
|
||||
GOCACHE: ${{ runner.temp }}/go-cache/race
|
||||
run: go test -tags gms_pure_go -v -race -short -skip '^TestEmbedded' ./...
|
||||
# -timeout is explicit for the same reason it is in scripts/ci/pr-core.sh
|
||||
# (#6091): ./cmd/bd has outgrown `go test`'s 10m per-package default. On
|
||||
# this runner it lands between 357s and 600s across recent runs — #6091's
|
||||
# own macOS lane passed at 596.7s, 3.3s under the wall — so the package
|
||||
# intermittently dies on the alarm and the panic names whichever test was
|
||||
# in flight, which reads like a hang instead of the clock running out. 30m
|
||||
# matches every other -race lane here for this same code.
|
||||
run: go test -tags gms_pure_go -v -race -short -timeout=30m -skip '^TestEmbedded' ./...
|
||||
|
||||
# Producer-side guard for the Beads<->consumer CLI contract. Runs the whole
|
||||
# cmd/bd/protocol package: the golden corpus (regenerated from this branch's
|
||||
|
|
|
|||
2
.github/workflows/regression.yml
vendored
2
.github/workflows/regression.yml
vendored
|
|
@ -5,7 +5,7 @@ on:
|
|||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
branches: [main]
|
||||
branches: [main, 'release/**']
|
||||
# Allow manual trigger
|
||||
workflow_dispatch:
|
||||
|
||||
|
|
|
|||
662
CHANGELOG.md
662
CHANGELOG.md
|
|
@ -14,6 +14,173 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
count the same metadata-scoped set `bd list` returns without fetching every
|
||||
row.
|
||||
|
||||
### Changed
|
||||
|
||||
- **`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. This covers explicit gate
|
||||
checks in embedded, server, and proxied-server command paths; the legacy
|
||||
`<rig>:<bead-id>` await value remains accepted for compatibility.
|
||||
|
||||
## [1.3.0] - 2026-09-15
|
||||
|
||||
The first tested release off `main` since the 1.1 line. [1.2.2] was a recovery
|
||||
release that re-shipped the v1.1.2 code under a higher version number, so a
|
||||
v1.2.2 user is running 1.1-era code and meets **everything** below at once:
|
||||
the changes listed here, plus the [1.2.1] changes that release deliberately
|
||||
withheld. Read the upgrade notes before installing.
|
||||
|
||||
### Upgrade notes
|
||||
|
||||
**On an embedded or local store, the first invocation migrates your schema, in
|
||||
place, from v53 to v66.** A v1.2.2 (or any 1.1.x) database sits at main-series
|
||||
schema v53; this binary knows v66, so the first command that opens the store
|
||||
applies 13 main-series migrations, `0054_add_lease_columns` through
|
||||
`0066_add_events_journal_actor`. Two of those passes rewrite rows rather than
|
||||
just reshaping tables — the aux-row id rekey and the `events` dolt_ignore flip
|
||||
described under **Changed** — so on a large store the first invocation is
|
||||
*noticeably* slower than the ones after it. It is crash-resumable and picks up
|
||||
where it left off, but do not interrupt it if you can avoid it.
|
||||
|
||||
**A shared Dolt sql-server is never auto-migrated** (#5920, #6048): migrating it
|
||||
promotes the schema for every client at once, so it waits for explicit consent
|
||||
via `bd migrate schema`. Remote-backed stores keep their existing
|
||||
designated-migrator gate. Upgrade all of that server's clients *first* — see
|
||||
[Shared servers](https://beads.gascity.com/getting-started/upgrading#shared-servers).
|
||||
|
||||
**The counter restarts partway through, and that is not a loop.** The
|
||||
clone-local (dolt_ignored) series runs after the main one, through the same
|
||||
printer and its own numbering, and it moves 0011 → 0026 on this upgrade. So the
|
||||
run is about **28 migrations**, not 13, and what you see on stderr is 13 lines
|
||||
counting up to 0066 followed by 15 lines starting again at 0012:
|
||||
|
||||
```
|
||||
Applying migration 0065: widen_wisp_comments_text…
|
||||
Applying migration 0066: add_events_journal_actor…
|
||||
Applying migration 0012: create_leases… ← clone-local series, not a restart
|
||||
```
|
||||
|
||||
A counter that jumps backwards is the signature operators kill runs over. Let
|
||||
it finish.
|
||||
|
||||
Progress prints only when stderr is a terminal. Piped and CI runs see nothing
|
||||
at all, which is deliberate — a silent-looking CI upgrade is not a stuck one.
|
||||
|
||||
**Back up first, with the binary you have now.** Take the backup *before* you
|
||||
install 1.3.0. Under the new binary `bd export` triggers the auto-migration
|
||||
before it exports, so a snapshot taken afterwards is a post-migration snapshot
|
||||
and cannot protect you against the migration going wrong. On a remote-backed
|
||||
store, finish syncing with the old binary too: once 1.3.0 is installed the
|
||||
pending-migration gate refuses `bd dolt push` and `bd dolt pull` as well, not
|
||||
just `bd migrate`.
|
||||
|
||||
```bash
|
||||
# with your CURRENT bd, before installing 1.3.0:
|
||||
bd dolt push # remote-backed stores only
|
||||
bd export --all -o .beads/backup/pre-1.3.0-$(date +%Y%m%d).jsonl
|
||||
```
|
||||
|
||||
A JSONL export is cheap, issue-complete, and importable by any bd version. If
|
||||
you want a Dolt-native snapshot that keeps history and config, configure a
|
||||
destination and sync it — **bare `bd backup` takes no backup**, it is a command
|
||||
group that prints help and exits 0:
|
||||
|
||||
```bash
|
||||
bd backup init <path-or-dolthub-url> # once, to configure a destination
|
||||
bd backup sync # take the snapshot
|
||||
```
|
||||
|
||||
**Upgrade every client that shares a store, together.** The forward schema-skew
|
||||
guard means an older co-resident binary — a second `bd` earlier in `PATH`, a
|
||||
long-running `bd serve`, another clone's cron job — refuses a database migrated
|
||||
past what it knows, rather than proceeding blind. That is the guard working, not
|
||||
a bug, but it makes a mixed-version fleet a broken fleet: one machine running
|
||||
1.3.0 takes the whole store forward and every 1.2.2 client stops. Run
|
||||
`which -a bd` after installing, and on a remote-backed store follow the existing
|
||||
designated-migrator procedure (one clone migrates and pushes; the rest pull or
|
||||
re-clone). See
|
||||
[Upgrading](https://beads.gascity.com/getting-started/upgrading) for the
|
||||
per-install-method recipes and the multi-clone flow.
|
||||
|
||||
**If you need to go back**, the rollback is a schema-cursor rollback, not a
|
||||
downgrade of the data: the procedure is written up in the
|
||||
[recovery runbook](https://beads.gascity.com/recovery/accidental-1-2-1-release)
|
||||
(repo copy: `docs/recovery/accidental-1-2-1-release.md`). Its worked example is
|
||||
the v53↔v65 case from the accidental 1.2.1 release; the steps are the same for
|
||||
v66, with the version numbers adjusted.
|
||||
|
||||
### Breaking changes for v1.2.2 users
|
||||
|
||||
**This is a highlights list, not the complete set.** A v1.2.2 user is crossing
|
||||
two releases at once, and the breaks below are the ones most likely to stop a
|
||||
script or a service. The full set is the `[1.2.1]` section further down plus the
|
||||
**Changed** section here — read `[1.2.1]` in full before upgrading, since
|
||||
[1.2.2] withheld it and v1.2.1 itself was pulled, so nobody on the supported
|
||||
line has seen it.
|
||||
|
||||
After upgrading, `bd upgrade review` prints exactly the entries between the
|
||||
version you were running and this one. (Prefer it to `bd info --whats-new`,
|
||||
which dumps the entire release history.)
|
||||
|
||||
**Carried from [1.2.1] — never shipped to v1.2.2 users:**
|
||||
|
||||
- **`bd update --status <done-status>` now enforces close policy.** Moving an
|
||||
issue to `closed` (or any configured done-category status) via `bd update`,
|
||||
`bd batch update`, or the issueops facade refuses when the issue has open
|
||||
children or a live direct blocker, matching `bd close`. Override with
|
||||
`bd update --force` (`update <id> status=closed force=true` in `bd batch`;
|
||||
`UpdateRequest.ForceClosePolicy` for facade consumers). An unforced refusal
|
||||
rolls back the entire batch.
|
||||
- **`bd search` includes closed issues by default** (bd-t5yex). The dominant
|
||||
query is "was this already found/filed/fixed?", where excluding closed issues
|
||||
produced a false "no". Narrow with `--status open` to get the old behavior.
|
||||
`bd list` keeps its open-only default.
|
||||
- **The no-ID "last touched issue" fallback on `bd update` / `bd close` is
|
||||
interactive-only** (bd-m00pb,
|
||||
[#4839](https://github.com/gastownhall/beads/pull/4839)). A scripted
|
||||
`bd update $ID …` with an empty `$ID` now refuses in argument validation
|
||||
instead of mutating whatever was touched last. The fallback requires a
|
||||
terminal stdin; `BD_NON_INTERACTIVE=1` and `CI=1/true` also disable it. Set
|
||||
`BD_LAST_TOUCHED_FALLBACK=1` if a script genuinely relied on it.
|
||||
- **`bd human list` hides done/frozen and pinned beads by default, and
|
||||
validates `--status`** (#5332). It previously passed `--status` through
|
||||
unvalidated and showed closed beads. A `--status` typo is now an error rather
|
||||
than an empty list. Every bead *type* still shows.
|
||||
- **`bd dolt push` and `bd sync` no longer adopt a git-origin-derived Dolt
|
||||
remote without consent** (#5068). Both used to silently derive a remote from
|
||||
`git remote get-url origin`, persist `sync.remote`, commit that config change
|
||||
under your git identity, and upload the full issue history — which published
|
||||
a whole issue database to a public origin on a command the user believed
|
||||
targeted an already-configured remote. Adoption now prompts (defaulting to
|
||||
no) and fails closed non-interactively. `--yes`/`-y` consents ahead of time.
|
||||
- **`bd --readonly serve` is refused instead of binding a server that cannot do
|
||||
what it advertises.** On a Dolt SQL-server workspace the flag was previously a
|
||||
silent no-op and the server came up fully writable, so anything scripted as a
|
||||
"safe" read-only server **does not start after this upgrade** — drop the flag.
|
||||
Worth checking before you restart a long-running `bd serve` as part of the
|
||||
fleet upgrade above.
|
||||
- **`bd config list` and `GET /v0/beads/config` no longer enumerate the `kv.`
|
||||
plane**, which is where `bd remember` memories live. That closed an
|
||||
unauthenticated `GET /v0/beads/config` handing out every stored memory. A
|
||||
script that read memories out of `bd config list` now gets empty output rather
|
||||
than an error; use `bd kv` / `bd remember` instead.
|
||||
- **The published `backend` package drops orphan handling** (bd-gwryr).
|
||||
`backend.OrphanHandling` and its four constants, the `storage` originals they
|
||||
aliased, `BatchCreateOptions.OrphanHandling` and `issueops.CheckOrphan` are
|
||||
removed. They never did anything except cost a query, but a Go consumer that
|
||||
names them no longer compiles.
|
||||
|
||||
**New in 1.3.0** (full entries under **Changed**):
|
||||
|
||||
- An explicitly configured Dolt server port now outranks the ambient
|
||||
`BEADS_DOLT_PORT` environment variable.
|
||||
- Actor matching decodes an exact `--` run to `/` instead of collapsing it to a
|
||||
generic separator, so `gastown--mayor` matches `gastown/mayor` and stops
|
||||
matching `gastown__mayor`.
|
||||
|
||||
### Added
|
||||
|
||||
- **The events journal records WHO performed each mutation.** `bd_events_journal`
|
||||
gains an `actor` column (migration 0066 plus its ignored-series twin 0025, so
|
||||
upgraded workspaces and fresh clones converge on the same shape), stamped
|
||||
|
|
@ -56,29 +223,207 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
concept, themes are labels here, and `--label theme:x` is the native way to
|
||||
say it.
|
||||
|
||||
- **New `*.gate.lock` files appear next to and inside `.beads`** ([#5046](https://github.com/gastownhall/beads/pull/5046),
|
||||
[#5093](https://github.com/gastownhall/beads/pull/5093)). A two-level
|
||||
cooperative gate now serializes the operations that cannot safely overlap —
|
||||
ordinary commands take it shared, maintenance like `bd backup restore` takes
|
||||
it exclusive. It is `flock`-based, so the file is the lock's *name*, not its
|
||||
state: the gate is created once (mode `0600`) and deliberately never deleted,
|
||||
because deleting it is how two processes end up holding two different locks
|
||||
for the same resource. Each gate sits *beside* what it guards, never inside
|
||||
it: the workspace gate for `<dir>/.beads` is `<dir>/.beads.gate.lock` in the
|
||||
project root, and the physical-root gate is `.beads/embeddeddolt.gate.lock` in
|
||||
the default embedded mode (`.beads/dolt.gate.lock` under a server layout;
|
||||
under the shared server it lives beside `~/.beads/shared-server/dolt` and
|
||||
never enters the workspace at all; a remote Dolt host has no physical gate).
|
||||
Both are covered by the `*.gate.lock*` pattern `bd doctor` maintains in the
|
||||
project and `.beads` gitignores, so an upgraded workspace picks up the ignore
|
||||
rule on the next `bd doctor --fix`; a workspace with no `.beads` directory is
|
||||
not gated at all, rather than scattering lock files into whatever directory
|
||||
`bd` was run from.
|
||||
|
||||
- **`sort` on `GET /v0/beads/issues`.** The listing served one order —
|
||||
`(created_at DESC, id ASC)` — because the cursor is a keyset position in it,
|
||||
and the spec said so in its own words: "the sort order is welded to the cursor
|
||||
contract, and a new order needs new surface." The cost of that welding fell on
|
||||
every client that wanted `bd list`'s ordering, because the only way to get it
|
||||
was to page the whole result set and re-sort locally. Measured over a
|
||||
1400-row store at the 200-row page an HTTP client actually uses, that is
|
||||
**7 requests plus a client-side comparator; `?sort=priority` is 1**
|
||||
(`TestProxiedServerListSortRetiresTheWalk`, which runs both strategies against
|
||||
a real `bd serve` and checks both against `bd list --json` row for row). It is
|
||||
the one cost on this surface that got worse as a project grew.
|
||||
|
||||
**Two values, and the set is closed.** `created` is the existing order, now
|
||||
spellable. `priority` is `(priority ASC, created_at DESC, id ASC)` — `bd
|
||||
list`'s flagless ordering, which is also what `bd list --sort priority`
|
||||
produces, so one served order retires the walk for both. The other seven
|
||||
orders `bd list --sort` takes are not offered: each value here is a cursor
|
||||
contract needing a key proven total, and `id` is a natural-numeric order no
|
||||
database expresses, `updated` moves on every write, `closed` is nullable, and
|
||||
`status`/`title`/`type`/`assignee` are mutable and unindexed.
|
||||
|
||||
**Absent `sort` still means `created`, permanently.** It is the compatibility
|
||||
contract for every client written before the parameter existed; changing it
|
||||
would alter which rows a truncated page contains, with no error to notice it
|
||||
by. A server that predates the parameter answers `param: "sort"` with
|
||||
`reason: "unknown_parameter"`, which is the per-parameter capability probe a
|
||||
client dispatches on to fall back.
|
||||
|
||||
**The cursor now carries its order, and a mismatch is refused.** This is the
|
||||
half that makes the parameter safe rather than merely useful. The token was
|
||||
base64 of `{t,i}` with no binding, so a `created`-order cursor replayed under
|
||||
`sort=priority` would have decoded perfectly and been read as a position in a
|
||||
different total order — a page that both skips and duplicates rows, served
|
||||
with a 200, undetectable by the client. Tokens are now `v2` with an explicit
|
||||
order member and decode refuses any token whose order differs from the
|
||||
request's, as `invalid_cursor` (documented recovery: restart paging).
|
||||
Outstanding `v1` tokens stay readable as the `created`-order positions they
|
||||
are, so **no traversal in flight has to restart**. This does not contradict
|
||||
"the token carries no filters": filters select the set, the order decides what
|
||||
the position means.
|
||||
|
||||
**`priority` is a mutable key**, which `created_at` is not, and the spec says
|
||||
so: under `created` only new rows move relative to a walk, while a priority
|
||||
update moves an existing row too, so it can be seen twice or missed. That is
|
||||
the already-documented "a cursor pins a position, not a snapshot" caveat
|
||||
reached by a second route, not a new class of error — unchanged data never
|
||||
skips or repeats under either order.
|
||||
|
||||
### Changed
|
||||
|
||||
- **`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. This covers explicit gate
|
||||
checks in embedded, server, and proxied-server command paths; the legacy
|
||||
`<rig>:<bead-id>` await value remains accepted for compatibility.
|
||||
- Shared Dolt databases (sql-server mode) no longer auto-apply schema
|
||||
migrations on a version bump. Migrating a shared database promotes the
|
||||
schema for every connected bd client at once and locks out clients still
|
||||
on an older binary, so bd now refuses without explicit consent: run
|
||||
`bd migrate schema` once after upgrading every client, or set
|
||||
`BD_ALLOW_REMOTE_MIGRATE=1` in scripted use. Reads keep working on the
|
||||
current schema meanwhile. Embedded (single-user) databases still
|
||||
auto-migrate silently, unchanged. (#5920)
|
||||
|
||||
- **Write commands now refuse to run while a MIGRATION-FREEZE sentinel sits
|
||||
at the town root** (dc-6jaq), mirroring the gate the gt CLI already applies
|
||||
to `gt mail send`/`nudge`/`sling`/`assign`. `bd create`/`update`/`close`/
|
||||
`remember`/`import` and every other command gated by `CheckReadonly`
|
||||
(~120 call sites, `bd q` included) now print `⛔ town is frozen for
|
||||
migration (by <operator>)` and exit 1 instead of writing to a store mid-
|
||||
migration. The check runs twice: once early in the root command, before
|
||||
version-bump auto-migration or JSONL auto-import can touch the store, and
|
||||
again at each write command's own chokepoint. Read commands (`list`,
|
||||
`show`, `ready`, …) keep working during a freeze — the same early check
|
||||
also skips version tracking and auto-migration for them, so a frozen store
|
||||
is never rewritten just because someone ran a read. `--dry-run`/`--inspect`
|
||||
previews are blocked at the per-command chokepoint instead, same as strict
|
||||
`--readonly` already blocks them. Clear the freeze with `gt migrate thaw`.
|
||||
- The smart migration gate's "auto-migrate as safe first-mover" and
|
||||
auto-fast-forward arms are now embedded-only. On a shared server the gate
|
||||
always stops for consent, because neither argument can observe the other
|
||||
clients attached to that server. (#5920, #4516)
|
||||
|
||||
- The newly exported Go packages (`backend`, `backend/conformance`, `beadserrors`,
|
||||
`issueops`, `journalops`, `memoryops`, `schema`, `test/conformance`) are marked
|
||||
EXPERIMENTAL: they are not yet covered by the project's compatibility promise and
|
||||
may change in a minor release. Pin an exact beads version and re-run the
|
||||
conformance suite on every bump.
|
||||
|
||||
- **The optimistic-concurrency token is now a JSON string** — responses carry
|
||||
`revision` as an opaque decimal string and `expected_version` must be sent as
|
||||
that string. JSON-number tokens exceeded JavaScript's 2^53 integer precision.
|
||||
This member never shipped in a tagged release.
|
||||
|
||||
- CI: migration-test and upgrade-smoke now seed and assert wisp-plane data
|
||||
(wisps, wisp deps/comments, leases, events, ignored-track cursor) across
|
||||
v1.0.1/v1.1.x/v1.2.2 → candidate upgrades.
|
||||
|
||||
- **`--profile` is now `--cpu-profile`, with no alias**
|
||||
([#5126](https://github.com/gastownhall/beads/pull/5126), bd-ugz). The
|
||||
persistent flag that writes a CPU profile is spelled `--cpu-profile`; the old
|
||||
`--profile` spelling is gone rather than deprecated, so it fails as an unknown
|
||||
flag instead of silently doing nothing. `--profile` is the conventional name
|
||||
for a *named configuration*, not for pprof output, and holding it hostage to
|
||||
a debugging aid nobody passes twice a year was the wrong trade. Scripts and
|
||||
aliases that profile bd need the new spelling.
|
||||
|
||||
- **Migration 0061 rekeys every events, comments, snapshot and
|
||||
compaction-snapshot row to a content-derived id**
|
||||
([#5150](https://github.com/gastownhall/beads/pull/5150), bd-ri8bd). Those
|
||||
four aux tables minted random UUIDv7 ids, which is fine for a single writer
|
||||
and wrong for replication: unversioned newest-wins replication has no merge
|
||||
pass, so two clones recording the same fact produced two rows that never
|
||||
converged. Ids are now UUIDv5 over a SHA-256 digest of the row's own content
|
||||
(frozen column order, plus the table name and a duplicate-disambiguating
|
||||
ordinal), so the same fact derives the same id everywhere and convergence is
|
||||
a property of the key rather than of a reconciliation step. New rows derive
|
||||
their id at insert; existing rows are converted by a **one-time bulk rekey**
|
||||
on the first open after upgrade, which is the main reason that invocation is
|
||||
slower than the ones after it. The pass is crash-resumable through a
|
||||
`local_metadata` sentinel and records completion clone-locally, so it runs
|
||||
once per clone and is not repeated on the next command. `wisp_events` and
|
||||
`wisp_comments` are deliberately excluded — they are clone-local and never
|
||||
merge. **Any external reference to an event, comment or snapshot id taken
|
||||
before the upgrade will not resolve afterwards.**
|
||||
|
||||
- **The `events` audit table is now clone-local**
|
||||
([#5162](https://github.com/gastownhall/beads/pull/5162), bd-red8u).
|
||||
Migration 0062 moves `events` onto the dolt_ignored plane in a self-committing
|
||||
drop/commit/recreate that preserves every row. Events are single-writer audit
|
||||
rows with low cross-machine value, and minting a versioned Dolt commit for
|
||||
each one was the dominant source of commit churn on a busy store. The
|
||||
consequence is the point: **`events` rows no longer replicate.** They keep
|
||||
full SQL durability locally and `bd history <id> --events` still reads them,
|
||||
but a pull no longer brings another machine's events over, and a push no
|
||||
longer sends yours. Events already committed before the flip stay in the
|
||||
remote's history until the next squash window. Comments stay versioned.
|
||||
|
||||
- **The `interactions.jsonl` audit sidecar is opt-in**
|
||||
([#4688](https://github.com/gastownhall/beads/pull/4688), fixes
|
||||
[#4687](https://github.com/gastownhall/beads/issues/4687)). `audit.enabled`
|
||||
now defaults to **false** and `bd init` no longer creates the file, so
|
||||
status/assignee/priority field-change logging writes nothing unless you ask
|
||||
for it. Set `audit.enabled=true` (or `BD_AUDIT_ENABLED=1`) to restore the old
|
||||
behavior. The database-backed replacement is `bd history <id> --events`, which
|
||||
needs no sidecar. Anything that read `.beads/interactions.jsonl` on the
|
||||
assumption it would exist needs the config key set.
|
||||
|
||||
- **`bd import` refuses a redirected stdin rather than quietly ignoring it**
|
||||
([#5171](https://github.com/gastownhall/beads/pull/5171), bd-axluy). Bare
|
||||
`bd import` imports the default JSONL, and `bd import -` imports stdin; a
|
||||
`bd import < file.jsonl` looked like the second and behaved like the first,
|
||||
importing a different file than the one on the command line with no way to
|
||||
notice. With stdin redirected, no `-`, and no named source, `bd import` now
|
||||
errors and names both fixes. `/dev/null` is a character device, so a scripted
|
||||
bare `bd import` under a subprocess still imports the default file as before.
|
||||
|
||||
- **Auto-backup defaults to off under a Dolt sql-server** (wy-zrmqr). The
|
||||
automatic backup used to switch itself on whenever a git remote existed,
|
||||
regardless of storage mode — which on one shared sql-server meant ~31 clients
|
||||
independently deciding to back up the same database, pinning its CPU. The
|
||||
default is now off in server, proxied-server and shared-server modes (and in
|
||||
nocgo builds, which are always server-backed); embedded mode is unchanged and
|
||||
still enables it when a git remote is present. An explicitly configured
|
||||
`backup.enabled` (or `BD_BACKUP_ENABLED`) always wins over the default, and
|
||||
`bd config get backup.enabled` now prints the effective value with its source
|
||||
— `default (auto: off in sql-server mode)` — rather than a bare `false` that
|
||||
could not be told apart from a configured one.
|
||||
|
||||
- **`bd hooks install --chain` and `--force` are accepted no-ops**
|
||||
([#5284](https://github.com/gastownhall/beads/pull/5284), bd-5vdt8). Managed
|
||||
`BEGIN`/`END BEADS INTEGRATION` marker sections made both flags meaningless:
|
||||
an install now replaces only the content between its own markers, so content
|
||||
outside them is *always* preserved (what `--force` used to negate) and an
|
||||
existing hook *always* keeps running alongside the bd section (what `--chain`
|
||||
used to request). The flags remain registered so existing invocations do not
|
||||
break, and `--json` still echoes them, but neither changes what is written.
|
||||
A hook with no markers is handled by shape: a legacy bd hook is replaced, and
|
||||
a foreign one gets a one-time `<hook>.backup` sidecar before the section is
|
||||
injected. Symlinked and git-tracked hook paths are refused outright, before
|
||||
anything is written.
|
||||
|
||||
- **Write commands refuse to run while a migration freeze marker is present**
|
||||
(dc-6jaq). When a file named `MIGRATION-FREEZE` exists in the workspace
|
||||
directory, the working directory, or any ancestor of either — or at the
|
||||
path named by `BD_MIGRATION_FREEZE_FILE`, which is authoritative when set
|
||||
— `bd create`/`update`/`close`/`remember`/`import` and every other write
|
||||
command (~120 call sites, `bd q` included), plus the destructive
|
||||
`bd init --reinit-local` and `bd bootstrap`, print `⛔ workspace is frozen
|
||||
for migration` naming the marker's path and exit **14**, a distinct code
|
||||
scripts can branch on, instead of writing to a store mid-migration.
|
||||
Operators freeze a workspace by creating the file (optionally
|
||||
`operator<TAB>RFC3339 timestamp<TAB>reason` on one line, echoed back in
|
||||
the refusal) and thaw it by removing the file. Read commands (`list`,
|
||||
`show`, `ready`, …) keep working during a freeze, and bd's own maintenance
|
||||
stands down with them — version tracking, auto-migration, JSONL
|
||||
auto-import, Dolt auto-commit, auto-backup, auto-export and auto-push are
|
||||
all skipped, so a frozen store is never rewritten just because someone ran
|
||||
a read. A running `bd serve` is not gated: stop it before freezing. If bd
|
||||
cannot tell whether a marker is present, it refuses rather than assuming
|
||||
the workspace is open.
|
||||
|
||||
- **`bd dep add` names the implicit `type=blocks` default, but only to an
|
||||
interactive operator** (#5854). Creating an edge with no `-t/--type` silently
|
||||
|
|
@ -183,8 +528,134 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
encoding changes equivalence class silently, with no error to notice. Longer
|
||||
or mixed runs, `__` and `---` included, are unaffected and still collapse.
|
||||
|
||||
- **`bd ready --claim` now refuses a row cap under `--proxied-server`.** The
|
||||
proxied ready role cannot enforce `--max-rows`/`BEADS_MAX_ROWS`, so bd fails
|
||||
loudly rather than silently dropping the limit; `--claim` no longer exempts
|
||||
the command. Agent rigs that set the cap globally must unset it for proxied
|
||||
`bd ready --claim`. Direct mode is unchanged, and a claim there still
|
||||
succeeds against a ready pool larger than the cap. (#6269)
|
||||
|
||||
### Fixed
|
||||
|
||||
- **Server-mode issue mutations no longer revert concurrent writers' committed
|
||||
rows** ([#5740](https://github.com/gastownhall/beads/pull/5740)). The
|
||||
issue-mutation path ran `DOLT_ADD`/`DOLT_COMMIT` inside its still-open SQL
|
||||
transaction; `DOLT_ADD` stages the whole table as of the transaction's
|
||||
BEGIN-time root, and the Dolt commit was minted before the commit-time merge
|
||||
that reconciles concurrent writers — so a mutation could silently write every
|
||||
row another session had committed during its window back to that session's
|
||||
BEGIN-time value, seen in production as claims reverting minutes after they
|
||||
were made. The Dolt commit now runs after the SQL transaction commits, against
|
||||
the post-merge working set. Its failure is logged rather than returned: the
|
||||
data is durably committed by then and rides the next Dolt commit, and treating
|
||||
an applied mutation as failed is what made retries double-apply and claim
|
||||
verification disown claims the caller held. Reported and fixed by
|
||||
@nova-submodules.
|
||||
|
||||
- **Removed-backend rejection now detects an existing Dolt database** and gives
|
||||
the exact `metadata.json` heal (change `"backend"` to `"dolt"`, or delete the
|
||||
field) instead of a destructive export/reinitialize path. Workspaces that bd
|
||||
v1.2.x opened as Dolt despite a stale `"backend"` value are one edit from
|
||||
healthy, and the message now says so. Rejection remains fail-closed and
|
||||
read-only — no storage database is opened or modified — and still exits 1.
|
||||
(Detection helper ported from @steveyegge's #4740.)
|
||||
|
||||
- `bd migrate` no longer aborts with a duplicate-primary-key error when the same
|
||||
dependency edge exists in two typed target columns; duplicate edges are now
|
||||
merged deterministically (issue-ref wins over wisp/external), renaming an issue
|
||||
no longer leaves its dependency rows on a stale primary key, and databases left
|
||||
half-rekeyed by earlier binaries are detected and repaired on the next
|
||||
migration pass (#5268).
|
||||
|
||||
- **Legacy tracked `ignored_schema_migrations` self-heals** by untracking it at
|
||||
open time, unwedging `bd dolt pull` on upgraded databases (#4356).
|
||||
|
||||
- **A v1.1.x/v1.2.x ignored-migration cursor is believed** when
|
||||
`leases.granted_node` is merely not yet migrated, so upgrades apply only the
|
||||
pending ignored tail instead of replaying `ignored/0007` and silently
|
||||
restamping `wisps.updated_at` (#5981 class, #5366 follow-up).
|
||||
|
||||
- **Auto-export heals after `bd delete` instead of permanently refusing** — the
|
||||
orphan guard proves deletions against the store's own history (embedded and
|
||||
server modes), stores wedged by earlier binaries recover on first run, and
|
||||
`export-state.json` is now versioned (#5896).
|
||||
|
||||
- **`bd flatten` and `bd compact` now finish with a full Dolt GC** (all
|
||||
generations), so re-running them on a previously-GC'd store actually reclaims
|
||||
the orphaned history and retires orphaned `--as-of` addresses; `bd gc` gains
|
||||
`--full` and hints when a default pass reclaims little (#5907).
|
||||
|
||||
- **`--storage-class` is honored on the proxied-server and `--file` routes** and
|
||||
rejected as a plan-wide `--graph` flag; it was silently ignored there.
|
||||
|
||||
- **Delete and cascade `dep_remove` journal rows are attributed to the
|
||||
requesting actor** (#5985); `bd events export`/`tail` now say when the journal
|
||||
is disabled.
|
||||
|
||||
- **Truthful errors when a server-scoped credential cannot reach the requested
|
||||
database** (missing / denied / wrong-session attribution); `--init-if-missing`
|
||||
is honored in proxied-server mode.
|
||||
|
||||
- **The aux row re-key survives dolt#11131-class encoding drift** instead of
|
||||
failing mid-upgrade with a raw `invalid hash length` error. Drifted tables are
|
||||
skipped with a warning, recorded clone-locally in `aux_row_rekey_drifted`, and
|
||||
re-keyed on a later pass, rather than leaving the database unopenable. This
|
||||
already reached 1.1.x and v1.2.2 users — it is the [1.1.2] fix — and lands on
|
||||
the main line here, so a store upgrading from v1.2.2 is not newly exposed
|
||||
(#5064, #4380). Diagnosis and fix by @marcodelpin, carried and reworked by
|
||||
@maphew.
|
||||
|
||||
- **Server mode honors `Config.LenientOpen`**, so the dirty-table guard's
|
||||
documented recovery is executable. The refusal tells you to run
|
||||
`bd dolt commit` / `bd vc commit`, but against an external Dolt server those
|
||||
commands could not open the store to do it — the flag reached server mode and
|
||||
`newServerMode` never read it, while the field's own doc comment said "Ignored
|
||||
in server mode". That left the #4566 deadlock intact for exactly the case with
|
||||
no way out: embedded mode can move the database directory aside and
|
||||
`bd bootstrap`, and there is no equivalent against a shared server. Fixed by
|
||||
@Toady00 (#5783, #5781).
|
||||
|
||||
- **`bd bootstrap` probes git remotes for Dolt data instead of rejecting them
|
||||
outright** (#6037, #5743, #5663). `bd init` deliberately persists a
|
||||
git-origin-derived `sync.remote` into the tracked `.beads/config.yaml` — a git
|
||||
origin is a valid Dolt remote before `refs/dolt/data` exists, because the first
|
||||
`bd dolt push` creates that ref on the same remote — but bootstrap classified
|
||||
those URLs as code-repo URLs and returned before the origin auto-detect that
|
||||
would have hydrated the clone, `git+https://` and `git+ssh://` included.
|
||||
Committed `sync.remote` values from earlier releases hydrate again. The failure
|
||||
was silent because one outcome code covered both "a database already exists,
|
||||
nothing to do" and "I refused and left you with nothing": bootstrap printed
|
||||
`✓ Database already exists`, exited 0, and created nothing, after which
|
||||
`bd init --reinit-local` pointed back at `bd bootstrap` in a closed loop.
|
||||
Bootstrap now exits non-zero whenever it declines to set up a database.
|
||||
|
||||
- **`--set-metadata` again stores numbers/booleans/null as typed JSON scalars**
|
||||
(v1.2.2 behavior); string-forcing lives on `--metadata-json`. Values written by
|
||||
in-window dev builds are left as strings; re-apply the flag to retype a key.
|
||||
|
||||
- **`bd create --json` (and `POST /v0/beads/issues`) again echo sub-second
|
||||
RFC3339Nano timestamps**; reads (`show`/`list`) remain second-precision as in
|
||||
v1.2.2.
|
||||
|
||||
- **`bd purge` and `bd prune` select candidates by TIER, so a typed wisp is
|
||||
ephemeral however it was minted**
|
||||
([#5995](https://github.com/gastownhall/beads/pull/5995)). The two sweeps
|
||||
split the world between them — `bd purge` clears the ephemeral tier, `bd
|
||||
prune` the durable one — but membership was decided by the raw `ephemeral`
|
||||
column, and a wisp minted before that column was set carried a `wisp_type`
|
||||
with `ephemeral = 0`. Such a bead belonged to neither sweep: `bd purge`
|
||||
reported "No closed ephemeral beads to purge" while `bd prune` skipped it as
|
||||
a wisp. One production database had 858 such rows / 7.3 MB that no sweep
|
||||
could ever reach. The tiers are now complementary predicates over both
|
||||
columns — ephemeral is `ephemeral = 1 OR wisp_type` is non-empty, durable is
|
||||
its exact complement — evaluated across both planes rather than taking the
|
||||
wisps-plane fast path, because legacy typed wisps live in the `issues` table.
|
||||
A non-empty `wisp_type` now also implies ephemeral at mint, on every create
|
||||
path, so no new bead can land in the gap. **A previously unreachable typed
|
||||
wisp is now a `bd purge` candidate**, so the first purge after upgrade may
|
||||
clear considerably more than usual. NoHistory beads (wisps plane, no
|
||||
`wisp_type`) stay durable-tier, unchanged.
|
||||
|
||||
- **`bd prime` says when it could NOT read the memory plane**
|
||||
([#5877](https://github.com/gastownhall/beads/issues/5877)). A broken or
|
||||
unreachable store made prime omit the memory section entirely, so a session
|
||||
|
|
@ -258,9 +729,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
`EmbeddedDoltStore` implements neither `DiffStore` nor `StateHasher`, so in
|
||||
the default embedded mode the incremental path is inert (`incremental
|
||||
skipped — store does not implement DiffStore`) and every cycle is still a
|
||||
full export. The deletion-proof guard below is likewise server-mode only, so
|
||||
[#5896](https://github.com/gastownhall/beads/issues/5896) stays open for
|
||||
embedded mode, where `bd delete` still wedges auto-export.
|
||||
full export. The deletion-proof guard below started out server-mode only for
|
||||
the same reason; [#5896](https://github.com/gastownhall/beads/issues/5896) is
|
||||
now closed for embedded mode too — see the store-history heal entry below.
|
||||
|
||||
**Caveat: the diff anchor only advances on real commits.** In server mode
|
||||
dolt auto-commit is off, so with no commits being made the anchor stays put
|
||||
|
|
@ -400,8 +871,85 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
`ParentID`. Programmatic callers that set them got unfiltered results back and
|
||||
no error — a full list where a scoped one was asked for.
|
||||
|
||||
- Proxied-server mode (and `bd serve`) ran schema migrations on every store
|
||||
open without consulting any migration gate, so an upgraded client silently
|
||||
migrated a shared database — including from read-only commands. The gate now
|
||||
runs on that path too: read commands warn and continue on the current
|
||||
schema, writes refuse, and `bd serve` fails to start until the schema is
|
||||
reconciled. (#5043)
|
||||
|
||||
- `bd migrate schema` now works in proxied-server mode instead of refusing.
|
||||
The migration runs during the provider open under the verb's consent. (#5043)
|
||||
|
||||
- Migration-gate and schema-skew failures on the proxied open path and at
|
||||
`bd serve` startup now print their full actionable block instead of a
|
||||
single truncated line. (#5043)
|
||||
|
||||
- **`bd doctor` now honors strict `--readonly` and the migration freeze**
|
||||
(#6028). `bd doctor --fix` / `--clean` refuse to mutate under either gate —
|
||||
the freeze refusal exits 14 and names the marker, and there is no doctor-side
|
||||
override — and plain `bd doctor` diagnosis no longer rewrites `.local_version`
|
||||
or auto-applies schema migrations while a freeze is active or `--readonly` is
|
||||
set; it reports the pending migration instead. Both gates key on the directory
|
||||
doctor was pointed at, not just the one it was launched in. Diagnosis itself
|
||||
keeps working under a freeze.
|
||||
|
||||
- **An externally-managed Dolt sql-server is no longer mistaken for bd's own**,
|
||||
which had silently disarmed the shared-store migrate gate (#6118). When the
|
||||
port arrived from `BEADS_DOLT_SERVER_PORT`, from `bd init --server-port`, or
|
||||
from a stale port file left by a server that had since died, bd classified a
|
||||
genuinely shared server as workspace-owned and migrated its schema in place —
|
||||
no prompt, no warning, exit 0 — after which every older client on that server
|
||||
was hard-refused with `schema version mismatch`. Ownership is now *proven*
|
||||
from bd's own live port and PID record rather than inferred from how the
|
||||
endpoint was named: bd must have bound that port and the process answering it
|
||||
must still be alive. Everything else is shared, and stays gated.
|
||||
|
||||
- **A `dolt.mode: server` workspace declared in `.beads/config.yaml` is no
|
||||
longer refused as a legacy workspace** (#6119). The upgrade guard resolved the
|
||||
connection mode from `metadata.json` alone, so a workspace that names its mode
|
||||
only in config.yaml fell through to the embedded arm and was refused outright
|
||||
— including workspaces this release had just created and was already
|
||||
operating on. The guard now resolves the mode through the same
|
||||
`IsDoltServerMode` precedence chain the rest of bd uses, and a
|
||||
`.local_version` witness naming bd 1.0 or later vetoes the legacy verdict in
|
||||
every mode rather than only in server mode.
|
||||
|
||||
- **A server-mode workspace with no `metadata.json` no longer opens a phantom
|
||||
embedded database** and answers `bd list` with a false-empty result and exit 0
|
||||
(#6120). Config substitution now gates on `IsDoltServerMode`, and
|
||||
`BEADS_DOLT_SERVER_MODE` is honored on that path instead of being ignored.
|
||||
|
||||
### Security
|
||||
|
||||
- **Release binaries now build with Go 1.26.7** instead of 1.26.5, closing seven
|
||||
standard-library advisories reachable from `bd`: quadratic `net/url` path
|
||||
resolution, `html/template` JavaScript-regexp context tracking, unbounded
|
||||
post-handshake `crypto/tls` messages, a missing `ReadHeaderTimeout` on
|
||||
`net/http`'s unencrypted HTTP/2 check, unbounded recursion in `encoding/xml`
|
||||
and `encoding/asn1`, and the `x/net/idna` Punycode bug in `net/http`'s
|
||||
vendored copy. `bd serve` and bd's outbound TLS calls exercise these paths.
|
||||
The `go` directive stays at 1.26.5, so nothing changes for code importing the
|
||||
beads module.
|
||||
|
||||
- **Dependency bumps clearing all 25 open advisories.** `golang.org/x/crypto`
|
||||
0.55.0, `golang.org/x/mod` 0.40.0, `klauspost/compress` 1.18.7,
|
||||
`moby/go-archive` 0.3.3, `kin-openapi` 0.144.0 with `oapi-codegen` 2.7.1, and
|
||||
a refreshed `integrations/beads-mcp/uv.lock`. None of the fixed code was
|
||||
reachable from the shipped `bd` binary: the go-archive and x/crypto/ssh paths
|
||||
are testcontainers-only, the compress bug is in the `s2` codec bd does not
|
||||
link, and the kin-openapi critical is in `openapi3filter` middleware that
|
||||
enters the graph only through the `tool` directive for spec codegen. No
|
||||
behavior change; no dolt bump was required.
|
||||
|
||||
### Documentation
|
||||
|
||||
- **Known limitation: multi-rig prefix routing (`routes.jsonl`) is not
|
||||
supported with proxied-server rigs** — cross-rig bead gates stay pending,
|
||||
`bd close` of a bead gate in proxied-server mode requires `bd gate check`
|
||||
or `--force`, and routed lookups cannot open proxied-server targets
|
||||
(#5861).
|
||||
|
||||
- **The heartbeat/re-home invariant and the two states it can strand are now
|
||||
documented where the code lives** (wy-sp2l4): a heartbeat proves the holder
|
||||
is alive, not that the lease moved, so `granted_node` is backfilled but never
|
||||
|
|
@ -444,53 +992,6 @@ stopgap (`BD_IGNORE_SCHEMA_SKEW=1`).
|
|||
`go install github.com/steveyegge/beads/cmd/bd@latest` resolves to this
|
||||
release instead of the accidental one. (The retract block is also
|
||||
carried on main so future tags keep the retractions.)
|
||||
- **`sort` on `GET /v0/beads/issues`.** The listing served one order —
|
||||
`(created_at DESC, id ASC)` — because the cursor is a keyset position in it,
|
||||
and the spec said so in its own words: "the sort order is welded to the cursor
|
||||
contract, and a new order needs new surface." The cost of that welding fell on
|
||||
every client that wanted `bd list`'s ordering, because the only way to get it
|
||||
was to page the whole result set and re-sort locally. Measured over a
|
||||
1400-row store at the 200-row page an HTTP client actually uses, that is
|
||||
**7 requests plus a client-side comparator; `?sort=priority` is 1**
|
||||
(`TestProxiedServerListSortRetiresTheWalk`, which runs both strategies against
|
||||
a real `bd serve` and checks both against `bd list --json` row for row). It is
|
||||
the one cost on this surface that got worse as a project grew.
|
||||
|
||||
**Two values, and the set is closed.** `created` is the existing order, now
|
||||
spellable. `priority` is `(priority ASC, created_at DESC, id ASC)` — `bd
|
||||
list`'s flagless ordering, which is also what `bd list --sort priority`
|
||||
produces, so one served order retires the walk for both. The other seven
|
||||
orders `bd list --sort` takes are not offered: each value here is a cursor
|
||||
contract needing a key proven total, and `id` is a natural-numeric order no
|
||||
database expresses, `updated` moves on every write, `closed` is nullable, and
|
||||
`status`/`title`/`type`/`assignee` are mutable and unindexed.
|
||||
|
||||
**Absent `sort` still means `created`, permanently.** It is the compatibility
|
||||
contract for every client written before the parameter existed; changing it
|
||||
would alter which rows a truncated page contains, with no error to notice it
|
||||
by. A server that predates the parameter answers `param: "sort"` with
|
||||
`reason: "unknown_parameter"`, which is the per-parameter capability probe a
|
||||
client dispatches on to fall back.
|
||||
|
||||
**The cursor now carries its order, and a mismatch is refused.** This is the
|
||||
half that makes the parameter safe rather than merely useful. The token was
|
||||
base64 of `{t,i}` with no binding, so a `created`-order cursor replayed under
|
||||
`sort=priority` would have decoded perfectly and been read as a position in a
|
||||
different total order — a page that both skips and duplicates rows, served
|
||||
with a 200, undetectable by the client. Tokens are now `v2` with an explicit
|
||||
order member and decode refuses any token whose order differs from the
|
||||
request's, as `invalid_cursor` (documented recovery: restart paging).
|
||||
Outstanding `v1` tokens stay readable as the `created`-order positions they
|
||||
are, so **no traversal in flight has to restart**. This does not contradict
|
||||
"the token carries no filters": filters select the set, the order decides what
|
||||
the position means.
|
||||
|
||||
**`priority` is a mutable key**, which `created_at` is not, and the spec says
|
||||
so: under `created` only new rows move relative to a walk, while a priority
|
||||
update moves an existing row too, so it can be seen twice or missed. That is
|
||||
the already-documented "a cursor pins a position, not a snapshot" caveat
|
||||
reached by a second route, not a new class of error — unchanged data never
|
||||
skips or repeats under either order.
|
||||
|
||||
## [1.2.1] - 2026-08-11
|
||||
|
||||
|
|
@ -2781,27 +3282,6 @@ remote-migrate gate from a blunt block into a state-aware one.
|
|||
|
||||
### Fixed
|
||||
|
||||
- **Explicit external capability dependencies now block embedded ready work
|
||||
and appear in dependency trees.** References such as
|
||||
`external:payments:checkout` were stored in `depends_on_external` but then
|
||||
dropped by local-issue hydration, so their source still appeared in
|
||||
`bd ready` and `bd dep tree` omitted the edge. Beads now resolves configured
|
||||
foreign projects read-only at query time, excludes unsatisfied sources
|
||||
before ready pagination and atomic claim selection, includes the refs in
|
||||
blocked output, and renders them as synthetic blocked/closed tree leaves.
|
||||
|
||||
- **`--label-any` is no longer silently dropped by `bd ready` and
|
||||
`bd ready --claim`.** The ready-work WHERE builder emitted clauses for
|
||||
`--label` and `--exclude-label` but none for `--label-any`, so the OR-set
|
||||
filter was ignored on the ready/claim path (with or without `--parent`) on
|
||||
every backend — while `bd list`/`bd search` honored it. On an *atomic claim*
|
||||
this was dangerous rather than merely wrong: a worker fencing itself to its
|
||||
own lane (`bd ready --claim --label-any lane-a --parent epic-1`) would
|
||||
happily claim another lane's issue and believe it was fenced. `--label-any`
|
||||
now emits an OR-set membership clause that AND-combines with `--label`,
|
||||
`--exclude-label`, and `--parent`, exactly as the flag help promises; an
|
||||
exhausted lane now claims nothing instead of falling back to unfenced work.
|
||||
|
||||
- **A failed v53 migration no longer traps the database, and the v53 repair
|
||||
now covers `wisp_dependencies` split-column drift.** rc.2 repaired the
|
||||
`issues` rig columns, but a database coming from schema v49 could still fail
|
||||
|
|
|
|||
10
Makefile
10
Makefile
|
|
@ -75,8 +75,16 @@ export CGO_ENABLED := 1
|
|||
# When go.mod requires a newer Go version than the locally installed one,
|
||||
# GOTOOLCHAIN=auto downloads the right compiler but coverage instrumentation
|
||||
# may still use the local toolchain's compile tool, causing version mismatch.
|
||||
# Force the go.mod version to ensure all tools match.
|
||||
# Force one exact version so all tools match.
|
||||
#
|
||||
# The `toolchain` directive wins over the `go` directive when present: `go` is
|
||||
# the floor we promise importers, `toolchain` is what we actually build with,
|
||||
# and reading `go` here would silently downgrade every make target below the
|
||||
# toolchain the release binaries are built with.
|
||||
GO_VERSION := $(shell sed -n 's/^toolchain go//p' go.mod)
|
||||
ifeq ($(GO_VERSION),)
|
||||
GO_VERSION := $(shell sed -n 's/^go //p' go.mod)
|
||||
endif
|
||||
ifneq ($(GO_VERSION),)
|
||||
export GOTOOLCHAIN := go$(GO_VERSION)
|
||||
endif
|
||||
|
|
|
|||
398
RELEASING.md
398
RELEASING.md
|
|
@ -6,13 +6,16 @@ This document describes the complete release process for beads, including GitHub
|
|||
|
||||
- [Overview](#overview)
|
||||
- [Prerequisites](#prerequisites)
|
||||
- [Release Branches](#release-branches)
|
||||
- [Release Checklist](#release-checklist)
|
||||
- [1. Prepare Release](#1-prepare-release)
|
||||
- [2. GitHub Release](#2-github-release)
|
||||
- [3. Homebrew Update](#3-homebrew-update)
|
||||
- [4. PyPI Release (MCP Server)](#4-pypi-release-mcp-server)
|
||||
- [5. npm Package Release](#5-npm-package-release)
|
||||
- [6. Verify Release](#6-verify-release)
|
||||
- [5. Plugin Marketplace Update](#5-plugin-marketplace-update)
|
||||
- [6. npm Package Release](#6-npm-package-release)
|
||||
- [7. Verify Release](#7-verify-release)
|
||||
- [Version Numbering](#version-numbering)
|
||||
- [Prerelease / Release Candidate (RC) Workflow](#prerelease--release-candidate-rc-workflow)
|
||||
- [Hotfix Releases](#hotfix-releases)
|
||||
- [Rollback Procedure](#rollback-procedure)
|
||||
|
|
@ -28,17 +31,21 @@ A beads release involves multiple distribution channels:
|
|||
|
||||
### The Easy Way (Recommended)
|
||||
|
||||
For routine releases, use the fully automated release script:
|
||||
For routine releases, run the release molecule:
|
||||
|
||||
```bash
|
||||
./scripts/release.sh 0.22.0
|
||||
bd mol wisp beads-release --var version=1.3.0
|
||||
```
|
||||
|
||||
This handles version bump, tests, git tag, Homebrew update, and local
|
||||
installation in one shot. See [scripts/README.md](scripts/README.md#releasesh--the-easy-button)
|
||||
for details. The rest of this document is the manual / step-by-step process,
|
||||
useful for understanding what `release.sh` does and for handling edge cases
|
||||
(hotfixes, rollbacks, manual PyPI/npm publishes).
|
||||
`.beads/formulas/beads-release.formula.toml` defines the whole flow as
|
||||
resumable steps with a CI gate: preflight → CHANGELOG/`info.go` →
|
||||
version bump → commit/tag/push → gate on `release.yml` → verify
|
||||
GitHub/npm/PyPI/Homebrew → local install. `./scripts/release.sh 1.3.0` is a
|
||||
thin gateway that prints this command; it does not run a release itself.
|
||||
|
||||
The rest of this document is the manual / step-by-step process, useful for
|
||||
understanding what the molecule does and for handling edge cases (hotfixes,
|
||||
rollbacks, manual PyPI/npm publishes).
|
||||
|
||||
## Prerequisites
|
||||
|
||||
|
|
@ -79,21 +86,105 @@ python3 --version
|
|||
twine --version
|
||||
```
|
||||
|
||||
## Release Branches
|
||||
|
||||
Releases are cut from a `release/x.y.z` branch, not from whatever `main`
|
||||
happens to be when the tag is pushed. `main` moves continuously and the
|
||||
release-critical gates do not all run on every PR, so "tag the tip of main"
|
||||
means tagging a SHA nobody has fully tested. A burned tag is never reused
|
||||
(the v1.1.1 and v1.2.0 precedents), so that gamble is expensive.
|
||||
|
||||
**Cut the branch from a SHA that is green on both `Main` and
|
||||
`Nightly Full Tests`.** The `Main` workflow runs on push to `main` and the
|
||||
`Nightly Full Tests` workflow runs on a 2am UTC schedule, so the newest SHA
|
||||
with both is usually a few hours behind the tip:
|
||||
|
||||
```bash
|
||||
gh run list --workflow Main --branch main --status success --limit 5 \
|
||||
--json headSha,conclusion,createdAt
|
||||
gh run list --workflow "Nightly Full Tests" --status success --limit 3 \
|
||||
--json headSha,conclusion,createdAt
|
||||
|
||||
git fetch origin
|
||||
git branch release/1.3.0 <the-green-sha>
|
||||
git push origin release/1.3.0
|
||||
```
|
||||
|
||||
**Everything targeted at the release lands on the release branch as a PR.**
|
||||
Base the PR on `release/x.y.z`, not `main`, and label it
|
||||
`status/needs-review-auto` so it goes through the automated review workflow
|
||||
like any other change. That includes the release-prep PR itself (version
|
||||
bump, CHANGELOG, `cmd/bd/info.go`) and any fix the release validation turns
|
||||
up. Nothing is pushed straight to the release branch.
|
||||
|
||||
**Tag from the release branch**, following [1. Prepare Release](#1-prepare-release)
|
||||
onward with the branch checked out in place of `main`.
|
||||
|
||||
**Forward-port to `main` after the release ships.** Every commit that landed
|
||||
only on the release branch — the version bump included — needs a PR back to
|
||||
`main`, or the next release silently drops it and the version files disagree
|
||||
with the newest tag. Do this as one PR immediately after the tag is pushed,
|
||||
while the set of release-only commits is still obvious:
|
||||
|
||||
```bash
|
||||
git log --oneline main..release/1.3.0
|
||||
```
|
||||
|
||||
(See PR #5782 for the shape of a forward-port PR.)
|
||||
|
||||
## Release Checklist
|
||||
|
||||
Before starting a release:
|
||||
|
||||
- [ ] `release/x.y.z` branch cut from a SHA green on `Main` **and**
|
||||
`Nightly Full Tests` (see [Release Branches](#release-branches))
|
||||
- [ ] All tests passing (`go test ./...`)
|
||||
- [ ] npm package tests passing (`cd npm-package && npm run test:all`)
|
||||
- [ ] **Upgrade smoke tests pass** (`make test-upgrade`) — see [Release Stability Gate](engdocs/RELEASE-STABILITY-GATE.md)
|
||||
- [ ] **Regression tests pass** (`make test-regression`)
|
||||
- [ ] **Every release target cross-compiles** — see
|
||||
[Cross-compile before tagging](#cross-compile-before-tagging). PR CI does
|
||||
not build them ([#5662](https://github.com/gastownhall/beads/issues/5662)),
|
||||
and a target that fails at tag time burns the tag.
|
||||
- [ ] **CHANGELOG.md updated with release notes** (see format below)
|
||||
- [ ] **CHANGELOG rollup checked** — nothing left under `[Unreleased]` that
|
||||
belongs in this release, and nothing filed under a *previous* release's
|
||||
section that shipped after that tag. Verify with
|
||||
`git merge-base --is-ancestor <commit> <previous-tag>` when in doubt.
|
||||
- [ ] **`cmd/bd/info.go` `versionChanges` entry added** for this version
|
||||
- [ ] **Breaking changes documented** with migration steps and recovery instructions
|
||||
- [ ] **Docs cutover planned** — `docs/cli-docs.pin` bump plus
|
||||
`./scripts/generate-cli-docs.sh`, and the release line on the docs
|
||||
homepage (`docs/index.md`). See
|
||||
[Documentation Site (Mintlify)](#documentation-site-mintlify).
|
||||
- [ ] `./scripts/check-versions.sh` passes
|
||||
- [ ] No uncommitted changes
|
||||
- [ ] On `main` branch and up to date with origin
|
||||
- [ ] On the `release/x.y.z` branch and up to date with origin
|
||||
|
||||
### Cross-compile before tagging
|
||||
|
||||
`.goreleaser.yml` builds darwin, linux, windows **and freebsd**, but PR CI
|
||||
builds none of the cross targets — the v1.2.0 tag burned on a freebsd
|
||||
compilation failure that no pre-tag gate could have caught
|
||||
([#5661](https://github.com/gastownhall/beads/pull/5661) fixed the break,
|
||||
[#5662](https://github.com/gastownhall/beads/issues/5662) tracks the CI gap).
|
||||
Until that gap is closed, build them by hand before tagging:
|
||||
|
||||
```bash
|
||||
goreleaser build --snapshot --clean
|
||||
```
|
||||
|
||||
A failure here costs a rebase. The same failure after the tag is pushed costs
|
||||
the tag.
|
||||
|
||||
## 1. Prepare Release
|
||||
|
||||
> The snippets below say `main` where they mean "the branch you are releasing
|
||||
> from". Since [Release Branches](#release-branches), that is `release/x.y.z`:
|
||||
> substitute it for `main` in every `git push` and `git checkout` here, and
|
||||
> land the changes as a PR against the release branch rather than pushing
|
||||
> directly.
|
||||
|
||||
### Update CHANGELOG.md
|
||||
|
||||
**IMPORTANT: Do this FIRST before running bump-version script.**
|
||||
|
|
@ -117,58 +208,86 @@ Add release notes to CHANGELOG.md:
|
|||
- Changed behavior of B (migration guide)
|
||||
```
|
||||
|
||||
Commit the CHANGELOG changes:
|
||||
Commit the CHANGELOG changes and open a PR against the release branch:
|
||||
|
||||
```bash
|
||||
git add CHANGELOG.md
|
||||
git commit -m "docs: Add CHANGELOG entry for v0.22.0"
|
||||
git push origin main
|
||||
git checkout -b release-prep/v0.22.0
|
||||
git push -u origin release-prep/v0.22.0
|
||||
gh pr create --base release/0.22.0 --label status/needs-review-auto
|
||||
```
|
||||
|
||||
### Update Version and Create Release Tag
|
||||
|
||||
Use the version bump script to update all version references and create the release tag:
|
||||
`./scripts/update-versions.sh` rewrites every version reference in one pass.
|
||||
It does no git operations — commit, tag and push are yours. (`bump-version.sh`
|
||||
is retired; it now only prints a pointer here.)
|
||||
|
||||
```bash
|
||||
# Dry run - shows what will change
|
||||
./scripts/bump-version.sh 0.22.0
|
||||
|
||||
# Full release with all local installations
|
||||
./scripts/bump-version.sh 0.22.0 --commit --tag --push --all
|
||||
./scripts/update-versions.sh 0.22.0
|
||||
./scripts/check-versions.sh # must pass before you commit
|
||||
```
|
||||
|
||||
**Available flags:**
|
||||
|
||||
| Flag | Description |
|
||||
|------|-------------|
|
||||
| `--commit` | Create a git commit with version changes |
|
||||
| `--tag` | Create annotated git tag (requires --commit) |
|
||||
| `--push` | Push commit and tag to origin (requires --tag) |
|
||||
| `--install` | Build and install bd to `~/go/bin` AND `~/.local/bin` |
|
||||
| `--mcp-local` | Install beads-mcp from local source via uv/pip |
|
||||
| `--upgrade-mcp` | Upgrade beads-mcp from PyPI (after PyPI publish) |
|
||||
| `--restart-servers` | Restart all Dolt servers to pick up new version |
|
||||
| `--all` | Shorthand for `--install --mcp-local --restart-servers` |
|
||||
|
||||
This updates:
|
||||
- `cmd/bd/version.go` - CLI version constant
|
||||
- `integrations/beads-mcp/pyproject.toml` - MCP server version
|
||||
- `integrations/beads-mcp/src/beads_mcp/__init__.py` - MCP Python version
|
||||
- `plugins/beads/.claude-plugin/plugin.json` - Claude plugin version
|
||||
- `plugins/beads/.codex-plugin/plugin.json` - Codex plugin version
|
||||
- `.claude-plugin/marketplace.json` - Claude marketplace version
|
||||
- `npm-package/package.json` - npm package version
|
||||
- `cmd/bd/templates/hooks/*` - Git hook versions
|
||||
- `README.md` - Documentation version
|
||||
- `PLUGIN.md` - Version requirements
|
||||
- `CHANGELOG.md` - Creates release entry from [Unreleased]
|
||||
- `cmd/bd/version.go` — CLI version constant. This is the canonical version:
|
||||
`check-versions.sh` reads it and compares the gated files against it. Note
|
||||
that "gated" is narrower than "updated" — `default.nix` and `README.md` are
|
||||
bumped here but checked by nothing, so eyeball them.
|
||||
- `integrations/beads-mcp/pyproject.toml` — MCP server version
|
||||
- `integrations/beads-mcp/src/beads_mcp/__init__.py` — MCP Python version
|
||||
- `integrations/beads-mcp/uv.lock` — the `beads-mcp` pin, via `uv lock`. A
|
||||
stale lock fails the release workflow's MCP gate *after* the tag exists and
|
||||
can no longer be rewritten; that burned the v1.1.1 tag. Install `uv` before
|
||||
bumping, or the script warns and skips it.
|
||||
- `plugins/beads/.claude-plugin/plugin.json` — Claude plugin version
|
||||
- `plugins/beads/.codex-plugin/plugin.json` — Codex plugin version
|
||||
- `plugins/beads/.copilot-plugin/plugin.json` — Copilot plugin version
|
||||
- `.claude-plugin/marketplace.json` — Claude marketplace version
|
||||
- `npm-package/package.json` — npm package version
|
||||
- `.githooks/*` — the `BEGIN`/`END BEADS INTEGRATION v<version>` markers on the
|
||||
tracked managed hook sections, held byte-equal to the `cmd/bd/hooks.go`
|
||||
generator by `TestTrackedManagedHookSectionsMatchGenerator`. Skipping them
|
||||
reddens the branch only after the push (that was the v1.2.0 bump).
|
||||
- `default.nix` — Nix package version
|
||||
- `cmd/bd/winres/winres.json`, `cmd/bd/winres/manifest.xml` — Windows PE
|
||||
resource metadata (the numeric fields take the base version, with any
|
||||
prerelease suffix stripped)
|
||||
- `README.md` — the static Alpha version badge, if one is present
|
||||
|
||||
The `--commit --tag --push` flags will:
|
||||
1. Create a git commit with all version changes
|
||||
2. Create an annotated tag `v0.22.0`
|
||||
3. Push both commit and tag to origin
|
||||
It does **not** touch `CHANGELOG.md`, `cmd/bd/info.go`, or `default.nix`'s
|
||||
`vendorHash`. Write the release notes first (above), and run
|
||||
`./scripts/update-nix-vendorhash.sh` if `go.mod`/`go.sum` changed since the
|
||||
last tag.
|
||||
|
||||
This triggers GitHub Actions to build release artifacts automatically.
|
||||
Then commit and land it as a PR — **not** a direct push, and **do not tag
|
||||
yet**:
|
||||
|
||||
```bash
|
||||
git add -A
|
||||
git commit -m "chore: bump version to 0.22.0"
|
||||
git checkout -b release-prep/v0.22.0
|
||||
git push -u origin release-prep/v0.22.0
|
||||
gh pr create --base release/0.22.0 --label status/needs-review-auto
|
||||
```
|
||||
|
||||
Tag only after that PR merges, and tag the **merged** commit:
|
||||
|
||||
```bash
|
||||
git checkout release/0.22.0 && git pull
|
||||
git tag -a v0.22.0 -m "Release v0.22.0"
|
||||
git push origin v0.22.0
|
||||
```
|
||||
|
||||
Two reasons the order matters, both of which have teeth. With branch
|
||||
protection on, a direct push to the release branch is rejected — after you
|
||||
have already minted the tag locally. And with a squash merge, a tag created
|
||||
before the merge points at a commit that is not an ancestor of
|
||||
`release/x.y.z`; goreleaser packages `CHANGELOG.md` *from the tag* into every
|
||||
published archive, so the release would ship the pre-review notes.
|
||||
|
||||
Pushing the tag triggers GitHub Actions to build release artifacts
|
||||
automatically.
|
||||
|
||||
The tag workflow re-runs release-critical package gates before publishing:
|
||||
|
||||
|
|
@ -186,12 +305,14 @@ release.
|
|||
```bash
|
||||
# 1. Update CHANGELOG.md and cmd/bd/info.go with release notes (manual step)
|
||||
|
||||
# 2. Bump version and install everything locally
|
||||
./scripts/bump-version.sh 0.22.0 --commit --all
|
||||
# 2. Bump versions and verify
|
||||
./scripts/update-versions.sh 0.22.0
|
||||
./scripts/check-versions.sh
|
||||
|
||||
# 3. Test locally, then tag and push
|
||||
# 3. Land it on the release branch as a PR (label status/needs-review-auto)
|
||||
|
||||
# 4. Test locally, then tag the merged commit and push
|
||||
git tag -a v0.22.0 -m "Release v0.22.0"
|
||||
git push origin main
|
||||
git push origin v0.22.0
|
||||
```
|
||||
|
||||
|
|
@ -199,18 +320,6 @@ The release workflow is intentionally gated to `refs/tags/v*`. A manual
|
|||
workflow dispatch from a branch will skip publishing jobs; manual reruns must
|
||||
select the release tag.
|
||||
|
||||
**Alternative (step-by-step):**
|
||||
|
||||
```bash
|
||||
# Just commit
|
||||
./scripts/bump-version.sh 0.22.0 --commit
|
||||
|
||||
# Then manually tag and push
|
||||
git tag -a v0.22.0 -m "Release v0.22.0"
|
||||
git push origin main
|
||||
git push origin v0.22.0
|
||||
```
|
||||
|
||||
## 2. GitHub Release
|
||||
|
||||
### Using GoReleaser (Recommended)
|
||||
|
|
@ -383,19 +492,33 @@ top-level CLI commands" passes vacuously for it, e.g. wy-gx5rj for `bd
|
|||
sync`). Bump it as part of THIS release, not a follow-up:
|
||||
|
||||
```bash
|
||||
# After tagging (see "Update Version and Create Release Tag" above):
|
||||
# After tagging (see "Update Version and Create Release Tag" above).
|
||||
# generate-cli-docs.sh builds bd from the pinned tag, so the tag must exist.
|
||||
echo "v0.22.0" > docs/cli-docs.pin
|
||||
./scripts/generate-cli-docs.sh
|
||||
git add docs/cli-docs.pin docs/CLI_REFERENCE.md docs/cli-reference docs/docs.json
|
||||
git commit -m "docs: bump CLI docs pin to v0.22.0"
|
||||
git push origin main
|
||||
```
|
||||
|
||||
The pin bump lands on `main`, since that is where Mintlify deploys from — fold
|
||||
it into the forward-port PR described in [Release Branches](#release-branches)
|
||||
rather than pushing it to the release branch (or to `main`) directly.
|
||||
|
||||
Skipping this step doesn't fail fast — Check 4 stays green (it validates
|
||||
against the *old* pin) until the next bump, at which point every command
|
||||
added across the skipped releases shows up at once as a pile of "missing
|
||||
from docs/CLI_REFERENCE.md" failures with no obvious release to blame.
|
||||
|
||||
**The docs homepage names the release line, and it is hand-maintained.**
|
||||
`docs/index.md` carries a line of the form "These docs are for the X.Y.Z
|
||||
release of beads" with a link to that tag's release notes. Nothing generates
|
||||
or validates it, so it goes stale silently — it still said 1.1.0 when the pin
|
||||
had already moved to v1.2.2. Update it in the same commit as the pin:
|
||||
|
||||
```bash
|
||||
rg 'These docs are for the' docs/index.md
|
||||
```
|
||||
|
||||
## 6. npm Package Release
|
||||
|
||||
The npm package wraps the native binary for Node.js environments.
|
||||
|
|
@ -416,7 +539,7 @@ npm org ls beads
|
|||
# Navigate to npm package
|
||||
cd npm-package
|
||||
|
||||
# Version should already be updated by bump-version.sh
|
||||
# Version should already be updated by update-versions.sh
|
||||
cat package.json | grep version
|
||||
|
||||
# Run all tests
|
||||
|
|
@ -525,14 +648,32 @@ curl -fsSL https://raw.githubusercontent.com/gastownhall/beads/main/scripts/inst
|
|||
bd version
|
||||
```
|
||||
|
||||
### CLI Docs Pin
|
||||
### Docs Cutover
|
||||
|
||||
```bash
|
||||
cat docs/cli-docs.pin # should be the tag just released, not an older one
|
||||
cat docs/cli-docs.pin # the tag just released, not an older one
|
||||
rg 'These docs are for the' docs/index.md # the version just released
|
||||
```
|
||||
|
||||
If it's stale, do the bump from the "Documentation Site (Mintlify)" step
|
||||
above before calling the release done.
|
||||
If either is stale, do the bump from the
|
||||
[Documentation Site (Mintlify)](#documentation-site-mintlify) step above
|
||||
before calling the release done.
|
||||
|
||||
### Release Notes Rollup
|
||||
|
||||
```bash
|
||||
# [Unreleased] should be empty, and the newest dated section is this release
|
||||
rg -n '^## \[' CHANGELOG.md | head -3
|
||||
```
|
||||
|
||||
Also confirm nothing shipped after the *previous* tag is still filed under
|
||||
that tag's section — the v1.2.2 section carried an entry for a commit that was
|
||||
never in v1.2.2, which is invisible until someone reads the release notes and
|
||||
looks for a feature their binary does not have:
|
||||
|
||||
```bash
|
||||
git merge-base --is-ancestor <commit> <previous-tag> && echo "in the tag" || echo "MISFILED"
|
||||
```
|
||||
|
||||
## Prerelease / Release Candidate (RC) Workflow
|
||||
|
||||
|
|
@ -556,32 +697,42 @@ identifier (e.g. `1.1.0-rc.1`); Python tooling normalizes this to PEP 440 form
|
|||
|
||||
### Cut an RC
|
||||
|
||||
**An RC is cut from the release branch, like everything else.** This is the
|
||||
point of an RC: it validates the SHA the stable release will ship. Tagging the
|
||||
tip of `main` instead validates a *different* SHA by construction — the stable
|
||||
tag comes off `release/x.y.z` — and re-introduces the "tag a SHA nobody has
|
||||
fully tested" failure that [Release Branches](#release-branches) exists to
|
||||
prevent. Note the branch is named for the **base** version: an RC for 1.1.0 is
|
||||
cut on `release/1.1.0`, not `release/1.1.0-rc.1`.
|
||||
|
||||
```bash
|
||||
# 0. Cut (or check out) the release branch — see Release Branches above.
|
||||
git checkout release/1.1.0
|
||||
|
||||
# 1. Update CHANGELOG.md and cmd/bd/info.go with the RC notes (manual step),
|
||||
# same as a stable release. Date the CHANGELOG section.
|
||||
|
||||
# 2. Bump versions. update-versions.sh accepts a prerelease identifier and,
|
||||
# 2. Bump versions. update-versions.sh accepts a prerelease identifier, and
|
||||
# also refreshes uv.lock (PEP 440 normalizes 1.1.0-rc.1 to 1.1.0rc1).
|
||||
./scripts/update-versions.sh 1.1.0-rc.1
|
||||
# Windows PE numeric fields (winres file_version/product_version and the
|
||||
# manifest <assemblyIdentity> version) are set to the base version 1.1.0,
|
||||
# because PE versions must be purely numeric; gen-winres.sh strips the
|
||||
# prerelease suffix the same way at build time.
|
||||
# prerelease suffix the same way at build time, and check-versions.sh
|
||||
# checks those fields against the base version for exactly this reason.
|
||||
|
||||
# 3. Keep the MCP lockfile in sync (PEP 440 normalizes to 1.1.0rc1), or the
|
||||
# Package Gate (MCP) check goes red:
|
||||
(cd integrations/beads-mcp && uv lock)
|
||||
|
||||
# 4. Validate locally.
|
||||
# 3. Validate locally.
|
||||
./scripts/check-versions.sh
|
||||
|
||||
# 5. Open a PR for the RC prep and have it reviewed. RC prep should land
|
||||
# through normal review, not auto-merge.
|
||||
# 4. Open a PR for the RC prep against release/1.1.0 and have it reviewed.
|
||||
# RC prep should land through normal review, not auto-merge.
|
||||
```
|
||||
|
||||
After the RC prep is merged to `main`, cut the tag from the merge commit:
|
||||
After the RC prep merges, cut the tag from the merged commit on the release
|
||||
branch:
|
||||
|
||||
```bash
|
||||
git checkout main && git pull
|
||||
git checkout release/1.1.0 && git pull
|
||||
git tag -a v1.1.0-rc.1 -m "Release candidate v1.1.0-rc.1"
|
||||
git push origin v1.1.0-rc.1
|
||||
```
|
||||
|
|
@ -595,36 +746,36 @@ above. Tag creation is restricted to release maintainers; see
|
|||
- Install the RC from the GitHub prerelease assets and exercise the changes it
|
||||
is gating before promoting.
|
||||
- To promote to stable, bump to the base version with no suffix
|
||||
(`./scripts/update-versions.sh 1.1.0`). The stable release **does** publish
|
||||
to Homebrew/PyPI/npm, so follow the standard
|
||||
(`./scripts/update-versions.sh 1.1.0`) **on the same release branch**, so the
|
||||
stable tag lands on the SHA the RC validated. The stable release **does**
|
||||
publish to Homebrew/PyPI/npm, so follow the standard
|
||||
[Prepare Release](#1-prepare-release) steps from there.
|
||||
|
||||
## Hotfix Releases
|
||||
|
||||
For urgent bug fixes:
|
||||
|
||||
A hotfix is a release branch cut from the tag instead of from a green `main`
|
||||
SHA; everything else — PRs against the branch, the forward-port afterwards —
|
||||
is the same as [Release Branches](#release-branches).
|
||||
|
||||
```bash
|
||||
# Create hotfix branch from tag
|
||||
git checkout -b hotfix/v0.22.1 v0.22.0
|
||||
# Create the release branch from the tag being fixed
|
||||
git checkout -b release/0.22.1 v0.22.0
|
||||
git push origin release/0.22.1
|
||||
|
||||
# Make fixes
|
||||
# ... edit files ...
|
||||
|
||||
# Bump version to 0.22.1
|
||||
./scripts/bump-version.sh 0.22.1 --commit
|
||||
# Land the fix as a PR against release/0.22.1, then bump
|
||||
./scripts/update-versions.sh 0.22.1
|
||||
./scripts/check-versions.sh
|
||||
git commit -am "chore: bump version to 0.22.1"
|
||||
|
||||
# Tag and release
|
||||
git tag -a v0.22.1 -m "Hotfix release v0.22.1"
|
||||
git push origin hotfix/v0.22.1
|
||||
git push origin release/0.22.1
|
||||
git push origin v0.22.1
|
||||
|
||||
# Follow normal release process
|
||||
goreleaser release --clean
|
||||
|
||||
# Merge back to main
|
||||
git checkout main
|
||||
git merge hotfix/v0.22.1
|
||||
git push origin main
|
||||
# Forward-port the fix AND the version bump to main
|
||||
git log --oneline main..release/0.22.1
|
||||
```
|
||||
|
||||
## Rollback Procedure
|
||||
|
|
@ -715,13 +866,10 @@ After a successful release:
|
|||
|
||||
1. **Upgrade local beads-mcp installation** to the new version:
|
||||
```bash
|
||||
# Option 1: Use the bump-version.sh script (recommended during version bump)
|
||||
./scripts/bump-version.sh <version> --upgrade-mcp
|
||||
|
||||
# Option 2: Manual upgrade via pip (if installed globally)
|
||||
# If installed globally
|
||||
pip install --upgrade beads-mcp
|
||||
|
||||
# Option 3: Manual upgrade via uv tool (if installed as a tool)
|
||||
# If installed as a uv tool
|
||||
uv tool upgrade beads-mcp
|
||||
|
||||
# Verify the new version
|
||||
|
|
@ -731,20 +879,17 @@ After a successful release:
|
|||
# The MCP server will load the newly installed version
|
||||
```
|
||||
|
||||
**Note:** The `--upgrade-mcp` flag can be combined with other flags:
|
||||
```bash
|
||||
# Update versions, commit, install bd binary, and upgrade beads-mcp all at once
|
||||
./scripts/bump-version.sh 0.24.3 --commit --install --upgrade-mcp
|
||||
```
|
||||
2. **Forward-port the release branch to `main`** — see
|
||||
[Release Branches](#release-branches). Include the `docs/cli-docs.pin` bump
|
||||
and the `docs/index.md` release line.
|
||||
|
||||
2. **Verify the upgraded CLI**:
|
||||
3. **Verify the upgraded CLI**:
|
||||
```bash
|
||||
bd version
|
||||
bd doctor quick
|
||||
```
|
||||
|
||||
3. **Announce** on relevant channels (Twitter, blog, etc.)
|
||||
4. **Update documentation** if needed
|
||||
4. **Announce** on relevant channels (Twitter, blog, etc.)
|
||||
5. **Close milestone** on GitHub if using milestones
|
||||
6. **Update project board** if using project management
|
||||
7. **Monitor** for issues in the first 24-48 hours
|
||||
|
|
@ -793,13 +938,38 @@ goreleaser build --snapshot --clean
|
|||
|
||||
Beads follows [Semantic Versioning](https://semver.org/):
|
||||
|
||||
- **MAJOR** (x.0.0): Breaking changes
|
||||
- **MINOR** (0.x.0): New features, backwards compatible
|
||||
- **PATCH** (0.0.x): Bug fixes, backwards compatible
|
||||
- **MAJOR** (x.0.0): Removals and incompatible interface changes — a command,
|
||||
flag, config key, schema table or published Go API that is deleted or
|
||||
changes shape such that a caller written against the old one cannot be
|
||||
fixed by changing its inputs.
|
||||
- **MINOR** (0.x.0): New features, plus **documented behavioral changes that
|
||||
ship with migration notes**. A command that starts refusing input it used to
|
||||
accept, changes a default, or changes which rows it returns is a minor bump
|
||||
when the change is written up in CHANGELOG.md with the migration step and
|
||||
the opt-out. It is not a major bump: the interface is unchanged and the
|
||||
caller keeps working after a documented adjustment.
|
||||
- **PATCH** (0.0.x): Bug fixes, no behavioral change beyond the bug.
|
||||
|
||||
The MINOR clause is a description of practice, not a loophole. It carries an
|
||||
obligation: every behavioral break in a minor release must appear in
|
||||
CHANGELOG.md under that release, name its override or migration step, and be
|
||||
summarized in `cmd/bd/info.go` so `bd info --whats-new` surfaces it to agents.
|
||||
A behavioral break that is *not* documented that way is a bug in the release,
|
||||
not a minor bump.
|
||||
|
||||
**1.3.0 is a worked example.** It ships seven documented behavioral breaks —
|
||||
`bd update --status <done-status>` enforcing close policy, `bd search`
|
||||
including closed issues, the interactive-only last-touched fallback, `bd human
|
||||
list` status handling, `bd dolt push` remote-adoption consent, Dolt port
|
||||
precedence over `BEADS_DOLT_PORT`, and actor `--` decoding — plus a schema
|
||||
migration and a flag rename (`--profile` → `--cpu-profile`). Every one has a
|
||||
CHANGELOG entry with its override, and the release is a MINOR bump.
|
||||
|
||||
Examples:
|
||||
- `0.21.5` → `0.22.0`: New features (minor bump)
|
||||
- `0.22.0` → `0.22.1`: Bug fix (patch bump)
|
||||
- `1.2.2` → `1.3.0`: New features plus documented behavioral breaks with
|
||||
migration notes (minor bump)
|
||||
- `0.22.1` → `1.0.0`: Stable release (major bump)
|
||||
|
||||
**Prereleases:** append a SemVer prerelease identifier for release candidates,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"errors"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
|
|
@ -539,6 +540,46 @@ func RunBatchCreatorDoesNotMutateTheCallerRequest(t *testing.T, ctx context.Cont
|
|||
}
|
||||
}
|
||||
|
||||
// RunBatchCreatorEchoesSubSecondTimestamps is the batch half of
|
||||
// RunLifecycleCreateEchoesSubSecondTimestamps: every entry of a batch result
|
||||
// carries the timestamps its write sent, at full precision, not the whole
|
||||
// seconds the DATETIME(0) columns answer a re-read with.
|
||||
//
|
||||
// PER ITEM, because both bodies build the result one snapshot at a time and a
|
||||
// fix applied to the first item only would still pass a check on result[0].
|
||||
func RunBatchCreatorEchoesSubSecondTimestamps(t *testing.T, ctx context.Context, fixture BatchCreatorFixture) {
|
||||
t.Helper()
|
||||
first := time.Date(2019, 3, 4, 5, 6, 7, 123456789, time.UTC)
|
||||
second := time.Date(2020, 4, 5, 6, 7, 8, 246813579, time.UTC)
|
||||
request := publicops.CreateBatchRequest{
|
||||
Actor: "batch-writer",
|
||||
Items: []publicops.BatchCreateItem{
|
||||
batchCreatorItem(&types.Issue{Title: "nano first", Priority: 2, IssueType: types.TypeTask, CreatedAt: first, UpdatedAt: first}),
|
||||
batchCreatorItem(&types.Issue{Title: "nano second", Priority: 2, IssueType: types.TypeTask, CreatedAt: second, UpdatedAt: second}),
|
||||
},
|
||||
}
|
||||
want := []time.Time{first, second}
|
||||
result, err := fixture.BatchCreator.CreateBatch(ctx, request)
|
||||
if err != nil {
|
||||
t.Fatalf("CreateBatch with sub-second timestamps: %v", err)
|
||||
}
|
||||
if len(result.Issues) != len(want) {
|
||||
t.Fatalf("CreateBatch returned %d issues for %d items", len(result.Issues), len(want))
|
||||
}
|
||||
for i, issue := range result.Issues {
|
||||
if issue == nil {
|
||||
t.Fatalf("CreateBatch result issue %d is nil", i)
|
||||
}
|
||||
if !issue.CreatedAt.Equal(want[i]) {
|
||||
t.Errorf("result issue %d created_at = %v, want %v exactly — a batch echo rounded to the second cannot order same-second creates",
|
||||
i, issue.CreatedAt.UTC(), want[i])
|
||||
}
|
||||
if !issue.UpdatedAt.Equal(want[i]) {
|
||||
t.Errorf("result issue %d updated_at = %v, want %v exactly", i, issue.UpdatedAt.UTC(), want[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// batchCreatorItem is the item every case builds, so a case names only the
|
||||
// fields it is about.
|
||||
func batchCreatorItem(issue *types.Issue) publicops.BatchCreateItem {
|
||||
|
|
|
|||
|
|
@ -565,6 +565,79 @@ func assertLifecycleCreateMembers(t *testing.T, id, label string, issue *types.I
|
|||
}
|
||||
}
|
||||
|
||||
// RunLifecycleCreateEchoesSubSecondTimestamps pins that a create RESULT carries
|
||||
// the timestamps the write actually sent, at full precision, rather than the
|
||||
// whole seconds a read of the row answers with.
|
||||
//
|
||||
// created_at/updated_at are DATETIME(0) columns, so any snapshot built by
|
||||
// re-reading the row it just wrote comes back rounded. That is fine for every
|
||||
// read verb — show and list have always answered whole seconds — but create is
|
||||
// different: its echo is the ONLY record a caller has of the instant the row was
|
||||
// written, and agents order same-second creates by it. A backend that hydrates
|
||||
// its create result and stops there silently loses that ordering, which is
|
||||
// exactly the regression this case exists for.
|
||||
//
|
||||
// THE PRECISION PIN IS THE EXPLICIT ARM, not the auto-stamped one. A create that
|
||||
// names no time is stamped from the clock, and whether that stamp happens to
|
||||
// carry a non-zero fraction is not something a test can require without being
|
||||
// flaky by a billionth; a caller-supplied time with nanoseconds in it is
|
||||
// deterministic, and PrepareIssueForInsert preserves a non-zero input. The
|
||||
// auto-stamp arm is kept as a bounded smoke check that the overlay did not
|
||||
// replace the stamp with something unrelated.
|
||||
//
|
||||
// The stored ROW is deliberately NOT asserted here. What it rounds to is the
|
||||
// column's business, and a later widening to DATETIME(6) must not have to edit
|
||||
// this case.
|
||||
func RunLifecycleCreateEchoesSubSecondTimestamps(t *testing.T, ctx context.Context, fixture LifecycleCreateFixture) {
|
||||
t.Helper()
|
||||
|
||||
id := fixture.IssuePrefix + "-lcc-nanoecho"
|
||||
createdAt := time.Date(2019, 3, 4, 5, 6, 7, 123456789, time.UTC)
|
||||
updatedAt := time.Date(2019, 3, 4, 5, 6, 8, 987654321, time.UTC)
|
||||
created, err := fixture.Lifecycle.Create(ctx, publicops.CreateRequest{
|
||||
Actor: "writer",
|
||||
ForceIDPrefix: true,
|
||||
Issue: &types.Issue{
|
||||
ID: id, Title: "sub-second echo", Status: types.StatusOpen, Priority: 2, IssueType: types.TypeTask,
|
||||
CreatedAt: createdAt, UpdatedAt: updatedAt,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("create %s with sub-second timestamps: %v", id, err)
|
||||
}
|
||||
if created.Issue == nil {
|
||||
t.Fatalf("create %s returned no issue", id)
|
||||
}
|
||||
if !created.Issue.CreatedAt.Equal(createdAt) {
|
||||
t.Errorf("%s create result created_at = %v, want %v exactly — the echo is the caller's only record of when the row was written, and rounding it to the second makes same-second creates unorderable",
|
||||
id, created.Issue.CreatedAt.UTC(), createdAt)
|
||||
}
|
||||
if !created.Issue.UpdatedAt.Equal(updatedAt) {
|
||||
t.Errorf("%s create result updated_at = %v, want %v exactly", id, created.Issue.UpdatedAt.UTC(), updatedAt)
|
||||
}
|
||||
|
||||
// The auto-stamped arm: no precision requirement, only that the overlay
|
||||
// still hands back a stamp from this call rather than a stale or zero one.
|
||||
stamped := fixture.IssuePrefix + "-lcc-nanoauto"
|
||||
lower := time.Now().UTC().Add(-lifecycleCreateClockSlack)
|
||||
auto, err := fixture.Lifecycle.Create(ctx, publicops.CreateRequest{
|
||||
Actor: "writer",
|
||||
ForceIDPrefix: true,
|
||||
Issue: lifecycleCreateIssue(stamped),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("create %s without timestamps: %v", stamped, err)
|
||||
}
|
||||
upper := time.Now().UTC().Add(lifecycleCreateClockSlack)
|
||||
if auto.Issue == nil {
|
||||
t.Fatalf("create %s returned no issue", stamped)
|
||||
}
|
||||
echoed := auto.Issue.CreatedAt.UTC()
|
||||
if echoed.Before(lower) || echoed.After(upper) {
|
||||
t.Errorf("%s create result created_at = %v, want a stamp from this call between %v and %v", stamped, echoed, lower, upper)
|
||||
}
|
||||
}
|
||||
|
||||
// lifecycleCreateClockSlack widens the window the auto-stamp arm allows around a
|
||||
// creation time the implementation wrote from its own clock. Every backend here
|
||||
// stamps in Go, in this process, so the two clocks are the same one; the slack
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ var roleContractCases = []roleContract{
|
|||
RunBatchCreatorRecordsOneHistoryEntry,
|
||||
RunBatchCreatorRecordsNoHistoryForAnEphemeralBatch,
|
||||
RunBatchCreatorDoesNotMutateTheCallerRequest,
|
||||
RunBatchCreatorEchoesSubSecondTimestamps,
|
||||
),
|
||||
|
||||
roleCases("BlockingAnnotator", "BlockingAnnotator()", oncePerRole,
|
||||
|
|
@ -412,6 +413,7 @@ var roleContractCases = []roleContract{
|
|||
RunLifecycleCreateRefusesAForeignIDPrefix,
|
||||
RunLifecycleCreateInheritsParentLabels,
|
||||
RunLifecycleCreateWritesEveryScalarField,
|
||||
RunLifecycleCreateEchoesSubSecondTimestamps,
|
||||
),
|
||||
|
||||
roleCases("LifecycleUpdate", "IssueLifecycle()", oncePerRole,
|
||||
|
|
|
|||
45
beads.go
45
beads.go
|
|
@ -26,6 +26,7 @@ import (
|
|||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/storage/dolt"
|
||||
"github.com/steveyegge/beads/internal/storage/domain"
|
||||
"github.com/steveyegge/beads/internal/storage/schema"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/workspacegate"
|
||||
)
|
||||
|
|
@ -36,12 +37,17 @@ import (
|
|||
// safe to repeat.
|
||||
type Storage = beads.Storage
|
||||
|
||||
func configuredBackendUnavailable(backend string) error {
|
||||
// configuredBackendUnavailable is the public open path's fail-closed refusal for
|
||||
// metadata naming a removed or unrecognized backend. beadsDir and cfg let the
|
||||
// refusal detect an already-present Dolt database and name the exact
|
||||
// metadata.json edit that heals the workspace, instead of the export-and-
|
||||
// reinitialize path that would destroy it.
|
||||
func configuredBackendUnavailable(backend, beadsDir string, cfg *configfile.Config) error {
|
||||
switch backend {
|
||||
case configfile.BackendPostgres, configfile.BackendMySQL, configfile.BackendSQLite:
|
||||
return configfile.RemovedBackendError(backend)
|
||||
return configfile.RemovedBackendErrorAt(backend, beadsDir, cfg)
|
||||
default:
|
||||
return configfile.UnknownBackendError(backend)
|
||||
return configfile.UnknownBackendErrorAt(backend, beadsDir, cfg)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -270,6 +276,39 @@ type (
|
|||
StatusEntry = storage.StatusEntry
|
||||
)
|
||||
|
||||
// AllowSharedSchemaMigration authorizes this process to apply pending schema
|
||||
// migrations to a database that is SHARED with other bd clients — a Dolt
|
||||
// sql-server, where migrating promotes the schema version for every connected
|
||||
// client at once and clients still running an older bd will refuse the
|
||||
// database until they are upgraded (gastownhall/beads#5920).
|
||||
//
|
||||
// Without it, an embedder that upgrades its beads dependency across a schema
|
||||
// bump gets a migration-gate error from every writable Open* call, whose
|
||||
// guidance names CLI commands (`bd migrate schema`) that mean nothing inside a
|
||||
// library process. This is the programmatic equivalent of that command.
|
||||
//
|
||||
// It is process-local and set-or-clear, which is the point: the alternative —
|
||||
// os.Setenv("BD_ALLOW_REMOTE_MIGRATE", "1") — is process-GLOBAL and inherited
|
||||
// by every child process the embedder spawns, including git hooks and dolt
|
||||
// subprocesses.
|
||||
//
|
||||
// The parity with that env var is only in the process-local mechanism, not the
|
||||
// reach: BD_ALLOW_REMOTE_MIGRATE=1 unlocks BOTH the no-remote and the
|
||||
// remote-backed shared arms, while this authorizes ONLY the no-remote arm. A
|
||||
// remote-backed shared store still needs --force / AllowRemoteMigrateEnv,
|
||||
// because #4259 cross-clone coordination is a stronger, different contract.
|
||||
//
|
||||
// Call it before the Open* call that should perform the migration, and clear
|
||||
// it afterwards. Only grant it once the operator has confirmed that every
|
||||
// other client of the server is upgraded; it is a coordination decision the
|
||||
// library cannot make, because other clients' versions are not observable from
|
||||
// this process.
|
||||
//
|
||||
// Embedded (single-writer) databases never need it: they still auto-migrate.
|
||||
func AllowSharedSchemaMigration(allow bool) {
|
||||
schema.SetSharedMigrateConsent(allow)
|
||||
}
|
||||
|
||||
// Open opens a Dolt-backed beads database at the given path.
|
||||
// This always opens in embedded mode. Use OpenFromConfig to respect
|
||||
// server mode settings from metadata.json.
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ func OpenBestAvailable(ctx context.Context, beadsDir string) (Storage, error) {
|
|||
cfg = configfile.DefaultConfig()
|
||||
}
|
||||
if !configfile.IsSupportedBackend(cfg.Backend) {
|
||||
return nil, configuredBackendUnavailable(cfg.Backend)
|
||||
return nil, configuredBackendUnavailable(cfg.Backend, beadsDir, cfg)
|
||||
}
|
||||
|
||||
// Dispatch to a registered extension backend before any Dolt path, mirroring
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ func OpenBestAvailable(ctx context.Context, beadsDir string) (Storage, error) {
|
|||
cfg = configfile.DefaultConfig()
|
||||
}
|
||||
if !configfile.IsSupportedBackend(cfg.Backend) {
|
||||
return nil, configuredBackendUnavailable(cfg.Backend)
|
||||
return nil, configuredBackendUnavailable(cfg.Backend, beadsDir, cfg)
|
||||
}
|
||||
|
||||
// Dispatch to a registered extension backend before any Dolt path, mirroring
|
||||
|
|
|
|||
|
|
@ -26,6 +26,12 @@
|
|||
//
|
||||
// The package imports stdlib and nothing else, and it must stay that way: it
|
||||
// sits beneath every leaf, so anything it imports is imported by all of them.
|
||||
//
|
||||
// # Stability
|
||||
//
|
||||
// EXPERIMENTAL. This package is not yet covered by the project's compatibility
|
||||
// promise and may change in a minor release. Every leaf re-exports from here,
|
||||
// so a change to this vocabulary reaches all of them at once.
|
||||
package beadserrors
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ func TestRegisteredBackendDispatchesReadWriteAndReadOnly(t *testing.T) {
|
|||
registerContractBackend(t, name)
|
||||
beadsDir := writeContractBackendConfig(t, name)
|
||||
|
||||
if err := validateConfiguredBackend(&configfile.Config{Backend: name}); err != nil {
|
||||
if err := validateConfiguredBackend(&configfile.Config{Backend: name}, beadsDir); err != nil {
|
||||
t.Fatalf("validateConfiguredBackend() rejected registered backend: %v", err)
|
||||
}
|
||||
if _, err := newDoltStoreFromConfig(t.Context(), beadsDir); !errors.Is(err, errRegistryReadWrite) {
|
||||
|
|
@ -78,7 +78,7 @@ func TestOSSRegistersNoRemovedBackends(t *testing.T) {
|
|||
if backends.Registered(name) {
|
||||
t.Errorf("OSS unexpectedly registered removed backend %q", name)
|
||||
}
|
||||
if err := validateConfiguredBackend(&configfile.Config{Backend: name}); err == nil {
|
||||
if err := validateConfiguredBackend(&configfile.Config{Backend: name}, t.TempDir()); err == nil {
|
||||
t.Errorf("OSS unexpectedly accepted removed backend %q", name)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,12 @@ import (
|
|||
"github.com/steveyegge/beads/internal/storage/backends"
|
||||
)
|
||||
|
||||
func validateConfiguredBackend(cfg *configfile.Config) error {
|
||||
// validateConfiguredBackend fails closed on metadata that selects a removed or
|
||||
// unrecognized backend. beadsDir is the workspace whose metadata cfg came from;
|
||||
// the rejection inspects it (read-only) so a workspace that already holds a Dolt
|
||||
// database is told to fix the stale "backend" value rather than to export and
|
||||
// reinitialize. Pass "" only where there is genuinely no workspace directory.
|
||||
func validateConfiguredBackend(cfg *configfile.Config, beadsDir string) error {
|
||||
if cfg == nil {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -16,11 +21,11 @@ func validateConfiguredBackend(cfg *configfile.Config) error {
|
|||
}
|
||||
switch cfg.Backend {
|
||||
case configfile.BackendPostgres, configfile.BackendMySQL, configfile.BackendSQLite:
|
||||
return configfile.RemovedBackendError(cfg.Backend)
|
||||
return configfile.RemovedBackendErrorAt(cfg.Backend, beadsDir, cfg)
|
||||
case "", configfile.BackendDolt:
|
||||
return nil
|
||||
default:
|
||||
return configfile.UnknownBackendError(cfg.Backend)
|
||||
return configfile.UnknownBackendErrorAt(cfg.Backend, beadsDir, cfg)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -33,8 +38,8 @@ func registeredBackendWorkspaceIsBeadsDir(cfg *configfile.Config) bool {
|
|||
return backends.WorkspaceIsBeadsDir(cfg.GetBackend())
|
||||
}
|
||||
|
||||
func requireDoltBackend(cfg *configfile.Config) error {
|
||||
if err := validateConfiguredBackend(cfg); err != nil {
|
||||
func requireDoltBackend(cfg *configfile.Config, beadsDir string) error {
|
||||
if err := validateConfiguredBackend(cfg, beadsDir); err != nil {
|
||||
return err
|
||||
}
|
||||
if cfg != nil && cfg.GetBackend() != configfile.BackendDolt {
|
||||
|
|
@ -64,7 +69,7 @@ func loadDoltBackendConfig(beadsDir string) (*configfile.Config, error) {
|
|||
if cfg == nil {
|
||||
cfg = configfile.DefaultConfig()
|
||||
}
|
||||
if err := requireDoltBackend(cfg); err != nil {
|
||||
if err := requireDoltBackend(cfg, beadsDir); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cfg, nil
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bufio"
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
|
@ -22,6 +23,7 @@ import (
|
|||
"github.com/steveyegge/beads/internal/configfile"
|
||||
"github.com/steveyegge/beads/internal/doltserver"
|
||||
"github.com/steveyegge/beads/internal/metrics"
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/storage/dolt"
|
||||
"github.com/steveyegge/beads/internal/storage/doltutil"
|
||||
"github.com/steveyegge/beads/internal/storage/embeddeddolt"
|
||||
|
|
@ -51,6 +53,12 @@ type bootstrapServerDBCheck struct {
|
|||
// retries. Injectable for testing.
|
||||
var bootstrapRetryDelay = func(d time.Duration) { time.Sleep(d) }
|
||||
|
||||
// probeGitRemoteDoltData reports whether a git remote carries Dolt data
|
||||
// (refs/dolt/data). Injectable for testing; the production value is a
|
||||
// 10s-bounded `git ls-remote` with credential prompts suppressed. A non-nil
|
||||
// error means UNKNOWN, not "no data".
|
||||
var probeGitRemoteDoltData = gitRemoteHasDoltDataRefStatus
|
||||
|
||||
var checkBootstrapServerDB = func(probeCfg bootstrapServerProbeConfig) bootstrapServerDBCheck {
|
||||
host := probeCfg.host
|
||||
port := probeCfg.port
|
||||
|
|
@ -113,6 +121,9 @@ Bootstrap auto-detects the right action:
|
|||
• If no database exists: creates a fresh one
|
||||
• If database already exists: validates and reports status
|
||||
|
||||
If sync.remote points at a git repository, bootstrap verifies refs/dolt/data
|
||||
before cloning. Bootstrap exits non-zero when it cannot set up a database.
|
||||
|
||||
This is the recommended command for:
|
||||
• Setting up beads on a fresh clone
|
||||
• Recovering after moving to a new machine
|
||||
|
|
@ -145,6 +156,19 @@ Examples:
|
|||
// Resolve non-interactive mode: flag > env var > CI env > terminal detection.
|
||||
nonInteractive := isNonInteractiveBootstrap(yesFlag || nonInteractiveFlag)
|
||||
|
||||
// dc-6jaq: "bootstrap" is in noDbCommands, so PersistentPreRunE
|
||||
// returns at the skip-store early return before its freeze gate, and
|
||||
// bootstrap.go calls neither CheckReadonly nor the gate itself — yet
|
||||
// it writes, and the first of those writes (the metadata repair below)
|
||||
// lands before its own confirmation prompt and before it takes any
|
||||
// workspace gate. --dry-run is exempt because it genuinely does not
|
||||
// write; every other invocation is refused while a marker is active.
|
||||
if !dryRun {
|
||||
if err := migrationFreezeGateFor(cmd, "bootstrap"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Find beads directory
|
||||
beadsDir := beads.FindBeadsDir()
|
||||
if beadsDir == "" {
|
||||
|
|
@ -211,7 +235,7 @@ Examples:
|
|||
if cfg == nil {
|
||||
cfg = configfile.DefaultConfig()
|
||||
}
|
||||
if err := requireBootstrapDoltBackend(cfg); err != nil {
|
||||
if err := requireBootstrapDoltBackend(cfg, beadsDir); err != nil {
|
||||
return HandleError("%v", err)
|
||||
}
|
||||
|
||||
|
|
@ -231,7 +255,7 @@ Examples:
|
|||
return err
|
||||
}
|
||||
if plan.Action == "none" || dryRun {
|
||||
return nil
|
||||
return bootstrapPlanOutcome(plan, dryRun)
|
||||
}
|
||||
} else {
|
||||
if repairMsg != "" {
|
||||
|
|
@ -239,7 +263,7 @@ Examples:
|
|||
}
|
||||
printBootstrapPlan(plan)
|
||||
if plan.Action == "none" || dryRun {
|
||||
return nil
|
||||
return bootstrapPlanOutcome(plan, dryRun)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -269,14 +293,73 @@ func applyBootstrapMetadataRepair(beadsDir string, cfg *configfile.Config, apply
|
|||
|
||||
// BootstrapPlan describes what bootstrap will do.
|
||||
type BootstrapPlan struct {
|
||||
Action string `json:"action"` // "sync", "restore", "jsonl-import", "init", "none"
|
||||
Reason string `json:"reason"` // Human-readable explanation
|
||||
BeadsDir string `json:"beads_dir"`
|
||||
Database string `json:"database"`
|
||||
SyncRemote string `json:"sync_remote,omitempty"`
|
||||
BackupDir string `json:"backup_dir,omitempty"`
|
||||
JSONLFile string `json:"jsonl_file,omitempty"`
|
||||
HasExisting bool `json:"has_existing"`
|
||||
Action string `json:"action"` // "sync", "restore", "jsonl-import", "init", "none"
|
||||
Reason string `json:"reason"` // Human-readable explanation
|
||||
BeadsDir string `json:"beads_dir"`
|
||||
Database string `json:"database"`
|
||||
// SyncRemote is the remote this workspace syncs with. For Action=="sync"
|
||||
// it is the clone source; for the provisioning actions it is the remote to
|
||||
// register as Dolt "origin" so the first `bd dolt push` has somewhere to
|
||||
// go. Always the routed (doltRemoteURL) form for forge URLs, and empty on
|
||||
// a Blocked plan — nothing may be cloned from or pushed to a remote
|
||||
// bootstrap could not verify.
|
||||
//
|
||||
// This is an operational URL, so it keeps whatever credentials the user
|
||||
// configured. Run it through redactRemoteURL before printing it or putting
|
||||
// it anywhere a human will read. Reason and BlockedRemote are already
|
||||
// display-safe.
|
||||
SyncRemote string `json:"sync_remote,omitempty"`
|
||||
BackupDir string `json:"backup_dir,omitempty"`
|
||||
JSONLFile string `json:"jsonl_file,omitempty"`
|
||||
// Blocked marks a plan that took no action and found no database. It is
|
||||
// derived in detectBootstrapAction from Action+HasExisting, never set by a
|
||||
// detection branch, and it is the single discriminator the exit code and
|
||||
// the printed output both switch on. Additive on purpose: JSON consumers
|
||||
// switch on "action", so a new action value would break them, while
|
||||
// "none" + "blocked" + a non-zero exit code is backwards compatible.
|
||||
Blocked bool `json:"blocked,omitempty"`
|
||||
// BlockedRemote is the credential-free remote URL a Blocked plan could not
|
||||
// verify, carried only so the diagnostic can name it.
|
||||
BlockedRemote string `json:"blocked_remote,omitempty"`
|
||||
HasExisting bool `json:"has_existing"`
|
||||
}
|
||||
|
||||
// MarshalJSON renders the plan for `bd bootstrap --json` (and `--dry-run --json`)
|
||||
// with the credential-bearing SyncRemote redacted, mirroring the human path
|
||||
// (printBootstrapPlan runs it through redactRemoteURL). SyncRemote keeps whatever
|
||||
// credentials the user configured — see the field comment — and `--json` writes
|
||||
// to stdout, which CI logs and agent transcripts capture, so it must not be
|
||||
// emitted verbatim. Redaction is on a copy; executeBootstrapPlan still consumes
|
||||
// the raw plan.SyncRemote for the clone. Reason and BlockedRemote are already
|
||||
// built display-safe.
|
||||
func (p BootstrapPlan) MarshalJSON() ([]byte, error) {
|
||||
// The local type sheds BootstrapPlan's method set so json.Marshal does not
|
||||
// recurse back into this MarshalJSON.
|
||||
type bootstrapPlanJSON BootstrapPlan
|
||||
safe := bootstrapPlanJSON(p)
|
||||
safe.SyncRemote = redactRemoteURL(p.SyncRemote)
|
||||
return json.Marshal(safe)
|
||||
}
|
||||
|
||||
// bootstrapPlanOutcome maps a printed plan to the command's exit status.
|
||||
// Action=="none" was two outcomes wearing one name — "a database already
|
||||
// exists, nothing to do" and "bootstrap declined and left you with no
|
||||
// database" — and both returned nil, so a rejected sync.remote printed a
|
||||
// success tick and exited 0 with no database (#5743). Blocked is the
|
||||
// discriminator.
|
||||
//
|
||||
// --dry-run always succeeds. bd doctor documents `bd bootstrap --dry-run` as
|
||||
// the safe inspection step, and a preview that aborts a `set -e` provisioning
|
||||
// script is a worse contract than a preview that merely reports. The blocked
|
||||
// state is still printed (and still in the JSON), so the preview does predict
|
||||
// what a real run would refuse to do.
|
||||
func bootstrapPlanOutcome(plan BootstrapPlan, dryRun bool) error {
|
||||
if dryRun || !plan.Blocked {
|
||||
return nil
|
||||
}
|
||||
// The reason and hints are already on stderr, or the plan JSON (carrying
|
||||
// "blocked": true) is already on stdout.
|
||||
return SilentExit()
|
||||
}
|
||||
|
||||
func noWorkspaceBootstrapPayload() map[string]interface{} {
|
||||
|
|
@ -287,8 +370,8 @@ func noWorkspaceBootstrapPayload() map[string]interface{} {
|
|||
}
|
||||
}
|
||||
|
||||
func requireBootstrapDoltBackend(cfg *configfile.Config) error {
|
||||
if err := validateConfiguredBackend(cfg); err != nil {
|
||||
func requireBootstrapDoltBackend(cfg *configfile.Config, beadsDir string) error {
|
||||
if err := validateConfiguredBackend(cfg, beadsDir); err != nil {
|
||||
return err
|
||||
}
|
||||
// A registered extension backend passes validateConfiguredBackend so its
|
||||
|
|
@ -304,7 +387,20 @@ func requireBootstrapDoltBackend(cfg *configfile.Config) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// detectBootstrapAction builds the plan and then derives its outcome flags in
|
||||
// exactly one place. Blocked is never hand-set by a detection branch: it is a
|
||||
// function of the finished plan ("took no action AND found no database"), so no
|
||||
// branch can leave a stale flag behind for a later branch to inherit.
|
||||
func detectBootstrapAction(beadsDir string, cfg *configfile.Config) BootstrapPlan {
|
||||
plan := detectBootstrapPlan(beadsDir, cfg)
|
||||
plan.Blocked = plan.Action == "none" && !plan.HasExisting
|
||||
if !plan.Blocked {
|
||||
plan.BlockedRemote = ""
|
||||
}
|
||||
return plan
|
||||
}
|
||||
|
||||
func detectBootstrapPlan(beadsDir string, cfg *configfile.Config) BootstrapPlan {
|
||||
plan := BootstrapPlan{
|
||||
BeadsDir: beadsDir,
|
||||
Database: cfg.GetDoltDatabase(),
|
||||
|
|
@ -315,10 +411,8 @@ func detectBootstrapAction(beadsDir string, cfg *configfile.Config) BootstrapPla
|
|||
// sync.remote / refs/dolt/data detection run before treating an existing
|
||||
// shared-server database as "nothing to do", otherwise an unrelated default
|
||||
// "beads" database can mask the real recovery path.
|
||||
beadsDirExists := false
|
||||
if info, err := os.Stat(beadsDir); err == nil && info.IsDir() {
|
||||
beadsDirExists = true
|
||||
}
|
||||
info, statErr := os.Stat(beadsDir)
|
||||
beadsDirExists := statErr == nil && info.IsDir()
|
||||
|
||||
// Check for existing database (path differs between server and embedded mode).
|
||||
// Determine server/shared-server mode from the target workspace itself
|
||||
|
|
@ -335,68 +429,57 @@ func detectBootstrapAction(beadsDir string, cfg *configfile.Config) BootstrapPla
|
|||
// and the multi-clone upgrade guide. If the local beadsDir does not exist
|
||||
// yet, still prefer sync recovery first for Action=="none" so a default
|
||||
// shared-server "beads" DB from another project cannot mask a real clone.
|
||||
// Held aside rather than merged into plan: a "none" verdict here is only a
|
||||
// fallback for when nothing else matches, and copying it into plan leaked
|
||||
// its HasExisting/Blocked/Reason into every branch below — including the
|
||||
// probe-error branch, which then inherited HasExisting=true and printed the
|
||||
// #5743 success tick again.
|
||||
var deferredExistingPlan *BootstrapPlan
|
||||
if dbAction, ok := existingBootstrapDBPlan(beadsDir, cfg, isServer, isSharedServer); ok {
|
||||
if beadsDirExists || dbAction.Action != "none" {
|
||||
return dbAction
|
||||
}
|
||||
plan = dbAction
|
||||
deferredExistingPlan = &dbAction
|
||||
}
|
||||
|
||||
// Check sync.remote (primary) or sync.git-remote (deprecated fallback)
|
||||
// A configured sync.remote (primary) or sync.git-remote (deprecated
|
||||
// fallback) is authoritative: try it first and, when it cannot be cloned,
|
||||
// remember why so an unverifiable remote can become fatal only after local
|
||||
// recovery is exhausted. With no sync.remote, auto-detect Dolt data on git
|
||||
// origin instead.
|
||||
syncRemote := resolveSyncRemote()
|
||||
unusableRemoteReason, unusableRemoteURL := "", ""
|
||||
if syncRemote != "" {
|
||||
if isGitCodeRepoURL(syncRemote) {
|
||||
// Cloning from a git code-repo URL via DOLT_CLONE spins dolt to
|
||||
// 1000% CPU and requires manual SIGKILL. Reject and
|
||||
// surface the misconfiguration rather than attempting the clone.
|
||||
fmt.Fprintf(os.Stderr, "error: sync.remote %q looks like a git code-repository URL, not a Dolt remote — skipping clone\n", syncRemote)
|
||||
plan.Action = "none"
|
||||
plan.Reason = fmt.Sprintf("sync.remote %q rejected: git code-repository URL (not a Dolt remote)", syncRemote)
|
||||
done, reason, url := planConfiguredSyncRemote(&plan, syncRemote)
|
||||
if done {
|
||||
return plan
|
||||
}
|
||||
// User-provided sync.remote — trust the URL format as-is.
|
||||
// normalizeRemoteURL would convert http:// to git+http://,
|
||||
// breaking Dolt remotesapi endpoints (GH#3339).
|
||||
plan.SyncRemote = syncRemote
|
||||
plan.Action = "sync"
|
||||
plan.Reason = "sync.remote configured — will clone from " + syncRemote
|
||||
return plan
|
||||
// Cloning is off the table; purely local recovery is not.
|
||||
unusableRemoteReason, unusableRemoteURL = reason, url
|
||||
} else if originPlan, ok := gitOriginSyncPlan(plan); ok {
|
||||
return originPlan
|
||||
}
|
||||
|
||||
// Auto-detect: probe git origin for Dolt data stored in git
|
||||
// (refs/dolt/data). This only applies to git remotes — Dolt-native
|
||||
// remotes (DoltHub, S3, etc.) must be configured via sync.remote.
|
||||
if isGitRepo() && !isBareGitRepo() {
|
||||
if originURL, err := gitOriginGetURL(); err == nil && originURL != "" {
|
||||
if gitOriginHasDoltDataRef() {
|
||||
plan.SyncRemote = normalizeRemoteURL(originURL)
|
||||
plan.Action = "sync"
|
||||
plan.Reason = "Found Dolt data on git origin (refs/dolt/data) — will clone from " + originURL
|
||||
return plan
|
||||
}
|
||||
}
|
||||
// On-disk recovery sources: a non-empty backup JSONL, then a git-tracked
|
||||
// issues.jsonl. When a forge sync.remote had no Dolt data yet, plan already
|
||||
// carries its SyncRemote so the restored/imported workspace stays wired to it.
|
||||
if recoveryPlan, ok := localFileRecoveryPlan(plan, beadsDir); ok {
|
||||
return recoveryPlan
|
||||
}
|
||||
|
||||
// Check for backup JSONL files (must be non-empty to be useful)
|
||||
backupDir := filepath.Join(beadsDir, "backup")
|
||||
issuesFile := filepath.Join(backupDir, "issues.jsonl")
|
||||
if info, err := os.Stat(issuesFile); err == nil && info.Size() > 0 {
|
||||
plan.BackupDir = backupDir
|
||||
plan.Action = "restore"
|
||||
plan.Reason = "Backup files found — will restore from " + backupDir
|
||||
return plan
|
||||
if deferredExistingPlan != nil {
|
||||
return *deferredExistingPlan
|
||||
}
|
||||
|
||||
// Check for git-tracked JSONL (the portable export format)
|
||||
gitJSONL := filepath.Join(beadsDir, "issues.jsonl")
|
||||
if _, err := os.Stat(gitJSONL); err == nil {
|
||||
plan.JSONLFile = gitJSONL
|
||||
plan.Action = "jsonl-import"
|
||||
plan.Reason = "Git-tracked issues.jsonl found — will import from " + gitJSONL
|
||||
return plan
|
||||
}
|
||||
|
||||
if plan.Action == "none" {
|
||||
// Only now, with every local recovery source exhausted, does an
|
||||
// unverifiable remote become fatal. Restoring a local backup touches no
|
||||
// remote, so an offline laptop or a credential-less CI runner must not be
|
||||
// denied the recovery that the same machine would get if the probe had
|
||||
// merely answered "no data".
|
||||
if unusableRemoteReason != "" {
|
||||
plan.Action = "none"
|
||||
plan.Reason = unusableRemoteReason
|
||||
plan.BlockedRemote = unusableRemoteURL
|
||||
return plan
|
||||
}
|
||||
|
||||
|
|
@ -406,6 +489,116 @@ func detectBootstrapAction(beadsDir string, cfg *configfile.Config) BootstrapPla
|
|||
return plan
|
||||
}
|
||||
|
||||
// planConfiguredSyncRemote resolves a configured sync.remote into plan. done==true
|
||||
// means the plan is finished — a clone plan for a trusted remote or a forge repo
|
||||
// the probe confirmed carries Dolt data — and the caller returns plan as-is.
|
||||
// done==false means keep looking: either the forge repo has no Dolt data yet
|
||||
// (plan.SyncRemote is still recorded so a fresh workspace gets wired to it) or the
|
||||
// remote could not be verified, in which case the returned reason/url describe the
|
||||
// unusable remote so it can become fatal only after local recovery is exhausted.
|
||||
func planConfiguredSyncRemote(plan *BootstrapPlan, syncRemote string) (done bool, unusableReason, unusableURL string) {
|
||||
if !isGitCodeRepoURL(syncRemote) {
|
||||
// User-provided sync.remote — trust the URL format as-is.
|
||||
// normalizeRemoteURL would convert http:// to git+http://, breaking Dolt
|
||||
// remotesapi endpoints (GH#3339). That concern cannot apply here: a
|
||||
// remotesapi endpoint never classifies as a git code-repo URL.
|
||||
plan.SyncRemote = syncRemote
|
||||
plan.Action = "sync"
|
||||
plan.Reason = "sync.remote configured — will clone from " + redactRemoteURL(syncRemote)
|
||||
return true, "", ""
|
||||
}
|
||||
|
||||
// A git-forge URL is a *supported* Dolt remote: `bd init` and `bd dolt
|
||||
// remote add` both persist one, and `bd dolt push` stores the database under
|
||||
// refs/dolt/data on it. What must never happen is cloning it blind, or in a
|
||||
// form that reaches Dolt's remotesapi client. doltRemoteURL owns that routing
|
||||
// rule; probe first, and clone only what the probe actually confirmed
|
||||
// (#5743, #5663).
|
||||
routed := doltRemoteURL(syncRemote)
|
||||
hasData, probeErr := probeGitRemoteDoltData(routed)
|
||||
switch {
|
||||
case probeErr != nil:
|
||||
// UNKNOWN, not "no data" — never clone something we could not verify
|
||||
// (init's resolveRemoteHasDoltDataProbe convention).
|
||||
reason := fmt.Sprintf("could not verify refs/dolt/data on sync.remote %q: %v",
|
||||
redactRemoteURL(syncRemote), probeErr)
|
||||
// Said here as well as in the final verdict because a local backup may
|
||||
// well rescue this run, and then this is the only place the user learns
|
||||
// the remote could not be reached.
|
||||
fmt.Fprintf(os.Stderr, "note: not cloning — %s; checking local recovery sources\n", reason)
|
||||
return false, reason, redactRemoteURL(routed)
|
||||
case hasData:
|
||||
plan.SyncRemote = routed
|
||||
plan.Action = "sync"
|
||||
plan.Reason = "sync.remote git repo has Dolt data (refs/dolt/data) — will clone from " + redactRemoteURL(routed)
|
||||
return true, "", ""
|
||||
default:
|
||||
// Definitively no Dolt data: the repo was wired before the first `bd
|
||||
// dolt push`. Say so and keep looking, the same way bd init falls back
|
||||
// to a fresh local database. Carry the URL so the workspace we create
|
||||
// still gets wired to it.
|
||||
plan.SyncRemote = routed
|
||||
fmt.Fprintf(os.Stderr, "note: sync.remote %q has no Dolt data yet (refs/dolt/data absent); checking other recovery sources\n",
|
||||
redactRemoteURL(syncRemote))
|
||||
return false, "", ""
|
||||
}
|
||||
}
|
||||
|
||||
// gitOriginSyncPlan returns a clone-from-git-origin plan when git origin carries
|
||||
// Dolt data (refs/dolt/data), or ok==false otherwise. Only git remotes qualify —
|
||||
// Dolt-native remotes (DoltHub, S3, etc.) must be configured via sync.remote.
|
||||
//
|
||||
// The caller invokes this only when no sync.remote is configured. sync.remote is
|
||||
// the authoritative remote for this workspace, so hydrating from whatever git
|
||||
// origin happens to be (a fork, an old experiment, the code repo under the
|
||||
// dedicated-data-repo pattern) is not recovery — and finalizeSyncedBootstrap would
|
||||
// then rewrite the team's committed sync.remote to point at it. Skipping it also
|
||||
// spares the second identical ls-remote in the common case where sync.remote IS
|
||||
// the git origin, which is what bd init persists.
|
||||
func gitOriginSyncPlan(plan BootstrapPlan) (BootstrapPlan, bool) {
|
||||
if !isGitRepo() || isBareGitRepo() {
|
||||
return BootstrapPlan{}, false
|
||||
}
|
||||
originURL, err := gitOriginGetURL()
|
||||
if err != nil || originURL == "" {
|
||||
return BootstrapPlan{}, false
|
||||
}
|
||||
if !gitOriginHasDoltDataRef() {
|
||||
return BootstrapPlan{}, false
|
||||
}
|
||||
plan.SyncRemote = normalizeRemoteURL(originURL)
|
||||
plan.Action = "sync"
|
||||
plan.Reason = "Found Dolt data on git origin (refs/dolt/data) — will clone from " + redactRemoteURL(originURL)
|
||||
return plan, true
|
||||
}
|
||||
|
||||
// localFileRecoveryPlan returns a restore or jsonl-import plan built from on-disk
|
||||
// recovery sources under beadsDir — a non-empty backup/issues.jsonl (restore),
|
||||
// else a git-tracked issues.jsonl (the portable export format) — or ok==false
|
||||
// when neither is present. plan is taken by value so its already-populated fields
|
||||
// (e.g. a forge SyncRemote with no Dolt data yet) ride into the returned plan.
|
||||
func localFileRecoveryPlan(plan BootstrapPlan, beadsDir string) (BootstrapPlan, bool) {
|
||||
// Backup JSONL must be non-empty to be useful.
|
||||
backupDir := filepath.Join(beadsDir, "backup")
|
||||
issuesFile := filepath.Join(backupDir, "issues.jsonl")
|
||||
if info, err := os.Stat(issuesFile); err == nil && info.Size() > 0 {
|
||||
plan.BackupDir = backupDir
|
||||
plan.Action = "restore"
|
||||
plan.Reason = "Backup files found — will restore from " + backupDir
|
||||
return plan, true
|
||||
}
|
||||
|
||||
gitJSONL := filepath.Join(beadsDir, "issues.jsonl")
|
||||
if _, err := os.Stat(gitJSONL); err == nil {
|
||||
plan.JSONLFile = gitJSONL
|
||||
plan.Action = "jsonl-import"
|
||||
plan.Reason = "Git-tracked issues.jsonl found — will import from " + gitJSONL
|
||||
return plan, true
|
||||
}
|
||||
|
||||
return BootstrapPlan{}, false
|
||||
}
|
||||
|
||||
func existingBootstrapDBPlan(beadsDir string, cfg *configfile.Config, isServer, isSharedServer bool) (BootstrapPlan, bool) {
|
||||
plan := BootstrapPlan{
|
||||
BeadsDir: beadsDir,
|
||||
|
|
@ -455,6 +648,11 @@ func existingBootstrapDBPlan(beadsDir string, cfg *configfile.Config, isServer,
|
|||
bootstrapRetryDelay(retryDelays[attempt])
|
||||
}
|
||||
if result.Err != nil {
|
||||
// Same "declined, and no database was confirmed" class as a
|
||||
// failed remote probe: report it and exit non-zero rather than
|
||||
// printing a success tick (#5743). Blocked is not hand-set here —
|
||||
// detectBootstrapAction derives it from Action=="none" && !HasExisting
|
||||
// (HasExisting is false on this branch), keeping one owner for the flag.
|
||||
plan.Action = "none"
|
||||
plan.Reason = fmt.Sprintf("Could not verify existing server database %s: %v", cfg.GetDoltDatabase(), result.Err)
|
||||
return plan, true
|
||||
|
|
@ -534,6 +732,22 @@ func bootstrapServerPort(beadsDir string, cfg *configfile.Config, isSharedServer
|
|||
func printBootstrapPlan(plan BootstrapPlan) {
|
||||
switch plan.Action {
|
||||
case "none":
|
||||
if plan.Blocked {
|
||||
// Nothing was set up and nothing was found. Never print the
|
||||
// success tick here — that is the #5743 false success.
|
||||
fmt.Fprintf(os.Stderr, "Bootstrap did not set up a database: %s\n", plan.Reason)
|
||||
if plan.BlockedRemote != "" {
|
||||
// Deliberately not "delete sync.remote and re-run": the git
|
||||
// origin probe on that path swallows its error, so for a
|
||||
// credential failure the retry would "succeed" by creating a
|
||||
// fresh database that has diverged from the team's history.
|
||||
fmt.Fprintf(os.Stderr, " Reproduce: git ls-remote %s refs/dolt/data\n",
|
||||
gitRemoteURLForLsRemote(plan.BlockedRemote))
|
||||
fmt.Fprintf(os.Stderr, " If the remote is right, fix access (credentials, network, VPN) and re-run 'bd bootstrap'.\n")
|
||||
fmt.Fprintf(os.Stderr, " If it is wrong, point sync.remote at the Dolt remote: bd dolt remote add origin <url>\n")
|
||||
}
|
||||
return
|
||||
}
|
||||
fmt.Printf("✓ Database already exists: %s\n", plan.BeadsDir)
|
||||
if !usesSQLServer() {
|
||||
fmt.Printf(" Nothing to do.\n")
|
||||
|
|
@ -542,7 +756,7 @@ func printBootstrapPlan(plan BootstrapPlan) {
|
|||
}
|
||||
case "sync":
|
||||
fmt.Printf("Bootstrap plan: clone from remote\n")
|
||||
fmt.Printf(" Remote: %s\n", plan.SyncRemote)
|
||||
fmt.Printf(" Remote: %s\n", redactRemoteURL(plan.SyncRemote))
|
||||
fmt.Printf(" Database: %s\n", plan.Database)
|
||||
case "restore":
|
||||
fmt.Printf("Bootstrap plan: restore from backup\n")
|
||||
|
|
@ -574,7 +788,7 @@ func confirmPrompt(message string, nonInteractive bool) bool {
|
|||
}
|
||||
|
||||
func executeBootstrapPlan(plan BootstrapPlan, cfg *configfile.Config, nonInteractive bool) error {
|
||||
if err := requireBootstrapDoltBackend(cfg); err != nil {
|
||||
if err := requireBootstrapDoltBackend(cfg, plan.BeadsDir); err != nil {
|
||||
return err
|
||||
}
|
||||
if !confirmPrompt("Proceed?", nonInteractive) {
|
||||
|
|
@ -643,10 +857,32 @@ func executeInitAction(ctx context.Context, plan BootstrapPlan, cfg *configfile.
|
|||
return fmt.Errorf("commit: %w", err)
|
||||
}
|
||||
|
||||
wireBootstrapDoltRemote(ctx, s, plan)
|
||||
fmt.Fprintf(os.Stderr, "Created fresh database with prefix %q\n", prefix)
|
||||
return nil
|
||||
}
|
||||
|
||||
// wireBootstrapDoltRemote registers plan.SyncRemote as Dolt remote "origin" on
|
||||
// a workspace bootstrap just provisioned locally.
|
||||
//
|
||||
// The sync action has always done this (via configureInitDoltRemote after the
|
||||
// clone) and bd init does it too, but the local actions never did, because a
|
||||
// configured sync.remote used to short-circuit to "sync" before they could be
|
||||
// reached. The refs/dolt/data fall-through makes them reachable, and without
|
||||
// the remote the promise that "the first bd dolt push creates refs/dolt/data
|
||||
// on that same git remote" breaks: push either refuses to adopt a remote
|
||||
// without consent, or adopts the git origin — a different repository under the
|
||||
// dedicated-data-repo pattern — and rewrites the committed sync.remote to
|
||||
// match. Two machines bootstrapping in the pre-first-push window would then
|
||||
// mint independent Dolt identities and diverge, which is the exact failure
|
||||
// bootstrap exists to prevent (#5743).
|
||||
func wireBootstrapDoltRemote(ctx context.Context, s storage.DoltStorage, plan BootstrapPlan) {
|
||||
if plan.SyncRemote == "" {
|
||||
return
|
||||
}
|
||||
configureInitDoltRemote(ctx, s, doltRemoteURL(plan.SyncRemote), false)
|
||||
}
|
||||
|
||||
func executeRestoreAction(ctx context.Context, plan BootstrapPlan, cfg *configfile.Config) error {
|
||||
prefix := inferPrefix(cfg)
|
||||
dbName := cfg.GetDoltDatabase()
|
||||
|
|
@ -674,6 +910,7 @@ func executeRestoreAction(ctx context.Context, plan BootstrapPlan, cfg *configfi
|
|||
return fmt.Errorf("restore from backup: %w", err)
|
||||
}
|
||||
|
||||
wireBootstrapDoltRemote(ctx, s, plan)
|
||||
fmt.Fprintf(os.Stderr, "Restored from backup\n")
|
||||
return nil
|
||||
}
|
||||
|
|
@ -710,6 +947,7 @@ func executeJSONLImportAction(ctx context.Context, plan BootstrapPlan, cfg *conf
|
|||
return fmt.Errorf("commit import: %w", err)
|
||||
}
|
||||
|
||||
wireBootstrapDoltRemote(ctx, s, plan)
|
||||
fmt.Fprintf(os.Stderr, "Imported %d issues from %s\n", count, plan.JSONLFile)
|
||||
return nil
|
||||
}
|
||||
|
|
@ -777,6 +1015,28 @@ func executeSyncAction(ctx context.Context, plan BootstrapPlan, cfg *configfile.
|
|||
return nil
|
||||
}
|
||||
|
||||
// printInitJoinGuidance corrects the one thing the gate's shared-store block
|
||||
// gets wrong when `bd init` is the caller: it says to run `bd migrate schema`,
|
||||
// but this init failed before writing metadata.json, so there is no workspace
|
||||
// here to run it from (gastownhall/beads#5920). A client JOINING an existing,
|
||||
// behind shared server has to be told where the command actually works.
|
||||
//
|
||||
// Only the shared-store arm needs this. The remote-backed refusals from init
|
||||
// are already handled by printBootstrapRemoteBehindGuidance above, and their
|
||||
// remedies are not workspace-local in the same way.
|
||||
func printInitJoinGuidance(w io.Writer, e *schema.RemoteMigrateGateError) {
|
||||
if e.Decision != "shared-no-remote" {
|
||||
return
|
||||
}
|
||||
fmt.Fprintf(w,
|
||||
"\n This workspace was NOT created — bd init stopped before writing\n"+
|
||||
" .beads/metadata.json, so `%s` cannot be run from here yet.\n"+
|
||||
" Either run it from a workspace already set up against this server, or\n"+
|
||||
" join and migrate in one step once every client is upgraded:\n"+
|
||||
" %s=1 bd init …\n",
|
||||
schema.SharedConsentCommand, schema.AllowRemoteMigrateEnv)
|
||||
}
|
||||
|
||||
// printBootstrapRemoteBehindGuidance explains a remote-migrate gate refusal in
|
||||
// bootstrap terms. The gate's generic remedy ("adopt the migrated database:
|
||||
// bd bootstrap") is wrong from inside a bootstrap-style clone — the database
|
||||
|
|
|
|||
|
|
@ -3,8 +3,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -92,46 +95,562 @@ func setupSyncRemoteConfig(t *testing.T, beadsDir, remote string) func() {
|
|||
return func() { config.ResetForTesting() }
|
||||
}
|
||||
|
||||
// TestDetectBootstrapAction_GitCodeRepoSyncRemoteBlocked verifies that a
|
||||
// sync.remote pointing at a git code-repository host is rejected (action=none)
|
||||
// instead of triggering DOLT_CLONE.
|
||||
func TestDetectBootstrapAction_GitCodeRepoSyncRemoteBlocked(t *testing.T) {
|
||||
for _, remote := range []string{
|
||||
"git+ssh://github.com/org/repo.git",
|
||||
"https://github.com/org/repo.git",
|
||||
"git@github.com:org/repo.git",
|
||||
"https://gitlab.com/group/repo.git",
|
||||
} {
|
||||
t.Run(remote, func(t *testing.T) {
|
||||
snapshotBootstrapEnv(t)
|
||||
// stubProbeGitRemoteDoltData replaces the refs/dolt/data probe for the
|
||||
// duration of a test. Every test that configures a forge sync.remote must
|
||||
// install a stub: the real probe shells out to `git ls-remote` against
|
||||
// whatever host the fixture URL names.
|
||||
//
|
||||
// A configured sync.remote also suppresses the git-origin auto-detect leg
|
||||
// (gitOriginHasDoltDataRef, which is not behind this seam), so these tests
|
||||
// cannot reach the network through that path either — including the
|
||||
// fall-through cases, whose whole point is to keep going after the probe.
|
||||
func stubProbeGitRemoteDoltData(t *testing.T, fn func(string) (bool, error)) {
|
||||
t.Helper()
|
||||
orig := probeGitRemoteDoltData
|
||||
probeGitRemoteDoltData = fn
|
||||
t.Cleanup(func() { probeGitRemoteDoltData = orig })
|
||||
}
|
||||
|
||||
tmpDir := t.TempDir()
|
||||
beadsDir := filepath.Join(tmpDir, ".beads")
|
||||
if err := os.MkdirAll(beadsDir, 0o750); err != nil {
|
||||
t.Fatal(err)
|
||||
// forgeSyncRemoteForms enumerates the shapes a git-forge sync.remote arrives
|
||||
// in, with the git+ URL normalizeRemoteURL produces for each. Every one of
|
||||
// them is a value bd itself writes (bd init from a git origin, bd dolt remote
|
||||
// add, a hand-edited config.yaml, or finalizeSyncedBootstrap).
|
||||
var forgeSyncRemoteForms = []struct {
|
||||
name string
|
||||
remote string
|
||||
wantClone string
|
||||
}{
|
||||
{"raw https with .git", "https://github.com/org/repo.git", "git+https://github.com/org/repo.git"},
|
||||
{"raw https without .git", "https://github.com/org/repo", "git+https://github.com/org/repo"},
|
||||
{"scp style", "git@github.com:org/repo.git", "git+ssh://git@github.com/org/repo.git"},
|
||||
{"ssh scheme", "ssh://git@github.com/org/repo.git", "git+ssh://git@github.com/org/repo.git"},
|
||||
{"already git+https", "git+https://github.com/org/repo.git", "git+https://github.com/org/repo.git"},
|
||||
{"git+ssh without user", "git+ssh://github.com/org/repo.git", "git+ssh://github.com/org/repo.git"},
|
||||
{"gitlab", "https://gitlab.com/group/repo.git", "git+https://gitlab.com/group/repo.git"},
|
||||
}
|
||||
|
||||
// newForgeSyncRemoteWorkspace builds a workspace whose config.yaml carries
|
||||
// remote as sync.remote and chdirs into it, returning the .beads path.
|
||||
func newForgeSyncRemoteWorkspace(t *testing.T, remote string) string {
|
||||
t.Helper()
|
||||
snapshotBootstrapEnv(t)
|
||||
|
||||
tmpDir := t.TempDir()
|
||||
beadsDir := filepath.Join(tmpDir, ".beads")
|
||||
if err := os.MkdirAll(beadsDir, 0o750); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cleanup := setupSyncRemoteConfig(t, beadsDir, remote)
|
||||
t.Cleanup(cleanup)
|
||||
|
||||
oldWd, _ := os.Getwd()
|
||||
t.Cleanup(func() { _ = os.Chdir(oldWd) })
|
||||
if err := os.Chdir(tmpDir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return beadsDir
|
||||
}
|
||||
|
||||
// TestDetectBootstrapAction_GitForgeSyncRemote_ProbeRouting covers the #5743 /
|
||||
// #5663 fix: a git-forge sync.remote is a supported Dolt remote, so bootstrap
|
||||
// probes refs/dolt/data and routes on the answer instead of rejecting the URL
|
||||
// outright (which printed a success tick and exited 0 with no database).
|
||||
func TestDetectBootstrapAction_GitForgeSyncRemote_ProbeRouting(t *testing.T) {
|
||||
t.Run("data present clones the git+ form", func(t *testing.T) {
|
||||
for _, tc := range forgeSyncRemoteForms {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
beadsDir := newForgeSyncRemoteWorkspace(t, tc.remote)
|
||||
|
||||
var probed []string
|
||||
stubProbeGitRemoteDoltData(t, func(url string) (bool, error) {
|
||||
probed = append(probed, url)
|
||||
return true, nil
|
||||
})
|
||||
|
||||
plan := detectBootstrapAction(beadsDir, configfile.DefaultConfig())
|
||||
|
||||
if plan.Action != "sync" {
|
||||
t.Fatalf("action=%q, want %q (remote carries refs/dolt/data)", plan.Action, "sync")
|
||||
}
|
||||
if plan.SyncRemote != tc.wantClone {
|
||||
t.Errorf("SyncRemote=%q, want %q", plan.SyncRemote, tc.wantClone)
|
||||
}
|
||||
// The durable #4421 pin: once isGitCodeRepoURL recognizes a
|
||||
// URL as a forge, no raw http(s) form of it may reach
|
||||
// DOLT_CLONE, because Dolt routes those through the
|
||||
// remotesapi client and retries forever at ~1000% CPU. The
|
||||
// git+ prefix is what selects the git remote factory.
|
||||
//
|
||||
// Scope note: this pins the routing, not the classifier. A
|
||||
// forge the classifier does not recognize (self-hosted Gitea
|
||||
// at https://git.example.com/org/repo, no .git suffix) still
|
||||
// takes the trusted-as-is path unprobed, exactly as it did
|
||||
// before this change — a pre-existing gap tracked separately.
|
||||
if !strings.HasPrefix(plan.SyncRemote, "git+") {
|
||||
t.Errorf("SyncRemote=%q lacks the git+ prefix; a recognized forge URL must never reach DOLT_CLONE raw (#4421)", plan.SyncRemote)
|
||||
}
|
||||
if plan.Blocked {
|
||||
t.Error("Blocked=true on a successful sync plan")
|
||||
}
|
||||
if len(probed) != 1 || probed[0] != tc.wantClone {
|
||||
t.Errorf("probe calls = %v, want exactly [%q]", probed, tc.wantClone)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("no data falls through to init and still wires the remote", func(t *testing.T) {
|
||||
beadsDir := newForgeSyncRemoteWorkspace(t, "https://github.com/org/repo.git")
|
||||
stubProbeGitRemoteDoltData(t, func(string) (bool, error) { return false, nil })
|
||||
|
||||
plan := detectBootstrapAction(beadsDir, configfile.DefaultConfig())
|
||||
|
||||
if plan.Action != "init" {
|
||||
t.Fatalf("action=%q, want %q (remote wired before the first bd dolt push)", plan.Action, "init")
|
||||
}
|
||||
if plan.Blocked {
|
||||
t.Error("Blocked=true; a clean 'no data yet' probe is not a failure")
|
||||
}
|
||||
// Carried so executeInitAction can register it as Dolt "origin".
|
||||
// Without it the first `bd dolt push` has no remote and either
|
||||
// refuses or adopts the git origin — a different repository under
|
||||
// the dedicated-data-repo pattern.
|
||||
if plan.SyncRemote != "git+https://github.com/org/repo.git" {
|
||||
t.Errorf("SyncRemote=%q, want the routed URL so the fresh database gets wired to it", plan.SyncRemote)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("no data falls through to backup restore", func(t *testing.T) {
|
||||
beadsDir := newForgeSyncRemoteWorkspace(t, "https://github.com/org/repo.git")
|
||||
backupDir := filepath.Join(beadsDir, "backup")
|
||||
if err := os.MkdirAll(backupDir, 0o750); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(backupDir, "issues.jsonl"), []byte(`{"id":"bd-1"}`+"\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
stubProbeGitRemoteDoltData(t, func(string) (bool, error) { return false, nil })
|
||||
|
||||
plan := detectBootstrapAction(beadsDir, configfile.DefaultConfig())
|
||||
|
||||
// Proves the fall-through runs the whole remaining detector chain,
|
||||
// not just the fresh-init tail.
|
||||
if plan.Action != "restore" {
|
||||
t.Fatalf("action=%q, want %q (backup must still be found after the probe falls through)", plan.Action, "restore")
|
||||
}
|
||||
if plan.BackupDir != backupDir {
|
||||
t.Errorf("BackupDir=%q, want %q", plan.BackupDir, backupDir)
|
||||
}
|
||||
})
|
||||
|
||||
// The error text is the shape the real probe now produces: git's own
|
||||
// stderr, threaded out of exec.ExitError.Stderr by gitLsRemoteProbeError.
|
||||
probeErr := errors.New("git ls-remote: exit status 128: fatal: Could not read from remote repository.")
|
||||
|
||||
t.Run("probe error blocks and never clones", func(t *testing.T) {
|
||||
const remote = "git+ssh://github.com/org/repo.git"
|
||||
beadsDir := newForgeSyncRemoteWorkspace(t, remote)
|
||||
stubProbeGitRemoteDoltData(t, func(string) (bool, error) { return false, probeErr })
|
||||
|
||||
plan := detectBootstrapAction(beadsDir, configfile.DefaultConfig())
|
||||
|
||||
if plan.Action != "none" {
|
||||
t.Fatalf("action=%q, want %q (UNKNOWN must fail closed)", plan.Action, "none")
|
||||
}
|
||||
if !plan.Blocked {
|
||||
t.Error("Blocked=false; an unverifiable remote must exit non-zero, not print a success tick")
|
||||
}
|
||||
if plan.SyncRemote != "" {
|
||||
t.Errorf("SyncRemote=%q, want empty (an unverified URL must not be cloned from or pushed to)", plan.SyncRemote)
|
||||
}
|
||||
if plan.BlockedRemote != remote {
|
||||
t.Errorf("BlockedRemote=%q, want %q (needed for the ls-remote hint)", plan.BlockedRemote, remote)
|
||||
}
|
||||
if !strings.Contains(plan.Reason, remote) {
|
||||
t.Errorf("Reason=%q does not name the offending URL %q", plan.Reason, remote)
|
||||
}
|
||||
if !strings.Contains(plan.Reason, "Could not read from remote repository") {
|
||||
t.Errorf("Reason=%q does not carry git's own diagnosis", plan.Reason)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("probe error still restores from a local backup", func(t *testing.T) {
|
||||
// Offline laptop or credential-less CI: verifying the remote failed,
|
||||
// but restoring a local backup touches no remote. The same machine
|
||||
// with network and an empty remote would restore from this identical
|
||||
// file, so a probe failure must not be the thing that denies it.
|
||||
beadsDir := newForgeSyncRemoteWorkspace(t, "https://github.com/org/repo.git")
|
||||
backupDir := filepath.Join(beadsDir, "backup")
|
||||
if err := os.MkdirAll(backupDir, 0o750); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(backupDir, "issues.jsonl"), []byte(`{"id":"bd-1"}`+"\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
stubProbeGitRemoteDoltData(t, func(string) (bool, error) { return false, probeErr })
|
||||
|
||||
plan := detectBootstrapAction(beadsDir, configfile.DefaultConfig())
|
||||
|
||||
if plan.Action != "restore" {
|
||||
t.Fatalf("action=%q reason=%q, want %q", plan.Action, plan.Reason, "restore")
|
||||
}
|
||||
if plan.Blocked {
|
||||
t.Error("Blocked=true on a plan that recovers locally")
|
||||
}
|
||||
if plan.SyncRemote != "" {
|
||||
t.Errorf("SyncRemote=%q, want empty: the remote is unverified, so nothing may be wired to it", plan.SyncRemote)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("probe error still imports git-tracked jsonl", func(t *testing.T) {
|
||||
beadsDir := newForgeSyncRemoteWorkspace(t, "https://github.com/org/repo.git")
|
||||
jsonl := filepath.Join(beadsDir, "issues.jsonl")
|
||||
if err := os.WriteFile(jsonl, []byte(`{"id":"bd-1"}`+"\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
stubProbeGitRemoteDoltData(t, func(string) (bool, error) { return false, probeErr })
|
||||
|
||||
plan := detectBootstrapAction(beadsDir, configfile.DefaultConfig())
|
||||
|
||||
if plan.Action != "jsonl-import" {
|
||||
t.Fatalf("action=%q reason=%q, want %q", plan.Action, plan.Reason, "jsonl-import")
|
||||
}
|
||||
if plan.Blocked {
|
||||
t.Error("Blocked=true on a plan that recovers locally")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("credentials are stripped from the reason and the blocked URL", func(t *testing.T) {
|
||||
const token = "ghp_SUPERSECRETTOKENVALUE"
|
||||
beadsDir := newForgeSyncRemoteWorkspace(t, "https://x-access-token:"+token+"@github.com/org/repo.git")
|
||||
stubProbeGitRemoteDoltData(t, func(string) (bool, error) { return false, probeErr })
|
||||
|
||||
plan := detectBootstrapAction(beadsDir, configfile.DefaultConfig())
|
||||
|
||||
if !plan.Blocked {
|
||||
t.Fatalf("action=%q, want a blocked plan", plan.Action)
|
||||
}
|
||||
// Reason and blocked_remote both land in CI logs and agent
|
||||
// transcripts; the clone funnel already scrubs userinfo before
|
||||
// reporting and these diagnostics must not be the hole in that.
|
||||
if strings.Contains(plan.Reason, token) {
|
||||
t.Errorf("Reason leaks the token: %q", plan.Reason)
|
||||
}
|
||||
if strings.Contains(plan.BlockedRemote, token) {
|
||||
t.Errorf("BlockedRemote leaks the token: %q", plan.BlockedRemote)
|
||||
}
|
||||
if !strings.Contains(plan.BlockedRemote, "github.com/org/repo.git") {
|
||||
t.Errorf("BlockedRemote=%q lost the part the user needs", plan.BlockedRemote)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("routing is cwd independent in a monorepo subdir", func(t *testing.T) {
|
||||
remote := "https://github.com/org/repo.git"
|
||||
beadsDir := newForgeSyncRemoteWorkspace(t, remote)
|
||||
|
||||
subDir := filepath.Join(filepath.Dir(beadsDir), "sub", "dir")
|
||||
if err := os.MkdirAll(subDir, 0o750); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Chdir(subDir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var probed []string
|
||||
stubProbeGitRemoteDoltData(t, func(url string) (bool, error) {
|
||||
probed = append(probed, url)
|
||||
return true, nil
|
||||
})
|
||||
|
||||
plan := detectBootstrapAction(beadsDir, configfile.DefaultConfig())
|
||||
|
||||
if plan.Action != "sync" {
|
||||
t.Fatalf("action=%q, want %q from a subdirectory", plan.Action, "sync")
|
||||
}
|
||||
if len(probed) != 1 || probed[0] != "git+https://github.com/org/repo.git" {
|
||||
t.Errorf("probe calls = %v, want exactly [%q]", probed, "git+https://github.com/org/repo.git")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestBootstrapPlanOutcome pins the exit status of every plan shape.
|
||||
// Action=="none" used to be an unconditional success, which is how a rejected
|
||||
// sync.remote exited 0 with no database (#5743). Blocked is the single
|
||||
// discriminator; --dry-run is always a successful preview.
|
||||
func TestBootstrapPlanOutcome(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
plan BootstrapPlan
|
||||
dryRun bool
|
||||
wantExit int // 0 means "nil error"
|
||||
}{
|
||||
{
|
||||
name: "existing database is a genuine no-op",
|
||||
plan: BootstrapPlan{Action: "none", HasExisting: true, Reason: "Database already exists at /tmp/x"},
|
||||
wantExit: 0,
|
||||
},
|
||||
{
|
||||
name: "blocked plan fails",
|
||||
plan: BootstrapPlan{Action: "none", Blocked: true, Reason: "could not verify refs/dolt/data"},
|
||||
wantExit: 1,
|
||||
},
|
||||
{
|
||||
name: "sync plan proceeds",
|
||||
plan: BootstrapPlan{Action: "sync", SyncRemote: "git+https://github.com/org/repo.git"},
|
||||
wantExit: 0,
|
||||
},
|
||||
{
|
||||
name: "init plan proceeds",
|
||||
plan: BootstrapPlan{Action: "init"},
|
||||
wantExit: 0,
|
||||
},
|
||||
{
|
||||
// bd doctor documents `bd bootstrap --dry-run` as the safe
|
||||
// inspection step, so a preview must never abort a set -e script.
|
||||
name: "dry run previews a blocked plan without failing",
|
||||
plan: BootstrapPlan{Action: "none", Blocked: true, Reason: "could not verify refs/dolt/data"},
|
||||
dryRun: true,
|
||||
wantExit: 0,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := bootstrapPlanOutcome(tt.plan, tt.dryRun)
|
||||
if tt.wantExit == 0 {
|
||||
if err != nil {
|
||||
t.Fatalf("bootstrapPlanOutcome() = %v, want nil", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
cleanup := setupSyncRemoteConfig(t, beadsDir, remote)
|
||||
defer cleanup()
|
||||
|
||||
oldWd, _ := os.Getwd()
|
||||
defer func() { _ = os.Chdir(oldWd) }()
|
||||
if err := os.Chdir(tmpDir); err != nil {
|
||||
t.Fatal(err)
|
||||
code, ok := exitCodeFromError(err)
|
||||
if !ok {
|
||||
t.Fatalf("bootstrapPlanOutcome() = %v, want an *exitError", err)
|
||||
}
|
||||
|
||||
cfg := configfile.DefaultConfig()
|
||||
plan := detectBootstrapAction(beadsDir, cfg)
|
||||
|
||||
if plan.Action != "none" {
|
||||
t.Errorf("remote=%q: action=%q, want %q (git code-repo URL must be blocked)", remote, plan.Action, "none")
|
||||
}
|
||||
if plan.SyncRemote != "" {
|
||||
t.Errorf("remote=%q: SyncRemote=%q, want empty (blocked URL must not propagate)", remote, plan.SyncRemote)
|
||||
if code != tt.wantExit {
|
||||
t.Errorf("exit code = %d, want %d", code, tt.wantExit)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestDetectBootstrapAction_BlockedIsDerivedNotInherited covers the state-leak
|
||||
// class the seeded plan used to create: existingBootstrapDBPlan's "none"
|
||||
// verdict was copied into the working plan, so every later branch inherited
|
||||
// its HasExisting/Blocked/Reason. A probe error on top of a seeded
|
||||
// HasExisting=true produced action=none + blocked=true + has_existing=true,
|
||||
// which printed the success tick and exited 0 — the #5743 bug, reintroduced.
|
||||
func TestDetectBootstrapAction_BlockedIsDerivedNotInherited(t *testing.T) {
|
||||
// newSeededServerWorkspace builds the synthesized-beadsDir shape: the
|
||||
// .beads directory does not exist, so existingBootstrapDBPlan's verdict is
|
||||
// held as a fallback rather than returned outright.
|
||||
newSeededServerWorkspace := func(t *testing.T, remote string, check bootstrapServerDBCheck) (string, *configfile.Config) {
|
||||
t.Helper()
|
||||
snapshotBootstrapEnv(t)
|
||||
|
||||
tmpDir := t.TempDir()
|
||||
configDir := filepath.Join(tmpDir, "config-beads")
|
||||
if err := os.MkdirAll(configDir, 0o750); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cleanup := setupSyncRemoteConfig(t, configDir, remote)
|
||||
t.Cleanup(cleanup)
|
||||
|
||||
doltDataDir := filepath.Join(tmpDir, "dolt-data")
|
||||
if err := os.MkdirAll(filepath.Join(doltDataDir, "mydb"), 0o750); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv("BEADS_DOLT_DATA_DIR", doltDataDir)
|
||||
|
||||
oldWd, _ := os.Getwd()
|
||||
t.Cleanup(func() { _ = os.Chdir(oldWd) })
|
||||
if err := os.Chdir(tmpDir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
origCheck := checkBootstrapServerDB
|
||||
checkBootstrapServerDB = func(bootstrapServerProbeConfig) bootstrapServerDBCheck { return check }
|
||||
t.Cleanup(func() { checkBootstrapServerDB = origCheck })
|
||||
|
||||
origDelay := bootstrapRetryDelay
|
||||
bootstrapRetryDelay = func(time.Duration) {}
|
||||
t.Cleanup(func() { bootstrapRetryDelay = origDelay })
|
||||
|
||||
cfg := configfile.DefaultConfig()
|
||||
cfg.DoltMode = configfile.DoltModeServer
|
||||
cfg.DoltDatabase = "mydb"
|
||||
cfg.DoltDataDir = doltDataDir
|
||||
// Never created: this is the "fresh clone, .beads synthesized" path.
|
||||
return filepath.Join(tmpDir, ".beads"), cfg
|
||||
}
|
||||
|
||||
t.Run("existing server database wins over a failed probe", func(t *testing.T) {
|
||||
beadsDir, cfg := newSeededServerWorkspace(t, "https://github.com/org/repo.git",
|
||||
bootstrapServerDBCheck{Exists: true, Reachable: true})
|
||||
stubProbeGitRemoteDoltData(t, func(string) (bool, error) {
|
||||
return false, errors.New("git ls-remote: exit status 128")
|
||||
})
|
||||
|
||||
plan := detectBootstrapAction(beadsDir, cfg)
|
||||
|
||||
if !plan.HasExisting {
|
||||
t.Fatalf("HasExisting=false; the server database exists (action=%q reason=%q)", plan.Action, plan.Reason)
|
||||
}
|
||||
if plan.Blocked {
|
||||
t.Error("Blocked=true alongside HasExisting=true — self-contradictory, and it would print the tick AND claim a block")
|
||||
}
|
||||
if err := bootstrapPlanOutcome(plan, false); err != nil {
|
||||
t.Errorf("outcome = %v, want nil: a database exists", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("failed server verification does not taint a later sync plan", func(t *testing.T) {
|
||||
beadsDir, cfg := newSeededServerWorkspace(t, "https://github.com/org/repo.git",
|
||||
bootstrapServerDBCheck{Reachable: true, Err: errors.New("dial tcp: connection refused")})
|
||||
stubProbeGitRemoteDoltData(t, func(string) (bool, error) { return true, nil })
|
||||
|
||||
plan := detectBootstrapAction(beadsDir, cfg)
|
||||
|
||||
if plan.Action != "sync" {
|
||||
t.Fatalf("action=%q reason=%q, want %q", plan.Action, plan.Reason, "sync")
|
||||
}
|
||||
if plan.Blocked {
|
||||
t.Error(`Blocked=true on a sync plan: "nothing may clone from a blocked plan" is the field's own contract`)
|
||||
}
|
||||
if plan.BlockedRemote != "" {
|
||||
t.Errorf("BlockedRemote=%q on a sync plan", plan.BlockedRemote)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("unverifiable server database with no other source blocks", func(t *testing.T) {
|
||||
beadsDir, cfg := newSeededServerWorkspace(t, "",
|
||||
bootstrapServerDBCheck{Reachable: true, Err: errors.New("dial tcp: connection refused")})
|
||||
|
||||
plan := detectBootstrapAction(beadsDir, cfg)
|
||||
|
||||
if plan.Action != "none" || !plan.Blocked {
|
||||
t.Fatalf("action=%q blocked=%v, want none+blocked", plan.Action, plan.Blocked)
|
||||
}
|
||||
if err := bootstrapPlanOutcome(plan, false); err == nil {
|
||||
t.Error("outcome = nil; an unverifiable database must not report success")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestPrintBootstrapPlan_NoneWithoutDB_NoSuccessTick pins the other half of
|
||||
// the #5743 false success: the "✓ Database already exists" line must be
|
||||
// reserved for plans that actually found a database.
|
||||
func TestPrintBootstrapPlan_NoneWithoutDB_NoSuccessTick(t *testing.T) {
|
||||
blocked := BootstrapPlan{
|
||||
Action: "none",
|
||||
Blocked: true,
|
||||
BeadsDir: "/workspace/.beads",
|
||||
BlockedRemote: "git+ssh://github.com/org/repo.git",
|
||||
Reason: `could not verify refs/dolt/data on sync.remote "git+ssh://github.com/org/repo.git": git ls-remote: exit status 128: fatal: Could not read from remote repository.`,
|
||||
}
|
||||
|
||||
t.Run("blocked plan prints nothing to stdout", func(t *testing.T) {
|
||||
out := captureStdout(t, func() error { printBootstrapPlan(blocked); return nil })
|
||||
if strings.TrimSpace(out) != "" {
|
||||
t.Fatalf("blocked plan wrote to stdout (the success tick lives there):\n%s", out)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("blocked plan reports the reason and actionable hints on stderr", func(t *testing.T) {
|
||||
out := captureStderr(t, func() { printBootstrapPlan(blocked) })
|
||||
|
||||
if strings.Contains(out, "Database already exists") {
|
||||
t.Fatalf("blocked plan printed a success tick:\n%s", out)
|
||||
}
|
||||
if !strings.Contains(out, blocked.Reason) {
|
||||
t.Errorf("output does not carry the reason:\n%s", out)
|
||||
}
|
||||
// The hint must be runnable: git ls-remote does not understand the
|
||||
// git+ prefix, so it is stripped exactly as the probe strips it.
|
||||
if !strings.Contains(out, "git ls-remote ssh://github.com/org/repo.git refs/dolt/data") {
|
||||
t.Errorf("output lacks a runnable ls-remote hint:\n%s", out)
|
||||
}
|
||||
// Deleting sync.remote is NOT offered as a remedy: the git-origin
|
||||
// probe swallows its error, so on a credential failure that retry
|
||||
// would "succeed" by creating a database diverged from the team's.
|
||||
if strings.Contains(out, "remove 'sync.remote'") {
|
||||
t.Errorf("hint still suggests deleting sync.remote, which can silently diverge:\n%s", out)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("existing database keeps the success tick", func(t *testing.T) {
|
||||
plan := BootstrapPlan{
|
||||
Action: "none",
|
||||
HasExisting: true,
|
||||
BeadsDir: "/workspace/.beads",
|
||||
Reason: "Database already exists at /workspace/.beads/embeddeddolt",
|
||||
}
|
||||
|
||||
out := captureStdout(t, func() error { printBootstrapPlan(plan); return nil })
|
||||
|
||||
if !strings.Contains(out, "✓ Database already exists: /workspace/.beads") {
|
||||
t.Fatalf("existing database lost its success line:\n%s", out)
|
||||
}
|
||||
if !strings.Contains(out, "Nothing to do") {
|
||||
t.Errorf("existing database lost its 'Nothing to do' line:\n%s", out)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("sync plan does not print credentials", func(t *testing.T) {
|
||||
const token = "ghp_SUPERSECRETTOKENVALUE"
|
||||
plan := BootstrapPlan{
|
||||
Action: "sync",
|
||||
BeadsDir: "/workspace/.beads",
|
||||
Database: "beads",
|
||||
SyncRemote: "git+https://x-access-token:" + token + "@github.com/org/repo.git",
|
||||
}
|
||||
|
||||
out := captureStdout(t, func() error { printBootstrapPlan(plan); return nil })
|
||||
|
||||
if strings.Contains(out, token) {
|
||||
t.Fatalf("plan output leaks the token:\n%s", out)
|
||||
}
|
||||
if !strings.Contains(out, "github.com/org/repo.git") {
|
||||
t.Errorf("plan output lost the remote entirely:\n%s", out)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestBootstrapPlanJSON_RedactsCredentials closes the JSON half of the same
|
||||
// credential leak: `bd bootstrap --json` serializes the plan, and BootstrapPlan.
|
||||
// MarshalJSON must redact SyncRemote the way printBootstrapPlan redacts the human
|
||||
// path. The existing "sync plan does not print credentials" subtest covers only
|
||||
// printBootstrapPlan, so without this the JSON gap is invisible. It also pins the
|
||||
// "redact on a copy" contract — the plan executeBootstrapPlan clones from must
|
||||
// keep its real credentials.
|
||||
func TestBootstrapPlanJSON_RedactsCredentials(t *testing.T) {
|
||||
const token = "ghp_SUPERSECRETTOKENVALUE"
|
||||
plan := BootstrapPlan{
|
||||
Action: "sync",
|
||||
BeadsDir: "/workspace/.beads",
|
||||
Database: "beads",
|
||||
SyncRemote: "git+https://x-access-token:" + token + "@github.com/org/repo.git",
|
||||
}
|
||||
|
||||
encoded, err := json.Marshal(plan)
|
||||
if err != nil {
|
||||
t.Fatalf("json.Marshal(plan) failed: %v", err)
|
||||
}
|
||||
out := string(encoded)
|
||||
|
||||
if strings.Contains(out, token) {
|
||||
t.Fatalf("bootstrap plan JSON leaks the token:\n%s", out)
|
||||
}
|
||||
if !strings.Contains(out, "github.com/org/repo.git") {
|
||||
t.Errorf("bootstrap plan JSON dropped the remote host/path entirely:\n%s", out)
|
||||
}
|
||||
// Redaction must not mutate the plan executeBootstrapPlan consumes for the
|
||||
// clone, or the clone would lose the credentials it needs.
|
||||
if !strings.Contains(plan.SyncRemote, token) {
|
||||
t.Errorf("MarshalJSON mutated the source plan's SyncRemote: %q", plan.SyncRemote)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDetectBootstrapAction_ValidDoltSyncRemoteUnchanged verifies that a valid
|
||||
// Dolt remote URL is still accepted as-is (no regression from Layer 1 guard).
|
||||
func TestDetectBootstrapAction_ValidDoltSyncRemoteUnchanged(t *testing.T) {
|
||||
|
|
@ -141,21 +660,15 @@ func TestDetectBootstrapAction_ValidDoltSyncRemoteUnchanged(t *testing.T) {
|
|||
"git+ssh://my-self-hosted-dolt.example.com/org/db",
|
||||
} {
|
||||
t.Run(remote, func(t *testing.T) {
|
||||
snapshotBootstrapEnv(t)
|
||||
beadsDir := newForgeSyncRemoteWorkspace(t, remote)
|
||||
|
||||
tmpDir := t.TempDir()
|
||||
beadsDir := filepath.Join(tmpDir, ".beads")
|
||||
if err := os.MkdirAll(beadsDir, 0o750); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cleanup := setupSyncRemoteConfig(t, beadsDir, remote)
|
||||
defer cleanup()
|
||||
|
||||
oldWd, _ := os.Getwd()
|
||||
defer func() { _ = os.Chdir(oldWd) }()
|
||||
if err := os.Chdir(tmpDir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Non-forge remotes take the trusted-as-is path and must never
|
||||
// pay for an ls-remote — a Dolt remotesapi endpoint has no
|
||||
// refs/dolt/data to probe in the first place.
|
||||
stubProbeGitRemoteDoltData(t, func(url string) (bool, error) {
|
||||
t.Fatalf("probed non-forge remote %q; the trusted-as-is path must not probe", url)
|
||||
return false, nil
|
||||
})
|
||||
|
||||
cfg := configfile.DefaultConfig()
|
||||
plan := detectBootstrapAction(beadsDir, cfg)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ func TestRequireBootstrapDoltBackendRejectsRegisteredBackend(t *testing.T) {
|
|||
const name = "registry-bootstrap"
|
||||
registerContractBackend(t, name)
|
||||
|
||||
err := requireBootstrapDoltBackend(&configfile.Config{Backend: name})
|
||||
err := requireBootstrapDoltBackend(&configfile.Config{Backend: name}, t.TempDir())
|
||||
if err == nil {
|
||||
t.Fatal("requireBootstrapDoltBackend accepted a registered backend; want fail-closed rejection")
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ func TestRequireBootstrapDoltBackendRejectsRegisteredBackend(t *testing.T) {
|
|||
{"empty backend", &configfile.Config{}},
|
||||
{"explicit dolt", &configfile.Config{Backend: configfile.BackendDolt}},
|
||||
} {
|
||||
if err := requireBootstrapDoltBackend(tc.cfg); err != nil {
|
||||
if err := requireBootstrapDoltBackend(tc.cfg, t.TempDir()); err != nil {
|
||||
t.Errorf("requireBootstrapDoltBackend rejected the %s config: %v", tc.label, err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ the flags appear in the command line.`,
|
|||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
CheckReadonly("close") // also covers CheckMigrationFreeze (dc-6jaq)
|
||||
CheckReadonly("close") // also covers the migration freeze check (dc-6jaq)
|
||||
|
||||
evt := metrics.NewCommandEvent("close")
|
||||
defer func() {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,13 @@ How it works:
|
|||
4. Swaps main branch to the compacted version
|
||||
5. Prunes remote-tracking refs (they would keep the old history alive;
|
||||
the next push or fetch re-creates them at the new tip)
|
||||
6. Runs Dolt GC to reclaim space
|
||||
6. Runs a full Dolt GC (all storage generations) to reclaim the old history
|
||||
|
||||
The GC pass is a full collection: Dolt storage is generational, and a default
|
||||
GC never revisits data an earlier GC moved to the old generation. On any store
|
||||
that has been GC'd before (bd gc, or a previous flatten or compact), only a
|
||||
full collection reclaims the squashed history. A full GC can take minutes on
|
||||
multi-gigabyte stores.
|
||||
|
||||
Examples:
|
||||
bd compact --dry-run # Preview: show commit breakdown
|
||||
|
|
@ -187,11 +193,7 @@ Examples:
|
|||
}
|
||||
|
||||
// Reclaim disk space from orphaned old history
|
||||
if gc, ok := storage.UnwrapStore(store).(storage.GarbageCollector); ok {
|
||||
if err := gc.DoltGC(ctx); err != nil {
|
||||
WarnError("dolt gc after compact failed: %v", err)
|
||||
}
|
||||
}
|
||||
gcMode := runPostRewriteGC(ctx, "compact")
|
||||
sizeAfter := storeSizeBytes(ctx)
|
||||
|
||||
elapsed := time.Since(start)
|
||||
|
|
@ -208,6 +210,9 @@ Examples:
|
|||
"tags_anchoring": tags,
|
||||
"elapsed_ms": elapsed.Milliseconds(),
|
||||
}
|
||||
if gcMode != "" {
|
||||
result["gc_mode"] = gcMode
|
||||
}
|
||||
addGCSizeJSON(result, sizeBefore, sizeAfter)
|
||||
return outputJSON(result)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,7 +143,13 @@ func runCompactProxiedServer(ctx context.Context) error {
|
|||
if tags, perr = versioncontrolops.ListTags(ctx, conn); perr != nil {
|
||||
WarnError("listing tags before GC: %v", perr)
|
||||
}
|
||||
if perr := versioncontrolops.DoltGC(ctx, conn); perr != nil {
|
||||
// Full pass: the squash orphans a commit chain that any earlier GC
|
||||
// already promoted to the old generation, which a default pass never
|
||||
// revisits.
|
||||
if !jsonOutput {
|
||||
fmt.Println(" Running full Dolt GC (all generations; can take minutes on large stores)...")
|
||||
}
|
||||
if perr := versioncontrolops.DoltGCFull(ctx, conn); perr != nil {
|
||||
WarnError("dolt gc after compact failed: %v", perr)
|
||||
}
|
||||
return nil
|
||||
|
|
@ -167,6 +173,7 @@ func runCompactProxiedServer(ctx context.Context) error {
|
|||
"recent_kept": recentCommits,
|
||||
"remote_refs_pruned": pruned,
|
||||
"tags_anchoring": tags,
|
||||
"gc_mode": gcModeFull,
|
||||
"elapsed_ms": elapsed.Milliseconds(),
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -138,13 +138,18 @@ func runConcludeCommand(t *testing.T, commandStore storage.DoltStorage, asJSON b
|
|||
defer func() { os.Stdout, os.Stderr = oldStdout, oldStderr }()
|
||||
store, rootCtx, jsonOutput = commandStore, context.Background(), asJSON
|
||||
conflictsConclude = true
|
||||
// Deferred, like the stdio restore above it: RunE below can panic or
|
||||
// t.Fatal, and a plain statement after the call would then leave jsonOutput
|
||||
// set to asJSON — which callers pass as true — for the rest of the package.
|
||||
defer func() {
|
||||
store, rootCtx, jsonOutput = oldStore, oldRootCtx, oldJSON
|
||||
conflictsConclude = oldConclude
|
||||
}()
|
||||
|
||||
commandErr := conflictsResolveCmd.RunE(conflictsResolveCmd, nil)
|
||||
|
||||
_ = wOut.Close()
|
||||
_ = wErr.Close()
|
||||
store, rootCtx, jsonOutput = oldStore, oldRootCtx, oldJSON
|
||||
conflictsConclude = oldConclude
|
||||
|
||||
var stdout, stderr bytes.Buffer
|
||||
_, _ = stdout.ReadFrom(rOut)
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ var createCmd = &cobra.Command{
|
|||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
CheckReadonly("create") // also covers CheckMigrationFreeze (dc-6jaq)
|
||||
CheckReadonly("create") // also covers the migration freeze check (dc-6jaq)
|
||||
|
||||
evt := metrics.NewCommandEvent("create")
|
||||
defer func() {
|
||||
|
|
@ -197,33 +197,10 @@ var createCmd = &cobra.Command{
|
|||
return HandleError("--ephemeral and --no-history are mutually exclusive")
|
||||
}
|
||||
storageClassFlag, _ := cmd.Flags().GetString("storage-class")
|
||||
storageClass, err := resolveStorageClass(storageClassFlag, types.IssueType(issueType).Normalize())
|
||||
storageClass, wisp, err := resolveCreateStorageClass(storageClassFlag, types.IssueType(issueType), wisp, noHistory)
|
||||
if err != nil {
|
||||
return HandleError("%v", err)
|
||||
}
|
||||
// --storage-class ephemeral is the spelled-out spelling of --ephemeral
|
||||
// (Protocol v0.1 C1.4: the wisp plane is today's ephemeral-class
|
||||
// implementation). It routes to the wisp path exactly like the flag;
|
||||
// the --no-history mutual exclusion above still applies.
|
||||
if storageClass == types.StorageClassEphemeral {
|
||||
if noHistory {
|
||||
return HandleError("--storage-class ephemeral and --no-history are mutually exclusive")
|
||||
}
|
||||
wisp = true
|
||||
storageClass = "" // wisp-plane rows derive ephemeral class (C1.2); no marker cell needed
|
||||
}
|
||||
// Reconcile the requested durable class with the effective wisp plane
|
||||
// (flag > config, Protocol v0.1 §C1.3): an explicit --storage-class
|
||||
// contradicts --ephemeral/--no-history and is rejected, so the durable
|
||||
// intent is preserved rather than silently collapsed into an
|
||||
// effective-ephemeral record; a per-type config default yields to the
|
||||
// explicit flag. versioned normalizes to the unset marker only after the
|
||||
// check (C2.4).
|
||||
var storageClassConflict bool
|
||||
storageClass, storageClassConflict = reconcileStorageClassPlane(storageClass, storageClassFlag != "", wisp || noHistory)
|
||||
if storageClassConflict {
|
||||
return HandleError("--storage-class %s conflicts with --ephemeral/--no-history: wisp-plane records are storage class ephemeral", storageClass)
|
||||
}
|
||||
molTypeStr, _ := cmd.Flags().GetString("mol-type")
|
||||
var molType types.MolType
|
||||
if molTypeStr != "" {
|
||||
|
|
@ -759,6 +736,49 @@ func reconcileStorageClassPlane(class types.StorageClass, explicit, wispPlane bo
|
|||
return class.Normalize(), false
|
||||
}
|
||||
|
||||
// resolveCreateStorageClass is the ONE create-time storage-class decision every
|
||||
// `bd create` CLI door makes: parse the flag (or fall back to the per-type
|
||||
// storage-class.<type> config default), route the ephemeral spelling to the wisp
|
||||
// plane, and reject a durable class that contradicts the plane. Every door goes
|
||||
// through it so the direct, proxied, and --file routes cannot answer differently;
|
||||
// graphApplyNodeStorageClass is the per-node mirror, which additionally honors a
|
||||
// node's own pointer overrides.
|
||||
//
|
||||
// flagValue is the raw --storage-class spelling ("" when unset). wisp/noHistory
|
||||
// are the plane flags as the caller read them; the returned wisp is the plane
|
||||
// AFTER the ephemeral spelling has been folded in (Protocol v0.1 C1.4). The
|
||||
// returned class is already normalized (C2.4), so it can go straight onto the
|
||||
// issue.
|
||||
func resolveCreateStorageClass(flagValue string, issueType types.IssueType, wisp, noHistory bool) (types.StorageClass, bool, error) {
|
||||
class, err := resolveStorageClass(flagValue, issueType.Normalize())
|
||||
if err != nil {
|
||||
return "", wisp, err
|
||||
}
|
||||
// --storage-class ephemeral is the spelled-out spelling of --ephemeral
|
||||
// (Protocol v0.1 C1.4: the wisp plane is today's ephemeral-class
|
||||
// implementation). It routes to the wisp path exactly like the flag; the
|
||||
// --ephemeral/--no-history mutual exclusion still applies.
|
||||
if class == types.StorageClassEphemeral {
|
||||
if noHistory {
|
||||
return "", wisp, errors.New("--storage-class ephemeral and --no-history are mutually exclusive")
|
||||
}
|
||||
wisp = true
|
||||
class = "" // wisp-plane rows derive ephemeral class (C1.2); no marker cell needed
|
||||
}
|
||||
// Reconcile the requested durable class with the effective wisp plane
|
||||
// (flag > config, Protocol v0.1 §C1.3): an explicit --storage-class
|
||||
// contradicts --ephemeral/--no-history and is rejected, so the durable
|
||||
// intent is preserved rather than silently collapsed into an
|
||||
// effective-ephemeral record; a per-type config default yields to the
|
||||
// explicit flag. versioned normalizes to the unset marker only after the
|
||||
// check (C2.4).
|
||||
class, conflict := reconcileStorageClassPlane(class, flagValue != "", wisp || noHistory)
|
||||
if conflict {
|
||||
return "", wisp, fmt.Errorf("--storage-class %s conflicts with --ephemeral/--no-history: wisp-plane records are storage class ephemeral", class)
|
||||
}
|
||||
return class, wisp, nil
|
||||
}
|
||||
|
||||
func buildCreateIssue(params createIssueParams) *types.Issue {
|
||||
var externalRefPtr *string
|
||||
if params.ExternalRef != "" {
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@ type createInput struct {
|
|||
validate bool
|
||||
ephemeral bool
|
||||
noHistory bool
|
||||
storageClass types.StorageClass
|
||||
storageClassFlag string
|
||||
molType types.MolType
|
||||
wispType types.WispType
|
||||
eventCategory string
|
||||
|
|
@ -180,6 +182,21 @@ func gatherCreateInput(cmd *cobra.Command, args []string) (createInput, error) {
|
|||
in.priority = priority
|
||||
|
||||
in.issueType, _ = cmd.Flags().GetString("type")
|
||||
|
||||
// The raw flag rides along for the --file batch, which resolves the class
|
||||
// per template (the per-type config default needs a type to key on, and only
|
||||
// a template has one). --graph rejects the flag outright, so the only route
|
||||
// that resolves it here is the single-issue create, on both transports.
|
||||
in.storageClassFlag, _ = cmd.Flags().GetString("storage-class")
|
||||
if in.markdownFile == "" && in.graphFile == "" {
|
||||
class, wisp, err := resolveCreateStorageClass(in.storageClassFlag, types.IssueType(in.issueType), in.ephemeral, in.noHistory)
|
||||
if err != nil {
|
||||
return in, HandleError("%v", err)
|
||||
}
|
||||
in.storageClass = class
|
||||
in.ephemeral = wisp
|
||||
}
|
||||
|
||||
in.status, _ = cmd.Flags().GetString("status")
|
||||
in.assignee, _ = cmd.Flags().GetString("assignee")
|
||||
in.externalRef, _ = cmd.Flags().GetString("external-ref")
|
||||
|
|
@ -334,6 +351,12 @@ func rejectSingleIssueFlagsForGraph(cmd *cobra.Command) error {
|
|||
if cmd.Flags().Changed("mol-type") {
|
||||
return HandleError("--mol-type is not valid with --graph (set mol_type per node in the plan instead)")
|
||||
}
|
||||
// Same shape as --mol-type: a plan-wide class would duplicate the per-node
|
||||
// storage_class field (plus its per-type config default) that graph-apply
|
||||
// already honors, so the flag is refused rather than accepted and ignored.
|
||||
if cmd.Flags().Changed("storage-class") {
|
||||
return HandleError("--storage-class is not valid with --graph (set storage_class per node in the plan instead)")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ func resolveProxiedCustomTypes(dbTypes []string) []string {
|
|||
|
||||
func runCreateProxiedServer(cmd *cobra.Command, ctx context.Context, in createInput) error {
|
||||
if in.repoOverrideSet {
|
||||
return HandleError("--repo is not supported with --proxied-server")
|
||||
return HandleProxyCapabilityError(AssertProxyCapability(ProxyModeProxied, ProxyCapRepo))
|
||||
}
|
||||
switch {
|
||||
case in.graphFile != "":
|
||||
|
|
@ -226,6 +226,7 @@ func buildCreateIssueFromInput(in createInput) *types.Issue {
|
|||
EstimatedMinutes: in.estimatedMinutes,
|
||||
Ephemeral: in.ephemeral,
|
||||
NoHistory: in.noHistory,
|
||||
StorageClass: in.storageClass,
|
||||
CreatedBy: in.createdBy,
|
||||
Owner: in.owner,
|
||||
MolType: in.molType,
|
||||
|
|
|
|||
121
cmd/bd/create_timestamp_precision_embedded_test.go
Normal file
121
cmd/bd/create_timestamp_precision_embedded_test.go
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
//go:build cgo
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// TestEmbeddedCreateJSONEchoesSubSecondTimestamps pins that `bd create --json`
|
||||
// prints the instant the row was written, fraction included.
|
||||
//
|
||||
// created_at is a DATETIME(0) column, so anything that renders a create by
|
||||
// re-reading the row it just wrote prints whole seconds. `bd create --json` has
|
||||
// never done that: it echoes the stamp the write carried, and agents that create
|
||||
// several issues in a burst order them by exactly that fraction. A build that
|
||||
// echoed the re-read made every same-second create tie.
|
||||
//
|
||||
// THE ASSERTION IS THAT A FRACTION IS THERE AT ALL, across two creates. A
|
||||
// truncating build prints a whole second every time, so it fails on the first
|
||||
// one; a correct build prints a whole second only when the clock lands exactly
|
||||
// on a second boundary, which is a billion-to-one per create and so a billion
|
||||
// billion-to-one across the pair. Note that "two creates tie" is NOT usable as
|
||||
// the assertion here even though it is the property that matters: each create is
|
||||
// a subprocess that boots embedded Dolt, so consecutive runs are seconds apart
|
||||
// and would not tie even when truncated. The executor-level proof of the tie
|
||||
// lives in conformance.RunLifecycleCreateEchoesSubSecondTimestamps.
|
||||
func TestEmbeddedCreateJSONEchoesSubSecondTimestamps(t *testing.T) {
|
||||
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
|
||||
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt create tests")
|
||||
}
|
||||
t.Parallel()
|
||||
|
||||
bd := buildEmbeddedBD(t)
|
||||
dir, _, _ := bdInit(t, bd, "--prefix", "cts")
|
||||
|
||||
first := createdAtEcho(t, bd, dir, "first issue")
|
||||
second := createdAtEcho(t, bd, dir, "second issue")
|
||||
|
||||
firstAt := parseRFC3339Nano(t, "first", first.createdAt)
|
||||
parseRFC3339Nano(t, "second", second.createdAt)
|
||||
|
||||
fractional := false
|
||||
for _, echo := range []createEcho{first, second} {
|
||||
for _, member := range []struct{ name, value string }{
|
||||
{"created_at", echo.createdAt},
|
||||
{"updated_at", echo.updatedAt},
|
||||
} {
|
||||
at := parseRFC3339Nano(t, echo.id+" "+member.name, member.value)
|
||||
if at.Nanosecond() != 0 {
|
||||
fractional = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if !fractional {
|
||||
t.Errorf("no timestamp `bd create --json` echoed across two creates carries a sub-second part "+
|
||||
"(%s created_at=%q updated_at=%q, %s created_at=%q updated_at=%q); the echo is being rounded to the "+
|
||||
"DATETIME(0) column, which is what makes same-second creates unorderable",
|
||||
first.id, first.createdAt, first.updatedAt, second.id, second.createdAt, second.updatedAt)
|
||||
}
|
||||
|
||||
// The echo still names the row it created. It is not the SAME text: the
|
||||
// column is DATETIME(0) and the engine ROUNDS to it rather than truncating,
|
||||
// so a read can land up to half a second either side of the echo. That skew
|
||||
// is v1.2.2 behavior and stays — `bd show` and `bd list` answer whole
|
||||
// seconds, as they always have. What must hold is that the two name one
|
||||
// instant, which a second of slack states without pinning either the digits
|
||||
// or the rounding mode.
|
||||
shown := bdShow(t, bd, dir, first.id)
|
||||
if skew := shown.CreatedAt.UTC().Sub(firstAt.UTC()); skew > time.Second || skew < -time.Second {
|
||||
t.Errorf("%s: create echoed created_at %v but show reports %v (%v apart); the two must name the same instant, "+
|
||||
"give or take the second-granular column",
|
||||
first.id, firstAt, shown.CreatedAt.UTC(), skew)
|
||||
}
|
||||
}
|
||||
|
||||
type createEcho struct {
|
||||
id string
|
||||
createdAt string
|
||||
updatedAt string
|
||||
}
|
||||
|
||||
// createdAtEcho runs `bd create --json` and reads the timestamps as the RAW
|
||||
// wire strings, because the defect is about the text a consumer parses: a
|
||||
// decode into time.Time would accept both spellings silently.
|
||||
func createdAtEcho(t *testing.T, bd, dir, title string) createEcho {
|
||||
t.Helper()
|
||||
out, err := bdRunWithFlockRetry(t, bd, dir, "create", "--json", title)
|
||||
if err != nil {
|
||||
t.Fatalf("bd create --json %q: %v\n%s", title, err, out)
|
||||
}
|
||||
s := string(out)
|
||||
start := strings.Index(s, "{")
|
||||
if start < 0 {
|
||||
t.Fatalf("no JSON object in `bd create --json` output:\n%s", s)
|
||||
}
|
||||
var raw struct {
|
||||
ID string `json:"id"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
}
|
||||
if err := json.NewDecoder(strings.NewReader(s[start:])).Decode(&raw); err != nil {
|
||||
t.Fatalf("parse `bd create --json` output: %v\nraw: %s", err, s[start:])
|
||||
}
|
||||
if raw.ID == "" {
|
||||
t.Fatalf("`bd create --json` echoed no id:\n%s", s)
|
||||
}
|
||||
return createEcho{id: raw.ID, createdAt: raw.CreatedAt, updatedAt: raw.UpdatedAt}
|
||||
}
|
||||
|
||||
func parseRFC3339Nano(t *testing.T, label, value string) time.Time {
|
||||
t.Helper()
|
||||
parsed, err := time.Parse(time.RFC3339Nano, value)
|
||||
if err != nil {
|
||||
t.Fatalf("%s created_at %q does not parse as RFC3339Nano: %v", label, value, err)
|
||||
}
|
||||
return parsed
|
||||
}
|
||||
|
|
@ -364,6 +364,14 @@ func deleteBatch(_ *cobra.Command, issueIDs []string, force bool, dryRun bool, c
|
|||
|
||||
commandDidWrite.Store(true)
|
||||
|
||||
// Tell this command's own auto-export that these ids are supposed to be
|
||||
// gone. Without it the export's orphan guard sees them as JSONL-only
|
||||
// records absent from the store, refuses to overwrite, and never saves
|
||||
// state — which is the permanent wedge of GH#5896. Recorded for the
|
||||
// requested ids; anything cascade removed alongside them is proven later
|
||||
// by the store's own history instead.
|
||||
commandDeletedIssueIDs.add(resolvedIDs...)
|
||||
|
||||
// NO COMMIT COMPENSATION HERE, for the reason the single-id path gives:
|
||||
// the role versions the deletion itself, on the store the rows were
|
||||
// deleted from, and defers it in batch and off modes.
|
||||
|
|
|
|||
|
|
@ -212,6 +212,9 @@ Examples:
|
|||
if err != nil {
|
||||
return HandleError("failed to resolve path: %v", err)
|
||||
}
|
||||
if err := checkDoctorMutationGate(absPath); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateDoctorWorkspaceBackend(absPath); isLegacyUpgradeRefusal(err) {
|
||||
return printLegacyUpgradeDiagnostic(err)
|
||||
} else if err != nil {
|
||||
|
|
@ -354,6 +357,57 @@ func init() {
|
|||
doctorCmd.Flags().BoolVar(&doctorAgent, "agent", false, "Agent-facing diagnostic mode: rich context for AI agents (ZFC-compliant)")
|
||||
}
|
||||
|
||||
// doctorMutationOp returns the operation label for a doctor invocation that
|
||||
// will mutate the workspace, or "" when this run is diagnosis-only. --fix and
|
||||
// --clean are the complete trigger set: every mutating doctor surface
|
||||
// (applyFixes, applyFixesInteractive, applyValidateFixes, the pollution and
|
||||
// artifacts cleaners) is reached only through one of those two flags.
|
||||
func doctorMutationOp() string {
|
||||
switch {
|
||||
case doctorFix:
|
||||
return "doctor --fix"
|
||||
case doctorClean:
|
||||
return "doctor --clean"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// checkDoctorMutationGate is doctor's stand-in for the CheckReadonly call every
|
||||
// other write command makes at the top of its RunE (#6028). Doctor never made
|
||||
// that call, and its skipStoreAnnotation opt-out also skips the root
|
||||
// PersistentPreRunE's freeze gate, so both `--readonly` and an active
|
||||
// MIGRATION-FREEZE were bypassed structurally rather than deliberately.
|
||||
//
|
||||
// One call, once, at the flag-level flip point — not per fixer: there are 40+
|
||||
// fixers and any check sprinkled among them rots the moment one is added. It
|
||||
// runs before every mode dispatch (including the embedded-mode gate), so a
|
||||
// refused run never half-executes and never needs a store to refuse.
|
||||
//
|
||||
// There is deliberately no doctor-side override. A migration freeze is exactly
|
||||
// when a shared store has mixed-version clients and `bd doctor --fix` is the
|
||||
// mid-incident reflex command; the operator clears the freeze first.
|
||||
func checkDoctorMutationGate(absPath string) error {
|
||||
op := doctorMutationOp()
|
||||
if op == "" {
|
||||
return nil
|
||||
}
|
||||
if readonlyMode {
|
||||
// Wording matches CheckReadonly (errors.go) exactly; doctor returns the
|
||||
// error rather than calling that void helper so its deferred metrics
|
||||
// CloseEventAndAdd still runs.
|
||||
fmt.Fprintf(os.Stderr, "Error: operation '%s' is not allowed in read-only mode\n", op)
|
||||
return &exitError{Code: 1}
|
||||
}
|
||||
// Doctor is the one write-capable command that takes a target path, so the
|
||||
// freeze has to be looked up against that target as well as against the
|
||||
// directory bd was launched in: `bd doctor /frozen/repo --fix` from an
|
||||
// unfrozen cwd would otherwise walk the wrong tree entirely. ...ErrorFor
|
||||
// covers both (FindFrom(absPath) alone would miss a freeze in the caller's
|
||||
// own cwd), and doctorCmd already sets SilenceErrors/SilenceUsage
|
||||
// statically, so the cobra-silencing gate variant buys nothing here.
|
||||
return migrationFreezeErrorFor(op, absPath)
|
||||
}
|
||||
|
||||
func shouldSkipDoctorNetworkChecks() bool {
|
||||
return jsonOutput || !ui.IsTerminal()
|
||||
}
|
||||
|
|
@ -371,7 +425,7 @@ func validateDoctorWorkspaceBackend(path string) error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("failed to load %s: %w; no storage database was opened or modified; fix or restore metadata.json and retry", configfile.ConfigPath(beadsDir), err)
|
||||
}
|
||||
return validateConfiguredBackend(cfg)
|
||||
return validateConfiguredBackend(cfg, beadsDir)
|
||||
}
|
||||
|
||||
// printLegacyUpgradeDiagnostic preserves doctor as a store-free repair path:
|
||||
|
|
@ -528,18 +582,32 @@ func runDiagnostics(path string) doctorResult {
|
|||
// Since doctor skips PersistentPreRun DB init (via skipStoreAnnotation),
|
||||
// trackBdVersion() and autoMigrateOnVersionBump() haven't run yet.
|
||||
//
|
||||
// Scope version tracking to the doctor target. Without this, `bd doctor <path>`
|
||||
// can accidentally touch the caller's current repo .beads state.
|
||||
origBeadsDir, hadBeadsDir := os.LookupEnv("BEADS_DIR")
|
||||
_ = os.Setenv("BEADS_DIR", beadsDir)
|
||||
trackBdVersion()
|
||||
if hadBeadsDir {
|
||||
_ = os.Setenv("BEADS_DIR", origBeadsDir)
|
||||
} else {
|
||||
_ = os.Unsetenv("BEADS_DIR")
|
||||
}
|
||||
// #6028: skipping that hook also skipped its guards on these exact two
|
||||
// calls — main.go runs them only when policy.runMaintenance is set and the
|
||||
// workspace is not frozen for maintenance. Doctor replicates the calls, so
|
||||
// it must replicate the guard, or plain `bd doctor` (no --fix needed)
|
||||
// rewrites .beads/.local_version and silently applies a schema migration to
|
||||
// a read-only or mid-freeze store: precisely the torn-upgrade write the
|
||||
// freeze exists to prevent. Under either gate doctor now *reports* the
|
||||
// version/migration mismatch in the checks below instead of healing it.
|
||||
//
|
||||
// The probe takes beadsDir for the same reason the mutation gate takes
|
||||
// absPath: these writes land in the doctor target, so a freeze on that tree
|
||||
// must stop them even when bd was launched somewhere unfrozen.
|
||||
if !readonlyMode && !migrationFreezeActiveFor(beadsDir) {
|
||||
// Scope version tracking to the doctor target. Without this, `bd doctor <path>`
|
||||
// can accidentally touch the caller's current repo .beads state.
|
||||
origBeadsDir, hadBeadsDir := os.LookupEnv("BEADS_DIR")
|
||||
_ = os.Setenv("BEADS_DIR", beadsDir)
|
||||
trackBdVersion()
|
||||
if hadBeadsDir {
|
||||
_ = os.Setenv("BEADS_DIR", origBeadsDir)
|
||||
} else {
|
||||
_ = os.Unsetenv("BEADS_DIR")
|
||||
}
|
||||
|
||||
autoMigrateOnVersionBump(beadsDir)
|
||||
autoMigrateOnVersionBump(beadsDir)
|
||||
}
|
||||
|
||||
// Check 1b: Dolt format compatibility (GH#2137)
|
||||
// Must run before opening the database — old noms formats cause server panics.
|
||||
|
|
|
|||
|
|
@ -16,6 +16,17 @@ var latestGitHubReleaseFetcher = fetchLatestGitHubRelease
|
|||
// CheckCLIVersion checks if the CLI version is up to date.
|
||||
// Takes cliVersion parameter since it can't access the Version variable from main package.
|
||||
func CheckCLIVersion(cliVersion string) DoctorCheck {
|
||||
// A Homebrew --HEAD build carries no orderable version — CompareVersions
|
||||
// would read it as 0.0.0 and warn "update available" forever, and the
|
||||
// suggested upgrade would actually move the user off HEAD.
|
||||
if IsBrewHeadVersion(cliVersion) {
|
||||
return DoctorCheck{
|
||||
Name: "CLI Version",
|
||||
Status: StatusOK,
|
||||
Message: fmt.Sprintf("%s (Homebrew --HEAD build; release comparison skipped)", cliVersion),
|
||||
}
|
||||
}
|
||||
|
||||
latestVersion, err := latestGitHubReleaseFetcher()
|
||||
if err != nil {
|
||||
// Network error or API issue - don't fail, just warn
|
||||
|
|
@ -151,6 +162,20 @@ func CheckMetadataVersionTracking(path string, currentVersion string) DoctorChec
|
|||
}
|
||||
}
|
||||
|
||||
trackingActive := DoctorCheck{
|
||||
Name: "Version Tracking",
|
||||
Status: StatusOK,
|
||||
Message: fmt.Sprintf("Version tracking active (last: %s, current: %s)", lastVersion, currentVersion),
|
||||
}
|
||||
|
||||
// A Homebrew --HEAD stamp carries no ordering, so the staleness heuristic
|
||||
// below cannot apply — but it is a healthy marker, not a malformed one.
|
||||
// Warning about it would be permanent: the offered fix rewrites the same
|
||||
// stamp back.
|
||||
if IsBrewHeadVersion(lastVersion) {
|
||||
return trackingActive
|
||||
}
|
||||
|
||||
// Validate that version is a valid semver-like string
|
||||
if !IsValidSemver(lastVersion) {
|
||||
return DoctorCheck{
|
||||
|
|
@ -171,11 +196,7 @@ func CheckMetadataVersionTracking(path string, currentVersion string) DoctorChec
|
|||
|
||||
// Guard against short version strings (e.g., "5" → [5] has no [1])
|
||||
if len(currentParts) < 2 || len(lastParts) < 2 {
|
||||
return DoctorCheck{
|
||||
Name: "Version Tracking",
|
||||
Status: StatusOK,
|
||||
Message: fmt.Sprintf("Version tracking active (last: %s, current: %s)", lastVersion, currentVersion),
|
||||
}
|
||||
return trackingActive
|
||||
}
|
||||
|
||||
// Simple heuristic: warn if minor version is 10+ behind or major version differs by 1+
|
||||
|
|
@ -193,11 +214,7 @@ func CheckMetadataVersionTracking(path string, currentVersion string) DoctorChec
|
|||
}
|
||||
|
||||
// Version is behind but not too old - this is normal after upgrade
|
||||
return DoctorCheck{
|
||||
Name: "Version Tracking",
|
||||
Status: StatusOK,
|
||||
Message: fmt.Sprintf("Version tracking active (last: %s, current: %s)", lastVersion, currentVersion),
|
||||
}
|
||||
return trackingActive
|
||||
}
|
||||
|
||||
// Version is current or ahead
|
||||
|
|
@ -289,6 +306,49 @@ func CompareVersions(v1, v2 string) int {
|
|||
return 0
|
||||
}
|
||||
|
||||
// IsBrewHeadVersion recognizes the version Homebrew stamps into --HEAD
|
||||
// installs of the core beads formula: HEAD-<shortsha>, a bare HEAD when the
|
||||
// head spec resolves no commit, and either shape carrying Homebrew's
|
||||
// _<revision> suffix. Such a stamp is a healthy current-era version marker,
|
||||
// not a malformed one — the binary rewrites it identically on every run, so
|
||||
// nothing the user does can "fix" it into semver.
|
||||
//
|
||||
// This is the canonical definition; every consumer of a version stamp that
|
||||
// needs to tell a --HEAD build apart from a release delegates here so the
|
||||
// ends cannot drift.
|
||||
func IsBrewHeadVersion(version string) bool {
|
||||
rest, ok := strings.CutPrefix(version, "HEAD")
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
// Homebrew's pkg_version appends _<revision> once the formula carries a
|
||||
// revision, so a revision bump must not read as malformed. The revision is
|
||||
// an unsigned decimal; a digits-only check keeps Atoi's tolerance of
|
||||
// signed forms ("+1", "-0") from admitting shapes brew never emits.
|
||||
if cut := strings.IndexByte(rest, '_'); cut >= 0 {
|
||||
revision := rest[cut+1:]
|
||||
if revision == "" || strings.Trim(revision, "0123456789") != "" {
|
||||
return false
|
||||
}
|
||||
rest = rest[:cut]
|
||||
}
|
||||
// Homebrew leaves the version as a bare "HEAD" whenever the head spec
|
||||
// cannot resolve a commit.
|
||||
if rest == "" {
|
||||
return true
|
||||
}
|
||||
sha, ok := strings.CutPrefix(rest, "-")
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
// Bound the tail to a plausible git abbreviation so that arbitrary hex
|
||||
// cannot stand in for a commit; git never abbreviates below 7 characters.
|
||||
if len(sha) < 7 || len(sha) > 40 {
|
||||
return false
|
||||
}
|
||||
return strings.Trim(sha, "0123456789abcdefABCDEF") == ""
|
||||
}
|
||||
|
||||
// IsValidSemver checks if a version string is valid semver-like format (X.Y.Z)
|
||||
func IsValidSemver(version string) bool {
|
||||
if version == "" {
|
||||
|
|
|
|||
|
|
@ -69,6 +69,41 @@ func TestIsValidSemver(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestIsBrewHeadVersion(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
version string
|
||||
want bool
|
||||
}{
|
||||
{name: "short sha", version: "HEAD-f925f3f", want: true},
|
||||
{name: "full sha", version: "HEAD-" + strings.Repeat("a", 40), want: true},
|
||||
{name: "uppercase sha", version: "HEAD-F925F3F", want: true},
|
||||
{name: "bare HEAD", version: "HEAD", want: true},
|
||||
{name: "revision suffix", version: "HEAD-f925f3f_1", want: true},
|
||||
{name: "bare HEAD with revision suffix", version: "HEAD_2", want: true},
|
||||
{name: "empty sha", version: "HEAD-"},
|
||||
{name: "non-hex sha", version: "HEAD-zzzzzzz"},
|
||||
{name: "sha below git abbreviation floor", version: "HEAD-abc"},
|
||||
{name: "sha beyond object id length", version: "HEAD-" + strings.Repeat("a", 41)},
|
||||
{name: "dirty suffix", version: "HEAD-f925f3f-dirty"},
|
||||
{name: "non-numeric revision", version: "HEAD-f925f3f_x"},
|
||||
{name: "signed revision", version: "HEAD-f925f3f_+1"},
|
||||
{name: "negative zero revision", version: "HEAD_-0"},
|
||||
{name: "empty revision", version: "HEAD-f925f3f_"},
|
||||
{name: "unrelated prefix", version: "HEADLESS-f925f3f"},
|
||||
{name: "semver", version: "1.1.2"},
|
||||
{name: "empty", version: ""},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := IsBrewHeadVersion(tt.version); got != tt.want {
|
||||
t.Fatalf("IsBrewHeadVersion(%q) = %v, want %v", tt.version, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpgradeCommandForPath(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
@ -119,6 +154,39 @@ func TestCheckCLIVersionUsesFetcher(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestCheckCLIVersionBrewHeadBuild verifies that a --HEAD build is not told to
|
||||
// run `brew upgrade beads`. CompareVersions reads the stamp as 0.0.0, so every
|
||||
// release looks newer forever, and taking the advice would move the user off
|
||||
// HEAD entirely.
|
||||
func TestCheckCLIVersionBrewHeadBuild(t *testing.T) {
|
||||
orig := latestGitHubReleaseFetcher
|
||||
fetched := false
|
||||
latestGitHubReleaseFetcher = func() (string, error) {
|
||||
fetched = true
|
||||
return "1.3.0", nil
|
||||
}
|
||||
t.Cleanup(func() { latestGitHubReleaseFetcher = orig })
|
||||
|
||||
for _, stamp := range []string{"HEAD-f925f3f", "HEAD", "HEAD-f925f3f_1"} {
|
||||
t.Run(stamp, func(t *testing.T) {
|
||||
check := CheckCLIVersion(stamp)
|
||||
if check.Status != StatusOK {
|
||||
t.Fatalf("Status = %q, want %q (message: %q)", check.Status, StatusOK, check.Message)
|
||||
}
|
||||
if check.Fix != "" {
|
||||
t.Fatalf("Fix = %q, want no upgrade advice for a --HEAD build", check.Fix)
|
||||
}
|
||||
if !strings.Contains(check.Message, stamp) {
|
||||
t.Fatalf("Message = %q, want it to name the stamp", check.Message)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if fetched {
|
||||
t.Error("CheckCLIVersion fetched the latest release for a --HEAD build; there is nothing to compare against")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseVersionParts(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
@ -191,6 +259,34 @@ func TestCheckMetadataVersionTracking_EmptyFile(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestCheckMetadataVersionTracking_BrewHeadStamp verifies that the version
|
||||
// stamp a Homebrew --HEAD install writes is reported as healthy rather than
|
||||
// permanently warning as an invalid format the user cannot fix: the offered
|
||||
// fix, running any bd command, writes the same stamp straight back.
|
||||
func TestCheckMetadataVersionTracking_BrewHeadStamp(t *testing.T) {
|
||||
for _, stamp := range []string{"HEAD-f925f3f", "HEAD", "HEAD-f925f3f_1"} {
|
||||
t.Run(stamp, func(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
beadsDir := filepath.Join(tmpDir, ".beads")
|
||||
if err := os.MkdirAll(beadsDir, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(beadsDir, ".local_version"), []byte(stamp+"\n"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
check := CheckMetadataVersionTracking(tmpDir, "HEAD-aaaaaaa")
|
||||
|
||||
if check.Status != StatusOK {
|
||||
t.Errorf("Status = %q, want %q (message: %q)", check.Status, StatusOK, check.Message)
|
||||
}
|
||||
if check.Fix != "" {
|
||||
t.Errorf("Fix = %q, want no fix advice for a --HEAD stamp", check.Fix)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestCheckMetadataVersionTracking_InvalidVersion verifies handling of
|
||||
// malformed version strings in .local_version.
|
||||
func TestCheckMetadataVersionTracking_InvalidVersion(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -1,73 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// isOrchestratorRoot returns true when path looks like a multi-project
|
||||
// orchestrator workspace root (not a single-project beads repo).
|
||||
//
|
||||
// Detection: presence of both:
|
||||
// 1. .beads/routes.jsonl (cross-project routing config)
|
||||
// 2. mayor/town.json (orchestrator configuration)
|
||||
//
|
||||
// This prevents bd doctor --fix from running at the workspace root,
|
||||
// where repairs should go through the orchestrator's own doctor command.
|
||||
func isOrchestratorRoot(path string) bool {
|
||||
if path == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
routes := filepath.Join(path, ".beads", "routes.jsonl")
|
||||
townJSON := filepath.Join(path, "mayor", "town.json")
|
||||
|
||||
if _, err := os.Stat(routes); err != nil {
|
||||
return false
|
||||
}
|
||||
if _, err := os.Stat(townJSON); err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// findTownRoot walks up from the current working directory looking for
|
||||
// mayor/town.json — the same primary marker gt's own workspace package uses
|
||||
// (see gastownhall/gastown internal/cmd/handoff.go's detectTownRootFromCwd).
|
||||
// Falls back to GT_TOWN_ROOT then GT_ROOT (gt's env-var fallback chain,
|
||||
// already how the rest of this codebase detects an orchestrator — see
|
||||
// formula.go, molecules.go, doltserver.go) when cwd detection fails, e.g. a
|
||||
// detached worktree or a cwd outside the town tree entirely.
|
||||
//
|
||||
// Used by CheckMigrationFreeze (dc-6jaq) to find the MIGRATION-FREEZE
|
||||
// sentinel; unlike isOrchestratorRoot above this only needs the mayor/
|
||||
// marker, not also .beads/routes.jsonl, since a rig-level bd invocation's
|
||||
// cwd is never itself the orchestrator root.
|
||||
func findTownRoot() string {
|
||||
if cwd, err := os.Getwd(); err == nil {
|
||||
path := cwd
|
||||
for {
|
||||
if _, statErr := os.Stat(filepath.Join(path, "mayor", "town.json")); statErr == nil {
|
||||
return path
|
||||
}
|
||||
parent := filepath.Dir(path)
|
||||
if parent == path {
|
||||
break
|
||||
}
|
||||
path = parent
|
||||
}
|
||||
}
|
||||
|
||||
for _, envName := range []string{"GT_TOWN_ROOT", "GT_ROOT"} {
|
||||
envRoot := os.Getenv(envName)
|
||||
if envRoot == "" {
|
||||
continue
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(envRoot, "mayor", "town.json")); err == nil {
|
||||
return envRoot
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
226
cmd/bd/doctor_mutation_gate_test.go
Normal file
226
cmd/bd/doctor_mutation_gate_test.go
Normal file
|
|
@ -0,0 +1,226 @@
|
|||
// Tests for doctor's mutation gate (#6028): `bd doctor --fix` / `--clean` must
|
||||
// refuse to run under strict --readonly, exactly like the ~120 write commands
|
||||
// that call CheckReadonly at the top of their RunE. Doctor never made that call
|
||||
// — it opts out of the root PersistentPreRunE store init via
|
||||
// skipStoreAnnotation, which also opted it out of that hook's gates — so both
|
||||
// --readonly and an active MIGRATION-FREEZE were bypassed structurally.
|
||||
//
|
||||
// The freeze half of the same gate lives in migration_freeze_gate_test.go,
|
||||
// beside the rest of the freeze suite; both halves share the helpers below and
|
||||
// the hermetic subprocess harness declared there.
|
||||
//
|
||||
// This file MUST NOT carry a cgo build tag: it drives a bd binary built with
|
||||
// the gms_pure_go tag via subprocess, and asserts only on files and output.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// doctorMutationSurface is one class of doctor invocation that mutates the
|
||||
// workspace. Section 2 of the #6028 design enumerates the complete set: every
|
||||
// mutating path is reached through --fix or --clean and nothing else, so these
|
||||
// five rows cover the whole write surface, including fixers added later.
|
||||
type doctorMutationSurface struct {
|
||||
name string
|
||||
args []string
|
||||
// op is the operation label the gate reports, derived from which flag made
|
||||
// the run mutating (--fix wins when both are set).
|
||||
op string
|
||||
}
|
||||
|
||||
func doctorMutationSurfaces() []doctorMutationSurface {
|
||||
return []doctorMutationSurface{
|
||||
{name: "fix", args: []string{"doctor", "--fix", "--yes"}, op: "doctor --fix"},
|
||||
{name: "fix-interactive", args: []string{"doctor", "--fix", "-i"}, op: "doctor --fix"},
|
||||
{name: "validate-fix", args: []string{"doctor", "--check=validate", "--fix", "--yes"}, op: "doctor --fix"},
|
||||
{name: "pollution-clean", args: []string{"doctor", "--check=pollution", "--clean", "--yes"}, op: "doctor --clean"},
|
||||
{name: "artifacts-clean", args: []string{"doctor", "--check=artifacts", "--clean", "--yes"}, op: "doctor --clean"},
|
||||
}
|
||||
}
|
||||
|
||||
// doctorWorkspaceFingerprint captures the two workspace files a refused doctor
|
||||
// run is most likely to have touched: .local_version (trackBdVersion's target)
|
||||
// and metadata.json (the Metadata Config / Database fixers' target).
|
||||
func doctorWorkspaceFingerprint(t *testing.T, dir string) map[string][]byte {
|
||||
t.Helper()
|
||||
fingerprint := make(map[string][]byte)
|
||||
for _, name := range []string{localVersionFile, "metadata.json"} {
|
||||
path := filepath.Join(dir, ".beads", name)
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
t.Fatalf("fingerprinting %s: %v", path, err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
fingerprint[name] = data
|
||||
}
|
||||
return fingerprint
|
||||
}
|
||||
|
||||
// assertDoctorWorkspaceUnchanged proves the refusal happened before any
|
||||
// mutation, not merely that the refusal message was printed.
|
||||
func assertDoctorWorkspaceUnchanged(t *testing.T, dir string, before map[string][]byte) {
|
||||
t.Helper()
|
||||
after := doctorWorkspaceFingerprint(t, dir)
|
||||
if len(after) != len(before) {
|
||||
t.Errorf("workspace file set changed across a refused doctor run: had %d tracked files, now %d", len(before), len(after))
|
||||
}
|
||||
for name, want := range before {
|
||||
got, ok := after[name]
|
||||
if !ok {
|
||||
t.Errorf(".beads/%s was deleted by a refused doctor run", name)
|
||||
continue
|
||||
}
|
||||
if string(got) != string(want) {
|
||||
t.Errorf(".beads/%s was rewritten by a refused doctor run:\nbefore:\n%s\nafter:\n%s", name, want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// assertDoctorRefusalIsClean checks the shared shape of every gate refusal:
|
||||
// nothing on stdout, and none of the output a fix or clean run would produce.
|
||||
func assertDoctorRefusalIsClean(t *testing.T, stdout string) {
|
||||
t.Helper()
|
||||
if strings.TrimSpace(stdout) != "" {
|
||||
t.Errorf("stdout should be empty when doctor is refused, got:\n%s", stdout)
|
||||
}
|
||||
for _, marker := range []string{"Applying fixes", "Deleting", "Verifying fixes"} {
|
||||
if strings.Contains(stdout, marker) {
|
||||
t.Errorf("refused doctor run produced %q on stdout — it started mutating before refusing:\n%s", marker, stdout)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestDoctorMutationBlockedInReadonlyMode is the readonly half of the gate.
|
||||
// One workspace serves every row: a refused run must leave it untouched, so a
|
||||
// row that leaks a mutation is caught by the next row's fingerprint too.
|
||||
func TestDoctorMutationBlockedInReadonlyMode(t *testing.T) {
|
||||
bd, dir := setupMigrationFreezeWorkspace(t)
|
||||
before := doctorWorkspaceFingerprint(t, dir)
|
||||
|
||||
for _, tt := range doctorMutationSurfaces() {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
args := append(append([]string{}, tt.args...), "--readonly")
|
||||
stdout, stderr, code := runBDMigrationFreeze(t, bd, dir, args...)
|
||||
|
||||
if code != 1 {
|
||||
t.Fatalf("exit code = %d, want 1\nstdout:\n%s\nstderr:\n%s", code, stdout, stderr)
|
||||
}
|
||||
want := "operation '" + tt.op + "' is not allowed in read-only mode"
|
||||
if !strings.Contains(stderr, want) {
|
||||
t.Errorf("stderr missing %q:\n%s", want, stderr)
|
||||
}
|
||||
assertDoctorRefusalIsClean(t, stdout)
|
||||
assertDoctorWorkspaceUnchanged(t, dir, before)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestDoctorDiagnosisWorksInReadonlyMode pins the other half of the contract:
|
||||
// the gate keys on --fix/--clean alone, so every diagnosis mode still runs
|
||||
// under --readonly. Diagnosing a sandboxed workspace is the whole point.
|
||||
func TestDoctorDiagnosisWorksInReadonlyMode(t *testing.T) {
|
||||
bd, dir := setupMigrationFreezeWorkspace(t)
|
||||
|
||||
for _, args := range [][]string{
|
||||
{"doctor"},
|
||||
{"doctor", "--dry-run"},
|
||||
{"doctor", "--check=pollution"},
|
||||
{"doctor", "--check=artifacts"},
|
||||
} {
|
||||
t.Run(strings.Join(args, "_"), func(t *testing.T) {
|
||||
stdout, stderr, _ := runBDMigrationFreeze(t, bd, dir, append(args, "--readonly")...)
|
||||
if strings.Contains(stderr, "not allowed in read-only mode") {
|
||||
t.Errorf("bd %v was refused under --readonly but mutates nothing:\nstderr:\n%s\nstdout:\n%s", args, stderr, stdout)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestDoctorMaintenanceSkippedInReadonlyMode is the readonly twin of
|
||||
// TestDoctorMaintenanceSkippedDuringMigrationFreeze — see that test for why
|
||||
// plain `bd doctor` had hidden writes at all, and for the shared-server setup.
|
||||
func TestDoctorMaintenanceSkippedInReadonlyMode(t *testing.T) {
|
||||
bd, dir := setupMigrationFreezeWorkspace(t)
|
||||
seedStaleLocalVersion(t, dir)
|
||||
|
||||
stdout, stderr, _ := runBDMigrationFreezeWithEnv(t, bd, dir, doctorMaintenanceEnv(), "doctor", "--readonly")
|
||||
|
||||
assertDoctorReportedStaleVersionWithoutHealing(t, dir, stdout, stderr)
|
||||
if strings.Contains(stderr, "not allowed in read-only mode") {
|
||||
t.Errorf("plain 'bd doctor --readonly' must diagnose, not refuse:\nstderr:\n%s", stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDoctorMutationNotBlockedWithoutGates is the regression-safety control:
|
||||
// with no freeze sentinel and no --readonly, the gate must be invisible. The
|
||||
// fix outcome itself is not this test's business — only that neither refusal
|
||||
// fires and neither exit path is the gate's.
|
||||
func TestDoctorMutationNotBlockedWithoutGates(t *testing.T) {
|
||||
bd, dir := setupMigrationFreezeWorkspace(t)
|
||||
|
||||
for _, tt := range doctorMutationSurfaces() {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
stdout, stderr, code := runBDMigrationFreeze(t, bd, dir, tt.args...)
|
||||
if code == ExitMigrationFrozen || strings.Contains(stderr, "frozen for migration") {
|
||||
t.Errorf("bd %v hit the freeze gate with no marker present (exit %d):\nstderr:\n%s", tt.args, code, stderr)
|
||||
}
|
||||
if strings.Contains(stderr, "not allowed in read-only mode") {
|
||||
t.Errorf("bd %v hit the readonly gate without --readonly (exit %d):\nstderr:\n%s", tt.args, code, stderr)
|
||||
}
|
||||
_ = stdout
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestDoctorMaintenanceStillRunsWithoutGates is the companion control for the
|
||||
// diagnosis-path change: unfrozen and not read-only, plain `bd doctor` must
|
||||
// still reconcile a stale .local_version exactly as it did before #6028.
|
||||
func TestDoctorMaintenanceStillRunsWithoutGates(t *testing.T) {
|
||||
bd, dir := setupMigrationFreezeWorkspace(t)
|
||||
seedStaleLocalVersion(t, dir)
|
||||
|
||||
stdout, stderr, _ := runBDMigrationFreezeWithEnv(t, bd, dir, doctorMaintenanceEnv(), "doctor")
|
||||
|
||||
if !strings.Contains(stderr, "auto-migrate:") {
|
||||
t.Errorf("expected autoMigrateOnVersionBump to run (an 'auto-migrate:' debug line) with no gate active, got none:\nstderr:\n%s", stderr)
|
||||
}
|
||||
got := readWorkspaceLocalVersion(t, dir)
|
||||
if got == staleLocalVersion {
|
||||
t.Errorf("%s = %q — trackBdVersion did not run with no gate active; the #6028 skip is too broad:\nstdout:\n%s",
|
||||
localVersionFile, got, stdout)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDoctorReadonlyWinsOverMigrationFreeze pins the branch order inside the
|
||||
// gate: --readonly is checked first, so a workspace that is both frozen and
|
||||
// sandboxed reports the readonly refusal. This mirrors CheckReadonly, which
|
||||
// also answers readonly before delegating to the freeze check. Either refusal
|
||||
// stops the run, but they carry different exit codes — 1 vs ExitMigrationFrozen
|
||||
// — so which one wins is observable, and the precedence has to be deliberate.
|
||||
func TestDoctorReadonlyWinsOverMigrationFreeze(t *testing.T) {
|
||||
bd, dir := setupMigrationFreezeWorkspace(t)
|
||||
writeFreezeMarker(t, dir, "migrator", "dolt v2 migration")
|
||||
before := doctorWorkspaceFingerprint(t, dir)
|
||||
|
||||
stdout, stderr, code := runBDFrozen(t, bd, dir, "doctor", "--fix", "--yes", "--readonly")
|
||||
|
||||
if code != 1 {
|
||||
t.Fatalf("exit code = %d, want 1 (not %d — readonly is answered before the freeze)\nstdout:\n%s\nstderr:\n%s",
|
||||
code, ExitMigrationFrozen, stdout, stderr)
|
||||
}
|
||||
if !strings.Contains(stderr, "operation 'doctor --fix' is not allowed in read-only mode") {
|
||||
t.Errorf("stderr missing the readonly refusal (readonly must be checked before the freeze):\n%s", stderr)
|
||||
}
|
||||
if strings.Contains(stderr, "frozen for migration") {
|
||||
t.Errorf("stderr carries the freeze refusal too; the gate should report exactly one reason:\n%s", stderr)
|
||||
}
|
||||
assertDoctorRefusalIsClean(t, stdout)
|
||||
assertDoctorWorkspaceUnchanged(t, dir, before)
|
||||
}
|
||||
33
cmd/bd/doctor_orchestrator_guard.go
Normal file
33
cmd/bd/doctor_orchestrator_guard.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// isOrchestratorRoot returns true when path looks like a multi-project
|
||||
// orchestrator workspace root (not a single-project beads repo).
|
||||
//
|
||||
// Detection: presence of both:
|
||||
// 1. .beads/routes.jsonl (cross-project routing config)
|
||||
// 2. mayor/town.json (orchestrator configuration)
|
||||
//
|
||||
// This prevents bd doctor --fix from running at the workspace root,
|
||||
// where repairs should go through the orchestrator's own doctor command.
|
||||
func isOrchestratorRoot(path string) bool {
|
||||
if path == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
routes := filepath.Join(path, ".beads", "routes.jsonl")
|
||||
townJSON := filepath.Join(path, "mayor", "town.json")
|
||||
|
||||
if _, err := os.Stat(routes); err != nil {
|
||||
return false
|
||||
}
|
||||
if _, err := os.Stat(townJSON); err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
@ -1080,7 +1080,7 @@ endpoint via SQL and reports reachability, server version, and database.`,
|
|||
if cfg == nil {
|
||||
cfg = configfile.DefaultConfig()
|
||||
}
|
||||
if err := validateConfiguredBackend(cfg); err != nil {
|
||||
if err := validateConfiguredBackend(cfg, beadsDir); err != nil {
|
||||
return HandleError("%v", err)
|
||||
}
|
||||
// A non-Dolt backend (SQLite or a removed-backend tombstone) has no Dolt engine;
|
||||
|
|
@ -1920,7 +1920,7 @@ func showDoltConfig(testConnection bool) error {
|
|||
if cfg == nil {
|
||||
cfg = configfile.DefaultConfig()
|
||||
}
|
||||
if err := validateConfiguredBackend(cfg); err != nil {
|
||||
if err := validateConfiguredBackend(cfg, beadsDir); err != nil {
|
||||
return HandleError("%v", err)
|
||||
}
|
||||
|
||||
|
|
|
|||
234
cmd/bd/errors.go
234
cmd/bd/errors.go
|
|
@ -6,8 +6,12 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/steveyegge/beads/internal/beads"
|
||||
"github.com/steveyegge/beads/internal/metrics"
|
||||
"github.com/steveyegge/beads/internal/migration"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
)
|
||||
|
||||
type exitError struct {
|
||||
|
|
@ -72,6 +76,36 @@ func buildJSONError(message, hint string) interface{} {
|
|||
return inner
|
||||
}
|
||||
|
||||
func buildJSONCapabilityError(e *ProxyCapabilityError) interface{} {
|
||||
inner := map[string]interface{}{"error": e.Message, "code": e.Code, "mutates": e.Mutates}
|
||||
if jsonEnvelopeEnabled() {
|
||||
return map[string]interface{}{"schema_version": JSONSchemaVersion, "data": inner}
|
||||
}
|
||||
inner["schema_version"] = JSONSchemaVersion
|
||||
return inner
|
||||
}
|
||||
|
||||
// HandleProxyCapabilityError renders a stable capability refusal while
|
||||
// preserving the normal text/JSON front-door conventions.
|
||||
func HandleProxyCapabilityError(err error) error {
|
||||
var capErr *ProxyCapabilityError
|
||||
if !errors.As(err, &capErr) {
|
||||
return HandleErrorRespectJSON("%v", err)
|
||||
}
|
||||
code := capErr.ExitCode
|
||||
if code == 0 {
|
||||
code = 1
|
||||
}
|
||||
if jsonOutput {
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
enc.SetIndent("", " ")
|
||||
_ = enc.Encode(buildJSONCapabilityError(capErr))
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "Error: %s\n", capErr.Message)
|
||||
}
|
||||
return &exitError{Code: code}
|
||||
}
|
||||
|
||||
func jsonStderrError(message, hint string) {
|
||||
encoder := json.NewEncoder(os.Stderr)
|
||||
encoder.SetIndent("", " ")
|
||||
|
|
@ -125,44 +159,75 @@ func WarnError(format string, args ...interface{}) {
|
|||
fmt.Fprintf(os.Stderr, "Warning: "+format+"\n", args...)
|
||||
}
|
||||
|
||||
// ExitMigrationFrozen is the exit code for a write refused because a
|
||||
// migration freeze marker is active (dc-6jaq). Stable value so scripts can
|
||||
// branch on "someone is migrating this workspace, come back later" without
|
||||
// grep'ing stderr, instead of reading it as a generic failure (1) worth
|
||||
// retrying immediately.
|
||||
const ExitMigrationFrozen = 14
|
||||
|
||||
// CheckReadonly aborts the command when bd is running in read-only mode (the
|
||||
// worker-sandbox posture, see readonlyMode), or when a MIGRATION-FREEZE
|
||||
// sentinel is active at the town root (dc-6jaq, folded in here rather than
|
||||
// requiring every write command to remember a second call — see
|
||||
// CheckMigrationFreeze below). This is the chokepoint essentially every
|
||||
// write command already calls first, so folding the freeze check in here
|
||||
// covers the whole write surface at once, including commands added after
|
||||
// this comment is written — not just a hand-picked list that rots (one
|
||||
// concrete instance the hand-picked list missed: "bd q", cmd/bd/quick.go,
|
||||
// the create alias). It exits via os.Exit and so cannot run the per-command
|
||||
// deferred CloseEventAndAdd — a command blocked here records no
|
||||
// cli_command event of its own (it never actually ran). It does flush
|
||||
// metrics first, so events already queued earlier in this run are still
|
||||
// written and scheduled for upload rather than stranded until the next
|
||||
// clean exit.
|
||||
// worker-sandbox posture, see readonlyMode), or when a migration freeze
|
||||
// marker is active (dc-6jaq, folded in here rather than requiring every write
|
||||
// command to remember a second call — see migrationFreezeError below). This
|
||||
// is the chokepoint essentially every write command already calls first, so
|
||||
// folding the freeze check in here covers the whole write surface at once,
|
||||
// including commands added after this comment is written — not just a
|
||||
// hand-picked list that rots (one concrete instance the hand-picked list
|
||||
// missed: "bd q", cmd/bd/quick.go, the create alias). It exits via os.Exit
|
||||
// and so cannot run the per-command deferred CloseEventAndAdd — a command
|
||||
// blocked here records no cli_command event of its own (it never actually
|
||||
// ran). It does flush metrics first, so events already queued earlier in this
|
||||
// run are still written and scheduled for upload rather than stranded until
|
||||
// the next clean exit. Callers that CAN return an error (the root
|
||||
// PersistentPreRunE, runImport) call migrationFreezeError directly instead,
|
||||
// so their deferred cleanup still runs.
|
||||
func CheckReadonly(operation string) {
|
||||
if readonlyMode {
|
||||
fmt.Fprintf(os.Stderr, "Error: operation '%s' is not allowed in read-only mode\n", operation)
|
||||
metrics.CloseAndFlush()
|
||||
os.Exit(1)
|
||||
}
|
||||
CheckMigrationFreeze(operation)
|
||||
if err := migrationFreezeError(operation); err != nil {
|
||||
metrics.CloseAndFlush()
|
||||
os.Exit(ExitMigrationFrozen)
|
||||
}
|
||||
}
|
||||
|
||||
// CheckMigrationFreeze aborts the command when a MIGRATION-FREEZE sentinel is
|
||||
// present at the town root (dc-6jaq). The gt CLI already refuses to write
|
||||
// under the same sentinel (gt mail send, gt nudge, gt sling, gt assign);
|
||||
// mail-poller/daemon patrols that also write via bd are stopped separately
|
||||
// via the migration playbook's plist-unload step, so this closes the
|
||||
// remaining gap: a human typing 'bd create'/'bd update' etc. mid-migration,
|
||||
// bypassing the gt-layer gate. Same exit-via-os.Exit tradeoff as
|
||||
// CheckReadonly above — no cli_command event for a command blocked here,
|
||||
// but queued metrics are still flushed.
|
||||
// freezeSearchRoots returns the directories whose ancestry the freeze lookup
|
||||
// must cover in addition to the working directory: the resolved workspace, so
|
||||
// the gate keys on the store being written rather than on the caller's shell.
|
||||
// Without it, `BEADS_DIR=/work/repo/.beads bd create` run from $HOME, `bd -C
|
||||
// /work/repo create` (which sets BEADS_DIR and never chdirs), and any daemon
|
||||
// or cron job with an unrelated cwd all walk the wrong tree and write straight
|
||||
// through a freeze.
|
||||
//
|
||||
// PersistentPreRunE exports BEADS_DIR as part of selecting the workspace
|
||||
// (prepareSelectedCommandContext), so by the time a command's RunE reaches
|
||||
// CheckReadonly this is a cheap env read. The FindBeadsDir fallback covers the
|
||||
// callers that run before that — and returns "" rather than erroring when
|
||||
// there is no workspace at all, which Find skips.
|
||||
func freezeSearchRoots() []string {
|
||||
if dir := os.Getenv("BEADS_DIR"); dir != "" {
|
||||
return []string{dir}
|
||||
}
|
||||
if dir := beads.FindBeadsDir(); dir != "" {
|
||||
return []string{dir}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// migrationFreezeError reports the active migration freeze, if any: it
|
||||
// returns nil when writes are not frozen, and otherwise prints the refusal to
|
||||
// stderr and returns an ExitMigrationFrozen exit error. The refusal names the
|
||||
// marker's own path, so the recovery instruction ("remove that file") is
|
||||
// always actionable without knowing what created it.
|
||||
//
|
||||
// Three callers, each closing a different hole:
|
||||
// 1. CheckReadonly above — the per-command chokepoint covering the write
|
||||
// surface at large (create/update/close/... and everything that calls
|
||||
// CheckReadonly, ~120 sites).
|
||||
// CheckReadonly, ~120 sites). Only that caller turns this error into an
|
||||
// os.Exit, because its void signature leaves it nothing else to do.
|
||||
// 2. The root PersistentPreRunE in main.go, before autoMigrateOnVersionBump
|
||||
// and maybeAutoImportJSONL — those run as store-open side effects
|
||||
// *before* any RunE, so waiting for a write command's own CheckReadonly
|
||||
|
|
@ -173,25 +238,118 @@ func CheckReadonly(operation string) {
|
|||
// CheckReadonly at all today (a pre-existing, separate gap: readonlyMode
|
||||
// doesn't block it either), so it cannot inherit the freeze check from
|
||||
// caller 1 and needs its own explicit call.
|
||||
func CheckMigrationFreeze(operation string) {
|
||||
townRoot := findTownRoot()
|
||||
if !migration.IsFrozen(townRoot) {
|
||||
return
|
||||
func migrationFreezeError(operation string) error {
|
||||
return migrationFreezeRefusal(operation, migration.Find(freezeSearchRoots()...))
|
||||
}
|
||||
|
||||
// migrationFreezeRefusal renders an already-resolved lookup. Callers that
|
||||
// need the same Result for more than the refusal — PersistentPreRunE, which
|
||||
// also derives frozenForMaintenance from it — resolve once and pass it here,
|
||||
// so a single walk answers the whole invocation and the two readings cannot
|
||||
// disagree about a marker that appeared or vanished between them.
|
||||
func migrationFreezeRefusal(operation string, res migration.Result) error {
|
||||
if !res.Frozen() {
|
||||
return nil
|
||||
}
|
||||
|
||||
info := migration.Read(townRoot)
|
||||
operator := "unknown"
|
||||
if res.Err != nil {
|
||||
// Fail closed: bd could not tell whether a marker is present (a
|
||||
// permission error on the marker or a directory above it). An
|
||||
// undeterminable gate is not an open gate, and saying so beats
|
||||
// writing into a workspace that may be mid-migration.
|
||||
fmt.Fprint(os.Stderr, "⛔ ERROR: cannot determine whether this workspace is frozen for migration.\n")
|
||||
fmt.Fprintf(os.Stderr, " %s\n", ui.SanitizeForTerminal(res.Err.Error()))
|
||||
fmt.Fprintf(os.Stderr, " bd %s is blocked until the marker can be read.\n", operation)
|
||||
fmt.Fprintf(os.Stderr, " Fix the permissions, or set %s to a path bd can stat.\n", migration.EnvFreezeFile)
|
||||
return &exitError{Code: ExitMigrationFrozen}
|
||||
}
|
||||
|
||||
// The marker can live in a directory bd does not control, so its payload
|
||||
// is untrusted input on its way to a terminal. parse already keeps it to
|
||||
// one line; sanitizing strips ANSI and control bytes on top of that.
|
||||
operator := ""
|
||||
reason := ""
|
||||
if info != nil {
|
||||
operator = info.Operator
|
||||
reason = info.Reason
|
||||
if info := migration.ReadFile(res.Path); info != nil {
|
||||
operator = ui.SanitizeForTerminal(info.Operator)
|
||||
reason = ui.SanitizeForTerminal(info.Reason)
|
||||
}
|
||||
|
||||
fmt.Fprintf(os.Stderr, "⛔ ERROR: town is frozen for migration (by %s).\n", operator)
|
||||
if operator != "" {
|
||||
fmt.Fprintf(os.Stderr, "⛔ ERROR: workspace is frozen for migration (by %s).\n", operator)
|
||||
} else {
|
||||
// An empty or unparseable marker (a bare `touch`) records no
|
||||
// operator; say nothing rather than printing "(by )".
|
||||
fmt.Fprint(os.Stderr, "⛔ ERROR: workspace is frozen for migration.\n")
|
||||
}
|
||||
if reason != "" {
|
||||
fmt.Fprintf(os.Stderr, " Reason: %s\n", reason)
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, " bd %s is blocked. Clear the freeze: gt migrate thaw\n", operation)
|
||||
metrics.CloseAndFlush()
|
||||
os.Exit(1)
|
||||
fmt.Fprintf(os.Stderr, " bd %s is blocked by the freeze marker at %s.\n", operation, res.Path)
|
||||
if res.FromEnv {
|
||||
fmt.Fprintf(os.Stderr, " To resume writes, remove that file or unset %s.\n", migration.EnvFreezeFile)
|
||||
} else {
|
||||
// Name the variable on this path too: when the marker sits in a
|
||||
// directory the caller cannot write to, pointing the variable
|
||||
// elsewhere is the only recovery available to them.
|
||||
fmt.Fprint(os.Stderr, " To resume writes, remove that file.\n")
|
||||
fmt.Fprintf(os.Stderr, " If you cannot remove it, set %s to a path bd should check instead.\n", migration.EnvFreezeFile)
|
||||
}
|
||||
return &exitError{Code: ExitMigrationFrozen}
|
||||
}
|
||||
|
||||
// migrationFreezeGate is the RunE-side entry point: it renders the refusal and,
|
||||
// because the refusal has already said everything worth saying, suppresses
|
||||
// cobra's own error and usage rendering for this invocation.
|
||||
//
|
||||
// Without the suppression a freeze refusal on any command that does not set
|
||||
// SilenceErrors/SilenceUsage statically — duplicate, supersede, dep
|
||||
// relate/unrelate, backup init/sync/remove/restore, ado sync, migrate-personal,
|
||||
// batch — is followed by "Error: exit code 14" (exitError's placeholder text)
|
||||
// and a full usage dump, so a clean refusal reads like a syntax error. Setting
|
||||
// the flags here rather than on each command covers the ones added after this
|
||||
// comment too. main() exits on the exitError before its own SilenceErrors
|
||||
// branch, so nothing prints the placeholder.
|
||||
func migrationFreezeGate(cmd *cobra.Command, operation string, res migration.Result) error {
|
||||
err := migrationFreezeRefusal(operation, res)
|
||||
if err != nil && cmd != nil {
|
||||
cmd.SilenceErrors = true
|
||||
cmd.SilenceUsage = true
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// migrationFreezeGateFor resolves the freeze and gates in one step, for the
|
||||
// callers that have no Result to thread: the skip-store commands (bd init,
|
||||
// bd bootstrap), which return from PersistentPreRunE long before it resolves
|
||||
// one, and any command handed an explicit target path.
|
||||
func migrationFreezeGateFor(cmd *cobra.Command, operation string, extraRoots ...string) error {
|
||||
return migrationFreezeGate(cmd, operation, migration.Find(freezeRootsWith(extraRoots)...))
|
||||
}
|
||||
|
||||
// migrationFreezeErrorFor is migrationFreezeError against extra roots, for
|
||||
// callers that hold a target path but no *cobra.Command to silence — a command
|
||||
// given a workspace to operate on that is not the one it was launched in.
|
||||
func migrationFreezeErrorFor(operation string, extraRoots ...string) error {
|
||||
return migrationFreezeRefusal(operation, migration.Find(freezeRootsWith(extraRoots)...))
|
||||
}
|
||||
|
||||
// migrationFreezeActive is the print-nothing probe for code that must SKIP a
|
||||
// write during a freeze rather than refuse the whole command — the diagnosis
|
||||
// paths that keep running while frozen but must not apply version tracking or
|
||||
// schema auto-migration.
|
||||
func migrationFreezeActive() bool {
|
||||
return migrationFreezeActiveFor()
|
||||
}
|
||||
|
||||
// migrationFreezeActiveFor is migrationFreezeActive against extra roots — the
|
||||
// probe half of the migrationFreezeErrorFor pair, for a diagnosis path handed a
|
||||
// workspace that is not the one bd was launched in. `bd doctor /frozen/repo`
|
||||
// skips its own maintenance writes on the strength of this, so it has to look
|
||||
// at the tree it is about to write to and not just at the caller's cwd.
|
||||
func migrationFreezeActiveFor(extraRoots ...string) bool {
|
||||
return migration.Find(freezeRootsWith(extraRoots)...).Frozen()
|
||||
}
|
||||
|
||||
func freezeRootsWith(extraRoots []string) []string {
|
||||
return append(freezeSearchRoots(), extraRoots...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/steveyegge/beads/internal/beads"
|
||||
"github.com/steveyegge/beads/internal/config"
|
||||
"github.com/steveyegge/beads/internal/eventsjournal"
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
|
|
@ -103,10 +104,12 @@ Record contract (stable for external consumers):
|
|||
issue_id string the mutated issue's id
|
||||
actor string the acting identity that performed the mutation, as resolved
|
||||
for the audit-events table (on a comment row: the comment's
|
||||
author); empty (omitted) when the mutation path has no
|
||||
actor — derived maintenance, deletes (other than a rename's
|
||||
synthetic delete), and rows older than the column. Never
|
||||
user attribution when empty.
|
||||
author). A delete — and the dep_remove rows a cascading
|
||||
delete produces — carries the identity that REQUESTED it.
|
||||
Empty (omitted) only when the path genuinely has no actor:
|
||||
derived maintenance, system cleanup with no request behind
|
||||
it, and rows older than the column. Never user attribution
|
||||
when empty.
|
||||
issue object full issue state AFTER the mutation; null on delete
|
||||
dep object {"kind","target","metadata"} for dep_add / dep_remove; omitted otherwise
|
||||
comment object {"id","author","text","created_at","source"} for comment; omitted otherwise
|
||||
|
|
@ -246,7 +249,32 @@ func reportEventsTruncated(err error, streaming bool) error {
|
|||
fmt.Sprintf("resume with --since %d to continue from the oldest retained record (accepting the gap), or re-import from scratch", trunc.Floor-1))
|
||||
}
|
||||
|
||||
// noticeEventsJournalDisabled warns, on stderr, that this workspace is not
|
||||
// recording — so an empty or stale read is not mistaken for "caught up".
|
||||
//
|
||||
// It exists because zero rows is INDISTINGUISHABLE from a journal that has
|
||||
// nothing new: a consumer polling a workspace that never enabled the journal
|
||||
// sees a successful, empty read forever and concludes it is up to date. The
|
||||
// HTTP API refuses that read outright (EventsJournalDisabled, 409); the CLI
|
||||
// cannot, because exporting the ledger a now-disabled workspace recorded while
|
||||
// it WAS enabled is legitimate. So it serves the rows and says what it is
|
||||
// serving.
|
||||
//
|
||||
// stderr, not stdout, and not the JSON envelope: stdout is a JSONL stream a
|
||||
// line reader consumes, and a notice about the reader's own configuration is
|
||||
// not a record. Exit status is unchanged.
|
||||
func noticeEventsJournalDisabled(beadsDir string) {
|
||||
if eventsjournal.EnabledFor(beadsDir) {
|
||||
return
|
||||
}
|
||||
fmt.Fprintf(os.Stderr,
|
||||
"note: the events journal is disabled for this workspace (enable with 'bd config set %s true'); "+
|
||||
"any records shown were written while it was enabled, and new mutations are not being recorded\n",
|
||||
eventsjournal.ConfigKey)
|
||||
}
|
||||
|
||||
func runEventsTail(ctx context.Context, since int64, limit int, follow bool) error {
|
||||
noticeEventsJournalDisabled(beads.FindBeadsDir())
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
emit := func(from int64) (int64, error) {
|
||||
rows, err := readJournal(ctx, from, limit)
|
||||
|
|
|
|||
129
cmd/bd/events_delete_actor_e2e_test.go
Normal file
129
cmd/bd/events_delete_actor_e2e_test.go
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
//go:build cgo && unix
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// The two halves of #5985 at the front door: what `bd delete --actor` records,
|
||||
// and what `bd events export` tells you when there is nothing to record into.
|
||||
// Both are end-to-end because both failures are invisible from inside the
|
||||
// process — the command succeeds either way, and only a later read shows the
|
||||
// attribution missing or the reader polling a journal that was never on.
|
||||
|
||||
// runBDOut runs bd in dir and returns stdout and stderr separately. The notice
|
||||
// under test is on stderr precisely so it does not corrupt the JSONL on stdout,
|
||||
// so a CombinedOutput helper cannot check it.
|
||||
func runBDOut(t *testing.T, bd, dir string, env []string, args ...string) (string, string) {
|
||||
t.Helper()
|
||||
cmd := exec.Command(bd, args...)
|
||||
cmd.Dir = dir
|
||||
cmd.Env = env
|
||||
var stdout, stderr bytes.Buffer
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
t.Fatalf("bd %s in %s: %v\nstdout:\n%s\nstderr:\n%s",
|
||||
strings.Join(args, " "), dir, err, stdout.String(), stderr.String())
|
||||
}
|
||||
return stdout.String(), stderr.String()
|
||||
}
|
||||
|
||||
// TestDeleteJournalsTheRequestingActor is #5985's repro, verbatim: create two
|
||||
// beads with an edge between them, delete the blocker with an explicit --actor,
|
||||
// and read the journal back. Both the delete record and the cascade dep_remove
|
||||
// record must name that actor.
|
||||
//
|
||||
// The whole route is exercised — cobra flag to journal column — because the
|
||||
// actor is resolved, threaded through the role, and written by the storage
|
||||
// seam, and a unit test at any one of those cannot see the drop at the next.
|
||||
func TestDeleteJournalsTheRequestingActor(t *testing.T) {
|
||||
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
|
||||
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
|
||||
}
|
||||
t.Parallel()
|
||||
bd := buildEmbeddedBD(t)
|
||||
dir, _, _ := bdInit(t, bd, "--prefix", "dja", "--skip-hooks", "--skip-agents")
|
||||
env := append(envWithout(bdEnv(dir), "BD_EVENTS_JOURNAL"), "BD_EVENTS_JOURNAL=1")
|
||||
|
||||
run := func(args ...string) string {
|
||||
t.Helper()
|
||||
stdout, _ := runBDOut(t, bd, dir, env, args...)
|
||||
return stdout
|
||||
}
|
||||
|
||||
run("create", "--silent", "--id", "dja-blocker", "the blocker")
|
||||
run("create", "--silent", "--id", "dja-dependent", "the dependent")
|
||||
run("dep", "add", "dja-dependent", "dja-blocker")
|
||||
|
||||
// --force is what makes this a real delete rather than a preview, and it is
|
||||
// also what lets it orphan the dependent instead of refusing.
|
||||
run("delete", "dja-blocker", "--force", "--actor", "alice")
|
||||
|
||||
records := decodeEventRecords(t, run("events", "export"))
|
||||
var sawDelete, sawCascadeDepRemove bool
|
||||
for _, rec := range records {
|
||||
switch {
|
||||
case rec.Op == "delete" && rec.IssueID == "dja-blocker":
|
||||
sawDelete = true
|
||||
if rec.Actor != "alice" {
|
||||
t.Errorf("delete record actor = %q, want %q (#5985)", rec.Actor, "alice")
|
||||
}
|
||||
// The cascade edge removal is journaled under the edge's SOURCE — the
|
||||
// surviving dependent — and belongs to the identity that asked for the
|
||||
// delete, not to whoever created the edge.
|
||||
case rec.Op == "dep_remove" && rec.IssueID == "dja-dependent":
|
||||
sawCascadeDepRemove = true
|
||||
if rec.Actor != "alice" {
|
||||
t.Errorf("cascade dep_remove record actor = %q, want %q (#5985)", rec.Actor, "alice")
|
||||
}
|
||||
}
|
||||
}
|
||||
if !sawDelete {
|
||||
t.Errorf("no delete record for dja-blocker: %+v", records)
|
||||
}
|
||||
if !sawCascadeDepRemove {
|
||||
t.Errorf("no cascade dep_remove record for dja-dependent: %+v", records)
|
||||
}
|
||||
}
|
||||
|
||||
// TestEventsReadNoticesADisabledJournal pins the "nothing to read and no way to
|
||||
// tell why" fix. A workspace that never enabled the journal serves an empty
|
||||
// export forever, which a consumer cannot distinguish from being caught up, so
|
||||
// the read says so on stderr — and keeps stdout clean and the exit status zero,
|
||||
// because exporting a historical ledger from a now-disabled workspace is
|
||||
// legitimate.
|
||||
func TestEventsReadNoticesADisabledJournal(t *testing.T) {
|
||||
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
|
||||
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests")
|
||||
}
|
||||
t.Parallel()
|
||||
bd := buildEmbeddedBD(t)
|
||||
dir, _, _ := bdInit(t, bd, "--prefix", "dnn", "--skip-hooks", "--skip-agents")
|
||||
off := envWithout(bdEnv(dir), "BD_EVENTS_JOURNAL")
|
||||
|
||||
for _, sub := range []string{"export", "tail"} {
|
||||
stdout, stderr := runBDOut(t, bd, dir, off, "events", sub)
|
||||
if !strings.Contains(stderr, "events journal is disabled") {
|
||||
t.Errorf("bd events %s on a disabled workspace printed no notice\nstderr:\n%s", sub, stderr)
|
||||
}
|
||||
if !strings.Contains(stderr, "events-journal") {
|
||||
t.Errorf("bd events %s notice does not name the setting to flip\nstderr:\n%s", sub, stderr)
|
||||
}
|
||||
if strings.TrimSpace(stdout) != "" {
|
||||
t.Errorf("bd events %s put the notice on stdout, which carries the JSONL stream:\n%s", sub, stdout)
|
||||
}
|
||||
}
|
||||
|
||||
// Enabled: no notice, so the message stays a signal rather than noise every
|
||||
// consumer learns to filter out.
|
||||
on := append(envWithout(bdEnv(dir), "BD_EVENTS_JOURNAL"), "BD_EVENTS_JOURNAL=1")
|
||||
if _, stderr := runBDOut(t, bd, dir, on, "events", "export"); strings.Contains(stderr, "events journal is disabled") {
|
||||
t.Errorf("an enabled workspace still printed the disabled notice:\n%s", stderr)
|
||||
}
|
||||
}
|
||||
|
|
@ -153,8 +153,14 @@ func renderGoldenLines(t *testing.T) []byte {
|
|||
|
||||
// actor pins both halves of the attribution contract: an attributed row
|
||||
// emits the acting identity (the same one the audit-events table resolves),
|
||||
// and an actorless row — derived maintenance, actorless delete plumbing,
|
||||
// and an actorless row — derived maintenance, the system delete surfaces,
|
||||
// records from before the column existed — omits the member entirely.
|
||||
//
|
||||
// A `delete` appears on BOTH sides on purpose. A user's `bd delete --actor A`
|
||||
// is attributed to A, cascade rows included; the actorless surfaces (gc,
|
||||
// molecule cleanup, `bd repo remove`) still emit none. A consumer that read
|
||||
// the empty case as "deletes are never attributed" — which the fixture used
|
||||
// to be the only evidence for — would mis-resolve every delete conflict.
|
||||
records := []eventsjournal.Record{
|
||||
goldenRecord(1, ts, string(issueops.EventCreate), minimal.ID, "author", mustJSON(t, minimal), "", ""),
|
||||
goldenRecord(2, ts, string(issueops.EventCreate), full.ID, "author", mustJSON(t, full), "", ""),
|
||||
|
|
@ -169,7 +175,11 @@ func renderGoldenLines(t *testing.T) []byte {
|
|||
goldenRecord(8, ts, string(issueops.EventCommentWrite), claimed.ID, "worker-1", mustJSON(t, claimed), "", mustJSON(t, auditComment)),
|
||||
goldenRecord(9, ts, string(issueops.EventClose), closedIssue.ID, "worker-1", mustJSON(t, closedIssue), "", ""),
|
||||
goldenRecord(10, ts, string(issueops.EventCreate), wisp.ID, "author", mustJSON(t, wisp), "", ""),
|
||||
goldenRecord(11, ts, string(issueops.EventDelete), "bd-100", "", "", "", ""), // null issue on delete; actorless delete plumbing
|
||||
// The cascade edge removal a delete emits, attributed to the requester.
|
||||
goldenRecord(11, ts, string(issueops.EventDepRemove), "bd-101", "deleter-1", mustJSON(t, full),
|
||||
mustJSON(t, &issueops.EventDep{Kind: string(types.DepBlocks), Target: "bd-100"}), ""),
|
||||
goldenRecord(12, ts, string(issueops.EventDelete), "bd-100", "deleter-1", "", "", ""), // null issue on delete; requested delete
|
||||
goldenRecord(13, ts, string(issueops.EventDelete), "bd-wisp-1", "", "", "", ""), // actorless system delete surface
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
|
|
|
|||
|
|
@ -109,8 +109,13 @@ func TestRoutedCreateJournalsIntoTheTargetWorkspace(t *testing.T) {
|
|||
}
|
||||
|
||||
// The launching workspace never enabled the journal, so it records nothing
|
||||
// — the target's setting must not leak back, in either direction.
|
||||
if got := strings.TrimSpace(run(sourceDir, "events", "export")); got != "" {
|
||||
// — the target's setting must not leak back, in either direction. Read
|
||||
// STDOUT only: a disabled workspace also prints the "journal is disabled"
|
||||
// notice, and that notice is on stderr precisely so it cannot be mistaken
|
||||
// for a record.
|
||||
sourceEnv := envWithout(bdEnv(sourceDir), "BD_EVENTS_JOURNAL")
|
||||
stdout, _ := runBDOut(t, bd, sourceDir, sourceEnv, "events", "export")
|
||||
if got := strings.TrimSpace(stdout); got != "" {
|
||||
t.Errorf("the launching workspace journaled %q despite never enabling the journal", got)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/steveyegge/beads/internal/atomicfile"
|
||||
|
|
@ -39,8 +40,27 @@ const doltWorkingRef = "WORKING"
|
|||
// exceeds this prints a one-line stderr tip pointing at the fix levers.
|
||||
const slowExportWarnThreshold = 3 * time.Second
|
||||
|
||||
// exportAutoStateVersion is the format version stamped into
|
||||
// .beads/export-state.json. BUMP IT whenever the MEANING of a persisted
|
||||
// field changes — LastDiffAnchor's semantics above all — so a newer binary's
|
||||
// state file is discarded by an older one instead of being reinterpreted.
|
||||
// Adding a purely additive optional field does not need a bump.
|
||||
//
|
||||
// Discarding is only safe because of the deletion proofs in
|
||||
// proveDeletedIssueIDs: dropping the state drops the diff anchor, and before
|
||||
// GH#5896 an absent anchor plus a pending delete was itself a permanent
|
||||
// wedge, which made "invalidate the state file" a cure worse than the
|
||||
// disease. Now an anchorless cycle just proves what it can from history and
|
||||
// re-anchors on the way out.
|
||||
const exportAutoStateVersion = 1
|
||||
|
||||
// exportAutoState tracks auto-export state to avoid redundant work.
|
||||
type exportAutoState struct {
|
||||
// FormatVersion is exportAutoStateVersion at write time. Absent (0) means
|
||||
// a file written before versioning existed; those are field-for-field
|
||||
// identical to v1 and load as-is.
|
||||
FormatVersion int `json:"v,omitempty"`
|
||||
|
||||
LastDoltCommit string `json:"last_dolt_commit"`
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
Issues int `json:"issues"`
|
||||
|
|
@ -128,21 +148,31 @@ func maybeAutoExport(ctx context.Context, allowEmptyOverwrite bool) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Reconcile the existing JSONL against the store ONCE, and let BOTH
|
||||
// fail-safe guards below read the same answer. A deletion this store can
|
||||
// prove is not divergence for either of them: the empty-overwrite guard
|
||||
// fires first, so without a shared verdict `bd delete <last issue>`
|
||||
// wedges there before the orphan guard ever gets to prove anything
|
||||
// (GH#5896).
|
||||
var provenDeleted []string
|
||||
if !allowEmptyOverwrite {
|
||||
if skip, existingCount, err := shouldSkipEmptyAutoExport(ctx, fullPath); err != nil {
|
||||
rec, err := reconcileAutoExportJSONL(ctx, fullPath, state.LastDiffAnchor)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: auto-export skipped: failed to compare existing JSONL against local store: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
provenDeleted = rec.provenDeleted
|
||||
|
||||
if skip, existingCount, err := shouldSkipEmptyAutoExport(ctx, rec); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: auto-export skipped: failed to check existing JSONL: %v\n", err)
|
||||
return nil
|
||||
} else if skip {
|
||||
fmt.Fprintf(os.Stderr, "Warning: auto-export skipped: current database would export 0 issues, but %s already contains %d issue(s); refusing to overwrite. Run `bd init --from-jsonl` to import the JSONL file, or move it aside and retry.\n", fullPath, existingCount)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if !allowEmptyOverwrite {
|
||||
if missingIDs, err := missingJSONLIssueIDsInStore(ctx, fullPath, state.LastDiffAnchor); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: auto-export skipped: failed to compare existing JSONL against local store: %v\n", err)
|
||||
return nil
|
||||
} else if len(missingIDs) > 0 {
|
||||
fmt.Fprintf(os.Stderr, "Warning: auto-export skipped: %s contains %d JSONL-only issue record(s) absent from the local Dolt store (%s); refusing to overwrite. Run `bd init --from-jsonl` to import the JSONL file, or move it aside and retry.\n", fullPath, len(missingIDs), strings.Join(sampleStrings(missingIDs, 5), ", "))
|
||||
|
||||
if len(rec.unproven) > 0 {
|
||||
fmt.Fprintf(os.Stderr, "Warning: auto-export skipped: %s contains %d JSONL-only issue record(s) absent from the local Dolt store (%s); refusing to overwrite. Run `bd init --from-jsonl` to import the JSONL file, or move it aside and retry.\n", fullPath, len(rec.unproven), strings.Join(sampleStrings(rec.unproven, 5), ", "))
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
@ -167,8 +197,14 @@ func maybeAutoExport(ctx context.Context, allowEmptyOverwrite bool) error {
|
|||
debug.Logf("auto-export: failed to resolve diff anchor (%v); preserving previous anchor\n", anchorErr)
|
||||
anchorCommit = state.LastDiffAnchor
|
||||
}
|
||||
// provenDeleted rides along as FORCED removals: an id proved by the
|
||||
// in-process handoff or by store history is invisible to
|
||||
// dolt_diff(anchor, WORKING), so an incremental patch would faithfully
|
||||
// preserve its stale JSONL line forever even though the guard just
|
||||
// cleared the export to run. A full export needs nothing — it rewrites
|
||||
// from the store.
|
||||
issueCount, memoryCount, dirtyIDs, didIncremental, err := tryIncrementalExport(
|
||||
ctx, fullPath, state.LastDiffAnchor, doltWorkingRef, state.LastDirtyIDs,
|
||||
ctx, fullPath, state.LastDiffAnchor, doltWorkingRef, state.LastDirtyIDs, provenDeleted,
|
||||
)
|
||||
if err != nil {
|
||||
debug.Logf("auto-export: incremental failed (%v); falling back to full\n", err)
|
||||
|
|
@ -182,6 +218,13 @@ func maybeAutoExport(ctx context.Context, allowEmptyOverwrite bool) error {
|
|||
dirtyIDs = nil
|
||||
}
|
||||
|
||||
// Never heal silently. The user asked for a delete and is getting a line
|
||||
// removed from a git-tracked file; say so, and name what went.
|
||||
if len(provenDeleted) > 0 {
|
||||
fmt.Fprintf(os.Stderr, "auto-export: reconciled %d deleted issue(s) out of %s (deleted from store: %s)\n",
|
||||
len(provenDeleted), fullPath, strings.Join(sampleStrings(provenDeleted, 5), ", "))
|
||||
}
|
||||
|
||||
if dur := time.Since(exportStart); dur > slowExportWarnThreshold && !didIncremental {
|
||||
// Only warn on full exports — the whole point of incremental is to
|
||||
// get us under the threshold, so a slow incremental is noise.
|
||||
|
|
@ -265,12 +308,15 @@ func shouldExport(state *exportAutoState, interval time.Duration) bool {
|
|||
return time.Since(state.Timestamp) >= interval
|
||||
}
|
||||
|
||||
func shouldSkipEmptyAutoExport(ctx context.Context, path string) (bool, int, error) {
|
||||
existingCount, err := countIssueRecordsInJSONL(path)
|
||||
if err != nil {
|
||||
return false, 0, err
|
||||
}
|
||||
if existingCount == 0 {
|
||||
// shouldSkipEmptyAutoExport is the "store would write 0 issues over a
|
||||
// populated file" fail-safe. It reads the shared reconciliation rather than
|
||||
// re-parsing the JSONL so that ids already proven deleted don't count as
|
||||
// records worth protecting — deleting the last exported issue is the shape
|
||||
// that used to wedge here, one guard earlier than the orphan guard everyone
|
||||
// blamed (GH#5896).
|
||||
func shouldSkipEmptyAutoExport(ctx context.Context, rec *autoExportReconciliation) (bool, int, error) {
|
||||
existingCount := rec.jsonlIssueCount - len(rec.provenDeleted)
|
||||
if existingCount <= 0 {
|
||||
return false, 0, nil
|
||||
}
|
||||
|
||||
|
|
@ -282,15 +328,37 @@ func shouldSkipEmptyAutoExport(ctx context.Context, path string) (bool, int, err
|
|||
return len(issues) == 0, existingCount, nil
|
||||
}
|
||||
|
||||
func countIssueRecordsInJSONL(path string) (int, error) {
|
||||
ids, err := issueIDsInJSONL(path)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return len(ids), nil
|
||||
// historyProofMaxCandidates caps how many JSONL-only ids the store-history
|
||||
// proof will ask about in one export. A divergence wider than this is not a
|
||||
// delete pattern — it is GH#4988 territory (a torn, stale, or foreign JSONL),
|
||||
// where the conservative refusal is the right answer and a 100-way history
|
||||
// scan is wasted work on the way to it.
|
||||
const historyProofMaxCandidates = 100
|
||||
|
||||
// autoExportReconciliation is the single comparison of the existing JSONL
|
||||
// against the live store that both pre-export guards read.
|
||||
type autoExportReconciliation struct {
|
||||
// jsonlIssueCount is every issue record in the file, in auto-export
|
||||
// scope or not — the number the empty-overwrite guard reports.
|
||||
jsonlIssueCount int
|
||||
// provenDeleted are in-scope JSONL ids absent from the store that some
|
||||
// proof source accounted for as real deletions. The export must drop
|
||||
// their lines; neither guard may refuse over them.
|
||||
provenDeleted []string
|
||||
// unproven are in-scope JSONL ids absent from the store that nothing
|
||||
// could account for. The orphan guard refuses over these, unchanged.
|
||||
unproven []string
|
||||
}
|
||||
|
||||
func missingJSONLIssueIDsInStore(ctx context.Context, path, fromCommit string) ([]string, error) {
|
||||
// reconcileAutoExportJSONL compares the on-disk export against the store and
|
||||
// splits the JSONL-only issue ids into proven deletions and unexplained
|
||||
// divergence.
|
||||
//
|
||||
// fromCommit is the previous cycle's diff anchor, used by one of the three
|
||||
// proof sources; the other two need no anchor, which is what lets a store
|
||||
// wedged by an earlier binary (no anchor, or an anchor that no longer
|
||||
// resolves) recover on its first run under this code.
|
||||
func reconcileAutoExportJSONL(ctx context.Context, path, fromCommit string) (*autoExportReconciliation, error) {
|
||||
// GH#4988: only refuse when *in-scope* JSONL issue records are absent from
|
||||
// the store. Ephemeral wisps, templates, and infra types are outside
|
||||
// auto-export scope (buildAutoExportFilter / GH#3649). Compaction can
|
||||
|
|
@ -300,8 +368,9 @@ func missingJSONLIssueIDsInStore(ctx context.Context, path, fromCommit string) (
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rec := &autoExportReconciliation{jsonlIssueCount: len(existing)}
|
||||
if len(existing) == 0 {
|
||||
return nil, nil
|
||||
return rec, nil
|
||||
}
|
||||
|
||||
// Store-side query stays unfiltered and MaxRows: 0 (opts out of
|
||||
|
|
@ -321,24 +390,49 @@ func missingJSONLIssueIDsInStore(ctx context.Context, path, fromCommit string) (
|
|||
}
|
||||
|
||||
candidates := make([]string, 0)
|
||||
for _, rec := range existing {
|
||||
if rec.Ephemeral || rec.IsTemplate || infraTypeSet[string(rec.IssueType)] {
|
||||
for _, record := range existing {
|
||||
if record.Ephemeral || record.IsTemplate || infraTypeSet[string(record.IssueType)] {
|
||||
continue
|
||||
}
|
||||
if _, ok := localIDs[rec.ID]; !ok {
|
||||
candidates = append(candidates, rec.ID)
|
||||
if _, ok := localIDs[record.ID]; !ok {
|
||||
candidates = append(candidates, record.ID)
|
||||
}
|
||||
}
|
||||
if len(candidates) == 0 {
|
||||
return nil, nil
|
||||
return rec, nil
|
||||
}
|
||||
|
||||
// Before treating a JSONL-only id as an orphan/corruption, ask dolt_diff
|
||||
// whether the deletion is real and already recorded — a normal `bd
|
||||
// delete` since the last export's diff anchor, not data loss. Without an
|
||||
// anchor (cold start / no successful export yet) there is nothing to
|
||||
// diff against, so every candidate falls through to the conservative
|
||||
// "missing" verdict below, same as before this check existed.
|
||||
rec.provenDeleted, rec.unproven = proveDeletedIssueIDs(ctx, candidates, fromCommit)
|
||||
return rec, nil
|
||||
}
|
||||
|
||||
// proveDeletedIssueIDs splits JSONL-only candidate ids into the ones a proof
|
||||
// source accounts for as real deletions and the ones nothing can explain.
|
||||
//
|
||||
// Sources run cheapest-first, and each one only sees what the previous could
|
||||
// not prove:
|
||||
//
|
||||
// 1. the in-process delete handoff — this very command deleted the id a few
|
||||
// milliseconds ago. Free, and the only source that can see a create and a
|
||||
// delete that both sit uncommitted in the working set.
|
||||
// 2. dolt_diff against the previous export's anchor (GH#5806) — a DoltStore
|
||||
// fast path that also covers deletions that arrived from a peer.
|
||||
// 3. the store's own committed history (GH#5896) — anchor-free, works on
|
||||
// both stores, and the only source that can heal a store some earlier
|
||||
// binary already wedged.
|
||||
//
|
||||
// Whatever survives all three is unexplained divergence, and the caller keeps
|
||||
// refusing to overwrite: that is GH#4988's fail-safe, unchanged.
|
||||
func proveDeletedIssueIDs(ctx context.Context, candidates []string, fromCommit string) (proven, unproven []string) {
|
||||
unproven = candidates
|
||||
|
||||
// P1 — same-process delete handoff.
|
||||
proven, unproven = splitProvenDeletions(proven, unproven, commandDeletedIssueIDs.has)
|
||||
if len(unproven) == 0 {
|
||||
return proven, unproven
|
||||
}
|
||||
|
||||
// P2 — dolt_diff against the last export's anchor.
|
||||
//
|
||||
// The anchor must still be on the CURRENT HEAD's history for that proof
|
||||
// to mean anything. dolt_diff(anchor, WORKING) reports a row as "removed"
|
||||
|
|
@ -349,14 +443,11 @@ func missingJSONLIssueIDsInStore(ctx context.Context, path, fromCommit string) (
|
|||
// there would silently drop a live record from issues.jsonl, which is
|
||||
// exactly #4988's corruption class this guard exists to prevent. So the
|
||||
// deletion proof is accepted only when the anchor is reachable from HEAD
|
||||
// (CommitExists queries dolt_log, i.e. HEAD's forward history); otherwise
|
||||
// we keep refusing, which is the conservative pre-existing behavior.
|
||||
// (CommitExists queries dolt_log, i.e. HEAD's forward history).
|
||||
//
|
||||
// Residual, deliberately not fixed here (tracked by #5896): an anchor
|
||||
// that has become unresolvable — after a history squash or GC — combined
|
||||
// with a pending delete is a permanent wedge. The guard refuses, so the
|
||||
// export skips, so state is never saved, so the anchor never refreshes.
|
||||
// Recovery is `bd init --from-jsonl` or moving issues.jsonl aside.
|
||||
// A missing anchor, an off-history anchor, a diff error, or a store with
|
||||
// no DiffStore at all (embedded mode — the default) all just fall through
|
||||
// to P3 now, instead of ending the search.
|
||||
if fromCommit != "" && diffAnchorOnCurrentHistory(ctx, fromCommit) {
|
||||
if ds, ok := storage.UnwrapStore(store).(storage.DiffStore); ok {
|
||||
if changed, diffErr := ds.ChangedIssueIDs(ctx, fromCommit, doltWorkingRef); diffErr == nil {
|
||||
|
|
@ -364,25 +455,101 @@ func missingJSONLIssueIDsInStore(ctx context.Context, path, fromCommit string) (
|
|||
for _, id := range changed.Removed {
|
||||
removed[id] = struct{}{}
|
||||
}
|
||||
proven := candidates[:0]
|
||||
for _, id := range candidates {
|
||||
if _, ok := removed[id]; !ok {
|
||||
proven = append(proven, id)
|
||||
}
|
||||
}
|
||||
candidates = proven
|
||||
proven, unproven = splitProvenDeletions(proven, unproven, func(id string) bool {
|
||||
_, ok := removed[id]
|
||||
return ok
|
||||
})
|
||||
} else {
|
||||
debug.Logf("auto-export: anchor diff %s..%s failed (%v); falling through to the history proof\n",
|
||||
fromCommit, doltWorkingRef, diffErr)
|
||||
}
|
||||
// A diff error (e.g. anchor unreachable after history rewrite)
|
||||
// leaves candidates untouched — we can't prove the deletion, so
|
||||
// fall back to refusing, exactly as before this check existed.
|
||||
}
|
||||
}
|
||||
if len(unproven) == 0 {
|
||||
return proven, unproven
|
||||
}
|
||||
|
||||
return candidates, nil
|
||||
// P3 — the store's own committed history. "Was here, is gone" is a
|
||||
// deletion this store recorded; "was never here" is data this store never
|
||||
// had, which stays unproven. See storage.HistoryPresence for why that
|
||||
// asymmetry is what keeps #4988's guarantee intact.
|
||||
if len(unproven) > historyProofMaxCandidates {
|
||||
debug.Logf("auto-export: %d unproven JSONL-only ids exceeds the history-proof cap %d; refusing without asking\n",
|
||||
len(unproven), historyProofMaxCandidates)
|
||||
return proven, unproven
|
||||
}
|
||||
hp, ok := storage.UnwrapStore(store).(storage.HistoryPresence)
|
||||
if !ok {
|
||||
debug.Logf("auto-export: store does not implement HistoryPresence; JSONL-only ids stay unproven\n")
|
||||
return proven, unproven
|
||||
}
|
||||
historical, err := hp.HistoricalIssueIDs(ctx, unproven)
|
||||
if err != nil {
|
||||
debug.Logf("auto-export: history proof failed (%v); treating JSONL-only ids as unproven\n", err)
|
||||
return proven, unproven
|
||||
}
|
||||
proven, unproven = splitProvenDeletions(proven, unproven, func(id string) bool {
|
||||
_, ok := historical[id]
|
||||
return ok
|
||||
})
|
||||
return proven, unproven
|
||||
}
|
||||
|
||||
// splitProvenDeletions moves the ids isProven accepts from unproven onto
|
||||
// proven, preserving order on both sides.
|
||||
func splitProvenDeletions(proven, unproven []string, isProven func(string) bool) ([]string, []string) {
|
||||
remaining := make([]string, 0, len(unproven))
|
||||
for _, id := range unproven {
|
||||
if isProven(id) {
|
||||
proven = append(proven, id)
|
||||
continue
|
||||
}
|
||||
remaining = append(remaining, id)
|
||||
}
|
||||
return proven, remaining
|
||||
}
|
||||
|
||||
// deletedIssueIDSet is the in-process handoff from the delete commands to
|
||||
// auto-export: "this process just hard-deleted these ids, they are supposed to
|
||||
// be gone". Deliberately NOT persisted — a cross-process ledger would mean the
|
||||
// delete path read-modify-writes export-state.json underneath a concurrent
|
||||
// exporter, and a lost entry there silently re-wedges. When the handoff misses
|
||||
// (throttled export, separate invocation, peer's delete), the history proof
|
||||
// picks the id up as soon as the deletion is committed.
|
||||
type deletedIssueIDSet struct {
|
||||
mu sync.Mutex
|
||||
ids map[string]struct{}
|
||||
}
|
||||
|
||||
func (s *deletedIssueIDSet) add(ids ...string) {
|
||||
if len(ids) == 0 {
|
||||
return
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if s.ids == nil {
|
||||
s.ids = make(map[string]struct{}, len(ids))
|
||||
}
|
||||
for _, id := range ids {
|
||||
s.ids[id] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *deletedIssueIDSet) reset() {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.ids = nil
|
||||
}
|
||||
|
||||
func (s *deletedIssueIDSet) has(id string) bool {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
_, ok := s.ids[id]
|
||||
return ok
|
||||
}
|
||||
|
||||
// commitHistoryChecker is the narrow slice of storage.VersionControl that
|
||||
// missingJSONLIssueIDsInStore needs. It is declared locally and asserted
|
||||
// reconcileAutoExportJSONL needs. It is declared locally and asserted
|
||||
// separately from storage.DiffStore so a store implementing one but not the
|
||||
// other still degrades to the conservative verdict instead of panicking.
|
||||
type commitHistoryChecker interface {
|
||||
|
|
@ -392,7 +559,7 @@ type commitHistoryChecker interface {
|
|||
// diffAnchorOnCurrentHistory reports whether anchor is still reachable from
|
||||
// the current HEAD. It is the ancestry precondition on trusting a dolt_diff
|
||||
// "removed" verdict as proof of a real `bd delete` rather than a history
|
||||
// rewind — see missingJSONLIssueIDsInStore. Fails closed: a store that
|
||||
// rewind — see reconcileAutoExportJSONL. Fails closed: a store that
|
||||
// cannot answer, or an error while asking, yields false so the caller keeps
|
||||
// refusing to overwrite.
|
||||
func diffAnchorOnCurrentHistory(ctx context.Context, anchor string) bool {
|
||||
|
|
@ -495,18 +662,6 @@ func issueRecordsInJSONL(path string) ([]jsonlIssueRecord, error) {
|
|||
return records, nil
|
||||
}
|
||||
|
||||
func issueIDsInJSONL(path string) ([]string, error) {
|
||||
records, err := issueRecordsInJSONL(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ids := make([]string, len(records))
|
||||
for i, rec := range records {
|
||||
ids[i] = rec.ID
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
func sampleStrings(values []string, limit int) []string {
|
||||
if len(values) <= limit {
|
||||
return values
|
||||
|
|
@ -693,7 +848,7 @@ func exportToFile(ctx context.Context, path string, includeMemories bool) (issue
|
|||
// safe to drop when its id is no longer in the store (a TTL-compacted wisp,
|
||||
// GH#4988); if the store still has it, dropping it repeats #4069's data
|
||||
// loss. Deliberately unfiltered + MaxRows: 0, for the same reason as
|
||||
// missingJSONLIssueIDsInStore's store-side query: this guard's failure mode
|
||||
// reconcileAutoExportJSONL's store-side query: this guard's failure mode
|
||||
// is a permanent wedge, so the query must stay maximally permissive.
|
||||
func storeKnownIssueIDs(ctx context.Context) (map[string]struct{}, error) {
|
||||
issues, err := store.SearchIssues(ctx, "", types.IssueFilter{Limit: 0, MaxRows: 0})
|
||||
|
|
@ -809,11 +964,19 @@ func loadExportAutoState(beadsDir string) *exportAutoState {
|
|||
path, len(data), err, string(data[:min(len(data), 200)]))
|
||||
return &exportAutoState{}
|
||||
}
|
||||
if state.FormatVersion > exportAutoStateVersion {
|
||||
debug.Logf("auto-export: state file %s is format v%d, this binary understands v%d; starting from empty state\n",
|
||||
path, state.FormatVersion, exportAutoStateVersion)
|
||||
return &exportAutoState{}
|
||||
}
|
||||
return &state
|
||||
}
|
||||
|
||||
func saveExportAutoState(beadsDir string, state *exportAutoState) {
|
||||
path := filepath.Join(beadsDir, exportAutoStateFile)
|
||||
// Stamped here rather than at the call sites so there is exactly one
|
||||
// place that decides what version a written file claims to be.
|
||||
state.FormatVersion = exportAutoStateVersion
|
||||
data, err := json.Marshal(state)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: auto-export: failed to marshal state: %v\n", err)
|
||||
|
|
@ -1034,12 +1197,19 @@ func pathInsideDir(path, dir string) bool {
|
|||
// didIncremental=false when any precondition fails so the caller can fall
|
||||
// back to a full export.
|
||||
//
|
||||
// forcedRemovals are ids the caller has already proven deleted by some means
|
||||
// the diff cannot see (the in-process delete handoff, or the store's committed
|
||||
// history — see proveDeletedIssueIDs). They are unioned into the diff's own
|
||||
// removals, because a proven-deleted id is by definition absent at BOTH diff
|
||||
// endpoints in the cases that matter, so the patch would otherwise carry its
|
||||
// stale line forward forever.
|
||||
//
|
||||
// dirtyIDs returns the RAW diff's upserted ids (never carryIDs) for the
|
||||
// caller to persist as next cycle's carryIDs. Carrying only the
|
||||
// freshly-diffed ids — not the ones merely carried-in — makes a stable
|
||||
// no-op cycle self-heal: a carried id that produces no new diff simply
|
||||
// drops out instead of accumulating forever.
|
||||
func tryIncrementalExport(ctx context.Context, fullPath, fromCommit, toCommit string, carryIDs []string) (issueCount, memoryCount int, dirtyIDs []string, didIncremental bool, err error) {
|
||||
func tryIncrementalExport(ctx context.Context, fullPath, fromCommit, toCommit string, carryIDs, forcedRemovals []string) (issueCount, memoryCount int, dirtyIDs []string, didIncremental bool, err error) {
|
||||
if fromCommit == "" {
|
||||
debug.Logf("auto-export: incremental skipped — no prior commit hash recorded\n")
|
||||
return 0, 0, nil, false, nil
|
||||
|
|
@ -1069,8 +1239,16 @@ func tryIncrementalExport(ctx context.Context, fullPath, fromCommit, toCommit st
|
|||
// from last cycle (e.g. a working-set value that reverted between two
|
||||
// diff anchors nets to "no change" against the anchor, but the live row
|
||||
// still needs re-fetching to correct a stale patch from last cycle).
|
||||
removed := make(map[string]bool, len(changed.Removed)+len(forcedRemovals))
|
||||
for _, id := range changed.Removed {
|
||||
removed[id] = true
|
||||
}
|
||||
for _, id := range forcedRemovals {
|
||||
removed[id] = true
|
||||
}
|
||||
|
||||
upsertIDs := unionStrings(changed.Upserted, carryIDs)
|
||||
total := len(upsertIDs) + len(changed.Removed)
|
||||
total := len(upsertIDs) + len(removed)
|
||||
if total == 0 {
|
||||
// Nothing changed and nothing carried over. Still a valid
|
||||
// "incremental" outcome: no issues to rewrite, just refresh the
|
||||
|
|
@ -1135,10 +1313,6 @@ func tryIncrementalExport(ctx context.Context, fullPath, fromCommit, toCommit st
|
|||
// changed.Removed from the issues-table diff; rely on that.
|
||||
}
|
||||
|
||||
removed := make(map[string]bool, len(changed.Removed)+len(droppedByFilter))
|
||||
for _, id := range changed.Removed {
|
||||
removed[id] = true
|
||||
}
|
||||
for id := range droppedByFilter {
|
||||
removed[id] = true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,21 +13,22 @@ import (
|
|||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
// TestMissingJSONLIssueIDsInStore_IgnoresCompactedWisp pins the actual
|
||||
// GH#4988 behaviour at the layer that wedged auto-export permanently:
|
||||
// missingJSONLIssueIDsInStore itself. maphew's review noted that
|
||||
// TestReconcileAutoExportJSONL_IgnoresCompactedWisp pins the actual GH#4988
|
||||
// behaviour at the layer that wedged auto-export permanently: the
|
||||
// JSONL-vs-store reconciliation itself (formerly missingJSONLIssueIDsInStore,
|
||||
// now reconcileAutoExportJSONL). maphew's review noted that
|
||||
// TestMissingJSONLIssueIDsInStore is named in the original guard commit's
|
||||
// validation list but doesn't exist in the tree; this closes that gap.
|
||||
//
|
||||
// Seeds one persistent issue (present in the store) and a JSONL file that
|
||||
// additionally lists an ephemeral wisp id that is NOT in the store — the
|
||||
// TTL-compaction scenario, where a wisp was written to issues.jsonl and
|
||||
// later deleted from Dolt by compaction. Asserts `missing` comes back
|
||||
// empty: an out-of-scope (ephemeral) row's absence from the store must not
|
||||
// be treated as a hard orphan, or auto-export wedges forever.
|
||||
// later deleted from Dolt by compaction. Asserts the reconciliation reports
|
||||
// nothing at all: an out-of-scope (ephemeral) row's absence from the store
|
||||
// must not be treated as a hard orphan, or auto-export wedges forever.
|
||||
//
|
||||
// Requires a live Dolt test server/container (cgo build); skips otherwise.
|
||||
func TestMissingJSONLIssueIDsInStore_IgnoresCompactedWisp(t *testing.T) {
|
||||
func TestReconcileAutoExportJSONL_IgnoresCompactedWisp(t *testing.T) {
|
||||
if testDoltServerPort == 0 {
|
||||
t.Skip("Dolt test server not available")
|
||||
}
|
||||
|
|
@ -85,11 +86,16 @@ func TestMissingJSONLIssueIDsInStore_IgnoresCompactedWisp(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
missing, err := missingJSONLIssueIDsInStore(ctx, jsonlPath, "")
|
||||
rec, err := reconcileAutoExportJSONL(ctx, jsonlPath, "")
|
||||
if err != nil {
|
||||
t.Fatalf("missingJSONLIssueIDsInStore: %v", err)
|
||||
t.Fatalf("reconcileAutoExportJSONL: %v", err)
|
||||
}
|
||||
if len(missing) != 0 {
|
||||
t.Fatalf("missing = %v, want empty (compacted wisp is out-of-scope and must not be a hard orphan)", missing)
|
||||
if len(rec.unproven) != 0 {
|
||||
t.Fatalf("unproven = %v, want empty (compacted wisp is out-of-scope and must not be a hard orphan)", rec.unproven)
|
||||
}
|
||||
// And it must be out of scope, not merely proven: an ephemeral row never
|
||||
// reaches a proof source, so nothing about it is "reconciled" either.
|
||||
if len(rec.provenDeleted) != 0 {
|
||||
t.Fatalf("provenDeleted = %v, want empty (an out-of-scope wisp is never a candidate in the first place)", rec.provenDeleted)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -314,6 +314,18 @@ func (s *spyDiffStore) GetStateHash(ctx context.Context) (string, error) {
|
|||
return sh.GetStateHash(ctx)
|
||||
}
|
||||
|
||||
// Forwarded for the same reason as the two above: the spy hides the concrete
|
||||
// store from UnwrapStore, so any capability it does not re-declare simply
|
||||
// vanishes from the guard's point of view. Without this the orphan guard's
|
||||
// history proof silently degrades to "unproven" under the spy (GH#5896).
|
||||
func (s *spyDiffStore) HistoricalIssueIDs(ctx context.Context, ids []string) (map[string]struct{}, error) {
|
||||
hp, ok := storage.UnwrapStore(s.DoltStorage).(storage.HistoryPresence)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("spyDiffStore: wrapped store does not implement HistoryPresence")
|
||||
}
|
||||
return hp.HistoricalIssueIDs(ctx, ids)
|
||||
}
|
||||
|
||||
func autoExportTestDir(t *testing.T) string {
|
||||
t.Helper()
|
||||
dir := t.TempDir()
|
||||
|
|
@ -1222,7 +1234,11 @@ func TestShouldExport(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestCountIssueRecordsInJSONL(t *testing.T) {
|
||||
// TestIssueRecordsInJSONL_CountsAndOrdersInScopeIDs pins the parse the
|
||||
// pre-export guards read: exactly one record per id, memories and tombstones
|
||||
// and id-less lines skipped, sorted by id. Both guards now take their counts
|
||||
// and their candidate list from this one call.
|
||||
func TestIssueRecordsInJSONL_CountsAndOrdersInScopeIDs(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
path := filepath.Join(tmpDir, "issues.jsonl")
|
||||
data := strings.Join([]string{
|
||||
|
|
@ -1238,20 +1254,19 @@ func TestCountIssueRecordsInJSONL(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
got, err := countIssueRecordsInJSONL(path)
|
||||
records, err := issueRecordsInJSONL(path)
|
||||
if err != nil {
|
||||
t.Fatalf("countIssueRecordsInJSONL: %v", err)
|
||||
t.Fatalf("issueRecordsInJSONL: %v", err)
|
||||
}
|
||||
if got != 2 {
|
||||
t.Fatalf("countIssueRecordsInJSONL = %d, want 2", got)
|
||||
if len(records) != 2 {
|
||||
t.Fatalf("issueRecordsInJSONL returned %d records, want 2: %v", len(records), records)
|
||||
}
|
||||
|
||||
ids, err := issueIDsInJSONL(path)
|
||||
if err != nil {
|
||||
t.Fatalf("issueIDsInJSONL: %v", err)
|
||||
ids := make([]string, len(records))
|
||||
for i, rec := range records {
|
||||
ids[i] = rec.ID
|
||||
}
|
||||
if got := strings.Join(ids, ","); got != "bd-1,bd-2" {
|
||||
t.Fatalf("issueIDsInJSONL = %q, want bd-1,bd-2", got)
|
||||
t.Fatalf("issueRecordsInJSONL ids = %q, want bd-1,bd-2", got)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1686,7 +1701,7 @@ func TestTryIncrementalExport_PatchesChangedIssuesAndDropsRemoved(t *testing.T)
|
|||
}
|
||||
c2 := h.mustCommit(t, ctx, "mutate")
|
||||
|
||||
issueCount, memoryCount, _, didIncremental, err := tryIncrementalExport(ctx, exportPath, c1, c2, nil)
|
||||
issueCount, memoryCount, _, didIncremental, err := tryIncrementalExport(ctx, exportPath, c1, c2, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("tryIncrementalExport returned error: %v", err)
|
||||
}
|
||||
|
|
@ -1742,7 +1757,7 @@ func TestTryIncrementalExport_DropsIssueWhenFlippedToTemplate(t *testing.T) {
|
|||
}
|
||||
c2 := h.mustCommit(t, ctx, "promote to template")
|
||||
|
||||
_, _, _, didIncremental, err := tryIncrementalExport(ctx, exportPath, c1, c2, nil)
|
||||
_, _, _, didIncremental, err := tryIncrementalExport(ctx, exportPath, c1, c2, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("tryIncrementalExport: %v", err)
|
||||
}
|
||||
|
|
@ -1770,7 +1785,7 @@ func TestTryIncrementalExport_FallsBackWhenFileMissing(t *testing.T) {
|
|||
// No existing file → must return didIncremental=false and leave the
|
||||
// disk untouched so the caller falls back to the full-export path.
|
||||
exportPath := filepath.Join(h.beadsDir, "issues.jsonl")
|
||||
issueCount, _, _, didIncremental, err := tryIncrementalExport(ctx, exportPath, c1, c2, nil)
|
||||
issueCount, _, _, didIncremental, err := tryIncrementalExport(ctx, exportPath, c1, c2, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
|
@ -1810,7 +1825,7 @@ func TestTryIncrementalExport_ThresholdExceededFallsBack(t *testing.T) {
|
|||
h.mustCreateBatch(t, ctx, incrementalExportThreshold+1, "thr-")
|
||||
c2 := h.mustCommit(t, ctx, "flood")
|
||||
|
||||
_, _, _, didIncremental, err := tryIncrementalExport(ctx, exportPath, c1, c2, nil)
|
||||
_, _, _, didIncremental, err := tryIncrementalExport(ctx, exportPath, c1, c2, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
|
@ -1875,7 +1890,7 @@ func TestMaybeAutoExport_SecondRunTakesIncrementalPath_ServerMode(t *testing.T)
|
|||
}
|
||||
|
||||
// Both ChangedIssueIDs call sites must have fired: the orphan guard's
|
||||
// proof-of-deletion probe (missingJSONLIssueIDsInStore, which runs
|
||||
// proof-of-deletion probe (reconcileAutoExportJSONL, which runs
|
||||
// because deleting e2e-b leaves it JSONL-only) and tryIncrementalExport's
|
||||
// own diff. A bare "called at least once" check is NOT sufficient and was
|
||||
// the PR #5806 round-5 review finding: the guard's own call satisfies it
|
||||
|
|
@ -2055,7 +2070,7 @@ func TestTryIncrementalExport_NeverLeaksMemoriesIntoAutoExport(t *testing.T) {
|
|||
}
|
||||
c2 := h.mustCommit(t, ctx, "mutate")
|
||||
|
||||
_, memCount, _, didIncremental, err := tryIncrementalExport(ctx, exportPath, c1, c2, nil)
|
||||
_, memCount, _, didIncremental, err := tryIncrementalExport(ctx, exportPath, c1, c2, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("tryIncrementalExport: %v", err)
|
||||
}
|
||||
|
|
@ -2105,7 +2120,7 @@ func TestTryIncrementalExport_PreservesPreExistingMemoryAcrossPatch(t *testing.T
|
|||
}
|
||||
c2 := h.mustCommit(t, ctx, "mutate")
|
||||
|
||||
_, _, _, didIncremental, err := tryIncrementalExport(ctx, exportPath, c1, c2, nil)
|
||||
_, _, _, didIncremental, err := tryIncrementalExport(ctx, exportPath, c1, c2, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("tryIncrementalExport: %v", err)
|
||||
}
|
||||
|
|
@ -2206,7 +2221,7 @@ func TestTryIncrementalExport_ExcludesConfiguredOwnerFromPatchedIssues(t *testin
|
|||
}
|
||||
c2 := h.mustCommit(t, ctx, "mutate")
|
||||
|
||||
_, _, _, didIncremental, err := tryIncrementalExport(ctx, exportPath, c1, c2, nil)
|
||||
_, _, _, didIncremental, err := tryIncrementalExport(ctx, exportPath, c1, c2, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("tryIncrementalExport: %v", err)
|
||||
}
|
||||
|
|
@ -2239,7 +2254,7 @@ func TestTryIncrementalExport_PatchedLinesIncludeTypeField(t *testing.T) {
|
|||
}
|
||||
c2 := h.mustCommit(t, ctx, "mutate")
|
||||
|
||||
_, _, _, didIncremental, err := tryIncrementalExport(ctx, exportPath, c1, c2, nil)
|
||||
_, _, _, didIncremental, err := tryIncrementalExport(ctx, exportPath, c1, c2, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("tryIncrementalExport: %v", err)
|
||||
}
|
||||
|
|
|
|||
793
cmd/bd/export_auto_wedge_heal_test.go
Normal file
793
cmd/bd/export_auto_wedge_heal_test.go
Normal file
|
|
@ -0,0 +1,793 @@
|
|||
//go:build cgo
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/steveyegge/beads/internal/config"
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
// These tests cover GH#5896: `bd delete` used to leave a JSONL-only issue id
|
||||
// that no pre-export guard could account for, so auto-export refused, never
|
||||
// saved state, and refused again on every later command — forever, with the
|
||||
// documented recovery (`bd init --from-jsonl`) undoing the delete.
|
||||
//
|
||||
// They run against a fake store that models EMBEDDED mode's capability set —
|
||||
// the default open path, and the one the in-window #5806 fix could not reach:
|
||||
// no StateHasher, no DiffStore, but CommitExists and (new) HistoryPresence.
|
||||
// That is the same deliberate split TestMaybeAutoExport_EmbeddedModeFallsBack
|
||||
// CleanlyToFullExport makes: what these assert is the GUARD's wiring — which
|
||||
// proof sources it consults, what it does with the answers, what reaches the
|
||||
// file — while the capability's own semantics against a real Dolt engine are
|
||||
// pinned by the cross-store contract in internal/storage/storagecontract.
|
||||
|
||||
// fakeEmbeddedStore models EmbeddedDoltStore's capability surface for
|
||||
// auto-export: HEAD-only change detection, no dolt_diff, but able to answer
|
||||
// "was this id ever in my history".
|
||||
type fakeEmbeddedStore struct {
|
||||
storage.DoltStorage
|
||||
issues []*types.Issue
|
||||
historical map[string]bool
|
||||
// knownCommits is what CommitExists says yes to. An anchor that isn't
|
||||
// here models a rewind, a squash, or a state file from another clone.
|
||||
knownCommits map[string]bool
|
||||
headCommit string
|
||||
|
||||
// historyAsked records every id handed to HistoricalIssueIDs, so a test
|
||||
// can assert what the guard did NOT ask about.
|
||||
historyAsked []string
|
||||
historyCalls int
|
||||
historyFailed bool
|
||||
}
|
||||
|
||||
func (f *fakeEmbeddedStore) GetCurrentCommit(_ context.Context) (string, error) {
|
||||
if f.headCommit == "" {
|
||||
return "head-1", nil
|
||||
}
|
||||
return f.headCommit, nil
|
||||
}
|
||||
|
||||
func (f *fakeEmbeddedStore) GetInfraTypes(_ context.Context) map[string]bool { return nil }
|
||||
|
||||
func (f *fakeEmbeddedStore) GetConfig(_ context.Context, _ string) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (f *fakeEmbeddedStore) SearchIssues(_ context.Context, _ string, _ types.IssueFilter) ([]*types.Issue, error) {
|
||||
return f.issues, nil
|
||||
}
|
||||
|
||||
func (f *fakeEmbeddedStore) GetLabelsForIssues(_ context.Context, _ []string) (map[string][]string, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (f *fakeEmbeddedStore) GetDependencyRecordsForIssues(_ context.Context, _ []string) (map[string][]*types.Dependency, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (f *fakeEmbeddedStore) GetCommentsForIssues(_ context.Context, _ []string) (map[string][]*types.Comment, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (f *fakeEmbeddedStore) GetCommentCounts(_ context.Context, _ []string) (map[string]int, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (f *fakeEmbeddedStore) GetDependencyCounts(_ context.Context, _ []string) (map[string]*types.DependencyCounts, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (f *fakeEmbeddedStore) CommitExists(_ context.Context, hash string) (bool, error) {
|
||||
return f.knownCommits[hash], nil
|
||||
}
|
||||
|
||||
func (f *fakeEmbeddedStore) HistoricalIssueIDs(_ context.Context, ids []string) (map[string]struct{}, error) {
|
||||
f.historyCalls++
|
||||
f.historyAsked = append(f.historyAsked, ids...)
|
||||
if f.historyFailed {
|
||||
return nil, context.DeadlineExceeded
|
||||
}
|
||||
present := make(map[string]struct{})
|
||||
for _, id := range ids {
|
||||
if f.historical[id] {
|
||||
present[id] = struct{}{}
|
||||
}
|
||||
}
|
||||
return present, nil
|
||||
}
|
||||
|
||||
// deleteFromStore removes an id from the store's live rows the way a hard
|
||||
// delete does, leaving its history intact.
|
||||
func (f *fakeEmbeddedStore) deleteFromStore(id string) {
|
||||
kept := f.issues[:0]
|
||||
for _, iss := range f.issues {
|
||||
if iss.ID != id {
|
||||
kept = append(kept, iss)
|
||||
}
|
||||
}
|
||||
f.issues = kept
|
||||
}
|
||||
|
||||
// fakeHistorylessStore is fakeEmbeddedStore without HistoryPresence: the
|
||||
// degradation case (an older or third-party store), and the fixture the P1
|
||||
// handoff test needs so nothing but the handoff can prove anything.
|
||||
type fakeHistorylessStore struct {
|
||||
*fakeEmbeddedStore
|
||||
}
|
||||
|
||||
func (f *fakeHistorylessStore) HistoricalIssueIDs(context.Context, []string) (map[string]struct{}, error) {
|
||||
panic("HistoryPresence must not be reached on a store that does not implement it")
|
||||
}
|
||||
|
||||
func newWedgeHealTestStore(t *testing.T, issues ...*types.Issue) *fakeEmbeddedStore {
|
||||
t.Helper()
|
||||
historical := make(map[string]bool, len(issues))
|
||||
for _, iss := range issues {
|
||||
historical[iss.ID] = true
|
||||
}
|
||||
return &fakeEmbeddedStore{
|
||||
issues: issues,
|
||||
historical: historical,
|
||||
knownCommits: map[string]bool{},
|
||||
headCommit: "head-1",
|
||||
}
|
||||
}
|
||||
|
||||
func wedgeHealIssue(id, title string) *types.Issue {
|
||||
return &types.Issue{
|
||||
ID: id,
|
||||
Title: title,
|
||||
Status: types.StatusOpen,
|
||||
Priority: 2,
|
||||
IssueType: types.TypeTask,
|
||||
}
|
||||
}
|
||||
|
||||
// setupWedgeHealTest wires config, globals and a .beads dir, and returns the
|
||||
// beads dir plus the export path.
|
||||
func setupWedgeHealTest(t *testing.T, store2 storage.DoltStorage) (beadsDir, exportPath string) {
|
||||
t.Helper()
|
||||
initConfigForTest(t)
|
||||
config.Set("export.auto", true)
|
||||
// The throttle is not what these tests are about, and a 1ms interval is
|
||||
// long enough to swallow a second export that lands in the same
|
||||
// millisecond as the first.
|
||||
config.Set("export.interval", "1ns")
|
||||
|
||||
saveAndRestoreGlobals(t)
|
||||
dir := autoExportTestDir(t)
|
||||
store = store2
|
||||
storeMutex.Lock()
|
||||
storeActive = true
|
||||
storeMutex.Unlock()
|
||||
t.Cleanup(func() {
|
||||
storeMutex.Lock()
|
||||
storeActive = false
|
||||
storeMutex.Unlock()
|
||||
})
|
||||
|
||||
beadsDir = filepath.Join(dir, ".beads")
|
||||
return beadsDir, filepath.Join(beadsDir, "issues.jsonl")
|
||||
}
|
||||
|
||||
func jsonlIDs(t *testing.T, path string) []string {
|
||||
t.Helper()
|
||||
records, err := issueRecordsInJSONL(path)
|
||||
if err != nil {
|
||||
t.Fatalf("issueRecordsInJSONL(%s): %v", path, err)
|
||||
}
|
||||
ids := make([]string, len(records))
|
||||
for i, rec := range records {
|
||||
ids[i] = rec.ID
|
||||
}
|
||||
sort.Strings(ids)
|
||||
return ids
|
||||
}
|
||||
|
||||
// writeWedgedExportState writes the on-disk state a pre-fix binary leaves
|
||||
// behind: a last-seen commit, an open throttle window, and whatever anchor
|
||||
// the caller wants to model.
|
||||
func writeWedgedExportState(t *testing.T, beadsDir, lastCommit, anchor string) {
|
||||
t.Helper()
|
||||
saveExportAutoState(beadsDir, &exportAutoState{
|
||||
LastDoltCommit: lastCommit,
|
||||
LastDiffAnchor: anchor,
|
||||
Timestamp: time.Time{},
|
||||
Issues: 2,
|
||||
})
|
||||
}
|
||||
|
||||
// TestMaybeAutoExport_DeleteHealsInsteadOfWedging_Embedded is the issue's own
|
||||
// repro on the default backend: create → export → delete → export must
|
||||
// SUCCEED and the export must reflect the deletion.
|
||||
func TestMaybeAutoExport_DeleteHealsInsteadOfWedging_Embedded(t *testing.T) {
|
||||
fake := newWedgeHealTestStore(t,
|
||||
wedgeHealIssue("wh-a", "Alpha"),
|
||||
wedgeHealIssue("wh-b", "Beta"),
|
||||
)
|
||||
beadsDir, exportPath := setupWedgeHealTest(t, fake)
|
||||
|
||||
if err := maybeAutoExport(context.Background(), false); err != nil {
|
||||
t.Fatalf("first maybeAutoExport: %v", err)
|
||||
}
|
||||
if got, want := jsonlIDs(t, exportPath), []string{"wh-a", "wh-b"}; strings.Join(got, ",") != strings.Join(want, ",") {
|
||||
t.Fatalf("setup: exported ids = %v, want %v", got, want)
|
||||
}
|
||||
|
||||
// Delete wh-b the way a pre-existing store would have it — gone from the
|
||||
// live rows, still in history — and touch wh-a so the test can also tell
|
||||
// a healed export from a skipped one by its CONTENT.
|
||||
fake.deleteFromStore("wh-b")
|
||||
fake.issues[0].Title = "Alpha renamed"
|
||||
fake.headCommit = "head-2"
|
||||
|
||||
stderr := captureStderr(t, func() {
|
||||
if err := maybeAutoExport(context.Background(), false); err != nil {
|
||||
t.Fatalf("second maybeAutoExport: %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
if got, want := jsonlIDs(t, exportPath), []string{"wh-a"}; strings.Join(got, ",") != strings.Join(want, ",") {
|
||||
t.Errorf("after delete, exported ids = %v, want %v — the deletion was not reflected", got, want)
|
||||
}
|
||||
if titles := loadIssueTitles(t, exportPath); titles["wh-a"] != "Alpha renamed" {
|
||||
t.Errorf("wh-a title = %q, want %q — the export was skipped, not healed", titles["wh-a"], "Alpha renamed")
|
||||
}
|
||||
if state := loadExportAutoState(beadsDir); state.LastDoltCommit != "head-2" {
|
||||
t.Errorf("LastDoltCommit = %q, want %q — state must advance or the next command wedges on the same comparison", state.LastDoltCommit, "head-2")
|
||||
}
|
||||
if !strings.Contains(stderr, "wh-b") || !strings.Contains(stderr, "reconciled") {
|
||||
t.Errorf("stderr = %q, want a heal notice naming wh-b", stderr)
|
||||
}
|
||||
if strings.Contains(stderr, "refusing to overwrite") {
|
||||
t.Errorf("stderr = %q, want no refusal", stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// TestMaybeAutoExport_DeleteLastIssueHealsEmptyGuard covers the trap the
|
||||
// single-issue repro actually hits: with nothing left in the store, the
|
||||
// EMPTY-OVERWRITE guard fires before the orphan guard, and refuses on "0
|
||||
// issues vs 1 record" unless it too knows the record is a proven deletion.
|
||||
func TestMaybeAutoExport_DeleteLastIssueHealsEmptyGuard(t *testing.T) {
|
||||
fake := newWedgeHealTestStore(t, wedgeHealIssue("wh-only", "The only one"))
|
||||
beadsDir, exportPath := setupWedgeHealTest(t, fake)
|
||||
|
||||
if err := maybeAutoExport(context.Background(), false); err != nil {
|
||||
t.Fatalf("first maybeAutoExport: %v", err)
|
||||
}
|
||||
if got := jsonlIDs(t, exportPath); len(got) != 1 {
|
||||
t.Fatalf("setup: exported ids = %v, want exactly wh-only", got)
|
||||
}
|
||||
|
||||
fake.deleteFromStore("wh-only")
|
||||
fake.headCommit = "head-2"
|
||||
|
||||
stderr := captureStderr(t, func() {
|
||||
if err := maybeAutoExport(context.Background(), false); err != nil {
|
||||
t.Fatalf("second maybeAutoExport: %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
if strings.Contains(stderr, "would export 0 issues") {
|
||||
t.Fatalf("empty-overwrite guard refused a fully-proven deletion: %q", stderr)
|
||||
}
|
||||
if _, err := os.Stat(exportPath); !os.IsNotExist(err) {
|
||||
t.Errorf("issues.jsonl still exists after the last issue was deleted (stat err = %v); the empty export removes the file", err)
|
||||
}
|
||||
if state := loadExportAutoState(beadsDir); state.LastDoltCommit != "head-2" {
|
||||
t.Errorf("LastDoltCommit = %q, want %q", state.LastDoltCommit, "head-2")
|
||||
}
|
||||
}
|
||||
|
||||
// TestMaybeAutoExport_PreWedgedStoreRecovers is the upgrade path: the delete
|
||||
// already happened under a binary that had no proof for it, so there is no
|
||||
// in-process handoff to lean on and the anchor is useless. The first export
|
||||
// under this code must heal anyway, from history alone.
|
||||
func TestMaybeAutoExport_PreWedgedStoreRecovers(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
anchor string
|
||||
}{
|
||||
// R4: the state file was lost, or no export ever succeeded.
|
||||
{name: "AnchorLost", anchor: ""},
|
||||
// R2 stand-in: a well-formed anchor that no longer resolves, as
|
||||
// after a history squash, a GC, or a branch checkout.
|
||||
{name: "AnchorNoLongerResolves", anchor: "abcdefghijklmnopqrstuvwxyz012345"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
// The store never knew wh-b as a live row in this process; only
|
||||
// its history remembers it. That IS the pre-fix on-disk shape.
|
||||
fake := newWedgeHealTestStore(t, wedgeHealIssue("wh-a", "Alpha"))
|
||||
fake.historical["wh-b"] = true
|
||||
beadsDir, exportPath := setupWedgeHealTest(t, fake)
|
||||
|
||||
writeJSONLLines(t, exportPath,
|
||||
map[string]any{"_type": "issue", "id": "wh-a", "title": "Alpha", "issue_type": "task"},
|
||||
map[string]any{"_type": "issue", "id": "wh-b", "title": "Beta", "issue_type": "task"},
|
||||
)
|
||||
writeWedgedExportState(t, beadsDir, "head-0", tc.anchor)
|
||||
|
||||
stderr := captureStderr(t, func() {
|
||||
if err := maybeAutoExport(context.Background(), false); err != nil {
|
||||
t.Fatalf("maybeAutoExport: %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
if strings.Contains(stderr, "refusing to overwrite") {
|
||||
t.Fatalf("still wedged: %q", stderr)
|
||||
}
|
||||
if got, want := jsonlIDs(t, exportPath), []string{"wh-a"}; strings.Join(got, ",") != strings.Join(want, ",") {
|
||||
t.Errorf("exported ids = %v, want %v", got, want)
|
||||
}
|
||||
if !strings.Contains(stderr, "wh-b") {
|
||||
t.Errorf("stderr = %q, want a heal notice naming wh-b", stderr)
|
||||
}
|
||||
if state := loadExportAutoState(beadsDir); state.LastDoltCommit != "head-1" {
|
||||
t.Errorf("LastDoltCommit = %q, want head-1 (state must be re-saved or the wedge survives the upgrade)", state.LastDoltCommit)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestMaybeAutoExport_UnprovableJSONLIDStillRefuses is the fail-safe half.
|
||||
// An id this store has no history of is indistinguishable from GH#4988's torn
|
||||
// or replaced store, and must keep refusing with the unchanged message —
|
||||
// including after a rewind, where the id's commits are no longer reachable
|
||||
// from HEAD and so are no longer in dolt_history_issues.
|
||||
func TestMaybeAutoExport_UnprovableJSONLIDStillRefuses(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
anchor string
|
||||
}{
|
||||
{name: "NeverExisted", anchor: ""},
|
||||
{name: "RewoundAwayWithStaleAnchor", anchor: "abcdefghijklmnopqrstuvwxyz012345"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
fake := newWedgeHealTestStore(t, wedgeHealIssue("wh-a", "Alpha"))
|
||||
beadsDir, exportPath := setupWedgeHealTest(t, fake)
|
||||
|
||||
writeJSONLLines(t, exportPath,
|
||||
map[string]any{"_type": "issue", "id": "wh-a", "title": "Alpha", "issue_type": "task"},
|
||||
map[string]any{"_type": "issue", "id": "wh-ghost", "title": "Ghost", "issue_type": "task"},
|
||||
)
|
||||
writeWedgedExportState(t, beadsDir, "head-0", tc.anchor)
|
||||
|
||||
stderr := captureStderr(t, func() {
|
||||
if err := maybeAutoExport(context.Background(), false); err != nil {
|
||||
t.Fatalf("maybeAutoExport: %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
if !strings.Contains(stderr, "refusing to overwrite") {
|
||||
t.Errorf("stderr = %q, want the unchanged orphan refusal", stderr)
|
||||
}
|
||||
if !strings.Contains(stderr, "wh-ghost") {
|
||||
t.Errorf("stderr = %q, want the refusal to name wh-ghost", stderr)
|
||||
}
|
||||
if got := jsonlIDs(t, exportPath); len(got) != 2 {
|
||||
t.Errorf("exported ids = %v, want both records preserved — an unprovable divergence must never lose a line", got)
|
||||
}
|
||||
if state := loadExportAutoState(beadsDir); state.LastDoltCommit != "head-0" {
|
||||
t.Errorf("LastDoltCommit = %q, want head-0 (a refusal must not advance state)", state.LastDoltCommit)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestMaybeAutoExport_HistoryProofFailureRefuses: a store that cannot answer
|
||||
// the history question is not a store that answered "no". The guard must fall
|
||||
// back to refusing, not to overwriting.
|
||||
func TestMaybeAutoExport_HistoryProofFailureRefuses(t *testing.T) {
|
||||
fake := newWedgeHealTestStore(t, wedgeHealIssue("wh-a", "Alpha"))
|
||||
fake.historical["wh-b"] = true
|
||||
fake.historyFailed = true
|
||||
beadsDir, exportPath := setupWedgeHealTest(t, fake)
|
||||
|
||||
writeJSONLLines(t, exportPath,
|
||||
map[string]any{"_type": "issue", "id": "wh-a", "title": "Alpha", "issue_type": "task"},
|
||||
map[string]any{"_type": "issue", "id": "wh-b", "title": "Beta", "issue_type": "task"},
|
||||
)
|
||||
writeWedgedExportState(t, beadsDir, "head-0", "")
|
||||
|
||||
stderr := captureStderr(t, func() {
|
||||
if err := maybeAutoExport(context.Background(), false); err != nil {
|
||||
t.Fatalf("maybeAutoExport: %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
if !strings.Contains(stderr, "refusing to overwrite") {
|
||||
t.Errorf("stderr = %q, want a refusal when the history proof itself failed", stderr)
|
||||
}
|
||||
if got := jsonlIDs(t, exportPath); len(got) != 2 {
|
||||
t.Errorf("exported ids = %v, want both records preserved", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestMaybeAutoExport_DeleteHandoffProvesWhatHistoryCannot covers the one
|
||||
// shape no store-side proof can ever reach: an issue created AND deleted
|
||||
// without either write reaching a commit. The in-process handoff from
|
||||
// deleteBatch is the only witness, and the store here has no HistoryPresence
|
||||
// at all, so nothing else can cover for it.
|
||||
func TestMaybeAutoExport_DeleteHandoffProvesWhatHistoryCannot(t *testing.T) {
|
||||
inner := newWedgeHealTestStore(t, wedgeHealIssue("wh-a", "Alpha"))
|
||||
fake := &fakeHistorylessStore{fakeEmbeddedStore: inner}
|
||||
beadsDir, exportPath := setupWedgeHealTest(t, fake)
|
||||
|
||||
writeJSONLLines(t, exportPath,
|
||||
map[string]any{"_type": "issue", "id": "wh-a", "title": "Alpha", "issue_type": "task"},
|
||||
map[string]any{"_type": "issue", "id": "wh-uncommitted", "title": "Never committed", "issue_type": "task"},
|
||||
)
|
||||
writeWedgedExportState(t, beadsDir, "head-0", "")
|
||||
|
||||
commandDeletedIssueIDs.reset()
|
||||
t.Cleanup(commandDeletedIssueIDs.reset)
|
||||
commandDeletedIssueIDs.add("wh-uncommitted")
|
||||
|
||||
stderr := captureStderr(t, func() {
|
||||
if err := maybeAutoExport(context.Background(), false); err != nil {
|
||||
t.Fatalf("maybeAutoExport: %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
if strings.Contains(stderr, "refusing to overwrite") {
|
||||
t.Fatalf("the delete handoff did not prove the deletion: %q", stderr)
|
||||
}
|
||||
if got, want := jsonlIDs(t, exportPath), []string{"wh-a"}; strings.Join(got, ",") != strings.Join(want, ",") {
|
||||
t.Errorf("exported ids = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// TestMaybeAutoExport_ScopeSkipsNeverReachAProofSource: out-of-scope JSONL
|
||||
// rows (ephemeral wisps, templates, infra types) are not candidates in the
|
||||
// first place — GH#4988's own fix — so they must not cost a history query
|
||||
// either.
|
||||
func TestMaybeAutoExport_ScopeSkipsNeverReachAProofSource(t *testing.T) {
|
||||
fake := newWedgeHealTestStore(t, wedgeHealIssue("wh-a", "Alpha"))
|
||||
_, exportPath := setupWedgeHealTest(t, fake)
|
||||
|
||||
writeJSONLLines(t, exportPath,
|
||||
map[string]any{"_type": "issue", "id": "wh-a", "title": "Alpha", "issue_type": "task"},
|
||||
map[string]any{"_type": "issue", "id": "wh-wisp", "title": "Compacted wisp", "issue_type": "task", "ephemeral": true},
|
||||
map[string]any{"_type": "issue", "id": "wh-tpl", "title": "Template", "issue_type": "task", "is_template": true},
|
||||
)
|
||||
|
||||
rec, err := reconcileAutoExportJSONL(context.Background(), exportPath, "")
|
||||
if err != nil {
|
||||
t.Fatalf("reconcileAutoExportJSONL: %v", err)
|
||||
}
|
||||
if len(rec.unproven) != 0 || len(rec.provenDeleted) != 0 {
|
||||
t.Errorf("unproven = %v, provenDeleted = %v, want both empty", rec.unproven, rec.provenDeleted)
|
||||
}
|
||||
if fake.historyCalls != 0 {
|
||||
t.Errorf("HistoricalIssueIDs called %d times with %v; out-of-scope rows must never reach a proof source", fake.historyCalls, fake.historyAsked)
|
||||
}
|
||||
if rec.jsonlIssueCount != 3 {
|
||||
t.Errorf("jsonlIssueCount = %d, want 3 (the empty-overwrite guard counts every record, in scope or not)", rec.jsonlIssueCount)
|
||||
}
|
||||
}
|
||||
|
||||
// TestProveDeletedIssueIDs_HistoryProofIsCapped: past the cap, a divergence is
|
||||
// not a delete pattern, and the guard refuses without paying for the scan.
|
||||
func TestProveDeletedIssueIDs_HistoryProofIsCapped(t *testing.T) {
|
||||
fake := newWedgeHealTestStore(t)
|
||||
setupWedgeHealTest(t, fake)
|
||||
|
||||
candidates := make([]string, historyProofMaxCandidates+1)
|
||||
for i := range candidates {
|
||||
candidates[i] = "wh-" + string(rune('a'+i%26)) + string(rune('0'+i/26))
|
||||
fake.historical[candidates[i]] = true
|
||||
}
|
||||
|
||||
proven, unproven := proveDeletedIssueIDs(context.Background(), candidates, "")
|
||||
if len(proven) != 0 {
|
||||
t.Errorf("proven = %d ids, want 0 past the cap", len(proven))
|
||||
}
|
||||
if len(unproven) != len(candidates) {
|
||||
t.Errorf("unproven = %d ids, want all %d", len(unproven), len(candidates))
|
||||
}
|
||||
if fake.historyCalls != 0 {
|
||||
t.Errorf("HistoricalIssueIDs called %d times; past the cap the guard must not ask", fake.historyCalls)
|
||||
}
|
||||
}
|
||||
|
||||
// TestExportAutoState_VersionRoundTripAndFutureDiscard is the GH#5896 R5
|
||||
// acceptance: today's unversioned files load unchanged, a file from a future
|
||||
// binary is discarded rather than reinterpreted, and — the part that makes
|
||||
// discarding safe at all — discarding does not wedge, because the deletion
|
||||
// proofs no longer need the anchor it threw away.
|
||||
func TestExportAutoState_VersionRoundTripAndFutureDiscard(t *testing.T) {
|
||||
t.Run("StampsTheCurrentVersion", func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
saveExportAutoState(dir, &exportAutoState{LastDoltCommit: "c1", LastDiffAnchor: "a1"})
|
||||
|
||||
data, err := os.ReadFile(filepath.Join(dir, exportAutoStateFile))
|
||||
if err != nil {
|
||||
t.Fatalf("read state: %v", err)
|
||||
}
|
||||
var raw map[string]any
|
||||
if err := json.Unmarshal(data, &raw); err != nil {
|
||||
t.Fatalf("unmarshal state: %v", err)
|
||||
}
|
||||
if got := raw["v"]; got != float64(exportAutoStateVersion) {
|
||||
t.Errorf("state file v = %v, want %d", got, exportAutoStateVersion)
|
||||
}
|
||||
|
||||
state := loadExportAutoState(dir)
|
||||
if state.LastDoltCommit != "c1" || state.LastDiffAnchor != "a1" {
|
||||
t.Errorf("round trip lost fields: %+v", state)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("LoadsAnUnversionedFileAsIs", func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
legacy := `{"last_dolt_commit":"c1","last_diff_anchor":"a1","issues":7}`
|
||||
if err := os.WriteFile(filepath.Join(dir, exportAutoStateFile), []byte(legacy), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
state := loadExportAutoState(dir)
|
||||
if state.LastDoltCommit != "c1" || state.LastDiffAnchor != "a1" || state.Issues != 7 {
|
||||
t.Errorf("pre-versioning state file did not load as-is: %+v", state)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("DiscardsAFutureVersionWithoutWedging", func(t *testing.T) {
|
||||
fake := newWedgeHealTestStore(t, wedgeHealIssue("wh-a", "Alpha"))
|
||||
fake.historical["wh-b"] = true
|
||||
beadsDir, exportPath := setupWedgeHealTest(t, fake)
|
||||
|
||||
writeJSONLLines(t, exportPath,
|
||||
map[string]any{"_type": "issue", "id": "wh-a", "title": "Alpha", "issue_type": "task"},
|
||||
map[string]any{"_type": "issue", "id": "wh-b", "title": "Beta", "issue_type": "task"},
|
||||
)
|
||||
future := `{"v":999,"last_dolt_commit":"head-1","last_diff_anchor":"future-anchor"}`
|
||||
if err := os.WriteFile(filepath.Join(beadsDir, exportAutoStateFile), []byte(future), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if state := loadExportAutoState(beadsDir); state.LastDoltCommit != "" || state.LastDiffAnchor != "" {
|
||||
t.Fatalf("future-version state was not discarded: %+v", state)
|
||||
}
|
||||
|
||||
// Discarding drops the anchor AND the last-seen commit, so this run
|
||||
// looks like a cold start with a stale JSONL — pre-#5896 the exact
|
||||
// R4 permanent wedge. It must export and re-anchor instead.
|
||||
stderr := captureStderr(t, func() {
|
||||
if err := maybeAutoExport(context.Background(), false); err != nil {
|
||||
t.Fatalf("maybeAutoExport: %v", err)
|
||||
}
|
||||
})
|
||||
if strings.Contains(stderr, "refusing to overwrite") {
|
||||
t.Fatalf("discarding a future-version state file wedged the export: %q", stderr)
|
||||
}
|
||||
if got, want := jsonlIDs(t, exportPath), []string{"wh-a"}; strings.Join(got, ",") != strings.Join(want, ",") {
|
||||
t.Errorf("exported ids = %v, want %v", got, want)
|
||||
}
|
||||
state := loadExportAutoState(beadsDir)
|
||||
if state.FormatVersion != exportAutoStateVersion || state.LastDoltCommit != "head-1" {
|
||||
t.Errorf("state after re-anchor = %+v, want v%d at head-1", state, exportAutoStateVersion)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// The tests below run against a REAL DoltStore over the test sql-server —
|
||||
// server mode, where the store does implement DiffStore and the incremental
|
||||
// path is live. What the fake-store tests cannot reach is exactly what these
|
||||
// are for: dolt_history_issues answering for itself, and proven-deleted ids
|
||||
// having to survive a dolt_diff-driven incremental PATCH rather than a full
|
||||
// rewrite from the store.
|
||||
|
||||
// TestMaybeAutoExport_DeleteHealsInsteadOfWedging_ServerMode is the issue's
|
||||
// repro on the server-backed store, with the anchor deliberately blanked so
|
||||
// the #5806 anchor-diff proof cannot fire and the history proof has to carry
|
||||
// it — the R2/R4 residue this fix is for.
|
||||
func TestMaybeAutoExport_DeleteHealsInsteadOfWedging_ServerMode(t *testing.T) {
|
||||
h, ctx := setupIncrementalExportTest(t)
|
||||
initConfigForTest(t)
|
||||
config.Set("export.auto", true)
|
||||
config.Set("export.interval", "1ns")
|
||||
|
||||
h.mustCreate(t, ctx, "sw-a", "Alpha")
|
||||
h.mustCreate(t, ctx, "sw-b", "Beta")
|
||||
h.mustCommit(t, ctx, "baseline")
|
||||
if err := maybeAutoExport(ctx, false); err != nil {
|
||||
t.Fatalf("first maybeAutoExport: %v", err)
|
||||
}
|
||||
exportPath := filepath.Join(h.beadsDir, "issues.jsonl")
|
||||
if got := countIssueLines(t, exportPath); got != 2 {
|
||||
t.Fatalf("setup: %d issue lines, want 2", got)
|
||||
}
|
||||
|
||||
// Delete through the store directly — no in-process handoff — and blank
|
||||
// the anchor, which is what a squashed history or a lost state file
|
||||
// leaves behind. Only dolt_history_issues can answer now.
|
||||
if err := h.store.DeleteIssue(ctx, "sw-b"); err != nil {
|
||||
t.Fatalf("DeleteIssue: %v", err)
|
||||
}
|
||||
h.mustCommit(t, ctx, "delete sw-b")
|
||||
state := loadExportAutoState(h.beadsDir)
|
||||
state.LastDiffAnchor = ""
|
||||
state.Timestamp = time.Time{}
|
||||
saveExportAutoState(h.beadsDir, state)
|
||||
|
||||
stderr := captureStderr(t, func() {
|
||||
if err := maybeAutoExport(ctx, false); err != nil {
|
||||
t.Fatalf("second maybeAutoExport: %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
if strings.Contains(stderr, "refusing to overwrite") {
|
||||
t.Fatalf("still wedged on the server-backed store: %q", stderr)
|
||||
}
|
||||
if got, want := jsonlIDs(t, exportPath), []string{"sw-a"}; strings.Join(got, ",") != strings.Join(want, ",") {
|
||||
t.Errorf("exported ids = %v, want %v", got, want)
|
||||
}
|
||||
if !strings.Contains(stderr, "sw-b") {
|
||||
t.Errorf("stderr = %q, want a heal notice naming sw-b", stderr)
|
||||
}
|
||||
if loadExportAutoState(h.beadsDir).LastDiffAnchor == "" {
|
||||
t.Error("the export re-anchored to nothing; the next cycle would take the same anchorless path forever")
|
||||
}
|
||||
}
|
||||
|
||||
// TestMaybeAutoExport_ProvenDeletionReachesTheIncrementalPatch is plumbing
|
||||
// consequence #1, and the one that fails SILENTLY if missed: the guard can
|
||||
// clear the export while the incremental patch still carries the deleted
|
||||
// record forward, because a row absent at BOTH diff endpoints produces no
|
||||
// diff row at all.
|
||||
//
|
||||
// The setup makes that shape exactly: sx-x is created and deleted entirely
|
||||
// AFTER the anchor, so dolt_diff(anchor, WORKING) never mentions it, while
|
||||
// sx-y is modified so the run genuinely stays on the incremental path.
|
||||
func TestMaybeAutoExport_ProvenDeletionReachesTheIncrementalPatch(t *testing.T) {
|
||||
h, ctx := setupIncrementalExportTest(t)
|
||||
initConfigForTest(t)
|
||||
config.Set("export.auto", true)
|
||||
config.Set("export.interval", "1ns")
|
||||
|
||||
spy := &spyDiffStore{DoltStorage: h.store}
|
||||
store = spy
|
||||
|
||||
h.mustCreate(t, ctx, "sx-y", "Yankee")
|
||||
h.mustCommit(t, ctx, "baseline")
|
||||
if err := maybeAutoExport(ctx, false); err != nil {
|
||||
t.Fatalf("first maybeAutoExport: %v", err)
|
||||
}
|
||||
exportPath := filepath.Join(h.beadsDir, "issues.jsonl")
|
||||
anchor := loadExportAutoState(h.beadsDir).LastDiffAnchor
|
||||
if anchor == "" {
|
||||
t.Fatal("setup: no diff anchor recorded, the incremental path can't be under test")
|
||||
}
|
||||
|
||||
// sx-x exists only between two commits that both come after the anchor,
|
||||
// and its JSONL line is written by an export that ran while it was live.
|
||||
h.mustCreate(t, ctx, "sx-x", "X-ray")
|
||||
h.mustCommit(t, ctx, "add sx-x")
|
||||
if err := maybeAutoExport(ctx, false); err != nil {
|
||||
t.Fatalf("second maybeAutoExport: %v", err)
|
||||
}
|
||||
if _, ok := loadIssueTitles(t, exportPath)["sx-x"]; !ok {
|
||||
t.Fatalf("setup: sx-x must be in the export before it is deleted")
|
||||
}
|
||||
// Pin the anchor back to before sx-x ever existed. Now the diff's two
|
||||
// endpoints both lack it, exactly like a create+delete inside one
|
||||
// throttle window.
|
||||
state := loadExportAutoState(h.beadsDir)
|
||||
state.LastDiffAnchor = anchor
|
||||
state.Timestamp = time.Time{}
|
||||
saveExportAutoState(h.beadsDir, state)
|
||||
|
||||
if err := h.store.DeleteIssue(ctx, "sx-x"); err != nil {
|
||||
t.Fatalf("DeleteIssue: %v", err)
|
||||
}
|
||||
h.mustCommit(t, ctx, "delete sx-x")
|
||||
if err := h.store.UpdateIssue(ctx, "sx-y", map[string]interface{}{"title": "Yankee renamed"}, "tester"); err != nil {
|
||||
t.Fatalf("UpdateIssue: %v", err)
|
||||
}
|
||||
|
||||
if err := maybeAutoExport(ctx, false); err != nil {
|
||||
t.Fatalf("third maybeAutoExport: %v", err)
|
||||
}
|
||||
|
||||
// LastDirtyIDs reaches state only from a successful incremental patch —
|
||||
// the full-export fallback nils it — and sx-y is the only upserted id, so
|
||||
// exactly {sx-y} is what says "this run was incremental AND it ran".
|
||||
if got, want := loadExportAutoState(h.beadsDir).LastDirtyIDs, []string{"sx-y"}; !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("LastDirtyIDs = %v, want %v — the run was skipped or fell back to a full export, and this test only means something on the incremental path", got, want)
|
||||
}
|
||||
titles := loadIssueTitles(t, exportPath)
|
||||
if _, stillThere := titles["sx-x"]; stillThere {
|
||||
t.Error("sx-x survived the incremental patch: a deletion proven outside dolt_diff never reached the file as a forced removal")
|
||||
}
|
||||
if titles["sx-y"] != "Yankee renamed" {
|
||||
t.Errorf("sx-y title = %q, want %q", titles["sx-y"], "Yankee renamed")
|
||||
}
|
||||
|
||||
// Content-equivalence control: an incrementally-patched file must describe
|
||||
// the same issue set, field for field, as a fresh full export of the same
|
||||
// state — including in what it OMITS.
|
||||
controlPath := filepath.Join(t.TempDir(), "control.jsonl")
|
||||
if _, _, err := exportToFile(ctx, controlPath, false); err != nil {
|
||||
t.Fatalf("control exportToFile: %v", err)
|
||||
}
|
||||
got := jsonlRecordsByID(t, exportPath)
|
||||
want := jsonlRecordsByID(t, controlPath)
|
||||
if len(got) != len(want) {
|
||||
t.Fatalf("incremental export has %d records, control full export has %d", len(got), len(want))
|
||||
}
|
||||
for id, wantRec := range want {
|
||||
gotRec, ok := got[id]
|
||||
if !ok {
|
||||
t.Errorf("record %s present in control export, missing from incremental export", id)
|
||||
continue
|
||||
}
|
||||
if !reflect.DeepEqual(gotRec, wantRec) {
|
||||
t.Errorf("record %s differs between incremental and full export:\n incremental: %v\n full: %v", id, gotRec, wantRec)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestMaybeAutoExport_HistoryProofDoesNotSurviveARewind is the safety sibling
|
||||
// of TestMaybeAutoExport_HistoryRewindDoesNotProveDeletion, aimed at the new
|
||||
// proof source rather than the anchor one. After a hard reset past an id's
|
||||
// creation, dolt_history_issues no longer reaches those commits, so the
|
||||
// history proof must come up empty and the guard must keep refusing — with
|
||||
// the line still in the file.
|
||||
func TestMaybeAutoExport_HistoryProofDoesNotSurviveARewind(t *testing.T) {
|
||||
h, ctx := setupIncrementalExportTest(t)
|
||||
initConfigForTest(t)
|
||||
config.Set("export.auto", true)
|
||||
config.Set("export.interval", "1ns")
|
||||
|
||||
h.mustCreate(t, ctx, "sr-a", "Alpha")
|
||||
c1 := h.mustCommit(t, ctx, "baseline")
|
||||
if err := maybeAutoExport(ctx, false); err != nil {
|
||||
t.Fatalf("first maybeAutoExport: %v", err)
|
||||
}
|
||||
exportPath := filepath.Join(h.beadsDir, "issues.jsonl")
|
||||
|
||||
h.mustCreate(t, ctx, "sr-x", "Rewound")
|
||||
h.mustCommit(t, ctx, "add sr-x")
|
||||
if err := maybeAutoExport(ctx, false); err != nil {
|
||||
t.Fatalf("second maybeAutoExport: %v", err)
|
||||
}
|
||||
if titles := loadIssueTitles(t, exportPath); titles["sr-x"] != "Rewound" {
|
||||
t.Fatalf("setup: sr-x must be exported before the rewind, got %v", titles)
|
||||
}
|
||||
|
||||
raw, ok := storage.UnwrapStore(h.store).(storage.RawDBAccessor)
|
||||
if !ok {
|
||||
t.Skip("store does not expose raw DB access")
|
||||
}
|
||||
if _, err := raw.DB().ExecContext(ctx, "CALL DOLT_RESET('--hard', ?)", c1); err != nil {
|
||||
t.Fatalf("CALL DOLT_RESET('--hard', %s): %v", c1, err)
|
||||
}
|
||||
// Blank the anchor so the anchor-diff proof cannot even be consulted:
|
||||
// whatever happens next is the history proof's answer alone.
|
||||
state := loadExportAutoState(h.beadsDir)
|
||||
state.LastDiffAnchor = ""
|
||||
state.Timestamp = time.Time{}
|
||||
saveExportAutoState(h.beadsDir, state)
|
||||
|
||||
stderr := captureStderr(t, func() {
|
||||
if err := maybeAutoExport(ctx, false); err != nil {
|
||||
t.Fatalf("third maybeAutoExport: %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
if !strings.Contains(stderr, "refusing to overwrite") {
|
||||
t.Errorf("stderr = %q, want the unchanged refusal: a rewound-away id is data this store LOST, not a deletion it recorded", stderr)
|
||||
}
|
||||
if _, stillThere := loadIssueTitles(t, exportPath)["sr-x"]; !stillThere {
|
||||
t.Error("sr-x was silently dropped from issues.jsonl after a history rewind: the history proof accepted a rewound-away row as a proven deletion")
|
||||
}
|
||||
}
|
||||
|
|
@ -27,7 +27,13 @@ This uses the Tim Sehn recipe:
|
|||
4. Swap main branch to the new flattened branch
|
||||
5. Prune remote-tracking refs (they would keep the old history alive;
|
||||
the next push or fetch re-creates them at the new tip)
|
||||
6. Run Dolt GC to reclaim space from old history
|
||||
6. Run a full Dolt GC (all storage generations) to reclaim the old history
|
||||
|
||||
The GC pass is a full collection: Dolt storage is generational, and a default
|
||||
GC never revisits data an earlier GC moved to the old generation. On any store
|
||||
that has been GC'd before (bd gc, or a previous flatten or compact), only a
|
||||
full collection reclaims the squashed history. A full GC can take minutes on
|
||||
multi-gigabyte stores.
|
||||
|
||||
This is irreversible — all commit history is lost. The resulting database
|
||||
has exactly one commit containing all current data.
|
||||
|
|
@ -143,11 +149,7 @@ Examples:
|
|||
printPruneReport(pruned, tags)
|
||||
}
|
||||
|
||||
if gc, ok := storage.UnwrapStore(store).(storage.GarbageCollector); ok {
|
||||
if err := gc.DoltGC(ctx); err != nil {
|
||||
WarnError("dolt gc after flatten failed: %v", err)
|
||||
}
|
||||
}
|
||||
gcMode := runPostRewriteGC(ctx, "flatten")
|
||||
sizeAfter := storeSizeBytes(ctx)
|
||||
|
||||
elapsed := time.Since(start)
|
||||
|
|
@ -161,6 +163,9 @@ Examples:
|
|||
"tags_anchoring": tags,
|
||||
"elapsed_ms": elapsed.Milliseconds(),
|
||||
}
|
||||
if gcMode != "" {
|
||||
result["gc_mode"] = gcMode
|
||||
}
|
||||
addGCSizeJSON(result, sizeBefore, sizeAfter)
|
||||
return outputJSON(result)
|
||||
}
|
||||
|
|
|
|||
25
cmd/bd/gc.go
25
cmd/bd/gc.go
|
|
@ -16,6 +16,7 @@ var (
|
|||
gcOlderThan int
|
||||
gcSkipDecay bool
|
||||
gcSkipDolt bool
|
||||
gcFull bool
|
||||
)
|
||||
|
||||
var gcCmd = &cobra.Command{
|
||||
|
|
@ -32,12 +33,19 @@ Runs three phases in sequence:
|
|||
Each phase can be skipped individually. Use --dry-run to preview all phases
|
||||
without making changes.
|
||||
|
||||
Phase 3 runs Dolt's default, generational GC: it only examines data written
|
||||
since the last GC. Data that survived an earlier GC lives in the old generation
|
||||
and is never revisited, so on a long-lived store the space freed by decay may
|
||||
not be reclaimed. Use --full to collect all generations (slower on large
|
||||
stores).
|
||||
|
||||
Examples:
|
||||
bd gc # Full GC with defaults (90 day decay)
|
||||
bd gc --dry-run # Preview what would happen
|
||||
bd gc --older-than 30 # Decay issues closed 30+ days ago
|
||||
bd gc --skip-decay # Skip issue deletion, just compact+GC
|
||||
bd gc --skip-dolt # Skip Dolt GC, just decay+compact
|
||||
bd gc --full # Collect all storage generations
|
||||
bd gc --force # Skip confirmation prompt`,
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
|
|
@ -190,7 +198,11 @@ Examples:
|
|||
results = append(results, phaseResult{name: "Dolt GC", detail: "not supported"})
|
||||
} else if gcDryRun {
|
||||
if !jsonOutput {
|
||||
fmt.Println(" Would run DOLT_GC()")
|
||||
if gcFull {
|
||||
fmt.Println(" Would run a full DOLT_GC() (all storage generations)")
|
||||
} else {
|
||||
fmt.Println(" Would run DOLT_GC()")
|
||||
}
|
||||
}
|
||||
results = append(results, phaseResult{name: "Dolt GC", detail: "dry-run"})
|
||||
} else {
|
||||
|
|
@ -200,7 +212,11 @@ Examples:
|
|||
// (bd-agctw). Sizes are reported so a no-op reclaim is visible.
|
||||
sizeBefore := storeSizeBytes(ctx)
|
||||
remoteRefs, tags := listRemoteRefsAndTags(ctx)
|
||||
if err := gc.DoltGC(ctx); err != nil {
|
||||
if gcFull && !jsonOutput {
|
||||
fmt.Println(" Running full Dolt GC (all generations; can take minutes on large stores)...")
|
||||
}
|
||||
gcMode, err := runDoltGCPass(ctx, gc, gcFull)
|
||||
if err != nil {
|
||||
WarnError("dolt gc failed: %v", err)
|
||||
results = append(results, phaseResult{name: "Dolt GC", detail: "failed"})
|
||||
} else {
|
||||
|
|
@ -211,6 +227,9 @@ Examples:
|
|||
}
|
||||
if !jsonOutput {
|
||||
fmt.Printf(" Done (%s)\n", detail)
|
||||
if gcMode != gcModeFull && suggestFullGC(sizeBefore, sizeAfter) {
|
||||
printFullGCHint()
|
||||
}
|
||||
if len(remoteRefs)+len(tags) > 0 {
|
||||
fmt.Printf(" Note: %d remote-tracking ref(s) and %d tag(s) anchor history;\n", len(remoteRefs), len(tags))
|
||||
fmt.Printf(" after a history squash, use bd flatten / bd compact so they are pruned first.\n")
|
||||
|
|
@ -220,6 +239,7 @@ Examples:
|
|||
gcSizeInfo = map[string]interface{}{
|
||||
"remote_refs": len(remoteRefs),
|
||||
"tags": len(tags),
|
||||
"mode": gcMode,
|
||||
}
|
||||
addGCSizeJSON(gcSizeInfo, sizeBefore, sizeAfter)
|
||||
}
|
||||
|
|
@ -275,6 +295,7 @@ func init() {
|
|||
gcCmd.Flags().IntVar(&gcOlderThan, "older-than", 90, "Delete closed issues older than N days")
|
||||
gcCmd.Flags().BoolVar(&gcSkipDecay, "skip-decay", false, "Skip issue deletion phase")
|
||||
gcCmd.Flags().BoolVar(&gcSkipDolt, "skip-dolt", false, "Skip Dolt garbage collection phase")
|
||||
gcCmd.Flags().BoolVar(&gcFull, "full", false, "Run a full Dolt GC (all generations; slower, reclaims space default passes cannot)")
|
||||
|
||||
rootCmd.AddCommand(gcCmd)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,6 +126,34 @@ func TestEmbeddedGC(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
// ===== Full GC =====
|
||||
|
||||
t.Run("gc_full", func(t *testing.T) {
|
||||
gcDir, _, _ := bdInit(t, bd, "--prefix", "gu")
|
||||
for i := 0; i < 3; i++ {
|
||||
bdCreate(t, bd, gcDir, fmt.Sprintf("Full GC issue %d", i), "--type", "task")
|
||||
}
|
||||
|
||||
// A default pass first, so the second one has an old generation to
|
||||
// collect — the case a generational pass cannot reclaim (#5907).
|
||||
bdGC(t, bd, gcDir, "--force", "--skip-decay")
|
||||
|
||||
out := bdGC(t, bd, gcDir, "--full", "--force", "--skip-decay")
|
||||
if !strings.Contains(out, "GC complete") {
|
||||
t.Errorf("expected 'GC complete' from bd gc --full: %s", out)
|
||||
}
|
||||
if !strings.Contains(out, "full Dolt GC") {
|
||||
t.Errorf("expected the full-GC notice: %s", out)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("gc_full_dry_run", func(t *testing.T) {
|
||||
out := bdGC(t, bd, dir, "--full", "--dry-run")
|
||||
if !strings.Contains(out, "full DOLT_GC()") {
|
||||
t.Errorf("dry run does not say it would run a full GC: %s", out)
|
||||
}
|
||||
})
|
||||
|
||||
// ===== No --force prompts =====
|
||||
|
||||
t.Run("gc_no_force_prompts", func(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -155,12 +155,23 @@ func runGCProxiedServer(ctx context.Context) error {
|
|||
}
|
||||
if gcDryRun {
|
||||
if !jsonOutput {
|
||||
fmt.Println(" Would run DOLT_GC() and DOLT_STATS_GC()")
|
||||
if gcFull {
|
||||
fmt.Println(" Would run a full DOLT_GC() (all storage generations) and DOLT_STATS_GC()")
|
||||
} else {
|
||||
fmt.Println(" Would run DOLT_GC() and DOLT_STATS_GC()")
|
||||
}
|
||||
}
|
||||
results = append(results, phaseResult{name: "Dolt GC", detail: "dry-run"})
|
||||
} else {
|
||||
if gcFull && !jsonOutput {
|
||||
fmt.Println(" Running full Dolt GC (all generations; can take minutes on large stores)...")
|
||||
}
|
||||
err := runProxiedNonTx(ctx, func(ctx context.Context, conn *sql.Conn) error {
|
||||
if err := versioncontrolops.DoltGC(ctx, conn); err != nil {
|
||||
doltGC := versioncontrolops.DoltGC
|
||||
if gcFull {
|
||||
doltGC = versioncontrolops.DoltGCFull
|
||||
}
|
||||
if err := doltGC(ctx, conn); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := conn.ExecContext(ctx, "CALL DOLT_STATS_GC()"); err != nil {
|
||||
|
|
|
|||
|
|
@ -74,6 +74,78 @@ func printPruneReport(pruned, tags []string) {
|
|||
}
|
||||
}
|
||||
|
||||
// Dolt GC pass kinds, reported as the "mode"/"gc_mode" JSON field.
|
||||
const (
|
||||
gcModeGenerational = "generational"
|
||||
gcModeFull = "full"
|
||||
)
|
||||
|
||||
// runDoltGCPass runs the requested Dolt GC pass and reports which pass actually
|
||||
// ran. Dolt GC is generational: a default pass only visits data written since
|
||||
// the last GC, while a full pass also collects the old generation. A store that
|
||||
// does not implement FullGarbageCollector degrades to a generational pass with
|
||||
// a warning.
|
||||
func runDoltGCPass(ctx context.Context, gc storage.GarbageCollector, full bool) (string, error) {
|
||||
if full {
|
||||
if fullGC, ok := gc.(storage.FullGarbageCollector); ok {
|
||||
return gcModeFull, fullGC.DoltGCFull(ctx)
|
||||
}
|
||||
WarnError("storage backend does not support a full GC; running a generational pass, " +
|
||||
"which cannot reclaim data an earlier GC moved to the old generation")
|
||||
}
|
||||
return gcModeGenerational, gc.DoltGC(ctx)
|
||||
}
|
||||
|
||||
// runPostRewriteGC runs the GC that follows a history rewrite and reports which
|
||||
// pass ran ("" when the backend has no GC at all). It is always a full pass:
|
||||
// the rewrite orphans a commit chain that any earlier GC already promoted to
|
||||
// the old generation, and a generational pass never revisits it. Failures are
|
||||
// warnings — the rewrite itself already succeeded.
|
||||
func runPostRewriteGC(ctx context.Context, op string) string {
|
||||
gc, ok := storage.UnwrapStore(store).(storage.GarbageCollector)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
if !jsonOutput {
|
||||
fmt.Println(" Running full Dolt GC (all generations; can take minutes on large stores)...")
|
||||
}
|
||||
mode, err := runDoltGCPass(ctx, gc, true)
|
||||
if err != nil {
|
||||
WarnError("dolt gc after %s failed: %v", op, err)
|
||||
}
|
||||
return mode
|
||||
}
|
||||
|
||||
const (
|
||||
// fullGCHintMinStoreBytes keeps the hint off small stores, where a few
|
||||
// reclaimed kilobytes are not worth a multi-minute full pass.
|
||||
fullGCHintMinStoreBytes = 64 << 20
|
||||
// fullGCHintMaxFreedFraction is what counts as "reclaimed ~nothing".
|
||||
fullGCHintMaxFreedFraction = 0.01
|
||||
)
|
||||
|
||||
// suggestFullGC reports whether a completed generational GC pass freed so
|
||||
// little of a non-trivial store that the caller should suggest --full.
|
||||
// before/after are ActiveDatabaseSize measurements; negative means unmeasurable
|
||||
// and disables the hint.
|
||||
func suggestFullGC(before, after int64) bool {
|
||||
if before < 0 || after < 0 || before < fullGCHintMinStoreBytes {
|
||||
return false
|
||||
}
|
||||
freed := before - after
|
||||
if freed < 0 {
|
||||
freed = 0
|
||||
}
|
||||
return float64(freed) < fullGCHintMaxFreedFraction*float64(before)
|
||||
}
|
||||
|
||||
// printFullGCHint explains why a default pass can reclaim nothing (text mode).
|
||||
func printFullGCHint() {
|
||||
fmt.Println(" Tip: little space was reclaimed. A default Dolt GC never revisits data an")
|
||||
fmt.Println(" earlier GC moved to the old generation — run 'bd gc --full' to collect all")
|
||||
fmt.Println(" generations.")
|
||||
}
|
||||
|
||||
// gcSizeLine formats a before/after size pair as "X → Y (freed Z)", or ""
|
||||
// when either measurement failed.
|
||||
func gcSizeLine(before, after int64) string {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
|
|
@ -95,3 +96,73 @@ func TestAddGCSizeJSONOmitsUnavailableMeasurements(t *testing.T) {
|
|||
t.Fatalf("freed_bytes was emitted without both measurements: %#v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSuggestFullGC(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const mib = 1 << 20
|
||||
tests := []struct {
|
||||
name string
|
||||
before, after int64
|
||||
want bool
|
||||
}{
|
||||
{name: "unmeasurable before", before: -1, after: 100 * mib},
|
||||
{name: "unmeasurable after", before: 100 * mib, after: -1},
|
||||
{name: "both unmeasurable", before: -1, after: -1},
|
||||
{name: "small store freeing nothing is not worth a full pass", before: 8 * mib, after: 8 * mib},
|
||||
{name: "just below the store floor", before: 64*mib - 1, after: 64*mib - 1},
|
||||
{name: "at the store floor, freed nothing", before: 64 * mib, after: 64 * mib, want: true},
|
||||
{name: "large store freed nothing", before: 4096 * mib, after: 4096 * mib, want: true},
|
||||
{name: "freed 0.9% of the store", before: 1000 * mib, after: 991 * mib, want: true},
|
||||
{name: "freed exactly 1% is not ~nothing", before: 1000 * mib, after: 990 * mib},
|
||||
{name: "field report: 1276 MB -> 971 MB freed 24%", before: 1276 * mib, after: 971 * mib},
|
||||
{name: "store grew during the pass", before: 1000 * mib, after: 1001 * mib, want: true},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
if got := suggestFullGC(tc.before, tc.after); got != tc.want {
|
||||
t.Fatalf("suggestFullGC(%d, %d) = %v, want %v", tc.before, tc.after, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestGCHelpDocumentsFullPass pins the help text explaining why a default Dolt
|
||||
// GC can reclaim nothing. These Long strings are the source the CLI reference
|
||||
// pages are generated from, so this wording is maintained only here.
|
||||
func TestGCHelpDocumentsFullPass(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
full := gcCmd.Flags().Lookup("full")
|
||||
if full == nil {
|
||||
t.Fatal("bd gc has no --full flag")
|
||||
}
|
||||
if !strings.Contains(full.Usage, "all generations") {
|
||||
t.Errorf("--full usage does not mention all generations: %q", full.Usage)
|
||||
}
|
||||
|
||||
for _, want := range []string{"--full", "old generation", "generational"} {
|
||||
if !strings.Contains(gcCmd.Long, want) {
|
||||
t.Errorf("gcCmd.Long does not mention %q", want)
|
||||
}
|
||||
}
|
||||
|
||||
rewrites := []struct {
|
||||
name string
|
||||
long string
|
||||
}{
|
||||
{"flatten", flattenCmd.Long},
|
||||
{"compact", compactDoltCmd.Long},
|
||||
}
|
||||
for _, cmd := range rewrites {
|
||||
if !strings.Contains(cmd.long, "full Dolt GC") {
|
||||
t.Errorf("%s help does not say it runs a full Dolt GC", cmd.name)
|
||||
}
|
||||
if !strings.Contains(cmd.long, "old generation") {
|
||||
t.Errorf("%s help does not explain the old generation", cmd.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
28
cmd/bd/history_capability.go
Normal file
28
cmd/bd/history_capability.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
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
|
||||
}
|
||||
138
cmd/bd/history_capability_test.go
Normal file
138
cmd/bd/history_capability_test.go
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
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"} {
|
||||
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)
|
||||
}
|
||||
for _, path := range []string{"dolt remote add", "dolt remote list", "dolt remote reset-data"} {
|
||||
if got, ok := LookupHistoryCapability(path); !ok || got != HistoryDirectOnly {
|
||||
t.Errorf("%q = %q, %v; want direct-only", path, got, ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyncRefusesBeforeProvider(t *testing.T) {
|
||||
root := &cobra.Command{Use: "bd"}
|
||||
cmd := &cobra.Command{Use: "sync"}
|
||||
root.AddCommand(cmd)
|
||||
err := validateProxyMaintenanceBeforeProvider(cmd)
|
||||
if err == nil {
|
||||
t.Fatalf("sync refusal = %#v", err)
|
||||
}
|
||||
if code, ok := exitCodeFromError(err); !ok || code != 1 {
|
||||
t.Fatalf("sync exit = %#v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHistoryDirectOnlyRefusalContract(t *testing.T) {
|
||||
expected := map[string]struct{ code, message string }{
|
||||
"branch": {"proxy.branch.unsupported", "branch is not supported in proxied-server mode"},
|
||||
"conflicts": {"proxy.conflicts.unsupported", "conflicts is not supported in proxied-server mode"},
|
||||
"repo": {"proxy.repo.unsupported", "repo is not supported in proxied-server mode"},
|
||||
"federation": {"proxy.federation.unsupported", "federation is not supported in proxied-server mode"},
|
||||
"vc": {"proxy.vc.unsupported", "vc is not supported in proxied-server mode"},
|
||||
"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"},
|
||||
"sync": {"proxy.sync.unsupported", "sync is not supported in proxied-server mode"},
|
||||
}
|
||||
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"} {
|
||||
parts := strings.Split(path, " ")
|
||||
root := &cobra.Command{Use: "bd"}
|
||||
cmd := &cobra.Command{Use: parts[0]}
|
||||
root.AddCommand(cmd)
|
||||
for _, part := range parts[1:] {
|
||||
child := &cobra.Command{Use: part}
|
||||
cmd.AddCommand(child)
|
||||
cmd = child
|
||||
}
|
||||
uowProvider = nil
|
||||
jsonOutput = true
|
||||
out := captureStdout(t, func() error { _ = validateProxyMaintenanceBeforeProvider(cmd); 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 {
|
||||
t.Fatalf("%s refusal = %q (%v)", path, out, err)
|
||||
}
|
||||
if uowProvider != nil {
|
||||
t.Fatal("refusal initialized provider")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHistoryNestedFrontDoorsRefuseAndSupportedPathsPass(t *testing.T) {
|
||||
oldJSON := jsonOutput
|
||||
jsonOutput = true
|
||||
t.Cleanup(func() { jsonOutput = oldJSON })
|
||||
expected := map[string]struct{ code, message string }{
|
||||
"vc merge": {"proxy.vc.unsupported", "vc merge is not supported in proxied-server mode"},
|
||||
"vc commit": {"proxy.vc.unsupported", "vc commit is not supported in proxied-server mode"},
|
||||
"repo add": {"proxy.repo.unsupported", "repo add is not supported in proxied-server mode"},
|
||||
"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"} {
|
||||
parts := strings.Split(path, " ")
|
||||
root := &cobra.Command{Use: "bd"}
|
||||
cmd := &cobra.Command{Use: parts[0]}
|
||||
root.AddCommand(cmd)
|
||||
for _, part := range parts[1:] {
|
||||
child := &cobra.Command{Use: part}
|
||||
cmd.AddCommand(child)
|
||||
cmd = child
|
||||
}
|
||||
err := validateProxyMaintenanceBeforeProvider(cmd)
|
||||
if path == "dolt remote remove" {
|
||||
if err != nil {
|
||||
t.Fatalf("supported %s refused: %v", path, err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err == nil {
|
||||
t.Fatalf("direct-only %s unexpectedly allowed", path)
|
||||
}
|
||||
if code, ok := exitCodeFromError(err); !ok || code != 1 {
|
||||
t.Fatalf("%s exit=%v, want 1", path, err)
|
||||
}
|
||||
var got map[string]any
|
||||
// validateProxyMaintenanceBeforeProvider 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 })
|
||||
if err := json.Unmarshal([]byte(out), &got); err != nil {
|
||||
t.Fatalf("%s refusal JSON: %v (%q)", path, err, out)
|
||||
}
|
||||
want := expected[path]
|
||||
if got["code"] != want.code || got["error"] != want.message || got["mutates"] != false {
|
||||
t.Fatalf("%s refusal = %#v, want code=%q message=%q mutates=false", path, got, want.code, want.message)
|
||||
}
|
||||
}
|
||||
root := &cobra.Command{Use: "bd"}
|
||||
history := &cobra.Command{Use: "history"}
|
||||
root.AddCommand(history)
|
||||
if err := validateProxyMaintenanceBeforeProvider(history); err != nil {
|
||||
t.Fatalf("history --events supported path refused: %v", err)
|
||||
}
|
||||
}
|
||||
167
cmd/bd/history_remote_frontdoor_matrix_test.go
Normal file
167
cmd/bd/history_remote_frontdoor_matrix_test.go
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
//go:build cgo && unix
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage/dbproxy/proxy"
|
||||
"github.com/steveyegge/beads/internal/testutil"
|
||||
)
|
||||
|
||||
// TestHistoryRemoteRefusalFrontDoorMatrix runs the real bd binary through all
|
||||
// supported proxied transports. Valid command arguments are intentional: a
|
||||
// typed capability refusal must win over Cobra usage validation and must not
|
||||
// start a provider or touch durable state.
|
||||
func TestHistoryRemoteRefusalFrontDoorMatrix(t *testing.T) {
|
||||
bd := buildEmbeddedBD(t)
|
||||
type fixture struct {
|
||||
name string
|
||||
make func(*testing.T) proxiedProject
|
||||
}
|
||||
fixtures := []fixture{{
|
||||
name: "managed-local",
|
||||
make: func(t *testing.T) proxiedProject {
|
||||
requireManagedLocalProxiedEnv(t)
|
||||
return bdManagedLocalInit(t, bd, "hm_managed", 5*time.Minute)
|
||||
},
|
||||
}}
|
||||
if os.Getenv("BEADS_TEST_PROXIED_SERVER") == "1" {
|
||||
fixtures = append(fixtures,
|
||||
fixture{name: "external-tcp", make: func(t *testing.T) proxiedProject {
|
||||
return newSharedProxiedProject(t, bd, "hm_tcp")
|
||||
}},
|
||||
fixture{name: "external-unix", make: func(t *testing.T) proxiedProject {
|
||||
requireProxiedServerEnv(t)
|
||||
upstream := testutil.StartIsolatedDoltContainerHandle(t)
|
||||
socket := filepath.Join(t.TempDir(), "dolt.sock")
|
||||
bridge := startOutageBridge(t, socket, upstream.Port, true)
|
||||
t.Cleanup(func() { _ = bridge.Process.Kill() })
|
||||
return bdProxiedInit(t, bd, "hm_unix", "--proxied-server-external-socket-path", socket)
|
||||
}},
|
||||
)
|
||||
}
|
||||
commands := []struct {
|
||||
name, code, message string
|
||||
args []string
|
||||
}{
|
||||
{"branch", "proxy.branch.unsupported", "branch is not supported in proxied-server mode", []string{"branch", "feature"}},
|
||||
{"conflicts list", "proxy.conflicts.unsupported", "conflicts list is not supported in proxied-server mode", []string{"conflicts", "list"}},
|
||||
{"repo add", "proxy.repo.unsupported", "repo add is not supported in proxied-server mode", []string{"repo", "add", "."}},
|
||||
{"federation sync", "proxy.federation.unsupported", "federation sync is not supported in proxied-server mode", []string{"federation", "sync"}},
|
||||
{"vc merge", "proxy.vc.unsupported", "vc merge is not supported in proxied-server mode", []string{"vc", "merge", "feature"}},
|
||||
{"vc commit", "proxy.vc.unsupported", "vc commit is not supported in proxied-server mode", []string{"vc", "commit"}},
|
||||
{"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"}},
|
||||
{"sync", "proxy.sync.unsupported", "sync is not supported in proxied-server mode", []string{"sync"}},
|
||||
}
|
||||
for _, f := range fixtures {
|
||||
t.Run(f.name, func(t *testing.T) {
|
||||
p := f.make(t)
|
||||
bdProxiedCreate(t, bd, p.dir, "matrix sentinel")
|
||||
_ = proxy.Shutdown(p.proxyRoot)
|
||||
before := snapshotHistoryArtifacts(t, p)
|
||||
for _, tc := range commands {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
// Put the global flag before the subcommand. A few nested
|
||||
// front doors do not inherit persistent flags after their args.
|
||||
args := append([]string{"--json"}, tc.args...)
|
||||
stdout, stderr, err := bdProxiedRunBuffersWithEnv(t, bd, p.dir, []string{"BEADS_JSON=1"}, args...)
|
||||
if err == nil {
|
||||
t.Fatalf("%v unexpectedly succeeded", tc.args)
|
||||
}
|
||||
var got struct {
|
||||
Code string `json:"code"`
|
||||
Error string `json:"error"`
|
||||
Mutates bool `json:"mutates"`
|
||||
}
|
||||
if jsonErr := json.Unmarshal([]byte(strings.TrimSpace(stdout)), &got); jsonErr == nil {
|
||||
if got.Code != tc.code || got.Error != tc.message || got.Mutates {
|
||||
t.Fatalf("refusal=%+v, want code=%q error=%q mutates=false", got, tc.code, tc.message)
|
||||
}
|
||||
} else if strings.TrimSpace(stderr) != "Error: "+tc.message {
|
||||
// Some nested commands render the same typed refusal through
|
||||
// the text path before config-backed JSON is applied.
|
||||
t.Fatalf("refusal JSON=%v stdout=%q stderr=%q", jsonErr, stdout, stderr)
|
||||
}
|
||||
if _, statErr := os.Stat(filepath.Join(p.proxyRoot, proxy.PIDFileName)); statErr == nil {
|
||||
t.Fatal("provider proxy started for direct-only refusal")
|
||||
}
|
||||
after := snapshotHistoryArtifacts(t, p)
|
||||
if string(before) != string(after) {
|
||||
t.Fatal("durable artifacts changed during refusal")
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func snapshotHistoryArtifacts(t *testing.T, p proxiedProject) []byte {
|
||||
t.Helper()
|
||||
var out []byte
|
||||
for _, path := range []string{
|
||||
filepath.Join(p.beadsDir, "config.yaml"), filepath.Join(p.beadsDir, "metadata.json"),
|
||||
filepath.Join(p.beadsDir, "events.jsonl"), filepath.Join(p.beadsDir, ".local_version"),
|
||||
filepath.Join(p.proxyRoot, proxy.LockFileName), filepath.Join(p.proxyRoot, proxy.PIDFileName),
|
||||
} {
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
t.Fatalf("snapshot %s: %v", path, err)
|
||||
}
|
||||
out = append(out, []byte(strconv.Itoa(len(path))+":"+path+":"+string(b)+"\n")...)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// TestHistoryRemoteSupportedFrontDoorParity checks the two operations that
|
||||
// are intentionally shared by direct and proxied providers.
|
||||
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")
|
||||
}
|
||||
bd := buildEmbeddedBD(t)
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
make func(*testing.T) proxiedProject
|
||||
}{
|
||||
{"managed-local", func(t *testing.T) proxiedProject {
|
||||
requireManagedLocalProxiedEnv(t)
|
||||
return bdManagedLocalInit(t, bd, "hs_managed", 5*time.Minute)
|
||||
}},
|
||||
{"external-tcp", func(t *testing.T) proxiedProject {
|
||||
requireProxiedServerEnv(t)
|
||||
return newSharedProxiedProject(t, bd, "hs_tcp")
|
||||
}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
p := tc.make(t)
|
||||
issue := bdProxiedCreate(t, bd, p.dir, "history parity")
|
||||
bdProxiedUpdate(t, bd, p.dir, issue.ID, "--title", "history parity updated")
|
||||
out, err := bdProxiedRun(t, bd, p.dir, "--json", "history", issue.ID, "--events")
|
||||
if err != nil || !strings.Contains(string(out), issue.ID) {
|
||||
t.Fatalf("history --events failed: %v\n%s", err, out)
|
||||
}
|
||||
db := openProxiedDB(t, p)
|
||||
if _, err := db.ExecContext(context.Background(), "CALL DOLT_REMOTE('add', ?, ?)", "backup", "https://example.invalid/backup"); err != nil {
|
||||
t.Fatalf("seed remote: %v", err)
|
||||
}
|
||||
out, err = bdProxiedRun(t, bd, p.dir, "--json", "dolt", "remote", "remove", "backup")
|
||||
if err != nil || !strings.Contains(string(out), "backup") {
|
||||
t.Fatalf("remote remove failed: %v\n%s", err, out)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -144,7 +144,13 @@ func runImport(cmd *cobra.Command, args []string) error {
|
|||
// CheckReadonly at all (a separate, pre-existing gap — readonlyMode
|
||||
// doesn't gate bd import either), so it can't pick up the freeze check
|
||||
// folded into CheckReadonly the way create/update/close/remember do.
|
||||
CheckMigrationFreeze("import")
|
||||
// The path that makes this call load-bearing rather than redundant is
|
||||
// `bd import --dry-run`: a preview sets useReadOnly, so it skips the early
|
||||
// gate in PersistentPreRunE, and runImport is the only chokepoint left.
|
||||
// Plain `bd import` is already stopped by that early gate.
|
||||
if err := migrationFreezeGateFor(cmd, "import"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
evt := metrics.NewCommandEvent("import")
|
||||
defer func() {
|
||||
|
|
|
|||
|
|
@ -220,6 +220,47 @@ type VersionChange struct {
|
|||
|
||||
// versionChanges contains agent-actionable changes for recent versions
|
||||
var versionChanges = []VersionChange{
|
||||
{
|
||||
Version: "1.3.0",
|
||||
Date: "2026-09-15",
|
||||
Changes: []string{
|
||||
"RELEASE: first tested release off main since the 1.1 line. v1.2.2 shipped the v1.1.2 tree, so a v1.2.2 user gets the 1.2.1 changes AND the 1.3.0 changes in one step; read the [1.3.0] AND [1.2.1] sections of CHANGELOG.md. 'bd upgrade review' prints exactly the entries between your previous version and this one — prefer it to 'bd info --whats-new', which dumps the whole release history.",
|
||||
"MIGRATION: on an embedded/local store the first invocation auto-migrates from schema v53 to v66 in place. That is ~28 migrations, not 13: the main series runs 0054->0066, then the clone-local series runs 0012->0026 through the same printer, so the counter VISIBLY RESTARTS partway through. That is not a loop — let it finish. Two passes rewrite rows, so the first command is noticeably slower; it is crash-resumable, do not interrupt it. Progress prints per step on stderr only when stderr is a terminal — a silent CI upgrade is not a stuck one.",
|
||||
"SHARED SERVER: a shared Dolt sql-server is NEVER auto-migrated (#5920, #6048) — migrating promotes the schema for every connected client at once, so it waits for explicit consent via 'bd migrate schema' (add --global for the shared global database). Upgrade every client of that server FIRST; between upgrade and consent, upgraded clients read normally and their writes are refused with guidance. If the shared server also has a Dolt remote, use 'bd migrate --force' from exactly one machine, then 'bd dolt push'.",
|
||||
"BACKUP: back up BEFORE installing, with your OLD binary. Under 1.3.0 'bd export' triggers the migration before exporting, so a snapshot taken afterwards cannot protect you against the migration going wrong. Old binary: 'bd dolt push' (remote-backed stores) then 'bd export --all -o .beads/backup/pre-1.3.0.jsonl'. For a Dolt-native snapshot use 'bd backup init <path>' then 'bd backup sync' — bare 'bd backup' is a command group that prints help and takes NO backup. Remote-backed stores stay gated after install; one designated clone migrates and pushes.",
|
||||
"UPGRADE: after migrating, older co-resident binaries REFUSE the store (forward schema-skew guard), so every client sharing a store must be upgraded together. Check with 'which -a bd' and restart any long-running 'bd serve'. Rollback is a schema-cursor rollback: https://beads.gascity.com/recovery/accidental-1-2-1-release",
|
||||
"BREAKING (highlights, not the full set — read the [1.2.1] CHANGELOG section too): 'bd update -s <done-status>' enforces close policy (override with --force); 'bd search' includes closed by default (narrow with --status open); the no-ID last-touched fallback on update/close is interactive-only; 'bd human list' hides done/frozen/pinned and validates --status; 'bd dolt push'/'bd sync' no longer adopt a git-origin-derived Dolt remote without consent; an explicitly configured Dolt port outranks BEADS_DOLT_PORT; and actor matching decodes an exact '--' run to '/'.",
|
||||
"BREAKING: 'bd --readonly serve' is now REFUSED instead of binding a writable server, so a scripted read-only server does not come back up after this upgrade — drop the flag. 'bd config list' and GET /v0/beads/config no longer enumerate the kv. plane where 'bd remember' memories live (use 'bd kv'/'bd remember'; scripts get empty output, not an error). The published backend package drops OrphanHandling and issueops.CheckOrphan, so a Go consumer naming them no longer compiles.",
|
||||
"BREAKING: the CPU profiling flag is now --cpu-profile; the old --profile spelling is gone with no alias and fails as an unknown flag.",
|
||||
"CHANGE: migration 0061 rekeys every events/comments/snapshot/compaction-snapshot row to a content-derived (UUIDv5-over-SHA-256) id, once per clone, on the first open after upgrade. Ids captured before the upgrade will not resolve afterwards.",
|
||||
"CHANGE: migration 0062 moves the events audit table to the clone-local plane — events keep full local durability and 'bd history <id> --events' still reads them, but they no longer replicate on push or pull.",
|
||||
"CHANGE: the interactions.jsonl audit sidecar is opt-in (audit.enabled defaults false, or BD_AUDIT_ENABLED=1); use 'bd history <id> --events' instead. Auto-backup now defaults OFF under a Dolt sql-server (embedded is unchanged); set backup.enabled explicitly to override.",
|
||||
"CHANGE: 'bd import' now ERRORS on a redirected stdin with no source argument instead of importing the default JSONL — use 'bd import -' or name the file. 'bd hooks install --chain/--force' are accepted no-ops; marker sections always preserve non-bd hook content.",
|
||||
"FIX: 'bd purge'/'bd prune' select candidates by tier (#5995), so typed wisps minted before the ephemeral column are reachable again — the first purge after upgrade may clear considerably more than usual.",
|
||||
"NEW: a two-level cooperative gate writes *.gate.lock files beside .beads and beside the Dolt physical root (e.g. .beads/embeddeddolt.gate.lock). They are flock names, never deleted; 'bd doctor --fix' adds the *.gate.lock* gitignore pattern.",
|
||||
},
|
||||
},
|
||||
{
|
||||
Version: "1.3.0-rc.2",
|
||||
Date: "2026-09-05",
|
||||
Changes: []string{
|
||||
"RC: candidate for the 1.3.0 line, carrying three server-mode fixes reported against rc.1; the [1.3.0] entry below still describes everything a 1.2.2 user meets, including the migration and backup notes — read it first.",
|
||||
"FIX: an env-pointed Dolt sql-server (BEADS_DOLT_SERVER_PORT) is classified shared, not owned, so the #5920/#6048 shared-store consent gate runs instead of being bypassed. Before this, bd migrated the shared database in place and exited 0, and older co-resident clients were then hard-refused with a schema version mismatch (#6118).",
|
||||
"FIX: a config.yaml server-mode workspace (dolt.mode: server, no metadata.json) is no longer misread as a legacy workspace — the guard resolves mode through the IsDoltServerMode precedence chain, and a .local_version witness naming bd 1.0 or later vetoes the legacy verdict in every mode (#6119).",
|
||||
"FIX: a metadata-less server-mode workspace no longer opens a phantom .beads/embeddeddolt database that answered 'bd list' with a false-empty exit 0; substitution gates on IsDoltServerMode and honors BEADS_DOLT_SERVER_MODE (#6120).",
|
||||
"CHANGE: 'bd ready --claim' under --proxied-server now refuses a --max-rows/BEADS_MAX_ROWS cap instead of silently dropping it; --claim is no longer exempt. Agent rigs that set the cap globally must unset it for proxied 'bd ready --claim'. Direct mode is unchanged.",
|
||||
},
|
||||
},
|
||||
{
|
||||
// Keyed so an rc.1 tester upgrading to rc.2 gets the rc.2 digest
|
||||
// above instead of the whole release history: getVersionsSince
|
||||
// returns every entry when it cannot find the previous version.
|
||||
Version: "1.3.0-rc.1",
|
||||
Date: "2026-08-31",
|
||||
Changes: []string{
|
||||
"RC: first candidate for the 1.3.0 line. Everything a 1.2.2 user meets on the way here — the in-place schema migration, the shared-server consent gate, the backup ordering, and the breaking changes — is described in the [1.3.0] entry below; read it first.",
|
||||
},
|
||||
},
|
||||
{
|
||||
Version: "1.2.2",
|
||||
Date: "2026-08-15",
|
||||
|
|
|
|||
118
cmd/bd/init.go
118
cmd/bd/init.go
|
|
@ -399,6 +399,32 @@ Non-interactive mode (--non-interactive or BD_NON_INTERACTIVE=1):
|
|||
fmt.Fprintf(os.Stderr, " See 'bd help init-safety' for the init flag surface.\n\n")
|
||||
reinitLocal = true
|
||||
}
|
||||
|
||||
// dc-6jaq: "init" is in noDbCommands, so PersistentPreRunE returns at
|
||||
// the skip-store early return before its freeze gate ever runs, and
|
||||
// init.go calls neither CheckReadonly nor the gate itself. That left
|
||||
// the single most destructive command in the CLI free to run during a
|
||||
// migration: `bd init --reinit-local` (or its --force alias) drops and
|
||||
// recreates the very database the marker is protecting, permanently,
|
||||
// and exited 0 without consulting the marker. Gate the destructive
|
||||
// variants here — the earliest point where every one of them is
|
||||
// resolved and nothing has been written yet, and ahead of the
|
||||
// --proxied-server branch below, which reaches its own writes without
|
||||
// passing through the init mutation gate at all.
|
||||
//
|
||||
// A plain first-time init is deliberately not gated: it creates a new
|
||||
// database rather than touching the frozen one, and an existing
|
||||
// workspace already refuses it via checkExistingBeadsData.
|
||||
if reinitLocal || discardRemote {
|
||||
op := "init --reinit-local"
|
||||
if discardRemote {
|
||||
op = "init --discard-remote"
|
||||
}
|
||||
if err := migrationFreezeGateFor(cmd, op, resolveInitBeadsDir()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
sharedServer, _ := cmd.Flags().GetBool("shared-server")
|
||||
externalServer, _ := cmd.Flags().GetBool("external")
|
||||
debugMode, _ := cmd.Flags().GetBool("debug")
|
||||
|
|
@ -639,6 +665,15 @@ Non-interactive mode (--non-interactive or BD_NON_INTERACTIVE=1):
|
|||
fromJSONL: fromJSONL,
|
||||
nonInteractive: nonInteractive,
|
||||
}); err != nil {
|
||||
// runInitProxiedServer runs the same checkExistingBeadsData
|
||||
// the route below does, but it runs it inside itself — so
|
||||
// --init-if-missing used to end here as a plain exit-1
|
||||
// "Aborting.", and its mismatch guards never ran at all. The
|
||||
// check happens before any .beads/ write, so nothing has been
|
||||
// touched by the time we get this error.
|
||||
if initIfMissing && !reinitLocal && errors.Is(err, errWorkspaceAlreadyInitialized) {
|
||||
return resolveInitIfMissingAlreadyInitialized(cmd, database, prefix, quiet)
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
@ -771,26 +806,7 @@ Non-interactive mode (--non-interactive or BD_NON_INTERACTIVE=1):
|
|||
// directory) must still abort rather than be masked as a
|
||||
// successful skip.
|
||||
if initIfMissing && errors.Is(err, errWorkspaceAlreadyInitialized) {
|
||||
// Guard against masking a genuine mismatch: an explicit
|
||||
// --prefix or --database that does not match the existing
|
||||
// workspace must abort, since silently skipping would ignore
|
||||
// the request and reuse a different database. --database is
|
||||
// the authoritative selector, so it is checked even when
|
||||
// --prefix is also set.
|
||||
existing := existingWorkspaceDBName()
|
||||
if cmd.Flags().Changed("database") {
|
||||
if initIfMissingDatabaseMismatch(existing, database) {
|
||||
return fmt.Errorf("workspace already initialized as database %q, but --database %q was requested.\nRemove --database (or pass a matching value) to reuse the existing workspace", existing, database)
|
||||
}
|
||||
} else if cmd.Flags().Changed("prefix") {
|
||||
if initIfMissingPrefixMismatch(existing, prefix) {
|
||||
return fmt.Errorf("workspace already initialized as database %q, but --prefix %q was requested.\nRemove --prefix (or pass a matching value) to reuse the existing workspace", existing, prefix)
|
||||
}
|
||||
}
|
||||
if !quiet {
|
||||
fmt.Fprintln(os.Stderr, "Skipping init: workspace already initialized.")
|
||||
}
|
||||
return nil
|
||||
return resolveInitIfMissingAlreadyInitialized(cmd, database, prefix, quiet)
|
||||
}
|
||||
return fmt.Errorf("%v", err)
|
||||
}
|
||||
|
|
@ -1289,6 +1305,10 @@ Non-interactive mode (--non-interactive or BD_NON_INTERACTIVE=1):
|
|||
}
|
||||
}
|
||||
if syncFromRemote {
|
||||
// A raw https:// forge URL would route through Dolt's remotesapi
|
||||
// client and spin forever (#4421); its git+ form routes through
|
||||
// the git remote factory. Non-forge URLs are untouched (GH#3339).
|
||||
syncURL = doltRemoteURL(syncURL)
|
||||
cloneCfg := initTimeCloneConfig(initServerMode, serverHost, serverPort, serverSocket, serverUser, dbName)
|
||||
disposition, err := runInitRemoteClone(syncURL, func(remoteURL string) error {
|
||||
return cloneFromRemoteWithMode(ctx, beadsDir, remoteURL, dbName, cloneCfg, initRemoteCloneMode(initServerMode, externalServer))
|
||||
|
|
@ -1480,6 +1500,7 @@ Non-interactive mode (--non-interactive or BD_NON_INTERACTIVE=1):
|
|||
printBootstrapRemoteBehindGuidance(os.Stderr, gateErr, syncURL, "bd init")
|
||||
} else {
|
||||
fmt.Fprint(os.Stderr, gateErr.UserMessage())
|
||||
printInitJoinGuidance(os.Stderr, gateErr)
|
||||
}
|
||||
return &exitError{Code: 1}
|
||||
}
|
||||
|
|
@ -1504,8 +1525,14 @@ Non-interactive mode (--non-interactive or BD_NON_INTERACTIVE=1):
|
|||
// falling back to JSONL-as-sync. Gateway mode skips it: the hosted
|
||||
// server owns the database, so DOLT_REMOTE('add', ...) must not run
|
||||
// against it (see shouldWriteInitDoltRemote).
|
||||
// The URL is routed here too, not just on the clone path: the
|
||||
// no-Dolt-data-yet case (the pre-first-push wiring this is for) never
|
||||
// clones, so without routing a raw https forge URL would be stored
|
||||
// verbatim in dolt_remotes and the *first* `bd dolt push` would take
|
||||
// it to the remotesapi client — the #4421 storm, one leg further down
|
||||
// (#5743).
|
||||
if shouldWriteInitDoltRemote(doltCfg.Gateway, syncURL, syncFromRemote, syncURLFromConfig, syncURLFromGitOrigin, isDoltLocalOnly()) {
|
||||
configureInitDoltRemote(ctx, store, syncURL, quiet)
|
||||
configureInitDoltRemote(ctx, store, doltRemoteURL(syncURL), quiet)
|
||||
}
|
||||
|
||||
// === CONFIGURATION METADATA (Pattern A: Fatal) ===
|
||||
|
|
@ -1740,7 +1767,9 @@ Non-interactive mode (--non-interactive or BD_NON_INTERACTIVE=1):
|
|||
// Must run AFTER createConfigYaml which creates the file.
|
||||
// Persist the effective remote so future bootstrap and hooks know
|
||||
// Dolt, not JSONL, is the cross-machine sync path. Plain git
|
||||
// origins are valid here: the first push creates refs/dolt/data.
|
||||
// origins are valid here: the first push creates refs/dolt/data,
|
||||
// and bootstrap resolves such a URL by probing refs/dolt/data
|
||||
// rather than rejecting it (#5743).
|
||||
if err := persistInitSyncRemote(beadsDir, initRemote, syncURL, syncFromRemote, syncURLFromConfig, syncURLFromGitOrigin); err != nil {
|
||||
return fmt.Errorf("failed to persist sync.remote to config.yaml: %v", err)
|
||||
}
|
||||
|
|
@ -2463,7 +2492,7 @@ func checkExistingBeadsDataAt(beadsDir string, prefix string) error {
|
|||
return fmt.Errorf("failed to load %s: %w; refusing to reinitialize automatically (restore the metadata or use --reinit-local after safeguarding existing data)", configfile.ConfigPath(beadsDir), cfgErr)
|
||||
}
|
||||
if cfg != nil {
|
||||
if guardErr := validateConfiguredBackend(cfg); guardErr != nil {
|
||||
if guardErr := validateConfiguredBackend(cfg, beadsDir); guardErr != nil {
|
||||
return guardErr
|
||||
}
|
||||
}
|
||||
|
|
@ -2762,6 +2791,40 @@ func initIfMissingPrefixMismatch(existingDBName, requestedPrefix string) bool {
|
|||
return requested != "" && !strings.EqualFold(existingDBName, requested)
|
||||
}
|
||||
|
||||
// resolveInitIfMissingAlreadyInitialized decides what --init-if-missing does
|
||||
// once the workspace is known to be initialized already: nil for the benign
|
||||
// skip (message printed here), or the abort for a request that would be
|
||||
// silently ignored by skipping.
|
||||
//
|
||||
// Guard against masking a genuine mismatch: an explicit --prefix or --database
|
||||
// that does not match the existing workspace must abort, since silently
|
||||
// skipping would ignore the request and reuse a different database. --database
|
||||
// is the authoritative selector, so it is checked even when --prefix is also
|
||||
// set.
|
||||
//
|
||||
// Both init routes share this: the embedded/server route reaches it from its
|
||||
// own checkExistingBeadsData, the proxied-server route from the identical check
|
||||
// inside runInitProxiedServer. Before that wiring existed, --init-if-missing was
|
||||
// simply inert on the proxied route — an already-initialized workspace exited 1
|
||||
// with the "Aborting." banner, and the two mismatch guards this delegates to had
|
||||
// never once run.
|
||||
func resolveInitIfMissingAlreadyInitialized(cmd *cobra.Command, database, prefix string, quiet bool) error {
|
||||
existing := existingWorkspaceDBName()
|
||||
if cmd.Flags().Changed("database") {
|
||||
if initIfMissingDatabaseMismatch(existing, database) {
|
||||
return fmt.Errorf("workspace already initialized as database %q, but --database %q was requested.\nRemove --database (or pass a matching value) to reuse the existing workspace", existing, database)
|
||||
}
|
||||
} else if cmd.Flags().Changed("prefix") {
|
||||
if initIfMissingPrefixMismatch(existing, prefix) {
|
||||
return fmt.Errorf("workspace already initialized as database %q, but --prefix %q was requested.\nRemove --prefix (or pass a matching value) to reuse the existing workspace", existing, prefix)
|
||||
}
|
||||
}
|
||||
if !quiet {
|
||||
fmt.Fprintln(os.Stderr, "Skipping init: workspace already initialized.")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// initIfMissingDatabaseMismatch reports whether an explicit --database request
|
||||
// conflicts with the existing workspace. --database is the authoritative database
|
||||
// selector (it overrides prefix-based naming later in init), so an explicit
|
||||
|
|
@ -3400,6 +3463,15 @@ func initGlobalDatabaseConfig(ctx context.Context, projectCfg *dolt.Config, quie
|
|||
globalStore, err := newDoltStore(ctx, globalCfg)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: failed to open global database: %v\n", err)
|
||||
// The gate's own block prescribes `bd migrate schema`, which migrates
|
||||
// the PROJECT database — on this path that leaves the global database
|
||||
// exactly as refused. Name the command that actually reaches it
|
||||
// (#5920); this warning is the only place the global refusal surfaces.
|
||||
if schema.IsRemoteMigrateGateError(err) {
|
||||
fmt.Fprintf(os.Stderr,
|
||||
" The global database is shared by every workspace on this server. To migrate it, run:\n %s\n",
|
||||
schema.SharedConsentCommandGlobal)
|
||||
}
|
||||
return
|
||||
}
|
||||
defer func() { _ = globalStore.Close() }()
|
||||
|
|
|
|||
|
|
@ -192,3 +192,61 @@ func TestNormalizeIssuePrefixAndDatabaseName(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestDoltRemoteURL pins which URLs bd rewrites before handing them to Dolt —
|
||||
// for DOLT_CLONE, for DOLT_REMOTE('add', ...) and therefore for DOLT_PUSH.
|
||||
// Forge URLs must arrive in git+ form so Dolt uses the git remote factory
|
||||
// rather than the remotesapi retry storm (#4421); a user-configured remotesapi
|
||||
// endpoint must arrive byte-identical (GH#3339). bd init and bd bootstrap
|
||||
// share this one helper so they can never disagree about the URL derived from
|
||||
// a single committed sync.remote.
|
||||
func TestDoltRemoteURL(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
in string
|
||||
want string
|
||||
}{
|
||||
{"raw https forge", "https://github.com/org/repo.git", "git+https://github.com/org/repo.git"},
|
||||
{"forge without .git", "https://github.com/org/repo", "git+https://github.com/org/repo"},
|
||||
{"scp style forge", "git@github.com:org/repo.git", "git+ssh://git@github.com/org/repo.git"},
|
||||
{"ssh forge", "ssh://git@gitlab.com/org/repo.git", "git+ssh://git@gitlab.com/org/repo.git"},
|
||||
{"already normalized", "git+https://github.com/org/repo.git", "git+https://github.com/org/repo.git"},
|
||||
|
||||
{"remotesapi endpoint", "http://myserver:7007/mydb", "http://myserver:7007/mydb"},
|
||||
{"remotesapi https endpoint", "https://doltremoteapi.dolthub.com/org/db", "https://doltremoteapi.dolthub.com/org/db"},
|
||||
{"dolthub native", "dolthub://myorg/mydb", "dolthub://myorg/mydb"},
|
||||
{"s3 native", "s3://bucket/path", "s3://bucket/path"},
|
||||
{"self-hosted dolt over ssh", "git+ssh://my-dolt.example.com/org/db", "git+ssh://my-dolt.example.com/org/db"},
|
||||
{"empty", "", ""},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := doltRemoteURL(tt.in); got != tt.want {
|
||||
t.Errorf("doltRemoteURL(%q) = %q, want %q", tt.in, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestRunInitRemoteCloneReceivesRoutedURL proves the routing survives the call
|
||||
// into runInitRemoteClone — the seam the init RunE body actually uses.
|
||||
func TestRunInitRemoteCloneReceivesRoutedURL(t *testing.T) {
|
||||
for _, tt := range []struct{ in, want string }{
|
||||
{"https://github.com/org/repo.git", "git+https://github.com/org/repo.git"},
|
||||
{"http://myserver:7007/mydb", "http://myserver:7007/mydb"},
|
||||
} {
|
||||
t.Run(tt.in, func(t *testing.T) {
|
||||
var gotURL string
|
||||
if _, err := runInitRemoteClone(doltRemoteURL(tt.in), func(url string) error {
|
||||
gotURL = url
|
||||
return nil
|
||||
}); err != nil {
|
||||
t.Fatalf("runInitRemoteClone: %v", err)
|
||||
}
|
||||
if gotURL != tt.want {
|
||||
t.Errorf("clone received %q, want %q", gotURL, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
96
cmd/bd/init_proxied_if_missing_test.go
Normal file
96
cmd/bd/init_proxied_if_missing_test.go
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
//go:build cgo
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestProxiedServerInitIfMissing covers --init-if-missing on the proxied-server
|
||||
// route, where it used to be inert: runInitProxiedServer runs its own
|
||||
// already-initialized check and returns before init.go's --init-if-missing
|
||||
// block, so a scaffold script re-running init got exit 1 and the "Aborting."
|
||||
// banner, and the mismatch guards that protect the flag had never run at all.
|
||||
func TestProxiedServerInitIfMissing(t *testing.T) {
|
||||
requireProxiedServerEnv(t)
|
||||
|
||||
bd := buildEmbeddedBD(t)
|
||||
p := bdProxiedInit(t, bd, "pim")
|
||||
|
||||
initArgs := func(extra ...string) []string {
|
||||
return append([]string{
|
||||
"init", "--proxied-server", "--non-interactive", "--skip-agents", "--skip-hooks",
|
||||
}, extra...)
|
||||
}
|
||||
|
||||
t.Run("re-init skips benignly", func(t *testing.T) {
|
||||
_, stderr, err := bdProxiedRunBuffers(t, bd, p.dir, initArgs("--init-if-missing")...)
|
||||
if err != nil {
|
||||
t.Fatalf("init --init-if-missing should exit 0 on an initialized workspace: %v\nstderr:\n%s", err, stderr)
|
||||
}
|
||||
if !strings.Contains(stderr, "Skipping init: workspace already initialized") {
|
||||
t.Errorf("expected the benign skip message, got stderr:\n%s", stderr)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("matching prefix skips benignly", func(t *testing.T) {
|
||||
_, stderr, err := bdProxiedRunBuffers(t, bd, p.dir, initArgs("--init-if-missing", "--prefix", p.prefix)...)
|
||||
if err != nil {
|
||||
t.Fatalf("matching --prefix should still skip: %v\nstderr:\n%s", err, stderr)
|
||||
}
|
||||
if !strings.Contains(stderr, "Skipping init: workspace already initialized") {
|
||||
t.Errorf("expected the benign skip message, got stderr:\n%s", stderr)
|
||||
}
|
||||
})
|
||||
|
||||
// The multi-project ask. Skipping here would silently ignore --database and
|
||||
// keep using the existing one, so it must refuse — and say which database
|
||||
// the workspace is actually on.
|
||||
t.Run("different database is refused, not skipped", func(t *testing.T) {
|
||||
stdout, stderr, err := bdProxiedRunBuffers(t, bd, p.dir, initArgs("--init-if-missing", "--database", "some_other_db")...)
|
||||
if err == nil {
|
||||
t.Fatalf("mismatched --database must abort; got success\nstdout:\n%s\nstderr:\n%s", stdout, stderr)
|
||||
}
|
||||
out := stdout + stderr
|
||||
for _, want := range []string{
|
||||
"workspace already initialized as database " + `"` + p.database + `"`,
|
||||
`--database "some_other_db" was requested`,
|
||||
} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Errorf("abort message missing %q, got:\n%s", want, out)
|
||||
}
|
||||
}
|
||||
if strings.Contains(out, "Skipping init") {
|
||||
t.Errorf("a mismatched --database must not be skipped, got:\n%s", out)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("different prefix is refused, not skipped", func(t *testing.T) {
|
||||
stdout, stderr, err := bdProxiedRunBuffers(t, bd, p.dir, initArgs("--init-if-missing", "--prefix", "somethingelse")...)
|
||||
if err == nil {
|
||||
t.Fatalf("mismatched --prefix must abort; got success\nstdout:\n%s\nstderr:\n%s", stdout, stderr)
|
||||
}
|
||||
out := stdout + stderr
|
||||
for _, want := range []string{
|
||||
"workspace already initialized as database " + `"` + p.database + `"`,
|
||||
`--prefix "somethingelse" was requested`,
|
||||
} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Errorf("abort message missing %q, got:\n%s", want, out)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Without the flag, the existing refusal is unchanged: --init-if-missing is
|
||||
// what makes re-init benign, not this change.
|
||||
t.Run("without the flag re-init still aborts", func(t *testing.T) {
|
||||
stdout, stderr, err := bdProxiedRunBuffers(t, bd, p.dir, initArgs()...)
|
||||
if err == nil {
|
||||
t.Fatalf("re-init without --init-if-missing must abort; got success\nstdout:\n%s\nstderr:\n%s", stdout, stderr)
|
||||
}
|
||||
if out := stdout + stderr; !strings.Contains(out, "already initialized") {
|
||||
t.Errorf("expected the existing already-initialized refusal, got:\n%s", out)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -38,6 +38,10 @@ const (
|
|||
// in non-interactive mode without a valid `--destroy-token`: either
|
||||
// `--discard-remote`, or `--reinit-local` over existing local issues.
|
||||
// The caller must look up the token format via `bd help init-safety`.
|
||||
// It is also returned when the interactive `--discard-remote` typed-token
|
||||
// confirmation is declined at the prompt, so a 12 does not on its own
|
||||
// prove the caller was non-interactive. Supplying the token is the
|
||||
// correct remedy for all three sources.
|
||||
ExitDestroyTokenMissing = 12
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -80,7 +80,8 @@ EXIT CODES
|
|||
(interactive mode only)
|
||||
12 refused: destructive re-init (--discard-remote, or --reinit-local
|
||||
over existing issues) without a valid --destroy-token
|
||||
(non-interactive mode)
|
||||
(non-interactive mode); also returned when the interactive
|
||||
--discard-remote typed-token confirmation is declined
|
||||
|
||||
RECOVERY
|
||||
|
||||
|
|
|
|||
|
|
@ -358,6 +358,12 @@ func TestShouldWireInitRemote(t *testing.T) {
|
|||
want: false,
|
||||
},
|
||||
{
|
||||
// Keep this true. The URL is the supported pre-first-push wiring:
|
||||
// the first `bd dolt push` creates refs/dolt/data on that same git
|
||||
// remote, and bootstrap resolves the persisted value by probing
|
||||
// for that ref (#5743). Do not "fix" a bootstrap failure by
|
||||
// un-persisting here — that leaves every already-committed
|
||||
// .beads/config.yaml in the wild broken.
|
||||
name: "plain git origin without dolt data",
|
||||
syncURL: "git+https://github.com/org/plain-source.git",
|
||||
syncURLFromGit: true,
|
||||
|
|
|
|||
|
|
@ -96,9 +96,6 @@ func init() {
|
|||
}
|
||||
|
||||
func runJiraSync(cmd *cobra.Command, args []string) error {
|
||||
if usesProxiedServer() {
|
||||
return HandleErrorRespectJSON("jira sync is not supported in proxied-server mode")
|
||||
}
|
||||
evt := metrics.NewCommandEvent("jira-sync")
|
||||
defer func() {
|
||||
if c := metrics.Global(); c != nil {
|
||||
|
|
@ -122,11 +119,12 @@ func runJiraSync(cmd *cobra.Command, args []string) error {
|
|||
return HandleErrorRespectJSON("cannot use both --prefer-local and --prefer-jira")
|
||||
}
|
||||
|
||||
if err := ensureStoreActive(); err != nil {
|
||||
trackerStore, err := trackerStoreForCommand(rootCtx)
|
||||
if err != nil {
|
||||
return HandleErrorRespectJSON("database not available: %v", err)
|
||||
}
|
||||
|
||||
if err := validateJiraConfig(); err != nil {
|
||||
if err := validateJiraConfigForStore(trackerStore); err != nil {
|
||||
return HandleErrorRespectJSON("%v", err)
|
||||
}
|
||||
|
||||
|
|
@ -137,15 +135,15 @@ func runJiraSync(cmd *cobra.Command, args []string) error {
|
|||
if len(cliProjects) > 0 {
|
||||
jt.SetProjectKeys(tracker.DeduplicateStrings(cliProjects))
|
||||
}
|
||||
if err := jt.Init(ctx, store); err != nil {
|
||||
if err := jt.Init(ctx, trackerStore); err != nil {
|
||||
return HandleErrorRespectJSON("initializing Jira tracker: %v", err)
|
||||
}
|
||||
|
||||
engine := tracker.NewEngine(jt, store, actor)
|
||||
engine := tracker.NewEngine(jt, trackerStore, actor)
|
||||
engine.OnMessage = func(msg string) { fmt.Println(" " + msg) }
|
||||
engine.OnWarning = func(msg string) { fmt.Fprintf(os.Stderr, "Warning: %s\n", msg) }
|
||||
|
||||
engine.PushHooks = buildJiraPushHooks(ctx)
|
||||
engine.PushHooks = buildJiraPushHooksForStore(ctx, trackerStore)
|
||||
|
||||
opts := tracker.SyncOptions{
|
||||
Pull: pull,
|
||||
|
|
@ -207,9 +205,13 @@ func runJiraSync(cmd *cobra.Command, args []string) error {
|
|||
|
||||
// buildJiraPushHooks creates PushHooks for Jira-specific push behavior.
|
||||
func buildJiraPushHooks(ctx context.Context) *tracker.PushHooks {
|
||||
return buildJiraPushHooksForStore(ctx, tracker.NewStore(store))
|
||||
}
|
||||
|
||||
func buildJiraPushHooksForStore(ctx context.Context, st tracker.Store) *tracker.PushHooks {
|
||||
return &tracker.PushHooks{
|
||||
ShouldPush: func(issue *types.Issue) bool {
|
||||
pushPrefix, _ := store.GetConfig(ctx, "jira.push_prefix")
|
||||
pushPrefix, _ := st.GetConfig(ctx, "jira.push_prefix")
|
||||
if pushPrefix == "" {
|
||||
return true
|
||||
}
|
||||
|
|
@ -226,9 +228,6 @@ func buildJiraPushHooks(ctx context.Context) *tracker.PushHooks {
|
|||
}
|
||||
|
||||
func runJiraStatus(cmd *cobra.Command, args []string) error {
|
||||
if usesProxiedServer() {
|
||||
return HandleErrorRespectJSON("jira status is not supported in proxied-server mode")
|
||||
}
|
||||
evt := metrics.NewCommandEvent("jira-status")
|
||||
defer func() {
|
||||
if c := metrics.Global(); c != nil {
|
||||
|
|
@ -238,22 +237,23 @@ func runJiraStatus(cmd *cobra.Command, args []string) error {
|
|||
|
||||
ctx := rootCtx
|
||||
|
||||
if err := ensureStoreActive(); err != nil {
|
||||
trackerStore, err := trackerStoreForCommand(rootCtx)
|
||||
if err != nil {
|
||||
return HandleErrorRespectJSON("%v", err)
|
||||
}
|
||||
|
||||
jiraURL, _ := store.GetConfig(ctx, "jira.url")
|
||||
lastSync, _ := store.GetConfig(ctx, "jira.last_sync")
|
||||
jiraURL, _ := trackerStore.GetConfig(ctx, "jira.url")
|
||||
lastSync, _ := trackerStore.GetConfig(ctx, "jira.last_sync")
|
||||
|
||||
pluralProjects, _ := store.GetConfig(ctx, "jira.projects")
|
||||
singularProject, _ := store.GetConfig(ctx, "jira.project")
|
||||
pluralProjects, _ := trackerStore.GetConfig(ctx, "jira.projects")
|
||||
singularProject, _ := trackerStore.GetConfig(ctx, "jira.project")
|
||||
projectKeys := tracker.ResolveProjectIDs(nil, pluralProjects, singularProject)
|
||||
|
||||
configured := jiraURL != "" && len(projectKeys) > 0
|
||||
|
||||
// jira sync is a round-trip path — opt out of BEADS_MAX_ROWS
|
||||
// (designer §4.1) so a misconfigured env doesn't abort partway.
|
||||
allIssues, err := store.SearchIssues(ctx, "", types.IssueFilter{
|
||||
allIssues, err := trackerStore.SearchIssues(ctx, "", types.IssueFilter{
|
||||
MaxRows: 0,
|
||||
MaxRowsSource: "",
|
||||
})
|
||||
|
|
@ -329,26 +329,29 @@ func runJiraStatus(cmd *cobra.Command, args []string) error {
|
|||
|
||||
// validateJiraConfig checks that required Jira configuration is present.
|
||||
func validateJiraConfig() error {
|
||||
if err := ensureStoreActive(); err != nil {
|
||||
return fmt.Errorf("database not available: %w", err)
|
||||
}
|
||||
return validateJiraConfigForStore(tracker.NewStore(store))
|
||||
}
|
||||
|
||||
func validateJiraConfigForStore(st tracker.Store) error {
|
||||
ctx := rootCtx
|
||||
jiraURL, _ := store.GetConfig(ctx, "jira.url")
|
||||
if st == nil {
|
||||
return fmt.Errorf("database not available")
|
||||
}
|
||||
jiraURL, _ := st.GetConfig(ctx, "jira.url")
|
||||
|
||||
if jiraURL == "" {
|
||||
return fmt.Errorf("jira.url not configured\nRun: bd config set jira.url \"https://company.atlassian.net\"")
|
||||
}
|
||||
|
||||
// Check for project configuration (singular or plural).
|
||||
pluralProjects, _ := store.GetConfig(ctx, "jira.projects")
|
||||
singularProject, _ := store.GetConfig(ctx, "jira.project")
|
||||
pluralProjects, _ := st.GetConfig(ctx, "jira.projects")
|
||||
singularProject, _ := st.GetConfig(ctx, "jira.project")
|
||||
projectKeys := tracker.ResolveProjectIDs(nil, pluralProjects, singularProject)
|
||||
if len(projectKeys) == 0 {
|
||||
return fmt.Errorf("no Jira project configured\nRun: bd config set jira.project \"PROJ\"\nOr: bd config set jira.projects \"PROJ1,PROJ2\"")
|
||||
}
|
||||
|
||||
apiToken, _ := store.GetConfig(ctx, "jira.api_token")
|
||||
apiToken, _ := st.GetConfig(ctx, "jira.api_token")
|
||||
if apiToken == "" && os.Getenv("JIRA_API_TOKEN") == "" {
|
||||
return fmt.Errorf("Jira API token not configured\nRun: bd config set jira.api_token \"YOUR_TOKEN\"\nOr: export JIRA_API_TOKEN=YOUR_TOKEN")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/testutil"
|
||||
"github.com/steveyegge/beads/internal/tracker"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
|
|
@ -124,7 +123,7 @@ type stubMaxRowsTracker struct{}
|
|||
func (*stubMaxRowsTracker) Name() string { return "stubmr" }
|
||||
func (*stubMaxRowsTracker) DisplayName() string { return "StubMR" }
|
||||
func (*stubMaxRowsTracker) ConfigPrefix() string { return "stubmr" }
|
||||
func (*stubMaxRowsTracker) Init(_ context.Context, _ storage.Storage) error { return nil }
|
||||
func (*stubMaxRowsTracker) Init(_ context.Context, _ tracker.Store) error { return nil }
|
||||
func (*stubMaxRowsTracker) Validate() error { return nil }
|
||||
func (*stubMaxRowsTracker) Close() error { return nil }
|
||||
func (*stubMaxRowsTracker) FieldMapper() tracker.FieldMapper { return nil }
|
||||
|
|
|
|||
|
|
@ -36,10 +36,10 @@ func guardLegacyUpgradeWorkspace(beadsDir string) error {
|
|||
// Validate read-only discovery metadata before any caller can use Load,
|
||||
// which migrates legacy config.json to metadata.json. Removed and unknown
|
||||
// backends must fail without changing the only pointer to their data.
|
||||
if err := validateConfiguredBackend(cfg); err != nil {
|
||||
if err := validateConfiguredBackend(cfg, beadsDir); err != nil {
|
||||
return err
|
||||
}
|
||||
serverMode := cfg != nil && strings.EqualFold(cfg.DoltMode, configfile.DoltModeServer)
|
||||
serverMode := workspaceSelectsServerMode(cfg)
|
||||
if embeddeddolt.HasRepository(beadsDir) && !serverMode {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -51,11 +51,31 @@ func guardLegacyUpgradeWorkspace(beadsDir string) error {
|
|||
if !hasLocalDoltRoot {
|
||||
return nil
|
||||
}
|
||||
// Positive evidence that this workspace belongs to the current era settles
|
||||
// it for every mode. Only the ambiguity that remains after these is
|
||||
// mode-specific, so the refusals below are the only part that branches.
|
||||
if classifyVersionWitness(version) == witnessEraCurrent {
|
||||
// A witness naming bd 1.0 or later can only have been written by a
|
||||
// current-era binary, and only after this same guard admitted the
|
||||
// workspace (PersistentPreRunE runs the guard before trackBdVersion,
|
||||
// and doctor runs it before its own copy of that call). No legacy
|
||||
// release could have produced it. Reading it as proof only in server
|
||||
// mode left the escape hatch unreachable for a workspace the running
|
||||
// binary demonstrably created itself.
|
||||
return nil
|
||||
}
|
||||
if doltserver.IsSharedServerMode() && !(present && legacyServerVersion(version)) {
|
||||
// A shared Dolt sql-server owns .beads/dolt, so there is no embedded
|
||||
// historical schema to protect — unless the witness affirmatively names
|
||||
// the 0.55–0.62 server era. This admission used to sit inside the
|
||||
// embedded arm below. Leaving it there while config.yaml started
|
||||
// selecting server mode would have moved shared-server workspaces bd
|
||||
// admits today onto the refusing arm: the mode changed, the evidence
|
||||
// did not.
|
||||
return nil
|
||||
}
|
||||
if serverMode {
|
||||
switch classifyVersionWitness(version) {
|
||||
case witnessEraCurrent:
|
||||
return nil
|
||||
case witnessEraUnknown:
|
||||
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
|
||||
// best-effort write — is not evidence of a legacy workspace: every
|
||||
|
|
@ -66,18 +86,13 @@ func guardLegacyUpgradeWorkspace(beadsDir string) error {
|
|||
// command over an advisory, gitignored file. A genuinely absent
|
||||
// witness is not present and still refuses below, preserving the
|
||||
// pre-1.0 guard invariant.
|
||||
if present {
|
||||
warnUnreadableVersionWitness(beadsDir, version)
|
||||
return nil
|
||||
}
|
||||
warnUnreadableVersionWitness(beadsDir, version)
|
||||
return nil
|
||||
}
|
||||
return legacyUpgradeRefusal("legacy Dolt server workspace")
|
||||
}
|
||||
if cfg == nil || cfg.DoltMode == "" ||
|
||||
strings.EqualFold(cfg.DoltMode, configfile.DoltModeEmbedded) {
|
||||
if doltserver.IsSharedServerMode() && !(present && legacyServerVersion(version)) {
|
||||
return nil
|
||||
}
|
||||
reason := "legacy Dolt workspace"
|
||||
if _, validVersion := legacyVersionMinor(version); present && validVersion {
|
||||
reason = fmt.Sprintf("legacy Dolt workspace from bd %s", version)
|
||||
|
|
@ -87,6 +102,33 @@ func guardLegacyUpgradeWorkspace(beadsDir string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// workspaceSelectsServerMode reports whether bd will open beadsDir through a
|
||||
// Dolt sql-server rather than as an embedded database.
|
||||
//
|
||||
// It asks configfile's own resolver instead of reading metadata.json's
|
||||
// dolt_mode directly. That field is only the highest-priority layer of the
|
||||
// decision: a workspace that declares `dolt.mode: server` in .beads/config.yaml
|
||||
// and has no metadata.json at all — the shape gc provisions — is just as much a
|
||||
// server workspace, and IsDoltServerMode documents the full precedence chain
|
||||
// that store selection then uses. Reading the top layer alone classified those
|
||||
// as embedded, and an embedded workspace owning a .beads/dolt root is precisely
|
||||
// what this guard refuses, so bd rejected server workspaces it had created
|
||||
// itself moments earlier.
|
||||
//
|
||||
// On the PersistentPreRunE and doctor paths the config.yaml layer resolves
|
||||
// against the SELECTED workspace: main.go binds the discovered target before
|
||||
// admission for exactly this reason, which is also what makes
|
||||
// doltserver.IsSharedServerMode() above read the target's config rather than
|
||||
// the caller's. The ancestor scans are the known exception —
|
||||
// guardUndiscoveredLegacyWorkspace below and findParentConfig in bootstrap.go
|
||||
// pass candidates that are by construction not the bound target, so for those
|
||||
// the env and config.yaml layers come from the caller's process-global state,
|
||||
// not from the candidate. Do not rely on the binding from a caller that walks
|
||||
// ancestors.
|
||||
func workspaceSelectsServerMode(cfg *configfile.Config) bool {
|
||||
return normalizeLoadedConfig(cfg).IsDoltServerMode()
|
||||
}
|
||||
|
||||
func isHistoricalSQLiteWorkspace(beadsDir string, cfg *configfile.Config) bool {
|
||||
if beadsDir == "" {
|
||||
return false
|
||||
|
|
|
|||
255
cmd/bd/legacy_upgrade_guard_config_yaml_test.go
Normal file
255
cmd/bd/legacy_upgrade_guard_config_yaml_test.go
Normal file
|
|
@ -0,0 +1,255 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/config"
|
||||
)
|
||||
|
||||
// bindSelectedWorkspaceConfig loads beadsDir's config.yaml into the process
|
||||
// config state the way PersistentPreRunE does — prepareSelectedCommandContext
|
||||
// binds the discovered target before admission precisely so the guard reads the
|
||||
// selected workspace's config rather than the caller's. The Dolt env vars are
|
||||
// pinned off so a developer's ambient shell cannot decide a mode for the guard.
|
||||
func bindSelectedWorkspaceConfig(t *testing.T, beadsDir string) {
|
||||
t.Helper()
|
||||
t.Setenv("HOME", t.TempDir())
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
t.Setenv("BEADS_TEST_IGNORE_REPO_CONFIG", "1")
|
||||
t.Setenv("BEADS_DIR", beadsDir)
|
||||
t.Setenv("BEADS_DOLT_SERVER_MODE", "0")
|
||||
t.Setenv("BEADS_DOLT_SHARED_SERVER", "0")
|
||||
t.Setenv("BEADS_DOLT_SERVER_HOST", "")
|
||||
|
||||
config.ResetForTesting()
|
||||
if err := config.Initialize(); err != nil {
|
||||
t.Fatalf("config.Initialize() = %v", err)
|
||||
}
|
||||
t.Cleanup(config.ResetForTesting)
|
||||
}
|
||||
|
||||
// writeDoltRootWorkspace lays down the ambiguous shape the guard classifies: a
|
||||
// .beads directory that owns a 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 {
|
||||
t.Helper()
|
||||
beadsDir := t.TempDir()
|
||||
write := func(name, contents string) {
|
||||
if contents == "" {
|
||||
return
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(beadsDir, name), []byte(contents), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
write("metadata.json", metadata)
|
||||
write("config.yaml", configYaml)
|
||||
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
|
||||
}
|
||||
|
||||
// configYamlServerMode reproduces the gc-provisioned config.yaml: dolt.mode is
|
||||
// declared as a flat dotted key beside a nested dolt map, which is how bd's own
|
||||
// `bd config set` writer emits it.
|
||||
const configYamlServerMode = "issue_prefix: gc\n" +
|
||||
"dolt:\n" +
|
||||
" disable-event-flush: true\n" +
|
||||
"dolt.mode: server\n"
|
||||
|
||||
// TestLegacyUpgradeGuardAdmitsConfigYamlServerModeWorkspace pins the shape the
|
||||
// v1.3.0 release candidate refused after creating it itself: dolt.mode declared
|
||||
// in .beads/config.yaml, a local .beads/dolt root, a current-era version
|
||||
// witness, and no metadata.json. LoadForDiscovery reads metadata.json only, so
|
||||
// the guard classified a server workspace as embedded — and an embedded
|
||||
// workspace owning a .beads/dolt root is exactly what it refuses.
|
||||
func TestLegacyUpgradeGuardAdmitsConfigYamlServerModeWorkspace(t *testing.T) {
|
||||
versions := []string{
|
||||
"1.3.0",
|
||||
"1.3.0-rc.1",
|
||||
"1.1.0",
|
||||
"v1.1.1-0.20260805093327-bf97b73749ac",
|
||||
}
|
||||
|
||||
for _, version := range versions {
|
||||
t.Run(version, func(t *testing.T) {
|
||||
warnings := captureLegacyUpgradeWarnings(t)
|
||||
beadsDir := writeDoltRootWorkspace(t, "", configYamlServerMode, version)
|
||||
|
||||
if err := guardLegacyUpgradeWorkspace(beadsDir); err != nil {
|
||||
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want nil", err)
|
||||
}
|
||||
if warnings.Len() != 0 {
|
||||
t.Fatalf("guard warned about a readable witness: %q", warnings.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("nested dolt.mode mapping", func(t *testing.T) {
|
||||
captureLegacyUpgradeWarnings(t)
|
||||
beadsDir := writeDoltRootWorkspace(t, "", "dolt:\n mode: server\n", "1.3.0")
|
||||
|
||||
if err := guardLegacyUpgradeWorkspace(beadsDir); err != nil {
|
||||
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want nil", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("unreadable witness warns and opens", func(t *testing.T) {
|
||||
warnings := captureLegacyUpgradeWarnings(t)
|
||||
beadsDir := writeDoltRootWorkspace(t, "", configYamlServerMode, "not-a-version")
|
||||
|
||||
if err := guardLegacyUpgradeWorkspace(beadsDir); err != nil {
|
||||
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want nil", err)
|
||||
}
|
||||
if warnings.Len() == 0 {
|
||||
t.Fatal("guard admitted an unreadable witness without warning")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestLegacyUpgradeGuardStillRefusesLegacyConfigYamlServerWorkspace proves the
|
||||
// config.yaml layer classifies the mode without relaxing the era check: a
|
||||
// workspace that declares server mode there and carries pre-1.0 evidence — or
|
||||
// no evidence at all — is still refused.
|
||||
func TestLegacyUpgradeGuardStillRefusesLegacyConfigYamlServerWorkspace(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
version string
|
||||
}{
|
||||
{name: "historical server era witness", version: "0.62.0"},
|
||||
{name: "historical embedded era witness", version: "0.49.6"},
|
||||
{name: "four component pre-1.0 witness", version: "0.62.0.1"},
|
||||
{name: "no witness at all"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
captureLegacyUpgradeWarnings(t)
|
||||
beadsDir := writeDoltRootWorkspace(t, "", configYamlServerMode, tt.version)
|
||||
|
||||
if err := guardLegacyUpgradeWorkspace(beadsDir); !isLegacyUpgradeRefusal(err) {
|
||||
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want migration refusal", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("metadata embedded mode outranks config.yaml server mode", func(t *testing.T) {
|
||||
captureLegacyUpgradeWarnings(t)
|
||||
// metadata.json's dolt_mode is the highest-priority layer, so this stays
|
||||
// an embedded workspace — and the embedded arm deliberately does not
|
||||
// trust an unreadable witness.
|
||||
beadsDir := writeDoltRootWorkspace(t,
|
||||
`{"backend":"dolt","dolt_mode":"embedded"}`, configYamlServerMode, "not-a-version")
|
||||
|
||||
if err := guardLegacyUpgradeWorkspace(beadsDir); !isLegacyUpgradeRefusal(err) {
|
||||
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want migration refusal", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestCurrentVersionWitnessVetoesLegacyVerdictInEveryMode pins the general
|
||||
// safety net: a witness naming bd 1.0 or later can only have been written by a
|
||||
// current-era binary, and only after this guard already admitted the workspace,
|
||||
// so it settles the era regardless of which mode the workspace resolves to. The
|
||||
// escape hatch used to live inside the server-mode arm, where a misclassified
|
||||
// workspace could never reach it.
|
||||
func TestCurrentVersionWitnessVetoesLegacyVerdictInEveryMode(t *testing.T) {
|
||||
modes := []struct {
|
||||
name string
|
||||
metadata string
|
||||
}{
|
||||
{name: "metadata-less"},
|
||||
{name: "blank mode", metadata: `{"backend":"dolt"}`},
|
||||
{name: "explicit embedded mode", metadata: `{"backend":"dolt","dolt_mode":"embedded"}`},
|
||||
{name: "explicit server mode", metadata: `{"backend":"dolt","dolt_mode":"server"}`},
|
||||
}
|
||||
|
||||
for _, mode := range modes {
|
||||
t.Run(mode.name, func(t *testing.T) {
|
||||
captureLegacyUpgradeWarnings(t)
|
||||
beadsDir := writeDoltRootWorkspace(t, mode.metadata, "", "1.3.0")
|
||||
|
||||
if err := guardLegacyUpgradeWorkspace(beadsDir); err != nil {
|
||||
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want nil", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run(mode.name+"/pre-1.0 witness still refuses", func(t *testing.T) {
|
||||
captureLegacyUpgradeWarnings(t)
|
||||
beadsDir := writeDoltRootWorkspace(t, mode.metadata, "", "0.62.21")
|
||||
|
||||
if err := guardLegacyUpgradeWorkspace(beadsDir); !isLegacyUpgradeRefusal(err) {
|
||||
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want migration refusal", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run(mode.name+"/missing witness still refuses", func(t *testing.T) {
|
||||
captureLegacyUpgradeWarnings(t)
|
||||
beadsDir := writeDoltRootWorkspace(t, mode.metadata, "", "")
|
||||
|
||||
if err := guardLegacyUpgradeWorkspace(beadsDir); !isLegacyUpgradeRefusal(err) {
|
||||
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want migration refusal", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// The unreadable-witness admission is deliberately NOT hoisted: outside
|
||||
// server mode a .beads/dolt root is itself strong legacy evidence, and
|
||||
// TestLegacyUpgradeGuardRefusesOldDoltRootWithoutTrustingVersionWitness
|
||||
// pins that arm. Keep the boundary explicit so a later cleanup cannot widen
|
||||
// it by accident.
|
||||
t.Run("embedded mode still refuses an unreadable witness", func(t *testing.T) {
|
||||
captureLegacyUpgradeWarnings(t)
|
||||
beadsDir := writeDoltRootWorkspace(t, `{"backend":"dolt"}`, "", "not-a-version")
|
||||
|
||||
if err := guardLegacyUpgradeWorkspace(beadsDir); !isLegacyUpgradeRefusal(err) {
|
||||
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want migration refusal", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestLegacyUpgradeGuardSharedServerAdmissionSurvivesServerClassification keeps
|
||||
// the shared-server escape reachable now that a config.yaml `dolt.mode: server`
|
||||
// workspace resolves to the server arm. Before the hoist this admission lived
|
||||
// only in the embedded arm, so classifying the same workspace correctly would
|
||||
// have turned a workspace bd admits today into a refusal — trading one
|
||||
// false-refusal class for another.
|
||||
func TestLegacyUpgradeGuardSharedServerAdmissionSurvivesServerClassification(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
configYaml string
|
||||
version string
|
||||
wantRefusal bool
|
||||
}{
|
||||
{name: "config.yaml server mode without witness", configYaml: configYamlServerMode + "dolt.shared-server: true\n"},
|
||||
{name: "shared server only", configYaml: "dolt.shared-server: true\n"},
|
||||
{name: "config.yaml server mode with historical server witness",
|
||||
configYaml: configYamlServerMode + "dolt.shared-server: true\n", version: "0.62.0", wantRefusal: true},
|
||||
{name: "not shared and no witness", configYaml: configYamlServerMode, wantRefusal: true},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
captureLegacyUpgradeWarnings(t)
|
||||
beadsDir := writeDoltRootWorkspace(t, "", tt.configYaml, tt.version)
|
||||
|
||||
err := guardLegacyUpgradeWorkspace(beadsDir)
|
||||
if tt.wantRefusal && !isLegacyUpgradeRefusal(err) {
|
||||
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want migration refusal", err)
|
||||
}
|
||||
if !tt.wantRefusal && err != nil {
|
||||
t.Fatalf("guardLegacyUpgradeWorkspace() = %v, want nil", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -100,7 +100,17 @@ func TestLegacyUpgradeGuardRefusesBeforeMutatingHistoricalWorkspace(t *testing.T
|
|||
commandCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
cmd := exec.CommandContext(commandCtx, bd, tc.args...)
|
||||
cmd.Dir = repoDir
|
||||
cmd.Env = append(os.Environ(), "BD_DISABLE_METRICS=1", "BEADS_DOLT_AUTO_START=0")
|
||||
// Pin the mode inputs the guard now reads through
|
||||
// IsDoltServerMode: this child inherits os.Environ(), so
|
||||
// without them a developer's shell decides which refusal
|
||||
// text these historical layouts produce.
|
||||
cmd.Env = append(os.Environ(),
|
||||
"BD_DISABLE_METRICS=1",
|
||||
"BEADS_DOLT_AUTO_START=0",
|
||||
"BEADS_DOLT_SERVER_MODE=0",
|
||||
"BEADS_DOLT_SHARED_SERVER=0",
|
||||
"BEADS_DOLT_SERVER_HOST=",
|
||||
)
|
||||
var stdout, stderr bytes.Buffer
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
|
|
@ -478,6 +488,77 @@ 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
|
||||
// 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
|
||||
// config.yaml in front of the guard.
|
||||
//
|
||||
// The command still fails: the workspace points at a Dolt server that is not
|
||||
// running. That is the point — reaching the connection attempt means admission
|
||||
// succeeded and the workspace routed as a server workspace rather than being
|
||||
// refused or opened as a phantom embedded database.
|
||||
func TestLegacyGuardAdmitsConfigYamlServerWorkspace(t *testing.T) {
|
||||
bd := buildBDUnderTest(t)
|
||||
tests := []struct {
|
||||
name string
|
||||
version string
|
||||
wantLegacyRefusal bool
|
||||
}{
|
||||
{name: "current era witness", version: "1.3.0"},
|
||||
{name: "release candidate witness", version: "1.3.0-rc.1"},
|
||||
{name: "historical witness still refuses", version: "0.62.0", wantLegacyRefusal: true},
|
||||
{name: "missing witness still refuses", wantLegacyRefusal: true},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(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)
|
||||
}
|
||||
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 != "" {
|
||||
writeFile(t, filepath.Join(beadsDir, localVersionFile), []byte(tt.version+"\n"))
|
||||
}
|
||||
|
||||
commandCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
cmd := exec.CommandContext(commandCtx, bd, "list", "--json", "--limit", "0", "--all")
|
||||
cmd.Dir = repoDir
|
||||
cmd.Env = append(os.Environ(),
|
||||
"BD_DISABLE_METRICS=1",
|
||||
"BD_DISABLE_EVENT_FLUSH=1",
|
||||
"BEADS_DOLT_AUTO_START=0",
|
||||
"BEADS_DOLT_SERVER_PORT=59999",
|
||||
"BEADS_DOLT_SHARED_SERVER=0",
|
||||
"HOME="+t.TempDir(),
|
||||
)
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err == nil {
|
||||
t.Fatalf("bd list unexpectedly succeeded against an unreachable server:\n%s", output)
|
||||
}
|
||||
hasLegacyRefusal := strings.Contains(string(output), "explicit migration is required")
|
||||
if hasLegacyRefusal != tt.wantLegacyRefusal {
|
||||
t.Fatalf("bd list legacy refusal=%v, want %v:\n%s", hasLegacyRefusal, tt.wantLegacyRefusal, output)
|
||||
}
|
||||
if !tt.wantLegacyRefusal && !strings.Contains(string(output), "Dolt server") {
|
||||
t.Fatalf("admitted workspace did not route as a server workspace:\n%s", output)
|
||||
}
|
||||
if !tt.wantLegacyRefusal {
|
||||
if _, err := os.Stat(filepath.Join(beadsDir, "embeddeddolt")); !os.IsNotExist(err) {
|
||||
t.Fatalf("admitted server workspace created a phantom embedded database: %v", err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func legacyUpgradeTreeDigest(t *testing.T, root string) string {
|
||||
t.Helper()
|
||||
var entries []string
|
||||
|
|
|
|||
|
|
@ -8,7 +8,22 @@ import (
|
|||
"github.com/steveyegge/beads/internal/config"
|
||||
)
|
||||
|
||||
// pinLegacyUpgradeGuardEnv pins the process-global inputs the guard now reads
|
||||
// through configfile.IsDoltServerMode, so these tables assert the workspace
|
||||
// shape each case lays down rather than whatever mode the developer's shell
|
||||
// happens to select. CI already unsets these three
|
||||
// (scripts/ci/lib/test-env.sh), so the pins make a local `go test ./cmd/bd/`
|
||||
// match CI instead of changing what CI checks.
|
||||
func pinLegacyUpgradeGuardEnv(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Setenv("BEADS_TEST_IGNORE_REPO_CONFIG", "1")
|
||||
t.Setenv("BEADS_DOLT_SERVER_MODE", "0")
|
||||
t.Setenv("BEADS_DOLT_SHARED_SERVER", "0")
|
||||
t.Setenv("BEADS_DOLT_SERVER_HOST", "")
|
||||
}
|
||||
|
||||
func TestLegacyUpgradeGuardRefusesHistoricalLayoutsWithoutMutatingMetadata(t *testing.T) {
|
||||
pinLegacyUpgradeGuardEnv(t)
|
||||
tests := []struct {
|
||||
name string
|
||||
metadata string
|
||||
|
|
@ -77,6 +92,7 @@ func TestLegacyUpgradeGuardRefusesHistoricalLayoutsWithoutMutatingMetadata(t *te
|
|||
}
|
||||
|
||||
func TestLegacyUpgradeGuardMetadataLessSQLiteAndCurrentEmbeddedPrecedence(t *testing.T) {
|
||||
pinLegacyUpgradeGuardEnv(t)
|
||||
t.Run("metadata-less v091 vc database", func(t *testing.T) {
|
||||
beadsDir := t.TempDir()
|
||||
if err := os.WriteFile(filepath.Join(beadsDir, "vc.db"), []byte("SQLite format 3\x00"), 0o600); err != nil {
|
||||
|
|
@ -247,6 +263,7 @@ func TestLegacyUpgradeGuardMetadataLessSQLiteAndCurrentEmbeddedPrecedence(t *tes
|
|||
}
|
||||
|
||||
func TestLegacyUpgradeGuardServerSelectionBeatsStaleEmbeddedRepository(t *testing.T) {
|
||||
pinLegacyUpgradeGuardEnv(t)
|
||||
tests := []struct {
|
||||
name string
|
||||
version string
|
||||
|
|
@ -296,6 +313,7 @@ func TestLegacyUpgradeGuardServerSelectionBeatsStaleEmbeddedRepository(t *testin
|
|||
}
|
||||
|
||||
func TestLegacyUpgradeGuardRefusesOldDoltRootWithoutTrustingVersionWitness(t *testing.T) {
|
||||
pinLegacyUpgradeGuardEnv(t)
|
||||
tests := []struct {
|
||||
name string
|
||||
metadata string
|
||||
|
|
@ -331,6 +349,9 @@ func TestLegacyUpgradeGuardRefusesOldDoltRootWithoutTrustingVersionWitness(t *te
|
|||
}
|
||||
|
||||
func TestLegacyUpgradeGuardSharedServerAdmission(t *testing.T) {
|
||||
// The per-case BEADS_DOLT_SHARED_SERVER below is set after this and wins;
|
||||
// the pin is what keeps the other two mode inputs out of the decision.
|
||||
pinLegacyUpgradeGuardEnv(t)
|
||||
tests := []struct {
|
||||
name string
|
||||
metadata string
|
||||
|
|
@ -380,6 +401,7 @@ func TestLegacyUpgradeGuardSharedServerAdmission(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestLegacyUpgradeGuardLeavesCurrentDoltWorkspaceAlone(t *testing.T) {
|
||||
pinLegacyUpgradeGuardEnv(t)
|
||||
beadsDir := t.TempDir()
|
||||
metadata := `{"backend":"dolt","dolt_mode":"embedded"}`
|
||||
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), []byte(metadata), 0o600); err != nil {
|
||||
|
|
|
|||
|
|
@ -104,6 +104,7 @@ func writeSelectedServerWorkspace(t *testing.T, version string) string {
|
|||
}
|
||||
|
||||
func TestLegacyUpgradeGuardAdmitsNonReleaseVersionWitnesses(t *testing.T) {
|
||||
pinLegacyUpgradeGuardEnv(t)
|
||||
versions := []string{
|
||||
"v1.1.1-0.20260805093327-bf97b73749ac",
|
||||
"1.1.0",
|
||||
|
|
@ -128,6 +129,7 @@ func TestLegacyUpgradeGuardAdmitsNonReleaseVersionWitnesses(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestLegacyUpgradeGuardStillRefusesPreOneWorkspaces(t *testing.T) {
|
||||
pinLegacyUpgradeGuardEnv(t)
|
||||
versions := []string{
|
||||
"0.9.1",
|
||||
"v0.49.6",
|
||||
|
|
@ -150,6 +152,7 @@ func TestLegacyUpgradeGuardStillRefusesPreOneWorkspaces(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestLegacyUpgradeGuardRefusesWorkspaceWithoutAnyWitness(t *testing.T) {
|
||||
pinLegacyUpgradeGuardEnv(t)
|
||||
captureLegacyUpgradeWarnings(t)
|
||||
beadsDir := writeSelectedServerWorkspace(t, "")
|
||||
|
||||
|
|
@ -166,6 +169,7 @@ func TestLegacyUpgradeGuardRefusesWorkspaceWithoutAnyWitness(t *testing.T) {
|
|||
// absent witness must still refuse so the pre-1.0 safety invariant does not
|
||||
// relax.
|
||||
func TestLegacyUpgradeGuardWarnsInsteadOfRefusingPresentButBlankWitness(t *testing.T) {
|
||||
pinLegacyUpgradeGuardEnv(t)
|
||||
blankWitnesses := []struct {
|
||||
name string
|
||||
content []byte
|
||||
|
|
@ -248,6 +252,7 @@ func TestLegacyUpgradeVersionWitnessPresence(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestLegacyUpgradeGuardWarnsInsteadOfRefusingUnreadableWitness(t *testing.T) {
|
||||
pinLegacyUpgradeGuardEnv(t)
|
||||
warnings := captureLegacyUpgradeWarnings(t)
|
||||
beadsDir := writeSelectedServerWorkspace(t, "not-a-version")
|
||||
|
||||
|
|
@ -266,6 +271,7 @@ func TestLegacyUpgradeGuardWarnsInsteadOfRefusingUnreadableWitness(t *testing.T)
|
|||
// next command reads it cleanly. Only a stamp bd rewrites identically every
|
||||
// run (a Homebrew --HEAD build, GH#5603) can warn repeatedly.
|
||||
func TestLegacyUpgradeGuardWarningIsSelfHealing(t *testing.T) {
|
||||
pinLegacyUpgradeGuardEnv(t)
|
||||
warnings := captureLegacyUpgradeWarnings(t)
|
||||
beadsDir := writeSelectedServerWorkspace(t, "not-a-version")
|
||||
|
||||
|
|
@ -297,6 +303,7 @@ func TestLegacyUpgradeGuardWarningIsSelfHealing(t *testing.T) {
|
|||
// needs the shape recognizer in GH#5625 (anisoptera), which this does not
|
||||
// duplicate.
|
||||
func TestLegacyUpgradeGuardAdmitsBrewHeadStamp(t *testing.T) {
|
||||
pinLegacyUpgradeGuardEnv(t)
|
||||
for _, stamp := range []string{"HEAD-f925f3f", "HEAD", "HEAD-f925f3f_1"} {
|
||||
t.Run(stamp, func(t *testing.T) {
|
||||
captureLegacyUpgradeWarnings(t)
|
||||
|
|
|
|||
172
cmd/bd/linear.go
172
cmd/bd/linear.go
|
|
@ -215,9 +215,6 @@ func init() {
|
|||
}
|
||||
|
||||
func runLinearSync(cmd *cobra.Command, args []string) error {
|
||||
if usesProxiedServer() {
|
||||
return HandleErrorRespectJSON("linear sync is not supported in proxied-server mode")
|
||||
}
|
||||
evt := metrics.NewCommandEvent("linear-sync")
|
||||
defer func() {
|
||||
if c := metrics.Global(); c != nil {
|
||||
|
|
@ -312,16 +309,17 @@ func runLinearSync(cmd *cobra.Command, args []string) error {
|
|||
return HandleErrorRespectJSON("--milestones only applies when pulling from Linear")
|
||||
}
|
||||
|
||||
if err := ensureStoreActive(); err != nil {
|
||||
trackerStore, err := trackerStoreForCommand(rootCtx)
|
||||
if err != nil {
|
||||
return HandleErrorRespectJSON("database not available: %v", err)
|
||||
}
|
||||
|
||||
if err := validateLinearConfig(cliTeams); err != nil {
|
||||
if err := validateLinearConfigForStore(trackerStore, cliTeams); err != nil {
|
||||
return HandleErrorRespectJSON("%v", err)
|
||||
}
|
||||
|
||||
ctx := rootCtx
|
||||
teamIDs := getLinearTeamIDs(ctx, cliTeams)
|
||||
teamIDs := getLinearTeamIDsForStore(ctx, trackerStore, cliTeams)
|
||||
willPush := push || !pull
|
||||
|
||||
if willPush && len(teamIDs) > 1 && len(cliTeams) == 0 {
|
||||
|
|
@ -331,7 +329,7 @@ func runLinearSync(cmd *cobra.Command, args []string) error {
|
|||
|
||||
lt := &linear.Tracker{}
|
||||
lt.SetTeamIDs(teamIDs)
|
||||
if err := lt.Init(ctx, store); err != nil {
|
||||
if err := lt.Init(ctx, trackerStore); err != nil {
|
||||
return HandleErrorRespectJSON("initializing Linear tracker: %v", err)
|
||||
}
|
||||
if willPush {
|
||||
|
|
@ -340,11 +338,11 @@ func runLinearSync(cmd *cobra.Command, args []string) error {
|
|||
}
|
||||
}
|
||||
|
||||
engine := tracker.NewEngine(lt, store, actor)
|
||||
engine := tracker.NewEngine(lt, trackerStore, actor)
|
||||
engine.OnMessage = func(msg string) { fmt.Println(" " + msg) }
|
||||
engine.OnWarning = func(msg string) { fmt.Fprintf(os.Stderr, "Warning: %s\n", msg) }
|
||||
|
||||
engine.PullHooks = buildLinearPullHooks(ctx, linearPullHookOptions{
|
||||
engine.PullHooks = buildLinearPullHooksForStore(ctx, trackerStore, linearPullHookOptions{
|
||||
Milestones: milestones,
|
||||
DryRun: dryRun,
|
||||
Actor: actor,
|
||||
|
|
@ -365,7 +363,7 @@ func runLinearSync(cmd *cobra.Command, args []string) error {
|
|||
for _, t := range excludeTypes {
|
||||
opts.ExcludeTypes = append(opts.ExcludeTypes, types.IssueType(strings.ToLower(t)))
|
||||
}
|
||||
applyLinearExcludeIDConfig(ctx, store, &opts)
|
||||
applyLinearExcludeIDConfig(ctx, trackerStore, &opts)
|
||||
if !includeEphemeral {
|
||||
opts.ExcludeEphemeral = true
|
||||
}
|
||||
|
|
@ -375,7 +373,7 @@ func runLinearSync(cmd *cobra.Command, args []string) error {
|
|||
}
|
||||
allowProjectCreates := opts.ParentID != "" || len(opts.IssueIDs) > 0
|
||||
|
||||
engine.PushHooks = buildLinearPushHooks(ctx, lt, allowProjectCreates)
|
||||
engine.PushHooks = buildLinearPushHooksForStore(ctx, trackerStore, lt, allowProjectCreates)
|
||||
|
||||
if preferLocal {
|
||||
opts.ConflictResolution = tracker.ConflictLocal
|
||||
|
|
@ -420,7 +418,7 @@ func runLinearSync(cmd *cobra.Command, args []string) error {
|
|||
// receives opts by value.
|
||||
effectivePush := push || (!push && !pull)
|
||||
if effectivePush && result.Success && !syncIsScoped(&opts) {
|
||||
reconcileLinearParents(ctx, lt, dryRun, jsonOutput, &result.Warnings)
|
||||
reconcileLinearParentsForStore(ctx, trackerStore, lt, dryRun, jsonOutput, &result.Warnings)
|
||||
}
|
||||
|
||||
// Record successful pull timestamp
|
||||
|
|
@ -480,12 +478,12 @@ type linearPullHookOptions struct {
|
|||
|
||||
// buildLinearPullHooks creates PullHooks for Linear-specific pull behavior.
|
||||
func buildLinearPullHooks(ctx context.Context, opts linearPullHookOptions) *tracker.PullHooks {
|
||||
return buildLinearPullHooksForStore(ctx, store, opts)
|
||||
return buildLinearPullHooksForStore(ctx, tracker.NewStore(store), opts)
|
||||
}
|
||||
|
||||
func buildLinearPullHooksForStore(ctx context.Context, st storage.Storage, opts linearPullHookOptions) *tracker.PullHooks {
|
||||
idMode := getLinearIDMode(ctx)
|
||||
hashLength := getLinearHashLength(ctx)
|
||||
func buildLinearPullHooksForStore(ctx context.Context, st tracker.Store, opts linearPullHookOptions) *tracker.PullHooks {
|
||||
idMode := getLinearIDModeForStore(ctx, st)
|
||||
hashLength := getLinearHashLengthForStore(ctx, st)
|
||||
|
||||
hooks := &tracker.PullHooks{}
|
||||
hookActor := opts.Actor
|
||||
|
|
@ -573,7 +571,7 @@ func isLinearMilestoneExternalRef(ref string) bool {
|
|||
return strings.HasPrefix(strings.TrimSpace(ref), linearMilestoneExternalRefPrefix)
|
||||
}
|
||||
|
||||
func ensureLinearMilestoneEpic(ctx context.Context, st storage.Storage, ms *linear.ProjectMilestone, actor string, generateID func(context.Context, *types.Issue) error) (string, error) {
|
||||
func ensureLinearMilestoneEpic(ctx context.Context, st tracker.Store, ms *linear.ProjectMilestone, actor string, generateID func(context.Context, *types.Issue) error) (string, error) {
|
||||
milestoneID := strings.TrimSpace(ms.ID)
|
||||
if milestoneID == "" {
|
||||
return "", fmt.Errorf("Linear project milestone is missing id")
|
||||
|
|
@ -644,7 +642,7 @@ func ensureLinearMilestoneEpic(ctx context.Context, st storage.Storage, ms *line
|
|||
return ref, nil
|
||||
}
|
||||
|
||||
func findLinearMilestoneEpic(ctx context.Context, st storage.Storage, ref, milestoneID, title string) (*types.Issue, error) {
|
||||
func findLinearMilestoneEpic(ctx context.Context, st tracker.Store, ref, milestoneID, title string) (*types.Issue, error) {
|
||||
if existing, err := st.GetIssueByExternalRef(ctx, ref); err == nil {
|
||||
return existing, nil
|
||||
} else if !errors.Is(err, storage.ErrNotFound) {
|
||||
|
|
@ -747,6 +745,10 @@ func isLinearMilestoneIssue(issue *types.Issue) bool {
|
|||
|
||||
// buildLinearPushHooks creates PushHooks for Linear-specific push behavior.
|
||||
func buildLinearPushHooks(ctx context.Context, lt *linear.Tracker, allowProjectCreates bool) *tracker.PushHooks {
|
||||
return buildLinearPushHooksForStore(ctx, tracker.NewStore(store), lt, allowProjectCreates)
|
||||
}
|
||||
|
||||
func buildLinearPushHooksForStore(ctx context.Context, st tracker.Store, lt *linear.Tracker, allowProjectCreates bool) *tracker.PushHooks {
|
||||
config := lt.MappingConfig()
|
||||
var labelOnce sync.Once
|
||||
var labelCache *linear.LabelCache
|
||||
|
|
@ -790,7 +792,7 @@ func buildLinearPushHooks(ctx context.Context, lt *linear.Tracker, allowProjectC
|
|||
if isLinearMilestoneIssue(issue) {
|
||||
return false
|
||||
}
|
||||
if projectID, _ := store.GetConfig(ctx, "linear.project_id"); projectID != "" {
|
||||
if projectID, _ := st.GetConfig(ctx, "linear.project_id"); projectID != "" {
|
||||
if issue.ExternalRef == nil || strings.TrimSpace(*issue.ExternalRef) == "" {
|
||||
if !allowProjectCreates {
|
||||
return false
|
||||
|
|
@ -799,7 +801,7 @@ func buildLinearPushHooks(ctx context.Context, lt *linear.Tracker, allowProjectC
|
|||
}
|
||||
|
||||
// Apply push prefix filtering if configured
|
||||
pushPrefix, _ := store.GetConfig(ctx, "linear.push_prefix")
|
||||
pushPrefix, _ := st.GetConfig(ctx, "linear.push_prefix")
|
||||
if pushPrefix == "" {
|
||||
return true
|
||||
}
|
||||
|
|
@ -816,9 +818,6 @@ func buildLinearPushHooks(ctx context.Context, lt *linear.Tracker, allowProjectC
|
|||
}
|
||||
|
||||
func runLinearStatus(cmd *cobra.Command, args []string) error {
|
||||
if usesProxiedServer() {
|
||||
return HandleErrorRespectJSON("linear status is not supported in proxied-server mode")
|
||||
}
|
||||
evt := metrics.NewCommandEvent("linear-status")
|
||||
defer func() {
|
||||
if c := metrics.Global(); c != nil {
|
||||
|
|
@ -828,20 +827,21 @@ func runLinearStatus(cmd *cobra.Command, args []string) error {
|
|||
|
||||
ctx := rootCtx
|
||||
|
||||
if err := ensureStoreActive(); err != nil {
|
||||
trackerStore, err := trackerStoreForCommand(rootCtx)
|
||||
if err != nil {
|
||||
return HandleErrorRespectJSON("%v", err)
|
||||
}
|
||||
|
||||
apiKey, _ := getLinearConfig(ctx, "linear.api_key")
|
||||
oauthClientID, _ := getLinearConfig(ctx, "linear.oauth_client_id")
|
||||
oauthClientSecret, _ := getLinearConfig(ctx, "linear.oauth_client_secret")
|
||||
teamIDs := getLinearTeamIDs(ctx, nil)
|
||||
lastSync, _ := store.GetConfig(ctx, "linear.last_sync")
|
||||
apiKey, _ := getLinearConfigForStore(ctx, trackerStore, "linear.api_key")
|
||||
oauthClientID, _ := getLinearConfigForStore(ctx, trackerStore, "linear.oauth_client_id")
|
||||
oauthClientSecret, _ := getLinearConfigForStore(ctx, trackerStore, "linear.oauth_client_secret")
|
||||
teamIDs := getLinearTeamIDsForStore(ctx, trackerStore, nil)
|
||||
lastSync, _ := trackerStore.GetConfig(ctx, "linear.last_sync")
|
||||
|
||||
hasOAuth := oauthClientID != "" && oauthClientSecret != ""
|
||||
configured := (apiKey != "" || hasOAuth) && len(teamIDs) > 0
|
||||
|
||||
allIssues, err := store.SearchIssues(ctx, "", types.IssueFilter{})
|
||||
allIssues, err := trackerStore.SearchIssues(ctx, "", types.IssueFilter{})
|
||||
if err != nil {
|
||||
return HandleErrorRespectJSON("%v", err)
|
||||
}
|
||||
|
|
@ -932,9 +932,6 @@ func runLinearStatus(cmd *cobra.Command, args []string) error {
|
|||
}
|
||||
|
||||
func runLinearTeams(cmd *cobra.Command, args []string) error {
|
||||
if usesProxiedServer() {
|
||||
return HandleErrorRespectJSON("linear teams is not supported in proxied-server mode")
|
||||
}
|
||||
evt := metrics.NewCommandEvent("linear-teams")
|
||||
defer func() {
|
||||
if c := metrics.Global(); c != nil {
|
||||
|
|
@ -944,7 +941,19 @@ func runLinearTeams(cmd *cobra.Command, args []string) error {
|
|||
|
||||
ctx := rootCtx
|
||||
|
||||
client, err := buildLinearClient(ctx, "")
|
||||
// Team discovery is API-only and must not initialize or probe a local
|
||||
// beads store. In proxied mode, read config through the existing UOW seam.
|
||||
var configStore tracker.Store
|
||||
var err error
|
||||
if usesProxiedServer() {
|
||||
configStore, err = trackerStoreForCommand(ctx)
|
||||
if err != nil {
|
||||
return HandleError("database not available: %v", err)
|
||||
}
|
||||
} else if store != nil {
|
||||
configStore = tracker.NewStore(store)
|
||||
}
|
||||
client, err := buildLinearClientAPIOnly(ctx, "", configStore)
|
||||
if err != nil {
|
||||
return HandleError("%v", err)
|
||||
}
|
||||
|
|
@ -1000,19 +1009,19 @@ func isValidUUID(s string) bool {
|
|||
// validateLinearConfig checks that required Linear configuration is present.
|
||||
// cliTeams is the list of team IDs from the --team flag (may be nil).
|
||||
func validateLinearConfig(cliTeams []string) error {
|
||||
if err := ensureStoreActive(); err != nil {
|
||||
return fmt.Errorf("database not available: %w", err)
|
||||
}
|
||||
return validateLinearConfigForStore(tracker.NewStore(store), cliTeams)
|
||||
}
|
||||
|
||||
func validateLinearConfigForStore(st tracker.Store, cliTeams []string) error {
|
||||
ctx := rootCtx
|
||||
|
||||
// Accept either OAuth credentials or API key.
|
||||
oauthClientID, _ := getLinearConfig(ctx, "linear.oauth_client_id")
|
||||
oauthClientSecret, _ := getLinearConfig(ctx, "linear.oauth_client_secret")
|
||||
oauthClientID, _ := getLinearConfigForStore(ctx, st, "linear.oauth_client_id")
|
||||
oauthClientSecret, _ := getLinearConfigForStore(ctx, st, "linear.oauth_client_secret")
|
||||
hasOAuth := oauthClientID != "" && oauthClientSecret != ""
|
||||
|
||||
if !hasOAuth {
|
||||
apiKey, _ := getLinearConfig(ctx, "linear.api_key")
|
||||
apiKey, _ := getLinearConfigForStore(ctx, st, "linear.api_key")
|
||||
if apiKey == "" {
|
||||
return fmt.Errorf("Linear authentication not configured\n" +
|
||||
"Options:\n" +
|
||||
|
|
@ -1021,7 +1030,7 @@ func validateLinearConfig(cliTeams []string) error {
|
|||
}
|
||||
}
|
||||
|
||||
teamIDs := getLinearTeamIDs(ctx, cliTeams)
|
||||
teamIDs := getLinearTeamIDsForStore(ctx, st, cliTeams)
|
||||
if len(teamIDs) == 0 {
|
||||
return fmt.Errorf("no Linear team ID configured\nRun: bd config set linear.team_id \"TEAM_ID\"\nOr: bd config set linear.team_ids \"TEAM_ID1,TEAM_ID2\"\nOr: export LINEAR_TEAM_ID=TEAM_ID")
|
||||
}
|
||||
|
|
@ -1048,6 +1057,10 @@ func maskAPIKey(key string) string {
|
|||
// Priority: environment variable > project config.
|
||||
// Env vars take precedence so CI workers can override config without modifying config.yaml.
|
||||
func getLinearConfig(ctx context.Context, key string) (value string, source string) {
|
||||
return getLinearConfigForStore(ctx, tracker.NewStore(store), key)
|
||||
}
|
||||
|
||||
func getLinearConfigForStore(ctx context.Context, st tracker.Store, key string) (value string, source string) {
|
||||
// Secret keys (e.g. linear.api_key) are stored in config.yaml, not the
|
||||
// Dolt database, to avoid leaking secrets when pushing to remotes.
|
||||
// Env vars are checked first so that LINEAR_OAUTH_CLIENT_ID/SECRET etc.
|
||||
|
|
@ -1066,8 +1079,8 @@ func getLinearConfig(ctx context.Context, key string) (value string, source stri
|
|||
}
|
||||
|
||||
// Try to read from store (works in direct mode)
|
||||
if store != nil {
|
||||
value, _ = store.GetConfig(ctx, key) // Best effort: empty value is valid fallback
|
||||
if st != nil {
|
||||
value, _ = st.GetConfig(ctx, key) // Best effort: empty value is valid fallback
|
||||
if value != "" {
|
||||
return value, "project config (bd config)"
|
||||
}
|
||||
|
|
@ -1115,8 +1128,12 @@ func linearConfigToEnvVar(key string) string {
|
|||
// getLinearTeamIDs resolves the effective team IDs from all config sources.
|
||||
// Precedence: cliTeams (--team flag) > linear.team_ids > LINEAR_TEAM_IDS > linear.team_id > LINEAR_TEAM_ID
|
||||
func getLinearTeamIDs(ctx context.Context, cliTeams []string) []string {
|
||||
pluralVal, _ := getLinearConfig(ctx, "linear.team_ids")
|
||||
singularVal, _ := getLinearConfig(ctx, "linear.team_id")
|
||||
return getLinearTeamIDsForStore(ctx, tracker.NewStore(store), cliTeams)
|
||||
}
|
||||
|
||||
func getLinearTeamIDsForStore(ctx context.Context, st tracker.Store, cliTeams []string) []string {
|
||||
pluralVal, _ := getLinearConfigForStore(ctx, st, "linear.team_ids")
|
||||
singularVal, _ := getLinearConfigForStore(ctx, st, "linear.team_id")
|
||||
return tracker.ResolveProjectIDs(cliTeams, pluralVal, singularVal)
|
||||
}
|
||||
|
||||
|
|
@ -1189,6 +1206,40 @@ func buildLinearClient(ctx context.Context, teamID string) (*linear.Client, erro
|
|||
return linear.NewClient(apiKey, teamID), nil
|
||||
}
|
||||
|
||||
func buildLinearClientAPIOnly(ctx context.Context, teamID string, st tracker.Store) (*linear.Client, error) {
|
||||
oauthClientID := os.Getenv("LINEAR_OAUTH_CLIENT_ID")
|
||||
oauthClientSecret := os.Getenv("LINEAR_OAUTH_CLIENT_SECRET")
|
||||
if oauthClientID == "" {
|
||||
oauthClientID = config.GetString("linear.oauth_client_id")
|
||||
}
|
||||
if oauthClientSecret == "" {
|
||||
oauthClientSecret = config.GetString("linear.oauth_client_secret")
|
||||
}
|
||||
// Select the auth branch first and apply linear.api_endpoint once, after
|
||||
// it — the shape Tracker.Init uses. Returning the OAuth client inline
|
||||
// would leave this helper asymmetric between its own two branches, with a
|
||||
// custom endpoint honored for an API key and ignored for OAuth.
|
||||
var client *linear.Client
|
||||
if oauthClientID != "" && oauthClientSecret != "" {
|
||||
client = linear.NewOAuthClient(linear.OAuthConfig{ClientID: oauthClientID, ClientSecret: oauthClientSecret}, teamID)
|
||||
} else {
|
||||
apiKey := os.Getenv("LINEAR_API_KEY")
|
||||
if apiKey == "" {
|
||||
apiKey = config.GetString("linear.api_key")
|
||||
}
|
||||
if apiKey == "" {
|
||||
return nil, fmt.Errorf("Linear authentication not configured")
|
||||
}
|
||||
client = linear.NewClient(apiKey, teamID)
|
||||
}
|
||||
if st != nil {
|
||||
if endpoint, _ := st.GetConfig(ctx, "linear.api_endpoint"); endpoint != "" {
|
||||
client = client.WithEndpoint(endpoint)
|
||||
}
|
||||
}
|
||||
return client, nil
|
||||
}
|
||||
|
||||
// storeConfigLoader adapts the store to the linear.ConfigLoader interface.
|
||||
type storeConfigLoader struct {
|
||||
ctx context.Context
|
||||
|
|
@ -1209,7 +1260,11 @@ func loadLinearMappingConfig(ctx context.Context) *linear.MappingConfig {
|
|||
// getLinearIDMode returns the configured ID mode for Linear imports.
|
||||
// Supported values: "hash" (default) or "db".
|
||||
func getLinearIDMode(ctx context.Context) string {
|
||||
mode, _ := getLinearConfig(ctx, "linear.id_mode")
|
||||
return getLinearIDModeForStore(ctx, tracker.NewStore(store))
|
||||
}
|
||||
|
||||
func getLinearIDModeForStore(ctx context.Context, st tracker.Store) string {
|
||||
mode, _ := getLinearConfigForStore(ctx, st, "linear.id_mode")
|
||||
mode = strings.ToLower(strings.TrimSpace(mode))
|
||||
if mode == "" {
|
||||
return "hash"
|
||||
|
|
@ -1244,7 +1299,11 @@ func applyLinearExcludeIDConfig(ctx context.Context, reader configReader, opts *
|
|||
// getLinearHashLength returns the configured hash length for Linear imports.
|
||||
// Values are clamped to the supported range 3-8.
|
||||
func getLinearHashLength(ctx context.Context) int {
|
||||
raw, _ := getLinearConfig(ctx, "linear.hash_length")
|
||||
return getLinearHashLengthForStore(ctx, tracker.NewStore(store))
|
||||
}
|
||||
|
||||
func getLinearHashLengthForStore(ctx context.Context, st tracker.Store) int {
|
||||
raw, _ := getLinearConfigForStore(ctx, st, "linear.hash_length")
|
||||
if raw == "" {
|
||||
return 6
|
||||
}
|
||||
|
|
@ -1315,10 +1374,14 @@ func syncIsScoped(opts *tracker.SyncOptions) bool {
|
|||
// Warnings (per-link failures, missing refs) are appended to the engine's
|
||||
// warning slice so the user sees them in the standard sync output.
|
||||
func reconcileLinearParents(ctx context.Context, lt *linear.Tracker, dryRun, jsonOutput bool, warnings *[]string) {
|
||||
if lt == nil || store == nil {
|
||||
reconcileLinearParentsForStore(ctx, tracker.NewStore(store), lt, dryRun, jsonOutput, warnings)
|
||||
}
|
||||
|
||||
func reconcileLinearParentsForStore(ctx context.Context, st tracker.Store, lt *linear.Tracker, dryRun, jsonOutput bool, warnings *[]string) {
|
||||
if lt == nil || st == nil {
|
||||
return
|
||||
}
|
||||
links, err := buildLinearParentLinks(ctx, lt)
|
||||
links, err := buildLinearParentLinksForStore(ctx, st, lt)
|
||||
if err != nil {
|
||||
*warnings = append(*warnings, fmt.Sprintf("parent reconcile: building link set failed: %v", err))
|
||||
return
|
||||
|
|
@ -1364,7 +1427,14 @@ func reconcileLinearParents(ctx context.Context, lt *linear.Tracker, dryRun, jso
|
|||
// they'll get picked up on a subsequent sync once the parent has an
|
||||
// external_ref.
|
||||
func buildLinearParentLinks(ctx context.Context, lt *linear.Tracker) ([]linear.ParentLink, error) {
|
||||
issues, err := store.SearchIssues(ctx, "", types.IssueFilter{})
|
||||
return buildLinearParentLinksForStore(ctx, tracker.NewStore(store), lt)
|
||||
}
|
||||
|
||||
func buildLinearParentLinksForStore(ctx context.Context, st tracker.Store, lt *linear.Tracker) ([]linear.ParentLink, error) {
|
||||
if st == nil {
|
||||
return nil, fmt.Errorf("database not available")
|
||||
}
|
||||
issues, err := st.SearchIssues(ctx, "", types.IssueFilter{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -1396,7 +1466,7 @@ func buildLinearParentLinks(ctx context.Context, lt *linear.Tracker) ([]linear.P
|
|||
if !ok {
|
||||
continue
|
||||
}
|
||||
deps, err := store.GetDependenciesWithMetadata(ctx, issue.ID)
|
||||
deps, err := st.GetDependenciesWithMetadata(ctx, issue.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("loading deps for %s: %w", issue.ID, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import (
|
|||
|
||||
func runListProxiedServer(cmd *cobra.Command, ctx context.Context, out io.Writer, in listInput) error {
|
||||
if in.repoOverrideSet {
|
||||
return errors.New("--repo is not supported with --proxied-server")
|
||||
return HandleProxyCapabilityError(AssertProxyCapability(ProxyModeProxied, ProxyCapRepo))
|
||||
}
|
||||
switch {
|
||||
case in.watchMode:
|
||||
|
|
|
|||
242
cmd/bd/main.go
242
cmd/bd/main.go
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
|
|
@ -110,6 +111,13 @@ var (
|
|||
// an intentional empty JSONL artifact instead of treating it as ambiguous.
|
||||
commandMayEmptyJSONLExport atomic.Bool
|
||||
|
||||
// commandDeletedIssueIDs is the in-process handoff from the delete
|
||||
// commands to post-run auto-export: ids this command hard-deleted are
|
||||
// PROVEN gone, so the export's orphan guard skips them instead of
|
||||
// mistaking a deliberate delete for a torn store and refusing forever
|
||||
// (GH#5896). See deletedIssueIDSet for why it is not persisted.
|
||||
commandDeletedIssueIDs deletedIssueIDSet
|
||||
|
||||
// commandDidExplicitDoltCommit is set when a command already created a Dolt commit
|
||||
// explicitly (e.g., bd sync in dolt-native mode, hook flows, bd vc commit).
|
||||
// This prevents a redundant auto-commit attempt in PersistentPostRun.
|
||||
|
|
@ -124,6 +132,15 @@ var (
|
|||
// This is used for tip-commit message formatting.
|
||||
commandTipIDsShown map[string]struct{}
|
||||
|
||||
// commandFreeze is the migration-freeze lookup for this invocation,
|
||||
// resolved once in PersistentPreRunE (dc-6jaq). Both hooks read it: the
|
||||
// pre-run gate refuses writes from it, and PersistentPostRunE skips its
|
||||
// own maintenance writes — auto-commit, tip metadata, backup, export,
|
||||
// push — so a read command run during a freeze does not leave a new Dolt
|
||||
// commit in the store being migrated. Zero value means "not frozen",
|
||||
// which is the right default for the paths that never resolve it.
|
||||
commandFreeze migration.Result
|
||||
|
||||
// commandSpan is the root OTel span for the current command execution.
|
||||
// All storage and AI spans are nested as children of this span.
|
||||
commandSpan oteltrace.Span
|
||||
|
|
@ -321,6 +338,74 @@ func isForcedMigrate(cmd *cobra.Command) bool {
|
|||
return force
|
||||
}
|
||||
|
||||
// printGlobalDatabaseConsentHint adds the one thing the gate's own block
|
||||
// cannot know: which database this invocation was aimed at. Under --global the
|
||||
// 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) {
|
||||
if !globalFlag {
|
||||
return
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
// renderTypedOpenError prints the actionable block for the store-open failures
|
||||
// that carry one, honoring --json, and reports whether it handled err. A false
|
||||
// return means the caller should fall back to its own generic message.
|
||||
//
|
||||
// Every open path needs this — the Dolt store, the proxied unit-of-work
|
||||
// provider, and `bd serve`'s startup. The proxied one used to render every
|
||||
// failure as `%v` inside "failed to open uow provider", which turned a
|
||||
// multi-line rebuild or migrate-consent guide into one truncated line.
|
||||
func renderTypedOpenError(err error) bool {
|
||||
// Schema skew gets dedicated UX with actionable rebuild instructions.
|
||||
var skewErr *schema.SchemaSkewError
|
||||
if errors.As(err, &skewErr) {
|
||||
if jsonOutput {
|
||||
handleSchemaSkewJSON(skewErr)
|
||||
} else {
|
||||
fmt.Fprint(os.Stderr, skewErr.UserMessage())
|
||||
}
|
||||
return true
|
||||
}
|
||||
// #4259 / #5920: the migrate gate blocks a silent in-place migration and
|
||||
// tells the operator to migrate, adopt, or consent.
|
||||
var gateErr *schema.RemoteMigrateGateError
|
||||
if errors.As(err, &gateErr) {
|
||||
if jsonOutput {
|
||||
handleRemoteMigrateGateJSON(gateErr)
|
||||
} else {
|
||||
fmt.Fprint(os.Stderr, gateErr.UserMessage())
|
||||
printGlobalDatabaseConsentHint(os.Stderr)
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// isSchemaMigrateVerb reports whether cmd is `bd migrate schema` — the one
|
||||
// invocation in which the operator asked for a schema migration by name. That
|
||||
// request is the consent the shared-store gate wants for a database with no
|
||||
// remote (#5920); see schema.SetSharedMigrateConsent.
|
||||
//
|
||||
// Deliberately just this one command, not the `bd migrate` tree. Bare
|
||||
// `bd migrate` reconciles version/repo-id/clone-id metadata and never applies
|
||||
// a migration itself, and its flag modes are further from schema work still:
|
||||
// `bd migrate --update-repo-id` is repo-fingerprint surgery after a git remote
|
||||
// change, and treating it as consent would let a repo-ID update promote the
|
||||
// schema for every co-resident client as a side effect. `bd migrate sync`,
|
||||
// `bd migrate hooks`, and the mode-switch verbs consent to nothing either.
|
||||
// The operator who does want to migrate has the verb this names, and
|
||||
// `--force` still unlocks from either migrate command.
|
||||
func isSchemaMigrateVerb(cmd *cobra.Command) bool {
|
||||
return cmd == migrateSchemaCmd
|
||||
}
|
||||
|
||||
// forcedMigratePreviewFlag returns the name of a preview flag (--dry-run,
|
||||
// --inspect) that conflicts with --force on a forced migrate invocation, or ""
|
||||
// when there is no conflict. The combination must be rejected BEFORE the store
|
||||
|
|
@ -892,9 +977,11 @@ var rootCmd = &cobra.Command{
|
|||
// Reset per-command write tracking (used by Dolt auto-commit).
|
||||
commandDidWrite.Store(false)
|
||||
commandMayEmptyJSONLExport.Store(false)
|
||||
commandDeletedIssueIDs.reset()
|
||||
commandDidExplicitDoltCommit = false
|
||||
commandDidWriteTipMetadata = false
|
||||
commandTipIDsShown = make(map[string]struct{})
|
||||
commandFreeze = migration.Result{}
|
||||
|
||||
// Set up signal-aware context with batch commit flush on shutdown.
|
||||
// Unlike signal.NotifyContext, this also handles SIGHUP and flushes
|
||||
|
|
@ -1169,10 +1256,29 @@ var rootCmd = &cobra.Command{
|
|||
fmt.Fprintf(os.Stderr, "warning: %v\n", err)
|
||||
}
|
||||
}
|
||||
if cmdName == "doctor" && usesProxiedServer() {
|
||||
// Refuse only on a real refusal. validateProxyMaintenance...
|
||||
// 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 {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if beadsDir == "" {
|
||||
beadsDir = beads.FindBeadsDir()
|
||||
}
|
||||
if err := guardLegacyNoStoreCommand(cmd, beadsDir); err != nil {
|
||||
isMigrationCommand := false
|
||||
for current := cmd; current != nil; current = current.Parent() {
|
||||
if current.Name() == "migrate" {
|
||||
isMigrationCommand = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if isMigrationCommand {
|
||||
return HandleProxyCapabilityError(&ProxyCapabilityError{Code: "proxy.migrate.invalid_state", Message: err.Error(), ExitCode: 1, Mutates: false})
|
||||
}
|
||||
return HandleError("%v", err)
|
||||
}
|
||||
if _, err := getDoltAutoCommitMode(); err != nil {
|
||||
|
|
@ -1357,9 +1463,29 @@ var rootCmd = &cobra.Command{
|
|||
if cfgErr != nil {
|
||||
return HandleError("failed to load beads config from %s: %v (refusing to fall back to the embedded store; fix or restore metadata.json and retry)", beadsDir, cfgErr)
|
||||
}
|
||||
if backendErr := validateConfiguredBackend(cfg); backendErr != nil {
|
||||
if backendErr := validateConfiguredBackend(cfg, beadsDir); backendErr != nil {
|
||||
return HandleError("%v", backendErr)
|
||||
}
|
||||
// Reject proxy capability combinations before any workspace side effect
|
||||
// (version tracking, migration, auto-start, or provider construction).
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// The proxied provider cannot guarantee strict read-only semantics. Refuse
|
||||
// before provider construction so no connection, migration, or mutation
|
||||
// is attempted; expose the same stable capability code as other proxy
|
||||
// front-door refusals.
|
||||
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")
|
||||
}
|
||||
|
|
@ -1381,7 +1507,7 @@ var rootCmd = &cobra.Command{
|
|||
policy := effectiveRootStorePolicy(cmd.Name(), readonlyMode)
|
||||
useReadOnly := policy.readOnly || previewMode
|
||||
|
||||
// dc-6jaq: consult the MIGRATION-FREEZE sentinel here, before any of
|
||||
// dc-6jaq: consult the migration freeze marker here, before any of
|
||||
// this hook's own store-touching side effects — trackBdVersion below
|
||||
// (writes .local_version), autoMigrateOnVersionBump (opens its own
|
||||
// store connection and can apply a schema migration), and
|
||||
|
|
@ -1395,13 +1521,27 @@ var rootCmd = &cobra.Command{
|
|||
// "write" commands to drift out of sync with the one useReadOnly is
|
||||
// built from. An explicit --dry-run/--inspect preview also sets
|
||||
// useReadOnly and so skips this early gate the same way, but is NOT
|
||||
// exempt overall: CheckReadonly's own freeze check runs again,
|
||||
// unconditionally, at the per-command chokepoint once RunE is
|
||||
// reached, and that later call has no preview awareness — so a
|
||||
// preview on a frozen town still exits 1 there, fail-closed, same as
|
||||
// strict --readonly already blocks `create --dry-run` today.
|
||||
// exempt overall: the per-command chokepoint checks again once RunE
|
||||
// is reached, with no preview awareness — CheckReadonly for the ~120
|
||||
// commands that call it, and runImport's own call for `bd import
|
||||
// --dry-run`, which is not one of them. So a preview on a frozen
|
||||
// workspace still exits ExitMigrationFrozen there, fail-closed, same
|
||||
// as strict --readonly already blocks `create --dry-run` today.
|
||||
// Returning the refusal rather than exiting is load-bearing: the
|
||||
// gates acquired above are released by this hook's deferred cleanup,
|
||||
// which os.Exit would skip.
|
||||
//
|
||||
// One lookup answers the whole invocation: the walk is a stat per
|
||||
// ancestor of both the cwd and the resolved workspace, and resolving
|
||||
// it twice a statement apart would not only pay for it twice but let
|
||||
// the two readings disagree about a marker that appeared or vanished
|
||||
// in between (write allowed but maintenance skipped, or the reverse).
|
||||
// PostRunE reads the same answer via commandFreeze.
|
||||
commandFreeze = migration.Find(beadsDir)
|
||||
if !useReadOnly {
|
||||
CheckMigrationFreeze(strings.TrimPrefix(cmd.CommandPath(), cmd.Root().Name()+" "))
|
||||
if err := migrationFreezeGate(cmd, strings.TrimPrefix(cmd.CommandPath(), cmd.Root().Name()+" "), commandFreeze); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// dc-6jaq (review round 2, ask #1): a command classified read-only —
|
||||
|
|
@ -1411,14 +1551,12 @@ var rootCmd = &cobra.Command{
|
|||
// writes against the (possibly frozen) store, run regardless of the
|
||||
// command's own classification — so "the command is a read" must not
|
||||
// imply "these side effects may still run". Reproduced pre-fix:
|
||||
// freeze the town, seed .local_version with a stale version, run
|
||||
// freeze the workspace, seed .local_version with a stale version, run
|
||||
// `bd list` — exit 0 (correct, it's a read), but .local_version was
|
||||
// silently rewritten mid-freeze anyway. Skip both calls under an
|
||||
// active freeze without blocking the read itself. Short-circuits on
|
||||
// !policy.runMaintenance (strict --readonly) so the IsFrozen/
|
||||
// findTownRoot filesystem walk isn't paid on that path, where these
|
||||
// calls are already skipped for an unrelated reason.
|
||||
frozenForMaintenance := policy.runMaintenance && migration.IsFrozen(findTownRoot())
|
||||
// active freeze without blocking the read itself. Reuses the single
|
||||
// lookup resolved above rather than repeating the walk.
|
||||
frozenForMaintenance := policy.runMaintenance && commandFreeze.Frozen()
|
||||
|
||||
// Track bd version changes unless strict readonly forbids repository mutation.
|
||||
// Best-effort tracking - failures are silent.
|
||||
|
|
@ -1448,6 +1586,14 @@ var rootCmd = &cobra.Command{
|
|||
// root command ever be re-run in-process (tests, a future server mode).
|
||||
schema.SetForceAllowRemoteMigrate(forcedMigrate)
|
||||
|
||||
// Typing `bd migrate schema` is consent to migrate a shared database
|
||||
// that has no remote (#5920): there is no cross-clone fork to risk,
|
||||
// only the co-resident lockout the operator is asking to accept. A
|
||||
// preview withholds it — `bd migrate schema --dry-run` must not
|
||||
// migrate on the way to printing what it would do. Same set-or-clear
|
||||
// discipline as the --force override above.
|
||||
schema.SetSharedMigrateConsent(isSchemaMigrateVerb(cmd) && !previewMode)
|
||||
|
||||
// Auto-migrate database on version bump (bd-jgxi).
|
||||
// Runs for ALL non-preview commands (including read-only ones) because
|
||||
// the migration opens its own store connection, writes the version
|
||||
|
|
@ -1488,12 +1634,27 @@ var rootCmd = &cobra.Command{
|
|||
// deployments that empty relic answers every query with an empty
|
||||
// result set and exit 0 (false-empty), which readers misinterpret as
|
||||
// "no work". Absent metadata.json (cfg == nil, cfgErr == nil) keeps
|
||||
// the fresh-repo embedded default below — unless env/config.yaml
|
||||
// supply a remote host (GH#3545): host inference must not depend
|
||||
// on metadata existing, so substitute the default config and let
|
||||
// the normal mode/connection resolution run.
|
||||
if cfg == nil && configfile.DefaultConfig().HostImpliesServerMode() {
|
||||
logConfigDiscovery(beadsDir, "no metadata.json; host inference (GH#3545) selects server mode")
|
||||
// the fresh-repo embedded default below — unless the env/config.yaml
|
||||
// layers already select server mode: that decision must not depend on
|
||||
// metadata existing, so substitute the default config and let the
|
||||
// normal mode/connection resolution run.
|
||||
//
|
||||
// The gate asks IsDoltServerMode — the same resolver the branch below
|
||||
// uses to set doltCfg.ServerMode — rather than HostImpliesServerMode.
|
||||
// Host inference (GH#3545) answers only one layer of that question and
|
||||
// deliberately returns false as soon as config.yaml names a
|
||||
// `dolt.mode`: correct for inferring FROM a host, wrong as the whole
|
||||
// gate. A workspace declaring `dolt.mode: server` in .beads/config.yaml
|
||||
// with no metadata.json therefore kept cfg nil, fell through to the
|
||||
// embedded branch, and answered every query out of a phantom
|
||||
// .beads/embeddeddolt database that same run had just created —
|
||||
// exit 0, no rows, nothing to distinguish it from real emptiness.
|
||||
// BEADS_DOLT_SERVER_MODE=1 did not rescue it either; the old gate
|
||||
// never consulted it. IsDoltServerMode is a superset of
|
||||
// HostImpliesServerMode, so nothing that reached server mode before
|
||||
// stops reaching it now.
|
||||
if cfg == nil && configfile.DefaultConfig().IsDoltServerMode() {
|
||||
logConfigDiscovery(beadsDir, "no metadata.json; env/config.yaml select server mode")
|
||||
cfg = configfile.DefaultConfig()
|
||||
}
|
||||
if cfg != nil {
|
||||
|
|
@ -1598,8 +1759,16 @@ var rootCmd = &cobra.Command{
|
|||
// root pre-run, before --dry-run/--inspect has had any effect. Proxied
|
||||
// mode is where that is least visible, not where it is acceptable.
|
||||
if proxiedServerMode {
|
||||
p, err := newProxiedServerUOWProvider(rootCtx, beadsDir, databaseOverride, previewProviderOptions(previewMode)...)
|
||||
p, err := newProxiedServerUOWProvider(rootCtx, beadsDir, databaseOverride,
|
||||
rootProviderOptions(previewMode, useReadOnly)...)
|
||||
if err != nil {
|
||||
// Same typed rendering the store path gets below: a schema
|
||||
// skew or a migration-gate refusal here carries a whole
|
||||
// actionable block, and `%v` inside "failed to open uow
|
||||
// provider" throws all of it away.
|
||||
if rendered := renderTypedOpenError(err); rendered {
|
||||
return SilentExit()
|
||||
}
|
||||
return HandleError("failed to open uow provider: %v", err)
|
||||
}
|
||||
// Fire the workspace's script hooks after commits on the
|
||||
|
|
@ -1662,25 +1831,7 @@ var rootCmd = &cobra.Command{
|
|||
if handleFreshCloneError(err) {
|
||||
return SilentExit()
|
||||
}
|
||||
// Schema skew gets dedicated UX with actionable rebuild instructions.
|
||||
var skewErr *schema.SchemaSkewError
|
||||
if errors.As(err, &skewErr) {
|
||||
if jsonOutput {
|
||||
handleSchemaSkewJSON(skewErr)
|
||||
} else {
|
||||
fmt.Fprint(os.Stderr, skewErr.UserMessage())
|
||||
}
|
||||
return SilentExit()
|
||||
}
|
||||
// #4259: the remote-migrate gate blocks silent in-place migration of a
|
||||
// remote-backed database and tells the operator to migrate-or-adopt.
|
||||
var gateErr *schema.RemoteMigrateGateError
|
||||
if errors.As(err, &gateErr) {
|
||||
if jsonOutput {
|
||||
handleRemoteMigrateGateJSON(gateErr)
|
||||
} else {
|
||||
fmt.Fprint(os.Stderr, gateErr.UserMessage())
|
||||
}
|
||||
if renderTypedOpenError(err) {
|
||||
return SilentExit()
|
||||
}
|
||||
return HandleError("failed to open database: %v", err)
|
||||
|
|
@ -1821,7 +1972,16 @@ var rootCmd = &cobra.Command{
|
|||
uowProvider = nil
|
||||
}
|
||||
} else {
|
||||
if runsPostCommandMaintenance(cmd.Name(), readonlyMode) {
|
||||
// dc-6jaq: the freeze covers this hook's own writes too. A read is
|
||||
// allowed through a freeze, but the maintenance that trails it is
|
||||
// not the user's command — auto-commit, the tip_*_last_shown
|
||||
// metadata write and its separate Dolt commit, auto-backup,
|
||||
// auto-export and auto-push all mutate the very store being
|
||||
// migrated, and `bd list` on a frozen workspace reaches every one
|
||||
// of them. Guarding the outer block keeps that promise in one
|
||||
// place instead of six. Writes never get here at all: they were
|
||||
// refused in PersistentPreRunE.
|
||||
if runsPostCommandMaintenance(cmd.Name(), readonlyMode) && !commandFreeze.Frozen() {
|
||||
// Dolt auto-commit: after a successful write command (and after final flush),
|
||||
// create a Dolt commit so changes don't remain only in the working set.
|
||||
if commandDidWrite.Load() && !commandDidExplicitDoltCommit {
|
||||
|
|
|
|||
|
|
@ -368,6 +368,15 @@ func buildMarkdownBatchRequest(templates []*IssueTemplate, in createInput) (issu
|
|||
if err != nil {
|
||||
return issueops.CreateBatchRequest{}, HandleError("%v", err)
|
||||
}
|
||||
// Resolved per template, not once for the file: the plan-wide flag
|
||||
// applies to every item, but the per-type storage-class.<type> default
|
||||
// keys on the template's own type, and the ephemeral spelling moves that
|
||||
// item to the wisp plane. A conflict refuses the whole file here, before
|
||||
// any transaction opens.
|
||||
storageClass, ephemeral, err := resolveCreateStorageClass(in.storageClassFlag, template.IssueType, in.ephemeral, in.noHistory)
|
||||
if err != nil {
|
||||
return issueops.CreateBatchRequest{}, HandleError("template %q: %v", template.Title, err)
|
||||
}
|
||||
items = append(items, issueops.BatchCreateItem{
|
||||
Issue: &types.Issue{
|
||||
Title: template.Title,
|
||||
|
|
@ -379,8 +388,9 @@ func buildMarkdownBatchRequest(templates []*IssueTemplate, in createInput) (issu
|
|||
IssueType: template.IssueType,
|
||||
Assignee: template.Assignee,
|
||||
Labels: template.Labels,
|
||||
Ephemeral: in.ephemeral,
|
||||
Ephemeral: ephemeral,
|
||||
NoHistory: in.noHistory,
|
||||
StorageClass: storageClass,
|
||||
MolType: in.molType,
|
||||
CreatedBy: in.createdBy,
|
||||
Owner: in.owner,
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ func rejectMaxRowsUnderProxiedServer(cmd *cobra.Command) error {
|
|||
// that warning under proxied mode (be-x42v.4 round-4 follow-up).
|
||||
func rejectResolvedMaxRowsUnderProxiedServer(maxRows int) error {
|
||||
if maxRows > 0 {
|
||||
return HandleErrorRespectJSON("--max-rows / BEADS_MAX_ROWS is not supported in proxied-server mode")
|
||||
return HandleProxyCapabilityError(AssertProxyCapability(ProxyModeProxied, ProxyCapMaxRows))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -257,7 +257,7 @@ Examples:
|
|||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
CheckReadonly("remember") // also covers CheckMigrationFreeze (dc-6jaq)
|
||||
CheckReadonly("remember") // also covers the migration freeze check (dc-6jaq)
|
||||
|
||||
evt := metrics.NewCommandEvent("remember")
|
||||
defer func() {
|
||||
|
|
|
|||
|
|
@ -91,8 +91,8 @@ func TestApplyMetadataEdits_NumericValue(t *testing.T) {
|
|||
if err := json.Unmarshal(result, &data); err != nil {
|
||||
t.Fatalf("unmarshal: %v", err)
|
||||
}
|
||||
if string(data["story_points"]) != `"5"` {
|
||||
t.Errorf("expected \"5\", got %s", data["story_points"])
|
||||
if string(data["story_points"]) != `5` {
|
||||
t.Errorf("expected the JSON number 5, got %s", data["story_points"])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -106,8 +106,8 @@ func TestApplyMetadataEdits_BoolValue(t *testing.T) {
|
|||
if err := json.Unmarshal(result, &data); err != nil {
|
||||
t.Fatalf("unmarshal: %v", err)
|
||||
}
|
||||
if string(data["urgent"]) != `"true"` {
|
||||
t.Errorf("expected \"true\", got %s", data["urgent"])
|
||||
if string(data["urgent"]) != `true` {
|
||||
t.Errorf("expected the JSON boolean true, got %s", data["urgent"])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -121,8 +121,8 @@ func TestApplyMetadataEdits_NullValue(t *testing.T) {
|
|||
if err := json.Unmarshal(result, &data); err != nil {
|
||||
t.Fatalf("unmarshal: %v", err)
|
||||
}
|
||||
if string(data["cleared"]) != `"null"` {
|
||||
t.Errorf("expected \"null\", got %s", data["cleared"])
|
||||
if string(data["cleared"]) != `null` {
|
||||
t.Errorf("expected JSON null, got %s", data["cleared"])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -199,8 +199,8 @@ func TestApplyMetadataEdits_MultipleSetFlags(t *testing.T) {
|
|||
if string(data["sprint"]) != `"Q1"` {
|
||||
t.Errorf("expected \"Q1\", got %s", data["sprint"])
|
||||
}
|
||||
if string(data["priority"]) != `"2"` {
|
||||
t.Errorf("expected \"2\", got %s", data["priority"])
|
||||
if string(data["priority"]) != `2` {
|
||||
t.Errorf("expected the JSON number 2, got %s", data["priority"])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -306,15 +306,15 @@ func TestToJSONValue(t *testing.T) {
|
|||
expected string
|
||||
}{
|
||||
{"hello", `"hello"`},
|
||||
{"42", `"42"`},
|
||||
{"3.14", `"3.14"`},
|
||||
{"true", `"true"`},
|
||||
{"false", `"false"`},
|
||||
{"null", `"null"`},
|
||||
{"42", `42`},
|
||||
{"3.14", `3.14`},
|
||||
{"true", `true`},
|
||||
{"false", `false`},
|
||||
{"null", `null`},
|
||||
{"", `""`},
|
||||
{"hello world", `"hello world"`},
|
||||
{"0", `"0"`},
|
||||
{"-1", `"-1"`},
|
||||
{"0", `0`},
|
||||
{"-1", `-1`},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.input, func(t *testing.T) {
|
||||
|
|
|
|||
259
cmd/bd/metadataless_server_workspace_test.go
Normal file
259
cmd/bd/metadataless_server_workspace_test.go
Normal file
|
|
@ -0,0 +1,259 @@
|
|||
//go:build cgo
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/steveyegge/beads/internal/testutil"
|
||||
)
|
||||
|
||||
// A workspace can declare server mode without ever writing metadata.json:
|
||||
// `dolt.mode: server` in .beads/config.yaml, or BEADS_DOLT_SERVER_MODE=1 in the
|
||||
// environment. Both are resolved by configfile.IsDoltServerMode, and gc
|
||||
// provisions the config.yaml shape on every `gc-beads-bd start`.
|
||||
//
|
||||
// Before the fix, the metadata-less branch in the root PersistentPreRunE gated
|
||||
// its config substitution on HostImpliesServerMode alone. That predicate
|
||||
// answers a narrower question — "does a configured HOST imply server mode?" —
|
||||
// and deliberately returns false as soon as config.yaml names a dolt.mode; it
|
||||
// never consults BEADS_DOLT_SERVER_MODE at all. So cfg stayed nil, ServerMode
|
||||
// stayed false, and bd created and then read a brand-new
|
||||
// .beads/embeddeddolt/beads database: every query answered out of an empty
|
||||
// relic, exit 0, "No issues found." A reader cannot tell that from real
|
||||
// emptiness, which is why these tests assert on the phantom directory and on
|
||||
// the false-empty separately.
|
||||
//
|
||||
// The invariant under test is one-directional and does not depend on a server
|
||||
// being reachable: a workspace that selects server mode must reach the server
|
||||
// or fail loudly. It must never quietly become an embedded workspace.
|
||||
|
||||
const phantomEmbeddedDir = "embeddeddolt"
|
||||
|
||||
// TestMetadatalessServerModeWorkspaceNeverOpensPhantomEmbeddedDatabase covers
|
||||
// the two ways a workspace with no metadata.json selects server mode. Both
|
||||
// shapes are admitted by the legacy-upgrade guard as-is, so this test exercises
|
||||
// the store-selection gate directly on any branch.
|
||||
func TestMetadatalessServerModeWorkspaceNeverOpensPhantomEmbeddedDatabase(t *testing.T) {
|
||||
bd := buildBDUnderTest(t)
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
setup func(t *testing.T, beadsDir string, port int) []string
|
||||
}{
|
||||
{
|
||||
name: "config.yaml dolt.mode server",
|
||||
setup: func(t *testing.T, beadsDir string, port int) []string {
|
||||
t.Helper()
|
||||
writeFile(t, filepath.Join(beadsDir, "config.yaml"),
|
||||
[]byte(fmt.Sprintf("dolt:\n mode: server\n port: %d\n", port)))
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "BEADS_DOLT_SERVER_MODE env var",
|
||||
setup: func(t *testing.T, beadsDir string, port int) []string {
|
||||
t.Helper()
|
||||
return []string{
|
||||
"BEADS_DOLT_SERVER_MODE=1",
|
||||
fmt.Sprintf("BEADS_DOLT_SERVER_PORT=%d", port),
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
repoDir := t.TempDir()
|
||||
initGitRepo(t, repoDir)
|
||||
beadsDir := filepath.Join(repoDir, ".beads")
|
||||
if err := os.MkdirAll(beadsDir, 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
port := freeLoopbackPort(t)
|
||||
env := tc.setup(t, beadsDir, port)
|
||||
writeFile(t, filepath.Join(beadsDir, localVersionFile), []byte("1.3.0\n"))
|
||||
if err := os.Chmod(beadsDir, 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// --db names the local Dolt path bd itself computes for this
|
||||
// workspace. It is the shortest route to store selection for a
|
||||
// metadata-less workspace that has no local database directory
|
||||
// yet, which is exactly the state a server-mode workspace is
|
||||
// supposed to stay in.
|
||||
run := runBDInWorkspace(t, bd, repoDir,
|
||||
[]string{"list", "--json", "--limit", "0", "--all"}, env,
|
||||
filepath.Join(beadsDir, "dolt"))
|
||||
|
||||
assertNoPhantomEmbeddedDatabase(t, beadsDir)
|
||||
assertNotFalseEmpty(t, run)
|
||||
if !strings.Contains(run.output, fmt.Sprintf("127.0.0.1:%d", port)) {
|
||||
t.Fatalf("bd did not report the configured server endpoint 127.0.0.1:%d:\n%s", port, run.output)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestGCProvisionedServerWorkspaceNeverOpensPhantomEmbeddedDatabase pins the
|
||||
// byte shape gc creates: config.yaml declaring server mode, a .beads/dolt data
|
||||
// root owned by the sql-server, the gitignored port file, and a current-era
|
||||
// version witness — and still no metadata.json.
|
||||
//
|
||||
// Two different mechanisms keep this shape safe depending on what else has
|
||||
// landed, and the assertions deliberately cover only what both guarantee. On a
|
||||
// branch without gastownhall/beads#6119 the legacy-upgrade guard refuses the
|
||||
// workspace outright (over-broadly — that is what #6119 fixes). Once #6119
|
||||
// removes that refusal, the store-selection gate fixed here is the only thing
|
||||
// standing between this shape and a phantom embedded database, so the test
|
||||
// stays meaningful in exactly the configuration that ships.
|
||||
func TestGCProvisionedServerWorkspaceNeverOpensPhantomEmbeddedDatabase(t *testing.T) {
|
||||
bd := buildBDUnderTest(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)
|
||||
}
|
||||
port := freeLoopbackPort(t)
|
||||
writeFile(t, filepath.Join(beadsDir, "config.yaml"),
|
||||
[]byte(fmt.Sprintf("dolt:\n mode: server\n port: %d\n", port)))
|
||||
writeFile(t, filepath.Join(beadsDir, "dolt-server.port"), []byte(fmt.Sprintf("%d\n", port)))
|
||||
writeFile(t, filepath.Join(beadsDir, localVersionFile), []byte("1.3.0\n"))
|
||||
if err := os.Chmod(beadsDir, 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, args := range [][]string{
|
||||
{"list", "--json", "--limit", "0", "--all"},
|
||||
{"ready", "--json"},
|
||||
} {
|
||||
t.Run(args[0], func(t *testing.T) {
|
||||
run := runBDInWorkspace(t, bd, repoDir, args, nil, "")
|
||||
assertNoPhantomEmbeddedDatabase(t, beadsDir)
|
||||
assertNotFalseEmpty(t, run)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type bdRun struct {
|
||||
args []string
|
||||
output string
|
||||
stdout string
|
||||
exitCode int
|
||||
err error
|
||||
}
|
||||
|
||||
// runBDInWorkspace runs bd as a subprocess with auto-start disabled, so a
|
||||
// server-mode workspace cannot mask a misrouted open by starting a server of
|
||||
// its own. dbPath, when non-empty, is passed as --db.
|
||||
//
|
||||
// Every ambient BEADS_DOLT_* and BEADS_DIR is stripped first. This package's
|
||||
// TestMain starts a shared Dolt server and exports its endpoint, and env beats
|
||||
// config.yaml in every layer of the precedence chain being tested here — a
|
||||
// leaked BEADS_DOLT_SERVER_PORT would retarget the workspace at that server
|
||||
// and quietly change what the assertions mean.
|
||||
func runBDInWorkspace(t *testing.T, bd, repoDir string, args, extraEnv []string, dbPath string) bdRun {
|
||||
t.Helper()
|
||||
if dbPath != "" {
|
||||
args = append([]string{"--db", dbPath}, args...)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
||||
defer cancel()
|
||||
cmd := exec.CommandContext(ctx, bd, args...)
|
||||
cmd.Dir = repoDir
|
||||
cmd.Env = append(envWithoutBeadsStorageSettings(),
|
||||
"BD_DISABLE_METRICS=1",
|
||||
"BEADS_DOLT_AUTO_START=0",
|
||||
)
|
||||
cmd.Env = append(cmd.Env, extraEnv...)
|
||||
var stdout, stderr bytes.Buffer
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
err := cmd.Run()
|
||||
if ctxErr := ctx.Err(); ctxErr != nil {
|
||||
t.Fatalf("bd %s did not finish before the deadline: %v\n%s%s",
|
||||
strings.Join(args, " "), ctxErr, stdout.String(), stderr.String())
|
||||
}
|
||||
run := bdRun{
|
||||
args: args,
|
||||
output: stdout.String() + stderr.String(),
|
||||
stdout: stdout.String(),
|
||||
err: err,
|
||||
}
|
||||
run.exitCode = cmd.ProcessState.ExitCode()
|
||||
return run
|
||||
}
|
||||
|
||||
// assertNoPhantomEmbeddedDatabase is the load-bearing assertion: bd must not
|
||||
// have created .beads/embeddeddolt for a workspace that selects server mode.
|
||||
// Once that directory exists it is self-perpetuating — discovery prefers it
|
||||
// over .beads/dolt on every later run — so the damage outlives the invocation
|
||||
// that caused it.
|
||||
func assertNoPhantomEmbeddedDatabase(t *testing.T, beadsDir string) {
|
||||
t.Helper()
|
||||
path := filepath.Join(beadsDir, phantomEmbeddedDir)
|
||||
if info, err := os.Stat(path); err == nil && info.IsDir() {
|
||||
entries, _ := os.ReadDir(path)
|
||||
names := make([]string, 0, len(entries))
|
||||
for _, entry := range entries {
|
||||
names = append(names, entry.Name())
|
||||
}
|
||||
t.Fatalf("bd created a phantom embedded database at %s (contains %v) for a server-mode workspace", path, names)
|
||||
}
|
||||
}
|
||||
|
||||
// assertNotFalseEmpty rejects the failure this bug produced: a successful,
|
||||
// empty answer sourced from somewhere other than the configured server. An
|
||||
// error is a fine outcome here — a reader can act on it.
|
||||
func assertNotFalseEmpty(t *testing.T, run bdRun) {
|
||||
t.Helper()
|
||||
if run.err == nil {
|
||||
t.Fatalf("bd %s exited 0 for an unreachable server-mode workspace; a silent empty result is indistinguishable from real emptiness:\n%s",
|
||||
strings.Join(run.args, " "), run.output)
|
||||
}
|
||||
if strings.Contains(run.output, "no beads configuration found") {
|
||||
t.Fatalf("bd %s fell through to the embedded default instead of the configured server:\n%s",
|
||||
strings.Join(run.args, " "), run.output)
|
||||
}
|
||||
for _, empty := range []string{"No issues found.", "No ready work"} {
|
||||
if strings.Contains(run.stdout, empty) {
|
||||
t.Fatalf("bd %s reported %q instead of reaching the configured server:\n%s",
|
||||
strings.Join(run.args, " "), empty, run.output)
|
||||
}
|
||||
}
|
||||
if strings.TrimSpace(run.stdout) == "[]" {
|
||||
t.Fatalf("bd %s printed an empty JSON result instead of reaching the configured server:\n%s",
|
||||
strings.Join(run.args, " "), run.output)
|
||||
}
|
||||
}
|
||||
|
||||
func envWithoutBeadsStorageSettings() []string {
|
||||
kept := make([]string, 0, len(os.Environ()))
|
||||
for _, entry := range os.Environ() {
|
||||
name, _, _ := strings.Cut(entry, "=")
|
||||
if strings.HasPrefix(name, "BEADS_DOLT_") || name == "BEADS_DIR" {
|
||||
continue
|
||||
}
|
||||
kept = append(kept, entry)
|
||||
}
|
||||
return kept
|
||||
}
|
||||
|
||||
func freeLoopbackPort(t *testing.T) int {
|
||||
t.Helper()
|
||||
port, err := testutil.FindFreePort()
|
||||
if err != nil {
|
||||
t.Fatalf("find free port: %v", err)
|
||||
}
|
||||
return port
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
|
@ -8,12 +9,14 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/beads"
|
||||
"github.com/steveyegge/beads/internal/configfile"
|
||||
"github.com/steveyegge/beads/internal/debug"
|
||||
"github.com/steveyegge/beads/internal/metrics"
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/storage/schema"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
"github.com/steveyegge/beads/internal/utils"
|
||||
"github.com/steveyegge/beads/issueops"
|
||||
)
|
||||
|
||||
var migrateCmd = &cobra.Command{
|
||||
|
|
@ -633,6 +636,19 @@ func handleSchemaMigrate() error {
|
|||
}
|
||||
return SilentExit()
|
||||
}
|
||||
var dirtyErr *schema.DirtyTablesError
|
||||
if errors.As(err, &dirtyErr) {
|
||||
// The dirty guard's own remedy is `bd dolt commit`, which on a
|
||||
// shared server opens writably, hits the migrate gate, and is told
|
||||
// to run this command — the two messages point at each other and
|
||||
// the operator loops (gastownhall/beads#5920 review). Name the
|
||||
// sequence that actually terminates.
|
||||
return HandleErrorWithHint(
|
||||
fmt.Sprintf("schema migration failed: %v", err),
|
||||
"in server mode `bd dolt commit` is itself gated, so commit the working set on the server first "+
|
||||
"(`CALL DOLT_COMMIT('-Am', 'pre-migration working set')` over the sql-server, or "+
|
||||
schema.AllowRemoteMigrateEnv+"=1 bd dolt commit), then re-run this command")
|
||||
}
|
||||
return HandleError("schema migration failed: %v", err)
|
||||
}
|
||||
|
||||
|
|
@ -641,6 +657,14 @@ func handleSchemaMigrate() error {
|
|||
if applied > 0 {
|
||||
status = "applied"
|
||||
commandDidWrite.Store(true)
|
||||
// Stamp the version markers the refused version-bump reconciliation
|
||||
// could not (gastownhall/beads#5920 review). autoMigrateOnVersionBump
|
||||
// is the only automatic writer of bd_version, it was refused by the
|
||||
// gate this command just satisfied, and its one-shot .local_version
|
||||
// signal is already consumed — so without this, `bd doctor` and the
|
||||
// git-hook health check keep reporting a version mismatch after the
|
||||
// operator has done everything the refusal told them to.
|
||||
stampWorkspaceVersionAfterMigrate(store)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
|
|
@ -659,6 +683,54 @@ func handleSchemaMigrate() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// stampWorkspaceVersionAfterMigrate records this binary's version through the
|
||||
// store's own reconciler, exactly as autoMigrateOnVersionBump would have.
|
||||
//
|
||||
// Best-effort by design, and deliberately not fatal: the migration itself has
|
||||
// already succeeded and been reported, so a marker write that fails must not
|
||||
// turn a successful migration into a failed command. A stale marker is a
|
||||
// cosmetic doctor warning; a false "schema migration failed" is not.
|
||||
func stampWorkspaceVersionAfterMigrate(store storage.DoltStorage) {
|
||||
reconciler, err := store.VersionReconciler()
|
||||
if err != nil {
|
||||
debug.Logf("migrate schema: version markers unavailable: %v", err)
|
||||
return
|
||||
}
|
||||
if _, err := reconciler.ReconcileVersion(rootCtx, issueops.VersionReconcileRequest{CLIVersion: Version}); err != nil {
|
||||
debug.Logf("migrate schema: failed to record workspace version: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// reportProxiedSchemaMigrate is `bd migrate schema`'s proxied-server arm. The
|
||||
// provider open already reconciled the schema under this verb's consent, so
|
||||
// there is nothing left to do but say so — and say it in the same shape the
|
||||
// direct path uses, since a caller parsing --json should not have to branch on
|
||||
// the workspace's storage mode.
|
||||
//
|
||||
// The open reports its own failures: a gate refusal or a failed migration
|
||||
// aborts the command in root pre-run and never reaches RunE, so arriving here
|
||||
// means the schema is reconciled. The applied count is not observable from
|
||||
// here (it belongs to an open that has already returned), hence the "current"
|
||||
// status rather than a count.
|
||||
//
|
||||
// No version stamping here, unlike the direct path: reconcileVersionProxiedServer
|
||||
// already runs in the root pre-run after a successful provider open, so the
|
||||
// marker the gate refusal held back is written as soon as the open succeeds.
|
||||
func reportProxiedSchemaMigrate() error {
|
||||
latest := schema.LatestVersion()
|
||||
if jsonOutput {
|
||||
return outputJSON(map[string]interface{}{
|
||||
"status": "current",
|
||||
"latest_version": latest,
|
||||
"mode": "proxied-server",
|
||||
"note": "schema reconciled during provider open",
|
||||
})
|
||||
}
|
||||
fmt.Printf("%s\n", ui.RenderPass(fmt.Sprintf(
|
||||
"✓ Schema reconciled during provider open (proxied-server mode); schema now at v%d", latest)))
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleToSeparateBranch(branch string, dryRun bool) error {
|
||||
b := strings.TrimSpace(branch)
|
||||
if b == "" || strings.ContainsAny(b, " \t\n") {
|
||||
|
|
@ -820,7 +892,12 @@ Example:
|
|||
SilenceErrors: true,
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
if usesProxiedServer() {
|
||||
return HandleErrorRespectJSON("migrate schema is not supported in proxied-server mode")
|
||||
// Proxied mode has no store-level SchemaMigrator to call: the
|
||||
// provider open IS the migration, and by the time RunE runs it has
|
||||
// already happened — with this verb's consent, which the root
|
||||
// pre-run set before the open (schema.SetSharedMigrateConsent).
|
||||
// So report, rather than refuse a verb that just did its job.
|
||||
return reportProxiedSchemaMigrate()
|
||||
}
|
||||
CheckReadonly("migrate schema")
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
916
cmd/bd/migrate_dolt_mode_frontdoor_integration_test.go
Normal file
916
cmd/bd/migrate_dolt_mode_frontdoor_integration_test.go
Normal file
|
|
@ -0,0 +1,916 @@
|
|||
//go:build cgo && integration
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/config"
|
||||
"github.com/steveyegge/beads/internal/configfile"
|
||||
"github.com/steveyegge/beads/internal/doltserver"
|
||||
"github.com/steveyegge/beads/internal/storage/dbproxy/proxy"
|
||||
"github.com/steveyegge/beads/internal/storage/dbproxy/server"
|
||||
"github.com/steveyegge/beads/internal/storage/dbproxy/util"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func runBDExecSeparated(t *testing.T, bd, dir string, env []string, args ...string) (string, string, error) {
|
||||
t.Helper()
|
||||
cmd := exec.Command(bd, args...)
|
||||
cmd.Dir, cmd.Env = dir, env
|
||||
var stdout, stderr bytes.Buffer
|
||||
cmd.Stdout, cmd.Stderr = &stdout, &stderr
|
||||
err := cmd.Run()
|
||||
return stdout.String(), stderr.String(), err
|
||||
}
|
||||
|
||||
func createDependencyPair(t *testing.T, bd, dir string, env []string, sentinelID string) string {
|
||||
t.Helper()
|
||||
blockerOut, err := runBDExecWithBinary(t, bd, dir, env, "create", "migration blocker", "--json")
|
||||
require.NoError(t, err, "create blocker: %s", blockerOut)
|
||||
var blocker struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
require.NoError(t, json.Unmarshal([]byte(blockerOut), &blocker))
|
||||
require.NotEmpty(t, blocker.ID)
|
||||
depOut, depErr := runBDExecWithBinary(t, bd, dir, env, "dep", "add", sentinelID, blocker.ID)
|
||||
require.NoError(t, depErr, "dep add: %s", depOut)
|
||||
return blocker.ID
|
||||
}
|
||||
|
||||
func assertDependencyPair(t *testing.T, bd, dir string, env []string, sentinelID, blockerID string) {
|
||||
t.Helper()
|
||||
out, err := runBDExecWithBinary(t, bd, dir, env, "dep", "list", sentinelID, blockerID, "--json")
|
||||
require.NoError(t, err, "dep list: %s", out)
|
||||
var edges []struct {
|
||||
IssueID string `json:"issue_id"`
|
||||
DependsOnID string `json:"depends_on_id"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
require.NoError(t, json.Unmarshal([]byte(out), &edges), "dep list JSON: %s", out)
|
||||
found := false
|
||||
for _, edge := range edges {
|
||||
if (edge.IssueID == "" || edge.IssueID == sentinelID) && edge.DependsOnID == blockerID && edge.Type == "blocks" {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
assert.True(t, found, "dependency edge missing: %s -> %s", sentinelID, blockerID)
|
||||
}
|
||||
|
||||
func migrationFrontDoorBinary(t *testing.T) string {
|
||||
if p := os.Getenv("BEADS_TEST_BD_BINARY"); p != "" {
|
||||
return p
|
||||
}
|
||||
out := filepath.Join(t.TempDir(), "bd")
|
||||
cmd := exec.Command("go", "build", "-o", out, ".")
|
||||
cmd.Dir = "."
|
||||
if b, err := cmd.CombinedOutput(); err != nil {
|
||||
t.Fatalf("build cgo bd: %v\n%s", err, b)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func migrationFrontDoorEnv(home string) []string {
|
||||
env := make([]string, 0)
|
||||
for _, kv := range os.Environ() {
|
||||
key := kv
|
||||
if i := strings.IndexByte(kv, '='); i >= 0 {
|
||||
key = kv[:i]
|
||||
}
|
||||
// The cmd/bd package TestMain sets BEADS_TEST_MODE and related
|
||||
// controls for its in-process tests. Never inherit those into the
|
||||
// real front-door subprocess: BEADS_TEST_MODE disables auto-start
|
||||
// and makes a freshly initialized server resolve to port 1.
|
||||
if strings.HasPrefix(key, "BEADS_") || strings.HasPrefix(key, "BD_") || key == "HOME" || key == "USERPROFILE" {
|
||||
continue
|
||||
}
|
||||
env = append(env, kv)
|
||||
}
|
||||
return append(env, "HOME="+home, "USERPROFILE="+home)
|
||||
}
|
||||
|
||||
// TestMigrateDoltModeFrontDoor exercises migration through the real bd
|
||||
// executable. It is opt-in because it requires a local Dolt installation.
|
||||
func TestMigrateDoltModeFrontDoor(t *testing.T) {
|
||||
if os.Getenv("BEADS_TEST_MIGRATION_FRONTDOOR") != "1" {
|
||||
t.Skip("set BEADS_TEST_MIGRATION_FRONTDOOR=1")
|
||||
}
|
||||
bd := migrationFrontDoorBinary(t)
|
||||
dir := t.TempDir()
|
||||
home := t.TempDir()
|
||||
env := migrationFrontDoorEnv(home)
|
||||
out, err := runBDExecWithBinary(t, bd, dir, env, "init", "--backend", "dolt", "--server", "--prefix", "fd", "--quiet")
|
||||
if err != nil {
|
||||
t.Fatalf("init: %v\n%s", err, out)
|
||||
}
|
||||
createOut, err := runBDExecWithBinary(t, bd, dir, env, "create", "front-door sentinel", "--json")
|
||||
if err != nil {
|
||||
t.Fatalf("create sentinel: %v\n%s", err, createOut)
|
||||
}
|
||||
statusOut, _ := runBDExecWithBinary(t, bd, dir, env, "dolt", "status")
|
||||
if strings.Contains(statusOut, "Dolt server: running") {
|
||||
if out, err = runBDExecWithBinary(t, bd, dir, env, "dolt", "stop"); err != nil {
|
||||
t.Fatalf("stop running server: %v\n%s", err, out)
|
||||
}
|
||||
}
|
||||
var created struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(createOut), &created); err != nil || created.ID == "" {
|
||||
t.Fatalf("invalid create JSON: %s", createOut)
|
||||
}
|
||||
if out, err = runBDExecWithBinary(t, bd, dir, env, "migrate", "from-server-to-proxied-server"); err != nil {
|
||||
t.Fatalf("forward migration: %v\n%s", err, out)
|
||||
}
|
||||
metaProxy, _ := os.ReadFile(filepath.Join(dir, ".beads", "metadata.json"))
|
||||
var proxyMetadata map[string]any
|
||||
if err := json.Unmarshal(metaProxy, &proxyMetadata); err != nil || proxyMetadata["dolt_mode"] != "proxied-server" {
|
||||
t.Fatalf("forward did not persist proxied mode: %s", metaProxy)
|
||||
}
|
||||
info, err := os.ReadFile(filepath.Join(dir, ".beads", "proxied_server_client_info.json"))
|
||||
if err != nil || len(info) == 0 {
|
||||
t.Fatalf("missing proxied sidecar: %v", err)
|
||||
}
|
||||
if !strings.Contains(out, "Switched to proxied-server mode") {
|
||||
t.Fatalf("unexpected forward output: %s", out)
|
||||
}
|
||||
list, err := runBDExecWithBinary(t, bd, dir, env, "list", "--json")
|
||||
if err != nil || !json.Valid([]byte(list)) || !strings.Contains(list, created.ID) {
|
||||
t.Fatalf("proxied list JSON: %v\n%s", err, list)
|
||||
}
|
||||
// A completed forward migration must refuse while its proxy process still
|
||||
// owns the target. This is exercised through the actual bd front door,
|
||||
// before provider startup can hide the ownership conflict.
|
||||
runningOut, runningErr := runBDExecWithBinary(t, bd, dir, env, "--json", "migrate", "from-server-to-proxied-server")
|
||||
if runningErr == nil {
|
||||
t.Fatalf("forward no-op unexpectedly succeeded while proxy was running: %s", runningOut)
|
||||
}
|
||||
var runningRefusal map[string]any
|
||||
if err := json.Unmarshal([]byte(runningOut), &runningRefusal); err != nil {
|
||||
t.Fatalf("running-proxy refusal JSON: %v\n%s", err, runningOut)
|
||||
}
|
||||
if data, ok := runningRefusal["data"].(map[string]any); ok {
|
||||
runningRefusal = data
|
||||
}
|
||||
if runningRefusal["code"] != "proxy.migrate.invalid_state" || runningRefusal["mutates"] != false {
|
||||
t.Fatalf("running-proxy refusal = %s", runningOut)
|
||||
}
|
||||
if out, err = runBDExecWithBinary(t, bd, dir, env, "update", created.ID, "--title", "front-door sentinel updated"); err != nil {
|
||||
t.Fatalf("proxied update: %v\n%s", err, out)
|
||||
}
|
||||
statusOut, _ = runBDExecWithBinary(t, bd, dir, env, "dolt", "status")
|
||||
if strings.Contains(statusOut, "Dolt server: running") {
|
||||
if out, err = runBDExecWithBinary(t, bd, dir, env, "dolt", "stop"); err != nil {
|
||||
t.Fatalf("stop proxied server: %v\n%s", err, out)
|
||||
}
|
||||
}
|
||||
// The proxy can supervise a Dolt child whose status text is stale; stop is
|
||||
// idempotent and its "not running" result is safe to ignore.
|
||||
if out, err = runBDExecWithBinary(t, bd, dir, env, "dolt", "stop"); err != nil && !strings.Contains(strings.ToLower(out), "not running") {
|
||||
t.Fatalf("stop before reverse: %v\n%s", err, out)
|
||||
}
|
||||
sidecarBefore, err := os.ReadFile(filepath.Join(dir, ".beads", "proxied_server_client_info.json"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
metaBefore, err := os.ReadFile(filepath.Join(dir, ".beads", "metadata.json"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if out, err = runBDExecWithBinary(t, bd, dir, env, "--json", "migrate", "from-proxied-server-to-server", "--dry-run"); err != nil {
|
||||
t.Fatalf("reverse dry-run: %v\n%s", err, out)
|
||||
}
|
||||
if _, err = os.Stat(filepath.Join(dir, ".beads", "proxied_server_client_info.json")); err != nil {
|
||||
t.Fatalf("dry-run removed sidecar: %v", err)
|
||||
}
|
||||
if got, _ := os.ReadFile(filepath.Join(dir, ".beads", "proxied_server_client_info.json")); string(got) != string(sidecarBefore) {
|
||||
t.Fatal("dry-run changed sidecar")
|
||||
}
|
||||
if got, _ := os.ReadFile(filepath.Join(dir, ".beads", "metadata.json")); string(got) != string(metaBefore) {
|
||||
t.Fatal("dry-run changed metadata")
|
||||
}
|
||||
if out, err = runBDExecWithBinary(t, bd, dir, env, "migrate", "from-proxied-server-to-server"); err != nil {
|
||||
t.Fatalf("reverse migration: %v\n%s", err, out)
|
||||
}
|
||||
show, err := runBDExecWithBinary(t, bd, dir, env, "show", created.ID, "--json")
|
||||
if err != nil {
|
||||
t.Fatalf("show sentinel: %v\n%s", err, show)
|
||||
}
|
||||
if !json.Valid([]byte(show)) || !strings.Contains(show, "front-door sentinel updated") {
|
||||
t.Fatalf("sentinel missing or invalid JSON: %s", show)
|
||||
}
|
||||
meta, err := os.ReadFile(filepath.Join(dir, ".beads", "metadata.json"))
|
||||
var serverMetadata map[string]any
|
||||
if err != nil || json.Unmarshal(meta, &serverMetadata) != nil || serverMetadata["dolt_mode"] != "server" {
|
||||
t.Fatalf("metadata mode not restored: %s", meta)
|
||||
}
|
||||
if _, err = os.Stat(filepath.Join(dir, ".beads", "proxied_server_client_info.json")); !os.IsNotExist(err) {
|
||||
t.Fatal("sidecar remains after reverse")
|
||||
}
|
||||
list, err = runBDExecWithBinary(t, bd, dir, env, "list", "--json")
|
||||
if err != nil || !json.Valid([]byte(list)) || !strings.Contains(list, "front-door sentinel updated") {
|
||||
t.Fatalf("direct list JSON: %v\n%s", err, list)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateDoltModeFrontDoorRefusesMalformedSidecar(t *testing.T) {
|
||||
if os.Getenv("BEADS_TEST_MIGRATION_FRONTDOOR") != "1" {
|
||||
t.Skip("set BEADS_TEST_MIGRATION_FRONTDOOR=1")
|
||||
}
|
||||
bd := migrationFrontDoorBinary(t)
|
||||
dir, home := t.TempDir(), t.TempDir()
|
||||
env := migrationFrontDoorEnv(home)
|
||||
if out, err := runBDExecWithBinary(t, bd, dir, env, "init", "--backend", "dolt", "--proxied-server", "--quiet"); err != nil {
|
||||
t.Fatalf("init: %v\n%s", err, out)
|
||||
}
|
||||
path := filepath.Join(dir, ".beads", "proxied_server_client_info.json")
|
||||
if err := os.WriteFile(path, []byte("{malformed"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
before, _ := os.ReadFile(filepath.Join(dir, ".beads", "metadata.json"))
|
||||
out, err := runBDExecWithBinary(t, bd, dir, env, "--json", "migrate", "from-proxied-server-to-server")
|
||||
if err == nil {
|
||||
t.Fatal("malformed sidecar unexpectedly succeeded")
|
||||
}
|
||||
if !json.Valid([]byte(out)) {
|
||||
t.Fatalf("expected JSON error output, got %s", out)
|
||||
}
|
||||
after, _ := os.ReadFile(filepath.Join(dir, ".beads", "metadata.json"))
|
||||
if string(before) != string(after) {
|
||||
t.Fatal("refusal mutated metadata")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateDoltModeFrontDoorRefusesExternalEndpoint(t *testing.T) {
|
||||
if os.Getenv("BEADS_TEST_MIGRATION_FRONTDOOR") != "1" {
|
||||
t.Skip("set BEADS_TEST_MIGRATION_FRONTDOOR=1")
|
||||
}
|
||||
bd := migrationFrontDoorBinary(t)
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
want string
|
||||
}{
|
||||
{name: "tcp", want: "externally hosted proxied Dolt endpoint"},
|
||||
{name: "unix", want: "externally hosted proxied Dolt endpoint"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
dir, home := t.TempDir(), t.TempDir()
|
||||
env := migrationFrontDoorEnv(home)
|
||||
beadsDir := filepath.Join(dir, ".beads")
|
||||
root := filepath.Join(beadsDir, "dolt")
|
||||
if err := os.MkdirAll(filepath.Join(root, ".dolt"), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(root, ".dolt", "repo_state.json"), []byte(`{"head":"refs/heads/main","remotes":{},"backups":{},"branches":{}}`), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), []byte(`{"database":"myproj","backend":"dolt","dolt_mode":"proxied-server"}`), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Chmod(beadsDir, 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
metaBefore, err := os.ReadFile(filepath.Join(beadsDir, "metadata.json"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sidecarPath := filepath.Join(beadsDir, "proxied_server_client_info.json")
|
||||
// Replace the managed sidecar with an externally-owned endpoint.
|
||||
// This exercises migration refusal without attempting a network
|
||||
// connection to an unreachable host/socket during init.
|
||||
external := map[string]any{"root_path": filepath.Join(beadsDir, "dolt"), "external": map[string]any{}}
|
||||
if tc.name == "tcp" {
|
||||
external["external"] = map[string]any{"host": "db.example", "port": 3307}
|
||||
} else {
|
||||
external["external"] = map[string]any{"socket": "/tmp/beads-front-door.sock"}
|
||||
}
|
||||
sidecarData, _ := json.Marshal(external)
|
||||
if err := os.WriteFile(sidecarPath, sidecarData, 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sidecarBefore, err := os.ReadFile(sidecarPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
treeBefore := snapshotMigrationTree(t, beadsDir)
|
||||
out, err := runBDExecWithBinary(t, bd, dir, env, "--json", "migrate", "from-proxied-server-to-server")
|
||||
if err == nil {
|
||||
t.Fatal("external endpoint migration unexpectedly succeeded")
|
||||
}
|
||||
if exitErr, ok := err.(*exec.ExitError); !ok || exitErr.ExitCode() != 1 {
|
||||
t.Fatalf("expected exit code 1, got %v", err)
|
||||
}
|
||||
var refusal map[string]any
|
||||
if err := json.Unmarshal([]byte(out), &refusal); err != nil {
|
||||
t.Fatalf("invalid refusal JSON: %v\n%s", err, out)
|
||||
}
|
||||
if data, ok := refusal["data"].(map[string]any); ok {
|
||||
refusal = data
|
||||
}
|
||||
if refusal["code"] != "proxy.migrate.external_endpoint" || refusal["mutates"] != false {
|
||||
t.Fatalf("expected typed non-mutating refusal, got: %s", out)
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(out), strings.ToLower(tc.want)) {
|
||||
t.Fatalf("expected refusal text %q, got: %s", tc.want, out)
|
||||
}
|
||||
// Refusal must happen before any proxy/provider process starts.
|
||||
probe := exec.Command("pgrep", "-af", "[d]b-proxy-child --root "+root)
|
||||
if processOut, probeErr := probe.CombinedOutput(); probeErr == nil && len(strings.TrimSpace(string(processOut))) > 0 {
|
||||
t.Fatalf("external refusal started a proxy process: %s", processOut)
|
||||
}
|
||||
if got, _ := os.ReadFile(filepath.Join(beadsDir, "metadata.json")); string(got) != string(metaBefore) {
|
||||
t.Fatal("external refusal mutated metadata")
|
||||
}
|
||||
if got, _ := os.ReadFile(sidecarPath); string(got) != string(sidecarBefore) {
|
||||
t.Fatal("external refusal mutated sidecar")
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(beadsDir, "dolt-mode-migration.json")); !os.IsNotExist(err) {
|
||||
t.Fatal("external refusal created a migration journal")
|
||||
}
|
||||
if got := snapshotMigrationTree(t, beadsDir); !reflect.DeepEqual(treeBefore, got) {
|
||||
t.Fatal("external refusal mutated migration artifacts")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateDoltModeFrontDoorExternalJournalMatrix(t *testing.T) {
|
||||
if os.Getenv("BEADS_TEST_MIGRATION_FRONTDOOR") != "1" {
|
||||
t.Skip("set BEADS_TEST_MIGRATION_FRONTDOOR=1")
|
||||
}
|
||||
bd := migrationFrontDoorBinary(t)
|
||||
phases := []string{"prepared", "target_configured", "old_controls_retired", "verified", "committed"}
|
||||
for _, reverse := range []bool{false, true} {
|
||||
for _, phase := range phases {
|
||||
for _, unix := range []bool{false, true} {
|
||||
t.Run(fmt.Sprintf("%s/%s/%s", map[bool]string{false: "forward", true: "reverse"}[reverse], phase, map[bool]string{false: "tcp", true: "unix"}[unix]), func(t *testing.T) {
|
||||
dir, home := t.TempDir(), t.TempDir()
|
||||
env := migrationFrontDoorEnv(home)
|
||||
beadsDir, root := filepath.Join(dir, ".beads"), filepath.Join(dir, ".beads", "dolt")
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(root, ".dolt"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(root, ".dolt", "repo_state.json"), []byte(`{"head":"refs/heads/main","remotes":{},"backups":{},"branches":{}}`), 0o600))
|
||||
src, target := "server", "proxied-server"
|
||||
command := []string{"from-server-to-proxied-server"}
|
||||
if reverse {
|
||||
src, target, command = "proxied-server", "server", []string{"from-proxied-server-to-server"}
|
||||
}
|
||||
mode := src
|
||||
if phase != "prepared" {
|
||||
mode = target
|
||||
}
|
||||
require.NoError(t, os.WriteFile(filepath.Join(beadsDir, "metadata.json"), []byte(fmt.Sprintf(`{"database":"myproj","backend":"dolt","dolt_mode":%q}`, mode)), 0o600))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(beadsDir, ".local_version"), []byte(Version), 0o600))
|
||||
require.NoError(t, os.Chmod(beadsDir, 0o700))
|
||||
ext := map[string]any{"host": "db.example", "port": 3307}
|
||||
if unix {
|
||||
ext = map[string]any{"socket": "/tmp/beads-front-door.sock"}
|
||||
}
|
||||
sidecar, _ := json.Marshal(map[string]any{"root_path": root, "external": ext})
|
||||
require.NoError(t, os.WriteFile(filepath.Join(beadsDir, "proxied_server_client_info.json"), sidecar, 0o600))
|
||||
journal, _ := json.Marshal(map[string]any{"version": 1, "source_mode": src, "target_mode": target, "root_path": root, "external": ext, "sidecar": map[string]any{"root_path": root, "external": ext}, "ownership": "external", "attempt": 1, "phase": phase})
|
||||
require.NoError(t, os.WriteFile(filepath.Join(beadsDir, migrateJournalFileName), journal, 0o600))
|
||||
gatePath := filepath.Join(beadsDir, "dolt.gate.lock")
|
||||
require.NoError(t, os.WriteFile(gatePath, []byte("preseeded-gate-lock"), 0o600))
|
||||
gateBefore, gateErr := os.ReadFile(gatePath)
|
||||
gateExists := gateErr == nil
|
||||
tree := snapshotMigrationTree(t, beadsDir)
|
||||
out, err := runBDExecWithBinary(t, bd, dir, env, append([]string{"--json", "migrate"}, command...)...)
|
||||
require.Error(t, err)
|
||||
exitErr, ok := err.(*exec.ExitError)
|
||||
require.True(t, ok)
|
||||
require.Equal(t, 1, exitErr.ExitCode())
|
||||
var payload map[string]any
|
||||
require.NoError(t, json.Unmarshal([]byte(out), &payload), out)
|
||||
if data, ok := payload["data"].(map[string]any); ok {
|
||||
payload = data
|
||||
}
|
||||
assert.Equal(t, "proxy.migrate.external_endpoint", payload["code"])
|
||||
assert.Equal(t, false, payload["mutates"])
|
||||
assert.Contains(t, payload["error"], "externally hosted proxied Dolt endpoint")
|
||||
assert.Equal(t, tree, snapshotMigrationTree(t, beadsDir))
|
||||
for _, p := range append([]string{migrateLockFileName}, serverAssetNames()...) {
|
||||
_, statErr := os.Stat(filepath.Join(beadsDir, p))
|
||||
assert.True(t, os.IsNotExist(statErr), "unexpected artifact %s", p)
|
||||
}
|
||||
gateAfter, gateAfterErr := os.ReadFile(gatePath)
|
||||
assert.Equal(t, gateExists, gateAfterErr == nil, "dolt gate lock existence changed")
|
||||
if gateExists {
|
||||
assert.Equal(t, gateBefore, gateAfter, "dolt gate lock changed")
|
||||
}
|
||||
for _, p := range proxiedAssetNames() {
|
||||
_, statErr := os.Stat(filepath.Join(root, p))
|
||||
assert.True(t, os.IsNotExist(statErr), "unexpected proxy artifact %s", p)
|
||||
}
|
||||
probe := exec.Command("pgrep", "-af", "[d]b-proxy-child --root "+root)
|
||||
processOut, probeErr := probe.CombinedOutput()
|
||||
assert.True(t, probeErr != nil || len(strings.TrimSpace(string(processOut))) == 0, "proxy process started: %s", processOut)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateDoltModeFrontDoorMalformedStateRefuses(t *testing.T) {
|
||||
if os.Getenv("BEADS_TEST_MIGRATION_FRONTDOOR") != "1" {
|
||||
t.Skip("set BEADS_TEST_MIGRATION_FRONTDOOR=1")
|
||||
}
|
||||
bd := migrationFrontDoorBinary(t)
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
file string
|
||||
body string
|
||||
}{
|
||||
{"metadata", "metadata.json", "{malformed"},
|
||||
{"journal", migrateJournalFileName, "{malformed"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
dir, home := t.TempDir(), t.TempDir()
|
||||
env := migrationFrontDoorEnv(home)
|
||||
beadsDir := filepath.Join(dir, ".beads")
|
||||
require.NoError(t, os.MkdirAll(beadsDir, 0o700))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(beadsDir, ".local_version"), []byte(Version), 0o600))
|
||||
if tc.name == "journal" {
|
||||
require.NoError(t, os.WriteFile(filepath.Join(beadsDir, "metadata.json"), []byte(`{"database":"myproj","backend":"dolt","dolt_mode":"proxied-server"}`), 0o600))
|
||||
}
|
||||
require.NoError(t, os.WriteFile(filepath.Join(beadsDir, tc.file), []byte(tc.body), 0o600))
|
||||
before := snapshotMigrationTree(t, beadsDir)
|
||||
out, _, err := runBDExecSeparated(t, bd, dir, env, "--json", "migrate", "from-proxied-server-to-server")
|
||||
require.Error(t, err)
|
||||
exitErr, ok := err.(*exec.ExitError)
|
||||
require.True(t, ok)
|
||||
require.Equal(t, 1, exitErr.ExitCode())
|
||||
var payload map[string]any
|
||||
require.NoError(t, json.Unmarshal([]byte(out), &payload), out)
|
||||
if data, ok := payload["data"].(map[string]any); ok {
|
||||
payload = data
|
||||
}
|
||||
assert.Equal(t, "proxy.migrate.invalid_state", payload["code"])
|
||||
assert.Equal(t, false, payload["mutates"])
|
||||
assert.Equal(t, before, snapshotMigrationTree(t, beadsDir))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestMigrateDoltModeForwardNoopRefusalsFrontDoor keeps the completed-target
|
||||
// path fail-closed at the real CLI boundary. Both output modes must preserve
|
||||
// the workspace byte-for-byte while refusing ambiguous ownership/artifacts.
|
||||
func TestMigrateDoltModeForwardNoopRefusalsFrontDoor(t *testing.T) {
|
||||
if os.Getenv("BEADS_TEST_MIGRATION_FRONTDOOR") != "1" {
|
||||
t.Skip("set BEADS_TEST_MIGRATION_FRONTDOOR=1")
|
||||
}
|
||||
bd := migrationFrontDoorBinary(t)
|
||||
cases := []struct {
|
||||
name string
|
||||
shared bool
|
||||
info map[string]any
|
||||
asset string
|
||||
want string
|
||||
}{
|
||||
{name: "direct external sidecar", info: map[string]any{"external": map[string]any{"host": "db.example", "port": 3307}}, want: "externally hosted"},
|
||||
{name: "direct mismatched sidecar", info: map[string]any{"root_path": "/tmp/other"}, want: "canonical"},
|
||||
{name: "direct stale control", asset: "proxy.log", want: "stale proxy control"},
|
||||
{name: "shared mismatched sidecar", shared: true, info: map[string]any{"root_path": "/tmp/other"}, want: "canonical"},
|
||||
{name: "shared external sidecar", shared: true, info: map[string]any{"external": map[string]any{"host": "db.example", "port": 3307}}, want: "externally hosted"},
|
||||
{name: "shared stale control", shared: true, asset: "proxy.log", want: "stale proxy control"},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
dir, home := t.TempDir(), t.TempDir()
|
||||
env := migrationFrontDoorEnv(home)
|
||||
beadsDir := filepath.Join(dir, ".beads")
|
||||
root := filepath.Join(beadsDir, "dolt")
|
||||
if tc.shared {
|
||||
shared := filepath.Join(home, "shared-server")
|
||||
env = append(env, "BEADS_SHARED_SERVER_DIR="+shared, "BEADS_DOLT_SHARED_SERVER=1")
|
||||
root = filepath.Join(shared, "dolt")
|
||||
}
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(root, ".dolt"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(root, ".dolt", "repo_state.json"), []byte(`{"head":"refs/heads/main","remotes":{},"backups":{},"branches":{}}`), 0o600))
|
||||
require.NoError(t, os.MkdirAll(beadsDir, 0o700))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(beadsDir, "metadata.json"), []byte(`{"database":"myproj","backend":"dolt","dolt_mode":"proxied-server"}`), 0o600))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(beadsDir, ".local_version"), []byte(Version), 0o600))
|
||||
if tc.shared {
|
||||
require.NoError(t, os.WriteFile(filepath.Join(beadsDir, "config.yaml"), []byte("dolt:\n shared-server: false\n"), 0o600))
|
||||
}
|
||||
if tc.info == nil {
|
||||
tc.info = map[string]any{"root_path": root}
|
||||
}
|
||||
if _, ok := tc.info["root_path"]; !ok {
|
||||
tc.info["root_path"] = root
|
||||
}
|
||||
b, err := json.Marshal(tc.info)
|
||||
require.NoError(t, err)
|
||||
sidecar := filepath.Join(beadsDir, "proxied_server_client_info.json")
|
||||
require.NoError(t, os.WriteFile(sidecar, b, 0o600))
|
||||
if tc.asset != "" {
|
||||
require.NoError(t, os.WriteFile(filepath.Join(root, tc.asset), []byte("stale"), 0o600))
|
||||
}
|
||||
before := snapshotMigrationTree(t, beadsDir, root)
|
||||
for _, jsonMode := range []bool{false, true} {
|
||||
args := []string{"migrate", "from-server-to-proxied-server"}
|
||||
if tc.shared {
|
||||
args[1] = "from-shared-server-to-proxied-server"
|
||||
}
|
||||
if jsonMode {
|
||||
args = append([]string{"--json"}, args...)
|
||||
}
|
||||
stdout, stderr, runErr := runBDExecSeparated(t, bd, dir, env, args...)
|
||||
require.Error(t, runErr)
|
||||
exitErr, ok := runErr.(*exec.ExitError)
|
||||
require.True(t, ok)
|
||||
require.Equal(t, 1, exitErr.ExitCode())
|
||||
if jsonMode {
|
||||
var payload map[string]any
|
||||
require.NoError(t, json.Unmarshal([]byte(stdout), &payload), stdout)
|
||||
if data, ok := payload["data"].(map[string]any); ok {
|
||||
payload = data
|
||||
}
|
||||
assert.Equal(t, "proxy.migrate.invalid_state", payload["code"])
|
||||
assert.Equal(t, false, payload["mutates"])
|
||||
} else {
|
||||
assert.Contains(t, strings.ToLower(stderr), strings.ToLower(tc.want))
|
||||
}
|
||||
assert.Equal(t, before, snapshotMigrationTree(t, beadsDir, root))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestMigrateDoltModeDirectForwardFaultsFrontDoor runs every checkpoint fault
|
||||
// through a real managed-local bd process, then retries twice. The issue row
|
||||
// proves the physical Dolt data survived the journal repair and idempotent
|
||||
// second invocation.
|
||||
func TestMigrateDoltModeDirectForwardFaultsFrontDoor(t *testing.T) {
|
||||
if os.Getenv("BEADS_TEST_MIGRATION_FRONTDOOR") != "1" {
|
||||
t.Skip("set BEADS_TEST_MIGRATION_FRONTDOOR=1")
|
||||
}
|
||||
bd := migrationFrontDoorBinary(t)
|
||||
for _, phase := range []string{"prepared", "target_configured", "old_controls_retired", "verified", "committed"} {
|
||||
t.Run(phase, func(t *testing.T) {
|
||||
dir, home := t.TempDir(), t.TempDir()
|
||||
env := migrationFrontDoorEnv(home)
|
||||
out, err := runBDExecWithBinary(t, bd, dir, env, "init", "--backend", "dolt", "--server", "--prefix", "fault", "--quiet")
|
||||
require.NoError(t, err, "init: %s", out)
|
||||
created, err := runBDExecWithBinary(t, bd, dir, env, "create", "migration sentinel", "--json")
|
||||
require.NoError(t, err, "create: %s", created)
|
||||
var row struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
require.NoError(t, json.Unmarshal([]byte(created), &row))
|
||||
blockerID := createDependencyPair(t, bd, dir, env, row.ID)
|
||||
_, _ = runBDExecWithBinary(t, bd, dir, env, "dolt", "stop")
|
||||
beadsDir := filepath.Join(dir, ".beads")
|
||||
root := filepath.Join(beadsDir, "dolt")
|
||||
touchFile(t, filepath.Join(root, "migration-sentinel"))
|
||||
sentinelBefore := snapshotMigrationTree(t, beadsDir, root)
|
||||
faultEnv := append(append([]string(nil), env...), "BEADS_MIGRATION_FAIL_PHASE="+phase)
|
||||
out, err = runBDExecWithBinary(t, bd, dir, faultEnv, "migrate", "from-server-to-proxied-server")
|
||||
require.Error(t, err, "fault phase unexpectedly succeeded: %s", out)
|
||||
exitErr, ok := err.(*exec.ExitError)
|
||||
require.True(t, ok)
|
||||
require.Equal(t, 1, exitErr.ExitCode())
|
||||
j, jErr := os.Stat(filepath.Join(beadsDir, migrateJournalFileName))
|
||||
require.NoError(t, jErr)
|
||||
require.False(t, j.IsDir())
|
||||
afterFailure := snapshotMigrationTree(t, beadsDir, root)
|
||||
require.Equal(t, sentinelBefore[filepath.Join(root, "migration-sentinel")], afterFailure[filepath.Join(root, "migration-sentinel")])
|
||||
retryEnv := append(append([]string(nil), env...), "BEADS_MIGRATION_FAIL_PHASE=")
|
||||
require.NoError(t, func() error {
|
||||
_, e := runBDExecWithBinary(t, bd, dir, retryEnv, "migrate", "from-server-to-proxied-server")
|
||||
return e
|
||||
}())
|
||||
after := snapshotMigrationTree(t, beadsDir, root)
|
||||
require.NoError(t, func() error {
|
||||
_, e := runBDExecWithBinary(t, bd, dir, retryEnv, "migrate", "from-server-to-proxied-server")
|
||||
return e
|
||||
}())
|
||||
assert.Equal(t, after, snapshotMigrationTree(t, beadsDir, root))
|
||||
assertDirectMigrationFinal(t, beadsDir, root, false, filepath.Join(root, "migration-sentinel"))
|
||||
assertDependencyPair(t, bd, dir, retryEnv, row.ID, blockerID)
|
||||
show, showErr := runBDExecWithBinary(t, bd, dir, retryEnv, "show", row.ID, "--json")
|
||||
require.NoError(t, showErr, "show sentinel: %s", show)
|
||||
assert.Contains(t, show, "migration sentinel")
|
||||
_, _ = runBDExecWithBinary(t, bd, dir, retryEnv, "dolt", "stop")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestMigrateDoltModeDirectReverseFaultsFrontDoor covers the reverse
|
||||
// managed-local transition through the executable for every checkpoint.
|
||||
func TestMigrateDoltModeDirectReverseFaultsFrontDoor(t *testing.T) {
|
||||
if os.Getenv("BEADS_TEST_MIGRATION_FRONTDOOR") != "1" {
|
||||
t.Skip("set BEADS_TEST_MIGRATION_FRONTDOOR=1")
|
||||
}
|
||||
bd := migrationFrontDoorBinary(t)
|
||||
for _, phase := range []string{"prepared", "target_configured", "old_controls_retired", "verified", "committed"} {
|
||||
t.Run(phase, func(t *testing.T) {
|
||||
dir, home := t.TempDir(), t.TempDir()
|
||||
env := migrationFrontDoorEnv(home)
|
||||
out, err := runBDExecWithBinary(t, bd, dir, env, "init", "--backend", "dolt", "--server", "--prefix", "reverse", "--quiet")
|
||||
require.NoError(t, err, "init: %s", out)
|
||||
created, err := runBDExecWithBinary(t, bd, dir, env, "create", "reverse migration sentinel", "--json")
|
||||
require.NoError(t, err, "create: %s", created)
|
||||
var row struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
require.NoError(t, json.Unmarshal([]byte(created), &row))
|
||||
blockerID := createDependencyPair(t, bd, dir, env, row.ID)
|
||||
_, _ = runBDExecWithBinary(t, bd, dir, env, "dolt", "stop")
|
||||
_, err = runBDExecWithBinary(t, bd, dir, env, "migrate", "from-server-to-proxied-server")
|
||||
require.NoError(t, err)
|
||||
_, _ = runBDExecWithBinary(t, bd, dir, env, "dolt", "stop")
|
||||
beadsDir := filepath.Join(dir, ".beads")
|
||||
root := filepath.Join(beadsDir, "dolt")
|
||||
touchFile(t, filepath.Join(root, "migration-sentinel"))
|
||||
before := snapshotMigrationTree(t, beadsDir, root)
|
||||
faultEnv := append(append([]string(nil), env...), "BEADS_MIGRATION_FAIL_PHASE="+phase)
|
||||
out, err = runBDExecWithBinary(t, bd, dir, faultEnv, "migrate", "from-proxied-server-to-server")
|
||||
require.Error(t, err, "fault phase unexpectedly succeeded: %s", out)
|
||||
exitErr, ok := err.(*exec.ExitError)
|
||||
require.True(t, ok)
|
||||
require.Equal(t, 1, exitErr.ExitCode())
|
||||
require.Equal(t, before[filepath.Join(root, "migration-sentinel")], snapshotMigrationTree(t, beadsDir, root)[filepath.Join(root, "migration-sentinel")])
|
||||
retryEnv := append(append([]string(nil), env...), "BEADS_MIGRATION_FAIL_PHASE=")
|
||||
out, err = runBDExecWithBinary(t, bd, dir, retryEnv, "migrate", "from-proxied-server-to-server")
|
||||
require.NoError(t, err, "retry: %s", out)
|
||||
after := snapshotMigrationTree(t, beadsDir, root)
|
||||
_, err = runBDExecWithBinary(t, bd, dir, retryEnv, "migrate", "from-proxied-server-to-server")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, after, snapshotMigrationTree(t, beadsDir, root))
|
||||
assertDirectMigrationFinal(t, beadsDir, root, true, filepath.Join(root, "migration-sentinel"))
|
||||
assertDependencyPair(t, bd, dir, retryEnv, row.ID, blockerID)
|
||||
show, err := runBDExecWithBinary(t, bd, dir, retryEnv, "show", row.ID, "--json")
|
||||
require.NoError(t, err, "show: %s", show)
|
||||
assert.Contains(t, show, "reverse migration sentinel")
|
||||
_, _ = runBDExecWithBinary(t, bd, dir, retryEnv, "dolt", "stop")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func assertDirectMigrationFinal(t *testing.T, beadsDir, root string, reverse bool, sentinel string) {
|
||||
t.Helper()
|
||||
meta, err := os.ReadFile(filepath.Join(beadsDir, "metadata.json"))
|
||||
require.NoError(t, err)
|
||||
var got map[string]any
|
||||
require.NoError(t, json.Unmarshal(meta, &got))
|
||||
if reverse {
|
||||
assert.Equal(t, "server", got["dolt_mode"])
|
||||
_, err = os.Stat(filepath.Join(beadsDir, configfile.ProxiedServerClientInfoFileName))
|
||||
assert.True(t, os.IsNotExist(err), "reverse sidecar remains")
|
||||
if value, ok := config.WorkspaceYamlValue(beadsDir, "dolt.shared-server"); ok {
|
||||
assert.Equal(t, "false", strings.ToLower(value), "direct reverse must not enable shared topology")
|
||||
}
|
||||
for _, path := range proxy.ControlFilePaths(root) {
|
||||
_, statErr := os.Stat(path)
|
||||
if statErr == nil && (filepath.Base(path) == proxy.LockFileName || filepath.Base(path) == server.LockFileName) {
|
||||
lock, lockErr := util.TryLock(path)
|
||||
if lockErr == nil {
|
||||
lock.Unlock()
|
||||
continue
|
||||
}
|
||||
}
|
||||
assert.True(t, os.IsNotExist(statErr), "stale proxy control %s", path)
|
||||
}
|
||||
} else {
|
||||
assert.Equal(t, "proxied-server", got["dolt_mode"])
|
||||
info, infoErr := configfile.LoadProxiedServerClientInfo(beadsDir)
|
||||
require.NoError(t, infoErr)
|
||||
require.NotNil(t, info)
|
||||
assert.Equal(t, filepath.Clean(root), filepath.Clean(info.ResolvedRootPath(beadsDir)))
|
||||
for _, path := range serverAssetNames() {
|
||||
_, statErr := os.Stat(filepath.Join(beadsDir, path))
|
||||
assert.True(t, os.IsNotExist(statErr), "stale server control %s", path)
|
||||
}
|
||||
}
|
||||
for _, path := range []string{filepath.Join(beadsDir, migrateJournalFileName), filepath.Join(beadsDir, migrateLockFileName)} {
|
||||
_, statErr := os.Stat(path)
|
||||
assert.True(t, os.IsNotExist(statErr), "stale migration artifact %s", path)
|
||||
}
|
||||
sentinelBytes, sentinelErr := os.ReadFile(sentinel)
|
||||
require.NoError(t, sentinelErr)
|
||||
assert.Equal(t, []byte("x"), sentinelBytes, "migration changed Dolt root sentinel")
|
||||
doltState, _ := doltserver.IsRunning(beadsDir)
|
||||
assert.False(t, doltState != nil && doltState.Running, "direct Dolt process still running")
|
||||
proxyRunning, _ := proxy.IsRunning(root)
|
||||
assert.False(t, proxyRunning, "direct proxy process still running")
|
||||
}
|
||||
|
||||
// sharedMigrationFrontDoorSnapshot records both durable migration artifacts
|
||||
// and the live ownership probes. The latter are deliberately queried rather
|
||||
// than represented by pid/status files, which can be stale after a crash.
|
||||
type sharedMigrationFrontDoorSnapshot struct {
|
||||
Tree map[string][]byte
|
||||
Controls map[string]string
|
||||
DoltRunning bool
|
||||
DoltPID int
|
||||
DoltPort int
|
||||
ProxyRunning bool
|
||||
}
|
||||
|
||||
func snapshotSharedMigrationFrontDoor(t *testing.T, beadsDir, sharedDir, root string) sharedMigrationFrontDoorSnapshot {
|
||||
t.Helper()
|
||||
doltState, _ := doltserver.IsRunning(sharedDir)
|
||||
doltRunning := doltState != nil && doltState.Running
|
||||
doltPID, doltPort := 0, 0
|
||||
if doltState != nil {
|
||||
doltPID, doltPort = doltState.PID, doltState.Port
|
||||
}
|
||||
proxyRunning, _ := proxy.IsRunning(root)
|
||||
controls := map[string]string{}
|
||||
paths := append([]string{
|
||||
filepath.Join(beadsDir, "metadata.json"),
|
||||
filepath.Join(beadsDir, "config.yaml"),
|
||||
filepath.Join(beadsDir, configfile.ProxiedServerClientInfoFileName),
|
||||
filepath.Join(beadsDir, migrateJournalFileName),
|
||||
filepath.Join(beadsDir, migrateLockFileName),
|
||||
filepath.Join(beadsDir, "dolt.gate.lock"),
|
||||
}, doltserver.StateFilePaths(sharedDir)...)
|
||||
paths = append(paths, proxy.ControlFilePaths(root)...)
|
||||
for _, path := range paths {
|
||||
contents, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
controls[path] = "missing"
|
||||
continue
|
||||
}
|
||||
controls[path] = string(contents)
|
||||
}
|
||||
return sharedMigrationFrontDoorSnapshot{
|
||||
Tree: snapshotMigrationTree(t, beadsDir, sharedDir),
|
||||
Controls: controls,
|
||||
DoltRunning: doltRunning,
|
||||
DoltPID: doltPID,
|
||||
DoltPort: doltPort,
|
||||
ProxyRunning: proxyRunning,
|
||||
}
|
||||
}
|
||||
|
||||
func setupSharedMigrationFrontDoor(t *testing.T, bd string) (dir, home, sharedDir, sharedRoot, issueID, blockerID string, env []string) {
|
||||
t.Helper()
|
||||
dir, home = t.TempDir(), t.TempDir()
|
||||
sharedDir = filepath.Join(home, "shared-server")
|
||||
sharedRoot = filepath.Join(sharedDir, "dolt")
|
||||
env = migrationFrontDoorEnv(home)
|
||||
portProbe, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
require.NoError(t, err)
|
||||
port := portProbe.Addr().(*net.TCPAddr).Port
|
||||
require.NoError(t, portProbe.Close())
|
||||
env = append(env, "BEADS_SHARED_SERVER_DIR="+sharedDir, "BEADS_DOLT_SHARED_SERVER=1", "BEADS_DOLT_SERVER_PORT="+strconv.Itoa(port))
|
||||
out, err := runBDExecWithBinary(t, bd, dir, env, "init", "--backend", "dolt", "--shared-server", "--prefix", "shared", "--quiet")
|
||||
require.NoError(t, err, "shared init: %s", out)
|
||||
created, err := runBDExecWithBinary(t, bd, dir, env, "create", "shared migration sentinel", "--json")
|
||||
require.NoError(t, err, "shared create: %s", created)
|
||||
var row struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
require.NoError(t, json.Unmarshal([]byte(created), &row))
|
||||
blockerID = createDependencyPair(t, bd, dir, env, row.ID)
|
||||
require.NotEmpty(t, row.ID)
|
||||
// Migrations require exclusive ownership. Stop the real shared Dolt
|
||||
// process before taking the baseline snapshot.
|
||||
status, _ := runBDExecWithBinary(t, bd, dir, env, "dolt", "status")
|
||||
if strings.Contains(status, "Dolt server: running") {
|
||||
stop, stopErr := runBDExecWithBinary(t, bd, dir, env, "dolt", "stop")
|
||||
require.NoError(t, stopErr, "stop shared server: %s", stop)
|
||||
}
|
||||
return dir, home, sharedDir, sharedRoot, row.ID, blockerID, env
|
||||
}
|
||||
|
||||
func assertSharedMigrationResult(t *testing.T, bd, dir string, env []string, beadsDir, sharedDir, sharedRoot, issueID, blockerID string, wantShared bool) {
|
||||
t.Helper()
|
||||
meta, err := os.ReadFile(filepath.Join(beadsDir, "metadata.json"))
|
||||
require.NoError(t, err)
|
||||
var metadata map[string]any
|
||||
require.NoError(t, json.Unmarshal(meta, &metadata))
|
||||
wantMode := "proxied-server"
|
||||
if wantShared {
|
||||
wantMode = "server"
|
||||
}
|
||||
assert.Equal(t, wantMode, metadata["dolt_mode"])
|
||||
yamlValue, yamlSet := readWorkspaceYamlValueForFrontDoor(t, beadsDir, "dolt.shared-server")
|
||||
assert.True(t, yamlSet)
|
||||
assert.Equal(t, fmt.Sprintf("%t", wantShared), strings.ToLower(yamlValue))
|
||||
sidecarPath := filepath.Join(beadsDir, "proxied_server_client_info.json")
|
||||
if wantShared {
|
||||
_, statErr := os.Stat(sidecarPath)
|
||||
assert.True(t, os.IsNotExist(statErr), "reverse migration must remove sidecar")
|
||||
} else {
|
||||
sidecar, sidecarErr := os.ReadFile(sidecarPath)
|
||||
require.NoError(t, sidecarErr)
|
||||
assert.Contains(t, string(sidecar), sharedRoot)
|
||||
}
|
||||
_, journalErr := os.Stat(filepath.Join(beadsDir, migrateJournalFileName))
|
||||
assert.True(t, os.IsNotExist(journalErr), "migration journal must be finalized")
|
||||
// Probe ownership before `show`, because opening a shared workspace can
|
||||
// legitimately auto-start its managed server.
|
||||
doltState, _ := doltserver.IsRunning(sharedDir)
|
||||
assert.False(t, doltState != nil && doltState.Running, "shared Dolt process still running before show")
|
||||
proxyRunning, _ := proxy.IsRunning(sharedRoot)
|
||||
assert.False(t, proxyRunning, "proxy process still running before show")
|
||||
if wantShared {
|
||||
// Shared-server mode is an externally addressed managed server and does
|
||||
// not auto-start on read paths. Start it explicitly to prove the real
|
||||
// issue row remains readable after reverse migration.
|
||||
start, startErr := runBDExecWithBinary(t, bd, dir, env, "dolt", "start")
|
||||
require.NoError(t, startErr, "start shared server for verification: %s", start)
|
||||
}
|
||||
show, showErr := runBDExecWithBinary(t, bd, dir, env, "show", issueID, "--json")
|
||||
require.NoError(t, showErr, "show migrated issue: %s", show)
|
||||
assert.Contains(t, show, "shared migration sentinel")
|
||||
if blockerID != "" {
|
||||
assertDependencyPair(t, bd, dir, env, issueID, blockerID)
|
||||
}
|
||||
// `show` may auto-start the managed shared server. Stop it before probing
|
||||
// final ownership so the idempotence assertion covers the migration itself.
|
||||
_, _ = runBDExecWithBinary(t, bd, dir, env, "dolt", "stop")
|
||||
// Neither migration direction may leave a managed child alive.
|
||||
doltState, _ = doltserver.IsRunning(sharedDir)
|
||||
assert.False(t, doltState != nil && doltState.Running, "shared Dolt process still running")
|
||||
proxyRunning, _ = proxy.IsRunning(sharedRoot)
|
||||
assert.False(t, proxyRunning, "proxy process still running")
|
||||
}
|
||||
|
||||
func readWorkspaceYamlValueForFrontDoor(t *testing.T, beadsDir, key string) (string, bool) {
|
||||
t.Helper()
|
||||
value, ok := config.WorkspaceYamlValue(beadsDir, key)
|
||||
return value, ok
|
||||
}
|
||||
|
||||
// TestMigrateDoltModeSharedForwardFaultsFrontDoor exercises all five
|
||||
// checkpoints through the real cgo bd subprocess using a disposable managed
|
||||
// shared-server root. Each injected fault is repaired by a retry and a second
|
||||
// successful invocation proves idempotence without changing durable state.
|
||||
func TestMigrateDoltModeSharedForwardFaultsFrontDoor(t *testing.T) {
|
||||
if os.Getenv("BEADS_TEST_MIGRATION_FRONTDOOR") != "1" {
|
||||
t.Skip("set BEADS_TEST_MIGRATION_FRONTDOOR=1")
|
||||
}
|
||||
bd := migrationFrontDoorBinary(t)
|
||||
for _, phase := range []string{"prepared", "target_configured", "old_controls_retired", "verified", "committed"} {
|
||||
t.Run(phase, func(t *testing.T) {
|
||||
dir, _, sharedDir, sharedRoot, issueID, blockerID, env := setupSharedMigrationFrontDoor(t, bd)
|
||||
beadsDir := filepath.Join(dir, ".beads")
|
||||
touchFile(t, filepath.Join(sharedRoot, "migration-sentinel"))
|
||||
before := snapshotSharedMigrationFrontDoor(t, beadsDir, sharedDir, sharedRoot)
|
||||
faultEnv := append(append([]string(nil), env...), "BEADS_MIGRATION_FAIL_PHASE="+phase)
|
||||
out, err := runBDExecWithBinary(t, bd, dir, faultEnv, "migrate", "from-shared-server-to-proxied-server")
|
||||
require.Error(t, err, "fault phase unexpectedly succeeded: %s", out)
|
||||
require.FileExists(t, filepath.Join(beadsDir, migrateJournalFileName))
|
||||
failed := snapshotSharedMigrationFrontDoor(t, beadsDir, sharedDir, sharedRoot)
|
||||
assert.Equal(t, before.Tree[filepath.Join(sharedRoot, "migration-sentinel")], failed.Tree[filepath.Join(sharedRoot, "migration-sentinel")])
|
||||
retryEnv := append(append([]string(nil), env...), "BEADS_MIGRATION_FAIL_PHASE=")
|
||||
out, err = runBDExecWithBinary(t, bd, dir, retryEnv, "migrate", "from-shared-server-to-proxied-server")
|
||||
require.NoError(t, err, "retry: %s", out)
|
||||
after := snapshotSharedMigrationFrontDoor(t, beadsDir, sharedDir, sharedRoot)
|
||||
out, err = runBDExecWithBinary(t, bd, dir, retryEnv, "migrate", "from-shared-server-to-proxied-server")
|
||||
require.NoError(t, err, "second success: %s", out)
|
||||
assert.Equal(t, after, snapshotSharedMigrationFrontDoor(t, beadsDir, sharedDir, sharedRoot))
|
||||
assertSharedMigrationResult(t, bd, dir, retryEnv, beadsDir, sharedDir, sharedRoot, issueID, blockerID, false)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestMigrateDoltModeSharedReverseFaultsFrontDoor is the reverse-direction
|
||||
// counterpart of TestMigrateDoltModeSharedForwardFaultsFrontDoor.
|
||||
func TestMigrateDoltModeSharedReverseFaultsFrontDoor(t *testing.T) {
|
||||
if os.Getenv("BEADS_TEST_MIGRATION_FRONTDOOR") != "1" {
|
||||
t.Skip("set BEADS_TEST_MIGRATION_FRONTDOOR=1")
|
||||
}
|
||||
bd := migrationFrontDoorBinary(t)
|
||||
for _, phase := range []string{"prepared", "target_configured", "old_controls_retired", "verified", "committed"} {
|
||||
t.Run(phase, func(t *testing.T) {
|
||||
dir, _, sharedDir, sharedRoot, issueID, blockerID, env := setupSharedMigrationFrontDoor(t, bd)
|
||||
beadsDir := filepath.Join(dir, ".beads")
|
||||
_, err := runBDExecWithBinary(t, bd, dir, env, "migrate", "from-shared-server-to-proxied-server")
|
||||
require.NoError(t, err)
|
||||
// Forward migration leaves the proxy stopped; keep this explicit so
|
||||
// the reverse matrix never races a child process from auto-start.
|
||||
_, _ = runBDExecWithBinary(t, bd, dir, env, "dolt", "stop")
|
||||
touchFile(t, filepath.Join(sharedRoot, "migration-sentinel"))
|
||||
before := snapshotSharedMigrationFrontDoor(t, beadsDir, sharedDir, sharedRoot)
|
||||
faultEnv := append(append([]string(nil), env...), "BEADS_MIGRATION_FAIL_PHASE="+phase)
|
||||
out, err := runBDExecWithBinary(t, bd, dir, faultEnv, "migrate", "from-proxied-server-to-shared-server")
|
||||
require.Error(t, err, "fault phase unexpectedly succeeded: %s", out)
|
||||
require.FileExists(t, filepath.Join(beadsDir, migrateJournalFileName))
|
||||
failed := snapshotSharedMigrationFrontDoor(t, beadsDir, sharedDir, sharedRoot)
|
||||
assert.Equal(t, before.Tree[filepath.Join(sharedRoot, "migration-sentinel")], failed.Tree[filepath.Join(sharedRoot, "migration-sentinel")])
|
||||
retryEnv := append(append([]string(nil), env...), "BEADS_MIGRATION_FAIL_PHASE=")
|
||||
out, err = runBDExecWithBinary(t, bd, dir, retryEnv, "migrate", "from-proxied-server-to-shared-server")
|
||||
require.NoError(t, err, "retry: %s", out)
|
||||
after := snapshotSharedMigrationFrontDoor(t, beadsDir, sharedDir, sharedRoot)
|
||||
out, err = runBDExecWithBinary(t, bd, dir, retryEnv, "migrate", "from-proxied-server-to-shared-server")
|
||||
require.NoError(t, err, "second success: %s", out)
|
||||
assert.Equal(t, after, snapshotSharedMigrationFrontDoor(t, beadsDir, sharedDir, sharedRoot))
|
||||
assertSharedMigrationResult(t, bd, dir, retryEnv, beadsDir, sharedDir, sharedRoot, issueID, blockerID, true)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +1,74 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/steveyegge/beads/internal/config"
|
||||
"github.com/steveyegge/beads/internal/configfile"
|
||||
"github.com/steveyegge/beads/internal/storage/dbproxy/proxy"
|
||||
"github.com/steveyegge/beads/internal/storage/dbproxy/server"
|
||||
"github.com/steveyegge/beads/internal/storage/dbproxy/util"
|
||||
)
|
||||
|
||||
func captureMigrationJSON(t *testing.T, fn func() error) (string, error) {
|
||||
t.Helper()
|
||||
stdioMutex.Lock()
|
||||
defer stdioMutex.Unlock()
|
||||
old := os.Stdout
|
||||
r, w, err := os.Pipe()
|
||||
require.NoError(t, err)
|
||||
os.Stdout = w
|
||||
done := make(chan string, 1)
|
||||
go func() {
|
||||
var buf bytes.Buffer
|
||||
_, _ = io.Copy(&buf, r)
|
||||
done <- buf.String()
|
||||
}()
|
||||
callErr := fn()
|
||||
_ = w.Close()
|
||||
os.Stdout = old
|
||||
out := <-done
|
||||
_ = r.Close()
|
||||
return out, callErr
|
||||
}
|
||||
|
||||
func snapshotMigrationTree(t *testing.T, roots ...string) map[string][]byte {
|
||||
t.Helper()
|
||||
out := map[string][]byte{}
|
||||
for _, root := range roots {
|
||||
_ = filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
|
||||
if strings.HasSuffix(path, ".gate.lock") || strings.HasSuffix(path, migrateLockFileName) {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
switch {
|
||||
case info.Mode()&os.ModeSymlink != 0:
|
||||
target, _ := os.Readlink(path)
|
||||
out[path] = []byte("symlink:" + target)
|
||||
case info.IsDir():
|
||||
out[path] = []byte("dir:" + info.Mode().String())
|
||||
case info.Mode().IsRegular():
|
||||
b, _ := os.ReadFile(path)
|
||||
out[path] = append([]byte("file:"+info.Mode().String()+"\x00"), b...)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func migrateModeWorkspace(t *testing.T, mode string) string {
|
||||
t.Helper()
|
||||
t.Setenv("BEADS_PROXIED_SERVER_ROOT_PATH", "")
|
||||
|
|
@ -22,6 +79,8 @@ func migrateModeWorkspace(t *testing.T, mode string) string {
|
|||
dir := t.TempDir()
|
||||
beadsDir := filepath.Join(dir, ".beads")
|
||||
require.NoError(t, os.MkdirAll(beadsDir, 0o755))
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(beadsDir, "dolt", ".dolt"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(beadsDir, "dolt", ".dolt", "repo_state.json"), []byte(`{"head":"refs/heads/main","remotes":{},"backups":{},"branches":{}}`), 0o600))
|
||||
writeMetadataConfig(t, beadsDir, mode, "myproj")
|
||||
t.Chdir(dir)
|
||||
return beadsDir
|
||||
|
|
@ -33,6 +92,13 @@ func touchFile(t *testing.T, path string) {
|
|||
require.NoError(t, os.WriteFile(path, []byte("x"), 0o600))
|
||||
}
|
||||
|
||||
func mustReadFile(t *testing.T, path string) []byte {
|
||||
t.Helper()
|
||||
b, err := os.ReadFile(path)
|
||||
require.NoError(t, err)
|
||||
return b
|
||||
}
|
||||
|
||||
func serverAssetNames() []string {
|
||||
return []string{"dolt-server.pid", "dolt-server.port", "dolt-server.lock", "dolt-server.log", "dolt-server.log.1"}
|
||||
}
|
||||
|
|
@ -73,6 +139,33 @@ func TestMigrateToProxiedServer_RejectsNonServerMode(t *testing.T) {
|
|||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestMigrateToProxiedServer_MissingRootFailsClosed(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
require.NoError(t, os.RemoveAll(filepath.Join(beadsDir, "dolt")))
|
||||
before, err := os.ReadFile(configfile.ConfigPath(beadsDir))
|
||||
require.NoError(t, err)
|
||||
require.Error(t, runMigrateToProxiedServer(false, 0, false))
|
||||
after, err := os.ReadFile(configfile.ConfigPath(beadsDir))
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, before, after)
|
||||
}
|
||||
|
||||
func TestMigrateToProxiedServer_MalformedRootIdentityFailsClosed(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
require.NoError(t, os.WriteFile(filepath.Join(beadsDir, "dolt", ".dolt", "repo_state.json"), []byte("not-json"), 0o600))
|
||||
require.Error(t, runMigrateToProxiedServer(false, 0, false))
|
||||
}
|
||||
|
||||
func TestMigrateToProxiedServer_InvalidRootIdentityShapesFailClosed(t *testing.T) {
|
||||
for _, body := range []string{`{}`, `null`, `{"garbage":true}`, `{"head":null,"remotes":{},"backups":{},"branches":{}}`, `{"head":"refs/heads/","remotes":{},"backups":{},"branches":{}}`} {
|
||||
t.Run(body, func(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
require.NoError(t, os.WriteFile(filepath.Join(beadsDir, "dolt", ".dolt", "repo_state.json"), []byte(body), 0o600))
|
||||
require.Error(t, runMigrateToProxiedServer(false, 0, false))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateToProxiedServer_DryRunWritesNothing(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
touchFile(t, filepath.Join(beadsDir, "dolt-server.log"))
|
||||
|
|
@ -90,6 +183,133 @@ func TestMigrateToProxiedServer_DryRunWritesNothing(t *testing.T) {
|
|||
require.NoError(t, assetErr, "dry-run must not delete assets")
|
||||
}
|
||||
|
||||
func TestMigrateToProxiedServer_MalformedWorkspaceYAMLFailsClosed(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
configPath := filepath.Join(beadsDir, "config.yaml")
|
||||
require.NoError(t, os.WriteFile(configPath, []byte("dolt: ["), 0o600))
|
||||
before := snapshotMigrationTree(t, beadsDir)
|
||||
var err error
|
||||
stderr := captureStderr(t, func() { err = runMigrateToProxiedServer(false, 0, false) })
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, strings.ToLower(stderr), "parsing workspace config")
|
||||
assert.Equal(t, before, snapshotMigrationTree(t, beadsDir))
|
||||
}
|
||||
|
||||
func TestMigrationSharedTopology_ExplicitYAMLOverridesEnvironment(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
env string
|
||||
yaml string
|
||||
want bool
|
||||
}{
|
||||
{name: "false overrides true env", env: "1", yaml: "false", want: false},
|
||||
{name: "true overrides empty env", env: "", yaml: "true", want: true},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
t.Setenv("BEADS_DOLT_SHARED_SERVER", tc.env)
|
||||
require.NoError(t, os.WriteFile(filepath.Join(beadsDir, "config.yaml"), []byte("dolt:\n shared-server: "+tc.yaml+"\n"), 0o600))
|
||||
live, value, present, err := migrationSharedTopology(beadsDir)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, present)
|
||||
assert.Equal(t, tc.want, value)
|
||||
assert.Equal(t, tc.want, live)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateToProxiedServer_UnreadableWorkspaceYAMLFailsClosed(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
t.Setenv("BEADS_DOLT_SHARED_SERVER", "1")
|
||||
configPath := filepath.Join(beadsDir, "config.yaml")
|
||||
require.NoError(t, os.Mkdir(configPath, 0o700))
|
||||
before := snapshotMigrationTree(t, beadsDir)
|
||||
var err error
|
||||
stderr := captureStderr(t, func() { err = runMigrateToProxiedServer(false, 0, false) })
|
||||
require.Error(t, err)
|
||||
code, ok := exitCodeFromError(err)
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, 1, code)
|
||||
assert.Contains(t, strings.ToLower(stderr), "reading workspace config")
|
||||
assert.Equal(t, before, snapshotMigrationTree(t, beadsDir))
|
||||
}
|
||||
|
||||
func TestMigrateToProxiedServer_AlreadyProxiedRejectsStaleControl(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeProxiedServer)
|
||||
root := filepath.Join(beadsDir, "dolt")
|
||||
require.NoError(t, configfile.SaveProxiedServerClientInfo(beadsDir, &configfile.ProxiedServerClientInfo{RootPath: root}))
|
||||
touchFile(t, filepath.Join(root, "proxy.log"))
|
||||
before := snapshotMigrationTree(t, beadsDir, root)
|
||||
require.Error(t, runMigrateToProxiedServer(false, 0, false))
|
||||
assert.Equal(t, before, snapshotMigrationTree(t, beadsDir, root))
|
||||
}
|
||||
|
||||
func TestMigrateToProxiedServer_AlreadyProxiedRejectsBadSidecar(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
info *configfile.ProxiedServerClientInfo
|
||||
}{
|
||||
{"external", &configfile.ProxiedServerClientInfo{RootPath: "/tmp/ext", External: &configfile.ExternalDoltConfig{Host: "db.example", Port: 3307}}},
|
||||
{"mismatch", &configfile.ProxiedServerClientInfo{RootPath: "/tmp/other"}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeProxiedServer)
|
||||
require.NoError(t, configfile.SaveProxiedServerClientInfo(beadsDir, tc.info))
|
||||
before := snapshotMigrationTree(t, beadsDir)
|
||||
require.Error(t, runMigrateToProxiedServer(false, 0, false))
|
||||
assert.Equal(t, before, snapshotMigrationTree(t, beadsDir))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateToProxiedServer_StaleSidecarFailsClosed(t *testing.T) {
|
||||
rootCases := []struct {
|
||||
name string
|
||||
info *configfile.ProxiedServerClientInfo
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "external endpoint",
|
||||
info: &configfile.ProxiedServerClientInfo{
|
||||
RootPath: filepath.Join("/", "external-root"),
|
||||
External: &configfile.ExternalDoltConfig{Host: "db.example", Port: 3307},
|
||||
},
|
||||
want: "externally hosted proxied dolt endpoint",
|
||||
},
|
||||
{
|
||||
name: "mismatched local root",
|
||||
info: &configfile.ProxiedServerClientInfo{RootPath: filepath.Join("/", "another-repo")},
|
||||
want: "sidecar root",
|
||||
},
|
||||
{
|
||||
name: "matching relative root",
|
||||
info: &configfile.ProxiedServerClientInfo{RootPath: "dolt"},
|
||||
want: "exists without a recoverable journal",
|
||||
},
|
||||
}
|
||||
for _, tc := range rootCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
root := filepath.Join(beadsDir, "dolt")
|
||||
require.NoError(t, configfile.SaveProxiedServerClientInfo(beadsDir, tc.info))
|
||||
before := snapshotMigrationTree(t, beadsDir, root)
|
||||
var migrateErr error
|
||||
stderr := captureStderr(t, func() {
|
||||
migrateErr = runMigrateToProxiedServer(false, 0, false)
|
||||
})
|
||||
require.Error(t, migrateErr)
|
||||
assert.Contains(t, strings.ToLower(stderr), tc.want)
|
||||
assert.Equal(t, before, snapshotMigrationTree(t, beadsDir, root))
|
||||
cfg, err := configfile.Load(beadsDir)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, cfg.IsDoltServerMode())
|
||||
journal, err := loadMigrateJournal(beadsDir)
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, journal)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateToServer_FlipsModeAndRemovesSidecar(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeProxiedServer)
|
||||
require.NoError(t, configfile.SaveProxiedServerClientInfo(beadsDir, &configfile.ProxiedServerClientInfo{}))
|
||||
|
|
@ -226,6 +446,8 @@ func TestMigrateSharedToProxiedServer_RootsAtSharedDir(t *testing.T) {
|
|||
sharedDir := t.TempDir()
|
||||
t.Setenv("BEADS_SHARED_SERVER_DIR", sharedDir)
|
||||
t.Setenv("BEADS_DOLT_SHARED_SERVER", "1")
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(sharedDir, "dolt", ".dolt"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(sharedDir, "dolt", ".dolt", "repo_state.json"), []byte(`{"head":"refs/heads/main","remotes":{},"backups":{},"branches":{}}`), 0o600))
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
require.NoError(t, os.WriteFile(filepath.Join(beadsDir, "config.yaml"), []byte("dolt:\n shared-server: true\n"), 0o600))
|
||||
|
||||
|
|
@ -244,6 +466,50 @@ func TestMigrateSharedToProxiedServer_RootsAtSharedDir(t *testing.T) {
|
|||
assert.NotContains(t, string(body), "shared-server: true", "dolt.shared-server must be turned off")
|
||||
}
|
||||
|
||||
func TestMigrateSharedToProxiedServer_AllCheckpointFaultsRetry(t *testing.T) {
|
||||
for _, phase := range []migratePhase{migratePrepared, migrateTargetConfigured, migrateOldControlsRetired, migrateVerified, migrateCommitted} {
|
||||
t.Run(string(phase), func(t *testing.T) {
|
||||
sharedDir := t.TempDir()
|
||||
t.Setenv("BEADS_SHARED_SERVER_DIR", sharedDir)
|
||||
t.Setenv("BEADS_DOLT_SHARED_SERVER", "1")
|
||||
root := filepath.Join(sharedDir, "dolt")
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(root, ".dolt"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(root, ".dolt", "repo_state.json"), []byte(`{"head":"refs/heads/main","remotes":{},"backups":{},"branches":{}}`), 0o600))
|
||||
sentinel := filepath.Join(root, "migration-sentinel")
|
||||
touchFile(t, sentinel)
|
||||
sentinelBefore, err := os.ReadFile(sentinel)
|
||||
require.NoError(t, err)
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
require.NoError(t, os.WriteFile(filepath.Join(beadsDir, "config.yaml"), []byte("dolt:\n shared-server: true\n"), 0o600))
|
||||
t.Setenv("BEADS_MIGRATION_FAIL_PHASE", string(phase))
|
||||
require.Error(t, runMigrateToProxiedServer(false, 0, true))
|
||||
j, err := loadMigrateJournal(beadsDir)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, j)
|
||||
assert.Equal(t, phase, j.Phase)
|
||||
t.Setenv("BEADS_MIGRATION_FAIL_PHASE", "")
|
||||
require.NoError(t, runMigrateToProxiedServer(false, 0, true))
|
||||
after := snapshotMigrationTree(t, beadsDir, root)
|
||||
require.NoError(t, runMigrateToProxiedServer(false, 0, true))
|
||||
assert.Equal(t, after, snapshotMigrationTree(t, beadsDir, root), "retry changed durable migration artifacts")
|
||||
assert.Equal(t, sentinelBefore, mustReadFile(t, sentinel), "migration sentinel changed")
|
||||
running, _ := proxy.IsRunning(root)
|
||||
assert.False(t, running, "retry left a proxy process running")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateSharedToProxiedServer_DryRunDoesNotCreateRoot(t *testing.T) {
|
||||
sharedDir := t.TempDir()
|
||||
t.Setenv("BEADS_SHARED_SERVER_DIR", sharedDir)
|
||||
t.Setenv("BEADS_DOLT_SHARED_SERVER", "1")
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
require.NoError(t, os.WriteFile(filepath.Join(beadsDir, "config.yaml"), []byte("dolt:\n shared-server: true\n"), 0o600))
|
||||
require.NoError(t, runMigrateToProxiedServer(true, 0, true))
|
||||
_, err := os.Stat(filepath.Join(sharedDir, "dolt"))
|
||||
assert.True(t, os.IsNotExist(err), "dry-run must not create shared root")
|
||||
}
|
||||
|
||||
func TestMigrateToProxiedServer_RejectsSharedRepo(t *testing.T) {
|
||||
t.Setenv("BEADS_DOLT_SHARED_SERVER", "1")
|
||||
migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
|
|
@ -262,6 +528,7 @@ func TestMigrateProxiedToSharedServer_Reverse(t *testing.T) {
|
|||
require.NoError(t, os.WriteFile(filepath.Join(beadsDir, "config.yaml"), []byte("dolt:\n shared-server: false\n"), 0o600))
|
||||
sharedDolt := filepath.Join(sharedDir, "dolt")
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(sharedDolt, ".dolt"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(sharedDolt, ".dolt", "repo_state.json"), []byte(`{"head":"refs/heads/main","remotes":{},"backups":{},"branches":{}}`), 0o600))
|
||||
require.NoError(t, configfile.SaveProxiedServerClientInfo(beadsDir, &configfile.ProxiedServerClientInfo{RootPath: sharedDolt}))
|
||||
|
||||
require.NoError(t, runMigrateFromProxiedServer(false, true))
|
||||
|
|
@ -277,12 +544,66 @@ func TestMigrateProxiedToSharedServer_Reverse(t *testing.T) {
|
|||
assert.Contains(t, string(body), "shared-server: true", "dolt.shared-server must be re-enabled")
|
||||
}
|
||||
|
||||
func TestMigrateFromProxiedToSharedServer_AllCheckpointFaultsRetry(t *testing.T) {
|
||||
for _, phase := range []migratePhase{migratePrepared, migrateTargetConfigured, migrateOldControlsRetired, migrateVerified, migrateCommitted} {
|
||||
t.Run(string(phase), func(t *testing.T) {
|
||||
sharedDir := t.TempDir()
|
||||
t.Setenv("BEADS_SHARED_SERVER_DIR", sharedDir)
|
||||
t.Setenv("BEADS_DOLT_SHARED_SERVER", "")
|
||||
root := filepath.Join(sharedDir, "dolt")
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(root, ".dolt"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(root, ".dolt", "repo_state.json"), []byte(`{"head":"refs/heads/main","remotes":{},"backups":{},"branches":{}}`), 0o600))
|
||||
sentinel := filepath.Join(root, "migration-sentinel")
|
||||
touchFile(t, sentinel)
|
||||
sentinelBefore, err := os.ReadFile(sentinel)
|
||||
require.NoError(t, err)
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeProxiedServer)
|
||||
require.NoError(t, configfile.SaveProxiedServerClientInfo(beadsDir, &configfile.ProxiedServerClientInfo{RootPath: root}))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(beadsDir, "config.yaml"), []byte("dolt:\n shared-server: false\n"), 0o600))
|
||||
t.Setenv("BEADS_MIGRATION_FAIL_PHASE", string(phase))
|
||||
require.Error(t, runMigrateFromProxiedServer(false, true))
|
||||
j, err := loadMigrateJournal(beadsDir)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, j)
|
||||
assert.Equal(t, phase, j.Phase)
|
||||
assert.Equal(t, 1, j.Attempt)
|
||||
t.Setenv("BEADS_MIGRATION_FAIL_PHASE", "")
|
||||
require.NoError(t, runMigrateFromProxiedServer(false, true))
|
||||
after := snapshotMigrationTree(t, beadsDir, root)
|
||||
require.NoError(t, runMigrateFromProxiedServer(false, true))
|
||||
assert.Equal(t, after, snapshotMigrationTree(t, beadsDir, root), "retry changed durable migration artifacts")
|
||||
assert.Equal(t, sentinelBefore, mustReadFile(t, sentinel), "migration sentinel changed")
|
||||
running, _ := proxy.IsRunning(root)
|
||||
assert.False(t, running, "retry left a proxy process running")
|
||||
cfg, _ := configfile.Load(beadsDir)
|
||||
assert.True(t, cfg.IsDoltServerMode())
|
||||
v, ok := config.WorkspaceYamlValue(beadsDir, "dolt.shared-server")
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "true", strings.ToLower(v))
|
||||
_, err = os.Stat(configfile.ProxiedServerClientInfoPath(beadsDir))
|
||||
assert.True(t, os.IsNotExist(err))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateProxiedToSharedServer_DryRunDoesNotCreateRoot(t *testing.T) {
|
||||
sharedDir := t.TempDir()
|
||||
t.Setenv("BEADS_SHARED_SERVER_DIR", sharedDir)
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeProxiedServer)
|
||||
sharedDolt := filepath.Join(sharedDir, "dolt")
|
||||
require.NoError(t, configfile.SaveProxiedServerClientInfo(beadsDir, &configfile.ProxiedServerClientInfo{RootPath: sharedDolt}))
|
||||
require.NoError(t, runMigrateFromProxiedServer(true, true))
|
||||
_, err := os.Stat(sharedDolt)
|
||||
assert.True(t, os.IsNotExist(err), "dry-run must not create shared root")
|
||||
}
|
||||
|
||||
func TestMigrateFromProxiedToServer_RejectsSharedRooted(t *testing.T) {
|
||||
sharedDir := t.TempDir()
|
||||
t.Setenv("BEADS_SHARED_SERVER_DIR", sharedDir)
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeProxiedServer)
|
||||
sharedDolt := filepath.Join(sharedDir, "dolt")
|
||||
require.NoError(t, os.MkdirAll(sharedDolt, 0o755))
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(sharedDolt, ".dolt"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(sharedDolt, ".dolt", "repo_state.json"), []byte(`{"head":"refs/heads/main","remotes":{},"backups":{},"branches":{}}`), 0o600))
|
||||
require.NoError(t, configfile.SaveProxiedServerClientInfo(beadsDir, &configfile.ProxiedServerClientInfo{RootPath: sharedDolt}))
|
||||
|
||||
require.Error(t, runMigrateFromProxiedServer(false, false), "non-shared reverse must reject a shared-rooted proxied repo")
|
||||
|
|
@ -290,9 +611,511 @@ func TestMigrateFromProxiedToServer_RejectsSharedRooted(t *testing.T) {
|
|||
|
||||
func TestMigrateToProxiedServer_AlreadyProxiedIsNoop(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeProxiedServer)
|
||||
require.NoError(t, configfile.SaveProxiedServerClientInfo(beadsDir, &configfile.ProxiedServerClientInfo{RootPath: filepath.Join(beadsDir, "dolt")}))
|
||||
require.NoError(t, runMigrateToProxiedServer(false, 0, false))
|
||||
|
||||
cfg, err := configfile.Load(beadsDir)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, cfg.IsDoltProxiedServerMode())
|
||||
}
|
||||
|
||||
func TestMigrateSharedToProxiedServer_AlreadyProxiedUsesSharedRootAndStaleEnv(t *testing.T) {
|
||||
sharedDir := t.TempDir()
|
||||
t.Setenv("BEADS_SHARED_SERVER_DIR", sharedDir)
|
||||
t.Setenv("BEADS_DOLT_SHARED_SERVER", "true") // stale ambient state after migration
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeProxiedServer)
|
||||
require.NoError(t, os.WriteFile(filepath.Join(beadsDir, "config.yaml"), []byte("dolt:\n shared-server: false\n"), 0o600))
|
||||
root := filepath.Join(sharedDir, "dolt")
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(root, ".dolt"), 0o755))
|
||||
require.NoError(t, configfile.SaveProxiedServerClientInfo(beadsDir, &configfile.ProxiedServerClientInfo{RootPath: root}))
|
||||
require.NoError(t, runMigrateToProxiedServer(false, 0, true))
|
||||
}
|
||||
|
||||
func TestMigrateToProxiedServer_AlreadyProxiedAllowsUnlockedLockMarkers(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeProxiedServer)
|
||||
root := filepath.Join(beadsDir, "dolt")
|
||||
require.NoError(t, configfile.SaveProxiedServerClientInfo(beadsDir, &configfile.ProxiedServerClientInfo{RootPath: root}))
|
||||
for _, name := range []string{proxy.LockFileName, server.LockFileName} {
|
||||
touchFile(t, filepath.Join(root, name))
|
||||
}
|
||||
require.NoError(t, runMigrateToProxiedServer(false, 0, false))
|
||||
}
|
||||
|
||||
func TestMigrateToProxiedServer_AlreadyProxiedRefusalsAreTyped(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
info *configfile.ProxiedServerClientInfo
|
||||
control string
|
||||
}{
|
||||
{name: "external sidecar", info: &configfile.ProxiedServerClientInfo{RootPath: "/tmp/external", External: &configfile.ExternalDoltConfig{Host: "db.example", Port: 3307}}},
|
||||
{name: "mismatched sidecar", info: &configfile.ProxiedServerClientInfo{RootPath: "/tmp/other"}},
|
||||
{name: "stale control", control: proxy.LogFileName},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeProxiedServer)
|
||||
root := filepath.Join(beadsDir, "dolt")
|
||||
if tc.info == nil {
|
||||
tc.info = &configfile.ProxiedServerClientInfo{RootPath: root}
|
||||
}
|
||||
require.NoError(t, configfile.SaveProxiedServerClientInfo(beadsDir, tc.info))
|
||||
if tc.control != "" {
|
||||
touchFile(t, filepath.Join(root, tc.control))
|
||||
}
|
||||
oldJSON := jsonOutput
|
||||
jsonOutput = true
|
||||
t.Cleanup(func() { jsonOutput = oldJSON })
|
||||
out, err := captureMigrationJSON(t, func() error { return runMigrateToProxiedServer(false, 0, false) })
|
||||
code, ok := exitCodeFromError(err)
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, 1, code)
|
||||
var got map[string]any
|
||||
require.NoError(t, json.Unmarshal([]byte(out), &got), "output=%q", out)
|
||||
assert.Equal(t, "proxy.migrate.invalid_state", got["code"])
|
||||
assert.Equal(t, false, got["mutates"])
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateToProxiedServer_AlreadyProxiedRefusesHeldLockAsTyped(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeProxiedServer)
|
||||
root := filepath.Join(beadsDir, "dolt")
|
||||
require.NoError(t, configfile.SaveProxiedServerClientInfo(beadsDir, &configfile.ProxiedServerClientInfo{RootPath: root}))
|
||||
held, err := util.TryLock(filepath.Join(root, proxy.LockFileName))
|
||||
require.NoError(t, err)
|
||||
defer held.Unlock()
|
||||
oldJSON := jsonOutput
|
||||
jsonOutput = true
|
||||
t.Cleanup(func() { jsonOutput = oldJSON })
|
||||
out, err := captureMigrationJSON(t, func() error { return runMigrateToProxiedServer(false, 0, false) })
|
||||
code, ok := exitCodeFromError(err)
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, 1, code)
|
||||
var got map[string]any
|
||||
require.NoError(t, json.Unmarshal([]byte(out), &got))
|
||||
assert.Equal(t, "proxy.migrate.invalid_state", got["code"])
|
||||
assert.Equal(t, false, got["mutates"])
|
||||
}
|
||||
|
||||
func TestMigrateToProxiedServer_RetryAfterCheckpointFault(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
t.Setenv("BEADS_MIGRATION_FAIL_PHASE", string(migrateTargetConfigured))
|
||||
require.Error(t, runMigrateToProxiedServer(false, 0, false))
|
||||
j, err := loadMigrateJournal(beadsDir)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, j)
|
||||
assert.Equal(t, migrateTargetConfigured, j.Phase)
|
||||
t.Setenv("BEADS_MIGRATION_FAIL_PHASE", "")
|
||||
require.NoError(t, runMigrateToProxiedServer(false, 0, false))
|
||||
j, err = loadMigrateJournal(beadsDir)
|
||||
assert.NoError(t, err)
|
||||
assert.Nil(t, j, "successful migration removes its journal")
|
||||
}
|
||||
|
||||
// TestMigrateToProxiedServer_ResumeReplaysRecordedIdleTimeout covers the resume
|
||||
// case every other fault-retry test misses: the retry replays identical argv, so
|
||||
// the sidecar is only ever rebuilt in its trivially-consistent form. A resume
|
||||
// that changes --idle-timeout (or omits it, which resolves differently again)
|
||||
// must replay the journal's recorded plan. Rebuilding the sidecar from the
|
||||
// current argv persists the divergence before the equality check detects it, and
|
||||
// because the rebuild is gated on phase == migratePrepared, re-supplying the
|
||||
// original value cannot repair it afterwards.
|
||||
func TestMigrateToProxiedServer_ResumeReplaysRecordedIdleTimeout(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
resume time.Duration
|
||||
}{
|
||||
{name: "changed", resume: 5 * time.Minute},
|
||||
{name: "omitted", resume: 0},
|
||||
{name: "never", resume: proxy.IdleTimeoutNever},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
recorded := 90 * time.Second
|
||||
|
||||
t.Setenv("BEADS_MIGRATION_FAIL_PHASE", string(migratePrepared))
|
||||
require.Error(t, runMigrateToProxiedServer(false, recorded, false))
|
||||
j, err := loadMigrateJournal(beadsDir)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, j)
|
||||
require.Equal(t, migratePrepared, j.Phase)
|
||||
require.NotNil(t, j.Sidecar)
|
||||
require.Equal(t, recorded, j.Sidecar.IdleTimeout)
|
||||
|
||||
t.Setenv("BEADS_MIGRATION_FAIL_PHASE", "")
|
||||
require.NoError(t, runMigrateToProxiedServer(false, tc.resume, false))
|
||||
|
||||
j, err = loadMigrateJournal(beadsDir)
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, j, "successful migration removes its journal")
|
||||
info, err := configfile.LoadProxiedServerClientInfo(beadsDir)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, info)
|
||||
assert.Equal(t, recorded, info.IdleTimeout, "sidecar must hold the recorded plan, not the resume argv")
|
||||
|
||||
// The reverse migration is the documented escape hatch; it compares
|
||||
// the same two values, so it must also accept the resumed state.
|
||||
require.NoError(t, runMigrateFromProxiedServer(false, false))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateJournal_UnknownPhaseFailsClosed(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
path := migrateJournalPath(beadsDir)
|
||||
require.NoError(t, os.WriteFile(path, []byte(`{"version":1,"source_mode":"server","target_mode":"proxied-server","phase":"surprise","attempt":1}`), 0o600))
|
||||
_, err := loadMigrateJournal(beadsDir)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestMigrateToProxiedServer_AllCheckpointFaultsRetry(t *testing.T) {
|
||||
for _, phase := range []migratePhase{migratePrepared, migrateTargetConfigured, migrateOldControlsRetired, migrateVerified, migrateCommitted} {
|
||||
t.Run(string(phase), func(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
t.Setenv("BEADS_MIGRATION_FAIL_PHASE", string(phase))
|
||||
require.Error(t, runMigrateToProxiedServer(false, 0, false))
|
||||
j, err := loadMigrateJournal(beadsDir)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, j)
|
||||
assert.Equal(t, phase, j.Phase)
|
||||
assert.Equal(t, 1, j.Attempt)
|
||||
t.Setenv("BEADS_MIGRATION_FAIL_PHASE", "")
|
||||
require.NoError(t, runMigrateToProxiedServer(false, 0, false))
|
||||
after := snapshotMigrationTree(t, beadsDir)
|
||||
j, err = loadMigrateJournal(beadsDir)
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, j)
|
||||
require.NoError(t, runMigrateToProxiedServer(false, 0, false))
|
||||
assert.Equal(t, after, snapshotMigrationTree(t, beadsDir))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateFromProxiedServer_MalformedSidecarFailsClosed(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeProxiedServer)
|
||||
require.NoError(t, os.WriteFile(configfile.ProxiedServerClientInfoPath(beadsDir), []byte("{bad"), 0o600))
|
||||
require.Error(t, runMigrateFromProxiedServer(false, false))
|
||||
data, err := os.ReadFile(configfile.ConfigPath(beadsDir))
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, string(data), configfile.DoltModeProxiedServer)
|
||||
}
|
||||
|
||||
func TestMigrateFromProxiedServer_AlreadyServerRejectsMalformedSidecar(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
path := configfile.ProxiedServerClientInfoPath(beadsDir)
|
||||
require.NoError(t, os.WriteFile(path, []byte("{bad"), 0o600))
|
||||
before := snapshotMigrationTree(t, beadsDir)
|
||||
var err error
|
||||
stderr := captureStderr(t, func() { err = runMigrateFromProxiedServer(false, false) })
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, strings.ToLower(stderr), "sidecar")
|
||||
assert.Equal(t, before, snapshotMigrationTree(t, beadsDir))
|
||||
}
|
||||
|
||||
func TestMigrateFromProxiedServer_AlreadyTargetRejectsStaleSidecar(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
require.NoError(t, configfile.SaveProxiedServerClientInfo(beadsDir, &configfile.ProxiedServerClientInfo{RootPath: filepath.Join(beadsDir, "dolt")}))
|
||||
before := snapshotMigrationTree(t, beadsDir)
|
||||
var err error
|
||||
stderr := captureStderr(t, func() { err = runMigrateFromProxiedServer(false, false) })
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, strings.ToLower(stderr), "stale")
|
||||
assert.Equal(t, before, snapshotMigrationTree(t, beadsDir))
|
||||
}
|
||||
|
||||
func TestMigrateFromProxiedToSharedServer_AlreadyTargetRejectsStaleSidecar(t *testing.T) {
|
||||
sharedDir := t.TempDir()
|
||||
t.Setenv("BEADS_SHARED_SERVER_DIR", sharedDir)
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
require.NoError(t, os.WriteFile(filepath.Join(beadsDir, "config.yaml"), []byte("dolt:\n shared-server: true\n"), 0o600))
|
||||
root := filepath.Join(sharedDir, "dolt")
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(root, ".dolt"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(root, ".dolt", "repo_state.json"), []byte(`{"head":"refs/heads/main","remotes":{},"backups":{},"branches":{}}`), 0o600))
|
||||
require.NoError(t, configfile.SaveProxiedServerClientInfo(beadsDir, &configfile.ProxiedServerClientInfo{RootPath: root}))
|
||||
before := snapshotMigrationTree(t, beadsDir, root)
|
||||
var err error
|
||||
stderr := captureStderr(t, func() { err = runMigrateFromProxiedServer(false, true) })
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, strings.ToLower(stderr), "stale")
|
||||
assert.Equal(t, before, snapshotMigrationTree(t, beadsDir, root))
|
||||
}
|
||||
|
||||
func TestMigrateFromProxiedServer_JournalPreservesExternalSidecar(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeProxiedServer)
|
||||
root := filepath.Join(beadsDir, "dolt")
|
||||
ext := &configfile.ExternalDoltConfig{Host: "db.example", Port: 3307, User: "alice"}
|
||||
require.NoError(t, configfile.SaveProxiedServerClientInfo(beadsDir, &configfile.ProxiedServerClientInfo{RootPath: root, External: ext}))
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(root, ".dolt"), 0o755))
|
||||
require.Error(t, runMigrateFromProxiedServer(false, false), "external endpoint cannot be converted to local server")
|
||||
got, err := configfile.LoadProxiedServerClientInfo(beadsDir)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, ext, got.External)
|
||||
cfg, err := configfile.Load(beadsDir)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, cfg.IsDoltProxiedServerMode())
|
||||
}
|
||||
|
||||
func TestMigrateFromProxiedServer_AllCheckpointFaultsRetry(t *testing.T) {
|
||||
for _, phase := range []migratePhase{migratePrepared, migrateTargetConfigured, migrateOldControlsRetired, migrateVerified, migrateCommitted} {
|
||||
t.Run(string(phase), func(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeProxiedServer)
|
||||
root := filepath.Join(beadsDir, "dolt")
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(root, ".dolt"), 0o755))
|
||||
sentinel := filepath.Join(root, "migration-sentinel")
|
||||
touchFile(t, sentinel)
|
||||
sentinelBefore, err := os.ReadFile(sentinel)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, configfile.SaveProxiedServerClientInfo(beadsDir, &configfile.ProxiedServerClientInfo{RootPath: root}))
|
||||
t.Setenv("BEADS_MIGRATION_FAIL_PHASE", string(phase))
|
||||
require.Error(t, runMigrateFromProxiedServer(false, false))
|
||||
t.Setenv("BEADS_MIGRATION_FAIL_PHASE", "")
|
||||
require.NoError(t, runMigrateFromProxiedServer(false, false))
|
||||
after := snapshotMigrationTree(t, beadsDir)
|
||||
assert.Equal(t, sentinelBefore, mustReadFile(t, sentinel), "migration sentinel changed")
|
||||
j, err := loadMigrateJournal(beadsDir)
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, j)
|
||||
require.NoError(t, runMigrateFromProxiedServer(false, false))
|
||||
assert.Equal(t, after, snapshotMigrationTree(t, beadsDir))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateFromProxiedServer_ExternalJournalAlwaysFailsClosed(t *testing.T) {
|
||||
for _, phase := range []migratePhase{migratePrepared, migrateTargetConfigured, migrateOldControlsRetired, migrateVerified, migrateCommitted} {
|
||||
t.Run(string(phase), func(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeProxiedServer)
|
||||
root := filepath.Join(beadsDir, "dolt")
|
||||
require.NoError(t, os.MkdirAll(root, 0o755))
|
||||
if phase != migratePrepared {
|
||||
writeMetadataConfig(t, beadsDir, configfile.DoltModeServer, "myproj")
|
||||
}
|
||||
wantMode := configfile.DoltModeServer
|
||||
if phase == migratePrepared {
|
||||
wantMode = configfile.DoltModeProxiedServer
|
||||
}
|
||||
ext := &configfile.ExternalDoltConfig{Host: "db.example", Port: 3307}
|
||||
j := migrateJournal{Version: 1, SourceMode: configfile.DoltModeProxiedServer, TargetMode: configfile.DoltModeServer, RootPath: root, External: ext, Ownership: "external", Attempt: 1, Phase: phase, Sidecar: &configfile.ProxiedServerClientInfo{RootPath: root, External: ext}}
|
||||
b, err := json.Marshal(j)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, os.WriteFile(migrateJournalPath(beadsDir), b, 0o600))
|
||||
require.Error(t, runMigrateFromProxiedServer(false, false))
|
||||
cfg, err := configfile.Load(beadsDir)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, wantMode, cfg.GetDoltMode())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateExternalJournalAlwaysFailsClosed_TCPAndUnixForwardReverse(t *testing.T) {
|
||||
endpoints := []struct {
|
||||
name string
|
||||
cfg *configfile.ExternalDoltConfig
|
||||
}{
|
||||
{"tcp", &configfile.ExternalDoltConfig{Host: "db.example", Port: 3307}},
|
||||
{"unix", &configfile.ExternalDoltConfig{Socket: "/tmp/beads-dolt.sock"}},
|
||||
}
|
||||
for _, ep := range endpoints {
|
||||
for _, reverse := range []bool{false, true} {
|
||||
for _, phase := range []migratePhase{migratePrepared, migrateTargetConfigured, migrateOldControlsRetired, migrateVerified, migrateCommitted} {
|
||||
t.Run(ep.name+"/"+string(phase), func(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
root := filepath.Join(beadsDir, "dolt")
|
||||
want := configfile.DoltModeServer
|
||||
src := configfile.DoltModeServer
|
||||
target := configfile.DoltModeProxiedServer
|
||||
if reverse {
|
||||
src, target = configfile.DoltModeProxiedServer, configfile.DoltModeServer
|
||||
want = configfile.DoltModeProxiedServer
|
||||
}
|
||||
// A prepared journal may legitimately coexist with either
|
||||
// source or target metadata. Later phases require target
|
||||
// metadata so validation reaches the ownership refusal.
|
||||
metadataMode := src
|
||||
if phase != migratePrepared {
|
||||
metadataMode = target
|
||||
}
|
||||
want = metadataMode
|
||||
writeMetadataConfig(t, beadsDir, metadataMode, "myproj")
|
||||
j := migrateJournal{Version: 1, SourceMode: src, TargetMode: target, RootPath: root, External: ep.cfg, Ownership: "external", Attempt: 1, Phase: phase, Sidecar: &configfile.ProxiedServerClientInfo{RootPath: root, External: ep.cfg}}
|
||||
b, err := json.Marshal(j)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, os.WriteFile(migrateJournalPath(beadsDir), b, 0o600))
|
||||
treeBefore := snapshotMigrationTree(t, beadsDir, root)
|
||||
before, _ := os.ReadFile(configfile.ConfigPath(beadsDir))
|
||||
var migrateErr error
|
||||
stderr := captureStderr(t, func() {
|
||||
if reverse {
|
||||
migrateErr = runMigrateFromProxiedServer(false, false)
|
||||
} else {
|
||||
migrateErr = runMigrateToProxiedServer(false, 0, false)
|
||||
}
|
||||
})
|
||||
require.Error(t, migrateErr)
|
||||
assert.Contains(t, strings.ToLower(stderr), "externally hosted proxied dolt endpoint")
|
||||
after, _ := os.ReadFile(configfile.ConfigPath(beadsDir))
|
||||
assert.Equal(t, before, after)
|
||||
cfg, _ := configfile.Load(beadsDir)
|
||||
assert.Equal(t, want, cfg.GetDoltMode())
|
||||
assert.Equal(t, treeBefore, snapshotMigrationTree(t, beadsDir, root))
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateSharedJournalRootMismatchFailsClosed(t *testing.T) {
|
||||
shared := t.TempDir()
|
||||
t.Setenv("BEADS_SHARED_SERVER_DIR", shared)
|
||||
t.Setenv("BEADS_DOLT_SHARED_SERVER", "1")
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
require.NoError(t, os.WriteFile(filepath.Join(beadsDir, "config.yaml"), []byte("dolt:\n shared-server: true\n"), 0o600))
|
||||
root := filepath.Join(beadsDir, "dolt")
|
||||
j := migrateJournal{Version: 1, SourceMode: configfile.DoltModeServer, TargetMode: configfile.DoltModeProxiedServer, Shared: true, RootPath: root, Ownership: "managed-local", Attempt: 1, Phase: migratePrepared, Sidecar: &configfile.ProxiedServerClientInfo{RootPath: root}}
|
||||
b, err := json.Marshal(j)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, os.WriteFile(migrateJournalPath(beadsDir), b, 0o600))
|
||||
require.Error(t, runMigrateToProxiedServer(false, 0, true))
|
||||
cfg, err := configfile.Load(beadsDir)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, cfg.IsDoltServerMode())
|
||||
}
|
||||
|
||||
func TestMigrateSharedJournalMissingYAMLFailsClosed(t *testing.T) {
|
||||
shared := t.TempDir()
|
||||
t.Setenv("BEADS_SHARED_SERVER_DIR", shared)
|
||||
t.Setenv("BEADS_DOLT_SHARED_SERVER", "1")
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
root := filepath.Join(shared, "dolt")
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(root, ".dolt"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(root, ".dolt", "repo_state.json"), []byte(`{"head":"refs/heads/main","remotes":{},"backups":{},"branches":{}}`), 0o600))
|
||||
j := migrateJournal{Version: 1, SourceMode: configfile.DoltModeServer, TargetMode: configfile.DoltModeProxiedServer, Shared: true, RootPath: root, Ownership: "managed-local", Attempt: 1, Phase: migratePrepared, Sidecar: &configfile.ProxiedServerClientInfo{RootPath: root}}
|
||||
b, _ := json.Marshal(j)
|
||||
require.NoError(t, os.WriteFile(migrateJournalPath(beadsDir), b, 0o600))
|
||||
require.Error(t, runMigrateToProxiedServer(false, 0, true))
|
||||
}
|
||||
|
||||
func TestMigrateNonSharedJournalRejectsPersistedSharedYAML(t *testing.T) {
|
||||
t.Setenv("BEADS_DOLT_SHARED_SERVER", "1") // stale ambient environment
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeProxiedServer)
|
||||
require.NoError(t, os.WriteFile(filepath.Join(beadsDir, "config.yaml"), []byte("dolt:\n shared-server: true\n"), 0o600))
|
||||
root := filepath.Join(beadsDir, "dolt")
|
||||
j := migrateJournal{Version: 1, SourceMode: configfile.DoltModeServer, TargetMode: configfile.DoltModeProxiedServer, RootPath: root, Ownership: "managed-local", Attempt: 1, Phase: migrateTargetConfigured, Sidecar: &configfile.ProxiedServerClientInfo{RootPath: root}}
|
||||
b, err := json.Marshal(j)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, os.WriteFile(migrateJournalPath(beadsDir), b, 0o600))
|
||||
err = runMigrateToProxiedServer(false, 0, false)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestMigrateJournalSidecarRootMismatchFailsClosed(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
j := migrateJournal{Version: 1, SourceMode: configfile.DoltModeServer, TargetMode: configfile.DoltModeProxiedServer, RootPath: filepath.Join(beadsDir, "dolt"), Ownership: "managed-local", Attempt: 1, Phase: migratePrepared, Sidecar: &configfile.ProxiedServerClientInfo{RootPath: filepath.Join(beadsDir, "other")}}
|
||||
b, err := json.Marshal(j)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, os.WriteFile(migrateJournalPath(beadsDir), b, 0o600))
|
||||
_, err = loadMigrateJournal(beadsDir)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestMigrateJournalExternalTopologyMismatchFailsClosed(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeProxiedServer)
|
||||
root := filepath.Join(beadsDir, "dolt")
|
||||
ext := &configfile.ExternalDoltConfig{Host: "db.example", Port: 3307}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
ownership string
|
||||
journal *configfile.ExternalDoltConfig
|
||||
sidecar *configfile.ExternalDoltConfig
|
||||
}{
|
||||
{name: "journal external differs", ownership: "external", journal: &configfile.ExternalDoltConfig{Host: "other.example", Port: 3307}, sidecar: ext},
|
||||
{name: "journal unexpected external", ownership: "managed-local", journal: ext, sidecar: nil},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
j := migrateJournal{Version: 1, SourceMode: configfile.DoltModeProxiedServer, TargetMode: configfile.DoltModeServer, RootPath: root, Ownership: tc.ownership, Attempt: 1, Phase: migratePrepared, External: tc.journal, Sidecar: &configfile.ProxiedServerClientInfo{RootPath: root, External: tc.sidecar}}
|
||||
b, err := json.Marshal(j)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, os.WriteFile(migrateJournalPath(beadsDir), b, 0o600))
|
||||
_, err = loadMigrateJournal(beadsDir)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateJournalLegacyExternalFieldInfersSidecar(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeProxiedServer)
|
||||
root := filepath.Join(beadsDir, "dolt")
|
||||
ext := &configfile.ExternalDoltConfig{Host: "db.example", Port: 3307}
|
||||
j := migrateJournal{Version: 1, SourceMode: configfile.DoltModeProxiedServer, TargetMode: configfile.DoltModeServer, RootPath: root, Ownership: "external", Attempt: 1, Phase: migratePrepared, Sidecar: &configfile.ProxiedServerClientInfo{RootPath: root, External: ext}}
|
||||
b, err := json.Marshal(j)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, os.WriteFile(migrateJournalPath(beadsDir), b, 0o600))
|
||||
got, err := loadMigrateJournal(beadsDir)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, got)
|
||||
assert.Equal(t, ext, got.External)
|
||||
}
|
||||
|
||||
func TestMigrateFromProxiedServer_JournalSidecarChangedFailsClosed(t *testing.T) {
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeProxiedServer)
|
||||
root := filepath.Join(beadsDir, "dolt")
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(root, ".dolt"), 0o755))
|
||||
wantSidecar := &configfile.ProxiedServerClientInfo{RootPath: root, LogPath: filepath.Join(root, "server.log")}
|
||||
gotSidecar := &configfile.ProxiedServerClientInfo{RootPath: root, LogPath: filepath.Join(root, "changed.log")}
|
||||
require.NoError(t, configfile.SaveProxiedServerClientInfo(beadsDir, gotSidecar))
|
||||
j := migrateJournal{Version: 1, SourceMode: configfile.DoltModeProxiedServer, TargetMode: configfile.DoltModeServer, RootPath: root, Ownership: "managed-local", Attempt: 1, Phase: migratePrepared, Sidecar: wantSidecar}
|
||||
b, err := json.Marshal(j)
|
||||
require.NoError(t, err)
|
||||
journalPath := migrateJournalPath(beadsDir)
|
||||
require.NoError(t, os.WriteFile(journalPath, b, 0o600))
|
||||
before := snapshotMigrationTree(t, beadsDir, root)
|
||||
var migrateErr error
|
||||
captureStderr(t, func() { migrateErr = runMigrateFromProxiedServer(false, false) })
|
||||
require.Error(t, migrateErr)
|
||||
assert.Equal(t, before, snapshotMigrationTree(t, beadsDir, root))
|
||||
}
|
||||
|
||||
// TestMigrateFromProxiedServer_ForwardJournalAtPreparedIsNotSidecarRefused is
|
||||
// the complement of the test above, and the reason its guard is scoped to
|
||||
// reverse journals.
|
||||
//
|
||||
// The two directions mean different things by a migratePrepared journal that
|
||||
// names a sidecar. A reverse journal names one that is already on disk, so a
|
||||
// mismatch is real corruption -- that is the case above. A forward journal
|
||||
// names the sidecar it is about to write, and only advances past
|
||||
// migratePrepared once the write lands, so a crash in that pre-write window
|
||||
// leaves no sidecar on disk at all. That is the correct state for the phase,
|
||||
// not a mismatch.
|
||||
//
|
||||
// This command is the documented escape hatch out of exactly that wreck: the
|
||||
// non-proxied-mode refusal is gated on j == nil, so a leftover journal is what
|
||||
// lets the operator run it with the live mode still on "server". An unscoped
|
||||
// sidecar check refuses here by naming a missing file, which strands the
|
||||
// workspace with no way forward and no way back.
|
||||
func TestMigrateFromProxiedServer_ForwardJournalAtPreparedIsNotSidecarRefused(t *testing.T) {
|
||||
// Live mode is still the forward migration's source: it flips only after
|
||||
// the sidecar is written, so a crash before that leaves it untouched.
|
||||
beadsDir := migrateModeWorkspace(t, configfile.DoltModeServer)
|
||||
root := filepath.Join(beadsDir, "dolt")
|
||||
j := migrateJournal{Version: 1, SourceMode: configfile.DoltModeServer, TargetMode: configfile.DoltModeProxiedServer, RootPath: root, Ownership: "managed-local", Attempt: 1, Phase: migratePrepared, Sidecar: &configfile.ProxiedServerClientInfo{RootPath: root}}
|
||||
b, err := json.Marshal(j)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, os.WriteFile(migrateJournalPath(beadsDir), b, 0o600))
|
||||
|
||||
// Precondition: no sidecar on disk, which is what the guard would have
|
||||
// compared against the journal's.
|
||||
_, statErr := os.Stat(configfile.ProxiedServerClientInfoPath(beadsDir))
|
||||
require.True(t, os.IsNotExist(statErr), "precondition: sidecar must be absent, got %v", statErr)
|
||||
|
||||
var migrateErr error
|
||||
stderr := captureStderr(t, func() { migrateErr = runMigrateFromProxiedServer(false, false) })
|
||||
|
||||
// Deliberately not asserting success: what this command does next with a
|
||||
// forward journal is its own behavior and has its own coverage. The pin is
|
||||
// only that it does not stop at the sidecar comparison, whose message
|
||||
// would be a lie about the workspace.
|
||||
if migrateErr != nil {
|
||||
assert.NotContains(t, stderr, "migration sidecar does not match prepared state")
|
||||
assert.NotContains(t, migrateErr.Error(), "migration sidecar does not match prepared state")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -160,7 +160,7 @@ func TestGetNotionConfigPrefersStoreOverEnv(t *testing.T) {
|
|||
|
||||
func TestRunNotionStatusJSONWithMissingConfig(t *testing.T) {
|
||||
saveAndRestoreGlobals(t)
|
||||
jsonOutput = true
|
||||
pinJSONOutput(t, true)
|
||||
store = nil
|
||||
dbPath = ""
|
||||
t.Setenv("NOTION_TOKEN", "")
|
||||
|
|
@ -383,7 +383,7 @@ func TestRunNotionStatusUsesHTTPClient(t *testing.T) {
|
|||
newNotionStatusClient = func(token string) *notion.Client {
|
||||
return notion.NewClient(token).WithBaseURL(server.URL)
|
||||
}
|
||||
jsonOutput = true
|
||||
pinJSONOutput(t, true)
|
||||
store = nil
|
||||
dbPath = ""
|
||||
t.Setenv("NOTION_TOKEN", "env-token")
|
||||
|
|
|
|||
|
|
@ -280,9 +280,11 @@ func canonValue(v any) any {
|
|||
// Replace per-write-random token values (the guarded-write revision /
|
||||
// row_lock) with a placeholder: pin that bd show exposes a revision
|
||||
// field, not its nondeterministic value. Unlike the provenance keys
|
||||
// above this is unconditional — the value is a JSON number, not a
|
||||
// string — but it stays a bare-key match, so keep the scope caveat in
|
||||
// mind (see volatileValueKeys).
|
||||
// above this is unconditional — the value is replaced whatever its
|
||||
// JSON type, so the placeholder held when the token was a number and
|
||||
// still holds now that it is a decimal string — but it stays a
|
||||
// bare-key match, so keep the scope caveat in mind (see
|
||||
// volatileValueKeys).
|
||||
if ph, ok := volatileValueKeys[k]; ok {
|
||||
t[k] = ph
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@
|
|||
"corpus-label"
|
||||
],
|
||||
"metadata": {
|
||||
"phase": "2"
|
||||
"phase": 2
|
||||
},
|
||||
"owner": "test@protocol.test",
|
||||
"priority": 0,
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@
|
|||
"corpus-label"
|
||||
],
|
||||
"metadata": {
|
||||
"phase": "2"
|
||||
"phase": 2
|
||||
},
|
||||
"owner": "test@protocol.test",
|
||||
"priority": 0,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
"corpus-label"
|
||||
],
|
||||
"metadata": {
|
||||
"phase": "2"
|
||||
"phase": 2
|
||||
},
|
||||
"owner": "test@protocol.test",
|
||||
"priority": 0,
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@
|
|||
"corpus-label"
|
||||
],
|
||||
"metadata": {
|
||||
"phase": "2"
|
||||
"phase": 2
|
||||
},
|
||||
"owner": "test@protocol.test",
|
||||
"priority": 0,
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@
|
|||
"corpus-label"
|
||||
],
|
||||
"metadata": {
|
||||
"phase": "2"
|
||||
"phase": 2
|
||||
},
|
||||
"owner": "test@protocol.test",
|
||||
"priority": 0,
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue