Testing & Debugging
Relevant source files
The following files were used as context for generating this wiki page:
- app/lib/runtime/message-parser.spec.ts
- vite.config.ts
- package.json
- CONTRIBUTING.md
- README.md
- app/lib/runtime/message-parser.ts
- app/utils/logger.ts (Referenced via imports in multiple files)
Testing and debugging in the Bolt project are centered around ensuring the integrity of AI-generated content parsing, maintaining a stable development environment, and providing detailed runtime visibility through logging. The project utilizes a modern testing stack led by Vitest for unit and integration testing, complemented by TypeScript for static type checking and ESLint for code quality enforcement.
The debugging workflow is enhanced by environment-specific configurations, such as adjustable log levels and specific browser requirements for local development. This ensures that developers can effectively trace the flow of data between the AI SDK, the Message Parser, and the WebContainer environment.
Sources: CONTRIBUTING.md:104-106, README.md:124-126
Testing Infrastructure
The project relies on Vitest as its primary test runner. The test suite is designed to validate critical path components, particularly the StreamingMessageParser, which handles the complex task of stripping and executing AI-generated artifacts.
Test Execution Commands
| Command | Description |
|---|---|
pnpm test | Runs the full test suite using Vitest in a single run. |
pnpm test:watch | Starts Vitest in watch mode for a test-driven development (TDD) workflow. |
pnpm run typecheck | Executes the TypeScript compiler (tsc) to verify type safety without emitting files. |
pnpm run lint | Runs ESLint to identify and report on code patterns and potential errors. |
Sources: package.json:12-21, CONTRIBUTING.md:86-91
Unit Testing: Message Parser
The message-parser.spec.ts file provides extensive unit tests for the StreamingMessageParser. These tests ensure that the parser correctly handles various scenarios including normal text passthrough, HTML tags, and the detection of <boltArtifact> and <boltAction> tags.
The diagram above illustrates the logic verified by the unit tests: ensuring that structural tags used for system commands are stripped from the user-facing UI while triggering appropriate callbacks.
Sources: app/lib/runtime/message-parser.spec.ts:13-25, app/lib/runtime/message-parser.ts:47-55
Debugging and Environment Configuration
Debugging is facilitated through environment variables and specific Vite server configurations that prevent known browser-specific issues during development.
Logging Configuration
Bolt uses a scoped logger that can be adjusted via environment variables. This allows developers to increase verbosity when troubleshooting specific modules.
- Variable:
VITE_LOG_LEVEL - Levels:
trace,debug,info,warn,error - Usage: Setting
VITE_LOG_LEVEL=debugin.env.localenables detailed logs for internal operations like artifact parsing and WebContainer interactions.
Sources: CONTRIBUTING.md:76-78, app/lib/runtime/message-parser.ts:13
Development Server & Browser Compatibility
The project includes a specific Vite plugin, chrome129IssuePlugin, to handle a known regression in Chrome 129 regarding JavaScript modules. This serves as a debugging aid by providing clear feedback to the developer when an incompatible browser version is detected.
This sequence shows the server-level interceptor that manages browser-specific debugging warnings.
Sources: vite.config.ts:38-66
Local Environment Setup
For local debugging of the production-like environment, the project provides a preview script. This is critical for testing features like HTTP streaming, which may behave differently in the development server compared to the production Cloudflare Pages environment.
| Feature | Local Dev (pnpm dev) | Preview (pnpm preview) |
|---|---|---|
| Server | Remix Vite Server | Wrangler Pages Dev |
| Debug Info | Hot Module Replacement (HMR) | Production build artifacts |
| Streaming | Fully supported | May have limitations with wrangler |
Sources: README.md:113-119, CONTRIBUTING.md:87-89
Static Analysis and Quality Assurance
Beyond dynamic testing, the project employs strict static analysis to prevent runtime errors.
- TypeScript (
tsconfig.json): Configured withstrict: trueandESNexttargets to ensure modern, safe code. It usesmoduleResolution: "Bundler"to align with Vite's resolution logic. - Linting: Uses a custom plugin
@blitz/eslint-pluginto enforce project-specific coding standards. - Type Generation:
pnpm run typegenuses Wrangler to generate types for Cloudflare environment bindings, ensuring that interactions with platform features are type-safe.
Sources: tsconfig.json:11-15, package.json:20-43, CONTRIBUTING.md:90
Summary
The Testing & Debugging framework in Bolt is designed to protect the integrity of the AI-to-WebContainer pipeline. By combining robust unit tests for the StreamingMessageParser with environment-aware logging and specific browser compatibility checks, the project ensures that developers can build and troubleshoot AI-powered development tools with high confidence.