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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
from __future__ import annotations
import json
import pytest
from gap_pipeline.release import export_release
from gap_pipeline.store import RunStore, sha256_payload
from gap_pipeline.surface import SURFACE_FAMILIES
def test_offline_release_export_verifies_and_assembles(
tmp_path,
item,
candidate_dict,
) -> None:
source_dir = tmp_path / "source"
source_dir.mkdir()
source_record = {
"index": item.item_id,
"question": item.problem,
"solution": item.solution,
"vars": item.variables,
"params": [],
"sci_consts": [],
"problem_type": "proof",
"variants": {},
}
(source_dir / f"{item.item_id}.json").write_text(
json.dumps(source_record),
encoding="utf-8",
)
surface_root = tmp_path / "surface-runs"
surface_store = RunStore(surface_root, item.item_id)
for family in SURFACE_FAMILIES:
surface_store.write_stage(
f"surface_{family}_variant",
{
"map": {"a": f"name{family.replace('_', '')}"},
"question": f"{family} question",
"solution": f"{family} solution",
},
request_id=None,
)
kernel_root = tmp_path / "kernel-runs"
kernel_store = RunStore(kernel_root, item.item_id)
candidate = {
**candidate_dict,
"node_order": ["n1"],
"terminal_answer": "4",
}
kernel_store.write_final(
{
"item_id": item.item_id,
"status": "accepted",
"proof_dag": {
"nodes": [{"node_id": "n1", "claim": "claim", "dependencies": []}],
"terminal_node_id": "n1",
},
"method_plan": {
"nodes": [{"node_id": "n1", "method_label": "method"}]
},
"accepted_replacement_plan": {
"changes": [
{
"slot_id": "s1",
"source_node_id": "n1",
"description": "value",
"original_value": "1",
"replacement_value": "2",
"guard_condition": "positive",
"guard_justification": "2 is positive",
}
],
"closure_statement": "closed",
},
"accepted_diffused_proof": {
"nodes": [
{
"node_id": "n1",
"dependencies": [],
"method_label": "method",
"instantiated_claim": "claim",
"justification": "reason",
}
],
"terminal_node_id": "n1",
"terminal_answer": "4",
},
"accepted_candidate": candidate,
"accepted_candidate_sha256": sha256_payload(candidate),
"accepted_bundle_sha256": "bundle-sha",
}
)
output_root = tmp_path / "release"
manifest = export_release(
source_dataset=source_dir,
surface_run_root=surface_root,
kernel_run_root=kernel_root,
output_root=output_root,
)
assert manifest["status"] == "complete"
assert manifest["exported_item_count"] == 1
output = json.loads(
(output_root / "records" / f"{item.item_id}.json").read_text()
)
assert set(output["variants"]) == {*SURFACE_FAMILIES, "kernel_variant"}
assert output["variants"]["kernel_variant"]["question"] == candidate["question"]
assert output["variants"]["kernel_variant"]["_meta"]["replacement_plan"]
with pytest.raises(FileExistsError):
export_release(
source_dataset=source_dir,
surface_run_root=surface_root,
kernel_run_root=kernel_root,
output_root=output_root,
)
|