Files
diagram-design/scripts/test-verify-semantic-motion.py
T
4faae6696c
CI / Plugin Package & Version Gate (push) Failing after 52s
CI / Python 3.9 Compatibility (push) Successful in 13s
CI / Lint & Verify (ubuntu-latest, Python 3.11) (push) Successful in 29s
Deploy gallery to GitHub Pages / build (push) Canceled after 0s
Deploy gallery to GitHub Pages / deploy (push) Canceled after 0s
CI / Lint & Verify (ubuntu-latest, Python 3.12) (push) Successful in 2m56s
CI / Lint & Verify (macos-latest, Python 3.11) (push) Canceled after 0s
CI / Lint & Verify (macos-latest, Python 3.12) (push) Canceled after 0s
CI / Lint & Verify (windows-latest, Python 3.11) (push) Canceled after 0s
CI / Lint & Verify (windows-latest, Python 3.12) (push) Canceled after 0s
Add adversarial tests for verify-semantic-motion.py and verify-sequence-oauth.py (#69)
* Add adversarial tests for verify-semantic-motion.py and verify-sequence-oauth.py

Every other verify-*.py in scripts/ has a matching test-verify-*.py
(verify-docs-sync, verify-geometry, verify-motion, verify-plugin-package),
and CONTRIBUTING.md lists both verify-semantic-motion.py and
verify-sequence-oauth.py as required PR gates, but neither had a dedicated
test file exercising its own pass/fail behavior.

- test-verify-semantic-motion.py: asserts the shipped SKILL.md /
  semantic-patterns.md / animation.md and the policy-trace animated example
  pass verify_markdown()/verify_example(), plus adversarial cases for a
  missing semantic-pattern router link, a missing pattern name, and a
  duplicate HTML/SVG id in the example.
- test-verify-sequence-oauth.py: CLI smoke-tests the shipped repo (expects
  ALL GATES PASSED) and an adversarial case that removes the dashed-return
  marker from the OAuth 401 response in a temporary copy of the repo tree
  (verify-sequence-oauth.py resolves paths from its own __file__, so the
  adversarial run executes the copied script against the copied tree).

Also wires both new tests into CONTRIBUTING.md's gate table and combined
validation command, following the exact pattern used for the existing
test-verify-*.py gates. (CI workflow wiring left out of this PR since it
touches .github/workflows/ci.yml — happy to add in a follow-up if useful.)

* Address review feedback on PR #69

- Wire test-verify-semantic-motion.py and test-verify-sequence-oauth.py
  into .github/workflows/ci.yml so CONTRIBUTING's new gates actually run
  in CI, with matching step-summary rows.
- Bump .claude-plugin/plugin.json and .codex-plugin/plugin.json in sync
  to 2.5.7 so scripts/verify-plugin-package.py origin/main passes again.
- Simplify test-verify-sequence-oauth.py's adversarial fixture to copy
  only the files verify-sequence-oauth.py's main() reads before the
  dashed-return check (type-sequence.md + cold-cache/oauth example
  trios), instead of shutil.copytree of the whole repository.

* Re-bump plugin manifests above current main

The prior 2.5.7 bump was superseded by subsequent merges of main into
this branch (main itself advanced past it to 2.6.5). Re-run
bump-plugin-version.py so the branch is strictly above upstream main
again (2.6.6), per @philyuchkoff's review: the diff had settled back
to no version delta at all.

---------

Co-authored-by: alvinhui <alvinhui@users.noreply.github.com>
Co-authored-by: Cathryn Lavery <50469282+cathrynlavery@users.noreply.github.com>
2026-08-25 01:57:59 -05:00

116 lines
4.6 KiB
Python

#!/usr/bin/env python3
"""Regression tests for verify-semantic-motion.py.
Covers the two entry points (verify_markdown, verify_example) against the
shipped skill docs / animated example, plus a handful of adversarial cases
that mirror the pattern used by test-verify-docs-sync.py and
test-verify-motion.py for the other verifiers in this repo.
"""
from __future__ import annotations
import importlib.util
import sys
import tempfile
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
VERIFIER = ROOT / "scripts/verify-semantic-motion.py"
def load_verifier():
sys.dont_write_bytecode = True
spec = importlib.util.spec_from_file_location(
"diagram_design_verify_semantic_motion", VERIFIER
)
if spec is None or spec.loader is None:
raise AssertionError("could not load verify-semantic-motion.py")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
def main() -> int:
module = load_verifier()
# Shipped docs and example must pass as-is.
markdown_errors = module.verify_markdown()
if markdown_errors:
raise AssertionError(f"shipped skill docs failed verify_markdown: {markdown_errors}")
print("OK: shipped SKILL.md / semantic-patterns.md / animation.md pass verify_markdown")
example_errors = module.verify_example()
if example_errors:
raise AssertionError(f"shipped example failed verify_example: {example_errors}")
print("OK: shipped policy-trace example passes verify_example")
original_skill = module.SKILL
try:
with tempfile.TemporaryDirectory(prefix="verify-semantic-motion-") as temp_dir:
scratch = Path(temp_dir)
# Missing semantic-pattern router link must be rejected.
missing_router = scratch / "missing-router.md"
missing_router.write_text(
original_skill.read_text(encoding="utf-8").replace(
"semantic-patterns.md", "patterns.md"
),
encoding="utf-8",
)
module.SKILL = missing_router
errors = module.verify_markdown()
if not any("must link to semantic-patterns.md" in error for error in errors):
raise AssertionError(f"missing semantic router was accepted: {errors}")
print("OK: missing semantic-pattern router link is rejected")
# Dropping one of the seven named patterns must be rejected.
missing_pattern = scratch / "missing-pattern.md"
missing_pattern.write_text(
original_skill.read_text(encoding="utf-8").replace(
"Fan-in queue / bottleneck", "Fan-in queue removed"
),
encoding="utf-8",
)
module.SKILL = missing_pattern
errors = module.verify_markdown()
if not any(
"does not route semantic pattern: Fan-in queue / bottleneck" in error
for error in errors
):
raise AssertionError(f"missing semantic pattern was accepted: {errors}")
print("OK: missing semantic-pattern name is rejected")
finally:
module.SKILL = original_skill
# A duplicated HTML/SVG id in the animated example must be rejected.
with tempfile.TemporaryDirectory(prefix="verify-semantic-motion-example-") as temp_dir:
source = module.EXAMPLE.read_text(encoding="utf-8")
first_id_start = source.find(' id="')
if first_id_start < 0:
raise AssertionError("shipped example unexpectedly has no id attributes to duplicate")
# Re-use an existing id value on a second, unrelated element to force a collision.
quote_start = first_id_start + len(' id="')
quote_end = source.find('"', quote_start)
duplicated_id = source[quote_start:quote_end]
insertion_point = source.rfind("</body>")
if insertion_point < 0:
raise AssertionError("shipped example unexpectedly has no </body> to anchor the test")
broken = (
source[:insertion_point]
+ f'<div id="{duplicated_id}"></div>'
+ source[insertion_point:]
)
broken_path = Path(temp_dir) / "duplicate-id.html"
broken_path.write_text(broken, encoding="utf-8")
errors = module.verify_example(broken_path)
if not any("duplicate HTML/SVG IDs" in error for error in errors):
raise AssertionError(f"duplicate id was accepted: {errors}")
print("OK: duplicate HTML/SVG id in the animated example is rejected")
print("All semantic-motion verifier tests passed.")
return 0
if __name__ == "__main__":
sys.exit(main())