源码快照 @ 2026-09-02 (source-only, 剔除非源码素材)

This commit is contained in:
agent-radar
2026-09-02 01:05:41 +08:00
commit 04bac1f6e2
2200 changed files with 489415 additions and 0 deletions
@@ -0,0 +1,60 @@
import { afterEach, describe, expect, test } from "bun:test";
import { canCreateWorkspaces } from "../src/app/lib/workspace-creation-policy";
const originalWindow = globalThis.window;
function installWindow(options: {
origin: string;
gateway?: boolean;
electronInfo?: {
baseUrl: string;
ownerToken: string;
};
}) {
Object.defineProperty(globalThis, "window", {
configurable: true,
value: {
addEventListener: () => undefined,
removeEventListener: () => undefined,
location: { origin: options.origin },
__OPENWORK_GATEWAY__: options.gateway ? { version: 1 } : undefined,
__OPENWORK_ELECTRON__: options.electronInfo
? {
invokeDesktop: async () => ({
running: true,
baseUrl: options.electronInfo?.baseUrl,
ownerToken: options.electronInfo?.ownerToken,
}),
}
: undefined,
},
});
}
afterEach(() => {
Object.defineProperty(globalThis, "window", {
configurable: true,
value: originalWindow,
});
});
describe("workspace creation policy", () => {
test("disables workspace creation in gateway runtime", () => {
installWindow({ origin: "https://web.openworklabs.com", gateway: true });
expect(canCreateWorkspaces()).toBe(false);
});
test("allows workspace creation in plain web runtime", () => {
installWindow({ origin: "https://self-hosted.example" });
expect(canCreateWorkspaces()).toBe(true);
});
test("allows workspace creation in desktop runtime", () => {
installWindow({
origin: "http://localhost:3000",
electronInfo: { baseUrl: "http://localhost:8787", ownerToken: "owner-token" },
});
expect(canCreateWorkspaces()).toBe(true);
});
});