beads/cmd/bd/dolt_commit_proxied_server_test.go
Vishnu J edb86e3470
fix: honor dolt.auto-commit in proxied server mode (#6499)
* fix(dolt): honor dolt.auto-commit=batch/off on the proxied-server write path (#4995)

In proxied-server mode every write minted a Dolt history commit whatever
dolt.auto-commit said. Two causes:

- cmd/bd/main.go never applied issueOpsContext(rootCtx) in the
  proxiedServerMode branch of the root pre-run, so the context carried no
  deferred-commit marker.
- internal/storage/uow/doltserver_tx.go: doltServerTx.Commit ignored
  issueops.VersionCommitDeferred(ctx) and ran CALL DOLT_COMMIT('-Am', ?)
  whenever a message was supplied.

Apply issueOpsContext to rootCtx in the proxied setup, and have
doltServerTx.Commit blank its message under a deferred context so the existing
plain-COMMIT branch persists the write to the working set without advancing
Dolt history. dolt.auto-commit=on is unchanged.

This commit alone strands batch/off writes in the working set; the explicit
flush point (`bd dolt commit`) follows in the later commits of this series.

(Originally recorded as "witness: salvage uncommitted work (ocb-ani)"; the
change itself is unmodified.)

* test(uow,cmd/bd): add regression tests for proxied dolt.auto-commit batch/off (#4995)

Add focused regression tests verifying that proxied dolt.auto-commit batch/off
defer Dolt version commits:
- cmd/bd: TestIssueOpsContextDefersByModeInProxiedServerMode verifies that
  issueOpsContext defers version commits in proxied-server mode when
  dolt.auto-commit is batch or off.
- internal/storage/uow: TestDoltServerTxCommitDefersDoltCommitUnderDeferredContext
  and TestDoltServerTxRunTxWithDeferredContextSkipsDoltCommit verify that
  doltServerTx.Commit blanks the commit message under a deferred context,
  bypassing DOLT_COMMIT and status checks, and executing plain COMMIT to
  persist writes into the working set without advancing Dolt history.

* fix(dolt): add the proxied flush point dolt.auto-commit=batch/off defers to (#4995)

The deferral half of this PR makes dolt.auto-commit=batch/off actually take
effect on the proxied-server write path. On its own that turns batch/off into
"never commit": proxied mode returns from the root pre-run before newDoltStore
runs, so getStore() is nil and `bd dolt commit` has no store to commit
through. Writes pile up in the sql-server working set where `dolt log`,
`dolt push` and backups never see them.

Add the missing half. cmd/bd/dolt_commit_proxied_server.go is the proxied dual
of `bd dolt commit`: it takes the uow.MaintenanceProvider route (RunNonTx) and
runs CALL DOLT_COMMIT('-Am', ?) on a pinned connection, gated on
issueops.HasPendingChanges. It deliberately does not go through
doltServerTx.Commit, which blanks its own message under the deferred context;
routing the flush through the deferral it exists to discharge would make the
flush a no-op. doltCommitCmd dispatches to it on usesProxiedServer(); the
message is built before the branch so both routes name the same default, and
the "Committed." / "Nothing to commit." contract is unchanged.

--dolt-auto-commit's help no longer claims proxied-server routes are
unaffected: it names the proxied flush point and keeps the SIGTERM/SIGHUP
flush marked embedded-only. docs/reference/configuration.md says the same.
`bd vc commit`'s proxied refusal now points at `bd dolt commit`.

Tests:
- cmd/bd/dolt_commit_proxied_integration_test.go: three batch writes leave
  dolt_log unchanged and stay readable, `bd dolt commit` advances it by
  exactly one, a second `bd dolt commit` reports "Nothing to commit." with
  dolt_log unchanged, and one write under --dolt-auto-commit on advances it
  by one. On the PR's original base it failed at the `bd dolt commit` step
  with "no store available". On current main the front door refuses the
  command before that code is reached, so this test is only green together
  with the next commit, which moves `dolt commit` to supported in the proxy
  capability registry.
- TestIssueOpsContextDefersByModeInProxiedServerMode renamed to
  TestIssueOpsContextDefersByModePolicyTable and the proxiedServerMode
  assignment dropped: issueOpsContext branches only on writesCommitNow(),
  never on the storage mode, so the old name over-promised.
- doltserver_tx_test.go: "bd: update bd-4995" -> "bd: update GH#4995", which
  no longer reads as a bead id.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(proxy): move `dolt commit` from refused to supported in the capability registry

Main's proxy capability registry (added by #6269, 24a9da6cc) declares
`dolt commit` direct-only: it has a "proxy.dolt_commit.unsupported" refusal
in proxyMaintenanceRefusals (cmd/bd/proxy_capability.go) and is classed
HistoryDirectOnly in historyCapabilityMatrix (cmd/bd/history_capability.go).
The front door therefore refuses `bd dolt commit` in proxied-server mode
before dispatch, so the proxied dual added earlier in this series is
unreachable, and dolt.auto-commit=batch/off has no way to flush.

the history/VC front-door contract, and neither the registry, its tests nor
the docs explain why `dolt commit` was listed. Nothing on main implemented
`dolt commit` for the proxied route at the time, which is consistent with the
entry being a statement of what existed rather than a design decision.

This flips a capability main had declared unsupported, deliberately: the
proxied route now has an implementation (runDoltCommitProxiedServer), and
batch/off need it as their flush point (GH#4995).

Declared the same way as the other proxied-supported command,
`dolt remote remove`: HistoryProxySupported in the history matrix, and no row
in proxyMaintenanceRefusals.

Tests follow: history_capability_test.go moves `dolt commit` from the
direct-only assertions and refusal contract to the proxy-supported ones
(including the nested front-door pass-through), and
history_remote_frontdoor_matrix_test.go drops the refusal row and adds a
`dolt commit` pass-through check to TestHistoryRemoteSupportedFrontDoorParity.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* fix(proxy): exempt explicit commit points from the proxied deferral (#4995)

Maintainer review fixup for PR #6499, adopt-pr iterations 1-2.

Major (Contract & Interface Fidelity). The deferral is applied once, to
rootCtx, so it blanketed BOTH commit classes the direct route distinguishes by
which wrapper a verb picks: policy-honoring writes (transactHonoringAutoCommit,
per-verb issueOpsContext) and explicit commit points (transact, which passes
the caller's message whatever the policy says). Under dolt.auto-commit=batch a
proxied `bd batch -m "release batch"` therefore persisted the rows, discarded
the message and minted nothing, while the identical command and config on the
direct route committed it — and batch_proxied_server.go's own contract comment
rejects exactly that ("would persist these writes while silently bypassing
Dolt history"), as does batch.go's "the contract is the same on both backends".

issueops.WithImmediateVersionCommit clears the marker and cmd/bd's
explicitCommitPointContext applies it in the duals whose direct twin calls
transact. Scope is the intersection of the transact call sites with
proxyPermittedPaths: batch, mol bond/pour/squash, mol wisp create, and the
WISP half of mol burn (cook and migrate issues also call transact but are
refused in proxied mode, so they have no dual to exempt). The review sized the
radius at batch + 4 mol verbs; mol wisp create is the same class — its direct
twin reaches cloneSubgraph's transact through spawnMoleculeWithOptions — so it
is exempted with them.

Membership is per commit site, not per command (iteration 2). `bd mol burn` is
two classes on the direct route: wisps go through burnWisps -> transact, while
persistent molecules go through deleteBatch -> issueOpsContext ->
dolt/deleter.go, which returns before DOLT_COMMIT when the context defers.
Exempting the whole command minted one Dolt commit per persistent molecule
under batch/off — on a destructive verb, where the identical direct-route
command defers them all to `bd dolt commit`. runMolBurnProxiedServer now
applies the exemption to the wisp RunTxResult only, and the flag help,
configuration.md and the helper's own radius comment say so.

Minors:

- The flush passes '--author' like DoltStorage.CommitAll, so the one commit
  batch mode keeps is attributed to the bd actor rather than the SQL session
  user (without it dolt_log reads `root <root@localhost>`).
- runDoltCommitProxiedServer calls the shared runProxiedNonTx instead of
  re-implementing its provider checks, so `bd --json dolt commit` keeps the
  JSON error envelope; `dolt commit`'s RunE no longer re-wraps an
  already-reported failure, and runProxiedNonTx's message gains the provider
  %T the open-coded version had.
- The flag help and configuration.md drop two false claims: that the deferral
  covers "every write" in proxied mode (the bd serve plane over the same
  provider never touches rootCtx, so daemon writes still commit per write) and
  that the SIGTERM/SIGHUP flush is "embedded-only" (flushBatchCommitOnShutdown
  gates on an open store, which direct SQL-server mode has; only proxied mode
  lacks one). Both surfaces now name the explicit-commit-point exemption.
- Both user-facing enumerations of that exemption are now derived from the
  explicitCommitPointContext call sites rather than restated (iteration 2):
  they had omitted mol wisp create, listed mol burn wholesale, and implied a
  message-less `bd batch` defers when batch.go synthesizes a default message
  and the dual exempts unconditionally, so every proxied batch commits.
- doltserver_tx.go's ephemeral-form comment names its second entry point —
  RunTx/RunTxResult under a deferred context — where its
  ONLY-dolt_ignored-state rationale stops applying.

Not done: regenerating docs/CLI_REFERENCE.md. Its --dolt-auto-commit drift is
base-preexisting, and the generated CLI docs are built from the release tag
pinned in docs/cli-docs.pin, not from this source, so touching them converts
the drift gate's inherited-drift warn-pass into a failure.

Tests. The uow blanking table gains the immediate-commit arm (tagless, so it
runs in every lane); the proxied integration test gains an explicit-batch-commit
step with a deferred plain create as its control, plus the flush attribution
assertions. Mutation-proved: reverting explicitCommitPointContext to a no-op
reds the new step (dolt_log 80 -> 80, no commit minted), and dropping
'--author' reds the attribution assertion with committer=root.

Iteration 2 adds the WIRING pin those left open — the mechanism was covered,
but deleting `ctx = explicitCommitPointContext(ctx)` from a dual was green in
every lane, which is why the mol burn over-application above was invisible.
dolt_autocommit_exemption_wiring_test.go is tagless and needs no server: a
uow.UnitOfWorkProvider that records the context RunTxResult hands NewUOW and
then refuses observes exactly the context each dual gives its transaction.
Mutation-proved per arm: neutering the exemption at batch/bond/squash reds
those three rows and only those; dropping it from the wisp RunTxResult reds
the wisp arm alone; and restoring the command-wide reassignment reds the
persistent arm alone, reproducing the defect this iteration fixes.

Validation: go build ./..., go vet (cgo and CGO_ENABLED=0), gofmt clean;
internal/storage/issueops; internal/storage/uow -run TestDoltServerTx; the
cmd/bd registry / history / policy / batch / mol / wisp / errors battery; and
the gated real-server lane BEADS_TEST_PROXIED_SERVER=1 green for both
TestProxiedServerBatchDefersThenDoltCommitAdvancesHeadOnce (41s) and
TestProxiedServerMolBurn (33s, all four subtests including the mixed
wisp+persistent burn this iteration changed).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
2026-09-27 01:31:11 -07:00

29 lines
1.3 KiB
Go

package main
import "testing"
// TestRenderDoltCommitAuthor pins the '--author' argument the proxied flush
// passes to DOLT_COMMIT (GH#4995). Dolt parses the git "Name <email>" grammar
// and rejects anything else, and the name half is an actor string the caller
// controls, so a stray bracket or newline must be stripped rather than turned
// into a failed flush — the flush is the only commit batch mode keeps.
func TestRenderDoltCommitAuthor(t *testing.T) {
for _, tc := range []struct {
name string
actor string
email string
want string
}{
{name: "actor and email", actor: "agent-7", email: "agent7@example.com", want: "agent-7 <agent7@example.com>"},
{name: "trims surrounding space", actor: " agent-7 ", email: " agent7@example.com\n", want: "agent-7 <agent7@example.com>"},
{name: "strips brackets the grammar owns", actor: "agent <7>", email: "a@b", want: "agent 7 <a@b>"},
{name: "strips embedded newline", actor: "agent\n7", email: "a@b", want: "agent 7 <a@b>"},
{name: "defaults an empty identity", actor: "", email: "", want: "beads <beads@localhost>"},
} {
t.Run(tc.name, func(t *testing.T) {
if got := renderDoltCommitAuthor(tc.actor, tc.email); got != tc.want {
t.Fatalf("renderDoltCommitAuthor(%q, %q) = %q, want %q", tc.actor, tc.email, got, tc.want)
}
})
}
}