Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

test(release): stabilize ACP bridge and installer checks

tianma-if27d3b1ce963e
diff --git a/apps/desktop/src/main/acp-mcp-bridge.test.mjs b/apps/desktop/src/main/acp-mcp-bridge.test.mjs
index 9f7e7207..148d133d 100644
--- a/apps/desktop/src/main/acp-mcp-bridge.test.mjs
+++ b/apps/desktop/src/main/acp-mcp-bridge.test.mjs
@@ -1,106 +1,27 @@
-import { afterEach, expect, test } from "bun:test";
-import { spawn } from "node:child_process";
-import { createServer } from "node:http";
+import { expect, test } from "bun:test";
+import { spawnSync } from "node:child_process";
+import { mkdtempSync, readFileSync, rmSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
import { fileURLToPath } from "node:url";
-import { startAcpMcpBridge } from "./acp-mcp-bridge.mjs";
-const servers = [];
-afterEach(async () => {
- await Promise.all(servers.splice(0).map((server) => new Promise((resolve) => server.close(resolve))));
-});
-
-const upstream = async () => {
- const requests = [];
- const server = createServer(async (request, response) => {
- const chunks = [];
- for await (const chunk of request) chunks.push(chunk);
- const body = Buffer.concat(chunks).toString("utf8");
- requests.push({ url: request.url, authorization: request.headers.authorization, body });
- response.setHeader("Content-Type", "application/json");
- if (request.url === "/api/v1/auth/session") {
- response.end(JSON.stringify({
- authenticated: request.headers.authorization === "Bearer long-lived-session",
- user: { id: "account-one" },
- }));
- return;
- }
- response.end(JSON.stringify({ jsonrpc: "2.0", id: 1, result: { tools: [] } }));
- });
- await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
- servers.push(server);
- return { url: `http://127.0.0.1:${server.address().port}`, requests };
-};
-
-test("ACP bridge forwards only authorized MCP requests and never exposes the login token", async () => {
- const remote = await upstream();
- let current = true;
- const bridge = await startAcpMcpBridge({
- baseUrl: remote.url,
- sessionToken: "long-lived-session",
- isCurrent: () => current,
- });
+test("ACP bridge protects the session and connects the packaged MCP adapter", () => {
+ const harness = fileURLToPath(new URL("../../../../tests/fixtures/acp-mcp-bridge-stdio-harness.mjs", import.meta.url));
+ const directory = mkdtempSync(join(tmpdir(), "edgeever-acp-mcp-test-"));
try {
- expect(bridge.url).not.toContain("long-lived-session");
- expect(bridge.secret).not.toBe("long-lived-session");
- const request = (authorization) => fetch(`${bridge.url}/mcp`, {
- method: "POST",
- headers: { authorization, "content-type": "application/json" },
- body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list" }),
+ const resultPath = join(directory, "result.json");
+ const result = spawnSync("node", [harness], {
+ encoding: "utf8",
+ timeout: 10_000,
+ env: { ...process.env, EDGE_EVER_TEST_RESULT_PATH: resultPath },
});
- expect((await request("Bearer wrong")).status).toBe(401);
- expect(remote.requests).toHaveLength(1);
- expect((await request(`Bearer ${bridge.secret}`)).status).toBe(200);
- expect(remote.requests.at(-1)?.authorization).toBe("Bearer long-lived-session");
- current = false;
- expect((await request(`Bearer ${bridge.secret}`)).status).toBe(401);
- expect(remote.requests).toHaveLength(2);
- } finally {
- await bridge.close();
- }
-});
-
-test("ACP bridge refuses an invalid desktop session", async () => {
- const remote = await upstream();
- await expect(startAcpMcpBridge({
- baseUrl: remote.url,
- sessionToken: "invalid-session",
- isCurrent: () => true,
- })).rejects.toThrow("note_access_unavailable");
- await expect(startAcpMcpBridge({
- baseUrl: remote.url,
- sessionToken: "long-lived-session",
- accountId: "account-two",
- isCurrent: () => true,
- })).rejects.toThrow("note_access_unavailable");
-});
-
-test("the packaged MCP stdio adapter reaches the signed-in instance through the ACP bridge", async () => {
- const remote = await upstream();
- const bridge = await startAcpMcpBridge({
- baseUrl: remote.url,
- sessionToken: "long-lived-session",
- isCurrent: () => true,
- });
- const script = fileURLToPath(new URL("../../../../scripts/edgeever-mcp-stdio.mjs", import.meta.url));
- const child = spawn(process.execPath, [script], {
- stdio: ["pipe", "pipe", "pipe"],
- env: { ...process.env, EDGEEVER_URL: bridge.url, EDGEEVER_TOKEN: bridge.secret },
- });
- try {
- const response = new Promise((resolve, reject) => {
- const timeout = setTimeout(() => reject(new Error("MCP stdio adapter timed out")), 5000);
- child.stdout.once("data", (chunk) => {
- clearTimeout(timeout);
- try { resolve(JSON.parse(chunk.toString("utf8").trim())); }
- catch (error) { reject(error); }
- });
- child.once("error", reject);
+ expect(result.status, result.stderr).toBe(0);
+ expect(JSON.parse(readFileSync(resultPath, "utf8"))).toEqual({
+ security: true,
+ invalidSession: true,
+ stdio: true,
});
- child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list" })}\n`);
- expect((await response).result).toEqual({ tools: [] });
- expect(remote.requests.at(-1)?.authorization).toBe("Bearer long-lived-session");
} finally {
- child.kill();
- await bridge.close();
+ rmSync(directory, { recursive: true, force: true });
}
-});
+}, 15_000);
diff --git a/scripts/docker-installer.test.mjs b/scripts/docker-installer.test.mjs
index 6432b61b..dcedfdc7 100644
--- a/scripts/docker-installer.test.mjs
+++ b/scripts/docker-installer.test.mjs
@@ -256,7 +256,7 @@ esac
} finally {
await rm(fixture, { recursive: true, force: true });
}
- });
+ }, 15_000);
test("prints actionable diagnostics without exposing the password", async () => {
const fixture = await mkdtemp(resolve(tmpdir(), "edgeever-installer-failure-"));
diff --git a/tests/fixtures/acp-mcp-bridge-stdio-harness.mjs b/tests/fixtures/acp-mcp-bridge-stdio-harness.mjs
new file mode 100644
index 00000000..3a1bc175
--- /dev/null
+++ b/tests/fixtures/acp-mcp-bridge-stdio-harness.mjs
@@ -0,0 +1,94 @@
+import { spawn } from "node:child_process";
+import { writeFileSync } from "node:fs";
+import { createServer } from "node:http";
+import { fileURLToPath } from "node:url";
+import assert from "node:assert/strict";
+import { startAcpMcpBridge } from "../../apps/desktop/src/main/acp-mcp-bridge.mjs";
+
+const sessionToken = "long-lived-session";
+const authorizations = [];
+const upstream = createServer((request, response) => {
+ authorizations.push(request.headers.authorization);
+ response.setHeader("Content-Type", "application/json");
+ if (request.url === "/api/v1/auth/session") {
+ response.end(JSON.stringify({
+ authenticated: request.headers.authorization === `Bearer ${sessionToken}`,
+ user: { id: "account-one" },
+ }));
+ return;
+ }
+ response.end(JSON.stringify({ jsonrpc: "2.0", id: 1, result: { tools: [] } }));
+});
+
+let bridge;
+let child;
+let current = true;
+try {
+ await new Promise((resolve, reject) => {
+ upstream.once("error", reject);
+ upstream.listen(0, "127.0.0.1", resolve);
+ });
+ bridge = await startAcpMcpBridge({
+ baseUrl: `http://127.0.0.1:${upstream.address().port}`,
+ sessionToken,
+ isCurrent: () => current,
+ });
+ assert.equal(bridge.url.includes(sessionToken), false);
+ assert.notEqual(bridge.secret, sessionToken);
+ const requestBridge = (secret) => fetch(`${bridge.url}/mcp`, {
+ method: "POST",
+ headers: { authorization: `Bearer ${secret}`, "content-type": "application/json" },
+ body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list" }),
+ });
+ assert.equal((await requestBridge("wrong")).status, 401);
+ assert.equal(authorizations.length, 1);
+ assert.equal((await requestBridge(bridge.secret)).status, 200);
+ assert.equal(authorizations.at(-1), `Bearer ${sessionToken}`);
+ current = false;
+ assert.equal((await requestBridge(bridge.secret)).status, 401);
+ assert.equal(authorizations.length, 2);
+ current = true;
+
+ const upstreamUrl = `http://127.0.0.1:${upstream.address().port}`;
+ await assert.rejects(startAcpMcpBridge({
+ baseUrl: upstreamUrl,
+ sessionToken: "invalid-session",
+ isCurrent: () => true,
+ }), /note_access_unavailable/);
+ await assert.rejects(startAcpMcpBridge({
+ baseUrl: upstreamUrl,
+ sessionToken,
+ accountId: "account-two",
+ isCurrent: () => true,
+ }), /note_access_unavailable/);
+
+ const script = fileURLToPath(new URL("../../scripts/edgeever-mcp-stdio.mjs", import.meta.url));
+ child = spawn(process.execPath, [script], {
+ stdio: ["pipe", "pipe", "pipe"],
+ env: { ...process.env, EDGEEVER_URL: bridge.url, EDGEEVER_TOKEN: bridge.secret },
+ });
+ let stderr = "";
+ child.stderr.on("data", (chunk) => { stderr += chunk.toString("utf8"); });
+ const responsePromise = new Promise((resolve, reject) => {
+ const timeout = setTimeout(() => reject(new Error(`MCP stdio adapter timed out: ${stderr}`)), 5_000);
+ child.stdout.once("data", (chunk) => {
+ clearTimeout(timeout);
+ try { resolve(JSON.parse(chunk.toString("utf8").trim())); }
+ catch (error) { reject(error); }
+ });
+ child.once("error", reject);
+ child.once("close", (code) => reject(new Error(`MCP stdio adapter exited ${code}: ${stderr}`)));
+ });
+ child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list" })}\n`);
+ const response = await responsePromise;
+ assert.deepEqual(response.result, { tools: [] });
+ assert.equal(authorizations.at(-1), `Bearer ${sessionToken}`);
+ writeFileSync(process.env.EDGE_EVER_TEST_RESULT_PATH, JSON.stringify({ security: true, invalidSession: true, stdio: true }));
+} catch (error) {
+ console.error(error);
+ process.exitCode = 1;
+} finally {
+ child?.kill();
+ if (bridge) await bridge.close();
+ await new Promise((resolve) => upstream.close(resolve));
+}