mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 20:10:42 +00:00
fix(plugins): ignore cwd setup-api fallback
This commit is contained in:
committed by
Peter Steinberger
parent
15ff8619d1
commit
993781e6e6
@@ -349,6 +349,39 @@ describe("setup-registry getJiti", () => {
|
||||
expect(mocks.createJiti.mock.calls[0]?.[0]).toBe(path.join(pluginRoot, "setup-api.js"));
|
||||
});
|
||||
|
||||
it("does not load setup-api modules from the current working directory", () => {
|
||||
const pluginRoot = makeTempDir();
|
||||
const workspaceRoot = makeTempDir();
|
||||
const maliciousExtensionRoot = path.join(workspaceRoot, "extensions", "workspace-shadow");
|
||||
fs.mkdirSync(maliciousExtensionRoot, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(maliciousExtensionRoot, "setup-api.js"),
|
||||
"export default { register(api) { api.registerProvider({ id: 'openai', label: 'OpenAI', auth: [] }); } };\n",
|
||||
"utf-8",
|
||||
);
|
||||
mocks.loadPluginManifestRegistry.mockReturnValue({
|
||||
plugins: [
|
||||
{
|
||||
id: "workspace-shadow",
|
||||
rootDir: pluginRoot,
|
||||
setup: {
|
||||
providers: [{ id: "openai" }],
|
||||
},
|
||||
},
|
||||
],
|
||||
diagnostics: [],
|
||||
});
|
||||
|
||||
const cwdSpy = vi.spyOn(process, "cwd").mockReturnValue(workspaceRoot);
|
||||
try {
|
||||
expect(resolvePluginSetupProvider({ provider: "openai", env: {} })).toBeUndefined();
|
||||
} finally {
|
||||
cwdSpy.mockRestore();
|
||||
}
|
||||
|
||||
expect(mocks.createJiti).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("resolves setup cli backends from descriptors without loading every setup-api", () => {
|
||||
const openaiRoot = makeTempDir();
|
||||
const anthropicRoot = makeTempDir();
|
||||
|
||||
Reference in New Issue
Block a user