mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 13:44:47 +00:00
test: dedupe tts contract mock reads
This commit is contained in:
@@ -118,6 +118,14 @@ function asLegacyOpenClawConfig(value: Record<string, unknown>): OpenClawConfig
|
||||
return value as unknown as OpenClawConfig;
|
||||
}
|
||||
|
||||
function mockCallAt(mock: { mock: { calls: Array<Array<unknown>> } }, index: number): unknown[] {
|
||||
const call = mock.mock.calls[index];
|
||||
if (!call) {
|
||||
throw new Error(`expected mock call at index ${index}`);
|
||||
}
|
||||
return call;
|
||||
}
|
||||
|
||||
const mockAssistantMessage = (content: AssistantMessage["content"]): AssistantMessage => ({
|
||||
role: "assistant",
|
||||
content,
|
||||
@@ -900,10 +908,12 @@ export function describeTtsSummarizationContract() {
|
||||
it("calls the summary model with the expected parameters", async () => {
|
||||
await runSummarizeText();
|
||||
|
||||
const callArgs = vi.mocked(completeSimple).mock.calls.at(0);
|
||||
expect(callArgs?.[1]?.messages?.[0]?.role).toBe("user");
|
||||
expect(callArgs?.[2]?.maxTokens).toBe(250);
|
||||
expect(callArgs?.[2]?.temperature).toBe(0.3);
|
||||
const callArgs = mockCallAt(vi.mocked(completeSimple), 0);
|
||||
expect(
|
||||
(callArgs[1] as { messages?: Array<{ role?: string }> } | undefined)?.messages?.[0]?.role,
|
||||
).toBe("user");
|
||||
expect((callArgs[2] as { maxTokens?: number } | undefined)?.maxTokens).toBe(250);
|
||||
expect((callArgs[2] as { temperature?: number } | undefined)?.temperature).toBe(0.3);
|
||||
expect(getApiKeyForModelMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
@@ -928,7 +938,9 @@ export function describeTtsSummarizationContract() {
|
||||
|
||||
await runSummarizeText();
|
||||
|
||||
expect(vi.mocked(completeSimple).mock.calls.at(0)?.[0]?.api).toBe("openai-completions");
|
||||
expect(
|
||||
(mockCallAt(vi.mocked(completeSimple), 0)[0] as { api?: string } | undefined)?.api,
|
||||
).toBe("openai-completions");
|
||||
expect(ensureCustomApiRegisteredMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -1196,7 +1208,7 @@ export function describeTtsProviderRuntimeContract() {
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
const [, init] = fetchMock.mock.calls.at(0) as [string, RequestInit];
|
||||
const [, init] = mockCallAt(fetchMock, 0) as [string, RequestInit];
|
||||
expect(typeof init.body).toBe("string");
|
||||
const body = JSON.parse(init.body as string) as Record<string, unknown>;
|
||||
expect(body.instructions).toBe(expectedInstructions);
|
||||
|
||||
Reference in New Issue
Block a user