test(gate): add unit tests for the evaluation gate decision core#122
Open
nankingjing wants to merge 1 commit into
Open
test(gate): add unit tests for the evaluation gate decision core#122nankingjing wants to merge 1 commit into
nankingjing wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
tests/test_gate.py— 22 unit tests forskillopt/evaluation/gate.py, the optimizer's validation-gate decision core (select_gate_score,evaluate_gate,GateResult).Why
skillopt/evaluation/gate.pyis the accept/reject decision at the heart of the ReflACT training loop — the analog of validation-based model selection / early stopping. It decides whether a candidate skill becomes the new current skill and whether it is promoted to best-so-far. Despite being pure, side-effect-free logic (the trainer owns all I/O), it currently has no dedicated test coverage — it is only reached indirectly throughengine/trainer.py, so a regression in the gate's branching or metric math would ship silently.This is in the spirit of #94 (bring
evaluate_gateunder direct test), applied to the main optimizer's gate.Coverage
select_gate_score:hard/soft/ default-metric projectionmixedweighting (default weight, custom weight,w=0→hard,w=1→soft)mixed_weightclamping to[0, 1](both directions)float; unknown metric raisesValueErrorevaluate_gate— all three actions and their exact resulting state:accept_new_best(beats current and best;best_stepadvances toglobal_step)accept(beats current, not best; best-so-far incl.best_steppreserved) — the branch only reachable whencurrent_score < best_scorereject(does not beat current; all state preserved)>semantics: a tie withcurrent_scoreis rejected (no lateral moves); a tie withbest_scoreabove current is anaccept, not a new bestcand_soft(soft/mixed), and that the defaulthardmetric ignorescand_softGateResult: field wiring and frozen-dataclass immutability.Plus a behavioral invariant test documenting that when
s_cur == s_bestat the start (the trainer's initialization), the two stay locked together and theacceptbranch is never taken — capturing the design property discussed in #113.Verification
Tests are pure-logic (no LLM, rollout, or network). Ran the full file against the unmodified
gate.py: 22 passed. Style matches the existing suite (tests/test_scoring.py,tests/test_types.py): class-grouped,pytest.approxfor float math, docstrings per group.No production code changed — tests only.