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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
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,
apply_rename_map,
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 == apply_rename_map(
item.problem, {"a": "positivequantity"}
)
assert variant.solution == apply_rename_map(
item.solution, {"a": "positivequantity"}
)
assert "that" in variant.question
assert "expand" in variant.solution
assert "obtain" in variant.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",
)
def test_surface_text_must_be_only_a_token_safe_rename(item) -> None:
rename_map = {"a": "positivequantity"}
question = apply_rename_map(item.problem, rename_map)
solution = apply_rename_map(item.solution, rename_map)
validate_surface_variant(
item,
rename_map=rename_map,
question=question,
solution=solution,
)
with pytest.raises(ValueError, match="exact deterministic rename"):
validate_surface_variant(
item,
rename_map=rename_map,
question=question + " Extra text.",
solution=solution,
)
|