Skip to content

Rewrite your app in Rust, piece by piece, checked against the original at every step. Works with TypeScript, JavaScript, Python, Go, Ruby, Java, C, PHP, C#, Kotlin, PowerShell and Swift.

gate: refuse --held-out-seed with --held-out-cases 0, say off once (#1282)

jakalijey22e2a3e8e777
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 46f01857..b4124059 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
## Unreleased
+- `gate` refuses `--held-out-seed` together with `--held-out-cases 0` before running any check
+ (the MCP `gate` tool too), instead of passing and ignoring the seed, and `--held-out-cases 0`
+ says the check is off once, in its `held-out` row, not also in a note above the table (#1250 by
+ @jakalijey).
- The website's Coverage and Gate pages say `record` measures lines for Python too, and that gate's
`coverage` check fails for an export with no recorded case unless it is waived; the line count
stays information only (#1263 by @jakalijey).
diff --git a/src/gate.rs b/src/gate.rs
index cdbb376a..04ed8bbe 100644
--- a/src/gate.rs
+++ b/src/gate.rs
@@ -1664,6 +1664,12 @@ pub fn gate_with(
node_args: &[String],
opts: &GateOptions,
) -> Result<GateOutcome> {
+ // A seed replays held-out inputs that `--held-out-cases 0` turns off: refuse the pair before
+ // any check runs, so a seed left in a script never passes for a replay that did not happen.
+ anyhow::ensure!(
+ !(opts.held_out_cases == 0 && opts.held_out_seed.is_some()),
+ "--held-out-seed replays held-out inputs, and --held-out-cases 0 turns them off: drop one"
+ );
let stamp = crate::state::Stamp::new(crate_dir, "gate");
let mut outcome = run(crate_dir, node_args, opts)?;
let repo = crate::rules::repo_of(crate_dir);
@@ -2077,13 +2083,6 @@ fn run(crate_dir: &Path, node_args: &[String], opts: &GateOptions) -> Result<Gat
&& d.missing.is_empty()
&& d.batches.iter().all(crate::batch_check::BatchDiff::ok)
{
- if opts.held_out_cases == 0 {
- notes.push(
- "held-out check off with --held-out-cases 0: only the recorded cases \
- were checked"
- .into(),
- );
- }
// The held-out check takes a while: show what is known first.
emit(crate_dir, &checks, &mut sent);
let mut used = Vec::new();
diff --git a/tests/held_out.rs b/tests/held_out.rs
index d4ae5eda..47f582f2 100644
--- a/tests/held_out.rs
+++ b/tests/held_out.rs
@@ -211,6 +211,31 @@ fn a_port_that_matches_every_recorded_case_but_not_other_inputs_fails_gate() {
std::fs::remove_dir_all(&repo).unwrap();
}
+#[test]
+fn a_held_out_seed_with_the_check_off_is_refused_before_any_check() {
+ // Refused before the crate is read: no port, no node needed.
+ let dir = std::env::temp_dir().join(format!(
+ "rust-anything-held-out-seed-off-{}",
+ std::process::id()
+ ));
+ let err = gate::gate_with(
+ &dir,
+ &[],
+ &GateOptions {
+ held_out_cases: 0,
+ held_out_seed: Some(5),
+ ..GateOptions::default()
+ },
+ )
+ .expect_err("a seed with the check off must be refused");
+ let msg = format!("{err:#}");
+ assert!(
+ msg.contains("--held-out-seed") && msg.contains("--held-out-cases 0"),
+ "{msg}"
+ );
+ assert!(!dir.exists(), "nothing was written for a refused gate");
+}
+
#[test]
fn a_correct_port_passes_the_held_out_check_and_says_what_it_tried() {
if !common::have("node") {