From 58512dee2fcc82d3fba0593cd15ccc876edb2126 Mon Sep 17 00:00:00 2001 From: Mykhailo Chalyi Date: Mon, 9 Nov 2026 19:16:21 +0000 Subject: [PATCH] fix(test): stop comparing an implementation-defined cp leftover to the host MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `cp_directory_dot_rejects_descendant_and_missing_source` compared its whole stdout against real `bash`, and one of the things it printed was whether `source/inside/item` exists after `cp -r source/. source/inside` is refused. That is not a stable cross-host observable, so the oracle comparison was flaky: assertion `left == right` failed left: [49, 10, 49, 10] // host: "1\n1\n" right: [49, 10, 117, 110, ... 10, 49, 10] // bashkit: "1\nunchanged\n1\n" It failed on CI on a commit whose diff was one workflow argument and three markdown files, having passed minutes earlier on the same commit in the preceding attempt of the same run — two runner VMs disagreeing, which is what a host-dependent observable looks like. `cp -r source/. source/inside` asks for the contents of `source/` to be copied into `source/inside`, and those contents are both `item` (a legitimate copy) and `inside` (the refusal). Whether the legitimate part lands before the refusal aborts the walk is up to the implementation. GNU coreutils 9.4 copies no entries yet still creates `source/inside/inside`; the CI host left `source/inside/item` behind. Reproduced the failure exactly by putting a `cp` that copies plain entries before refusing ahead of GNU cp on PATH: the old script then yields `1\n1\n` against bashkit's `1\nunchanged\n1\n`, byte for byte the CI assertion, while the new script yields `1\n1\n` on both. The oracle now compares only the two refusal statuses, which every implementation agrees on. bashkit's own contract — that it refuses a descendant copy atomically, copying nothing in — is asserted directly against bashkit instead, so coverage of that behaviour is unchanged rather than dropped. The file already carried this reasoning for stderr ("Host cp diagnostics vary (GNU/BSD)"); this extends it to the one layout detail that turned out to vary too. 1790 integration tests pass. --- .../integration/cp_directory_dot_tests.rs | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/crates/bashkit/tests/integration/cp_directory_dot_tests.rs b/crates/bashkit/tests/integration/cp_directory_dot_tests.rs index 6c6850f30..233d652fe 100644 --- a/crates/bashkit/tests/integration/cp_directory_dot_tests.rs +++ b/crates/bashkit/tests/integration/cp_directory_dot_tests.rs @@ -64,7 +64,34 @@ async fn cp_directory_dot_respects_no_clobber() { #[tokio::test] async fn cp_directory_dot_rejects_descendant_and_missing_source() { - check("mkdir -p source/inside destination; echo keep > source/item; cp -r source/. source/inside 2>/dev/null; echo $?; test ! -e source/inside/item && echo unchanged; cp -r missing/. destination 2>/dev/null; echo $?", "1\nunchanged\n1\n").await; + // Oracle-compared: the two refusal statuses only. Both hosts and bashkit + // agree a descendant copy and a missing source each exit 1. + check( + "mkdir -p source/inside destination; echo keep > source/item; \ + cp -r source/. source/inside 2>/dev/null; echo $?; \ + cp -r missing/. destination 2>/dev/null; echo $?", + "1\n1\n", + ) + .await; + + // bashkit refuses a descendant copy atomically: nothing under `source/` + // is copied in. Asserted against bashkit only, never the host, because + // what a host `cp` leaves behind after refusing is implementation-defined + // and not stable even for one version. GNU coreutils 9.4 copies no + // entries but does create `source/inside/inside`; CI produced a partial + // copy (`source/inside/item` present) for this very script on one runner + // and not on another, for the same commit, which is what made comparing + // this probe against the oracle flaky. + let refusal = Bash::new() + .exec( + "mkdir -p source/inside; echo keep > source/item; \ + cp -r source/. source/inside 2>/dev/null; \ + test ! -e source/inside/item && echo unchanged", + ) + .await + .unwrap(); + assert_eq!(refusal.exit_code, 0, "{}", refusal.stderr); + assert_eq!(refusal.stdout, "unchanged\n", "{}", refusal.stderr); // Host cp diagnostics vary (GNU/BSD); compare only status/layout above. let result = Bash::new()