test(core): cover base schema + respond; neutralize tunnel log prefix

This commit is contained in:
admin committed 2026-06-16 19:51:13 +05:00
1 parent dd99f4a47b
commit df64404d21
4 files changed
+61 -3

No files matched your search

@@ -0,0 +1,32 @@
import { describe, expect, it } from 'vitest'
import * as z from 'zod'
import { baseConnectionShape, sshConfigSchema } from '../../../src/config/baseSchema.js'
// A minimal concrete schema built from the shared base, the way a leaf package
// would compose it.
const testSchema = z.object({ ...baseConnectionShape, type: z.literal('test') }).strict()
describe('sshConfigSchema', () => {
it('defaults port to 22', () => {
expect(sshConfigSchema.parse({ host: 'h', user: 'u' }).port).toBe(22)
})
it('rejects unknown keys (strict)', () => {
expect(() => sshConfigSchema.parse({ host: 'h', user: 'u', bogus: 1 })).toThrow()
})
})
describe('baseConnectionShape', () => {
it('accepts a valid connection and defaults readonly to false', () => {
const c = testSchema.parse({ name: 'c1', host: 'h', user: 'u', type: 'test' })
expect(c.readonly).toBe(false)
expect(c.port).toBeUndefined()
})
it('requires user', () => {
expect(() => testSchema.parse({ name: 'c1', host: 'h', type: 'test' })).toThrow()
})
it('rejects an invalid name', () => {
expect(() =>
testSchema.parse({ name: 'bad name!', host: 'h', user: 'u', type: 'test' })
).toThrow()
})
})
@@ -0,0 +1,21 @@
import { describe, expect, it } from 'vitest'
import { errorMessage, fail, ok } from '../../../src/mcp/respond.js'
describe('respond helpers', () => {
it('ok wraps a JSON payload as text content', () => {
const r = ok({ a: 1 })
expect(r).toEqual({ content: [{ type: 'text', text: JSON.stringify({ a: 1 }) }] })
expect(r.isError).toBeUndefined()
})
it('fail returns an error result with the message text', () => {
const r = fail('boom')
expect(r.content).toEqual([{ type: 'text', text: 'boom' }])
expect(r.isError).toBe(true)
})
it('errorMessage extracts Error.message', () => {
expect(errorMessage(new Error('nope'))).toBe('nope')
})
it('errorMessage stringifies non-Errors', () => {
expect(errorMessage('plain')).toBe('plain')
})
})