* fix(schema,uow): route the proxied data-behind open to the #6575 stop with topology-correct guidance (port of #6695)
Port of the release/1.3.x commit bb03a310a9 (PR #6695) to main, where it
never landed: v1.3.1 is cut from a release branch that is not an ancestor
of main.
The proxied / `bd serve` open path never reached the #6575 data-behind
stop. doltSQLProvider.initSchemaAttempt passed a nil adopter to
CheckSharedStoreMigrateGate, so localDataBehind short-circuited and the
router could never emit smartDataBehind. A proxied store that was level
on schema and behind in data reported `shared-store` instead, whose body
is the designated-migrator recipe -- `bd migrate --force` then
`bd dolt push` -- which in that state is exactly the #6368 wedge the
stop exists to prevent. The refusal was always safe (the shared arm
suppresses the auto-migrate either way); the guidance was not.
- uow: wire a dataBehindAdopter with AheadBehind only
(versioncontrolops.LocalAheadBehind). IsStrictAncestor/WorkingSetClean
stay nil so the remote-ahead arm keeps its plain adopt directive, and
FastForward stays nil because it would promote the schema for every
co-resident client. Read-only proxied opens print the pull-first block
instead of the shared-consent template.
- uow.WithProxiedServerMode(), set only by openProxiedServerUOWProvider,
marks the refusal Proxied: the same provider serves `bd serve` on a
SERVER-mode workspace, where `bd dolt pull` works.
- schema: a Proxied refusal names the server host as where the pull runs
(`bd dolt pull` is refused at the proxied front door,
proxy.dolt_pull.unsupported), the option id becomes
pull-first-on-server-host, and the guidance says the forced
`bd migrate schema --force` consent step IS runnable from the proxied
workspace (the capability registry permits `migrate schema`), so it must
wait for the pull, and that BD_ALLOW_REMOTE_MIGRATE=1 is reachable too.
- cmd/bd: the --json `expected` field carries the same location
qualifier (dataBehindExpectedField).
Not ported, because main already has it: the release PR's F-B half (the
shared data-behind consent step naming `bd migrate schema --force` and
its --global twin, the printGlobalDatabaseConsentHint retarget, and the
shared_migrate_consent_test.go changes) landed on main as #6692.
Adapted to main: the release line's proxyMaintenanceRefusals table is
main's capability registry, so TestProxyMaintenanceAllowsTheSharedConsentVerb
drives validateProxyRegistryBeforeProvider for every proxied topology and
also pins that `bd dolt pull` and the bare `bd migrate` are refused; the
CHANGELOG paragraph is appended to main's existing #6575 entry.
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs(upgrading): where the proxied data-behind pull runs; pin its plumbing
Review fixes for the proxied data-behind stop: the one major of review
attempt 1, the cheap minors, and the nit, plus the wording minor of
attempt 2.
- Clone behind the remote, the docs section the gate's payload links
to, prescribed `bd dolt pull` with no topology qualifier: the remedy a
proxied-server workspace refuses at its front door. Its intro now says
so, and a proxied-server step pair puts the pull (and any conflict
resolution) on the server host, from a workspace with direct database
access, then `bd migrate schema --force` in the proxied workspace. It
also warns that nothing there enforces that order: `--force` and
BD_ALLOW_REMOTE_MIGRATE=1 are honored before the stop is reached, so
the stop never sees them. The warning ends on the payload's own
instruction, not to reach for either to get past the stop, rather than
a negation ("neither is a way past it") that read as the topology
blocking the wedge. The pending-migration exception above the section,
the proxied-server list under Shared servers (now three differences)
and the init-safety ordering rule say the same. The heading, and with
it the anchor the gate links, is unchanged.
- The option plumbing that carries the fix is pinned link by link.
TestApplyProviderOptions covers WithProxiedServerMode (it sets that
field and no open posture). The cmd/bd append moves into
proxiedProviderOptions, which TestProxiedProviderOptions holds to
exactly one added option on a fresh slice. And
TestNewDoltServerUOWProvider_CarriesProxiedServerMode opens two real
providers on one server, with and without the option, and reads the
field the gate copies; openAndInitSchema's provider literal and the
shared test open helpers are left as they were.
- TestProxyMaintenanceAllowsTheSharedConsentVerb also pins `bd dolt
push` and `bd conflicts resolve` as refused, the rest of the list the
proxied refusal body recites. `dolt push` is refused as unimplemented,
the kind of row that flips to allowed once a route lands.
- localDataBehind's doc comment is re-wrapped so the IsStrictAncestor
sentence no longer breaks across the inserted parenthetical.
- The CHANGELOG entry notes the docs change.
Each new pin is red with its link reverted: the option dropped from the
cmd/bd append, the append made in place, the field copy deleted from
the provider literal, the constructor dropping its options, the option
also setting preview, and the push and conflicts codes changed. Still
unpinned: which option the cmd/bd append adds (options are opaque
outside uow) and that `bd serve`'s server-mode open passes none; both
need a seam in cmd/bd.
Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
223 lines
9.2 KiB
Go
223 lines
9.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/steveyegge/beads/internal/configfile"
|
|
"github.com/steveyegge/beads/internal/storage/uow"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// TestRootProviderOptions pins the CLI-side wiring the reviewer flagged as
|
|
// untested: the root pre-run turns its previewMode/useReadOnly classification
|
|
// into providerOpts by calling this function, and a refactor that dropped or
|
|
// inverted that could not fail any existing test. uow.providerOptions is
|
|
// unexported, so this cannot poke inside the returned uow.ProviderOption
|
|
// values (see internal/storage/uow/preview_provider_test.go's
|
|
// TestApplyProviderOptions for the same-package introspection); it instead
|
|
// pins what an external caller can observe — how many options each posture
|
|
// yields — which is what the CLI wiring is responsible for.
|
|
func TestRootProviderOptions(t *testing.T) {
|
|
for _, tt := range []struct {
|
|
name string
|
|
preview, readOnly bool
|
|
want int
|
|
}{
|
|
{name: "ordinary write open", want: 0},
|
|
{name: "preview", preview: true, want: 1},
|
|
{name: "read-only", readOnly: true, want: 1},
|
|
// Preview is the stronger posture and must win: it neither creates nor
|
|
// migrates, while read-only opens normally.
|
|
{name: "preview wins over read-only", preview: true, readOnly: true, want: 1},
|
|
} {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
opts := rootProviderOptions(tt.preview, tt.readOnly)
|
|
if len(opts) != tt.want {
|
|
t.Fatalf("rootProviderOptions(%t, %t) len = %d, want %d", tt.preview, tt.readOnly, len(opts), tt.want)
|
|
}
|
|
for i, o := range opts {
|
|
if o == nil {
|
|
t.Fatalf("rootProviderOptions(%t, %t)[%d] is nil", tt.preview, tt.readOnly, i)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestProxiedProviderOptions pins the proxied-only half of the open posture:
|
|
// every proxied open gains exactly one option on top of the caller's, the
|
|
// proxied-server marker the data-behind refusal reads to say where `bd dolt
|
|
// pull` can be run. Dropping that append would put a proxied workspace back on
|
|
// the runnable-here remedy its own front door refuses. As with
|
|
// TestRootProviderOptions, the options are opaque from here: uow's
|
|
// TestApplyProviderOptions pins what WithProxiedServerMode sets, and
|
|
// TestNewDoltServerUOWProvider_CarriesProxiedServerMode that the open carries
|
|
// it to the gate.
|
|
func TestProxiedProviderOptions(t *testing.T) {
|
|
for _, tt := range []struct {
|
|
name string
|
|
in []uow.ProviderOption
|
|
}{
|
|
{name: "no caller options"},
|
|
{name: "preview", in: []uow.ProviderOption{uow.WithPreview()}},
|
|
{name: "read-only", in: []uow.ProviderOption{uow.WithReadOnly()}},
|
|
} {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
out := proxiedProviderOptions(tt.in)
|
|
if len(out) != len(tt.in)+1 {
|
|
t.Fatalf("proxiedProviderOptions(%d options) len = %d, want %d", len(tt.in), len(out), len(tt.in)+1)
|
|
}
|
|
for i, o := range out {
|
|
if o == nil {
|
|
t.Fatalf("proxiedProviderOptions(%d options)[%d] is nil", len(tt.in), i)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
// The append must not land in the caller's backing array: with spare
|
|
// capacity an in-place append would write the marker into a slice the
|
|
// caller still owns.
|
|
in := make([]uow.ProviderOption, 1, 4)
|
|
in[0] = uow.WithPreview()
|
|
out := proxiedProviderOptions(in)
|
|
if &out[0] == &in[0] {
|
|
t.Fatal("proxiedProviderOptions returned the caller's backing array")
|
|
}
|
|
if in[:cap(in)][1] != nil {
|
|
t.Fatal("proxiedProviderOptions wrote into the caller's spare capacity")
|
|
}
|
|
}
|
|
|
|
func TestNewProxiedServerUOWProvider_RoutesExternalConfigToExternalProvider(t *testing.T) {
|
|
beadsDir := t.TempDir()
|
|
require.NoError(t, configfile.SaveProxiedServerClientInfo(beadsDir, &configfile.ProxiedServerClientInfo{
|
|
External: &configfile.ExternalDoltConfig{
|
|
Host: "db.invalid",
|
|
},
|
|
}))
|
|
|
|
_, err := newProxiedServerUOWProvider(context.Background(), beadsDir, "")
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), "Host requires Port",
|
|
"expected external validation error proving the external code path was taken; got: %v", err)
|
|
}
|
|
|
|
// A corrupted sidecar must abort provider construction, not silently fall
|
|
// back to a fresh managed local database (bd-aj3g5, restoring f880a985b;
|
|
// split-brain: reads return zero issues, writes land in the wrong database).
|
|
func TestNewProxiedServerUOWProvider_CorruptSidecarErrorsInsteadOfManagedFallback(t *testing.T) {
|
|
beadsDir := t.TempDir()
|
|
require.NoError(t, os.WriteFile(
|
|
filepath.Join(beadsDir, configfile.ProxiedServerClientInfoFileName),
|
|
[]byte("{not json"), 0o600))
|
|
|
|
_, err := newProxiedServerUOWProvider(context.Background(), beadsDir, "")
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), configfile.ProxiedServerClientInfoPath(beadsDir),
|
|
"error must name the unreadable sidecar path; got: %v", err)
|
|
assert.Contains(t, err.Error(), "refusing to fall back",
|
|
"must refuse the managed-local fallback; got: %v", err)
|
|
}
|
|
|
|
// An unparseable workspace config must abort too — defaulting the database
|
|
// name sends writes to the wrong database, and the team-server identity
|
|
// assertion silently degrades to no assertion at all.
|
|
func TestNewProxiedServerUOWProvider_CorruptWorkspaceConfigErrors(t *testing.T) {
|
|
beadsDir := t.TempDir()
|
|
require.NoError(t, os.WriteFile(
|
|
filepath.Join(beadsDir, configfile.ConfigFileName),
|
|
[]byte("{not json"), 0o600))
|
|
|
|
_, err := newProxiedServerUOWProvider(context.Background(), beadsDir, "")
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), configfile.ConfigPath(beadsDir),
|
|
"error must name the unreadable workspace config path; got: %v", err)
|
|
assert.Contains(t, err.Error(), "refusing to fall back",
|
|
"must refuse the fresh-database fallback; got: %v", err)
|
|
}
|
|
|
|
// An UNREADABLE (permission-denied) sidecar is the same hazard as an
|
|
// unparseable one: the file exists, so falling back would fork a fresh
|
|
// database while the real one sits behind the perms error.
|
|
func TestNewProxiedServerUOWProvider_UnreadableSidecarErrors(t *testing.T) {
|
|
if os.Geteuid() == 0 {
|
|
t.Skip("running as root; chmod 000 does not deny reads")
|
|
}
|
|
beadsDir := t.TempDir()
|
|
sidecar := filepath.Join(beadsDir, configfile.ProxiedServerClientInfoFileName)
|
|
require.NoError(t, os.WriteFile(sidecar, []byte("{}"), 0o600))
|
|
require.NoError(t, os.Chmod(sidecar, 0o000))
|
|
t.Cleanup(func() { _ = os.Chmod(sidecar, 0o600) })
|
|
|
|
_, err := newProxiedServerUOWProvider(context.Background(), beadsDir, "")
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), configfile.ProxiedServerClientInfoPath(beadsDir),
|
|
"error must name the unreadable sidecar path; got: %v", err)
|
|
assert.Contains(t, err.Error(), "refusing to fall back",
|
|
"must refuse the managed-local fallback; got: %v", err)
|
|
}
|
|
|
|
// ABSENT files are the legal fresh-workspace path: both loads return
|
|
// (nil, nil) and the topology resolves to the defaults with no error. Pinned
|
|
// at the resolver level because the full provider would go on to start a
|
|
// managed dolt server.
|
|
func TestResolveProxiedServerUOWTopology_AbsentFilesResolveDefaults(t *testing.T) {
|
|
beadsDir := t.TempDir()
|
|
|
|
topology, err := resolveProxiedServerUOWTopology(beadsDir, "", assertWorkspaceIdentity)
|
|
require.NoError(t, err, "absent metadata.json and sidecar must not be an error")
|
|
assert.Equal(t, configfile.DefaultDoltDatabase, topology.database)
|
|
assert.False(t, topology.teamServer)
|
|
assert.Nil(t, topology.external)
|
|
}
|
|
|
|
func TestNewExternalProxiedServerUOWProvider_CreatesRootDir(t *testing.T) {
|
|
beadsDir := t.TempDir()
|
|
external := &configfile.ExternalDoltConfig{Host: "db.invalid"}
|
|
|
|
_, err := newExternalProxiedServerUOWProvider(context.Background(), beadsDir, sqlServerUOWTopology{
|
|
database: "beads_test",
|
|
external: external,
|
|
})
|
|
require.Error(t, err, "invalid external config must surface a validation error")
|
|
|
|
wantRoot := proxiedServerRoot(beadsDir)
|
|
assert.DirExists(t, wantRoot, "external provider should create the proxied server root dir before validating")
|
|
}
|
|
|
|
func TestNewExternalProxiedServerUOWProvider_HonorsCustomRootPath(t *testing.T) {
|
|
beadsDir := t.TempDir()
|
|
customRoot := filepath.Join(t.TempDir(), "custom-proxy-root")
|
|
|
|
require.NoError(t, configfile.SaveProxiedServerClientInfo(beadsDir, &configfile.ProxiedServerClientInfo{
|
|
RootPath: customRoot,
|
|
External: &configfile.ExternalDoltConfig{Host: "db.invalid"},
|
|
}))
|
|
|
|
_, err := newProxiedServerUOWProvider(context.Background(), beadsDir, "")
|
|
require.Error(t, err, "invalid external config must surface a validation error")
|
|
|
|
assert.DirExists(t, customRoot, "external provider should create the custom root dir, not the default")
|
|
assert.NoDirExists(t, proxiedServerRoot(beadsDir), "default root must not be created when a custom RootPath is set")
|
|
}
|
|
|
|
func TestNewExternalProxiedServerUOWProvider_HonorsCustomLogPath(t *testing.T) {
|
|
beadsDir := t.TempDir()
|
|
customLogDir := t.TempDir()
|
|
customLog := filepath.Join(customLogDir, "external.log")
|
|
|
|
require.NoError(t, configfile.SaveProxiedServerClientInfo(beadsDir, &configfile.ProxiedServerClientInfo{
|
|
LogPath: customLog,
|
|
External: &configfile.ExternalDoltConfig{Host: "db.invalid"},
|
|
}))
|
|
|
|
_, err := newProxiedServerUOWProvider(context.Background(), beadsDir, "")
|
|
require.Error(t, err, "invalid external config must surface a validation error")
|
|
assert.Contains(t, err.Error(), "Host requires Port",
|
|
"external code path must be the one reached; got: %v", err)
|
|
}
|