Files
next-ai-draw-io/packages/mcp-server/tests/xml-reference.test.ts
T
dayuan.jiang fc8ffc5655 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
2026-10-12 08:25:47 +09:00

53 lines
1.8 KiB
TypeScript

/**
* The XML references returned by get_drawing_guide with a topic. Each
* snippet must be accepted by create_new_diagram as bare mxCell elements;
* whether draw.io renders it as intended is checked by hand.
*/
import { describe, expect, it } from "vitest"
import { prepareNewDiagram } from "../src/new-diagram.ts"
import { hasCells } from "../src/pages.ts"
import { XML_REFERENCE } from "../src/xml-reference.ts"
/** The code block of a reference: the lines indented by four spaces. */
function snippet(topic: keyof typeof XML_REFERENCE): string {
return XML_REFERENCE[topic]
.split("\n")
.filter((line) => line.startsWith(" "))
.map((line) => line.slice(4))
.join("\n")
}
describe("XML_REFERENCE", () => {
it.each(["tables", "layers", "groups"] as const)(
"%s snippet passes prepareNewDiagram",
(topic) => {
const xml = snippet(topic)
expect(xml).toContain("<mxCell")
const result = prepareNewDiagram(xml)
expect(result.ok, result.ok ? "" : result.error).toBe(true)
if (result.ok) expect(result.fixes).toEqual([])
},
)
it("tables use draw.io's table shapes", () => {
const xml = snippet("tables")
expect(xml).toContain("shape=table;")
expect(xml).toContain("shape=tableRow;")
expect(xml).toContain("shape=partialRectangle;")
})
it('layers keep the layer cell with parent="0"', () => {
const result = prepareNewDiagram(snippet("layers"))
expect(result.ok).toBe(true)
if (!result.ok) return
expect(hasCells(result.xml)).toBe(true)
expect(result.xml).toContain('id="L2"')
expect(result.xml).toContain('parent="L2"')
})
it("groups use a group container", () => {
expect(snippet("groups")).toContain('style="group"')
})
})