diff --git a/apps/albedo/test/albedo/composition/skills_test.gleam b/apps/albedo/test/albedo/composition/skills_test.gleam index 6ce9eba0f..93f56ebb9 100644 --- a/apps/albedo/test/albedo/composition/skills_test.gleam +++ b/apps/albedo/test/albedo/composition/skills_test.gleam @@ -1,10 +1,17 @@ //// Skill metadata cannot forge model context. Direct parser cases cover YAML //// term ambiguity and exact byte/scalar limits without repeated daemon setup. +//// Every skill albedo ships parses into the catalog, and the frontmatter +//// parser neither crashes nor hangs on arbitrary bytes. +import albedo_file/info as file_info +import albedo_property import albedo_sdk/skills/catalog import albedo_sdk/skills/frontmatter +import gleam/bit_array +import gleam/list import gleam/string import gleeunit/should +import qcheck @external(erlang, "albedo_skills_test_support", "fixture") fn fixture() -> #(String, String, String) @@ -111,3 +118,68 @@ fn for_metadata( directory_name, ) } + +/// Every directory under priv/skills is a valid, uniquely named skill with +/// its own slash command. No list of names is kept here: a new shipped skill +/// is checked as soon as it exists. +pub fn every_shipped_skill_is_in_the_catalog_test() -> Nil { + let builtin = catalog.native_builtin() + assert builtin != "" + let assert Ok(entries) = file_info.list(builtin) + let shipped = list.sort(entries, string.compare) + assert shipped != [] + let #(root, workspace, home) = fixture() + let assert Ok(found) = catalog.scan_at(workspace, home, builtin, readable: Ok) + cleanup(root) + assert found.diagnostics == [] + let names = + list.map(found.skills, fn(skill) { skill.name }) + |> list.sort(string.compare) + assert names == shipped + list.each(found.skills, fn(skill) { + assert skill.scope == catalog.BuiltIn + assert string.trim(skill.description) != "" + }) + let commands = + catalog.commands(found) |> list.map(fn(command) { command.command }) + assert list.length(list.unique(commands)) == list.length(shipped) +} + +/// Untrusted SKILL.md bytes, mostly shaped like frontmatter, either parse or +/// are refused with a diagnostic. +pub fn frontmatter_parser_answers_every_input_test_() -> albedo_property.Timed { + use <- albedo_property.within(120) + let piece = + qcheck.from_generators(qcheck.return(<<"---\n":utf8>>), [ + qcheck.return(<<"name: ":utf8>>), + qcheck.return(<<"description: ":utf8>>), + qcheck.return(<<"\n":utf8>>), + qcheck.return(<<"\r\n":utf8>>), + qcheck.return(<<"- ":utf8>>), + qcheck.return(<<"&a ":utf8>>), + qcheck.return(<<"*a":utf8>>), + qcheck.return(<<"!!binary ":utf8>>), + qcheck.return(<<"[{":utf8>>), + qcheck.return(<<"\"\\u00":utf8>>), + qcheck.return(<<" ":utf8>>), + qcheck.return(<<255, 0>>), + qcheck.map(qcheck.string(), bit_array.from_string), + qcheck.byte_aligned_bit_array(), + ]) + use bytes <- albedo_property.run( + 2000, + qcheck.map( + qcheck.generic_list(piece, qcheck.bounded_int(0, 24)), + bit_array.concat, + ), + ) + case frontmatter.parse(bytes, "fallback") { + Ok(#(name, description)) -> { + assert name != "" + assert string.trim(description) != "" + } + Error(message) -> { + assert message != "" + } + } +} diff --git a/e2e/extensions_test.py b/e2e/extensions_test.py index 9a032ce01..ec015fe62 100644 --- a/e2e/extensions_test.py +++ b/e2e/extensions_test.py @@ -533,17 +533,6 @@ class ExtensionTests(unittest.TestCase): self.assertIn("[older conversation summary;", json.dumps(sent)) self.assertEqual(second["input"][: len(sent)], sent) - def test_every_shipped_skill_loads(self): - self.reload() - shipped = sorted( - path.name - for path in ( - Path(__file__).parents[1] / "apps/albedo/priv/skills" - ).iterdir() - ) - listed = {c["slash_name"] for c in self.commands()} - self.assertEqual([name for name in shipped if f"/{name}" not in listed], []) - def test_builtin_skill_is_listed_and_yields_to_a_workspace_skill_of_the_same_name( self, ):