From c416c7d266442ea91e8e5c2e08bcb22f98fd840c Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Fri, 7 Nov 2025 22:50:55 -0800 Subject: [PATCH] Prevent test pollution in production database (bd-z528) - Add warning when creating issues with 'Test' prefix - Suggest BEADS_DB for isolated testing - Document testing workflow in AGENTS.md - Include examples for manual and automated testing Amp-Thread-ID: https://ampcode.com/threads/T-fc7b7391-8881-4dd9-8e1f-28a2f95afb2b Co-authored-by: Amp --- AGENTS.md | 28 ++++++++++++++++++++++++++++ cmd/bd/create.go | 7 +++++++ 2 files changed, 35 insertions(+) diff --git a/AGENTS.md b/AGENTS.md index fb8437c0..e8f66382 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -609,6 +609,34 @@ beads/ └── *.md # Documentation ``` +### Testing Workflow + +**IMPORTANT:** Never pollute the production database with test issues! + +**For manual testing**, use the `BEADS_DB` environment variable to point to a temporary database: + +```bash +# Create test issues in isolated database +BEADS_DB=/tmp/test.db ./bd init --quiet --prefix test +BEADS_DB=/tmp/test.db ./bd create "Test issue" -p 1 + +# Or for quick testing +BEADS_DB=/tmp/test.db ./bd create "Test feature" -p 1 +``` + +**For automated tests**, use `t.TempDir()` in Go tests: + +```go +func TestMyFeature(t *testing.T) { + tmpDir := t.TempDir() + testDB := filepath.Join(tmpDir, ".beads", "beads.db") + s := newTestStore(t, testDB) + // ... test code +} +``` + +**Warning:** bd will warn you when creating issues with "Test" prefix in the production database. Always use `BEADS_DB` for manual testing. + ### Before Committing 1. **Run tests**: `go test -short ./...` (full tests run in CI) diff --git a/cmd/bd/create.go b/cmd/bd/create.go index 85b9e2ec..d4226e73 100644 --- a/cmd/bd/create.go +++ b/cmd/bd/create.go @@ -57,6 +57,13 @@ var createCmd = &cobra.Command{ os.Exit(1) } + // Warn if creating a test issue in production database + if strings.HasPrefix(strings.ToLower(title), "test") { + yellow := color.New(color.FgYellow).SprintFunc() + fmt.Fprintf(os.Stderr, "%s Creating issue with 'Test' prefix in production database.\n", yellow("⚠")) + fmt.Fprintf(os.Stderr, " For testing, consider using: BEADS_DB=/tmp/test.db ./bd create \"Test issue\"\n") + } + // Load template if specified var tmpl *Template if fromTemplate != "" {