|  | 
|  | 1 | +// Copyright Mia srl | 
|  | 2 | +// SPDX-License-Identifier: Apache-2.0 | 
|  | 3 | +// | 
|  | 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | +// you may not use this file except in compliance with the License. | 
|  | 6 | +// You may obtain a copy of the License at | 
|  | 7 | +// | 
|  | 8 | +//     http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | +// | 
|  | 10 | +// Unless required by applicable law or agreed to in writing, software | 
|  | 11 | +// distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | +// See the License for the specific language governing permissions and | 
|  | 14 | +// limitations under the License. | 
|  | 15 | + | 
|  | 16 | +import assert from 'node:assert' | 
|  | 17 | +import { beforeEach, suite, test } from 'node:test' | 
|  | 18 | + | 
|  | 19 | +import { Client } from '@modelcontextprotocol/sdk/client/index.js' | 
|  | 20 | +import { GetPromptResultSchema, ListPromptsResultSchema } from '@modelcontextprotocol/sdk/types.js' | 
|  | 21 | + | 
|  | 22 | +import { addDeployPrompt } from './deploy' | 
|  | 23 | +import { TestMCPServer } from '../server/utils.test' | 
|  | 24 | + | 
|  | 25 | +suite('setup deploy prompt', () => { | 
|  | 26 | +  let client: Client | 
|  | 27 | +  beforeEach(async () => { | 
|  | 28 | +    client = await TestMCPServer((server) => { | 
|  | 29 | +      addDeployPrompt(server) | 
|  | 30 | +    }) | 
|  | 31 | +  }) | 
|  | 32 | + | 
|  | 33 | +  test('the prompt is included in the list of prompts', async () => { | 
|  | 34 | +    const result = await client.request( | 
|  | 35 | +      { | 
|  | 36 | +        method: 'prompts/list', | 
|  | 37 | +      }, | 
|  | 38 | +      ListPromptsResultSchema, | 
|  | 39 | +    ) | 
|  | 40 | + | 
|  | 41 | +    assert.equal(result.prompts.length, 1) | 
|  | 42 | +  }) | 
|  | 43 | + | 
|  | 44 | +  test('the prompt is retrieved with the requested parameters', async () => { | 
|  | 45 | +    const result = await client.request( | 
|  | 46 | +      { | 
|  | 47 | +        method: 'prompts/get', | 
|  | 48 | +        params: { | 
|  | 49 | +          name: 'deploy', | 
|  | 50 | +          arguments: { | 
|  | 51 | +            tenant: 'my-tenant', | 
|  | 52 | +            project: 'my-project', | 
|  | 53 | +            environment: 'my-environment', | 
|  | 54 | +          }, | 
|  | 55 | +        }, | 
|  | 56 | +      }, | 
|  | 57 | +      GetPromptResultSchema, | 
|  | 58 | +    ) | 
|  | 59 | + | 
|  | 60 | +    assert.equal(result.messages.length, 3) | 
|  | 61 | +    const [ firstUserMessage, firstAssistantMessage, secondUserMessage ] = result.messages | 
|  | 62 | +    assert.equal(firstUserMessage.role, 'user') | 
|  | 63 | +    assert.equal(firstAssistantMessage.role, 'assistant') | 
|  | 64 | +    assert.equal(secondUserMessage.role, 'user') | 
|  | 65 | + | 
|  | 66 | +    const firstUserMessageText = firstUserMessage.content.text | 
|  | 67 | +    if (typeof firstUserMessageText !== 'string') { | 
|  | 68 | +      assert.fail('message text is not a string') | 
|  | 69 | +    } | 
|  | 70 | + | 
|  | 71 | +    assert.ok(firstUserMessageText.includes('my-project')) | 
|  | 72 | +    assert.ok(firstUserMessageText.includes('my-tenant')) | 
|  | 73 | +    assert.ok(firstUserMessageText.includes('my-environment')) | 
|  | 74 | +    assert.ok(firstUserMessageText.includes('Please fetch which revision')) | 
|  | 75 | + | 
|  | 76 | +    const firstAssistantMessageText = firstAssistantMessage.content.text | 
|  | 77 | +    if (typeof firstAssistantMessageText !== 'string') { | 
|  | 78 | +      assert.fail('message text is not a string') | 
|  | 79 | +    } | 
|  | 80 | + | 
|  | 81 | +    assert.ok(firstAssistantMessageText.includes('my-project')) | 
|  | 82 | +    assert.ok(firstAssistantMessageText.includes('my-tenant')) | 
|  | 83 | +    assert.ok(firstAssistantMessageText.includes('my-environment')) | 
|  | 84 | +    assert.ok(firstAssistantMessageText.includes('to be fetched')) | 
|  | 85 | +  }) | 
|  | 86 | + | 
|  | 87 | +  test('the prompt is retrieved including the revisionName', async () => { | 
|  | 88 | +    const result = await client.request( | 
|  | 89 | +      { | 
|  | 90 | +        method: 'prompts/get', | 
|  | 91 | +        params: { | 
|  | 92 | +          name: 'deploy', | 
|  | 93 | +          arguments: { | 
|  | 94 | +            tenant: 'my-tenant', | 
|  | 95 | +            project: 'my-project', | 
|  | 96 | +            environment: 'my-environment', | 
|  | 97 | +            revisionName: 'my-revision', | 
|  | 98 | +          }, | 
|  | 99 | +        }, | 
|  | 100 | +      }, | 
|  | 101 | +      GetPromptResultSchema, | 
|  | 102 | +    ) | 
|  | 103 | + | 
|  | 104 | +    assert.equal(result.messages.length, 3) | 
|  | 105 | +    const [ firstUserMessage, firstAssistantMessage, secondUserMessage ] = result.messages | 
|  | 106 | +    assert.equal(firstUserMessage.role, 'user') | 
|  | 107 | +    assert.equal(firstAssistantMessage.role, 'assistant') | 
|  | 108 | +    assert.equal(secondUserMessage.role, 'user') | 
|  | 109 | + | 
|  | 110 | +    const firstUserMessageText = firstUserMessage.content.text | 
|  | 111 | +    if (typeof firstUserMessageText !== 'string') { | 
|  | 112 | +      assert.fail('message text is not a string') | 
|  | 113 | +    } | 
|  | 114 | + | 
|  | 115 | +    assert.ok(firstUserMessageText.includes('my-revision')) | 
|  | 116 | + | 
|  | 117 | +    const firstAssistantMessageText = firstAssistantMessage.content.text | 
|  | 118 | +    if (typeof firstAssistantMessageText !== 'string') { | 
|  | 119 | +      assert.fail('message text is not a string') | 
|  | 120 | +    } | 
|  | 121 | + | 
|  | 122 | +    assert.ok(firstAssistantMessageText.includes('my-revision')) | 
|  | 123 | +  }) | 
|  | 124 | +}) | 
0 commit comments