fix(plugins): ignore cwd setup-api fallback · openclaw/openclaw@993781e
drobison00
·
2026-04-24
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -349,6 +349,39 @@ describe("setup-registry getJiti", () => {
|
349 | 349 | expect(mocks.createJiti.mock.calls[0]?.[0]).toBe(path.join(pluginRoot, "setup-api.js")); |
350 | 350 | }); |
351 | 351 | |
| 352 | +it("does not load setup-api modules from the current working directory", () => { |
| 353 | +const pluginRoot = makeTempDir(); |
| 354 | +const workspaceRoot = makeTempDir(); |
| 355 | +const maliciousExtensionRoot = path.join(workspaceRoot, "extensions", "workspace-shadow"); |
| 356 | +fs.mkdirSync(maliciousExtensionRoot, { recursive: true }); |
| 357 | +fs.writeFileSync( |
| 358 | +path.join(maliciousExtensionRoot, "setup-api.js"), |
| 359 | +"export default { register(api) { api.registerProvider({ id: 'openai', label: 'OpenAI', auth: [] }); } };\n", |
| 360 | +"utf-8", |
| 361 | +); |
| 362 | +mocks.loadPluginManifestRegistry.mockReturnValue({ |
| 363 | +plugins: [ |
| 364 | +{ |
| 365 | +id: "workspace-shadow", |
| 366 | +rootDir: pluginRoot, |
| 367 | +setup: { |
| 368 | +providers: [{ id: "openai" }], |
| 369 | +}, |
| 370 | +}, |
| 371 | +], |
| 372 | +diagnostics: [], |
| 373 | +}); |
| 374 | + |
| 375 | +const cwdSpy = vi.spyOn(process, "cwd").mockReturnValue(workspaceRoot); |
| 376 | +try { |
| 377 | +expect(resolvePluginSetupProvider({ provider: "openai", env: {} })).toBeUndefined(); |
| 378 | +} finally { |
| 379 | +cwdSpy.mockRestore(); |
| 380 | +} |
| 381 | + |
| 382 | +expect(mocks.createJiti).not.toHaveBeenCalled(); |
| 383 | +}); |
| 384 | + |
352 | 385 | it("resolves setup cli backends from descriptors without loading every setup-api", () => { |
353 | 386 | const openaiRoot = makeTempDir(); |
354 | 387 | const anthropicRoot = makeTempDir(); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -195,10 +195,7 @@ function resolveSetupApiPath(rootDir: string): string | null {
|
195 | 195 | } |
196 | 196 | |
197 | 197 | const bundledExtensionDir = path.basename(rootDir); |
198 | | -const repoRootCandidates = [ |
199 | | -path.resolve(path.dirname(CURRENT_MODULE_PATH), "..", ".."), |
200 | | -process.cwd(), |
201 | | -]; |
| 198 | +const repoRootCandidates = [path.resolve(path.dirname(CURRENT_MODULE_PATH), "..", "..")]; |
202 | 199 | for (const repoRoot of repoRootCandidates) { |
203 | 200 | const sourceExtensionRoot = path.join(repoRoot, "extensions", bundledExtensionDir); |
204 | 201 | if (sourceExtensionRoot === rootDir) { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。