* Unify workspace service proxying * Clean up service proxy review issues
175 lines
5.7 KiB
TypeScript
175 lines
5.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import type { WorkspaceScriptPayload } from "@getpaseo/protocol/messages";
|
|
import type { ActiveConnection } from "@/runtime/host-runtime";
|
|
import { resolveWorkspaceScriptLink } from "./workspace-script-links";
|
|
|
|
const runningService: WorkspaceScriptPayload = {
|
|
scriptName: "web",
|
|
type: "service",
|
|
hostname: "web--feature--paseo.localhost",
|
|
port: 3000,
|
|
localProxyUrl: "http://web--feature--paseo.localhost:6767",
|
|
publicProxyUrl: null,
|
|
proxyUrl: "http://web--feature--paseo.localhost:6767",
|
|
lifecycle: "running",
|
|
health: "healthy",
|
|
exitCode: null,
|
|
terminalId: null,
|
|
};
|
|
|
|
function resolveLink(activeConnection: ActiveConnection | null) {
|
|
return resolveWorkspaceScriptLink({
|
|
script: runningService,
|
|
activeConnection,
|
|
});
|
|
}
|
|
|
|
describe("resolveWorkspaceScriptLink", () => {
|
|
it("uses the local proxy URL for loopback TCP connections", () => {
|
|
expect(
|
|
resolveLink({ type: "directTcp", endpoint: "localhost:6767", display: "localhost:6767" }),
|
|
).toEqual({
|
|
openUrl: "http://web--feature--paseo.localhost:6767",
|
|
labelUrl: "http://web--feature--paseo.localhost:6767",
|
|
});
|
|
});
|
|
|
|
it("uses the local proxy URL for socket and pipe connections", () => {
|
|
expect(
|
|
resolveLink({ type: "directSocket", endpoint: "/tmp/paseo.sock", display: "socket" }),
|
|
).toEqual({
|
|
openUrl: "http://web--feature--paseo.localhost:6767",
|
|
labelUrl: "http://web--feature--paseo.localhost:6767",
|
|
});
|
|
});
|
|
|
|
it("degrades to daemon-host plus service port for direct network connections", () => {
|
|
expect(
|
|
resolveLink({
|
|
type: "directTcp",
|
|
endpoint: "mac-mini.tail123.ts.net:6767",
|
|
display: "mac-mini.tail123.ts.net:6767",
|
|
}),
|
|
).toEqual({
|
|
openUrl: "http://mac-mini.tail123.ts.net:3000",
|
|
labelUrl: "http://mac-mini.tail123.ts.net:3000",
|
|
});
|
|
});
|
|
|
|
it("shows the local proxy URL but disables opening over relay", () => {
|
|
expect(
|
|
resolveLink({ type: "relay", endpoint: "relay.paseo.sh:443", display: "relay" }),
|
|
).toEqual({
|
|
openUrl: null,
|
|
labelUrl: "http://web--feature--paseo.localhost:6767",
|
|
});
|
|
});
|
|
|
|
it("opens the public URL over relay when one is provided", () => {
|
|
expect(
|
|
resolveWorkspaceScriptLink({
|
|
script: {
|
|
...runningService,
|
|
publicProxyUrl: "https://web--feature--paseo.services.example.com",
|
|
proxyUrl: "https://web--feature--paseo.services.example.com",
|
|
},
|
|
activeConnection: { type: "relay", endpoint: "relay.paseo.sh:443", display: "relay" },
|
|
}),
|
|
).toEqual({
|
|
openUrl: "https://web--feature--paseo.services.example.com",
|
|
labelUrl: "https://web--feature--paseo.services.example.com",
|
|
});
|
|
});
|
|
|
|
it("uses local URL for direct loopback even when public URL exists", () => {
|
|
expect(
|
|
resolveWorkspaceScriptLink({
|
|
script: {
|
|
...runningService,
|
|
publicProxyUrl: "https://web--feature--paseo.services.example.com",
|
|
proxyUrl: "https://web--feature--paseo.services.example.com",
|
|
},
|
|
activeConnection: { type: "directTcp", endpoint: "127.0.0.1:6767", display: "localhost" },
|
|
}),
|
|
).toEqual({
|
|
openUrl: "http://web--feature--paseo.localhost:6767",
|
|
labelUrl: "http://web--feature--paseo.localhost:6767",
|
|
});
|
|
});
|
|
|
|
it("uses local URL for direct socket and pipe even when public URL exists", () => {
|
|
expect(
|
|
resolveWorkspaceScriptLink({
|
|
script: {
|
|
...runningService,
|
|
publicProxyUrl: "https://web--feature--paseo.services.example.com",
|
|
proxyUrl: "https://web--feature--paseo.services.example.com",
|
|
},
|
|
activeConnection: { type: "directPipe", endpoint: "paseo", display: "pipe" },
|
|
}),
|
|
).toEqual({
|
|
openUrl: "http://web--feature--paseo.localhost:6767",
|
|
labelUrl: "http://web--feature--paseo.localhost:6767",
|
|
});
|
|
});
|
|
|
|
it("uses public URL for direct remote TCP when split URLs exist", () => {
|
|
expect(
|
|
resolveWorkspaceScriptLink({
|
|
script: {
|
|
...runningService,
|
|
publicProxyUrl: "https://web--feature--paseo.services.example.com",
|
|
proxyUrl: "https://web--feature--paseo.services.example.com",
|
|
},
|
|
activeConnection: {
|
|
type: "directTcp",
|
|
endpoint: "mac-mini.tail123.ts.net:6767",
|
|
display: "remote",
|
|
},
|
|
}),
|
|
).toEqual({
|
|
openUrl: "https://web--feature--paseo.services.example.com",
|
|
labelUrl: "https://web--feature--paseo.services.example.com",
|
|
});
|
|
});
|
|
|
|
it("keeps old daemon local-only proxyUrl payloads working", () => {
|
|
const {
|
|
localProxyUrl: _localProxyUrl,
|
|
publicProxyUrl: _publicProxyUrl,
|
|
...oldPayload
|
|
} = runningService;
|
|
|
|
expect(
|
|
resolveWorkspaceScriptLink({
|
|
script: oldPayload,
|
|
activeConnection: { type: "directTcp", endpoint: "localhost:6767", display: "localhost" },
|
|
}),
|
|
).toEqual({
|
|
openUrl: "http://web--feature--paseo.localhost:6767",
|
|
labelUrl: "http://web--feature--paseo.localhost:6767",
|
|
});
|
|
});
|
|
|
|
it("keeps old daemon public proxyUrl payloads working over relay", () => {
|
|
const {
|
|
localProxyUrl: _localProxyUrl,
|
|
publicProxyUrl: _publicProxyUrl,
|
|
...oldPayload
|
|
} = {
|
|
...runningService,
|
|
proxyUrl: "https://web--feature--paseo.services.example.com",
|
|
};
|
|
|
|
expect(
|
|
resolveWorkspaceScriptLink({
|
|
script: oldPayload,
|
|
activeConnection: { type: "relay", endpoint: "relay.paseo.sh:443", display: "relay" },
|
|
}),
|
|
).toEqual({
|
|
openUrl: "https://web--feature--paseo.services.example.com",
|
|
labelUrl: "https://web--feature--paseo.services.example.com",
|
|
});
|
|
});
|
|
});
|