mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 15:34:31 +00:00
chore: Fix types in tests 28/N.
This commit is contained in:
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { SubagentRunRecord } from "../../agents/subagent-registry.js";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import {
|
||||
getAbortMemory,
|
||||
@@ -28,7 +29,9 @@ const commandQueueMocks = vi.hoisted(() => ({
|
||||
vi.mock("../../process/command-queue.js", () => commandQueueMocks);
|
||||
|
||||
const subagentRegistryMocks = vi.hoisted(() => ({
|
||||
listSubagentRunsForRequester: vi.fn(() => []),
|
||||
listSubagentRunsForRequester: vi.fn<(requesterSessionKey: string) => SubagentRunRecord[]>(
|
||||
() => [],
|
||||
),
|
||||
markSubagentRunTerminated: vi.fn(() => 1),
|
||||
}));
|
||||
|
||||
|
||||
@@ -233,7 +233,7 @@ async function runReplyAgentWithBase(params: {
|
||||
baseRun: ReturnType<typeof createBaseRun>;
|
||||
storePath: string;
|
||||
sessionKey: string;
|
||||
sessionEntry: Record<string, unknown>;
|
||||
sessionEntry: SessionEntry;
|
||||
commandBody: string;
|
||||
typingMode?: "instant";
|
||||
}): Promise<void> {
|
||||
@@ -303,7 +303,7 @@ describe("runReplyAgent typing (heartbeat)", () => {
|
||||
persistStore: boolean;
|
||||
}) {
|
||||
const storePath = path.join(params.stateDir, "sessions", "sessions.json");
|
||||
const sessionEntry = { sessionId: params.sessionId, updatedAt: Date.now() };
|
||||
const sessionEntry: SessionEntry = { sessionId: params.sessionId, updatedAt: Date.now() };
|
||||
const sessionStore = { main: sessionEntry };
|
||||
|
||||
await fs.mkdir(path.dirname(storePath), { recursive: true });
|
||||
@@ -490,7 +490,7 @@ describe("runReplyAgent typing (heartbeat)", () => {
|
||||
it("announces auto-compaction in verbose mode and tracks count", async () => {
|
||||
await withTempStateDir(async (stateDir) => {
|
||||
const storePath = path.join(stateDir, "sessions", "sessions.json");
|
||||
const sessionEntry = { sessionId: "session", updatedAt: Date.now() };
|
||||
const sessionEntry: SessionEntry = { sessionId: "session", updatedAt: Date.now() };
|
||||
const sessionStore = { main: sessionEntry };
|
||||
|
||||
state.runEmbeddedPiAgentMock.mockImplementationOnce(async (params: AgentRunParams) => {
|
||||
@@ -549,6 +549,9 @@ describe("runReplyAgent typing (heartbeat)", () => {
|
||||
expect(payload).toMatchObject({
|
||||
text: expect.stringContaining("Context limit exceeded during compaction"),
|
||||
});
|
||||
if (!payload) {
|
||||
throw new Error("expected payload");
|
||||
}
|
||||
expect(payload.text?.toLowerCase()).toContain("reset");
|
||||
expect(sessionStore.main.sessionId).not.toBe(sessionId);
|
||||
|
||||
@@ -594,6 +597,9 @@ describe("runReplyAgent typing (heartbeat)", () => {
|
||||
expect(payload).toMatchObject({
|
||||
text: expect.stringContaining("Context limit exceeded"),
|
||||
});
|
||||
if (!payload) {
|
||||
throw new Error("expected payload");
|
||||
}
|
||||
expect(payload.text?.toLowerCase()).toContain("reset");
|
||||
expect(sessionStore.main.sessionId).not.toBe(sessionId);
|
||||
|
||||
@@ -638,6 +644,9 @@ describe("runReplyAgent typing (heartbeat)", () => {
|
||||
expect(payload).toMatchObject({
|
||||
text: expect.stringContaining("Message ordering conflict"),
|
||||
});
|
||||
if (!payload) {
|
||||
throw new Error("expected payload");
|
||||
}
|
||||
expect(payload.text?.toLowerCase()).toContain("reset");
|
||||
expect(sessionStore.main.sessionId).not.toBe(sessionId);
|
||||
await expect(fs.access(transcriptPath)).rejects.toBeDefined();
|
||||
|
||||
@@ -128,7 +128,8 @@ describe("createFollowupRunner compaction", () => {
|
||||
await runner(queued);
|
||||
|
||||
expect(onBlockReply).toHaveBeenCalled();
|
||||
expect(onBlockReply.mock.calls[0][0].text).toContain("Auto-compaction complete");
|
||||
const firstCall = (onBlockReply.mock.calls as unknown as Array<Array<{ text?: string }>>)[0];
|
||||
expect(firstCall?.[0]?.text).toContain("Auto-compaction complete");
|
||||
expect(sessionStore.main.compactionCount).toBe(1);
|
||||
});
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import { SILENT_REPLY_TOKEN } from "../tokens.js";
|
||||
const mocks = vi.hoisted(() => ({
|
||||
sendMessageDiscord: vi.fn(async () => ({ messageId: "m1", channelId: "c1" })),
|
||||
sendMessageIMessage: vi.fn(async () => ({ messageId: "ok" })),
|
||||
sendMessageMSTeams: vi.fn(async () => ({
|
||||
sendMessageMSTeams: vi.fn(async (_params: unknown) => ({
|
||||
messageId: "m1",
|
||||
conversationId: "c1",
|
||||
})),
|
||||
|
||||
@@ -5,6 +5,7 @@ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi }
|
||||
import { buildModelAliasIndex } from "../../agents/model-selection.js";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import { saveSessionStore } from "../../config/sessions.js";
|
||||
import type { SessionEntry } from "../../config/sessions.js";
|
||||
import { formatZonedTimestamp } from "../../infra/format-time/format-datetime.ts";
|
||||
import { enqueueSystemEvent, resetSystemEventsForTest } from "../../infra/system-events.js";
|
||||
import { applyResetModelOverride } from "./session-reset-model.js";
|
||||
@@ -866,11 +867,11 @@ describe("applyResetModelOverride", () => {
|
||||
it("selects a model hint and strips it from the body", async () => {
|
||||
const cfg = {} as OpenClawConfig;
|
||||
const aliasIndex = buildModelAliasIndex({ cfg, defaultProvider: "openai" });
|
||||
const sessionEntry = {
|
||||
const sessionEntry: SessionEntry = {
|
||||
sessionId: "s1",
|
||||
updatedAt: Date.now(),
|
||||
};
|
||||
const sessionStore = { "agent:main:dm:1": sessionEntry };
|
||||
const sessionStore: Record<string, SessionEntry> = { "agent:main:dm:1": sessionEntry };
|
||||
const sessionCtx = { BodyStripped: "minimax summarize" };
|
||||
const ctx = { ChatType: "direct" };
|
||||
|
||||
@@ -896,14 +897,14 @@ describe("applyResetModelOverride", () => {
|
||||
it("clears auth profile overrides when reset applies a model", async () => {
|
||||
const cfg = {} as OpenClawConfig;
|
||||
const aliasIndex = buildModelAliasIndex({ cfg, defaultProvider: "openai" });
|
||||
const sessionEntry = {
|
||||
const sessionEntry: SessionEntry = {
|
||||
sessionId: "s1",
|
||||
updatedAt: Date.now(),
|
||||
authProfileOverride: "anthropic:default",
|
||||
authProfileOverrideSource: "user",
|
||||
authProfileOverrideCompactionCount: 2,
|
||||
};
|
||||
const sessionStore = { "agent:main:dm:1": sessionEntry };
|
||||
const sessionStore: Record<string, SessionEntry> = { "agent:main:dm:1": sessionEntry };
|
||||
const sessionCtx = { BodyStripped: "minimax summarize" };
|
||||
const ctx = { ChatType: "direct" };
|
||||
|
||||
@@ -929,11 +930,11 @@ describe("applyResetModelOverride", () => {
|
||||
it("skips when resetTriggered is false", async () => {
|
||||
const cfg = {} as OpenClawConfig;
|
||||
const aliasIndex = buildModelAliasIndex({ cfg, defaultProvider: "openai" });
|
||||
const sessionEntry = {
|
||||
const sessionEntry: SessionEntry = {
|
||||
sessionId: "s1",
|
||||
updatedAt: Date.now(),
|
||||
};
|
||||
const sessionStore = { "agent:main:dm:1": sessionEntry };
|
||||
const sessionStore: Record<string, SessionEntry> = { "agent:main:dm:1": sessionEntry };
|
||||
const sessionCtx = { BodyStripped: "minimax summarize" };
|
||||
const ctx = { ChatType: "direct" };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user