fix(mcp): keep a nested skill's file entries when its parent disagrees

A parent lists its nested skills' files under the same URIs and was
loaded after them, so a file changed between the two reads had the
nested skill's entry overwritten by the parent's newer digest, and reads
of it no longer matched what the nested skill advertised. The parent is
now skipped for that build and served after the next refresh.
This commit is contained in:
Willie
2026-10-06 16:51:34 +08:00
parent 699dcb86ec
commit 321d3beeed
2 changed files with 24 additions and 0 deletions
+8
View File
@@ -104,6 +104,14 @@ func (b *Builder) Build() (*Catalog, error) {
if j := slices.IndexFunc(unserved, func(o string) bool { return strings.HasPrefix(o, s.RelPath+"/") }); reason == "" && j >= 0 {
reason = fmt.Sprintf("contains %s, which is not served", unserved[j])
}
// A parent lists its nested skills' files under the same URIs. If one changed
// between the two reads, the entries disagree; serve the parent next refresh
// rather than overwrite what the nested skill advertises.
for uri, f := range files {
if old, ok := c.byFile[uri]; reason == "" && ok && old.digest != f.digest {
reason = "a nested skill changed while it was read; it is served after the next refresh"
}
}
if reason != "" {
c.Skipped = append(c.Skipped, Skip{Path: s.RelPath, Reason: reason})
unserved = append(unserved, s.RelPath)
+16
View File
@@ -122,6 +122,22 @@ func TestBuild_SkipsParentOfExcludedNestedSkill(t *testing.T) {
}
}
// A parent and its nested skill list the same files under the same URIs; an
// unchanged tree serves both.
func TestBuild_ServesParentAndNestedSkillTogether(t *testing.T) {
src := t.TempDir()
writeFile(t, filepath.Join(src, "suite/SKILL.md"), skillMD("suite"))
writeFile(t, filepath.Join(src, "suite/child/SKILL.md"), skillMD("child"))
c, err := (&Builder{Source: src}).Build()
if err != nil {
t.Fatal(err)
}
if len(c.Skills) != 2 {
t.Errorf("skills=%v warnings=%v, want suite and suite/child served", c.Skills, c.Skipped)
}
}
func TestBuild_SkipsParentOfInvalidNestedSkill(t *testing.T) {
src := t.TempDir()
writeFile(t, filepath.Join(src, "suite/SKILL.md"), skillMD("suite"))