mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 19:04:45 +00:00
test: guard core sdk null helpers
This commit is contained in:
@@ -28,8 +28,9 @@ describe("acp prompt cwd prefix", () => {
|
||||
const call = requestSpy.mock.calls[index];
|
||||
expect(call?.[0]).toBe("chat.send");
|
||||
expect(call?.[2]).toEqual({ timeoutMs: null });
|
||||
expect(typeof call?.[1]).toBe("object");
|
||||
expect(call?.[1]).not.toBeNull();
|
||||
if (!call?.[1] || typeof call[1] !== "object") {
|
||||
throw new Error(`expected chat.send payload ${index}`);
|
||||
}
|
||||
return call?.[1] as Record<string, unknown>;
|
||||
}
|
||||
|
||||
|
||||
@@ -127,8 +127,9 @@ async function expectOversizedPromptRejected(params: { sessionId: string; text:
|
||||
type MockCallSource = { mock: { calls: Array<Array<unknown>> } };
|
||||
|
||||
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>;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,8 +47,9 @@ function asRecord(value: unknown): Record<string, unknown> {
|
||||
}
|
||||
|
||||
function expectRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
expect(value, label).not.toBeNull();
|
||||
expect(typeof value, label).toBe("object");
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
expect(Array.isArray(value), label).toBe(false);
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
@@ -59,8 +60,10 @@ function readString(value: unknown): string | null {
|
||||
|
||||
function expectNonEmptyString(value: unknown, label: string): string {
|
||||
const text = readString(value);
|
||||
expect(text, label).not.toBeNull();
|
||||
return text as string;
|
||||
if (text === null) {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
function readStringArray(value: unknown): string[] {
|
||||
|
||||
@@ -71,7 +71,6 @@ describe("applyPluginNodeInvokePolicy", () => {
|
||||
params: { path: "/tmp/x" },
|
||||
});
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
if (result === null) {
|
||||
throw new Error("expected plugin policy failure");
|
||||
}
|
||||
|
||||
@@ -156,8 +156,6 @@ describe("agent event handler", () => {
|
||||
}
|
||||
|
||||
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`);
|
||||
}
|
||||
|
||||
@@ -114,8 +114,9 @@ function buildBasicSessionTranscript(
|
||||
}
|
||||
|
||||
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>;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,9 @@ import {
|
||||
} from "./diagnostic-stability.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);
|
||||
|
||||
@@ -64,8 +64,6 @@ function countMatching<T>(items: readonly T[], predicate: (item: T) => boolean)
|
||||
}
|
||||
|
||||
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`);
|
||||
}
|
||||
|
||||
@@ -165,7 +165,6 @@ describe("discord plugin-sdk facade", () => {
|
||||
expect(callParams.agentId).toBe("agent");
|
||||
expect(callParams.cfg).toBe(mocks.runtimeConfig);
|
||||
expect(callParams.childSessionKey).toBe("child");
|
||||
expect(binding).not.toBeNull();
|
||||
if (!binding) {
|
||||
throw new Error("expected Discord subagent binding");
|
||||
}
|
||||
|
||||
@@ -9,8 +9,9 @@ import {
|
||||
} from "./provider-model-shared.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);
|
||||
|
||||
@@ -39,8 +39,6 @@ function requireStreamFn(streamFn: StreamFn | null | undefined) {
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
expect(value).toBeTypeOf("object");
|
||||
expect(value).not.toBeNull();
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be an object`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user