* refactor(proxy): one capability registry, with a reason on every refusal
Proxied-server policy lived in three path tables (a maintenance refusal
map, a history classification map, a transform row list), each with its
own lookup and its own front-door validator, plus a flag matrix. Nothing
forced a new command to appear in any of them, so an unclassified
command sailed past the gate and died in the store factory with
`proxy server store should be uow provider`. That — not the table count
— was the root problem.
One table now (cmd/bd/capability_registry.go), and a test that fails
when a runnable command is missing from it. Adding a command is no
longer a place where policy can be forgotten: it is a build failure
until someone decides whether the proxied front door lets it through.
Every refusal carries a Reason: `design` where refusing is correct and
expected to stay (shared history, multi-repo routing, destructive admin,
storage-format surgery, strict --readonly), `unimplemented` where it is
a gap with a named owner. The reason renders in the refusal JSON,
additive to the frozen {code, error, mutates} contract, and is omitted
on refusals that report a runtime state rather than a policy so a
consumer keying on its presence is never told "" by mistake.
The registry also inventories the 57 untyped refusals commands raise
from their own RunE. Those rows are not enforced — converting them
changes observable output and belongs to the slice that owns each
family — but a source scan now keeps the inventory honest in both
directions.
The store-factory backstop is typed as `proxy.store.unrouted`, the
unreachable duplicate readonly refusal in main.go is gone (the proxied
branch above it already returns for the only config that reaches it),
and with it `backendSupportsStrictReadonly`, which had no other caller.
No outcome changes. Every code, message and exit status is identical,
which #6576's five-topology matrix proves: 90/90 cells unchanged
(HONORED 47, REFUSED_TYPED 24 = 4 design + 20 unimplemented, ERROR 12,
WRONG_ANSWER 4, DEGRADED 3), all five topologies exercised, no skips.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* refactor(proxy): `migrate hooks` is an unimplemented refusal, not a design one
The registry filed `migrate hooks` under "storage-format and workspace
surgery against a store other clients may be holding open". That rationale
does not describe it: migrate_hooks.go plans and applies GIT HOOK FILE
migration through doctor.PlanHookMigration, on the local filesystem, and
opens no store at all. Left as it was, proxied-local — the default topology
since 1.3.0 — loses the command permanently, because `design` tells every
later slice the refusal is semantic and settled.
It is not settled, but it is also not free to lift, and the difference is
structural rather than semantic. `migrate hooks` appears on none of main.go's
store-init skip lists, so permitting it makes the root pre-run open the
proxied provider before RunE runs. Measured with the row flipped to
permitted, not reasoned about: on a managed-local workspace
`bd migrate hooks --dry-run` started the proxy AND its dolt child — both
pidfiles present — to print a hook plan for five missing hooks, and on a
workspace with an unreadable sidecar it exited 1 with "failed to open uow
provider: corrupt proxied-server sidecar ..." where it had cleanly refused
before. Trading a typed refusal for a provider-open error is not a lift.
So: Reason=unimplemented with a Tracking item that names the actual work —
put the command on the store-init skip list first, then permit it — which is
S7's, not this slice's. No outcome changes; the row still refuses with the
same code, message and exit status. The registry header now says that
permitting a path costs a provider open, since that is the fact this row
turns on and the one the completeness test cannot see.
Also leaves S7 an explicit instruction on the rows next door. `migrate
issues`, `migrate-personal` and `admin cleanup`/`admin reset` claim `design`
on a topology-blind rationale — "a store other clients may be holding open",
"destructive against a possibly-shared store" — that describes external and
team-server workspaces and does not describe managed-local, which is 1:1 and
bd-owned. They are not reclassified here: the table cannot yet express
"refused, except on managed-local", and narrowing them is semantic work
nobody has done. The comments now say that is why, so the next reader does
not mistake conservatism for a considered verdict.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* feat(backup): route the backup family over proxied-server, refuse it by design off-host
A proxied-server workspace had no backup path at all: all five verbs — init,
sync, remove, status, restore — refused. Proxied has been the default topology
since 1.3.0, which made this the highest user-weight gap in the proxied-parity
plan.
The mechanism needed no proxy work. CALL DOLT_BACKUP(...) is ordinary SQL,
RunNonTx already hands out a raw pinned connection (the seam compact --dolt and
gc run on), the UOW DSN sets a connect timeout and no read deadline, and an
active connection keeps the idle reaper from arming — so a backup that takes
minutes is safe from both the driver and the 30s reaper. The work was use
cases, route files and policy rows, and the premise held.
The policy is the interesting half, and it is the first genuinely
topology-differentiated rule in the capability registry. A backup destination
is resolved by the SERVER: `file:///…` names a path on the machine running
dolt. On managed-local that machine and that user are bd's own, because bd
spawned the child. Anywhere else — an external host or socket, or a
beads-team-server database — the URL describes a filesystem bd cannot see, so
honoring the command would either fail at the point of use or, far worse,
report success having written the backup where the operator will never look.
Those shapes stay refused with Reason=design: no plumbing on this side gives bd
a path on somebody else's host.
Team-server is classified by OWNERSHIP, not transport. bts owns the store's
schema and identity whether bd reaches it over a port, a socket, or a child bd
started, and one client registering a server-side backup remote acts on every
client's data — the shape of the storm this command's own help text warns about.
Restore quiesces before it replaces. DOLT_BACKUP('restore') swaps the database
under the server, which is undefined with clients connected, so: the exclusive
workspace gate `bd backup restore` already takes excludes every other gated bd
command (including `bd serve`); this closes the provider the pre-run opened and
shuts the proxy and its dolt child down; it reopens a provider of its own to
run the restore as the only client; then it puts the topology down and reopens
once more to reconcile the project identity and the backup remote — which also
proves the restored database is serviceable. The final shutdown leaves the
workspace quiescent for the next command to relaunch lazily.
Registry rows gain a Topology map and honoredOn(), stated as "refuse, except
here" so a shape nobody thought about — a new transport, or the unknown a
corrupt sidecar produces — inherits the refusal rather than the exemption.
resolveProxiedTopology reads the shape from the workspace and reports unknown
rather than guessing.
`bd backup restore --json` now prints a result object on every topology; it
printed nothing before, which left a caller unable to tell a completed restore
from a skipped one. The four backup subcommands that lacked SilenceUsage/
SilenceErrors no longer follow their error message with "Error: exit code 1"
and a usage block.
Verified by round trip, not by exit codes: TestManagedLocalProxiedBackupRoundTrip
takes a backup on a live managed-local workspace, creates an issue after it,
restores, and asserts the pre-backup issue is back and the post-backup one is
gone, with both pidfiles absent afterwards.
TestProxiedServerBackupRefusedOnExternalTopology pins the typed design refusal
against the shared container and proves a refused command starts nothing and
writes nothing.
Flips four cells of #6576's matrix: `backup status` and `backup sync` go
REFUSED_TYPED/unimplemented -> HONORED and -> ERROR ("no backup destination
configured", the command's own error, same as every direct topology) on
proxied-local, and unimplemented -> design on proxied-external-tcp.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix(backup): say why proxied backup is refused, and stop calling a cleanup failure a restore failure
Review follow-ups on the proxied backup slice. None of them changes which
commands are honored on which topology; what changes is what the refusal
CLAIMS, and what a restore says when only its teardown failed.
The refusal rationale was true of one destination scheme out of five. It said
"a backup destination is resolved on the server's filesystem, not this
client's" — which describes `file://` and nothing else. resolveDoltBackupURL
passes `https://`, `aws://` and `gs://` straight through, and `bd backup`'s
own help recommends DoltHub by name; for those the server pushes over the
network from its own environment and no filesystem of anybody's is involved.
An operator running `bd backup init https://doltremoteapi.dolthub.com/...` on
an external topology got a permanent verdict explained by a filesystem the
command never touches.
The refusal itself stands, on the reason that is true of every scheme: `CALL
DOLT_BACKUP('add', …)` registers the remote ON THE SERVER, where it is global
to every client connected to it, so one workspace's backup decision becomes
everyone's — the same shape as the auto-backup storm this command's help text
already warns about. The file:// locality problem is now stated as the second,
scheme-specific problem it is. The message keeps its frozen
"<path> is not supported in proxied-server mode" prefix and its
proxy.backup.unsupported code.
The remote-scheme case gets a Tracking item, the way `diff` got "1.4
candidate". The outcome is design; that particular CASE is an open question,
and a design label with no tracking reads as "never" to every later slice.
It is the same server-env credential question S4 has to answer for `dolt
push` on these same topologies. Recorded there too: restore-from-a-remote is
already half-broken in DIRECT mode, because validateBackupRestoreDir stats its
argument, so `bd backup restore https://...` fails everywhere today.
A restore that succeeded and then failed to shut the proxy down reported
"restore failed". The operator's data was back; they were told it was not,
and the obvious next move — run the restore again — was the wrong one.
withQuiescedProxiedProvider now returns teardown failures wrapped in
*proxiedTeardownError instead of flattening them into the operation's error,
and the message the caller renders is split into a function a test can hold
still, because the judgement it encodes (did the data come back) is the point.
Both call sites distinguish now; the second one's "did not reopen" wording was
also wrong for a teardown failure, since it had reopened.
Two smaller things while in here. The guard-rail comment on
newProxiedServerUOWProviderAdopting still said "only two callers legitimately
have no workspace identity to assert" — this slice added a third. That comment
is the register of identity-assertion bypasses, so it now names the third and
why, and says what to do about a fourth. And DirToFileURL was "file://" +
filepath.Abs with no scheme check: it would have turned a DoltHub URL into
file:///cwd/https:/doltremoteapi.dolthub.com/... , a valid-looking URL naming a
directory nobody asked for. Unreachable today, and every caller is a restore
path, which is exactly the capability the tracking item above describes.
CHANGELOG additionally discloses two direct-mode changes this slice makes that
were previously only visible in the diff: `bd backup restore --json` prints a
result object on EVERY topology where it used to print nothing, and the four
backup subcommands that gained SilenceUsage/SilenceErrors no longer follow a
failure with "Error: exit code 1" and a usage block, on every topology.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix(backup): quiesce failed restore reopens and pin JSON output (bd-obos)
Preserve the primary constructor or operation error while reporting cleanup failures without a successful-restore marker. Exercise a real malformed-backup reopen failure and assert both pidfiles are removed; retain the successful round trip and assert its JSON result.
Agent-Signature: codex-unknown-model-unknown-reasoning on behalf of Julian Knutsen
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
188 lines
8 KiB
Go
188 lines
8 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"errors"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func transformTestCommand(path string, flags ...string) *cobra.Command {
|
|
root := &cobra.Command{Use: "bd"}
|
|
cmd := &cobra.Command{Use: path}
|
|
for _, flag := range flags {
|
|
if flag == "of" || flag == "with" {
|
|
cmd.Flags().String(flag, "", "")
|
|
} else {
|
|
cmd.Flags().Bool(flag, false, "")
|
|
}
|
|
}
|
|
root.AddCommand(cmd)
|
|
return cmd
|
|
}
|
|
|
|
func TestProxyTransformCapabilityRows(t *testing.T) {
|
|
cases := []struct {
|
|
name, path, argument string
|
|
flags []string
|
|
outcome ProxyCapabilityOutcome
|
|
code, message string
|
|
exit int
|
|
mutates bool
|
|
}{
|
|
{name: "rename", path: "rename", outcome: ProxyOutcomeRefused, code: "proxy.transform.unsupported", message: "rename is not supported in proxied-server mode", exit: 1},
|
|
{name: "rename-prefix", path: "rename-prefix", outcome: ProxyOutcomeRefused, code: "proxy.transform.unsupported", message: "rename-prefix is not supported in proxied-server mode", exit: 1},
|
|
{name: "rename-prefix dry-run", path: "rename-prefix", argument: "--dry-run", flags: []string{"dry-run"}, outcome: ProxyOutcomeRefused, code: "proxy.transform.unsupported", message: "rename-prefix --dry-run is not supported in proxied-server mode", exit: 1},
|
|
{name: "rename-prefix repair", path: "rename-prefix", argument: "--repair", flags: []string{"repair"}, outcome: ProxyOutcomeRefused, code: "proxy.transform.unsupported", message: "rename-prefix --repair is not supported in proxied-server mode", exit: 1},
|
|
{name: "rename-prefix repair dry-run", path: "rename-prefix", argument: "--dry-run --repair", flags: []string{"dry-run", "repair"}, outcome: ProxyOutcomeRefused, code: "proxy.transform.unsupported", message: "rename-prefix --dry-run --repair is not supported in proxied-server mode", exit: 1},
|
|
{name: "duplicate", path: "duplicate", outcome: ProxyOutcomeRefused, code: "proxy.transform.unsupported", message: "duplicate is not supported in proxied-server mode", exit: 1},
|
|
{name: "duplicate of", path: "duplicate", argument: "--of", flags: []string{"of"}, outcome: ProxyOutcomeRefused, code: "proxy.transform.unsupported", message: "duplicate --of is not supported in proxied-server mode", exit: 1},
|
|
{name: "supersede", path: "supersede", outcome: ProxyOutcomeRefused, code: "proxy.transform.unsupported", message: "supersede is not supported in proxied-server mode", exit: 1},
|
|
{name: "supersede with", path: "supersede", argument: "--with", flags: []string{"with"}, outcome: ProxyOutcomeRefused, code: "proxy.transform.unsupported", message: "supersede --with is not supported in proxied-server mode", exit: 1},
|
|
{name: "duplicates", path: "duplicates", flags: []string{"auto-merge", "dry-run"}, outcome: ProxyOutcomeHonored},
|
|
{name: "duplicates auto-merge", path: "duplicates", argument: "--auto-merge", flags: []string{"auto-merge", "dry-run"}, outcome: ProxyOutcomeRefused, code: "proxy.transform.unsupported", message: "duplicates --auto-merge is not supported in proxied-server mode", exit: 1},
|
|
{name: "duplicates auto-merge dry-run", path: "duplicates", argument: "--auto-merge --dry-run", flags: []string{"auto-merge", "dry-run"}, outcome: ProxyOutcomeHonored},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
cmd := transformTestCommand(tc.path, tc.flags...)
|
|
if tc.argument != "" {
|
|
for _, flag := range strings.Fields(tc.argument) {
|
|
if err := cmd.Flags().Set(strings.TrimPrefix(flag, "--"), "true"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
row, ok := capabilityRowFor(cmd)
|
|
if !ok {
|
|
t.Fatalf("lookup(%q, %q) missing row", tc.path, tc.argument)
|
|
}
|
|
if row.Path != tc.path || row.ArgSet != tc.argument || row.Rule.Outcome != tc.outcome {
|
|
t.Fatalf("row = %#v, want path=%q argument=%q outcome=%q", row, tc.path, tc.argument, tc.outcome)
|
|
}
|
|
if tc.outcome == ProxyOutcomeRefused {
|
|
if row.Rule.Code != tc.code || row.Rule.Message != tc.message || row.Rule.ExitCode != tc.exit || row.Rule.Mutates != tc.mutates {
|
|
t.Fatalf("refusal fields = code=%q message=%q exit=%d mutates=%t",
|
|
row.Rule.Code, row.Rule.Message, row.Rule.ExitCode, row.Rule.Mutates)
|
|
}
|
|
var typed error = proxyCapabilityErrorFor(row.Rule)
|
|
var got *ProxyCapabilityError
|
|
if !errors.As(typed, &got) || got.Code != tc.code || got.ExitCode != 1 || got.Mutates {
|
|
t.Fatalf("typed refusal = %#v", typed)
|
|
}
|
|
}
|
|
if err := validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal); tc.outcome == ProxyOutcomeHonored && err != nil {
|
|
t.Fatalf("honored transform refused: %v", err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestProxyDuplicatesAutoMergeDryRunMatrix(t *testing.T) {
|
|
cmd := transformTestCommand("duplicates", "auto-merge", "dry-run")
|
|
_ = cmd.Flags().Set("auto-merge", "true")
|
|
if err := validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal); err == nil {
|
|
t.Fatalf("non-dry auto-merge error = %v", err)
|
|
}
|
|
_ = cmd.Flags().Set("dry-run", "true")
|
|
if err := validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal); err != nil {
|
|
t.Fatalf("dry-run auto-merge refused: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestProxyTransformRefusalRendering(t *testing.T) {
|
|
t.Setenv("BD_JSON_ENVELOPE", "")
|
|
cmd := transformTestCommand("rename")
|
|
oldJSON := jsonOutput
|
|
t.Cleanup(func() { jsonOutput = oldJSON })
|
|
|
|
jsonOutput = false
|
|
var textErr string
|
|
stderr := captureStderr(t, func() {
|
|
err := validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal)
|
|
if code, ok := exitCodeFromError(err); !ok || code != 1 {
|
|
t.Fatalf("exit = %v, want 1", err)
|
|
}
|
|
textErr = err.Error()
|
|
})
|
|
if textErr != "exit code 1" || stderr != "Error: rename is not supported in proxied-server mode\n" {
|
|
t.Fatalf("text refusal = %q (err %q)", stderr, textErr)
|
|
}
|
|
|
|
jsonOutput = true
|
|
stdout := captureStdout(t, func() error {
|
|
_ = validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal)
|
|
return nil
|
|
})
|
|
var envelope map[string]any
|
|
if err := json.Unmarshal([]byte(stdout), &envelope); err != nil {
|
|
t.Fatalf("JSON refusal: %v (%q)", err, stdout)
|
|
}
|
|
if envelope["code"] != "proxy.transform.unsupported" || envelope["error"] != "rename is not supported in proxied-server mode" {
|
|
t.Fatalf("JSON refusal = %#v", envelope)
|
|
}
|
|
}
|
|
|
|
func TestProxyTransformMatcherIgnoresInheritedOutputFlags(t *testing.T) {
|
|
root := &cobra.Command{Use: "bd"}
|
|
root.PersistentFlags().Bool("json", false, "output JSON")
|
|
cmd := &cobra.Command{Use: "duplicates"}
|
|
cmd.Flags().Bool("auto-merge", false, "")
|
|
cmd.Flags().Bool("dry-run", false, "")
|
|
root.AddCommand(cmd)
|
|
if err := cmd.Flags().Set("auto-merge", "true"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := root.PersistentFlags().Set("json", "true"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
row, ok := capabilityRowFor(cmd)
|
|
if !ok || row.ArgSet != "--auto-merge" || row.Rule.Outcome != ProxyOutcomeRefused {
|
|
t.Fatalf("row with inherited --json = %#v, ok=%v", row, ok)
|
|
}
|
|
}
|
|
|
|
func TestProxyTransformRefusalHasNoProviderOrFileMutation(t *testing.T) {
|
|
dir := t.TempDir()
|
|
version := []byte("version-before\n")
|
|
issues := []byte(`{"id":"before","title":"untouched"}` + "\n")
|
|
versionPath := dir + "/.local_version"
|
|
issuesPath := dir + "/issues.jsonl"
|
|
if err := os.WriteFile(versionPath, version, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(issuesPath, issues, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
oldProvider := uowProvider
|
|
uowProvider = nil
|
|
t.Cleanup(func() { uowProvider = oldProvider })
|
|
|
|
cmd := transformTestCommand("supersede")
|
|
err := validateProxyRegistryBeforeProvider(cmd, ProxyTopologyManagedLocal)
|
|
if err == nil {
|
|
t.Fatal("expected transform refusal")
|
|
}
|
|
if code, ok := exitCodeFromError(err); !ok || code != 1 {
|
|
t.Fatalf("exit = %v, want 1", err)
|
|
}
|
|
if uowProvider != nil {
|
|
t.Fatal("transform refusal initialized a provider")
|
|
}
|
|
gotVersion, err := os.ReadFile(versionPath)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
gotIssues, err := os.ReadFile(issuesPath)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !bytes.Equal(gotVersion, version) || !bytes.Equal(gotIssues, issues) {
|
|
t.Fatal("transform refusal mutated workspace files")
|
|
}
|
|
}
|