Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
lobehub avatar

Testing

  • 1.5k installs
  • 81.3k repo stars
  • Updated August 5, 2026
  • lobehub/lobe-chat

This is a copy of testing by lobehub - installs and ranking accrue to the original listing.

testing is a Lobe Chat skill that documents end-to-end testing patterns for AI agent runtimes with minimal mocking for developers who need reliable E2E coverage using PGLite and in-memory state managers instead of full e

About

testing is the Agent Runtime E2E Testing Guide from lobe-chat. It follows a Minimal Mock Principle: only three external dependencies are mocked—database via PGLite from `@lobechat/database/test-utils`, Redis via InMemoryAgentStateManager, and stream events via InMemoryStreamEventManager. Model-bank and other internals run with real configuration rather than stubs. Developers reach for this skill when writing E2E tests for AI agent runtimes that must exercise realistic paths without standing up production databases or Redis. The approach prioritizes faithful runtime behavior over heavy isolation.

  • Minimal Mock Principle: only mock Database (PGLite), Redis state, and Redis stream managers
  • Uses real model-bank, Mecha, AgentRuntimeService and AgentRuntimeCoordinator in every test
  • Always prefer vi.spyOn over vi.mock for flexible per-test LLM responses
  • Default model is always gpt-5 from model-bank for test stability
  • Provides reusable test helpers including getTestDB and createOpenAIStreamResponse

Testing by the numbers

  • 1,518 all-time installs (skills.sh)
  • +83 installs in the week ending Aug 4, 2026 (Skillselion tracking)
  • Security screen: LOW risk (skills.sh audit)
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/lobehub/lobe-chat --skill testing

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs1.5k
repo stars81.3k
Security audit3 / 3 scanners passed
Last updatedAugust 5, 2026
Repositorylobehub/lobe-chat

How do you E2E test AI agent runtimes with minimal mocks?

Run reliable end-to-end tests for AI agent runtimes with minimal mocking.

Who is it for?

Backend developers on Lobe Chat or similar agent runtimes who need E2E tests with only database and Redis mocked.

Skip if: Teams testing unrelated UI components or projects without agent runtime architecture should skip this Lobe Chat-specific testing guide.

When should I use this skill?

User writes E2E tests for AI agent runtimes, PGLite test setup, or minimal-mock agent integration tests in lobe-chat.

What you get

End-to-end agent runtime test suites using PGLite and in-memory Redis substitutes with real model-bank configuration.

  • E2E test files
  • PGLite and in-memory manager test setup

By the numbers

  • Mocks exactly 3 external dependencies in agent runtime E2E tests

Files

SKILL.mdMarkdownGitHub ↗

LobeHub Testing Guide

Quick Reference

Commands:

# Run specific test file
bunx vitest run --silent='passed-only' '[file-path]'

# Database package (client-db, PGlite — default, skips BM25/pg_search)
cd packages/database && bunx vitest run --silent='passed-only' '[file]'

# Database package (server-db, Postgres — BM25/pgvector parity, what CI measures coverage in)
cd packages/database && TEST_SERVER_DB=1 bunx vitest run --silent='passed-only' '[file]'

Never run bun run test - it runs all 3000+ tests (\~10 minutes).

Database models/repositories: every new file under packages/database/src/models/**
or src/repositories/** ships with a sibling __tests__/<name>.test.ts in the same PR.
Use the real DB via getTestDB() (integration style), guard BM25/full-text-search blocks
with describe.skipIf(!isServerDB), and always test user-isolation. See
references/db-model-test.md for setup, schema gotchas, and the client-vs-server-db split.

Test Categories

CategoryLocationConfig
Webappsrc/**/*.test.ts(x)vitest.config.ts
Packagespackages/*/**/*.test.tspackages/*/vitest.config.ts
Desktopapps/desktop/**/*.test.tsapps/desktop/vitest.config.ts

Core Principles

