fix(dolt): route bd dolt push's git-origin adoption through the persisted-remote probe (wy-82hc5)
adoptGitOriginRemoteForPush decided "this rig has no Dolt remote" from len(ListRemotes) alone — the same unhardened assumption wy-xtv17 removed from the no-remote gate. In the GH#2118 cold-start window a just-started sql-server reports an empty dolt_remotes while the remote IS persisted in .dolt/repo_state.json, so `bd dolt push` re-derived origin from git there. Usually the same URL and a harmless re-add; when the persisted remote and the git origin disagree (a Dolt remote pointed elsewhere, or a renamed or redirected origin), it repointed push on the strength of a stale listing. The evidence rule now lives in exactly one function, hasConfiguredRemote: dolt_remotes, then the on-disk probe reached through the storage decorator chain, with a failed listing returned as an error rather than read as "no remote". hasNoRemoteConfigured (the bd sync / dolt push|pull exit-0 gate) is a wrapper over it, and adoption asks the same question. Two siblings deciding this from different evidence is exactly how push kept the hole after wy-xtv17 fixed the gate. Behavior change worth naming: during the cold-start window a plain `bd dolt push` now fails loudly (the CLI-route picker in internal/storage/dolt/store.go is itself a len(ListRemotes)-only decider, so it falls back to SQL DOLT_PUSH and reports "remote origin not found") instead of self-healing by adopting. That is the wy-xtv17/bd-6dnrw.7 trade — loud beats a silent repoint — and the window is transient. Converging the remaining len(ListRemotes)-only deciders, including that route picker, is wy-6k7f7. Test: TestAdoptGitOriginRemoteForPush_PersistedRemoteVetoesAdoption drives the real wireStorageDecorators chain (hooks, and hooks + telemetry) over a store whose dolt_remotes is empty and whose remote is on disk, asserting adoption is a quiet no-op with no AddRemote, plus the structural cases and that a failed listing stays an error. Negative control run four times across two reviewers: removing the veto fails this test and the wy-xtv17 tests in both chain variants.
This commit is contained in:
parent
cd25e0919d
commit
59241bf165
2 changed files with 154 additions and 9 deletions
|
|
@ -202,14 +202,44 @@ func isConfirmedNoRemote(ctx context.Context, st remoteLister, err error) bool {
|
|||
// runs on a timer and must not fail every tick on a solo rig — can reuse the
|
||||
// proof without loosening it.
|
||||
func hasNoRemoteConfigured(ctx context.Context, st remoteLister) bool {
|
||||
configured, listErr := hasConfiguredRemote(ctx, st)
|
||||
return listErr == nil && !configured
|
||||
}
|
||||
|
||||
// hasConfiguredRemote decides, from evidence, whether a rig has a Dolt remote
|
||||
// at all. It is the one decider for the push/sync no-remote question: both
|
||||
// hasNoRemoteConfigured (the `bd sync` / `bd dolt push|pull` exit-0 gate) and
|
||||
// adoptGitOriginRemoteForPush go through it. It is NOT yet the only reader of
|
||||
// that evidence in cmd/bd — `bd config apply`, ensureDoltRemote, and the
|
||||
// doctor/drift diagnostics still judge from len(ListRemotes) alone and have
|
||||
// the same cold-start hole; converging them is wy-6k7f7. Do not assume a new
|
||||
// remote-related decision is covered by this function: route it here.
|
||||
//
|
||||
// Two sources of evidence, because dolt_remotes alone is not enough: a
|
||||
// server-mode rig whose sql-server has just cold-started can report an EMPTY
|
||||
// dolt_remotes while the remote IS persisted on disk in .dolt/repo_state.json
|
||||
// (GH#2118), so the on-disk probe gets a veto. The probe has to be reached
|
||||
// through the storage decorator chain, since HasPersistedRemote is not part of
|
||||
// storage.DoltStorage and the store bd holds is all but always decorated —
|
||||
// that is wy-xtv17.
|
||||
//
|
||||
// A failed listing is neither evidence: it returns the error, and callers must
|
||||
// not read it as "no remote". Having two sibling functions decide this from
|
||||
// different evidence is what left `bd dolt push` still trusting an empty
|
||||
// dolt_remotes after wy-xtv17 hardened the no-remote gate (wy-82hc5), so the
|
||||
// rule lives here once.
|
||||
func hasConfiguredRemote(ctx context.Context, st remoteLister) (bool, error) {
|
||||
remotes, listErr := st.ListRemotes(ctx)
|
||||
if listErr != nil || len(remotes) > 0 {
|
||||
return false
|
||||
if listErr != nil {
|
||||
return false, listErr
|
||||
}
|
||||
if len(remotes) > 0 {
|
||||
return true, nil
|
||||
}
|
||||
if prober, ok := persistedRemoteProberFor(st); ok && prober.HasPersistedRemote() {
|
||||
return false
|
||||
return true, nil
|
||||
}
|
||||
return true
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// persistedRemoteProberFor finds the on-disk remote probe behind any chain of
|
||||
|
|
@ -334,14 +364,21 @@ func printNoRemoteGuidance() {
|
|||
fmt.Println(" • Azure Blob Storage: az://account.blob.core.windows.net/container/path")
|
||||
}
|
||||
|
||||
// adoptGitOriginRemoteForPush gives a rig with no Dolt remote the one its git
|
||||
// origin implies, so `bd dolt push` works out of the box.
|
||||
//
|
||||
// It asks hasConfiguredRemote rather than reading len(ListRemotes) itself: an
|
||||
// empty dolt_remotes is not proof of a remote-less rig during the GH#2118
|
||||
// cold-start window, and adopting there re-derives the remote from git.
|
||||
// Usually that is the same URL and the AddRemote is a harmless re-add, but
|
||||
// when the persisted remote and the git origin disagree — a Dolt remote
|
||||
// deliberately pointed elsewhere, or a renamed/redirected origin — the rig
|
||||
// starts pushing somewhere else on the strength of a stale listing (wy-82hc5).
|
||||
func adoptGitOriginRemoteForPush(ctx context.Context, st storage.DoltStorage) (bool, error) {
|
||||
remotes, err := st.ListRemotes(ctx)
|
||||
if err != nil {
|
||||
configured, err := hasConfiguredRemote(ctx, st)
|
||||
if err != nil || configured {
|
||||
return false, err
|
||||
}
|
||||
if len(remotes) > 0 {
|
||||
return false, nil
|
||||
}
|
||||
beadsDir := selectedDoltBeadsDir()
|
||||
if beadsDir == "" {
|
||||
return false, fmt.Errorf("no active beads workspace")
|
||||
|
|
|
|||
|
|
@ -1224,6 +1224,114 @@ func TestHasNoRemoteConfigured_ProbesThroughDecoratedStore(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// fakeAdoptingDoltStore is fakeProbingDoltStore plus the write side of the
|
||||
// adoption path: it records AddRemote instead of performing it, so a
|
||||
// regression surfaces as an assertion here rather than as a real remote write
|
||||
// (and stops before adoption can touch the workspace config or git).
|
||||
type fakeAdoptingDoltStore struct {
|
||||
fakeProbingDoltStore
|
||||
listErr error
|
||||
addRemoteCalls int
|
||||
}
|
||||
|
||||
func (f *fakeAdoptingDoltStore) ListRemotes(ctx context.Context) ([]storage.RemoteInfo, error) {
|
||||
if f.listErr != nil {
|
||||
return nil, f.listErr
|
||||
}
|
||||
return f.fakeProbingDoltStore.ListRemotes(ctx)
|
||||
}
|
||||
|
||||
func (f *fakeAdoptingDoltStore) AddRemote(_ context.Context, name, url string) error {
|
||||
f.addRemoteCalls++
|
||||
return fmt.Errorf("fakeAdoptingDoltStore: AddRemote(%q, %q) must not be called", name, url)
|
||||
}
|
||||
|
||||
// wy-82hc5: `bd dolt push` adopts the git origin as the Dolt remote when the
|
||||
// rig appears to have none, and it judged that on an empty dolt_remotes alone
|
||||
// — the same unhardened assumption wy-xtv17 removed from the no-remote gate.
|
||||
// In the GH#2118 cold-start window (sql-server just started, remote persisted
|
||||
// in .dolt/repo_state.json but dolt_remotes not yet populated) that re-derives
|
||||
// the remote from git, silently repointing push whenever the persisted remote
|
||||
// and the git origin disagree. The on-disk probe must veto first, and it can
|
||||
// only be reached through the storage decorator chain.
|
||||
func TestAdoptGitOriginRemoteForPush_PersistedRemoteVetoesAdoption(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
for _, chain := range []struct {
|
||||
name string
|
||||
telemetry bool
|
||||
}{
|
||||
{"hooks only", false},
|
||||
{"hooks + telemetry", true},
|
||||
} {
|
||||
t.Run(chain.name, func(t *testing.T) {
|
||||
clearTelemetryEnv(t)
|
||||
if chain.telemetry {
|
||||
t.Setenv("BD_OTEL_STDOUT", "true")
|
||||
}
|
||||
decorate := func(raw storage.DoltStorage) storage.DoltStorage {
|
||||
return wireStorageDecorators(raw, hooks.NewRunner("/nonexistent"), false)
|
||||
}
|
||||
|
||||
// The load-bearing case, driven through the real call site:
|
||||
// dolt_remotes is empty, the remote is on disk. Adoption must be
|
||||
// a quiet no-op — no AddRemote, no error, and no walk into the
|
||||
// workspace/git half of the function.
|
||||
raw := &fakeAdoptingDoltStore{fakeProbingDoltStore: fakeProbingDoltStore{persisted: true}}
|
||||
persisted := decorate(raw)
|
||||
if _, direct := persisted.(persistedRemoteProber); direct {
|
||||
t.Fatalf("%T implements persistedRemoteProber directly; this test no longer exercises the peel", persisted)
|
||||
}
|
||||
adopted, err := adoptGitOriginRemoteForPush(ctx, persisted)
|
||||
if err != nil {
|
||||
t.Errorf("adoptGitOriginRemoteForPush returned error %v; a persisted remote is a no-op, not a failure", err)
|
||||
}
|
||||
if adopted {
|
||||
t.Error("adoptGitOriginRemoteForPush adopted the git origin although the remote is persisted on disk (GH#2118 cold-start window)")
|
||||
}
|
||||
if raw.addRemoteCalls != 0 {
|
||||
t.Errorf("AddRemote called %d times; the persisted-remote veto did not fire", raw.addRemoteCalls)
|
||||
}
|
||||
|
||||
// The structural decision behind it, through the same chain.
|
||||
// This block, not the call-site block above, is the assertion
|
||||
// that fails in EVERY environment when the veto is removed: with
|
||||
// the fix reverted, adoption above bails early at
|
||||
// selectedDoltBeadsDir() on a machine with no resolvable
|
||||
// workspace, so its `adopted` / addRemoteCalls assertions are
|
||||
// environment-dependent. Do not drop these as redundant.
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
store *fakeAdoptingDoltStore
|
||||
want bool
|
||||
}{
|
||||
{"persisted on disk only", &fakeAdoptingDoltStore{fakeProbingDoltStore: fakeProbingDoltStore{persisted: true}}, true},
|
||||
{"listed in dolt_remotes", &fakeAdoptingDoltStore{fakeProbingDoltStore: fakeProbingDoltStore{remotes: []storage.RemoteInfo{{Name: "origin"}}}}, true},
|
||||
{"no remote anywhere", &fakeAdoptingDoltStore{}, false},
|
||||
} {
|
||||
got, err := hasConfiguredRemote(ctx, decorate(tc.store))
|
||||
if err != nil {
|
||||
t.Errorf("hasConfiguredRemote(%s) error: %v", tc.name, err)
|
||||
}
|
||||
if got != tc.want {
|
||||
t.Errorf("hasConfiguredRemote(%s) = %v, want %v", tc.name, got, tc.want)
|
||||
}
|
||||
}
|
||||
|
||||
// A failed ListRemotes is still a real error, not "no remote":
|
||||
// guessing a remote off a broken listing is how the wrong URL
|
||||
// gets adopted.
|
||||
listErr := fmt.Errorf("dolt_remotes unavailable")
|
||||
broken := decorate(&fakeAdoptingDoltStore{listErr: listErr})
|
||||
if _, err := hasConfiguredRemote(ctx, broken); !errors.Is(err, listErr) {
|
||||
t.Errorf("hasConfiguredRemote swallowed a ListRemotes failure: err = %v", err)
|
||||
}
|
||||
if adopted, err := adoptGitOriginRemoteForPush(ctx, broken); adopted || !errors.Is(err, listErr) {
|
||||
t.Errorf("adoptGitOriginRemoteForPush(list error) = (%v, %v), want (false, the list error)", adopted, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// A store that is neither a prober nor a decorator must not be treated as one:
|
||||
// the probe is optional, and its absence means "no on-disk evidence", not
|
||||
// "remote persisted".
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue