Files
last30days-skill/tests/test_plugin_contract.py
T
Trevin Chow 997708ad48 refactor(skill): apply ce-code-review fixes — bump to 3.2.2, fallback tests, comparison resolver
12 fixes from the multi-agent code review on PR #400:

Version 3.2.1 -> 3.2.2 across all manifests (SKILL.md frontmatter + body
header, pyproject.toml, .claude-plugin/{plugin,marketplace}.json, sync.sh
cache path). The PR ships observable behavior changes (STEP 0 logic flip,
resolver order change, badge fallback) that should not silently appear
under the same version number — the new fallback reads SKILL.md version
directly so the badge would otherwise be misleading.

render.py::_skill_version:
- `import re` moved to module top
- _VERSION_RE extracted as a module-level compiled pattern that accepts
  double-quoted, single-quoted, and unquoted YAML version scalars
- `break` -> `continue` on corrupt manifest, so a corrupt inner manifest
  no longer shadows a valid outer one
- Wrap SKILL.md read_text() in try/except for UnicodeDecodeError to keep
  badge emission from crashing on mis-encoded SKILL.md
- Docstring clarifies precedence; inline comment marks the fallback boundary
  between the manifest walk and the SKILL.md walk

tests/test_skill_version.py (new): 7 unit tests for the fallback paths
(manifest absent, manifest corrupt, corrupt-inner + valid-outer, both
absent, SKILL.md without version, single-quoted, unquoted).

tests/test_plugin_contract.py: tombstone test asserting .codex-plugin/
stays removed (was the only CI guard against accidental reintroduction).

SKILL.md:
- STEP 0 bash echoes CLAUDE_CACHE_LATEST so the model can see the
  resolved value when deciding whether to hop
- "Both shapes ship in the wild" comment now names the two cache layouts
  (nested {cache}/{version}/skills/last30days/ vs flat {cache}/{version}/)
- Comparison-mode bash invocation gets its own inline SKILL_ROOT resolver
  (latent gap: the contract tells the model to skip Step 1 on comparison
  queries, so SKILL_ROOT was previously unset there)

CHANGELOG.md: [Unreleased] entries for the resolver rewrite and the
breaking removal of Codex native-plugin support.

All 9 reviewer personas surfaced findings; 3 cross-reviewer corroboration
clusters were promoted (import re, "both shapes" comment, missing fallback
tests). Maintainability follow-up flagged: regex now duplicated across
render.py and 2 test files; could consolidate via shared lib/skill_meta.py
helper in a future PR.
2026-05-15 21:45:25 -07:00

63 lines
2.4 KiB
Python

import json
import re
import tomllib
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SKILL_ROOT = ROOT / "skills" / "last30days"
def _json(path: Path) -> dict:
return json.loads(path.read_text(encoding="utf-8"))
def _skill_version() -> str:
text = (SKILL_ROOT / "SKILL.md").read_text(encoding="utf-8")
match = re.search(r'^version:\s*"([^"]+)"\s*$', text, re.MULTILINE)
if not match:
raise AssertionError("SKILL.md version frontmatter not found")
return match.group(1)
class TestPluginContract(unittest.TestCase):
def test_codex_plugin_scaffold_stays_removed(self) -> None:
# .codex-plugin/ was removed in the resolver-collapse refactor; Codex users
# install via `npx skills add` or `~/.codex/skills/`. A reintroduction would
# silently fork the install surface.
self.assertFalse((ROOT / ".codex-plugin").exists())
def test_versions_match_across_manifests(self) -> None:
pyproject = tomllib.loads((ROOT / "pyproject.toml").read_text(encoding="utf-8"))
version = pyproject["project"]["version"]
self.assertEqual(version, _skill_version())
self.assertEqual(version, _json(ROOT / ".claude-plugin" / "plugin.json")["version"])
marketplace = _json(ROOT / ".claude-plugin" / "marketplace.json")
plugins = marketplace.get("plugins") or []
self.assertEqual(1, len(plugins))
self.assertEqual(version, plugins[0]["version"])
def test_claude_marketplace_has_current_schema_shape(self) -> None:
marketplace = _json(ROOT / ".claude-plugin" / "marketplace.json")
self.assertNotIn("$schema", marketplace)
self.assertNotIn("description", marketplace)
self.assertIn("metadata", marketplace)
self.assertIn("description", marketplace["metadata"])
def test_workflows_do_not_reference_removed_root_scripts_dir(self) -> None:
offenders = []
for path in sorted((ROOT / ".github" / "workflows").glob("*.yml")):
for line_number, line in enumerate(path.read_text(encoding="utf-8").splitlines(), start=1):
if "scripts/" in line and "skills/last30days/scripts/" not in line:
offenders.append(f"{path.relative_to(ROOT)}:{line_number}: {line.strip()}")
self.assertEqual([], offenders)
if __name__ == "__main__":
unittest.main()