from pathlib import Path from job_research.models import ApecListing, ApecRunMeta, ListingWarning from job_research.storage import apec_run_paths def test_apec_models_serialize_expected_listing_shape() -> None: listing = ApecListing( source="apec", source_job_id="123", url="https://example.test/job/123", title="Data Engineer", company="Example", location="Paris", contract_type="CDI", description_text="Build pipelines", published_at="2026-06-01", fetched_at="2026-06-01T10:00:00Z", warnings=[ ListingWarning( field="location", message="Location inferred from page text", ) ], ) run_meta = ApecRunMeta( derived_queries=["Data Engineer"], fetched_count=1, normalized_count=1, deduplicated_count=1, failed_count=0, listing_errors=[], ) assert listing.model_dump()["source"] == "apec" assert listing.model_dump()["warnings"][0]["field"] == "location" assert run_meta.model_dump()["derived_queries"] == ["Data Engineer"] def test_apec_run_paths_builds_expected_layout(tmp_path: Path) -> None: paths = apec_run_paths(tmp_path, run_id="2026-06-01T10-00-00Z") run_dir = tmp_path / "apec" / "runs" / "2026-06-01T10-00-00Z" assert paths["run_dir"] == run_dir assert paths["listings"] == run_dir / "listings.yaml" assert paths["run_meta"] == run_dir / "run-meta.yaml" assert paths["snapshots"] == run_dir / "snapshots" def test_apec_run_artifacts_include_snapshot_and_meta(tmp_path: Path) -> None: paths = apec_run_paths(tmp_path, run_id="2026-06-01T10-00-00Z") paths["snapshots"].mkdir(parents=True, exist_ok=True) snapshot = paths["snapshots"] / "job-123.html" snapshot.write_text("snapshot", encoding="utf-8") assert snapshot.read_text(encoding="utf-8") == "snapshot"