"""Size guard: fail when a Spire skill or agent file nears the character cut. Cut is 20,000 characters (len() of decoded text); fail at 90%. """ import unittest from pathlib import Path PLUGIN = Path(__file__).resolve().parent.parent CUT = 20_000 FAIL_AT = int(CUT * 0.9) def files(): return sorted([*PLUGIN.glob("skills/*/SKILL.md"), *PLUGIN.glob("agents/*.md")]) class SizeTest(unittest.TestCase): def test_sizes(self): found = files() self.assertTrue(found, "no skill or agent files found") over = [] for f in found: n = len(f.read_text(encoding="utf-8")) pct = 100 * n / CUT print(f"{pct:5.1f}% {n:6d} {f.relative_to(PLUGIN)}") if n >= FAIL_AT: over.append(f"{f.relative_to(PLUGIN)}: {n} chars ({pct:.1f}% of {CUT})") self.assertFalse(over, f"files at or over {FAIL_AT} chars:\n" + "\n".join(over)) if __name__ == "__main__": unittest.main()