29 行
926 B
Python
29 行
926 B
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from typing import Any, Dict, List
|
|
|
|
import requests
|
|
|
|
from lab.utils import write_json
|
|
|
|
|
|
def collect(profile: Dict[str, Any], run_dir: Path, timeout: float = 8.0) -> Dict[str, Any]:
|
|
observations: List[Dict[str, Any]] = []
|
|
for url in profile.get("baseline_urls", []):
|
|
try:
|
|
response = requests.get(url, timeout=timeout, verify=False)
|
|
observations.append(
|
|
{
|
|
"url": url,
|
|
"status_code": response.status_code,
|
|
"headers": dict(response.headers),
|
|
"body_excerpt": response.text[:400],
|
|
}
|
|
)
|
|
except Exception as exc:
|
|
observations.append({"url": url, "error": str(exc)})
|
|
payload = {"observations": observations}
|
|
write_json(run_dir / "logs" / "baseline.json", payload)
|
|
return payload
|