fix(sync): allow routed prefixes in import validation
When importing issues in a multi-rig setup (Gas Town), the prefix validation was failing for issues with prefixes from other rigs (e.g., hq-* prefixes from town-level beads). This fix extends buildAllowedPrefixSet to also load prefixes from routes.jsonl, allowing issues from any routed rig to pass validation. Fixes: gt-2maz79 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,12 +4,14 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/steveyegge/beads/internal/config"
|
"github.com/steveyegge/beads/internal/config"
|
||||||
"github.com/steveyegge/beads/internal/linear"
|
"github.com/steveyegge/beads/internal/linear"
|
||||||
|
"github.com/steveyegge/beads/internal/routing"
|
||||||
"github.com/steveyegge/beads/internal/storage"
|
"github.com/steveyegge/beads/internal/storage"
|
||||||
"github.com/steveyegge/beads/internal/storage/sqlite"
|
"github.com/steveyegge/beads/internal/storage/sqlite"
|
||||||
"github.com/steveyegge/beads/internal/types"
|
"github.com/steveyegge/beads/internal/types"
|
||||||
@@ -228,8 +230,12 @@ func handlePrefixMismatch(ctx context.Context, sqliteStore *sqlite.SQLiteStorage
|
|||||||
// Read allowed_prefixes config for additional valid prefixes (e.g., mol-*)
|
// Read allowed_prefixes config for additional valid prefixes (e.g., mol-*)
|
||||||
allowedPrefixesConfig, _ := sqliteStore.GetConfig(ctx, "allowed_prefixes")
|
allowedPrefixesConfig, _ := sqliteStore.GetConfig(ctx, "allowed_prefixes")
|
||||||
|
|
||||||
|
// Get beads directory from database path for route lookup
|
||||||
|
beadsDir := filepath.Dir(sqliteStore.Path())
|
||||||
|
|
||||||
// GH#686: In multi-repo mode, allow all prefixes (nil = allow all)
|
// GH#686: In multi-repo mode, allow all prefixes (nil = allow all)
|
||||||
allowedPrefixes := buildAllowedPrefixSet(configuredPrefix, allowedPrefixesConfig)
|
// Also include prefixes from routes.jsonl for multi-rig setups (Gas Town)
|
||||||
|
allowedPrefixes := buildAllowedPrefixSet(configuredPrefix, allowedPrefixesConfig, beadsDir)
|
||||||
if allowedPrefixes == nil {
|
if allowedPrefixes == nil {
|
||||||
return issues, nil
|
return issues, nil
|
||||||
}
|
}
|
||||||
@@ -1029,7 +1035,8 @@ func validateNoDuplicateExternalRefs(issues []*types.Issue, clearDuplicates bool
|
|||||||
// buildAllowedPrefixSet returns allowed prefixes, or nil to allow all (GH#686).
|
// buildAllowedPrefixSet returns allowed prefixes, or nil to allow all (GH#686).
|
||||||
// In multi-repo mode, additional repos have their own prefixes - allow all.
|
// In multi-repo mode, additional repos have their own prefixes - allow all.
|
||||||
// Also accepts allowedPrefixesConfig (comma-separated list like "gt-,mol-").
|
// Also accepts allowedPrefixesConfig (comma-separated list like "gt-,mol-").
|
||||||
func buildAllowedPrefixSet(primaryPrefix string, allowedPrefixesConfig string) map[string]bool {
|
// Also loads prefixes from routes.jsonl for multi-rig setups (Gas Town).
|
||||||
|
func buildAllowedPrefixSet(primaryPrefix string, allowedPrefixesConfig string, beadsDir string) map[string]bool {
|
||||||
if config.GetMultiRepoConfig() != nil {
|
if config.GetMultiRepoConfig() != nil {
|
||||||
return nil // Multi-repo: allow all prefixes
|
return nil // Multi-repo: allow all prefixes
|
||||||
}
|
}
|
||||||
@@ -1049,5 +1056,20 @@ func buildAllowedPrefixSet(primaryPrefix string, allowedPrefixesConfig string) m
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load prefixes from routes.jsonl for multi-rig setups (Gas Town)
|
||||||
|
// This allows issues from other rigs to coexist in the same JSONL
|
||||||
|
if beadsDir != "" {
|
||||||
|
routes, err := routing.LoadRoutes(beadsDir)
|
||||||
|
if err == nil && len(routes) > 0 {
|
||||||
|
for _, route := range routes {
|
||||||
|
// Normalize: remove trailing - if present
|
||||||
|
prefix := strings.TrimSuffix(route.Prefix, "-")
|
||||||
|
if prefix != "" {
|
||||||
|
allowed[prefix] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return allowed
|
return allowed
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user