Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as opaque submodule gitlinks on GitHub) into fully-tracked first-party content. AITM now merges its 7 vendored repos as first-party engines: - memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts - git: vendored C git (bundled binary) + gitnexus (in-process code intelligence) - agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess) Includes the full session's product build: Gitgram web/mobile/backend features, AITM website/CLI/MCP, the unified memory layer, engine build tooling (scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md), and extensive test suites. Build artifacts, node_modules, external/, and gemini-cli are gitignored. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
98 lines
2.9 KiB
TypeScript
98 lines
2.9 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { streamAgentResponse, type AgentMessage } from '../../src/core/llm/agent';
|
|
|
|
describe('streamAgentResponse abort', () => {
|
|
const userMessage: AgentMessage[] = [{ role: 'user', content: 'hello' }];
|
|
|
|
it('yields cancelled when the LangGraph stream throws AbortError', async () => {
|
|
const agent = {
|
|
stream: async () => {
|
|
throw new DOMException('The operation was aborted', 'AbortError');
|
|
},
|
|
};
|
|
|
|
const chunks = [];
|
|
for await (const chunk of streamAgentResponse(agent as any, userMessage, {
|
|
signal: new AbortController().signal,
|
|
})) {
|
|
chunks.push(chunk);
|
|
}
|
|
|
|
expect(chunks).toEqual([{ type: 'cancelled' }]);
|
|
});
|
|
|
|
it('yields cancelled when the abort signal is set mid-stream', async () => {
|
|
const controller = new AbortController();
|
|
const agent = {
|
|
stream: async function* () {
|
|
yield ['values', { messages: [] }];
|
|
controller.abort();
|
|
for (let i = 0; i < 100; i++) {
|
|
yield ['messages', [{ _getType: () => 'ai', content: 'still going' }]];
|
|
}
|
|
},
|
|
};
|
|
|
|
const chunks = [];
|
|
for await (const chunk of streamAgentResponse(agent as any, userMessage, {
|
|
signal: controller.signal,
|
|
})) {
|
|
chunks.push(chunk);
|
|
if (chunk.type === 'cancelled') break;
|
|
}
|
|
|
|
expect(chunks[chunks.length - 1]).toEqual({ type: 'cancelled' });
|
|
expect(chunks.filter((c) => c.type === 'error')).toEqual([]);
|
|
});
|
|
|
|
it('passes AbortSignal to agent.stream config', async () => {
|
|
const controller = new AbortController();
|
|
let capturedConfig: Record<string, unknown> | undefined;
|
|
|
|
const agent = {
|
|
stream: async (_input: unknown, config: Record<string, unknown>) => {
|
|
capturedConfig = config;
|
|
throw new DOMException('aborted', 'AbortError');
|
|
},
|
|
};
|
|
|
|
for await (const _chunk of streamAgentResponse(agent as any, userMessage, {
|
|
signal: controller.signal,
|
|
})) {
|
|
// drain
|
|
}
|
|
|
|
expect(capturedConfig?.signal).toBe(controller.signal);
|
|
});
|
|
|
|
it('yields cancelled for a plain Error with name AbortError', async () => {
|
|
const agent = {
|
|
stream: async () => {
|
|
throw Object.assign(new Error('aborted'), { name: 'AbortError' });
|
|
},
|
|
};
|
|
|
|
const chunks = [];
|
|
for await (const chunk of streamAgentResponse(agent as any, userMessage)) {
|
|
chunks.push(chunk);
|
|
}
|
|
|
|
expect(chunks).toEqual([{ type: 'cancelled' }]);
|
|
});
|
|
|
|
it('does not treat unrelated errors mentioning abort as cancellation', async () => {
|
|
const agent = {
|
|
stream: async () => {
|
|
throw new Error('Cannot abort the current transaction');
|
|
},
|
|
};
|
|
|
|
const chunks = [];
|
|
for await (const chunk of streamAgentResponse(agent as any, userMessage)) {
|
|
chunks.push(chunk);
|
|
}
|
|
|
|
expect(chunks).toEqual([{ type: 'error', error: 'Cannot abort the current transaction' }]);
|
|
});
|
|
});
|