continue-custom/extensions/cli/src/test-helpers
Nate Sesti b12499cb0e
feat: show remote sessions in cn ls (#7694)
* feat: /title slash command

* fix: /title slash command should be able to be submitted with text

* test: add tests for last commit's changes

* fix: EOF in action.yml

* feat: list remote sessions in cn ls and /resume

* feat: load more sessions and make them scrollable

* chore: format

* improv: debug script builds automatically for cli

* feat: load remote session

* fix: wrap entrypoint in function so it doesn't run at import-time

* feat: /diff and /apply slash commands for cn remote

* feat: full screen diff viewer

* feat: status message for /apply slash command

* Update extensions/cli/src/ui/UserInput.tsx

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* fix: remove console.logs

* Potential fix for code scanning alert no. 60: Uncontrolled command line

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

* Potential fix for code scanning alert no. 61: Uncontrolled command line

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

* fix: build.js

* feat: list remote sessions in history of extensions

* feat: open remote agents in browser

* chore: fix tests and lint

* fix: import Text

* fix: small bug

* fix: address feedback

* fix: adjust extension gui for compatibility with cli session history

* feat: load session history from remote

* feat: open remote session in browser

* fix: tests, linting, formatting

* fix: don't use any

* address nitpicks

---------

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
2025-09-19 22:44:26 -07:00
..
__tests__ chore: run prettier --write on cli 2025-08-20 17:57:35 -07:00
adapter-mocks.ts Add 'extensions/cli/' from commit 'e27a5c87d520e28844c9eac10bc6d301feee4b5e' 2025-08-20 17:19:56 -07:00
cli-helpers.ts feat: show remote sessions in cn ls (#7694) 2025-09-19 22:44:26 -07:00
mock-helpers.ts Add 'extensions/cli/' from commit 'e27a5c87d520e28844c9eac10bc6d301feee4b5e' 2025-08-20 17:19:56 -07:00
mock-llm-server.ts Add 'extensions/cli/' from commit 'e27a5c87d520e28844c9eac10bc6d301feee4b5e' 2025-08-20 17:19:56 -07:00
README.md Add 'extensions/cli/' from commit 'e27a5c87d520e28844c9eac10bc6d301feee4b5e' 2025-08-20 17:19:56 -07:00
renderWithServices.tsx Add 'extensions/cli/' from commit 'e27a5c87d520e28844c9eac10bc6d301feee4b5e' 2025-08-20 17:19:56 -07:00
testServiceContainer.ts Add 'extensions/cli/' from commit 'e27a5c87d520e28844c9eac10bc6d301feee4b5e' 2025-08-20 17:19:56 -07:00
ui-test-context-minimal.ts Add 'extensions/cli/' from commit 'e27a5c87d520e28844c9eac10bc6d301feee4b5e' 2025-08-20 17:19:56 -07:00
ui-test-context.ts refactor: phase 2 2025-09-01 12:00:43 -07:00

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.