* feat(gitlab): sync issue dependency links on push After issue content syncs, mirror local beads dependency edges as GitLab issue links: blocks -> GitLab blocks/is_blocked_by (direction-normalized), related/relates-to -> a single relates_to link per unordered pair (deduped). Children of synced epics also keep the epic's milestone during a dependency-only sync. Reports links_pushed in --json. Additive only (never deletes remote links). License-aware: blocks/ is_blocked_by needs GitLab Premium/Ultimate; on instances without it the link is reported as a single curated, non-fatal message (links_license_skipped in JSON) while relates_to and milestones still apply. Genuine (non-license) link failures remain real warnings, kept distinct from the license case. Feature: max-efe Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * refactor(gitlab): address review — drop dead RelationMap, add push link parity Follow-up to maphew's review on #4294. - Delete the dead GitLab RelationMap: issueLinksToDependencies maps link types via hardcoded constants and ignores MappingConfig, so the field, its default, and the test assertion were dead config surface implying a configurability that does not exist. (Linear's RelationMap is untouched.) - Give `bd gitlab push` dependency-link + epic-milestone parity with `bd gitlab sync`: extract the shared pushGitLabDependencyLinks helper from runGitLabSync's inline block and call it from runGitLabPush, scoped to the requested IssueIDs. Render push output natively so the link pass runs before the summary, dry-run ordering is correct, and the --json payload carries links_pushed / links_license_skipped / milestones_updated, matching sync in all output modes; also guard OnMessage under !jsonOutput. Reviewed with /code-review + /codex (dry-run "Synced" line, output ordering, and --json link-stat omission all caught and fixed here). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(gitlab): check outputJSON error in runGitLabSync (errcheck) CI lint (first run on this branch, only-new-issues=false) flagged the unchecked outputJSON return in the sync --json path. Return it, matching runGitLabPush. Fixes the Lint / Build Artifacts / PR Lint failures. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(gitlab): carry closed state on push; surface failed-close in sync result GitLab's POST /issues (and milestone/work-item creation) cannot set state, so closed beads were pushed as opened issues and closed epics as active milestones — milestone progress read 0/X even when all children were done. - Close after create on all three paths (CreateIssue, createMilestone, createTaskWorkItem) via a best-effort follow-up state_event=close. - BeadsIssueToGitLabFields emits state_event close/reopen so the update path flips both directions (reopening a bead reopens the GitLab issue). deferred stays open — only "done" work counts toward milestone completion. - A failed best-effort close now records a warning on TrackerIssue.Warnings, which the engine drains into the sync result (visible in --json) instead of a bare stderr print that left --json reporting errors:0 while the issue was left open. On close failure the created issue and its external_ref are still returned so the next push doesn't create a duplicate (the push skip-guard means it won't retry the close until the bead is next modified — hence the surfaced warning). Reviewed via /code-review + Codex. bd: max-9t6 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
652 lines
19 KiB
Go
652 lines
19 KiB
Go
// Package gitlab provides client and data types for the GitLab REST API.
|
|
package gitlab
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/steveyegge/beads/internal/types"
|
|
)
|
|
|
|
// TestDefaultGitLabMappingConfig verifies the default configuration has proper mappings.
|
|
func TestDefaultGitLabMappingConfig(t *testing.T) {
|
|
config := DefaultMappingConfig()
|
|
|
|
// Verify priority mappings exist
|
|
if len(config.PriorityMap) == 0 {
|
|
t.Error("PriorityMap is empty, want default priority mappings")
|
|
}
|
|
// Should map "high" to priority 1
|
|
if p, ok := config.PriorityMap["high"]; !ok || p != 1 {
|
|
t.Errorf("PriorityMap[\"high\"] = %d, want 1", p)
|
|
}
|
|
|
|
// Verify state mappings exist
|
|
if len(config.StateMap) == 0 {
|
|
t.Error("StateMap is empty, want default state mappings")
|
|
}
|
|
// "opened" should map to "open"
|
|
if s, ok := config.StateMap["opened"]; !ok || s != "open" {
|
|
t.Errorf("StateMap[\"opened\"] = %q, want \"open\"", s)
|
|
}
|
|
|
|
// Verify type mappings exist
|
|
if len(config.LabelTypeMap) == 0 {
|
|
t.Error("LabelTypeMap is empty, want default type mappings")
|
|
}
|
|
// "bug" should map to "bug"
|
|
if typ, ok := config.LabelTypeMap["bug"]; !ok || typ != "bug" {
|
|
t.Errorf("LabelTypeMap[\"bug\"] = %q, want \"bug\"", typ)
|
|
}
|
|
}
|
|
|
|
// TestpriorityFromLabels verifies parsing priority::* labels.
|
|
func TestPriorityFromLabels(t *testing.T) {
|
|
config := DefaultMappingConfig()
|
|
|
|
tests := []struct {
|
|
name string
|
|
labels []string
|
|
wantPriority int
|
|
}{
|
|
{
|
|
name: "priority::critical",
|
|
labels: []string{"priority::critical", "bug"},
|
|
wantPriority: 0,
|
|
},
|
|
{
|
|
name: "priority::high",
|
|
labels: []string{"priority::high"},
|
|
wantPriority: 1,
|
|
},
|
|
{
|
|
name: "priority::medium",
|
|
labels: []string{"priority::medium", "type::feature"},
|
|
wantPriority: 2,
|
|
},
|
|
{
|
|
name: "priority::low",
|
|
labels: []string{"priority::low"},
|
|
wantPriority: 3,
|
|
},
|
|
{
|
|
name: "no priority label defaults to medium",
|
|
labels: []string{"bug", "backend"},
|
|
wantPriority: 2, // Default to medium
|
|
},
|
|
{
|
|
name: "empty labels defaults to medium",
|
|
labels: []string{},
|
|
wantPriority: 2,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := priorityFromLabels(tt.labels, config)
|
|
if got != tt.wantPriority {
|
|
t.Errorf("priorityFromLabels(%v) = %d, want %d", tt.labels, got, tt.wantPriority)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TeststatusFromLabelsAndState verifies status determination from labels and GitLab state.
|
|
func TestStatusFromLabelsAndState(t *testing.T) {
|
|
config := DefaultMappingConfig()
|
|
|
|
tests := []struct {
|
|
name string
|
|
labels []string
|
|
state string
|
|
wantStatus string
|
|
}{
|
|
{
|
|
name: "status::open explicit label",
|
|
labels: []string{"status::open"},
|
|
state: "opened",
|
|
wantStatus: "open",
|
|
},
|
|
{
|
|
name: "status::in_progress overrides opened state",
|
|
labels: []string{"status::in_progress"},
|
|
state: "opened",
|
|
wantStatus: "in_progress",
|
|
},
|
|
{
|
|
name: "status::blocked",
|
|
labels: []string{"status::blocked", "bug"},
|
|
state: "opened",
|
|
wantStatus: "blocked",
|
|
},
|
|
{
|
|
name: "status::deferred",
|
|
labels: []string{"status::deferred"},
|
|
state: "opened",
|
|
wantStatus: "deferred",
|
|
},
|
|
{
|
|
name: "status::done maps to closed",
|
|
labels: []string{"status::done"},
|
|
state: "opened",
|
|
wantStatus: "closed",
|
|
},
|
|
{
|
|
name: "closed state wins over status labels",
|
|
labels: []string{"status::in_progress"},
|
|
state: "closed",
|
|
wantStatus: "closed",
|
|
},
|
|
{
|
|
name: "opened state without status label",
|
|
labels: []string{"bug"},
|
|
state: "opened",
|
|
wantStatus: "open",
|
|
},
|
|
{
|
|
name: "reopened state maps to open",
|
|
labels: []string{},
|
|
state: "reopened",
|
|
wantStatus: "open",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := statusFromLabelsAndState(tt.labels, tt.state, config)
|
|
if got != tt.wantStatus {
|
|
t.Errorf("statusFromLabelsAndState(%v, %q) = %q, want %q", tt.labels, tt.state, got, tt.wantStatus)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TesttypeFromLabels verifies parsing type::* labels.
|
|
func TestTypeFromLabels(t *testing.T) {
|
|
config := DefaultMappingConfig()
|
|
|
|
tests := []struct {
|
|
name string
|
|
labels []string
|
|
wantType string
|
|
}{
|
|
{
|
|
name: "type::bug",
|
|
labels: []string{"type::bug", "priority::high"},
|
|
wantType: "bug",
|
|
},
|
|
{
|
|
name: "type::feature",
|
|
labels: []string{"type::feature"},
|
|
wantType: "feature",
|
|
},
|
|
{
|
|
name: "type::task",
|
|
labels: []string{"type::task"},
|
|
wantType: "task",
|
|
},
|
|
{
|
|
name: "type::epic",
|
|
labels: []string{"type::epic"},
|
|
wantType: "epic",
|
|
},
|
|
{
|
|
name: "type::chore",
|
|
labels: []string{"type::chore"},
|
|
wantType: "chore",
|
|
},
|
|
{
|
|
name: "enhancement maps to feature",
|
|
labels: []string{"type::enhancement"},
|
|
wantType: "feature",
|
|
},
|
|
{
|
|
name: "bare bug label (no prefix)",
|
|
labels: []string{"bug"},
|
|
wantType: "bug",
|
|
},
|
|
{
|
|
name: "no type label defaults to task",
|
|
labels: []string{"priority::high"},
|
|
wantType: "task",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := typeFromLabels(tt.labels, config)
|
|
if got != tt.wantType {
|
|
t.Errorf("typeFromLabels(%v) = %q, want %q", tt.labels, got, tt.wantType)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestGitLabIssueToBeads verifies full conversion from GitLab Issue to beads Issue.
|
|
func TestGitLabIssueToBeads(t *testing.T) {
|
|
config := DefaultMappingConfig()
|
|
|
|
createdAt := time.Date(2024, 1, 15, 10, 0, 0, 0, time.UTC)
|
|
updatedAt := time.Date(2024, 1, 16, 14, 0, 0, 0, time.UTC)
|
|
|
|
glIssue := &Issue{
|
|
ID: 123456,
|
|
IID: 42,
|
|
ProjectID: 789,
|
|
Title: "Fix authentication bug",
|
|
Description: "Users cannot log in with SSO",
|
|
State: "opened",
|
|
CreatedAt: &createdAt,
|
|
UpdatedAt: &updatedAt,
|
|
Labels: []string{"type::bug", "priority::high", "status::in_progress"},
|
|
Assignee: &User{
|
|
ID: 101,
|
|
Username: "jdoe",
|
|
Name: "John Doe",
|
|
},
|
|
Author: &User{
|
|
ID: 102,
|
|
Username: "alice",
|
|
Name: "Alice Smith",
|
|
},
|
|
WebURL: "https://gitlab.example.com/group/project/-/issues/42",
|
|
DueDate: "2024-01-20",
|
|
Weight: 3,
|
|
}
|
|
|
|
conversion := GitLabIssueToBeads(glIssue, config)
|
|
if conversion == nil {
|
|
t.Fatal("GitLabIssueToBeads returned nil")
|
|
}
|
|
|
|
issue := conversion.Issue
|
|
if issue == nil {
|
|
t.Fatal("conversion.Issue is nil")
|
|
}
|
|
|
|
// Verify basic fields
|
|
if issue.Title != "Fix authentication bug" {
|
|
t.Errorf("Title = %q, want %q", issue.Title, "Fix authentication bug")
|
|
}
|
|
if issue.Description != "Users cannot log in with SSO" {
|
|
t.Errorf("Description = %q, want %q", issue.Description, "Users cannot log in with SSO")
|
|
}
|
|
|
|
// Verify external reference
|
|
if issue.ExternalRef == nil || *issue.ExternalRef != "https://gitlab.example.com/group/project/-/issues/42" {
|
|
t.Errorf("ExternalRef = %v, want GitLab URL", issue.ExternalRef)
|
|
}
|
|
if issue.SourceSystem != "gitlab:789:42" {
|
|
t.Errorf("SourceSystem = %q, want \"gitlab:789:42\"", issue.SourceSystem)
|
|
}
|
|
|
|
// Verify mapped fields
|
|
if issue.IssueType != types.TypeBug {
|
|
t.Errorf("IssueType = %q, want %q", issue.IssueType, types.TypeBug)
|
|
}
|
|
if issue.Priority != 1 {
|
|
t.Errorf("Priority = %d, want 1 (high)", issue.Priority)
|
|
}
|
|
if issue.Status != types.StatusInProgress {
|
|
t.Errorf("Status = %q, want %q", issue.Status, types.StatusInProgress)
|
|
}
|
|
|
|
// Verify assignee
|
|
if issue.Assignee != "jdoe" {
|
|
t.Errorf("Assignee = %q, want \"jdoe\"", issue.Assignee)
|
|
}
|
|
|
|
// Verify estimate from weight (3 hours = 180 minutes)
|
|
if issue.EstimatedMinutes == nil || *issue.EstimatedMinutes != 180 {
|
|
t.Errorf("EstimatedMinutes = %v, want 180 (from weight 3)", issue.EstimatedMinutes)
|
|
}
|
|
}
|
|
|
|
// TestGitLabIssueToBeads_ClosedIssue verifies closed issues are converted correctly.
|
|
func TestGitLabIssueToBeads_ClosedIssue(t *testing.T) {
|
|
config := DefaultMappingConfig()
|
|
|
|
closedAt := time.Date(2024, 1, 17, 10, 0, 0, 0, time.UTC)
|
|
glIssue := &Issue{
|
|
ID: 100,
|
|
IID: 10,
|
|
Title: "Closed task",
|
|
State: "closed",
|
|
ClosedAt: &closedAt,
|
|
Labels: []string{"status::in_progress"}, // Should be overridden by closed state
|
|
WebURL: "https://gitlab.example.com/project/-/issues/10",
|
|
}
|
|
|
|
conversion := GitLabIssueToBeads(glIssue, config)
|
|
issue := conversion.Issue
|
|
if issue == nil {
|
|
t.Fatal("conversion.Issue is nil")
|
|
}
|
|
|
|
if issue.Status != types.StatusClosed {
|
|
t.Errorf("Status = %q, want %q (closed state overrides labels)", issue.Status, types.StatusClosed)
|
|
}
|
|
}
|
|
|
|
// TestBeadsIssueToGitLabFields verifies conversion from beads Issue to GitLab update fields.
|
|
func TestBeadsIssueToGitLabFields(t *testing.T) {
|
|
config := DefaultMappingConfig()
|
|
|
|
estimatedMinutes := 300 // 5 hours
|
|
beadsIssue := &types.Issue{
|
|
Title: "New feature request",
|
|
Description: "Add dark mode support",
|
|
IssueType: types.TypeFeature,
|
|
Priority: 1, // High
|
|
Status: types.StatusInProgress,
|
|
Assignee: "jdoe",
|
|
EstimatedMinutes: &estimatedMinutes,
|
|
}
|
|
|
|
fields := BeadsIssueToGitLabFields(beadsIssue, config)
|
|
|
|
// Verify title and description
|
|
if fields["title"] != "New feature request" {
|
|
t.Errorf("fields[\"title\"] = %v, want \"New feature request\"", fields["title"])
|
|
}
|
|
if fields["description"] != "Add dark mode support" {
|
|
t.Errorf("fields[\"description\"] = %v, want \"Add dark mode support\"", fields["description"])
|
|
}
|
|
|
|
// Verify labels include type, priority, and status
|
|
labels, ok := fields["labels"].([]string)
|
|
if !ok {
|
|
t.Fatalf("fields[\"labels\"] is not []string")
|
|
}
|
|
|
|
hasType := false
|
|
hasPriority := false
|
|
hasStatus := false
|
|
for _, l := range labels {
|
|
if l == "type::feature" {
|
|
hasType = true
|
|
}
|
|
if l == "priority::high" {
|
|
hasPriority = true
|
|
}
|
|
if l == "status::in_progress" {
|
|
hasStatus = true
|
|
}
|
|
}
|
|
if !hasType {
|
|
t.Errorf("labels missing type::feature, got %v", labels)
|
|
}
|
|
if !hasPriority {
|
|
t.Errorf("labels missing priority::high, got %v", labels)
|
|
}
|
|
if !hasStatus {
|
|
t.Errorf("labels missing status::in_progress, got %v", labels)
|
|
}
|
|
|
|
// Verify weight from estimate
|
|
if fields["weight"] != 5 {
|
|
t.Errorf("fields[\"weight\"] = %v, want 5", fields["weight"])
|
|
}
|
|
}
|
|
|
|
// TestBeadsIssueToGitLabFields_StateEvent verifies state_event tracks the bead
|
|
// status in both directions: closed issues close, non-closed issues reopen. The
|
|
// reopen direction ensures a bead reopened after being synced closed does not
|
|
// stay closed in GitLab on update.
|
|
func TestBeadsIssueToGitLabFields_StateEvent(t *testing.T) {
|
|
config := DefaultMappingConfig()
|
|
|
|
tests := []struct {
|
|
name string
|
|
status types.Status
|
|
want string
|
|
}{
|
|
{"closed", types.StatusClosed, "close"},
|
|
{"open", types.StatusOpen, "reopen"},
|
|
{"in_progress", types.StatusInProgress, "reopen"},
|
|
// deferred is deliberately NOT closed in GitLab: only truly-done work
|
|
// counts toward milestone completion.
|
|
{"deferred", types.StatusDeferred, "reopen"},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
fields := BeadsIssueToGitLabFields(&types.Issue{Title: "t", Status: tt.status}, config)
|
|
if fields["state_event"] != tt.want {
|
|
t.Errorf("state_event = %v, want %q", fields["state_event"], tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestBeadsIssueToGitLabFields_OpenStatus verifies open issues don't get redundant status labels.
|
|
func TestBeadsIssueToGitLabFields_OpenStatus(t *testing.T) {
|
|
config := DefaultMappingConfig()
|
|
|
|
openIssue := &types.Issue{
|
|
Title: "New task",
|
|
IssueType: types.TypeTask,
|
|
Status: types.StatusOpen,
|
|
}
|
|
|
|
fields := BeadsIssueToGitLabFields(openIssue, config)
|
|
labels := fields["labels"].([]string)
|
|
|
|
for _, l := range labels {
|
|
if l == "status::open" {
|
|
t.Errorf("open issue should not get status::open label (handled by GitLab state), got %v", labels)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestissueLinksToDependencies verifies conversion of GitLab IssueLinks to beads Dependencies.
|
|
func TestIssueLinksToDependencies(t *testing.T) {
|
|
config := DefaultMappingConfig()
|
|
|
|
links := []IssueLink{
|
|
{
|
|
SourceIssue: &Issue{IID: 42, ProjectID: 789},
|
|
TargetIssue: &Issue{IID: 43, ProjectID: 789},
|
|
LinkType: "blocks",
|
|
},
|
|
{
|
|
SourceIssue: &Issue{IID: 42, ProjectID: 789},
|
|
TargetIssue: &Issue{IID: 44, ProjectID: 789},
|
|
LinkType: "relates_to",
|
|
},
|
|
{
|
|
SourceIssue: &Issue{IID: 42, ProjectID: 789},
|
|
TargetIssue: &Issue{IID: 45, ProjectID: 789},
|
|
LinkType: "is_blocked_by",
|
|
},
|
|
}
|
|
|
|
deps := issueLinksToDependencies(42, links, config)
|
|
|
|
if len(deps) != 3 {
|
|
t.Fatalf("issueLinksToDependencies returned %d dependencies, want 3", len(deps))
|
|
}
|
|
|
|
// Check blocks dependency: source 42 blocks target 43, so 43 depends on 42.
|
|
if deps[0].Type != "blocks" {
|
|
t.Errorf("deps[0].Type = %q, want \"blocks\"", deps[0].Type)
|
|
}
|
|
if deps[0].FromGitLabIID != 43 || deps[0].ToGitLabIID != 42 {
|
|
t.Errorf("deps[0] = %d -> %d, want 43 -> 42", deps[0].FromGitLabIID, deps[0].ToGitLabIID)
|
|
}
|
|
|
|
// Check relates_to dependency
|
|
if deps[1].Type != "related" {
|
|
t.Errorf("deps[1].Type = %q, want \"related\"", deps[1].Type)
|
|
}
|
|
|
|
// Check is_blocked_by: source 42 is blocked by target 45, so 42 depends on 45.
|
|
if deps[2].Type != "blocks" {
|
|
t.Errorf("deps[2].Type = %q, want \"blocks\"", deps[2].Type)
|
|
}
|
|
if deps[2].FromGitLabIID != 42 || deps[2].ToGitLabIID != 45 {
|
|
t.Errorf("deps[2] = %d -> %d, want 42 -> 45", deps[2].FromGitLabIID, deps[2].ToGitLabIID)
|
|
}
|
|
}
|
|
|
|
// TestfilterNonScopedLabels verifies that non-scoped labels are preserved.
|
|
func TestFilterNonScopedLabels(t *testing.T) {
|
|
labels := []string{
|
|
"type::bug",
|
|
"priority::high",
|
|
"status::in_progress",
|
|
"backend",
|
|
"needs-review",
|
|
"urgent",
|
|
}
|
|
|
|
filtered := filterNonScopedLabels(labels)
|
|
|
|
// Should only have non-scoped labels
|
|
expected := []string{"backend", "needs-review", "urgent"}
|
|
if len(filtered) != len(expected) {
|
|
t.Fatalf("filterNonScopedLabels returned %d labels, want %d", len(filtered), len(expected))
|
|
}
|
|
|
|
for i, l := range filtered {
|
|
if l != expected[i] {
|
|
t.Errorf("filtered[%d] = %q, want %q", i, l, expected[i])
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestPriorityToLabel verifies conversion from beads priority to GitLab label value.
|
|
func TestPriorityToLabel(t *testing.T) {
|
|
tests := []struct {
|
|
priority int
|
|
want string
|
|
}{
|
|
{0, "critical"},
|
|
{1, "high"},
|
|
{2, "medium"},
|
|
{3, "low"},
|
|
{4, "none"},
|
|
{-1, "medium"}, // Default for invalid
|
|
{5, "medium"}, // Default for out of range
|
|
{100, "medium"}, // Default for very large
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
got := priorityToLabel(tt.priority)
|
|
if got != tt.want {
|
|
t.Errorf("priorityToLabel(%d) = %q, want %q", tt.priority, got, tt.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestissueLinksToDependencies_AsTarget verifies conversion when we are the target issue.
|
|
func TestIssueLinksToDependencies_AsTarget(t *testing.T) {
|
|
config := DefaultMappingConfig()
|
|
|
|
// Issue 42 is the target (blocked by 43)
|
|
links := []IssueLink{
|
|
{
|
|
SourceIssue: &Issue{IID: 43, ProjectID: 789},
|
|
TargetIssue: &Issue{IID: 42, ProjectID: 789},
|
|
LinkType: "blocks",
|
|
},
|
|
}
|
|
|
|
deps := issueLinksToDependencies(42, links, config)
|
|
|
|
if len(deps) != 1 {
|
|
t.Fatalf("issueLinksToDependencies returned %d dependencies, want 1", len(deps))
|
|
}
|
|
|
|
// When we are target, source becomes the dependency
|
|
if deps[0].ToGitLabIID != 43 {
|
|
t.Errorf("deps[0].ToGitLabIID = %d, want 43 (source issue)", deps[0].ToGitLabIID)
|
|
}
|
|
if deps[0].FromGitLabIID != 42 {
|
|
t.Errorf("deps[0].FromGitLabIID = %d, want 42", deps[0].FromGitLabIID)
|
|
}
|
|
}
|
|
|
|
// TestissueLinksToDependencies_UnknownLinkType verifies unknown link types are skipped.
|
|
func TestIssueLinksToDependencies_UnknownLinkType(t *testing.T) {
|
|
config := DefaultMappingConfig()
|
|
|
|
links := []IssueLink{
|
|
{
|
|
SourceIssue: &Issue{IID: 42, ProjectID: 789},
|
|
TargetIssue: &Issue{IID: 43, ProjectID: 789},
|
|
LinkType: "unknown_type",
|
|
},
|
|
}
|
|
|
|
deps := issueLinksToDependencies(42, links, config)
|
|
|
|
if len(deps) != 0 {
|
|
t.Fatalf("issueLinksToDependencies returned %d dependencies, want 0 for unknown link type", len(deps))
|
|
}
|
|
}
|
|
|
|
// TestissueLinksToDependencies_NilIssues verifies handling of nil source/target issues.
|
|
func TestIssueLinksToDependencies_NilIssues(t *testing.T) {
|
|
config := DefaultMappingConfig()
|
|
|
|
// Link with nil target
|
|
links := []IssueLink{
|
|
{
|
|
SourceIssue: &Issue{IID: 42, ProjectID: 789},
|
|
TargetIssue: nil,
|
|
LinkType: "blocks",
|
|
},
|
|
}
|
|
|
|
deps := issueLinksToDependencies(42, links, config)
|
|
|
|
if len(deps) != 0 {
|
|
t.Fatalf("issueLinksToDependencies returned %d dependencies, want 0 for nil target", len(deps))
|
|
}
|
|
}
|
|
|
|
// TestMappingConfigUsesTypesConstants verifies that DefaultMappingConfig uses
|
|
// the exported mapping constants from types.go, ensuring single source of truth.
|
|
// This prevents duplicate definitions between types.go and mapping.go.
|
|
func TestMappingConfigUsesTypesConstants(t *testing.T) {
|
|
config := DefaultMappingConfig()
|
|
|
|
// Priority mappings should match types.go PriorityMapping
|
|
if p := config.PriorityMap["critical"]; p != PriorityMapping["critical"] {
|
|
t.Errorf("PriorityMap[critical] = %d, want %d (from PriorityMapping)", p, PriorityMapping["critical"])
|
|
}
|
|
if p := config.PriorityMap["high"]; p != PriorityMapping["high"] {
|
|
t.Errorf("PriorityMap[high] = %d, want %d (from PriorityMapping)", p, PriorityMapping["high"])
|
|
}
|
|
if p := config.PriorityMap["medium"]; p != PriorityMapping["medium"] {
|
|
t.Errorf("PriorityMap[medium] = %d, want %d (from PriorityMapping)", p, PriorityMapping["medium"])
|
|
}
|
|
if p := config.PriorityMap["low"]; p != PriorityMapping["low"] {
|
|
t.Errorf("PriorityMap[low] = %d, want %d (from PriorityMapping)", p, PriorityMapping["low"])
|
|
}
|
|
if p := config.PriorityMap["none"]; p != PriorityMapping["none"] {
|
|
t.Errorf("PriorityMap[none] = %d, want %d (from PriorityMapping)", p, PriorityMapping["none"])
|
|
}
|
|
|
|
// Status mappings should match types.go StatusMapping
|
|
if s := config.StateMap["opened"]; s != StatusMapping["open"] {
|
|
t.Errorf("StateMap[opened] = %q, want %q (from StatusMapping)", s, StatusMapping["open"])
|
|
}
|
|
if s := config.StateMap["closed"]; s != StatusMapping["closed"] {
|
|
t.Errorf("StateMap[closed] = %q, want %q (from StatusMapping)", s, StatusMapping["closed"])
|
|
}
|
|
|
|
// Type mappings should match types.go typeMapping
|
|
if typ := config.LabelTypeMap["bug"]; typ != typeMapping["bug"] {
|
|
t.Errorf("LabelTypeMap[bug] = %q, want %q (from typeMapping)", typ, typeMapping["bug"])
|
|
}
|
|
if typ := config.LabelTypeMap["feature"]; typ != typeMapping["feature"] {
|
|
t.Errorf("LabelTypeMap[feature] = %q, want %q (from typeMapping)", typ, typeMapping["feature"])
|
|
}
|
|
if typ := config.LabelTypeMap["task"]; typ != typeMapping["task"] {
|
|
t.Errorf("LabelTypeMap[task] = %q, want %q (from typeMapping)", typ, typeMapping["task"])
|
|
}
|
|
if typ := config.LabelTypeMap["enhancement"]; typ != typeMapping["enhancement"] {
|
|
t.Errorf("LabelTypeMap[enhancement] = %q, want %q (from typeMapping)", typ, typeMapping["enhancement"])
|
|
}
|
|
}
|