fix(mcp-server): recover sessions in one place, and more fixes from the third review

- A session whose state expired was recovered from its auto-save file only
  for the preview page; the tools built on their older copy and then
  overwrote the file. They now recover it first (restoreSavedSession).
- A preview tab that missed the last AI write pushed its older diagram
  over the recovered one after a restart. It now shows the recovered
  diagram and keeps its own copy in History.
- An empty record of what the model has seen (after load_diagram or a
  page tool on unseen changes) no longer lets one page of a multi-page
  document count for all, and get_diagram counts a page only once found.
- History: a thumbnail goes only to the entry it shows, the cached image
  never belongs to an older diagram, a re-serialized copy adds no entry,
  and a cleared document with its own pages is kept before a restore.
- The root cell id check reads attributes one by one: rack-id="1" or id
  text inside a label no longer counts.
- A compressed page counts as having cells; a saved file that could not
  be read is never written over.
This commit is contained in:
dayuan.jiang
2026-10-05 13:04:32 +09:00
parent 49468f9478
commit cfbf17f97e
12 changed files with 288 additions and 53 deletions
@@ -85,6 +85,15 @@ describe("hasCells", () => {
)
})
it("counts a compressed page as having cells", () => {
// draw.io's compressed format: the page's model is text
expect(
hasCells(
`<mxfile><diagram id="p" name="P">dZHBDoIwDIafhjtsGPWM6MkTB8/LVmBxrGQMQZ/eLRuIUS/bv/VfmybF</diagram></mxfile>`,
),
).toBe(true)
})
it("counts cells with spaces around the =", () => {
expect(hasCells(`<mxCell id = "a" vertex="1" parent="1"/>`)).toBe(true)
expect(
@@ -106,6 +115,27 @@ describe("reservedIdError", () => {
`<UserObject id="1" label="Docs"><mxCell vertex="1" parent="1"><mxGeometry as="geometry"/></mxCell></UserObject>`,
),
).toMatch(/"0" and "1"/)
// Other attributes ending in id, and id text inside a label
expect(
reservedIdError(
`<UserObject label="Server" rack-id="1" id="7"><mxCell vertex="1" parent="1"/></UserObject>`,
),
).toBeNull()
expect(
reservedIdError(
`<UserObject id="u" label="Example: id='1'"><mxCell vertex="1" parent="1"/></UserObject>`,
),
).toBeNull()
expect(
reservedIdError(
`<mxCell id="5" data-id="0" vertex="1" parent="1"/>`,
),
).toBeNull()
expect(
reservedIdError(
`<mxCell id="5" value="id=&quot;1&quot; vertex=&quot;1&quot;" vertex="1" parent="1"/>`,
),
).toBeNull()
// A whole model has its own root cells
expect(
reservedIdError(