From 905861c4e05067f100e7dea03361b10345e52aa8 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 11 May 2026 20:59:33 +0100 Subject: [PATCH] test: guard command object helpers --- src/commands/channels.add.test.ts | 5 +++-- src/commands/configure.wizard.test.ts | 5 +++-- src/commands/doctor-gateway-services.test.ts | 5 +++-- src/commands/doctor-plugin-registry.test.ts | 1 - .../doctor-state-integrity.linux-storage.test.ts | 1 - .../doctor/shared/legacy-config-migrate.test.ts | 1 - src/commands/migrate/selection.test.ts | 2 -- src/commands/model-picker.test.ts | 5 +++-- .../models/list.list-command.forward-compat.test.ts | 10 ++++++---- src/commands/models/list.status.test.ts | 2 -- src/commands/onboard-auth.test.ts | 5 +++-- 11 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/commands/channels.add.test.ts b/src/commands/channels.add.test.ts index e679e0351a3..61f075817cb 100644 --- a/src/commands/channels.add.test.ts +++ b/src/commands/channels.add.test.ts @@ -124,8 +124,9 @@ function listConfiguredAccountIds( } function requireRecord(value: unknown, label: string): Record { - expect(value, label).toBeTypeOf("object"); - expect(value, label).not.toBeNull(); + if (!value || typeof value !== "object") { + throw new Error(`expected ${label}`); + } return value as Record; } diff --git a/src/commands/configure.wizard.test.ts b/src/commands/configure.wizard.test.ts index 1954d6fa597..f99d7d73391 100644 --- a/src/commands/configure.wizard.test.ts +++ b/src/commands/configure.wizard.test.ts @@ -202,8 +202,9 @@ function setupBaseWizardState(config: OpenClawConfig = {}) { } function requireRecord(value: unknown, label: string): Record { - expect(value, label).toBeTypeOf("object"); - expect(value, label).not.toBeNull(); + if (!value || typeof value !== "object") { + throw new Error(`expected ${label}`); + } return value as Record; } diff --git a/src/commands/doctor-gateway-services.test.ts b/src/commands/doctor-gateway-services.test.ts index 133154df904..23fa55fa035 100644 --- a/src/commands/doctor-gateway-services.test.ts +++ b/src/commands/doctor-gateway-services.test.ts @@ -195,8 +195,9 @@ function createGatewayCommand(entrypoint: string) { } function requireRecord(value: unknown, label: string): Record { - expect(value, label).toBeTypeOf("object"); - expect(value, label).not.toBeNull(); + if (!value || typeof value !== "object") { + throw new Error(`expected ${label}`); + } return value as Record; } diff --git a/src/commands/doctor-plugin-registry.test.ts b/src/commands/doctor-plugin-registry.test.ts index 98f906c17cb..31e96d2dfb7 100644 --- a/src/commands/doctor-plugin-registry.test.ts +++ b/src/commands/doctor-plugin-registry.test.ts @@ -31,7 +31,6 @@ async function readRequiredPersistedInstalledPluginIndex( stateDir: string, ): Promise { const persisted = await readPersistedInstalledPluginIndex({ stateDir }); - expect(persisted).not.toBeNull(); if (!persisted) { throw new Error("Expected persisted installed plugin index"); } diff --git a/src/commands/doctor-state-integrity.linux-storage.test.ts b/src/commands/doctor-state-integrity.linux-storage.test.ts index e57836ef834..634c796e947 100644 --- a/src/commands/doctor-state-integrity.linux-storage.test.ts +++ b/src/commands/doctor-state-integrity.linux-storage.test.ts @@ -115,7 +115,6 @@ describe("detectLinuxSdBackedStateDir", () => { }, }); - expect(result).not.toBeNull(); if (result === null) { throw new Error("Expected Linux state storage warning details"); } diff --git a/src/commands/doctor/shared/legacy-config-migrate.test.ts b/src/commands/doctor/shared/legacy-config-migrate.test.ts index 4358323a7ae..b8bce151c97 100644 --- a/src/commands/doctor/shared/legacy-config-migrate.test.ts +++ b/src/commands/doctor/shared/legacy-config-migrate.test.ts @@ -656,7 +656,6 @@ describe("legacy migrate heartbeat config", () => { }); expect(res.changes).toStrictEqual(["Removed empty top-level heartbeat."]); - expect(res.config).not.toBeNull(); if (res.config === null) { throw new Error("Expected migrated config"); } diff --git a/src/commands/migrate/selection.test.ts b/src/commands/migrate/selection.test.ts index 573f0b7dec2..4289b039031 100644 --- a/src/commands/migrate/selection.test.ts +++ b/src/commands/migrate/selection.test.ts @@ -151,8 +151,6 @@ function expectItemStatus( } function requireRecord(value: unknown, label: string): Record { - expect(typeof value).toBe("object"); - expect(value).not.toBeNull(); if (typeof value !== "object" || value === null) { throw new Error(`${label} was not an object`); } diff --git a/src/commands/model-picker.test.ts b/src/commands/model-picker.test.ts index 9b34b43086e..0cb2831615d 100644 --- a/src/commands/model-picker.test.ts +++ b/src/commands/model-picker.test.ts @@ -170,8 +170,9 @@ type MockCallSource = { }; function requireRecord(value: unknown, label: string): Record { - expect(value, label).toBeTypeOf("object"); - expect(value, label).not.toBeNull(); + if (!value || typeof value !== "object") { + throw new Error(`expected ${label}`); + } return value as Record; } diff --git a/src/commands/models/list.list-command.forward-compat.test.ts b/src/commands/models/list.list-command.forward-compat.test.ts index e0203625cd5..3cc88e3d17b 100644 --- a/src/commands/models/list.list-command.forward-compat.test.ts +++ b/src/commands/models/list.list-command.forward-compat.test.ts @@ -136,15 +136,17 @@ function expectRowFields( function modelRegistryOptions(index = 0): Record { const options = mocks.loadModelRegistry.mock.calls[index]?.[1]; - expect(options).toBeTypeOf("object"); - expect(options).not.toBeNull(); + if (!options || typeof options !== "object") { + throw new Error(`expected model registry options ${index}`); + } return options as Record; } function providerCatalogOptions(index = 0): Record { const options = mocks.loadProviderCatalogModelsForList.mock.calls[index]?.[0]; - expect(options).toBeTypeOf("object"); - expect(options).not.toBeNull(); + if (!options || typeof options !== "object") { + throw new Error(`expected provider catalog options ${index}`); + } return options as Record; } diff --git a/src/commands/models/list.status.test.ts b/src/commands/models/list.status.test.ts index c761247743f..cfa998e18d2 100644 --- a/src/commands/models/list.status.test.ts +++ b/src/commands/models/list.status.test.ts @@ -264,8 +264,6 @@ function createRuntime() { } function requireRecord(value: unknown, label: string): Record { - expect(typeof value).toBe("object"); - expect(value).not.toBeNull(); if (typeof value !== "object" || value === null) { throw new Error(`${label} was not an object`); } diff --git a/src/commands/onboard-auth.test.ts b/src/commands/onboard-auth.test.ts index 4f763c77726..71f95551a85 100644 --- a/src/commands/onboard-auth.test.ts +++ b/src/commands/onboard-auth.test.ts @@ -82,8 +82,9 @@ vi.mock("../secrets/provider-env-vars.js", () => ({ })); function requireRecord(value: unknown, label: string): Record { - expect(typeof value, label).toBe("object"); - expect(value, label).not.toBeNull(); + if (!value || typeof value !== "object") { + throw new Error(`expected ${label}`); + } return value as Record; }