mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-16 18:34:18 +00:00
test: guard core agent null helpers
This commit is contained in:
@@ -93,8 +93,6 @@ async function readSessionFileJsonLines<T>(sessionFile: string): Promise<T[]> {
|
||||
}
|
||||
|
||||
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`);
|
||||
}
|
||||
|
||||
@@ -30,8 +30,6 @@ const overrideBoundaryAwareStreamFnOnce = (streamFn: StreamFn): void => {
|
||||
};
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
expect(value).toBeTypeOf("object");
|
||||
expect(value).not.toBeNull();
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be an object`);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ async function expectPathMissing(targetPath: string): Promise<void> {
|
||||
function expectBudgetResult(
|
||||
result: Awaited<ReturnType<typeof enforceSessionDiskBudget>>,
|
||||
): asserts result is NonNullable<Awaited<ReturnType<typeof enforceSessionDiskBudget>>> {
|
||||
expect(result).not.toBeNull();
|
||||
if (result === null) {
|
||||
throw new Error("expected disk budget enforcement result");
|
||||
}
|
||||
|
||||
@@ -132,7 +132,6 @@ describe("Crestodian assistant", () => {
|
||||
removeTempDir: async () => {},
|
||||
},
|
||||
});
|
||||
expect(result).not.toBeNull();
|
||||
if (result === null) {
|
||||
throw new Error("Expected planner result");
|
||||
}
|
||||
@@ -214,7 +213,6 @@ describe("Crestodian assistant", () => {
|
||||
removeTempDir: async () => {},
|
||||
},
|
||||
});
|
||||
expect(result).not.toBeNull();
|
||||
if (result === null) {
|
||||
throw new Error("Expected planner result");
|
||||
}
|
||||
@@ -266,7 +264,6 @@ describe("Crestodian assistant", () => {
|
||||
removeTempDir: async () => {},
|
||||
},
|
||||
});
|
||||
expect(result).not.toBeNull();
|
||||
if (result === null) {
|
||||
throw new Error("Expected planner result");
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@ function parseLastJsonLine(raw: string): unknown {
|
||||
}
|
||||
|
||||
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`);
|
||||
}
|
||||
|
||||
@@ -99,9 +99,10 @@ describeLive("Crestodian live rescue channel smoke", () => {
|
||||
|
||||
const config = JSON.parse(await fs.readFile(configPath, "utf8")) as OpenClawConfig;
|
||||
const defaultModel = config.agents?.defaults?.model;
|
||||
expect(typeof defaultModel).toBe("object");
|
||||
expect(defaultModel).not.toBeNull();
|
||||
expect((defaultModel as { primary?: unknown }).primary).toBe("openai/gpt-5.5");
|
||||
if (!defaultModel || typeof defaultModel !== "object") {
|
||||
throw new Error("expected default model object");
|
||||
}
|
||||
expect(defaultModel.primary).toBe("openai/gpt-5.5");
|
||||
const auditPath = path.join(tempDir, "audit", "crestodian.jsonl");
|
||||
const auditLines = (await fs.readFile(auditPath, "utf8")).trim().split("\n");
|
||||
expect(auditLines.some((line) => line.includes('"operation":"config.setDefaultModel"'))).toBe(
|
||||
|
||||
@@ -68,7 +68,8 @@ describe("runCrestodianTui", () => {
|
||||
expect(options.historyLimit).toBe(200);
|
||||
expect(options.config).toEqual({});
|
||||
expect(options.title).toBe("openclaw crestodian");
|
||||
expect(typeof options.backend).toBe("object");
|
||||
expect(options.backend).not.toBeNull();
|
||||
if (!options.backend || typeof options.backend !== "object") {
|
||||
throw new Error("expected crestodian TUI backend");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -184,8 +184,9 @@ function makeBaseParams(overrides: {
|
||||
}
|
||||
|
||||
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>;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import {
|
||||
type CliRespawnPlan = NonNullable<ReturnType<typeof buildCliRespawnPlan>>;
|
||||
|
||||
function expectCliRespawnPlan(plan: ReturnType<typeof buildCliRespawnPlan>): CliRespawnPlan {
|
||||
expect(plan).not.toBeNull();
|
||||
if (plan === null) {
|
||||
throw new Error("Expected CLI respawn plan");
|
||||
}
|
||||
|
||||
@@ -81,7 +81,9 @@ vi.mock("./channel-tools.js", () => ({
|
||||
|
||||
async function waitForTransport(): Promise<{ onclose?: (() => void) | undefined }> {
|
||||
await vi.waitFor(() => {
|
||||
expect(transportState.lastTransport).not.toBeNull();
|
||||
if (transportState.lastTransport === null) {
|
||||
throw new Error("MCP stdio transport was not created");
|
||||
}
|
||||
});
|
||||
if (!transportState.lastTransport) {
|
||||
throw new Error("MCP stdio transport was not created");
|
||||
|
||||
Reference in New Issue
Block a user