beads/cmd/bd/workspace_identity_test.go
beads/crew/elinor 0bb3bf20a0 feat: add workspace identity preflight and bd bootstrap command (GH#2438, GH#2372)
Add validateWorkspaceIdentity() preflight in PersistentPreRun that compares
project_id from metadata.json with _project_id in the database. Blocks writes
on mismatch to prevent cross-project data corruption. Escape hatch:
BEADS_SKIP_IDENTITY_CHECK=1.

Add 'bd bootstrap' command as non-destructive alternative to 'bd init --force'.
Auto-detects recovery action: sync from remote, restore from backup, or create
fresh. Supports --dry-run and --json.

Co-Authored-By: matt wilkie <maphew@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 17:33:34 -07:00

25 lines
669 B
Go

package main
import (
"testing"
)
func TestValidateWorkspaceIdentity_NilStore(t *testing.T) {
// When store is nil, validateWorkspaceIdentity should be a no-op
// (no panic, no os.Exit)
origStore := store
store = nil
defer func() { store = nil; store = origStore }()
validateWorkspaceIdentity(nil, "/nonexistent")
// If we got here, no os.Exit was called — pass
}
func TestValidateWorkspaceIdentity_NonexistentDir(t *testing.T) {
// When beadsDir doesn't exist, configfile.Load fails and we skip validation
origStore := store
store = nil
defer func() { store = origStore }()
validateWorkspaceIdentity(nil, "/nonexistent/path/that/does/not/exist")
}