peppa/packages/testkit/test/mcp-guide.test.ts
2026-11-17 12:46:19 +05:00

61 lines
3.1 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// PEP-190: the AI-client guide — get_started, the hint in answers, the public page /mcp-guide.
import assert from "node:assert/strict";
import { existsSync, readFileSync } from "node:fs";
import { after, before, describe, test } from "node:test";
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
import { core, db, teardown } from "./helpers.ts";
process.env.PEPPA_SECRET = "mock-secret-for-tests";
const { createManagerServer, MANAGER_INSTRUCTIONS } = await import("@peppa/mcp/manager");
let user: Awaited<ReturnType<typeof core.upsertUserFromGitea>>;
let client: Client;
before(async () => {
user = await core.upsertUserFromGitea(db, { id: 901, login: "mock-guide" }, { access_token: "x" });
const [a, b] = InMemoryTransport.createLinkedPair();
await createManagerServer(db, user, "https://peppa.test").connect(a);
client = new Client({ name: "mock-chatgpt", version: "0" });
await client.connect(b);
});
after(teardown);
const call = async (name: string, args: Record<string, unknown> = {}) =>
((await client.callTool({ name, arguments: args })).content as Array<{ text: string }>)[0]!.text;
describe("PEP-190: памятка для ИИ-клиентов", () => {
test("get_started есть в списке, описание просит вызвать первым, текст запрещает git и код и описывает «Готово»", async () => {
const tools = (await client.listTools()).tools;
const t = tools.find((x) => x.name === "get_started")!;
assert.ok(t, "get_started is listed");
assert.match(t.description!, /FIRST/);
assert.match(t.description!, /Вызови первым/);
assert.equal(t.annotations?.readOnlyHint, true);
const text = await call("get_started");
assert.equal(text, core.MCP_GUIDE);
assert.match(text, /never go to git/i);
assert.match(text, /Never write or suggest code/);
assert.match(text, /Done means accepted/);
assert.match(text, /«Принять»/);
assert.ok(!/RULES\.md|OpenSpec proposal/.test(text), "developer-agent rules are not here");
});
test("instructions сервера включают ту же памятку", () => {
assert.ok(MANAGER_INSTRUCTIONS.includes(core.MCP_GUIDE));
});
test("list_projects и get_task начинаются со строки про get_started", async () => {
assert.ok((await call("list_projects")).startsWith(core.GET_STARTED_HINT));
assert.match(core.GET_STARTED_HINT, /get_started/);
assert.equal(core.GET_STARTED_HINT, "Правила работы — инструмент get_started");
});
test("/mcp-guide открыта без входа и показывает тот же текст", () => {
const page = new URL("../../../apps/web/app/mcp-guide/page.tsx", import.meta.url);
assert.ok(existsSync(page), "the page lies outside the (app) group, so no sign-in is required");
const src = readFileSync(page, "utf8");
assert.doesNotMatch(src, /requireUser|currentUser/);
assert.match(src, /value=\{MCP_GUIDE\}/);
});
});