fix(pipeline): a slug used in two places is refused even when one is the wing's own (#208)
FindSlug returned the first hit, so a wing's own page of a name masked another page of the same name (the retired dirs are searched before the wings, and wings alphabetically). FindSlugs returns every match and callers refuse any that is not their own. Found by the legacy-move planner's own test. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/mathiasbq/hyperguild/ingestion/internal/brainfs"
|
||||
@@ -133,45 +134,46 @@ func LoadWingInventory(brainDir, wing string) (map[PageType][]Entry, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// FindSlug returns the brain-relative path of an existing page whose basename is
|
||||
// slug, searching the retired dirs (wiki/{sources,concepts,entities}/) and every
|
||||
// wing hall (wiki/<wing>/<hall>/). The slug is a page's graph identity, so two
|
||||
// pages must not share one.
|
||||
func FindSlug(brainDir, slug string) (string, bool, error) {
|
||||
// FindSlugs returns the brain-relative path of EVERY existing page whose
|
||||
// basename is slug, searching the retired dirs (wiki/{sources,concepts,
|
||||
// entities}/) and every wing hall (wiki/<wing>/<hall>/), sorted. The slug is a
|
||||
// page's graph identity, so two pages must not share one; returning all of
|
||||
// them (not the first) is what lets a caller tell "only my own page" from "my
|
||||
// own page and somebody else's".
|
||||
func FindSlugs(brainDir, slug string) ([]string, error) {
|
||||
bfs, err := brainfs.Open(brainDir)
|
||||
if err != nil {
|
||||
return "", false, fmt.Errorf("open brain: %w", err)
|
||||
return nil, fmt.Errorf("open brain: %w", err)
|
||||
}
|
||||
defer func() { _ = bfs.Close() }()
|
||||
file := slug + ".md"
|
||||
has := func(dir string) (bool, error) {
|
||||
var found []string
|
||||
check := func(dir string) error {
|
||||
names, err := bfs.ReadDirRegular(dir)
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
return false, nil
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return false, err
|
||||
return err
|
||||
}
|
||||
for _, n := range names {
|
||||
if n == file {
|
||||
return true, nil
|
||||
found = append(found, dir+"/"+file)
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
return nil
|
||||
}
|
||||
for _, d := range []string{"wiki/sources", "wiki/concepts", "wiki/entities"} {
|
||||
if ok, err := has(d); err != nil {
|
||||
return "", false, err
|
||||
} else if ok {
|
||||
return d + "/" + file, true, nil
|
||||
if err := check(d); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
wings, err := bfs.ReadDirDirs("wiki")
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
return "", false, nil
|
||||
return found, nil
|
||||
}
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
return nil, err
|
||||
}
|
||||
for _, w := range wings {
|
||||
if w == "sources" || w == "concepts" || w == "entities" {
|
||||
@@ -182,12 +184,11 @@ func FindSlug(brainDir, slug string) (string, bool, error) {
|
||||
continue
|
||||
}
|
||||
for _, h := range halls {
|
||||
if ok, err := has("wiki/" + w + "/" + h); err != nil {
|
||||
return "", false, err
|
||||
} else if ok {
|
||||
return "wiki/" + w + "/" + h + "/" + file, true, nil
|
||||
if err := check("wiki/" + w + "/" + h); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", false, nil
|
||||
sort.Strings(found)
|
||||
return found, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user