mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-13 15:47:28 +00:00
test: guard extension provider helpers
This commit is contained in:
@@ -48,8 +48,9 @@ function createModelRegistry(models: ProviderRuntimeModel[]) {
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
expect(value, label).toBeTypeOf("object");
|
||||
expect(value, label).not.toBeNull();
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
|
||||
|
||||
@@ -100,8 +100,9 @@ async function runCreateMeetBrowserScript(params: { buttonText: string }) {
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
expect(value, label).toBeTypeOf("object");
|
||||
expect(value, label).not.toBeNull();
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,8 +43,9 @@ function captureStdout() {
|
||||
}
|
||||
|
||||
function expectFields(value: unknown, expected: Record<string, unknown>): void {
|
||||
expect(value).toBeTypeOf("object");
|
||||
expect(value).not.toBeNull();
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error("expected fields object");
|
||||
}
|
||||
const record = value as Record<string, unknown>;
|
||||
for (const [key, expectedValue] of Object.entries(expected)) {
|
||||
expect(record[key], key).toEqual(expectedValue);
|
||||
@@ -54,8 +55,9 @@ function expectFields(value: unknown, expected: Record<string, unknown>): void {
|
||||
function firstRecord(value: unknown): Record<string, unknown> {
|
||||
expect(Array.isArray(value)).toBe(true);
|
||||
const [record] = value as unknown[];
|
||||
expect(record).toBeTypeOf("object");
|
||||
expect(record).not.toBeNull();
|
||||
if (!record || typeof record !== "object") {
|
||||
throw new Error("expected first record");
|
||||
}
|
||||
return record as Record<string, unknown>;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,14 +63,16 @@ function mockObjectArg(mock: unknown, index = -1): Record<string, unknown> {
|
||||
const calls = (mock as { mock?: { calls?: Array<Array<unknown>> } }).mock?.calls ?? [];
|
||||
const call = index < 0 ? calls.at(index) : calls[index];
|
||||
const [arg] = call ?? [];
|
||||
expect(arg).toBeTypeOf("object");
|
||||
expect(arg).not.toBeNull();
|
||||
if (!arg || typeof arg !== "object") {
|
||||
throw new Error(`expected mock object argument ${index}`);
|
||||
}
|
||||
return arg as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function expectFields(value: unknown, expected: Record<string, unknown>): void {
|
||||
expect(value).toBeTypeOf("object");
|
||||
expect(value).not.toBeNull();
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error("expected fields object");
|
||||
}
|
||||
const record = value as Record<string, unknown>;
|
||||
for (const [key, expectedValue] of Object.entries(expected)) {
|
||||
expect(record[key], key).toEqual(expectedValue);
|
||||
|
||||
@@ -109,7 +109,6 @@ describe("toWikiPageSummary", () => {
|
||||
relativePath: "entities/brad.md",
|
||||
raw,
|
||||
});
|
||||
expect(summary).not.toBeNull();
|
||||
if (!summary) {
|
||||
throw new Error("expected wiki summary");
|
||||
}
|
||||
|
||||
@@ -3,9 +3,6 @@ import type { ResolvedMemoryWikiConfig } from "./config.js";
|
||||
import { createWikiApplyTool } from "./tool.js";
|
||||
|
||||
function asSchemaObject(value: unknown): Record<string, unknown> {
|
||||
expect(typeof value).toBe("object");
|
||||
expect(value).not.toBeNull();
|
||||
expect(Array.isArray(value)).toBe(false);
|
||||
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
||||
throw new Error("Expected JSON schema object");
|
||||
}
|
||||
|
||||
@@ -29,8 +29,9 @@ type GuardedFetchCall = {
|
||||
};
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
expect(value, label).toBeTypeOf("object");
|
||||
expect(value, label).not.toBeNull();
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
|
||||
|
||||
@@ -75,8 +75,10 @@ describe("transcribeOpenAiAudio", () => {
|
||||
expect(form.get("language")).toBe("en");
|
||||
expect(form.get("prompt")).toBe("hello");
|
||||
const file = form.get("file") as Blob | { type?: string; name?: string } | null;
|
||||
expect(file).not.toBeNull();
|
||||
expect(file?.type).toBe("audio/wav");
|
||||
if (!file) {
|
||||
throw new Error("expected OpenAI audio file");
|
||||
}
|
||||
expect(file.type).toBe("audio/wav");
|
||||
if (file && "name" in file && typeof file.name === "string") {
|
||||
expect(file.name).toBe("voice.wav");
|
||||
}
|
||||
|
||||
@@ -93,8 +93,9 @@ function runWrappedPayloadCase(params: {
|
||||
}
|
||||
|
||||
function expectFields(value: unknown, expected: Record<string, unknown>): void {
|
||||
expect(value).toBeTypeOf("object");
|
||||
expect(value).not.toBeNull();
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error("expected fields object");
|
||||
}
|
||||
const record = value as Record<string, unknown>;
|
||||
for (const [key, expectedValue] of Object.entries(expected)) {
|
||||
expect(record[key], key).toEqual(expectedValue);
|
||||
|
||||
@@ -94,8 +94,6 @@ function requireFetchCallHeaders(index: number): Headers {
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
expect(typeof value).toBe("object");
|
||||
expect(value).not.toBeNull();
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`${label} was not an object`);
|
||||
}
|
||||
|
||||
@@ -87,14 +87,16 @@ import type { QaProviderModeInput } from "./run-config.js";
|
||||
function mockFirstObjectArg(mock: unknown): Record<string, unknown> {
|
||||
const calls = (mock as { mock?: { calls?: Array<Array<unknown>> } }).mock?.calls ?? [];
|
||||
const [arg] = calls[0] ?? [];
|
||||
expect(arg).toBeTypeOf("object");
|
||||
expect(arg).not.toBeNull();
|
||||
if (!arg || typeof arg !== "object") {
|
||||
throw new Error("expected first mock object argument");
|
||||
}
|
||||
return arg as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function expectFields(value: unknown, expected: Record<string, unknown>): void {
|
||||
expect(value).toBeTypeOf("object");
|
||||
expect(value).not.toBeNull();
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error("expected fields object");
|
||||
}
|
||||
const record = value as Record<string, unknown>;
|
||||
for (const [key, expectedValue] of Object.entries(expected)) {
|
||||
expect(record[key], key).toEqual(expectedValue);
|
||||
|
||||
@@ -78,8 +78,10 @@ describe("transcribeSenseAudioAudio", () => {
|
||||
expect(form.get("language")).toBe("en");
|
||||
expect(form.get("prompt")).toBe("hello");
|
||||
const file = form.get("file") as Blob | { type?: string; name?: string } | null;
|
||||
expect(file).not.toBeNull();
|
||||
expect(file?.type).toBe("audio/wav");
|
||||
if (!file) {
|
||||
throw new Error("expected SenseAudio audio file");
|
||||
}
|
||||
expect(file.type).toBe("audio/wav");
|
||||
if (file && "name" in file && typeof file.name === "string") {
|
||||
expect(file.name).toBe("voice.wav");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user