File size: 2,082 Bytes
4440aec | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import path from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import { afterEach, describe, expect, it, vi } from "vitest";
function moduleNotFoundError(filePath: string): Error {
return Object.assign(new Error(`Cannot find module '${filePath}'`), {
code: "ERR_MODULE_NOT_FOUND",
url: pathToFileURL(filePath).href,
});
}
describe("authenticated request dispatcher load failures", () => {
afterEach(() => {
vi.doUnmock("./authenticated-request-dispatch.server-methods.runtime.js");
vi.resetModules();
vi.unstubAllEnvs();
});
it("returns typed restart guidance when the running install changed", async () => {
vi.stubEnv("OPENCLAW_PROFILE", "r13");
const missingChunk = path.join(
path.dirname(fileURLToPath(import.meta.url)),
"missing-request-dispatch-chunk.js",
);
const error = moduleNotFoundError(missingChunk);
vi.resetModules();
vi.doMock("./authenticated-request-dispatch.server-methods.runtime.js", () => ({
get handleGatewayRequest() {
throw error;
},
}));
// Imported after doMock so the harness binds a dispatcher whose lazy runtime
// load hits the mocked failing module.
const { createDispatchTestHarness, createOperatorWsClient } =
await import("./authenticated-request-dispatch.test-support.js");
const harness = createDispatchTestHarness({ connId: "stale-install-dispatch" });
const client = createOperatorWsClient({ connId: "stale-install-dispatch" });
await harness.dispatcher.dispatch(
{ type: "req", id: "stale-install", method: "status", params: {} },
client,
);
expect(await harness.awaitResponseFrame("stale-install")).toMatchObject({
id: "stale-install",
ok: false,
error: {
code: "UNAVAILABLE",
retryable: false,
message: expect.stringContaining("openclaw --profile r13 gateway restart"),
details: {
code: "STALE_INSTALL",
restartCommand: "openclaw --profile r13 gateway restart",
},
},
});
});
});
|