Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-8095: fix(execenv): normalize required metadata for Codex user skills (#9346)

tangyuanjccfc165ce6ad7
diff --git a/server/internal/daemon/execenv/codex_user_skills.go b/server/internal/daemon/execenv/codex_user_skills.go
index fa4ff6ecd3..e23e496b83 100644
--- a/server/internal/daemon/execenv/codex_user_skills.go
+++ b/server/internal/daemon/execenv/codex_user_skills.go
@@ -5,7 +5,10 @@ import (
"log/slog"
"os"
"path/filepath"
+ "reflect"
"strings"
+
+ "gopkg.in/yaml.v3"
)
// seedUserCodexSkills links user-installed skill directories from the shared
@@ -14,14 +17,15 @@ import (
// per-task directory (via the CODEX_HOME env var), so without this step the
// CLI never sees the user's `~/.codex/skills/` content.
//
-// Links, never copies. A copy charges the whole skill tree to every task
+// Skill trees stay linked. A copy charges the whole skill tree to every task
// directory — 100 MB for a user with a handful of npm-backed skills — and
// hydrateCodexSkills re-does it on every task start, on the critical path,
// while no GC path ever reclaims it as long as the issue stays open. The two
// other shared resources in the same per-task home already link for the same
// reason: sessions (linkCodexSessionsToStore) and the plugin cache
// (exposeSharedCodexPluginCache). A skill directory is read-only input to the
-// CLI, so the write isolation a copy incidentally bought has no requester.
+// CLI. Only a SKILL.md missing required metadata gets a task-local replacement;
+// its support files remain linked and the shared source is never rewritten.
//
// Workspace-assigned skills take precedence on name conflict: any user skill
// whose sanitized name matches a workspace skill's sanitized name is skipped
@@ -97,10 +101,228 @@ func seedUserCodexSkills(codexHome string, workspaceSkills []SkillContextForEnv,
logger.Warn("execenv: codex user-skill clean dst failed", "name", name, "error", err)
continue
}
- if err := createDirLink(resolved, dst); err != nil {
- logger.Warn("execenv: codex user-skill link failed", "name", name, "error", err)
+ if err := seedCodexUserSkill(resolved, dst, name); err != nil {
+ _ = os.RemoveAll(dst)
+ logger.Warn("execenv: codex user-skill normalization failed", "name", name, "error", err)
continue
}
}
return nil
}
+
+// normalizeUserCodexSkillContent repairs only what Codex's skill parser
+// rejects, and otherwise returns content unchanged so the skill stays linked:
+//
+// - no frontmatter at all: synthesize one around the body;
+// - description missing, blank or not a string: fill it (Codex requires a
+// non-empty description);
+// - name present but not a string: replace it with the slug. A missing or
+// blank name is left alone — Codex falls back to the directory name.
+//
+// Every repair is re-parsed and must keep all other fields semantically
+// identical; anything that cannot be repaired that way returns an error and
+// the caller skips the skill instead of publishing a file Codex cannot load.
+func normalizeUserCodexSkillContent(content, slug string) (string, error) {
+ fm, body, ok := frontmatterParts(content)
+ description := "Instructions for the " + slug + " skill."
+ if !ok {
+ if strings.HasPrefix(content, "---") {
+ return "", fmt.Errorf("unterminated skill frontmatter")
+ }
+ return synthesizeFrontmatter(content, slug, description), nil
+ }
+ // Decoding into a map is the validity gate: unlike a Node decode it
+ // rejects duplicate keys, which Codex's loader rejects too.
+ var before map[string]any
+ if err := yaml.Unmarshal([]byte(fm), &before); err != nil || before == nil {
+ return "", fmt.Errorf("invalid skill frontmatter")
+ }
+ desc, _ := before["description"].(string)
+ needDesc := strings.TrimSpace(desc) == ""
+ rawName, nameKey := before["name"]
+ _, nameIsString := rawName.(string)
+ needName := nameKey && rawName != nil && !nameIsString
+ if !needDesc && !needName {
+ return content, nil
+ }
+ _, descKey := before["description"]
+ if needDesc && !descKey && !needName {
+ // Common case: a plain block mapping simply lacks description. Insert
+ // one line after the opening delimiter so the rest stays byte-for-byte.
+ fmStart, _ := frontmatterBodyStart(content)
+ eol := strings.TrimPrefix(content[:fmStart], "---")
+ candidate := content[:fmStart] + "description: " + yamlEscapeInline(description) + eol + content[fmStart:]
+ if verifyUserSkillRepair(candidate, before, description) {
+ return candidate, nil
+ }
+ // Flow mappings, indented mappings, root tags etc. cannot take a
+ // prepended line; fall through to the node rewrite.
+ }
+ candidate, err := rewriteUserSkillFrontmatterNode(fm, body, slug, description, needName, needDesc)
+ if err != nil {
+ return "", err
+ }
+ if !verifyUserSkillRepair(candidate, before, description) {
+ return "", fmt.Errorf("skill frontmatter could not be repaired safely")
+ }
+ return candidate, nil
+}
+
+// verifyUserSkillRepair reports whether repaired parses, carries the filled
+// description, and leaves every other field equal to the original — the
+// guarantee that a repair neither breaks nor changes the author's metadata.
+func verifyUserSkillRepair(repaired string, before map[string]any, description string) bool {
+ fm, _, ok := frontmatterParts(repaired)
+ if !ok {
+ return false
+ }
+ var after map[string]any
+ if err := yaml.Unmarshal([]byte(fm), &after); err != nil || after == nil {
+ return false
+ }
+ if d, _ := after["description"].(string); strings.TrimSpace(d) == "" {
+ return false
+ }
+ if n, present := after["name"]; present && n != nil {
+ if _, isString := n.(string); !isString {
+ return false
+ }
+ }
+ for k, v := range before {
+ if k == "description" || k == "name" {
+ continue
+ }
+ if !reflect.DeepEqual(after[k], v) {
+ return false
+ }
+ }
+ for k := range after {
+ if _, existed := before[k]; !existed && k != "description" && k != "name" {
+ return false
+ }
+ }
+ return true
+}
+
+// rewriteUserSkillFrontmatterNode edits the parsed node tree: an existing
+// value is swapped in place keeping its comments; aliases that pointed at it
+// are expanded first so they keep their original value instead of dangling.
+// A missing key is prepended, in whatever style (block or flow) the mapping
+// already uses.
+func rewriteUserSkillFrontmatterNode(fm, body, slug, description string, needName, needDesc bool) (string, error) {
+ var doc yaml.Node
+ if err := yaml.Unmarshal([]byte(fm), &doc); err != nil || len(doc.Content) == 0 || doc.Content[0].Kind != yaml.MappingNode {
+ return "", fmt.Errorf("invalid skill frontmatter")
+ }
+ mapping := doc.Content[0]
+ set := func(key, value string) {
+ replacement := &yaml.Node{Kind: yaml.ScalarNode, Tag: "!!str", Value: value}
+ for i := 0; i+1 < len(mapping.Content); i += 2 {
+ if mapping.Content[i].Value != key {
+ continue
+ }
+ old := mapping.Content[i+1]
+ if old.Anchor != "" {
+ expandAliasesOf(&doc, old)
+ }
+ replacement.HeadComment = old.HeadComment
+ replacement.LineComment = old.LineComment
+ replacement.FootComment = old.FootComment
+ mapping.Content[i+1] = replacement
+ return
+ }
+ mapping.Content = append([]*yaml.Node{
+ {Kind: yaml.ScalarNode, Tag: "!!str", Value: key},
+ replacement,
+ }, mapping.Content...)
+ }
+ if needDesc {
+ set("description", description)
+ }
+ if needName {
+ set("name", slug)
+ }
+ var out strings.Builder
+ enc := yaml.NewEncoder(&out)
+ enc.SetIndent(2)
+ if err := enc.Encode(&doc); err != nil {
+ return "", err
+ }
+ if err := enc.Close(); err != nil {
+ return "", err
+ }
+ return "---\n" + out.String() + "---\n" + body, nil
+}
+
+// expandAliasesOf replaces every alias of target under n with an anchor-free
+// copy of target, so target can be removed without stranding them.
+func expandAliasesOf(n, target *yaml.Node) {
+ for i, child := range n.Content {
+ if child.Kind == yaml.AliasNode && child.Alias == target {
+ expanded := *target
+ expanded.Anchor = ""
+ n.Content[i] = &expanded
+ continue
+ }
+ expandAliasesOf(child, target)
+ }
+}
+
+func seedCodexUserSkill(src, dst, name string) error {
+ data, err := os.ReadFile(filepath.Join(src, "SKILL.md"))
+ if err != nil {
+ return err
+ }
+ normalized, err := normalizeUserCodexSkillContent(string(data), sanitizeSkillName(name))
+ if err != nil {
+ return err
+ }
+ if normalized == string(data) {
+ return createDirLink(src, dst)
+ }
+ // A hidden sibling is owned and reclaimed with the per-task skills tree.
+ // Keeping dst a link also preserves junction-based hydration on Windows.
+ overlay := filepath.Join(filepath.Dir(dst), ".multica-normalized", name)
+ if err := os.RemoveAll(overlay); err != nil {
+ return err
+ }
+ complete := false
+ defer func() {
+ if !complete {
+ _ = os.RemoveAll(overlay)
+ }
+ }()
+ if err := os.MkdirAll(overlay, 0o755); err != nil {
+ return err
+ }
+ if err := os.WriteFile(filepath.Join(overlay, "SKILL.md"), []byte(normalized), 0o644); err != nil {
+ return err
+ }
+ entries, err := os.ReadDir(src)
+ if err != nil {
+ return err
+ }
+ for _, entry := range entries {
+ if entry.Name() == "SKILL.md" {
+ continue
+ }
+ source, target := filepath.Join(src, entry.Name()), filepath.Join(overlay, entry.Name())
+ info, err := os.Stat(source)
+ if err != nil {
+ return err
+ }
+ if info.IsDir() {
+ err = createDirLink(source, target)
+ } else {
+ err = createFileLink(source, target)
+ }
+ if err != nil {
+ return err
+ }
+ }
+ if err := createDirLink(overlay, dst); err != nil {
+ return err
+ }
+ complete = true
+ return nil
+}
diff --git a/server/internal/daemon/execenv/codex_user_skills_test.go b/server/internal/daemon/execenv/codex_user_skills_test.go
index 32c372ffb5..dfdf493440 100644
--- a/server/internal/daemon/execenv/codex_user_skills_test.go
+++ b/server/internal/daemon/execenv/codex_user_skills_test.go
@@ -4,7 +4,10 @@ import (
"os"
"path/filepath"
"runtime"
+ "strings"
"testing"
+
+ "gopkg.in/yaml.v3"
)
// User skills reach the per-task CODEX_HOME as links, not copies (MUL-6000).
@@ -41,7 +44,7 @@ func TestSeedUserCodexSkillsLinksInsteadOfCopying(t *testing.T) {
sharedHome := t.TempDir()
t.Setenv("CODEX_HOME", sharedHome)
userSkill := filepath.Join(sharedHome, "skills", "alpha")
- writeUserSkill(t, userSkill, "alpha v1")
+ writeUserSkill(t, userSkill, validUserSkillFixture("alpha v1"))
codexHome := t.TempDir()
if err := seedUserCodexSkills(codexHome, nil, testLogger()); err != nil {
@@ -55,8 +58,8 @@ func TestSeedUserCodexSkillsLinksInsteadOfCopying(t *testing.T) {
if err != nil {
t.Fatalf("read seeded SKILL.md: %v", err)
}
- if string(body) != "alpha v1" {
- t.Errorf("seeded SKILL.md = %q, want %q", body, "alpha v1")
+ if string(body) != validUserSkillFixture("alpha v1") {
+ t.Errorf("seeded SKILL.md = %q, want %q", body, validUserSkillFixture("alpha v1"))
}
// The decisive proof it is not a copy: content added to the user's real
@@ -74,7 +77,7 @@ func TestSeedUserCodexSkillsResolvesInstallerSymlink(t *testing.T) {
// pointing into a shared ~/.agents/skills/<name>/.
agentsRoot := t.TempDir()
realSkill := filepath.Join(agentsRoot, "lark-base")
- writeUserSkill(t, realSkill, "lark-base v1")
+ writeUserSkill(t, realSkill, validUserSkillFixture("lark-base v1"))
sharedHome := t.TempDir()
t.Setenv("CODEX_HOME", sharedHome)
@@ -97,8 +100,8 @@ func TestSeedUserCodexSkillsResolvesInstallerSymlink(t *testing.T) {
if err != nil {
t.Fatalf("symlink-installed skill unreadable through the per-task link: %v", err)
}
- if string(body) != "lark-base v1" {
- t.Errorf("SKILL.md = %q, want %q", body, "lark-base v1")
+ if string(body) != validUserSkillFixture("lark-base v1") {
+ t.Errorf("SKILL.md = %q, want %q", body, validUserSkillFixture("lark-base v1"))
}
// The per-task link must point at the real directory, not at the
@@ -161,7 +164,7 @@ func TestHydrateCodexSkillsWipeKeepsUserSkillContent(t *testing.T) {
sharedHome := t.TempDir()
t.Setenv("CODEX_HOME", sharedHome)
userSkill := filepath.Join(sharedHome, "skills", "alpha")
- writeUserSkill(t, userSkill, "alpha v1")
+ writeUserSkill(t, userSkill, validUserSkillFixture("alpha v1"))
if err := os.WriteFile(filepath.Join(userSkill, "reference.md"), []byte("support"), 0o644); err != nil {
t.Fatal(err)
}
@@ -194,7 +197,7 @@ func TestHydrateCodexSkillsNeverWritesThroughAUserSkillLink(t *testing.T) {
sharedHome := t.TempDir()
t.Setenv("CODEX_HOME", sharedHome)
userSkill := filepath.Join(sharedHome, "skills", "alpha")
- writeUserSkill(t, userSkill, "user version")
+ writeUserSkill(t, userSkill, validUserSkillFixture("user version"))
codexHome := t.TempDir()
skillsDir := filepath.Join(codexHome, "skills")
@@ -211,10 +214,199 @@ func TestHydrateCodexSkillsNeverWritesThroughAUserSkillLink(t *testing.T) {
if err != nil {
t.Fatalf("read user skill: %v", err)
}
- if string(body) != "user version" {
+ if string(body) != validUserSkillFixture("user version") {
t.Fatalf("workspace skill was written through the link into the user's skill dir: %q", body)
}
if _, err := os.Stat(filepath.Join(skillsDir, "alpha-multica", "SKILL.md")); err != nil {
t.Errorf("colliding workspace skill did not land in a sibling dir: %v", err)
}
}
+
+func validUserSkillFixture(body string) string {
+ return "---\nname: user-skill\ndescription: Test instructions.\n---\n\n" + body
+}
+
+func TestSeedUserCodexSkillsNormalizesWithoutChangingSource(t *testing.T) {
+ sharedHome := t.TempDir()
+ t.Setenv("CODEX_HOME", sharedHome)
+ source := filepath.Join(sharedHome, "skills", "koc-publish-registration")
+ original := "# Publish\n\nPlain-text instructions.\n"
+ writeUserSkill(t, source, original)
+ if err := os.MkdirAll(filepath.Join(source, "references"), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(filepath.Join(source, "references", "guide.md"), []byte("before"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ home := t.TempDir()
+ for i := 0; i < 2; i++ {
+ if err := hydrateCodexSkills(home, nil, nil, testLogger()); err != nil {
+ t.Fatal(err)
+ }
+ dst := filepath.Join(home, "skills", "koc-publish-registration")
+ data, err := os.ReadFile(filepath.Join(dst, "SKILL.md"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ fm := parseFrontmatter(t, string(data))
+ if fm["name"] != "koc-publish-registration" || fm["description"] == "" || !strings.Contains(string(data), "Plain-text instructions.") {
+ t.Fatalf("not loadable: %s", data)
+ }
+ unchanged, err := os.ReadFile(filepath.Join(source, "SKILL.md"))
+ if err != nil || string(unchanged) != original {
+ t.Fatalf("shared source changed: %q, %v", unchanged, err)
+ }
+ if err := os.WriteFile(filepath.Join(source, "references", "guide.md"), []byte("after"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ guide, err := os.ReadFile(filepath.Join(dst, "references", "guide.md"))
+ if err != nil || string(guide) != "after" {
+ t.Fatalf("support tree was copied: %q, %v", guide, err)
+ }
+ }
+}
+
+func TestNormalizeUserCodexSkillContentRetainsPolicies(t *testing.T) {
+ original := "---\nname: alpha\ndisable-model-invocation: true\nallowed-tools: [Read]\n---\nbody\n"
+ normalized, err := normalizeUserCodexSkillContent(original, "alpha")
+ if err != nil {
+ t.Fatal(err)
+ }
+ fm := parseFrontmatter(t, normalized)
+ if fm["disable-model-invocation"] != true || fm["description"] == "" {
+ t.Fatalf("policy lost: %#v", fm)
+ }
+ if _, ok := fm["allowed-tools"].([]interface{}); !ok {
+ t.Fatalf("tools lost: %#v", fm)
+ }
+}
+
+func TestSeedUserCodexSkillsSkipsMalformedSibling(t *testing.T) {
+ sharedHome := t.TempDir()
+ t.Setenv("CODEX_HOME", sharedHome)
+ writeUserSkill(t, filepath.Join(sharedHome, "skills", "broken"), "---\nname: broken\ndescription: [invalid\n---\nbody")
+ writeUserSkill(t, filepath.Join(sharedHome, "skills", "good"), validUserSkillFixture("working"))
+ home := t.TempDir()
+ if err := seedUserCodexSkills(home, nil, testLogger()); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := os.Lstat(filepath.Join(home, "skills", "broken")); !os.IsNotExist(err) {
+ t.Fatalf("malformed skill published: %v", err)
+ }
+ if _, err := os.Stat(filepath.Join(home, "skills", "good", "SKILL.md")); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func TestNormalizeUserCodexSkillContentPreservesFormatting(t *testing.T) {
+ cases := []struct {
+ name, in, want string
+ }{
+ {
+ name: "missing description keeps comments and order",
+ in: "---\nname: alpha\n# keep me\nallowed-tools: [Read]\nmetadata:\n short-description: x\n---\nbody\n",
+ want: "---\ndescription: \"Instructions for the alpha skill.\"\nname: alpha\n# keep me\nallowed-tools: [Read]\nmetadata:\n short-description: x\n---\nbody\n",
+ },
+ {
+ name: "CRLF line endings stay CRLF",
+ in: "---\r\nname: alpha\r\n---\r\nbody\r\n",
+ want: "---\r\ndescription: \"Instructions for the alpha skill.\"\r\nname: alpha\r\n---\r\nbody\r\n",
+ },
+ {
+ name: "empty value replaced in place",
+ in: "---\n# keep me\nzeta: 1\nname: alpha\ndescription:\n---\nbody\n",
+ want: "---\n# keep me\nzeta: 1\nname: alpha\ndescription: Instructions for the alpha skill.\n---\nbody\n",
+ },
+ }
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ got, err := normalizeUserCodexSkillContent(tc.in, "alpha")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if got != tc.want {
+ t.Fatalf("got %q\nwant %q", got, tc.want)
+ }
+ raw, _, ok := frontmatterParts(got)
+ var fm map[string]any
+ if !ok || yaml.Unmarshal([]byte(raw), &fm) != nil {
+ t.Fatalf("unparseable: %q", got)
+ }
+ if fm["name"] != "alpha" || fm["description"] != "Instructions for the alpha skill." {
+ t.Fatalf("not loadable: %#v", fm)
+ }
+ })
+ }
+}
+
+func TestNormalizeUserCodexSkillContentRejectsDuplicateKeys(t *testing.T) {
+ if _, err := normalizeUserCodexSkillContent("---\nname: a\nname: b\n---\nbody", "alpha"); err == nil {
+ t.Fatal("duplicate-key frontmatter accepted")
+ }
+}
+
+// Review regressions from MUL-8095: every repair must parse, keep other
+// fields equal, and never touch a skill Codex already accepts.
+func TestNormalizeUserCodexSkillContentRepairsEveryMappingStyle(t *testing.T) {
+ cases := []struct {
+ name, in string
+ check func(t *testing.T, out string, fm map[string]any)
+ }{
+ {name: "flow mapping missing description", in: "---\n{name: alpha, allowed-tools: [Read]}\n---\nbody\n",
+ check: func(t *testing.T, out string, fm map[string]any) {
+ if tools, _ := fm["allowed-tools"].([]any); len(tools) != 1 || tools[0] != "Read" {
+ t.Fatalf("allowed-tools lost: %#v", fm)
+ }
+ }},
+ {name: "indented mapping missing description", in: "---\n name: alpha\n allowed-tools: [Read]\n---\nbody\n"},
+ {name: "anchored empty description keeps aliases and comment", in: "---\nname: alpha\ndescription: &shared \"\" # retain me\nmetadata:\n short-description: *shared\n---\nbody\n",
+ check: func(t *testing.T, out string, fm map[string]any) {
+ if md, _ := fm["metadata"].(map[string]any); md["short-description"] != "" {
+ t.Fatalf("alias value changed: %#v", fm)
+ }
+ if !strings.Contains(out, "# retain me") {
+ t.Fatalf("line comment lost: %s", out)
+ }
+ }},
+ {name: "non-string name replaced", in: "---\nname: [a]\ndescription: Demo\n---\nbody\n",
+ check: func(t *testing.T, out string, fm map[string]any) {
+ if fm["name"] != "alpha" {
+ t.Fatalf("name not repaired: %#v", fm)
+ }
+ }},
+ }
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ out, err := normalizeUserCodexSkillContent(tc.in, "alpha")
+ if err != nil {
+ t.Fatal(err)
+ }
+ raw, body, ok := frontmatterParts(out)
+ var fm map[string]any
+ if !ok || yaml.Unmarshal([]byte(raw), &fm) != nil {
+ t.Fatalf("repair produced invalid YAML:\n%s", out)
+ }
+ if d, _ := fm["description"].(string); strings.TrimSpace(d) == "" || body != "body\n" {
+ t.Fatalf("not loadable: %q", out)
+ }
+ if tc.check != nil {
+ tc.check(t, out, fm)
+ }
+ })
+ }
+}
+
+func TestNormalizeUserCodexSkillContentLeavesLoadableSkillsUntouched(t *testing.T) {
+ // Codex falls back to the directory name for a missing or blank name, so
+ // these already load and must stay linked byte-for-byte.
+ for _, in := range []string{
+ "---\n{description: Demo skill}\n---\nbody\n",
+ "---\ndescription: Demo skill\n---\nbody\n",
+ "---\nname: \"\"\ndescription: Demo skill\n---\nbody\n",
+ } {
+ out, err := normalizeUserCodexSkillContent(in, "alpha")
+ if err != nil || out != in {
+ t.Fatalf("loadable skill rewritten: %q -> %q (%v)", in, out, err)
+ }
+ }
+}
diff --git a/server/internal/daemon/execenv/execenv_test.go b/server/internal/daemon/execenv/execenv_test.go
index 6f924b2a2e..99bdb1ca75 100644
--- a/server/internal/daemon/execenv/execenv_test.go
+++ b/server/internal/daemon/execenv/execenv_test.go
@@ -4872,8 +4872,8 @@ func TestPrepareCodexSeedsUserSkills(t *testing.T) {
if data, err := os.ReadFile(filepath.Join(env.CodexHome, "skills", "summarize", "SKILL.md")); err != nil {
t.Fatalf("user skill SKILL.md not seeded: %v", err)
- } else if string(data) != "summarize" {
- t.Errorf("summarize SKILL.md = %q, want %q", data, "summarize")
+ } else if !strings.HasSuffix(string(data), "summarize") || !strings.Contains(string(data), "name: summarize") || !strings.Contains(string(data), "description:") {
+ t.Errorf("summarize SKILL.md not normalized: %q", data)
}
if data, err := os.ReadFile(filepath.Join(env.CodexHome, "skills", "summarize", "examples", "ex.md")); err != nil {
t.Fatalf("user skill support file not seeded: %v", err)
@@ -4882,8 +4882,8 @@ func TestPrepareCodexSeedsUserSkills(t *testing.T) {
}
if data, err := os.ReadFile(filepath.Join(env.CodexHome, "skills", "translate", "SKILL.md")); err != nil {
t.Fatalf("second user skill not seeded: %v", err)
- } else if string(data) != "translate" {
- t.Errorf("translate SKILL.md = %q, want %q", data, "translate")
+ } else if !strings.HasSuffix(string(data), "translate") || !strings.Contains(string(data), "name: translate") || !strings.Contains(string(data), "description:") {
+ t.Errorf("translate SKILL.md not normalized: %q", data)
}
if _, err := os.Stat(filepath.Join(env.CodexHome, "skills", ".DS_Store")); !os.IsNotExist(err) {
t.Errorf("ignored dotfile leaked into codex-home/skills: err=%v", err)
@@ -4985,10 +4985,11 @@ func TestPrepareCodexResolvesUserSkillSymlinks(t *testing.T) {
t.Setenv("CODEX_HOME", sharedHome)
installerRoot := filepath.Join(t.TempDir(), "installer", "lark-mail")
+ const skillContent = "---\nname: lark-mail\ndescription: Mail instructions\n---\nlark"
if err := os.MkdirAll(installerRoot, 0o755); err != nil {
t.Fatalf("seed installer dir: %v", err)
}
- if err := os.WriteFile(filepath.Join(installerRoot, "SKILL.md"), []byte("lark"), 0o644); err != nil {
+ if err := os.WriteFile(filepath.Join(installerRoot, "SKILL.md"), []byte(skillContent), 0o644); err != nil {
t.Fatalf("seed installer SKILL.md: %v", err)
}
@@ -5032,8 +5033,8 @@ func TestPrepareCodexResolvesUserSkillSymlinks(t *testing.T) {
if err != nil {
t.Fatalf("seeded SKILL.md missing: %v", err)
}
- if string(data) != "lark" {
- t.Errorf("seeded SKILL.md = %q, want %q", data, "lark")
+ if string(data) != skillContent {
+ t.Errorf("seeded SKILL.md = %q, want %q", data, skillContent)
}
}
@@ -5081,8 +5082,9 @@ func TestReuseSeedsUserSkillUpdates(t *testing.T) {
if err != nil {
t.Fatalf("user skill not refreshed on reuse: %v", err)
}
- if string(data) != "v2" {
- t.Errorf("after Reuse, user skill content = %q, want %q", data, "v2")
+ want := synthesizeFrontmatter("v2", "summarize", "Instructions for the summarize skill.")
+ if string(data) != want {
+ t.Errorf("after Reuse, user skill content = %q, want %q", data, want)
}
}