feat(runtime): implement single-article consolidation runtime and modularize codebase
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
"""Unit tests for enrichment harness covering scenarios ENR-001 to ENR-009."""
|
||||
|
||||
import pytest
|
||||
|
||||
from src.runtime.enrichment.harness import (
|
||||
EnrichmentFailedError,
|
||||
normalize_tag,
|
||||
validate_and_extract_enrichment,
|
||||
)
|
||||
|
||||
|
||||
def test_tag_normalization():
|
||||
raw_tag = " Copa Sudamericana "
|
||||
norm = normalize_tag(raw_tag)
|
||||
assert norm == "copa sudamericana"
|
||||
|
||||
|
||||
def test_validate_and_extract_enrichment_valid():
|
||||
valid_ids = {"blk_01", "blk_02"}
|
||||
resp = {
|
||||
"sentiment": "positive",
|
||||
"tags": ["River Plate", "copa sudamericana", "Futebol"],
|
||||
"evidence_candidate_ids": ["blk_01"],
|
||||
}
|
||||
extracted = validate_and_extract_enrichment(resp, valid_ids)
|
||||
assert extracted["sentiment"] == "positive"
|
||||
assert len(extracted["tags"]) == 3
|
||||
assert "river plate" in extracted["tags"]
|
||||
assert "copa sudamericana" in extracted["tags"]
|
||||
assert "futebol" in extracted["tags"]
|
||||
|
||||
|
||||
def test_enrichment_fails_on_duplicate_tags():
|
||||
valid_ids = {"blk_01"}
|
||||
resp = {
|
||||
"sentiment": "neutral",
|
||||
"tags": [
|
||||
"futebol",
|
||||
"Futebol",
|
||||
" futebol ",
|
||||
], # 3 items for schema, but collapses to 1 unique tag
|
||||
"evidence_candidate_ids": ["blk_01"],
|
||||
}
|
||||
with pytest.raises(EnrichmentFailedError) as exc_info:
|
||||
validate_and_extract_enrichment(resp, valid_ids)
|
||||
assert "outside allowed bound" in str(exc_info.value)
|
||||
Reference in New Issue
Block a user