From 82966afa64ec0cbd0e09084cf7af89067ccf0c2d Mon Sep 17 00:00:00 2001 From: Parafee41 Date: Sun, 1 Nov 2026 03:35:42 +0800 Subject: [PATCH] test(mcp): assert server protocol metadata (#3788) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * test(mcp): assert server protocol metadata * test: remove resolved server duplicate audit pair --------- Co-authored-by: Gergő Magyar --- .../fixtures/scenario-map-recall/audit.json | 6 ---- gitnexus/test/unit/server.test.ts | 33 +++++++++++++++---- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/gitnexus/test/fixtures/scenario-map-recall/audit.json b/gitnexus/test/fixtures/scenario-map-recall/audit.json index 8844e8872..f71daafb6 100644 --- a/gitnexus/test/fixtures/scenario-map-recall/audit.json +++ b/gitnexus/test/fixtures/scenario-map-recall/audit.json @@ -368,12 +368,6 @@ "category": "reexport-context", "basis": "local-backend.ts imports and directly re-exports the same isTestFilePath function. Both tests pass undefined, null and empty string and assert false three times." }, - { - "a": "test/unit/server.test.ts#server error handling > createMCPServer reads version from package.json", - "b": "test/unit/server.test.ts#prompt registration > server registers detect_impact and generate_map prompts", - "category": "same-file", - "basis": "Identical scenario body in one file, using the same helpers, input data and assertions. Enclosing setup has no relevant difference." - }, { "a": "test/unit/shared-type-extractors.test.ts#extractElementTypeFromString > returns undefined when base is not a simple word: user model[]", "b": "test/unit/shared-type-extractors.test.ts#extractElementTypeFromString > returns undefined for complex non-word base before []: user model[]", diff --git a/gitnexus/test/unit/server.test.ts b/gitnexus/test/unit/server.test.ts index f806fb7fe..000946abe 100644 --- a/gitnexus/test/unit/server.test.ts +++ b/gitnexus/test/unit/server.test.ts @@ -27,6 +27,7 @@ import { } from '../../src/mcp/server.js'; import { GITNEXUS_TOOLS } from '../../src/mcp/tools.js'; import { createMcpRepositoryPolicy } from '../../src/mcp/repository-policy.js'; +import { packageVersion } from '../../src/core/package-version.js'; // ─── Mock backend ────────────────────────────────────────────────── @@ -660,22 +661,42 @@ describe('server error handling', () => { expect(() => createMCPServer(backend)).not.toThrow(); }); - it('createMCPServer reads version from package.json', () => { + it('createMCPServer advertises the package version', async () => { const backend = createMockBackend(); const server = createMCPServer(backend); - // Server was created with version from package.json — no crash - expect(server).toBeDefined(); + const client = new Client({ name: 'version-test-client', version: '0.0.0' }); + const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); + + try { + await Promise.all([server.connect(serverTransport), client.connect(clientTransport)]); + expect(client.getServerVersion()).toMatchObject({ version: packageVersion() }); + } finally { + await client.close(); + await server.close(); + } }); }); // ─── Prompt definitions ─────────────────────────────────────────────── describe('prompt registration', () => { - it('server registers detect_impact and generate_map prompts', () => { + it('server registers detect_impact and generate_map prompts', async () => { const backend = createMockBackend(); - // Creating the server registers all handlers including prompts const server = createMCPServer(backend); - expect(server).toBeDefined(); + const client = new Client({ name: 'prompt-test-client', version: '0.0.0' }); + const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); + + try { + await Promise.all([server.connect(serverTransport), client.connect(clientTransport)]); + const response = await client.listPrompts(); + expect(response.prompts.map((prompt) => prompt.name)).toEqual([ + 'detect_impact', + 'generate_map', + ]); + } finally { + await client.close(); + await server.close(); + } }); });