Merged
fix(ops-perf-optimize): 兼容已实测终选记录的 decision 字段 #428
wychenAdd on 7 days ago
fix(ops-perf-optimize): 兼容已实测终选记录的 decision 字段 #428
Merged
Total: 3 files changed+76-7
| @@ -0,0 +1 @@ | |||
| 1 | +- 【ops-perf-optimize】修复已实测终选记录仅含明确 decision 字段时经验回流阻塞的问题,兼容读取且保留冻结证据和既有校验。 | ||
Mplugins-official/ops-perf-optimize/skills/ops-perf-optimize-workflow/scripts/experience_reflux.py+10-2
| @@ -134,8 +134,16 @@ def selection_outcome(selection): | |||
| 134 | if outcome in ("implementation_failed", "screened", "no_candidate"): | 134 | if outcome in ("implementation_failed", "screened", "no_candidate"): |
| 135 | require(selection.get("candidate_accepted") is not True, "failed candidate marked accepted") | 135 | require(selection.get("candidate_accepted") is not True, "failed candidate marked accepted") |
| 136 | return outcome | 136 | return outcome |
| 137 | - require(isinstance(selection.get("candidate_accepted"), bool), "selection lacks candidate_accepted") | 137 | + accepted = selection.get("candidate_accepted") |
| 138 | - return "accepted" if selection["candidate_accepted"] else "rejected" | 138 | + if "candidate_accepted" not in selection and outcome == "measured": |
| 139 | + # Legacy measured selections record the same choice in decision. | ||
| 140 | + decision = selection.get("decision") | ||
| 141 | + if decision == "retain_candidate": | ||
| 142 | + accepted = True | ||
| 143 | + elif decision == "retain_baseline": | ||
| 144 | + accepted = False | ||
| 145 | + require(isinstance(accepted, bool), "selection lacks candidate_accepted") | ||
| 146 | + return "accepted" if accepted else "rejected" | ||
| 139 | 147 | ||
| 140 | 148 | ||
| 141 | def validate_bundle(bundle_path, manifest_path): | 149 | def validate_bundle(bundle_path, manifest_path): |
| @@ -9,7 +9,6 @@ | |||
| 9 | # ----------------------------------------------------------------------------------------------------------- | 9 | # ----------------------------------------------------------------------------------------------------------- |
| 10 | 10 | ||
| 11 | """Exercise both values of the evidence gate; fixtures are not content reviews.""" | 11 | """Exercise both values of the evidence gate; fixtures are not content reviews.""" |
| 12 | -import copy | ||
| 13 | import json | 12 | import json |
| 14 | import sys | 13 | import sys |
| 15 | from pathlib import Path | 14 | from pathlib import Path |
| @@ -21,7 +20,7 @@ ROOT = Path(__file__).resolve().parents[1] | |||
| 21 | sys.path.insert(0, str(ROOT / "skills/ops-perf-optimize-workflow/scripts")) | 20 | sys.path.insert(0, str(ROOT / "skills/ops-perf-optimize-workflow/scripts")) |
| 22 | import experience_reflux as reflux | 21 | import experience_reflux as reflux |
| 23 | import workflow_state as workflow | 22 | import workflow_state as workflow |
| 24 | -from test_search_installed import installed_search, python as installed_python | 23 | +from test_search_installed import installed_search, python as installed_python # noqa: F401 |
| 25 | 24 | ||
| 26 | 25 | ||
| 27 | def save(path, value): | 26 | def save(path, value): |
| @@ -148,6 +147,65 @@ def test_structure_only_is_not_semantic_pass(case): | |||
| 148 | assert reflux.validate(case.bp, case.manifest)["status"] == "structure_pass" | 147 | assert reflux.validate(case.bp, case.manifest)["status"] == "structure_pass" |
| 149 | 148 | ||
| 150 | 149 | ||
| 150 | +@pytest.mark.parametrize("decision,outcome", [ | ||
| 151 | + ("retain_candidate", "accepted"), | ||
| 152 | + ("retain_baseline", "rejected"), | ||
| 153 | +]) | ||
| 154 | +def test_legacy_decision_renders_without_rewriting_frozen_inputs(case, decision, outcome): | ||
| 155 | + import subprocess | ||
| 156 | + | ||
| 157 | + selection_path = case.root / "implementation/round1/selection.json" | ||
| 158 | + selection = json.loads(selection_path.read_text()) | ||
| 159 | + selection.pop("candidate_accepted") | ||
| 160 | + selection["decision"] = decision | ||
| 161 | + save(selection_path, selection) | ||
| 162 | + reference = reflux.file_ref(selection_path) | ||
| 163 | + case.state["stages"]["round1.complete"]["artifacts"] = [reference] | ||
| 164 | + state_path = save(case.root / "workflow-state.json", case.state) | ||
| 165 | + case.bundle["sources"]["selection1"] = reference | ||
| 166 | + case.bundle["rounds"][0]["outcome"] = outcome | ||
| 167 | + save(case.bp, case.bundle) | ||
| 168 | + frozen = {path: path.read_bytes() for path in (selection_path, state_path, case.bp, case.manifest)} | ||
| 169 | + material = case.root / "legacy-material.md" | ||
| 170 | + | ||
| 171 | + result = subprocess.run([ | ||
| 172 | + sys.executable, "-B", str(ROOT / "skills/ops-perf-optimize-workflow/scripts/experience_reflux.py"), | ||
| 173 | + "render", "--manifest", str(case.manifest), "--bundle", str(case.bp), "--out", str(material), | ||
| 174 | + ], text=True, capture_output=True, check=False) | ||
| 175 | + | ||
| 176 | + assert result.returncode == 0, result.stdout + result.stderr | ||
| 177 | + assert f"| round1.complete | {outcome} |" in material.read_text() | ||
| 178 | + assert all(path.read_bytes() == content for path, content in frozen.items()) | ||
| 179 | + | ||
| 180 | + | ||
| 181 | +@pytest.mark.parametrize("selection", [ | ||
| 182 | + {"search": {"outcome": "measured"}}, | ||
| 183 | + {"decision": "unknown", "search": {"outcome": "measured"}}, | ||
| 184 | + {"decision": "retain_candidate", "search": {}}, | ||
| 185 | + {"candidate_accepted": None, "decision": "retain_candidate", "search": {"outcome": "measured"}}, | ||
| 186 | + {"candidate_accepted": "true", "decision": "retain_candidate", "search": {"outcome": "measured"}}, | ||
| 187 | +]) | ||
| 188 | +def test_legacy_decision_does_not_accept_ambiguous_or_invalid_records(selection): | ||
| 189 | + with pytest.raises(ValueError, match="selection lacks candidate_accepted"): | ||
| 190 | + reflux.selection_outcome(selection) | ||
| 191 | + | ||
| 192 | + | ||
| 193 | +@pytest.mark.parametrize("accepted", [True, False]) | ||
| 194 | +def test_explicit_candidate_accepted_remains_authoritative(accepted): | ||
| 195 | + selection = { | ||
| 196 | + "candidate_accepted": accepted, | ||
| 197 | + "decision": "retain_baseline" if accepted else "retain_candidate", | ||
| 198 | + "search": {"outcome": "measured"}, | ||
| 199 | + } | ||
| 200 | + assert reflux.selection_outcome(selection) == ("accepted" if accepted else "rejected") | ||
| 201 | + | ||
| 202 | + | ||
| 203 | +@pytest.mark.parametrize("outcome", ["implementation_failed", "screened", "no_candidate"]) | ||
| 204 | +def test_failed_outcome_still_rejects_accepted_candidate(outcome): | ||
| 205 | + with pytest.raises(ValueError, match="failed candidate marked accepted"): | ||
| 206 | + reflux.selection_outcome({"candidate_accepted": True, "search": {"outcome": outcome}}) | ||
| 207 | + | ||
| 208 | + | ||
| 151 | @pytest.mark.parametrize( | 209 | @pytest.mark.parametrize( |
| 152 | "mutation,reason", | 210 | "mutation,reason", |
| 153 | [ | 211 | [ |
| @@ -387,10 +445,12 @@ def test_cli_cannot_overwrite_evidence(case, monkeypatch): | |||
| 387 | assert source.read_bytes() == before | 445 | assert source.read_bytes() == before |
| 388 | 446 | ||
| 389 | 447 | ||
| 390 | -def test_installed_gate_runs_without_source_checkout_imports(case, installed_search): | 448 | +@pytest.mark.usefixtures("installed_search") |
| 391 | - output = installed_python(installed_search, | 449 | +def test_installed_gate_runs_without_source_checkout_imports(case, request): |
| 450 | + installation = request.getfixturevalue("installed_search") | ||
| 451 | + output = installed_python(installation, | ||
| 392 | "import experience_reflux as e; import workflow_state; " | 452 | "import experience_reflux as e; import workflow_state; " |
| 393 | "print(e.validate(sys.argv[2], sys.argv[3], material_path=sys.argv[4], " | 453 | "print(e.validate(sys.argv[2], sys.argv[3], material_path=sys.argv[4], " |
| 394 | "review_path=sys.argv[5])['status'])", case.bp, case.manifest, case.material, case.rp) | 454 | "review_path=sys.argv[5])['status'])", case.bp, case.manifest, case.material, case.rp) |
| 395 | assert output.strip() == "pass" | 455 | assert output.strip() == "pass" |
| 396 | - assert (installed_search["skills"] / "ops-perf-postprocess/references/experience-reflux.md").is_file() | 456 | + assert (installation["skills"] / "ops-perf-postprocess/references/experience-reflux.md").is_file() |