mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-10-11 20:19:51 +08:00
fix(mcp-server): keep both pages when get_diagram meets a page export, and more review fixes
Found by the PR review, each with a test that failed first:
- get_diagram during a page export returned the one-page projection on
screen as the whole document (6 of 6 times when timed so). The preview
page no longer answers a sync while a projection shows, and syncs after
reloading, so the poll that restores the real document exports it.
- Exports are numbered on the server too: a late result of an export that
timed out was saved as the next export's file.
- In Chrome, a new_xml with a syntax error counted the <parsererror>
element as a second cell, so the web app rejected edits that auto-fix
repairs ("must contain exactly one cell").
- hasCells missed single-quoted ids, so screenshot_diagram called such a
diagram empty and auto-save never created its file.
- A literal \n directly under a <diagram> that has a model passed
validation; only text-only pages are compressed data.
- A wrapped mxCell repeating its UserObject's id took the wrapper's place
in edits, so delete and update left an empty or nested wrapper.
- Bare cells with a shape or edge id of "0" or "1" are rejected with a
clear message instead of being renamed, which broke their edges.
- DRAWIO_DATA_DIR expands ~, which JSON configs pass on as it is.
This commit is contained in:
@@ -135,6 +135,36 @@ test("display_diagram replaces the document with the fixed diagram", async ({
|
||||
await expect(canvas.getByText("Second", { exact: true })).toHaveCount(0)
|
||||
})
|
||||
|
||||
test("an edit with a fixable cell is fixed, not rejected", async ({
|
||||
page: p,
|
||||
}) => {
|
||||
// Chrome's DOMParser puts a <parsererror> next to the cell, which used
|
||||
// to count as a second cell
|
||||
const canvas = await mockReplies(p, [
|
||||
streamedToolCall("display_diagram", { xml: cell("a", "Alpha", 40) }),
|
||||
streamedToolCall("edit_diagram", {
|
||||
operations: [
|
||||
{
|
||||
operation: "add",
|
||||
cell_id: "c",
|
||||
new_xml: cell("c", "Gamma", 400).replace(
|
||||
"</mxCell>",
|
||||
"</mxcell>",
|
||||
),
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
await sendMessage(p, "Draw a box")
|
||||
await waitForCompleteCount(p, 1)
|
||||
await sendMessage(p, "Add another box")
|
||||
await waitForCompleteCount(p, 2)
|
||||
await expect(canvas.getByText("Gamma", { exact: true })).toBeVisible({
|
||||
timeout: 15000,
|
||||
})
|
||||
await expect(p.getByText(/exactly one cell/)).toHaveCount(0)
|
||||
})
|
||||
|
||||
test("edit_diagram applies all operations or none", async ({ page: p }) => {
|
||||
const canvas = await mockReplies(p, [
|
||||
streamedToolCall("display_diagram", {
|
||||
|
||||
Reference in New Issue
Block a user