Pass recipe arguments to their scripts as data
Cause
just substitutes a {{param}} into the recipe's shell line as text before the
shell runs it. lab trigger-flow ran bash "{{engine}}" trigger-flow "{{project}}" "{{goal}}" {{rest}},
so a goal of Fix `make` ran make on the host, and $(...) or a " did the same.
Flow goals are prose that often carries markdown backticks, so ordinary use reaches it.
Unquoted variadics (up, geo, test, vale-check) also split, expanded and globbed.
Mechanism
flowchart LR
A["goal argument<br/>Fix `make`"] --> B{"recipe body"}
B -->|"main: {{goal}}"| C["just splices the text<br/>into the shell line"]
C --> D["sh -c parses it:<br/>backtick runs make on the host"]
B -->|"fix: positional-arguments, "$2""| E["sh gets the line unchanged<br/>and the goal as $2"]
E --> F["engine argv holds the goal<br/>byte for byte, one word"]
F --> G["engine hands it on as a<br/>base64 Ruby literal or shell_quote"]Coverage
94 recipes across the root justfile, the skill justfile with its lab and
contrib modules, and publish.just; 61 take parameters and 57 bodies
interpolated one. RUN means the canary file was created; MAN means the argument
arrived split, expanded or globbed. Results on main:
| Recipe | backtick | $(cmd) |
"; cmd; " |
'; cmd; ' |
newline | $VAR |
glob |
|---|---|---|---|---|---|---|---|
lab trigger-flow goal, trigger-preflight goal, enable-flow, license, seed, runner-docker-auth user, runner-tls-ca, drift-check |
RUN | RUN | RUN | ok | ok | MAN | ok |
lab trigger-flow rest, up, geo; root test, vale-check, word-budget |
RUN | RUN | MAN | MAN | RUN | MAN | MAN |
root tag-notes-check |
ok | ok | ok | RUN | ok | ok | ok |
lab ssh-cmd, lab default, contrib draft, publish (already quote() or "$@") |
ok | ok | ok | ok | ok | ok | ok |
Every cell is ok on this branch.
The engine had the same flaw one hop on. gitlab_rails_file put each value in a
Ruby %q{}, so a } in a goal ended the literal, and inline Ruby, gitlab_rake
and runner-docker-auth put values in single quotes. The remote vm_ssh command
strings built from up and dev flags stay as they are: they run on the
operator's own VM from the operator's own flags.
Fix
- Every just file sets
positional-arguments, the formcontrib.justalready used, and every recipe passes"$1"or"$@". No body interpolates a parameter. Usage strings and benign behaviour are unchanged. simulation.shaddsruby_str, a base64 Ruby literal, for values reaching Rails, and usesshell_quotefor the rake task and the runner-docker-auth values.tests/recipe-arguments.sh, run byjust test, drives the real just files against stub scripts that record argv: 7 payloads × 19 recipes, a variadic word-split case, a default case, and a static check that fails any recipe body interpolating a parameter. Onmain: 122 failed. Here: 271 passed.engine-selftest.shchecks a goal reaches Rails, rake and runner config byte for byte. Withmain's engine it fails 7; here it passes.