diff --git a/CHANGELOG.md b/CHANGELOG.md index a5618ca17..cba3b27f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -524,6 +524,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- **A routed `bd create` reports a failed follow-up commit** (#6254). When + `--repo` or the `routing.*` settings send a create to another repository, + the follow-up Dolt commit in that repository wrote its error only to the + debug log. It now prints `Warning: created , but the follow-up Dolt + commit in failed: ` on stderr. The create still succeeds, + prints the issue and syncs a remote target, because that commit runs only + under `dolt.auto-commit=on`, where the create has already committed the new + issue. - **`bd gate list` works over a connected HTTP workspace** (S20). The workspace-wide listing built a raw `SearchIssues` filter, which the HTTP backend refuses, so gc's `renudge-stale-human-gates` order failed on every diff --git a/cmd/bd/create.go b/cmd/bd/create.go index 64aeada9c..19b968b71 100644 --- a/cmd/bd/create.go +++ b/cmd/bd/create.go @@ -606,9 +606,11 @@ var createCmd = &cobra.Command{ created.Comments = nil edges := createDepEdges{parentID: parentID, specs: depSpecs, waitsFor: waitsForSpec} - if edges.empty() { + routed := repoPath != "." && targetStore != nil + if edges.empty() && !routed { // Bare create: preserve the embedded-mode follow-up Dolt commit. - // The deps path commits inside its transaction instead. + // The deps path commits inside its transaction instead, and a + // routed create's one follow-up commit is flushRoutedCreate. shouldCommit, err := shouldCommitCreatePostWrites(created, false) if err != nil { return HandleError("dolt auto-commit failed: %v", err) @@ -621,13 +623,8 @@ var createCmd = &cobra.Command{ } } - if repoPath != "." && targetStore != nil { - if err := commitPendingIfEmbedded(ctx, targetStore, currentActor(), doltAutoCommitParams{ - Command: "create", - IssueIDs: []string{created.ID}, - }); err != nil { - debug.Logf("warning: failed to commit routed repo: %v", err) - } + if routed { + flushRoutedCreate(ctx, targetStore, repoPath, created.ID) } if remoteCache != nil { @@ -907,6 +904,19 @@ func shouldCommitCreatePostWrites(_ *types.Issue, _ bool) (bool, error) { return embeddedWritesCommitNow() } +// flushRoutedCreate runs a routed create's follow-up Dolt commit in the target +// store. That commit runs only under dolt.auto-commit=on, where ops.Create has +// already committed the new row, so its failure cannot lose the issue: it is a +// warning that names the target, and the create still succeeds. +func flushRoutedCreate(ctx context.Context, target storage.DoltStorage, repoPath, id string) { + if err := commitPendingIfEmbedded(ctx, target, currentActor(), doltAutoCommitParams{ + Command: "create", + IssueIDs: []string{id}, + }); err != nil { + WarnError("created %s, but the follow-up Dolt commit in %s failed: %v", id, repoPath, err) + } +} + func createDepsAcceptedTypeList() string { names := []string{"blocked-by", "depends-on"} for _, depType := range types.WellKnownDependencyTypes() { diff --git a/cmd/bd/create_embedded_test.go b/cmd/bd/create_embedded_test.go index 43ed28a3a..44f320be1 100644 --- a/cmd/bd/create_embedded_test.go +++ b/cmd/bd/create_embedded_test.go @@ -159,6 +159,33 @@ func assertDepExists(t *testing.T, beadsDir, database, issueID, dependsOnID stri } } +// assertCommittedAtHead verifies via raw SQL that each issue is in the store's +// HEAD commit and that its working set holds no uncommitted change. +func assertCommittedAtHead(t *testing.T, beadsDir, database string, ids ...string) { + t.Helper() + db, cleanup, err := embeddeddolt.OpenSQL(t.Context(), filepath.Join(beadsDir, "embeddeddolt"), database, "main") + if err != nil { + t.Fatalf("OpenSQL: %v", err) + } + defer cleanup() + for _, id := range ids { + var count int + if err := db.QueryRowContext(t.Context(), "SELECT COUNT(*) FROM issues AS OF 'HEAD' WHERE id = ?", id).Scan(&count); err != nil { + t.Fatalf("count %s at HEAD: %v", id, err) + } + if count != 1 { + t.Errorf("issue %s at HEAD: count = %d, want 1", id, count) + } + } + var dirty string + if err := db.QueryRowContext(t.Context(), "SELECT COALESCE(GROUP_CONCAT(table_name), '') FROM dolt_status").Scan(&dirty); err != nil { + t.Fatalf("query dolt_status: %v", err) + } + if dirty != "" { + t.Errorf("uncommitted tables in the working set: %s", dirty) + } +} + func assertDepExistsWithType(t *testing.T, beadsDir, database, issueID, dependsOnID, expectedType string) { t.Helper() dataDir := filepath.Join(beadsDir, "embeddeddolt") @@ -990,6 +1017,7 @@ func TestEmbeddedCreateCrossRepo(t *testing.T) { // Verify issue exists in the TARGET store, not the source targetBeadsDir := filepath.Join(targetDir, ".beads") + assertCommittedAtHead(t, targetBeadsDir, "tgt", issue.ID) tgtStore := openStore(t, targetBeadsDir, "tgt") got, err := tgtStore.GetIssue(t.Context(), issue.ID) if err != nil { @@ -1044,6 +1072,7 @@ func TestEmbeddedCreateCrossRepoWithParent(t *testing.T) { // Verify parent-child dependency exists in the target store targetBeadsDir := filepath.Join(targetDir, ".beads") assertDepExists(t, targetBeadsDir, "tgt", child.ID, parent.ID) + assertCommittedAtHead(t, targetBeadsDir, "tgt", parent.ID, child.ID) } func TestEmbeddedCreateDryRunRepoDoesNotInitializeTarget(t *testing.T) { diff --git a/cmd/bd/dolt_autocommit_server_test.go b/cmd/bd/dolt_autocommit_server_test.go index 9476f5e46..ec55534c1 100644 --- a/cmd/bd/dolt_autocommit_server_test.go +++ b/cmd/bd/dolt_autocommit_server_test.go @@ -149,6 +149,38 @@ func TestCommitPendingIfEmbeddedPropagatesEmbeddedError(t *testing.T) { } } +func TestFlushRoutedCreateWarnsOnCommitFailure(t *testing.T) { + for _, tc := range []struct { + name string + err error + want string + }{ + {name: "commit succeeds", want: ""}, + { + name: "commit fails", + err: errors.New("commit failed"), + want: "Warning: created tgt-1, but the follow-up Dolt commit in ../planning failed: commit failed\n", + }, + } { + t.Run(tc.name, func(t *testing.T) { + saveStorageMode(t) + serverMode = false + proxiedServerMode = false + + fake := &fakeCommitPendingStore{err: tc.err} + got := captureStderr(t, func() { + flushRoutedCreate(context.Background(), fake, "../planning", "tgt-1") + }) + if fake.commitCalls != 1 { + t.Fatalf("Commit calls = %d, want 1", fake.commitCalls) + } + if got != tc.want { + t.Fatalf("stderr = %q, want %q", got, tc.want) + } + }) + } +} + func TestShouldCommitCreatePostWritesSkipsServerMode(t *testing.T) { saveStorageMode(t) serverMode = true