Enforce LF-only SKILL.md frontmatter
The contract stated an LF rule the checker only enforced by accident: CRLF on a single line, a lone CR, a Unicode line separator, or CRLF on a delimiter passed. Require LF delimiters and LF-only frontmatter lines, and test each case. Every package in every tag v0.1.0-v0.14.0 still passes. The contract now names the required frontmatter keys and shows runnable check and pack commands. Refs #20 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f872770dc9
commit
45eff20ecb
3 files changed
+38
-10
No files matched your search
@@ -237,10 +237,26 @@ class RoleStepRejectionTests(unittest.TestCase):
|
||||
copy.replace_in_skill(old, new)
|
||||
self.assertRejected(copy, message)
|
||||
|
||||
def test_frontmatter_lines_end_in_lf_only(self):
|
||||
def replace_bytes(old, new, count=1):
|
||||
return lambda copy: copy.write_file("SKILL.md", (copy.path / "SKILL.md").read_bytes().replace(old, new, count))
|
||||
cases = (
|
||||
("CRLF throughout", replace_bytes(b"\n", b"\r\n", -1)),
|
||||
("CRLF after description", replace_bytes(b"\nmetadata:", b"\r\nmetadata:")),
|
||||
("lone CR after description", replace_bytes(b"\nmetadata:", b"\rmetadata:")),
|
||||
("U+2028 after description", replace_bytes(b"\nmetadata:", "\u2028metadata:".encode())),
|
||||
("CRLF on opening delimiter", replace_bytes(b"---\n", b"---\r\n")),
|
||||
("CRLF on closing delimiter", replace_bytes(b"\n---\n", b"\n---\r\n")),
|
||||
)
|
||||
for name in NEW_PAIR_FIXTURES:
|
||||
for label, mutate in cases:
|
||||
with self.subTest(name=name, case=label), FixtureCopy(name) as copy:
|
||||
mutate(copy)
|
||||
self.assertRejected(copy, "frontmatter|skill metadata")
|
||||
|
||||
def test_rejects_unsafe_or_undeclared_content(self):
|
||||
cases = (
|
||||
("BOM", lambda copy: copy.write_file("SKILL.md", b"\xef\xbb\xbf" + (copy.path / "SKILL.md").read_bytes()), "invalid text"),
|
||||
("CRLF frontmatter", lambda copy: copy.write_file("SKILL.md", (copy.path / "SKILL.md").read_bytes().replace(b"\n", b"\r\n")), "incompatible skill metadata"),
|
||||
("NUL", lambda copy: copy.write_file("notes.md", "a\x00b\n"), "invalid text"),
|
||||
("invalid UTF-8", lambda copy: copy.write_file("notes.md", b"\xff\xfe\n"), "invalid UTF-8"),
|
||||
("empty resource", lambda copy: copy.write_file("notes.md", b""), "text bounds"),
|
||||
|
||||
Reference in new issue
Block a user