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
@@ -3,6 +3,7 @@
*/
import {
chmodSync,
existsSync,
mkdtempSync,
readdirSync,
@@ -84,6 +85,23 @@ describe("Autosaver", () => {
expect(new Autosaver(null).load("mcp-back")).toBeNull()
})
it("never replaces a saved file it could not read", () => {
const saver = new Autosaver(tempDir(), 10)
saver.schedule("mcp-locked", DIAGRAM)
saver.flush()
const path = saver.pathFor("mcp-locked") as string
chmodSync(path, 0o000)
try {
expect(saver.load("mcp-locked")).toBeNull()
// The blank page shown instead must not overwrite the diagram
saver.schedule("mcp-locked", BLANK)
saver.flush()
} finally {
chmodSync(path, 0o644)
}
expect(readFileSync(path, "utf-8")).toBe(DIAGRAM)
})
it("does nothing when saving is off", () => {
const saver = new Autosaver(null)
expect(saver.pathFor("mcp-x")).toBeNull()