Preserve dependency metadata during import (#141)

This commit is contained in:
Mark Wotton
2025-10-24 14:34:52 +07:00
committed by GitHub
parent e293974c71
commit dd8327ff2b
2 changed files with 54 additions and 4 deletions

View File

@@ -61,8 +61,12 @@ func (s *SQLiteStorage) AddDependency(ctx context.Context, dep *types.Dependency
}
}
dep.CreatedAt = time.Now()
dep.CreatedBy = actor
if dep.CreatedAt.IsZero() {
dep.CreatedAt = time.Now()
}
if dep.CreatedBy == "" {
dep.CreatedBy = actor
}
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
@@ -191,8 +195,12 @@ func (s *SQLiteStorage) addDependencyUnchecked(ctx context.Context, dep *types.D
// NOTE: We skip parent-child direction validation here because during import/remap,
// we're just updating IDs on existing dependencies that were already validated.
dep.CreatedAt = time.Now()
dep.CreatedBy = actor
if dep.CreatedAt.IsZero() {
dep.CreatedAt = time.Now()
}
if dep.CreatedBy == "" {
dep.CreatedBy = actor
}
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"strings"
"testing"
"time"
"github.com/steveyegge/beads/internal/types"
)
@@ -149,6 +150,47 @@ func TestRemoveDependency(t *testing.T) {
}
}
func TestAddDependencyPreservesProvidedMetadata(t *testing.T) {
store, cleanup := setupTestDB(t)
defer cleanup()
ctx := context.Background()
parent := &types.Issue{Title: "Parent", Status: types.StatusOpen, Priority: 1, IssueType: types.TypeTask}
child := &types.Issue{Title: "Child", Status: types.StatusOpen, Priority: 1, IssueType: types.TypeTask}
store.CreateIssue(ctx, parent, "test-user")
store.CreateIssue(ctx, child, "test-user")
customTime := time.Date(2024, 10, 24, 12, 0, 0, 0, time.UTC)
dep := &types.Dependency{
IssueID: child.ID,
DependsOnID: parent.ID,
Type: types.DepParentChild,
CreatedAt: customTime,
CreatedBy: "import",
}
if err := store.AddDependency(ctx, dep, "test-user"); err != nil {
t.Fatalf("AddDependency failed: %v", err)
}
records, err := store.GetDependencyRecords(ctx, child.ID)
if err != nil {
t.Fatalf("GetDependencyRecords failed: %v", err)
}
if len(records) != 1 {
t.Fatalf("Expected 1 dependency record, got %d", len(records))
}
got := records[0]
if !got.CreatedAt.Equal(customTime) {
t.Fatalf("Expected CreatedAt %v, got %v", customTime, got.CreatedAt)
}
if got.CreatedBy != "import" {
t.Fatalf("Expected CreatedBy 'import', got %q", got.CreatedBy)
}
}
func TestGetDependents(t *testing.T) {
store, cleanup := setupTestDB(t)
defer cleanup()