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:
@@ -53,11 +53,18 @@ func Run(ctx context.Context, cfg Config, brainDir, content, source string, dryR
|
||||
var err error
|
||||
if cfg.Wing != "" {
|
||||
// A source slug is a page's graph identity: refuse to take over a slug
|
||||
// that lives anywhere but this wing's own sources/.
|
||||
if existing, found, ferr := wiki.FindSlug(brainDir, wiki.Slug(source)); ferr != nil {
|
||||
// that lives anywhere but this wing's own sources/ — including when
|
||||
// this wing's own page of that name also exists.
|
||||
slug := wiki.Slug(source)
|
||||
own := "wiki/" + cfg.Wing + "/sources/" + slug + ".md"
|
||||
existing, ferr := wiki.FindSlugs(brainDir, slug)
|
||||
if ferr != nil {
|
||||
return Result{}, fmt.Errorf("check source slug: %w", ferr)
|
||||
} else if own := "wiki/" + cfg.Wing + "/sources/" + wiki.Slug(source) + ".md"; found && existing != own {
|
||||
return Result{}, fmt.Errorf("source slug %q is already used by %s", wiki.Slug(source), existing)
|
||||
}
|
||||
for _, p := range existing {
|
||||
if p != own {
|
||||
return Result{}, fmt.Errorf("source slug %q is already used by %s", slug, p)
|
||||
}
|
||||
}
|
||||
inventory, err = wiki.LoadWingInventory(brainDir, cfg.Wing)
|
||||
} else {
|
||||
|
||||
@@ -140,3 +140,17 @@ func listAll(t *testing.T, dir string) []string {
|
||||
_ = filepath.WalkDir(dir, func(p string, _ os.DirEntry, _ error) error { out = append(out, p); return nil })
|
||||
return out
|
||||
}
|
||||
|
||||
// The first match must not hide a second one: this wing's own page of the name
|
||||
// exists AND a page of the same name lives elsewhere.
|
||||
func TestRun_ASlugUsedInTwoPlacesIsRefusedEvenWhenTheOwnPageIsOneOfThem(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(dir, "wiki/web-clip/sources"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "wiki/web-clip/sources/talk.md"), []byte("---\ntitle: Talk\n---\nown"), 0o644))
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(dir, "wiki/entities"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "wiki/entities/talk.md"), []byte("---\ntitle: Talk\n---\nan entity"), 0o644))
|
||||
|
||||
_, err := Run(context.Background(), wingCfg("web-clip", sourceEntityConcept()...), dir, "body", "talk", false)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "already used")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user