Add unit tests for skill capabilities, skill planner, and UV setup
- Implement tests for random ID generation, ensuring preference for crypto.randomUUID. - Create tests for runtime context capabilities, validating the injection of enabled skill capabilities. - Add tests for skill capability parsing, including classification and command example extraction. - Introduce tests for the skill planner, verifying tool call planning based on user requests and attachment requirements. - Establish tests for UV setup, ensuring proper handling of Python installation scenarios and environment checks.
This commit is contained in:
87
tests/chat-store-runtime-refresh.test.ts
Normal file
87
tests/chat-store-runtime-refresh.test.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
// @vitest-environment node
|
||||
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
const mocks = vi.hoisted(() => {
|
||||
let gatewayEventHandler: ((event: any) => void | Promise<void>) | null = null;
|
||||
|
||||
return {
|
||||
gatewayRpc: vi.fn(),
|
||||
hostApiFetch: vi.fn(),
|
||||
onGatewayEvent: vi.fn((callback: (event: any) => void | Promise<void>) => {
|
||||
gatewayEventHandler = callback;
|
||||
return () => {
|
||||
gatewayEventHandler = null;
|
||||
};
|
||||
}),
|
||||
emitGatewayEvent: async (event: any) => {
|
||||
await gatewayEventHandler?.(event);
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock('../src/lib/gateway-client', () => ({
|
||||
gatewayRpc: mocks.gatewayRpc,
|
||||
onGatewayEvent: mocks.onGatewayEvent,
|
||||
}));
|
||||
|
||||
vi.mock('../src/lib/host-api', () => ({
|
||||
hostApiFetch: mocks.hostApiFetch,
|
||||
}));
|
||||
|
||||
vi.mock('../src/stores/agents', () => ({
|
||||
agentsStore: {
|
||||
init: vi.fn(async () => undefined),
|
||||
resolveMainSessionKey: vi.fn(() => 'agent:test:main'),
|
||||
getState: vi.fn(() => ({
|
||||
defaultAgentId: 'test',
|
||||
defaultProviderAccountId: null,
|
||||
})),
|
||||
getAgentById: vi.fn(() => undefined),
|
||||
},
|
||||
}));
|
||||
|
||||
describe('chat store runtime refresh', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules();
|
||||
vi.clearAllMocks();
|
||||
|
||||
mocks.gatewayRpc.mockImplementation(async (method: string) => {
|
||||
if (method === 'session.list') {
|
||||
return ['agent:test:main'];
|
||||
}
|
||||
|
||||
if (method === 'chat.history') {
|
||||
return [];
|
||||
}
|
||||
|
||||
throw new Error(`Unexpected RPC method: ${method}`);
|
||||
});
|
||||
|
||||
mocks.hostApiFetch.mockResolvedValue({
|
||||
messages: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('reloads current history when skills runtime changes', async () => {
|
||||
const { chatStore } = await import('../src/stores/chat');
|
||||
|
||||
await chatStore.init();
|
||||
|
||||
const initialHistoryCalls = mocks.gatewayRpc.mock.calls.filter(
|
||||
([method]) => method === 'chat.history',
|
||||
).length;
|
||||
|
||||
await mocks.emitGatewayEvent({
|
||||
type: 'runtime:changed',
|
||||
topics: ['skills'],
|
||||
syncedAt: new Date().toISOString(),
|
||||
});
|
||||
|
||||
const afterRefreshHistoryCalls = mocks.gatewayRpc.mock.calls.filter(
|
||||
([method]) => method === 'chat.history',
|
||||
).length;
|
||||
|
||||
expect(afterRefreshHistoryCalls).toBe(initialHistoryCalls + 1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user