/
gkat
/
gitverse-codex-plugin
Обзор
Документация
Войти
/
gkat
/
gitverse-codex-plugin
Код
Запросы
0
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
test/local-tools.test.mjs
116 строк
3 KB
gkat
Register repository listing as standalone MCP server
29 июл 2026, 15:31
29 июл 2026, 15:31
8aee95b
Код
Авторство
О чём код?
import assert from "node:assert/strict"; import test from "node:test"; import { callLocalTool, listMyRepositories, } from "../scripts/local-tools.mjs"; function response({ status = 200, body = [], link = "" } = {}) { return { ok: status >= 200 && status < 300, status, headers: new Headers(link ? { link } : {}), async json() { return body; }, }; } test("lists and normalizes repositories with pagination", async () => { let request; const result = await listMyRepositories({ token: "test-token", args: { page: 2, per_page: 10 }, fetchImpl: async (url, options) => { request = { url: String(url), options }; return response({ link: '<https://api.gitverse.ru/user/repos?page=3>; rel="next"', body: [ { full_name: "alice/project", description: "Example", private: false, visibility: "public", archived: false, default_branch: "main", language: "JavaScript", updated_at: "2026-01-01T00:00:00Z", html_url: "https://gitverse.ru/alice/project", permissions: { pull: true, push: true, admin: false }, }, ], }); }, }); assert.equal( request.url, "https://api.gitverse.ru/user/repos?page=2&per_page=10", ); assert.equal(request.options.headers.Authorization, "Bearer test-token"); assert.equal( request.options.headers.Accept, "application/vnd.gitverse.object+json;version=1", ); assert.equal(result.count, 1); assert.equal(result.has_next_page, true); assert.equal(result.repositories[0].full_name, "alice/project"); }); test("rejects invalid pagination before making a request", async () => { let called = false; await assert.rejects( listMyRepositories({ token: "test-token", args: { per_page: 51 }, fetchImpl: async () => { called = true; }, }), /per_page must be an integer between 1 and 50/, ); assert.equal(called, false); }); test("distinguishes invalid credentials from insufficient permissions", async () => { await assert.rejects( listMyRepositories({ token: "test-token", fetchImpl: async () => response({ status: 401 }), }), /missing, invalid, or revoked/, ); await assert.rejects( listMyRepositories({ token: "test-token", fetchImpl: async () => response({ status: 403 }), }), /token is valid but lacks permission/, ); }); test("returns a valid MCP response for the local tool", async () => { const reply = await callLocalTool( { jsonrpc: "2.0", id: 7, method: "tools/call", params: { name: "list_my_repositories", arguments: {} }, }, { token: "test-token", fetchImpl: async () => response({ body: [] }), }, ); assert.equal(reply.id, 7); assert.deepEqual(JSON.parse(reply.result.content[0].text), { Result: { repositories: [], page: 1, per_page: 30, count: 0, has_next_page: false, }, }); });