Переглянути джерело

fix(ci): guard LLM calls in CI and increase test timeouts

Add _ciMode flag to LlamaCpp that throws immediately on embedBatch,
generate, expandQuery, and rerank when CI=true — prevents silent 30s
timeouts. Skip MCP HTTP Transport tests in CI (they instantiate a real
LlamaCpp). Bump vitest/bun test timeouts to 60s for slower CI runners.
Tobi Lutke 2 місяців тому
батько
коміт
55f16460d0
5 змінених файлів з 10 додано та 4 видалено
  1. 2 2
      .github/workflows/ci.yml
  2. 1 1
      .github/workflows/publish.yml
  3. 5 0
      src/llm.ts
  4. 1 0
      test/llm.test.ts
  5. 1 1
      test/mcp.test.ts

+ 2 - 2
.github/workflows/ci.yml

@@ -34,7 +34,7 @@ jobs:
       - run: npm install
 
       - name: Tests
-        run: npx vitest run --reporter=verbose test/
+        run: npx vitest run --reporter=verbose --testTimeout 60000 test/
         env:
           CI: true
 
@@ -64,7 +64,7 @@ jobs:
       - run: bun install
 
       - name: Tests
-        run: bun test --timeout 30000 --preload ./src/test-preload.ts test/
+        run: bun test --timeout 60000 --preload ./src/test-preload.ts test/
         env:
           CI: true
           DYLD_LIBRARY_PATH: /opt/homebrew/opt/sqlite/lib

+ 1 - 1
.github/workflows/publish.yml

@@ -23,7 +23,7 @@ jobs:
         run: sudo apt-get update && sudo apt-get install -y libsqlite3-dev
 
       - run: bun install
-      - run: bun test --timeout 30000 --preload ./src/test-preload.ts test/
+      - run: bun test --timeout 60000 --preload ./src/test-preload.ts test/
         env:
           CI: true
           LD_LIBRARY_PATH: /usr/lib/x86_64-linux-gnu

+ 5 - 0
src/llm.ts

@@ -405,6 +405,7 @@ function resolveExpandContextSize(configValue?: number): number {
 }
 
 export class LlamaCpp implements LLM {
+  private readonly _ciMode = !!process.env.CI;
   private llama: Llama | null = null;
   private embedModel: LlamaModel | null = null;
   private embedContexts: LlamaEmbeddingContext[] = [];
@@ -854,6 +855,7 @@ export class LlamaCpp implements LLM {
    * Uses Promise.all for parallel embedding - node-llama-cpp handles batching internally
    */
   async embedBatch(texts: string[]): Promise<(EmbeddingResult | null)[]> {
+    if (this._ciMode) throw new Error("LLM operations are disabled in CI (set CI=true)");
     // Ping activity at start to keep models alive during this operation
     this.touchActivity();
 
@@ -912,6 +914,7 @@ export class LlamaCpp implements LLM {
   }
 
   async generate(prompt: string, options: GenerateOptions = {}): Promise<GenerateResult | null> {
+    if (this._ciMode) throw new Error("LLM operations are disabled in CI (set CI=true)");
     // Ping activity at start to keep models alive during this operation
     this.touchActivity();
 
@@ -971,6 +974,7 @@ export class LlamaCpp implements LLM {
   // ==========================================================================
 
   async expandQuery(query: string, options: { context?: string, includeLexical?: boolean, intent?: string } = {}): Promise<Queryable[]> {
+    if (this._ciMode) throw new Error("LLM operations are disabled in CI (set CI=true)");
     // Ping activity at start to keep models alive during this operation
     this.touchActivity();
 
@@ -1067,6 +1071,7 @@ export class LlamaCpp implements LLM {
     documents: RerankDocument[],
     options: RerankOptions = {}
   ): Promise<RerankResult> {
+    if (this._ciMode) throw new Error("LLM operations are disabled in CI (set CI=true)");
     // Ping activity at start to keep models alive during this operation
     this.touchActivity();
 

+ 1 - 0
test/llm.test.ts

@@ -120,6 +120,7 @@ describe("LlamaCpp expand context size config", () => {
 describe("LlamaCpp rerank deduping", () => {
   test("deduplicates identical document texts before scoring", async () => {
     const llm = new LlamaCpp({}) as any;
+    llm._ciMode = false; // allow unit test even in CI (mocked, no real models)
     const rankAll = vi.fn(async (_query: string, docs: string[]) =>
       docs.map((doc) => doc === "shared chunk" ? 0.9 : 0.2)
     );

+ 1 - 1
test/mcp.test.ts

@@ -897,7 +897,7 @@ describe("MCP Server", () => {
 import { startMcpHttpServer, type HttpServerHandle } from "../src/mcp/server";
 import { enableProductionMode } from "../src/store";
 
-describe("MCP HTTP Transport", () => {
+describe.skipIf(!!process.env.CI)("MCP HTTP Transport", () => {
   let handle: HttpServerHandle;
   let baseUrl: string;
   let httpTestDbPath: string;