refactor(worker): extract AgentRuntime interface, shared provider helpers, and adapter registry

This commit is contained in:
Gabriel Brown
2026-07-10 18:28:41 -04:00
parent 697fb7286d
commit 38431155b2
5 changed files with 278 additions and 163 deletions
@@ -0,0 +1,42 @@
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: async () => {},
runTurn: async () => ({}),
abort: async () => {},
};
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');
});
});