fix(tmux): preserve configured fallback port
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -3,7 +3,7 @@ import { describe, test, expect, mock, beforeEach, spyOn, afterAll } from 'bun:t
|
|||||||
import type { TmuxConfig } from '../../config/schema'
|
import type { TmuxConfig } from '../../config/schema'
|
||||||
import type { WindowState, PaneAction } from './types'
|
import type { WindowState, PaneAction } from './types'
|
||||||
import type { ActionResult, ExecuteContext } from './action-executor'
|
import type { ActionResult, ExecuteContext } from './action-executor'
|
||||||
import type { TmuxUtilDeps } from './manager'
|
import type { TmuxSessionManager as TmuxSessionManagerType, TmuxUtilDeps } from './manager'
|
||||||
import * as sharedModule from '../../shared'
|
import * as sharedModule from '../../shared'
|
||||||
|
|
||||||
type ExecuteActionsResult = {
|
type ExecuteActionsResult = {
|
||||||
@@ -287,24 +287,67 @@ describe('TmuxSessionManager', () => {
|
|||||||
|
|
||||||
test('falls back to default port when serverUrl has port 0', async () => {
|
test('falls back to default port when serverUrl has port 0', async () => {
|
||||||
// given
|
// given
|
||||||
mockIsInsideTmux.mockReturnValue(true)
|
const previousOpenCodePort = process.env.OPENCODE_PORT
|
||||||
const { TmuxSessionManager } = await import('./manager')
|
delete process.env.OPENCODE_PORT
|
||||||
const ctx = {
|
let manager: TmuxSessionManagerType | undefined
|
||||||
...createMockContext(),
|
try {
|
||||||
serverUrl: new URL('http://127.0.0.1:0/'),
|
mockIsInsideTmux.mockReturnValue(true)
|
||||||
}
|
const { TmuxSessionManager } = await import('./manager')
|
||||||
const config = createTmuxConfig({ enabled: true,
|
const ctx = {
|
||||||
layout: 'main-vertical',
|
...createMockContext(),
|
||||||
main_pane_size: 60,
|
serverUrl: new URL('http://127.0.0.1:0/'),
|
||||||
main_pane_min_width: 80,
|
}
|
||||||
agent_pane_min_width: 40, })
|
const config = createTmuxConfig({ enabled: true,
|
||||||
|
layout: 'main-vertical',
|
||||||
|
main_pane_size: 60,
|
||||||
|
main_pane_min_width: 80,
|
||||||
|
agent_pane_min_width: 40, })
|
||||||
|
|
||||||
// when
|
// when
|
||||||
const manager = new TmuxSessionManager(ctx, config, mockTmuxDeps)
|
manager = new TmuxSessionManager(ctx, config, mockTmuxDeps)
|
||||||
|
} finally {
|
||||||
|
if (previousOpenCodePort === undefined) {
|
||||||
|
delete process.env.OPENCODE_PORT
|
||||||
|
} else {
|
||||||
|
process.env.OPENCODE_PORT = previousOpenCodePort
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect((manager as any).serverUrl).toBe('http://localhost:4096')
|
expect((manager as any).serverUrl).toBe('http://localhost:4096')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('falls back to configured OPENCODE_PORT when serverUrl has port 0', async () => {
|
||||||
|
// given
|
||||||
|
const previousOpenCodePort = process.env.OPENCODE_PORT
|
||||||
|
process.env.OPENCODE_PORT = '5678'
|
||||||
|
let manager: TmuxSessionManagerType | undefined
|
||||||
|
try {
|
||||||
|
mockIsInsideTmux.mockReturnValue(true)
|
||||||
|
const { TmuxSessionManager } = await import('./manager')
|
||||||
|
const ctx = {
|
||||||
|
...createMockContext(),
|
||||||
|
serverUrl: new URL('http://127.0.0.1:0/'),
|
||||||
|
}
|
||||||
|
const config = createTmuxConfig({ enabled: true,
|
||||||
|
layout: 'main-vertical',
|
||||||
|
main_pane_size: 60,
|
||||||
|
main_pane_min_width: 80,
|
||||||
|
agent_pane_min_width: 40, })
|
||||||
|
|
||||||
|
// when
|
||||||
|
manager = new TmuxSessionManager(ctx, config, mockTmuxDeps)
|
||||||
|
} finally {
|
||||||
|
if (previousOpenCodePort === undefined) {
|
||||||
|
delete process.env.OPENCODE_PORT
|
||||||
|
} else {
|
||||||
|
process.env.OPENCODE_PORT = previousOpenCodePort
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect((manager as any).serverUrl).toBe('http://localhost:5678')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('onSessionCreated', () => {
|
describe('onSessionCreated', () => {
|
||||||
@@ -1989,7 +2032,7 @@ describe('TmuxSessionManager', () => {
|
|||||||
const cleanupPromise = manager.cleanup()
|
const cleanupPromise = manager.cleanup()
|
||||||
|
|
||||||
// then
|
// then
|
||||||
await expect(cleanupPromise).resolves.toBeUndefined()
|
expect(await cleanupPromise).toBeUndefined()
|
||||||
expect(mockKillTmuxSessionIfExists).toHaveBeenCalledTimes(1)
|
expect(mockKillTmuxSessionIfExists).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -72,7 +72,8 @@ export class TmuxSessionManager {
|
|||||||
this.client = ctx.client
|
this.client = ctx.client
|
||||||
this.tmuxConfig = tmuxConfig
|
this.tmuxConfig = tmuxConfig
|
||||||
this.deps = deps
|
this.deps = deps
|
||||||
const fallbackUrl = "http://localhost:4096"
|
const defaultPort = process.env.OPENCODE_PORT ?? "4096"
|
||||||
|
const fallbackUrl = `http://localhost:${defaultPort}`
|
||||||
const rawServerUrl = ctx.serverUrl?.toString()
|
const rawServerUrl = ctx.serverUrl?.toString()
|
||||||
try {
|
try {
|
||||||
if (rawServerUrl) {
|
if (rawServerUrl) {
|
||||||
|
|||||||
Reference in New Issue
Block a user