-
Notifications
You must be signed in to change notification settings - Fork 424
fix(v2): detect MSYS2 bash from native toolchain git exec paths #1590
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
+118
−5
Merged
Changes from all commits
Commits
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,5 @@ | ||
| --- | ||
| "@moonshot-ai/kimi-code": patch | ||
| --- | ||
|
|
||
| Fix bash auto-detection on Windows in the experimental v2 engine when git comes from a native MSYS2 toolchain (ucrt64/clang64/clangarm64). |
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
100 changes: 100 additions & 0 deletions
100
packages/agent-core-v2/test/_base/execEnv/environmentProbe.test.ts
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,100 @@ | ||
| /** | ||
| * Host environment probe — MSYS2 bash detection. | ||
| * | ||
| * Pins the Windows shell probe against native MSYS2 toolchains: a git whose | ||
| * `git --exec-path` reports an `ucrt64` / `clang64` / `clangarm64` prefix | ||
| * (e.g. `C:/msys64/ucrt64/libexec/git-core`) must walk back to the MSYS2 root | ||
| * and resolve the shared bash at `usr\bin\bash.exe`, instead of failing to | ||
| * detect any shell. | ||
| * | ||
| * All tests expect `probeHostEnvironment()` to be a pure function of injected | ||
| * platform probes (no ambient state) so the same suite runs identically on | ||
| * macOS/Linux/Windows CI runners. | ||
| * | ||
| * Ported from `packages/kaos/test/environment.test.ts` (the MSYS2 cases added | ||
| * by the bash-detection fix); the v1 file carries the full POSIX / Git for | ||
| * Windows / Scoop shim matrix, which the vendored probe shares verbatim. | ||
| */ | ||
|
|
||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { | ||
| probeHostEnvironment, | ||
| type HostEnvironmentProbeDeps, | ||
| } from '#/_base/execEnv/environmentProbe'; | ||
|
|
||
| interface StubOpts { | ||
| readonly platform: string; | ||
| readonly env?: Record<string, string | undefined>; | ||
| readonly existingPaths?: readonly string[]; | ||
| readonly execFileResults?: Readonly<Record<string, string>>; | ||
| } | ||
|
|
||
| /** Build a stub deps bag mimicking Node's `os` + `process` surface. */ | ||
| function stubDeps(opts: StubOpts): HostEnvironmentProbeDeps { | ||
| const existing = new Set(opts.existingPaths ?? []); | ||
| return { | ||
| platform: opts.platform, | ||
| arch: 'x86_64', | ||
| release: '1.2.3', | ||
| homeDir: 'C:\\Users\\me', | ||
| env: opts.env ?? {}, | ||
| isFile: async (path: string) => existing.has(path), | ||
| execFileText: async (file: string, args: readonly string[]) => | ||
| opts.execFileResults?.[execFileKey(file, args)], | ||
| }; | ||
| } | ||
|
|
||
| function execFileKey(file: string, args: readonly string[]): string { | ||
| return [file, ...args].join('\0'); | ||
| } | ||
|
|
||
| describe('probeHostEnvironment', () => { | ||
| it('resolves MSYS2 ucrt64 native git through git --exec-path', async () => { | ||
| const gitExe = 'C:\\msys64\\ucrt64\\bin\\git.exe'; | ||
| const env = await probeHostEnvironment( | ||
| stubDeps({ | ||
| platform: 'win32', | ||
| env: { PATH: 'C:\\msys64\\ucrt64\\bin' }, | ||
| execFileResults: { | ||
| [execFileKey(gitExe, ['--exec-path'])]: 'C:/msys64/ucrt64/libexec/git-core\n', | ||
| }, | ||
| existingPaths: [gitExe, 'C:\\msys64\\usr\\bin\\bash.exe'], | ||
| }), | ||
| ); | ||
| expect(env.shellName).toBe('bash'); | ||
| expect(env.shellPath).toBe('C:\\msys64\\usr\\bin\\bash.exe'); | ||
| }); | ||
|
|
||
| it('resolves MSYS2 clang64 native git through git --exec-path', async () => { | ||
| const gitExe = 'C:\\msys64\\clang64\\bin\\git.exe'; | ||
| const env = await probeHostEnvironment( | ||
| stubDeps({ | ||
| platform: 'win32', | ||
| env: { PATH: 'C:\\msys64\\clang64\\bin' }, | ||
| execFileResults: { | ||
| [execFileKey(gitExe, ['--exec-path'])]: 'C:/msys64/clang64/libexec/git-core\n', | ||
| }, | ||
| existingPaths: [gitExe, 'C:\\msys64\\usr\\bin\\bash.exe'], | ||
| }), | ||
| ); | ||
| expect(env.shellName).toBe('bash'); | ||
| expect(env.shellPath).toBe('C:\\msys64\\usr\\bin\\bash.exe'); | ||
| }); | ||
|
|
||
| it('resolves MSYS2 clangarm64 native git through git --exec-path', async () => { | ||
| const gitExe = 'C:\\msys64\\clangarm64\\bin\\git.exe'; | ||
| const env = await probeHostEnvironment( | ||
| stubDeps({ | ||
| platform: 'win32', | ||
| env: { PATH: 'C:\\msys64\\clangarm64\\bin' }, | ||
| execFileResults: { | ||
| [execFileKey(gitExe, ['--exec-path'])]: 'C:/msys64/clangarm64/libexec/git-core\n', | ||
| }, | ||
| existingPaths: [gitExe, 'C:\\msys64\\usr\\bin\\bash.exe'], | ||
| }), | ||
| ); | ||
| expect(env.shellName).toBe('bash'); | ||
| expect(env.shellPath).toBe('C:\\msys64\\usr\\bin\\bash.exe'); | ||
| }); | ||
| }); | ||
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.
packages/agent-core-v2/AGENTS.mdsays comments in this package should not "note porting / skeleton status"; this new header adds provenance about being ported from the kaos suite instead of describing only the test scenario/responsibility. Please drop the porting note or move any necessary rationale into the commit/PR text rather than the source header.Useful? React with 👍 / 👎.