1. Prefer `vi.spyOn` over `vi.mock` - More targeted, easier to maintain 2. Tests must pass type check - Run bun run type-check after writing tests 3. After 1-2 failed fix attempts, stop and ask for help 4. Test behavior, not implementation details 5. Regression tests for bug fixes - After fixing a bug, add a regression test that fails before the fix and passes after, to prevent recurrence 6. No new component tests - Only update existing React component tests. Complex logic should be extracted into hooks and tested there instead 7. All source changes before any test changes - Complete all source file edits first, then update tests in a separate pass. Interleaving disrupts reasoning about the source changes, especially across many files

Basic Test Structure

import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';

beforeEach(() => {
  vi.clearAllMocks();
});

afterEach(() => {
  vi.restoreAllMocks();
});

describe('ModuleName', () => {
  describe('functionName', () => {
    it('should handle normal case', () => {
      // Arrange → Act → Assert
    });
  });
});

Mock Patterns

// ✅ Spy on direct dependencies
vi.spyOn(messageService, 'createMessage').mockResolvedValue('id');

// ✅ Use vi.stubGlobal for browser APIs
vi.stubGlobal('Image', mockImage);
vi.spyOn(URL, 'createObjectURL').mockReturnValue('blob:mock');

// ❌ Avoid mocking entire modules globally
vi.mock('@/services/chat'); // Too broad

Detailed Guides

See references/ for specific testing scenarios:

  • Database Model testing: references/db-model-test.md
  • Electron IPC testing: references/electron-ipc-test.md
  • Zustand Store Action testing: references/zustand-store-action-test.md
  • Agent Runtime E2E testing: references/agent-runtime-e2e.md
  • Desktop Controller testing: references/desktop-controller-test.md

Fixing Failing Tests — Optimize or Delete?

When tests fail due to implementation changes (not bugs), evaluate before blindly fixing:

Keep & Fix (update test data/assertions)

  • Behavior tests: Tests that verify _what_ the code does (output, side effects, user-visible behavior). Just update mock data formats or expected values.
  • Example: Tool data structure changed from { name } to { function: { name } } → update mock data
  • Example: Output format changed from Current date: YYYY-MM-DD to Current date: YYYY-MM-DD (TZ) → update expected string

Delete (over-specified, low value)

  • Param-forwarding tests: Tests that assert exact internal function call arguments (e.g., expect(internalFn).toHaveBeenCalledWith(expect.objectContaining({ exact params }))) — these break on every refactor and duplicate what behavior tests already cover.
  • Implementation-coupled tests: Tests that verify _how_ the code works internally rather than _what_ it produces. If a higher-level test already covers the same behavior, the low-level test adds maintenance cost without coverage gain.

Decision Checklist

1. Does the test verify externally observable behavior (API response, DB write, rendered output)? → Keep 2. Does the test only verify internal wiring (which function receives which params)? → Check if a behavior test already covers it. If yes → Delete 3. Is the same behavior already tested at a higher integration level? → Delete the lower-level duplicate 4. Would the test break again on the next routine refactor? → Consider raising to integration level or deleting

When Writing New Tests

  • Prefer integration-level assertions (verify final output) over white-box assertions (verify internal calls)
  • Use expect.objectContaining only for stable, public-facing contracts — not for internal param shapes that change with refactors
  • Mock at boundaries (DB, network, external services), not between internal modules

Common Issues

1. Module pollution: Use vi.resetModules() when tests fail mysteriously 2. Mock not working: Check setup position and use vi.clearAllMocks() in beforeEach 3. Test data pollution: Clean database state in beforeEach/afterEach 4. Async issues: Wrap state changes in act() for React hooks

Related skills

How it compares

Use this skill for Lobe Chat agent runtime E2E with surgical mocks; use react-testing-library when the target is React DOM components instead.

FAQ

What does the Lobe Chat testing skill mock?

The Lobe Chat testing skill mocks only three dependencies: database via PGLite, Redis agent state via InMemoryAgentStateManager, and stream events via InMemoryStreamEventManager. Model-bank and other runtime internals are not mocked.

Why use minimal mocking for agent runtime E2E tests?

The Lobe Chat testing guide applies a Minimal Mock Principle so E2E suites exercise real model-bank configuration and runtime paths while avoiding production database or Redis setup, improving confidence before ship.

Is Testing safe to install?

skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

Testing & QAagentsautomation

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.