* test(cmd/bd): repair the embedded-gated tests that rotted while no lane ran them These tests skip unless BEADS_TEST_EMBEDDED_DOLT=1 but no CI lane selected them, so they rotted unseen. Running them shows: - TestEventsTailFollowReportsTruncationOnTheStream raced on a plain bytes.Buffer that os/exec's copy goroutine writes while the test polls it. Use the package's syncBuffer. - TestCorruptMetadataDiagnosticsRunAndDataFailsLoud still asserted that doctor and init run on a corrupt metadata.json. #4857 deliberately made every workspace command refuse instead (pinned for doctor by TestDoctorRejectsCorruptMetadataBeforeSharedServerChecks). Rewrite it to the shipped contract as TestEmbeddedCorruptMetadataFailsLoudUntilRestored: version warns, doctor/list/init refuse naming the file without touching it, and restoring the file brings the data back. - dolt_remote_origin_guard_embedded_test.go was tagged `embeddeddolt && cgo`, a tag no lane sets, so it never compiled in CI (gazelle left it out of bd_test srcs). Retag it `cgo`, as #4153 did for its dolt_local_only sibling, and add it to srcs. Drop its four bd doctor git-origin tests: bd doctor runs no checks on an embedded workspace (GH#3794), so two could never pass and two passed vacuously on empty output. Rename the surviving tests into the TestEmbedded* prefix. Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * ci(embedded): run every BEADS_TEST_EMBEDDED_DOLT-gated cmd/bd test in the embedded lane The embedded-Dolt cmd lane selected tests with grep '^func TestEmbedded' cmd/bd/*_embedded_test.go, and only its two Bazel targets set BEADS_TEST_EMBEDDED_DOLT. A test that skips without the variable but missed the name prefix or the file suffix skipped in every lane and reported green: 92 of them, including #7203's --if-revision CLI coverage (TestIfRevisionMatchAndMismatch, TestReassignFenceCLI, ...). - embedded-test-shard.sh and gen_embedded_cmd_shard_manifest.py select TestEmbedded* by name across cmd/bd/*_test.go, as proxied-test-shard.sh does, leaving authors one rule. - Rename the gated tests into the TestEmbedded* prefix (TestDoctorEmbedded<X> -> TestEmbeddedDoctor<X>) and update every reference. - Place the new names with gen_embedded_cmd_shard_manifest.py 100 --weights=duration --write (incremental). - Add TestEmbeddedGatedTestsRunInTheEmbeddedLane: it walks cmd/bd's tests for any that reach os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" and fails if a shard of the lane never lists one. The proxied guard's helpers now take the variable and the script; a fixture test pins the walk. Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
232 lines
7.3 KiB
Go
232 lines
7.3 KiB
Go
//go:build cgo
|
|
|
|
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// Integration tests for be-3v2ou: dolt.local-only enforcement (FR-01 to FR-05).
|
|
//
|
|
// TDD gate tests: these fail before the implementation because the guards
|
|
// don't exist yet. Run with BEADS_TEST_EMBEDDED_DOLT=1.
|
|
|
|
// bdLocalOnlySetup inits a project and enables dolt.local-only=true.
|
|
func bdLocalOnlySetup(t *testing.T, bd string) (dir string) {
|
|
t.Helper()
|
|
dir, _, _ = bdInit(t, bd, "--prefix", "lo")
|
|
bdConfig(t, bd, dir, "set", "dolt.local-only", "true")
|
|
return dir
|
|
}
|
|
|
|
// bdDoltSeparate runs "bd dolt <args>" and returns (stdout, stderr, err)
|
|
// with separate buffers. Used when tests must distinguish stdout from stderr.
|
|
func bdDoltSeparate(t *testing.T, bd, dir string, args ...string) (string, string, error) {
|
|
t.Helper()
|
|
fullArgs := append([]string{"dolt"}, args...)
|
|
cmd := exec.Command(bd, fullArgs...)
|
|
cmd.Dir = dir
|
|
cmd.Env = bdEnv(dir)
|
|
var stdout, stderr bytes.Buffer
|
|
cmd.Stdout = &stdout
|
|
cmd.Stderr = &stderr
|
|
err := cmd.Run()
|
|
return stdout.String(), stderr.String(), err
|
|
}
|
|
|
|
// -- push --
|
|
|
|
func TestEmbeddedDoltLocalOnly_Push_ExitsZeroWithMessage(t *testing.T) {
|
|
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
|
|
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run dolt.local-only embedded tests")
|
|
}
|
|
t.Parallel()
|
|
bd := buildEmbeddedBD(t)
|
|
dir := bdLocalOnlySetup(t, bd)
|
|
|
|
// bdDolt fatals on non-zero exit — this asserts exit 0.
|
|
out := bdDolt(t, bd, dir, "push")
|
|
|
|
for _, want := range []string{
|
|
"Remote sync is disabled for this project (dolt.local-only=true).",
|
|
"bd config unset dolt.local-only",
|
|
} {
|
|
if !strings.Contains(out, want) {
|
|
t.Errorf("push stdout missing %q\ngot:\n%s", want, out)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestEmbeddedDoltLocalOnly_Push_LocalStoreCopy(t *testing.T) {
|
|
// The push no-op message must include the "Your issues are stored locally" line.
|
|
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
|
|
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run dolt.local-only embedded tests")
|
|
}
|
|
t.Parallel()
|
|
bd := buildEmbeddedBD(t)
|
|
dir := bdLocalOnlySetup(t, bd)
|
|
|
|
out := bdDolt(t, bd, dir, "push")
|
|
if !strings.Contains(out, "stored locally") {
|
|
t.Errorf("push no-op missing 'stored locally'\ngot:\n%s", out)
|
|
}
|
|
}
|
|
|
|
func TestEmbeddedDoltLocalOnly_Push_JSON_DisabledStatus(t *testing.T) {
|
|
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
|
|
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run dolt.local-only embedded tests")
|
|
}
|
|
t.Parallel()
|
|
bd := buildEmbeddedBD(t)
|
|
dir := bdLocalOnlySetup(t, bd)
|
|
|
|
out := bdDolt(t, bd, dir, "--json", "push")
|
|
|
|
var got map[string]string
|
|
if err := json.Unmarshal([]byte(strings.TrimSpace(out)), &got); err != nil {
|
|
t.Fatalf("bd dolt --json push: stdout not valid JSON: %v\nout: %s", err, out)
|
|
}
|
|
if got["status"] != "disabled" {
|
|
t.Errorf("JSON[status] = %q, want \"disabled\"", got["status"])
|
|
}
|
|
if got["reason"] != "dolt.local-only=true" {
|
|
t.Errorf("JSON[reason] = %q, want \"dolt.local-only=true\"", got["reason"])
|
|
}
|
|
}
|
|
|
|
// -- pull --
|
|
|
|
func TestEmbeddedDoltLocalOnly_Pull_ExitsZeroWithMessage(t *testing.T) {
|
|
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
|
|
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run dolt.local-only embedded tests")
|
|
}
|
|
t.Parallel()
|
|
bd := buildEmbeddedBD(t)
|
|
dir := bdLocalOnlySetup(t, bd)
|
|
|
|
out := bdDolt(t, bd, dir, "pull")
|
|
|
|
for _, want := range []string{
|
|
"Remote sync is disabled for this project (dolt.local-only=true).",
|
|
"Nothing to pull",
|
|
"bd config unset dolt.local-only",
|
|
} {
|
|
if !strings.Contains(out, want) {
|
|
t.Errorf("pull stdout missing %q\ngot:\n%s", want, out)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestEmbeddedDoltLocalOnly_Pull_JSON_DisabledStatus(t *testing.T) {
|
|
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
|
|
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run dolt.local-only embedded tests")
|
|
}
|
|
t.Parallel()
|
|
bd := buildEmbeddedBD(t)
|
|
dir := bdLocalOnlySetup(t, bd)
|
|
|
|
out := bdDolt(t, bd, dir, "--json", "pull")
|
|
|
|
var got map[string]string
|
|
if err := json.Unmarshal([]byte(strings.TrimSpace(out)), &got); err != nil {
|
|
t.Fatalf("bd dolt --json pull: stdout not valid JSON: %v\nout: %s", err, out)
|
|
}
|
|
if got["status"] != "disabled" {
|
|
t.Errorf("JSON[status] = %q, want \"disabled\"", got["status"])
|
|
}
|
|
if got["reason"] != "dolt.local-only=true" {
|
|
t.Errorf("JSON[reason] = %q, want \"dolt.local-only=true\"", got["reason"])
|
|
}
|
|
}
|
|
|
|
// -- remote add --
|
|
|
|
func TestEmbeddedDoltLocalOnly_RemoteAdd_RefusesExitOne(t *testing.T) {
|
|
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
|
|
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run dolt.local-only embedded tests")
|
|
}
|
|
t.Parallel()
|
|
bd := buildEmbeddedBD(t)
|
|
dir := bdLocalOnlySetup(t, bd)
|
|
|
|
stdout, stderr, err := bdDoltSeparate(t, bd, dir, "remote", "add", "origin", "https://doltremoteapi.dolthub.com/test/repo")
|
|
if err == nil {
|
|
t.Fatalf("bd dolt remote add: expected exit non-zero, but succeeded\nstdout:\n%s", stdout)
|
|
}
|
|
for _, want := range []string{
|
|
"cannot add Dolt remote",
|
|
"dolt.local-only",
|
|
"bd config unset dolt.local-only",
|
|
} {
|
|
if !strings.Contains(strings.ToLower(stderr+stdout), strings.ToLower(want)) {
|
|
t.Errorf("remote-add output missing %q\nstdout: %s\nstderr: %s", want, stdout, stderr)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestEmbeddedDoltLocalOnly_RemoteAdd_ErrorOnStderr(t *testing.T) {
|
|
// The refusal must go to stderr (not stdout) so agents can distinguish errors.
|
|
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
|
|
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run dolt.local-only embedded tests")
|
|
}
|
|
t.Parallel()
|
|
bd := buildEmbeddedBD(t)
|
|
dir := bdLocalOnlySetup(t, bd)
|
|
|
|
stdout, stderr, _ := bdDoltSeparate(t, bd, dir, "remote", "add", "origin", "https://doltremoteapi.dolthub.com/test/repo")
|
|
if !strings.Contains(strings.ToLower(stderr), "disabled") {
|
|
t.Errorf("remote-add refusal not on stderr\nstderr: %s", stderr)
|
|
}
|
|
if strings.Contains(strings.ToLower(stdout), "disabled") {
|
|
t.Errorf("remote-add refusal leaked onto stdout\nstdout: %s", stdout)
|
|
}
|
|
}
|
|
|
|
// -- config round-trip --
|
|
|
|
func TestEmbeddedDoltLocalOnly_ConfigRoundTrip(t *testing.T) {
|
|
// bd config set dolt.local-only true / unset must persist via config.yaml.
|
|
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
|
|
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run dolt.local-only embedded tests")
|
|
}
|
|
t.Parallel()
|
|
bd := buildEmbeddedBD(t)
|
|
dir, _, _ := bdInit(t, bd, "--prefix", "cr")
|
|
|
|
// Set: push becomes a no-op.
|
|
bdConfig(t, bd, dir, "set", "dolt.local-only", "true")
|
|
out := bdDolt(t, bd, dir, "push")
|
|
if !strings.Contains(out, "dolt.local-only=true") {
|
|
t.Errorf("after set: push output = %q, want to mention dolt.local-only=true", out)
|
|
}
|
|
|
|
// Unset: key must be absent from config. bd config get returns "(not set ...)" for missing keys.
|
|
bdConfig(t, bd, dir, "unset", "dolt.local-only")
|
|
val := bdConfig(t, bd, dir, "get", "dolt.local-only")
|
|
if !strings.Contains(val, "not set") {
|
|
t.Errorf("after unset: bd config get dolt.local-only = %q, want 'not set'", val)
|
|
}
|
|
}
|
|
|
|
// -- bd dolt status --
|
|
|
|
func TestEmbeddedDoltLocalOnly_DoltStatus_ShowsDisabled(t *testing.T) {
|
|
// When dolt.local-only=true, bd dolt status must include the indicator line.
|
|
if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" {
|
|
t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run dolt.local-only embedded tests")
|
|
}
|
|
t.Parallel()
|
|
bd := buildEmbeddedBD(t)
|
|
dir := bdLocalOnlySetup(t, bd)
|
|
|
|
out := bdDolt(t, bd, dir, "status")
|
|
want := "Remote sync: disabled (dolt.local-only=true)"
|
|
if !strings.Contains(out, want) {
|
|
t.Errorf("dolt status missing %q\ngot:\n%s", want, out)
|
|
}
|
|
}
|