summaryrefslogtreecommitdiff
path: root/tests/test_surface.py
blob: 4d92de3cac29d44b1033bd2bfff02d84a290296c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from __future__ import annotations

import asyncio

import pytest

from gap_pipeline.clients import ScriptedClient
from gap_pipeline.store import RunStore
from gap_pipeline.surface import SurfacePipeline, validate_surface_variant


def test_surface_pipeline_uses_full_original_contract(tmp_path, item) -> None:
    response = {
        "map": {"a": "positivequantity"},
        "question": r"Let \(positivequantity>0\). Prove the renamed inequality.",
        "solution": r"Apply the same proof to \(positivequantity\).",
    }
    client = ScriptedClient(
        {f"{item.item_id}.surface.descriptive_long": response}
    )
    variant = asyncio.run(
        SurfacePipeline(
            client,
            RunStore(tmp_path, item.item_id),
        ).run_family(item, "descriptive_long")
    )
    assert variant.rename_map == {"a": "positivequantity"}
    assert variant.question == response["question"]
    assert variant.solution == response["solution"]


def test_missing_symbol_and_nonbijection_are_rejected(item) -> None:
    with pytest.raises(ValueError, match="every var and param"):
        validate_surface_variant(
            item,
            rename_map={},
            question="question",
            solution="solution",
        )

    item.variables.append("b")
    with pytest.raises(ValueError, match="one-to-one"):
        validate_surface_variant(
            item,
            rename_map={"a": "sharedname", "b": "sharedname"},
            question="question",
            solution="solution",
        )


def test_original_identifier_contract_is_enforced(item) -> None:
    with pytest.raises(ValueError, match="original prompt contract"):
        validate_surface_variant(
            item,
            rename_map={"a": "TooShort"},
            question="question",
            solution="solution",
        )