chore: Fix types in tests 21/N.

This commit is contained in:
cpojer
2026-02-17 12:22:17 +09:00
parent 18cc48dfd9
commit 245018fd6b
6 changed files with 48 additions and 20 deletions

View File

@@ -3,6 +3,7 @@ import os from "node:os";
import path from "node:path";
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { loadModelCatalog } from "../agents/model-catalog.js";
import type { OpenClawConfig } from "../config/config.js";
import { getReplyFromConfig } from "./reply.js";
type RunEmbeddedPiAgent = typeof import("../agents/pi-embedded.js").runEmbeddedPiAgent;
@@ -11,7 +12,7 @@ type RunEmbeddedPiAgentReply = Awaited<ReturnType<RunEmbeddedPiAgent>>;
const piEmbeddedMock = vi.hoisted(() => ({
abortEmbeddedPiRun: vi.fn().mockReturnValue(false),
runEmbeddedPiAgent: vi.fn<ReturnType<RunEmbeddedPiAgent>, Parameters<RunEmbeddedPiAgent>>(),
runEmbeddedPiAgent: vi.fn<RunEmbeddedPiAgent>(),
queueEmbeddedPiMessage: vi.fn().mockReturnValue(false),
resolveEmbeddedSessionLane: (key: string) => `session:${key.trim() || "main"}`,
isEmbeddedPiRunActive: vi.fn().mockReturnValue(false),
@@ -55,6 +56,8 @@ function restoreHomeEnv(snapshot: HomeEnvSnapshot) {
let fixtureRoot = "";
let caseId = 0;
type GetReplyOptions = NonNullable<Parameters<typeof getReplyFromConfig>[1]>;
function createEmbeddedReply(text: string): RunEmbeddedPiAgentReply {
return {
payloads: [{ text }],
@@ -75,11 +78,11 @@ function createTelegramMessage(messageSid: string) {
} as const;
}
function createReplyConfig(home: string, streamMode?: "block") {
function createReplyConfig(home: string, streamMode?: "block"): OpenClawConfig {
return {
agents: {
defaults: {
model: "anthropic/claude-opus-4-5",
model: { primary: "anthropic/claude-opus-4-5" },
workspace: path.join(home, "openclaw"),
},
},
@@ -91,8 +94,8 @@ function createReplyConfig(home: string, streamMode?: "block") {
async function runTelegramReply(params: {
home: string;
messageSid: string;
onBlockReply?: Parameters<typeof getReplyFromConfig>[1]["onBlockReply"];
onReplyStart?: Parameters<typeof getReplyFromConfig>[1]["onReplyStart"];
onBlockReply?: GetReplyOptions["onBlockReply"];
onReplyStart?: GetReplyOptions["onReplyStart"];
disableBlockStreaming?: boolean;
streamMode?: "block";
}) {
@@ -220,7 +223,8 @@ describe("block streaming", () => {
streamMode: "block",
});
expect(resStreamMode?.text).toBe("final");
const streamPayload = Array.isArray(resStreamMode) ? resStreamMode[0] : resStreamMode;
expect(streamPayload?.text).toBe("final");
expect(onBlockReplyStreamMode).not.toHaveBeenCalled();
});
});