3a521ada4d
Поверхности записи «целым телом» были несимметричны: у in-app агента полная
замена тела markdown называлась updatePageContent (имя не про формат, тогда как
парный updatePageJson — про JSON), а у внешнего MCP голого plain-body-replace
не было вовсе (только import_page_markdown — на деле парсер round-trip к
export_page_markdown, не plain-replace). Пара должна быть updatePageMarkdown /
updatePageJson.
Пост-Фаза-1б архитектура (реестр + циклы по обоим хостам):
- новая shared-спека updatePageMarkdown (mcpName update_page_markdown, inAppKey
updatePageMarkdown, tier как у updatePageJson) с execute (client, {pageId,
content, title}) => client.updatePage(...) — тот же путь updatePageContentRealtime
→ markdownToProseMirrorCanonical, ^[...]-сноски парсятся. Реестровый цикл
регистрирует её на ОБОИХ хостах автоматически. Добавлен 'updatePage' в
Pick DocmostClientLike.
- import_page_markdown убран с внешнего MCP через inAppOnly:true у спеки
importPageMarkdown — MCP-цикл и генератор инвентаря её пропускают, in-app
агент сохраняет importPageMarkdown; спека и client-метод НЕ удалены.
- удалён inline in-app updatePageContent tool (теперь из реестра под inAppKey
updatePageMarkdown) + его INLINE_TOOL_TIERS-энтри.
- ROUTING_PROSE: bulk-rewrite ссылается на update_page_markdown|update_page_json;
убрано упоминание import_page_markdown; инвентарь генерируется из catalogLine.
- лейбл-мапы chat-markdown.util (en/ru), человекочитаемые метки не тронуты.
- НЕ тронуты одноимённые внутренности: PageService.updatePageContent,
updatePageContentRealtime, collaboration.handler — переименовано только имя тула.
Тесты: updatePageMarkdown на обеих поверхностях с идентичной схемой, forward в
client.updatePage; import_page_markdown ОТСУТСТВУЕТ на MCP, присутствует in-app;
^[...]→сноски покрыт через collaboration.test. CHANGELOG BREAKING + миграция;
README/README.ru пакета обновлены. Гейт: mcp node --test 646/646, server jest
259, tsc чисто. Первый линк breaking-окна #416 (#411→#412→#413→#415).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
79 lines
3.1 KiB
JavaScript
79 lines
3.1 KiB
JavaScript
// Footnote-canonicalization binding tests for the MCP FULL-document write tools
|
|
// (issue #228, review #4): update_page_json and copy_page_content must persist a
|
|
// footnote-canonical doc. These override the `replacePage` seam (symmetric to the
|
|
// `mutatePage` seam used by the insert-footnote-wrapper test) to capture the
|
|
// persisted doc WITHOUT a live Hocuspocus collab socket. Symmetric to the
|
|
// server-side focus specs for createPage / updatePage (markdown 'replace').
|
|
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { DocmostClient } from "../../build/client.js";
|
|
|
|
const para = (...c) => ({ type: "paragraph", content: c });
|
|
const ref = (id) => ({ type: "footnoteReference", attrs: { id } });
|
|
const def = (id, text) => ({
|
|
type: "footnoteDefinition",
|
|
attrs: { id },
|
|
content: [{ type: "paragraph", content: [{ type: "text", text }] }],
|
|
});
|
|
const list = (...d) => ({ type: "footnotesList", content: d });
|
|
|
|
function findAll(node, type, acc = []) {
|
|
if (!node || typeof node !== "object") return acc;
|
|
if (node.type === type) acc.push(node);
|
|
if (Array.isArray(node.content)) for (const c of node.content) findAll(c, type, acc);
|
|
return acc;
|
|
}
|
|
const defIds = (doc) => findAll(doc, "footnoteDefinition").map((d) => d.attrs.id);
|
|
|
|
function makeClient(sourceDoc) {
|
|
const calls = { replaced: [] };
|
|
class TestClient extends DocmostClient {
|
|
async ensureAuthenticated() {}
|
|
async getCollabTokenWithReauth() {
|
|
return "collab-token";
|
|
}
|
|
async getPageRaw(pageId) {
|
|
return { id: pageId, slugId: "s", title: "P", spaceId: "sp", content: sourceDoc };
|
|
}
|
|
async replacePage(pageId, doc, token, apiUrl) {
|
|
calls.replaced.push({ pageId, doc });
|
|
return { doc, verify: { ok: true } };
|
|
}
|
|
}
|
|
const client = new TestClient("http://127.0.0.1:1/api", "e@x.com", "pw");
|
|
return { client, calls };
|
|
}
|
|
|
|
test("update_page_json canonicalizes the persisted full doc (out-of-order -> reference order)", async () => {
|
|
const { client, calls } = makeClient();
|
|
const outOfOrder = {
|
|
type: "doc",
|
|
content: [
|
|
para({ type: "text", text: "x" }, ref("b"), ref("a")),
|
|
list(def("a", "A"), def("b", "B")),
|
|
],
|
|
};
|
|
await client.updatePageJson("p1", outOfOrder);
|
|
assert.equal(calls.replaced.length, 1);
|
|
// Definitions reordered to reference order [b, a] before persisting.
|
|
assert.deepEqual(defIds(calls.replaced[0].doc), ["b", "a"]);
|
|
assert.equal(findAll(calls.replaced[0].doc, "footnotesList").length, 1);
|
|
});
|
|
|
|
test("copy_page_content canonicalizes the persisted copy (orphan definition dropped)", async () => {
|
|
const sourceDoc = {
|
|
type: "doc",
|
|
content: [
|
|
para({ type: "text", text: "x" }, ref("a")),
|
|
list(def("a", "A"), def("orphan", "O")),
|
|
],
|
|
};
|
|
const { client, calls } = makeClient(sourceDoc);
|
|
const res = await client.copyPageContent("src", "dst");
|
|
assert.equal(calls.replaced.length, 1);
|
|
assert.equal(calls.replaced[0].pageId, "dst");
|
|
// The orphan definition is dropped by canonicalization before the copy lands.
|
|
assert.deepEqual(defIds(calls.replaced[0].doc), ["a"]);
|
|
assert.equal(res.success, true);
|
|
});
|