Skip to content

Commit c816645

Browse files
committed
test(skills): cover frontmatter edge cases
Signed-off-by: phernandez <paul@basicmachines.co>
1 parent a45fa07 commit c816645

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

scripts/validate_skills.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
PLAIN_SCALAR_MAPPING_VALUE = re.compile(r":(?:\s|$)")
1212

1313

14+
def strip_matching_quotes(value: str) -> str:
15+
if len(value) >= 2 and value[0] == value[-1] and value[0] in {'"', "'"}:
16+
return value[1:-1]
17+
return value
18+
19+
1420
def validate_plain_scalar(path: Path, line_number: int, key: str, value: str) -> None:
1521
"""Catch invalid plain-scalar YAML that Codex rejects while loading skills."""
1622
stripped = value.strip()
@@ -50,7 +56,7 @@ def parse_frontmatter(path: Path) -> dict[str, str]:
5056
key = key.strip()
5157
value = value.strip()
5258
validate_plain_scalar(path, line_number, key, value)
53-
frontmatter[key] = value.strip('"')
59+
frontmatter[key] = strip_matching_quotes(value)
5460
else:
5561
raise SystemExit(f"{path}: unclosed YAML frontmatter")
5662

tests/ci/test_validate_skills.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,48 @@ def test_parse_frontmatter_rejects_unquoted_mapping_colon(tmp_path: Path) -> Non
2525
parse_frontmatter(skill)
2626

2727

28+
def test_parse_frontmatter_allows_url_colons_in_plain_values(tmp_path: Path) -> None:
29+
skill = tmp_path / "SKILL.md"
30+
skill.write_text(
31+
"\n".join(
32+
[
33+
"---",
34+
"name: memory-notes",
35+
"description: See https://docs.basicmemory.com for usage.",
36+
"---",
37+
"# Skill",
38+
"",
39+
]
40+
),
41+
encoding="utf-8",
42+
)
43+
44+
frontmatter = parse_frontmatter(skill)
45+
46+
assert frontmatter["description"] == "See https://docs.basicmemory.com for usage."
47+
48+
49+
def test_parse_frontmatter_strips_matching_single_quotes(tmp_path: Path) -> None:
50+
skill = tmp_path / "SKILL.md"
51+
skill.write_text(
52+
"\n".join(
53+
[
54+
"---",
55+
"name: memory-notes",
56+
"description: 'Use when values contain mapping-like text: safely.'",
57+
"---",
58+
"# Skill",
59+
"",
60+
]
61+
),
62+
encoding="utf-8",
63+
)
64+
65+
frontmatter = parse_frontmatter(skill)
66+
67+
assert frontmatter["description"] == "Use when values contain mapping-like text: safely."
68+
69+
2870
def test_parse_frontmatter_keeps_nested_fields_nested(tmp_path: Path) -> None:
2971
schema = tmp_path / "schema.md"
3072
schema.write_text(
@@ -47,3 +89,4 @@ def test_parse_frontmatter_keeps_nested_fields_nested(tmp_path: Path) -> None:
4789

4890
assert frontmatter["type"] == "schema"
4991
assert frontmatter["entity"] == "Task"
92+
assert frontmatter["schema"] == ""

0 commit comments

Comments
 (0)