feat: seaborn is disqualifying (hard gate) across all raters + detect_seaborn for import/usage forms
Browse files- README.md +45 -5
- audit_corpus/labels.json +49 -21
- audit_corpus/viol_seaborn_bare_sns.py +14 -0
- audit_corpus/viol_seaborn_from_import.py +16 -0
- guac_coder/__init__.py +8 -0
- guac_coder/decision_judge.py +9 -0
- guac_coder/grpo_rewards.py +60 -8
- guac_coder/rewards.py +32 -2
- tests/test_decision_judge.py +19 -3
- tests/test_seaborn_gate.py +184 -0
README.md
CHANGED
|
@@ -25,7 +25,7 @@ and is collected by `compute_grpo_rewards()`:
|
|
| 25 |
| # | Rule | Function | Intent |
|
| 26 |
|---|---|---|---|
|
| 27 |
| 1 | chroptiks preference | `chroptiks_preference_reward` | reward `chroptiks` for plotting |
|
| 28 |
-
| 2 | no seaborn | `no_seaborn_reward` | punish `seaborn` |
|
| 29 |
| 3 | no plot grids | `no_plot_grids_reward` | punish `grid(...)` |
|
| 30 |
| 4 | no plot titles | `no_plot_titles_reward` | punish `title(...)` |
|
| 31 |
| 5 | no bar graphs | `no_bargraphs_reward` | punish bar/barh/pie charts |
|
|
@@ -40,6 +40,42 @@ and is collected by `compute_grpo_rewards()`:
|
|
| 40 |
|
| 41 |
The unweighted mean of the 13 rules is the scalar reward (`combined_grpo_reward`).
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
A **legacy** 12-rule path also lives in `guac_coder/rewards.py`
|
| 44 |
(`compute_static_rewards` / `compute_total_reward`), plus an optional LLM-as-judge
|
| 45 |
component (`compute_llm_judge_reward`) that calls `npcpy.llm_funcs.get_llm_response`
|
|
@@ -108,8 +144,8 @@ guac-audit --corpus ./audit_corpus --rater-a static --rater-b decision \
|
|
| 108 |
```
|
| 109 |
|
| 110 |
```
|
| 111 |
-
Rater audit: static vs decision over
|
| 112 |
-
compared:
|
| 113 |
|
| 114 |
rule n agree abstain static>0,decision<0 mean gap
|
| 115 |
objective_comments_reward 11 0.00 10 0 1.50
|
|
@@ -162,6 +198,8 @@ regression case in `audit_corpus/`:
|
|
| 162 |
| `plt.bar(...)`, `ax.barh(...)` | same prefix problem |
|
| 163 |
| `sns.set_style("whitegrid")` | enables grids via a *string*, never calls `grid(...)` |
|
| 164 |
| `plt.style.use("seaborn-v0_8-whitegrid")` | same |
|
|
|
|
|
|
|
| 165 |
|
| 166 |
Run the audit after any reward change and diff the report against the previous
|
| 167 |
one -- agreement going down, or a new `static>0, decision<0` entry, means the
|
|
@@ -169,7 +207,7 @@ edit introduced a hole.
|
|
| 169 |
|
| 170 |
**Agreement is not accuracy.** A weak second rater can disagree with a correct
|
| 171 |
rule. Always read the labeled-accuracy block, which is why the corpus carries
|
| 172 |
-
labels. Measured on the current
|
| 173 |
|
| 174 |
| rater | labeled accuracy |
|
| 175 |
|---|---|
|
|
@@ -194,7 +232,9 @@ nothing collects a large total:
|
|
| 194 |
| `viol_grids_titles.py` (grids **and** titles) | `+0.038` |
|
| 195 |
| empty / `pass` / comments only | `-1.000` |
|
| 196 |
|
| 197 |
-
So `x = 1` outranks a script that has two real violations.
|
|
|
|
|
|
|
| 198 |
|
| 199 |
* absolute reward values are not comparable across snippets of different
|
| 200 |
structure; only the *ranking within a GRPO group* is meaningful;
|
|
|
|
| 25 |
| # | Rule | Function | Intent |
|
| 26 |
|---|---|---|---|
|
| 27 |
| 1 | chroptiks preference | `chroptiks_preference_reward` | reward `chroptiks` for plotting |
|
| 28 |
+
| 2 | no seaborn | `no_seaborn_reward` | punish `seaborn` (**hard gate** -- see below) |
|
| 29 |
| 3 | no plot grids | `no_plot_grids_reward` | punish `grid(...)` |
|
| 30 |
| 4 | no plot titles | `no_plot_titles_reward` | punish `title(...)` |
|
| 31 |
| 5 | no bar graphs | `no_bargraphs_reward` | punish bar/barh/pie charts |
|
|
|
|
| 40 |
|
| 41 |
The unweighted mean of the 13 rules is the scalar reward (`combined_grpo_reward`).
|
| 42 |
|
| 43 |
+
### Seaborn is disqualifying, not a soft penalty
|
| 44 |
+
|
| 45 |
+
`seaborn` is a **hard gate**, not merely rule 2. If the snippet uses seaborn,
|
| 46 |
+
every rule collapses to `SEABORN_FLOOR` (`-1.0`) and the total is `-1.0`,
|
| 47 |
+
whatever else the script does right:
|
| 48 |
+
|
| 49 |
+
```python
|
| 50 |
+
>>> combined_grpo_reward(EXCELLENT_SCRIPT_THAT_IMPORTS_SEABORN) # logging, to_csv,
|
| 51 |
+
-1.0 # chroptiks, resume, __main__ guard
|
| 52 |
+
>>> combined_grpo_reward(CLEAN_BUT_PLAIN_SCRIPT)
|
| 53 |
+
0.154
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
This is deliberate. Each rule rewards the *absence* of a violation, so a soft
|
| 57 |
+
penalty let a well-structured seaborn script outscore honest code -- the rules
|
| 58 |
+
were paying for seaborn. The gate applies in **every** rater:
|
| 59 |
+
|
| 60 |
+
| rater | how the gate applies |
|
| 61 |
+
|---|---|
|
| 62 |
+
| `static` | requires no request |
|
| 63 |
+
| `decision` | decided from the code, so the model is never called and cannot disagree |
|
| 64 |
+
| `llm` (legacy) | short-circuits before the judge, so a generous judge cannot offset it |
|
| 65 |
+
|
| 66 |
+
All three forms are caught -- a plain import, `from seaborn import ...`, and a
|
| 67 |
+
bare `sns.`/`seaborn.` call with no visible import:
|
| 68 |
+
|
| 69 |
+
```python
|
| 70 |
+
from guac_coder import detect_seaborn, uses_seaborn
|
| 71 |
+
detect_seaborn("from seaborn import scatterplot") # 'from seaborn import scatterplot'
|
| 72 |
+
detect_seaborn("def f(): sns.barplot()") # 'sns. usage'
|
| 73 |
+
detect_seaborn("import matplotlib.pyplot as plt") # None (not gated)
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
`matplotlib` is discouraged (it loses rule 1 to `chroptiks`) but is **not**
|
| 77 |
+
disqualifying; only seaborn is.
|
| 78 |
+
|
| 79 |
A **legacy** 12-rule path also lives in `guac_coder/rewards.py`
|
| 80 |
(`compute_static_rewards` / `compute_total_reward`), plus an optional LLM-as-judge
|
| 81 |
component (`compute_llm_judge_reward`) that calls `npcpy.llm_funcs.get_llm_response`
|
|
|
|
| 144 |
```
|
| 145 |
|
| 146 |
```
|
| 147 |
+
Rater audit: static vs decision over 13 cases
|
| 148 |
+
compared: 13 mean total: static=0.1482 decision=0.1823
|
| 149 |
|
| 150 |
rule n agree abstain static>0,decision<0 mean gap
|
| 151 |
objective_comments_reward 11 0.00 10 0 1.50
|
|
|
|
| 198 |
| `plt.bar(...)`, `ax.barh(...)` | same prefix problem |
|
| 199 |
| `sns.set_style("whitegrid")` | enables grids via a *string*, never calls `grid(...)` |
|
| 200 |
| `plt.style.use("seaborn-v0_8-whitegrid")` | same |
|
| 201 |
+
| `from seaborn import scatterplot` | only `import seaborn` was matched, so this scored **+0.077** |
|
| 202 |
+
| bare `sns.barplot(...)`, no import | usage without an import was invisible, also **+0.077** |
|
| 203 |
|
| 204 |
Run the audit after any reward change and diff the report against the previous
|
| 205 |
one -- agreement going down, or a new `static>0, decision<0` entry, means the
|
|
|
|
| 207 |
|
| 208 |
**Agreement is not accuracy.** A weak second rater can disagree with a correct
|
| 209 |
rule. Always read the labeled-accuracy block, which is why the corpus carries
|
| 210 |
+
labels. Measured on the current 13-case corpus:
|
| 211 |
|
| 212 |
| rater | labeled accuracy |
|
| 213 |
|---|---|
|
|
|
|
| 232 |
| `viol_grids_titles.py` (grids **and** titles) | `+0.038` |
|
| 233 |
| empty / `pass` / comments only | `-1.000` |
|
| 234 |
|
| 235 |
+
So `x = 1` outranks a script that has two real violations. Seaborn is the one
|
| 236 |
+
exception: the hard gate puts it at `-1.000`, below everything. Two consequences
|
| 237 |
+
of the floor remain for the *other* rules:
|
| 238 |
|
| 239 |
* absolute reward values are not comparable across snippets of different
|
| 240 |
structure; only the *ranking within a GRPO group* is meaningful;
|
audit_corpus/labels.json
CHANGED
|
@@ -1,33 +1,61 @@
|
|
| 1 |
{
|
| 2 |
"clean_full.py": {
|
| 3 |
-
"
|
|
|
|
|
|
|
|
|
|
| 4 |
"no_plot_grids_reward": 0.5,
|
| 5 |
"no_plot_titles_reward": 0.5,
|
| 6 |
-
"
|
| 7 |
"no_try_except_reward": 0.5,
|
| 8 |
-
"no_classes_reward": 0.5,
|
| 9 |
"not_bare_script_reward": 0.5,
|
| 10 |
-
"
|
| 11 |
-
"pandas_csv_preference_reward": 1.0,
|
| 12 |
-
"logging_over_print_reward": 1.0
|
| 13 |
},
|
| 14 |
"clean_minimal.py": {
|
| 15 |
-
"
|
|
|
|
|
|
|
| 16 |
"no_plot_grids_reward": 0.5,
|
| 17 |
"no_plot_titles_reward": 0.5,
|
| 18 |
-
"
|
| 19 |
"no_try_except_reward": 0.5,
|
| 20 |
-
"
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
"viol_bargraph_seaborn_api.py": {
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
"
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"clean_full.py": {
|
| 3 |
+
"chroptiks_preference_reward": 1.0,
|
| 4 |
+
"logging_over_print_reward": 1.0,
|
| 5 |
+
"no_bargraphs_reward": 0.5,
|
| 6 |
+
"no_classes_reward": 0.5,
|
| 7 |
"no_plot_grids_reward": 0.5,
|
| 8 |
"no_plot_titles_reward": 0.5,
|
| 9 |
+
"no_seaborn_reward": 0.5,
|
| 10 |
"no_try_except_reward": 0.5,
|
|
|
|
| 11 |
"not_bare_script_reward": 0.5,
|
| 12 |
+
"pandas_csv_preference_reward": 1.0
|
|
|
|
|
|
|
| 13 |
},
|
| 14 |
"clean_minimal.py": {
|
| 15 |
+
"chroptiks_preference_reward": 0.0,
|
| 16 |
+
"no_bargraphs_reward": 0.5,
|
| 17 |
+
"no_classes_reward": 0.5,
|
| 18 |
"no_plot_grids_reward": 0.5,
|
| 19 |
"no_plot_titles_reward": 0.5,
|
| 20 |
+
"no_seaborn_reward": 0.5,
|
| 21 |
"no_try_except_reward": 0.5,
|
| 22 |
+
"not_bare_script_reward": 0.5
|
| 23 |
+
},
|
| 24 |
+
"viol_bare_script.py": {
|
| 25 |
+
"not_bare_script_reward": -1.0
|
| 26 |
+
},
|
| 27 |
+
"viol_bargraph_seaborn_api.py": {
|
| 28 |
+
"no_bargraphs_reward": -1.0,
|
| 29 |
+
"no_seaborn_reward": -1.0
|
| 30 |
+
},
|
| 31 |
+
"viol_classes.py": {
|
| 32 |
+
"no_classes_reward": -1.0
|
| 33 |
+
},
|
| 34 |
+
"viol_dictwriter.py": {
|
| 35 |
+
"pandas_csv_preference_reward": -1.0
|
| 36 |
+
},
|
| 37 |
+
"viol_grids_titles.py": {
|
| 38 |
+
"no_plot_grids_reward": -1.0,
|
| 39 |
+
"no_plot_titles_reward": -1.0
|
| 40 |
+
},
|
| 41 |
+
"viol_narrative.py": {
|
| 42 |
+
"objective_comments_reward": -1.0
|
| 43 |
+
},
|
| 44 |
+
"viol_prints.py": {
|
| 45 |
+
"logging_over_print_reward": -1.0
|
| 46 |
+
},
|
| 47 |
+
"viol_seaborn.py": {
|
| 48 |
+
"chroptiks_preference_reward": -1.0,
|
| 49 |
+
"no_seaborn_reward": -1.0
|
| 50 |
+
},
|
| 51 |
+
"viol_seaborn_bare_sns.py": {
|
| 52 |
+
"no_seaborn_reward": -1.0
|
| 53 |
+
},
|
| 54 |
+
"viol_seaborn_from_import.py": {
|
| 55 |
+
"chroptiks_preference_reward": -1.0,
|
| 56 |
+
"no_seaborn_reward": -1.0
|
| 57 |
+
},
|
| 58 |
+
"viol_try_except.py": {
|
| 59 |
+
"no_try_except_reward": -1.0
|
| 60 |
+
}
|
| 61 |
}
|
audit_corpus/viol_seaborn_bare_sns.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Bare sns usage with no visible import, otherwise clean structure."""
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
|
| 5 |
+
logger = logging.getLogger(__name__)
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def draw(df):
|
| 9 |
+
logger.info("drawing %d rows", len(df))
|
| 10 |
+
sns.barplot(data=df, x="a", y="b")
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
if __name__ == "__main__":
|
| 14 |
+
draw([{"a": 1, "b": 2}])
|
audit_corpus/viol_seaborn_from_import.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Seaborn reached through a from-import, with otherwise clean structure."""
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
|
| 5 |
+
from seaborn import scatterplot
|
| 6 |
+
|
| 7 |
+
logger = logging.getLogger(__name__)
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def draw(df):
|
| 11 |
+
logger.info("drawing %d rows", len(df))
|
| 12 |
+
scatterplot(data=df, x="a", y="b")
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
if __name__ == "__main__":
|
| 16 |
+
draw([{"a": 1, "b": 2}])
|
guac_coder/__init__.py
CHANGED
|
@@ -37,9 +37,13 @@ from guac_coder.grpo_pipeline import (
|
|
| 37 |
)
|
| 38 |
from guac_coder.grpo_rewards import (
|
| 39 |
GRPO_REWARD_REGISTRY,
|
|
|
|
|
|
|
| 40 |
StaticCodeAnalyzer,
|
| 41 |
combined_grpo_reward,
|
| 42 |
compute_grpo_rewards,
|
|
|
|
|
|
|
| 43 |
)
|
| 44 |
from guac_coder.rater_audit import compare_raters, run_audit
|
| 45 |
from guac_coder.rewards import (
|
|
@@ -88,6 +92,10 @@ __all__ = [
|
|
| 88 |
"combined_grpo_reward",
|
| 89 |
"GRPO_REWARD_REGISTRY",
|
| 90 |
"StaticCodeAnalyzer",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
"DecisionJudgeConfig",
|
| 92 |
"DecisionRaterError",
|
| 93 |
"ask_decision_model",
|
|
|
|
| 37 |
)
|
| 38 |
from guac_coder.grpo_rewards import (
|
| 39 |
GRPO_REWARD_REGISTRY,
|
| 40 |
+
SEABORN_FLOOR,
|
| 41 |
+
VALIDITY_FLOOR,
|
| 42 |
StaticCodeAnalyzer,
|
| 43 |
combined_grpo_reward,
|
| 44 |
compute_grpo_rewards,
|
| 45 |
+
detect_seaborn,
|
| 46 |
+
uses_seaborn,
|
| 47 |
)
|
| 48 |
from guac_coder.rater_audit import compare_raters, run_audit
|
| 49 |
from guac_coder.rewards import (
|
|
|
|
| 92 |
"combined_grpo_reward",
|
| 93 |
"GRPO_REWARD_REGISTRY",
|
| 94 |
"StaticCodeAnalyzer",
|
| 95 |
+
"detect_seaborn",
|
| 96 |
+
"uses_seaborn",
|
| 97 |
+
"SEABORN_FLOOR",
|
| 98 |
+
"VALIDITY_FLOOR",
|
| 99 |
"DecisionJudgeConfig",
|
| 100 |
"DecisionRaterError",
|
| 101 |
"ask_decision_model",
|
guac_coder/decision_judge.py
CHANGED
|
@@ -362,14 +362,23 @@ def compute_decision_rewards(
|
|
| 362 |
# static path applies the same floor, and without it both raters would
|
| 363 |
# hand garbage a positive score.
|
| 364 |
from guac_coder.grpo_rewards import (
|
|
|
|
| 365 |
VALIDITY_FLOOR,
|
| 366 |
_empty_rule_scores,
|
| 367 |
is_valid_python,
|
|
|
|
| 368 |
)
|
| 369 |
|
| 370 |
if not is_valid_python(code):
|
| 371 |
return {k: VALIDITY_FLOOR for k in _empty_rule_scores()}
|
| 372 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
key = None
|
| 374 |
if cfg.cache:
|
| 375 |
digest = hashlib.sha1(code.encode("utf-8")).hexdigest()
|
|
|
|
| 362 |
# static path applies the same floor, and without it both raters would
|
| 363 |
# hand garbage a positive score.
|
| 364 |
from guac_coder.grpo_rewards import (
|
| 365 |
+
SEABORN_FLOOR,
|
| 366 |
VALIDITY_FLOOR,
|
| 367 |
_empty_rule_scores,
|
| 368 |
is_valid_python,
|
| 369 |
+
uses_seaborn,
|
| 370 |
)
|
| 371 |
|
| 372 |
if not is_valid_python(code):
|
| 373 |
return {k: VALIDITY_FLOOR for k in _empty_rule_scores()}
|
| 374 |
|
| 375 |
+
# Seaborn is disqualifying, exactly as in the static path. This is decided
|
| 376 |
+
# from the code, not by asking the model, so the gate holds even when the
|
| 377 |
+
# decision model is unavailable, uncertain, or wrong about it -- and it
|
| 378 |
+
# saves the request entirely.
|
| 379 |
+
if uses_seaborn(code):
|
| 380 |
+
return {k: SEABORN_FLOOR for k in _empty_rule_scores()}
|
| 381 |
+
|
| 382 |
key = None
|
| 383 |
if cfg.cache:
|
| 384 |
digest = hashlib.sha1(code.encode("utf-8")).hexdigest()
|
guac_coder/grpo_rewards.py
CHANGED
|
@@ -85,9 +85,13 @@ def chroptiks_preference_reward(code: str) -> float:
|
|
| 85 |
|
| 86 |
@_safe_reward
|
| 87 |
def no_seaborn_reward(code: str) -> float:
|
| 88 |
-
"""Rule 1: punish seaborn use.
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
return -1.0
|
| 92 |
return 0.5
|
| 93 |
|
|
@@ -295,6 +299,47 @@ def not_bare_script_reward(code: str) -> float:
|
|
| 295 |
# unparseable output outranks real but imperfect code.
|
| 296 |
VALIDITY_FLOOR = -1.0
|
| 297 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
|
| 299 |
# Registry of all reward functions for easy iteration
|
| 300 |
GRPO_REWARD_REGISTRY: List = [
|
|
@@ -371,19 +416,26 @@ def is_valid_python(code: str) -> bool:
|
|
| 371 |
return False
|
| 372 |
|
| 373 |
|
| 374 |
-
def _empty_rule_scores() -> Dict[str, float]:
|
| 375 |
-
"""Per-rule scores used when
|
| 376 |
-
return {func.__name__:
|
| 377 |
|
| 378 |
|
| 379 |
def compute_grpo_rewards(code: str) -> Dict[str, float]:
|
| 380 |
"""Compute all GRPO rewards for a code snippet and return per-rule scores.
|
| 381 |
|
| 382 |
-
|
| 383 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
"""
|
| 385 |
if not is_valid_python(code):
|
| 386 |
return _empty_rule_scores()
|
|
|
|
|
|
|
| 387 |
scores: Dict[str, float] = {}
|
| 388 |
for func in GRPO_REWARD_REGISTRY:
|
| 389 |
scores[func.__name__] = func(code)
|
|
|
|
| 85 |
|
| 86 |
@_safe_reward
|
| 87 |
def no_seaborn_reward(code: str) -> float:
|
| 88 |
+
"""Rule 1: punish seaborn use.
|
| 89 |
+
|
| 90 |
+
Matches imports, ``from seaborn import ...`` and bare ``sns.`` usage.
|
| 91 |
+
Note that :func:`compute_grpo_rewards` already gates on this and returns
|
| 92 |
+
the floor for every rule; this stays as the per-rule view.
|
| 93 |
+
"""
|
| 94 |
+
if uses_seaborn(code):
|
| 95 |
return -1.0
|
| 96 |
return 0.5
|
| 97 |
|
|
|
|
| 299 |
# unparseable output outranks real but imperfect code.
|
| 300 |
VALIDITY_FLOOR = -1.0
|
| 301 |
|
| 302 |
+
# Hard gate: seaborn is disqualifying, not merely one rule among thirteen.
|
| 303 |
+
# Using seaborn collapses *every* rule to the floor so no other strength in the
|
| 304 |
+
# snippet can buy the score back up. This is deliberate: a beautiful, resumable,
|
| 305 |
+
# well-logged script that imports seaborn is still exactly the thing we are
|
| 306 |
+
# training against, and a soft penalty let it outscore clean code.
|
| 307 |
+
SEABORN_FLOOR = VALIDITY_FLOOR
|
| 308 |
+
|
| 309 |
+
# Import forms: ``import seaborn``, ``import seaborn as sns``,
|
| 310 |
+
# ``from seaborn import scatterplot``.
|
| 311 |
+
_SEABORN_IMPORT_RE = re.compile(r"^\s*(?:import\s+seaborn\b|from\s+seaborn\b)", re.MULTILINE)
|
| 312 |
+
# Usage without an import (pasted snippets, aliased imports we cannot resolve).
|
| 313 |
+
_SEABORN_USE_RE = re.compile(r"\b(?:sns|seaborn)\s*\.")
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
def detect_seaborn(code: str):
|
| 317 |
+
"""Return a short reason if ``code`` uses seaborn, else ``None``.
|
| 318 |
+
|
| 319 |
+
Catches all three ways seaborn reaches a script: a plain import, a
|
| 320 |
+
``from seaborn import ...`` form, and usage of ``sns.``/``seaborn.``
|
| 321 |
+
without any visible import (common in model output that assumes context).
|
| 322 |
+
|
| 323 |
+
The previous check only matched ``import seaborn``, so
|
| 324 |
+
``from seaborn import scatterplot`` and a naked ``sns.barplot(...)`` both
|
| 325 |
+
slipped through and collected the *clean* bonus -- i.e. seaborn code was
|
| 326 |
+
being rewarded.
|
| 327 |
+
"""
|
| 328 |
+
if not code:
|
| 329 |
+
return None
|
| 330 |
+
match = _SEABORN_IMPORT_RE.search(code)
|
| 331 |
+
if match:
|
| 332 |
+
return match.group(0).strip()
|
| 333 |
+
match = _SEABORN_USE_RE.search(code)
|
| 334 |
+
if match:
|
| 335 |
+
return f"{match.group(0).strip()} usage"
|
| 336 |
+
return None
|
| 337 |
+
|
| 338 |
+
|
| 339 |
+
def uses_seaborn(code: str) -> bool:
|
| 340 |
+
"""Whether ``code`` uses seaborn in any form."""
|
| 341 |
+
return detect_seaborn(code) is not None
|
| 342 |
+
|
| 343 |
|
| 344 |
# Registry of all reward functions for easy iteration
|
| 345 |
GRPO_REWARD_REGISTRY: List = [
|
|
|
|
| 416 |
return False
|
| 417 |
|
| 418 |
|
| 419 |
+
def _empty_rule_scores(value: float = VALIDITY_FLOOR) -> Dict[str, float]:
|
| 420 |
+
"""Per-rule scores used when a hard gate rejects the snippet."""
|
| 421 |
+
return {func.__name__: value for func in GRPO_REWARD_REGISTRY}
|
| 422 |
|
| 423 |
|
| 424 |
def compute_grpo_rewards(code: str) -> Dict[str, float]:
|
| 425 |
"""Compute all GRPO rewards for a code snippet and return per-rule scores.
|
| 426 |
|
| 427 |
+
Two hard gates run before the rules:
|
| 428 |
+
|
| 429 |
+
* unparseable or empty snippets return :data:`VALIDITY_FLOOR` for every
|
| 430 |
+
rule instead of the per-rule "no violation found" bonus;
|
| 431 |
+
* **seaborn collapses everything to :data:`SEABORN_FLOOR`**. Seaborn is
|
| 432 |
+
disqualifying rather than a single soft penalty, so no amount of good
|
| 433 |
+
structure elsewhere can pull the score back up.
|
| 434 |
"""
|
| 435 |
if not is_valid_python(code):
|
| 436 |
return _empty_rule_scores()
|
| 437 |
+
if uses_seaborn(code):
|
| 438 |
+
return _empty_rule_scores(SEABORN_FLOOR)
|
| 439 |
scores: Dict[str, float] = {}
|
| 440 |
for func in GRPO_REWARD_REGISTRY:
|
| 441 |
scores[func.__name__] = func(code)
|
guac_coder/rewards.py
CHANGED
|
@@ -18,7 +18,12 @@ logger = logging.getLogger(__name__)
|
|
| 18 |
# Static analysis helpers
|
| 19 |
# ---------------------------------------------------------------------------
|
| 20 |
|
| 21 |
-
_SEABORN_PATTERNS = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
_GRID_PATTERNS = [r"\.grid\(", r"\.grid\s*="]
|
| 23 |
_TITLE_PATTERNS = [r"\.set_title\(", r"\.set_title\s*=", r"\.title\("]
|
| 24 |
_BARGRAPH_PATTERNS = [
|
|
@@ -218,7 +223,16 @@ def compute_static_rewards(code: str, cfg: RewardConfig) -> Dict[str, float]:
|
|
| 218 |
|
| 219 |
|
| 220 |
def total_static_reward(code: str, cfg: RewardConfig) -> float:
|
| 221 |
-
"""Return scalar sum of all static rewards.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
rewards = compute_static_rewards(code, cfg)
|
| 223 |
return sum(rewards.values())
|
| 224 |
|
|
@@ -328,7 +342,23 @@ def compute_total_reward(
|
|
| 328 |
"""Combine static and LLM-judge rewards into a single scalar.
|
| 329 |
|
| 330 |
Returns a dict with 'total', 'static', 'llm', and per-component breakdowns.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 332 |
static = compute_static_rewards(code, cfg)
|
| 333 |
llm = compute_llm_judge_reward(code, get_llm_response_fn, cfg)
|
| 334 |
|
|
|
|
| 18 |
# Static analysis helpers
|
| 19 |
# ---------------------------------------------------------------------------
|
| 20 |
|
| 21 |
+
_SEABORN_PATTERNS = [
|
| 22 |
+
r"\bimport\s+seaborn\b",
|
| 23 |
+
r"\bfrom\s+seaborn\b",
|
| 24 |
+
# Bare usage without a visible import (pasted snippets, aliased imports).
|
| 25 |
+
r"\b(?:sns|seaborn)\s*\.",
|
| 26 |
+
]
|
| 27 |
_GRID_PATTERNS = [r"\.grid\(", r"\.grid\s*="]
|
| 28 |
_TITLE_PATTERNS = [r"\.set_title\(", r"\.set_title\s*=", r"\.title\("]
|
| 29 |
_BARGRAPH_PATTERNS = [
|
|
|
|
| 223 |
|
| 224 |
|
| 225 |
def total_static_reward(code: str, cfg: RewardConfig) -> float:
|
| 226 |
+
"""Return scalar sum of all static rewards.
|
| 227 |
+
|
| 228 |
+
Seaborn is disqualifying: the total collapses to
|
| 229 |
+
:data:`guac_coder.grpo_rewards.SEABORN_FLOOR` regardless of anything else
|
| 230 |
+
in the snippet, matching the 13-rule path so the two agree.
|
| 231 |
+
"""
|
| 232 |
+
from guac_coder.grpo_rewards import SEABORN_FLOOR, uses_seaborn
|
| 233 |
+
|
| 234 |
+
if uses_seaborn(code):
|
| 235 |
+
return SEABORN_FLOOR
|
| 236 |
rewards = compute_static_rewards(code, cfg)
|
| 237 |
return sum(rewards.values())
|
| 238 |
|
|
|
|
| 342 |
"""Combine static and LLM-judge rewards into a single scalar.
|
| 343 |
|
| 344 |
Returns a dict with 'total', 'static', 'llm', and per-component breakdowns.
|
| 345 |
+
|
| 346 |
+
Seaborn short-circuits the whole blend to
|
| 347 |
+
:data:`guac_coder.grpo_rewards.SEABORN_FLOOR`. A weighted average would let
|
| 348 |
+
a generous LLM judge offset the penalty, which defeats the point of a hard
|
| 349 |
+
gate; the LLM judge is not even called.
|
| 350 |
"""
|
| 351 |
+
from guac_coder.grpo_rewards import SEABORN_FLOOR, uses_seaborn
|
| 352 |
+
|
| 353 |
+
if uses_seaborn(code):
|
| 354 |
+
return {
|
| 355 |
+
"total": SEABORN_FLOOR,
|
| 356 |
+
"static": SEABORN_FLOOR,
|
| 357 |
+
"llm": 0.0,
|
| 358 |
+
"static_components": {},
|
| 359 |
+
"llm_components": {},
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
static = compute_static_rewards(code, cfg)
|
| 363 |
llm = compute_llm_judge_reward(code, get_llm_response_fn, cfg)
|
| 364 |
|
tests/test_decision_judge.py
CHANGED
|
@@ -183,13 +183,29 @@ class TestErrorHandling:
|
|
| 183 |
)
|
| 184 |
|
| 185 |
def test_on_error_static_falls_back_to_regex_rules(self):
|
| 186 |
-
rewards = compute_decision_rewards(
|
| 187 |
-
assert rewards == compute_grpo_rewards(
|
| 188 |
|
| 189 |
def test_on_error_zero_returns_neutral_rewards(self):
|
| 190 |
-
rewards = compute_decision_rewards(
|
| 191 |
assert set(rewards.values()) == {0.0}
|
| 192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
def test_on_error_raise_propagates(self):
|
| 194 |
from guac_coder.decision_judge import DecisionRaterError
|
| 195 |
|
|
|
|
| 183 |
)
|
| 184 |
|
| 185 |
def test_on_error_static_falls_back_to_regex_rules(self):
|
| 186 |
+
rewards = compute_decision_rewards(CLEAN_CODE, cfg=self._dead_cfg("static"))
|
| 187 |
+
assert rewards == compute_grpo_rewards(CLEAN_CODE)
|
| 188 |
|
| 189 |
def test_on_error_zero_returns_neutral_rewards(self):
|
| 190 |
+
rewards = compute_decision_rewards(CLEAN_CODE, cfg=self._dead_cfg("zero"))
|
| 191 |
assert set(rewards.values()) == {0.0}
|
| 192 |
|
| 193 |
+
def test_seaborn_gate_precedes_the_endpoint(self):
|
| 194 |
+
"""Seaborn is disqualifying before any request is made.
|
| 195 |
+
|
| 196 |
+
The gate must not depend on the decision model being reachable, so a
|
| 197 |
+
dead endpoint must still yield the floor rather than an error or a
|
| 198 |
+
neutral score.
|
| 199 |
+
"""
|
| 200 |
+
from guac_coder.grpo_rewards import SEABORN_FLOOR
|
| 201 |
+
|
| 202 |
+
for on_error in ("static", "zero", "raise"):
|
| 203 |
+
rewards = compute_decision_rewards(
|
| 204 |
+
"import seaborn as sns\nsns.barplot(x=[1], y=[2])\n",
|
| 205 |
+
cfg=self._dead_cfg(on_error),
|
| 206 |
+
)
|
| 207 |
+
assert set(rewards.values()) == {SEABORN_FLOOR}, on_error
|
| 208 |
+
|
| 209 |
def test_on_error_raise_propagates(self):
|
| 210 |
from guac_coder.decision_judge import DecisionRaterError
|
| 211 |
|
tests/test_seaborn_gate.py
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Seaborn is disqualifying, not merely one soft penalty.
|
| 2 |
+
|
| 3 |
+
The 13 rules each reward the *absence* of a violation, so before this gate a
|
| 4 |
+
well-structured script that used seaborn still collected enough clean credit to
|
| 5 |
+
outrank honest code ("excellent script that uses seaborn" scored higher than a
|
| 6 |
+
plain clean script). Seaborn must therefore collapse the whole score, in every
|
| 7 |
+
rater, so no amount of good structure elsewhere can buy it back.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import pytest
|
| 11 |
+
|
| 12 |
+
from guac_coder.config import RewardConfig
|
| 13 |
+
from guac_coder.decision_judge import (
|
| 14 |
+
DecisionJudgeConfig,
|
| 15 |
+
combined_decision_reward,
|
| 16 |
+
compute_decision_rewards,
|
| 17 |
+
)
|
| 18 |
+
from guac_coder.grpo_rewards import (
|
| 19 |
+
SEABORN_FLOOR,
|
| 20 |
+
combined_grpo_reward,
|
| 21 |
+
compute_grpo_rewards,
|
| 22 |
+
detect_seaborn,
|
| 23 |
+
uses_seaborn,
|
| 24 |
+
)
|
| 25 |
+
from guac_coder.rewards import compute_total_reward, total_static_reward
|
| 26 |
+
from guac_coder.training import score_completion
|
| 27 |
+
|
| 28 |
+
# Otherwise excellent: logging, pandas to_csv, chroptiks, resume check, guard.
|
| 29 |
+
EXCELLENT = """import logging
|
| 30 |
+
import os
|
| 31 |
+
|
| 32 |
+
import chroptiks as cpt
|
| 33 |
+
import pandas as pd
|
| 34 |
+
import seaborn as sns
|
| 35 |
+
|
| 36 |
+
logger = logging.getLogger(__name__)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def load(path):
|
| 40 |
+
if os.path.exists(path):
|
| 41 |
+
with open(path) as fh:
|
| 42 |
+
return fh.read()
|
| 43 |
+
return None
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def run(rows):
|
| 47 |
+
for i, row in enumerate(rows):
|
| 48 |
+
pd.DataFrame([row]).to_csv("o.csv", mode="a", header=(i == 0), index=False)
|
| 49 |
+
logger.info("row %d", i)
|
| 50 |
+
sns.scatterplot(data=rows, x="a", y="b")
|
| 51 |
+
cpt.plot("o.csv")
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
run([{"a": 1, "b": 2}])
|
| 56 |
+
"""
|
| 57 |
+
|
| 58 |
+
CLEAN = """import logging
|
| 59 |
+
|
| 60 |
+
logger = logging.getLogger(__name__)
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def main():
|
| 64 |
+
logger.info("hello")
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
if __name__ == "__main__":
|
| 68 |
+
main()
|
| 69 |
+
"""
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
@pytest.mark.parametrize(
|
| 73 |
+
"code,expected",
|
| 74 |
+
[
|
| 75 |
+
("import seaborn as sns\nsns.barplot(x=[1], y=[2])\n", True),
|
| 76 |
+
("import seaborn\nseaborn.set_theme()\n", True),
|
| 77 |
+
("from seaborn import scatterplot\nscatterplot(x=[1])\n", True),
|
| 78 |
+
("from seaborn.pairplot import PairGrid\n", True),
|
| 79 |
+
("def f():\n sns.barplot(x=[1], y=[2])\n", True),
|
| 80 |
+
("def f():\n return seaborn.color_palette()\n", True),
|
| 81 |
+
("import matplotlib.pyplot as plt\nplt.plot([1])\n", False),
|
| 82 |
+
("import logging\nlogging.info('x')\n", False),
|
| 83 |
+
("sns_thing = 1\n", False),
|
| 84 |
+
],
|
| 85 |
+
)
|
| 86 |
+
def test_detect_seaborn_forms(code, expected):
|
| 87 |
+
"""Every way seaborn reaches a script must be detected."""
|
| 88 |
+
assert uses_seaborn(code) is expected
|
| 89 |
+
assert (detect_seaborn(code) is not None) is expected
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def test_detect_seaborn_names_the_form():
|
| 93 |
+
"""The reason string is what makes a bad score explainable."""
|
| 94 |
+
assert "from seaborn" in detect_seaborn("from seaborn import scatterplot\n")
|
| 95 |
+
assert "sns." in detect_seaborn("def f():\n sns.barplot()\n")
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
@pytest.mark.parametrize(
|
| 99 |
+
"code",
|
| 100 |
+
[
|
| 101 |
+
"import seaborn as sns\nsns.barplot(x=[1], y=[2])\n",
|
| 102 |
+
"from seaborn import scatterplot\nscatterplot(x=[1])\n",
|
| 103 |
+
"def f():\n sns.barplot(x=[1], y=[2])\n",
|
| 104 |
+
EXCELLENT,
|
| 105 |
+
],
|
| 106 |
+
)
|
| 107 |
+
def test_seaborn_collapses_every_rule_to_the_floor(code):
|
| 108 |
+
"""Not just the seaborn rule: the entire vector goes to the floor."""
|
| 109 |
+
rewards = compute_grpo_rewards(code)
|
| 110 |
+
assert set(rewards.values()) == {SEABORN_FLOOR}
|
| 111 |
+
assert combined_grpo_reward(code) == SEABORN_FLOOR
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def test_excellent_seaborn_worse_than_clean_code():
|
| 115 |
+
"""The regression this gate exists for.
|
| 116 |
+
|
| 117 |
+
Before the gate, EXCELLENT scored above CLEAN because its structure earned
|
| 118 |
+
more clean credit than seaborn cost it. That is the wrong ordering for
|
| 119 |
+
training.
|
| 120 |
+
"""
|
| 121 |
+
assert combined_grpo_reward(EXCELLENT) < combined_grpo_reward(CLEAN)
|
| 122 |
+
assert combined_grpo_reward(EXCELLENT) == SEABORN_FLOOR
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def test_clean_code_is_unaffected():
|
| 126 |
+
"""The gate must not touch code that does not use seaborn."""
|
| 127 |
+
rewards = compute_grpo_rewards(CLEAN)
|
| 128 |
+
# The gate is uniform collapse; a single -1.0 rule is just a penalty.
|
| 129 |
+
assert set(rewards.values()) != {SEABORN_FLOOR}
|
| 130 |
+
assert rewards["no_seaborn_reward"] == 0.5
|
| 131 |
+
assert combined_grpo_reward(CLEAN) > SEABORN_FLOOR
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def test_matplotlib_alone_is_not_gated():
|
| 135 |
+
"""matplotlib is discouraged, but only seaborn is disqualifying."""
|
| 136 |
+
code = "import matplotlib.pyplot as plt\nplt.plot([1])\n"
|
| 137 |
+
rewards = compute_grpo_rewards(code)
|
| 138 |
+
assert set(rewards.values()) != {SEABORN_FLOOR}
|
| 139 |
+
assert rewards["no_seaborn_reward"] == 0.5
|
| 140 |
+
assert combined_grpo_reward(code) > SEABORN_FLOOR
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def test_decision_rater_gates_seaborn_without_calling_the_endpoint():
|
| 144 |
+
"""The gate is decided from the code, so a dead model still yields the floor."""
|
| 145 |
+
calls = []
|
| 146 |
+
|
| 147 |
+
def judge(code, cfg=None):
|
| 148 |
+
calls.append(code)
|
| 149 |
+
return {}
|
| 150 |
+
|
| 151 |
+
cfg = DecisionJudgeConfig(model="offline", cache=False)
|
| 152 |
+
rewards = compute_decision_rewards(EXCELLENT, cfg=cfg, judge_fn=judge)
|
| 153 |
+
assert set(rewards.values()) == {SEABORN_FLOOR}
|
| 154 |
+
assert calls == [], "the endpoint must not be called for a gated snippet"
|
| 155 |
+
assert combined_decision_reward(EXCELLENT, cfg=cfg, judge_fn=judge) == SEABORN_FLOOR
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
def test_score_completion_gates_seaborn_for_every_rater():
|
| 159 |
+
code = "import seaborn as sns\nsns.barplot(x=[1], y=[2])\n"
|
| 160 |
+
for rater in ("static", "decision"):
|
| 161 |
+
cfg = RewardConfig(rater=rater, decision_model="offline")
|
| 162 |
+
total, details = score_completion(code, lambda **k: {}, cfg, rater=rater)
|
| 163 |
+
assert total == SEABORN_FLOOR, rater
|
| 164 |
+
assert set(details["rules"].values()) == {SEABORN_FLOOR}, rater
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def test_legacy_path_agrees_with_the_13_rule_path():
|
| 168 |
+
"""The two scoring paths must not disagree about a disqualifying rule."""
|
| 169 |
+
cfg = RewardConfig()
|
| 170 |
+
for code in (EXCELLENT, "from seaborn import scatterplot\nscatterplot(x=[1])\n", CLEAN):
|
| 171 |
+
legacy = total_static_reward(code, cfg)
|
| 172 |
+
modern = combined_grpo_reward(code)
|
| 173 |
+
assert (legacy == SEABORN_FLOOR) == (modern == SEABORN_FLOOR), code
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
def test_legacy_blend_cannot_be_rescued_by_the_llm_judge():
|
| 177 |
+
"""A generous judge must not offset a hard gate."""
|
| 178 |
+
|
| 179 |
+
def generous_judge(prompt=None, **kwargs):
|
| 180 |
+
return {"scores": {k: 1 for k in ("seaborn_use", "grid_use", "title_use")}}
|
| 181 |
+
|
| 182 |
+
result = compute_total_reward(EXCELLENT, generous_judge, RewardConfig())
|
| 183 |
+
assert result["total"] == SEABORN_FLOOR
|
| 184 |
+
assert result["llm_components"] == {}
|