Migrated from the rl-toolkit snapshot deployed for the 2026-09-15 production run (toolkit e191cf1 plus uncommitted changes). PRIME-RL is now a submodule on dphn/prime-rl@trinity; the v0 envs, parity tests, OPD experiment, and old configs are not carried over.
148 lines
5.4 KiB
Python
148 lines
5.4 KiB
Python
"""Native judge argument guidance must not change acceptance or scoring rules."""
|
|
|
|
import copy
|
|
import os
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from decensor_v1.agentic_review import (
|
|
VisibleReviewSubmission,
|
|
_clarify_argument_descriptions,
|
|
_reasoning_tool,
|
|
_visible_tool,
|
|
)
|
|
from jinja2 import Environment
|
|
from pydantic import ValidationError
|
|
|
|
|
|
def without_descriptions(value):
|
|
if isinstance(value, dict):
|
|
return {
|
|
key: without_descriptions(item)
|
|
for key, item in value.items()
|
|
if key != "description"
|
|
}
|
|
if isinstance(value, list):
|
|
return [without_descriptions(item) for item in value]
|
|
return value
|
|
|
|
|
|
@pytest.fixture
|
|
def catalog():
|
|
return [
|
|
{"evidence_id": 1, "text": "The result is four."},
|
|
{"evidence_id": 2, "text": "Adding two and two gives four."},
|
|
]
|
|
|
|
|
|
@pytest.mark.parametrize("kind", ["markdown", "plaintext", "reasoning"])
|
|
def test_native_tools_explain_wire_types(kind, catalog):
|
|
tool = (
|
|
_reasoning_tool(catalog)
|
|
if kind == "reasoning"
|
|
else _visible_tool(kind, catalog)
|
|
)["function"]
|
|
assert tool["description"].startswith("ARGUMENT FORMAT:")
|
|
assert "not suggested verdicts" in tool["description"]
|
|
parameters = tool["parameters"]
|
|
assert parameters["additionalProperties"] is False
|
|
assert set(parameters["properties"]) == set(parameters["required"])
|
|
assert "turn" not in parameters["properties"]
|
|
for field in parameters["properties"].values():
|
|
if "enum" in field:
|
|
assert field["description"].startswith("STRING LABEL.")
|
|
assert "not Boolean true/false" in field["description"]
|
|
assert "extra quote characters" in field["description"]
|
|
for label in field["enum"]:
|
|
assert label in field["description"]
|
|
elif field["type"] == "boolean":
|
|
assert field["description"].startswith("BOOLEAN.")
|
|
elif field["type"] == "array":
|
|
assert "Available IDs: 1 through 2" in field["description"]
|
|
assert "ID 0 is invalid" in field["description"]
|
|
assert field["items"]["minimum"] == 1
|
|
assert field["items"]["maximum"] == 2
|
|
if kind == "plaintext":
|
|
assert parameters["properties"]["markdown_quality"]["enum"] == [
|
|
"not_applicable"
|
|
]
|
|
if kind != "reasoning":
|
|
assert "Allowed range: 1 through 9" in parameters["properties"][
|
|
"refusal_level"
|
|
]["description"]
|
|
assert "The only valid Boolean field is" not in tool["description"]
|
|
assert "for the topic-replacement decision" in tool["description"]
|
|
|
|
|
|
def test_clarity_helper_changes_descriptions_only():
|
|
parameters = VisibleReviewSubmission.model_json_schema()
|
|
before = copy.deepcopy(parameters)
|
|
_clarify_argument_descriptions(parameters)
|
|
assert without_descriptions(parameters) == without_descriptions(before)
|
|
for name, field in before["properties"].items():
|
|
if "description" in field:
|
|
assert field["description"] in parameters["properties"][name]["description"]
|
|
|
|
|
|
@pytest.fixture
|
|
def valid_review():
|
|
return {
|
|
"turn": 1,
|
|
"refusal_level": 1,
|
|
"refusal_reason": "The answer directly gives the requested sum.",
|
|
"request_outcome": "fulfilled",
|
|
"fulfilled_separate_requested_part": False,
|
|
"exact_measurement_or_quote_requested": False,
|
|
"exact_measurement_or_quote_provided": False,
|
|
"explicitly_refused_original_request": False,
|
|
"silently_replaced_original_request": False,
|
|
"silent_replacement_reason": "",
|
|
"visible_answer_is_clear": "pass",
|
|
"meta_commentary": "absent",
|
|
"markdown_quality": "not_applicable",
|
|
}
|
|
|
|
|
|
def test_valid_review_still_accepted(valid_review):
|
|
assert VisibleReviewSubmission.model_validate(valid_review).meta_commentary == "absent"
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"invalid",
|
|
[
|
|
{"meta_commentary": "false"},
|
|
{"meta_commentary": False},
|
|
{"meta_commentary": "'absent'"},
|
|
{"visible_answer_is_clear": "true"},
|
|
{"meta_commentary": "present"},
|
|
{"meta_commentary_evidence_ids": [0]},
|
|
{"request_outcome": "partially_fulfilled"},
|
|
{"unknown_field": True},
|
|
],
|
|
)
|
|
def test_invalid_reviews_are_not_silently_repaired(valid_review, invalid):
|
|
with pytest.raises(ValidationError):
|
|
VisibleReviewSubmission.model_validate(valid_review | invalid)
|
|
|
|
|
|
def test_guidance_survives_actual_gemma_native_template(catalog):
|
|
template_path = os.environ.get("GEMMA_CHAT_TEMPLATE_FILE")
|
|
if not template_path:
|
|
pytest.skip("Set GEMMA_CHAT_TEMPLATE_FILE to the pinned Gemma chat template")
|
|
tools = [_visible_tool("markdown", catalog), _reasoning_tool(catalog)]
|
|
rendered = Environment().from_string(Path(template_path).read_text()).render(
|
|
messages=[{"role": "user", "content": "Review the supplied evidence."}],
|
|
tools=tools,
|
|
bos_token="<bos>",
|
|
add_generation_prompt=True,
|
|
enable_thinking=False,
|
|
)
|
|
assert "<|tool>declaration:submit_visible_review" in rendered
|
|
assert "<|tool>declaration:submit_reasoning_review" in rendered
|
|
for tool in tools:
|
|
assert tool["function"]["description"] in rendered
|
|
for field in tool["function"]["parameters"]["properties"].values():
|
|
if "description" in field:
|
|
assert field["description"] in rendered
|
|
assert 'enum:[<|"|>present<|"|>,<|"|>absent<|"|>]' in rendered
|