mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-10-13 04:59:51 +08:00
refactor(mcp-server): remove dead code and fold repeated tool plumbing
- index.ts: registerTool() does the session check, try/catch and the
write queue for all 15 tools; fail()/ok(), syncFromBrowser(),
commitDocument() and describePages() replace the copied blocks; drop
pickPageSelector, currentSession.version, the input ?? {} defaults;
add_page reuses prepareNewModel() split out of prepareNewDiagram
- xml-validation.ts: drop the hand-written syntax checks that saxes
already reports, MAX_XML_SIZE and the stale header
- http-server.ts: one pendingExport object, no unread response fields,
no CORS/OPTIONS branch for same-origin requests, fewer exports
- diagram-operations parseNewCell(), addHistory returns void,
normalizeToMxfile without host, foldCells without layer, expandStyles
removed, unused preview.css rule removed, no .d.ts output
- xml-examples.ts styleRules() shares the Styles paragraphs with the
web prompt
- tests: setupFiles installs the DOM polyfill once, server-wiring uses
the SDK client, mcp-core.test.ts drops the cases MCP tests already
cover
This commit is contained in:
@@ -3,13 +3,7 @@
|
||||
* a page, like in the web app, and the server adds the wrapper and root cells.
|
||||
*/
|
||||
|
||||
import { beforeAll, describe, expect, it } from "vitest"
|
||||
import { installDomPolyfill } from "../src/dom.ts"
|
||||
|
||||
beforeAll(() => {
|
||||
installDomPolyfill()
|
||||
})
|
||||
|
||||
import { describe, expect, it } from "vitest"
|
||||
import { prepareNewDiagram, reservedIdError } from "../src/new-diagram.ts"
|
||||
import { hasCells, wrapCellsInModel } from "../src/pages.ts"
|
||||
import { validateAndFixXml } from "../src/xml-validation.ts"
|
||||
@@ -100,6 +94,22 @@ describe("hasCells", () => {
|
||||
hasCells(`<mxCell id = "0"/><mxCell id = "1" parent="0"/>`),
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it("does not mistake ids that start with 0 or 1 for root cells", () => {
|
||||
expect(
|
||||
hasCells(
|
||||
'<mxCell id="0"/><mxCell id="1" parent="0"/><mxCell id="10"/>',
|
||||
),
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it("counts a cell wrapped in a UserObject", () => {
|
||||
expect(
|
||||
hasCells(
|
||||
'<mxCell id="0"/><mxCell id="1" parent="0"/><UserObject id="u" link="x"><mxCell vertex="1" parent="1"/></UserObject>',
|
||||
),
|
||||
).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe("reservedIdError", () => {
|
||||
|
||||
Reference in New Issue
Block a user