* fix(dolt): require consent before adopting a Dolt remote derived from git origin (#5068)
On a rig with no Dolt remote configured, `bd dolt push` and `bd sync` derived
one from git origin, called AddRemote, persisted sync.remote into
.beads/config.yaml, committed that config change under the user's git identity,
and uploaded the full issue history. No prompt, no flag, no opt-out. The
reporter's git origin was a public repo, so private issue history was published
by a command they believed targeted an already-configured remote.
The pre-existing hasConfiguredRemote probe (59241bf16) is not a guard against
this: it is a correctness fix for a stale-empty-listing edge case in the
GH#2118 cold-start window, and it only decides *whether a remote is already
configured*, never whether adopting a new one is wanted.
Adoption now fails closed:
- interactive: show the derived URL and every side effect that follows a yes
(AddRemote, the sync.remote write, the config commit made under the user's
git identity, the upload) and default to NO. An empty line, EOF or a read
error is a decline.
- non-interactive: refuse and exit non-zero, naming the URL that would have
been adopted and the explicit opt-in. Not knowing where the upload was
going was half the reported complaint.
- --yes/-y consents ahead of time for scripted use, and still announces the
target so a scripted run leaves a record of where it uploaded.
- --no-adopt or BD_NO_REMOTE_ADOPT=1 disables adoption; it beats --yes, so a
--yes buried in an alias cannot defeat a deliberate machine-level opt-out.
Deliberately NOT reusing confirmPrompt from bootstrap.go: it returns true when
stdin is not a TTY. That is the right default for "proceed with the thing you
asked for" and the wrong one here.
`bd sync` gets the same gate and the same flags. It publishes the same history
to the same derived remote, so leaving it ungated would just move the hole.
This is the part most likely to need a maintainer ruling: an automated `bd
sync` on a rig that was relying on implicit adoption now needs --yes or a
configured remote.
Also moved workspace resolution below the gate. selectedDoltBeadsDir calls
prepareSelectedNoDBContext, which mutates process and on-disk workspace state,
so on the old ordering that mutation happened before consent. Found because
tests that called the real function polluted the shared test binary and broke
TestInitDatabaseAdoptsExistingProjectID.
The consent decision is a pure function (decideRemoteAdoption) plus a pure
application step (applyAdoptionConsent), so the fail-closed property is
asserted by table tests rather than inferred from the call site, and the tests
need no TTY, store, or repo to mutate.
Rigs that already have a remote configured are unaffected: that path is an
early return above the gate, and the existing persisted-remote veto test now
passes AssumeYes so it still fails if the veto is ever moved below consent.
Validated: go build ./... ; go vet ./cmd/bd ; the adoption/sync/init test set
passes and no longer pollutes. Full `make test` is in the local verification
queue (the cmd/bd package exceeds go test's default 10m timeout in-session).
Agent-Signature: claude-opus-5-medium on behalf of maphew
* test(dolt): update the embedded adoption tests for the consent gate (#5068)
CI caught what my local `make test` could not: TestEmbeddedInit's
dolt_push_lazily_adopts_later_git_origin and
dolt_push_adopts_target_origin_with_dash_c assert that `bd dolt push` adopts a
git origin, and a test process has no TTY, so the new gate correctly refuses.
Those two subtests cover a capability this PR keeps, not the behavior it
removes, so they now pass --yes — the scripted consent. Their assertions are
otherwise untouched.
Added dolt_push_refuses_to_adopt_without_consent alongside them: no TTY, no
--yes, and then all four things that must NOT have happened — the push fails,
the refusal names the remote it would have adopted, no Dolt remote was added,
sync.remote was not persisted, and refs/dolt/data is absent on the bare remote
(i.e. nothing was uploaded). That last assertion is the one the issue is
actually about.
Why local validation missed it: cmd/bd/init_embedded_test.go skips unless
BEADS_TEST_EMBEDDED_DOLT=1, and CI runs it as sharded "Test (Embedded Dolt Cmd
N/20)" jobs. `make test` going green does not exercise it. Recorded as a bd
memory so the next agent touching push/sync/init runs it explicitly.
Agent-Signature: claude-opus-5-medium on behalf of maphew
* review fixes: --json is non-interactive; refusals name the caller's own command
Two consent-surface gaps: a JSON-mode run on a pty would block forever on
the interactive prompt (JSON is a machine contract — refuse with the
--yes guidance instead, matching the hook-migration consent gate), and
the refusal/prompt text hardcoded `bd dolt push --yes`, steering bd sync
users into a pull-less push. Adoption messages now carry an adoptOptIn
naming the command actually run. Also: push --help documents adoption,
and the dead errors.Is line is gone.
Agent-Signature: claude-code-claude-fable-5-unknown-reasoning on behalf of Steve Yegge
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xmjba2GjaHnrvaU2sM8Kz5
---------
Co-authored-by: Beadwright <beadwright@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
208 lines
7.2 KiB
Go
208 lines
7.2 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestDecideRemoteAdoptionFailsClosed is the #5068 regression assertion in its
|
|
// purest form: with no consent input at all, the answer is refuse. Every
|
|
// variant below exists because a "sensible default" in any one of them is how
|
|
// the original bug read — bd derived a remote and uploaded to it because
|
|
// nothing said not to.
|
|
func TestDecideRemoteAdoptionFailsClosed(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name string
|
|
policy adoptPolicy
|
|
wantDecide adoptDecision
|
|
wantRefusal adoptRefusal
|
|
}{
|
|
{
|
|
name: "zero value refuses",
|
|
policy: adoptPolicy{},
|
|
wantDecide: adoptRefuse,
|
|
wantRefusal: adoptRefusedNonInteractive,
|
|
},
|
|
{
|
|
name: "non-interactive without --yes refuses",
|
|
policy: adoptPolicy{Interactive: false},
|
|
wantDecide: adoptRefuse,
|
|
wantRefusal: adoptRefusedNonInteractive,
|
|
},
|
|
{
|
|
name: "interactive asks rather than assuming",
|
|
policy: adoptPolicy{Interactive: true},
|
|
wantDecide: adoptAsk,
|
|
wantRefusal: adoptRefusalNone,
|
|
},
|
|
{
|
|
name: "--yes is consent even when non-interactive",
|
|
policy: adoptPolicy{AssumeYes: true},
|
|
wantDecide: adoptProceed,
|
|
wantRefusal: adoptRefusalNone,
|
|
},
|
|
{
|
|
name: "--no-adopt refuses, and it is not an error",
|
|
policy: adoptPolicy{Disabled: true, Interactive: true},
|
|
wantDecide: adoptRefuse,
|
|
wantRefusal: adoptRefusedDisabled,
|
|
},
|
|
{
|
|
// Contradictory instructions: the safer one wins. Otherwise a
|
|
// scripted --yes buried in an alias would silently defeat a
|
|
// deliberate BD_NO_REMOTE_ADOPT=1 on the machine.
|
|
name: "--no-adopt beats --yes",
|
|
policy: adoptPolicy{Disabled: true, AssumeYes: true, Interactive: true},
|
|
wantDecide: adoptRefuse,
|
|
wantRefusal: adoptRefusedDisabled,
|
|
},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
gotDecide, gotRefusal := decideRemoteAdoption(tc.policy)
|
|
if gotDecide != tc.wantDecide || gotRefusal != tc.wantRefusal {
|
|
t.Errorf("decideRemoteAdoption(%+v) = (%v, %v), want (%v, %v)",
|
|
tc.policy, gotDecide, gotRefusal, tc.wantDecide, tc.wantRefusal)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCurrentAdoptPolicyHonorsEnvKillSwitch(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
env string
|
|
want bool
|
|
}{
|
|
{"1", true},
|
|
{"true", true},
|
|
{"YES", true},
|
|
{"0", false},
|
|
{"", false},
|
|
{"maybe", false},
|
|
} {
|
|
t.Run("BD_NO_REMOTE_ADOPT="+tc.env, func(t *testing.T) {
|
|
t.Setenv("BD_NO_REMOTE_ADOPT", tc.env)
|
|
if got := currentAdoptPolicy(false, false, true, false).Disabled; got != tc.want {
|
|
t.Errorf("Disabled = %v, want %v", got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
|
|
t.Setenv("BD_NO_REMOTE_ADOPT", "")
|
|
if !currentAdoptPolicy(false, true, true, false).Disabled {
|
|
t.Error("--no-adopt alone did not disable adoption")
|
|
}
|
|
}
|
|
|
|
// --json is a machine contract: even on a TTY (agent harnesses often allocate
|
|
// one), the policy must be non-interactive so a JSON consumer never blocks on
|
|
// a prompt it cannot see. The refusal error is the correct surface instead.
|
|
func TestCurrentAdoptPolicyJSONModeIsNotInteractive(t *testing.T) {
|
|
t.Setenv("BD_NO_REMOTE_ADOPT", "")
|
|
p := currentAdoptPolicy(false, false, true, true)
|
|
if p.Interactive {
|
|
t.Fatal("jsonMode policy is Interactive; bd sync --json on a pty would hang on the consent prompt")
|
|
}
|
|
if decision, refusal := decideRemoteAdoption(p); decision != adoptRefuse || refusal != adoptRefusedNonInteractive {
|
|
t.Fatalf("jsonMode without --yes: decision = %v/%v, want refuse/non-interactive", decision, refusal)
|
|
}
|
|
if decision, _ := decideRemoteAdoption(currentAdoptPolicy(true, false, true, true)); decision != adoptProceed {
|
|
t.Fatal("jsonMode with --yes must still proceed")
|
|
}
|
|
}
|
|
|
|
// TestAdoptionRefusedErrorNamesTheURL: the reporter's complaint was not only
|
|
// that bd adopted a remote, but that they could not tell where the upload was
|
|
// going. An error that omits the URL does not fix that half.
|
|
func TestAdoptionRefusedErrorNamesTheURL(t *testing.T) {
|
|
const url = "git+ssh://git@github.com/someone/public-repo.git"
|
|
msg := adoptionRefusedError(url, pushAdoptOptIn).Error()
|
|
for _, want := range []string{url, "bd dolt push --yes", "--no-adopt", "BD_NO_REMOTE_ADOPT"} {
|
|
if !strings.Contains(msg, want) {
|
|
t.Errorf("refusal message does not mention %q:\n%s", want, msg)
|
|
}
|
|
}
|
|
}
|
|
|
|
// The refusal must name the command the user actually ran: steering a sync
|
|
// user into `bd dolt push --yes` would trade their pull away.
|
|
func TestAdoptionRefusedErrorNamesTheCallersCommand(t *testing.T) {
|
|
msg := adoptionRefusedError("git+ssh://git@github.com/x/y.git", syncAdoptOptIn).Error()
|
|
if !strings.Contains(msg, "bd sync --yes") {
|
|
t.Errorf("sync-path refusal does not offer bd sync --yes:\n%s", msg)
|
|
}
|
|
if strings.Contains(msg, "bd dolt push --yes") {
|
|
t.Errorf("sync-path refusal steers the user to bd dolt push:\n%s", msg)
|
|
}
|
|
}
|
|
|
|
// TestApplyAdoptionConsentGatesTheWrite is acceptance item 5 of #5068 at the
|
|
// gate itself: with no configured Dolt remote and a derived git-origin URL,
|
|
// nothing downstream may run without consent. Everything after this call in
|
|
// adoptGitOriginRemoteForPush writes (AddRemote, sync.remote, the git commit,
|
|
// then the upload), so proceed=false is exactly "nothing was uploaded".
|
|
func TestApplyAdoptionConsentGatesTheWrite(t *testing.T) {
|
|
const url = "git+ssh://git@github.com/someone/public-repo.git"
|
|
|
|
for _, tc := range []struct {
|
|
name string
|
|
policy adoptPolicy
|
|
wantProceed bool
|
|
wantErr bool
|
|
}{
|
|
{
|
|
// The reported bug: a scripted/hook invocation with a public git
|
|
// origin and no configured remote must not upload.
|
|
name: "non-interactive without --yes does not proceed, and says so",
|
|
policy: adoptPolicy{Interactive: false},
|
|
wantProceed: false,
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "--yes proceeds",
|
|
policy: adoptPolicy{AssumeYes: true},
|
|
wantProceed: true,
|
|
wantErr: false,
|
|
},
|
|
{
|
|
// --no-adopt is a request, not a failure: the caller falls through
|
|
// to ordinary no-remote handling.
|
|
name: "--no-adopt does not proceed and is not an error",
|
|
policy: adoptPolicy{Disabled: true, Interactive: true},
|
|
wantProceed: false,
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "--no-adopt beats --yes",
|
|
policy: adoptPolicy{Disabled: true, AssumeYes: true},
|
|
wantProceed: false,
|
|
wantErr: false,
|
|
},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
t.Setenv("BD_NO_REMOTE_ADOPT", "")
|
|
proceed, err := applyAdoptionConsent(url, tc.policy, pushAdoptOptIn)
|
|
if proceed != tc.wantProceed {
|
|
t.Errorf("proceed = %v, want %v", proceed, tc.wantProceed)
|
|
}
|
|
if (err != nil) != tc.wantErr {
|
|
t.Errorf("err = %v, wantErr = %v", err, tc.wantErr)
|
|
}
|
|
if tc.wantErr && err != nil && !strings.Contains(err.Error(), url) {
|
|
t.Errorf("refusal did not name the remote it would have adopted: %v", err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// The zero-value policy is what a caller that forgets to wire the flags would
|
|
// pass. It must refuse, not adopt.
|
|
func TestApplyAdoptionConsentZeroPolicyRefuses(t *testing.T) {
|
|
t.Setenv("BD_NO_REMOTE_ADOPT", "")
|
|
proceed, err := applyAdoptionConsent("git+ssh://git@github.com/x/y.git", adoptPolicy{}, pushAdoptOptIn)
|
|
if proceed {
|
|
t.Fatal("zero-value policy proceeded with adoption")
|
|
}
|
|
if err == nil {
|
|
t.Fatal("zero-value policy refused silently; the user gets no explanation")
|
|
}
|
|
}
|