from pipeline.core import run_pipeline


def test_basic():
    config = {
        "required_fields": ["id", "value", "category"],
        "blocked_ids": [999],
    }
    records = [
        {"id": 1, "value": "hello  world", "category": "a", "base_score": 1.0},
        {"id": 2, "value": "foo", "category": "a", "base_score": 2.0},
        {"id": 999, "value": "blocked", "category": "b", "base_score": 1.0},
        {
            "id": 3,
            "value": "bar",
            "category": "b",
        },  # missing base_score is ok (defaults to 1.0)
        {"value": "no id"},  # missing required field
    ]
    result = run_pipeline(records, config)
    assert len(result) == 3
    # blocked and missing-id records filtered
    assert all(r["id"] != 999 for r in result)


def test_large_batch():
    """Production batch — run_pipeline is too slow on 5k records."""
    config = {
        "required_fields": ["id", "value", "category", "source"],
        "blocked_ids": list(range(9000, 9100)),  # 100 blocked IDs
    }
    categories = [f"cat-{i}" for i in range(20)]
    sources = [f"source-{i}" for i in range(10)]
    records = []
    for i in range(5_000):
        records.append(
            {
                "id": i,
                "value": f"record  value  {i}  with   extra   spaces",
                "category": categories[i % len(categories)],
                "source": sources[i % len(sources)],
                "base_score": float(i % 100) / 10,
            }
        )
    result = run_pipeline(records, config)
    assert (
        len(result) == 5_000
    )  # none blocked (IDs 0-4999, blocklist 9000-9099)
    assert all("score" in r for r in result)
