test: fix transcription and tool schema assertions

This commit is contained in:
Peter Steinberger
2026-01-03 14:55:05 +00:00
parent 5de3395204
commit 77c76ca52f
2 changed files with 11 additions and 6 deletions

View File

@@ -16,7 +16,6 @@ describe("createClawdisCodingTools", () => {
properties?: Record<string, unknown>; properties?: Record<string, unknown>;
required?: string[]; required?: string[];
}; };
expect(parameters.anyOf?.length ?? 0).toBeGreaterThan(0);
expect(parameters.properties?.action).toBeDefined(); expect(parameters.properties?.action).toBeDefined();
expect(parameters.properties?.controlUrl).toBeDefined(); expect(parameters.properties?.controlUrl).toBeDefined();
expect(parameters.properties?.targetUrl).toBeDefined(); expect(parameters.properties?.targetUrl).toBeDefined();

View File

@@ -4,15 +4,14 @@ import path from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest"; import { afterEach, describe, expect, it, vi } from "vitest";
import { transcribeInboundAudio } from "./transcription.js";
vi.mock("../globals.js", () => ({ vi.mock("../globals.js", () => ({
isVerbose: () => false, isVerbose: () => false,
shouldLogVerbose: () => false,
logVerbose: vi.fn(), logVerbose: vi.fn(),
})); }));
vi.mock("../process/exec.js", () => ({ vi.mock("../process/exec.js", () => ({
runExec: vi.fn(async () => ({ stdout: "transcribed text\n" })), runExec: vi.fn(),
})); }));
const runtime = { const runtime = {
@@ -22,6 +21,7 @@ const runtime = {
describe("transcribeInboundAudio", () => { describe("transcribeInboundAudio", () => {
afterEach(() => { afterEach(() => {
vi.resetAllMocks(); vi.resetAllMocks();
vi.unstubAllGlobals();
}); });
it("downloads mediaUrl to temp file and returns transcript", async () => { it("downloads mediaUrl to temp file and returns transcript", async () => {
@@ -34,8 +34,7 @@ describe("transcribeInboundAudio", () => {
status: 200, status: 200,
arrayBuffer: async () => tmpBuf, arrayBuffer: async () => tmpBuf,
})) as unknown as typeof fetch; })) as unknown as typeof fetch;
// @ts-expect-error override global fetch for test vi.stubGlobal("fetch", fetchMock);
global.fetch = fetchMock;
const cfg = { const cfg = {
routing: { routing: {
@@ -47,6 +46,12 @@ describe("transcribeInboundAudio", () => {
}; };
const ctx = { MediaUrl: "https://example.com/audio.ogg" }; const ctx = { MediaUrl: "https://example.com/audio.ogg" };
const execModule = await import("../process/exec.js");
vi.mocked(execModule.runExec).mockResolvedValue({
stdout: "transcribed text\n",
stderr: "",
});
const { transcribeInboundAudio } = await import("./transcription.js");
const result = await transcribeInboundAudio( const result = await transcribeInboundAudio(
cfg as never, cfg as never,
ctx as never, ctx as never,
@@ -57,6 +62,7 @@ describe("transcribeInboundAudio", () => {
}); });
it("returns undefined when no transcription command", async () => { it("returns undefined when no transcription command", async () => {
const { transcribeInboundAudio } = await import("./transcription.js");
const res = await transcribeInboundAudio( const res = await transcribeInboundAudio(
{ routing: {} } as never, { routing: {} } as never,
{} as never, {} as never,