mcp-sampling-prefill.test.mjs
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠ breaking
1 day 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
2 commits
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠
1 day ago
sha256:9103f98c89257ed2b01c237cea895dabb3e85ea337dccb1161c175e4422355b6
docs: accept Calendar Events v0 spec with Phase 0 security …
Human
2 days ago