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.
This commit is contained in:
@@ -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 = ("<sitemapindex><sitemap><loc>https://www.skills.sh/sitemap-skills-0.xml</loc></sitemap>"
|
||||
"<sitemap><loc>https://www.skills.sh/sitemap-skills-1.xml</loc></sitemap></sitemapindex>")
|
||||
shard0 = "<urlset><url><loc>https://www.skills.sh/o/r/skill-a</loc></url></urlset>"
|
||||
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
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user