mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-13 23:56:07 +00:00
test: guard command object helpers
This commit is contained in:
@@ -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>;
|
||||
}
|
||||
|
||||
|
||||
@@ -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>;
|
||||
}
|
||||
|
||||
|
||||
@@ -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>;
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -115,7 +115,6 @@ describe("detectLinuxSdBackedStateDir", () => {
|
||||
},
|
||||
});
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
if (result === null) {
|
||||
throw new Error("Expected Linux state storage warning details");
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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`);
|
||||
}
|
||||
|
||||
@@ -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>;
|
||||
}
|
||||
|
||||
|
||||
@@ -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>;
|
||||
}
|
||||
|
||||
|
||||
@@ -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`);
|
||||
}
|
||||
|
||||
@@ -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>;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user