fix: use shellParse for cmd tokenization to match genValidationFile#173
Open
memosr wants to merge 1 commit into
Open
fix: use shellParse for cmd tokenization to match genValidationFile#173memosr wants to merge 1 commit into
memosr wants to merge 1 commit into
Conversation
src/lib/genValidationFile.ts tokenizes the forge command with shellParse
from shell-quote before storing it in the JSON config — correctly handling
quoted arguments like --sig "run()".
src/lib/validation-service.ts then read that same cmd field back and
re-tokenized with cfg.cmd.trim().split(/\\s+/), a naive whitespace split.
For auto-generated configs this happened to work because genValidationFile
strips quotes before joining. But the README example shows manually
authored configs that include shell-quoted args:
"cmd": "forge script ... --sig \"run()\""
The naive whitespace split passes \"run()\" (with quotes) as the --sig
value to spawn, not run(). The forge invocation then fails to find any
function matching the literal quoted string, producing an opaque error
unrelated to the actual problem.
Replaced the naive split with shellParse from the same shell-quote
package already imported in genValidationFile. Filtered the result to
plain string tokens, since shell-quote returns OpEntry objects for shell
operators (|, ;, >, etc.) that have no meaning when spawning forge
directly.
Both the write path (genValidationFile) and the read path
(validation-service) now use the same tokenizer, so any cmd string that
round-trips through the JSON config is parsed identically.
Collaborator
🟡 Heimdall Review Status
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
genValidationFilewrites thecmdfield usingshellParse, butvalidation-servicereads it back with a naive whitespace split. This produces wrong arguments toforgefor manually authored configs that follow the README's example syntax.The drift
Write path —
src/lib/genValidationFile.tsusesshellParsefromshell-quoteto tokenize the forge command before storing it. This correctly handles quoted arguments like--sig "run()".Read path —
src/lib/validation-service.ts:94reads the samecmdfield back with:A naive whitespace split. The two paths use different tokenizers for the same string.
Why it appears to work
For auto-generated configs,
genValidationFilestrips quotes before joining the arguments, so the storedcmdhappens to have no quotes — and a naive split works.Where it breaks
The README's documented example shows manually authored configs with shell-quoted args:
{ "cmd": "forge script ... --sig \"run()\"" }Running this through
cfg.cmd.trim().split(/\s+/)produces argv tokens including the literal"run()"with quotes preserved.spawn('forge', [..., '--sig', '"run()"', ...])passes the quoted string to forge, which then can't find a function matching that literal.The error surfaces as "function not found" — completely opaque, with no hint that the actual problem is in the tokenizer mismatch.
The fix
Uses
shellParsefrom the sameshell-quotepackage already imported ingenValidationFile. The.filter()is needed becauseshell-quotereturnsOpEntryobjects for shell operators (|,;,>, etc.) that have no meaning when spawningforgedirectly — we want only plain string tokens.Now both the write path and the read path use the same tokenizer. Any
cmdstring that round-trips through the JSON config is parsed identically on both sides.Verification
src/lib/validation-service.tsgenValidationFile).filter()ensures only string tokens reachspawn()