Skip to content

The platform for continuously improving AI agents.

2.1 KB
Raw Blame
"""A run scores with the judges and intent pinned when it was created, also after a relaunch."""

import os

import pytest
from conftest import frozen_dataset
from factories import make_capability, make_matrix_row, make_project

from overbae.innermind import generation, runs
from overbae.models import EvalRun

pytestmark = [pytest.mark.django_db(transaction=True), pytest.mark.covers("metrics-math")]


def test_relaunched_run_scores_with_the_judges_and_intent_it_was_created_with(
    fake_llm, settings, monkeypatch
):
    monkeypatch.setenv("OPENROUTER_API_KEY", "pinning-test-key")
    settings.CACHES = {
        "default": {
            "BACKEND": "django.core.cache.backends.redis.RedisCache",
            "LOCATION": os.environ.get("TEST_REDIS_URL", "redis://localhost:6379/15"),
        }
    }
    project = make_project()
    capability = make_capability(project, description="Answer billing questions.")
    dataset = frozen_dataset(
        project, [{"input": "q", "expected_output": "a"}], capability=capability
    )
    run = runs.create_run(
        project=project,
        name="pinned",
        cell=dataset.active_cell,
        mode=EvalRun.Mode.RECORDED,
        matrix=[make_matrix_row(project).snapshot()],
        judge_model="claude-haiku-4-5",
    )
    # A registry change after creation: the run keeps the models it pinned.
    EvalRun.objects.filter(pk=run.pk).update(
        judge_context={**run.judge_context, "decision_model": "typesafe/jev-1.14"},
        status=EvalRun.Status.COMPLETED,
    )
    capability.description = "Something else entirely."
    capability.save()
    fake_llm.decide = lambda *_: "no"

    assert runs.relaunch(run)
    assert runs.start(run.pk) == "score"
    published = []
    generation.dispatch(lambda *_: None, lambda run_id, token: published.append(token))
    assert runs.score(run.pk, published[-1])

    decision = fake_llm.decisions[-1]
    assert decision["model"] == "typesafe/jev-1.14"
    assert "haiku" in fake_llm.requests[-1].body["model"]
    assert EvalRun.objects.get(pk=run.pk).judge_context["intent"] == "Answer billing questions."