mcp-sampling-prefill.test.mjs
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠ breaking
10 days ago
| 1 | import { describe, it } from 'node:test'; |
| 2 | import assert from 'node:assert/strict'; |
| 3 | import { maybeAppendSamplingPrefill } from '../mcp/prompts/helpers.mjs'; |
| 4 | |
| 5 | function makeMockServer({ sampling = true, response = 'Draft response here' } = {}) { |
| 6 | return { |
| 7 | server: { |
| 8 | getClientCapabilities: () => (sampling ? { sampling: {} } : {}), |
| 9 | createMessage: async () => ({ |
| 10 | content: { type: 'text', text: response }, |
| 11 | model: 'mock', |
| 12 | role: 'assistant', |
| 13 | }), |
| 14 | }, |
| 15 | }; |
| 16 | } |
| 17 | |
| 18 | describe('maybeAppendSamplingPrefill', () => { |
| 19 | it('appends assistant message when sampling available', async () => { |
| 20 | const result = await maybeAppendSamplingPrefill( |
| 21 | makeMockServer(), |
| 22 | { |
| 23 | description: 'test', |
| 24 | messages: [ |
| 25 | { role: 'user', content: { type: 'text', text: 'Summarize my notes.' } }, |
| 26 | ], |
| 27 | } |
| 28 | ); |
| 29 | assert.equal(result.messages.length, 2); |
| 30 | assert.equal(result.messages[1].role, 'assistant'); |
| 31 | assert.equal(result.messages[1].content.text, 'Draft response here'); |
| 32 | }); |
| 33 | |
| 34 | it('does not append when sampling unavailable', async () => { |
| 35 | const result = await maybeAppendSamplingPrefill( |
| 36 | makeMockServer({ sampling: false }), |
| 37 | { |
| 38 | description: 'test', |
| 39 | messages: [ |
| 40 | { role: 'user', content: { type: 'text', text: 'Summarize.' } }, |
| 41 | ], |
| 42 | } |
| 43 | ); |
| 44 | assert.equal(result.messages.length, 1); |
| 45 | }); |
| 46 | |
| 47 | it('does not append when last message is already assistant', async () => { |
| 48 | const result = await maybeAppendSamplingPrefill( |
| 49 | makeMockServer(), |
| 50 | { |
| 51 | messages: [ |
| 52 | { role: 'user', content: { type: 'text', text: 'Hello' } }, |
| 53 | { role: 'assistant', content: { type: 'text', text: 'Existing prefill' } }, |
| 54 | ], |
| 55 | } |
| 56 | ); |
| 57 | assert.equal(result.messages.length, 2); |
| 58 | assert.equal(result.messages[1].content.text, 'Existing prefill'); |
| 59 | }); |
| 60 | |
| 61 | it('returns unchanged for empty messages', async () => { |
| 62 | const result = await maybeAppendSamplingPrefill(makeMockServer(), { messages: [] }); |
| 63 | assert.deepEqual(result.messages, []); |
| 64 | }); |
| 65 | |
| 66 | it('returns unchanged for null input', async () => { |
| 67 | const result = await maybeAppendSamplingPrefill(makeMockServer(), null); |
| 68 | assert.equal(result, null); |
| 69 | }); |
| 70 | |
| 71 | it('handles string content in user message', async () => { |
| 72 | const result = await maybeAppendSamplingPrefill( |
| 73 | makeMockServer(), |
| 74 | { |
| 75 | messages: [{ role: 'user', content: 'plain string content' }], |
| 76 | } |
| 77 | ); |
| 78 | assert.equal(result.messages.length, 2); |
| 79 | assert.equal(result.messages[1].role, 'assistant'); |
| 80 | }); |
| 81 | |
| 82 | it('preserves description field', async () => { |
| 83 | const result = await maybeAppendSamplingPrefill( |
| 84 | makeMockServer(), |
| 85 | { |
| 86 | description: 'My description', |
| 87 | messages: [{ role: 'user', content: { type: 'text', text: 'test' } }], |
| 88 | } |
| 89 | ); |
| 90 | assert.equal(result.description, 'My description'); |
| 91 | }); |
| 92 | }); |
File History
4 commits
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠
10 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b
fix(7C-L1b): route hosted delegation proposals through cani…
Human
minor
⚠
30 days ago
sha256:2827ba9e7632a4b141c50caf1e8f7d77abbc3515be20e7465f2bccb0ac4edf91
fix: repair endpoint now sets has_active_subscription when …
Human
minor
⚠
50 days ago
sha256:6a102aafafdfe7e70a24f4e59740200f0ee713ce7915f1b53e9d4ba5ee8b4410
Initial Muse snapshot
Human
82 days ago