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.

map: say --check also fails on a recording that cannot be trusted (#1273)

jakalijey052de43c2036
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 16d4a4e0..dbd4308e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,9 @@
## Unreleased
+- `map --help` and `docs/how-it-works.md` say that `map --check` also exits 1 when a recording
+ cannot be trusted (fingerprint missing, cases edited, removed or dropped), not only when an
+ original changed (#1252 by @jakalijey).
- `fuzz` ends its list of mismatches with `- ... and N more` when more cases failed than it shows,
as `app replay` does. Before, the first 20 read as all of them (#1261 by @jakalijey).
- Go: a `range` is a hash iteration order risk only over a map literal, a `maps.` call or a name
diff --git a/docs/how-it-works.md b/docs/how-it-works.md
index d7d5a740..ca74e259 100644
--- a/docs/how-it-works.md
+++ b/docs/how-it-works.md
@@ -613,7 +613,8 @@ ports it, the functions in Rust and kept in the original, the cases and the last
whole app's glue (Rust only, or still handing cases to the original), the units not ported yet,
and every port whose original changed since it was recorded. `map --write` saves it as
`rust/PORT_MAP.md`; committed, it shows each upstream change as a diff. `map --check` exits 1
-while any recording is stale, for CI.
+while any recording is stale, for CI: when an original changed since it was recorded, or when a
+recording cannot be trusted (fingerprint missing, cases edited, removed or dropped).
After an upstream change: pull it, run `map`, and for each port marked **changed** run `record`
again, then `diff`. The new mismatches are exactly what changed upstream; port those.
diff --git a/src/main.rs b/src/main.rs
index 505b1266..0a649343 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -574,7 +574,8 @@ enum Cmd {
/// Write the map to rust/PORT_MAP.md in the repository instead of printing it.
#[arg(long, conflicts_with = "json")]
write: bool,
- /// Exit 1 when the original changed since any port was recorded.
+ /// Exit 1 when the original changed since any port was recorded, or when a recording
+ /// cannot be trusted (fingerprint missing, cases edited, removed or dropped).
#[arg(long)]
check: bool,
/// Print the machine-readable report as JSON.
diff --git a/tests/port_map.rs b/tests/port_map.rs
index 25ff5ee4..fa826d3c 100644
--- a/tests/port_map.rs
+++ b/tests/port_map.rs
@@ -454,6 +454,18 @@ fn map_check_fails_for_a_recording_whose_fingerprint_file_is_gone() {
.arg(&repo)
.output()
.unwrap();
- assert!(!out.status.success(), "map --check must fail");
+ assert_eq!(
+ out.status.code(),
+ Some(1),
+ "map --check must exit 1, not 2 for an error: {}",
+ String::from_utf8_lossy(&out.stderr)
+ );
std::fs::remove_dir_all(&repo).unwrap();
+
+ let help = common::cli().args(["map", "--help"]).output().unwrap();
+ let help = String::from_utf8_lossy(&help.stdout);
+ assert!(
+ help.contains("a recording cannot be trusted"),
+ "map --help must say an untrusted recording fails --check: {help}"
+ );
}
diff --git a/website/content/cli-help.json b/website/content/cli-help.json
index e3ddf6f2..ee51ad53 100644
--- a/website/content/cli-help.json
+++ b/website/content/cli-help.json
@@ -119,7 +119,7 @@
},
{
"command": "map",
- "help": "Map the port: every unit of the original, the crate that ports it, its cases and last diff, its last switch from the audit log, the whole app's glue, and which recordings the original changed past since they were made. Commit the map (`--write`) to see upstream changes in it\n\nUsage: rust-anything map [OPTIONS] [REPO]\n\nArguments:\n [REPO] Repository root [default: .]\n\nOptions:\n --crates <CRATES> Also look for crates in this folder (crates kept outside the repository)\n --write Write the map to rust/PORT_MAP.md in the repository instead of printing it\n --check Exit 1 when the original changed since any port was recorded\n --json Print the machine-readable report as JSON\n -h, --help Print help\n"
+ "help": "Map the port: every unit of the original, the crate that ports it, its cases and last diff, its last switch from the audit log, the whole app's glue, and which recordings the original changed past since they were made. Commit the map (`--write`) to see upstream changes in it\n\nUsage: rust-anything map [OPTIONS] [REPO]\n\nArguments:\n [REPO] Repository root [default: .]\n\nOptions:\n --crates <CRATES> Also look for crates in this folder (crates kept outside the repository)\n --write Write the map to rust/PORT_MAP.md in the repository instead of printing it\n --check Exit 1 when the original changed since any port was recorded, or when a recording cannot be trusted (fingerprint missing, cases edited, removed or dropped)\n --json Print the machine-readable report as JSON\n -h, --help Print help\n"
},
{
"command": "log",