fix(ai): restore FakeOpenAI mock .withResponse() so openai-completions tests pass
The openai-completions provider now calls .withResponse() on the
create() result to surface HTTP status/headers for the new onResponse
hook (d131fcd4). The FakeOpenAI test mock only returned an async
iterable, so 4 tests in openai-completions-tool-choice.test.ts that
actually consume the stream failed with "withResponse is not a function".
Updated the mock to return a Promise augmented with .withResponse()
resolving to { data: <async iterable>, response: { status, headers } }.
closes #3304
This commit is contained in:
@@ -24,9 +24,9 @@ vi.mock("openai", () => {
|
||||
class FakeOpenAI {
|
||||
chat = {
|
||||
completions: {
|
||||
create: async (params: unknown) => {
|
||||
create: (params: unknown) => {
|
||||
mockState.lastParams = params;
|
||||
return {
|
||||
const stream = {
|
||||
async *[Symbol.asyncIterator]() {
|
||||
const chunks = mockState.chunks ?? [
|
||||
{
|
||||
@@ -44,6 +44,17 @@ vi.mock("openai", () => {
|
||||
}
|
||||
},
|
||||
};
|
||||
const promise = Promise.resolve(stream) as Promise<typeof stream> & {
|
||||
withResponse: () => Promise<{
|
||||
data: typeof stream;
|
||||
response: { status: number; headers: Headers };
|
||||
}>;
|
||||
};
|
||||
promise.withResponse = async () => ({
|
||||
data: stream,
|
||||
response: { status: 200, headers: new Headers() },
|
||||
});
|
||||
return promise;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user