deepmodebot 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/plugins/marketplace.json +1 -1
- package/.claude-plugin/marketplace.json +2 -2
- package/.omp-plugin/marketplace.json +2 -2
- package/README.md +15 -6
- package/bin/deepmodebot.mjs +104 -10
- package/native/dmb-gate/Cargo.toml +1 -1
- package/native/dmb-gate/src/agents.rs +58 -25
- package/native/dmb-gate/src/ci.rs +530 -14
- package/native/dmb-gate/src/main.rs +215 -7
- package/native/dmb-gate/src/reward.rs +1895 -242
- package/native/dmb-gate/src/sim.rs +969 -0
- package/native/dmb-gate/src/slop.rs +1061 -295
- package/package.json +1 -1
- package/plugins/deepmodebot/.antigravity-plugin/plugin.json +1 -1
- package/plugins/deepmodebot/.antigravity-plugin/skills/deep/SKILL.md +1 -1
- package/plugins/deepmodebot/.claude-plugin/plugin.json +1 -1
- package/plugins/deepmodebot/.codex-plugin/plugin.json +2 -2
- package/plugins/deepmodebot/agents/comment-sicko.md +29 -0
- package/plugins/deepmodebot/agents/researcher.md +29 -0
- package/plugins/deepmodebot/agents/reviewer.md +29 -0
- package/plugins/deepmodebot/agents/scout.md +28 -0
- package/plugins/deepmodebot/agents/security-reviewer.md +27 -0
- package/plugins/deepmodebot/commands/deep.md +3 -2
- package/plugins/deepmodebot/commands/tournament.md +1 -1
- package/plugins/deepmodebot/hooks/hooks.json +12 -2
- package/plugins/deepmodebot/hooks.json +1 -1
- package/plugins/deepmodebot/scripts/antigravity-guard.mjs +740 -37
- package/plugins/deepmodebot/skills/agent-harnesses/references/antigravity.md +2 -2
- package/plugins/deepmodebot/skills/deepmodebot/SKILL.md +19 -11
- package/plugins/deepmodebot/skills/deepmodebot/assets/agents-md/agents_md.py +51 -20
- package/plugins/deepmodebot/skills/deepmodebot/assets/autoroute/autoroute.py +54 -49
- package/plugins/deepmodebot/skills/deepmodebot/assets/contain/claude-guard.sh +4 -0
- package/plugins/deepmodebot/skills/deepmodebot/assets/contain/claude_guard.py +658 -21
- package/plugins/deepmodebot/skills/deepmodebot/assets/contain/holdout_guard_cases.json +272 -0
- package/plugins/deepmodebot/skills/deepmodebot/assets/contain/omp-contain.ts +774 -23
- package/plugins/deepmodebot/skills/deepmodebot/assets/f2p-gate/f2p_gate.py +547 -0
- package/plugins/deepmodebot/skills/deepmodebot/assets/gap-audit/gap_audit.py +5 -11
- package/plugins/deepmodebot/skills/deepmodebot/assets/git-guardrails/git-guard-patterns.txt +4 -4
- package/plugins/deepmodebot/skills/deepmodebot/assets/git-guardrails/git-guard.sh +53 -6
- package/plugins/deepmodebot/skills/deepmodebot/assets/git-guardrails/git-guard.ts +48 -2
- package/plugins/deepmodebot/skills/deepmodebot/assets/local-ci/local_ci.py +262 -6
- package/plugins/deepmodebot/skills/deepmodebot/assets/local-ci/slop_gate.py +529 -122
- package/plugins/deepmodebot/skills/deepmodebot/assets/loop/loop.py +747 -46
- package/plugins/deepmodebot/skills/deepmodebot/assets/memory/project_memory.py +404 -5
- package/plugins/deepmodebot/skills/deepmodebot/assets/mutation/mutation_gate.py +798 -0
- package/plugins/deepmodebot/skills/deepmodebot/assets/reward-guard/reward_guard.py +2050 -200
- package/plugins/deepmodebot/skills/deepmodebot/assets/rules/rule-paths.json +44 -1
- package/plugins/deepmodebot/skills/deepmodebot/assets/rules/rule_ledger.py +278 -252
- package/plugins/deepmodebot/skills/deepmodebot/assets/rules/rules_watch.py +436 -0
- package/plugins/deepmodebot/skills/deepmodebot/assets/self-grill/self_grill.py +594 -18
- package/plugins/deepmodebot/skills/deepmodebot/assets/setup/project_setup.py +41 -5
- package/plugins/deepmodebot/skills/deepmodebot/assets/sim/sim.py +856 -0
- package/plugins/deepmodebot/skills/deepmodebot/assets/worker-gate/worker_gate.py +237 -0
- package/plugins/deepmodebot/skills/deepmodebot/references/catalog.md +3 -2
- package/plugins/deepmodebot/skills/deepmodebot/references/delegation.md +6 -2
- package/plugins/deepmodebot/skills/deepmodebot/references/playbooks/authoring-a-skill.md +1 -1
- package/plugins/deepmodebot/skills/deepmodebot/references/playbooks/hillclimb.md +1 -0
- package/plugins/deepmodebot/skills/deepmodebot/references/playbooks/self-authoring.md +1 -1
- package/plugins/deepmodebot/skills/deepmodebot/references/principles/no-reward-hacking.md +6 -6
- package/plugins/deepmodebot/skills/deepmodebot/references/rule-approval.md +36 -16
- package/plugins/deepmodebot/skills/deepmodebot/references/techniques/autoroute.md +9 -8
- package/plugins/deepmodebot/skills/deepmodebot/references/techniques/correct.md +1 -0
- package/plugins/deepmodebot/skills/deepmodebot/references/techniques/inner-loop.md +6 -2
- package/plugins/deepmodebot/skills/deepmodebot/references/techniques/mutation-testing.md +31 -9
- package/plugins/deepmodebot/skills/deepmodebot/references/techniques/no-comments.md +1 -1
- package/plugins/deepmodebot/skills/deepmodebot/references/techniques/panel.md +4 -4
- package/plugins/deepmodebot/skills/deepmodebot/references/techniques/sim.md +41 -0
- package/plugins/deepmodebot/skills/deepmodebot/references/techniques/tdd.md +12 -0
- package/plugins/deepmodebot/skills/deepmodebot/references/techniques/tournament.md +24 -13
- package/plugins/deepmodebot/skills/deepmodebot/worker.md +28 -16
- package/plugins/deepmodebot/agents/comment-sicko/agent.md +0 -35
- package/plugins/deepmodebot/agents/researcher/agent.md +0 -33
- package/plugins/deepmodebot/agents/reviewer/agent.md +0 -35
- package/plugins/deepmodebot/agents/scout/agent.md +0 -33
- package/plugins/deepmodebot/agents/security-reviewer/agent.md +0 -31
|
@@ -14,92 +14,51 @@ pub struct RewardFinding {
|
|
|
14
14
|
pub fix: &'static str,
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
const MIN_FLOOR_EPSILON: f64 = 1e-
|
|
17
|
+
const MIN_FLOOR_EPSILON: f64 = 1e-4;
|
|
18
18
|
|
|
19
|
+
fn metric_min_floor(metric: &str) -> f64 {
|
|
20
|
+
match metric {
|
|
21
|
+
"iou" | "ssim" | "dice" | "f1" | "auc" | "accuracy" | "acc" | "precision" | "recall"
|
|
22
|
+
| "fidelity" | "similarity" | "coverage" | "pass_rate" | "win_rate" | "ndcg" | "mrr"
|
|
23
|
+
| "hit_rate" | "r2" | "spearman" | "pearson" => 0.50,
|
|
24
|
+
"clip" | "clip_score" | "ap" | "map" | "bleu" | "rouge" => 0.15,
|
|
25
|
+
"psnr" => 10.0,
|
|
26
|
+
"protrusion" => 0.02,
|
|
27
|
+
"score" | "confidence" | "symmetry" => 0.05,
|
|
28
|
+
"cov_fail_under" | "fail_under" => 50.0,
|
|
29
|
+
_ => MIN_FLOOR_EPSILON,
|
|
30
|
+
}
|
|
31
|
+
}
|
|
19
32
|
const BARE_LOWER_METRICS: &[&str] = &[
|
|
20
|
-
"iou",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"f1",
|
|
26
|
-
"auc",
|
|
27
|
-
"bleu",
|
|
28
|
-
"rouge",
|
|
29
|
-
"accuracy",
|
|
30
|
-
"precision",
|
|
31
|
-
"recall",
|
|
32
|
-
"fidelity",
|
|
33
|
-
"similarity",
|
|
34
|
-
"coverage",
|
|
35
|
-
"pass_rate",
|
|
36
|
-
"win_rate",
|
|
37
|
-
"score",
|
|
38
|
-
"confidence",
|
|
39
|
-
"protrusion",
|
|
40
|
-
"symmetry",
|
|
33
|
+
"iou", "ssim", "psnr", "clip_score", "dice", "f1", "auc", "bleu", "rouge", "accuracy",
|
|
34
|
+
"precision", "recall", "fidelity", "similarity", "coverage", "pass_rate", "win_rate",
|
|
35
|
+
"score", "confidence", "protrusion", "symmetry", "fail_under",
|
|
36
|
+
"throughput", "qps", "rps", "tps", "fps", "ops_per_sec", "tok_per_sec", "speedup",
|
|
37
|
+
"ndcg", "mrr", "hit_rate", "sharpe", "r2", "spearman", "pearson",
|
|
41
38
|
];
|
|
42
39
|
|
|
43
40
|
const QUAL_LOWER_METRICS: &[&str] = &[
|
|
44
|
-
"iou",
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"dice",
|
|
50
|
-
"f1",
|
|
51
|
-
"auc",
|
|
52
|
-
"ap",
|
|
53
|
-
"map",
|
|
54
|
-
"bleu",
|
|
55
|
-
"rouge",
|
|
56
|
-
"accuracy",
|
|
57
|
-
"acc",
|
|
58
|
-
"precision",
|
|
59
|
-
"recall",
|
|
60
|
-
"fidelity",
|
|
61
|
-
"similarity",
|
|
62
|
-
"coverage",
|
|
63
|
-
"pass_rate",
|
|
64
|
-
"win_rate",
|
|
65
|
-
"score",
|
|
66
|
-
"confidence",
|
|
67
|
-
"protrusion",
|
|
68
|
-
"symmetry",
|
|
41
|
+
"iou", "ssim", "psnr", "clip", "clip_score", "dice", "f1", "auc", "ap", "map", "bleu",
|
|
42
|
+
"rouge", "accuracy", "acc", "precision", "recall", "fidelity", "similarity", "coverage",
|
|
43
|
+
"pass_rate", "win_rate", "score", "confidence", "protrusion", "symmetry", "fail_under",
|
|
44
|
+
"cov_fail_under", "throughput", "qps", "rps", "tps", "fps", "ops_per_sec", "tok_per_sec",
|
|
45
|
+
"speedup", "ndcg", "mrr", "hit_rate", "sharpe", "r2", "spearman", "pearson",
|
|
69
46
|
];
|
|
70
47
|
|
|
71
48
|
const BARE_UPPER_METRICS: &[&str] = &[
|
|
72
|
-
"mse",
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"chamfer",
|
|
77
|
-
"hausdorff",
|
|
78
|
-
"drift",
|
|
79
|
-
"tolerance",
|
|
80
|
-
"holes",
|
|
81
|
-
"non_manifold",
|
|
49
|
+
"mse", "mae", "rmse", "lpips", "chamfer", "hausdorff", "drift", "tolerance", "holes",
|
|
50
|
+
"non_manifold", "latency", "latency_ms", "p50", "p95", "p99", "p99_ms", "ttft", "ttft_ms",
|
|
51
|
+
"max_ms", "duration_ms", "memory_mb", "rss_mb", "heap_mb", "allocs", "bundle_kb",
|
|
52
|
+
"perplexity", "ppl", "wer", "cer", "fpr", "fnr", "max_diff_pixel_ratio", "max_diff_pixels",
|
|
82
53
|
];
|
|
83
54
|
|
|
84
55
|
const QUAL_UPPER_METRICS: &[&str] = &[
|
|
85
|
-
"mse",
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"hausdorff",
|
|
91
|
-
"drift",
|
|
92
|
-
"tolerance",
|
|
93
|
-
"holes",
|
|
94
|
-
"non_manifold",
|
|
95
|
-
"err",
|
|
96
|
-
"error",
|
|
97
|
-
"loss",
|
|
98
|
-
"tol",
|
|
99
|
-
"epsilon",
|
|
100
|
-
"eps",
|
|
56
|
+
"mse", "mae", "rmse", "lpips", "chamfer", "hausdorff", "drift", "tolerance", "holes",
|
|
57
|
+
"non_manifold", "latency", "latency_ms", "p50", "p95", "p99", "p99_ms", "ttft", "ttft_ms",
|
|
58
|
+
"max_ms", "duration_ms", "memory_mb", "rss_mb", "heap_mb", "allocs", "bundle_kb",
|
|
59
|
+
"perplexity", "ppl", "wer", "cer", "fpr", "fnr", "max_diff_pixel_ratio", "max_diff_pixels",
|
|
60
|
+
"err", "error", "loss", "tol", "epsilon", "eps",
|
|
101
61
|
];
|
|
102
|
-
|
|
103
62
|
const SKIP_FLAGS: &[&str] = &[
|
|
104
63
|
"--skip-gate",
|
|
105
64
|
"--skip-gates",
|
|
@@ -110,9 +69,10 @@ const SKIP_FLAGS: &[&str] = &[
|
|
|
110
69
|
"--bypass-gate",
|
|
111
70
|
"--pass-if-no-tests",
|
|
112
71
|
"--passWithNoTests",
|
|
72
|
+
"--no-cov",
|
|
113
73
|
];
|
|
114
74
|
|
|
115
|
-
const
|
|
75
|
+
const PRIMITIVE_TOKENS: &[&str] = &[
|
|
116
76
|
"bpy.ops.mesh.primitive_cube_add",
|
|
117
77
|
"bpy.ops.mesh.primitive_cone_add",
|
|
118
78
|
"bpy.ops.mesh.primitive_cylinder_add",
|
|
@@ -122,18 +82,37 @@ const PRIMITIVE_CALLS: &[&str] = &[
|
|
|
122
82
|
"bpy.ops.mesh.primitive_monkey_add",
|
|
123
83
|
"bpy.ops.mesh.primitive_plane_add",
|
|
124
84
|
"bpy.ops.mesh.primitive_grid_add",
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
"
|
|
129
|
-
"
|
|
130
|
-
"
|
|
131
|
-
"
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
"
|
|
136
|
-
"
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
const PRIMITIVE_PATHS: &[&str] = &[
|
|
88
|
+
"/Engine/BasicShapes/Cube",
|
|
89
|
+
"/Engine/BasicShapes/Cone",
|
|
90
|
+
"/Engine/BasicShapes/Cylinder",
|
|
91
|
+
"/Engine/BasicShapes/Sphere",
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
const PRIMITIVE_FN_CALLS: &[&str] = &[
|
|
95
|
+
"trimesh.creation.box",
|
|
96
|
+
"trimesh.creation.cone",
|
|
97
|
+
"trimesh.creation.cylinder",
|
|
98
|
+
"trimesh.creation.icosphere",
|
|
99
|
+
"trimesh.creation.uv_sphere",
|
|
100
|
+
"trimesh.creation.capsule",
|
|
101
|
+
"trimesh.creation.annulus",
|
|
102
|
+
"create_cube",
|
|
103
|
+
"create_cone",
|
|
104
|
+
"create_cylinder",
|
|
105
|
+
"create_uv_sphere",
|
|
106
|
+
"create_icosphere",
|
|
107
|
+
"THREE.BoxGeometry",
|
|
108
|
+
"THREE.ConeGeometry",
|
|
109
|
+
"THREE.CylinderGeometry",
|
|
110
|
+
"THREE.SphereGeometry",
|
|
111
|
+
"THREE.IcosahedronGeometry",
|
|
112
|
+
"MeshBuilder.CreateBox",
|
|
113
|
+
"MeshBuilder.CreateSphere",
|
|
114
|
+
"MeshBuilder.CreateCylinder",
|
|
115
|
+
"MeshBuilder.CreateCone",
|
|
137
116
|
];
|
|
138
117
|
|
|
139
118
|
fn git(root: &Path, args: &[&str]) -> Option<(bool, String)> {
|
|
@@ -153,7 +132,7 @@ fn git(root: &Path, args: &[&str]) -> Option<(bool, String)> {
|
|
|
153
132
|
|
|
154
133
|
fn is_test_file(rel: &str) -> bool {
|
|
155
134
|
let low = rel.to_ascii_lowercase();
|
|
156
|
-
low.starts_with("tests/")
|
|
135
|
+
if low.starts_with("tests/")
|
|
157
136
|
|| low.starts_with("test/")
|
|
158
137
|
|| low.starts_with("spec/")
|
|
159
138
|
|| low.starts_with("__tests__/")
|
|
@@ -163,37 +142,100 @@ fn is_test_file(rel: &str) -> bool {
|
|
|
163
142
|
|| low.contains("/spec/")
|
|
164
143
|
|| low.contains("/__tests__/")
|
|
165
144
|
|| low.contains("/evals/")
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
145
|
+
{
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
let fname = low.rsplit('/').next().unwrap_or(&low);
|
|
149
|
+
fname.starts_with("test_")
|
|
150
|
+
|| fname.contains("_test.")
|
|
151
|
+
|| fname.contains(".test.")
|
|
152
|
+
|| fname.contains(".spec.")
|
|
171
153
|
}
|
|
172
154
|
|
|
173
155
|
fn is_gate_or_eval_file(rel: &str) -> bool {
|
|
174
156
|
let low = rel.to_ascii_lowercase();
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
157
|
+
if [
|
|
158
|
+
"gate/", "gates/", "eval/", "evals/", "bench/", "benchmark/", "benchmarks/", "validator/", "validators/",
|
|
159
|
+
]
|
|
160
|
+
.iter()
|
|
161
|
+
.any(|d| low.starts_with(d) || low.contains(&format!("/{}", d)))
|
|
162
|
+
{
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
let fname = low.rsplit('/').next().unwrap_or(&low);
|
|
166
|
+
let Some((stem, _ext)) = fname.rsplit_once('.') else {
|
|
167
|
+
return false;
|
|
168
|
+
};
|
|
169
|
+
[
|
|
170
|
+
"gate", "eval", "bench", "validator", "fidelity", "metric", "scorer",
|
|
171
|
+
]
|
|
172
|
+
.iter()
|
|
173
|
+
.any(|k| stem == *k || stem.ends_with(&format!("_{}", k)) || stem.ends_with(&format!("-{}", k)))
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
fn is_migration_file(rel: &str) -> bool {
|
|
177
|
+
let low = rel.to_ascii_lowercase();
|
|
178
|
+
[
|
|
179
|
+
"migration/", "migrations/", "alembic/", "drizzle/", "prisma/migrations/",
|
|
180
|
+
]
|
|
181
|
+
.iter()
|
|
182
|
+
.any(|d| low.starts_with(d) || low.contains(&format!("/{}", d)))
|
|
183
|
+
|| low.contains("migrat")
|
|
192
184
|
}
|
|
193
185
|
|
|
186
|
+
fn strip_trailing_comment<'a>(ext: &str, line: &'a str) -> &'a str {
|
|
187
|
+
let hash_cmt = matches!(
|
|
188
|
+
ext,
|
|
189
|
+
"py" | "sh" | "ps1" | "yml" | "yaml" | "toml" | "ini" | "cfg" | "tf"
|
|
190
|
+
);
|
|
191
|
+
let slash_cmt = matches!(
|
|
192
|
+
ext,
|
|
193
|
+
"js" | "mjs" | "cjs" | "ts" | "tsx" | "jsx" | "rs" | "go" | "json" | "jsonc"
|
|
194
|
+
);
|
|
195
|
+
let dash_cmt = matches!(ext, "sql" | "lean");
|
|
196
|
+
let semi_cmt = ext == "smt2";
|
|
197
|
+
if !hash_cmt && !slash_cmt && !dash_cmt && !semi_cmt {
|
|
198
|
+
return line;
|
|
199
|
+
}
|
|
200
|
+
let bytes = line.as_bytes();
|
|
201
|
+
let mut quote: Option<u8> = None;
|
|
202
|
+
let mut i = 0;
|
|
203
|
+
while i < bytes.len() {
|
|
204
|
+
let b = bytes[i];
|
|
205
|
+
if let Some(q) = quote {
|
|
206
|
+
if b == b'\\' && i + 1 < bytes.len() {
|
|
207
|
+
i += 2;
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
if b == q {
|
|
211
|
+
quote = None;
|
|
212
|
+
}
|
|
213
|
+
} else if b == b'"' || b == b'\'' {
|
|
214
|
+
quote = Some(b);
|
|
215
|
+
} else if hash_cmt
|
|
216
|
+
&& b == b'#'
|
|
217
|
+
&& !line[i..].starts_with("#[")
|
|
218
|
+
&& !line[i..].starts_with("#![")
|
|
219
|
+
{
|
|
220
|
+
return &line[..i];
|
|
221
|
+
} else if slash_cmt && i + 1 < bytes.len() && b == b'/' && bytes[i + 1] == b'/' {
|
|
222
|
+
return &line[..i];
|
|
223
|
+
} else if dash_cmt && i + 1 < bytes.len() && b == b'-' && bytes[i + 1] == b'-' {
|
|
224
|
+
return &line[..i];
|
|
225
|
+
} else if semi_cmt && b == b';' {
|
|
226
|
+
return &line[..i];
|
|
227
|
+
}
|
|
228
|
+
i += 1;
|
|
229
|
+
}
|
|
230
|
+
line
|
|
231
|
+
}
|
|
194
232
|
fn is_scanner_or_comment(ext: &str, line: &str) -> bool {
|
|
195
|
-
let
|
|
196
|
-
|
|
233
|
+
let code = strip_trailing_comment(ext, line).trim();
|
|
234
|
+
let code_low = code.to_ascii_lowercase();
|
|
235
|
+
if code.is_empty()
|
|
236
|
+
|| ext == "md"
|
|
237
|
+
|| (matches!(ext, "cmd" | "bat") && (code_low.starts_with("rem ") || code_low.starts_with("::")))
|
|
238
|
+
{
|
|
197
239
|
return true;
|
|
198
240
|
}
|
|
199
241
|
for meta in [
|
|
@@ -209,6 +251,12 @@ fn is_scanner_or_comment(ext: &str, line: &str) -> bool {
|
|
|
209
251
|
"TEST_SKIP_RE",
|
|
210
252
|
"TEST_SKIP_DECORATOR_RE",
|
|
211
253
|
"REWARD_HACK_CMD_RE",
|
|
254
|
+
"SNAPSHOT_OVERWRITE_RE",
|
|
255
|
+
"PACKAGE_NOOP_SCRIPT_RE",
|
|
256
|
+
"E2E_API_STUB_RE",
|
|
257
|
+
"ML_EVAL_LEAKAGE_RE",
|
|
258
|
+
"PROD_TLS_BYPASS_RE",
|
|
259
|
+
"PROD_FK_BYPASS_RE",
|
|
212
260
|
"\"rule\":",
|
|
213
261
|
"rule: \"",
|
|
214
262
|
"Zeroed quality threshold",
|
|
@@ -216,21 +264,10 @@ fn is_scanner_or_comment(ext: &str, line: &str) -> bool {
|
|
|
216
264
|
"Goodhart / Anti-Reward-Hacking",
|
|
217
265
|
"`--min-",
|
|
218
266
|
] {
|
|
219
|
-
if
|
|
267
|
+
if code.contains(meta) {
|
|
220
268
|
return true;
|
|
221
269
|
}
|
|
222
270
|
}
|
|
223
|
-
if matches!(ext, "py" | "sh" | "yml" | "yaml" | "toml")
|
|
224
|
-
&& s.starts_with('#')
|
|
225
|
-
&& !s.starts_with("#[")
|
|
226
|
-
{
|
|
227
|
-
return true;
|
|
228
|
-
}
|
|
229
|
-
if matches!(ext, "js" | "mjs" | "cjs" | "ts" | "tsx" | "jsx" | "rs" | "go")
|
|
230
|
-
&& s.starts_with("//")
|
|
231
|
-
{
|
|
232
|
-
return true;
|
|
233
|
-
}
|
|
234
271
|
false
|
|
235
272
|
}
|
|
236
273
|
|
|
@@ -238,23 +275,48 @@ fn parse_leading_f64(raw: &str) -> Option<f64> {
|
|
|
238
275
|
let t = raw
|
|
239
276
|
.trim_start()
|
|
240
277
|
.trim_start_matches([',', ' ', '\t'])
|
|
241
|
-
.trim_start_matches(['"', '\''])
|
|
278
|
+
.trim_start_matches(['"', '\''])
|
|
279
|
+
.trim_start();
|
|
280
|
+
let low = t.to_ascii_lowercase();
|
|
281
|
+
for (tok, v) in [
|
|
282
|
+
("-infinity", f64::NEG_INFINITY),
|
|
283
|
+
("+infinity", f64::INFINITY),
|
|
284
|
+
("infinity", f64::INFINITY),
|
|
285
|
+
("-inf", f64::NEG_INFINITY),
|
|
286
|
+
("+inf", f64::INFINITY),
|
|
287
|
+
("inf", f64::INFINITY),
|
|
288
|
+
("-nan", f64::NAN),
|
|
289
|
+
("+nan", f64::NAN),
|
|
290
|
+
("nan", f64::NAN),
|
|
291
|
+
] {
|
|
292
|
+
if let Some(rest) = low.strip_prefix(tok) {
|
|
293
|
+
if rest.is_empty() || (!rest.as_bytes()[0].is_ascii_alphanumeric() && rest.as_bytes()[0] != b'_') {
|
|
294
|
+
return Some(v);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
242
298
|
let bytes = t.as_bytes();
|
|
243
299
|
let mut i = 0;
|
|
244
300
|
if i < bytes.len() && (bytes[i] == b'-' || bytes[i] == b'+') {
|
|
245
301
|
i += 1;
|
|
246
302
|
}
|
|
247
|
-
let
|
|
248
|
-
while i < bytes.len() && bytes[i].is_ascii_digit() {
|
|
303
|
+
let mut digits_seen = 0usize;
|
|
304
|
+
while i < bytes.len() && (bytes[i].is_ascii_digit() || bytes[i] == b'_') {
|
|
305
|
+
if bytes[i].is_ascii_digit() {
|
|
306
|
+
digits_seen += 1;
|
|
307
|
+
}
|
|
249
308
|
i += 1;
|
|
250
309
|
}
|
|
251
310
|
if i < bytes.len() && bytes[i] == b'.' {
|
|
252
311
|
i += 1;
|
|
253
|
-
while i < bytes.len() && bytes[i].is_ascii_digit() {
|
|
312
|
+
while i < bytes.len() && (bytes[i].is_ascii_digit() || bytes[i] == b'_') {
|
|
313
|
+
if bytes[i].is_ascii_digit() {
|
|
314
|
+
digits_seen += 1;
|
|
315
|
+
}
|
|
254
316
|
i += 1;
|
|
255
317
|
}
|
|
256
318
|
}
|
|
257
|
-
if
|
|
319
|
+
if digits_seen == 0 {
|
|
258
320
|
return None;
|
|
259
321
|
}
|
|
260
322
|
if i < bytes.len() && (bytes[i] == b'e' || bytes[i] == b'E') {
|
|
@@ -264,7 +326,7 @@ fn parse_leading_f64(raw: &str) -> Option<f64> {
|
|
|
264
326
|
i += 1;
|
|
265
327
|
}
|
|
266
328
|
let exp_digits = i;
|
|
267
|
-
while i < bytes.len() && bytes[i].is_ascii_digit() {
|
|
329
|
+
while i < bytes.len() && (bytes[i].is_ascii_digit() || bytes[i] == b'_') {
|
|
268
330
|
i += 1;
|
|
269
331
|
}
|
|
270
332
|
if i == exp_digits {
|
|
@@ -274,37 +336,112 @@ fn parse_leading_f64(raw: &str) -> Option<f64> {
|
|
|
274
336
|
if i < bytes.len() && (bytes[i].is_ascii_alphanumeric() || bytes[i] == b'_') {
|
|
275
337
|
return None;
|
|
276
338
|
}
|
|
277
|
-
t[..i].
|
|
339
|
+
let cleaned: String = t[..i].chars().filter(|c| *c != '_').collect();
|
|
340
|
+
cleaned.parse::<f64>().ok()
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
fn prefix_metric_floor(tok: &str) -> Option<f64> {
|
|
344
|
+
let norm = tok.replace('-', "_");
|
|
345
|
+
if matches!(
|
|
346
|
+
norm.as_str(),
|
|
347
|
+
"p" | "k" | "port" | "ports" | "workers" | "threads" | "bytes" | "size" | "len" | "length"
|
|
348
|
+
| "delay" | "wait" | "sleep" | "timeout" | "retries" | "count" | "items" | "nodes"
|
|
349
|
+
| "epochs" | "steps" | "batch"
|
|
350
|
+
) {
|
|
351
|
+
return None;
|
|
352
|
+
}
|
|
353
|
+
if QUAL_LOWER_METRICS.contains(&norm.as_str()) {
|
|
354
|
+
return Some(metric_min_floor(&norm));
|
|
355
|
+
}
|
|
356
|
+
if norm.is_empty() {
|
|
357
|
+
return None;
|
|
358
|
+
}
|
|
359
|
+
let mut best: Option<f64> = None;
|
|
360
|
+
for m in QUAL_LOWER_METRICS {
|
|
361
|
+
if m.starts_with(&norm) {
|
|
362
|
+
let f = metric_min_floor(m);
|
|
363
|
+
best = Some(best.map_or(f, |b| b.max(f)));
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
best
|
|
278
367
|
}
|
|
279
368
|
|
|
280
369
|
pub fn has_threshold_zero_or_skip(line: &str) -> bool {
|
|
281
370
|
let low = line.to_ascii_lowercase();
|
|
282
|
-
for
|
|
283
|
-
let cli_flag = format!("--min-{}", m.replace('_', "-"));
|
|
371
|
+
for flag_pref in ["--min-", "--gate-min-"] {
|
|
284
372
|
let mut cfrom = 0;
|
|
285
|
-
while let Some(rel) = low[cfrom..].find(
|
|
373
|
+
while let Some(rel) = low[cfrom..].find(flag_pref) {
|
|
286
374
|
let pos = cfrom + rel;
|
|
287
|
-
let
|
|
288
|
-
cfrom =
|
|
375
|
+
let name_start = pos + flag_pref.len();
|
|
376
|
+
cfrom = name_start;
|
|
377
|
+
if pos > 0
|
|
378
|
+
&& (low.as_bytes()[pos - 1].is_ascii_alphanumeric()
|
|
379
|
+
|| low.as_bytes()[pos - 1] == b'_')
|
|
380
|
+
{
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
let name_len = low[name_start..]
|
|
384
|
+
.bytes()
|
|
385
|
+
.take_while(|b| b.is_ascii_alphanumeric() || *b == b'-' || *b == b'_')
|
|
386
|
+
.count();
|
|
387
|
+
if name_len == 0 {
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
let tok = &low[name_start..name_start + name_len];
|
|
391
|
+
let Some(floor) = prefix_metric_floor(tok) else {
|
|
392
|
+
continue;
|
|
393
|
+
};
|
|
394
|
+
let tail = low[name_start + name_len..].trim_start_matches(['"', '\'']);
|
|
395
|
+
if let Some(rest) = tail
|
|
396
|
+
.strip_prefix('=')
|
|
397
|
+
.or_else(|| tail.strip_prefix(','))
|
|
398
|
+
.or_else(|| tail.strip_prefix(' '))
|
|
399
|
+
.or_else(|| tail.strip_prefix('\t'))
|
|
400
|
+
{
|
|
401
|
+
if let Some(val) = parse_leading_f64(rest) {
|
|
402
|
+
if !val.is_finite() || val < floor {
|
|
403
|
+
return true;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
for bare_pref in ["--min", "--mi", "--gate-min", "--gate-mi"] {
|
|
410
|
+
let mut bfrom = 0;
|
|
411
|
+
while let Some(rel) = low[bfrom..].find(bare_pref) {
|
|
412
|
+
let pos = bfrom + rel;
|
|
413
|
+
let end = pos + bare_pref.len();
|
|
414
|
+
bfrom = end;
|
|
289
415
|
if pos > 0
|
|
290
416
|
&& (low.as_bytes()[pos - 1].is_ascii_alphanumeric()
|
|
291
417
|
|| low.as_bytes()[pos - 1] == b'_')
|
|
292
418
|
{
|
|
293
419
|
continue;
|
|
294
420
|
}
|
|
421
|
+
if end < low.len()
|
|
422
|
+
&& (low.as_bytes()[end].is_ascii_alphanumeric()
|
|
423
|
+
|| low.as_bytes()[end] == b'-'
|
|
424
|
+
|| low.as_bytes()[end] == b'_')
|
|
425
|
+
{
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
295
428
|
let tail = low[end..].trim_start_matches(['"', '\'']);
|
|
296
429
|
if let Some(rest) = tail
|
|
297
430
|
.strip_prefix('=')
|
|
298
431
|
.or_else(|| tail.strip_prefix(','))
|
|
299
432
|
.or_else(|| tail.strip_prefix(' '))
|
|
433
|
+
.or_else(|| tail.strip_prefix('\t'))
|
|
300
434
|
{
|
|
301
435
|
if let Some(val) = parse_leading_f64(rest) {
|
|
302
|
-
if val
|
|
436
|
+
if !val.is_finite() || val < 0.50 {
|
|
303
437
|
return true;
|
|
304
438
|
}
|
|
305
439
|
}
|
|
306
440
|
}
|
|
307
441
|
}
|
|
442
|
+
}
|
|
443
|
+
for m in QUAL_LOWER_METRICS {
|
|
444
|
+
let floor = metric_min_floor(m);
|
|
308
445
|
for pref in ["min_", "minimum_"] {
|
|
309
446
|
let kw = format!("{}{}", pref, m);
|
|
310
447
|
let mut from = 0;
|
|
@@ -321,14 +458,14 @@ pub fn has_threshold_zero_or_skip(line: &str) -> bool {
|
|
|
321
458
|
if !prev_ok || !next_ok {
|
|
322
459
|
continue;
|
|
323
460
|
}
|
|
324
|
-
let rest = low[end..].trim_start();
|
|
461
|
+
let rest = low[end..].trim_start_matches(['"', '\'']).trim_start();
|
|
325
462
|
if let Some(val_part) = rest
|
|
326
463
|
.strip_prefix('=')
|
|
327
464
|
.filter(|s| !s.starts_with('='))
|
|
328
465
|
.or_else(|| rest.strip_prefix(':'))
|
|
329
466
|
{
|
|
330
467
|
if let Some(val) = parse_leading_f64(val_part) {
|
|
331
|
-
if val
|
|
468
|
+
if !val.is_finite() || val < floor {
|
|
332
469
|
return true;
|
|
333
470
|
}
|
|
334
471
|
}
|
|
@@ -337,12 +474,67 @@ pub fn has_threshold_zero_or_skip(line: &str) -> bool {
|
|
|
337
474
|
}
|
|
338
475
|
}
|
|
339
476
|
for flag in SKIP_FLAGS {
|
|
340
|
-
|
|
477
|
+
let fl_low = flag.to_ascii_lowercase();
|
|
478
|
+
let mut sfrom = 0;
|
|
479
|
+
while let Some(rel) = low[sfrom..].find(&fl_low) {
|
|
480
|
+
let pos = sfrom + rel;
|
|
481
|
+
let end = pos + fl_low.len();
|
|
482
|
+
sfrom = end;
|
|
483
|
+
let prev_ok = pos == 0
|
|
484
|
+
|| (!low.as_bytes()[pos - 1].is_ascii_alphanumeric() && low.as_bytes()[pos - 1] != b'_');
|
|
485
|
+
let next_ok = end >= low.len()
|
|
486
|
+
|| (!low.as_bytes()[end].is_ascii_alphanumeric()
|
|
487
|
+
&& low.as_bytes()[end] != b'_'
|
|
488
|
+
&& low.as_bytes()[end] != b'-');
|
|
489
|
+
if prev_ok && next_ok {
|
|
490
|
+
return true;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if let Some(cpos) = low.find("git commit") {
|
|
495
|
+
let seg = low[cpos + "git commit".len()..].split([';', '&', '|']).next().unwrap_or("");
|
|
496
|
+
if seg
|
|
497
|
+
.split_ascii_whitespace()
|
|
498
|
+
.any(|t| t == "-n" || t == "--no-verify")
|
|
499
|
+
{
|
|
341
500
|
return true;
|
|
342
501
|
}
|
|
343
502
|
}
|
|
344
|
-
if
|
|
345
|
-
|
|
503
|
+
if let Some(pos) = low.find("--cov-fail-under") {
|
|
504
|
+
let tail = low[pos + "--cov-fail-under".len()..].trim_start_matches(['"', '\'']);
|
|
505
|
+
if let Some(rest) = tail
|
|
506
|
+
.strip_prefix('=')
|
|
507
|
+
.or_else(|| tail.strip_prefix(','))
|
|
508
|
+
.or_else(|| tail.strip_prefix(' '))
|
|
509
|
+
.or_else(|| tail.strip_prefix('\t'))
|
|
510
|
+
{
|
|
511
|
+
if let Some(val) = parse_leading_f64(rest) {
|
|
512
|
+
if !val.is_finite() || val < 50.0 {
|
|
513
|
+
return true;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
for (flag_kw, bad_val) in [
|
|
519
|
+
("--require-spark-receipt", "false"),
|
|
520
|
+
("--gate-mode", "off"),
|
|
521
|
+
("--measured-gates", "off"),
|
|
522
|
+
("--skip-heavy-renders", "true"),
|
|
523
|
+
("--check-360", "false"),
|
|
524
|
+
] {
|
|
525
|
+
if let Some(pos) = low.find(flag_kw) {
|
|
526
|
+
let tail = low[pos + flag_kw.len()..].trim_start_matches(['"', '\'']);
|
|
527
|
+
if let Some(rest) = tail
|
|
528
|
+
.strip_prefix('=')
|
|
529
|
+
.or_else(|| tail.strip_prefix(','))
|
|
530
|
+
.or_else(|| tail.strip_prefix(' '))
|
|
531
|
+
{
|
|
532
|
+
let val = rest.trim_start_matches([' ', '"', '\'']);
|
|
533
|
+
if val.starts_with(bad_val) {
|
|
534
|
+
return true;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
346
538
|
}
|
|
347
539
|
for kw in ["skip_reference", "skip_validation", "skip_fidelity", "bypass_gate"] {
|
|
348
540
|
if let Some(pos) = low.find(kw) {
|
|
@@ -366,6 +558,16 @@ pub fn has_threshold_zero_or_skip(line: &str) -> bool {
|
|
|
366
558
|
}
|
|
367
559
|
}
|
|
368
560
|
}
|
|
561
|
+
if low.contains("go test")
|
|
562
|
+
&& (low.contains("-run=^$")
|
|
563
|
+
|| low.contains("-run ^$")
|
|
564
|
+
|| low.contains("-run=\"^$\"")
|
|
565
|
+
|| low.contains("-run='^$'")
|
|
566
|
+
|| low.contains("-run \"^$\"")
|
|
567
|
+
|| low.contains("-run '^$'"))
|
|
568
|
+
{
|
|
569
|
+
return true;
|
|
570
|
+
}
|
|
369
571
|
false
|
|
370
572
|
}
|
|
371
573
|
|
|
@@ -378,10 +580,15 @@ pub fn has_test_skip(line: &str) -> bool {
|
|
|
378
580
|
if t.starts_with("#[ignore") || t.starts_with("# [ignore") {
|
|
379
581
|
return true;
|
|
380
582
|
}
|
|
583
|
+
if t.starts_with("@pytest.mark.xfail") && !t.contains("strict=True") && !t.contains("strict = True") {
|
|
584
|
+
return true;
|
|
585
|
+
}
|
|
381
586
|
for pat in ["@pytest.mark.skip", "@unittest.skip"] {
|
|
382
587
|
if let Some(after) = t.strip_prefix(pat) {
|
|
383
|
-
|
|
384
|
-
|
|
588
|
+
let boundary_ok = after.is_empty()
|
|
589
|
+
|| after.starts_with('(')
|
|
590
|
+
|| after.starts_with(|c: char| c.is_ascii_whitespace());
|
|
591
|
+
if boundary_ok {
|
|
385
592
|
return true;
|
|
386
593
|
}
|
|
387
594
|
}
|
|
@@ -429,46 +636,714 @@ pub fn find_rs_cfg_test_line(txt: &str) -> Option<usize> {
|
|
|
429
636
|
None
|
|
430
637
|
}
|
|
431
638
|
|
|
432
|
-
|
|
433
|
-
|
|
639
|
+
fn is_ident_char(c: char) -> bool {
|
|
640
|
+
c.is_alphanumeric() || c == '_'
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
pub fn has_primitive_standin(line: &str) -> bool {
|
|
644
|
+
if PRIMITIVE_TOKENS.iter().any(|tok| has_word_token(line, tok)) {
|
|
645
|
+
return true;
|
|
646
|
+
}
|
|
647
|
+
for p in PRIMITIVE_PATHS {
|
|
648
|
+
let mut from = 0;
|
|
649
|
+
while let Some(rel) = line[from..].find(p) {
|
|
650
|
+
let end = from + rel + p.len();
|
|
651
|
+
from = end;
|
|
652
|
+
let next_ok = !line[end..].chars().next().is_some_and(is_ident_char);
|
|
653
|
+
if next_ok {
|
|
654
|
+
return true;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
for fn_name in PRIMITIVE_FN_CALLS {
|
|
659
|
+
let mut from = 0;
|
|
660
|
+
while let Some(rel) = line[from..].find(fn_name) {
|
|
661
|
+
let pos = from + rel;
|
|
662
|
+
let end = pos + fn_name.len();
|
|
663
|
+
from = end;
|
|
664
|
+
let prev_ok = !line[..pos].chars().next_back().is_some_and(is_ident_char);
|
|
665
|
+
let next_ok = !line[end..].chars().next().is_some_and(is_ident_char);
|
|
666
|
+
if !prev_ok {
|
|
667
|
+
continue;
|
|
668
|
+
}
|
|
669
|
+
if line[end..].trim_start().starts_with('(') {
|
|
670
|
+
return true;
|
|
671
|
+
}
|
|
672
|
+
if next_ok && (fn_name.starts_with("THREE.") || fn_name.starts_with("MeshBuilder.")) {
|
|
673
|
+
let before_trimmed = line[..pos].trim_end();
|
|
674
|
+
if let Some(before_new) = before_trimmed.strip_suffix("new") {
|
|
675
|
+
let new_boundary = !before_new.chars().next_back().is_some_and(is_ident_char);
|
|
676
|
+
if new_boundary && pos > before_trimmed.len() {
|
|
677
|
+
return true;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
false
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
fn has_word_token(haystack: &str, word: &str) -> bool {
|
|
687
|
+
let mut from = 0;
|
|
688
|
+
while let Some(rel) = haystack[from..].find(word) {
|
|
689
|
+
let pos = from + rel;
|
|
690
|
+
let end = pos + word.len();
|
|
691
|
+
from = end;
|
|
692
|
+
let prev_ok = !haystack[..pos].chars().next_back().is_some_and(is_ident_char);
|
|
693
|
+
let next_ok = !haystack[end..].chars().next().is_some_and(is_ident_char);
|
|
694
|
+
if prev_ok && next_ok {
|
|
695
|
+
return true;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
false
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
fn has_word_prefix(haystack: &str, pref: &str) -> bool {
|
|
702
|
+
let mut from = 0;
|
|
703
|
+
while let Some(rel) = haystack[from..].find(pref) {
|
|
704
|
+
let pos = from + rel;
|
|
705
|
+
from = pos + pref.len();
|
|
706
|
+
if !haystack[..pos].chars().next_back().is_some_and(is_ident_char) {
|
|
707
|
+
return true;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
false
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
fn extract_unquoted_comment<'a>(ext: &str, line: &'a str) -> &'a str {
|
|
714
|
+
let allow_hash = !matches!(
|
|
715
|
+
ext,
|
|
716
|
+
"rs" | "go" | "js" | "mjs" | "cjs" | "ts" | "tsx" | "jsx" | "c" | "cpp" | "java"
|
|
717
|
+
);
|
|
718
|
+
let bytes = line.as_bytes();
|
|
719
|
+
let mut quote: Option<u8> = None;
|
|
720
|
+
let mut i = 0;
|
|
721
|
+
while i < bytes.len() {
|
|
722
|
+
let b = bytes[i];
|
|
723
|
+
if let Some(q) = quote {
|
|
724
|
+
if b == b'\\' && i + 1 < bytes.len() {
|
|
725
|
+
i += 2;
|
|
726
|
+
continue;
|
|
727
|
+
}
|
|
728
|
+
if b == q {
|
|
729
|
+
quote = None;
|
|
730
|
+
}
|
|
731
|
+
} else if b == b'"' || b == b'\'' {
|
|
732
|
+
quote = Some(b);
|
|
733
|
+
} else if allow_hash
|
|
734
|
+
&& b == b'#'
|
|
735
|
+
&& !line[i..].starts_with("#[")
|
|
736
|
+
&& !line[i..].starts_with("#![")
|
|
737
|
+
{
|
|
738
|
+
return &line[i..];
|
|
739
|
+
} else if i + 1 < bytes.len()
|
|
740
|
+
&& b == b'/'
|
|
741
|
+
&& (bytes[i + 1] == b'/' || bytes[i + 1] == b'*')
|
|
742
|
+
{
|
|
743
|
+
return &line[i..];
|
|
744
|
+
}
|
|
745
|
+
i += 1;
|
|
746
|
+
}
|
|
747
|
+
""
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
fn quoted_end(text: &str, mut i: usize, delimiter: &str) -> Option<usize> {
|
|
751
|
+
let bytes = text.as_bytes();
|
|
752
|
+
while i < bytes.len() {
|
|
753
|
+
if bytes[i..].starts_with(delimiter.as_bytes()) {
|
|
754
|
+
return Some(i + delimiter.len());
|
|
755
|
+
}
|
|
756
|
+
i += if bytes[i] == b'\\' { 2 } else { 1 };
|
|
757
|
+
}
|
|
758
|
+
None
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
pub fn scrub_proof_text_lines(ext: &str, text: &str) -> BTreeMap<usize, String> {
|
|
762
|
+
let (open_tok, close_tok) = match ext {
|
|
763
|
+
"lean" => ("/-", "-/"),
|
|
764
|
+
"v" => ("(*", "*)"),
|
|
765
|
+
_ => ("", ""),
|
|
766
|
+
};
|
|
767
|
+
let dash_line = ext == "lean";
|
|
768
|
+
let semi_line = ext == "smt2";
|
|
769
|
+
let mut depth: usize = 0;
|
|
770
|
+
let mut out = BTreeMap::new();
|
|
771
|
+
for (idx, raw) in text.lines().enumerate() {
|
|
772
|
+
let bytes = raw.as_bytes();
|
|
773
|
+
let mut buf = String::with_capacity(raw.len());
|
|
774
|
+
let mut i = 0;
|
|
775
|
+
while i < bytes.len() {
|
|
776
|
+
if depth > 0 {
|
|
777
|
+
if !open_tok.is_empty() && raw[i..].starts_with(open_tok) {
|
|
778
|
+
depth += 1;
|
|
779
|
+
i += 2;
|
|
780
|
+
continue;
|
|
781
|
+
}
|
|
782
|
+
if !close_tok.is_empty() && raw[i..].starts_with(close_tok) {
|
|
783
|
+
depth -= 1;
|
|
784
|
+
buf.push(' ');
|
|
785
|
+
i += 2;
|
|
786
|
+
continue;
|
|
787
|
+
}
|
|
788
|
+
if let Some(ch) = raw[i..].chars().next() {
|
|
789
|
+
i += ch.len_utf8();
|
|
790
|
+
} else {
|
|
791
|
+
break;
|
|
792
|
+
}
|
|
793
|
+
continue;
|
|
794
|
+
}
|
|
795
|
+
if bytes[i] == b'"' {
|
|
796
|
+
buf.push_str("\"\"");
|
|
797
|
+
i = quoted_end(raw, i + 1, "\"").unwrap_or(bytes.len());
|
|
798
|
+
continue;
|
|
799
|
+
}
|
|
800
|
+
if dash_line && raw[i..].starts_with("--") {
|
|
801
|
+
break;
|
|
802
|
+
}
|
|
803
|
+
if semi_line && bytes[i] == b';' {
|
|
804
|
+
break;
|
|
805
|
+
}
|
|
806
|
+
if !open_tok.is_empty() && raw[i..].starts_with(open_tok) {
|
|
807
|
+
depth += 1;
|
|
808
|
+
buf.push(' ');
|
|
809
|
+
i += 2;
|
|
810
|
+
continue;
|
|
811
|
+
}
|
|
812
|
+
if let Some(ch) = raw[i..].chars().next() {
|
|
813
|
+
buf.push(ch);
|
|
814
|
+
i += ch.len_utf8();
|
|
815
|
+
} else {
|
|
816
|
+
break;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
out.insert(idx + 1, buf);
|
|
820
|
+
}
|
|
821
|
+
out
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
fn has_kw_ws_ident(trimmed: &str, kw: &str) -> bool {
|
|
825
|
+
let Some(after) = trimmed.strip_prefix(kw) else {
|
|
826
|
+
return false;
|
|
827
|
+
};
|
|
828
|
+
if !after.chars().next().is_some_and(char::is_whitespace) {
|
|
829
|
+
return false;
|
|
830
|
+
}
|
|
831
|
+
after
|
|
832
|
+
.trim_start()
|
|
833
|
+
.chars()
|
|
834
|
+
.next()
|
|
835
|
+
.is_some_and(|c| c.is_ascii_alphabetic() || c == '_')
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
fn has_admitted_dot(line: &str) -> bool {
|
|
839
|
+
let mut from = 0;
|
|
840
|
+
while let Some(rel) = line[from..].find("Admitted") {
|
|
841
|
+
let pos = from + rel;
|
|
842
|
+
let end = pos + "Admitted".len();
|
|
843
|
+
from = end;
|
|
844
|
+
let prev_ok = !line[..pos].chars().next_back().is_some_and(is_ident_char);
|
|
845
|
+
let next_ok = !line[end..].chars().next().is_some_and(is_ident_char);
|
|
846
|
+
if prev_ok && next_ok && line[end..].trim_start().starts_with('.') {
|
|
847
|
+
return true;
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
false
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
fn has_smt_assert_false(line: &str) -> bool {
|
|
854
|
+
let low = line.to_ascii_lowercase();
|
|
855
|
+
let mut from = 0;
|
|
856
|
+
while let Some(rel) = low[from..].find('(') {
|
|
857
|
+
let pos = from + rel + 1;
|
|
858
|
+
from = pos;
|
|
859
|
+
let after_paren = low[pos..].trim_start();
|
|
860
|
+
let Some(after_assert) = after_paren.strip_prefix("assert") else {
|
|
861
|
+
continue;
|
|
862
|
+
};
|
|
863
|
+
if !after_assert.chars().next().is_some_and(char::is_whitespace) {
|
|
864
|
+
continue;
|
|
865
|
+
}
|
|
866
|
+
let after_ws = after_assert.trim_start();
|
|
867
|
+
if let Some(after_false) = after_ws.strip_prefix("false") {
|
|
868
|
+
if after_false.trim_start().starts_with(')') {
|
|
869
|
+
return true;
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
false
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
fn has_proof_escape_scrubbed(ext: &str, line: &str) -> bool {
|
|
877
|
+
let t = line.trim_start();
|
|
878
|
+
let after_noncomp = t
|
|
879
|
+
.strip_prefix("noncomputable")
|
|
880
|
+
.filter(|r| r.chars().next().is_some_and(char::is_whitespace))
|
|
881
|
+
.map(str::trim_start)
|
|
882
|
+
.unwrap_or(t);
|
|
883
|
+
match ext {
|
|
884
|
+
"lean" => {
|
|
885
|
+
has_word_token(line, "sorry")
|
|
886
|
+
|| has_word_token(line, "sorryAx")
|
|
887
|
+
|| has_word_token(line, "admit")
|
|
888
|
+
|| has_word_token(line, "native_decide")
|
|
889
|
+
|| has_kw_ws_ident(after_noncomp, "axiom")
|
|
890
|
+
}
|
|
891
|
+
"v" => {
|
|
892
|
+
has_admitted_dot(line)
|
|
893
|
+
|| has_kw_ws_ident(t, "Axiom")
|
|
894
|
+
|| has_kw_ws_ident(t, "Parameter")
|
|
895
|
+
}
|
|
896
|
+
"smt2" => has_smt_assert_false(line),
|
|
897
|
+
_ => false,
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
fn has_tla_cfg_commented_invariant(raw_line: &str) -> bool {
|
|
902
|
+
let t = raw_line.trim_start();
|
|
903
|
+
let Some(rest) = t.strip_prefix("\\*") else {
|
|
904
|
+
return false;
|
|
905
|
+
};
|
|
906
|
+
let u = rest.trim_start();
|
|
907
|
+
["INVARIANT", "INVARIANTS", "PROPERTY", "PROPERTIES"]
|
|
908
|
+
.iter()
|
|
909
|
+
.any(|kw| u.starts_with(kw) && !u[kw.len()..].chars().next().is_some_and(is_ident_char))
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
fn has_iac_sec_suppression(cmt_slice: &str) -> bool {
|
|
913
|
+
if cmt_slice.is_empty() {
|
|
914
|
+
return false;
|
|
915
|
+
}
|
|
916
|
+
let low = cmt_slice.to_ascii_lowercase();
|
|
917
|
+
let norm_ws: String = low.split_whitespace().collect::<Vec<_>>().join(" ");
|
|
918
|
+
has_word_prefix(&low, "tfsec:ignore:")
|
|
919
|
+
|| has_word_prefix(&low, "checkov:skip=")
|
|
920
|
+
|| has_word_prefix(&low, "trivy:ignore:")
|
|
921
|
+
|| has_word_prefix(&low, "terrascan:skip=")
|
|
922
|
+
|| has_word_token(&norm_ws, "kics-scan ignore")
|
|
923
|
+
|| has_word_token(&low, "nosemgrep")
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
fn has_vacuous_query(line: &str) -> bool {
|
|
927
|
+
let low = line.to_ascii_lowercase();
|
|
928
|
+
let norm_ws: String = low.split_whitespace().collect::<Vec<_>>().join(" ");
|
|
929
|
+
if has_word_token(&norm_ws, "where false") || has_word_token(&norm_ws, "limit 0") {
|
|
930
|
+
return true;
|
|
931
|
+
}
|
|
932
|
+
let mut from = 0;
|
|
933
|
+
while let Some(rel) = low[from..].find("where") {
|
|
934
|
+
let pos = from + rel;
|
|
935
|
+
let end = pos + "where".len();
|
|
936
|
+
from = end;
|
|
937
|
+
let prev_ok = pos == 0
|
|
938
|
+
|| (!low.as_bytes()[pos - 1].is_ascii_alphanumeric() && low.as_bytes()[pos - 1] != b'_');
|
|
939
|
+
if !prev_ok || !low[end..].chars().next().is_some_and(char::is_whitespace) {
|
|
940
|
+
continue;
|
|
941
|
+
}
|
|
942
|
+
let after_where = low[end..].trim_start();
|
|
943
|
+
if let Some(after_one) = after_where.strip_prefix('1') {
|
|
944
|
+
let after_one_ws = after_one.trim_start();
|
|
945
|
+
if let Some(after_eq) = after_one_ws.strip_prefix('=') {
|
|
946
|
+
let after_eq_ws = after_eq.trim_start();
|
|
947
|
+
if let Some(after_zero) = after_eq_ws.strip_prefix('0') {
|
|
948
|
+
if !after_zero
|
|
949
|
+
.chars()
|
|
950
|
+
.next()
|
|
951
|
+
.is_some_and(|c| c.is_ascii_alphanumeric() || c == '_')
|
|
952
|
+
{
|
|
953
|
+
return true;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
false
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
pub fn has_hardcoded_pass(line: &str) -> bool {
|
|
963
|
+
let compact: String = line.chars().filter(|c| !c.is_ascii_whitespace()).collect();
|
|
964
|
+
let low = compact.to_ascii_lowercase();
|
|
965
|
+
let Some(rpos) = low.find("return{") else {
|
|
966
|
+
return false;
|
|
967
|
+
};
|
|
968
|
+
let body = &low[rpos + "return{".len()..];
|
|
969
|
+
let mut after_pass: Option<&str> = None;
|
|
970
|
+
for pk in [
|
|
971
|
+
"\"pass\":", "'pass':", "\"passed\":", "'passed':", "\"ok\":", "'ok':", "\"verdict\":", "'verdict':",
|
|
972
|
+
] {
|
|
973
|
+
if let Some(rest) = body.strip_prefix(pk) {
|
|
974
|
+
for pv in ["true,", "\"pass\",", "'pass',"] {
|
|
975
|
+
if let Some(r2) = rest.strip_prefix(pv) {
|
|
976
|
+
after_pass = Some(r2);
|
|
977
|
+
break;
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
let Some(rem) = after_pass else {
|
|
983
|
+
return false;
|
|
984
|
+
};
|
|
985
|
+
for mk in [
|
|
986
|
+
"\"iou\":", "'iou':", "\"ssim\":", "'ssim':", "\"psnr\":", "'psnr':", "\"score\":", "'score':",
|
|
987
|
+
"\"fidelity\":", "'fidelity':", "\"accuracy\":", "'accuracy':", "\"f1\":", "'f1':", "\"auc\":", "'auc':",
|
|
988
|
+
"\"bleu\":", "'bleu':", "\"rouge\":", "'rouge':", "\"ndcg\":", "'ndcg':", "\"pass_rate\":", "'pass_rate':",
|
|
989
|
+
"\"win_rate\":", "'win_rate':", "\"coverage\":", "'coverage':", "\"throughput\":", "'throughput':",
|
|
990
|
+
"\"speedup\":", "'speedup':",
|
|
991
|
+
] {
|
|
992
|
+
if let Some(vrest) = rem.strip_prefix(mk) {
|
|
993
|
+
for num in ["1.0", "100.0"] {
|
|
994
|
+
if let Some(tail) = vrest.strip_prefix(num) {
|
|
995
|
+
if !tail.chars().next().is_some_and(|c| c.is_ascii_alphanumeric() || c == '_') {
|
|
996
|
+
return true;
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
false
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
fn has_prod_test_branch(line: &str) -> bool {
|
|
1006
|
+
if [
|
|
1007
|
+
"PYTEST_CURRENT_TEST",
|
|
1008
|
+
"JEST_WORKER_ID",
|
|
1009
|
+
"VITEST_WORKER_ID",
|
|
1010
|
+
"UNITTEST_RUNNING",
|
|
1011
|
+
"_called_from_test",
|
|
1012
|
+
]
|
|
1013
|
+
.iter()
|
|
1014
|
+
.any(|m| line.contains(m))
|
|
1015
|
+
{
|
|
1016
|
+
return true;
|
|
1017
|
+
}
|
|
1018
|
+
let norm: String = line.split_whitespace().collect::<Vec<_>>().join(" ");
|
|
1019
|
+
norm.contains("\"pytest\" in sys.modules")
|
|
1020
|
+
|| norm.contains("'pytest' in sys.modules")
|
|
1021
|
+
|| norm.contains("\"unittest\" in sys.modules")
|
|
1022
|
+
|| norm.contains("'unittest' in sys.modules")
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
fn is_e2e_file(rel: &str) -> bool {
|
|
1026
|
+
let low = rel.to_ascii_lowercase();
|
|
1027
|
+
low.starts_with("e2e/")
|
|
1028
|
+
|| low.starts_with("cypress/")
|
|
1029
|
+
|| low.starts_with("playwright/")
|
|
1030
|
+
|| low.contains("/e2e/")
|
|
1031
|
+
|| low.contains("/cypress/")
|
|
1032
|
+
|| low.contains("/playwright/")
|
|
1033
|
+
|| low.contains(".e2e.")
|
|
1034
|
+
|| low.contains(".pw.")
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
fn has_snapshot_overwrite(line: &str) -> bool {
|
|
1038
|
+
let low = line.to_ascii_lowercase();
|
|
1039
|
+
for flag in [
|
|
1040
|
+
"--update-snapshots",
|
|
1041
|
+
"--snapshot-update",
|
|
1042
|
+
"--overwrite-snapshots",
|
|
1043
|
+
"--updatesnapshot",
|
|
1044
|
+
] {
|
|
1045
|
+
if let Some(pos) = low.find(flag) {
|
|
1046
|
+
let prev_ok = pos == 0
|
|
1047
|
+
|| (!low.as_bytes()[pos - 1].is_ascii_alphanumeric() && low.as_bytes()[pos - 1] != b'_');
|
|
1048
|
+
let after = &low[pos + flag.len()..];
|
|
1049
|
+
let next_ok = after.is_empty()
|
|
1050
|
+
|| after.starts_with('=')
|
|
1051
|
+
|| after.starts_with(|c: char| c.is_ascii_whitespace() || matches!(c, ';' | '&' | '|' | ')' | '"' | '\''));
|
|
1052
|
+
if prev_ok && next_ok {
|
|
1053
|
+
return true;
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
if low.contains("cargo ") && low.contains("insta accept") {
|
|
1058
|
+
return true;
|
|
1059
|
+
}
|
|
1060
|
+
for env_k in ["update_snapshots=", "snapshot_update=", "insta_update="] {
|
|
1061
|
+
if let Some(pos) = low.find(env_k) {
|
|
1062
|
+
let v = low[pos + env_k.len()..].trim_start_matches(['"', '\'']);
|
|
1063
|
+
if v.starts_with('1') || v.starts_with("true") || v.starts_with("always") || v.starts_with("all") {
|
|
1064
|
+
return true;
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
for runner in ["jest ", "vitest ", "playwright test "] {
|
|
1069
|
+
let mut from = 0;
|
|
1070
|
+
while let Some(rel) = low[from..].find(runner) {
|
|
1071
|
+
let pos = from + rel;
|
|
1072
|
+
from = pos + runner.len();
|
|
1073
|
+
let prev_ok = pos == 0
|
|
1074
|
+
|| (!low.as_bytes()[pos - 1].is_ascii_alphanumeric()
|
|
1075
|
+
&& low.as_bytes()[pos - 1] != b'_'
|
|
1076
|
+
&& low.as_bytes()[pos - 1] != b'-');
|
|
1077
|
+
if !prev_ok {
|
|
1078
|
+
continue;
|
|
1079
|
+
}
|
|
1080
|
+
let seg = low[pos + runner.len()..].split([';', '&', '|']).next().unwrap_or("");
|
|
1081
|
+
if seg
|
|
1082
|
+
.split(|c: char| c.is_ascii_whitespace() || c == ')')
|
|
1083
|
+
.any(|tok| tok == "-u" || tok == "--update")
|
|
1084
|
+
{
|
|
1085
|
+
return true;
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
false
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
fn is_package_noop_script(line: &str) -> bool {
|
|
1093
|
+
let t = line.trim().trim_end_matches(',').trim();
|
|
1094
|
+
for key in ["\"test\"", "\"check\"", "\"typecheck\"", "\"lint\"", "\"verify\""] {
|
|
1095
|
+
if let Some(rest) = t.strip_prefix(key) {
|
|
1096
|
+
let Some(val_part) = rest.trim_start().strip_prefix(':') else {
|
|
1097
|
+
continue;
|
|
1098
|
+
};
|
|
1099
|
+
let v = val_part.trim();
|
|
1100
|
+
if let Some(inner) = v.strip_prefix('"').and_then(|s| s.strip_suffix('"')) {
|
|
1101
|
+
let cmd = inner.trim().to_ascii_lowercase();
|
|
1102
|
+
if cmd == "true" || cmd == "exit 0" || cmd == ":" {
|
|
1103
|
+
return true;
|
|
1104
|
+
}
|
|
1105
|
+
if (cmd == "echo" || cmd.starts_with("echo "))
|
|
1106
|
+
&& !cmd.contains("&&")
|
|
1107
|
+
&& !cmd.contains("||")
|
|
1108
|
+
&& !cmd.contains(';')
|
|
1109
|
+
&& !cmd.contains('|')
|
|
1110
|
+
{
|
|
1111
|
+
return true;
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
false
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
fn has_json_key_false(line: &str, keys_low: &[&str]) -> bool {
|
|
1120
|
+
let bytes = line.as_bytes();
|
|
1121
|
+
let mut i = 0;
|
|
1122
|
+
while i < bytes.len() {
|
|
1123
|
+
let q = bytes[i];
|
|
1124
|
+
if q != b'"' && q != b'\'' {
|
|
1125
|
+
i += 1;
|
|
1126
|
+
continue;
|
|
1127
|
+
}
|
|
1128
|
+
let prev = line[..i].trim_end();
|
|
1129
|
+
let is_key_pos = prev.is_empty() || prev.ends_with('{') || prev.ends_with(',');
|
|
1130
|
+
let mut j = i + 1;
|
|
1131
|
+
let mut key_buf = String::new();
|
|
1132
|
+
while j < bytes.len() {
|
|
1133
|
+
if bytes[j] == b'\\' && j + 1 < bytes.len() {
|
|
1134
|
+
key_buf.push(bytes[j + 1] as char);
|
|
1135
|
+
j += 2;
|
|
1136
|
+
continue;
|
|
1137
|
+
}
|
|
1138
|
+
if bytes[j] == q {
|
|
1139
|
+
break;
|
|
1140
|
+
}
|
|
1141
|
+
if let Some(ch) = line[j..].chars().next() {
|
|
1142
|
+
key_buf.push(ch);
|
|
1143
|
+
j += ch.len_utf8();
|
|
1144
|
+
} else {
|
|
1145
|
+
break;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
if j >= bytes.len() {
|
|
1149
|
+
break;
|
|
1150
|
+
}
|
|
1151
|
+
let after = line[j + 1..].trim_start();
|
|
1152
|
+
if is_key_pos {
|
|
1153
|
+
if let Some(vpart) = after.strip_prefix(':') {
|
|
1154
|
+
let val = vpart.trim_start().to_ascii_lowercase();
|
|
1155
|
+
let key_low = key_buf.to_ascii_lowercase();
|
|
1156
|
+
if keys_low.contains(&key_low.as_str())
|
|
1157
|
+
&& val.starts_with("false")
|
|
1158
|
+
&& !val[5..]
|
|
1159
|
+
.chars()
|
|
1160
|
+
.next()
|
|
1161
|
+
.is_some_and(|c| c.is_ascii_alphanumeric() || c == '_')
|
|
1162
|
+
{
|
|
1163
|
+
return true;
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
i = j + 1;
|
|
1168
|
+
}
|
|
1169
|
+
false
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
pub fn find_mypy_section_lines(txt: &str) -> BTreeSet<usize> {
|
|
1173
|
+
let mut out = BTreeSet::new();
|
|
1174
|
+
let mut in_mypy = false;
|
|
1175
|
+
for (idx, raw) in txt.lines().enumerate() {
|
|
1176
|
+
let t = raw.trim();
|
|
1177
|
+
if t.starts_with('[') && t.ends_with(']') {
|
|
1178
|
+
let sec = t[1..t.len() - 1].trim().to_ascii_lowercase();
|
|
1179
|
+
in_mypy = sec == "mypy"
|
|
1180
|
+
|| sec.starts_with("mypy-")
|
|
1181
|
+
|| sec.starts_with("mypy.")
|
|
1182
|
+
|| sec.starts_with("tool.mypy");
|
|
1183
|
+
continue;
|
|
1184
|
+
}
|
|
1185
|
+
if in_mypy {
|
|
1186
|
+
out.insert(idx + 1);
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
out
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
fn has_tsconfig_weaken(line: &str) -> bool {
|
|
1193
|
+
has_json_key_false(
|
|
1194
|
+
line,
|
|
1195
|
+
&[
|
|
1196
|
+
"strict",
|
|
1197
|
+
"noimplicitany",
|
|
1198
|
+
"strictnullchecks",
|
|
1199
|
+
"strictfunctiontypes",
|
|
1200
|
+
"strictbindcallapply",
|
|
1201
|
+
"noimplicitreturns",
|
|
1202
|
+
"noemitonerror",
|
|
1203
|
+
"checkjs",
|
|
1204
|
+
],
|
|
1205
|
+
)
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
fn has_py_typecheck_weaken(trimmed_low: &str, in_mypy_ctx: bool) -> bool {
|
|
1209
|
+
let compact: String = trimmed_low.chars().filter(|c| !c.is_ascii_whitespace()).collect();
|
|
1210
|
+
(in_mypy_ctx && compact.starts_with("ignore_errors=true"))
|
|
1211
|
+
|| compact.starts_with("disallow_untyped_defs=false")
|
|
1212
|
+
|| compact.starts_with("check_untyped_defs=false")
|
|
1213
|
+
|| compact.contains("typecheckingmode=\"off\"")
|
|
1214
|
+
|| compact.contains("'typecheckingmode':'off'")
|
|
1215
|
+
|| compact.contains("\"typecheckingmode\":\"off\"")
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
fn has_rs_crate_allow(line: &str) -> bool {
|
|
1219
|
+
let compact: String = line.chars().filter(|c| !c.is_ascii_whitespace()).collect();
|
|
1220
|
+
compact.starts_with("#![allow(warnings)]")
|
|
1221
|
+
|| compact.starts_with("#![allow(unused)]")
|
|
1222
|
+
|| compact.starts_with("#![allow(dead_code)]")
|
|
1223
|
+
|| compact.starts_with("#![allow(clippy::all)]")
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
fn has_e2e_api_stub(line: &str) -> bool {
|
|
1227
|
+
let is_route = line.contains("page.route(") || line.contains("context.route(") || line.contains("cy.intercept(");
|
|
1228
|
+
is_route && (line.contains("/api/") || line.contains("/graphql") || line.contains("/trpc"))
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
fn has_inflated_visual_tolerance(line: &str) -> bool {
|
|
1232
|
+
if let Some(pos) = line.find("maxDiffPixelRatio") {
|
|
1233
|
+
if let Some(colon) = line[pos..].find(':') {
|
|
1234
|
+
if let Some(v) = parse_leading_f64(&line[pos + colon + 1..]) {
|
|
1235
|
+
if v > 0.10 {
|
|
1236
|
+
return true;
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
if let Some(pos) = line.find("maxDiffPixels") {
|
|
1242
|
+
if let Some(colon) = line[pos..].find(':') {
|
|
1243
|
+
if let Some(v) = parse_leading_f64(&line[pos + colon + 1..]) {
|
|
1244
|
+
if v >= 5000.0 {
|
|
1245
|
+
return true;
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
false
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
fn has_ml_eval_leakage(line: &str, is_train_or_scratch: bool) -> bool {
|
|
1254
|
+
for prefix in [".fit(", ".train_on_batch("] {
|
|
1255
|
+
if let Some(pos) = line.find(prefix) {
|
|
1256
|
+
let arg = line[pos + prefix.len()..].trim_start();
|
|
1257
|
+
if [
|
|
1258
|
+
"X_test", "x_test", "test_x", "test_dataset", "eval_dataset", "val_dataset",
|
|
1259
|
+
]
|
|
1260
|
+
.iter()
|
|
1261
|
+
.any(|bad| arg.starts_with(bad) && !arg[bad.len()..].chars().next().is_some_and(|c| c.is_ascii_alphanumeric() || c == '_'))
|
|
1262
|
+
{
|
|
1263
|
+
return true;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
let compact: String = line.chars().filter(|c| !c.is_ascii_whitespace()).collect();
|
|
1268
|
+
if compact.contains("train_dataset=test_dataset") || compact.contains("train_dataset=eval_dataset") {
|
|
1269
|
+
return true;
|
|
1270
|
+
}
|
|
1271
|
+
is_train_or_scratch
|
|
1272
|
+
&& line.contains("load_dataset(")
|
|
1273
|
+
&& (compact.contains("split=\"test\"") || compact.contains("split='test'"))
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
fn has_prod_integrity_bypass(line: &str, is_migration: bool) -> bool {
|
|
1277
|
+
let compact: String = line.chars().filter(|c| !c.is_ascii_whitespace()).collect();
|
|
1278
|
+
let low = compact.to_ascii_lowercase();
|
|
1279
|
+
if low.contains("node_tls_reject_unauthorized=0")
|
|
1280
|
+
|| low.contains("node_tls_reject_unauthorized=\"0\"")
|
|
1281
|
+
|| low.contains("node_tls_reject_unauthorized='0'")
|
|
1282
|
+
|| low.contains("insecureskipverify:true")
|
|
1283
|
+
|| low.contains("danger_accept_invalid_certs(true)")
|
|
1284
|
+
{
|
|
1285
|
+
return true;
|
|
1286
|
+
}
|
|
1287
|
+
if !is_migration
|
|
1288
|
+
&& (low.contains("pragmaforeign_keys=off")
|
|
1289
|
+
|| low.contains("pragmaforeign_keys=0")
|
|
1290
|
+
|| low.contains("setforeign_key_checks=0"))
|
|
1291
|
+
{
|
|
1292
|
+
return true;
|
|
1293
|
+
}
|
|
1294
|
+
for prefix in ["requests.", "httpx."] {
|
|
1295
|
+
for method in ["get(", "post(", "put(", "delete(", "patch(", "request(", "client(", "asyncclient("] {
|
|
1296
|
+
let call = format!("{}{}", prefix, method);
|
|
1297
|
+
if let Some(pos) = low.find(&call) {
|
|
1298
|
+
let inside = low[pos + call.len()..].split(')').next().unwrap_or("");
|
|
1299
|
+
if inside.contains("verify=false") {
|
|
1300
|
+
return true;
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
false
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
fn has_tautological_assert(line: &str) -> bool {
|
|
1309
|
+
let t = line.trim_start();
|
|
1310
|
+
let py_taut = t.strip_prefix("assert True").is_some_and(|r| {
|
|
1311
|
+
let rt = r.trim_start();
|
|
1312
|
+
rt.is_empty() || rt.starts_with('#') || rt.starts_with(';') || rt.starts_with(',')
|
|
1313
|
+
});
|
|
1314
|
+
if py_taut {
|
|
1315
|
+
return true;
|
|
1316
|
+
}
|
|
1317
|
+
let c: String = t.chars().filter(|ch| !ch.is_ascii_whitespace()).collect();
|
|
1318
|
+
c.contains("self.assertTrue(True)")
|
|
1319
|
+
|| ["True", "False", "0", "1"]
|
|
1320
|
+
.iter()
|
|
1321
|
+
.any(|v| c.contains(&format!("self.assertEqual({},{})", v, v)))
|
|
1322
|
+
|| ["true", "false", "0", "1"].iter().any(|v| {
|
|
1323
|
+
["toBe", "toStrictEqual", "toEqual"]
|
|
1324
|
+
.iter()
|
|
1325
|
+
.any(|m| c.contains(&format!("expect({}).{}({})", v, m, v)))
|
|
1326
|
+
})
|
|
1327
|
+
|| c.contains("assert!(true)")
|
|
1328
|
+
|| ["true", "false", "0", "1"]
|
|
1329
|
+
.iter()
|
|
1330
|
+
.any(|v| c.contains(&format!("assert_eq!({},{})", v, v)))
|
|
434
1331
|
}
|
|
435
1332
|
|
|
436
|
-
|
|
437
|
-
let
|
|
438
|
-
if
|
|
1333
|
+
fn is_real_assert_line(line: &str) -> bool {
|
|
1334
|
+
let t = line.trim_start();
|
|
1335
|
+
if t.starts_with('"') || t.starts_with('\'') || has_tautological_assert(t) {
|
|
439
1336
|
return false;
|
|
440
1337
|
}
|
|
441
|
-
|
|
442
|
-
"
|
|
443
|
-
"
|
|
444
|
-
"
|
|
445
|
-
"
|
|
446
|
-
"
|
|
447
|
-
"'ok'",
|
|
448
|
-
"\"verdict\"",
|
|
449
|
-
"'verdict'",
|
|
450
|
-
]
|
|
451
|
-
.iter()
|
|
452
|
-
.any(|k| low.contains(k));
|
|
453
|
-
let has_metric_key = [
|
|
454
|
-
"\"iou\"",
|
|
455
|
-
"'iou'",
|
|
456
|
-
"\"ssim\"",
|
|
457
|
-
"'ssim'",
|
|
458
|
-
"\"psnr\"",
|
|
459
|
-
"'psnr'",
|
|
460
|
-
"\"score\"",
|
|
461
|
-
"'score'",
|
|
462
|
-
"\"fidelity\"",
|
|
463
|
-
"'fidelity'",
|
|
464
|
-
]
|
|
465
|
-
.iter()
|
|
466
|
-
.any(|k| low.contains(k));
|
|
467
|
-
let has_pass_val = low.contains("true") || low.contains("\"pass\"") || low.contains("'pass'");
|
|
468
|
-
has_pass_key && has_metric_key && has_pass_val
|
|
1338
|
+
t.starts_with("assert ")
|
|
1339
|
+
|| line.contains("self.assert")
|
|
1340
|
+
|| line.contains("expect(")
|
|
1341
|
+
|| line.contains("assert_eq!(")
|
|
1342
|
+
|| line.contains("assert_ne!(")
|
|
1343
|
+
|| line.contains("assert!(")
|
|
469
1344
|
}
|
|
470
1345
|
|
|
471
|
-
fn match_ident_bound(low: &str, cand: &str, allow_assign: bool) -> Option<f64> {
|
|
1346
|
+
fn match_ident_bound(low: &str, cand: &str, upper: bool, allow_assign: bool) -> Option<f64> {
|
|
472
1347
|
let mut from = 0;
|
|
473
1348
|
while let Some(rel) = low[from..].find(cand) {
|
|
474
1349
|
let pos = from + rel;
|
|
@@ -484,11 +1359,11 @@ fn match_ident_bound(low: &str, cand: &str, allow_assign: bool) -> Option<f64> {
|
|
|
484
1359
|
continue;
|
|
485
1360
|
}
|
|
486
1361
|
let rest = low[end..].trim_start();
|
|
487
|
-
let ineq =
|
|
488
|
-
.strip_prefix("
|
|
489
|
-
|
|
490
|
-
.or_else(|| rest.strip_prefix('>'))
|
|
491
|
-
|
|
1362
|
+
let ineq = if upper {
|
|
1363
|
+
rest.strip_prefix("<=").or_else(|| rest.strip_prefix('<'))
|
|
1364
|
+
} else {
|
|
1365
|
+
rest.strip_prefix(">=").or_else(|| rest.strip_prefix('>'))
|
|
1366
|
+
};
|
|
492
1367
|
if let Some(vs) = ineq {
|
|
493
1368
|
if let Some(val) = parse_leading_f64(vs) {
|
|
494
1369
|
return Some(val);
|
|
@@ -507,7 +1382,6 @@ fn match_ident_bound(low: &str, cand: &str, allow_assign: bool) -> Option<f64> {
|
|
|
507
1382
|
}
|
|
508
1383
|
None
|
|
509
1384
|
}
|
|
510
|
-
|
|
511
1385
|
fn extract_metric_bounds(
|
|
512
1386
|
lines: &[String],
|
|
513
1387
|
upper: bool,
|
|
@@ -536,7 +1410,7 @@ fn extract_metric_bounds(
|
|
|
536
1410
|
}
|
|
537
1411
|
}
|
|
538
1412
|
}
|
|
539
|
-
if let Some(val) = match_ident_bound(&low, "tolerance", true) {
|
|
1413
|
+
if let Some(val) = match_ident_bound(&low, "tolerance", true, true) {
|
|
540
1414
|
map.insert("tolerance".to_string(), val);
|
|
541
1415
|
}
|
|
542
1416
|
}
|
|
@@ -573,13 +1447,13 @@ fn extract_metric_bounds(
|
|
|
573
1447
|
]
|
|
574
1448
|
};
|
|
575
1449
|
for qcand in qual_forms {
|
|
576
|
-
if let Some(val) = match_ident_bound(&low, &qcand, true) {
|
|
1450
|
+
if let Some(val) = match_ident_bound(&low, &qcand, upper, true) {
|
|
577
1451
|
map.insert(qcand, val);
|
|
578
1452
|
}
|
|
579
1453
|
}
|
|
580
1454
|
}
|
|
581
1455
|
for bm in bare_metrics {
|
|
582
|
-
if let Some(val) = match_ident_bound(&low, bm, is_test_or_gate) {
|
|
1456
|
+
if let Some(val) = match_ident_bound(&low, bm, upper, is_test_or_gate) {
|
|
583
1457
|
map.entry((*bm).to_string()).or_insert(val);
|
|
584
1458
|
}
|
|
585
1459
|
}
|
|
@@ -591,14 +1465,35 @@ pub fn scan_hunk_weakening(
|
|
|
591
1465
|
rel: &str,
|
|
592
1466
|
hunks: &[(Vec<String>, Vec<(usize, String)>)],
|
|
593
1467
|
is_test_or_gate: bool,
|
|
1468
|
+
is_test: bool,
|
|
594
1469
|
out: &mut Vec<RewardFinding>,
|
|
595
1470
|
) {
|
|
596
1471
|
for (rem, add) in hunks {
|
|
597
|
-
if rem.is_empty()
|
|
1472
|
+
if rem.is_empty() {
|
|
598
1473
|
continue;
|
|
599
1474
|
}
|
|
600
|
-
let ln = add
|
|
1475
|
+
let ln = add.first().map_or(1, |(l, _)| *l);
|
|
601
1476
|
let add_only: Vec<String> = add.iter().map(|(_, s)| s.clone()).collect();
|
|
1477
|
+
if is_test {
|
|
1478
|
+
let rem_asserts = rem.iter().filter(|r| is_real_assert_line(r)).count();
|
|
1479
|
+
let add_asserts = add_only.iter().filter(|a| is_real_assert_line(a)).count();
|
|
1480
|
+
if rem_asserts >= 2 && add_asserts == 0 {
|
|
1481
|
+
out.push(RewardFinding {
|
|
1482
|
+
severity: "P0",
|
|
1483
|
+
rule: "reward-hack-assertions-deleted",
|
|
1484
|
+
file: rel.to_string(),
|
|
1485
|
+
line: ln,
|
|
1486
|
+
message: format!(
|
|
1487
|
+
"Test hunk deleted {} behavioral assertions and left 0 assertions.",
|
|
1488
|
+
rem_asserts
|
|
1489
|
+
),
|
|
1490
|
+
fix: "Keep behavioral assertions intact and fix the implementation under test.",
|
|
1491
|
+
});
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
if add.is_empty() {
|
|
1495
|
+
continue;
|
|
1496
|
+
}
|
|
602
1497
|
let old_low = extract_metric_bounds(rem, false, is_test_or_gate);
|
|
603
1498
|
let new_low = extract_metric_bounds(&add_only, false, is_test_or_gate);
|
|
604
1499
|
for (k, old_v) in &old_low {
|
|
@@ -650,7 +1545,7 @@ pub fn diff_file_hunks(
|
|
|
650
1545
|
let Ok(meta) = fs::symlink_metadata(&full) else {
|
|
651
1546
|
return (Vec::new(), Vec::new());
|
|
652
1547
|
};
|
|
653
|
-
if meta.file_type().is_symlink() || !meta.is_file() || meta.len() >
|
|
1548
|
+
if meta.file_type().is_symlink() || !meta.is_file() || meta.len() > 16 * 1024 * 1024 {
|
|
654
1549
|
return (Vec::new(), Vec::new());
|
|
655
1550
|
}
|
|
656
1551
|
let has_head = git(root, &["rev-parse", "--verify", "HEAD"])
|
|
@@ -714,6 +1609,497 @@ pub fn diff_file_hunks(
|
|
|
714
1609
|
(added, hunks)
|
|
715
1610
|
}
|
|
716
1611
|
|
|
1612
|
+
type EvalToken<'a> = (&'a str, usize);
|
|
1613
|
+
type EvalStatement<'a> = (usize, Vec<EvalToken<'a>>);
|
|
1614
|
+
|
|
1615
|
+
const COMPARISON_DUNDERS: &[&str] = &["__eq__", "__ne__", "__lt__", "__le__", "__gt__", "__ge__"];
|
|
1616
|
+
const PYTEST_OVERRIDE_HOOKS: &[&str] = &["pytest_runtest_makereport", "pytest_collection_modifyitems"];
|
|
1617
|
+
|
|
1618
|
+
fn evaluator_statements<'a>(python: bool, lines: &[(usize, &'a str)]) -> Vec<EvalStatement<'a>> {
|
|
1619
|
+
let mut statements = Vec::new();
|
|
1620
|
+
let mut delimiter = "";
|
|
1621
|
+
let mut depth = 0;
|
|
1622
|
+
let mut indent = 0;
|
|
1623
|
+
let mut tokens = Vec::new();
|
|
1624
|
+
let mut previous = 0;
|
|
1625
|
+
for &(ln, raw) in lines {
|
|
1626
|
+
if ln != previous + 1 {
|
|
1627
|
+
if !tokens.is_empty() {
|
|
1628
|
+
statements.push((indent, std::mem::take(&mut tokens)));
|
|
1629
|
+
}
|
|
1630
|
+
delimiter = "";
|
|
1631
|
+
depth = 0;
|
|
1632
|
+
}
|
|
1633
|
+
previous = ln;
|
|
1634
|
+
if tokens.is_empty() {
|
|
1635
|
+
indent = 0;
|
|
1636
|
+
for ch in raw.bytes() {
|
|
1637
|
+
match ch {
|
|
1638
|
+
b' ' => indent += 1,
|
|
1639
|
+
b'\t' => indent = (indent / 8 + 1) * 8,
|
|
1640
|
+
12 => indent = 0,
|
|
1641
|
+
_ => break,
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
let mut i = 0;
|
|
1646
|
+
while i < raw.len() {
|
|
1647
|
+
if !delimiter.is_empty() {
|
|
1648
|
+
let end = if delimiter == "*/" {
|
|
1649
|
+
raw[i..].find("*/").map(|offset| i + offset + 2)
|
|
1650
|
+
} else {
|
|
1651
|
+
quoted_end(raw, i, delimiter)
|
|
1652
|
+
};
|
|
1653
|
+
let Some(end) = end else { break };
|
|
1654
|
+
i = end;
|
|
1655
|
+
delimiter = "";
|
|
1656
|
+
continue;
|
|
1657
|
+
}
|
|
1658
|
+
let rest = &raw[i..];
|
|
1659
|
+
let Some(ch) = rest.chars().next() else { break };
|
|
1660
|
+
if ch.is_whitespace() {
|
|
1661
|
+
i += ch.len_utf8();
|
|
1662
|
+
continue;
|
|
1663
|
+
}
|
|
1664
|
+
if (python && ch == '#') || (!python && rest.starts_with("//")) {
|
|
1665
|
+
break;
|
|
1666
|
+
}
|
|
1667
|
+
if !python && rest.starts_with("/*") {
|
|
1668
|
+
i += 2;
|
|
1669
|
+
delimiter = "*/";
|
|
1670
|
+
continue;
|
|
1671
|
+
}
|
|
1672
|
+
if matches!(ch, '\'' | '"') || (!python && ch == '`') {
|
|
1673
|
+
let quote = if python && (rest.starts_with("'''") || rest.starts_with("\"\"\"")) {
|
|
1674
|
+
&rest[..3]
|
|
1675
|
+
} else {
|
|
1676
|
+
&rest[..1]
|
|
1677
|
+
};
|
|
1678
|
+
if let Some(end) = quoted_end(raw, i + quote.len(), quote) {
|
|
1679
|
+
tokens.push((&raw[i..end], ln));
|
|
1680
|
+
i = end;
|
|
1681
|
+
continue;
|
|
1682
|
+
}
|
|
1683
|
+
tokens.push(("''", ln));
|
|
1684
|
+
if quote.len() == 3 || quote == "`" || raw.ends_with('\\') {
|
|
1685
|
+
delimiter = quote;
|
|
1686
|
+
}
|
|
1687
|
+
break;
|
|
1688
|
+
}
|
|
1689
|
+
let width = if is_ident_char(ch) {
|
|
1690
|
+
rest.find(|c| !is_ident_char(c)).unwrap_or(rest.len())
|
|
1691
|
+
} else if rest.starts_with("==") {
|
|
1692
|
+
2
|
|
1693
|
+
} else {
|
|
1694
|
+
ch.len_utf8()
|
|
1695
|
+
};
|
|
1696
|
+
let value = &rest[..width];
|
|
1697
|
+
if python {
|
|
1698
|
+
match value {
|
|
1699
|
+
"(" | "[" | "{" => depth += 1,
|
|
1700
|
+
")" | "]" | "}" => depth -= 1,
|
|
1701
|
+
_ => {}
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
tokens.push((value, ln));
|
|
1705
|
+
i += width;
|
|
1706
|
+
}
|
|
1707
|
+
if tokens.last().is_some_and(|t| t.0 == "\\") {
|
|
1708
|
+
tokens.pop();
|
|
1709
|
+
} else if !tokens.is_empty() && (!python || depth <= 0) {
|
|
1710
|
+
statements.push((indent, std::mem::take(&mut tokens)));
|
|
1711
|
+
depth = 0;
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
if !tokens.is_empty() {
|
|
1715
|
+
statements.push((indent, tokens));
|
|
1716
|
+
}
|
|
1717
|
+
statements
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
fn strip_wrapping_parens<'s, 'a>(mut words: &'s [&'a str]) -> &'s [&'a str] {
|
|
1721
|
+
while words.len() > 1 && words.first() == Some(&"(") && words.last() == Some(&")") {
|
|
1722
|
+
let mut depth = 0;
|
|
1723
|
+
let close = words.iter().position(|w| {
|
|
1724
|
+
depth += i32::from(*w == "(") - i32::from(*w == ")");
|
|
1725
|
+
depth == 0
|
|
1726
|
+
});
|
|
1727
|
+
if close != Some(words.len() - 1) {
|
|
1728
|
+
break;
|
|
1729
|
+
}
|
|
1730
|
+
words = &words[1..words.len() - 1];
|
|
1731
|
+
}
|
|
1732
|
+
words
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
fn literal_bool(words: &[&str]) -> Option<bool> {
|
|
1736
|
+
let end = words.iter().position(|w| *w == ";").unwrap_or(words.len());
|
|
1737
|
+
match strip_wrapping_parens(&words[..end]) {
|
|
1738
|
+
["True"] => Some(true),
|
|
1739
|
+
["False"] => Some(false),
|
|
1740
|
+
_ => None,
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
fn suite_start(words: &[&str]) -> usize {
|
|
1745
|
+
let mut depth = 0;
|
|
1746
|
+
for (i, word) in words.iter().enumerate() {
|
|
1747
|
+
match *word {
|
|
1748
|
+
":" if depth == 0 => return i + 1,
|
|
1749
|
+
"(" | "[" | "{" => depth += 1,
|
|
1750
|
+
")" | "]" | "}" => depth -= 1,
|
|
1751
|
+
_ => {}
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
0
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
fn pytest_args(line: &str) -> impl Iterator<Item = &str> {
|
|
1758
|
+
line.split(|c: char| c.is_whitespace() || "'\"`\\=,;[](){}".contains(c))
|
|
1759
|
+
.filter(|s| !s.is_empty())
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
fn pytest_option_width(arg: &str, next: &str) -> usize {
|
|
1763
|
+
if matches!(arg, "--deselect" | "--continue-on-collection-errors") || arg.starts_with("-pno:") {
|
|
1764
|
+
1
|
|
1765
|
+
} else if (arg == "-p" && next.starts_with("no:"))
|
|
1766
|
+
|| (arg == "-k" && next == "not")
|
|
1767
|
+
|| (arg == "--assert" && next == "plain")
|
|
1768
|
+
|| (matches!(arg, "xfail_strict" | "strict_xfail") && next.eq_ignore_ascii_case("false"))
|
|
1769
|
+
{
|
|
1770
|
+
2
|
|
1771
|
+
} else {
|
|
1772
|
+
0
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
fn scan_pytest_options<'a>(
|
|
1777
|
+
tokens: impl IntoIterator<Item = EvalToken<'a>>,
|
|
1778
|
+
mut emit: impl FnMut(&[EvalToken<'a>]),
|
|
1779
|
+
) {
|
|
1780
|
+
let mut previous = ("", 0);
|
|
1781
|
+
for token in tokens {
|
|
1782
|
+
if pytest_option_width(previous.0, token.0) == 2 {
|
|
1783
|
+
emit(&[previous, token]);
|
|
1784
|
+
}
|
|
1785
|
+
if pytest_option_width(token.0, "") == 1 {
|
|
1786
|
+
emit(&[token]);
|
|
1787
|
+
}
|
|
1788
|
+
previous = token;
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
|
|
1792
|
+
fn pytest_config_arguments<'a>(
|
|
1793
|
+
ext: &str,
|
|
1794
|
+
lines: &[(usize, &'a str)],
|
|
1795
|
+
pytest_config: bool,
|
|
1796
|
+
command_config: bool,
|
|
1797
|
+
) -> Vec<EvalToken<'a>> {
|
|
1798
|
+
let mut opts_indent = None;
|
|
1799
|
+
let mut opts_close = "";
|
|
1800
|
+
let mut continuation = false;
|
|
1801
|
+
let mut previous = 0;
|
|
1802
|
+
let mut tokens = Vec::new();
|
|
1803
|
+
for &(ln, raw) in lines {
|
|
1804
|
+
if ln != previous + 1 {
|
|
1805
|
+
opts_indent = None;
|
|
1806
|
+
opts_close = "";
|
|
1807
|
+
continuation = false;
|
|
1808
|
+
}
|
|
1809
|
+
previous = ln;
|
|
1810
|
+
if is_scanner_or_comment(ext, raw) {
|
|
1811
|
+
continue;
|
|
1812
|
+
}
|
|
1813
|
+
let line = strip_trailing_comment(ext, raw);
|
|
1814
|
+
let stripped = line.trim();
|
|
1815
|
+
let (key, value) = stripped.split_once('=').unwrap_or((stripped, ""));
|
|
1816
|
+
let (key, value) = (key.trim(), value.trim_start());
|
|
1817
|
+
let indent = line.len() - line.trim_start().len();
|
|
1818
|
+
let in_addopts = !opts_close.is_empty() || opts_indent.is_some_and(|n| indent > n);
|
|
1819
|
+
if !opts_close.is_empty() && stripped.contains(opts_close) {
|
|
1820
|
+
opts_close = "";
|
|
1821
|
+
}
|
|
1822
|
+
if !in_addopts {
|
|
1823
|
+
opts_indent = None;
|
|
1824
|
+
}
|
|
1825
|
+
let command = command_config && pytest_args(line)
|
|
1826
|
+
.any(|w| w == "pytest" || w.trim_end_matches(':') == "PYTEST_ADDOPTS");
|
|
1827
|
+
let setting = pytest_config && matches!(key, "addopts" | "xfail_strict" | "strict_xfail");
|
|
1828
|
+
if command || setting {
|
|
1829
|
+
tokens.push(("", 0));
|
|
1830
|
+
}
|
|
1831
|
+
if command || setting || continuation || in_addopts {
|
|
1832
|
+
tokens.extend(pytest_args(line).map(|word| (word, ln)));
|
|
1833
|
+
}
|
|
1834
|
+
if pytest_config && key == "addopts" {
|
|
1835
|
+
opts_indent = Some(indent);
|
|
1836
|
+
for (opener, closer) in [("[", "]"), ("\"\"\"", "\"\"\""), ("'''", "'''")] {
|
|
1837
|
+
if value.strip_prefix(opener).is_some_and(|v| !v.contains(closer)) {
|
|
1838
|
+
opts_close = closer;
|
|
1839
|
+
break;
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
continuation = (command || continuation) && line.trim_end().ends_with('\\');
|
|
1844
|
+
if !continuation && opts_close.is_empty() && opts_indent.is_none() {
|
|
1845
|
+
tokens.push(("", 0));
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
tokens
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
fn scan_evaluator_bypasses(
|
|
1852
|
+
rel: &str, norm_rel: &str, ext: &str, added: &[(usize, String)],
|
|
1853
|
+
full_text: Option<&str>, in_test: bool, out: &mut Vec<RewardFinding>,
|
|
1854
|
+
) {
|
|
1855
|
+
let low = norm_rel.to_ascii_lowercase();
|
|
1856
|
+
let path: Vec<_> = low.split('/').collect();
|
|
1857
|
+
let fname = path.last().copied().unwrap_or_default();
|
|
1858
|
+
let python = ext == "py";
|
|
1859
|
+
let js = matches!(ext, "js" | "mjs" | "cjs" | "ts" | "tsx" | "jsx" | "mts" | "cts");
|
|
1860
|
+
let pytest_config = matches!(fname, "pytest.ini" | ".pytest.ini" | "pytest.toml" | ".pytest.toml" | "pyproject.toml" | "setup.cfg" | "tox.ini");
|
|
1861
|
+
let command_config = matches!(ext, "sh" | "ps1" | "cmd" | "bat" | "yaml" | "yml")
|
|
1862
|
+
|| matches!(fname, "makefile" | "package.json" | "tox.ini");
|
|
1863
|
+
let runner_config = fname == "package.json" || ["jest.config.", "vitest.config.", "vite.config."]
|
|
1864
|
+
.iter().any(|prefix| fname.starts_with(prefix));
|
|
1865
|
+
if added.is_empty() || !(python || js || pytest_config || command_config || runner_config) {
|
|
1866
|
+
return;
|
|
1867
|
+
}
|
|
1868
|
+
let lines: Vec<_> = if let Some(text) = full_text.filter(|s| !s.is_empty()) {
|
|
1869
|
+
text.lines().enumerate().map(|(i, line)| (i + 1, line)).collect()
|
|
1870
|
+
} else {
|
|
1871
|
+
let mut lines: Vec<_> = added.iter().map(|(ln, line)| (*ln, line.as_str())).collect();
|
|
1872
|
+
lines.sort_unstable_by_key(|t| t.0);
|
|
1873
|
+
lines
|
|
1874
|
+
};
|
|
1875
|
+
let added_lines: BTreeSet<_> = added.iter().map(|t| t.0).collect();
|
|
1876
|
+
let mut hits = BTreeSet::new();
|
|
1877
|
+
let mut emit = |rule, tokens: &[EvalToken<'_>]| {
|
|
1878
|
+
let ln = tokens.iter().find_map(|(_, ln)| added_lines.contains(ln).then_some(*ln));
|
|
1879
|
+
if let Some(ln) = ln {
|
|
1880
|
+
hits.insert((ln, rule));
|
|
1881
|
+
}
|
|
1882
|
+
ln.is_some()
|
|
1883
|
+
};
|
|
1884
|
+
|
|
1885
|
+
let conftest = fname == "conftest.py";
|
|
1886
|
+
let in_test = in_test || conftest;
|
|
1887
|
+
let entrypoint = !in_test && (
|
|
1888
|
+
fname == "__main__.py" || matches!(path[0], "bin" | "cmd")
|
|
1889
|
+
|| path.len() > 1 && matches!(path[path.len() - 2], "bin" | "cli")
|
|
1890
|
+
|| matches!(fname.split('.').next(), Some("cli" | "__main__")) || fname.contains(".cli.")
|
|
1891
|
+
|| (fname == "main.py" && path.len() == 1)
|
|
1892
|
+
|| lines.first().is_some_and(|(ln, s)| *ln == 1 && s.starts_with("#!") &&
|
|
1893
|
+
(if python { &["python"][..] } else { &["node", "bun", "deno"][..] })
|
|
1894
|
+
.iter().any(|word| s.contains(*word)))
|
|
1895
|
+
);
|
|
1896
|
+
let source_terms: &[&str] = if python {
|
|
1897
|
+
&["__", "exit", "outcome", "marker", "pytest", "TestResult", "PYTEST_ADDOPTS"]
|
|
1898
|
+
} else {
|
|
1899
|
+
&["exit", "passWithNoTests", "bail"]
|
|
1900
|
+
};
|
|
1901
|
+
if (python || js || runner_config) && full_text.is_none_or(|text| {
|
|
1902
|
+
text.is_empty() || source_terms.iter().any(|term| text.contains(*term))
|
|
1903
|
+
}) {
|
|
1904
|
+
let mut statements = evaluator_statements(python, &lines);
|
|
1905
|
+
let mut main_indent = None;
|
|
1906
|
+
let mut loops = Vec::new();
|
|
1907
|
+
let plugin = conftest || fname.contains("pytest") || fname.contains("plugin")
|
|
1908
|
+
|| python && statements.iter().any(|(_, tokens)| {
|
|
1909
|
+
matches!(tokens[0].0, "import" | "from" | "def" | "async")
|
|
1910
|
+
&& tokens.iter().any(|(w, _)| PYTEST_OVERRIDE_HOOKS.contains(w) || matches!(*w, "pytest" | "_pytest"))
|
|
1911
|
+
});
|
|
1912
|
+
let mut collections = None;
|
|
1913
|
+
if js || runner_config {
|
|
1914
|
+
statements = vec![(0, statements.into_iter().flat_map(|(_, tokens)| tokens).collect())];
|
|
1915
|
+
}
|
|
1916
|
+
for (idx, (indent, tokens)) in statements.iter().enumerate() {
|
|
1917
|
+
let words: Vec<_> = tokens.iter().map(|t| t.0).collect();
|
|
1918
|
+
let suite = if python { suite_start(&words) } else { 0 };
|
|
1919
|
+
let def_at = usize::from(words.starts_with(&["async", "def"]));
|
|
1920
|
+
let name = if words.get(def_at) == Some(&"def") {
|
|
1921
|
+
words.get(def_at + 1).copied().unwrap_or_default()
|
|
1922
|
+
} else {
|
|
1923
|
+
""
|
|
1924
|
+
};
|
|
1925
|
+
if main_indent.is_some_and(|n| *indent <= n) {
|
|
1926
|
+
main_indent = None;
|
|
1927
|
+
}
|
|
1928
|
+
if collections.is_some_and(|n| *indent <= n) {
|
|
1929
|
+
collections = None;
|
|
1930
|
+
}
|
|
1931
|
+
while loops.last().is_some_and(|n| indent <= n) {
|
|
1932
|
+
loops.pop();
|
|
1933
|
+
}
|
|
1934
|
+
let guard = python && suite > 0 && words[0] == "if" && !in_test && matches!(
|
|
1935
|
+
strip_wrapping_parens(&words[1..suite - 1]),
|
|
1936
|
+
["__name__", "==", "'__main__'" | "\"__main__\""]
|
|
1937
|
+
| ["'__main__'" | "\"__main__\"", "==", "__name__"]
|
|
1938
|
+
);
|
|
1939
|
+
if guard && suite == words.len() {
|
|
1940
|
+
main_indent = Some(*indent);
|
|
1941
|
+
}
|
|
1942
|
+
if python && suite > 0 && suite == words.len() {
|
|
1943
|
+
if words[0] == "for" || words.starts_with(&["async", "for"]) {
|
|
1944
|
+
loops.push(*indent);
|
|
1945
|
+
}
|
|
1946
|
+
if name == "pytest_collection_modifyitems" {
|
|
1947
|
+
collections = Some(*indent);
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
if python && !in_test && COMPARISON_DUNDERS.contains(&name) && suite > 0 {
|
|
1951
|
+
let inline = &words[suite..];
|
|
1952
|
+
if let Some(body) = inline.strip_prefix(&["return"]) {
|
|
1953
|
+
if literal_bool(body).is_some() {
|
|
1954
|
+
emit("reward-hack-constant-comparison", tokens);
|
|
1955
|
+
}
|
|
1956
|
+
} else if inline.is_empty() {
|
|
1957
|
+
let body = &statements[idx + 1..];
|
|
1958
|
+
if let Some((body_indent, _)) = body.first().filter(|(n, _)| n > indent) {
|
|
1959
|
+
let mut prior = None;
|
|
1960
|
+
for (inner_indent, inner) in body {
|
|
1961
|
+
if inner_indent <= indent || inner.iter().any(|t| matches!(t.0, "raise" | "yield" | "def")) {
|
|
1962
|
+
break;
|
|
1963
|
+
}
|
|
1964
|
+
if let Some(at) = inner.iter().position(|t| t.0 == "return") {
|
|
1965
|
+
let expr: Vec<_> = inner[at + 1..].iter().map(|t| t.0).collect();
|
|
1966
|
+
let Some(value) = literal_bool(&expr) else { break };
|
|
1967
|
+
if prior.is_some_and(|p| p != value) {
|
|
1968
|
+
break;
|
|
1969
|
+
}
|
|
1970
|
+
prior = Some(value);
|
|
1971
|
+
if at == 0 && inner_indent == body_indent {
|
|
1972
|
+
if !emit("reward-hack-constant-comparison", &tokens[..suite]) {
|
|
1973
|
+
emit("reward-hack-constant-comparison", inner);
|
|
1974
|
+
}
|
|
1975
|
+
break;
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
if python && (
|
|
1983
|
+
(words.contains(&"\"PYTEST_ADDOPTS\"") || words.contains(&"'PYTEST_ADDOPTS'")) && words.contains(&"=")
|
|
1984
|
+
|| words.windows(4).any(|w| w == ["pytest", ".", "main", "("])
|
|
1985
|
+
|| words.contains(&"subprocess") && words.iter().any(|w| matches!(*w, "'pytest'" | "\"pytest\""))
|
|
1986
|
+
) {
|
|
1987
|
+
let args = tokens.iter().flat_map(|&(w, ln)| pytest_args(w).map(move |part| (part, ln)));
|
|
1988
|
+
scan_pytest_options(args, |span| { emit("reward-hack-pytest-config-bypass", span); });
|
|
1989
|
+
}
|
|
1990
|
+
for (i, w) in words.iter().copied().enumerate() {
|
|
1991
|
+
let tail = &words[i + 1..];
|
|
1992
|
+
if python && !in_test && COMPARISON_DUNDERS.contains(&w) && tail.starts_with(&["=", "lambda"]) {
|
|
1993
|
+
let colon = suite_start(&words[i + 2..]);
|
|
1994
|
+
if colon > 0 && literal_bool(&words[i + 2 + colon..]).is_some() {
|
|
1995
|
+
emit("reward-hack-constant-comparison", &tokens[i..]);
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
if python && PYTEST_OVERRIDE_HOOKS.contains(&w) && (w == name || tail.starts_with(&["="])) {
|
|
1999
|
+
emit("reward-hack-pytest-hook-override", if w == name {
|
|
2000
|
+
tokens
|
|
2001
|
+
} else {
|
|
2002
|
+
&tokens[i..(i + 3).min(tokens.len())]
|
|
2003
|
+
});
|
|
2004
|
+
}
|
|
2005
|
+
let attribute = i > 0 && words[i - 1] == ".";
|
|
2006
|
+
if python && w == "outcome" && attribute
|
|
2007
|
+
&& matches!(tail, ["=", "'passed'" | "\"passed\"", ..]) && (plugin || collections.is_some())
|
|
2008
|
+
{
|
|
2009
|
+
emit("reward-hack-test-outcome-rewrite", &tokens[i.saturating_sub(2)..i + 3]);
|
|
2010
|
+
}
|
|
2011
|
+
if python && w == "add_marker" && attribute && tail.starts_with(&["("]) {
|
|
2012
|
+
let mut marker = i + 2;
|
|
2013
|
+
if matches!(&words[marker..], ["pytest" | "_pytest", ".", "mark", ".", ..]) {
|
|
2014
|
+
marker += 4;
|
|
2015
|
+
} else if words[marker..].starts_with(&["mark", "."]) {
|
|
2016
|
+
marker += 2;
|
|
2017
|
+
}
|
|
2018
|
+
if matches!(words.get(marker), Some(&("skip" | "xfail" | "'skip'" | "\"skip\"" | "'xfail'" | "\"xfail\"")))
|
|
2019
|
+
&& (!loops.is_empty() || collections.is_some() || name == "pytest_collection_modifyitems"
|
|
2020
|
+
|| words[marker + 1..].contains(&"for") || (suite > 0 && words[0] == "for"))
|
|
2021
|
+
{
|
|
2022
|
+
emit("reward-hack-bulk-test-marker", &tokens[i - 1..marker + 1]);
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
if python && i >= 2 && tail.starts_with(&["="]) && attribute
|
|
2026
|
+
&& ((w == "fail" && words[i - 2] == "pytest")
|
|
2027
|
+
|| (matches!(w, "addFailure" | "addError") && words[i - 2] == "TestResult"))
|
|
2028
|
+
{
|
|
2029
|
+
emit("reward-hack-test-outcome-rewrite", &tokens[i - 2..(i + 3).min(tokens.len())]);
|
|
2030
|
+
}
|
|
2031
|
+
if python && w == "setattr" && tail.starts_with(&["("]) {
|
|
2032
|
+
let target = &tail[1..];
|
|
2033
|
+
if matches!(target,
|
|
2034
|
+
["'pytest.fail'" | "\"pytest.fail\"" | "'unittest.TestResult.addFailure'" | "\"unittest.TestResult.addFailure\""
|
|
2035
|
+
| "'unittest.TestResult.addError'" | "\"unittest.TestResult.addError\"", ",", ..]
|
|
2036
|
+
| ["pytest", ",", "'fail'" | "\"fail\"", ..]
|
|
2037
|
+
| ["unittest", ".", "TestResult", ",", "'addFailure'" | "\"addFailure\"" | "'addError'" | "\"addError\"", ..]
|
|
2038
|
+
| ["TestResult", ",", "'addFailure'" | "\"addFailure\"" | "'addError'" | "\"addError\"", ..]
|
|
2039
|
+
) {
|
|
2040
|
+
emit("reward-hack-test-outcome-rewrite", &tokens[i..(i + 8).min(tokens.len())]);
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
if matches!(w, "exit" | "_exit") && tail.starts_with(&["("])
|
|
2044
|
+
&& !entrypoint && main_indent.is_none() && !guard
|
|
2045
|
+
{
|
|
2046
|
+
let start = if attribute {
|
|
2047
|
+
let owner = if i >= 2 && (i < 3 || words[i - 3] != ".") { words[i - 2] } else { "" };
|
|
2048
|
+
if !matches!((python, owner, w), (true, "os", "_exit") | (true, "sys", "exit") | (false, "process", "exit")) {
|
|
2049
|
+
continue;
|
|
2050
|
+
}
|
|
2051
|
+
i - 2
|
|
2052
|
+
} else if !python || w != "exit" || (name == "exit" && i == def_at + 1) {
|
|
2053
|
+
continue;
|
|
2054
|
+
} else {
|
|
2055
|
+
i
|
|
2056
|
+
};
|
|
2057
|
+
let value = i + 2 + words[i + 2..].iter().take_while(|w| **w == "(").count();
|
|
2058
|
+
let closings = value - i - 2;
|
|
2059
|
+
if words.get(value) == Some(&"0")
|
|
2060
|
+
&& words.get(value + 1..value + 1 + closings).is_some_and(|s| s.iter().all(|w| *w == ")"))
|
|
2061
|
+
{
|
|
2062
|
+
let mut close = value + 1 + closings;
|
|
2063
|
+
close += usize::from(words.get(close) == Some(&","));
|
|
2064
|
+
if words.get(close) == Some(&")") {
|
|
2065
|
+
emit("reward-hack-zero-exit", &tokens[start..close + 1]);
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
if runner_config {
|
|
2070
|
+
let wanted = match w.trim_matches(['\'', '"']) {
|
|
2071
|
+
"passWithNoTests" => "true",
|
|
2072
|
+
"bail" => "0",
|
|
2073
|
+
_ => continue,
|
|
2074
|
+
};
|
|
2075
|
+
if tail.starts_with(&[":", wanted]) && matches!(tail.get(2), None | Some(&("," | "}" | ";"))) {
|
|
2076
|
+
emit("reward-hack-js-runner-bypass", &tokens[i..i + 3]);
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
if pytest_config || command_config {
|
|
2083
|
+
let config_ext = if fname == "makefile" { "sh" } else { ext };
|
|
2084
|
+
let args = pytest_config_arguments(config_ext, &lines, pytest_config, command_config);
|
|
2085
|
+
scan_pytest_options(args, |span| { emit("reward-hack-pytest-config-bypass", span); });
|
|
2086
|
+
}
|
|
2087
|
+
for (line, rule) in hits {
|
|
2088
|
+
let (severity, message, fix) = match rule {
|
|
2089
|
+
"reward-hack-constant-comparison" => ("P1", "Comparison method returns a constant boolean instead of comparing operands.", "Compare the operands and return NotImplemented for unsupported types."),
|
|
2090
|
+
"reward-hack-zero-exit" => ("P0", "A success exit in library or test code can terminate verification before failures are reported.", "Return to the caller or propagate the error; exit only at the CLI boundary."),
|
|
2091
|
+
"reward-hack-pytest-hook-override" => ("P1", "A pytest plugin overrides test reporting or collection.", "Keep collection and reporting intact; do not rewrite evaluator outcomes."),
|
|
2092
|
+
"reward-hack-test-outcome-rewrite" => ("P0", "Evaluator outcomes can be forced to pass or their failure handlers replaced.", "Preserve the evaluator's original outcome and failure handlers."),
|
|
2093
|
+
"reward-hack-bulk-test-marker" => ("P1", "A loop or collection hook applies skip/xfail to collected tests.", "Run the collected tests and fix their failures."),
|
|
2094
|
+
"reward-hack-pytest-config-bypass" => ("P1", "Pytest options suppress collection, plugin checks, assertion rewriting, or strict xfails.", "Keep the evaluator's collection, plugins, assertion rewriting, and strict xfail checks intact."),
|
|
2095
|
+
"reward-hack-js-runner-bypass" => ("P1", "Test runner allows an empty test run or explicitly disables fail-fast with bail: 0.", "Require a nonempty test run and retain the configured failure policy."),
|
|
2096
|
+
_ => unreachable!(),
|
|
2097
|
+
};
|
|
2098
|
+
out.push(RewardFinding { severity, rule, file: rel.to_owned(), line, message: message.to_owned(), fix });
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
|
|
2102
|
+
#[cfg(test)]
|
|
717
2103
|
pub fn scan_file_reward_hacks(
|
|
718
2104
|
rel: &str,
|
|
719
2105
|
added: &[(usize, String)],
|
|
@@ -722,6 +2108,20 @@ pub fn scan_file_reward_hacks(
|
|
|
722
2108
|
include_primitives: bool,
|
|
723
2109
|
rs_cfg_test_line: Option<usize>,
|
|
724
2110
|
out: &mut Vec<RewardFinding>,
|
|
2111
|
+
) {
|
|
2112
|
+
scan_file_reward_hacks_full(rel, added, hunks, allow_primitives, include_primitives, rs_cfg_test_line, None, None, out);
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2115
|
+
pub fn scan_file_reward_hacks_full(
|
|
2116
|
+
rel: &str,
|
|
2117
|
+
added: &[(usize, String)],
|
|
2118
|
+
hunks: &[(Vec<String>, Vec<(usize, String)>)],
|
|
2119
|
+
allow_primitives: bool,
|
|
2120
|
+
include_primitives: bool,
|
|
2121
|
+
rs_cfg_test_line: Option<usize>,
|
|
2122
|
+
mypy_lines: Option<&BTreeSet<usize>>,
|
|
2123
|
+
full_text: Option<&str>,
|
|
2124
|
+
out: &mut Vec<RewardFinding>,
|
|
725
2125
|
) {
|
|
726
2126
|
let norm_rel = rel.replace('\\', "/");
|
|
727
2127
|
let ext = Path::new(&norm_rel)
|
|
@@ -731,42 +2131,253 @@ pub fn scan_file_reward_hacks(
|
|
|
731
2131
|
.unwrap_or_default();
|
|
732
2132
|
if ext == "md"
|
|
733
2133
|
|| norm_rel.ends_with("assets/reward-guard/reward_guard.py")
|
|
2134
|
+
|| norm_rel.ends_with("assets/reward-guard/test_reward_guard.py")
|
|
734
2135
|
|| norm_rel.ends_with("native/dmb-gate/src/reward.rs")
|
|
2136
|
+
|| norm_rel.ends_with("native/dmb-gate/src/main.rs")
|
|
735
2137
|
|| norm_rel.ends_with("scripts/antigravity-guard.mjs")
|
|
736
2138
|
|| norm_rel.ends_with("assets/contain/claude_guard.py")
|
|
2139
|
+
|| norm_rel.ends_with("assets/contain/test_contain.py")
|
|
2140
|
+
|| norm_rel.ends_with("assets/contain/test_antigravity_guard.py")
|
|
737
2141
|
|| norm_rel.ends_with("assets/git-guardrails/git-guard-patterns.txt")
|
|
738
2142
|
|| norm_rel.ends_with("assets/git-guardrails/git-guard.ts")
|
|
2143
|
+
|| norm_rel.ends_with("assets/git-guardrails/git-guard.sh")
|
|
2144
|
+
|| norm_rel.ends_with("assets/git-guardrails/test_git_guard.py")
|
|
2145
|
+
|| norm_rel.ends_with("assets/self-grill/test_self_grill.py")
|
|
739
2146
|
{
|
|
740
2147
|
return;
|
|
741
2148
|
}
|
|
742
|
-
let
|
|
2149
|
+
let is_scratch = norm_rel.starts_with(".scratch/");
|
|
2150
|
+
let test_file = !is_scratch && is_test_file(&norm_rel);
|
|
2151
|
+
let e2e_file = !is_scratch && is_e2e_file(&norm_rel);
|
|
743
2152
|
let gate_file = is_gate_or_eval_file(&norm_rel);
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
2153
|
+
let is_ci_yaml = matches!(ext.as_str(), "yml" | "yaml")
|
|
2154
|
+
&& (norm_rel.starts_with(".github/workflows/")
|
|
2155
|
+
|| norm_rel == ".gitlab-ci.yml"
|
|
2156
|
+
|| norm_rel == ".deepmodebot/ci.yml");
|
|
2157
|
+
let file_name_low = Path::new(&norm_rel)
|
|
2158
|
+
.file_name()
|
|
2159
|
+
.and_then(|n| n.to_str())
|
|
2160
|
+
.map(|s| s.to_ascii_lowercase())
|
|
2161
|
+
.unwrap_or_default();
|
|
2162
|
+
let is_tsconfig = file_name_low.starts_with("tsconfig") && ext == "json";
|
|
2163
|
+
let is_pkg_json = file_name_low == "package.json";
|
|
2164
|
+
let is_py_type_cfg = matches!(
|
|
2165
|
+
file_name_low.as_str(),
|
|
2166
|
+
"pyproject.toml" | "mypy.ini" | ".mypy.ini" | "setup.cfg" | "pyrightconfig.json"
|
|
2167
|
+
);
|
|
2168
|
+
let is_mypy_ini = matches!(file_name_low.as_str(), "mypy.ini" | ".mypy.ini");
|
|
2169
|
+
let is_migration = is_migration_file(&norm_rel);
|
|
2170
|
+
let is_biome_cfg = matches!(file_name_low.as_str(), "biome.json" | "biome.jsonc");
|
|
2171
|
+
let is_pw_cfg = file_name_low.starts_with("playwright.config.");
|
|
2172
|
+
let is_train_py = ext == "py"
|
|
2173
|
+
&& ["train", "finetune", "sft", "rlhf", "pretrain"]
|
|
2174
|
+
.iter()
|
|
2175
|
+
.any(|p| file_name_low.starts_with(p));
|
|
2176
|
+
let is_prod_code = !is_scratch
|
|
2177
|
+
&& !test_file
|
|
2178
|
+
&& !e2e_file
|
|
2179
|
+
&& !gate_file
|
|
2180
|
+
&& matches!(
|
|
2181
|
+
ext.as_str(),
|
|
2182
|
+
"py" | "js" | "mjs" | "cjs" | "ts" | "tsx" | "jsx" | "rs" | "go" | "sql"
|
|
2183
|
+
);
|
|
2184
|
+
let proof_map = if matches!(ext.as_str(), "lean" | "v" | "smt2") {
|
|
2185
|
+
full_text.map(|ft| scrub_proof_text_lines(&ext, ft))
|
|
2186
|
+
} else {
|
|
2187
|
+
None
|
|
2188
|
+
};
|
|
2189
|
+
scan_evaluator_bypasses(rel, &norm_rel, &ext, added, full_text, test_file || e2e_file, out);
|
|
2190
|
+
for (ln, raw_line) in added {
|
|
2191
|
+
let in_test_ctx = !is_scratch
|
|
2192
|
+
&& (test_file
|
|
2193
|
+
|| e2e_file
|
|
2194
|
+
|| rs_cfg_test_line.map(|cfg_ln| *ln >= cfg_ln).unwrap_or(false));
|
|
2195
|
+
if ext == "cfg" && has_tla_cfg_commented_invariant(raw_line) {
|
|
2196
|
+
out.push(RewardFinding {
|
|
2197
|
+
severity: "P0",
|
|
2198
|
+
rule: "reward-hack-proof-escape",
|
|
2199
|
+
file: rel.to_string(),
|
|
2200
|
+
line: *ln,
|
|
2201
|
+
message: "TLA+ `.cfg` comments out `INVARIANT`/`PROPERTY` so model checking passes vacuously.".to_string(),
|
|
2202
|
+
fix: "Keep every TLA+ invariant and temporal property active and fix the specification.",
|
|
2203
|
+
});
|
|
747
2204
|
}
|
|
748
|
-
let
|
|
749
|
-
if in_test_ctx &&
|
|
2205
|
+
let cmt_slice = extract_unquoted_comment(&ext, raw_line);
|
|
2206
|
+
if !in_test_ctx && has_iac_sec_suppression(cmt_slice) {
|
|
750
2207
|
out.push(RewardFinding {
|
|
751
2208
|
severity: "P1",
|
|
752
|
-
rule: "reward-hack-
|
|
2209
|
+
rule: "reward-hack-scanner-suppressed",
|
|
753
2210
|
file: rel.to_string(),
|
|
754
2211
|
line: *ln,
|
|
755
|
-
message: "
|
|
756
|
-
fix: "
|
|
2212
|
+
message: "Inline security/IaC scanner suppression (`tfsec`/`checkov`/`trivy`/`nosemgrep`) silences a policy check.".to_string(),
|
|
2213
|
+
fix: "Remediate the underlying security or IaC misconfiguration instead of suppressing the scanner.",
|
|
757
2214
|
});
|
|
758
2215
|
}
|
|
2216
|
+
if is_scanner_or_comment(&ext, raw_line) {
|
|
2217
|
+
continue;
|
|
2218
|
+
}
|
|
2219
|
+
let line = strip_trailing_comment(&ext, raw_line);
|
|
2220
|
+
if in_test_ctx || is_pw_cfg || gate_file {
|
|
2221
|
+
if has_inflated_visual_tolerance(line) {
|
|
2222
|
+
out.push(RewardFinding {
|
|
2223
|
+
severity: "P0",
|
|
2224
|
+
rule: "reward-hack-visual-tolerance-inflated",
|
|
2225
|
+
file: rel.to_string(),
|
|
2226
|
+
line: *ln,
|
|
2227
|
+
message: "Visual regression diff tolerance inflated (`maxDiffPixelRatio > 0.10` or `maxDiffPixels >= 5000`) to mask broken UI.".to_string(),
|
|
2228
|
+
fix: "Keep tight screenshot tolerances and fix the visual layout regression.",
|
|
2229
|
+
});
|
|
2230
|
+
}
|
|
2231
|
+
if line.contains(".disableRules([") || line.contains(".disableRules( [") {
|
|
2232
|
+
out.push(RewardFinding {
|
|
2233
|
+
severity: "P1",
|
|
2234
|
+
rule: "reward-hack-a11y-disabled",
|
|
2235
|
+
file: rel.to_string(),
|
|
2236
|
+
line: *ln,
|
|
2237
|
+
message: "Accessibility audit rules disabled (`disableRules([...])`) to force a passing check.".to_string(),
|
|
2238
|
+
fix: "Fix the underlying accessibility violation instead of disabling Axe rules.",
|
|
2239
|
+
});
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
759
2242
|
if in_test_ctx {
|
|
2243
|
+
if e2e_file && has_e2e_api_stub(line) {
|
|
2244
|
+
out.push(RewardFinding {
|
|
2245
|
+
severity: "P1",
|
|
2246
|
+
rule: "reward-hack-e2e-api-stubbed",
|
|
2247
|
+
file: rel.to_string(),
|
|
2248
|
+
line: *ln,
|
|
2249
|
+
message: "E2E spec intercepts/stubs `/api/`, `/graphql`, or `/trpc` backend routes instead of exercising the real server.".to_string(),
|
|
2250
|
+
fix: "Run E2E specs against the live backend service; reserve route mocks for unit tests or 3rd-party external APIs.",
|
|
2251
|
+
});
|
|
2252
|
+
}
|
|
2253
|
+
if has_test_skip(line) {
|
|
2254
|
+
out.push(RewardFinding {
|
|
2255
|
+
severity: "P1",
|
|
2256
|
+
rule: "reward-hack-test-skip",
|
|
2257
|
+
file: rel.to_string(),
|
|
2258
|
+
line: *ln,
|
|
2259
|
+
message: "Unconditional test skip or non-strict `xfail` added (`skip` / `xfail` / `#[ignore]`) silences a failing check.".to_string(),
|
|
2260
|
+
fix: "Fix the failing behavior instead of skipping or xfailing the test.",
|
|
2261
|
+
});
|
|
2262
|
+
}
|
|
2263
|
+
if has_tautological_assert(line) {
|
|
2264
|
+
out.push(RewardFinding {
|
|
2265
|
+
severity: "P1",
|
|
2266
|
+
rule: "reward-hack-tautological-test",
|
|
2267
|
+
file: rel.to_string(),
|
|
2268
|
+
line: *ln,
|
|
2269
|
+
message: "Tautological assertion (`assert True` / `expect(true).toBe(true)`) passes vacuously without testing behavior.".to_string(),
|
|
2270
|
+
fix: "Assert concrete behavioral outputs of the system under test.",
|
|
2271
|
+
});
|
|
2272
|
+
}
|
|
760
2273
|
continue;
|
|
761
2274
|
}
|
|
2275
|
+
let trimmed_low = line.trim().to_ascii_lowercase();
|
|
2276
|
+
if is_pkg_json && is_package_noop_script(line) {
|
|
2277
|
+
out.push(RewardFinding {
|
|
2278
|
+
severity: "P0",
|
|
2279
|
+
rule: "reward-hack-noop-script",
|
|
2280
|
+
file: rel.to_string(),
|
|
2281
|
+
line: *ln,
|
|
2282
|
+
message: "`package.json` verification script (`test`/`check`/`typecheck`/`lint`) replaced with a no-op (`echo`/`true`/`exit 0`).".to_string(),
|
|
2283
|
+
fix: "Wire `package.json` scripts to the real test runner, typechecker, and linter.",
|
|
2284
|
+
});
|
|
2285
|
+
}
|
|
2286
|
+
let in_mypy_ctx = is_mypy_ini || mypy_lines.is_some_and(|s| s.contains(ln));
|
|
2287
|
+
if (is_ci_yaml
|
|
2288
|
+
&& trimmed_low.starts_with("continue-on-error:")
|
|
2289
|
+
&& trimmed_low[18..].trim_start().starts_with("true"))
|
|
2290
|
+
|| (is_tsconfig && has_tsconfig_weaken(line))
|
|
2291
|
+
|| (is_py_type_cfg && has_py_typecheck_weaken(&trimmed_low, in_mypy_ctx))
|
|
2292
|
+
|| (is_biome_cfg && has_json_key_false(line, &["enabled"]))
|
|
2293
|
+
|| (ext == "rs" && is_prod_code && has_rs_crate_allow(line))
|
|
2294
|
+
{
|
|
2295
|
+
out.push(RewardFinding {
|
|
2296
|
+
severity: "P0",
|
|
2297
|
+
rule: "reward-hack-ci-or-typecheck-neutered",
|
|
2298
|
+
file: rel.to_string(),
|
|
2299
|
+
line: *ln,
|
|
2300
|
+
message: "CI, typechecker, or compiler gate neutered (`continue-on-error: true`, `tsconfig`/`mypy`/`pyright` strictness off, `biome` disabled, or crate `#![allow(...)]`).".to_string(),
|
|
2301
|
+
fix: "Keep strict CI/compiler/typechecker gates enabled and fix the underlying errors.",
|
|
2302
|
+
});
|
|
2303
|
+
}
|
|
2304
|
+
if is_prod_code && has_prod_test_branch(line) {
|
|
2305
|
+
out.push(RewardFinding {
|
|
2306
|
+
severity: "P0",
|
|
2307
|
+
rule: "reward-hack-prod-test-branch",
|
|
2308
|
+
file: rel.to_string(),
|
|
2309
|
+
line: *ln,
|
|
2310
|
+
message: "Production code branches on test-runner state (`PYTEST_CURRENT_TEST` / `JEST_WORKER_ID` / `sys.modules['pytest']`).".to_string(),
|
|
2311
|
+
fix: "Remove test-environment detection from production code; use dependency injection at external boundaries.",
|
|
2312
|
+
});
|
|
2313
|
+
}
|
|
2314
|
+
if is_prod_code && has_prod_integrity_bypass(line, is_migration) {
|
|
2315
|
+
out.push(RewardFinding {
|
|
2316
|
+
severity: "P0",
|
|
2317
|
+
rule: "reward-hack-integrity-bypass",
|
|
2318
|
+
file: rel.to_string(),
|
|
2319
|
+
line: *ln,
|
|
2320
|
+
message: "Production code disables TLS certificate verification (`verify=False` / `InsecureSkipVerify`) or DB foreign-key checks.".to_string(),
|
|
2321
|
+
fix: "Keep TLS verification and relational foreign-key constraints enabled and fix the root configuration/schema bug.",
|
|
2322
|
+
});
|
|
2323
|
+
}
|
|
2324
|
+
if has_ml_eval_leakage(line, is_train_py || is_scratch) {
|
|
2325
|
+
out.push(RewardFinding {
|
|
2326
|
+
severity: "P0",
|
|
2327
|
+
rule: "reward-hack-eval-leakage",
|
|
2328
|
+
file: rel.to_string(),
|
|
2329
|
+
line: *ln,
|
|
2330
|
+
message: "Training script fits on or loads `test`/`eval` split directly (train-on-test data leakage).".to_string(),
|
|
2331
|
+
fix: "Train strictly on training splits and hold out validation/test splits for evaluation only.",
|
|
2332
|
+
});
|
|
2333
|
+
}
|
|
2334
|
+
if has_snapshot_overwrite(line) {
|
|
2335
|
+
out.push(RewardFinding {
|
|
2336
|
+
severity: "P0",
|
|
2337
|
+
rule: "reward-hack-snapshot-overwrite",
|
|
2338
|
+
file: rel.to_string(),
|
|
2339
|
+
line: *ln,
|
|
2340
|
+
message: "Unattended snapshot overwrite flag (`--update-snapshots`, `-u`, `cargo insta accept`, `INSTA_UPDATE=always`) rewrites golden expectations.".to_string(),
|
|
2341
|
+
fix: "Verify outputs against locked snapshots instead of overwriting golden baselines.",
|
|
2342
|
+
});
|
|
2343
|
+
}
|
|
762
2344
|
if has_threshold_zero_or_skip(line) {
|
|
763
2345
|
out.push(RewardFinding {
|
|
764
2346
|
severity: "P0",
|
|
765
2347
|
rule: "reward-hack-threshold-zero",
|
|
766
2348
|
file: rel.to_string(),
|
|
767
2349
|
line: *ln,
|
|
768
|
-
message: "
|
|
769
|
-
fix: "
|
|
2350
|
+
message: "Sub-floor quality/coverage threshold, gate skip flag, or empty `go test -run=^$` filter bypasses real evaluation.".to_string(),
|
|
2351
|
+
fix: "Keep evaluation thresholds above their floor and run the real test suite.",
|
|
2352
|
+
});
|
|
2353
|
+
}
|
|
2354
|
+
if matches!(ext.as_str(), "lean" | "v" | "smt2") {
|
|
2355
|
+
let single_map;
|
|
2356
|
+
let scrubbed_ln = if let Some(pm) = &proof_map {
|
|
2357
|
+
pm.get(ln).map(String::as_str).unwrap_or("")
|
|
2358
|
+
} else {
|
|
2359
|
+
single_map = scrub_proof_text_lines(&ext, line);
|
|
2360
|
+
single_map.get(&1).map(String::as_str).unwrap_or("")
|
|
2361
|
+
};
|
|
2362
|
+
if has_proof_escape_scrubbed(&ext, scrubbed_ln) {
|
|
2363
|
+
out.push(RewardFinding {
|
|
2364
|
+
severity: "P0",
|
|
2365
|
+
rule: "reward-hack-proof-escape",
|
|
2366
|
+
file: rel.to_string(),
|
|
2367
|
+
line: *ln,
|
|
2368
|
+
message: "Formal proof trust escape (`sorry`/`admit`/`Admitted.`/custom `axiom`/`native_decide`/`(assert false)`) bypasses verification.".to_string(),
|
|
2369
|
+
fix: "Construct a complete kernel-checked proof without axioms, sorry, or contradictory premises.",
|
|
2370
|
+
});
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
if (gate_file || (ext == "sql" && !is_migration)) && has_vacuous_query(line) {
|
|
2374
|
+
out.push(RewardFinding {
|
|
2375
|
+
severity: "P0",
|
|
2376
|
+
rule: "reward-hack-vacuous-query",
|
|
2377
|
+
file: rel.to_string(),
|
|
2378
|
+
line: *ln,
|
|
2379
|
+
message: "Vacuous query predicate (`WHERE 1=0` / `WHERE FALSE` / `LIMIT 0`) forces 0 error rows in validation.".to_string(),
|
|
2380
|
+
fix: "Query the real dataset without vacuous filters and fix invalid records.",
|
|
770
2381
|
});
|
|
771
2382
|
}
|
|
772
2383
|
if include_primitives && !allow_primitives && has_primitive_standin(line) {
|
|
@@ -775,8 +2386,8 @@ pub fn scan_file_reward_hacks(
|
|
|
775
2386
|
rule: "reward-hack-primitive-standin",
|
|
776
2387
|
file: rel.to_string(),
|
|
777
2388
|
line: *ln,
|
|
778
|
-
message: "Local procedural primitive geometry (`cube`/`cone`/`sphere`/`cylinder`) added in production/pipeline code.".to_string(),
|
|
779
|
-
fix: "Produce the asset via the real upstream generator/solver with a provenance receipt, or pass `--allow-primitives` for genuine CAD/procedural geometry.",
|
|
2389
|
+
message: "Local procedural primitive geometry (`cube`/`cone`/`sphere`/`cylinder`) added in production/pipeline or scratch code.".to_string(),
|
|
2390
|
+
fix: "Produce the asset via the real upstream generator/solver with a signed provenance receipt, or pass `--allow-primitives` for genuine CAD/procedural geometry.",
|
|
780
2391
|
});
|
|
781
2392
|
}
|
|
782
2393
|
if has_hardcoded_pass(line) {
|
|
@@ -790,22 +2401,8 @@ pub fn scan_file_reward_hacks(
|
|
|
790
2401
|
});
|
|
791
2402
|
}
|
|
792
2403
|
}
|
|
793
|
-
let
|
|
794
|
-
|
|
795
|
-
.filter_map(|(rem, add)| {
|
|
796
|
-
let kept: Vec<(usize, String)> = add
|
|
797
|
-
.iter()
|
|
798
|
-
.filter(|(ln, _)| rs_cfg_test_line.map(|cfg_ln| *ln < cfg_ln).unwrap_or(true))
|
|
799
|
-
.cloned()
|
|
800
|
-
.collect();
|
|
801
|
-
if kept.is_empty() {
|
|
802
|
-
None
|
|
803
|
-
} else {
|
|
804
|
-
Some((rem.clone(), kept))
|
|
805
|
-
}
|
|
806
|
-
})
|
|
807
|
-
.collect();
|
|
808
|
-
scan_hunk_weakening(rel, &filtered_hunks, test_file || gate_file, out);
|
|
2404
|
+
let has_test_block = test_file || e2e_file || rs_cfg_test_line.is_some();
|
|
2405
|
+
scan_hunk_weakening(rel, hunks, has_test_block || gate_file, has_test_block, out);
|
|
809
2406
|
}
|
|
810
2407
|
|
|
811
2408
|
fn read_json_string(s: &str) -> Option<(String, usize)> {
|
|
@@ -948,10 +2545,25 @@ fn norm_rel_arg(raw: &str) -> String {
|
|
|
948
2545
|
s.trim_start_matches('/').to_string()
|
|
949
2546
|
}
|
|
950
2547
|
|
|
951
|
-
fn
|
|
2548
|
+
fn discover_scratch_scripts_and_symlinks(root: &Path) -> (Vec<String>, Vec<RewardFinding>) {
|
|
952
2549
|
let scratch = root.join(".scratch");
|
|
2550
|
+
if let Ok(sm) = fs::symlink_metadata(&scratch) {
|
|
2551
|
+
if sm.file_type().is_symlink() {
|
|
2552
|
+
return (
|
|
2553
|
+
Vec::new(),
|
|
2554
|
+
vec![RewardFinding {
|
|
2555
|
+
severity: "P0",
|
|
2556
|
+
rule: "reward-hack-scratch-symlink",
|
|
2557
|
+
file: ".scratch".to_string(),
|
|
2558
|
+
line: 1,
|
|
2559
|
+
message: "`.scratch` is a symlink; scratch symlinks are forbidden to prevent outside-repo gate bypasses.".to_string(),
|
|
2560
|
+
fix: "Replace `.scratch` symlink with a real directory inside the project root.",
|
|
2561
|
+
}],
|
|
2562
|
+
);
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
953
2565
|
if !scratch.is_dir() {
|
|
954
|
-
return Vec::new();
|
|
2566
|
+
return (Vec::new(), Vec::new());
|
|
955
2567
|
}
|
|
956
2568
|
let skip_top = [
|
|
957
2569
|
"reward-guard",
|
|
@@ -963,6 +2575,7 @@ fn discover_scratch_scripts(root: &Path) -> Vec<String> {
|
|
|
963
2575
|
"quota-guard",
|
|
964
2576
|
];
|
|
965
2577
|
let mut found = Vec::new();
|
|
2578
|
+
let mut sym_findings = Vec::new();
|
|
966
2579
|
let mut stack = vec![(scratch.clone(), true)];
|
|
967
2580
|
while let Some((dir, is_top)) = stack.pop() {
|
|
968
2581
|
let Ok(entries) = fs::read_dir(&dir) else {
|
|
@@ -973,41 +2586,63 @@ fn discover_scratch_scripts(root: &Path) -> Vec<String> {
|
|
|
973
2586
|
let Ok(meta) = fs::symlink_metadata(&p) else {
|
|
974
2587
|
continue;
|
|
975
2588
|
};
|
|
2589
|
+
let name = entry.file_name().to_string_lossy().to_string();
|
|
2590
|
+
let low = name.to_ascii_lowercase();
|
|
2591
|
+
let rel_s = p
|
|
2592
|
+
.strip_prefix(root)
|
|
2593
|
+
.map(|r| r.to_string_lossy().replace('\\', "/"))
|
|
2594
|
+
.unwrap_or_else(|_| name.clone());
|
|
976
2595
|
if meta.file_type().is_symlink() {
|
|
2596
|
+
sym_findings.push(RewardFinding {
|
|
2597
|
+
severity: "P0",
|
|
2598
|
+
rule: "reward-hack-scratch-symlink",
|
|
2599
|
+
file: rel_s,
|
|
2600
|
+
line: 1,
|
|
2601
|
+
message: "Symlink inside `.scratch/` is blocked to prevent external script bypasses.".to_string(),
|
|
2602
|
+
fix: "Remove the symlink from `.scratch/`.",
|
|
2603
|
+
});
|
|
2604
|
+
continue;
|
|
2605
|
+
}
|
|
2606
|
+
if (is_top && skip_top.contains(&name.as_str()))
|
|
2607
|
+
|| low.starts_with("check-")
|
|
2608
|
+
|| low.starts_with("npm-test-")
|
|
2609
|
+
|| low.starts_with("init-cli-test-")
|
|
2610
|
+
|| low.starts_with("panel-")
|
|
2611
|
+
|| low.starts_with("autoroute-test-")
|
|
2612
|
+
{
|
|
977
2613
|
continue;
|
|
978
2614
|
}
|
|
979
|
-
let name = entry.file_name().to_string_lossy().to_string();
|
|
980
2615
|
if meta.is_dir() {
|
|
981
|
-
let low = name.to_ascii_lowercase();
|
|
982
|
-
if (is_top && skip_top.contains(&name.as_str()))
|
|
983
|
-
|| low.starts_with("check-")
|
|
984
|
-
|| low.starts_with("npm-test-")
|
|
985
|
-
|| low.starts_with("init-cli-test-")
|
|
986
|
-
|| low.starts_with("panel-")
|
|
987
|
-
|| low.contains("test")
|
|
988
|
-
{
|
|
989
|
-
continue;
|
|
990
|
-
}
|
|
991
2616
|
stack.push((p, false));
|
|
992
|
-
} else if meta.is_file() && meta.len() > 0
|
|
2617
|
+
} else if meta.is_file() && meta.len() > 0 {
|
|
993
2618
|
let ext = p
|
|
994
2619
|
.extension()
|
|
995
2620
|
.and_then(|e| e.to_str())
|
|
996
2621
|
.map(|s| s.to_ascii_lowercase())
|
|
997
2622
|
.unwrap_or_default();
|
|
998
|
-
if matches!(ext.as_str(), "py" | "sh" | "js" | "mjs" | "cjs" | "ts") {
|
|
999
|
-
if
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
2623
|
+
if matches!(ext.as_str(), "py" | "sh" | "ps1" | "cmd" | "bat" | "js" | "mjs" | "cjs" | "ts") {
|
|
2624
|
+
if meta.len() > 16 * 1024 * 1024 {
|
|
2625
|
+
sym_findings.push(RewardFinding {
|
|
2626
|
+
severity: "P0",
|
|
2627
|
+
rule: "reward-hack-oversized-scratch-script",
|
|
2628
|
+
file: rel_s,
|
|
2629
|
+
line: 1,
|
|
2630
|
+
message: "Scratch script exceeds 16 MiB (padding bypass blocked).".to_string(),
|
|
2631
|
+
fix: "Remove oversized padded script from `.scratch/`.",
|
|
2632
|
+
});
|
|
2633
|
+
} else if found.len() < 500 {
|
|
2634
|
+
found.push(rel_s);
|
|
1004
2635
|
}
|
|
1005
2636
|
}
|
|
1006
2637
|
}
|
|
1007
2638
|
}
|
|
1008
2639
|
}
|
|
1009
2640
|
found.sort();
|
|
1010
|
-
found
|
|
2641
|
+
(found, sym_findings)
|
|
2642
|
+
}
|
|
2643
|
+
|
|
2644
|
+
fn discover_scratch_scripts(root: &Path) -> Vec<String> {
|
|
2645
|
+
discover_scratch_scripts_and_symlinks(root).0
|
|
1011
2646
|
}
|
|
1012
2647
|
|
|
1013
2648
|
fn changed_files(
|
|
@@ -1136,12 +2771,17 @@ pub fn run(args: &[String]) -> ExitCode {
|
|
|
1136
2771
|
let per_file = parallel_map(&changed, |rel| {
|
|
1137
2772
|
let mut local = Vec::new();
|
|
1138
2773
|
let (mut added, hunks) = diff_file_hunks(&root, rel, staged, base_ref.as_deref());
|
|
1139
|
-
let full_txt =
|
|
2774
|
+
let full_txt = if staged && !added.is_empty() {
|
|
2775
|
+
git(&root, &["show", &format!(":{rel}")]).filter(|(ok, _)| *ok).map(|(_, text)| text)
|
|
2776
|
+
} else {
|
|
2777
|
+
fs::read_to_string(root.join(rel)).ok()
|
|
2778
|
+
};
|
|
1140
2779
|
let rs_cfg_ln = if rel.ends_with(".rs") {
|
|
1141
2780
|
full_txt.as_deref().and_then(find_rs_cfg_test_line)
|
|
1142
2781
|
} else {
|
|
1143
2782
|
None
|
|
1144
2783
|
};
|
|
2784
|
+
let mypy_set = full_txt.as_deref().map(find_mypy_section_lines);
|
|
1145
2785
|
if added.is_empty() && !explicit_files.is_empty() {
|
|
1146
2786
|
if let Some(txt) = &full_txt {
|
|
1147
2787
|
added = txt
|
|
@@ -1152,13 +2792,26 @@ pub fn run(args: &[String]) -> ExitCode {
|
|
|
1152
2792
|
}
|
|
1153
2793
|
}
|
|
1154
2794
|
if !added.is_empty() || !hunks.is_empty() {
|
|
1155
|
-
|
|
2795
|
+
scan_file_reward_hacks_full(
|
|
2796
|
+
rel,
|
|
2797
|
+
&added,
|
|
2798
|
+
&hunks,
|
|
2799
|
+
allow_primitives,
|
|
2800
|
+
true,
|
|
2801
|
+
rs_cfg_ln,
|
|
2802
|
+
mypy_set.as_ref(),
|
|
2803
|
+
full_txt.as_deref(),
|
|
2804
|
+
&mut local,
|
|
2805
|
+
);
|
|
1156
2806
|
}
|
|
1157
2807
|
local
|
|
1158
2808
|
});
|
|
1159
2809
|
|
|
1160
2810
|
let mut findings: Vec<RewardFinding> = per_file.into_iter().flatten().collect();
|
|
1161
2811
|
check_contract_locks(&root, &mut findings);
|
|
2812
|
+
if include_scratch && !staged && explicit_files.is_empty() {
|
|
2813
|
+
findings.extend(discover_scratch_scripts_and_symlinks(&root).1);
|
|
2814
|
+
}
|
|
1162
2815
|
|
|
1163
2816
|
let p0 = findings.iter().filter(|f| f.severity == "P0").count();
|
|
1164
2817
|
let p1 = findings.iter().filter(|f| f.severity == "P1").count();
|