1
0

test_bootstrap.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import importlib
  2. import os
  3. import sys
  4. import pytest
  5. sys.path.insert(0, os.path.abspath(
  6. os.path.join(os.path.dirname(__file__), "../../.hermes-plugin")
  7. ))
  8. BOOTSTRAP_MARKER = "superpowers:using-superpowers bootstrap for hermes"
  9. # Hermes spills injected context over 10,000 chars to a file, which breaks
  10. # inline injection semantics. The bootstrap must stay under it with margin.
  11. HERMES_CONTEXT_SPILL_LIMIT = 10_000
  12. def _load():
  13. if "__init__" in sys.modules:
  14. del sys.modules["__init__"]
  15. return importlib.import_module("__init__")
  16. def _bootstrap():
  17. m = _load()
  18. return m._build_bootstrap(m._skills_dir())
  19. class TestStripFrontmatter:
  20. def test_strips_yaml_block(self):
  21. m = _load()
  22. content = "---\nname: foo\ndescription: bar\n---\n# Body\nContent here"
  23. assert m._strip_frontmatter(content) == "# Body\nContent here"
  24. def test_no_frontmatter_returns_trimmed_content(self):
  25. m = _load()
  26. content = "# No frontmatter\nJust content"
  27. assert m._strip_frontmatter(content) == "# No frontmatter\nJust content"
  28. def test_strips_surrounding_whitespace_from_body(self):
  29. m = _load()
  30. content = "---\nname: foo\n---\n\n\n# Body\n\n"
  31. assert m._strip_frontmatter(content) == "# Body"
  32. class TestSkillsDirResolution:
  33. def test_repo_layout_resolves(self):
  34. # The repo checkout IS the git-clone layout: .hermes-plugin/ and
  35. # skills/ are siblings, so resolution must succeed from here.
  36. m = _load()
  37. skills = m._skills_dir()
  38. assert os.path.isfile(
  39. os.path.join(skills, "using-superpowers", "SKILL.md")
  40. )
  41. class TestBootstrapContent:
  42. def test_marker_and_wrapper(self):
  43. content = _bootstrap()
  44. assert BOOTSTRAP_MARKER in content
  45. assert content.startswith("<EXTREMELY_IMPORTANT>")
  46. assert content.rstrip().endswith("</EXTREMELY_IMPORTANT>")
  47. def test_contains_using_superpowers_body(self):
  48. content = _bootstrap()
  49. # A distinctive line from the skill body proves the real SKILL.md was
  50. # embedded, not a stub.
  51. assert "You have superpowers" in content
  52. assert "## The Rule" in content
  53. def test_frontmatter_stripped(self):
  54. content = _bootstrap()
  55. assert "---\nname:" not in content
  56. def test_tool_mapping_sourced_from_reference_file(self):
  57. m = _load()
  58. content = _bootstrap()
  59. ref = os.path.join(
  60. m._skills_dir(), "using-superpowers", "references", "hermes-tools.md"
  61. )
  62. with open(ref, encoding="utf-8") as f:
  63. ref_text = f.read().strip()
  64. # The mapping is included verbatim from the reference file — the
  65. # single source, not a drift-prone inline copy.
  66. assert ref_text in content
  67. assert "read_file" in content
  68. def test_skill_view_guidance_present(self):
  69. content = _bootstrap()
  70. assert 'skill_view("superpowers:brainstorming")' in content
  71. def test_under_hermes_context_spill_limit(self):
  72. content = _bootstrap()
  73. assert len(content) < HERMES_CONTEXT_SPILL_LIMIT, (
  74. f"bootstrap is {len(content)} chars; hermes spills injected "
  75. f"context over {HERMES_CONTEXT_SPILL_LIMIT} to a file, which "
  76. "breaks inline injection"
  77. )