Revert "fix: pr-bug-scan findings from #1565" (#1634)

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Jinjing 2026-05-09 16:52:34 -07:00 committed by GitHub
parent cd30a335d1
commit 2e1a3ab17a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 7 additions and 79 deletions

View File

@ -23,7 +23,7 @@ const {
vi.mock('electron', () => ({
app: { on: vi.fn(), removeListener: vi.fn() },
BrowserWindow: browserWindowMock,
ipcMain: { on: vi.fn(), removeListener: vi.fn() },
ipcMain: { on: vi.fn(), removeListener: vi.fn(), handle: vi.fn(), removeHandler: vi.fn() },
Menu: { buildFromTemplate: buildFromTemplateMock },
nativeTheme: { shouldUseDarkColors: false },
screen: {
@ -63,6 +63,8 @@ describe('createMainWindow', () => {
isMock.dev = false
vi.mocked(ipcMain.on).mockReset()
vi.mocked(ipcMain.removeListener).mockReset()
vi.mocked(ipcMain.handle).mockReset()
vi.mocked(ipcMain.removeHandler).mockReset()
vi.useRealTimers()
})

View File

@ -1496,8 +1496,7 @@ export function useComposerState(options: UseComposerStateOptions): UseComposerS
agent,
draft: quickDraftPrompt,
cmdOverrides: settings?.agentCmdOverrides ?? {},
platform: CLIENT_PLATFORM,
windowsShell: settings?.terminalWindowsShell
platform: CLIENT_PLATFORM
})
let startupPlan: ReturnType<typeof buildAgentStartupPlan> = null
@ -1590,7 +1589,6 @@ export function useComposerState(options: UseComposerStateOptions): UseComposerS
resolvedSetupDecision,
selectedRepo,
settings?.agentCmdOverrides,
settings?.terminalWindowsShell,
settings?.rightSidebarOpenByDefault,
setRightSidebarOpen,
setRightSidebarTab,

View File

@ -286,8 +286,7 @@ export async function launchWorkItemDirect(args: LaunchWorkItemDirectArgs): Prom
agent: effectiveAgent,
draft: draftContent,
cmdOverrides: settings?.agentCmdOverrides ?? {},
platform: CLIENT_PLATFORM,
windowsShell: settings?.terminalWindowsShell
platform: CLIENT_PLATFORM
})
if (draftLaunchPlan) {
startupPlan = {

View File

@ -194,60 +194,6 @@ describe('buildAgentDraftLaunchPlan', () => {
})
})
it('uses cmd.exe syntax to clear the pi prefill var when Windows shell is cmd', () => {
expect(
buildAgentDraftLaunchPlan({
agent: 'pi',
draft: 'https://github.com/acme/repo/issues/42',
cmdOverrides: {},
platform: 'win32',
windowsShell: 'cmd.exe'
})
).toEqual({
agent: 'pi',
launchCommand: 'pi; set "ORCA_PI_PREFILL="',
expectedProcess: 'pi',
env: { ORCA_PI_PREFILL: 'https://github.com/acme/repo/issues/42' }
})
})
it('uses Remove-Item Env: to clear the pi prefill var on PowerShell', () => {
// Why: `set "FOO="` is cmd-only; PowerShell parses it as the Set-Variable
// alias and never clears the env var, so re-running pi re-prefills with
// the stale URL. Use the portable PowerShell form instead.
expect(
buildAgentDraftLaunchPlan({
agent: 'pi',
draft: 'https://github.com/acme/repo/issues/42',
cmdOverrides: {},
platform: 'win32',
windowsShell: 'powershell.exe'
})
).toEqual({
agent: 'pi',
launchCommand: 'pi; Remove-Item Env:ORCA_PI_PREFILL -ErrorAction SilentlyContinue',
expectedProcess: 'pi',
env: { ORCA_PI_PREFILL: 'https://github.com/acme/repo/issues/42' }
})
})
it('treats pwsh.exe as PowerShell for the prefill clear-var', () => {
expect(
buildAgentDraftLaunchPlan({
agent: 'pi',
draft: 'https://github.com/acme/repo/issues/42',
cmdOverrides: {},
platform: 'win32',
windowsShell: 'pwsh.exe'
})
).toEqual({
agent: 'pi',
launchCommand: 'pi; Remove-Item Env:ORCA_PI_PREFILL -ErrorAction SilentlyContinue',
expectedProcess: 'pi',
env: { ORCA_PI_PREFILL: 'https://github.com/acme/repo/issues/42' }
})
})
it('returns null for an empty draft so callers fall back cleanly', () => {
expect(
buildAgentDraftLaunchPlan({

View File

@ -23,14 +23,6 @@ export type AgentStartupPlan = {
env?: Record<string, string>
}
function isPowerShellLike(shell: string | undefined): boolean {
if (!shell) {
return false
}
const normalized = shell.toLowerCase().replace(/\\/g, '/').split('/').pop() ?? ''
return normalized === 'powershell.exe' || normalized === 'pwsh.exe' || normalized === 'pwsh'
}
function quoteStartupArg(value: string, platform: NodeJS.Platform): string {
if (platform === 'win32') {
return `"${value.replace(/"/g, '""')}"`
@ -141,15 +133,8 @@ export function buildAgentDraftLaunchPlan(args: {
draft: string
cmdOverrides: Partial<Record<TuiAgent, string>>
platform: NodeJS.Platform
/** Why: the post-exit clear-var command differs per Windows shell. cmd.exe
* uses `set "FOO="`, but PowerShell parses that as the `Set-Variable`
* alias and never clears the env var so re-running the agent re-prefills
* with the stale URL. Callers on Windows pass the configured shell
* (`terminalWindowsShell`) so we can emit `Remove-Item Env:FOO` for
* PowerShell/pwsh. POSIX platforms ignore this. */
windowsShell?: string
}): AgentDraftLaunchPlan | null {
const { agent, draft, cmdOverrides, platform, windowsShell } = args
const { agent, draft, cmdOverrides, platform } = args
const config = TUI_AGENT_CONFIG[agent]
const trimmed = draft.trim()
if (!trimmed) {
@ -173,9 +158,7 @@ export function buildAgentDraftLaunchPlan(args: {
// terminal would inherit the stale value and re-prefill with the old URL.
const clearVar =
platform === 'win32'
? isPowerShellLike(windowsShell)
? `Remove-Item Env:${config.draftPromptEnvVar} -ErrorAction SilentlyContinue`
: `set "${config.draftPromptEnvVar}="`
? `set "${config.draftPromptEnvVar}="`
: `unset ${config.draftPromptEnvVar}`
return {
agent,