소스 검색

test: move all tests to flat test/ directory

No more src/models/ and src/integration/ subfolders to forget about.
All 9 test files live in test/, one command runs everything:

  npx vitest run test/
  bun test test/
Tobi Lutke 3 달 전
부모
커밋
870d3aed3b
13개의 변경된 파일37개의 추가작업 그리고 77개의 파일을 삭제
  1. 4 25
      .github/workflows/ci.yml
  2. 4 12
      CLAUDE.md
  3. 1 13
      package.json
  4. 0 0
      test/cli.test.ts
  5. 3 3
      test/eval-bm25.test.ts
  6. 6 6
      test/eval.test.ts
  7. 2 2
      test/formatter.test.ts
  8. 1 1
      test/llm.test.ts
  9. 8 8
      test/mcp.test.ts
  10. 1 1
      test/store-paths.test.ts
  11. 1 1
      test/store.helpers.unit.test.ts
  12. 5 5
      test/store.test.ts
  13. 1 0
      vitest.config.ts

+ 4 - 25
.github/workflows/ci.yml

@@ -33,16 +33,8 @@ jobs:
 
       - run: npm install
 
-      - name: Unit tests
-        run: npx vitest run --reporter=verbose src/*.test.ts
-
-      - name: Model tests
-        run: npx vitest run --reporter=verbose src/models/*.test.ts
-        env:
-          CI: true
-
-      - name: Integration tests
-        run: npx vitest run --reporter=verbose src/integration/*.test.ts
+      - name: Tests
+        run: npx vitest run --reporter=verbose test/
         env:
           CI: true
 
@@ -71,21 +63,8 @@ jobs:
 
       - run: bun install
 
-      - name: Unit tests
-        run: bun test --preload ./src/test-preload.ts src/*.test.ts
-        env:
-          DYLD_LIBRARY_PATH: /opt/homebrew/opt/sqlite/lib
-          LD_LIBRARY_PATH: /usr/lib/x86_64-linux-gnu
-
-      - name: Model tests
-        run: bun test --preload ./src/test-preload.ts src/models/*.test.ts
-        env:
-          CI: true
-          DYLD_LIBRARY_PATH: /opt/homebrew/opt/sqlite/lib
-          LD_LIBRARY_PATH: /usr/lib/x86_64-linux-gnu
-
-      - name: Integration tests
-        run: bun test --preload ./src/test-preload.ts src/integration/*.test.ts
+      - name: Tests
+        run: bun test --preload ./src/test-preload.ts test/
         env:
           CI: true
           DYLD_LIBRARY_PATH: /opt/homebrew/opt/sqlite/lib

+ 4 - 12
CLAUDE.md

@@ -122,23 +122,15 @@ bun src/qmd.ts <command>   # Run from source
 bun link               # Install globally as 'qmd'
 ```
 
-## Test Layout
+## Tests
 
-- `src/*.test.ts` = unit tests
-- `src/models/*.test.ts` = tests that require model/runtime setup
-- `src/integration/*.test.ts` = integration tests (CLI subprocesses, daemon/server behavior)
-
-### Run Order
+All tests live in `test/`. Run everything:
 
 ```sh
-npx vitest run --reporter=verbose src/*.test.ts
-npx vitest run --reporter=verbose src/models/*.test.ts
-npx vitest run --reporter=verbose src/integration/*.test.ts
+npx vitest run --reporter=verbose test/
+bun test --preload ./src/test-preload.ts test/
 ```
 
-Use this order for faster feedback:
-`unit -> models -> integration`.
-
 ## Architecture
 
 - SQLite FTS5 for full-text search (BM25)

+ 1 - 13
package.json

@@ -15,19 +15,7 @@
     "CHANGELOG.md"
   ],
   "scripts": {
-    "test": "vitest run",
-    "test:unit": "vitest run --reporter=verbose src/*.test.ts",
-    "test:models": "vitest run --reporter=verbose src/models/*.test.ts",
-    "test:integration": "vitest run --reporter=verbose src/integration/*.test.ts",
-    "test:unit:bun": "bun run vitest run --reporter=verbose --testTimeout=120000 src/*.test.ts",
-    "test:models:bun": "bun run vitest run --reporter=verbose --testTimeout=120000 src/models/*.test.ts",
-    "test:integration:bun": "bun run vitest run --reporter=verbose --testTimeout=120000 src/integration/*.test.ts",
-    "test:unit:node": "npx vitest run --reporter=verbose --testTimeout=120000 src/*.test.ts",
-    "test:models:node": "npx vitest run --reporter=verbose --testTimeout=120000 src/models/*.test.ts",
-    "test:integration:node": "npx vitest run --reporter=verbose --testTimeout=120000 src/integration/*.test.ts",
-    "test:ci:bun": "npm run test:unit:bun && npm run test:models:bun && npm run test:integration:bun",
-    "test:ci:node": "npm run test:unit:node && npm run test:models:node && npm run test:integration:node",
-    "test:ci": "npm run test:unit && npm run test:models && npm run test:integration",
+    "test": "vitest run --reporter=verbose test/",
     "qmd": "tsx src/qmd.ts",
     "index": "tsx src/qmd.ts index",
     "vector": "tsx src/qmd.ts vector",

+ 0 - 0
src/integration/cli.test.ts → test/cli.test.ts


+ 3 - 3
src/eval-bm25.test.ts → test/eval-bm25.test.ts

@@ -8,7 +8,7 @@ import { describe, test, expect, beforeAll, afterAll } from "vitest";
 import { mkdtempSync, rmSync, readFileSync, readdirSync } from "fs";
 import { join, dirname } from "path";
 import { tmpdir } from "os";
-import type { Database } from "./db.js";
+import type { Database } from "../src/db.js";
 import { createHash } from "crypto";
 import { fileURLToPath } from "url";
 
@@ -17,7 +17,7 @@ import {
   searchFTS,
   insertDocument,
   insertContent,
-} from "./store";
+} from "../src/store";
 
 // Set INDEX_PATH before importing store to prevent using global index
 const tempDir = mkdtempSync(join(tmpdir(), "qmd-eval-unit-"));
@@ -92,7 +92,7 @@ describe("BM25 Search (FTS)", () => {
     db = store.db;
 
     // Load and index eval documents
-    const evalDocsDir = join(dirname(fileURLToPath(import.meta.url)), "../test/eval-docs");
+    const evalDocsDir = join(dirname(fileURLToPath(import.meta.url)), "eval-docs");
     const files = readdirSync(evalDocsDir).filter(f => f.endsWith(".md"));
 
     for (const file of files) {

+ 6 - 6
src/models/eval.test.ts → test/eval.test.ts

@@ -14,8 +14,8 @@ import { describe, test, expect, beforeAll, afterAll } from "vitest";
 import { mkdtempSync, rmSync, readFileSync, readdirSync } from "fs";
 import { join } from "path";
 import { tmpdir } from "os";
-import { openDatabase } from "../db.js";
-import type { Database } from "../db.js";
+import { openDatabase } from "../src/db.js";
+import type { Database } from "../src/db.js";
 import { createHash } from "crypto";
 import { fileURLToPath } from "url";
 import { dirname } from "path";
@@ -35,8 +35,8 @@ import {
   reciprocalRankFusion,
   DEFAULT_EMBED_MODEL,
   type RankedResult,
-} from "../store";
-import { getDefaultLlamaCpp, formatDocForEmbedding, disposeDefaultLlamaCpp } from "../llm";
+} from "../src/store";
+import { getDefaultLlamaCpp, formatDocForEmbedding, disposeDefaultLlamaCpp } from "../src/llm";
 
 // Eval queries with expected documents
 const evalQueries: {
@@ -110,7 +110,7 @@ describe("BM25 Search (FTS)", () => {
     db = store.db;
 
     // Load and index eval documents
-    const evalDocsDir = join(dirname(fileURLToPath(import.meta.url)), "../../test/eval-docs");
+    const evalDocsDir = join(dirname(fileURLToPath(import.meta.url)), "eval-docs");
     const files = readdirSync(evalDocsDir).filter(f => f.endsWith(".md"));
 
     for (const file of files) {
@@ -182,7 +182,7 @@ describe.skipIf(!!process.env.CI)("Vector Search", () => {
     const llm = getDefaultLlamaCpp();
     store.ensureVecTable(768); // embeddinggemma uses 768 dimensions
 
-    const evalDocsDir = join(dirname(fileURLToPath(import.meta.url)), "../../test/eval-docs");
+    const evalDocsDir = join(dirname(fileURLToPath(import.meta.url)), "eval-docs");
     const files = readdirSync(evalDocsDir).filter(f => f.endsWith(".md"));
 
     for (const file of files) {

+ 2 - 2
src/formatter.test.ts → test/formatter.test.ts

@@ -27,8 +27,8 @@ import {
   documentToXml,
   formatDocument,
   type MultiGetFile,
-} from "./formatter.js";
-import type { SearchResult, DocumentResult } from "./store.js";
+} from "../src/formatter.js";
+import type { SearchResult, DocumentResult } from "../src/store.js";
 
 // =============================================================================
 // Test Fixtures

+ 1 - 1
src/models/llm.test.ts → test/llm.test.ts

@@ -17,7 +17,7 @@ import {
   SessionReleasedError,
   type RerankDocument,
   type ILLMSession,
-} from "../llm.js";
+} from "../src/llm.js";
 
 // =============================================================================
 // Singleton Tests (no model loading required)

+ 8 - 8
src/models/mcp.test.ts → test/mcp.test.ts

@@ -6,16 +6,16 @@
  */
 
 import { describe, test, expect, beforeAll, afterAll, beforeEach, afterEach } from "vitest";
