mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 02:18:25 +00:00
chore: Fix types in tests 25/N.
This commit is contained in:
@@ -17,7 +17,7 @@ function createForeignSignalHarness() {
|
||||
}
|
||||
},
|
||||
removeEventListener,
|
||||
} as AbortSignal;
|
||||
} as unknown as AbortSignal;
|
||||
|
||||
return {
|
||||
fakeSignal,
|
||||
@@ -38,7 +38,7 @@ describe("wrapFetchWithAbortSignal", () => {
|
||||
|
||||
await wrapped("https://example.com", { method: "POST", body: "hi" });
|
||||
|
||||
expect(seenInit?.duplex).toBe("half");
|
||||
expect((seenInit as (RequestInit & { duplex?: string }) | undefined)?.duplex).toBe("half");
|
||||
});
|
||||
|
||||
it("converts foreign abort signals to native controllers", async () => {
|
||||
@@ -119,7 +119,7 @@ describe("wrapFetchWithAbortSignal", () => {
|
||||
aborted: false,
|
||||
addEventListener: (_event: string, _handler: () => void) => {},
|
||||
removeEventListener,
|
||||
} as AbortSignal;
|
||||
} as unknown as AbortSignal;
|
||||
|
||||
await expect(wrapped("https://example.com", { signal: fakeSignal })).rejects.toBe(fetchError);
|
||||
expect(removeEventListener).toHaveBeenCalledOnce();
|
||||
@@ -141,7 +141,7 @@ describe("wrapFetchWithAbortSignal", () => {
|
||||
aborted: false,
|
||||
addEventListener: (_event: string, _handler: () => void) => {},
|
||||
removeEventListener,
|
||||
} as AbortSignal;
|
||||
} as unknown as AbortSignal;
|
||||
|
||||
expect(() => wrapped("https://example.com", { signal: fakeSignal })).toThrow(syncError);
|
||||
expect(removeEventListener).toHaveBeenCalledOnce();
|
||||
@@ -157,7 +157,7 @@ describe("wrapFetchWithAbortSignal", () => {
|
||||
aborted: true,
|
||||
addEventListener,
|
||||
removeEventListener,
|
||||
} as AbortSignal;
|
||||
} as unknown as AbortSignal;
|
||||
|
||||
await wrapped("https://example.com", { signal: fakeSignal });
|
||||
|
||||
@@ -177,7 +177,7 @@ describe("wrapFetchWithAbortSignal", () => {
|
||||
const preconnectSpy = vi.fn(function (this: unknown) {
|
||||
return this;
|
||||
});
|
||||
const fetchImpl = vi.fn(async () => ({ ok: true }) as Response) as typeof fetch & {
|
||||
const fetchImpl = vi.fn(async () => ({ ok: true }) as Response) as unknown as typeof fetch & {
|
||||
preconnect: (url: string, init?: { credentials?: RequestCredentials }) => unknown;
|
||||
};
|
||||
fetchImpl.preconnect = preconnectSpy;
|
||||
|
||||
@@ -9,19 +9,21 @@ import {
|
||||
readRequestBodyWithLimit,
|
||||
} from "./http-body.js";
|
||||
|
||||
type MockIncomingMessage = IncomingMessage & {
|
||||
destroyed?: boolean;
|
||||
destroy: (error?: Error) => MockIncomingMessage;
|
||||
__unhandledDestroyError?: unknown;
|
||||
};
|
||||
|
||||
function createMockRequest(params: {
|
||||
chunks?: string[];
|
||||
headers?: Record<string, string>;
|
||||
emitEnd?: boolean;
|
||||
}): IncomingMessage {
|
||||
const req = new EventEmitter() as IncomingMessage & {
|
||||
destroyed?: boolean;
|
||||
destroy: (error?: Error) => void;
|
||||
__unhandledDestroyError?: unknown;
|
||||
};
|
||||
}): MockIncomingMessage {
|
||||
const req = new EventEmitter() as MockIncomingMessage;
|
||||
req.destroyed = false;
|
||||
req.headers = params.headers ?? {};
|
||||
req.destroy = (error?: Error) => {
|
||||
req.destroy = ((error?: Error) => {
|
||||
req.destroyed = true;
|
||||
if (error) {
|
||||
// Simulate Node's async 'error' emission on destroy(err). If no listener is
|
||||
@@ -34,7 +36,8 @@ function createMockRequest(params: {
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
return req;
|
||||
}) as MockIncomingMessage["destroy"];
|
||||
|
||||
if (params.chunks) {
|
||||
void Promise.resolve().then(() => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
createPinnedLookup,
|
||||
type LookupFn,
|
||||
resolvePinnedHostname,
|
||||
resolvePinnedHostnameWithPolicy,
|
||||
} from "./ssrf.js";
|
||||
@@ -10,7 +11,7 @@ describe("ssrf pinning", () => {
|
||||
const lookup = vi.fn(async () => [
|
||||
{ address: "93.184.216.34", family: 4 },
|
||||
{ address: "93.184.216.35", family: 4 },
|
||||
]);
|
||||
]) as unknown as LookupFn;
|
||||
|
||||
const pinned = await resolvePinnedHostname("Example.com.", lookup);
|
||||
expect(pinned.hostname).toBe("example.com");
|
||||
@@ -44,7 +45,7 @@ describe("ssrf pinning", () => {
|
||||
});
|
||||
|
||||
it("rejects private DNS results", async () => {
|
||||
const lookup = vi.fn(async () => [{ address: "10.0.0.8", family: 4 }]);
|
||||
const lookup = vi.fn(async () => [{ address: "10.0.0.8", family: 4 }]) as unknown as LookupFn;
|
||||
await expect(resolvePinnedHostname("example.com", lookup)).rejects.toThrow(/private|internal/i);
|
||||
});
|
||||
|
||||
@@ -52,7 +53,7 @@ describe("ssrf pinning", () => {
|
||||
const fallback = vi.fn((host: string, options?: unknown, callback?: unknown) => {
|
||||
const cb = typeof options === "function" ? options : (callback as () => void);
|
||||
(cb as (err: null, address: string, family: number) => void)(null, "1.2.3.4", 4);
|
||||
});
|
||||
}) as unknown as Parameters<typeof createPinnedLookup>[0]["fallback"];
|
||||
const lookup = createPinnedLookup({
|
||||
hostname: "example.com",
|
||||
addresses: ["93.184.216.34"],
|
||||
@@ -74,7 +75,9 @@ describe("ssrf pinning", () => {
|
||||
});
|
||||
|
||||
it("enforces hostname allowlist when configured", async () => {
|
||||
const lookup = vi.fn(async () => [{ address: "93.184.216.34", family: 4 }]);
|
||||
const lookup = vi.fn(async () => [
|
||||
{ address: "93.184.216.34", family: 4 },
|
||||
]) as unknown as LookupFn;
|
||||
|
||||
await expect(
|
||||
resolvePinnedHostnameWithPolicy("api.example.com", {
|
||||
@@ -86,7 +89,9 @@ describe("ssrf pinning", () => {
|
||||
});
|
||||
|
||||
it("supports wildcard hostname allowlist patterns", async () => {
|
||||
const lookup = vi.fn(async () => [{ address: "93.184.216.34", family: 4 }]);
|
||||
const lookup = vi.fn(async () => [
|
||||
{ address: "93.184.216.34", family: 4 },
|
||||
]) as unknown as LookupFn;
|
||||
|
||||
await expect(
|
||||
resolvePinnedHostnameWithPolicy("assets.example.com", {
|
||||
|
||||
@@ -864,10 +864,15 @@ describe("runMessageAction accountId defaults", () => {
|
||||
});
|
||||
|
||||
expect(handleAction).toHaveBeenCalled();
|
||||
const ctx = handleAction.mock.calls[0]?.[0] as {
|
||||
accountId?: string | null;
|
||||
params: Record<string, unknown>;
|
||||
};
|
||||
const ctx = (handleAction.mock.calls as unknown as Array<[unknown]>)[0]?.[0] as
|
||||
| {
|
||||
accountId?: string | null;
|
||||
params: Record<string, unknown>;
|
||||
}
|
||||
| undefined;
|
||||
if (!ctx) {
|
||||
throw new Error("expected action context");
|
||||
}
|
||||
expect(ctx.accountId).toBe("ops");
|
||||
expect(ctx.params.accountId).toBe("ops");
|
||||
});
|
||||
|
||||
@@ -96,7 +96,7 @@ describe("session cost usage", () => {
|
||||
},
|
||||
},
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
} as unknown as OpenClawConfig;
|
||||
|
||||
const originalState = process.env.OPENCLAW_STATE_DIR;
|
||||
process.env.OPENCLAW_STATE_DIR = root;
|
||||
@@ -275,7 +275,11 @@ describe("session cost usage", () => {
|
||||
try {
|
||||
const summary = await loadSessionCostSummary({
|
||||
sessionId: "sess-worker-1",
|
||||
sessionEntry: { sessionFile: workerSessionFile } as { sessionFile: string },
|
||||
sessionEntry: {
|
||||
sessionId: "sess-worker-1",
|
||||
updatedAt: Date.now(),
|
||||
sessionFile: workerSessionFile,
|
||||
},
|
||||
agentId: "worker1",
|
||||
});
|
||||
expect(summary?.totalTokens).toBe(18);
|
||||
@@ -317,7 +321,11 @@ describe("session cost usage", () => {
|
||||
try {
|
||||
const timeseries = await loadSessionUsageTimeSeries({
|
||||
sessionId: "sess-worker-2",
|
||||
sessionEntry: { sessionFile: workerSessionFile } as { sessionFile: string },
|
||||
sessionEntry: {
|
||||
sessionId: "sess-worker-2",
|
||||
updatedAt: Date.now(),
|
||||
sessionFile: workerSessionFile,
|
||||
},
|
||||
agentId: "worker2",
|
||||
});
|
||||
expect(timeseries?.points.length).toBe(1);
|
||||
@@ -357,7 +365,11 @@ describe("session cost usage", () => {
|
||||
try {
|
||||
const logs = await loadSessionLogs({
|
||||
sessionId: "sess-worker-3",
|
||||
sessionEntry: { sessionFile: workerSessionFile } as { sessionFile: string },
|
||||
sessionEntry: {
|
||||
sessionId: "sess-worker-3",
|
||||
updatedAt: Date.now(),
|
||||
sessionFile: workerSessionFile,
|
||||
},
|
||||
agentId: "worker3",
|
||||
});
|
||||
expect(logs).toHaveLength(1);
|
||||
|
||||
Reference in New Issue
Block a user