refactor(worker): extract AgentRuntime interface, shared provider helpers, and adapter registry
This commit is contained in:
@@ -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');
|
||||
});
|
||||
});
|
||||
@@ -156,6 +156,7 @@ describe('maintenance workspace cleanup', () => {
|
||||
boxHandle: { boxName: 'spoon-box-tester', release },
|
||||
githubToken: 'github-token',
|
||||
redact: (value: string) => value,
|
||||
runtime: 'codex',
|
||||
containerName: 'spoon-agent-job-maintenance',
|
||||
opencodeSession: {
|
||||
client: {} as never,
|
||||
|
||||
Reference in New Issue
Block a user