* fix(tier3): grade Hermes and OpenCode calls by their recorded results
A successful read could hide a failed edit to the same file, and a runner error could count as a successful command. Match each tool result to its call before giving credit for a manifest read, a file change, or recovery from a command failure.
Use the same Hermes tool names and result handling in the runner and the verifier shipped with Harbor tasks. Keep rejected terminal attempts visible to security checks without treating them as completed commands.
Co-authored-by: Narendran Raghavan <nraghavan@nvidia.com>
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Deepak Jain <deepujain@gmail.com>
* fix(tier3): grade command completion and file actions by their receipts
A Claude background launch can succeed before the command exits. Do not use that receipt to verify a file read or a successful retry. A failed directory change must not make a later deletion look safe.
Use the recorded Pi and OpenCode file outcomes, not JSON error messages in the file. Match the expected operation and replacement text to the call that performed it.
Co-authored-by: Narendran Raghavan <nraghavan@nvidia.com>
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Deepak Jain <deepujain@gmail.com>
* fix(tier3): require completion evidence for run claims
Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com>
---------
Signed-off-by: Deepak Jain <deepujain@gmail.com>
Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com>
Co-authored-by: Narendran Raghavan <nraghavan@nvidia.com>
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
* fix(tier3): treat placeholder expected_script and behavior values as no expectation
Signed-off-by: Christopher Kevin <christopherk@nvidia.com>
* fix(tier3): preserve expected behaviors in standalone checks
Signed-off-by: Christopher Kevin <christopherk@nvidia.com>
* fix(tier3): defer annotations in standalone verifier helpers
Signed-off-by: Christopher Kevin <christopherk@nvidia.com>
* fix(tier3): validate expected_script and normalize assertions
Signed-off-by: Christopher Kevin <christopherk@nvidia.com>
* fix: report invalid expected_script response
Signed-off-by: Christopher Kevin <christopherk@nvidia.com>
---------
Signed-off-by: Christopher Kevin <christopherk@nvidia.com>
Co-authored-by: Narendran Raghavan <32655573+rng1995@users.noreply.github.com>
* fix(tier3): require invocation evidence for script execution credit
check_script_execution() asked only whether the expected script name
appeared anywhere in an execution command's text, so reading, printing
or searching the script earned the same full credit as running it. At
5c73273, `cat run.py`, `head -20 run.py`, `echo run.py`,
`grep -n threshold run.py` and `python run.py.bak` each returned
{"passed": true, "score": 1.0, "reason": "Executed run.py"} from both
the host checker and the bundled Harbor verifier.
The detection contract
----------------------
The command text is all this check has, and it does not settle every
command, so the three results mean three different things:
1.0 the text shows a recognised invocation of the expected script,
and every token between the start of the command and the script
was recognised. Claimed only when nothing in the command depends
on data the text does not carry.
0.0 the text shows a recognised NON-invocation: the script is an
argument to a command that does not run it, or an option means
no script runs at all (`--help`, `-n`, `perl -c`).
0.75 the existing partial credit, meaning this walk could not resolve
the command. Any shape it does not model lands here. Unmodelled
is never scored 0.0 and never scored 1.0.
That third rule is the one that matters, because it decides what a shell
feature nobody anticipated costs: a wrong answer, or an honest "cannot
tell". Cases that land at 0.75 today: a path the shell builds at run
time; an option outside an interpreter's or wrapper's grammar; the
script named only in heredoc data; a path reaching a command through
standard input or through a tool's own `{}` substitution; inline code,
a module or `eval` text that names the script; and the script redirected
into a command's standard input. Several of these are decidable by
something that modelled `xargs`, `find` or Python. This walk does not
model them and says so rather than guessing.
What earns full credit
----------------------
The script invoked directly, an interpreter given it as its script
argument, a `source`, or a `sh -c` payload that does one of those. Every
other command is reported as not an invocation, so reading, copying,
deleting or touching the file needs no list of non-executing verbs.
Only the first non-option argument is an interpreter's script, so
`python other.py run.py` runs other.py and passes run.py to it. Options
come from a per-interpreter grammar whose sets were derived by running
every option against a script that records whether it executed.
Measuring rather than reading documentation is what separated `ruby -v`
(runs the script) from `ruby --version` (does not), and it is why
`perl -M`, `perl -i.bak` and `python -Q` are absent: their argument is
conditionally attached, so no single rule resolves them.
Wrappers have grammars derived the same way. A help or version option
means the wrapper printed and exited, so `env --help python run.py` runs
nothing; an unlisted option leaves the command unresolved rather than
assuming the wrapped command still runs. `--` ends a wrapper's options
but not its positional arguments, so `timeout -- 30 python run.py` still
reads 30 as the duration.
The set of commands that run another command has no end, so it is not
listed. `flock`, `taskset`, `ionice`, `chrt`, `strace` and `watch` have
no grammar here, and neither will the next one. Instead, an unrecognised
command that carries what looks like an interpreter running the script
is left unresolved, while one that merely takes the script as an
argument stays a non-invocation. So `flock /tmp/x python run.py` is
unresolved and `flock /tmp/x cat run.py` is still zero.
`xargs` and `parallel` are deliberately never transparent. Whether they
run anything depends on their standard input, which a command's own text
never carries: `printf '' | xargs -r python run.py` runs nothing, and
`xargs -p` runs nothing with no terminal to confirm at. Crediting the
command after them was a false positive waiting to happen.
Heredoc operators are found with a quote-aware scan that skips
arithmetic, so neither `echo '<<'` nor `echo $((1 << 2))` is read as
one. A body ends at its delimiter line, so commands after the terminator
are still walked, and a here-string operand ends at a separator outside
quotes, so `cat <<< "a; b"; python run.py` still reaches the invocation.
Separately, shlex returns a run of punctuation such as `));` as one
token, which is split back into its operators so the command after
`(cd x && python run.py);` is not read as an argument of the one before.
The observation fallback no longer rescues a command that named the
script without invoking it, because that output is text the command
itself produced, and no longer credits a file-read tool returning the
script's own source.
Applied to eval_core/checks.py and to the bundled verifier in
harbor/templates/eval.py, whose observation-fallback ordering also
differed from the host copy.
Evidence
--------
scripts/script_invocation_differential.py is the harness these claims
come from, added here so they can be re-run rather than taken on trust.
It executes every command for real in a throwaway directory against
fixtures that write a marker when they run, treats the marker as ground
truth, and compares host checker and bundled verifier on every command.
192 curated shapes, plus as many generated ones as `--fuzz` asks for.
On 2195 executed commands (192 curated plus 2000 generated), on Python
3.12 and 3.13: no false positive, no false negative, no divergence
between the two implementations. A separate pass put 4036 malformed
command strings through both implementations without an exception.
Two limitations are declared rather than hidden.
A chain such as `diff a b && python run.py` where the first link failed
is still credited, because the walk is static and a tool call does not
carry which link of a chain failed. The harness reports these separately
rather than counting them as agreement, and this is the only way a 1.0
can be wrong under the contract above.
In the other direction, `./wrap.sh run.py` scores 0.0 although the
wrapper runs the script. By text alone that command is indistinguishable
from `cat run.py`: an unrecognised command with the script as its
argument. No parser resolves it, and scoring it 0.75 would mean scoring
`cat run.py` 0.75 as well, which would undo the fix this change exists
for. `su -c '...'` and `script -c '...'` are the same shape with the
invocation inside a quoted payload.
The alternative contract, where 0.0 requires a recognised non-executing
command and everything else falls to 0.75, would resolve those three. It
was measured and not taken, because it trades them for the error the
issue is about. Twenty ways of reading a script that this module never
names, among them `xxd`, `hexdump`, `strings`, `od`, `base64`, `shasum`
and `iconv`, all score 0.0 under the contract above; under the
alternative every one of them would score 0.75 until somebody added it
to a list. Over-crediting a read is the defect being fixed here, so
unrecognised commands are biased towards 0.0 and a small number of
wrappers are under-credited instead. Flipping that bias is a one-place
change if the maintainers prefer the other direction.
Tests
-----
tests/tier3/test_script_invocation_evidence.py: 380 cases parametrised
over both implementations, covering non-executing commands, interpreter
and wrapper options, wrapper help, end-of-options, stdin-driven tools,
inline code and modules, heredoc bodies and terminators, arithmetic,
punctuation runs, assignment-only commands, run-time substitution,
invocations quoted as data, both observation fallbacks, and genuine
invocation controls across python, perl, ruby, node and sourcing, plus
invocations carried inside commands with no grammar of their own, and
reading verbs this module never names. 210 of the 380 fail against
5c73273; all 380 pass here.
Signed-off-by: mavericksea-ai <274285725+mavericksea-ai@users.noreply.github.com>
* fix(tier3): score five command shapes as the shell runs them
Review of the first revision found five commands the walk read
differently from how the shell runs them, all present in both the host
checker and the bundled Harbor verifier at 6ba1071.
Partial credit without a reference. A bare `cd` loses track of the
directory and an option outside a grammar may have consumed anything,
and the walk reported both as unresolved, so an unrelated `cd` with
empty output scored 0.75 where 5c73273 scored 0.0, inflating the
enclosing skill-execution score. Parsing uncertainty is not evidence
about a script the command never names, so the walk now answers "did
not run it" unless the script's file name appears somewhere in the
command text, the same reference test 5c73273 applied. 0.75 is
therefore only ever given for a command that names the script.
A script's own arguments read as the shell's options. `bash run.sh -c
'echo done'` and `bash -- run.sh -c 'echo done'` run run.sh, but the
inline-code check scanned every argument, took the script's `-c` as
the shell's, and the walk went looking for a payload and never came
back to the operand. The grammar walk that finds the script operand
now decides whether the shell runs inline code, so only the option
prefix counts and `--` ends it.
Redirections standing before the script. `python3 < /dev/null run.py`
runs run.py, but only output redirections were dropped from the
argument stream, so `<` was resolved as the first operand. The
interpreter's operands are now taken with every redirection removed:
`<`, `<&`, `<>`, `>&`, the descriptor in `2>/dev/null` and `2>&1`,
and the attached forms the fallback tokenizer leaves in one token.
`_command_input_args` itself is unchanged, because the activation
check that also uses it reads `<` operands on purpose, and a script
fed through standard input is still detected before this and left
unresolved.
Invocations inside control structures. `if true; then ./run.py; fi`
and `for i in one; do ./run.py; done` run the script, but after the
split at `;` the walk treated `then` and `do` as unknown executables.
`if`, `then`, `else`, `elif`, `while`, `until` and `do` now stand
before the command rather than being one, in either order with
assignments. A `for` or `select` header with a single value binds its
variable for the body, so `for f in run.py; do python $f; done` scores
1.0 and `for f in run.py; do cat $f; done` scores 0.0; a header with
several values that name the script leaves the command unresolved,
because which one `$f` is when the body runs is not settled by the
text, and `case` is left unresolved rather than modelled. Neither is
ever a settled non-invocation.
Versioned interpreter names. `/usr/bin/perl5.38.2 run.pl` scored 0.0
while `perl run.pl` scored 1.0: the gate deciding whether a command
runs a script accepted versioned Python names only, although the
grammar lookup already stripped the suffix. The stripped name is now
used for every interpreter decision, so `perl5.38.2 -c run.pl` also
keeps perl's grammar and scores 0.0.
Evidence
--------
All five reproduced against 6ba1071 by executing the review's
commands, marker files as ground truth, before any code changed. The
generator in scripts/script_invocation_differential.py could not have
produced any of them: it always named the target, only ever used
`python3`, had no control words or input redirections in any list,
and the harness filed a 0.75 on a command that did not run under
"agreed". It now generates all five shape classes, names versioned
interpreters the way this machine installs them, and reports a 0.75
on a command that never names the script as a defect of its own.
On 2197 executed commands (260 curated plus 2000 generated), on Python
3.12 and 3.13: no false positive, no false negative, no divergence
between the two implementations, no partial without a reference. A
second seed reads the same, and 17,680 mutated or truncated commands
through both implementations raised nothing and never diverged.
Tests
-----
tests/tier3/test_script_invocation_evidence.py gains 136 cases over
both implementations for the five shapes and their controls: `bash -c
'echo done' run.sh` stays 0.0 because run.sh is only the payload's
`$0`, reading the script inside a loop stays 0.0, `perl5.38.2 -c
run.pl` stays 0.0, and a script fed through standard input stays
unresolved. 516 pass; 84 of the 136 new cases fail against 6ba1071
and the other 52 are the controls, which held there and hold here.
Signed-off-by: mavericksea-ai <274285725+mavericksea-ai@users.noreply.github.com>
* fix(tier3): keep descriptors with their operators, read the -c payload from the same stream, and scope loop bindings
Three regressions from 6084463, each reproduced in both implementations
and fixed in both.
A digit standing apart from its operator is an operand. The tokenizer
split `2>/dev/null` and `2 > numeric.out` into the same tokens, so the
operand walk could not tell a descriptor from a script named 2 and
dropped the digit either way, crediting `python3 2 > numeric.out run.py`
with running run.py. Attached descriptors are now kept with their
operator before tokenizing (quoted, outside quotes only), so `2>` stays
one token and a bare `2` is the script it is.
The -c payload comes from the same argument stream as the option.
`_runs_inline_code` saw -c through the redirection-filtered operands
while `_shell_c_payload` read the raw tokens and took the redirection as
the payload, scoring `bash -c 2>/dev/null './run.sh'` 0.0. Both now read
the interpreter's operands with every redirection removed.
A loop header that settles nothing forgets an earlier binding. A second
`for f in a b` left the value a first single-value header gave `f`, so
its body was read against the wrong script. A header with several values
or none now drops the variable. Extending the harness to generate that
shape showed a fourth case: a binding made inside a pipeline, a piped
compound command included, does not outlive it, because each command of
a pipeline runs in a subshell. Bindings made there are now scoped to the
pipeline, and a compound command that feeds a pipeline is scoped with it.
The generator now produces detached descriptors, redirections between -c
and its payload, and sequential loop headers; the harness fixtures gained
the scripts 0, 1 and 2 so those commands succeed as the shell reads them.
On 2316 commands (316 curated, 2000 generated), two seeds, Python 3.12:
no false positive, no false negative, no divergence, no partial without a
reference. 4036 malformed strings through both implementations without
an exception. 74 new tests over both implementations, 590 total; 34 fail
against 6084463 and the rest are controls.
Signed-off-by: mavericksea-ai <274285725+mavericksea-ai@users.noreply.github.com>
* fix(tier3): keep the redirection operand a word, keep bindings past an empty loop, read pipeline scope by shell, and read a quoted word as a word
Three regressions from 67f03dd, each reproduced in both implementations
and fixed in both, plus the neighbours the same checks turned up.
An operand written flush against its descriptor became part of the
operator's quoted word: `'0<'run.py` tokenized as one word, so the walk
never saw the filename and `python3 0<run.py` scored 0.0 where the spaced
form scored 0.75. The operand is now split into its own word before
tokenizing, and keeps its whole name (`2>1.log`).
`for f in; do ...; done` runs zero iterations and never assigns f, in
bash, dash, zsh, ksh and mksh alike. The header forgot every earlier
binding, so `f=run.py; for f in; do :; done; python3 "$f"` scored 0.0.
The earlier binding now stands, and the body, which never runs, is
skipped whole up to its matching `done` rather than read as execution
evidence. select is a loop of the same kind and is treated the same.
Whether the last command of a pipeline keeps its bindings depends on
the shell: zsh and ksh run it in the current shell, bash, dash and mksh
fork it (each measured). The walk applied bash's rule to every payload,
so `zsh -c 'printf "" | for f in run.py; do :; done; python3 "$f"'`
scored 0.0 for a script that ran. A `-c` payload now carries its shell
into the walk. An option change that can move the last stage between the
two rules (`shopt -s lastpipe` in bash, `emulate sh` in zsh) or an
unmodelled shell is walked under both readings, and their disagreement
is unresolved (0.75), never "did not run". The tool call's own shell is
read as bash, as the harness executes. ksh, mksh and ash are modelled
shells with sh's options, so `ksh run.sh` runs a script and `ksh -c`
carries its payload.
The tokenizer drops quotes, so `'done'` read as the reserved word and
ended the skipped loop body early, `printf "("` read as a subshell
opening, and `printf '%s' ';|' python3 run.py` split into a printf and
a python3. A quoted or escaped word whose unquoted text would read as
syntax (a reserved word, a parenthesis or brace, a separator, a
redirection operator, or any run of metacharacters) is now marked
before tokenizing and the walk reads it as the ordinary word the shell
does; the mark is dropped wherever a word is read as a value, and a
mark character already in the text is doubled first so a file named
with it keeps its identity. `d'on'e` and `\done` are covered.
Scopes are one stack, innermost last. A `( ... )` group and a compound
command isolated as a pipeline stage each copy the innermost scope and
drop their copy when they end, so they nest correctly in either order:
`printf "" | { f=run.py; (f=other.py); python3 "$f"; }` runs run.py
(a gap present at NVIDIA main too). Every group and compound opener in
a segment is placed in turn, and each compound is tested for its own
pipe, so in `{ if ...; fi | cat; }` only the `if` is a stage and in
`{ printf "" | f=x; }` the pipe belongs to the command inside the
braces. A pipe before `(` belongs to the group; a pipeline written
inside a group still isolates its stages; skipping an empty loop's body
keeps the frames in step.
`((` at command position is an arithmetic command in bash, zsh, ksh and
mksh when its two halves close together as `))`, whatever is between
(`((f=x; cmd))` fails and runs nothing); closed apart, or under dash, it
is nested subshells, and under `sh` or `ash` both readings are walked.
The body stays one word, so its separators split nothing. A variable an
arithmetic command assigns becomes a number, stays as it was after an
error, or is never read again because ksh aborts, so one that held the
script is unresolved afterwards and any other stays not the script.
Found alongside: a binding made inside `( ... )` reached the command
after the group (`(f=run.py); python3 "$f"` scored 1.0, and it runs
nothing), in every shell; parentheses now scope a copy of the bindings,
under the pipeline rule. `for f; do` iterates the positional parameters,
which a tool call has none of, so at the top level it runs nothing and
keeps the variable's value; where the text can supply some (`set --`,
`shift`, operands after a `-c` payload beyond its `$0`) a later read of
the variable is unresolved, and an operand naming the script reaches the
payload only through `$1`, `$@`, `$0` or `for f; do` written in it. An
interpreter with no script operand fed by a pipe whose earlier stage
names the script (`cat run.py | python3`) reads its program from
standard input, the same shape as `python3 < run.py`, and is unresolved
rather than "nothing ran".
The differential harness gains `--baseline REF`, which scores every
executed command with the checker at that ref as well and lists each
score that moved, against the marker: a score lowered on a command that
ran, or raised on one that did not, is listed first for review. Against
f9d69af, 523 curated commands move 85 scores: 34 false positives and
45 false negatives repaired, and six deliberate unresolved readings
(`cat 0<run.py`, equal to `cat 0< run.py`; `emulate sh` in zsh). 2000
generated commands on each of three seeds: no false positive, no false
negative, no host/verifier divergence, no score lowered on a command
that ran. The harness also reports a command whose named tool is not
installed as not runnable, instead of reading its redirected `command
not found` as a run.
Verified: 1061 tests over both implementations, ruff clean; the harness
executed 506 curated, 4000 fuzzed and 5988 composed commands (new
`--compose N`: bindings nested two or three scopes deep under bash, zsh
and ksh); and three independent generated corpora of 1548, 204 and 192
commands, with no false positive, false negative or divergence
under bash 5.2 with zsh 5.9, ksh 93u+, mksh, dash and Python 3.12.
Signed-off-by: mavericksea-ai <maverickaisea@gmail.com>
* fix(tier3): read variables that builtins and prefixes bind as the shell does, and read every heredoc declared on a line
Two regressions from the review of 190f4ce, each reproduced in both
implementations and fixed in both, plus the neighbours the same checks
turned up. Every behaviour below was measured on bash 5.2 (and bash
--posix), dash, zsh 5.9, ksh 93u+m, mksh and busybox ash with a script
that writes a marker.
`export f=run.py; python3 "$f"` and `readonly f=run.py; python3 "$f"`
run the script in every shell, but neither builtin bound anything in the
walk, so both scored 0.0. `export` and `readonly` now bind as `f=run.py`
does; `declare` binds in bash and zsh, and `typeset` also in ksh and
mksh; where a shell lacks one the command fails and binds nothing, so
`sh -c` (dash on some systems, bash --posix on others, ash on Alpine) is
walked under all three and disagreement is unresolved. A value is
expanded when the builtin runs, since an assignment copies a value and
is not an alias: `f=other.py; export g=$f; f=run.py; python3 "$g"` runs
other.py. With several names, bash expands every value before assigning
any and ksh assigns in order. `+x` and `export -n` take the export away
where the shell accepts them, also after `command`, `command -p` or
`builtin`, in any number, where those reach the builtin (zsh's `command`
does not). `-f` and `-p` touch no variable, and any other option
(`declare -u` upper-cases the value) leaves it unsettled; with no value,
bash leaves the value as it was. An attribute that changes what a later
assignment stores stays with the name until `unset` or a `+` option
removes it: `-u` leaves a later value unsettled (whether `RUN.PY` names
the script depends on the file system), `-l` lowercases it, and an array
keeps its value in this shell but is never exported to a child. With
`-i` a value is evaluated, and one that is not a number there
(`declare -i f; f=run.py`) is an error at which bash exits, as every
shell with `typeset` does for most forms (bash goes on after a prefix,
ksh after `typeset`), so nothing after it is credited. After
`declare -n f=g` (`nameref f=g` in ksh and mksh), assigning, exporting,
unexporting, reading into or unsetting `f` acts on `g`, which is
unsettled afterwards whether or not the text bound it; `+n`,
`unset -n` and a second `-n` free or re-point `f` and leave `g` alone.
`local` outside a function binds in zsh and mksh only and the walk does
not track function bodies, so its value is unsettled. `unset f` empties
it.
`read`, `mapfile`, `getopts` and `printf -v` bind from data the text
does not carry, so their names are unsettled. Reading the script stays
uncredited: `export f=run.py; cat "$f"` is 0.0.
`python3 <<A <<B run.py`, with A's body then B's, runs the script, but
only the first heredoc on the header was consumed: `<<B run.py` stayed
in the command's words and operand extraction stopped at it. Every
heredoc declared on a line, across commands joined on that line
included, now takes its body after the line ends, in the order declared,
as all six shells do up to the number each accepts on a line: bash exits
at 17 ("maximum here-document count exceeded") and mksh stops at 11,
before running anything on the line; the others read 60 and more. Past
the shell's limit, and past 256 heredoc and here-string operators in one
command (a bound on the work), the line and everything after it are
data. The same gap walked the second body as commands, so `cat <<A <<B`
whose B body holds `python3 run.py` scored 1.0 for a line that is data;
it is now unresolved, like any script named in data. So is a ninth body,
which the previous limit of eight operators walked as commands. The
shared tokenizer turns every newline into a separator, quoted ones too,
so a heredoc inside a `-c` payload lost its lines and its body was
walked as commands: a `bash -c` payload running `cat <<EOF` with
`python3 run.py` as the body scored 1.0 and runs nothing. Within this
walk a quoted newline is now kept and restored for the payload's shell,
so the body is data there as well.
A here-string is a syntax error in dash and busybox ash, which then run
nothing on its line nor any of a compound command spanning lines around
it (measured), so under those readings nothing in such a text is
credited: `dash -c 'cat <<< x; python3 run.py'` is unresolved rather
than 1.0.
Found alongside, false positives in 190f4ce unless noted:
- An assignment written before a command is that command's environment
only. It is not seen by the command's own words and does not outlive
it, so `f=run.py python3 "$f"` and `f=run.py true; python3 "$f"` run
python3 with an empty argument, yet both scored 1.0. `env f=run.py`
is the same. Before a special builtin (`f=run.py :`) the assignment
outlives the command in the POSIX shells, bash --posix among them,
and not in bash or zsh; that is read per shell.
- A `-c` payload's shell sees what it inherits: the exported names
(`export`, `declare -x`, and anything bound while `set -a` is on, which
stays exported after `set +a`), its command's own prefix, and what each
`env` before it removes (`-i`, `-`, `-u NAME`, their long forms and
clusters) and adds (`NAME=value`), in order; after `env -S` or `sudo`
a payload that reads a variable is unresolved. The walk substituted
this shell's bindings into a single-quoted payload, so
`f=run.py; bash -c 'python3 "$f"'` scored 1.0 though the child never
sees an unexported `f`. A `$` inside single quotes or escaped is now
marked literal before tokenizing (within this walk only; the shared
tokenizer and the other checks are unchanged) and the payload is
walked with the inherited names, so
`export f=run.py; bash -c 'python3 "$f"'` is 1.0, the unexported form
and `export f=run.py; env -u f bash -c 'python3 "$f"'` 0.0. A `$` left
unquoted is expanded by this shell first, a name it never bound to
nothing, so `bash -c "f=run.py; python3 \"$f\""` (1.0 before) runs
python3 with an empty argument and is 0.0. A payload
that reads a variable is walked even when it does not name the script
itself, since the command around it does.
- An assignment to a read-only name fails. A bare one stops every shell
(bash abandons the rest of its line); bash goes on after the other
forms, ksh after a prefix, and dash, zsh, mksh and ash stop after most
of them (the table is in the code). Where the shell stops, nothing
after the failure is credited, so `readonly f=run.py; f=other.py;
python3 run.py`, which scored 1.0 and runs nothing, is unresolved. A
subshell stops alone. A special builtin given an option the shell
rejects (`export -n` in dash, ksh and mksh, `unset -n` in dash, mksh
and ash) stops a POSIX shell the same way unless `command` runs it;
bash and zsh go on.
- `let`, `$((...))` and `$[...]` assign as `((...))` does, and the walk
read only `((...))`: `f=run.py; let f=1; python3 "$f"` scored 1.0 and
runs `python3 1`. A variable that held the script now ends unsettled
(a number, or unchanged after an error), as it already did after
`((...))`. `$((` reaches the walk as `$ ( (`, which it reads as
groups, so the assignment is applied to the scope around them; a
subshell or pipeline stage keeps its own.
- Text read a second time can expand a `$` this shell left quoted.
`eval` reads its words in this shell with the command's prefix in
effect, after this shell has expanded them, and a name it may bind is
unsettled after it, so `f=run.py; eval f=other.py; python3 "$f"` (1.0,
runs nothing) is unresolved, and so is `code='export -n f'; eval
"$code"` before a child that reads `f`. Where eval's text is not
settled here (a command substitution, a value the text cannot settle),
every bound name is unsettled. Inline code and a shell reading a
heredoc or here-string get the command's environment, and an unquoted
heredoc body is expanded here, so where a variable in such text holds
the script the command is unresolved (these were 0.0 on commands that
ran).
- The tokenizer hands `(((` over as one token, which was split into
three subshells. bash, zsh and mksh read it as `( ((`, so in
`f=other.py; (((for f in run.py; do :; done; python3 "$f")) | cat)` the
inner `((...))` is arithmetic and runs nothing; ksh and dash read
nested subshells and run the script. Found by `--compose` on seed 7.
The differential harness gains 319 curated shapes for all of the above
(842 in total, each executed for real) and a generator class for them.
On seeds 20260928 and 7, each with 3000 generated and 3000 composed
commands (6749 and 6724 executed): no false positive, no false
negative, no host/verifier divergence, no partial without a reference.
Against f65d468 (`--baseline`), 277 and 264 scores move: none
lowered on a command that ran; 132 and 122 false positives and 111
and 98 false negatives repaired; the rest are unsettled readings
(0.0 to 0.75) on text a shell settles differently, from data the text
does not carry, after an `eval` or a `-n` name that may change it,
past a shell's heredoc limit, or beside a here-string the shell rejects,
and unresolved readings that became 1.0 on commands that ran.
tests/tier3/test_script_invocation_evidence.py gains 490 tests over
both implementations; 262 fail at f65d468 and the rest are
controls. 1462 pass, as does all of tests/tier3 on Python 3.12 and
3.13; ruff check and format are clean.
Limitations, unchanged in kind: control-flow conditions are not
evaluated, a short-circuited `&&` chain is credited, and a redirection
the shell rejects at run time is credited. A variable the text never
binds is read as empty, as the harness's `env -i` shell has it. A
function body is read where it is written, not where it is called, and
readers the walk has no grammar for (`trap`, `find -exec`, a pipe into a
shell, a file written and then run) are not followed. A value read
through a `-n` name, or given under `declare -u`, stays unresolved even
where the command runs, and a `-i` value that is not a number is read
as an error even where it happens to evaluate (`read` data).
Signed-off-by: mavericksea-ai <maverickaisea@gmail.com>
* fix(tier3): read a compound's opening word after an assignment as the shell does, and never raise on it
190f4ce read a loop word written after an assignment as a loop header,
while the scope scanner, rightly, opened no loop there. With an empty list
the walk then looked for a closing word that was never recorded, and
check_script_execution raised IndexError instead of returning a score:
`LANG=C for g in; do python3 run.py; done`, or
`f=x for g in; do echo; done; python3 run.py`. The exception reached
score_skill_execution in both the host checker and the bundled verifier.
A compound's opening word is reserved only where a command starts. After
an assignment, bash, bash --posix, dash, zsh, ksh, mksh and busybox ash all
refuse it with the compound's own syntax (for, select, while, until, if,
case, `{`, `(`, `[[` and `((`), so the line runs nothing, though some
shells run the lines before it. The loop header is now read only where the
scanner opened a loop, and a text holding such a word credits nothing, as a
here-string does under dash: an invocation there is 0.75 and a
non-invocation stays 0.0. Before 190f4ce these commands scored 1.0 without
running, and the rest of the family still did at 6812810. `A=(` and `A=$(`
reach the scan as an array and a substitution and are unaffected.
A test feeds every prefix and every single-character deletion of twenty
representative commands through both implementations and requires a score
from each. The differential harness now lists a command on which the
--baseline checker raises as a move rather than stopping.
Signed-off-by: mavericksea-ai <maverickaisea@gmail.com>
* fix(tier3): credit the first command a shell ran before a line it refuses, and read a native call under the shell it names
4594693 applied a refusal to the whole tool call, so a command completed
on an earlier line lost its credit: `python3 run.py` followed on the next
line by `A=1 for g in x; do :; done` scored 0.75 in both the host checker
and the bundled verifier, though bash and dash run run.py before
rejecting the second line.
bash, bash --posix, dash, ksh, mksh and busybox ash parse and run a text
one complete command at a time; zsh parses the whole of a -c text first,
so a refusal anywhere in it runs nothing. Measured with `python3 run.py`
on the line before each refused form, and before `cat <<< x` under dash
and ash. A command ends at an unquoted newline, outside a comment and a
heredoc body, once every compound it opens is closed and the line does
not end on `|`, `&&`, `||` or a function's name awaiting its body.
Under every reading but zsh, the first command of the text is credited
on its own when a later one is refused, and only when it is a plain
pipeline: words and complete redirections joined by `|`, with no
reserved word, group or assignment where a command starts, no
parenthesis, `&&`, `||`, substitution, here-string, carriage return or
escaped newline, and no -c payload. Nothing ran before it, so no command
the walk does not model can have stopped it (`exit`, `exec true`,
`set -n` and `kill $$` before `python3 run.py` each run nothing), and a
line refused for a reason the walk does not detect is not credited:
`python3 run.py >`, `python3 run.py; fi`, `python3 run.py (x)` and
`python3 run.py` ending in a carriage return run nothing in any
modelled shell. Anything else before a refused line, including an
uncalled function (`f() {`, `python3 run.py`, `}`), stays 0.75, as at
4594693. A -c payload with a refused line stays 0.75 too: its text is
what the tokenizer left of it, where a carriage return reads as a
line's end.
check_script_execution read every command under bash rules. A native call
can name its shell: Codex's exec_command keeps `shell`, such as /bin/zsh,
in its arguments. Under zsh the last stage of a pipeline runs in the
current shell, so `printf "" | for f in run.py; do :; done; python3 "$f"`
runs run.py, but it scored 0.0. The name, without its directory, a .exe
suffix or a version number, is now passed to the walk as a -c payload's
shell already was: zsh and ksh keep the last stage's bindings, dash has
no here-string, `declare` or arithmetic command, and sh is walked as
dash, bash --posix and ash, with disagreement unresolved. A call that
names no shell is read as bash, as before. A shell outside the modelled
ones reads the text by rules the walk does not know, so a command there
that names the script is unresolved rather than given a definite score.
The differential harness executes each native-shell case with the shell
it names and passes the name through, and scores the lines around a
refused one even though the shell reports a syntax error.
Signed-off-by: mavericksea-ai <maverickaisea@gmail.com>
* fix(tier3): avoid shell marker boundary scan false positive
Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com>
* fix(tier3): read export -p and readonly -p given names as each shell does
_apply_binding_builtin read every ``-p`` as a listing that changes no
variable. Measured with a marker in bash, bash --posix, dash, zsh, ksh,
mksh and busybox ash: given names, ``export -p`` and ``readonly -p`` act on
them as they do without ``-p`` in bash, bash --posix, ksh, mksh and ash,
and list only when no name is given. So ``export f=run.py; export -p
f=other.py; python3 "$f"`` runs other.py there, ``export -p f=run.py``
binds and exports run.py, and ``f=run.py; readonly -p f`` makes f
read-only. dash and zsh list the names and change nothing. ``declare -p``
and ``typeset -p`` only list in bash and zsh, whatever else is given with
them; ksh's ``typeset -p`` and mksh's ``typeset -px`` assign, and are read
as unsettled. A redirection and its operand are not a builtin's operands:
``export -p > f=other.py`` writes the listing to a file named f=other.py
and binds nothing, and a plain ``export > f=other.py`` was misread the
same way. Only a word that is wholly a redirection operator is read as
one, as the tokenizer leaves an unquoted operator, so ``export g='>'
f=run.py`` binds both names. ksh refuses ``unset`` given no name and
stops, which ``unset > f`` now is.
The same line read ``-f`` and ``-F`` as naming functions in every shell.
ksh's ``typeset -f f=run.py`` assigns, and ``-F`` is a float attribute in
zsh and ksh; both are now read as the shell does or left unsettled. A
numeric attribute (``-i``, ``-F``, ``-E``) given to a name whose value is
not a number stops zsh and ksh, whether the value is given with it or
held: ``f=run.py; typeset -i f; python3 run.py`` runs nothing there. A
decimal, ``0x10`` or ``16#ff`` (a base from 2 to 36, its leading zeros
dropped as both shells drop them) is a number there; an expression is
not evaluated. A base is not converted until it is known to be short,
so a malformed one of thousands of digits gets a score, not the
ValueError int() raises past 4,300 digits.
A width given with ``-L``, ``-R`` or ``-Z``, in the word or as the next
one, cuts or pads the value at once in zsh, ksh and mksh, so
``f=run.py; typeset -L3 f; python3 "$f"`` runs ``run`` and the name is
unsettled.
The differential harness executes the new cases under each shell it names,
and its fuzzing draws on ``-p`` forms.
Signed-off-by: mavericksea-ai <maverickaisea@gmail.com>
---------
Signed-off-by: mavericksea-ai <274285725+mavericksea-ai@users.noreply.github.com>
Signed-off-by: mavericksea-ai <maverickaisea@gmail.com>
Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com>
Co-authored-by: Narendran Raghavan <32655573+rng1995@users.noreply.github.com>
Co-authored-by: Narendran Raghavan <nraghavan@nvidia.com>