feat: add server assembly and stdio entry
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { parseArgs } from '../../src/cli.js'
|
||||
|
||||
describe('parseArgs', () => {
|
||||
it('prefers the --config flag', () => {
|
||||
expect(parseArgs(['--config', '/tmp/c.json'], { DBMOLE_CONFIG: '/env.json' })).toEqual({
|
||||
configPath: '/tmp/c.json'
|
||||
})
|
||||
})
|
||||
|
||||
it('falls back to DBMOLE_CONFIG env', () => {
|
||||
expect(parseArgs([], { DBMOLE_CONFIG: '/env.json' })).toEqual({ configPath: '/env.json' })
|
||||
})
|
||||
|
||||
it('returns undefined without flag or env', () => {
|
||||
expect(parseArgs([], {})).toEqual({ configPath: undefined })
|
||||
})
|
||||
|
||||
it('ignores --config without a value', () => {
|
||||
expect(parseArgs(['--config'], {})).toEqual({ configPath: undefined })
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,37 @@
|
||||
import { mkdtempSync, rmSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
||||
import { createRegistry } from '../../src/config/registry.js'
|
||||
import { createServer } from '../../src/server.js'
|
||||
import { connectClient, fakeManager } from './helpers.js'
|
||||
|
||||
describe('createServer', () => {
|
||||
let dir: string
|
||||
|
||||
beforeEach(() => {
|
||||
dir = mkdtempSync(join(tmpdir(), 'dbmole-server-'))
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
it('registers all nine tools', async () => {
|
||||
const registry = createRegistry({ storePath: join(dir, 'connections.json'), env: {} })
|
||||
const server = createServer(registry, fakeManager())
|
||||
const client = await connectClient(server)
|
||||
const { tools } = await client.listTools()
|
||||
expect(tools.map((tool) => tool.name).sort()).toEqual([
|
||||
'add_connection',
|
||||
'describe_table',
|
||||
'execute_sql',
|
||||
'list_connections',
|
||||
'list_databases',
|
||||
'list_tables',
|
||||
'remove_connection',
|
||||
'test_connection',
|
||||
'update_connection'
|
||||
])
|
||||
})
|
||||
})
|
||||
@@ -1,7 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
describe('smoke', () => {
|
||||
it('runs', () => {
|
||||
expect(1 + 1).toBe(2)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user