rhizome-node/docs/test-helpers.md
Lentil Hoffman d7c4fda93e
refactor(resolver): overhaul plugin system and dependency handling
Core Changes:
- Completely rewrote CustomResolver reducer with dependency-ordered processing
- Enhanced plugin initialization with proper dependency injection
- Improved delta processing and property value tracking
- Added robust error handling for duplicate property IDs

Resolver Improvements:
- Updated to use new accumulator structure
- Implemented execution order processing for plugins
- Enhanced debug logging and error reporting
- Simplified TimestampResolver by removing unused initializer

Configuration Updates:
- Added TypeScript path aliases for test helpers
- Improved module resolution paths

Key Benefits:
- More robust plugin dependency management
- More efficient state updates
- Enhanced type safety
- Better error messages and debugging
- More consistent plugin initialization

This refactoring focuses on improving the robustness of the resolver,
especially around plugin lifecycle management and dependency handling.
The changes ensure better separation of concerns and more predictable
behavior when dealing with complex plugin dependencies.
2025-06-25 06:10:34 -05:00

2.8 KiB

Test Helpers

This document provides documentation for the test helper functions available in the Rhizome Node test suite.

testResolverWithPlugins

A helper function for testing custom resolvers with plugins and a sequence of deltas.

Import

import { testResolverWithPlugins, createTestDelta } from '@test-helpers/resolver-test-helper';

Signature

function testResolverWithPlugins<T>({
  entityId,
  plugins,
  deltas,
  expectedResult
}: {
  entityId: string;
  plugins: Record<string, ResolverPlugin>;
  deltas: Delta[];
  expectedResult: (result: T) => void;
}): Promise<void>;

Parameters

  • entityId: The ID of the entity to test
  • plugins: An object mapping property names to their respective resolver plugins
  • deltas: An array of Delta objects to process
  • expectedResult: A callback function that receives the resolved result for assertions

Return Value

A promise that resolves when the test is complete.

Example Usage

import { testResolverWithPlugins, createTestDelta } from '@test-helpers/resolver-test-helper';
import { ConcatenationPlugin } from '@src/views/resolvers/custom-resolvers/builtin-plugins';

describe('MyCustomResolver', () => {
  test('should process deltas correctly', async () => {
    // Run test with plugins and deltas
    await testResolverWithPlugins({
      entityId: 'entity1',
      plugins: {
        myProperty: new ConcatenationPlugin()
      },
      deltas: [
        createTestDelta('user1', 'host1')
          .setProperty('entity1', 'myProperty', 'value1')
          .buildV1(),
        createTestDelta('user1', 'host1')
          .setProperty('entity1', 'myProperty', 'value2')
          .buildV1()
      ],
      expectedResult: (result) => {
        expect(result.properties.myProperty).toBe('value1 value2');
      }
    });
  });
});

createTestDelta

A helper function for creating test deltas with a fluent API.

Example Usage

const delta = createTestDelta('user1', 'host1')
  .withTimestamp(1000)
  .setProperty('entity1', 'tags', 'red', 'color1')
  .buildV1();

How It Works

  1. Creates a new Lossless instance for the test
  2. Sets up a CustomResolver with the provided plugins
  3. Ingests all provided deltas into the Lossless instance
  4. Retrieves a view for the specified entity
  5. Processes the view through the resolver
  6. Calls the expectedResult callback with the resolved entity

Best Practices

  • Use this helper when testing custom resolvers with plugins
  • The helper handles all setup and teardown of test resources
  • Use createTestDelta for consistent delta creation in tests
  • The helper ensures type safety between the resolver and the expected result type
  • Each test gets a fresh Lossless instance automatically