fix: preserve telegram proxy on gateway restart after doctor (#546)
Co-authored-by: zuolingxuan <zuolingxuan@bytedance.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
e10ff3a1fb
commit
56701d823c
89
tests/unit/openclaw-proxy.test.ts
Normal file
89
tests/unit/openclaw-proxy.test.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
const {
|
||||
readOpenClawConfigMock,
|
||||
writeOpenClawConfigMock,
|
||||
withConfigLockMock,
|
||||
} = vi.hoisted(() => ({
|
||||
readOpenClawConfigMock: vi.fn(),
|
||||
writeOpenClawConfigMock: vi.fn(),
|
||||
withConfigLockMock: vi.fn(async (fn: () => Promise<unknown>) => await fn()),
|
||||
}));
|
||||
|
||||
vi.mock('@electron/utils/channel-config', () => ({
|
||||
readOpenClawConfig: readOpenClawConfigMock,
|
||||
writeOpenClawConfig: writeOpenClawConfigMock,
|
||||
}));
|
||||
|
||||
vi.mock('@electron/utils/config-mutex', () => ({
|
||||
withConfigLock: withConfigLockMock,
|
||||
}));
|
||||
|
||||
vi.mock('@electron/utils/logger', () => ({
|
||||
logger: {
|
||||
info: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
error: vi.fn(),
|
||||
debug: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
describe('syncProxyConfigToOpenClaw', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('preserves existing telegram proxy on startup-style sync when proxy is disabled', async () => {
|
||||
readOpenClawConfigMock.mockResolvedValue({
|
||||
channels: {
|
||||
telegram: {
|
||||
botToken: 'token',
|
||||
proxy: 'socks5://127.0.0.1:7891',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const { syncProxyConfigToOpenClaw } = await import('@electron/utils/openclaw-proxy');
|
||||
|
||||
await syncProxyConfigToOpenClaw({
|
||||
proxyEnabled: false,
|
||||
proxyServer: '',
|
||||
proxyHttpServer: '',
|
||||
proxyHttpsServer: '',
|
||||
proxyAllServer: '',
|
||||
proxyBypassRules: '',
|
||||
});
|
||||
|
||||
expect(writeOpenClawConfigMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('clears telegram proxy when explicitly requested while proxy is disabled', async () => {
|
||||
readOpenClawConfigMock.mockResolvedValue({
|
||||
channels: {
|
||||
telegram: {
|
||||
botToken: 'token',
|
||||
proxy: 'socks5://127.0.0.1:7891',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const { syncProxyConfigToOpenClaw } = await import('@electron/utils/openclaw-proxy');
|
||||
|
||||
await syncProxyConfigToOpenClaw({
|
||||
proxyEnabled: false,
|
||||
proxyServer: '',
|
||||
proxyHttpServer: '',
|
||||
proxyHttpsServer: '',
|
||||
proxyAllServer: '',
|
||||
proxyBypassRules: '',
|
||||
}, {
|
||||
preserveExistingWhenDisabled: false,
|
||||
});
|
||||
|
||||
expect(writeOpenClawConfigMock).toHaveBeenCalledTimes(1);
|
||||
const updatedConfig = writeOpenClawConfigMock.mock.calls[0][0] as {
|
||||
channels: { telegram: Record<string, unknown> };
|
||||
};
|
||||
expect(updatedConfig.channels.telegram.proxy).toBeUndefined();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user