

























@@ -34,7 +34,7 @@ function hermeticEnv(overrides: NodeJS.ProcessEnv = {}): NodeJS.ProcessEnv {
3434};
3535}
363637-function createCandidate(rootDir: string): PluginCandidate {
37+function createCandidate(rootDir: string, id = "demo"): PluginCandidate {
3838fs.writeFileSync(
3939path.join(rootDir, "index.ts"),
4040"throw new Error('runtime entry should not load while migrating plugin registry');\n",
@@ -43,15 +43,15 @@ function createCandidate(rootDir: string): PluginCandidate {
4343fs.writeFileSync(
4444path.join(rootDir, "openclaw.plugin.json"),
4545JSON.stringify({
46-id: "demo",
47-name: "Demo",
46+ id,
47+name: id,
4848configSchema: { type: "object" },
49-providers: ["demo"],
49+providers: [id],
5050}),
5151"utf8",
5252);
5353return {
54-idHint: "demo",
54+idHint: id,
5555source: path.join(rootDir, "index.ts"),
5656 rootDir,
5757origin: "global",
@@ -83,6 +83,45 @@ describe("plugin registry install migration", () => {
8383expect(readConfig).not.toHaveBeenCalled();
8484});
858586+it("persists only plugins enabled by the central config policy", async () => {
87+const stateDir = makeTempDir();
88+const enabledDir = path.join(stateDir, "plugins", "enabled-demo");
89+const disabledDir = path.join(stateDir, "plugins", "disabled-demo");
90+fs.mkdirSync(enabledDir, { recursive: true });
91+fs.mkdirSync(disabledDir, { recursive: true });
92+93+await expect(
94+migratePluginRegistryForInstall({
95+ stateDir,
96+candidates: [
97+createCandidate(enabledDir, "enabled-demo"),
98+createCandidate(disabledDir, "disabled-demo"),
99+],
100+readConfig: async () => ({
101+plugins: {
102+entries: {
103+"disabled-demo": {
104+enabled: false,
105+},
106+},
107+},
108+}),
109+env: hermeticEnv(),
110+}),
111+).resolves.toMatchObject({
112+status: "migrated",
113+current: {
114+plugins: [expect.objectContaining({ pluginId: "enabled-demo" })],
115+},
116+});
117+118+await expect(readPersistedInstalledPluginIndex({ stateDir })).resolves.toMatchObject({
119+plugins: [expect.objectContaining({ pluginId: "enabled-demo" })],
120+});
121+const persisted = await readPersistedInstalledPluginIndex({ stateDir });
122+expect(persisted?.plugins.map((plugin) => plugin.pluginId)).toEqual(["enabled-demo"]);
123+});
124+86125it("supports dry-run preflight without reading config or writing the registry", async () => {
87126const stateDir = makeTempDir();
88127const readConfig = vi.fn(async () => ({}));
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。