* fix: use ~/.agent-browser for socket files instead of TMPDIR This fixes issue #163 where different TMPDIR values (common with tmux/screen/VSCode/IntelliJ) caused the CLI and daemon to use different socket paths. Socket directory priority: 1. AGENT_BROWSER_SOCKET_DIR (explicit override) 2. $XDG_RUNTIME_DIR/agent-browser (Linux standard) 3. ~/.agent-browser (fallback, like Docker Desktop) Both CLI (Rust) and daemon (Node.js) now use the same logic. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: session list now looks in correct socket directory - Make get_socket_dir() public in connection.rs - Update session list to use get_socket_dir() instead of temp_dir() - Update pid file pattern from agent-browser-{session}.pid to {session}.pid - Add tmpdir fallback to daemon.ts when homedir is unavailable Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test: add unit tests for socket directory resolution Add comprehensive tests for get_socket_dir/getSocketDir to verify: - AGENT_BROWSER_SOCKET_DIR takes priority - Empty strings are ignored (fixes Rust/TypeScript consistency) - XDG_RUNTIME_DIR fallback works correctly - Home directory fallback when env vars unset Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
import * as os from 'os';
|
|
import * as path from 'path';
|
|
import { getSocketDir } from './daemon.js';
|
|
|
|
describe('getSocketDir', () => {
|
|
const originalEnv = { ...process.env };
|
|
|
|
beforeEach(() => {
|
|
// Clear relevant env vars before each test
|
|
delete process.env.AGENT_BROWSER_SOCKET_DIR;
|
|
delete process.env.XDG_RUNTIME_DIR;
|
|
});
|
|
|
|
afterEach(() => {
|
|
// Restore original env
|
|
process.env = { ...originalEnv };
|
|
});
|
|
|
|
describe('AGENT_BROWSER_SOCKET_DIR', () => {
|
|
it('should use custom path when set', () => {
|
|
process.env.AGENT_BROWSER_SOCKET_DIR = '/custom/socket/path';
|
|
expect(getSocketDir()).toBe('/custom/socket/path');
|
|
});
|
|
|
|
it('should ignore empty string', () => {
|
|
process.env.AGENT_BROWSER_SOCKET_DIR = '';
|
|
const result = getSocketDir();
|
|
expect(result).toContain('.agent-browser');
|
|
});
|
|
|
|
it('should take priority over XDG_RUNTIME_DIR', () => {
|
|
process.env.AGENT_BROWSER_SOCKET_DIR = '/custom/path';
|
|
process.env.XDG_RUNTIME_DIR = '/run/user/1000';
|
|
expect(getSocketDir()).toBe('/custom/path');
|
|
});
|
|
});
|
|
|
|
describe('XDG_RUNTIME_DIR', () => {
|
|
it('should use when AGENT_BROWSER_SOCKET_DIR is not set', () => {
|
|
process.env.XDG_RUNTIME_DIR = '/run/user/1000';
|
|
expect(getSocketDir()).toBe('/run/user/1000/agent-browser');
|
|
});
|
|
|
|
it('should ignore empty string', () => {
|
|
process.env.AGENT_BROWSER_SOCKET_DIR = '';
|
|
process.env.XDG_RUNTIME_DIR = '';
|
|
const result = getSocketDir();
|
|
expect(result).toContain('.agent-browser');
|
|
});
|
|
});
|
|
|
|
describe('fallback', () => {
|
|
it('should use home directory when env vars are not set', () => {
|
|
const result = getSocketDir();
|
|
const expected = path.join(os.homedir(), '.agent-browser');
|
|
expect(result).toBe(expected);
|
|
});
|
|
});
|
|
});
|