From d457e7f039ee2f0b1b655fca9535b4e33f35c05a Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Fri, 18 Sep 2026 11:16:39 -0700 Subject: [PATCH] test(skills): seam the sitemap-shard retry test on the hub guarded GET The shard fetch now routes through hub()._guarded_http_get (#114887), so a patch on tools.skills_hub_skillssh._get_text intercepted nothing and the test reached the live sitemap on CI. Patch tools.skills_hub._ssrf_safe_http_get like the neighbouring guarded-GET test and model the dark shard as a 503. --- tests/tools/test_skills_hub.py | 18 ++++++++++++------ tools/skills_hub_skillssh.py | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/tools/test_skills_hub.py b/tests/tools/test_skills_hub.py index 32e759998f..b7631b4d73 100644 --- a/tests/tools/test_skills_hub.py +++ b/tests/tools/test_skills_hub.py @@ -258,23 +258,29 @@ class TestSkillsShSource: @patch("tools.skills_hub._write_index_cache") @patch("tools.skills_hub._read_index_cache", return_value=None) def test_sitemap_catalog_retries_failed_shard_and_never_caches_partial( - self, _mock_read_cache, mock_write_cache, _mock_sleep, + self, _mock_read_cache, mock_write_cache, _mock_sleep, monkeypatch, ): """A per-skill sitemap shard that keeps failing is a hole in the catalog, not an empty shard: retry it, and never publish the partial slice to the shared cache.""" + monkeypatch.setattr("tools.skills_hub.is_safe_url", lambda _url: True) + monkeypatch.setattr("tools.skills_hub.check_website_access", lambda _url: None) + monkeypatch.setattr("tools.skills_hub_skillssh._cached_metas", lambda _key: None) + monkeypatch.setattr("tools.skills_hub_skillssh._cache_metas", lambda _key, _metas: None) index = ("https://www.skills.sh/sitemap-skills-0.xml" "https://www.skills.sh/sitemap-skills-1.xml") shard0 = "https://www.skills.sh/o/r/skill-a" calls: List[str] = [] - def fake_get_text(url, **kwargs): + def fake_get(url, *, timeout, headers=None): calls.append(url) if url.endswith("sitemap.xml"): - return index - return shard0 if url.endswith("sitemap-skills-0.xml") else None + return MagicMock(status_code=200, headers={}, text=index) + if url.endswith("sitemap-skills-0.xml"): + return MagicMock(status_code=200, headers={}, text=shard0) + return MagicMock(status_code=503, headers={}, text="") - with patch("tools.skills_hub_skillssh._get_text", side_effect=fake_get_text): - results = self._source()._sitemap_catalog(0) + monkeypatch.setattr("tools.skills_hub._ssrf_safe_http_get", fake_get) + results = self._source()._sitemap_catalog(0) assert [m.identifier for m in results] == ["skills-sh/o/r/skill-a"] assert calls.count("https://www.skills.sh/sitemap-skills-1.xml") == SkillSource.CATALOG_PAGE_RETRIES diff --git a/tools/skills_hub_skillssh.py b/tools/skills_hub_skillssh.py index a5cd8cd777..7a3fe96f3f 100644 --- a/tools/skills_hub_skillssh.py +++ b/tools/skills_hub_skillssh.py @@ -139,7 +139,7 @@ class SkillsShSource(SkillSource): return self._featured_skills(limit) # Step 2: collect canonical "owner/repo/skill" IDs from each sitemap. A shard - # ``_get_text`` returns None for is a hole, not an empty shard: retry it, and + # ``_xml`` returns None for is a hole, not an empty shard: retry it, and # if it stays dark return the partial slice without publishing it to the cache. seen, results, partial = set(), [], False for sitemap_url in skill_sitemap_urls: