fix(fermata): a bad glob costs only itself; commands read what is there, behind a wrapper or a shell

- A glob in [files] or [policy] that does not compile costs only that pattern while open,
  with a note by name beside text output. A [files] list with none left leaves the built-in
  list. Under deny the refusal stays, and the channel filter stays strict.
- A file named `credentials` is on the default list, at any depth.
- A word with a separator counts only if the path is there, the shell may expand it, or a
  redirect names it: packages, branches and hosts' paths are not denied.
- timeout, nice, ionice, stdbuf, xargs and busybox are prefixes; `2>&1` stays in its segment.
- `bash|sh|zsh -c` and `eval` arguments are read as command lines.
- A `<<` with no closing line is no heredoc. A commented line's own comment is dropped.
  Text holding NUL fails to parse. The unknown-field message says so. Durations are bound
  to under 6 characters. More source extensions pass the gate.
- Removed: HarnessAdapter::post_tool_op (dead since 3C was dropped), tool_op back inline.
This commit is contained in:
2026-11-07 02:00:45 +01:00
parent 999ed6ba4e
commit 6bf602aa6a
20 changed files with 579 additions and 140 deletions
+40 -6
View File
@@ -137,12 +137,17 @@ fn a_word_after_an_output_redirect_takes_the_verb_of_its_segment() {
// ---------------------------------------------------------------------------
#[test]
fn a_word_is_a_path_when_it_is_a_file_or_holds_a_separator() {
fn a_word_is_a_path_when_it_is_a_file_or_holds_a_separator_and_is_there() {
check(Posix, &[
("npm run build", NOTHING),
("cat build", NOTHING),
("cat a-word", NOTHING),
("cat build/new", &[("build/new", Prints)]),
// What is not there is a package, a branch or a host's path, unless a redirect
// writes it or the shell may expand it.
("cat build/new", NOTHING),
("tool > build/new", &[("build/new", Other)]),
("tool < build/new", &[("build/new", Prints)]),
("tool $X/new", &[("$X/new", Other)]),
("cat vendor/", &[("vendor", Prints)]),
("cat ~/x", &[("~/x", Prints)]),
("cat $HOME/x", &[("~/x", Prints)]),
@@ -150,7 +155,7 @@ fn a_word_is_a_path_when_it_is_a_file_or_holds_a_separator() {
]);
// No home known: the text stays as written, under the working directory.
let f = fixture();
let named = command_paths("cat ~/x", Posix, f.cwd.path(), None);
let named = command_paths("cat > ~/x", Posix, f.cwd.path(), None);
assert_eq!(named[0].path, f.cwd.path().join("~/x"));
}
@@ -244,7 +249,7 @@ fn everything_else_is_other() {
("mv .env a-copy", ENV_OTHER),
("rm .env", ENV_OTHER),
("python .env", ENV_OTHER),
("docker cp .env c:/x", &[(".env", Other), ("c:/x", Other)]),
("docker cp .env c:/x", ENV_OTHER),
("git add .env", ENV_OTHER),
("git diff .env", ENV_OTHER),
("git", NOTHING),
@@ -279,6 +284,33 @@ fn the_verb_comes_after_assignments_and_prefixes() {
]);
}
#[test]
fn a_wrapper_is_no_verb_and_its_flag_or_number_neither() {
check(Posix, &[
("timeout 5 cat .env", ENV_PRINTS),
("timeout 5s cat .env", ENV_PRINTS),
("nice -n 10 cat .env", ENV_PRINTS),
("ionice -c 2 cat .env", ENV_PRINTS),
("stdbuf -o0 cat .env", ENV_PRINTS),
("xargs -n 1 cat .env", ENV_PRINTS),
("busybox cat .env", ENV_PRINTS),
("timeout 5 ls .env", ENV_METADATA),
// The named limit: a flag's value that is a word becomes the verb.
("sudo -u root cat .env", ENV_OTHER),
]);
}
#[test]
fn an_early_redirect_stays_in_its_segment() {
check(Posix, &[
("cat 2>&1 .env", ENV_PRINTS),
("cat 1>&2 .env", ENV_PRINTS),
("cat >&2 .env", ENV_PRINTS),
("cat .env 2>&1 | ls", ENV_PRINTS),
("a & cat .env", ENV_PRINTS),
]);
}
#[test]
fn the_verb_word_is_never_a_path() {
check(Posix, &[
@@ -365,8 +397,10 @@ fn a_heredoc_body_is_text() {
("cat > a.txt << \"EOF\"\nsee cat .env\nEOF\ncat .env", &[("a.txt", Prints), (".env", Prints)]),
("cat > a.txt <<-EOF\n\tsee cat .env\n\tEOF\ncat .env", &[("a.txt", Prints), (".env", Prints)]),
("git commit -F - <<EOF\nfix .env loading\nEOF", NOTHING),
// Never closed: the rest is its body.
("cat <<EOF\ncat .env", NOTHING),
// Never closed: no heredoc, and what follows runs. Under-denial is the worse error.
("cat <<EOF\ncat .env", ENV_PRINTS),
("echo $((1<<2))\ncat .env", ENV_PRINTS),
("x=$((a<<1))\nsource .env", ENV_OTHER),
("cat <<EOF | grep x .env\nbody\nEOF", ENV_PRINTS),
// A here-string is text too.
("cat <<< .env", NOTHING),