Refactor test mocks to access engine instances directly
Update mock retrieval to use actual instances from WorkflowEngine instead of mocking class constructors. Flatten search result fixtures to match updated VaultIndexer return shape.
This commit is contained in:
@@ -52,21 +52,18 @@ function createMockWorkflowEngine(
|
||||
|
||||
const engine = new WorkflowEngine(vault as any, app as any, 'http://localhost:11434', 'llama3');
|
||||
|
||||
// Access private properties via jest mocking
|
||||
const mockVaultIndexer = VaultIndexer as unknown as jest.Mocked<typeof VaultIndexer>;
|
||||
const mockToolExecutor = ToolExecutor as unknown as jest.Mocked<typeof ToolExecutor>;
|
||||
const mockOllamaClient = OllamaClient as unknown as jest.Mocked<typeof OllamaClient>;
|
||||
const mockConversationStateManager = ConversationStateManager as unknown as jest.Mocked<
|
||||
typeof ConversationStateManager
|
||||
>;
|
||||
// Access the actual mock instances created inside WorkflowEngine constructor
|
||||
const mockVaultIndexer = (engine as any).vaultIndexer as jest.Mocked<VaultIndexer>;
|
||||
const mockToolExecutor = (engine as any).toolExecutor as jest.Mocked<ToolExecutor>;
|
||||
const mockOllamaClient = (engine as any).ollamaClient as jest.Mocked<OllamaClient>;
|
||||
const mockConversationStateManager = (engine as any).conversationStateManager as jest.Mocked<ConversationStateManager>;
|
||||
|
||||
return {
|
||||
engine,
|
||||
mockVaultIndexer: mockVaultIndexer.prototype as unknown as jest.Mocked<VaultIndexer>,
|
||||
mockToolExecutor: mockToolExecutor.prototype as unknown as jest.Mocked<ToolExecutor>,
|
||||
mockOllamaClient: mockOllamaClient.prototype as unknown as jest.Mocked<OllamaClient>,
|
||||
mockConversationStateManager:
|
||||
mockConversationStateManager.prototype as unknown as jest.Mocked<ConversationStateManager>,
|
||||
mockVaultIndexer,
|
||||
mockToolExecutor,
|
||||
mockOllamaClient,
|
||||
mockConversationStateManager,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -534,18 +531,18 @@ describe('WorkflowEngine', () => {
|
||||
it('should execute vault search step successfully', async () => {
|
||||
const mockEntries = [
|
||||
{
|
||||
file: { path: 'meeting-note.md', basename: 'meeting-note' },
|
||||
path: 'meeting-note.md',
|
||||
title: 'Team Meeting',
|
||||
content: 'Meeting notes content',
|
||||
score: 10,
|
||||
frontmatter: { tags: 'meeting,team' },
|
||||
tags: 'meeting,team',
|
||||
},
|
||||
{
|
||||
file: { path: 'project-update.md', basename: 'project-update' },
|
||||
path: 'project-update.md',
|
||||
title: 'Project Update',
|
||||
content: 'Project progress notes',
|
||||
score: 8,
|
||||
frontmatter: { tags: 'meeting,project' },
|
||||
tags: 'meeting,project',
|
||||
},
|
||||
];
|
||||
|
||||
@@ -581,18 +578,18 @@ describe('WorkflowEngine', () => {
|
||||
it('should apply tag filter in vault search', async () => {
|
||||
const mockEntries = [
|
||||
{
|
||||
file: { path: 'meeting-note.md', basename: 'meeting-note' },
|
||||
path: 'meeting-note.md',
|
||||
title: 'Team Meeting',
|
||||
content: 'Meeting notes',
|
||||
score: 10,
|
||||
frontmatter: { tags: 'meeting,team' },
|
||||
tags: 'meeting,team',
|
||||
},
|
||||
{
|
||||
file: { path: 'personal-note.md', basename: 'personal-note' },
|
||||
path: 'personal-note.md',
|
||||
title: 'Personal Note',
|
||||
content: 'Personal thoughts',
|
||||
score: 8,
|
||||
frontmatter: { tags: 'personal,daily' },
|
||||
tags: 'personal,daily',
|
||||
},
|
||||
];
|
||||
|
||||
@@ -727,7 +724,7 @@ describe('WorkflowEngine', () => {
|
||||
it('should execute format step with variable interpolation', async () => {
|
||||
mockVaultIndexer.searchVault.mockResolvedValueOnce([
|
||||
{
|
||||
file: { path: 'note.md' },
|
||||
path: 'note.md',
|
||||
title: 'Test Note',
|
||||
content: 'Note content',
|
||||
score: 10,
|
||||
@@ -845,7 +842,7 @@ describe('WorkflowEngine', () => {
|
||||
it('should execute multiple steps in sequence', async () => {
|
||||
mockVaultIndexer.searchVault.mockResolvedValueOnce([
|
||||
{
|
||||
file: { path: 'note.md' },
|
||||
path: 'note.md',
|
||||
title: 'Test Note',
|
||||
content: 'Content',
|
||||
score: 10,
|
||||
@@ -994,7 +991,7 @@ describe('WorkflowEngine', () => {
|
||||
it('should handle initial variables correctly', async () => {
|
||||
mockVaultIndexer.searchVault.mockResolvedValueOnce([
|
||||
{
|
||||
file: { path: 'note.md' },
|
||||
path: 'note.md',
|
||||
title: 'Meeting',
|
||||
content: 'Content',
|
||||
score: 10,
|
||||
@@ -1083,7 +1080,7 @@ describe('WorkflowEngine', () => {
|
||||
it('should interpolate simple variables', async () => {
|
||||
mockVaultIndexer.searchVault.mockResolvedValueOnce([
|
||||
{
|
||||
file: { path: 'note.md' },
|
||||
path: 'note.md',
|
||||
title: 'Note',
|
||||
content: 'Content',
|
||||
score: 10,
|
||||
|
||||
Reference in New Issue
Block a user