Lentil Hoffman 50ac2b7b35
refactor: rename Lossless to Hyperview and Lossy to View
- Renamed Lossless class to Hyperview for clarity
- Renamed Lossy class to View for simplicity
- Updated all imports and references throughout the codebase
- Updated documentation to reflect new terminology
- Fixed test files to use new class names
- Added proper exports in index files
2025-07-09 14:28:52 -05:00

95 lines
2.8 KiB
TypeScript

import { describe, test, expect, beforeEach } from '@jest/globals';
import { RhizomeNode, Hyperview } from '@src';
import { CollapsedDelta } from '@src/views/hyperview';
import { CustomResolver, ResolverPlugin } from '@src/views/resolvers/custom-resolvers';
type PropertyTypes = string | number | boolean | null;
describe('Circular Dependency Detection', () => {
let node: RhizomeNode;
let hyperview: Hyperview;
beforeEach(() => {
node = new RhizomeNode();
hyperview = new Hyperview(node);
});
test('should detect circular dependencies', () => {
// PluginA depends on PluginB
class PluginA extends ResolverPlugin<{ value: string }> {
readonly dependencies = ['b'] as const;
initialize() {
return { value: '' };
}
update(currentState: { value: string }, newValue: PropertyTypes, _delta: CollapsedDelta, _dependencies: { b: string }) {
return { value: String(newValue) };
}
resolve(_state: { value: string }) {
return 'a';
}
}
// PluginB depends on PluginA (circular dependency)
class PluginB extends ResolverPlugin<{ value: string }> {
readonly dependencies = ['a'] as const;
initialize() {
return { value: '' };
}
update(_currentState: { value: string }, newValue: PropertyTypes, _delta: CollapsedDelta, _dependencies: { a: string }) {
return { value: String(newValue) };
}
resolve(_state: { value: string }) {
return 'b';
}
}
// Should throw an error when circular dependencies are detected
expect(() => {
new CustomResolver(hyperview, {
'a': new PluginA(),
'b': new PluginB()
});
}).toThrow('Circular dependency detected in plugin dependencies');
});
test('should detect longer circular dependency chains', () => {
class PluginA extends ResolverPlugin<{ value: string }> {
readonly dependencies = ['c'] as const;
initialize() { return { value: '' }; }
update() { return { value: '' }; }
resolve() { return 'a'; }
}
class PluginB extends ResolverPlugin<{ value: string }> {
readonly dependencies = ['a'] as const;
initialize() { return { value: '' }; }
update() { return { value: '' }; }
resolve() { return 'b'; }
}
class PluginC extends ResolverPlugin<{ value: string }> {
readonly dependencies = ['b'] as const;
initialize() { return { value: '' }; }
update() { return { value: '' }; }
resolve() { return 'c'; }
}
// Should detect the circular dependency: a -> c -> b -> a
expect(() => {
new CustomResolver(hyperview, {
'a': new PluginA(),
'b': new PluginB(),
'c': new PluginC()
});
}).toThrow('Circular dependency detected in plugin dependencies');
});
});