diff --git a/integrations/dsh/src/environment/host/manager.ts b/integrations/dsh/src/environment/host/manager.ts index ca8ff5e0..fe6fa821 100644 --- a/integrations/dsh/src/environment/host/manager.ts +++ b/integrations/dsh/src/environment/host/manager.ts @@ -316,6 +316,17 @@ export class ReMeEnvManager { workspaceDir: string; authToken?: string; }): Promise { + // Only a root-path loopback endpoint can become a local service. A + // configured gateway prefix (or a remote URL) is probed elsewhere, and a + // start could at best fail after stopping a same-origin service: skip it + // instead of reporting a failure on every DSH start. + let launchable = false; + try { + launchable = this.launchable(this.endpoint(options.endpoint)); + } catch { + launchable = false; + } + if (!launchable) return; const status = await this.serviceStatus( options.endpoint, options.authToken ?? "", diff --git a/integrations/dsh/tests/env-manager.test.mjs b/integrations/dsh/tests/env-manager.test.mjs index f91c9cc3..507fb580 100644 --- a/integrations/dsh/tests/env-manager.test.mjs +++ b/integrations/dsh/tests/env-manager.test.mjs @@ -80,6 +80,41 @@ test("serializes concurrent starts into one service launch", async (t) => { assert.equal(second.alreadyRunning, true); }); +test("auto-start only attempts a launch for a local root-path endpoint", async (t) => { + const { manager, calls, directory } = managerIn(t); + const workspace = join(directory, "workspace"); + const statuses = []; + manager.serviceStatus = async (endpoint) => { + statuses.push(endpoint); + return { + phase: "stopped", + managed: false, + endpoint, + logPath: join(directory, "service.log"), + }; + }; + + // A gateway prefix cannot be launched, so auto-start does not even probe it + // for a start: it could only fail after stopping a same-origin service, and + // would report a failure on every DSH start. + await manager.autoStart({ + endpoint: "http://127.0.0.1:2334/reme", + pythonPath: "D:\\env\\python.exe", + workspaceDir: workspace, + }); + assert.deepEqual(statuses, []); + assert.equal(calls.spawn.length, 0); + + // A root-path endpoint is auto-started as before. + await manager.autoStart({ + endpoint: "http://127.0.0.1:2334", + pythonPath: "D:\\env\\python.exe", + workspaceDir: workspace, + }); + assert.ok(statuses.length > 0); + assert.equal(calls.spawn.length, 1); +}); + test("a failed spawn can be retried immediately", async (t) => { const { manager, calls, directory, io } = managerIn(t); io.spawnService = async (options) => {