fix: make tests resilient to project .beads/redirect

Tests were failing because beads.FindDatabasePath() follows the
project's .beads/redirect file, causing tests to find unexpected
databases. Fixed by:

- Setting BEADS_DIR in tests that need isolation from git repo detection
- Clearing BEADS_DIR in TestMain to prevent global contamination
- Updating migration test schema to include owner column

This ensures tests work correctly in crew directories that have
redirect files pointing to shared .beads directories.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Executed-By: beads/crew/dave
Rig: beads
Role: crew
This commit is contained in:
beads/crew/dave
2026-01-10 20:39:55 -08:00
committed by Steve Yegge
parent f79e636000
commit ac24a63187
6 changed files with 92 additions and 16 deletions

View File

@@ -454,6 +454,7 @@ func TestMigrateContentHashColumn(t *testing.T) {
}
// Drop the column to simulate fresh migration
// Note: Schema must include owner column for GetIssue to work
_, err = s.db.Exec(`
CREATE TABLE issues_backup AS SELECT * FROM issues;
DROP TABLE issues;
@@ -471,8 +472,10 @@ func TestMigrateContentHashColumn(t *testing.T) {
estimated_minutes INTEGER,
created_at DATETIME NOT NULL,
created_by TEXT DEFAULT '',
owner TEXT DEFAULT '',
updated_at DATETIME NOT NULL,
closed_at DATETIME,
closed_by_session TEXT DEFAULT '',
external_ref TEXT,
compaction_level INTEGER DEFAULT 0,
compacted_at DATETIME,
@@ -488,10 +491,6 @@ func TestMigrateContentHashColumn(t *testing.T) {
ephemeral INTEGER DEFAULT 0,
pinned INTEGER DEFAULT 0,
is_template INTEGER DEFAULT 0,
replies_to TEXT DEFAULT '',
relates_to TEXT DEFAULT '',
duplicate_of TEXT DEFAULT '',
superseded_by TEXT DEFAULT '',
await_type TEXT DEFAULT '',
await_id TEXT DEFAULT '',
timeout_ns INTEGER DEFAULT 0,
@@ -511,7 +510,7 @@ func TestMigrateContentHashColumn(t *testing.T) {
defer_until DATETIME,
CHECK ((status = 'closed') = (closed_at IS NOT NULL))
);
INSERT INTO issues SELECT id, title, description, design, acceptance_criteria, notes, status, priority, issue_type, assignee, estimated_minutes, created_at, '', updated_at, closed_at, external_ref, compaction_level, compacted_at, original_size, compacted_at_commit, source_repo, '', NULL, '', '', '', '', 0, 0, 0, '', '', '', '', '', '', 0, '', '', '', '', NULL, '', '', '', '', '', '', '', NULL, NULL FROM issues_backup;
INSERT INTO issues SELECT id, title, description, design, acceptance_criteria, notes, status, priority, issue_type, assignee, estimated_minutes, created_at, '', '', updated_at, closed_at, '', external_ref, compaction_level, compacted_at, original_size, compacted_at_commit, source_repo, '', NULL, '', '', '', '', 0, 0, 0, '', '', 0, '', '', '', '', NULL, '', '', '', '', '', '', '', NULL, NULL FROM issues_backup;
DROP TABLE issues_backup;
`)
if err != nil {