Universal SEO skill for Claude Code. 26 sub-skills + 19 sub-agents covering technical SEO, E-E-A-T, schema, GEO/AEO, agent readiness (Lighthouse Agentic Browsing, WebMCP, llms.txt), backlinks, local SEO, e-commerce, international SEO, Google APIs, and PDF/Excel reporting. 9 optional extensions for live SEO data.
fix(schema): cover @graph type lists, scope the hook skip, harden validators
Agrici Daniel1feb929fef6e
diff --git a/hooks/run-python-hook.js b/hooks/run-python-hook.jsindex 67e7dff..4c07b41 100644--- a/hooks/run-python-hook.js+++ b/hooks/run-python-hook.js@@ -2,11 +2,19 @@"use strict";const { spawnSync } = require("child_process");+const path = require("path");// Same list as valid_extensions in validate-schema.py. The hook fires on every// Edit and Write, so skip the Python probe for files that cannot hold JSON-LD.const SCHEMA_FILE_EXTENSIONS = [".html", ".htm", ".jsx", ".tsx", ".vue", ".svelte", ".php", ".ejs"];+// The skip belongs to the schema hook only; any other hook script always runs.+const SCHEMA_HOOK_SCRIPT = "validate-schema.py";++function isSchemaHook(hookScript) {+ return path.basename(hookScript) === SCHEMA_HOOK_SCRIPT;+}+function cannotHoldSchema(filePath) {// An unsubstituted "${tool_input.file_path}" leaves the path to the stdin event.if (!filePath || filePath.includes("${")) {@@ -52,7 +60,7 @@ function probe(candidate) {function main() {const [, , hookScript, ...hookArgs] = process.argv;- if (!hookScript || cannotHoldSchema(hookArgs[0])) {+ if (!hookScript || (isSchemaHook(hookScript) && cannotHoldSchema(hookArgs[0]))) {process.exit(0);}diff --git a/hooks/validate-schema.py b/hooks/validate-schema.pyindex e065c00..a5aa12b 100755--- a/hooks/validate-schema.py+++ b/hooks/validate-schema.py@@ -195,10 +195,10 @@ def _validate_schema_object() -> List[str]:"""Validate one schema node, including members of a top-level ``@graph``.- @param obj: JSON-LD node to validate.- @param block_num: Script block number used in diagnostics.- @param inherited_context: Whether the node inherits its context from a graph.- @returns: Validation errors and warnings for the node and its graph members.+ ``obj`` is the JSON-LD node and ``block_num`` is the script block number+ used in diagnostics. ``inherited_context`` is set for a node that takes its+ context from an enclosing graph. Returns the errors and warnings for the+ node and its graph members."""errors = []prefix = f"Block {block_num}"@@ -236,11 +236,15 @@ def _validate_schema_object(errors.append(f"{prefix}: @type must be a non-empty string or a non-empty list of non-empty strings")- schema_types = [- schema_type- for schema_type in schema_types- if isinstance(schema_type, str) and schema_type.strip()- ]+ # dict.fromkeys drops repeats and keeps order, so ["HowTo", "HowTo"] is+ # reported once.+ schema_types = list(+ dict.fromkeys(+ schema_type+ for schema_type in schema_types+ if isinstance(schema_type, str) and schema_type.strip()+ )+ )deprecated = {"HowTo": "deprecated September 2023","SpecialAnnouncement": "deprecated July 31, 2025",diff --git a/scripts/schema_ecommerce_validate.py b/scripts/schema_ecommerce_validate.pyindex 6df87b5..b71344b 100644--- a/scripts/schema_ecommerce_validate.py+++ b/scripts/schema_ecommerce_validate.py@@ -111,7 +111,7 @@ def _as_dicts(value) -> list[dict]:def _has_loyalty_price(offer: dict) -> bool:return any(- spec.get("@type") == "UnitPriceSpecification" and spec.get("validForMemberTier")+ _has_type(spec, "UnitPriceSpecification") and spec.get("validForMemberTier")for spec in _as_dicts(offer.get("priceSpecification")))@@ -175,6 +175,12 @@ def validate(payload: dict | list, *, require_eu_energy: bool = False) -> dict:for offer in offers_list:if not isinstance(offer, dict):+ findings.append({+ "severity": "High",+ "rule": "malformed-offer",+ "message": "Each entry in offers must be a JSON object, "+ f"got {type(offer).__name__}.",+ })continueif _has_type(offer, "AggregateOffer"):findings.append({@@ -197,9 +203,13 @@ def validate(payload: dict | list, *, require_eu_energy: bool = False) -> dict:"message": f"Offer is missing recommended {field!r}.",})+ # Non-object offers were reported above; the offer-level fallbacks+ # below read the first offer that is an object.+ first_offer = next((o for o in offers_list if isinstance(o, dict)), {})+# 4. hasMerchantReturnPolicy (recommended or conditional).- return_policy = prod.get("hasMerchantReturnPolicy") or (- offers_list[0].get("hasMerchantReturnPolicy") if offers_list else None+ return_policy = prod.get("hasMerchantReturnPolicy") or first_offer.get(+ "hasMerchantReturnPolicy")if not return_policy:findings.append({@@ -218,9 +228,7 @@ def validate(payload: dict | list, *, require_eu_energy: bool = False) -> dict:})# 5. shippingDetails (recommended or conditional).- shipping = prod.get("shippingDetails") or (- offers_list[0].get("shippingDetails") if offers_list else None- )+ shipping = prod.get("shippingDetails") or first_offer.get("shippingDetails")if not shipping:findings.append({"severity": "Medium",diff --git a/scripts/validate_backlink_report.py b/scripts/validate_backlink_report.pyindex 25bae48..69c551c 100644--- a/scripts/validate_backlink_report.py+++ b/scripts/validate_backlink_report.py@@ -56,11 +56,11 @@ def validate_schema_claims(parsed_data: dict) -> list:"message": f"Schema block missing @type. Keys present: {list(s.keys())[:5]}",})+ # @type arrays like ["Product", "ItemPage"] are valid, so check every+ # member: a deprecated type inside a list must still be flagged.schema_type = s.get("@type", "")- if isinstance(schema_type, list):- # @type arrays like ["Product", "ItemPage"] are valid- pass- elif schema_type in ("HowTo",):+ schema_types = schema_type if isinstance(schema_type, list) else [schema_type]+ if "HowTo" in schema_types:issues.append({"severity": "error","field": f"schema[{i}]",diff --git a/tests/test_cross_platform_hooks.py b/tests/test_cross_platform_hooks.pyindex ac1d08e..6063a81 100644--- a/tests/test_cross_platform_hooks.py+++ b/tests/test_cross_platform_hooks.py@@ -55,7 +55,7 @@ def test_hook_launcher_preserves_blocking_exit_code_two(tmp_path: Path) -> None:script = tmp_path / "block.py"script.write_text("import sys\n"- "assert sys.argv[1] == 'page.html'\n"+ "assert sys.argv[1] == 'payload'\n""sys.exit(2)\n",encoding="utf-8",)@@ -63,7 +63,7 @@ def test_hook_launcher_preserves_blocking_exit_code_two(tmp_path: Path) -> None:env["CLAUDE_SEO_PYTHON"] = sys.executableproc = subprocess.run(- [node, str(HOOK_LAUNCHER), str(script), "page.html"],+ [node, str(HOOK_LAUNCHER), str(script), "payload"],env=env,capture_output=True,text=True,@@ -78,7 +78,9 @@ def test_hook_launcher_skips_files_that_cannot_hold_schema(tmp_path: Path) -> Noif not node:pytest.skip("node is not available in this test environment")- script = tmp_path / "block.py"+ # The skip is keyed on the script's basename, so the stand-in carries the+ # schema hook's name.+ script = tmp_path / "validate-schema.py"script.write_text("import sys\nsys.exit(2)\n", encoding="utf-8")env = os.environ.copy()env["CLAUDE_SEO_PYTHON"] = sys.executable@@ -100,6 +102,28 @@ def test_hook_launcher_skips_files_that_cannot_hold_schema(tmp_path: Path) -> Noassert run("${tool_input.file_path}") == 2+def test_hook_launcher_extension_skip_applies_only_to_schema_hook(tmp_path: Path) -> None:+ node = shutil.which("node")+ if not node:+ pytest.skip("node is not available in this test environment")++ script = tmp_path / "other-hook.py"+ script.write_text("import sys\nsys.exit(2)\n", encoding="utf-8")+ env = os.environ.copy()+ env["CLAUDE_SEO_PYTHON"] = sys.executable++ # Any other hook script runs whatever the file argument looks like.+ for path_arg in ("notes.md", "app/main.py", "page.html"):+ proc = subprocess.run(+ [node, str(HOOK_LAUNCHER), str(script), path_arg],+ env=env,+ capture_output=True,+ text=True,+ timeout=15,+ )+ assert proc.returncode == 2, path_arg++def test_hook_launcher_extensions_match_validator() -> None:launcher = HOOK_LAUNCHER.read_text(encoding="utf-8")validator = (REPO_ROOT / "hooks" / "validate-schema.py").read_text(encoding="utf-8")diff --git a/tests/test_schema_hook_policy.py b/tests/test_schema_hook_policy.pyindex e173c77..e7c4cd2 100644--- a/tests/test_schema_hook_policy.py+++ b/tests/test_schema_hook_policy.py@@ -104,11 +104,7 @@ def test_schema_type_array_is_validated_without_crashing(tmp_path: Path) -> Nonedef test_schema_type_rejects_malformed_values(tmp_path: Path) -> None:- """Report malformed @type values instead of silently accepting them.-- @param tmp_path: Pytest-managed directory for temporary HTML fixtures.- @returns: None.- """+ """Report malformed @type values instead of silently accepting them."""invalid_types = [1,{"@id": "Organization"},@@ -136,6 +132,39 @@ def test_deprecated_type_inside_array_is_still_blocked(tmp_path: Path) -> None:assert _run_payload(tmp_path, payload).returncode == 2+def test_repeated_deprecated_type_is_reported_once(tmp_path: Path) -> None:+ payload = {+ "@context": "https://schema.org",+ "@type": ["HowTo", "Organization", "HowTo"],+ "name": "Example",+ }+ result = _run_payload(tmp_path, payload, capture_output=True, encoding="utf-8")+ assert result.returncode == 2+ assert result.stderr.count("@type 'HowTo' is deprecated") == 1+++def test_list_valued_type_inside_graph_does_not_crash(tmp_path: Path) -> None:+ payload = {+ "@context": "https://schema.org",+ "@graph": [+ {"@type": ["LocalBusiness", "FinancialService"], "name": "Example Advisory"},+ ],+ }+ result = _run_payload(tmp_path, payload, capture_output=True, encoding="utf-8")+ assert "TypeError" not in result.stderr+ assert _clean(result)+++def test_deprecated_type_inside_a_graph_member_type_list_blocks(tmp_path: Path) -> None:+ payload = {+ "@context": "https://schema.org",+ "@graph": [{"@type": ["LocalBusiness", "ClaimReview"], "name": "Old markup"}],+ }+ result = _run_payload(tmp_path, payload, capture_output=True, encoding="utf-8")+ assert result.returncode == 2+ assert "ClaimReview" in result.stderr++def test_non_object_graph_members_are_reported_without_crashing(tmp_path: Path) -> None:payload = {"@context": "https://schema.org",diff --git a/tests/test_schema_v2.py b/tests/test_schema_v2.pyindex a75d0b4..1ef1f5e 100644--- a/tests/test_schema_v2.py+++ b/tests/test_schema_v2.py@@ -214,6 +214,49 @@ def test_validate_price_specification_list_without_loyalty_is_reported() -> Noneassert "missing-member-program" in rules+def test_validate_loyalty_price_accepts_list_valued_price_spec_type() -> None:+ product = _minimal_product()+ product["offers"][0]["priceSpecification"] = [+ {+ "@type": ["UnitPriceSpecification", "PriceSpecification"],+ "price": 79.99,+ "priceCurrency": "USD",+ "validForMemberTier": {"@type": "MemberProgramTier", "name": "Gold"},+ }+ ]+ result = ev.validate(product)+ rules = [f["rule"] for f in result["findings"]]+ assert "missing-member-program" not in rules+++def test_validate_reports_non_object_offers_without_crashing() -> None:+ for bad_offer in ("https://example.com/offer", None, 42):+ product = _minimal_product()+ product["offers"].insert(0, bad_offer)+ product["offers"][1]["hasMerchantReturnPolicy"] = {+ "@type": "MerchantReturnPolicy",+ "applicableCountry": "US",+ "returnPolicyCategory": "https://schema.org/MerchantReturnFiniteReturnWindow",+ }+ result = ev.validate(product)+ findings = {f["rule"]: f["severity"] for f in result["findings"]}+ assert findings["malformed-offer"] == "High", bad_offer+ assert result["ok"] is False+ # The first offer that is an object still supplies the offer-level fallbacks.+ assert "missing-return-policy" not in findings+ assert "missing-shipping-details" in findings+++def test_validate_reports_offers_list_with_no_objects() -> None:+ product = _minimal_product()+ product["offers"] = ["https://example.com/offer"]+ result = ev.validate(product)+ rules = [f["rule"] for f in result["findings"]]+ assert rules.count("malformed-offer") == 1+ assert "missing-return-policy" in rules+ assert "missing-shipping-details" in rules++def test_validate_finds_offers_when_offers_is_single_dict() -> None:product = _minimal_product()product["offers"] = product["offers"][0] # single dict, not listdiff --git a/tests/test_validate_backlink_report.py b/tests/test_validate_backlink_report.pyindex 0651398..5151395 100644--- a/tests/test_validate_backlink_report.py+++ b/tests/test_validate_backlink_report.py@@ -34,6 +34,14 @@ def test_schema_type_array_is_not_flagged() -> None:assert issues == []+def test_deprecated_howto_inside_type_array_is_flagged_as_error() -> None:+ issues = vbr.validate_schema_claims({"schema": [{"@type": ["Article", "HowTo"]}]})++ assert len(issues) == 1+ assert issues[0]["severity"] == "error"+ assert "HowTo" in issues[0]["message"]++def test_verification_summary_mismatch_is_flagged_as_error() -> None:verify_data = {"data": {