-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/twitter-messages-image-outbound
- Loading branch information
Showing
17 changed files
with
750 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
packages/plugin-bittensor/__tests__/actions/sn34.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { describe, expect, it, vi, beforeEach } from 'vitest'; | ||
import { analyzeImage, analysisHistory } from '../../src/actions/sn34'; | ||
import { elizaLogger } from '@elizaos/core'; | ||
|
||
vi.mock('@elizaos/core', () => ({ | ||
elizaLogger: { | ||
info: vi.fn(), | ||
error: vi.fn(), | ||
debug: vi.fn(), | ||
} | ||
})); | ||
|
||
describe('sn34', () => { | ||
let mockRuntime; | ||
let mockMessage; | ||
let mockState; | ||
let mockCallback; | ||
|
||
beforeEach(() => { | ||
mockRuntime = { | ||
character: { | ||
settings: { | ||
secrets: { | ||
BITMIND: 'test-api-key' | ||
} | ||
} | ||
} | ||
}; | ||
|
||
mockMessage = { | ||
content: { | ||
text: 'analyze this image: https://example.com/image.jpg' | ||
} | ||
}; | ||
|
||
mockState = {}; | ||
mockCallback = vi.fn(); | ||
|
||
// Reset all mocks | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
describe('analyzeImage', () => { | ||
describe('validation', () => { | ||
it('should validate when image URL is present', async () => { | ||
const result = await analyzeImage.validate(mockRuntime, mockMessage); | ||
expect(result).toBe(true); | ||
expect(elizaLogger.info).toHaveBeenCalledWith('🔍 BitMind: Validating analysis request...'); | ||
}); | ||
|
||
it('should fail validation when no image URL is present', async () => { | ||
mockMessage.content.text = 'analyze this image'; | ||
const result = await analyzeImage.validate(mockRuntime, mockMessage); | ||
expect(result).toBe(false); | ||
expect(elizaLogger.error).toHaveBeenCalledWith('❌ BitMind: No image URL found in request'); | ||
}); | ||
|
||
it('should fail validation when API credentials are missing', async () => { | ||
mockRuntime.character.settings.secrets.BITMIND = undefined; | ||
const result = await analyzeImage.validate(mockRuntime, mockMessage); | ||
expect(result).toBe(false); | ||
expect(elizaLogger.error).toHaveBeenCalledWith('❌ BitMind: API credentials not configured'); | ||
}); | ||
}); | ||
|
||
describe('action properties', () => { | ||
it('should have correct action properties', () => { | ||
expect(analyzeImage.name).toBe('DETECT_IMAGE'); | ||
expect(analyzeImage.similes).toEqual([ | ||
'ANALYZE_IMAGE', | ||
'VERIFY_IMAGE', | ||
'BITMIND_DETECTION', | ||
'AI_DETECTION', | ||
'REAL_OR_FAKE' | ||
]); | ||
expect(analyzeImage.examples).toBeDefined(); | ||
expect(Array.isArray(analyzeImage.examples)).toBe(true); | ||
}); | ||
|
||
it('should have valid examples', () => { | ||
analyzeImage.examples.forEach(example => { | ||
expect(Array.isArray(example)).toBe(true); | ||
example.forEach(interaction => { | ||
expect(interaction).toHaveProperty('user'); | ||
expect(interaction).toHaveProperty('content'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('analysisHistory', () => { | ||
describe('validation', () => { | ||
it('should validate successfully', async () => { | ||
const result = await analysisHistory.validate(mockRuntime); | ||
expect(result).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('action properties', () => { | ||
it('should have correct action properties', () => { | ||
expect(analysisHistory.name).toBe('IMAGE_REPORT'); | ||
expect(analysisHistory.similes).toEqual([ | ||
'SHOW_DETECTIONS', | ||
'IMAGE_HISTORY', | ||
'PAST_ANALYSES', | ||
'DETECTION_HISTORY' | ||
]); | ||
expect(analysisHistory.description).toBe('Display history of AI image analysis results'); | ||
expect(analysisHistory.examples).toBeDefined(); | ||
expect(Array.isArray(analysisHistory.examples)).toBe(true); | ||
}); | ||
|
||
it('should have valid examples', () => { | ||
analysisHistory.examples.forEach(example => { | ||
expect(Array.isArray(example)).toBe(true); | ||
example.forEach(interaction => { | ||
expect(interaction).toHaveProperty('user'); | ||
expect(interaction).toHaveProperty('content'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
113 changes: 113 additions & 0 deletions
113
packages/plugin-bittensor/__tests__/evaluators/fact.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { describe, expect, it, vi, beforeEach } from 'vitest'; | ||
import { factEvaluator } from '../../src/evaluators/fact'; | ||
import { composeContext, generateObjectArray, MemoryManager } from '@elizaos/core'; | ||
|
||
vi.mock('@elizaos/core', () => ({ | ||
composeContext: vi.fn(), | ||
generateObjectArray: vi.fn(), | ||
MemoryManager: vi.fn().mockImplementation((config: any) => ({ | ||
getMemoriesByEvaluator: vi.fn().mockResolvedValue([]), | ||
addMemory: vi.fn().mockResolvedValue(true), | ||
addEmbeddingToMemory: vi.fn().mockResolvedValue({ | ||
id: 'test-memory-id', | ||
content: { | ||
text: 'Test memory content' | ||
} | ||
}), | ||
createMemory: vi.fn().mockResolvedValue({ | ||
id: 'test-memory-id', | ||
content: { | ||
text: 'Test memory content' | ||
} | ||
}) | ||
})), | ||
ModelClass: { | ||
SMALL: 'small' | ||
} | ||
})); | ||
|
||
describe('factEvaluator', () => { | ||
let mockRuntime; | ||
let mockMessage; | ||
|
||
beforeEach(() => { | ||
mockRuntime = { | ||
character: { | ||
settings: {} | ||
}, | ||
messageManager: { | ||
countMemories: vi.fn().mockResolvedValue(5) | ||
}, | ||
composeState: vi.fn().mockResolvedValue({ | ||
agentId: 'test-agent', | ||
roomId: 'test-room' | ||
}), | ||
getConversationLength: vi.fn().mockReturnValue(10) | ||
}; | ||
|
||
mockMessage = { | ||
content: { | ||
text: 'I live in New York and work as a software engineer.' | ||
}, | ||
roomId: 'test-room' | ||
}; | ||
|
||
// Reset all mocks | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
describe('validation', () => { | ||
it('should validate successfully', async () => { | ||
const result = await factEvaluator.validate(mockRuntime, mockMessage); | ||
expect(result).toBe(true); | ||
expect(mockRuntime.messageManager.countMemories).toHaveBeenCalledWith('test-room'); | ||
expect(mockRuntime.getConversationLength).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('evaluator properties', () => { | ||
it('should have correct evaluator properties', () => { | ||
expect(factEvaluator.name).toBe('GET_FACTS'); | ||
expect(factEvaluator.similes).toContain('GET_CLAIMS'); | ||
expect(factEvaluator.description).toBeDefined(); | ||
expect(factEvaluator.description).toContain('Extract factual information'); | ||
expect(factEvaluator.examples).toBeDefined(); | ||
expect(Array.isArray(factEvaluator.examples)).toBe(true); | ||
}); | ||
|
||
it('should have valid examples', () => { | ||
factEvaluator.examples.forEach(example => { | ||
expect(example).toBeDefined(); | ||
// Will add more specific example validations based on the example structure | ||
}); | ||
}); | ||
}); | ||
|
||
describe('fact extraction', () => { | ||
it('should handle fact extraction', async () => { | ||
const mockFacts = [ | ||
{ | ||
claim: 'User lives in New York', | ||
type: 'fact', | ||
in_bio: false, | ||
already_known: false | ||
}, | ||
{ | ||
claim: 'User works as a software engineer', | ||
type: 'fact', | ||
in_bio: false, | ||
already_known: false | ||
} | ||
]; | ||
|
||
vi.mocked(composeContext).mockReturnValue('mock-context'); | ||
vi.mocked(generateObjectArray).mockResolvedValue(mockFacts); | ||
|
||
const result = await factEvaluator.handler(mockRuntime, mockMessage); | ||
|
||
expect(composeContext).toHaveBeenCalled(); | ||
expect(generateObjectArray).toHaveBeenCalled(); | ||
expect(result).toBeDefined(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
globals: true, | ||
environment: 'node', | ||
}, | ||
}); |
Oops, something went wrong.