- 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.
88 lines
2.2 KiB
TypeScript
88 lines
2.2 KiB
TypeScript
// @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);
|
|
});
|
|
});
|