fix(tmux): validate 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:
@@ -348,6 +348,38 @@ describe('TmuxSessionManager', () => {
|
||||
// then
|
||||
expect((manager as any).serverUrl).toBe('http://localhost:5678')
|
||||
})
|
||||
|
||||
test('ignores invalid OPENCODE_PORT when serverUrl has port 0', async () => {
|
||||
// given
|
||||
const previousOpenCodePort = process.env.OPENCODE_PORT
|
||||
process.env.OPENCODE_PORT = 'not-a-port'
|
||||
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:4096')
|
||||
})
|
||||
})
|
||||
|
||||
describe('onSessionCreated', () => {
|
||||
|
||||
@@ -72,7 +72,11 @@ export class TmuxSessionManager {
|
||||
this.client = ctx.client
|
||||
this.tmuxConfig = tmuxConfig
|
||||
this.deps = deps
|
||||
const defaultPort = process.env.OPENCODE_PORT ?? "4096"
|
||||
const configuredPort = process.env.OPENCODE_PORT
|
||||
const parsedPort = configuredPort ? Number(configuredPort) : 4096
|
||||
const defaultPort = Number.isInteger(parsedPort) && parsedPort > 0 && parsedPort <= 65535
|
||||
? String(parsedPort)
|
||||
: "4096"
|
||||
const fallbackUrl = `http://localhost:${defaultPort}`
|
||||
const rawServerUrl = ctx.serverUrl?.toString()
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user