import json, pandas as pd from jof250 import inventory, provenance def test_sha256_and_duplicates(tmp_path, synthetic_pdf): dup = tmp_path / "copy.pdf"; dup.write_bytes(synthetic_pdf.read_bytes()) (tmp_path / "notes.txt").write_text("not a pdf") df = inventory.scan(tmp_path) assert len(df) == 3 and df.sha256.nunique() == 2 assert provenance.sha256_file(synthetic_pdf) == provenance.sha256_file(dup) assert df[df.ext == ".pdf"].pdf_valid.all() def test_pdf_probe_extracts_doi(synthetic_pdf): r = inventory.pdf_probe(synthetic_pdf); assert r["pages"] == 1 and r["doi_in_pdf"] == "10.1111/jofi.99999" def test_classify_excludes_non_pdf_and_duplicates(tmp_path, synthetic_pdf, monkeypatch): dup = tmp_path / "copy.pdf"; dup.write_bytes(synthetic_pdf.read_bytes()); (tmp_path / "x.csv").write_text("a") df = inventory.scan(tmp_path); df["bib_doi"] = "10.1111/jofi.99999"; df["bib_year"] = 2018; df["bib_section"] = "ARTICLES"; df["bib_title"] = "A Synthetic Test Article"; df["bib_joined"] = True out = inventory.classify(df) assert (out.decision == "exclude").sum() == 3 # csv + 2 identical PDFs (both flagged as duplicate content) assert "non-PDF file" in set(out.decision_reason) def test_frozen_manifest_exists_and_counts_match(): from jof250 import config p = config.manifests_dir() / "corpus_v1_frozen.json" if not p.exists(): import pytest; pytest.skip("real corpus not audited on this machine") fz = json.loads(p.read_text()); man = pd.read_parquet(config.manifests_dir() / "corpus_manifest.parquet") assert fz["n_included"] == int((man.decision == "include").sum()) == len(fz["documents"])