mirror of
https://github.com/penpot/penpot.git
synced 2026-10-29 05:50:35 +00:00
* 🎉 Add multi-file session routing to the MCP server Session routing: - Track each user's Penpot connections by session ID. - Dispatch explicit sessions directly; otherwise discover the sole session. - Return a retryable error when discovery fails or is incomplete. Plugin and tools: - Initialize connections with a fresh session ID and file metadata. - Share the optional sessionId schema and place it last in tool inputs. Validation: - 84 tests, server type checking, and MCP formatting checks pass. - Disable test logging to avoid the logging worker shutdown hang. AI-assisted-by: gpt-6 * 🎉 Support independent MCP connections - Require explicit connection intent for each integrated workspace. - Derive short session IDs from the Penpot app instance and file. - Show and copy session IDs in the MCP menu and standalone plugin UI. - Stop stale callbacks and reconnect attempts after disconnect. Validate with frontend and plugin tests, type checking, live multi-tab checks, and standalone UI checks with a simulated connection. Server tests pass with --test-force-exit; the normal runner can hang on shutdown. AI-assisted-by: gpt-6 * 📚 Document multi-file MCP sessions - Explain independent connections, session selection, and copying IDs. - Describe session ID lifetimes for integrated and standalone plugins. - Correct browser focus, connection, and recovery guidance. Validate with the documentation site build and diff checks. AI-assisted-by: gpt-6 * ✨ Change behavior on session ID duplication * ✨ Open MCP toolbar menu on hover and match menu style --------- Co-authored-by: alonso.torres <alonso.torres@kaleidos.net> Co-authored-by: elhombretecla <delacruzgarciajuan@gmail.com>
78 lines
2.5 KiB
TypeScript
78 lines
2.5 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { SessionIdDisplay } from "./SessionIdDisplay.ts";
|
|
|
|
class DisplayFixture {
|
|
public readonly value = { textContent: "" };
|
|
public readonly feedback = { textContent: "" };
|
|
public onCopy!: () => Promise<void>;
|
|
public readonly button = {
|
|
disabled: true,
|
|
addEventListener: (_event: string, listener: () => Promise<void>) => {
|
|
this.onCopy = listener;
|
|
},
|
|
};
|
|
public readonly root = {
|
|
hidden: true,
|
|
querySelector: (selector: string) =>
|
|
({
|
|
"#session-id-value": this.value,
|
|
"#copy-session-id-btn": this.button,
|
|
"#session-id-feedback": this.feedback,
|
|
})[selector],
|
|
};
|
|
public readonly copied: string[] = [];
|
|
public readonly display: SessionIdDisplay;
|
|
|
|
constructor(
|
|
writeText = async (text: string) => {
|
|
this.copied.push(text);
|
|
}
|
|
) {
|
|
this.display = new SessionIdDisplay(this.root as unknown as HTMLElement, { writeText });
|
|
}
|
|
}
|
|
|
|
test("shows and copies the exact session ID, then clears it on disconnect", async () => {
|
|
const ui = new DisplayFixture();
|
|
ui.display.setSessionId("pq3gxqddgj");
|
|
assert.equal(ui.root.hidden, false);
|
|
assert.equal(ui.value.textContent, "pq3gxqddgj");
|
|
await ui.onCopy();
|
|
assert.deepEqual(ui.copied, ["pq3gxqddgj"]);
|
|
assert.equal(ui.feedback.textContent, "Copied");
|
|
ui.display.setSessionId(null);
|
|
assert.equal(ui.root.hidden, true);
|
|
assert.equal(ui.value.textContent, "");
|
|
assert.equal(ui.feedback.textContent, "");
|
|
assert.equal(ui.button.disabled, true);
|
|
await ui.onCopy();
|
|
assert.equal(ui.copied.length, 1);
|
|
});
|
|
|
|
test("reports clipboard denial and keeps the ID available for manual copying", async () => {
|
|
const ui = new DisplayFixture(async () => {
|
|
throw new Error("Permission denied");
|
|
});
|
|
ui.display.setSessionId("pq3gxqddgj");
|
|
await ui.onCopy();
|
|
assert.match(ui.feedback.textContent, /Could not copy/);
|
|
assert.equal(ui.value.textContent, "pq3gxqddgj");
|
|
});
|
|
|
|
test("ignores late clipboard feedback after the session changes", async () => {
|
|
let finish!: () => void;
|
|
const ui = new DisplayFixture(
|
|
() =>
|
|
new Promise<void>((resolve) => {
|
|
finish = resolve;
|
|
})
|
|
);
|
|
ui.display.setSessionId("pq3gxqddgj");
|
|
const pending = ui.onCopy();
|
|
ui.display.setSessionId("jablgbun4p");
|
|
finish();
|
|
await pending;
|
|
assert.equal(ui.feedback.textContent, "");
|
|
});
|