mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-26 02:24:43 +00:00
fix(app): derive terminal WebSocket URL from browser origin instead o… (#12178)
This commit is contained in:
36
packages/app/src/components/terminal-url.test.ts
Normal file
36
packages/app/src/components/terminal-url.test.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import { ptySocketUrl } from "./terminal-url"
|
||||
|
||||
describe("ptySocketUrl", () => {
|
||||
test("uses browser host instead of sdk host", () => {
|
||||
const url = ptySocketUrl("http://localhost:4096", "pty_1", "/repo", {
|
||||
host: "192.168.1.50:4096",
|
||||
protocol: "http:",
|
||||
})
|
||||
expect(url.toString()).toBe("ws://192.168.1.50:4096/pty/pty_1/connect?directory=%2Frepo")
|
||||
})
|
||||
|
||||
test("uses secure websocket on https", () => {
|
||||
const url = ptySocketUrl("http://localhost:4096", "pty_1", "/repo", {
|
||||
host: "opencode.local",
|
||||
protocol: "https:",
|
||||
})
|
||||
expect(url.toString()).toBe("wss://opencode.local/pty/pty_1/connect?directory=%2Frepo")
|
||||
})
|
||||
|
||||
test("preserves browser port", () => {
|
||||
const url = ptySocketUrl("http://localhost:4096", "pty_1", "/repo", {
|
||||
host: "opencode.local:8443",
|
||||
protocol: "https:",
|
||||
})
|
||||
expect(url.toString()).toBe("wss://opencode.local:8443/pty/pty_1/connect?directory=%2Frepo")
|
||||
})
|
||||
|
||||
test("handles slash base url", () => {
|
||||
const url = ptySocketUrl("/", "pty_1", "/repo", {
|
||||
host: "192.168.1.50:4096",
|
||||
protocol: "http:",
|
||||
})
|
||||
expect(url.toString()).toBe("ws://192.168.1.50:4096/pty/pty_1/connect?directory=%2Frepo")
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user