|
| 1 | +// Local-only — the integration Edit sheet for a STDIO MCP server, driven in a |
| 2 | +// real browser. `local` is the only surface that enables stdio MCP |
| 3 | +// (`dangerouslyAllowStdioMCP: true`), so it is the only place this sheet can be |
| 4 | +// exercised end to end. |
| 5 | +// |
| 6 | +// The sheet used to say "Stdio MCP integrations cannot be edited. Remove and |
| 7 | +// recreate the integration with the updated command." (#812) — changing a |
| 8 | +// command meant editing `executor.jsonc` by hand, or losing the integration's |
| 9 | +// connections and policies to a delete-and-re-add. |
| 10 | +// |
| 11 | +// The assertion is deliberately not "the field accepted my text". The scenario |
| 12 | +// edits the DECLARED env map through the form and then reads the tool catalog: |
| 13 | +// the fixture advertises `saw_declared_env` only when that variable is present |
| 14 | +// in the spawned child's environment, so the tool appearing proves the edited |
| 15 | +// config travelled the whole way — form, config write, respawn, rediscovery. |
| 16 | +import { fileURLToPath } from "node:url"; |
| 17 | + |
| 18 | +import { expect } from "@effect/vitest"; |
| 19 | +import { Effect } from "effect"; |
| 20 | +import { HttpApiClient } from "effect/unstable/httpapi"; |
| 21 | +import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/unstable/http"; |
| 22 | +import { composePluginApi } from "@executor-js/api/server"; |
| 23 | +import { mcpHttpPlugin } from "@executor-js/plugin-mcp/api"; |
| 24 | + |
| 25 | +import { scenario } from "../src/scenario"; |
| 26 | +import { Browser, Cli, RunDir, Target } from "../src/services"; |
| 27 | +import { withLocalServer } from "./local-server"; |
| 28 | + |
| 29 | +const api = composePluginApi([mcpHttpPlugin()] as const); |
| 30 | + |
| 31 | +const FIXTURE = fileURLToPath(new URL("./fixtures/stdio-mcp-server.mjs", import.meta.url)); |
| 32 | + |
| 33 | +const SECRET = "s3cr3t-typed-into-the-edit-sheet"; |
| 34 | + |
| 35 | +scenario( |
| 36 | + "Local · a stdio MCP server's command and environment are editable from the integration Edit sheet", |
| 37 | + { timeout: 300_000 }, |
| 38 | + Effect.gen(function* () { |
| 39 | + const cli = yield* Cli; |
| 40 | + const browser = yield* Browser; |
| 41 | + const target = yield* Target; |
| 42 | + const runDir = yield* RunDir; |
| 43 | + const identity = yield* target.newIdentity(); |
| 44 | + |
| 45 | + yield* withLocalServer(cli, runDir, (server) => |
| 46 | + Effect.gen(function* () { |
| 47 | + const client = yield* HttpApiClient.make(api, { |
| 48 | + baseUrl: new URL("/api", server.origin).toString(), |
| 49 | + transformClient: HttpClient.mapRequest((request) => |
| 50 | + HttpClientRequest.setHeader(request, "authorization", `Bearer ${server.token}`), |
| 51 | + ), |
| 52 | + }).pipe(Effect.provide(FetchHttpClient.layer)); |
| 53 | + |
| 54 | + const slug = "e2e-stdio-editable"; |
| 55 | + |
| 56 | + // A plain stdio server: no declared env, so the env-gated tool is absent |
| 57 | + // until the edit adds the variable. |
| 58 | + yield* client.mcp.addServer({ |
| 59 | + payload: { |
| 60 | + transport: "stdio", |
| 61 | + name: "E2E Stdio Editable", |
| 62 | + command: "node", |
| 63 | + args: [FIXTURE], |
| 64 | + slug, |
| 65 | + }, |
| 66 | + }); |
| 67 | + |
| 68 | + const before = yield* client.tools.list({ query: { integration: slug } }); |
| 69 | + expect( |
| 70 | + before.map((t) => t.name), |
| 71 | + "the server starts with its base tool and no declared env", |
| 72 | + ).toContain("echo_tool"); |
| 73 | + expect( |
| 74 | + before.map((t) => t.name), |
| 75 | + "the env-gated tool is absent before the edit", |
| 76 | + ).not.toContain("saw_declared_env"); |
| 77 | + |
| 78 | + yield* browser.session(identity, async ({ page, step }) => { |
| 79 | + await step("Open the stdio integration from the console", async () => { |
| 80 | + await page.goto(server.url, { waitUntil: "domcontentloaded" }); |
| 81 | + await page.getByTestId(`integration-entry-${slug}`).first().click(); |
| 82 | + // Wait for the detail page's own data, not just its shell: clicking |
| 83 | + // Edit while the accounts panel is still a skeleton races the layout |
| 84 | + // shift that lands when it resolves. |
| 85 | + await page.getByText("default").first().waitFor({ timeout: 30_000 }); |
| 86 | + await page.getByRole("button", { name: "Edit" }).waitFor({ timeout: 30_000 }); |
| 87 | + }); |
| 88 | + |
| 89 | + await step("Open the Edit sheet — the stdio command is editable", async () => { |
| 90 | + await page.getByRole("button", { name: "Edit" }).click(); |
| 91 | + await page.getByText("Edit integration").waitFor({ timeout: 30_000 }); |
| 92 | + await page.getByText("Server command").waitFor({ timeout: 30_000 }); |
| 93 | + // The read-only dead end this replaces. |
| 94 | + expect( |
| 95 | + await page.getByText("Stdio MCP integrations cannot be edited").count(), |
| 96 | + "the read-only message is gone", |
| 97 | + ).toBe(0); |
| 98 | + expect( |
| 99 | + await page.getByRole("textbox", { name: "Command" }).inputValue(), |
| 100 | + "the stored command is loaded into the form", |
| 101 | + ).toBe("node"); |
| 102 | + }); |
| 103 | + |
| 104 | + await step("Declare an environment variable and save", async () => { |
| 105 | + await page |
| 106 | + .getByRole("textbox", { name: "Environment variables" }) |
| 107 | + .fill(`EXECUTOR_E2E_SECRET=${SECRET}`); |
| 108 | + await page.getByRole("button", { name: "Save" }).click(); |
| 109 | + await page.getByText("Server command").waitFor({ state: "hidden", timeout: 30_000 }); |
| 110 | + }); |
| 111 | + }); |
| 112 | + |
| 113 | + // The edit persisted as the DECLARED static env map on the config. |
| 114 | + const stored = yield* client.mcp.getServer({ params: { slug } }); |
| 115 | + expect( |
| 116 | + stored?.config.transport === "stdio" ? stored.config.env : undefined, |
| 117 | + "the sheet wrote the declared env map", |
| 118 | + ).toEqual({ EXECUTOR_E2E_SECRET: SECRET }); |
| 119 | + expect( |
| 120 | + stored?.config.transport === "stdio" ? stored.config.command : undefined, |
| 121 | + "the command it did not touch is unchanged", |
| 122 | + ).toBe("node"); |
| 123 | + |
| 124 | + // And it reached the spawned server: the fixture gates this tool's very |
| 125 | + // existence on that variable being in its own environment. |
| 126 | + const after = yield* client.tools.list({ query: { integration: slug } }); |
| 127 | + expect( |
| 128 | + after.map((t) => t.name), |
| 129 | + "the edited environment reached the respawned server and the catalog was rebuilt", |
| 130 | + ).toContain("saw_declared_env"); |
| 131 | + expect( |
| 132 | + after.map((t) => t.name), |
| 133 | + "the rebuild kept the tools that still exist", |
| 134 | + ).toContain("echo_tool"); |
| 135 | + }), |
| 136 | + ); |
| 137 | + }), |
| 138 | +); |
0 commit comments