mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 19:14:44 +00:00
test: guard agent tool null helpers
This commit is contained in:
@@ -63,8 +63,9 @@ function requireApprovalRequestPayload(callIndex: number): ApprovalRequestPayloa
|
||||
const call = vi.mocked(callGatewayTool).mock.calls[callIndex];
|
||||
expect(call?.[0]).toBe("exec.approval.request");
|
||||
const payload = call?.[2];
|
||||
expect(typeof payload).toBe("object");
|
||||
expect(payload).not.toBeNull();
|
||||
if (!payload || typeof payload !== "object") {
|
||||
throw new Error(`expected approval request payload ${callIndex}`);
|
||||
}
|
||||
return payload as ApprovalRequestPayload;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,8 +67,9 @@ function mockClaudeCliCredentialRead() {
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -158,8 +158,9 @@ function buildPreparedContext(params?: {
|
||||
}
|
||||
|
||||
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>;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,8 +55,9 @@ function findGatewayRequest(method: string): GatewayRequest | undefined {
|
||||
}
|
||||
|
||||
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>;
|
||||
}
|
||||
|
||||
|
||||
@@ -105,8 +105,9 @@ function createRunEntry(overrides: Partial<SubagentRunRecord> = {}): SubagentRun
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -115,8 +116,9 @@ function expectFields(value: unknown, expected: Record<string, unknown>): void {
|
||||
|
||||
function firstCallArg(mock: ReturnType<typeof vi.fn>): Record<string, unknown> {
|
||||
const [arg] = mock.mock.calls[0] ?? [];
|
||||
expect(arg).toBeTypeOf("object");
|
||||
expect(arg).not.toBeNull();
|
||||
if (!arg || typeof arg !== "object") {
|
||||
throw new Error("expected first call argument object");
|
||||
}
|
||||
return arg as Record<string, unknown>;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,8 +47,9 @@ vi.mock("./subagent-orphan-recovery.js", () => ({
|
||||
}));
|
||||
|
||||
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);
|
||||
|
||||
@@ -962,8 +962,9 @@ describe("createImageGenerateTool", () => {
|
||||
expect(mockCallArg(webMedia.loadWebMedia, 0, "loadWebMedia", 0)).toBe(
|
||||
"media://inbound/reference.png",
|
||||
);
|
||||
expect(loadArgs).not.toBeNull();
|
||||
expect(typeof loadArgs).toBe("object");
|
||||
if (!loadArgs || typeof loadArgs !== "object") {
|
||||
throw new Error("expected loadWebMedia options");
|
||||
}
|
||||
});
|
||||
|
||||
it("passes web_fetch SSRF policy to remote reference images", async () => {
|
||||
|
||||
@@ -64,7 +64,6 @@ describe("music generate background helpers", () => {
|
||||
providerId: "google",
|
||||
});
|
||||
|
||||
expect(handle).not.toBeNull();
|
||||
if (!handle) {
|
||||
throw new Error("Expected music generation task handle");
|
||||
}
|
||||
|
||||
@@ -146,8 +146,9 @@ function resetMusicGenerateMocks() {
|
||||
}
|
||||
|
||||
function detailsOf(result: { details?: unknown }): Record<string, unknown> {
|
||||
expect(typeof result.details).toBe("object");
|
||||
expect(result.details).not.toBeNull();
|
||||
if (!result.details || typeof result.details !== "object") {
|
||||
throw new Error("expected result details object");
|
||||
}
|
||||
return result.details as Record<string, unknown>;
|
||||
}
|
||||
|
||||
@@ -155,30 +156,34 @@ function generateMusicOptions(
|
||||
callIndex = musicGenerationRuntimeMocks.generateMusic.mock.calls.length - 1,
|
||||
): Record<string, unknown> {
|
||||
const options = musicGenerationRuntimeMocks.generateMusic.mock.calls[callIndex]?.[0];
|
||||
expect(typeof options).toBe("object");
|
||||
expect(options).not.toBeNull();
|
||||
if (!options || typeof options !== "object") {
|
||||
throw new Error(`expected generateMusic options ${callIndex}`);
|
||||
}
|
||||
return options as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function taskProgressCall(callIndex = 0): Record<string, unknown> {
|
||||
const call = taskExecutorMocks.recordTaskRunProgressByRunId.mock.calls[callIndex]?.[0];
|
||||
expect(typeof call).toBe("object");
|
||||
expect(call).not.toBeNull();
|
||||
if (!call || typeof call !== "object") {
|
||||
throw new Error(`expected task progress call ${callIndex}`);
|
||||
}
|
||||
return call as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function taskCompleteCall(callIndex = 0): Record<string, unknown> {
|
||||
const call = taskExecutorMocks.completeTaskRunByRunId.mock.calls[callIndex]?.[0];
|
||||
expect(typeof call).toBe("object");
|
||||
expect(call).not.toBeNull();
|
||||
if (!call || typeof call !== "object") {
|
||||
throw new Error(`expected task complete call ${callIndex}`);
|
||||
}
|
||||
return call as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function wakeCompletionCall(callIndex = 0): Record<string, unknown> {
|
||||
const call =
|
||||
musicGenerateBackgroundMocks.wakeMusicGenerationTaskCompletion.mock.calls[callIndex]?.[0];
|
||||
expect(typeof call).toBe("object");
|
||||
expect(call).not.toBeNull();
|
||||
if (!call || typeof call !== "object") {
|
||||
throw new Error(`expected wake completion call ${callIndex}`);
|
||||
}
|
||||
return call as Record<string, unknown>;
|
||||
}
|
||||
|
||||
|
||||
@@ -82,8 +82,9 @@ function withDefaultModel(primary: string): OpenClawConfig {
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user