c2743251e9
Self-evolving AI scientist framework built on LangGraph/LangChain with CLI/TUI core, FastAPI gateway, and Next.js frontend. Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
77 lines
2.6 KiB
Python
77 lines
2.6 KiB
Python
"""Tests for Humanizer pattern catalog and prompts."""
|
|
|
|
from EvoScientist.humanizer.models import HumanizerAnalysis
|
|
from EvoScientist.humanizer.pattern_catalog import (
|
|
PATTERNS,
|
|
get_patterns,
|
|
render_pattern_catalog,
|
|
)
|
|
from EvoScientist.humanizer.pipeline import (
|
|
_ensure_json_instruction,
|
|
_extract_json,
|
|
_validate_structured_payload,
|
|
)
|
|
from EvoScientist.humanizer.prompts import build_analyze_prompt, build_rewrite_prompt
|
|
|
|
|
|
def test_pattern_catalog_has_mvp_patterns():
|
|
assert len(PATTERNS) == 29
|
|
ids = {pattern.id for pattern in PATTERNS}
|
|
assert "template_abstract" in ids
|
|
assert "unsupported_scientific_claim" in ids
|
|
assert len(get_patterns("scientific")) == 29
|
|
|
|
|
|
def test_pattern_catalog_renders_for_prompt():
|
|
rendered = render_pattern_catalog("scientific")
|
|
assert "ai_frequency_words" in rendered
|
|
assert "unsupported_scientific_claim" in rendered
|
|
|
|
|
|
def test_prompt_builders_include_inputs():
|
|
analysis = HumanizerAnalysis(ai_score=0.7, overall_assessment="Likely AI-like")
|
|
analyze_prompt = build_analyze_prompt("x" * 30)
|
|
rewrite_prompt = build_rewrite_prompt("x" * 30, analysis)
|
|
assert "Pattern catalog" in analyze_prompt
|
|
assert "JSON" in analyze_prompt
|
|
assert "overall_assessment" in analyze_prompt
|
|
assert "Original text" in rewrite_prompt
|
|
|
|
|
|
def test_analysis_payload_tolerates_missing_assessment():
|
|
analysis = _validate_structured_payload(
|
|
HumanizerAnalysis,
|
|
{
|
|
"ai_score": 0.78,
|
|
"patterns": [
|
|
{
|
|
"name": "generic transition",
|
|
"text": "Moreover, this study...",
|
|
}
|
|
],
|
|
},
|
|
)
|
|
assert analysis.overall_assessment
|
|
assert analysis.hits[0].pattern == "generic transition"
|
|
assert analysis.hits[0].fix_strategy == "replace"
|
|
|
|
|
|
def test_analysis_payload_tolerates_string_uniformity_issue():
|
|
analysis = _validate_structured_payload(
|
|
HumanizerAnalysis,
|
|
{
|
|
"ai_score": 0.62,
|
|
"overall_assessment": "Mixed register.",
|
|
"uniformity_issues": "Severe register inconsistency across paragraphs.",
|
|
},
|
|
)
|
|
assert analysis.uniformity_issues[0].aspect == "paragraph_structure"
|
|
assert "register inconsistency" in analysis.uniformity_issues[0].description
|
|
|
|
|
|
def test_json_instruction_and_extraction_are_robust():
|
|
assert "JSON" in _ensure_json_instruction("Analyze this text")
|
|
assert _ensure_json_instruction("Return json only") == "Return json only"
|
|
payload = _extract_json('prefix {"ai_score": 0.4, "nested": {"ok": true}} trailing {bad')
|
|
assert payload["nested"]["ok"] is True
|