Files
spoon/apps/agent-worker/tests/unit/agent-runtime.test.ts
T

43 lines
1.4 KiB
TypeScript

import { describe, expect, test } from 'vitest';
import type { AgentRuntime } from '../../src/runtime/agent-runtime';
import type { Claim } from '../../src/runtime/provider';
import { getAdapter, registerAdapter } from '../../src/runtime/agent-runtime';
import { isCodexLoginProfile, opencodeModel } from '../../src/runtime/provider';
describe('agent runtime registry', () => {
test('registerAdapter/getAdapter resolves a registered runtime', () => {
const fake: AgentRuntime = {
name: 'codex',
prepareAuth: () => Promise.resolve(),
runTurn: () => Promise.resolve({}),
abort: () => Promise.resolve(),
};
registerAdapter('codex', () => fake);
expect(getAdapter('codex').name).toBe('codex');
});
test('getAdapter throws for an unregistered runtime', () => {
expect(() => getAdapter('opencode')).toThrow(/No agent runtime adapter/);
});
});
describe('shared provider helpers re-exported from runtime/provider', () => {
test('isCodexLoginProfile detects opencode login profiles', () => {
expect(
isCodexLoginProfile({
aiProviderProfile: { provider: 'opencode_openai_login' },
} as Claim),
).toBe(true);
expect(isCodexLoginProfile({} as Claim)).toBe(false);
});
test('opencodeModel prefixes the provider', () => {
expect(
opencodeModel({
aiProviderProfile: { provider: 'anthropic', model: 'claude-x' },
} as Claim),
).toBe('anthropic/claude-x');
});
});