Repository navigation
perf(tests): reduce Codex fixture startup overhead #2209
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
Alan-TheGentleman
merged 2 commits into
Gentleman-Programming:main
from
dnlrsls:fix/2208-native-session-end-shell
Oct 31, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| package plugin_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "runtime" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
| ) | ||
|
|
||
| func TestCodexHandoffToolGuard(t *testing.T) { | ||
| tools := []string{"engram", "curl", "cat", "dirname", "jq", "date", "touch", "bash"} | ||
| cases := []struct{ name, remove, inject string }{ | ||
| {name: "owned files use one validation subprocess"}, | ||
| {name: "function shadow", inject: "jq() { :; }\n"}, | ||
| {name: "alias shadow", inject: "shopt -s expand_aliases\nalias jq=true\n"}, | ||
| {name: "wrong resolved path", inject: `command() { | ||
| if [ "$1" = -v ] && [ "$2" = jq ]; then printf '/outside/jq\n'; else builtin command "$@"; fi | ||
| } | ||
| `}, | ||
| } | ||
| for _, name := range tools { | ||
| cases = append(cases, struct{ name, remove, inject string }{name: "missing " + name, remove: name}) | ||
| } | ||
| for _, tc := range cases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| cwd := filepath.Join(t.TempDir(), "fixture root with spaces") | ||
| if err := os.Mkdir(cwd, 0700); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| f := newCodexIntentFixture(t) | ||
| env := codexHandoffEnv(t, cwd, "http://127.0.0.1:19437") | ||
| if tc.remove != "" { | ||
| if err := os.Remove(filepath.Join(cwd, "bin", tc.remove)); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| } | ||
| trace := filepath.Join(cwd, "validation-pids") | ||
| bin := codexIntentQuote(filepath.ToSlash(filepath.Join(cwd, "bin"))) | ||
| if f.cygpath != "" { | ||
| bin = "$(" + codexIntentQuote(f.cygpath) + " -u -- " + bin + ")" | ||
| } | ||
| script := "bin=" + bin + "\nexport PATH=\"$bin\"\n" + tc.inject + | ||
| "type() { builtin printf '%s\\n' \"${BASHPID-unavailable}\" >> " + codexIntentQuote(filepath.ToSlash(trace)) + "; builtin type \"$@\"; }\n" + | ||
| codexHandoffToolGuard() + "printf 'accepted\\n'\n" | ||
| ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
| defer cancel() | ||
| cmd := exec.CommandContext(ctx, f.bash, "--noprofile", "--norc", "-p", "-c", script) | ||
| cmd.WaitDelay = time.Second | ||
| cmd.Env, cmd.Dir = env, cwd | ||
| output, err := cmd.CombinedOutput() | ||
| if tc.remove != "" || tc.inject != "" { | ||
| if err == nil || cmd.ProcessState.ExitCode() != 92 || len(output) != 0 { | ||
| t.Fatalf("guard accepted invalid lookup: err=%v output=%q", err, output) | ||
| } | ||
| return | ||
| } | ||
| if err != nil || string(output) != "accepted\n" { | ||
| t.Fatalf("owned tools rejected: %v %q", err, output) | ||
| } | ||
| data, err := os.ReadFile(trace) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| pids := map[string]bool{} | ||
| calls := strings.Fields(string(data)) | ||
| for _, pid := range calls { | ||
| pids[pid] = true | ||
| } | ||
| if len(calls) != len(tools) { | ||
| t.Fatalf("validated %d tools, want %d", len(calls), len(tools)) | ||
| } | ||
| // Legacy macOS Bash lacks BASHPID. All lookup/rejection behavior | ||
| // still runs there; native Windows must expose process identity | ||
| // for the MSYS subprocess-budget regression. | ||
| if pids["unavailable"] && runtime.GOOS != "windows" { | ||
| return | ||
| } | ||
| if pids["unavailable"] || len(pids) != 1 { | ||
| t.Fatalf("validation used %d subprocesses for %d tool checks; want one subprocess and %d checks", len(pids), len(calls), len(tools)) | ||
| } | ||
| }) | ||
| } | ||
| } |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restrict the search to the selected Git installation.
If
C:\tools\Git\cmd\git.exehas no native Bash, this candidate can selectC:\tools\usr\bin\bash.exefrom another installation. The tests then execute that shell instead of rejecting the launcher-only Git installation. (raw.githubusercontent.com)Derive the installation root from the supported
git.exelayout and search only itsusr/bin/bash.exe. Add a test with a Bash executable outside that root.