-
Notifications
You must be signed in to change notification settings - Fork 10.3k
fix(runtimes): reach a working agent CLI past a broken shim #7153
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
Open
lefarcen
wants to merge
3
commits into
main
Choose a base branch
from
fix/dsh-version-compat
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 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
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,110 @@ | ||
| import { chmodSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'; | ||
| import { tmpdir } from 'node:os'; | ||
| import path from 'node:path'; | ||
| import { afterEach, beforeEach, describe, expect, it } from 'vitest'; | ||
| import { detectAgent } from '../../src/runtimes/detection.js'; | ||
| import type { RuntimeAgentDef } from '../../src/runtimes/types.js'; | ||
|
|
||
| // A minimal agent def: no compatibility probe, so these cases isolate the | ||
| // binary-resolution stage from the profile handshake that `deepseek-harness` | ||
| // layers on top of it. | ||
| const def: RuntimeAgentDef = { | ||
| id: 'deepseek-harness', | ||
| name: 'DeepSeek Harness', | ||
| bin: 'dsh', | ||
| versionArgs: ['--version'], | ||
| fallbackModels: [{ id: 'default', label: 'Default' }], | ||
| buildArgs: () => [], | ||
| streamFormat: 'dsh-profile-jsonl', | ||
| }; | ||
|
|
||
| /** | ||
| * A shim that resolves on PATH but cannot be executed: the interpreter its | ||
| * shebang names does not exist, so the spawn fails with ENOENT. This is the | ||
| * shape a half-finished `npm i -g` leaves behind — the wrapper survives, the | ||
| * package it points at does not. | ||
| */ | ||
| function writeBrokenShim(dir: string): string { | ||
| const bin = path.join(dir, 'dsh'); | ||
| writeFileSync(bin, '#!/nonexistent/interpreter\n'); | ||
| chmodSync(bin, 0o755); | ||
| return bin; | ||
| } | ||
|
|
||
| function writeWorkingShim(dir: string, version = '0.1.0-rc.6'): string { | ||
| const bin = path.join(dir, 'dsh'); | ||
| writeFileSync(bin, `#!/bin/sh\nprintf '%s\\n' '${version}'\n`); | ||
| chmodSync(bin, 0o755); | ||
| return bin; | ||
| } | ||
|
|
||
| describe('agent executable resolution falls back past unusable candidates', () => { | ||
| const dirs: string[] = []; | ||
| let savedPath: string | undefined; | ||
| let savedAgentHome: string | undefined; | ||
| let savedDshBin: string | undefined; | ||
|
|
||
| beforeEach(() => { | ||
| savedPath = process.env.PATH; | ||
| savedAgentHome = process.env.OD_AGENT_HOME; | ||
| savedDshBin = process.env.DSH_BIN; | ||
| delete process.env.DSH_BIN; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| if (savedPath === undefined) delete process.env.PATH; | ||
| else process.env.PATH = savedPath; | ||
| if (savedAgentHome === undefined) delete process.env.OD_AGENT_HOME; | ||
| else process.env.OD_AGENT_HOME = savedAgentHome; | ||
| if (savedDshBin === undefined) delete process.env.DSH_BIN; | ||
| else process.env.DSH_BIN = savedDshBin; | ||
| while (dirs.length > 0) { | ||
| rmSync(dirs.pop() as string, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| function tempDir(label: string): string { | ||
| const dir = mkdtempSync(path.join(tmpdir(), `od-exec-fallback-${label}-`)); | ||
| dirs.push(dir); | ||
| return dir; | ||
| } | ||
|
|
||
| // The production report behind this suite: a stale `npm i -g` wrapper sat in | ||
| // a directory that OpenDesign searches *before* the one the official | ||
| // installer writes to, so the working CLI was never reached and the agent | ||
| // vanished from the picker entirely. | ||
| it('reaches a working binary that sits behind a broken one on PATH', async () => { | ||
| if (process.platform === 'win32') return; | ||
| const brokenDir = tempDir('broken'); | ||
| const goodDir = tempDir('good'); | ||
| writeBrokenShim(brokenDir); | ||
| const goodBin = writeWorkingShim(goodDir); | ||
|
|
||
| process.env.OD_AGENT_HOME = goodDir; | ||
| process.env.PATH = [brokenDir, goodDir].join(path.delimiter); | ||
|
|
||
| const detected = await detectAgent(def); | ||
|
|
||
| expect(detected.available).toBe(true); | ||
| expect(detected.path).toBe(goodBin); | ||
| expect(detected.version).toBe('0.1.0-rc.6'); | ||
| }); | ||
|
|
||
| // Even when every candidate is unusable, detection must surface the path it | ||
| // actually tried. The picker hides an agent that reports no path at all, so | ||
| // dropping it leaves the user with an invisible agent and no way to act. | ||
| it('keeps the attempted path when no candidate can be executed', async () => { | ||
| if (process.platform === 'win32') return; | ||
| const brokenDir = tempDir('only-broken'); | ||
| const brokenBin = writeBrokenShim(brokenDir); | ||
|
|
||
| process.env.OD_AGENT_HOME = brokenDir; | ||
| process.env.PATH = brokenDir; | ||
|
|
||
| const detected = await detectAgent(def); | ||
|
|
||
| expect(detected.available).toBe(false); | ||
| expect(detected.path).toBe(brokenBin); | ||
| expect(detected.diagnostics?.[0]?.reason).toBe('shim-broken'); | ||
| }); | ||
| }); |
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.