fix(fermata): an editor's swap or backup file no longer refuses

One non-UTF-8 .env.swp blocked everything a checkout sent across a link, and would
withhold every tool output under deny. A discovered *.swp, *.swo, *.swn, *.swx or
*~ that cannot be read or parsed is now passed over under every setting. One that
can be parsed stays known to the redactor. .bak, .env.gpg and [[file]] overrides
keep the rule.
This commit is contained in:
2026-11-06 23:36:57 +01:00
parent 969cff212f
commit 5c3b239f59
5 changed files with 84 additions and 0 deletions
+10
View File
@@ -225,6 +225,16 @@ fn other_settings_stay_open_and_quote_nothing() {
}
}
/// An editor's file does not take down every tool output of a `deny` project.
#[test]
fn an_editors_swap_file_does_not_withhold_under_deny() {
let p = project(&[(".botsecrets", DENY), (".env", "API_TOKEN=value-on-the-failing-line\n")]);
fs::write(p.dir.path().join(".env.swp"), b"b0VIM \xff\xfe\x00\x01").unwrap();
let (out, _) = p.post(json!(RESPONSE));
let text = out["hookSpecificOutput"]["updatedToolOutput"].as_str().unwrap();
assert!(text.starts_with("output of the tool") && !text.contains(VALUE), "{text}");
}
// ---------------------------------------------------------------------------
// PreToolUse
// ---------------------------------------------------------------------------
+46
View File
@@ -327,3 +327,49 @@ fn opaque_file_formats_are_skipped_gracefully() {
let keys: Vec<&str> = manifest.entries().iter().map(|e| e.key.as_str()).collect();
assert!(keys.contains(&"PASSWORD"));
}
// ---------------------------------------------------------------------------
// Editor artefacts
// ---------------------------------------------------------------------------
const NOT_UTF8: &[u8] = b"b0VIM 9.1 \xff\xfe\x00\x01";
fn deny_config() -> SecretsConfig {
config_from_toml("[enforcement]\non_parse_error = \"deny\"\n")
}
/// Stays strict by default: an editor's file that cannot be read stops nothing, and
/// one that can is still redacted. Anything else that cannot be read still refuses.
#[test]
fn an_editors_file_that_cannot_be_read_does_not_refuse_and_one_that_can_stays_known() {
let dir = tempfile::tempdir().unwrap();
let config = deny_config();
for name in [".env.swp", ".env.swo", ".env.swn", ".env.swx", ".env.local~"] {
fs::write(dir.path().join(name), NOT_UTF8).unwrap();
}
fs::write(dir.path().join(".env.bak.swp"), "API_KEY=readable-swap-value-1234\n").unwrap();
let manifest = Manifest::build(&config, dir.path()).expect("editor files must not refuse");
let values: Vec<&str> = manifest.entries().iter().map(|e| e.value.as_str()).collect();
assert_eq!(values, ["readable-swap-value-1234"]);
for name in [".env.gpg", ".env.bak", ".env.orig", ".env.local"] {
let file = dir.path().join(name);
fs::write(&file, NOT_UTF8).unwrap();
assert!(Manifest::build(&config, dir.path()).is_err(), "{name} must still refuse");
fs::remove_file(&file).unwrap();
}
}
/// A file named by hand is meant, whatever it is called.
#[test]
fn a_file_override_named_like_an_editors_file_still_refuses_and_a_found_one_does_not() {
let dir = tempfile::tempdir().unwrap();
fs::write(dir.path().join(".env.swp"), NOT_UTF8).unwrap();
Manifest::build(&deny_config(), dir.path()).expect("found by a pattern: no refusal");
let config = config_from_toml(
"[enforcement]\non_parse_error = \"deny\"\n[[file]]\npath = \".env.swp\"\nformat = \"env\"\n",
);
assert!(Manifest::build(&config, dir.path()).is_err());
}