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.

app drift: list an edited, skipped or removed recording apart from upstream changes (#1289)

jakalijey442e4d47fce7
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6890dd9b..8eadd874 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
## Unreleased
+- `app drift` lists a case whose recording was edited, marked skipped or removed under "Recording
+ changed" (verdict `recording edited`, `recording skipped` or `recording removed`, and `recording`
+ in `--json`), not as "original changed": it says to record again or restore the files, and
+ `drifted` stays true (#1258 by @jakalijey).
- When cases do not answer, `app record` says "The 1 that did is written" for one case, and says
"the cases recorded before were kept" only when the folder had a recording before this run
(#1259 by @jakalijey).
diff --git a/docs/tools.md b/docs/tools.md
index 26d59bc5..f69dadfe 100644
--- a/docs/tools.md
+++ b/docs/tools.md
@@ -460,7 +460,7 @@ May overwrite files, runs the original's code or commands.
Tool `app_drift` · CLI `rust-anything app drift`
-Check that the recording still describes the original and the port still matches: replays the original against rust/app-cases (cases it no longer matches changed upstream, listed in `changed`), lists examples in its docs that no case records (`new`), and replays the build (`failing`, each with a verdict: "original changed, port still old" or "port regression"). Writes rust/app-cases/drift-report.md and leaves replay-report.md as it was. For CLIs and servers; for units, `map` lists every port whose original changed (`changed_upstream`).
+Check that the recording still describes the original and the port still matches: replays the original against rust/app-cases (cases it no longer matches changed upstream, listed in `changed`; cases whose recording was edited, skipped or removed are listed apart in `recording`), lists examples in its docs that no case records (`new`), and replays the build (`failing`, each with a verdict: "original changed, port still old" or "port regression"). Writes rust/app-cases/drift-report.md and leaves replay-report.md as it was. For CLIs and servers; for units, `map` lists every port whose original changed (`changed_upstream`).
Runs the original's code or commands.
diff --git a/src/drift.rs b/src/drift.rs
index cdb7343d..6b175b42 100644
--- a/src/drift.rs
+++ b/src/drift.rs
@@ -35,6 +35,8 @@ pub struct DriftOutcome {
pub cases: usize,
/// Cases the original no longer matches: it changed upstream.
pub changed: Vec<Drifted>,
+ /// Cases whose recording was edited, skipped or removed: the original was not what changed.
+ pub recording: Vec<Drifted>,
/// Cases the build no longer matches.
pub failing: Vec<Drifted>,
/// Examples in the original's docs that no case records.
@@ -47,6 +49,14 @@ fn fields(f: &Failure) -> Vec<String> {
f.problems.iter().map(|p| p.field.clone()).collect()
}
+/// `edited`, `skipped` or `removed` when replay found the case's recording itself touched.
+fn recording_change(f: &Failure) -> Option<&str> {
+ f.problems
+ .iter()
+ .find(|p| p.field == "recording")
+ .map(|p| p.at.as_ref().map_or("changed", |at| at.kind.as_str()))
+}
+
fn failed(outcome: &ReplayOutcome) -> BTreeSet<&str> {
outcome.failures.iter().map(|f| f.case.as_str()).collect()
}
@@ -106,9 +116,26 @@ pub fn drift(opts: &DriftOptions) -> Result<DriftOutcome> {
let original_failed = failed(&original);
let port_failed = port.as_ref().map(failed).unwrap_or_default();
+ // A case whose files were edited, skipped or removed says nothing about the original: list it
+ // apart, and not as a port failure either, since the recording it was checked against is not
+ // the one `record` wrote.
+ let recording: Vec<Drifted> = original
+ .failures
+ .iter()
+ .filter_map(|f| {
+ recording_change(f).map(|kind| Drifted {
+ case: f.case.clone(),
+ args: f.args.clone(),
+ fields: fields(f),
+ verdict: format!("recording {kind}"),
+ })
+ })
+ .collect();
+ let touched: BTreeSet<&str> = recording.iter().map(|d| d.case.as_str()).collect();
let changed: Vec<Drifted> = original
.failures
.iter()
+ .filter(|f| !touched.contains(f.case.as_str()))
.map(|f| Drifted {
case: f.case.clone(),
args: f.args.clone(),
@@ -124,6 +151,7 @@ pub fn drift(opts: &DriftOptions) -> Result<DriftOutcome> {
let failing: Vec<Drifted> = port
.iter()
.flat_map(|p| &p.failures)
+ .filter(|f| !touched.contains(f.case.as_str()))
.map(|f| Drifted {
case: f.case.clone(),
args: f.args.clone(),
@@ -139,8 +167,12 @@ pub fn drift(opts: &DriftOptions) -> Result<DriftOutcome> {
let outcome = DriftOutcome {
build: port.as_ref().map(|p| p.build.clone()),
cases: original.total,
- drifted: !changed.is_empty() || !failing.is_empty() || !new.is_empty(),
+ drifted: !changed.is_empty()
+ || !recording.is_empty()
+ || !failing.is_empty()
+ || !new.is_empty(),
changed,
+ recording,
failing,
new,
report: dir.join(REPORT_FILE),
@@ -212,6 +244,10 @@ fn report(
out += "## Changed upstream\n\nThe original no longer gives what was recorded. If the change is intended, record again (`rust-anything app record`) and port it.\n";
diffs(&mut out, &outcome.changed, original);
}
+ if !outcome.recording.is_empty() {
+ out += "\n## Recording changed\n\nThese cases' files in the recording were edited, marked skipped or removed, so the original was not compared with what `record` wrote, and whether it changed upstream is not known. Restore the files and run `app drift` again, or record them again (`rust-anything app record`) after checking what the original gives.\n";
+ diffs(&mut out, &outcome.recording, original);
+ }
if let Some(p) = port
&& !outcome.failing.is_empty()
{
@@ -253,6 +289,7 @@ mod tests {
cases: 3,
drifted: !changed.is_empty() || !failing.is_empty() || !new.is_empty(),
changed,
+ recording: Vec::new(),
failing,
new: new.into_iter().map(String::from).collect(),
report: PathBuf::new(),
@@ -298,6 +335,25 @@ mod tests {
assert!(!text.contains("## "), "{text}");
}
+ #[test]
+ fn a_touched_recording_has_its_own_heading() {
+ let mut out = outcome(vec![], vec![], vec![]);
+ out.recording = vec![Drifted {
+ verdict: "recording edited".into(),
+ ..drifted("greet")
+ }];
+ out.drifted = true;
+ let original = replay(
+ &["node", "cli.js"],
+ 2,
+ vec![failure("greet", "-hello\n+hi\n")],
+ );
+ let text = report(&out, &original, None);
+ assert!(text.contains("## Recording changed\n"), "{text}");
+ assert!(text.contains("### greet (recording edited)"), "{text}");
+ assert!(!text.contains("## Changed upstream"), "{text}");
+ }
+
#[test]
fn a_build_reports_its_command_and_matches() {
let port = replay(&["target/app", "--flag"], 2, vec![]);
diff --git a/src/main.rs b/src/main.rs
index 38b2fc4e..9370065b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3021,6 +3021,7 @@ fn run_app(command: AppCmd) -> Result<ExitCode> {
);
for (title, list) in [
("Changed upstream", &outcome.changed),
+ ("Recording changed", &outcome.recording),
("Port failures", &outcome.failing),
] {
if !list.is_empty() {
diff --git a/src/mcp.rs b/src/mcp.rs
index 7c06c662..fbf661fa 100644
--- a/src/mcp.rs
+++ b/src/mcp.rs
@@ -1041,7 +1041,7 @@ fn tool_schemas() -> Value {
},
{
"name": "app_drift",
- "description": "Check that the recording still describes the original and the port still matches: replays the original against rust/app-cases (cases it no longer matches changed upstream, listed in `changed`), lists examples in its docs that no case records (`new`), and replays the build (`failing`, each with a verdict: \"original changed, port still old\" or \"port regression\"). Writes rust/app-cases/drift-report.md and leaves replay-report.md as it was. For CLIs and servers; for units, `map` lists every port whose original changed (`changed_upstream`).",
+ "description": "Check that the recording still describes the original and the port still matches: replays the original against rust/app-cases (cases it no longer matches changed upstream, listed in `changed`; cases whose recording was edited, skipped or removed are listed apart in `recording`), lists examples in its docs that no case records (`new`), and replays the build (`failing`, each with a verdict: \"original changed, port still old\" or \"port regression\"). Writes rust/app-cases/drift-report.md and leaves replay-report.md as it was. For CLIs and servers; for units, `map` lists every port whose original changed (`changed_upstream`).",
"inputSchema": { "type": "object", "properties": {
"repo": { "type": "string", "description": "Repository root." },
"build": { "type": "string", "description": "Build to check; defaults to rust/app, built with cargo, when it exists." },
diff --git a/tests/app.rs b/tests/app.rs
index 0316c983..2d518cce 100644
--- a/tests/app.rs
+++ b/tests/app.rs
@@ -1727,6 +1727,87 @@ fn app_replay_with_a_port_on_a_cli_recording_fails_before_running() {
std::fs::remove_dir_all(&repo).unwrap();
}
+#[test]
+fn drift_lists_an_edited_or_removed_recording_apart_from_upstream_changes() {
+ let Some(python) = common::python() else {
+ return;
+ };
+ let repo = one_off(
+ "drift-recording",
+ &[
+ ("cli.py", "import sys\nprint(sys.argv[1].upper())\n"),
+ (
+ "inputs.jsonl",
+ "{\"name\":\"hi\",\"args\":[\"hi\"]}\n{\"name\":\"bye\",\"args\":[\"bye\"]}\n",
+ ),
+ ],
+ );
+ let inputs = repo.join("inputs.jsonl");
+ app::record(&RecordOptions {
+ repo: &repo,
+ run: &[python.to_string(), "cli.py".to_string()],
+ inputs: Some(&inputs),
+ normalize: &[],
+ name: None,
+ traps: false,
+ timeout_secs: None,
+ http: None,
+ server_args: None,
+ fresh: None,
+ pace_ms: None,
+ port: None,
+ float_tolerance: None,
+ float_files: &[],
+ effects: None,
+ ready_secs: None,
+ ready_request: None,
+ sandbox: false,
+ })
+ .unwrap();
+ let dir = app::cases_dir(&repo);
+ std::fs::write(dir.join("hi.stdout"), "HELLO\n").unwrap();
+ for entry in std::fs::read_dir(&dir).unwrap() {
+ let path = entry.unwrap().path();
+ if path
+ .file_name()
+ .and_then(|n| n.to_str())
+ .is_some_and(|n| n.starts_with("bye."))
+ {
+ std::fs::remove_file(path).unwrap();
+ }
+ }
+ let out = drift::drift(&DriftOptions {
+ repo: &repo,
+ build: None,
+ timeout_secs: None,
+ })
+ .unwrap();
+ let report = std::fs::read_to_string(&out.report).unwrap();
+ std::fs::remove_dir_all(&repo).unwrap();
+
+ assert!(out.drifted, "{out:?}");
+ assert!(
+ out.changed.is_empty(),
+ "the original did not change: {out:?}"
+ );
+ let verdicts: Vec<(&str, &str)> = out
+ .recording
+ .iter()
+ .map(|d| (d.case.as_str(), d.verdict.as_str()))
+ .collect();
+ assert!(
+ verdicts.contains(&("hi", "recording edited")),
+ "{verdicts:?}"
+ );
+ assert!(
+ verdicts.contains(&("bye", "recording removed")),
+ "{verdicts:?}"
+ );
+ assert!(report.contains("## Recording changed"), "{report}");
+ assert!(!report.contains("## Changed upstream"), "{report}");
+ assert!(!report.contains("original changed"), "{report}");
+}
+
#[test]
fn drift_finds_upstream_changes_and_new_examples() {
if !common::have("node") {