7cb3199d09
Один логический тул жил под двумя именами: внешний MCP snake_case (edit_page_text), in-app camelCase (editPageText) — дублирование доков, путаница при переносе промптов/скиллов, помеха шарингу спек (#294). Решение владельца: единый camelCase везде, включая внешний MCP. После этого mcpName === inAppKey. - tool-specs.ts: mcpName ВЫВЕДЕН из ключа спеки (mcpName == inAppKey) для всех 43 shared-спек — раньше divergent snake, теперь равен ключу (проверено: mcpName читается только структурно — цикл регистрации, генератор <tool_inventory>, TOOL_FAMILY). +5 inline-регистраций (tableGet/updateComment/deleteComment/ docmostTransform; search без изменений). Рантайм: 47 тулов, все camelCase, ноль подчёркиваний. - Контракт-конвенция ИНВЕРТИРОВАНА: shared-tool-specs.contract.spec `mcpName === toSnake(inAppKey)` → `mcpName === inAppKey`; tool-specs.test и tool-inventory.test обновлены. - ROUTING_PROSE/TOOL_FAMILY/INLINE_MCP_INVENTORY (server-instructions.ts) → camelCase (105 замен). ai-chat.prompt/guard уже на in-app camelCase-ключах — без изменений (guard прошёл). comment-signal EXCLUDED_TOOLS схлопнут с дублей snake+camel до camelCase. - Некоторое неочевидное: assertUnambiguousMatch(op: "patch_node"|"delete_node") в prosemirror-markdown/node-ops — op интерполируется в model-facing ошибку; литерал-юнион + call-sites → "patchNode"|"deleteNode". - Все snake-имена в описаниях/error-строках/комментах/тестах/доках → camelCase (whole-token, longest-match-first). CHANGELOG: BREAKING-таблица 46 строк + миграция (allowlists mcp__gitmost-*__get_node→__getNode, промпты/скиллы, .mcp.json, метрики по tool-label); релизится вместе с #411. Внутренние имена методов (PageService.updatePageContent и т.п.) НЕ тронуты — переименованы только ИМЕНА ТУЛОВ. Гейт: mcp node --test 677/677; tsc -p apps/server чисто; jest ai-chat-tools. service + shared-tool-specs.contract + tool-tiers + ai-chat.prompt + comment-signal-inapp → 323. Второй линк breaking-окна (#411→ЭТОТ→#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): updatePageJson and copyPageContent 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("updatePageJson 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("copyPageContent 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);
|
|
});
|