test(core): cover base schema + respond; neutralize tunnel log prefix
This commit is contained in:
1 parent
dd99f4a47b
commit
df64404d21
4 files changed
+61
-3
No files matched your search
@@ -67,7 +67,7 @@ export const openTunnel = async (
|
||||
|
||||
// After 'ready' resolved, later ssh errors must not crash the process.
|
||||
client.on('error', (error) => {
|
||||
console.error('dbmole: ssh tunnel error: ' + error.message)
|
||||
console.error('ssh-tunnel: ssh tunnel error: ' + error.message)
|
||||
})
|
||||
|
||||
let closed = false
|
||||
@@ -140,7 +140,7 @@ export const openTunnel = async (
|
||||
// without a persistent one, a later listener error is swallowed and the
|
||||
// tunnel silently serves a dead socket. Mark it closed instead.
|
||||
server.on('error', (error) => {
|
||||
console.error('dbmole: tunnel listener error: ' + error.message)
|
||||
console.error('ssh-tunnel: tunnel listener error: ' + error.message)
|
||||
markClosed()
|
||||
})
|
||||
|
||||
|
||||
@@ -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')
|
||||
})
|
||||
})
|
||||
@@ -3,6 +3,11 @@ import { defineConfig } from 'vitest/config'
|
||||
export default defineConfig({
|
||||
test: {
|
||||
include: ['test/unit/**/*.test.ts'],
|
||||
coverage: { provider: 'v8', include: ['src/**'], thresholds: { lines: 90, functions: 90 } }
|
||||
coverage: {
|
||||
provider: 'v8',
|
||||
include: ['src/**'],
|
||||
exclude: ['src/index.ts'],
|
||||
thresholds: { lines: 90, functions: 90 }
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user