test: guard extension helper null checks

This commit is contained in:
Peter Steinberger
2026-05-11 21:18:47 +01:00
parent bbd3ccf8e6
commit 6eccb0d3bf
16 changed files with 18 additions and 32 deletions

View File

@@ -107,8 +107,9 @@ function getActPostHandler() {
}
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

@@ -35,8 +35,6 @@ async function expectSetupErrorStatus(
}
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

@@ -69,8 +69,9 @@ function expectInputText(text: 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>;
}

View File

@@ -21,8 +21,6 @@ function createContractTool(overrides: Partial<AnyAgentTool>): AnyAgentTool {
}
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

@@ -50,8 +50,9 @@ function compileManifestConfigSchema() {
}
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

@@ -1282,7 +1282,6 @@ describe("handleFeishuMessage command authorization", () => {
expect(finalized.OriginatingTo).toBe("chat:oc-group");
expect(finalized.SenderId).toBe("ou-allowed");
const groupSessionKey = resolveGroupSessionKey(finalized as never);
expect(groupSessionKey).not.toBeNull();
if (!groupSessionKey) {
throw new Error("Expected group session key");
}

View File

@@ -64,8 +64,9 @@ type ToolResultWithDetails = {
const WORKSPACE_ROOT = path.resolve("/workspace");
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

@@ -108,8 +108,6 @@ function createCtx(overrides: {
}
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

@@ -51,8 +51,6 @@ function withConfig(fileTransfer: Record<string, unknown> | undefined) {
}
function expectResultFields(result: unknown, fields: Record<string, unknown>) {
expect(typeof result).toBe("object");
expect(result).not.toBeNull();
if (typeof result !== "object" || result === null) {
throw new Error("policy result was not an object");
}

View File

@@ -47,8 +47,6 @@ class MockMatrixClient {
}
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

@@ -34,8 +34,6 @@ function expectBodiesExclude(bodies: string[], text: string) {
}
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

@@ -19,8 +19,6 @@ function requestUrl(input: RequestInfo | URL | undefined): string {
}
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

@@ -28,7 +28,6 @@ function installQaChannelTestRegistry() {
}
function expectDispatchedContext(ctx: Record<string, unknown> | null): Record<string, unknown> {
expect(ctx).not.toBeNull();
if (ctx === null) {
throw new Error("Expected dispatched context");
}

View File

@@ -49,8 +49,6 @@ describe("handleSlackAction", () => {
}
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

@@ -220,10 +220,12 @@ describe("VoiceCallWebhookServer realtime transcription provider selection", ()
expect(mocks.getRealtimeTranscriptionProvider).not.toHaveBeenCalled();
expect(mocks.listRealtimeTranscriptionProviders).toHaveBeenCalledWith(null);
const mediaStreamHandler = server.getMediaStreamHandler();
expect(mediaStreamHandler).not.toBeNull();
expect(mediaStreamHandler?.handleUpgrade).toBeTypeOf("function");
expect(mediaStreamHandler?.sendAudio).toBeTypeOf("function");
expect(mediaStreamHandler?.closeAll).toBeTypeOf("function");
if (!mediaStreamHandler) {
throw new Error("expected media stream handler");
}
expect(mediaStreamHandler.handleUpgrade).toBeTypeOf("function");
expect(mediaStreamHandler.sendAudio).toBeTypeOf("function");
expect(mediaStreamHandler.closeAll).toBeTypeOf("function");
} finally {
await server.stop();
}

View File

@@ -60,8 +60,6 @@ function sendFailure(error: string, threadId = "thread") {
}
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`);
}