Fix stress test polluting project database

The TestStressNoUniqueConstraintViolations test was creating 1000 test
issues in the project's real database instead of its temp database.

Root cause: The RPC client automatically sets req.Cwd to os.Getwd() when
not explicitly provided. The server's getStorageForRequest() then uses
findDatabaseForCwd() to locate and open the database for that working
directory. Since the test ran from the project directory, it discovered
and used .beads/bd.db instead of the temp database.

Fix: Change working directory to the temp directory before running the
test, so the client's automatic Cwd detection points to the temp .beads/
directory instead of the project's.

Also ensures .beads subdirectory exists in temp dir for proper discovery.
This commit is contained in:
Steve Yegge
2025-10-21 22:17:15 -07:00
parent 5ab0f996b9
commit 16f53c99a2
2 changed files with 66 additions and 47 deletions

View File

@@ -305,14 +305,33 @@ func TestStressTimeouts(t *testing.T) {
// TestStressNoUniqueConstraintViolations verifies no ID collisions
func TestStressNoUniqueConstraintViolations(t *testing.T) {
// Save current directory and change to temp dir to prevent client from using project database
origWd, err := os.Getwd()
if err != nil {
t.Fatalf("Failed to get working directory: %v", err)
}
tmpDir, err := os.MkdirTemp("", "bd-stress-unique-*")
if err != nil {
t.Fatalf("Failed to create temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
// Change to temp dir so client.ExecuteWithCwd uses THIS directory, not project directory
if err := os.Chdir(tmpDir); err != nil {
t.Fatalf("Failed to change directory: %v", err)
}
defer os.Chdir(origWd)
dbPath := filepath.Join(tmpDir, "test.db")
socketPath := filepath.Join(tmpDir, "bd.sock")
// Create .beads subdirectory so findDatabaseForCwd finds THIS database, not project's
beadsDir := filepath.Join(tmpDir, ".beads")
if err := os.MkdirAll(beadsDir, 0755); err != nil {
os.RemoveAll(tmpDir)
t.Fatalf("Failed to create .beads dir: %v", err)
}
dbPath := filepath.Join(beadsDir, "test.db")
socketPath := filepath.Join(beadsDir, "bd.sock")
store, err := sqlitestorage.New(dbPath)
if err != nil {