Files
Public Source Publisher 787a2b1dc3 RepoPulse: update frontend/src and backend/app (+4 areas)
Public changes compared with the previous published export:
19 files changed.

Affected areas:
- backend/app: 3 files
- dependencies: 2 files
- documentation: 1 file
- frontend: 2 files
- frontend/src: 10 files
- tests: 1 file

Changed files:
- Updated: "backend/app/acquisition.py"
- Added: "backend/app/icons.py"
- Updated: "backend/app/main.py"
- Added: "backend/tests/test_icons.py"
- Updated: "docs/ARCHITECTURE.md"
- Updated: "frontend/package-lock.json"
- Updated: "frontend/package.json"
- Updated: "frontend/playwright.config.ts"
- Updated: "frontend/src/App.tsx"
- Updated: "frontend/src/components/DashboardView.tsx"
- Added: "frontend/src/components/HealthRing.tsx"
- Updated: "frontend/src/components/HistoryView.tsx"
- Added: "frontend/src/components/Icon.tsx"
- Updated: "frontend/src/components/PortfolioAtlas.tsx"
- Updated: "frontend/src/components/RemediationCenter.tsx"
- Added: "frontend/src/components/RepoAvatar.tsx"
- Updated: "frontend/src/main.tsx"
- Updated: "frontend/src/styles.css"
- Updated: "frontend/vite.config.ts"

Export provenance/manifests refreshed; excluded from the change summary.

Publish curated RepoPulse source from 7a60c53ee2c1daebecd66a01656e323f1db72e56
2026-11-20 04:45:33 +00:00

107 lines
4.9 KiB
Python

from __future__ import annotations
import subprocess
from pathlib import Path
from app.icons import MAX_ICON_BYTES, ProjectIconResolver
PNG = b"\x89PNG\r\n\x1a\n" + b"\x00" * 32
SVG = b'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 8 8"><rect width="8" height="8"/></svg>'
def _mirror(tmp_path: Path, files: dict[str, bytes]) -> tuple[Path, Path, str]:
source = tmp_path / "source"
source.mkdir()
for relative, content in files.items():
target = source / relative
target.parent.mkdir(parents=True, exist_ok=True)
target.write_bytes(content)
subprocess.run(["git", "init", "--quiet", str(source)], check=True)
subprocess.run(["git", "-C", str(source), "config", "user.email", "test@example.com"], check=True)
subprocess.run(["git", "-C", str(source), "config", "user.name", "RepoPulse Test"], check=True)
subprocess.run(["git", "-C", str(source), "add", "."], check=True)
subprocess.run(["git", "-C", str(source), "commit", "--quiet", "-m", "initial"], check=True)
revision = subprocess.run(["git", "-C", str(source), "rev-parse", "HEAD"], check=True, capture_output=True, text=True).stdout.strip()
mirrors = tmp_path / "mirrors"
mirrors.mkdir()
mirror = mirrors / "gitea-1.git"
subprocess.run(["git", "clone", "--quiet", "--mirror", str(source), str(mirror)], check=True)
return mirrors, mirror, revision
def test_prefers_a_public_svg_favicon_over_logos_and_excluded_fixtures(tmp_path: Path) -> None:
mirrors, mirror, revision = _mirror(tmp_path, {
"README.md": b"# Demo\n",
"docs/logo.png": PNG,
"tests/fixtures/favicon.svg": SVG,
"node_modules/pkg/favicon.svg": SVG,
"frontend/public/favicon.svg": SVG,
"frontend/public/icons.svg": SVG,
})
icon = ProjectIconResolver(mirrors).resolve(mirror, revision)
assert icon is not None
assert icon.path == "frontend/public/favicon.svg"
assert icon.media_type == "image/svg+xml"
assert icon.content == SVG
def test_rejects_content_that_does_not_match_its_extension_and_oversized_files(tmp_path: Path) -> None:
mirrors, mirror, revision = _mirror(tmp_path, {
"public/favicon.svg": b"#!/bin/sh\necho not an image\n",
"public/logo.png": b"not a png",
"public/icon.png": PNG + b"\x00" * MAX_ICON_BYTES,
"app/icon.png": PNG,
})
icon = ProjectIconResolver(mirrors).resolve(mirror, revision)
assert icon is not None
assert icon.path == "app/icon.png"
assert icon.media_type == "image/png"
def test_prefers_a_larger_raster_over_a_tiny_favicon(tmp_path: Path) -> None:
mirrors, mirror, revision = _mirror(tmp_path, {
"frontend/public/icons/favicon-16.png": PNG,
"frontend/public/icons/apple-touch-icon.png": PNG + bytes(8000),
})
icon = ProjectIconResolver(mirrors).resolve(mirror, revision)
assert icon is not None
assert icon.path == "frontend/public/icons/apple-touch-icon.png"
def test_missing_icons_unknown_revisions_and_foreign_mirrors_resolve_to_none(tmp_path: Path) -> None:
mirrors, mirror, revision = _mirror(tmp_path, {"README.md": b"# Demo\n"})
resolver = ProjectIconResolver(mirrors)
assert resolver.resolve(mirror, revision) is None
assert resolver.resolve(mirror, "not-a-revision") is None
assert resolver.resolve(mirror, "0" * 40) is None
assert resolver.resolve(tmp_path / "source" / ".git", revision) is None
def test_icon_endpoint_serves_the_mirror_icon_with_strict_headers(tmp_path: Path, monkeypatch) -> None:
from fastapi.testclient import TestClient
from app import main as main_module
from app.models import Repository
from app.store import ScanStore
mirrors, _mirror_path, revision = _mirror(tmp_path, {"public/favicon.svg": SVG})
store = ScanStore(str(tmp_path / "history.db"))
repository = Repository(id="gitea:1", provider="gitea", provider_repository_id="1", owner="Jens", name="Demo", full_name="Jens/Demo", latest_revision=revision)
store.upsert_repository(repository)
empty = Repository(id="gitea:2", provider="gitea", provider_repository_id="2", owner="Jens", name="Empty", full_name="Jens/Empty")
store.upsert_repository(empty)
monkeypatch.setattr(main_module, "store", store)
monkeypatch.setattr(main_module, "project_icons", ProjectIconResolver(mirrors))
monkeypatch.setattr(main_module.repository_acquirer, "mirrors_root", mirrors)
client = TestClient(main_module.app)
response = client.get(f"/api/v1/repositories/gitea:1/icon?rev={revision}")
assert response.status_code == 200
assert response.content == SVG
assert response.headers["content-type"].startswith("image/svg+xml")
assert "sandbox" in response.headers["content-security-policy"]
assert response.headers["x-content-type-options"] == "nosniff"
assert client.get("/api/v1/repositories/gitea:2/icon").status_code == 404
assert client.get("/api/v1/repositories/gitea:404/icon").status_code == 404