-import { openDatabase, loadSqliteVec } from "../db.js";
-import type { Database } from "../db.js";
+import { openDatabase, loadSqliteVec } from "../src/db.js";
+import type { Database } from "../src/db.js";
 import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
 import { z } from "zod";
-import { getDefaultLlamaCpp, disposeDefaultLlamaCpp } from "../llm";
+import { getDefaultLlamaCpp, disposeDefaultLlamaCpp } from "../src/llm";
 import { mkdtemp, writeFile, readdir, unlink, rmdir } from "node:fs/promises";
 import { join } from "node:path";
 import { tmpdir } from "node:os";
 import YAML from "yaml";
-import type { CollectionConfig } from "../collections";
+import type { CollectionConfig } from "../src/collections";
 
 // =============================================================================
 // Test Database Setup
@@ -192,8 +192,8 @@ import {
   DEFAULT_RERANK_MODEL,
   DEFAULT_MULTI_GET_MAX_BYTES,
   createStore,
-} from "../store";
-import type { RankedResult } from "../store";
+} from "../src/store";
+import type { RankedResult } from "../src/store";
 // Note: searchResultsToMcpCsv no longer used in MCP - using structuredContent instead
 
 // =============================================================================
@@ -865,8 +865,8 @@ describe("MCP Server", () => {
 // HTTP Transport Tests
 // =============================================================================
 
-import { startMcpHttpServer, type HttpServerHandle } from "../mcp";
-import { enableProductionMode } from "../store";
+import { startMcpHttpServer, type HttpServerHandle } from "../src/mcp";
+import { enableProductionMode } from "../src/store";
 
 describe("MCP HTTP Transport", () => {
   let handle: HttpServerHandle;

+ 1 - 1
src/store-paths.test.ts → test/store-paths.test.ts

@@ -16,7 +16,7 @@ import {
   normalizePathSeparators,
   getRelativePathFromPrefix,
   resolve,
-} from "./store.js";
+} from "../src/store.js";
 
 // =============================================================================
 // Test Utilities

+ 1 - 1
src/store.helpers.unit.test.ts → test/store.helpers.unit.test.ts

@@ -15,7 +15,7 @@ import {
   normalizeDocid,
   isDocid,
   handelize,
-} from "./store";
+} from "../src/store";
 
 // =============================================================================
 // Path Utilities

+ 5 - 5
src/models/store.test.ts → test/store.test.ts

@@ -7,13 +7,13 @@
  */
 
 import { describe, test, expect, beforeAll, afterAll, beforeEach, afterEach, vi } from "vitest";
-import { openDatabase, loadSqliteVec } from "../db.js";
-import type { Database } from "../db.js";
+import { openDatabase, loadSqliteVec } from "../src/db.js";
+import type { Database } from "../src/db.js";
 import { unlink, mkdtemp, rmdir, writeFile } from "node:fs/promises";
 import { tmpdir } from "node:os";
 import { join } from "node:path";
 import YAML from "yaml";
-import { disposeDefaultLlamaCpp } from "../llm.js";
+import { disposeDefaultLlamaCpp } from "../src/llm.js";
 import {
   createStore,
   verifySqliteVecLoaded,
@@ -49,8 +49,8 @@ import {
   type DocumentResult,
   type SearchResult,
   type RankedResult,
-} from "../store.js";
-import type { CollectionConfig } from "../collections.js";
+} from "../src/store.js";
+import type { CollectionConfig } from "../src/collections.js";
 
 // =============================================================================
 // LlamaCpp Setup

+ 1 - 0
vitest.config.ts

@@ -3,5 +3,6 @@ import { defineConfig } from "vitest/config";
 export default defineConfig({
   test: {
     testTimeout: 30000,
+    include: ["test/**/*.test.ts"],
   },
 });