test: guard core sdk null helpers

This commit is contained in:
Peter Steinberger
2026-05-11 21:16:13 +01:00
parent bff97df6e5
commit 32b8925cfa
11 changed files with 22 additions and 22 deletions

View File

@@ -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>;
}

View File

@@ -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>;
}

View File

@@ -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[] {

View File

@@ -71,7 +71,6 @@ describe("applyPluginNodeInvokePolicy", () => {
params: { path: "/tmp/x" },
});
expect(result).not.toBeNull();
if (result === null) {
throw new Error("expected plugin policy failure");
}

View File

@@ -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`);
}

View File

@@ -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>;
}

View File

@@ -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);

View File

@@ -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`);
}

View File

@@ -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");
}

View File

@@ -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);

View File

@@ -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`);
}