Skip to content

Commit 00a356e

Browse files
committed
refactor(plugins): remove unused web runtime facades
1 parent 41ff392 commit 00a356e

3 files changed

Lines changed: 76 additions & 277 deletions

File tree

‎config/assertion-safety-baseline.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3546,7 +3546,7 @@ src/plugins/runtime/runtime-llm-isolated.ts 3
35463546
src/plugins/runtime/runtime-llm.runtime.ts 4
35473547
src/plugins/runtime/runtime-plugin-boundary.ts 2
35483548
src/plugins/runtime/runtime-taskflow.ts 1
3549-
src/plugins/runtime/runtime-web-channel-plugin.ts 3
3549+
src/plugins/runtime/runtime-web-channel-plugin.ts 1
35503550
src/plugins/schema-validator.ts 6
35513551
src/plugins/sdk-alias.ts 3
35523552
src/plugins/services.ts 1
Lines changed: 75 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,113 @@
1-
// Runtime web-channel plugin tests cover web channel plugin activation and runtime behavior.
1+
// Runtime web-channel plugin tests cover the public monitor facade and plugin lifecycle.
22
import fs from "node:fs";
33
import path from "node:path";
44
import { afterEach, describe, expect, it, vi } from "vitest";
55
import { createTempDirTracker } from "../../../test/helpers/temp-dir.js";
66

77
const tempDirs = createTempDirTracker();
88

