mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-27 08:28:14 +00:00
chore: Fix types in tests 13/N.
This commit is contained in:
@@ -145,7 +145,7 @@ describe("directive behavior", () => {
|
||||
{
|
||||
agents: {
|
||||
defaults: {
|
||||
model: "anthropic/claude-opus-4-5",
|
||||
model: { primary: "anthropic/claude-opus-4-5" },
|
||||
workspace: path.join(home, "openclaw"),
|
||||
},
|
||||
},
|
||||
@@ -179,7 +179,7 @@ describe("directive behavior", () => {
|
||||
{
|
||||
agents: {
|
||||
defaults: {
|
||||
model: "anthropic/claude-opus-4-5",
|
||||
model: { primary: "anthropic/claude-opus-4-5" },
|
||||
workspace: path.join(home, "openclaw"),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -83,7 +83,7 @@ describe("directive behavior", () => {
|
||||
{
|
||||
agents: {
|
||||
defaults: {
|
||||
model: "anthropic/claude-opus-4-5",
|
||||
model: { primary: "anthropic/claude-opus-4-5" },
|
||||
workspace: path.join(home, "openclaw"),
|
||||
},
|
||||
},
|
||||
@@ -120,7 +120,7 @@ describe("directive behavior", () => {
|
||||
{
|
||||
agents: {
|
||||
defaults: {
|
||||
model: "anthropic/claude-opus-4-5",
|
||||
model: { primary: "anthropic/claude-opus-4-5" },
|
||||
workspace: path.join(home, "openclaw"),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -55,7 +55,7 @@ describe("directive behavior", () => {
|
||||
{
|
||||
agents: {
|
||||
defaults: {
|
||||
model: "anthropic/claude-opus-4-5",
|
||||
model: { primary: "anthropic/claude-opus-4-5" },
|
||||
workspace: path.join(home, "openclaw"),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -62,7 +62,7 @@ describe("trigger handling", () => {
|
||||
{
|
||||
agents: {
|
||||
defaults: {
|
||||
model: "anthropic/claude-opus-4-5",
|
||||
model: { primary: "anthropic/claude-opus-4-5" },
|
||||
workspace: join(home, "openclaw"),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -46,7 +46,7 @@ describe("trigger handling", () => {
|
||||
const text = Array.isArray(res) ? res[0]?.text : res?.text;
|
||||
expect(text).toContain("tools.elevated.enabled");
|
||||
|
||||
const storeRaw = await fs.readFile(cfg.session.store, "utf-8");
|
||||
const storeRaw = await fs.readFile(cfg.session!.store, "utf-8");
|
||||
const store = JSON.parse(storeRaw) as Record<string, { elevatedLevel?: string }>;
|
||||
expect(store[MAIN_SESSION_KEY]?.elevatedLevel).toBeUndefined();
|
||||
});
|
||||
|
||||
@@ -38,7 +38,7 @@ describe("trigger handling", () => {
|
||||
const text = Array.isArray(res) ? res[0]?.text : res?.text;
|
||||
expect(text).toContain("Elevated mode disabled.");
|
||||
|
||||
const store = loadSessionStore(cfg.session.store);
|
||||
const store = loadSessionStore(cfg.session!.store);
|
||||
expect(store["agent:main:whatsapp:group:123@g.us"]?.elevatedLevel).toBe("off");
|
||||
});
|
||||
});
|
||||
@@ -64,7 +64,7 @@ describe("trigger handling", () => {
|
||||
const text = Array.isArray(res) ? res[0]?.text : res?.text;
|
||||
expect(text).toContain("Elevated mode set to ask");
|
||||
|
||||
const storeRaw = await fs.readFile(cfg.session.store, "utf-8");
|
||||
const storeRaw = await fs.readFile(cfg.session!.store, "utf-8");
|
||||
const store = JSON.parse(storeRaw) as Record<string, { elevatedLevel?: string }>;
|
||||
expect(store["agent:main:whatsapp:group:123@g.us"]?.elevatedLevel).toBe("on");
|
||||
});
|
||||
|
||||
@@ -36,7 +36,7 @@ function mockEmbeddedOkPayload() {
|
||||
|
||||
async function writeStoredModelOverride(cfg: ReturnType<typeof makeCfg>): Promise<void> {
|
||||
await fs.writeFile(
|
||||
cfg.session.store,
|
||||
cfg.session!.store,
|
||||
JSON.stringify({
|
||||
[MAIN_SESSION_KEY]: {
|
||||
sessionId: "main",
|
||||
@@ -154,7 +154,7 @@ describe("trigger handling", () => {
|
||||
);
|
||||
const text = Array.isArray(res) ? res[0]?.text : res?.text;
|
||||
expect(text).toContain("Group activation set to always");
|
||||
const store = JSON.parse(await fs.readFile(cfg.session.store, "utf-8")) as Record<
|
||||
const store = JSON.parse(await fs.readFile(cfg.session!.store, "utf-8")) as Record<
|
||||
string,
|
||||
{ groupActivation?: string }
|
||||
>;
|
||||
|
||||
@@ -143,7 +143,7 @@ describe("trigger handling", () => {
|
||||
const text = Array.isArray(res) ? res[0]?.text : res?.text;
|
||||
expect(text).toContain("Send policy set to off");
|
||||
|
||||
const storeRaw = await fs.readFile(cfg.session.store, "utf-8");
|
||||
const storeRaw = await fs.readFile(cfg.session!.store, "utf-8");
|
||||
const store = JSON.parse(storeRaw) as Record<string, { sendPolicy?: string }>;
|
||||
expect(store[MAIN_SESSION_KEY]?.sendPolicy).toBe("deny");
|
||||
});
|
||||
|
||||
@@ -50,7 +50,7 @@ describe("trigger handling", () => {
|
||||
Provider: "whatsapp",
|
||||
} as Parameters<typeof resolveSessionKey>[1]);
|
||||
await fs.writeFile(
|
||||
cfg.session.store,
|
||||
cfg.session!.store,
|
||||
JSON.stringify(
|
||||
{
|
||||
[sessionKey]: {
|
||||
|
||||
@@ -42,7 +42,7 @@ describe("trigger handling", () => {
|
||||
{
|
||||
agents: {
|
||||
defaults: {
|
||||
model: "anthropic/claude-opus-4-5",
|
||||
model: { primary: "anthropic/claude-opus-4-5" },
|
||||
workspace: join(home, "openclaw"),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -32,7 +32,7 @@ async function expectResetBlockedForNonOwner(params: {
|
||||
{
|
||||
agents: {
|
||||
defaults: {
|
||||
model: "anthropic/claude-opus-4-5",
|
||||
model: { primary: "anthropic/claude-opus-4-5" },
|
||||
workspace: join(home, "openclaw"),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -78,7 +78,7 @@ describe("trigger handling", () => {
|
||||
|
||||
expect(normalized).toContain("Model set to openrouter/anthropic/claude-opus-4-5");
|
||||
|
||||
const store = loadSessionStore(cfg.session.store);
|
||||
const store = loadSessionStore(cfg.session!.store);
|
||||
expect(store[sessionKey]?.providerOverride).toBe("openrouter");
|
||||
expect(store[sessionKey]?.modelOverride).toBe("anthropic/claude-opus-4-5");
|
||||
});
|
||||
@@ -92,7 +92,7 @@ describe("trigger handling", () => {
|
||||
expect(normalized).toContain("Browse: /models or /models <provider>");
|
||||
expect(normalized).toContain("Switch: /model <provider/model>");
|
||||
|
||||
const store = loadSessionStore(cfg.session.store);
|
||||
const store = loadSessionStore(cfg.session!.store);
|
||||
expect(store[sessionKey]?.providerOverride).toBeUndefined();
|
||||
expect(store[sessionKey]?.modelOverride).toBeUndefined();
|
||||
});
|
||||
@@ -107,7 +107,7 @@ describe("trigger handling", () => {
|
||||
|
||||
expect(normalized).toContain("Model reset to default (anthropic/claude-opus-4-5)");
|
||||
|
||||
const store = loadSessionStore(cfg.session.store);
|
||||
const store = loadSessionStore(cfg.session!.store);
|
||||
expect(store[sessionKey]?.providerOverride).toBeUndefined();
|
||||
expect(store[sessionKey]?.modelOverride).toBeUndefined();
|
||||
});
|
||||
@@ -119,7 +119,7 @@ describe("trigger handling", () => {
|
||||
|
||||
expect(normalized).toContain("Model set to openai/gpt-5.2");
|
||||
|
||||
const store = loadSessionStore(cfg.session.store);
|
||||
const store = loadSessionStore(cfg.session!.store);
|
||||
expect(store[sessionKey]?.providerOverride).toBe("openai");
|
||||
expect(store[sessionKey]?.modelOverride).toBe("gpt-5.2");
|
||||
});
|
||||
|
||||
@@ -26,7 +26,7 @@ describe("trigger handling", () => {
|
||||
const targetSessionKey = "agent:main:telegram:group:123";
|
||||
const targetSessionId = "session-target";
|
||||
await fs.writeFile(
|
||||
cfg.session.store,
|
||||
cfg.session!.store,
|
||||
JSON.stringify(
|
||||
{
|
||||
[targetSessionKey]: {
|
||||
@@ -85,7 +85,7 @@ describe("trigger handling", () => {
|
||||
const text = Array.isArray(res) ? res[0]?.text : res?.text;
|
||||
expect(text).toBe("⚙️ Agent was aborted.");
|
||||
expect(getAbortEmbeddedPiRunMock()).toHaveBeenCalledWith(targetSessionId);
|
||||
const store = loadSessionStore(cfg.session.store);
|
||||
const store = loadSessionStore(cfg.session!.store);
|
||||
expect(store[targetSessionKey]?.abortedLastRun).toBe(true);
|
||||
expect(getFollowupQueueDepth(targetSessionKey)).toBe(0);
|
||||
});
|
||||
@@ -98,7 +98,7 @@ describe("trigger handling", () => {
|
||||
|
||||
// Seed the target session to ensure the native command mutates it.
|
||||
await fs.writeFile(
|
||||
cfg.session.store,
|
||||
cfg.session!.store,
|
||||
JSON.stringify(
|
||||
{
|
||||
[targetSessionKey]: {
|
||||
@@ -131,7 +131,7 @@ describe("trigger handling", () => {
|
||||
const text = Array.isArray(res) ? res[0]?.text : res?.text;
|
||||
expect(text).toContain("Model set to openai/gpt-4.1-mini");
|
||||
|
||||
const store = loadSessionStore(cfg.session.store);
|
||||
const store = loadSessionStore(cfg.session!.store);
|
||||
expect(store[targetSessionKey]?.providerOverride).toBe("openai");
|
||||
expect(store[targetSessionKey]?.modelOverride).toBe("gpt-4.1-mini");
|
||||
expect(store[slashSessionKey]).toBeUndefined();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { resetSubagentRegistryForTests } from "../../agents/subagent-registry.js";
|
||||
import type { SpawnSubagentResult } from "../../agents/subagent-spawn.js";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
|
||||
const hoisted = vi.hoisted(() => {
|
||||
const spawnSubagentDirectMock = vi.fn();
|
||||
@@ -53,7 +54,7 @@ function forbiddenResult(error: string): SpawnSubagentResult {
|
||||
|
||||
const baseCfg = {
|
||||
session: { mainKey: "main", scope: "per-sender" },
|
||||
};
|
||||
} satisfies OpenClawConfig;
|
||||
|
||||
describe("/subagents spawn command", () => {
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -5,9 +5,11 @@ import type { GetReplyOptions, ReplyPayload } from "../types.js";
|
||||
import type { ReplyDispatcher } from "./reply-dispatcher.js";
|
||||
import { buildTestCtx } from "./test-ctx.js";
|
||||
|
||||
type AbortResult = { handled: boolean; aborted: boolean; stoppedSubagents?: number };
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
routeReply: vi.fn(async () => ({ ok: true, messageId: "mock" })),
|
||||
tryFastAbortFromMessage: vi.fn(async () => ({
|
||||
routeReply: vi.fn(async (_params: unknown) => ({ ok: true, messageId: "mock" })),
|
||||
tryFastAbortFromMessage: vi.fn<() => Promise<AbortResult>>(async () => ({
|
||||
handled: false,
|
||||
aborted: false,
|
||||
})),
|
||||
@@ -117,8 +119,8 @@ describe("dispatchReplyFromConfig", () => {
|
||||
|
||||
const replyResolver = async (
|
||||
_ctx: MsgContext,
|
||||
_opts: GetReplyOptions | undefined,
|
||||
_cfg: OpenClawConfig,
|
||||
_opts?: GetReplyOptions,
|
||||
_cfg?: OpenClawConfig,
|
||||
) => ({ text: "hi" }) satisfies ReplyPayload;
|
||||
await dispatchReplyFromConfig({ ctx, cfg, dispatcher, replyResolver });
|
||||
|
||||
@@ -141,8 +143,8 @@ describe("dispatchReplyFromConfig", () => {
|
||||
|
||||
const replyResolver = async (
|
||||
_ctx: MsgContext,
|
||||
_opts: GetReplyOptions | undefined,
|
||||
_cfg: OpenClawConfig,
|
||||
_opts?: GetReplyOptions,
|
||||
_cfg?: OpenClawConfig,
|
||||
) => ({ text: "hi" }) satisfies ReplyPayload;
|
||||
await dispatchReplyFromConfig({ ctx, cfg, dispatcher, replyResolver });
|
||||
|
||||
@@ -172,8 +174,8 @@ describe("dispatchReplyFromConfig", () => {
|
||||
|
||||
const replyResolver = async (
|
||||
_ctx: MsgContext,
|
||||
opts: GetReplyOptions | undefined,
|
||||
_cfg: OpenClawConfig,
|
||||
opts?: GetReplyOptions,
|
||||
_cfg?: OpenClawConfig,
|
||||
) => {
|
||||
expect(opts?.onToolResult).toBeDefined();
|
||||
await opts?.onToolResult?.({
|
||||
@@ -205,8 +207,8 @@ describe("dispatchReplyFromConfig", () => {
|
||||
|
||||
const replyResolver = async (
|
||||
_ctx: MsgContext,
|
||||
opts: GetReplyOptions | undefined,
|
||||
_cfg: OpenClawConfig,
|
||||
opts?: GetReplyOptions,
|
||||
_cfg?: OpenClawConfig,
|
||||
) => {
|
||||
expect(opts?.onToolResult).toBeDefined();
|
||||
expect(typeof opts?.onToolResult).toBe("function");
|
||||
@@ -228,8 +230,8 @@ describe("dispatchReplyFromConfig", () => {
|
||||
|
||||
const replyResolver = async (
|
||||
_ctx: MsgContext,
|
||||
opts: GetReplyOptions | undefined,
|
||||
_cfg: OpenClawConfig,
|
||||
opts?: GetReplyOptions,
|
||||
_cfg?: OpenClawConfig,
|
||||
) => {
|
||||
expect(opts?.onToolResult).toBeDefined();
|
||||
await opts?.onToolResult?.({ text: "🔧 exec: ls" });
|
||||
@@ -260,8 +262,8 @@ describe("dispatchReplyFromConfig", () => {
|
||||
|
||||
const replyResolver = async (
|
||||
_ctx: MsgContext,
|
||||
opts: GetReplyOptions | undefined,
|
||||
_cfg: OpenClawConfig,
|
||||
opts?: GetReplyOptions,
|
||||
_cfg?: OpenClawConfig,
|
||||
) => {
|
||||
// Simulate tool result emission
|
||||
await opts?.onToolResult?.({ text: "🔧 exec: ls" });
|
||||
@@ -287,8 +289,8 @@ describe("dispatchReplyFromConfig", () => {
|
||||
|
||||
const replyResolver = async (
|
||||
_ctx: MsgContext,
|
||||
opts: GetReplyOptions | undefined,
|
||||
_cfg: OpenClawConfig,
|
||||
opts?: GetReplyOptions,
|
||||
_cfg?: OpenClawConfig,
|
||||
) => {
|
||||
expect(opts?.onToolResult).toBeDefined();
|
||||
await opts?.onToolResult?.({ text: "🔧 tools/sessions_send" });
|
||||
|
||||
Reference in New Issue
Block a user