fix(client,exporter): handle HTTP 429 retry and sanitize JSON

_get_with_retry now retries on HTTP 429 responses, respecting the
Retry-After header when present. exporter sanitizes control characters
(0x00-0x1F except \n \r \t) in text fields before JSON serialization.

fixes #11
fixes #12

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
sylvain
2026-03-12 19:15:25 +01:00
parent 9783389bfb
commit b40dea32f4
4 changed files with 163 additions and 6 deletions

View File

@@ -56,6 +56,43 @@ class TestReposToDicts:
assert field in d, f"Missing field: {field}"
class TestSanitizeControlChars:
"""Test control character sanitization in export."""
def test_export_json_sanitizes_control_chars(self):
"""Description with control chars (0x00, 0x01, 0x02) produces valid JSON without them."""
repo = _make_repo(description="hello\x00\x01\x02world")
output = export_json([repo])
parsed = json.loads(output)
assert parsed[0]["description"] == "helloworld"
def test_export_json_preserves_newlines_tabs(self):
"""Newlines and tabs are preserved in JSON export (they are valid JSON escapes)."""
repo = _make_repo(description="line1\nline2\ttab")
output = export_json([repo])
parsed = json.loads(output)
assert parsed[0]["description"] == "line1\nline2\ttab"
def test_export_json_unicode_safe(self):
"""Description with emojis and accents produces valid JSON."""
repo = _make_repo(description="Projet avec accents : e, a et emojis 🚀🎉")
output = export_json([repo])
parsed = json.loads(output)
assert "🚀" in parsed[0]["description"]
assert "accents" in parsed[0]["description"]
def test_sanitize_name_and_full_name(self):
"""Control chars in name and full_name fields are also sanitized."""
repo = _make_repo(name="test\x00repo", full_name="admin/test\x01repo")
result = repos_to_dicts([repo])
assert result[0]["name"] == "testrepo"
assert result[0]["full_name"] == "admin/testrepo"
class TestExportJson:
"""Test export_json function."""