feat: implement Stream Spoofing interceptor and robust format preservation patches

This commit is contained in:
lingyuzeng
2026-03-22 17:55:47 +08:00
parent ebd73e1c69
commit ce99e8b418
12 changed files with 426 additions and 11 deletions

View File

@@ -3,11 +3,13 @@ import { buildServer } from '../src/server';
import { FastifyInstance } from 'fastify';
import fs from 'fs';
import path from 'path';
import { config } from '../src/config';
describe('Proxy Integration Test', () => {
let server: FastifyInstance;
beforeEach(() => {
config.proxyMode = 'ollama';
server = buildServer();
// In vitest we can mock the global fetch
global.fetch = vi.fn();
@@ -29,6 +31,7 @@ describe('Proxy Integration Test', () => {
// Mock fetch to return the ollama-xml-response.json
(global.fetch as any).mockResolvedValue({
ok: true,
text: async () => JSON.stringify(responseJson),
json: async () => responseJson
});
@@ -47,14 +50,14 @@ describe('Proxy Integration Test', () => {
expect(fetchArgs[0]).toContain('/api/chat');
const upstreamBody = JSON.parse(fetchArgs[1].body);
expect(upstreamBody.model).toBe('Huihui-Qwen3.5-27B-Claude-4.6-Opus-abliterated-4bit');
expect(upstreamBody.model).toBe('hotwa/qwen35-9b-agent:latest');
// Verify response was rewritten
expect(body.message.content).toBe("");
expect(body.message.tool_calls).toBeDefined();
expect(body.message.tool_calls).toHaveLength(1);
expect(body.message.tool_calls[0].function.name).toBe('read');
expect(JSON.parse(body.message.tool_calls[0].function.arguments)).toEqual({
expect(body.message.tool_calls[0].function.arguments).toEqual({
path: "/tmp/test.txt"
});
});