fix(browse-sh): fetch SKILL.md via /api/skills/{slug}+skillMdUrl

The catalog's sourceUrl points at github.com/browserbase/browse.sh,
whose underlying repository is not always public — most raw URLs derived
from it 404. Use the per-skill detail endpoint instead, which returns a
skillMdUrl CDN blob that reliably resolves to the SKILL.md text. Fall
back to a raw.githubusercontent.com sourceUrl if the detail call fails.

- tools/skills_hub.py: rewrite BrowseShSource.fetch() to resolve via
  /api/skills/{slug} -> skillMdUrl; drop the unreachable _to_raw_url
  helper; expose the resolved URL in bundle.metadata.skill_md_url.
- tests/tools/test_skills_hub_browse_sh.py: match the real catalog
  shape (name = task name, slug = host/task-id), exercise the
  detail-endpoint -> blob two-call flow, and add a fallback test.
- scripts/release.py: map kylejeong21@gmail.com -> Kylejeong2.
This commit is contained in:
teknium1 2026-05-19 14:14:22 -07:00 committed by Teknium
parent 90be1be501
commit 890b2ebd5b
3 changed files with 90 additions and 55 deletions

View file

@ -6,29 +6,31 @@ from unittest.mock import patch
from tools.skills_hub import BrowseShSource, SkillMeta, SkillBundle
# Catalog shape mirrors the real ``GET https://browse.sh/api/skills`` response:
# ``slug`` is ``<hostname>/<task-id>`` and ``name`` is the task name.
SAMPLE_CATALOG = [
{
"slug": "airbnb.com/search-listings-ddgioa",
"name": "airbnb.com",
"name": "search-listings",
"title": "Airbnb Search Listings",
"description": "Search and browse Airbnb listings by location and dates.",
"hostname": "airbnb.com",
"category": "travel",
"tags": ["travel", "accommodation"],
"sourceUrl": "https://github.com/browserbase/browse-sh/blob/main/skills/airbnb.com/SKILL.md",
"sourceUrl": "https://github.com/browserbase/browse.sh/blob/main/skills/airbnb.com/search-listings-ddgioa/SKILL.md",
"recommendedMethod": "stagehand",
"proxies": False,
"installCount": 42,
},
{
"slug": "amazon.com/search-products-xyz",
"name": "amazon.com",
"name": "search-products",
"title": "Amazon Product Search",
"description": "Search for products on Amazon.",
"hostname": "amazon.com",
"category": "shopping",
"tags": ["shopping", "ecommerce"],
"sourceUrl": "https://raw.githubusercontent.com/browserbase/browse-sh/main/skills/amazon.com/SKILL.md",
"sourceUrl": "https://github.com/browserbase/browse.sh/blob/main/skills/amazon.com/search-products-xyz/SKILL.md",
"recommendedMethod": "stagehand",
"proxies": False,
"installCount": 99,
@ -60,7 +62,7 @@ class TestBrowseShSource(unittest.TestCase):
self.assertGreaterEqual(len(results), 1)
meta = results[0]
self.assertIsInstance(meta, SkillMeta)
self.assertEqual(meta.name, "airbnb.com")
self.assertEqual(meta.name, "search-listings")
self.assertEqual(meta.source, "browse-sh")
self.assertEqual(meta.trust_level, "community")
self.assertEqual(meta.identifier, "browse-sh/airbnb.com/search-listings-ddgioa")
@ -70,7 +72,7 @@ class TestBrowseShSource(unittest.TestCase):
def test_search_filters_by_query(self, _mock_catalog):
results = self.src.search("amazon", limit=10)
self.assertEqual(len(results), 1)
self.assertEqual(results[0].name, "amazon.com")
self.assertEqual(results[0].extra["hostname"], "amazon.com")
results_all = self.src.search("", limit=10)
self.assertEqual(len(results_all), 2)
@ -78,22 +80,50 @@ class TestBrowseShSource(unittest.TestCase):
@patch("tools.skills_hub.httpx.get")
@patch.object(BrowseShSource, "_fetch_catalog", return_value=SAMPLE_CATALOG)
def test_fetch_returns_bundle(self, _mock_catalog, mock_get):
mock_get.return_value = _MockResponse(
status_code=200,
text="# Airbnb Skill\n\nSearch and book Airbnb listings.",
# First call: GET /api/skills/{slug} returns the detail object with skillMdUrl.
# Second call: GET the CDN blob URL returns the SKILL.md text.
blob_url = (
"https://gh0lfhlmyzhg6tww.public.blob.vercel-storage.com"
"/skills/airbnb.com/search-listings-ddgioa/SKILL.md"
)
mock_get.side_effect = [
_MockResponse(status_code=200, json_data={"skillMdUrl": blob_url}),
_MockResponse(status_code=200, text="# Airbnb Skill\n\nSearch and book Airbnb listings."),
]
bundle = self.src.fetch("browse-sh/airbnb.com/search-listings-ddgioa")
self.assertIsNotNone(bundle)
self.assertIsInstance(bundle, SkillBundle)
self.assertEqual(bundle.name, "airbnb.com")
self.assertEqual(bundle.name, "search-listings")
self.assertIn("SKILL.md", bundle.files)
self.assertIn("Airbnb", bundle.files["SKILL.md"])
self.assertEqual(bundle.source, "browse-sh")
self.assertEqual(bundle.trust_level, "community")
self.assertEqual(bundle.identifier, "browse-sh/airbnb.com/search-listings-ddgioa")
mock_get.assert_called_once()
call_url = mock_get.call_args.args[0]
self.assertIn("raw.githubusercontent.com", call_url)
self.assertEqual(bundle.metadata["skill_md_url"], blob_url)
# Two HTTP calls: detail endpoint + blob.
self.assertEqual(mock_get.call_count, 2)
first_url = mock_get.call_args_list[0].args[0]
second_url = mock_get.call_args_list[1].args[0]
self.assertIn("/api/skills/airbnb.com/search-listings-ddgioa", first_url)
self.assertEqual(second_url, blob_url)
@patch("tools.skills_hub.httpx.get")
@patch.object(BrowseShSource, "_fetch_catalog", return_value=SAMPLE_CATALOG)
def test_fetch_falls_back_to_raw_github_url(self, _mock_catalog, mock_get):
# Detail endpoint fails → fall back to a raw.githubusercontent.com sourceUrl.
raw_catalog = [dict(SAMPLE_CATALOG[0])]
raw_catalog[0]["sourceUrl"] = (
"https://raw.githubusercontent.com/example/repo/main/skills/"
"airbnb.com/search-listings-ddgioa/SKILL.md"
)
with patch.object(BrowseShSource, "_fetch_catalog", return_value=raw_catalog):
mock_get.side_effect = [
_MockResponse(status_code=500, json_data=None), # detail endpoint fails
_MockResponse(status_code=200, text="# Fallback content"),
]
bundle = self.src.fetch("browse-sh/airbnb.com/search-listings-ddgioa")
self.assertIsNotNone(bundle)
self.assertEqual(bundle.files["SKILL.md"], "# Fallback content")
@patch.object(BrowseShSource, "_fetch_catalog", return_value=SAMPLE_CATALOG)
def test_fetch_missing_slug_returns_none(self, _mock_catalog):
@ -105,28 +135,12 @@ class TestBrowseShSource(unittest.TestCase):
meta = self.src.inspect("browse-sh/airbnb.com/search-listings-ddgioa")
self.assertIsNotNone(meta)
self.assertIsInstance(meta, SkillMeta)
self.assertEqual(meta.name, "airbnb.com")
self.assertEqual(meta.name, "search-listings")
self.assertEqual(meta.identifier, "browse-sh/airbnb.com/search-listings-ddgioa")
self.assertEqual(meta.extra["hostname"], "airbnb.com")
self.assertEqual(meta.extra["category"], "travel")
self.assertEqual(meta.extra["install_count"], 42)
def test_to_raw_url_conversion(self):
# GitHub HTML URL should be converted
html_url = "https://github.com/browserbase/browse-sh/blob/main/skills/airbnb.com/SKILL.md"
raw_url = self.src._to_raw_url(html_url)
self.assertEqual(
raw_url,
"https://raw.githubusercontent.com/browserbase/browse-sh/main/skills/airbnb.com/SKILL.md",
)
# Already a raw URL — should be returned unchanged
already_raw = "https://raw.githubusercontent.com/browserbase/browse-sh/main/skills/amazon.com/SKILL.md"
self.assertEqual(self.src._to_raw_url(already_raw), already_raw)
# Unrecognised URL — should return None
self.assertIsNone(self.src._to_raw_url("https://example.com/something"))
if __name__ == "__main__":
unittest.main()