Repository navigation
mcpx: shebang-first interpreter dispatch + script.interpreter + script.cwd (#2167) #2611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
cf21abc
mcpx: shebang-first interpreter dispatch + script.interpreter + scrip…
dezren39 2cd0551
fix(mcpx): address Codex findings on the shebang dispatch PR (#2167)
dezren39 534a14a
fix(mcpx): honour env shebang options -u and -i (#2167)
dezren39 98367b9
fix(mcpx): review findings on the shebang dispatch PR (#2167)
283126b
mcpx: shebang -C and PATH assignments honoured on both dispatch paths…
dezren39 38b556e
fix(mcpx): resolve shebang interpreters after choosing cwd (#2167)
dezren39 3819dd4
Merge remote-tracking branch 'origin/main' into queue/3201-2167-sheba…
dezren39 2742f41
Merge remote-tracking branch 'origin/main' into queue/3201-2167-sheba…
dezren39 52dbf17
fix(mcpx): honour env terminator assignments, raw -S payloads, empty …
dezren39 031db4d
mcpx: fix the four Codex P2s on the shebang dispatch PR (#2611)
dezren39 4fff16a
WIP: disposition CodeRabbit round on 031db4d4 (#2167)
a5dbbe0
Merge origin/main into queue/3201-2167-shebang-dispatch
dezren39 05b113e
fix(mcpx): disposition the CodeRabbit round on the dispatch PR (#2167)
39240a4
fix(mcpx): disposition the two Codex P2s on the dispatch PR (#2167)
fd64ab0
fix(mcpx): keep backslashes literal in single-quoted env -S payloads …
910a64b
Merge remote-tracking branch 'origin/main' into queue/3201-2167-sheba…
dezren39 bdd9231
mcpx: env -S splitter + workdir dispatch — 4 Codex findings (PR #2611)
dezren39 631b3a8
mcpx: lease dispatched workdirs + empty unquoted env expansions start…
dezren39 0847133
Merge remote-tracking branch 'origin/main' into queue/3201-2167-sheba…
dezren39 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package cli | ||
|
|
||
| // A snippet's own shebang must survive the prefix splice: dispatch reads | ||
| // the first line to pick the interpreter, and a prefix line in front of a | ||
| // shebang sent a valid shell snippet to the JavaScript harness (#2611 | ||
| // review). | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestInlineSourceKeepsAShebangFirst(t *testing.T) { | ||
| sh := scriptShape{prefix: []string{`echo before`}} | ||
| got := sh.inlineSource([]string{"#!/bin/sh\necho hello"}) | ||
| if !strings.HasPrefix(got, "#!/bin/sh\n") { | ||
| t.Fatalf("the snippet's shebang must stay on line 1:\n%s", got) | ||
| } | ||
| if !strings.Contains(got, "echo before") || !strings.Contains(got, "echo hello") { | ||
| t.Fatalf("prefix and body must both survive:\n%s", got) | ||
| } | ||
| } | ||
|
|
||
| func TestInlineSourceWithoutShebangIsUnchanged(t *testing.T) { | ||
| sh := scriptShape{prefix: []string{"const a = 1"}, suffix: []string{"const b = 2"}} | ||
| got := sh.inlineSource([]string{"console.log(1)"}) | ||
| want := "const a = 1\nconsole.log(1)\nconst b = 2" | ||
| if got != want { | ||
| t.Errorf("got %q, want %q", got, want) | ||
| } | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package e2e_test | ||
|
|
||
| // Effect probes for the dispatch settings (#2167): the two knobs that | ||
| // decide whether a script runs under an interpreter and where it runs | ||
| // must reach the CLI from the environment like every other setting, or | ||
| // the settings registry entry is decoration. | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| // MCPX_SCRIPT_INTERPRETER makes `mcpx exec` run the source under that | ||
| // command line instead of a JavaScript runtime. The source is not a | ||
| // TypeScript program, so without the setting the run cannot produce | ||
| // this output. | ||
| func TestScriptInterpreterIsReachableFromTheEnvironment(t *testing.T) { | ||
| e := newEnv(t, oneServer) | ||
| saved := e.envVars | ||
| e.envVars = append(append([]string{}, saved...), "MCPX_SCRIPT_INTERPRETER=sh") | ||
| defer func() { e.envVars = saved }() | ||
|
|
||
| out := e.run("exec", "echo from-the-configured-interpreter") | ||
| if !strings.Contains(out, "from-the-configured-interpreter") { | ||
| t.Fatalf("MCPX_SCRIPT_INTERPRETER should run the source under sh:\n%s", out) | ||
| } | ||
| } | ||
|
|
||
| // MCPX_SCRIPT_CWD=script moves a dispatched run to the script's own | ||
| // directory; the default (caller) leaves it where mcpx was invoked, so | ||
| // the two are distinguishable from the script's own pwd. | ||
| func TestScriptCwdIsReachableFromTheEnvironment(t *testing.T) { | ||
| e := newEnv(t, oneServer) | ||
| sub := filepath.Join(e.dir, "scripts") | ||
| if err := os.MkdirAll(sub, 0o755); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| script := filepath.Join(sub, "where.sh") | ||
| if err := os.WriteFile(script, []byte("#!/bin/sh\npwd\n"), 0o755); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| saved := e.envVars | ||
| e.envVars = append(append([]string{}, saved...), "MCPX_SCRIPT_CWD=script") | ||
| defer func() { e.envVars = saved }() | ||
|
|
||
| out := e.run("run", script) | ||
| // The dispatch notice shares the stream; the script's pwd is the | ||
| // last line it printed. | ||
| lines := strings.Split(strings.TrimSpace(out), "\n") | ||
| got, _ := filepath.EvalSymlinks(strings.TrimSpace(lines[len(lines)-1])) | ||
| want, _ := filepath.EvalSymlinks(sub) | ||
| if got != want { | ||
| t.Fatalf("MCPX_SCRIPT_CWD=script: pwd = %q, want %q\n%s", got, want, out) | ||
| } | ||
| } |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.