mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 19:20:43 +00:00
test: restore current-main test isolation
This commit is contained in:
@@ -20,6 +20,12 @@ import type { UploadCacheAdapter } from "./media.js";
|
|||||||
import { UPLOAD_PREPARE_FALLBACK_CODE } from "./retry.js";
|
import { UPLOAD_PREPARE_FALLBACK_CODE } from "./retry.js";
|
||||||
import type { TokenManager } from "./token.js";
|
import type { TokenManager } from "./token.js";
|
||||||
|
|
||||||
|
const fetchWithSsrFGuardMock = vi.hoisted(() => vi.fn());
|
||||||
|
|
||||||
|
vi.mock("openclaw/plugin-sdk/ssrf-runtime", () => ({
|
||||||
|
fetchWithSsrFGuard: fetchWithSsrFGuardMock,
|
||||||
|
}));
|
||||||
|
|
||||||
// ============ Test doubles ============
|
// ============ Test doubles ============
|
||||||
|
|
||||||
/** Build a minimal ApiClient stub whose `request` is fully mockable. */
|
/** Build a minimal ApiClient stub whose `request` is fully mockable. */
|
||||||
@@ -82,18 +88,17 @@ const FIXTURE_BUFFER = Buffer.from("0123456789abcdefghij"); // 20 bytes
|
|||||||
let originalFetch: typeof globalThis.fetch;
|
let originalFetch: typeof globalThis.fetch;
|
||||||
|
|
||||||
function stubFetchOk(): ReturnType<typeof vi.fn> {
|
function stubFetchOk(): ReturnType<typeof vi.fn> {
|
||||||
const spy = vi.fn(
|
fetchWithSsrFGuardMock.mockImplementation(async () => ({
|
||||||
async () =>
|
response: new Response("", {
|
||||||
new Response("", {
|
status: 200,
|
||||||
status: 200,
|
headers: {
|
||||||
headers: {
|
ETag: '"etag-value"',
|
||||||
ETag: '"etag-value"',
|
"x-cos-request-id": "req-id",
|
||||||
"x-cos-request-id": "req-id",
|
},
|
||||||
},
|
}),
|
||||||
}),
|
release: vi.fn(),
|
||||||
);
|
}));
|
||||||
globalThis.fetch = spy as unknown as typeof globalThis.fetch;
|
return fetchWithSsrFGuardMock;
|
||||||
return spy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============ Tests ============
|
// ============ Tests ============
|
||||||
@@ -122,6 +127,7 @@ describe("media-chunked: ChunkedMediaApi.uploadChunked", () => {
|
|||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
globalThis.fetch = originalFetch;
|
globalThis.fetch = originalFetch;
|
||||||
|
fetchWithSsrFGuardMock.mockReset();
|
||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -235,7 +241,7 @@ describe("media-chunked: ChunkedMediaApi.uploadChunked", () => {
|
|||||||
|
|
||||||
// 3 COS PUTs, one per part, each to the presigned URL.
|
// 3 COS PUTs, one per part, each to the presigned URL.
|
||||||
expect(fetchSpy).toHaveBeenCalledTimes(3);
|
expect(fetchSpy).toHaveBeenCalledTimes(3);
|
||||||
const putUrls = fetchSpy.mock.calls.map((c) => c[0]);
|
const putUrls = fetchSpy.mock.calls.map((c) => (c[0] as { url: string }).url);
|
||||||
expect(putUrls).toEqual(
|
expect(putUrls).toEqual(
|
||||||
expect.arrayContaining([
|
expect.arrayContaining([
|
||||||
"https://cos.example.com/part-1",
|
"https://cos.example.com/part-1",
|
||||||
|
|||||||
@@ -88,6 +88,10 @@ vi.mock("openclaw/plugin-sdk/memory-host-search", () => ({
|
|||||||
getActiveMemorySearchManager: mocks.getActiveMemorySearchManager,
|
getActiveMemorySearchManager: mocks.getActiveMemorySearchManager,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
vi.mock("../../../src/plugins/memory-runtime.js", () => ({
|
||||||
|
getActiveMemorySearchManager: mocks.getActiveMemorySearchManager,
|
||||||
|
}));
|
||||||
|
|
||||||
vi.mock("./tunnel.js", () => ({
|
vi.mock("./tunnel.js", () => ({
|
||||||
startTunnel: mocks.startTunnel,
|
startTunnel: mocks.startTunnel,
|
||||||
}));
|
}));
|
||||||
|
|||||||
Reference in New Issue
Block a user