




















@@ -25,6 +25,8 @@ type GatewayLoopStart = (params?: { startupStartedAt?: number }) => Promise<unkn
2525const runGatewayLoop = vi.fn(async ({ start }: { start: GatewayLoopStart }) => {
2626await start();
2727});
28+const normalizeStateDirEnv = vi.fn((_env?: NodeJS.ProcessEnv) => undefined);
29+const callOrder = vi.hoisted(() => [] as string[]);
2830const gatewayLogMessages = vi.hoisted(() => [] as string[]);
2931const configState = vi.hoisted(() => ({
3032cfg: {} as Record<string, unknown>,
@@ -65,6 +67,7 @@ vi.mock("../../config/config.js", () => ({
65676668vi.mock("../../config/paths.js", () => ({
6769CONFIG_PATH: "/tmp/openclaw-test-missing-config.json",
70+normalizeStateDirEnv: (env?: NodeJS.ProcessEnv) => normalizeStateDirEnv(env),
6871resolveStateDir: () => "/tmp",
6972resolveGatewayPort: (cfg?: { gateway?: { port?: number } }) => cfg?.gateway?.port ?? 18789,
7073}));
@@ -236,6 +239,8 @@ describe("gateway run option collisions", () => {
236239waitForPortBindable.mockClear();
237240ensureDevGatewayConfig.mockClear();
238241runGatewayLoop.mockClear();
242+normalizeStateDirEnv.mockReset();
243+callOrder.length = 0;
239244});
240245241246async function runGatewayCli(argv: string[]) {
@@ -265,6 +270,14 @@ describe("gateway run option collisions", () => {
265270}
266271267272it("forwards parent-captured options to `gateway run` subcommand", async () => {
273+normalizeStateDirEnv.mockImplementation((_env?: NodeJS.ProcessEnv) => {
274+callOrder.push("normalize");
275+});
276+startGatewayServer.mockImplementationOnce(async (_port: number, _opts?: unknown) => {
277+callOrder.push("start");
278+return { close: vi.fn(async () => {}) };
279+});
280+268281await runGatewayCli([
269282"gateway",
270283"run",
@@ -283,6 +296,8 @@ describe("gateway run option collisions", () => {
283296).toEqual({ intervalMs: 150, timeoutMs: 3000 });
284297expect(setGatewayWsLogStyle).toHaveBeenCalledWith("full");
285298expect(gatewayStartOptions().auth?.token).toBe("tok_run");
299+expect(normalizeStateDirEnv).toHaveBeenCalledWith(process.env);
300+expect(callOrder).toEqual(["normalize", "start"]);
286301});
287302288303it("marks service-mode gateway descendants with the live gateway pid", async () => {
@@ -297,6 +312,7 @@ describe("gateway run option collisions", () => {
297312expect(process.env[GATEWAY_SERVICE_RUNTIME_PID_ENV]).toBe(String(process.pid));
298313},
299314);
315+expect(normalizeStateDirEnv).toHaveBeenCalledWith(process.env);
300316});
301317302318it("blocks --force port cleanup from an older binary with newer config", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。