Elffuss BraidHub

kikocis/continue public

Changeset: 3ff29c567dd0
3ff29c567dd0 Merge pull request #7874 from tommypurcell/fix-report-this-error-links Dallin Romney,
..
__tests__/
README.md2.5 KiB
adapter-mocks.ts2.7 KiB
cli-helpers.ts6.4 KiB
mock-helpers.ts4.3 KiB
mock-llm-server.ts8.3 KiB
renderWithServices.tsx1.2 KiB
testServiceContainer.ts3.5 KiB
ui-test-context-minimal.ts1.3 KiB
ui-test-context.ts3.2 KiB

README.md

Test Helpers

This directory contains helper functions for testing the Continue CLI.

Mock LLM Server

The mock-llm-server.ts module provides utilities for creating mock LLM servers in tests. This allows you to test the CLI's behavior without making real API calls.

Basic Usage

import {
  setupMockLLMTest,
  cleanupMockLLMServer,
} from "../test-helpers/mock-llm-server.js";

describe("My Test", () => {
  let context: any;
  let mockServer: MockLLMServer;

  beforeEach(async () => {
    context = await createTestContext();
    mockServer = await setupMockLLMTest(context, {
      response: "Hello from mock LLM!",
    });
  });

  afterEach(async () => {
    await cleanupMockLLMServer(mockServer);
    await cleanupTestContext(context);
  });

  it("should get response from mock", async () => {
    const result = await runCLI(context, {
      args: ["-p", "Test prompt", "--config", context.configPath],
    });
    expect(result.stdout).toContain("Hello from mock LLM!");
  });
});

Advanced Usage

Dynamic Responses

mockServer = await setupMockLLMTest(context, {
  response: (prompt: string) => {
    if (prompt.includes("weather")) {
      return "It's sunny!";
    }
    return "Default response";
  },
});

Non-Streaming Responses

mockServer = await setupMockLLMTest(context, {
  response: "Non-streaming response",
  streaming: false, // Sends entire response at once instead of word-by-word
});

Note: The CLI always expects SSE format, so responses are always sent as streaming events. The streaming option only controls whether the response is chunked word-by-word or sent all at once.

Custom Request Handling

const mockServer = await createMockLLMServer({
  customHandler: (req, res) => {
    // Custom logic here
    res.writeHead(200);
    res.end("Custom response");
  },
});

Request Tracking

The mock server tracks all requests it receives:

// After making requests...
expect(mockServer.requests).toHaveLength(1);
expect(mockServer.requests[0].body.messages[0].content).toBe("User prompt");

API Reference

setupMockLLMTest(context, options)

Sets up a complete test environment with mock LLM server, config file, and skips onboarding.

createMockLLMServer(options)

Creates just the mock server without test environment setup.

createMockLLMConfig(mockServer, modelName)

Generates a config YAML string for the mock server.

cleanupMockLLMServer(mockServer)

Properly shuts down the mock server.