9-
afterEach(() => {
9+
afterEach(async () => {
10+
const { clearPluginMetadataLifecycleCaches } = await import("../plugin-metadata-lifecycle.js");
11+
clearPluginMetadataLifecycleCaches();
1012
tempDirs.cleanup();
1113
vi.doUnmock("./runtime-plugin-boundary.js");
1214
vi.resetModules();
1315
});
1416

1517
describe("runtime web channel plugin", () => {
16-
it("resolves the default auth dir through the light runtime on each call", async () => {
17-
let authDir = "/tmp/openclaw-default-auth";
18-
const resolveDefaultWebAuthDir = vi.fn(() => authDir);
19-
const resolvePluginRuntimeRecordByEntryBaseNames = vi.fn(() => ({
20-
origin: "bundled",
21-
source: "test",
22-
}));
23-
24-
vi.doMock("./runtime-plugin-boundary.js", () => ({
25-
loadPluginBoundaryModule: () => ({ resolveDefaultWebAuthDir }),
26-
resolvePluginRuntimeModulePath: () => "/tmp/light-runtime-api.js",
27-
resolvePluginRuntimeRecordByEntryBaseNames,
28-
}));
29-
30-
const { resolveWebChannelAuthDir } = await import("./runtime-web-channel-plugin.js");
31-
32-
expect(resolveWebChannelAuthDir()).toBe("/tmp/openclaw-default-auth");
33-
authDir = "/tmp/openclaw-profile-auth";
34-
expect(resolveWebChannelAuthDir()).toBe("/tmp/openclaw-profile-auth");
35-
expect(resolveDefaultWebAuthDir).toHaveBeenCalledTimes(2);
36-
});
37-
38-
it.each(["light", "heavy"] as const)(
39-
"reloads replaced %s runtime artifacts and dependencies after plugin lifecycle clears",
40-
async (kind) => {
41-
const pluginRoot = fs.realpathSync(tempDirs.make("openclaw-web-runtime-replacement-"));
42-
const modulePath = path.join(
43-
pluginRoot,
44-
kind === "light" ? "light-runtime-api.js" : "runtime-api.js",
45-
);
46-
const dependencyPath = path.join(pluginRoot, "dependency.js");
47-
fs.writeFileSync(path.join(pluginRoot, "package.json"), '{"type":"commonjs"}\n', "utf8");
48-
49-
const writeRuntime = (marker: string) => {
50-
fs.writeFileSync(dependencyPath, `module.exports = ${JSON.stringify(marker)};\n`, "utf8");
51-
const exportName = kind === "light" ? "resolveDefaultWebAuthDir" : "startWebLoginWithQr";
52-
fs.writeFileSync(
53-
modulePath,
54-
`module.exports = { ${exportName}: () => ${JSON.stringify(marker)} + ":" + require("./dependency.js") };\n`,
55-
"utf8",
56-
);
57-
};
58-
writeRuntime("retired");
59-
60-
vi.doMock("./runtime-plugin-boundary.js", async (importOriginal) => ({
61-
...(await importOriginal<typeof import("./runtime-plugin-boundary.js")>()),
62-
resolvePluginRuntimeRecordByEntryBaseNames: () => ({
63-
origin: "global",
64-
rootDir: pluginRoot,
65-
source: path.join(pluginRoot, "index.js"),
66-
}),
67-
resolvePluginRuntimeModulePath: () => modulePath,
68-
}));
69-
70-
const runtime = await import("./runtime-web-channel-plugin.js");
71-
const { clearPluginMetadataLifecycleCaches } =
72-
await import("../plugin-metadata-lifecycle.js");
73-
const invoke = () =>
74-
kind === "light"
75-
? Promise.resolve(runtime.resolveWebChannelAuthDir())
76-
: runtime.startWebLoginWithQr();
77-
78-
await expect(invoke()).resolves.toBe("retired:retired");
79-
writeRuntime("replacement");
80-
await expect(invoke()).resolves.toBe("retired:retired");
81-
82-
clearPluginMetadataLifecycleCaches();
83-
84-
await expect(invoke()).resolves.toBe("replacement:replacement");
85-
await expect(invoke()).resolves.toBe("replacement:replacement");
86-
},
87-
);
88-
89-
it("reports heavy runtime load failures as promise rejections", async () => {
18+
it("forwards library monitor calls lazily with exact arguments and runtime receiver", async () => {
19+
const result = { marker: "complete" };
20+
const monitorWebChannel = vi.fn(async (..._args: unknown[]) => result);
21+
const runtimeModule = { monitorWebChannel };
22+
const loadPluginBoundaryModule = vi.fn(() => runtimeModule);
9023
vi.doMock("./runtime-plugin-boundary.js", () => ({
91-
loadPluginBoundaryModule: () => {
92-
throw new Error("runtime unavailable");
93-
},
24+
loadPluginBoundaryModule,
9425
resolvePluginRuntimeModulePath: () => "/tmp/runtime-api.js",
9526
resolvePluginRuntimeRecordByEntryBaseNames: () => ({
9627
origin: "bundled",
9728
source: "test",
9829
}),
9930
}));
100-
const runtime = await import("./runtime-web-channel-plugin.js");
10131

102-
await expect(runtime.loginWeb(false)).rejects.toThrow("runtime unavailable");
103-
await expect(runtime.monitorWebChannel()).rejects.toThrow("runtime unavailable");
32+
const library = await import("../../library.js");
33+
expect(loadPluginBoundaryModule).not.toHaveBeenCalled();
34+
const args = [
35+
true,
36+
vi.fn(),
37+
false,
38+
vi.fn(),
39+
{ log: vi.fn() },
40+
new AbortController().signal,
41+
{ accountId: "work" },
42+
];
43+
await expect(library.monitorWebChannel(...args)).resolves.toBe(result);
44+
expect(monitorWebChannel).toHaveBeenCalledOnce();
45+
expect(monitorWebChannel.mock.contexts[0]).toBe(runtimeModule);
46+
const [receivedArgs] = monitorWebChannel.mock.calls;
47+
expect(receivedArgs).toHaveLength(args.length);
48+
for (const [index, arg] of args.entries()) {
49+
expect(receivedArgs?.[index]).toBe(arg);
50+
}
51+
52+
const monitorError = new Error("monitor failed");
53+
monitorWebChannel.mockRejectedValueOnce(monitorError);
54+
await expect(library.monitorWebChannel(...args)).rejects.toBe(monitorError);
10455
});
10556

106-
it("falls back to the older WhatsApp light runtime auth dir export", async () => {
107-
vi.doMock("./runtime-plugin-boundary.js", () => ({
108-
loadPluginBoundaryModule: () => ({ WA_WEB_AUTH_DIR: "/tmp/openclaw-legacy-auth" }),
109-
resolvePluginRuntimeModulePath: () => "/tmp/light-runtime-api.js",
57+
it("reloads replaced monitor artifacts and dependencies after plugin lifecycle clears", async () => {
58+
const pluginRoot = fs.realpathSync(tempDirs.make("openclaw-web-runtime-replacement-"));
59+
const modulePath = path.join(pluginRoot, "runtime-api.js");
60+
const dependencyPath = path.join(pluginRoot, "dependency.js");
61+
fs.writeFileSync(path.join(pluginRoot, "package.json"), '{"type":"commonjs"}\n', "utf8");
62+
63+
const writeRuntime = (marker: string) => {
64+
fs.writeFileSync(dependencyPath, `module.exports = ${JSON.stringify(marker)};\n`, "utf8");
65+
fs.writeFileSync(
66+
modulePath,
67+
`module.exports = { monitorWebChannel: () => ${JSON.stringify(marker)} + ":" + require("./dependency.js") };\n`,
68+
"utf8",
69+
);
70+
};
71+
writeRuntime("retired");
72+
73+
vi.doMock("./runtime-plugin-boundary.js", async (importOriginal) => ({
74+
...(await importOriginal<typeof import("./runtime-plugin-boundary.js")>()),
11075
resolvePluginRuntimeRecordByEntryBaseNames: () => ({
111-
origin: "external",
112-
source: "test",
76+
origin: "global",
77+
rootDir: pluginRoot,
78+
source: path.join(pluginRoot, "index.js"),
11379
}),
80+
resolvePluginRuntimeModulePath: () => modulePath,
11481
}));
11582

116-
const { resolveWebChannelAuthDir } = await import("./runtime-web-channel-plugin.js");
83+
const runtime = await import("./runtime-web-channel-plugin.js");
84+
const { clearPluginMetadataLifecycleCaches } = await import("../plugin-metadata-lifecycle.js");
85+
await expect(runtime.monitorWebChannel()).resolves.toBe("retired:retired");
86+
writeRuntime("replacement");
87+
await expect(runtime.monitorWebChannel()).resolves.toBe("retired:retired");
11788

118-
expect(resolveWebChannelAuthDir()).toBe("/tmp/openclaw-legacy-auth");
89+
clearPluginMetadataLifecycleCaches();
90+
91+
await expect(runtime.monitorWebChannel()).resolves.toBe("replacement:replacement");
92+
await expect(runtime.monitorWebChannel()).resolves.toBe("replacement:replacement");
11993
});
12094

121-
it("rejects non-string legacy auth dir exports", async () => {
95+
it("reports heavy runtime load failures as promise rejections", async () => {
96+
const loadError = new Error("runtime unavailable");
97+
const loadPluginBoundaryModule = vi.fn(() => {
98+
throw loadError;
99+
});
122100
vi.doMock("./runtime-plugin-boundary.js", () => ({
123-
loadPluginBoundaryModule: () => ({
124-
WA_WEB_AUTH_DIR: Object("/tmp/openclaw-string-object-auth"),
125-
}),
126-
resolvePluginRuntimeModulePath: () => "/tmp/light-runtime-api.js",
101+
loadPluginBoundaryModule,
102+
resolvePluginRuntimeModulePath: () => "/tmp/runtime-api.js",
127103
resolvePluginRuntimeRecordByEntryBaseNames: () => ({
128-
origin: "external",
104+
origin: "bundled",
129105
source: "test",
130106
}),
131107
}));
108+
const runtime = await import("./runtime-web-channel-plugin.js");
132109

133-
const { resolveWebChannelAuthDir } = await import("./runtime-web-channel-plugin.js");
134-
135-
expect(() => resolveWebChannelAuthDir()).toThrow(
136-
"web channel plugin runtime is missing export 'resolveDefaultWebAuthDir'",
137-
);
110+
expect(loadPluginBoundaryModule).not.toHaveBeenCalled();
111+
await expect(runtime.monitorWebChannel()).rejects.toBe(loadError);
138112
});
139113
});

0 commit comments

Comments
 (0)