Download packages/app/src/utils/terminal-websocket-url.test.ts from SaylorTwift/opencode: direct link, hf CLI and curl.
- Browser
- Download file 2.65 kB
-
https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/app/src/utils/terminal-websocket-url.test.ts
- Command line
-
hf download hf://SaylorTwift/opencode/packages/app/src/utils/terminal-websocket-url.test.ts
-
curl -L -o terminal-websocket-url.test.ts https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/app/src/utils/terminal-websocket-url.test.ts
2.65 kB
| import { describe, expect, test } from "bun:test" | |
| import { terminalWebSocketURL } from "./terminal-websocket-url" | |
| describe("terminalWebSocketURL", () => { | |
| test("uses the current ticketed PTY route", () => { | |
| const url = terminalWebSocketURL({ | |
| url: "http://127.0.0.1:49365", | |
| id: "pty_test", | |
| directory: "/tmp/project", | |
| cursor: 0, | |
| ticket: "connect-ticket", | |
| }) | |
| expect(url.protocol).toBe("ws:") | |
| expect(url.username).toBe("") | |
| expect(url.password).toBe("") | |
| expect(url.pathname).toBe("/api/pty/pty_test/connect") | |
| expect(url.searchParams.get("location[directory]")).toBe("/tmp/project") | |
| expect(url.searchParams.get("cursor")).toBe("0") | |
| expect(url.searchParams.get("ticket")).toBe("connect-ticket") | |
| expect(url.searchParams.has("auth_token")).toBe(false) | |
| }) | |
| test("uses query auth without embedding credentials in websocket URL for v1", () => { | |
| const url = terminalWebSocketURL({ | |
| protocol: "v1", | |
| url: "http://127.0.0.1:49365", | |
| id: "pty_test", | |
| directory: "/tmp/project", | |
| cursor: 0, | |
| sameOrigin: false, | |
| username: "opencode", | |
| password: "secret", | |
| }) | |
| expect(url.protocol).toBe("ws:") | |
| expect(url.username).toBe("") | |
| expect(url.password).toBe("") | |
| expect(url.pathname).toBe("/pty/pty_test/connect") | |
| expect(url.searchParams.get("directory")).toBe("/tmp/project") | |
| expect(url.searchParams.get("auth_token")).toBe(btoa("opencode:secret")) | |
| }) | |
| test("omits query auth for same-origin saved credentials for v1", () => { | |
| const url = terminalWebSocketURL({ | |
| protocol: "v1", | |
| url: "https://app.example.test", | |
| id: "pty_test", | |
| directory: "/tmp/project", | |
| cursor: 10, | |
| sameOrigin: true, | |
| username: "opencode", | |
| password: "secret", | |
| }) | |
| expect(url.protocol).toBe("wss:") | |
| expect(url.pathname).toBe("/pty/pty_test/connect") | |
| expect(url.searchParams.get("directory")).toBe("/tmp/project") | |
| expect(url.searchParams.has("auth_token")).toBe(false) | |
| }) | |
| test("uses query auth for same-origin credentials from auth_token for v1", () => { | |
| const url = terminalWebSocketURL({ | |
| protocol: "v1", | |
| url: "https://app.example.test", | |
| id: "pty_test", | |
| directory: "/tmp/project", | |
| cursor: 10, | |
| sameOrigin: true, | |
| username: "opencode", | |
| password: "secret", | |
| authToken: true, | |
| }) | |
| expect(url.protocol).toBe("wss:") | |
| expect(url.pathname).toBe("/pty/pty_test/connect") | |
| expect(url.searchParams.get("directory")).toBe("/tmp/project") | |
| expect(url.searchParams.get("auth_token")).toBe(btoa("opencode:secret")) | |
| }) | |
| }) | |