import { describe, expect, it } from "vitest"; import { adapterSupportsRemoteManagedEnvironments, getEnvironmentCapabilities, isSandboxProviderSupportedForAdapter, supportedEnvironmentDriversForAdapter, } from "./environment-support.js"; describe("isSandboxProviderSupportedForAdapter", () => { it("treats Paperclip Runner as a remote-managed adapter", () => { expect(adapterSupportsRemoteManagedEnvironments("paperclip_runner")).toBe(true); expect(supportedEnvironmentDriversForAdapter("paperclip_runner")).toEqual([ "local", "ssh", "sandbox", "plugin", ]); }); it("accepts additional sandbox providers for remote-managed adapters", () => { expect( isSandboxProviderSupportedForAdapter("codex_local", "fake-plugin", ["fake-plugin"]), ).toBe(true); }); it("rejects providers for adapters without remote-managed environment support", () => { expect( isSandboxProviderSupportedForAdapter("openclaw", "fake-plugin", ["fake-plugin"]), ).toBe(false); }); it("treats grok_local as a remote-managed local adapter", () => { expect(adapterSupportsRemoteManagedEnvironments("grok_local")).toBe(true); expect(supportedEnvironmentDriversForAdapter("grok_local")).toEqual(["local", "ssh", "sandbox"]); expect( isSandboxProviderSupportedForAdapter("grok_local", "fake-plugin", ["fake-plugin"]), ).toBe(true); }); it("includes grok_local sandbox support in environment capabilities", () => { const capabilities = getEnvironmentCapabilities(["grok_local"], { sandboxProviders: { "fake-plugin": { displayName: "Fake Plugin" }, }, }); expect(capabilities.adapters).toEqual([ expect.objectContaining({ adapterType: "grok_local", drivers: expect.objectContaining({ sandbox: "supported", ssh: "supported" }), sandboxProviders: expect.objectContaining({ "fake-plugin": "supported" }), }), ]); }); it("treats kimi_local as a remote-managed local adapter", () => { expect(adapterSupportsRemoteManagedEnvironments("kimi_local")).toBe(true); expect(supportedEnvironmentDriversForAdapter("kimi_local")).toEqual(["local", "ssh", "sandbox"]); expect( isSandboxProviderSupportedForAdapter("kimi_local", "fake-plugin", ["fake-plugin"]), ).toBe(true); }); it("includes kimi_local sandbox support in environment capabilities", () => { const capabilities = getEnvironmentCapabilities(["kimi_local"], { sandboxProviders: { "fake-plugin": { displayName: "Fake Plugin" }, }, }); expect(capabilities.adapters).toEqual([ expect.objectContaining({ adapterType: "kimi_local", drivers: expect.objectContaining({ sandbox: "supported", ssh: "supported" }), sandboxProviders: expect.objectContaining({ "fake-plugin": "supported" }), }), ]); }); }); describe("getEnvironmentCapabilities reusable leases default", () => { it("test_absent_reusable_leases_presents_as_false", () => { const capabilities = getEnvironmentCapabilities(["codex_local"], { sandboxProviders: { // The manifest does not declare supportsReusableLeases. "fake-plugin": { displayName: "Fake Plugin" }, }, }); expect(capabilities.sandboxProviders["fake-plugin"].supportsReusableLeases).toBe(false); // A manifest that declares true still presents as true. const declared = getEnvironmentCapabilities(["codex_local"], { sandboxProviders: { "reuse-plugin": { displayName: "Reuse Plugin", supportsReusableLeases: true }, }, }); expect(declared.sandboxProviders["reuse-plugin"].supportsReusableLeases).toBe(true); // The built-in fake provider presents as false. expect(capabilities.sandboxProviders.fake.supportsReusableLeases).toBe(false); }); }); describe("environment login PTY support", () => { it("offers a plugin sign-in only for the adapters its running driver hosts", async () => { const { environmentSupportsLoginPty } = await import("./environment-support.js"); const computer = { driver: "plugin", config: { pluginKey: "fixture", driverKey: "computer" } }; const capabilities = { ...getEnvironmentCapabilities(["codex_local"]), loginPtyDrivers: { "fixture:computer": { supportsLoginPty: true, loginAdapters: ["claude_local", "grok_local"] } } }; expect(environmentSupportsLoginPty(computer, capabilities)).toBe(true); expect(environmentSupportsLoginPty({ driver: "plugin", config: { pluginKey: "other", driverKey: "computer" } }, capabilities)).toBe(false); expect(environmentSupportsLoginPty({ driver: "local", config: {} }, capabilities)).toBe(false); expect(environmentSupportsLoginPty(computer, capabilities, "grok_local")).toBe(true); expect(environmentSupportsLoginPty(computer, capabilities, "claude_local")).toBe(true); expect(environmentSupportsLoginPty(computer, capabilities, "codex_local")).toBe(false); const none = { ...capabilities, loginPtyDrivers: { "fixture:computer": { supportsLoginPty: true, loginAdapters: [] } } }; expect(environmentSupportsLoginPty(computer, none)).toBe(false); expect(environmentSupportsLoginPty(computer, none, "claude_local")).toBe(false); }); });