Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
114 lines
3.7 KiB
TypeScript
114 lines
3.7 KiB
TypeScript
import { describe, it } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { MockLanguageModelV4, simulateReadableStream } from 'ai/test';
|
|
import { processCattyStream, shouldEmitAgentEventsForStreamChunk } from './turnDrivers/cattyStreamProcessor';
|
|
import { createInitialCattyRuntimeContext } from './cattyRuntimeContext';
|
|
import type { ChatMessage } from '../types';
|
|
|
|
describe('shouldEmitAgentEventsForStreamChunk', () => {
|
|
it('suppresses trace events for SDK internal stream-state errors', () => {
|
|
assert.equal(
|
|
shouldEmitAgentEventsForStreamChunk({
|
|
type: 'error',
|
|
error: new Error('reasoning part abc not found'),
|
|
}),
|
|
false,
|
|
);
|
|
});
|
|
|
|
it('still emits trace events for real stream errors', () => {
|
|
assert.equal(
|
|
shouldEmitAgentEventsForStreamChunk({
|
|
type: 'error',
|
|
error: new Error('Provider returned HTTP 500'),
|
|
}),
|
|
true,
|
|
);
|
|
assert.equal(
|
|
shouldEmitAgentEventsForStreamChunk({ type: 'text-delta', text: 'hi' }),
|
|
true,
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('processCattyStream reasoning continuation', () => {
|
|
it('persists reasoning encrypted content delivered on reasoning-end', async () => {
|
|
const model = new MockLanguageModelV4({
|
|
doStream: async () => ({
|
|
stream: simulateReadableStream({
|
|
chunks: [
|
|
{ type: 'stream-start', warnings: [] },
|
|
{
|
|
type: 'reasoning-start',
|
|
id: 'r1',
|
|
providerMetadata: { openai: { itemId: 'rs_1' } },
|
|
},
|
|
{
|
|
type: 'reasoning-delta',
|
|
id: 'r1',
|
|
delta: 'thinking',
|
|
providerMetadata: { openai: { itemId: 'rs_1' } },
|
|
},
|
|
{
|
|
type: 'reasoning-end',
|
|
id: 'r1',
|
|
providerMetadata: {
|
|
openai: { itemId: 'rs_1', reasoningEncryptedContent: 'enc-abc' },
|
|
},
|
|
},
|
|
{
|
|
type: 'finish',
|
|
finishReason: { unified: 'stop', raw: undefined },
|
|
usage: {
|
|
inputTokens: { total: 1, noCache: 1, cacheRead: undefined, cacheWrite: undefined },
|
|
outputTokens: { total: 1, text: 1, reasoning: undefined },
|
|
},
|
|
},
|
|
],
|
|
}),
|
|
}),
|
|
});
|
|
|
|
const messages = new Map<string, ChatMessage>();
|
|
messages.set('assistant-1', {
|
|
id: 'assistant-1',
|
|
role: 'assistant',
|
|
content: '',
|
|
timestamp: 0,
|
|
});
|
|
const ui = {
|
|
addMessageToSession: (sessionId: string, message: ChatMessage) => {
|
|
messages.set(message.id, message);
|
|
},
|
|
updateMessageById: (sessionId: string, messageId: string, updater: (msg: ChatMessage) => ChatMessage) => {
|
|
const message = messages.get(messageId);
|
|
if (message) messages.set(messageId, updater(message));
|
|
},
|
|
};
|
|
|
|
await processCattyStream({
|
|
streamSessionId: 'session-1',
|
|
model,
|
|
systemPrompt: 'test',
|
|
toolsBundle: { tools: {}, toolsContext: {} },
|
|
sdkMessages: [{ role: 'user', content: 'hello' }],
|
|
signal: new AbortController().signal,
|
|
currentAssistantMsgId: 'assistant-1',
|
|
maxIterations: 1,
|
|
runtimeContext: createInitialCattyRuntimeContext({
|
|
chatSessionId: 'session-1',
|
|
turnId: 'turn-1',
|
|
permissionMode: 'auto',
|
|
scopeType: 'terminal',
|
|
}),
|
|
ui,
|
|
});
|
|
|
|
const continuation = messages.get('assistant-1')?.providerContinuation;
|
|
const encryptedContent = continuation?.reasoningParts?.at(-1)?.providerOptions?.openai
|
|
?.reasoningEncryptedContent;
|
|
assert.equal(encryptedContent, 'enc-abc');
|
|
assert.match(continuation?.reasoningParts?.map(part => part.text).join('') ?? '', /thinking/);
|
|
});
|
|
});
|