chore: Fix types in tests 38/N.

This commit is contained in:
cpojer
2026-02-17 15:47:23 +09:00
parent 238718c1d8
commit 084e39b519
19 changed files with 85 additions and 40 deletions

View File

@@ -126,7 +126,8 @@ function createErrnoError(code: string) {
}
function mockWorkspaceStateRead(params: { onboardingCompletedAt?: string; errorCode?: string }) {
mocks.fsReadFile.mockImplementation(async (filePath: string | URL | number) => {
mocks.fsReadFile.mockImplementation(async (...args: unknown[]) => {
const filePath = args[0];
if (String(filePath).endsWith("workspace-state.json")) {
if (params.errorCode) {
throw createErrnoError(params.errorCode);

View File

@@ -107,6 +107,9 @@ describe("chat abort transcript persistence", () => {
params: { sessionKey: "main", runId },
respond,
context: context as never,
req: {} as never,
client: null,
isWebchatConnect: () => false,
});
const [ok1, payload1] = respond.mock.calls.at(-1) ?? [];
@@ -121,6 +124,9 @@ describe("chat abort transcript persistence", () => {
params: { sessionKey: "main", runId },
respond,
context: context as never,
req: {} as never,
client: null,
isWebchatConnect: () => false,
});
const lines = await readTranscriptLines(transcriptPath);
@@ -178,6 +184,9 @@ describe("chat abort transcript persistence", () => {
params: { sessionKey: "main" },
respond,
context: context as never,
req: {} as never,
client: null,
isWebchatConnect: () => false,
});
const [ok, payload] = respond.mock.calls.at(-1) ?? [];
@@ -235,7 +244,9 @@ describe("chat abort transcript persistence", () => {
},
respond,
context: context as never,
client: undefined,
req: {} as never,
client: null,
isWebchatConnect: () => false,
});
const [ok, payload] = respond.mock.calls.at(-1) ?? [];

View File

@@ -26,7 +26,7 @@ describe("gateway chat.inject transcript writes", () => {
);
vi.doMock("../session-utils.js", async (importOriginal) => {
const original = await importOriginal();
const original = await importOriginal<typeof import("../session-utils.js")>();
return {
...original,
loadSessionEntry: () => ({
@@ -50,7 +50,10 @@ describe("gateway chat.inject transcript writes", () => {
await chatHandlers["chat.inject"]({
params: { sessionKey: "k1", message: "hello" },
respond,
context,
req: {} as never,
client: null as never,
isWebchatConnect: () => false,
context: context as unknown as GatewayRequestContext,
});
expect(respond).toHaveBeenCalled();

View File

@@ -28,6 +28,10 @@ describe("skills.update", () => {
skillKey: "brave-search",
apiKey: "abc\r\ndef",
},
req: {} as never,
client: null as never,
isWebchatConnect: () => false,
context: {} as never,
respond: (success, _result, err) => {
ok = success;
error = err;

View File

@@ -106,7 +106,9 @@ describe("sessions.usage", () => {
expect(respond).toHaveBeenCalledTimes(1);
expect(respond.mock.calls[0]?.[0]).toBe(true);
const result = respond.mock.calls[0]?.[1] as unknown as { sessions: Array<unknown> };
const result = respond.mock.calls[0]?.[1] as unknown as {
sessions: Array<{ key: string; agentId: string }>;
};
expect(result.sessions).toHaveLength(2);
// Sorted by most recent first (mtime=200 -> opus first).

View File

@@ -1,4 +1,5 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../../config/config.js";
vi.mock("../../infra/session-cost-usage.js", async () => {
const actual = await vi.importActual<typeof import("../../infra/session-cost-usage.js")>(
@@ -63,7 +64,7 @@ describe("gateway usage helpers", () => {
vi.useFakeTimers();
vi.setSystemTime(new Date("2026-02-05T00:00:00.000Z"));
const config = {} as unknown as ReturnType<import("../../config/config.js").loadConfig>;
const config = {} as OpenClawConfig;
const a = await __test.loadCostUsageSummaryCached({
startMs: 1,
endMs: 2,