98 lines
2.4 KiB
TypeScript
98 lines
2.4 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
|
|
|
import {
|
|
normalizeCodexJsonLine,
|
|
normalizeOpenCodeEvent,
|
|
} from '../../src/agent-events';
|
|
|
|
describe('agent event normalization', () => {
|
|
test('normalizes Codex assistant deltas and session ids', () => {
|
|
expect(
|
|
normalizeCodexJsonLine(
|
|
JSON.stringify({
|
|
type: 'session.created',
|
|
session_id: 'codex-session-1',
|
|
}),
|
|
),
|
|
).toContainEqual({ kind: 'session', sessionId: 'codex-session-1' });
|
|
|
|
expect(
|
|
normalizeCodexJsonLine(
|
|
JSON.stringify({
|
|
type: 'response.output_text.delta',
|
|
delta: 'hello',
|
|
}),
|
|
),
|
|
).toContainEqual({ kind: 'assistant_delta', content: 'hello' });
|
|
});
|
|
|
|
test('normalizes Codex command and file events', () => {
|
|
expect(
|
|
normalizeCodexJsonLine(
|
|
JSON.stringify({
|
|
type: 'command.completed',
|
|
command: 'bun test',
|
|
output: 'ok',
|
|
}),
|
|
),
|
|
).toContainEqual({
|
|
kind: 'command_executed',
|
|
command: 'bun test',
|
|
output: 'ok',
|
|
});
|
|
|
|
expect(
|
|
normalizeCodexJsonLine(
|
|
JSON.stringify({
|
|
type: 'file.edited',
|
|
path: 'src/app.ts',
|
|
}),
|
|
),
|
|
).toContainEqual({ kind: 'file_edited', path: 'src/app.ts' });
|
|
});
|
|
|
|
test('normalizes OpenCode assistant, tool, and permission events', () => {
|
|
expect(
|
|
normalizeOpenCodeEvent({
|
|
type: 'message.part.delta',
|
|
properties: {
|
|
part: { text: 'streamed' },
|
|
messageID: 'message-1',
|
|
},
|
|
}),
|
|
).toContainEqual({
|
|
kind: 'assistant_delta',
|
|
content: 'streamed',
|
|
externalMessageId: 'message-1',
|
|
});
|
|
|
|
expect(
|
|
normalizeOpenCodeEvent({
|
|
type: 'tool.started',
|
|
properties: { tool: 'edit', input: { path: 'README.md' } },
|
|
}),
|
|
).toContainEqual({
|
|
kind: 'tool_started',
|
|
name: 'edit',
|
|
input: '{\n "path": "README.md"\n}',
|
|
externalMessageId: '',
|
|
});
|
|
|
|
expect(
|
|
normalizeOpenCodeEvent({
|
|
type: 'permission.asked',
|
|
properties: {
|
|
permissionID: 'perm-1',
|
|
message: 'Run bun test?',
|
|
},
|
|
}),
|
|
).toContainEqual({
|
|
kind: 'permission_requested',
|
|
externalRequestId: 'perm-1',
|
|
title: 'Permission requested',
|
|
body: 'Run bun test?',
|
|
metadata: '{\n "permissionID": "perm-1",\n "message": "Run bun test?"\n}',
|
|
});
|
|
});
|
|
});
|