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.

fix(gate): emit single --accept-known-diffs command when both rules fail (#1432)

m3lon06ebeece778b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6da4c401..c1cf5439 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
## Unreleased
+- `gate`'s `accepted diffs` check now prints a single `--accept-known-diffs <N>` command when both rules fail (naming the count that clears both), and updates `fix:`, `gate --help`, and MCP tool documentation to clarify entries vs. accepted cases (#1349 by @m3lonxd).
- `profile` and `go` on a C repository say they do not run C workloads yet and name Instruments' Time Profiler on macOS alongside `perf record -g` on Linux, matching other unsupported languages (#1398 by @m3lonxd).
- Python: `time.localtime()`, `time.gmtime()`, `time.strftime()`, `time.ctime()`,
`time.asctime()` and `datetime.today()` count as reading the clock in `bridge` and `analyze`.
diff --git a/docs/tools.md b/docs/tools.md
index 1668c292..899aac73 100644
--- a/docs/tools.md
+++ b/docs/tools.md
@@ -301,7 +301,7 @@ Runs the original's code or commands.
| --- | --- | --- | --- |
| `crate` | string | yes | Folder of the generated crate (holds rust-anything.json). |
| `node_args` | string[] | | Extra arguments for node, e.g. ["--import=tsx"]. |
-| `accept_known_diffs` | integer | | You have read the entries of known-diffs.jsonl (this many): cases they accept count as matches. Without it, entries added since the last passing gate, or more than a tenth of the cases, fail the gate. |
+| `accept_known_diffs` | integer | | Number of entries added to known-diffs.jsonl since the last passing gate, or, when the entries accept more than a tenth of the cases, the number of cases they accept. Without it, those fail the gate. |
| `accept_smaller_recording` | boolean | | The recording has fewer cases than at the last passing gate, and that is meant. |
| `accept_dropped` | integer | | record could not record this many generated cases and you have looked at them. |
| `held_out_cases` | integer | | Fresh inputs per function (and as many perturbed recorded ones) the held-out check runs after behavior passes (default 50); 0 turns it off. |
diff --git a/src/gate.rs b/src/gate.rs
index 04ed8bbe..4d7293f3 100644
--- a/src/gate.rs
+++ b/src/gate.rs
@@ -110,7 +110,8 @@ fn fix_for(check: &Check, crate_dir: &Path) -> Option<String> {
}
"accepted diffs" => format!(
"read each entry of {c}/{}; if they are meant, run `rust-anything gate {q} \
- --accept-known-diffs <how many>`",
+ --accept-known-diffs <how many>` (entries added since the last passing gate, or, when \
+ the entries accept more than a tenth of the cases, the number of cases they accept)",
crate::recording::KNOWN_DIFFS
),
"tests" => format!(
@@ -1413,12 +1414,13 @@ fn accepted_diffs_check(
.as_ref()
.and_then(|b| b.known_diffs_accepted)
.unwrap_or(0);
+ let added_fails = added > said;
+ let share_fails = accepted * 10 > total && accepted > said.max(before);
let mut problems = Vec::new();
- if added > said {
+ if added_fails {
problems.push(format!(
"{} {} added to {} since the last passing gate{}: each one makes a case that differs \
- count as a match; read them, and if they are meant, run `rust-anything gate {} \
- --accept-known-diffs {entries}`",
+ count as a match",
added,
if added == 1 {
"entry was"
@@ -1431,18 +1433,29 @@ fn accepted_diffs_check(
} else {
""
},
- crate::app::cli_path(crate_dir)
));
}
- if accepted * 10 > total && accepted > said.max(before) {
+ if share_fails {
problems.push(format!(
"{accepted} of {total} recorded cases ({}%) are accepted as known differences, more than a \
- tenth: that is a different port, not an intended change; if it is meant, run \
- `rust-anything gate {} --accept-known-diffs {accepted}`",
+ tenth: that is a different port, not an intended change",
accepted * 100 / total.max(1),
- crate::app::cli_path(crate_dir)
));
}
+ if !problems.is_empty() {
+ let needed = match (added_fails, share_fails) {
+ (true, true) => entries.max(accepted),
+ (true, false) => entries,
+ (false, true) => accepted,
+ (false, false) => 0,
+ };
+ if let Some(last) = problems.last_mut() {
+ last.push_str(&format!(
+ "; read them, and if they are meant, run `rust-anything gate {} --accept-known-diffs {needed}`",
+ crate::app::cli_path(crate_dir)
+ ));
+ }
+ }
let said_note = if said > 0 {
format!("; {said} named by --accept-known-diffs")
} else {
@@ -4731,6 +4744,24 @@ mod guard_tests {
.unwrap()
.passed
);
+ // Both rules fail at once (1 added entry accepting 20 of 100 cases):
+ // one failure command naming the number that clears both (`20`, not `1`).
+ let dir_both = crate::app::temp_dir("guard-known-both").unwrap();
+ std::fs::write(dir_both.join("known-diffs.jsonl"), format!("{entry}\n")).unwrap();
+ let c = accepted_diffs_check(&dir_both, 20, 100, &opts(None)).unwrap();
+ assert!(!c.passed, "{c:?}");
+ assert!(c.detail.contains("--accept-known-diffs 20"), "{}", c.detail);
+ assert!(!c.detail.contains("--accept-known-diffs 1"), "{}", c.detail);
+ let c1 = accepted_diffs_check(&dir_both, 20, 100, &opts(Some(1))).unwrap();
+ assert!(!c1.passed, "{c1:?}");
+ assert!(
+ c1.detail.contains("--accept-known-diffs 20"),
+ "{}",
+ c1.detail
+ );
+ let c20 = accepted_diffs_check(&dir_both, 20, 100, &opts(Some(20))).unwrap();
+ assert!(c20.passed, "{c20:?}");
+ std::fs::remove_dir_all(dir_both).unwrap();
std::fs::remove_dir_all(dir).unwrap();
}
diff --git a/src/main.rs b/src/main.rs
index 3fe65293..92d9fca8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -470,8 +470,9 @@ enum Cmd {
/// Extra arguments for node, e.g. `--node-arg=--import=tsx`.
#[arg(long = "node-arg", allow_hyphen_values = true)]
node_args: Vec<String>,
- /// You have read the entries of known-diffs.jsonl (this many): cases they accept count
- /// as matches. Without it, entries added since the last passing gate fail the gate.
+ /// Number of entries added to known-diffs.jsonl since the last passing gate, or, when
+ /// the entries accept more than a tenth of the cases, the number of cases they accept.
+ /// Without it, those fail the gate.
#[arg(long, value_name = "N")]
accept_known_diffs: Option<usize>,
/// The recording has fewer cases than at the last passing gate, and that is meant.
diff --git a/src/mcp.rs b/src/mcp.rs
index 2e3a5d54..a7e1af9f 100644
--- a/src/mcp.rs
+++ b/src/mcp.rs
@@ -1012,7 +1012,7 @@ fn tool_schemas() -> Value {
"inputSchema": { "type": "object", "properties": {
"crate": crate_dir,
"node_args": { "type": "array", "items": { "type": "string" }, "description": "Extra arguments for node, e.g. [\"--import=tsx\"]." },
- "accept_known_diffs": { "type": "integer", "description": "You have read the entries of known-diffs.jsonl (this many): cases they accept count as matches. Without it, entries added since the last passing gate, or more than a tenth of the cases, fail the gate." },
+ "accept_known_diffs": { "type": "integer", "description": "Number of entries added to known-diffs.jsonl since the last passing gate, or, when the entries accept more than a tenth of the cases, the number of cases they accept. Without it, those fail the gate." },
"accept_smaller_recording": { "type": "boolean", "description": "The recording has fewer cases than at the last passing gate, and that is meant." },
"accept_dropped": { "type": "integer", "description": "record could not record this many generated cases and you have looked at them." },
"held_out_cases": { "type": "integer", "minimum": 0, "description": "Fresh inputs per function (and as many perturbed recorded ones) the held-out check runs after behavior passes (default 50); 0 turns it off." },
diff --git a/website/content/cli-help.json b/website/content/cli-help.json
index ee51ad53..c5c57ee7 100644
--- a/website/content/cli-help.json
+++ b/website/content/cli-help.json
@@ -67,7 +67,7 @@
},
{
"command": "gate",
- "help": "5. Check the definition of done for a port\n\nUsage: rust-anything gate [OPTIONS] [CRATE_DIR]\n\nArguments:\n [CRATE_DIR] Crate folder made by `bridge` [default: .]\n\nOptions:\n --json Print the machine-readable report as JSON\n --json-events Print each check as a JSON line as soon as it is known, then a `result` line\n --held-out-cases <N> Fresh inputs per function (and as many perturbed recorded ones) the held-out check runs after `behavior` passes, from a seed taken from the clock; 0 turns it off [default: 50]\n --held-out-seed <SEED> Draw the held-out inputs from this seed, to replay a failing run (printed with it)\n --node-arg <NODE_ARGS> Extra arguments for node, e.g. `--node-arg=--import=tsx`\n --accept-known-diffs <N> You have read the entries of known-diffs.jsonl (this many): cases they accept count as matches. Without it, entries added since the last passing gate fail the gate\n --accept-smaller-recording The recording has fewer cases than at the last passing gate, and that is meant\n --accept-dropped <N> `record` could not record this many generated cases, and you have looked at them\n -h, --help Print help\n"
+ "help": "5. Check the definition of done for a port\n\nUsage: rust-anything gate [OPTIONS] [CRATE_DIR]\n\nArguments:\n [CRATE_DIR] Crate folder made by `bridge` [default: .]\n\nOptions:\n --json Print the machine-readable report as JSON\n --json-events Print each check as a JSON line as soon as it is known, then a `result` line\n --held-out-cases <N> Fresh inputs per function (and as many perturbed recorded ones) the held-out check runs after `behavior` passes, from a seed taken from the clock; 0 turns it off [default: 50]\n --held-out-seed <SEED> Draw the held-out inputs from this seed, to replay a failing run (printed with it)\n --node-arg <NODE_ARGS> Extra arguments for node, e.g. `--node-arg=--import=tsx`\n --accept-known-diffs <N> Number of entries added to known-diffs.jsonl since the last passing gate, or, when the entries accept more than a tenth of the cases, the number of cases they accept. Without it, those fail the gate\n --accept-smaller-recording The recording has fewer cases than at the last passing gate, and that is meant\n --accept-dropped <N> `record` could not record this many generated cases, and you have looked at them\n -h, --help Print help\n"
},
{
"command": "selftest",