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:
@@ -16,37 +16,41 @@ func put(t *testing.T, dir, rel string) {
|
||||
require.NoError(t, os.WriteFile(full, []byte("---\ntitle: x\n---\n"), 0o644))
|
||||
}
|
||||
|
||||
func TestFindSlug(t *testing.T) {
|
||||
func TestFindSlugs(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
put(t, dir, "wiki/sources/legacy-src.md")
|
||||
put(t, dir, "wiki/concepts/a-concept.md")
|
||||
put(t, dir, "wiki/entities/an-entity.md")
|
||||
put(t, dir, "wiki/homelab/failures/in-a-hall.md")
|
||||
put(t, dir, "wiki/web-clip/sources/a-clip.md")
|
||||
// One slug in two places: the first hit must not hide the second.
|
||||
put(t, dir, "wiki/sources/shared-slug.md")
|
||||
put(t, dir, "wiki/entities/shared-slug.md")
|
||||
put(t, dir, "wiki/aaa/facts/shared-slug.md")
|
||||
|
||||
tests := []struct {
|
||||
slug string
|
||||
want string
|
||||
want []string
|
||||
}{
|
||||
{"legacy-src", "wiki/sources/legacy-src.md"},
|
||||
{"a-concept", "wiki/concepts/a-concept.md"},
|
||||
{"an-entity", "wiki/entities/an-entity.md"},
|
||||
{"in-a-hall", "wiki/homelab/failures/in-a-hall.md"},
|
||||
{"a-clip", "wiki/web-clip/sources/a-clip.md"},
|
||||
{"nothing-here", ""},
|
||||
{"legacy-src", []string{"wiki/sources/legacy-src.md"}},
|
||||
{"a-concept", []string{"wiki/concepts/a-concept.md"}},
|
||||
{"an-entity", []string{"wiki/entities/an-entity.md"}},
|
||||
{"in-a-hall", []string{"wiki/homelab/failures/in-a-hall.md"}},
|
||||
{"a-clip", []string{"wiki/web-clip/sources/a-clip.md"}},
|
||||
{"shared-slug", []string{"wiki/aaa/facts/shared-slug.md", "wiki/entities/shared-slug.md", "wiki/sources/shared-slug.md"}},
|
||||
{"nothing-here", nil},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.slug, func(t *testing.T) {
|
||||
got, found, err := FindSlug(dir, tt.slug)
|
||||
got, err := FindSlugs(dir, tt.slug)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tt.want != "", found)
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindSlug_NoWikiDirIsNotAFinding(t *testing.T) {
|
||||
_, found, err := FindSlug(t.TempDir(), "x")
|
||||
func TestFindSlugs_NoWikiDirFindsNothing(t *testing.T) {
|
||||
got, err := FindSlugs(t.TempDir(), "x")
|
||||
require.NoError(t, err)
|
||||
assert.False(t, found)
|
||||
assert.Empty(t, got)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user