Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as opaque submodule gitlinks on GitHub) into fully-tracked first-party content. AITM now merges its 7 vendored repos as first-party engines: - memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts - git: vendored C git (bundled binary) + gitnexus (in-process code intelligence) - agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess) Includes the full session's product build: Gitgram web/mobile/backend features, AITM website/CLI/MCP, the unified memory layer, engine build tooling (scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md), and extensive test suites. Build artifacts, node_modules, external/, and gemini-cli are gitignored. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
234 lines
6.4 KiB
Go
234 lines
6.4 KiB
Go
package issueops
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/DATA-DOG/go-sqlmock"
|
|
"github.com/steveyegge/beads/internal/storage"
|
|
"github.com/steveyegge/beads/internal/types"
|
|
)
|
|
|
|
func TestValidateCreateIssuesMixedBucketDependenciesRejectsCrossBucketEdges(t *testing.T) {
|
|
regularA := &types.Issue{ID: "test-regular-a", IssueType: types.TypeTask}
|
|
regularB := &types.Issue{ID: "test-regular-b", IssueType: types.TypeTask}
|
|
wispA := &types.Issue{ID: "test-wisp-a", IssueType: types.TypeTask, Ephemeral: true}
|
|
wispB := &types.Issue{ID: "test-wisp-b", IssueType: types.TypeTask, Ephemeral: true}
|
|
|
|
tests := []struct {
|
|
name string
|
|
issues []*types.Issue
|
|
wantError bool
|
|
}{
|
|
{
|
|
name: "regular to wisp",
|
|
issues: []*types.Issue{
|
|
{
|
|
ID: regularA.ID,
|
|
IssueType: types.TypeTask,
|
|
Dependencies: []*types.Dependency{{
|
|
DependsOnID: wispA.ID,
|
|
Type: types.DepBlocks,
|
|
}},
|
|
},
|
|
wispA,
|
|
},
|
|
wantError: true,
|
|
},
|
|
{
|
|
name: "wisp to regular",
|
|
issues: []*types.Issue{
|
|
regularA,
|
|
{
|
|
ID: wispA.ID,
|
|
IssueType: types.TypeTask,
|
|
Ephemeral: true,
|
|
Dependencies: []*types.Dependency{{
|
|
DependsOnID: regularA.ID,
|
|
Type: types.DepBlocks,
|
|
}},
|
|
},
|
|
},
|
|
wantError: true,
|
|
},
|
|
{
|
|
name: "same bucket dependencies",
|
|
issues: []*types.Issue{
|
|
regularB,
|
|
{
|
|
ID: regularA.ID,
|
|
IssueType: types.TypeTask,
|
|
Dependencies: []*types.Dependency{{
|
|
DependsOnID: regularB.ID,
|
|
Type: types.DepBlocks,
|
|
}},
|
|
},
|
|
wispB,
|
|
{
|
|
ID: wispA.ID,
|
|
IssueType: types.TypeTask,
|
|
Ephemeral: true,
|
|
Dependencies: []*types.Dependency{{
|
|
DependsOnID: wispB.ID,
|
|
Type: types.DepBlocks,
|
|
}},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "out of batch target",
|
|
issues: []*types.Issue{
|
|
{
|
|
ID: regularA.ID,
|
|
IssueType: types.TypeTask,
|
|
Dependencies: []*types.Dependency{{
|
|
DependsOnID: "test-external-wisp",
|
|
Type: types.DepBlocks,
|
|
}},
|
|
},
|
|
wispA,
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
err := ValidateCreateIssuesMixedBucketDependencies(tt.issues)
|
|
if tt.wantError {
|
|
if err == nil || !strings.Contains(err.Error(), "cross-bucket dependency") {
|
|
t.Fatalf("error = %v, want cross-bucket dependency", err)
|
|
}
|
|
return
|
|
}
|
|
if err != nil {
|
|
t.Fatalf("error = %v, want nil", err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestFilterCreateIssuesMixedBucketDependenciesSkipsWhenConfigured(t *testing.T) {
|
|
regular := &types.Issue{
|
|
ID: "test-regular-source",
|
|
IssueType: types.TypeTask,
|
|
Dependencies: []*types.Dependency{{
|
|
DependsOnID: "test-wisp-target",
|
|
Type: types.DepBlocks,
|
|
}},
|
|
}
|
|
wisp := &types.Issue{
|
|
ID: "test-wisp-target",
|
|
IssueType: types.TypeTask,
|
|
Ephemeral: true,
|
|
}
|
|
var skipped []string
|
|
|
|
filtered, err := filterCreateIssuesMixedBucketDependencies([]*types.Issue{regular, wisp}, storage.BatchCreateOptions{
|
|
SkipDependencyValidationErrors: true,
|
|
OnSkippedDependency: func(issueID, dependsOnID, reason string) {
|
|
skipped = append(skipped, issueID+" -> "+dependsOnID+": "+reason)
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("filterCreateIssuesMixedBucketDependencies error = %v, want nil", err)
|
|
}
|
|
if len(filtered) != 2 {
|
|
t.Fatalf("len(filtered) = %d, want 2", len(filtered))
|
|
}
|
|
if len(filtered[0].Dependencies) != 0 {
|
|
t.Fatalf("filtered[0].Dependencies = %#v, want none", filtered[0].Dependencies)
|
|
}
|
|
if len(regular.Dependencies) != 1 {
|
|
t.Fatalf("regular.Dependencies was mutated to %#v, want original dependency preserved", regular.Dependencies)
|
|
}
|
|
if len(skipped) != 1 || !strings.Contains(skipped[0], "test-regular-source -> test-wisp-target") ||
|
|
!strings.Contains(skipped[0], "cross-bucket dependency") {
|
|
t.Fatalf("skipped = %#v, want cross-bucket dependency detail", skipped)
|
|
}
|
|
}
|
|
|
|
func TestPersistDependenciesReturnsTargetLookupErrors(t *testing.T) {
|
|
ctx := context.Background()
|
|
db, mock, tx := beginMockTx(t)
|
|
defer db.Close()
|
|
targetErr := errors.New("target lookup failed")
|
|
issue := &types.Issue{
|
|
ID: "source",
|
|
IssueType: types.TypeTask,
|
|
Dependencies: []*types.Dependency{{
|
|
DependsOnID: "target",
|
|
Type: types.DepBlocks,
|
|
}},
|
|
}
|
|
|
|
mock.ExpectQuery("SELECT 1 FROM wisps WHERE id = \\? LIMIT 1").
|
|
WithArgs("target").
|
|
WillReturnError(sql.ErrNoRows)
|
|
mock.ExpectQuery("SELECT 1 FROM issues WHERE id = \\?").
|
|
WithArgs("target").
|
|
WillReturnError(targetErr)
|
|
|
|
err := PersistDependencies(ctx, tx, []*types.Issue{issue}, "tester")
|
|
if err == nil || !strings.Contains(err.Error(), "failed to check dependency target target for source") {
|
|
t.Fatalf("error = %v, want dependency target lookup error", err)
|
|
}
|
|
|
|
mock.ExpectRollback()
|
|
if err := tx.Rollback(); err != nil {
|
|
t.Fatalf("rollback: %v", err)
|
|
}
|
|
if err := mock.ExpectationsWereMet(); err != nil {
|
|
t.Fatalf("unmet expectations: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestPersistDependenciesSkipsValidationErrorsWhenConfigured(t *testing.T) {
|
|
ctx := context.Background()
|
|
db, mock, tx := beginMockTx(t)
|
|
defer db.Close()
|
|
issue := &types.Issue{
|
|
ID: "source",
|
|
IssueType: types.TypeTask,
|
|
Dependencies: []*types.Dependency{{
|
|
DependsOnID: "source",
|
|
Type: types.DepBlocks,
|
|
}},
|
|
}
|
|
var skipped []string
|
|
|
|
mock.ExpectQuery("SELECT 1 FROM wisps WHERE id = \\? LIMIT 1").
|
|
WithArgs("source").
|
|
WillReturnError(sql.ErrNoRows)
|
|
mock.ExpectQuery("SELECT 1 FROM issues WHERE id = \\?").
|
|
WithArgs("source").
|
|
WillReturnRows(sqlmock.NewRows([]string{"1"}).AddRow(1))
|
|
|
|
result, err := PersistDependenciesWithOptionsResult(ctx, tx, []*types.Issue{issue}, "tester", storage.BatchCreateOptions{
|
|
SkipDependencyValidationErrors: true,
|
|
OnSkippedDependency: func(issueID, dependsOnID, reason string) {
|
|
skipped = append(skipped, issueID+" -> "+dependsOnID+": "+reason)
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("PersistDependenciesWithOptionsResult error = %v, want nil", err)
|
|
}
|
|
if len(result.ChangedTables) != 0 {
|
|
t.Fatalf("ChangedTables = %#v, want none", result.ChangedTables)
|
|
}
|
|
if len(skipped) != 1 || !strings.Contains(skipped[0], "source -> source") ||
|
|
!strings.Contains(skipped[0], "cannot depend on itself") {
|
|
t.Fatalf("skipped = %#v, want self-dependency detail", skipped)
|
|
}
|
|
|
|
mock.ExpectRollback()
|
|
if err := tx.Rollback(); err != nil {
|
|
t.Fatalf("rollback: %v", err)
|
|
}
|
|
if err := mock.ExpectationsWereMet(); err != nil {
|
|
t.Fatalf("unmet expectations: %v", err)
|
|
}
|
|
}
|