* fix(uow): tell the truth about why an open could not reach the database
Three things on the server-backed open path claimed to know more than the
server told them.
A failed USE was labeled `database %q not found` no matter what came back,
including the access-denied errors a credential scoped to one database gets
for every other name. The advice that followed ("provision it") is the wrong
remedy for a denial, which needs a grant — and a server hides existence from
an ungranted credential, so bd cannot tell absence from denial and must stop
pretending it can. classifyUseDatabaseError now says denied when the server
said denied, absent when the server said absent, and neither when it said
something else.
A successful USE, and a database named in the MySQL handshake, were both
taken as proof the session was on that database. A front door that scopes
connections by credential can accept a foreign name and serve its own
database anyway; every later unqualified read then belongs to a different
project while bd attributes it to the requested one. assertSessionDatabase
asks SELECT DATABASE() on both pools and refuses the mismatch by name.
A denied CREATE DATABASE surfaced the raw driver error. It now explains that
the server provisions databases itself — with no retry and no fallback.
The new strings name the server administrator, not a product.
* fix(init): honor --init-if-missing on the proxied-server route
The proxied branch returns from init before the --init-if-missing block ever
runs, and runInitProxiedServer does its own already-initialized check — so on
that route the flag did nothing. A scaffold script re-running init got exit 1
and the "Aborting." banner, and the mismatch guards written to protect the
flag had never executed once.
Route the proxied branch's already-initialized error through the same
decision the other route makes: skip benignly, unless an explicit --database
or --prefix disagrees with the existing workspace, in which case refuse and
name the database the workspace is actually on. Skipping there would silently
ignore the request and keep using a different database.
The check runs before any .beads/ write, so the refusal leaves nothing
behind. --reinit-local stays inert on this route; that is a separate gap.
* fix(dolt): assert the gateway put the session on the database bd asked for
The gateway open treats a successful connect as the existence proof and skips
the identity check on purpose. But a connect proves only that the credential
was accepted — a gateway scopes connections by credential, so it can take a
foreign database name in the handshake and serve its own. Every read after
that is unqualified, so bd reads one project's rows believing they belong to
another's database.
On `bd init --database=<other>` there was no error at all: resolveInitIssuePrefix
adopts whatever prefix comes back, so the workspace quietly attached itself to
someone else's project. One SELECT DATABASE() after the ping closes it, and
names both databases so the operator can see what happened.
* test(init): name the proxied init-if-missing test so CI runs it
The proxied-server lane discovers its tests by grepping for
`^func TestProxiedServer` (.github/scripts/proxied-test-shard.sh), so a
proxied integration test named anything else is written, passes locally, and
is never executed on a PR. Renamed; it hash-distributes to shard 12.
* refactor(uow): name the preview USE remedy once instead of twice
* docs(init): correct a stale directional reference in the helper comment
* docs(dolt): the gateway existence proof is now connect-plus-assertion
96 lines
3.7 KiB
Go
96 lines
3.7 KiB
Go
//go:build cgo
|
|
|
|
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestProxiedServerInitIfMissing covers --init-if-missing on the proxied-server
|
|
// route, where it used to be inert: runInitProxiedServer runs its own
|
|
// already-initialized check and returns before init.go's --init-if-missing
|
|
// block, so a scaffold script re-running init got exit 1 and the "Aborting."
|
|
// banner, and the mismatch guards that protect the flag had never run at all.
|
|
func TestProxiedServerInitIfMissing(t *testing.T) {
|
|
requireProxiedServerEnv(t)
|
|
|
|
bd := buildEmbeddedBD(t)
|
|
p := bdProxiedInit(t, bd, "pim")
|
|
|
|
initArgs := func(extra ...string) []string {
|
|
return append([]string{
|
|
"init", "--proxied-server", "--non-interactive", "--skip-agents", "--skip-hooks",
|
|
}, extra...)
|
|
}
|
|
|
|
t.Run("re-init skips benignly", func(t *testing.T) {
|
|
_, stderr, err := bdProxiedRunBuffers(t, bd, p.dir, initArgs("--init-if-missing")...)
|
|
if err != nil {
|
|
t.Fatalf("init --init-if-missing should exit 0 on an initialized workspace: %v\nstderr:\n%s", err, stderr)
|
|
}
|
|
if !strings.Contains(stderr, "Skipping init: workspace already initialized") {
|
|
t.Errorf("expected the benign skip message, got stderr:\n%s", stderr)
|
|
}
|
|
})
|
|
|
|
t.Run("matching prefix skips benignly", func(t *testing.T) {
|
|
_, stderr, err := bdProxiedRunBuffers(t, bd, p.dir, initArgs("--init-if-missing", "--prefix", p.prefix)...)
|
|
if err != nil {
|
|
t.Fatalf("matching --prefix should still skip: %v\nstderr:\n%s", err, stderr)
|
|
}
|
|
if !strings.Contains(stderr, "Skipping init: workspace already initialized") {
|
|
t.Errorf("expected the benign skip message, got stderr:\n%s", stderr)
|
|
}
|
|
})
|
|
|
|
// The multi-project ask. Skipping here would silently ignore --database and
|
|
// keep using the existing one, so it must refuse — and say which database
|
|
// the workspace is actually on.
|
|
t.Run("different database is refused, not skipped", func(t *testing.T) {
|
|
stdout, stderr, err := bdProxiedRunBuffers(t, bd, p.dir, initArgs("--init-if-missing", "--database", "some_other_db")...)
|
|
if err == nil {
|
|
t.Fatalf("mismatched --database must abort; got success\nstdout:\n%s\nstderr:\n%s", stdout, stderr)
|
|
}
|
|
out := stdout + stderr
|
|
for _, want := range []string{
|
|
"workspace already initialized as database " + `"` + p.database + `"`,
|
|
`--database "some_other_db" was requested`,
|
|
} {
|
|
if !strings.Contains(out, want) {
|
|
t.Errorf("abort message missing %q, got:\n%s", want, out)
|
|
}
|
|
}
|
|
if strings.Contains(out, "Skipping init") {
|
|
t.Errorf("a mismatched --database must not be skipped, got:\n%s", out)
|
|
}
|
|
})
|
|
|
|
t.Run("different prefix is refused, not skipped", func(t *testing.T) {
|
|
stdout, stderr, err := bdProxiedRunBuffers(t, bd, p.dir, initArgs("--init-if-missing", "--prefix", "somethingelse")...)
|
|
if err == nil {
|
|
t.Fatalf("mismatched --prefix must abort; got success\nstdout:\n%s\nstderr:\n%s", stdout, stderr)
|
|
}
|
|
out := stdout + stderr
|
|
for _, want := range []string{
|
|
"workspace already initialized as database " + `"` + p.database + `"`,
|
|
`--prefix "somethingelse" was requested`,
|
|
} {
|
|
if !strings.Contains(out, want) {
|
|
t.Errorf("abort message missing %q, got:\n%s", want, out)
|
|
}
|
|
}
|
|
})
|
|
|
|
// Without the flag, the existing refusal is unchanged: --init-if-missing is
|
|
// what makes re-init benign, not this change.
|
|
t.Run("without the flag re-init still aborts", func(t *testing.T) {
|
|
stdout, stderr, err := bdProxiedRunBuffers(t, bd, p.dir, initArgs()...)
|
|
if err == nil {
|
|
t.Fatalf("re-init without --init-if-missing must abort; got success\nstdout:\n%s\nstderr:\n%s", stdout, stderr)
|
|
}
|
|
if out := stdout + stderr; !strings.Contains(out, "already initialized") {
|
|
t.Errorf("expected the existing already-initialized refusal, got:\n%s", out)
|
|
}
|
|
})
|
|
}
|