This document outlines the testing strategy, progress, and guidelines for the BBai project. It serves as a reference for current and future testing efforts, ensuring comprehensive coverage and consistent quality across the project.
IMPORTANT: When creating tests for a new tool, it is crucial to use an existing tool's test file as a template. Follow the structure, style, and conventions of existing tests as closely as possible, modifying only what is necessary for the new tool's specific functionality.
When creating tests for a new tool:
- Identify an existing tool test file that is most similar to the new tool you're testing.
- Create a new test file in the
tests
directory within the tool's directory (e.g.,api/src/llms/tools/toolName.tool/tests/tool.test.ts
), using the identified file as a template. - Import necessary testing utilities from Deno's standard testing library.
- Create mock objects for
LLMConversationInteraction
,LLMAnswerToolUse
, andProjectEditor
as needed. - Write tests covering:
- Basic functionality
- Edge cases
- Error scenarios
- Input validation
- Test all public methods of the tool, including
toolUseInputFormatter
andtoolRunResultFormatter
. - Follow the patterns established in existing tool tests for consistency, including:
- Test file structure (imports, test organization)
- Use of
withTestProject
andgetProjectEditor
- Error handling and assertion patterns
- Use of temporary files and directories
- Ensure proper cleanup after each test, especially for file system operations.
- Include tests for both browser and console formatters (
toolUseInputFormatter
andtoolRunResultFormatter
). - Maintain consistent naming conventions for test cases across all tool test files.
- Always use an existing tool's test file as a template and maintain consistency with it as much as possible.
- Each tool should have its own test file within its directory.
- Tests should cover basic functionality, edge cases, and error scenarios.
- Use
Deno.test()
for creating test cases. - Set
sanitizeResources
andsanitizeOps
tofalse
for each test to handle resource management properly. - Use a temporary directory for file-based tests to ensure a clean state for each test.
File: api/src/llms/tools/searchAndReplace.tool/tests/tool.test.ts
Completed tests:
- Basic functionality (modifying existing files)
- Creating new files with
createIfMissing
flag - Multiple operations on a new file
- Attempting to create a file outside the project root
- Handling empty operations array
- Unicode character support
Potential additional tests:
- Very large file content
- Complex search and replace patterns (e.g., regex)
- Error handling for invalid operations
File: api/src/llms/tools/requestFiles.tool/tests/tool.test.ts
Completed tests:
- Requesting existing files
- Attempting to request a non-existent file
- Attempting to request a file outside the project root
Potential additional tests:
- Requesting multiple files (mix of existing and non-existing)
- Handling empty array of file names
- Testing various file path formats (relative, absolute)
- Requesting files with special characters in names
File: api/src/llms/tools/searchProject.tool/tests/tool.test.ts
Completed tests:
- Basic search functionality
- Searching with file pattern restrictions
- Handling searches with no results
- Error handling for invalid search patterns
- Partial testing of search within nested directory structures
Potential additional tests:
- More complex search patterns (e.g., regular expressions)
- Very large projects or files
- Edge cases in nested directory structures
- Implement tests for remaining tools in the
api/src/llms/tools
directory - Consider creating tests for
LLMToolManager
and interaction classes
-
Isolation: Each tool has its own test file within its directory to maintain clear separation of concerns and make it easier to locate and update specific tests.
-
Comprehensive Coverage: We aim to test not just the happy path, but also edge cases and error scenarios to ensure robust tool behavior.
-
File Handling: Many tools interact with the file system. We use a temporary directory for these tests to ensure a clean state and prevent interference between tests.
-
Error Handling: We explicitly test for expected errors (e.g., file not found, access denied) to ensure the tools fail gracefully and provide meaningful error messages.
-
Unicode Support: Testing with Unicode characters ensures the tools can handle a wide range of text inputs correctly.
-
Resource Management: By setting
sanitizeResources
andsanitizeOps
tofalse
, we take responsibility for proper resource cleanup, which is especially important for file system operations. -
Mocking Considerations: While we currently test against a real file system, we may want to consider mocking the file system in the future for more controlled and faster tests.
- Run and verify the implemented SearchProject tool tests.
- Review and expand test coverage for existing tools based on the potential additional tests listed above.
- Implement tests for remaining tools and components (e.g., LLMToolManager, interaction classes).
- Consider implementing integration tests that cover the interaction between multiple tools and components.
- Set up continuous integration to run these tests automatically on each commit or pull request.
- Regularly review and update this document as new tests are added or testing strategies evolve.
- Implemented initial test cases for the SearchProject tool, covering basic functionality, file pattern restrictions, no-result scenarios, and error handling.
- Created a consistent test environment with multiple files and a subdirectory for SearchProject tool tests.
- Updated test file locations to reflect the new tool directory structure.
To maintain consistency across all tool tests:
- Use the same import structure at the beginning of each test file.
- Follow the same pattern for creating test projects and editors (using
withTestProject
andgetProjectEditor
). - Use consistent naming conventions for test cases (e.g., "ToolName - Specific scenario being tested").
- Structure test cases similarly, with setup, execution, and assertion phases clearly defined.
- Use the same patterns for error checking and assertions across all tool tests.
- Include tests for both success and failure scenarios for each tool operation.
- Test both browser and console formatters consistently across all tools.
- All test files should be located in the
tests
directory within each tool's directory. - The main test file for each tool should be named
tool.test.ts
. - Additional test files, if needed, should follow a clear naming convention (e.g.,
formatter.browser.test.ts
,formatter.console.test.ts
).
To run all tests, use the following command from the project root:
deno task test
This command is defined in the deno.jsonc
file (which delegates to the api/deno.jsonc
file) and includes the necessary permissions and test file locations.
Thorough testing is crucial for maintaining the reliability and functionality of the BBai project. By following these guidelines and continuously expanding our test coverage, we can ensure that the project remains robust and dependable as it grows and evolves. The recent updates to the tool directory structure and test file locations demonstrate our commitment to organized and comprehensive testing, laying the groundwork for consistent and reliable testing across all components of the system.