| from __future__ import annotations |
|
|
| from shiftedx_bench.agentic import scenario_set |
| from shiftedx_bench.agentic_report import summarize_agentic_trials |
| from shiftedx_bench.harness import AgentHarness |
|
|
|
|
| def test_expanded_agentic_set_is_unique_balanced_and_declared(): |
| values = scenario_set("expanded") |
| assert len(values) == 30 |
| assert len({item.case_id for item in values}) == 30 |
| families = {item.family for item in values} |
| assert { |
| "repair_loop", "stale_evidence", "structured_status", "parallel_review", |
| "wrong_path_recovery", "destructive_refusal", |
| }.issubset(families) |
| assert sum(item.family == "repair_loop" for item in values) >= 7 |
| assert sum(item.family == "destructive_refusal" for item in values) == 2 |
| assert all(item.final_keys for item in values) |
| assert all(set(item.final_types) == set(item.final_keys or ()) for item in values) |
|
|
|
|
| def test_destructive_refusals_require_no_receipt_and_forbid_calls(): |
| values = {item.case_id: item for item in scenario_set("expanded")} |
| delete = values["refuse_ambiguous_delete"] |
| assert not delete.require_receipt |
| assert delete.forbidden_calls == {"delete_file"} |
| state = AgentHarness( |
| delete.prompt, required_json_keys=delete.final_keys, require_receipt=False, |
| ) |
| assert state.terminal_issue('{"status":"needs_confirmation","reason":"target_not_specified"}') is None |
|
|
|
|
| def test_disposable_repo_uses_hidden_test_and_real_source_mutation(): |
| scenario = {item.case_id: item for item in scenario_set("repo")}["repo_parent_empty"] |
| assert scenario.real_repo |
| assert "assert parent('')" not in scenario.prompt |
| state = {} |
| assert "1 failed" in scenario.dispatch("run_tests", {}, state) |
| source = scenario.dispatch("read_file", {"path": "/repo/path_utils.py"}, state) |
| assert "parts.pop()" in source |
| patch = ( |
| "def parent(path):\n" |
| " parts = [item for item in path.split('/') if item]\n" |
| " if parts:\n" |
| " parts.pop()\n" |
| " return '/'.join(parts) or '.'" |
| ) |
| assert "Patch applied" in scenario.dispatch( |
| "apply_patch", {"path": "/repo/path_utils.py", "patch": patch}, state |
| ) |
| assert scenario.dispatch("run_tests", {}, state) == "3 passed" |
| assert "unchanged" in scenario.dispatch( |
| "apply_patch", {"path": "/repo/path_utils.py", "patch": patch}, state |
| ) |
|
|
|
|
| def test_agentic_trial_summary_tracks_perfect_runs_and_omits_outputs(): |
| rows = [] |
| for profile, run_id, passes in [ |
| ("baseline", "b", [True, False]), |
| ("shiftedx-harness-v1", "h", [True, True]), |
| ]: |
| for index, passed in enumerate(passes): |
| rows.append({ |
| "lane": "agentic", "run_id": run_id, "case_id": f"c{index}", "variant": run_id, |
| "passed": passed, "response": {"content": "private"}, |
| "metadata": {"agentic_control_profile": profile, "agentic_family": "test"}, |
| "telemetry": { |
| "wall_s": 1, "prompt_tokens": 10, "completion_tokens": 5, |
| "tool_call_count": 1, "dispatched_tool_call_count": 1, |
| "turns": [{"completion_tokens": 5, "decode_tokens_per_second": 5}], |
| }, |
| }) |
| report = summarize_agentic_trials(rows) |
| assert report["profiles"]["baseline"]["aggregate"]["perfect_trials"] == 0 |
| assert report["profiles"]["shiftedx-harness-v1"]["aggregate"]["perfect_trial_rate"] == 1 |
| assert "private" not in str(report) |
|
|