TelosDB / test /
@楽曲作りまくりおじさん 楽曲作りまくりおじさん authored 6 days ago
..
README.md Add comprehensive test suite (35 tests) and update journal 8 days ago
db.test.js feat: add local datetime support and automated updated_at trigger for items table 6 days ago
integration.test.js Add comprehensive test suite (35 tests) and update journal 8 days ago
mcp-handlers.test.js fix: align all embedding dimensions to 384 for Gemma 3 300M consistency 6 days ago
scripts.test.js docs: update README onboarding guide and fix script tests 6 days ago
setup.js fix: align all embedding dimensions to 384 for Gemma 3 300M consistency 6 days ago
README.md

テストスイート概要

test/ フォルダには、SQLite Vector MCP サーバーの包括的なテストスイートが含まれています。

テストファイル構成

1. setup.js - テスト用ユーティリティ

  • createTestDb(dbName) - テスト用データベースの作成
  • cleanupTestDb(dbName) - テスト用データベースのクリーンアップ
  • setTestEnv() / clearTestEnv() - テスト環境変数の設定・クリア

2. db.test.js - データベースモジュールテスト(5テスト)

  • データベースファイルの作成確認
  • テーブルスキーマの正確性(id, content, path, created_at, updated_at)
  • アイテムの挿入機能
  • アイテムの取得機能
  • タイムスタンプデフォルト値の検証

3. mcp-tools.test.js - MCPツール定義テスト(11テスト)

  • 5つの必須ツールの存在確認(add_item_text, add_item, search_text, search_vector, llm_generate)
  • ツール定義の構造検証(name, description, inputSchema)
  • add_item_text のスキーマ検証
  • search_vector のベクトル次元検証(3次元)
  • llm_generate のプロンプト欄検証
  • すべてのツールの有効性チェック

4. mcp-handlers.test.js - MCPハンドラーテスト(6テスト)

  • エンベッディング次元の検証ロジック
  • 検索結果フィールド(content, path, created_at, updated_at)の完全性
  • アイテムの挿入と返却値検証
  • 類似度検索の機能確認
  • 空の検索結果の適切なハンドリング
  • タイムスタンプの操作を通じた保存検証

5. llama-client.test.js - LLamaクライアントテスト(9テスト)

llamaEmbedding():

  • data配列形式のレスポンス解析
  • 直接embedding欄のレスポンス解析
  • エラーレスポンスのハンドリング(500 ステータス)
  • embedding配列の不足時のエラー処理
  • リクエストボディの正確性(model, input フィールド)

llamaCompletion():

  • レスポンス解析
  • オプション(temperature, n_predict)の引き渡し
  • エラーレスポンスのハンドリング(503 ステータス)
  • 環境変数(LLAMACPP*)の使用確認

6. integration.test.js - 統合テスト(4テスト)

  • 完全なアイテムライフサイクル(作成→取得)
  • 複数アイテムとメタデータの処理
  • データ完全性の検証
  • 並行処理のようなシナリオの処理

テスト実行方法

全テスト実行

bun test

特定のテストモジュール実行

bun test test/db.test.js                    # データベーステスト
bun test test/mcp-tools.test.js             # ツール定義テスト
bun test test/mcp-handlers.test.js          # ハンドラーテスト
bun test test/llama-client.test.js          # LLamaクライアントテスト
bun test test/integration.test.js           # 統合テスト

package.json スクリプト

npm test                    # 全テスト実行
npm run test:db             # db テスト
npm run test:tools          # tools テスト
npm run test:handlers       # handlers テスト
npm run test:llama          # llama テスト
npm run test:integration    # integration テスト
npm run test:watch          # ウォッチモード(ファイル変更時に再実行)

テスト統計

  • 総テスト数: 35
  • カバレッジ対象:
    • Database operations (schema, insert, retrieve)
    • MCP tool definitions and validation
    • LLama.cpp API integration
    • Error handling
    • Data integrity

テスト環境

  • テストランナー: Bun built-in test framework (bun:test)
  • データベース: bun:sqlite (Bun組込SQLite)
  • テストスタイル: Assertion-based (expect statements)
  • 実行時間: ~250ms

注記

  • テスト実行時に test-*.db ファイルが一時的に作成されます
  • テスト環境では本番の better-sqlite3 の代わりに bun:sqlite を使用
  • 各テストは独立しており、データの競合を避けるため テーブルクリア処理を含みます