Skip to content

AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary

fix: validate html publish response shape

Trevin Chow76fb9de86bc3
diff --git a/skills/last30days/scripts/lib/html_publish.py b/skills/last30days/scripts/lib/html_publish.py
index ae4d2a4c..a47b1708 100644
--- a/skills/last30days/scripts/lib/html_publish.py
+++ b/skills/last30days/scripts/lib/html_publish.py
@@ -53,6 +53,8 @@ def publish_html(
result = json.loads(body)
except json.JSONDecodeError as exc:
raise HtmlPublishError("publish endpoint returned non-JSON response") from exc
+ if not isinstance(result, dict):
+ raise HtmlPublishError("publish endpoint returned unexpected JSON response")
url = result.get("url")
if not isinstance(url, str) or not url.startswith("https://"):
diff --git a/tests/test_html_publish.py b/tests/test_html_publish.py
index a26ae8fc..5bd5326b 100644
--- a/tests/test_html_publish.py
+++ b/tests/test_html_publish.py
@@ -63,7 +63,7 @@ def _diag() -> dict[str, object]:
class _FakeResponse:
- def __init__(self, payload: dict[str, object]):
+ def __init__(self, payload: object):
self.payload = payload
def __enter__(self):
@@ -118,6 +118,13 @@ class HtmlPublishModuleTests(unittest.TestCase):
with self.assertRaisesRegex(html_publish.HtmlPublishError, "HTML content is required"):
html_publish.publish_html("<html></html>", opener=opener)
+ def test_publish_rejects_json_response_that_is_not_an_object(self):
+ def opener(_request, timeout):
+ return _FakeResponse(["https://site.ht-ml.app"])
+
+ with self.assertRaisesRegex(html_publish.HtmlPublishError, "unexpected JSON response"):
+ html_publish.publish_html("<html></html>", opener=opener)
+
class HtmlPublishCliTests(unittest.TestCase):
def test_publish_requires_html_emit(self):