fix(dolt): green — propagate ServerPortSource so legacy port-env override isn't silently skipped (refs be-9tju)
Two-part fix for the request-changes security blocker on this branch:
1. internal/storage/dolt/open.go applyResolvedConfig: when ServerPort
resolves via doltserver.DefaultConfig(beadsDir)'s fallback chain
(env > port file > config.yaml > metadata), propagate the resolved
.PortSource and .PortSharedServer alongside .Port — mirroring the
pattern store.go's own fallback block already uses. Previously only
.Port was copied, leaving ServerPortSource at its zero value
(PortSourceUnset) even when the port came from an ambient/stored
resolution like the port file.
2. internal/storage/dolt/store.go applyConfigDefaults: widen the legacy
BEADS_DOLT_PORT / BEADS_DOLT_SERVER_PORT env-override gate from
`cfg.ServerPort == 0` to `cfg.ServerPort == 0 ||
!cfg.ServerPortSource.IsAuthoritative()`. Part 1 alone isn't
sufficient: the gate only ever checked whether ServerPort was zero,
independent of whether its source was actually caller-authoritative.
Without both parts, applyConfigDefaults's PortSourceUnset check
(`if cfg.ServerPort != 0 && cfg.ServerPortSource == PortSourceUnset {
cfg.ServerPortSource = PortSourceCallerExplicit }`) mislabeled a
port-file-resolved port as caller-explicit, which then made the legacy
env override a silent no-op for any normal (non-init) bd command
against an already-initialized project — a regression of the hq-27t
bug class, exactly as reported in be-9tju's rejection notes.
A genuinely caller-explicit ServerPort (e.g. bd init --server-port)
still outranks the ambient env var: applyResolvedConfig only stamps
PortSourceCallerExplicit when the caller preset ServerPort before the
call, and IsAuthoritative() is true for that source — covered by the
new "genuinely caller-explicit ... still outranks ambient env" subtest
committed in the RED step (4f4de51618).
Targeted test: go test ./internal/storage/dolt/... -run
TestApplyResolvedConfig -v — all 10 subtests (6 original + 4 new) pass.
Full suite: bash scripts/ci/pr-core.sh succeeded in 345s, zero FAILs,
including both packages that timed out on the prior rejected run
(cmd/bd 288.243s ok, internal/storage/embeddeddolt 255.521s ok) and
both packages this diff touches (internal/doltserver 5.045s ok,
internal/storage/dolt 9.520s ok). Log: /tmp/tdd-green-pr-core.log.
This commit is contained in:
parent
4f4de51618
commit
2dbcbd7f2a
2 changed files with 19 additions and 2 deletions
|
|
@ -251,7 +251,17 @@ func applyResolvedConfig(ctx context.Context, beadsDir string, fileCfg *configfi
|
|||
// Use doltserver.DefaultConfig for port resolution (env > port file >
|
||||
// config.yaml > metadata > DerivePort). fileCfg.GetDoltServerPort()
|
||||
// falls back to 3307 which is wrong for standalone repos.
|
||||
cfg.ServerPort = doltserver.DefaultConfig(beadsDir).Port
|
||||
//
|
||||
// PortSource/PortSharedServer must travel with Port: applyConfigDefaults
|
||||
// infers "caller-explicit" from "ServerPort nonzero, ServerPortSource
|
||||
// unset" (be-wf9a.1), so leaving the source unset here mislabels an
|
||||
// ambient/stored resolution (e.g. the port file) as a deliberate
|
||||
// caller assertion — which then makes the legacy BEADS_DOLT_PORT
|
||||
// env-var override a silent no-op (be-9tju).
|
||||
resolved := doltserver.DefaultConfig(beadsDir)
|
||||
cfg.ServerPort = resolved.Port
|
||||
cfg.ServerPortSource = resolved.PortSource
|
||||
cfg.ServerPortSharedServer = resolved.PortSharedServer
|
||||
}
|
||||
// Resolve the server-mode credential (the connection username). In server mode a
|
||||
// configured credential command takes precedence over the static user; it fails
|
||||
|
|
|
|||
|
|
@ -1436,7 +1436,14 @@ func applyConfigDefaults(cfg *Config) {
|
|||
if envPort == "" {
|
||||
envPort = os.Getenv("BEADS_DOLT_PORT") // legacy fallback
|
||||
}
|
||||
if envPort != "" && cfg.ServerPort == 0 {
|
||||
// Also fires when ServerPort is already nonzero but its source isn't
|
||||
// authoritative (e.g. PortSourcePortFile from applyResolvedConfig's own
|
||||
// doltserver.DefaultConfig fallback above) — bd's own port-file
|
||||
// bookkeeping must not silently outrank an explicit env override
|
||||
// (be-9tju; regression of the hq-27t bug class). A genuinely
|
||||
// caller-explicit ServerPort (PortSourceCallerExplicit, stamped above)
|
||||
// still wins: IsAuthoritative() is true for it.
|
||||
if envPort != "" && (cfg.ServerPort == 0 || !cfg.ServerPortSource.IsAuthoritative()) {
|
||||
if p, err := strconv.Atoi(envPort); err == nil && p > 0 {
|
||||
cfg.ServerPort = p
|
||||
// This env read happens before doltserver.DefaultConfig is
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue