`bd prime` failed silent by design when storage was down: a broken or unreachable store made formatMemoriesForPrime return "", so the memory section was simply omitted. An agent that woke with zero recall produced output identical to a workspace that has no memories — same text, same exit 0 — and an operator running a fleet had no instrument that could tell the two apart (gh#5877). Prime already had the right precedent for this: a deadline opening the store renders a visible "Skipped: timed out ..." banner rather than going quiet. This extends that treatment to the three sibling failures that still returned "" — store open failure, the Memories() accessor, and the List() call — via a shared formatPrimeMemoryUnavailable helper carrying the same section shape: Skipped: beads storage unavailable (<error>) — persistent memories were NOT injected this session. Run `bd doctor`; ... The proxied-server route shares the helper, so the two routes cannot drift. The quoted error is reduced to its first line, whitespace collapsed and capped at 160 runes: storage errors carry multi-line hints and prime is injected into a context window. Two cases stay silent, deliberately. A healthy store with zero memories renders nothing, so fresh workspaces get no noise. And a directory with no workspace at all has nothing to inject and nothing wrong with it — telling those apart needed a typed error, so ensureStoreActiveWithContext now wraps ErrNoBeadsDatabase (message unchanged) and both prime routes match on it with errors.Is instead of on prose. Exit codes are unchanged; prime still never fails a session-start hook. Tests changed: - prime_proxied_integration_test.go's "degrades_silently_when_plane_ unavailable" asserted the empty-memories fallback for a corrupted proxied sidecar; that assertion IS the bug. Renamed to "reports_when_plane_unavailable" and it now asserts the banner and the absence of "No memories stored" (still cgo + shared-proxied-server gated, so not run here). - stubPrimeStoreUnavailable, the helper eight prime tests use to detach from an ambient workspace, now reports ErrNoBeadsDatabase. Any other error would render the new banner into all of their output, and whether it did would depend on the runner's ancestor directories.
114 lines
4.7 KiB
Go
114 lines
4.7 KiB
Go
//go:build cgo
|
|
|
|
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/steveyegge/beads/internal/configfile"
|
|
)
|
|
|
|
// TestProxiedServerPrime covers the bd-mm8wf seam from lion's #5361 review:
|
|
// `bd prime` sits in noDbCommands, so formatMemoriesForPrime lazily
|
|
// initialized storage via ensureStoreActiveForPrime — a direct-store open
|
|
// (the bd-m7zzd seam class) that in proxied mode the store factory refuses,
|
|
// which the silent-skip contract then swallowed: proxied prime never carried
|
|
// memories at all. The memory read now rides the proxied plane (one
|
|
// read-only UOW, ConfigUseCase().GetAllConfig), so proxied prime has parity
|
|
// with classic when the server is reachable and still degrades silently when
|
|
// it is not.
|
|
func TestProxiedServerPrime(t *testing.T) {
|
|
requireSharedProxiedServer(t)
|
|
t.Parallel()
|
|
bd := buildEmbeddedBD(t)
|
|
|
|
// A lazy direct open in this workspace would materialize an embedded
|
|
// store directory; the proxied plane never does.
|
|
assertNoEmbeddedStore := func(t *testing.T, p proxiedProject) {
|
|
t.Helper()
|
|
embeddedDir := filepath.Join(p.beadsDir, "embeddeddolt")
|
|
if _, err := os.Stat(embeddedDir); !os.IsNotExist(err) {
|
|
t.Errorf("expected no embedded store at %s after bd prime (direct-store seam), stat err=%v", embeddedDir, err)
|
|
}
|
|
}
|
|
|
|
t.Run("memories_only_injects_via_proxied_plane", func(t *testing.T) {
|
|
t.Parallel()
|
|
p := newSharedProxiedProject(t, bd, "ppr1")
|
|
content := "proxied prime memories ride the uow plane"
|
|
out := bdProxiedMem(t, bd, p.dir, "remember", content, "--key", "proxied-prime-seam")
|
|
if !strings.Contains(out, "Remembered [proxied-prime-seam]") {
|
|
t.Fatalf("expected 'Remembered [proxied-prime-seam]', got: %s", out)
|
|
}
|
|
|
|
db := openProxiedDB(t, p)
|
|
head := readDoltHead(t, db)
|
|
|
|
out = bdProxiedMem(t, bd, p.dir, "prime", "--memories-only")
|
|
if !strings.Contains(out, "## Persistent Memories") {
|
|
t.Errorf("expected Persistent Memories section in proxied prime output, got: %s", out)
|
|
}
|
|
if !strings.Contains(out, "proxied-prime-seam") || !strings.Contains(out, content) {
|
|
t.Errorf("expected memory key and content in proxied prime output, got: %s", out)
|
|
}
|
|
|
|
// The read is read-only on the proxied plane: no Dolt commit landed.
|
|
if n := readDoltLogCountSince(t, db, head); n != 0 {
|
|
t.Errorf("expected 0 commits from a prime memory read, got %d", n)
|
|
}
|
|
assertNoEmbeddedStore(t, p)
|
|
})
|
|
|
|
t.Run("full_prime_appends_memories_section", func(t *testing.T) {
|
|
t.Parallel()
|
|
p := newSharedProxiedProject(t, bd, "ppr2")
|
|
bdProxiedMem(t, bd, p.dir, "remember", "full prime carries memories in proxied mode", "--key", "full-prime-check")
|
|
out := bdProxiedMem(t, bd, p.dir, "prime", "--full")
|
|
if !strings.Contains(out, "## Persistent Memories") || !strings.Contains(out, "full-prime-check") {
|
|
t.Errorf("expected memories section with key 'full-prime-check' in full prime output, got: %s", out)
|
|
}
|
|
assertNoEmbeddedStore(t, p)
|
|
})
|
|
|
|
t.Run("no_memories_yields_stored_none_message", func(t *testing.T) {
|
|
t.Parallel()
|
|
p := newSharedProxiedProject(t, bd, "ppr3")
|
|
out := bdProxiedMem(t, bd, p.dir, "prime", "--memories-only")
|
|
if !strings.Contains(out, "No memories stored") {
|
|
t.Errorf("expected 'No memories stored' for empty proxied memory set, got: %s", out)
|
|
}
|
|
})
|
|
|
|
t.Run("reports_when_plane_unavailable", func(t *testing.T) {
|
|
t.Parallel()
|
|
p := newSharedProxiedProject(t, bd, "ppr4")
|
|
content := "this memory must not surface when the plane is down"
|
|
bdProxiedMem(t, bd, p.dir, "remember", content, "--key", "plane-down")
|
|
|
|
// Corrupt the proxied-server sidecar: provider open now fails before
|
|
// touching any server, the deterministic stand-in for an unreachable
|
|
// plane. Prime must still exit 0 and must not fall back to a direct
|
|
// store — but it says so rather than rendering as an empty memory set
|
|
// (gh#5877), which is what made a downed plane indistinguishable from
|
|
// a workspace that simply has no memories.
|
|
sidecar := configfile.ProxiedServerClientInfoPath(p.beadsDir)
|
|
if err := os.WriteFile(sidecar, []byte("not json{"), 0o644); err != nil {
|
|
t.Fatalf("corrupting sidecar %s: %v", sidecar, err)
|
|
}
|
|
|
|
out := bdProxiedMem(t, bd, p.dir, "prime", "--memories-only")
|
|
if strings.Contains(out, content) || strings.Contains(out, "plane-down") {
|
|
t.Errorf("expected memory to be skipped when the proxied plane is unavailable, got: %s", out)
|
|
}
|
|
if !strings.Contains(out, "beads storage unavailable") || !strings.Contains(out, "were NOT injected this session") {
|
|
t.Errorf("expected the storage-unavailable banner when the proxied plane is down, got: %s", out)
|
|
}
|
|
if strings.Contains(out, "No memories stored") {
|
|
t.Errorf("an unreachable plane must not render as an empty memory set, got: %s", out)
|
|
}
|
|
assertNoEmbeddedStore(t, p)
|
|
})
|
|
}
|