test: guard command object helpers

This commit is contained in:
Peter Steinberger
2026-05-11 20:59:33 +01:00
parent 3eb5070817
commit 905861c4e0
11 changed files with 21 additions and 21 deletions

View File

@@ -124,8 +124,9 @@ function listConfiguredAccountIds(
}
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

@@ -202,8 +202,9 @@ function setupBaseWizardState(config: OpenClawConfig = {}) {
}
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

@@ -195,8 +195,9 @@ function createGatewayCommand(entrypoint: 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

@@ -31,7 +31,6 @@ async function readRequiredPersistedInstalledPluginIndex(
stateDir: string,
): Promise<InstalledPluginIndex> {
const persisted = await readPersistedInstalledPluginIndex({ stateDir });
expect(persisted).not.toBeNull();
if (!persisted) {
throw new Error("Expected persisted installed plugin index");
}

View File

@@ -115,7 +115,6 @@ describe("detectLinuxSdBackedStateDir", () => {
},
});
expect(result).not.toBeNull();
if (result === null) {
throw new Error("Expected Linux state storage warning details");
}

View File

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

View File

@@ -151,8 +151,6 @@ function expectItemStatus(
}
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

@@ -170,8 +170,9 @@ type MockCallSource = {
};
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

@@ -136,15 +136,17 @@ function expectRowFields(
function modelRegistryOptions(index = 0): Record<string, unknown> {
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<string, unknown>;
}
function providerCatalogOptions(index = 0): Record<string, unknown> {
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<string, unknown>;
}

View File

@@ -264,8 +264,6 @@ function createRuntime() {
}
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

@@ -82,8 +82,9 @@ vi.mock("../secrets/provider-env-vars.js", () => ({
}));
function requireRecord(value: unknown, label: string): Record<string, unknown> {
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<string, unknown>;
}