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