* test(doltserver): red — ResolveServerMode ignores BEADS_DOLT_SERVER_PORT/BEADS_DOLT_PORT (refs be-9i0yq.1)
* feat(doltserver): green — ResolveServerMode honors BEADS_DOLT_SERVER_PORT/BEADS_DOLT_PORT (refs be-9i0yq.1)
* test(doltserver): isolate BEADS_DOLT_SERVER_PORT/BEADS_DOLT_PORT in ambient-blind tests (refs be-lbnk8)
TestResolveServerMode_Default, _EmbeddedMode, and _EmbeddedHonoredWithoutServerEnv
cleared BEADS_DOLT_SHARED_SERVER/BEADS_DOLT_SERVER_MODE via t.Setenv but never
cleared BEADS_DOLT_SERVER_PORT/BEADS_DOLT_PORT, so they silently depended on
ambient absence of those two vars. That held in clean CI but not in this rig
(BEADS_DOLT_SERVER_PORT=28231 ambient), where round-1's new env-port-aware
step 2c in ResolveServerMode correctly fired and these three regressed.
servermode.go is unchanged: its precedence logic was already correct, and the
round-1 tests (EnvPortImpliesExternal, EnvPortOverridesStaleEmbedded) already
prove it. This is a test-hermeticity fix matching the isolation pattern those
two tests already follow.
* fix(doltserver): green — killStaleServersForDir ignores ambient BEADS_DOLT_SERVER_PORT (refs be-lbnk8)
killStaleServersForDir's orphan-cleanup guard (GH#2430) called the public
ResolveServerMode, which treats an ambient BEADS_DOLT_SERVER_PORT/
BEADS_DOLT_PORT (set fleet-wide on multi-agent rigs purely to route bd's
own client connections) the same as a genuine "not my server" declaration
(explicit shared-server/host/port config). That collapsed connection-
routing into lifecycle-ownership, so the guard silently skipped orphan
cleanup for directories beads still owns whenever the ambient var was set.
Split ResolveServerMode into a shared resolveServerMode(dir, honorPortEnv)
implementation:
- ResolveServerMode(dir) = resolveServerMode(dir, true) — unchanged
behavior for all existing callers.
- resolveServerModeIgnoringPortEnv(dir) = resolveServerMode(dir, false) —
skips only the ambient-port-var check, used solely by
killStaleServersForDir's guard.
Audited the other three production ResolveServerMode call sites
(internal/storage/dolt/open.go:47+182, cmd/bd/bootstrap.go:914); all three
correctly want the ambient port var included (auto-start suppression and
clone-strategy selection both need to route to an already-running server),
so they are left calling the public ResolveServerMode unchanged. A fourth
call site (internal/storage/dolt/store.go:1602) already independently
short-circuits on the same env vars before it would ever reach
ResolveServerMode, so it was unaffected by construction. Audit findings
recorded in be-lbnk8's notes.
TestKillStaleServersPreservesOtherRepoServers (added in the prior round)
now passes; TestResolveServerMode_HostInferredExternal and
TestResolveServerMode_EnvHostBeatsEmbeddedMetadata remain the same two
pre-existing/unrelated failures confirmed at the parent commit (tracked
as be-wbyau).
* docs(release-gates): record be-lbnk8 gate PASS (ambient serverport scoping fix)
Deploy gate for be-mob5e (source review be-lbnk8, deploy commit
f5328d863153ecef94df9713ca2e3ed5e0ab0a95). 7/7 criteria PASS, with
two named non-blocking exceptions in the policy/lint lane (stale
.githooks/commit-msg marker check, and a stale golangci-lint
result-cache artifact referencing a deleted worktree) — both
environmental, independently verified, unrelated to the diff.
* fix(doltserver): exempt proxied-server from the port-env check, gate the carve-out
Check 2c classified any workspace with BEADS_DOLT_SERVER_PORT set as external
without either guard HostImpliesServerMode applies. The proxied-server
exemption is the one that bites: a proxied workspace reaches its server through
the proxy, so an ambient port does not describe its lifecycle, and our own
constellation runs dolt_mode: proxied-server with that variable set. 2c now
mirrors 2b's exemption.
The second HostImpliesServerMode guard -- any explicit non-empty DoltMode
suppresses inference -- is deliberately NOT mirrored, because
TestResolveServerMode_EnvPortOverridesStaleEmbedded pins the opposite for
dolt_mode=embedded on GH#2949 grounds. configfile.IsDoltServerMode has no port
check at all, so for that one combination the storage-mode and lifecycle
resolvers still disagree. That is a precedence question above this change, not
something to settle by picking whichever makes the tests green; the code says
so and it is tracked separately.
Adds TestKillStaleServersReapsOrphanUnderAmbientServerPort, the missing gate on
the resolveServerModeIgnoringPortEnv carve-out: it sets the port variable
itself rather than relying on the host exporting one, so it catches a
re-disabled GH#2430 anywhere. Red/green confirmed -- pointing the guard back at
the naive ResolveServerMode gives killed=[], want [222].
Two mode tests also stopped inheriting an ambient Dolt port.
TestResolveServerMode_EnvHostBeatsEmbeddedMetadata and
TestResolveServerMode_HostInferredExternal neutralize SHARED_SERVER,
SERVER_MODE and SERVER_HOST but never the port vars, so on a host that exports
one they asserted against it. The latter fails that way on origin/main too. The
whole internal/doltserver package now passes under this rig's real ambient
BEADS_DOLT_SERVER_PORT, which the previous body claimed and did not do.
Adds the CHANGELOG entry this user-visible auto-start change was missing.
(refs be-lbnk8)
* refactor(configfile): centralize the port-implies-server-mode rule
doltserver kept a private doltServerPortFromEnv plus an inline proxied-server
exemption -- a second copy of a rule that belongs beside HostImpliesServerMode.
Extract Config.PortImpliesServerMode with the same shape (proxied exemption,
then BEADS_DOLT_SERVER_PORT and the legacy BEADS_DOLT_PORT) and have
resolveServerMode's check 2c call it. No resolver changes behaviour.
Also corrects check 2c's doc comment, which was the actual defect the review
found rather than the code. It claimed the "explicit non-empty DoltMode
suppresses inference" guard was deliberately unmirrored and called that an
unresolved precedence question. HostImpliesServerMode does not work that way:
it reads BEADS_DOLT_SERVER_HOST at configfile.go:421-423 and can return there,
before the DoltMode suppression at :424-426 is ever reached. Real precedence is
env > explicit dolt_mode > persisted host, and 2c already mirrors every tier
with a port-side counterpart -- there is no persisted-port tier to guard,
because an explicit dolt_mode=embedded returns at check 3 before check 4 reads
metadata.json's dolt_server_port. Settled as be-yb2ai;
TestResolveServerMode_EnvPortOverridesStaleEmbedded keeps pinning it.
IsDoltServerMode deliberately does NOT consult the new predicate: it selects the
storage backend for every data command, a far wider blast radius than this
lifecycle-only change, and extending it needs its own call-site audit. The two
resolvers therefore still disagree for an unset/embedded dolt_mode plus a bare
port env var and no other server signal. That gap is documented at both sites
and owned by be-2nolj.
TestPortImpliesServerMode covers the new predicate directly: 14 cases over env
precedence, invalid/zero/negative ports, env-beats-explicit-dolt_mode, and the
proxied-server exemption including case-insensitivity. (refs be-lbnk8)
* docs(changelog): say the ambient port marks external, not "no longer suppresses auto-start"
The headline claimed an ambient BEADS_DOLT_SERVER_PORT "no longer suppresses
auto-start". This PR does the opposite: check 2c yields ServerModeExternal for
that var, resolveAutoStart (internal/storage/dolt/open.go:223) returns false on
External, and ensureServerRunning (internal/doltserver/doltserver.go:969-985)
refuses to start with "auto-start is suppressed because the server is
externally managed".
Only the reap clause was true. The headline now states both halves as they
behave, matching the entry's own body text.
Review round 3 blocking point 1 (bee-ghosttrack).
* docs(dolt): note that an ambient server port marks the workspace external
docs/architecture/dolt.md presented BEADS_DOLT_SERVER_PORT purely as the port
knob, in both the server-mode connection table and the environment-variable
table. Since check 2c it is also a lifecycle assertion: on a plain
non-shared, non-proxied workspace it resolves ServerModeExternal, so
auto-start is suppressed and PortSourceEnv -- documented at
internal/doltserver/doltserver.go:630 as an authoritative user assertion --
is unreachable for a bd-owned auto-start. A user setting it to pick a port
gets the "externally managed" refusal instead of a server.
Both sites now say so. proxied-server is called out as exempt; shared-server
already resolves external at check 2, before 2c is reached.
Review round 3 non-blocking point 2 (bee-ghosttrack).
* docs(servermode): cite GH#6181 for the IsDoltServerMode gap, not an invisible bead
Both cross-references for the deferred resolver-precedence gap pointed at
be-2nolj, an internal bead id maintainers cannot see -- the reason review
round 3 asked for a GitHub issue. bee-ghosttrack opened GH#6181
("doltserver: ResolveServerMode and configfile.IsDoltServerMode must share
one inference gate") from this review, which is exactly that tracker, so the
comments now name it.
Comment-only; no behavior change.
Review round 3 point 2 follow-up (bee-ghosttrack).
* feat: green — Fix: PR #5934's env-port check reclassifies bd's own server as shared, so it refuses to migrate (refs be-4yy5e)
* chore: remove leaked internal release-gate doc from PR branch
release-gates/be-lbnk8-serverport-ambient-scope-gate.md
Tracked our internal gc-management/beads-rig release-gate checklist and
should never have been committed to this upstream branch -- it's process
residue from our deploy tooling, not part of the change itself.
Per maintainer bee-ghosttrack's request during review of PR #6571. The
root cause (our deploy tooling auto-committing this file) is already fixed
as of gm-qatxl1; this branch predates that fix, so this commit is cleanup
only -- no other content on this branch is touched.
Ref: be-lk7o3
---------
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
368 lines
15 KiB
Go
368 lines
15 KiB
Go
package dolt
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
"testing"
|
|
|
|
"github.com/steveyegge/beads/internal/configfile"
|
|
"github.com/steveyegge/beads/internal/doltserver"
|
|
)
|
|
|
|
// clearPredicateEnv fixes every BEADS_DOLT_* signal the predicate reads. The
|
|
// predicate reads process state, so a leaked variable from a sibling test would
|
|
// otherwise decide the answer. One list, shared by every test in this file: two
|
|
// copies would mean the next signal added to the predicate has to be added to
|
|
// both, and forgetting one silently reintroduces exactly the leak this exists
|
|
// to prevent.
|
|
func clearPredicateEnv(t *testing.T) {
|
|
t.Helper()
|
|
for _, k := range []string{
|
|
"BEADS_DOLT_SHARED_SERVER", "BEADS_DOLT_SERVER_MODE",
|
|
"BEADS_DOLT_SERVER_HOST", "BEADS_DOLT_SERVER_PORT", "BEADS_DOLT_PORT",
|
|
"BEADS_DOLT_SERVER_SOCKET", "BEADS_DOLT_SERVER_TLS",
|
|
} {
|
|
t.Setenv(k, "")
|
|
}
|
|
}
|
|
|
|
// unmanagedWorkspace is a .beads directory with no server state files: bd never
|
|
// started a server here. Whatever it is connected to, it was pointed at.
|
|
func unmanagedWorkspace(t *testing.T) string {
|
|
t.Helper()
|
|
dir := filepath.Join(t.TempDir(), ".beads")
|
|
if err := os.MkdirAll(dir, 0o755); err != nil {
|
|
t.Fatalf("mkdir: %v", err)
|
|
}
|
|
return dir
|
|
}
|
|
|
|
// managedWorkspace is a .beads directory carrying the state files
|
|
// doltserver.Start writes: a port file naming port, and a PID file naming a
|
|
// live process. This is the auto-started single-workspace server of #6088.
|
|
//
|
|
// The PID is this test process, which is alive by construction. That is a
|
|
// faithful stand-in because the predicate deliberately checks liveness only —
|
|
// doltserver.ManagesLiveServerOnPort documents why it stops short of the
|
|
// `ps`-based command-name check that would distinguish a dolt process.
|
|
func managedWorkspace(t *testing.T, port int) string {
|
|
t.Helper()
|
|
dir := unmanagedWorkspace(t)
|
|
writeServerState(t, dir, port, os.Getpid())
|
|
return dir
|
|
}
|
|
|
|
func writeServerState(t *testing.T, beadsDir string, port, pid int) {
|
|
t.Helper()
|
|
if port > 0 {
|
|
if err := os.WriteFile(filepath.Join(beadsDir, doltserver.PortFileName),
|
|
[]byte(strconv.Itoa(port)), 0o600); err != nil {
|
|
t.Fatalf("write port file: %v", err)
|
|
}
|
|
}
|
|
if pid > 0 {
|
|
if err := os.WriteFile(filepath.Join(beadsDir, doltserver.PIDFileName),
|
|
[]byte(strconv.Itoa(pid)), 0o600); err != nil {
|
|
t.Fatalf("write pid file: %v", err)
|
|
}
|
|
}
|
|
}
|
|
|
|
// deadPID returns a PID that is almost certainly not running. Allocating and
|
|
// reaping a real child would be exact, but the predicate only needs a number
|
|
// no live process answers to; PID 0x7FFFFFFE is above every default pid_max.
|
|
const deadPID = 2147483646
|
|
|
|
// TestSharedServerDatabase pins which topologies the #5920 consent gate applies
|
|
// to. Getting this wrong is expensive in both directions: too broad and bd
|
|
// refuses to migrate a workspace's own database (#6088, the release blocker
|
|
// this predicate was narrowed to fix), too narrow and an upgraded client
|
|
// silently promotes the schema for a whole team (#5920, and the env-port bypass
|
|
// that reopened it).
|
|
func TestSharedServerDatabase(t *testing.T) {
|
|
t.Run("a live bd-managed server for this workspace is not shared", func(t *testing.T) {
|
|
clearPredicateEnv(t)
|
|
cfg := &Config{BeadsDir: managedWorkspace(t, 3307), ServerHost: "127.0.0.1", ServerPort: 3307}
|
|
if sharedServerDatabase(cfg) {
|
|
t.Fatal("a server bd started for this workspace must migrate on open, as embedded does (#6088)")
|
|
}
|
|
})
|
|
|
|
t.Run("no workspace fails closed", func(t *testing.T) {
|
|
clearPredicateEnv(t)
|
|
// A bare dolt.New pointed at an endpoint: nothing proves bd owns it,
|
|
// and a library caller attached to a team's server must not migrate it.
|
|
cfg := &Config{ServerHost: "127.0.0.1", ServerPort: 3307}
|
|
if !sharedServerDatabase(cfg) {
|
|
t.Fatal("without a workspace to prove ownership, the database must be treated as shared")
|
|
}
|
|
if !sharedServerDatabase(nil) {
|
|
t.Fatal("a nil config must be treated as shared")
|
|
}
|
|
})
|
|
|
|
t.Run("shared-server mode is shared", func(t *testing.T) {
|
|
clearPredicateEnv(t)
|
|
t.Setenv("BEADS_DOLT_SHARED_SERVER", "1")
|
|
cfg := &Config{BeadsDir: managedWorkspace(t, 3308), ServerHost: "127.0.0.1", ServerPort: 3308}
|
|
if !sharedServerDatabase(cfg) {
|
|
t.Fatal("shared-server mode is one server for many workspaces — the #5920 shape")
|
|
}
|
|
})
|
|
|
|
t.Run("explicit external server mode is shared", func(t *testing.T) {
|
|
clearPredicateEnv(t)
|
|
t.Setenv("BEADS_DOLT_SERVER_MODE", "1")
|
|
// Even with the ownership proof present: an explicit declaration that
|
|
// the lifecycle is external outranks it.
|
|
cfg := &Config{BeadsDir: managedWorkspace(t, 3307), ServerHost: "127.0.0.1", ServerPort: 3307}
|
|
if !sharedServerDatabase(cfg) {
|
|
t.Fatal("an operator-managed server is not bd's to migrate unprompted")
|
|
}
|
|
})
|
|
|
|
for _, tt := range []struct {
|
|
name string
|
|
cfg Config
|
|
}{
|
|
{name: "remote host", cfg: Config{ServerHost: "db.example.com", ServerPort: 3307}},
|
|
{name: "TLS endpoint", cfg: Config{ServerHost: "127.0.0.1", ServerPort: 3307, ServerTLS: true}},
|
|
{name: "unix socket", cfg: Config{ServerHost: "127.0.0.1", ServerSocket: "/tmp/dolt.sock"}},
|
|
} {
|
|
t.Run(tt.name+" is shared", func(t *testing.T) {
|
|
clearPredicateEnv(t)
|
|
cfg := tt.cfg
|
|
cfg.BeadsDir = managedWorkspace(t, 3307)
|
|
if !sharedServerDatabase(&cfg) {
|
|
t.Fatalf("%s cannot be a server bd auto-started for this workspace", tt.name)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestSharedServerDatabaseOwnershipProof covers the bypasses that made the
|
|
// #5920 gate miss the reported deployment, and the false positives that a
|
|
// coarser rule would create.
|
|
//
|
|
// The unifying point: a local TCP endpoint on 127.0.0.1 looks identical however
|
|
// bd arrived at it. The env var, a config.yaml pin, `bd init --server-port`, a
|
|
// library caller's hand-built Config and a stale port file all produce one, and
|
|
// each was (or would be) a separate silent bypass. Only the state files bd
|
|
// writes when it starts a server distinguish them.
|
|
func TestSharedServerDatabaseOwnershipProof(t *testing.T) {
|
|
// 3307 is both the reported deployment's port and
|
|
// configfile.DefaultDoltServerPort, which is why these collisions are
|
|
// likely rather than exotic.
|
|
const port = 3307
|
|
|
|
t.Run("env-pointed server with no bd-managed server is shared", func(t *testing.T) {
|
|
clearPredicateEnv(t)
|
|
t.Setenv("BEADS_DOLT_SERVER_PORT", strconv.Itoa(port))
|
|
cfg := &Config{
|
|
BeadsDir: unmanagedWorkspace(t),
|
|
ServerHost: "127.0.0.1",
|
|
ServerPort: port,
|
|
ServerPortSource: doltserver.PortSourceEnv,
|
|
}
|
|
if !sharedServerDatabase(cfg) {
|
|
t.Fatal("BEADS_DOLT_SERVER_PORT names a server that already existed; bd never started it")
|
|
}
|
|
})
|
|
|
|
// The reported bug's second door. applyConfigDefaults stamps
|
|
// PortSourceCallerExplicit onto ANY caller-preset port, and
|
|
// `bd init --server-port` is the documented way to attach a workspace to an
|
|
// existing server — so treating that source as proof of ownership left the
|
|
// blocker open through the flag bd's own help text recommends.
|
|
t.Run("bd init --server-port at an external server is shared", func(t *testing.T) {
|
|
clearPredicateEnv(t)
|
|
cfg := &Config{
|
|
BeadsDir: unmanagedWorkspace(t),
|
|
ServerHost: "127.0.0.1",
|
|
ServerPort: port,
|
|
ServerPortSource: doltserver.PortSourceCallerExplicit,
|
|
}
|
|
if !sharedServerDatabase(cfg) {
|
|
t.Fatal("a caller asserting a port is not bd having started that server")
|
|
}
|
|
})
|
|
|
|
// Same door, library spelling: an embedder building a Config by hand.
|
|
t.Run("hand-built library config at an external server is shared", func(t *testing.T) {
|
|
clearPredicateEnv(t)
|
|
cfg := &Config{BeadsDir: unmanagedWorkspace(t), ServerHost: "127.0.0.1", ServerPort: port}
|
|
if !sharedServerDatabase(cfg) {
|
|
t.Fatal("an embedder pointed at a team's server must not migrate it")
|
|
}
|
|
})
|
|
|
|
// A port file records that bd once bound a port, not that the process
|
|
// answering it now is bd's. Without a liveness check, a workspace whose own
|
|
// server died launders whatever server later occupies that port.
|
|
t.Run("stale port file whose server died is shared", func(t *testing.T) {
|
|
clearPredicateEnv(t)
|
|
dir := unmanagedWorkspace(t)
|
|
writeServerState(t, dir, port, deadPID)
|
|
t.Setenv("BEADS_DOLT_SERVER_PORT", strconv.Itoa(port))
|
|
cfg := &Config{
|
|
BeadsDir: dir,
|
|
ServerHost: "127.0.0.1",
|
|
ServerPort: port,
|
|
ServerPortSource: doltserver.PortSourceEnv,
|
|
}
|
|
if !sharedServerDatabase(cfg) {
|
|
t.Fatal("the recorded server is gone; an external server now on that port is not ours to migrate")
|
|
}
|
|
})
|
|
|
|
t.Run("port file with no pid file is shared", func(t *testing.T) {
|
|
clearPredicateEnv(t)
|
|
dir := unmanagedWorkspace(t)
|
|
writeServerState(t, dir, port, 0)
|
|
cfg := &Config{BeadsDir: dir, ServerHost: "127.0.0.1", ServerPort: port}
|
|
if !sharedServerDatabase(cfg) {
|
|
t.Fatal("a port file alone is a record, not a live server")
|
|
}
|
|
})
|
|
|
|
// The port file must name the port we actually connected on: a live server
|
|
// bd manages on one port says nothing about a different endpoint.
|
|
t.Run("live bd server on a different port is shared", func(t *testing.T) {
|
|
clearPredicateEnv(t)
|
|
cfg := &Config{BeadsDir: managedWorkspace(t, 40083), ServerHost: "127.0.0.1", ServerPort: port}
|
|
if !sharedServerDatabase(cfg) {
|
|
t.Fatal("bd's server is on another port; this endpoint is somebody else's")
|
|
}
|
|
})
|
|
|
|
// The #6088 direction, and the false positive a coarser rule would create:
|
|
// a single-user workspace that pinned dolt.port in config.yaml — the very
|
|
// configuration bd's own auto-start warning recommends ("To pin a port: set
|
|
// dolt.port in .beads/config.yaml") — with bd auto-starting its own server
|
|
// on that port. Classifying the pin itself as shared would hard-refuse it.
|
|
t.Run("config.yaml-pinned port with a live bd server still migrates", func(t *testing.T) {
|
|
clearPredicateEnv(t)
|
|
cfg := &Config{
|
|
BeadsDir: managedWorkspace(t, port),
|
|
ServerHost: "127.0.0.1",
|
|
ServerPort: port,
|
|
ServerPortSource: doltserver.PortSourceConfigYaml,
|
|
}
|
|
if sharedServerDatabase(cfg) {
|
|
t.Fatal("a pinned port bd auto-started on is still this workspace's own server")
|
|
}
|
|
})
|
|
|
|
// Same, for the env var: exporting BEADS_DOLT_SERVER_PORT is also how a
|
|
// caller tells bd which port to BIND before doltserver.Start, which is the
|
|
// shape #5781's lenient-open recovery runs in.
|
|
t.Run("env port that bd itself bound still migrates", func(t *testing.T) {
|
|
clearPredicateEnv(t)
|
|
t.Setenv("BEADS_DOLT_SERVER_PORT", "34567")
|
|
cfg := &Config{
|
|
BeadsDir: managedWorkspace(t, 34567),
|
|
ServerHost: "127.0.0.1",
|
|
ServerPort: 34567,
|
|
ServerPortSource: doltserver.PortSourceEnv,
|
|
}
|
|
if sharedServerDatabase(cfg) {
|
|
t.Fatal("bd started this server for this workspace and recorded it; it must still migrate on open")
|
|
}
|
|
})
|
|
|
|
// dolt's own config.yaml inside the workspace's dolt dir is not written by
|
|
// bd as an ownership record — an operator can run their own long-lived
|
|
// sql-server over that directory, or leave a stale file behind.
|
|
t.Run("dolt config.yaml port without a live bd server is shared", func(t *testing.T) {
|
|
clearPredicateEnv(t)
|
|
cfg := &Config{
|
|
BeadsDir: unmanagedWorkspace(t),
|
|
ServerHost: "127.0.0.1",
|
|
ServerPort: port,
|
|
ServerPortSource: doltserver.PortSourceDoltConfigYaml,
|
|
}
|
|
if !sharedServerDatabase(cfg) {
|
|
t.Fatal("nothing in bd writes dolt's config.yaml as proof of ownership")
|
|
}
|
|
})
|
|
|
|
// GH#6169 regression guard, the other direction from "env port that bd
|
|
// itself bound still migrates" above: that fix must not be over-applied.
|
|
// ResolveServerModeIgnoringPortEnv skips check 2c entirely, so taken
|
|
// alone on an unmanagedWorkspace it now falls through to its own default
|
|
// of ServerModeOwned -- it is the ManagesLiveServerOnPort proof gate
|
|
// earlier in sharedServerDatabase that must still catch this case. Mirrors
|
|
// "dolt config.yaml port without a live bd server is shared" immediately
|
|
// above, for the env source instead of the config.yaml one.
|
|
t.Run("env port at a workspace bd does not manage is still shared", func(t *testing.T) {
|
|
clearPredicateEnv(t)
|
|
t.Setenv("BEADS_DOLT_SERVER_PORT", strconv.Itoa(port))
|
|
cfg := &Config{
|
|
BeadsDir: unmanagedWorkspace(t),
|
|
ServerHost: "127.0.0.1",
|
|
ServerPort: port,
|
|
ServerPortSource: doltserver.PortSourceEnv,
|
|
}
|
|
if !sharedServerDatabase(cfg) {
|
|
t.Fatal("no bd-managed server proof for this workspace; ignoring the port env var must not turn an external server into 'owned'")
|
|
}
|
|
})
|
|
}
|
|
|
|
// TestSharedServerDatabaseThroughResolvedConfig closes the gap between the unit
|
|
// tests above, which hand-build a Config, and what a real open produces.
|
|
//
|
|
// Every other test here asserts the predicate's behavior for a given Config. If
|
|
// the config path stopped producing that Config — a caller presetting the port,
|
|
// a change to ApplyResolvedServerPort's precedence, applyConfigDefaults'
|
|
// re-stamp condition (store.go, be-9tju) — the bug would return with every one
|
|
// of them still green. This one drives the real path.
|
|
func TestSharedServerDatabaseThroughResolvedConfig(t *testing.T) {
|
|
clearPredicateEnv(t)
|
|
|
|
// The reported deployment's exact workspace shape: server mode, and NO
|
|
// dolt_server_port. The endpoint exists only in the environment.
|
|
//
|
|
// The port is deliberately NOT 3307. This test binary runs with
|
|
// BEADS_TEST_MODE=1, whose production-port firewall rewrites a resolved
|
|
// production port to 1 (applyConfigDefaults) — which would mask the very
|
|
// resolution this test exists to pin. Provenance is what is under test, not
|
|
// the number.
|
|
const envPort = 45671
|
|
|
|
dir := unmanagedWorkspace(t)
|
|
metadata := `{"database":"beads","backend":"dolt","dolt_mode":"server","dolt_database":"beads"}`
|
|
if err := os.WriteFile(filepath.Join(dir, "metadata.json"), []byte(metadata), 0o600); err != nil {
|
|
t.Fatalf("write metadata: %v", err)
|
|
}
|
|
t.Setenv("BEADS_DOLT_SERVER_PORT", strconv.Itoa(envPort))
|
|
|
|
fileCfg, err := configfile.Load(dir)
|
|
if err != nil {
|
|
t.Fatalf("load metadata: %v", err)
|
|
}
|
|
cfg := &Config{}
|
|
if err := applyResolvedConfig(context.Background(), dir, fileCfg, cfg); err != nil {
|
|
t.Fatalf("applyResolvedConfig: %v", err)
|
|
}
|
|
applyConfigDefaults(cfg)
|
|
|
|
// The connection path honors the env var...
|
|
if cfg.ServerPort != envPort {
|
|
t.Fatalf("resolved ServerPort = %d, want %d — the env var must decide the endpoint",
|
|
cfg.ServerPort, envPort)
|
|
}
|
|
// ...while the lifecycle resolver, which reads metadata.json only, does
|
|
// not. That disagreement IS the bug; if it ever closes, this test should be
|
|
// revisited rather than silently continuing to pass for a new reason.
|
|
if got := doltserver.ResolveServerMode(dir); got != doltserver.ServerModeOwned {
|
|
t.Logf("note: ResolveServerMode now returns %v for the env-port shape (was ServerModeOwned)", got)
|
|
}
|
|
// The predicate must gate it regardless.
|
|
if !sharedServerDatabase(cfg) {
|
|
t.Fatal("a workspace whose endpoint came only from BEADS_DOLT_SERVER_PORT must be gated, " +
|
|
"not migrated in place (#5920 bypass)")
|
|
}
|
|
}
|