fix(queue): keep remote host identity stable

This commit is contained in:
Bohdan Triapitsyn
2026-08-22 13:22:42 +03:00
parent 171a03d8f1
commit 049ff52427
3 changed files with 27 additions and 3 deletions
+22 -1
View File
@@ -108,7 +108,7 @@ describe('createConfiguredWebAPIs', () => {
expect(initializeRuntimeEndpoint).toHaveBeenCalledWith({
apiBaseUrl: bootstrap.apiBaseUrl,
runtimeKey: null,
runtimeKey: 'host:host-1',
});
expect(setRuntimeBearerToken).toHaveBeenCalledWith(bootstrap.clientToken);
expect(setRuntimeExtraHeaders).toHaveBeenCalledWith(bootstrap.runtimeHeaders);
@@ -116,6 +116,27 @@ describe('createConfiguredWebAPIs', () => {
expect(opencodeClient.reconnectToRuntimeBaseUrl).toHaveBeenCalled();
});
test('uses the configured desktop host id across changing SSH tunnel URLs', () => {
const current = makeWindow();
current.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__ = {
target: 'remote',
status: 'ok',
hostId: 'ssh-castle',
url: 'http://127.0.0.1:62545',
localAvailable: true,
};
current.__OPENCHAMBER_API_BASE_URL__ = 'http://127.0.0.1:62545';
current.__OPENCHAMBER_LOCAL_ORIGIN__ = 'http://127.0.0.1:3901';
installWindow(current);
createConfiguredWebAPIs();
expect(initializeRuntimeEndpoint).toHaveBeenCalledWith({
apiBaseUrl: 'http://127.0.0.1:62545',
runtimeKey: 'host:ssh-castle',
});
});
test('activates an embedded relay without relying on Electron preload IPC', () => {
const relay = {
relayUrl: 'wss://relay.example.com',
+4 -1
View File
@@ -2,6 +2,7 @@ import { getRuntimeExtraHeadersSync, refreshLocalRuntimeUrlAuthToken, refreshRun
import { installRuntimeFetchBridge } from '@openchamber/ui/lib/runtime-fetch';
import { initializeRuntimeEndpoint, switchRuntimeEndpoint } from '@openchamber/ui/lib/runtime-switch';
import { restoreDesktopRelayRuntime } from '@openchamber/ui/lib/desktopRelayRestore';
import { getInjectedBootOutcome } from '@openchamber/ui/lib/desktopBoot';
import { configureRuntimeUrlResolver } from '@openchamber/ui/lib/runtime-url';
import type { EmbeddedSessionRuntimeBootstrap } from '@openchamber/ui/components/layout/contextPanelEmbeddedChat';
import { opencodeClient } from '@openchamber/ui/lib/opencode/client';
@@ -45,6 +46,8 @@ export const getDesktopRelayRestoreReady = (): Promise<void> => desktopRelayRest
export const createConfiguredWebAPIs = (bootstrap?: EmbeddedSessionRuntimeBootstrap | null) => {
const { apiBaseUrl, clientToken, localOrigin, runtimeHeaders, relayHostId, relay } = bootstrap ?? readRuntimeBootstrapConfig();
const bootOutcome = bootstrap ? null : getInjectedBootOutcome();
const desktopHostId = relayHostId || (bootOutcome?.target === 'remote' ? bootOutcome.hostId : '');
const urls = configureRuntimeUrlResolver({
apiBaseUrl: apiBaseUrl || undefined,
@@ -52,7 +55,7 @@ export const createConfiguredWebAPIs = (bootstrap?: EmbeddedSessionRuntimeBootst
});
initializeRuntimeEndpoint({
apiBaseUrl,
runtimeKey: sameOrigin(apiBaseUrl, localOrigin) ? 'local' : null,
runtimeKey: sameOrigin(apiBaseUrl, localOrigin) ? 'local' : (desktopHostId ? `host:${desktopHostId}` : null),
});
setRuntimeBearerToken(clientToken || null);
setRuntimeExtraHeaders(runtimeHeaders || null);