mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 17:44:33 +00:00
test(integration): dedupe messaging, secrets, and plugin test suites
This commit is contained in:
@@ -78,6 +78,21 @@ describe("pw-tools-core", () => {
|
||||
};
|
||||
}
|
||||
|
||||
async function expectAtomicDownloadSave(params: {
|
||||
saveAs: ReturnType<typeof vi.fn>;
|
||||
targetPath: string;
|
||||
tempDir: string;
|
||||
content: string;
|
||||
}) {
|
||||
const savedPath = params.saveAs.mock.calls[0]?.[0];
|
||||
expect(typeof savedPath).toBe("string");
|
||||
expect(savedPath).not.toBe(params.targetPath);
|
||||
expect(path.dirname(String(savedPath))).toBe(params.tempDir);
|
||||
expect(path.basename(String(savedPath))).toContain(".openclaw-output-");
|
||||
expect(path.basename(String(savedPath))).toContain(".part");
|
||||
expect(await fs.readFile(params.targetPath, "utf8")).toBe(params.content);
|
||||
}
|
||||
|
||||
it("waits for the next download and atomically finalizes explicit output paths", async () => {
|
||||
await withTempDir(async (tempDir) => {
|
||||
const harness = createDownloadEventHarness();
|
||||
@@ -104,13 +119,7 @@ describe("pw-tools-core", () => {
|
||||
harness.trigger(download);
|
||||
|
||||
const res = await p;
|
||||
const savedPath = saveAs.mock.calls[0]?.[0];
|
||||
expect(typeof savedPath).toBe("string");
|
||||
expect(savedPath).not.toBe(targetPath);
|
||||
expect(path.dirname(String(savedPath))).toBe(tempDir);
|
||||
expect(path.basename(String(savedPath))).toContain(".openclaw-output-");
|
||||
expect(path.basename(String(savedPath))).toContain(".part");
|
||||
expect(await fs.readFile(targetPath, "utf8")).toBe("file-content");
|
||||
await expectAtomicDownloadSave({ saveAs, targetPath, tempDir, content: "file-content" });
|
||||
expect(res.path).toBe(targetPath);
|
||||
});
|
||||
});
|
||||
@@ -146,13 +155,7 @@ describe("pw-tools-core", () => {
|
||||
harness.trigger(download);
|
||||
|
||||
const res = await p;
|
||||
const savedPath = saveAs.mock.calls[0]?.[0];
|
||||
expect(typeof savedPath).toBe("string");
|
||||
expect(savedPath).not.toBe(targetPath);
|
||||
expect(path.dirname(String(savedPath))).toBe(tempDir);
|
||||
expect(path.basename(String(savedPath))).toContain(".openclaw-output-");
|
||||
expect(path.basename(String(savedPath))).toContain(".part");
|
||||
expect(await fs.readFile(targetPath, "utf8")).toBe("report-content");
|
||||
await expectAtomicDownloadSave({ saveAs, targetPath, tempDir, content: "report-content" });
|
||||
expect(res.path).toBe(targetPath);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createServer, type AddressInfo } from "node:net";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { getFreePort } from "./test-port.js";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
controlPort: 0,
|
||||
@@ -12,12 +12,13 @@ const mocks = vi.hoisted(() => ({
|
||||
|
||||
vi.mock("../config/config.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../config/config.js")>();
|
||||
const browserConfig = {
|
||||
enabled: true,
|
||||
};
|
||||
return {
|
||||
...actual,
|
||||
loadConfig: () => ({
|
||||
browser: {
|
||||
enabled: true,
|
||||
},
|
||||
browser: browserConfig,
|
||||
}),
|
||||
};
|
||||
});
|
||||
@@ -58,17 +59,6 @@ vi.mock("./pw-ai-state.js", () => ({
|
||||
const { startBrowserControlServerFromConfig, stopBrowserControlServer } =
|
||||
await import("./server.js");
|
||||
|
||||
async function getFreePort(): Promise<number> {
|
||||
const probe = createServer();
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
probe.once("error", reject);
|
||||
probe.listen(0, "127.0.0.1", () => resolve());
|
||||
});
|
||||
const addr = probe.address() as AddressInfo;
|
||||
await new Promise<void>((resolve) => probe.close(() => resolve()));
|
||||
return addr.port;
|
||||
}
|
||||
|
||||
describe("browser control auth bootstrap failures", () => {
|
||||
beforeEach(async () => {
|
||||
mocks.controlPort = await getFreePort();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { createServer, type AddressInfo } from "node:net";
|
||||
import { fetch as realFetch } from "undici";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { getFreePort } from "./test-port.js";
|
||||
|
||||
let testPort = 0;
|
||||
let prevGatewayPort: string | undefined;
|
||||
@@ -68,17 +68,6 @@ vi.mock("./server-context.js", async (importOriginal) => {
|
||||
const { startBrowserControlServerFromConfig, stopBrowserControlServer } =
|
||||
await import("./server.js");
|
||||
|
||||
async function getFreePort(): Promise<number> {
|
||||
const probe = createServer();
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
probe.once("error", reject);
|
||||
probe.listen(0, "127.0.0.1", () => resolve());
|
||||
});
|
||||
const addr = probe.address() as AddressInfo;
|
||||
await new Promise<void>((resolve) => probe.close(() => resolve()));
|
||||
return addr.port;
|
||||
}
|
||||
|
||||
describe("browser control evaluate gating", () => {
|
||||
beforeEach(async () => {
|
||||
testPort = await getFreePort();
|
||||
|
||||
Reference in New Issue
Block a user