Skip to content

Commit 8432918

Browse files
committed
test(plugins): keep rpc source walk on source call gateway
1 parent 01e7f64 commit 8432918

2 files changed

Lines changed: 27 additions & 16 deletions

File tree

scripts/e2e/kitchen-sink-rpc-walk.mjs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ function unwrapRpcPayload(raw) {
227227
}
228228

229229
async function rpcCall(method, params, options) {
230-
const { callGateway } = await loadCallGatewayModule();
230+
const { callGateway } = await loadCallGatewayModule(options.runner);
231231
const payload = await callGateway({
232232
config: readJson(options.env.OPENCLAW_CONFIG_PATH),
233233
configPath: options.env.OPENCLAW_CONFIG_PATH,
@@ -241,27 +241,35 @@ async function rpcCall(method, params, options) {
241241
return unwrapRpcPayload(payload);
242242
}
243243

244-
async function loadCallGatewayModule() {
245-
callGatewayModulePromise ??= importCallGatewayModule();
244+
async function loadCallGatewayModule(runner) {
245+
callGatewayModulePromise ??= importCallGatewayModule(runner);
246246
return callGatewayModulePromise;
247247
}
248248

249-
async function importCallGatewayModule() {
249+
async function importCallGatewayModule(runner) {
250+
if (!usesPackagedOpenClawEntry(runner)) {
251+
return import(pathToFileURL(path.join(process.cwd(), "src/gateway/call.ts")).href);
252+
}
250253
const distDir = path.join(process.cwd(), "dist");
251-
if (fs.existsSync(distDir)) {
252-
const candidates = fs
253-
.readdirSync(distDir)
254-
.filter((name) => /^call(?:\.runtime)?-[A-Za-z0-9_-]+\.js$/u.test(name))
255-
.toSorted((left, right) => left.localeCompare(right));
256-
for (const name of candidates) {
257-
const module = await import(pathToFileURL(path.join(distDir, name)).href);
258-
if (typeof module.callGateway === "function") {
259-
return module;
260-
}
254+
const candidates = fs.existsSync(distDir)
255+
? fs
256+
.readdirSync(distDir)
257+
.filter((name) => /^call(?:\.runtime)?-[A-Za-z0-9_-]+\.js$/u.test(name))
258+
.toSorted((left, right) => left.localeCompare(right))
259+
: [];
260+
for (const name of candidates) {
261+
const module = await import(pathToFileURL(path.join(distDir, name)).href);
262+
if (typeof module.callGateway === "function") {
263+
return module;
261264
}
262-
throw new Error(`unable to find callGateway export in dist (${candidates.join(", ")})`);
263265
}
264-
return import(pathToFileURL(path.join(process.cwd(), "src/gateway/call.ts")).href);
266+
throw new Error(`unable to find callGateway export in dist (${candidates.join(", ")})`);
267+
}
268+
269+
function usesPackagedOpenClawEntry(runner) {
270+
return Boolean(
271+
process.env.OPENCLAW_ENTRY && runner?.baseArgs?.[0] === process.env.OPENCLAW_ENTRY,
272+
);
265273
}
266274

267275
async function retryRpcCall(method, params, options) {

test/scripts/plugin-prerelease-test-plan.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ describe("scripts/lib/plugin-prerelease-test-plan.mjs", () => {
188188
expect(walkScript).toContain("tools.invoke");
189189
expect(walkScript).toContain("tts.providers");
190190
expect(walkScript).toContain("plugins.uiDescriptors");
191+
expect(walkScript).toContain("loadCallGatewayModule(options.runner)");
192+
expect(walkScript).toContain("usesPackagedOpenClawEntry(runner)");
193+
expect(walkScript).toContain("src/gateway/call.ts");
191194
expect(walkScript).toContain("^call(?:\\.runtime)?");
192195
});
193196

0 commit comments

Comments
 (0)