fix(desktop): Workspace HTML previews (render view and new window) (#189)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Yaowei ZhengandClaude Fable 5 authored and GitHub committed 2026-08-04 18:10:46 +08:00
1 parent d312d368b8
commit e015d9e591
7 files changed
+108 -4

No files matched your search

+18
View File
@@ -3,6 +3,7 @@ import {
appOriginFor,
desktopLoginUrl,
isAppUrl,
isLocalSurfaceUrl,
parsePortFile,
restartDelayMs,
} from "../src/util.js";
@@ -42,6 +43,23 @@ describe("isAppUrl", () => {
});
});
describe("isLocalSurfaceUrl", () => {
const origin = "http://localhost:7364";
it("accepts the app origin and its loopback counterpart on the same port", () => {
// The counterpart is where Workspace previews are served: a preview window must be
// able to reach it, which the stricter app-origin rule would deny.
expect(isLocalSurfaceUrl("http://localhost:7364/chat", origin)).toBe(true);
expect(isLocalSurfaceUrl("http://127.0.0.1:7364/preview/tok/x.html", origin)).toBe(true);
});
it("rejects other ports, other hosts, other schemes, and junk", () => {
expect(isLocalSurfaceUrl("http://127.0.0.1:7365/preview/x", origin)).toBe(false);
expect(isLocalSurfaceUrl("http://example.com:7364/", origin)).toBe(false);
expect(isLocalSurfaceUrl("https://localhost:7364/", origin)).toBe(false);
expect(isLocalSurfaceUrl("not a url", origin)).toBe(false);
expect(isLocalSurfaceUrl("http://localhost:7364/", null)).toBe(false);
});
});
describe("restartDelayMs", () => {
it("doubles from 1s and caps at 8s", () => {
expect([0, 1, 2, 3, 4].map(restartDelayMs)).toEqual([1000, 2000, 4000, 8000, 8000]);