**feat(tests): add tests for TextEncoder, TensorFlow.js, and fallback mechanisms**

- Introduced `test-fallback-function.js` and `test-fallback-simple.js` to validate `executeInThread` fallback functionality with both named and anonymous compute-intensive functions.
- Added `test-tensorflow-textencoder.js` for TensorFlow.js and TextEncoder tests in a Node.js environment.
- Created `test-tensorflow-textencoder.html` for browser-based TensorFlow.js and TextEncoder tests.
- Implemented cross-environment test support in `cli-package/src/test-tensorflow-textencoder.ts` for CLI functionality.
- Enhanced `src/utils/embedding.ts`, `textEncoding.ts`, and `brainy-wrapper.js` to include updated global `TextEncoder` and `TextDecoder` utilities for compatibility and worker improvements.
- Standardized and expanded utility methods in `PlatformNode` for broader support, including `isFloat32Array` and `isTypedArray` checks.
- Updated Node.js requirement to `>= 24.4.0` across documentation and configuration files for compatibility improvements.

This update introduces comprehensive testing for fallback mechanisms, TensorFlow.js, and TextEncoder across multiple environments, ensuring robustness and compatibility.
This commit is contained in:
David Snelling 2025-07-11 11:11:56 -07:00
parent 00039f836f
commit f0db5b471f
30 changed files with 1799 additions and 1583 deletions

View file

@ -5,13 +5,8 @@
* A command-line interface for interacting with the Brainy vector database
*/
// Import the unified text encoding utilities
// This needs to be done before importing @soulcraft/brainy
import { applyTensorFlowPatch } from './utils/textEncoding.js'
// Apply the TensorFlow.js platform patch if needed
// Log environment information
console.log('Brainy running in Node.js environment')
applyTensorFlowPatch()
import {
BrainyData,
@ -1360,6 +1355,21 @@ augmentCommand
// Add the augment command to the program
program.addCommand(augmentCommand)
// Add a top-level test-tensorflow-textencoder command
program
.command('test-tensorflow-textencoder')
.description('Test TensorFlow.js and TextEncoder functionality')
.action(async () => {
try {
// Import the test function from the test file
const { runTest } = await import('./test-tensorflow-textencoder.js')
await runTest()
} catch (error) {
console.error('Error:', (error as Error).message)
process.exit(1)
}
})
// Add a top-level test-pipeline command that redirects to augment test-pipeline
program
.command('test-pipeline')