fix(fermata): empty masked text becomes [fermata]; a Monitor without a command is left alone; tests for the CRLF and JSON-escaped spellings

This commit is contained in:
2026-11-07 01:29:03 +01:00
parent a583cc24dc
commit ac2fa03306
4 changed files with 75 additions and 2 deletions
+35
View File
@@ -230,3 +230,38 @@ fn an_unclosed_quote_leaves_the_next_key_alone() {
let shown = read(&p, "nextfakevalue lastfakevalue");
assert_eq!(shown, "***** *****");
}
// ---------------------------------------------------------------------------
// Two spellings no other test needs
// ---------------------------------------------------------------------------
/// Short lines, so that no line is masked alone and only the whole value can match.
const SHORT_A: &str = "fakeab1";
const SHORT_B: &str = "fakecd2";
#[test]
fn a_value_read_from_a_file_with_windows_line_ends() {
let env = format!("API_TOKEN=\"{SHORT_A}\n{SHORT_B}\"\n");
let p = project(&[(".env", &env)]);
let shown = read(&p, &format!("{SHORT_A}\r\n{SHORT_B}\r\n"));
assert!(!shown.contains(SHORT_A) && !shown.contains(SHORT_B), "{shown}");
}
#[test]
fn a_value_with_a_quote_inside_a_json_string_of_a_tool_result() {
let p = project(&[(".env", "API_TOKEN='a\"b-fakevalue123'\n")]);
let text = json!({"k": "a\"b-fakevalue123"}).to_string();
let payload = json!({"tool_name": "mcp__srv__t", "tool_input": {}, "tool_response": {"content": [{"type": "text", "text": text}]}});
let output = Command::cargo_bin("fermata")
.unwrap()
.args(["hook", "--event", "post-tool-use", "--harness", "claude"])
.current_dir(p.0.path())
.env("HOME", p.1.path())
.write_stdin(payload.to_string())
.assert()
.success()
.get_output()
.clone();
let out = String::from_utf8(output.stdout).unwrap();
assert!(out.contains("updatedToolOutput") && !out.contains("fakevalue123"), "{out}");
}
+33
View File
@@ -301,3 +301,36 @@ fn the_note_stands_beside_the_heuristic_warning() {
assert!(context.starts_with(NOTE) && context.contains("WARNING"), "{context}");
assert!(!context.contains("ghp_"), "{context}");
}
// ---------------------------------------------------------------------------
// Empty text and a Monitor without a command
// ---------------------------------------------------------------------------
#[test]
fn the_absent_style_leaves_no_empty_text() {
let p = project(&[(".env", &format!("API_TOKEN={SECRET}\n")), (".botsecrets", &styled("absent"))]);
let todo = json!({"oldTodos": [], "newTodos": [{"content": SECRET, "status": "pending", "activeForm": "Working"}]});
let out = p.post("TodoWrite", todo);
assert_eq!(out["hookSpecificOutput"]["updatedToolOutput"]["newTodos"][0]["content"], "[fermata]", "{out}");
let mcp = json!({"content": [{"type": "text", "text": SECRET}]});
let out = p.post("mcp__srv__t", mcp);
assert_eq!(out["hookSpecificOutput"]["updatedToolOutput"]["content"][0]["text"], "[fermata]", "{out}");
}
#[test]
fn a_monitor_without_a_command_is_left_alone() {
let p = project(&[]);
let output = Command::cargo_bin("fermata")
.unwrap()
.args(["hook", "--event", "pre-tool-use", "--harness", "claude"])
.current_dir(p.dir.path())
.env("HOME", p.home.path())
.write_stdin(json!({"tool_name": "Monitor", "tool_input": {"ws": "wss://example.test/x"}}).to_string())
.assert()
.success()
.get_output()
.clone();
assert_eq!(output.stdout, b"{}");
assert!(output.stderr.is_empty(), "{}", String::from_utf8_lossy(&output.stderr));
}