mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-16 18:34:18 +00:00
test: guard cli null helpers
This commit is contained in:
@@ -1872,7 +1872,9 @@ describe("capability cli", () => {
|
||||
argv: ["capability", "model", "auth", "logout", "--provider", "openai", "--json"],
|
||||
});
|
||||
|
||||
expect(updatedStore).not.toBeNull();
|
||||
if (updatedStore === null) {
|
||||
throw new Error("expected updated auth store");
|
||||
}
|
||||
const storeSnapshot = updatedStore as unknown as Record<string, any>;
|
||||
expect(storeSnapshot.profiles).toEqual({
|
||||
"anthropic:default": { id: "anthropic:default" },
|
||||
|
||||
@@ -79,8 +79,9 @@ vi.mock("../commands/channel-setup/plugin-install.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);
|
||||
@@ -89,8 +90,9 @@ function expectFields(value: unknown, expected: Record<string, unknown>): void {
|
||||
|
||||
function readFirstCallArg(mock: ReturnType<typeof vi.fn>): Record<string, unknown> {
|
||||
const [arg] = mock.mock.calls[0] ?? [];
|
||||
expect(arg).toBeTypeOf("object");
|
||||
expect(arg).not.toBeNull();
|
||||
if (!arg || typeof arg !== "object") {
|
||||
throw new Error("expected first call argument object");
|
||||
}
|
||||
return arg as Record<string, unknown>;
|
||||
}
|
||||
|
||||
|
||||
@@ -183,8 +183,9 @@ function expectFirstInstallPlanCallOmitsToken() {
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -123,8 +123,6 @@ function mockLocalPairingFallback(message?: 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`);
|
||||
}
|
||||
|
||||
@@ -116,8 +116,9 @@ describe("models cli", () => {
|
||||
for (const [key, value] of Object.entries(expected)) {
|
||||
expect(options?.[key]).toEqual(value);
|
||||
}
|
||||
expect(typeof context).toBe("object");
|
||||
expect(context).not.toBeNull();
|
||||
if (!context || typeof context !== "object") {
|
||||
throw new Error("expected command context");
|
||||
}
|
||||
}
|
||||
|
||||
it("registers github-copilot login command", async () => {
|
||||
|
||||
@@ -51,8 +51,9 @@ type MockCalls = {
|
||||
};
|
||||
|
||||
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>;
|
||||
}
|
||||
|
||||
|
||||
@@ -400,7 +400,9 @@ describe("resolveMissingPluginCommandMessage", () => {
|
||||
},
|
||||
{ registry: losslessClawToolRegistry },
|
||||
);
|
||||
expect(message).not.toBeNull();
|
||||
if (message === null) {
|
||||
throw new Error("expected missing plugin command message");
|
||||
}
|
||||
expect(message).toContain('"lcm_recent"');
|
||||
expect(message).toContain('"lossless-claw"');
|
||||
expect(message).toContain("agent tool");
|
||||
@@ -411,7 +413,9 @@ describe("resolveMissingPluginCommandMessage", () => {
|
||||
const message = resolveMissingPluginCommandMessage("LCM_Recent", undefined, {
|
||||
registry: losslessClawToolRegistry,
|
||||
});
|
||||
expect(message).not.toBeNull();
|
||||
if (message === null) {
|
||||
throw new Error("expected missing plugin command message");
|
||||
}
|
||||
expect(message).toContain("agent tool");
|
||||
expect(message).toContain('"lossless-claw"');
|
||||
});
|
||||
@@ -495,7 +499,9 @@ describe("resolveMissingPluginCommandMessage", () => {
|
||||
const message = resolveMissingPluginCommandMessage("feishu_chat", undefined, {
|
||||
resolveToolOwner: () => manifestOnlyOwner,
|
||||
});
|
||||
expect(message).not.toBeNull();
|
||||
if (message === null) {
|
||||
throw new Error("expected missing plugin command message");
|
||||
}
|
||||
expect(message).toContain("may be provided by");
|
||||
expect(message).toContain('"feishu"');
|
||||
expect(message).not.toContain("registered by");
|
||||
|
||||
@@ -118,14 +118,16 @@ function mockCall(mock: unknown, index = 0): Array<unknown> {
|
||||
|
||||
function mockFirstObjectArg(mock: unknown): Record<string, unknown> {
|
||||
const [arg] = mockCall(mock);
|
||||
expect(arg).toBeTypeOf("object");
|
||||
expect(arg).not.toBeNull();
|
||||
if (!arg || typeof arg !== "object") {
|
||||
throw new Error("expected first mock argument object");
|
||||
}
|
||||
return arg as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function expectObjectFields(value: unknown, expected: Record<string, unknown>): void {
|
||||
expect(value).toBeTypeOf("object");
|
||||
expect(value).not.toBeNull();
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error("expected object fields");
|
||||
}
|
||||
const record = value as Record<string, unknown>;
|
||||
for (const [key, expectedValue] of Object.entries(expected)) {
|
||||
expect(record[key], key).toEqual(expectedValue);
|
||||
@@ -133,8 +135,9 @@ function expectObjectFields(value: unknown, expected: Record<string, unknown>):
|
||||
}
|
||||
|
||||
function expectLogger(value: unknown): void {
|
||||
expect(value).toBeTypeOf("object");
|
||||
expect(value).not.toBeNull();
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error("expected logger object");
|
||||
}
|
||||
}
|
||||
|
||||
function expectStatusWorkspaceCall(workspaceDir: string): void {
|
||||
|
||||
Reference in New Issue
Block a user