mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-16 23:10:43 +00:00
fix: narrow Gateway proxy bypass target (#77018)
* fix: narrow Gateway proxy bypass target * fix: narrow Gateway proxy bypass target * fix(clawsweeper): address review for automerge-openclaw-openclaw-77018 (1) * fix(clawsweeper): address review for automerge-openclaw-openclaw-77018 (2) * fix(clawsweeper): address review for automerge-openclaw-openclaw-77018 (validation-3) * fix(clawsweeper): address review for automerge-openclaw-openclaw-77018 (4-final) * fix: narrow Gateway proxy bypass target * fix(clawsweeper): address review for automerge-openclaw-openclaw-77018 (1) * fix(clawsweeper): address review for automerge-openclaw-openclaw-77018 (2) * fix(clawsweeper): reconcile automerge-openclaw-openclaw-77018 with main (1) --------- Co-authored-by: clawsweeper <274271284+clawsweeper[bot]@users.noreply.github.com>
This commit is contained in:
87
src/node-host/runner.test.ts
Normal file
87
src/node-host/runner.test.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { GatewayClientOptions } from "../gateway/client.js";
|
||||
import { runNodeHost } from "./runner.js";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
capturedGatewayClientOptions: [] as GatewayClientOptions[],
|
||||
ensureNodeHostConfig: vi.fn(async () => ({
|
||||
version: 1,
|
||||
nodeId: "node-test",
|
||||
})),
|
||||
saveNodeHostConfig: vi.fn(async () => undefined),
|
||||
getRuntimeConfig: vi.fn(() => ({
|
||||
gateway: {
|
||||
handshakeTimeoutMs: 1_000,
|
||||
},
|
||||
})),
|
||||
startGatewayClientWhenEventLoopReady: vi.fn(async () => ({
|
||||
ready: false,
|
||||
aborted: false,
|
||||
elapsedMs: 0,
|
||||
})),
|
||||
}));
|
||||
|
||||
vi.mock("../config/config.js", () => ({
|
||||
getRuntimeConfig: mocks.getRuntimeConfig,
|
||||
}));
|
||||
|
||||
vi.mock("../gateway/client-start-readiness.js", () => ({
|
||||
startGatewayClientWhenEventLoopReady: mocks.startGatewayClientWhenEventLoopReady,
|
||||
}));
|
||||
|
||||
vi.mock("../gateway/client.js", () => ({
|
||||
GatewayClient: function GatewayClient(opts: GatewayClientOptions) {
|
||||
mocks.capturedGatewayClientOptions.push(opts);
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("../gateway/connection-auth.js", () => ({
|
||||
resolveGatewayConnectionAuth: vi.fn(async () => ({})),
|
||||
}));
|
||||
|
||||
vi.mock("../infra/device-identity.js", () => ({
|
||||
loadOrCreateDeviceIdentity: vi.fn(() => ({
|
||||
id: "device-test",
|
||||
publicKey: "public-key-test",
|
||||
privateKey: "private-key-test",
|
||||
})),
|
||||
}));
|
||||
|
||||
vi.mock("../infra/machine-name.js", () => ({
|
||||
getMachineDisplayName: vi.fn(async () => "test-node"),
|
||||
}));
|
||||
|
||||
vi.mock("../infra/path-env.js", () => ({
|
||||
ensureOpenClawCliOnPath: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("./config.js", () => ({
|
||||
ensureNodeHostConfig: mocks.ensureNodeHostConfig,
|
||||
saveNodeHostConfig: mocks.saveNodeHostConfig,
|
||||
}));
|
||||
|
||||
vi.mock("./plugin-node-host.js", () => ({
|
||||
ensureNodeHostPluginRegistry: vi.fn(async () => undefined),
|
||||
listRegisteredNodeHostCapsAndCommands: vi.fn(() => ({
|
||||
caps: [],
|
||||
commands: [],
|
||||
})),
|
||||
}));
|
||||
|
||||
describe("runNodeHost", () => {
|
||||
it("passes the resolved Gateway URL to the Gateway client", async () => {
|
||||
await expect(
|
||||
runNodeHost({
|
||||
gatewayHost: "127.0.0.1",
|
||||
gatewayPort: 18789,
|
||||
}),
|
||||
).rejects.toThrow("event loop readiness timeout");
|
||||
|
||||
expect(mocks.capturedGatewayClientOptions).toHaveLength(1);
|
||||
expect(mocks.capturedGatewayClientOptions[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
url: "ws://127.0.0.1:18789",
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user