SPB Git

spb/wp45_uqo

Public
4.1 KB · 59 lines python
1import json, pytest2from pathlib import Path3from jof250 import auditing, generation45def test_load_manuscript_resolves_inputs_and_bib(synthetic_manuscript):6    ms = auditing.load_manuscript(synthetic_manuscript)7    assert ms["title"] == "A Synthetic Manuscript" and "3.2" in ms["abstract"]8    assert {s["role"] for s in ms["sections"] if s["level"] == 1} >= {"introduction", "results"}9    assert ms["tables"][0]["label"] == "tab:main" and ms["equations"][0]["label"] == "eq:main"10    assert "doe2098" in ms["bib_keys"] and ms["bib_dois"]["doe2098"].startswith("10.1111")1112def test_citation_check_flags_unknown_keys(synthetic_manuscript):13    ms = auditing.load_manuscript(synthetic_manuscript); c = auditing.citation_check(ms["text"], ms["bib_keys"])14    assert c["unknown_keys"] == ["nothere2099"]1516def test_numeric_preservation():17    r = auditing.numeric_preservation("effect 3.2 percent with 1,000 firms in 2018", "effect 3.2 percent with 1000 firms and 7.7 extra")18    assert r["preserved_rate"] == 1.0 and r["new_in_output"] == ["7.7"]1920def test_unsupported_claims_detection():21    flagged = auditing.unsupported_claims("Leverage causes default in every economy we have ever studied. Table 2 shows that leverage increases default by 3 percent.")22    assert len(flagged) == 1 and "causes" in flagged[0]["verb"]2324def test_overlap_detection_on_synthetic_text(monkeypatch):25    monkeypatch.setattr(auditing, "corpus_shingles", lambda: {"docA": auditing._shingles("the quick brown fox jumps over the lazy dog again and again today")})26    r = auditing.overlap_with_corpus("the quick brown fox jumps over the lazy dog again and again today")27    assert r["max_overlap_share"] == 1.0 and r["top_docs"][0]["doc_id"] == "docA"28    assert auditing.overlap_with_corpus("completely different words about econometrics and banking")["max_overlap_share"] == 0.02930def test_audit_report_renders(synthetic_manuscript, monkeypatch):31    monkeypatch.setattr(auditing, "verify_dois", lambda d, limit=60: {"checked": len(d), "resolved": 0, "unresolved": []})32    monkeypatch.setattr(auditing, "corpus_shingles", lambda: {})33    rep = auditing.audit_manuscript(synthetic_manuscript); txt = auditing.render_report(rep)34    assert "unknown citation key: nothere2099" in rep["issues"] and "Manuscript audit" in txt3536def test_evidence_for_claim(synthetic_manuscript):37    r = auditing.evidence_for_claim(synthetic_manuscript, "the effect is 3.2 percent")38    assert r["status"] == "supported_by_table"3940def test_missing_manuscript_fails_loudly(tmp_path):41    with pytest.raises(FileNotFoundError): auditing.load_manuscript(tmp_path)4243def test_genre_detection_and_profile_fallback(synthetic_manuscript):44    ms = auditing.load_manuscript(synthetic_manuscript); det = generation.detect_genre(ms)45    assert det["genre"] in ("empirical", "theoretical")46    name, prof, note = generation.profile_for("empirical", "real_estate_housing"); assert name and "outside the corpus" in note4748def test_engine_writes_proposal_file_without_touching_manuscript(synthetic_manuscript, tmp_path, monkeypatch):49    before = (synthetic_manuscript / "sections" / "intro.tex").read_text()50    fake = {"text": "Intro draft with 3.2 percent.\n=== CHANGE LOG ===\n- moves\n=== FLAGS ===\n- none", "json": None, "model": "fake", "stop_reason": "end_turn", "latency_s": 0.1, "usage": {"input": 1, "output": 1, "cache_read": 0, "cache_write": 0}, "cost_usd": 0.0, "request_id": "r", "cached": False, "ts": "t", "effort": "low"}51    monkeypatch.setattr(generation.llm, "call", lambda *a, **k: fake)52    monkeypatch.setattr(generation, "retrieve_for", lambda *a, **k: [])53    monkeypatch.setattr(generation.auditing, "overlap_with_corpus", lambda t, n=8: {"n_shingles": 0, "max_overlap_share": 0.0, "top_docs": []})54    out = tmp_path / "prop" / "intro.tex"55    res = generation.run(synthetic_manuscript, "introduction", mode="write", output=out, condition="E_full_engine")56    assert out.exists() and out.read_text().startswith("% jof250") and out.with_suffix(".report.md").exists()57    assert (synthetic_manuscript / "sections" / "intro.tex").read_text() == before58    assert res["audit"]["final"]["numeric"]["new_in_output"] == [] and res["n_calls"] == 259
Files · 62a9da723bfa8125e943fa9f6b4bc31044d26d0e
Menu

Theme