Skip to content

Commit 4af47ff

Browse files
committed
fix(plugins): clean exact install load paths on uninstall
1 parent 5d30ff9 commit 4af47ff

8 files changed

Lines changed: 271 additions & 11 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Docs: https://docs.openclaw.ai
66

77
### Changes
88

9+
- **Plugin uninstall cleanup:** remove exact recorded install paths from `plugins.load.paths` for marketplace, npm, and other managed installs while preserving parent, child, prefix, and unrelated paths.
910
- Fixed Crabbox hydration on unprivileged cloud sandboxes by falling back to a user-writable pnpm store when the shared `/var/cache/crabbox` cache is unavailable, preserving the hardlink import mode after hydration, and making Docker an explicit routed capability instead of an implicit install requirement.
1011

1112
- **Browser extension relay CDP compat:** answer `Target.getBrowserContexts` so Puppeteer-based clients (chrome-devtools-mcp) can drive the paired Chrome without the remote-debugging permission prompt, serve DevTools-style `/json/list` target descriptors, and add `openclaw browser extension cdp` to print the relay endpoint plus auth header for external CDP clients.

‎docs/cli/plugins.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ openclaw plugins uninstall <id> --keep-files
420420
openclaw plugins uninstall <id> --force
421421
```
422422

423-
`uninstall` removes plugin records from `plugins.entries`, the persisted plugin index, plugin allow/deny list entries, and linked `plugins.load.paths` entries when applicable. Unless `--keep-files` is set, uninstall also removes the tracked managed install directory, but only when it resolves inside OpenClaw's plugin extensions root. If the plugin currently owns the `memory` or `contextEngine` slot, that slot resets to its default (`memory-core` for memory, `legacy` for context engine).
423+
`uninstall` removes plugin records from `plugins.entries`, the persisted plugin index, plugin allow/deny list entries, and any `plugins.load.paths` entry that exactly resolves to the recorded install path. Linked path installs also remove an exact entry for their recorded source path. Parent directories, child paths, prefix matches, and unrelated load paths are preserved. Unless `--keep-files` is set, uninstall also removes the tracked managed install directory, but only when it resolves inside OpenClaw's plugin extensions root. If the plugin currently owns the `memory` or `contextEngine` slot, that slot resets to its default (`memory-core` for memory, `legacy` for context engine).
424424

425425
`uninstall` prints a preview of what will be removed, then prompts `Uninstall plugin "<id>"?` before making changes. Pass `--force` to skip the confirmation prompt (useful for scripts and non-interactive runs); without it, uninstall requires an interactive TTY. `--dry-run` prints the same preview and exits without prompting or changing anything.
426426

‎qa/scenarios/plugins/clawhub-marketplace-list.yaml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ scenario:
88
primary:
99
- clawhub.marketplace-list
1010
- clawhub.update-by-plugin-id
11-
secondary:
1211
- clawhub.uninstall-config-index-policy-file-cleanup
1312
objective: Verify package-installed marketplace listing, install, update, and uninstall behavior through the release plugin marketplace lane.
1413
successCriteria:
1514
- A fixture marketplace is written into the package-installed home.
1615
- The package-installed CLI lists the fixture marketplace as JSON and includes the expected plugin.
1716
- The marketplace plugin installs into the managed directory with canonical marketplace metadata and a SQLite install/index record.
1817
- A plugin-ID dry run reports 0.0.1 to 0.0.2 without mutating the record or CLI, then the real update persists 0.0.2 and exposes the v2 CLI output.
19-
- Uninstall removes the plugin CLI and install metadata.
18+
- Uninstall removes the config entry, SQLite install/index metadata, allow/deny policy entries, exact managed load path, managed directory, and plugin CLI while preserving unrelated policy and load-path sentinels.
2019
docsRefs:
2120
- docs/help/testing.md
2221
- docs/concepts/qa-e2e-automation.md

‎scripts/e2e/lib/release-plugin-marketplace/lifecycle-assertions.mjs‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ function resolveRecordedPath(value) {
3030
return path.resolve(value);
3131
}
3232

33+
function resolveComparablePath(value) {
34+
const resolved = resolveRecordedPath(value);
35+
try {
36+
return fs.realpathSync(resolved);
37+
} catch {
38+
return resolved;
39+
}
40+
}
41+
3342
function assertPathInside(parent, child, label) {
3443
const relative = path.relative(fs.realpathSync(parent), fs.realpathSync(child));
3544
assert(
@@ -38,6 +47,14 @@ function assertPathInside(parent, child, label) {
3847
);
3948
}
4049

50+
function samePath(left, right) {
51+
return resolveComparablePath(left) === resolveComparablePath(right);
52+
}
53+
54+
function appendUnique(values, additions) {
55+
return [...new Set([...(values ?? []), ...additions])];
56+
}
57+
4158
function assertMarketplaceState() {
4259
const pluginId = process.argv[3];
4360
const expectedVersion = process.argv[4];
@@ -106,6 +123,83 @@ function assertMarketplaceState() {
106123
}
107124
}
108125

126+
function seedMarketplaceUninstallState() {
127+
const pluginId = process.argv[3];
128+
const sentinelPluginId = process.argv[4];
129+
const sentinelPath = process.argv[5];
130+
const installPathFile = process.argv[6];
131+
assert(pluginId, "missing plugin id");
132+
assert(sentinelPluginId, "missing sentinel plugin id");
133+
assert(sentinelPath, "missing sentinel path");
134+
assert(installPathFile, "missing install path file");
135+
136+
const index = readPluginInstallIndex({ stateDir: stateDir(), configPath: configPath() });
137+
const installPath = index.installRecords?.[pluginId]?.installPath;
138+
assert(installPath, `install path missing for ${pluginId}`);
139+
assert(
140+
fs.existsSync(installPath),
141+
`managed install path missing before uninstall: ${installPath}`,
142+
);
143+
assert(fs.existsSync(sentinelPath), `sentinel path missing before uninstall: ${sentinelPath}`);
144+
145+
const config = readJson(configPath());
146+
const plugins = config.plugins ?? {};
147+
config.plugins = {
148+
...plugins,
149+
allow: appendUnique(plugins.allow, [pluginId, sentinelPluginId]),
150+
deny: appendUnique(plugins.deny, [pluginId, sentinelPluginId]),
151+
load: {
152+
...plugins.load,
153+
paths: appendUnique(plugins.load?.paths, [installPath, sentinelPath]),
154+
},
155+
};
156+
fs.writeFileSync(configPath(), `${JSON.stringify(config, null, 2)}\n`, "utf8");
157+
fs.writeFileSync(installPathFile, `${installPath}\n`, "utf8");
158+
}
159+
160+
function assertMarketplaceUninstalled() {
161+
const pluginId = process.argv[3];
162+
const sentinelPluginId = process.argv[4];
163+
const sentinelPath = process.argv[5];
164+
const installPathFile = process.argv[6];
165+
assert(pluginId, "missing plugin id");
166+
assert(sentinelPluginId, "missing sentinel plugin id");
167+
assert(sentinelPath, "missing sentinel path");
168+
assert(installPathFile, "missing install path file");
169+
170+
const installPath = fs.readFileSync(installPathFile, "utf8").trim();
171+
const index = readPluginInstallIndex({ stateDir: stateDir(), configPath: configPath() });
172+
const config = readJson(configPath());
173+
const loadPaths = config.plugins?.load?.paths ?? [];
174+
175+
assert(!index.installRecords?.[pluginId], `install record still present for ${pluginId}`);
176+
assert(
177+
!(index.plugins ?? []).some((entry) => entry.pluginId === pluginId),
178+
`installed plugin index still includes ${pluginId}`,
179+
);
180+
assert(!config.plugins?.entries?.[pluginId], `plugin config entry still present for ${pluginId}`);
181+
assert(!config.plugins?.allow?.includes(pluginId), `allowlist still includes ${pluginId}`);
182+
assert(!config.plugins?.deny?.includes(pluginId), `denylist still includes ${pluginId}`);
183+
assert(
184+
config.plugins?.allow?.includes(sentinelPluginId),
185+
`allowlist lost sentinel ${sentinelPluginId}`,
186+
);
187+
assert(
188+
config.plugins?.deny?.includes(sentinelPluginId),
189+
`denylist lost sentinel ${sentinelPluginId}`,
190+
);
191+
assert(
192+
!loadPaths.some((candidate) => samePath(candidate, installPath)),
193+
`load paths still include managed install path ${installPath}`,
194+
);
195+
assert(
196+
loadPaths.some((candidate) => samePath(candidate, sentinelPath)),
197+
`load paths lost sentinel path ${sentinelPath}`,
198+
);
199+
assert(!fs.existsSync(installPath), `managed install path still exists: ${installPath}`);
200+
assert(fs.existsSync(sentinelPath), `sentinel path was removed: ${sentinelPath}`);
201+
}
202+
109203
function assertUpdateLog() {
110204
const logPath = process.argv[3];
111205
const expected = process.argv[4];
@@ -117,6 +211,8 @@ function assertUpdateLog() {
117211

118212
const commands = {
119213
"assert-marketplace-state": assertMarketplaceState,
214+
"seed-marketplace-uninstall-state": seedMarketplaceUninstallState,
215+
"assert-marketplace-uninstalled": assertMarketplaceUninstalled,
120216
"assert-update-log": assertUpdateLog,
121217
};
122218

‎scripts/e2e/lib/release-plugin-marketplace/scenario.sh‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,29 @@ node "$marketplace_assertions" \
126126
openclaw release-market ping >/tmp/openclaw-release-plugin-marketplace-cli-v2.log 2>&1
127127
node scripts/e2e/lib/release-scenarios/assertions.mjs assert-file-contains /tmp/openclaw-release-plugin-marketplace-cli-v2.log "release-marketplace-plugin:v2"
128128

129+
sentinel_plugin_id="release-marketplace-other"
130+
sentinel_path="$marketplace_root/plugins/$sentinel_plugin_id"
131+
node "$marketplace_assertions" \
132+
seed-marketplace-uninstall-state \
133+
release-marketplace-plugin \
134+
"$sentinel_plugin_id" \
135+
"$sentinel_path" \
136+
"$install_path_file"
129137
openclaw plugins uninstall release-marketplace-plugin --force >/tmp/openclaw-release-plugin-marketplace-uninstall.log 2>&1
138+
node "$marketplace_assertions" \
139+
assert-update-log \
140+
/tmp/openclaw-release-plugin-marketplace-uninstall.log \
141+
"Removed: config entry, install record, allowlist entry, denylist entry, load path, directory."
130142
if openclaw release-market ping >/tmp/openclaw-release-plugin-marketplace-cli-after-uninstall.log 2>&1; then
131143
echo "release-market CLI should be gone after uninstall" >&2
132144
exit 1
133145
fi
146+
node "$marketplace_assertions" \
147+
assert-marketplace-uninstalled \
148+
release-marketplace-plugin \
149+
"$sentinel_plugin_id" \
150+
"$sentinel_path" \
151+
"$install_path_file"
134152
node scripts/e2e/lib/release-scenarios/assertions.mjs assert-plugin-uninstalled release-marketplace-plugin release-market
135153

136154
echo "Release plugin marketplace scenario passed."

‎src/plugins/uninstall.test.ts‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,15 @@ function createGitInstallRecord(pluginId = "my-plugin", installPath?: string): P
148148
};
149149
}
150150

151+
function createMarketplaceInstallRecord(installPath: string): PluginInstallRecord {
152+
return {
153+
source: "marketplace",
154+
installPath,
155+
marketplaceSource: "release-fixtures",
156+
marketplacePlugin: "my-plugin",
157+
};
158+
}
159+
151160
function createPathInstallRecord(
152161
installPath = "/path/to/plugin",
153162
sourcePath = installPath,
@@ -384,6 +393,76 @@ describe("removePluginFromConfig", () => {
384393
expect(actions.loadPath).toBe(true);
385394
});
386395

396+
it.each([
397+
{
398+
name: "marketplace install path",
399+
installRecord: createMarketplaceInstallRecord("/managed/my-plugin"),
400+
loadPaths: ["/managed/my-plugin", "/managed/my-plugin/child", "/other/path"],
401+
expectedPaths: ["/managed/my-plugin/child", "/other/path"],
402+
expectedChanged: true,
403+
},
404+
{
405+
name: "npm install path",
406+
installRecord: createNpmInstallRecord("my-plugin", "/managed/my-plugin"),
407+
loadPaths: ["/managed/my-plugin", "/managed/my-plugin/child", "/other/path"],
408+
expectedPaths: ["/managed/my-plugin/child", "/other/path"],
409+
expectedChanged: true,
410+
},
411+
{
412+
name: "absent load paths",
413+
installRecord: createMarketplaceInstallRecord("/managed/my-plugin"),
414+
loadPaths: undefined,
415+
expectedPaths: undefined,
416+
expectedChanged: false,
417+
},
418+
{
419+
name: "mismatched and child paths",
420+
installRecord: createNpmInstallRecord("my-plugin", "/managed/my-plugin"),
421+
loadPaths: ["/managed/my-plugin-other", "/managed/my-plugin/child"],
422+
expectedPaths: ["/managed/my-plugin-other", "/managed/my-plugin/child"],
423+
expectedChanged: false,
424+
},
425+
])(
426+
"cleans only the exact $name from load.paths",
427+
({ installRecord, loadPaths, expectedPaths, expectedChanged }) => {
428+
const config = createPluginConfig({
429+
installs: { "my-plugin": installRecord },
430+
loadPaths,
431+
});
432+
433+
const { config: result, actions } = removePluginFromConfig(config, "my-plugin");
434+
435+
expect(result.plugins?.load?.paths).toEqual(expectedPaths);
436+
expect(actions.loadPath).toBe(expectedChanged);
437+
},
438+
);
439+
440+
it("removes a canonical marketplace install path without removing siblings", async () => {
441+
const tempRoot = path.join(process.cwd(), ".tmp");
442+
await fs.mkdir(tempRoot, { recursive: true });
443+
const tempDir = await fs.mkdtemp(path.join(tempRoot, "openclaw-uninstall-marketplace-path-"));
444+
try {
445+
const installPath = path.join(tempDir, "managed", "my-plugin");
446+
const linkedPath = path.join(tempDir, "my-plugin-link");
447+
const siblingPath = path.join(tempDir, "managed", "my-plugin-other");
448+
await fs.mkdir(installPath, { recursive: true });
449+
await fs.symlink(installPath, linkedPath, "dir");
450+
const config = createPluginConfig({
451+
installs: {
452+
"my-plugin": createMarketplaceInstallRecord(installPath),
453+
},
454+
loadPaths: [linkedPath, siblingPath],
455+
});
456+
457+
const { config: result, actions } = removePluginFromConfig(config, "my-plugin");
458+
459+
expect(result.plugins?.load?.paths).toEqual([siblingPath]);
460+
expect(actions.loadPath).toBe(true);
461+
} finally {
462+
await fs.rm(tempDir, { recursive: true, force: true });
463+
}
464+
});
465+
387466
it("removes absolute load path for a workspace-relative install source path", async () => {
388467
const tempRoot = path.join(process.cwd(), ".tmp");
389468
await fs.mkdir(tempRoot, { recursive: true });

‎src/plugins/uninstall.ts‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,11 @@ export function resolveUninstallChannelConfigKeys(
361361
return keys;
362362
}
363363

364-
function loadPathMatchesInstallSourcePath(loadPath: string, sourcePath: string): boolean {
365-
if (loadPath === sourcePath) {
364+
function loadPathMatchesInstallPath(loadPath: string, installPath: string): boolean {
365+
if (loadPath === installPath) {
366366
return true;
367367
}
368-
return resolveComparablePath(loadPath) === resolveComparablePath(sourcePath);
368+
return resolveComparablePath(loadPath) === resolveComparablePath(installPath);
369369
}
370370

371371
function resolveComparablePath(value: string): string {
@@ -435,17 +435,23 @@ export function removePluginFromConfig(
435435
actions.denylist = true;
436436
}
437437

438-
// Remove linked path from load.paths (for source === "path" plugins)
438+
// Remove exact tracked install paths without consuming parent, child, or prefix matches.
439439
let load = pluginsConfig.load;
440-
if (installRecord?.source === "path" && installRecord.sourcePath) {
441-
const sourcePath = installRecord.sourcePath;
440+
const trackedInstallPaths = [
441+
installRecord?.installPath,
442+
installRecord?.source === "path" ? installRecord.sourcePath : undefined,
443+
].filter((value): value is string => Boolean(value));
444+
if (trackedInstallPaths.length > 0) {
442445
const loadPaths = load?.paths;
443446
if (
444447
Array.isArray(loadPaths) &&
445-
loadPaths.some((p) => loadPathMatchesInstallSourcePath(p, sourcePath))
448+
loadPaths.some((p) =>
449+
trackedInstallPaths.some((installPath) => loadPathMatchesInstallPath(p, installPath)),
450+
)
446451
) {
447452
const nextLoadPaths = loadPaths.filter(
448-
(p) => !loadPathMatchesInstallSourcePath(p, sourcePath),
453+
(p) =>
454+
!trackedInstallPaths.some((installPath) => loadPathMatchesInstallPath(p, installPath)),
449455
);
450456
load = nextLoadPaths.length > 0 ? { ...load, paths: nextLoadPaths } : undefined;
451457
actions.loadPath = true;

‎test/scripts/release-plugin-marketplace-lifecycle.test.ts‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,24 @@ function writeMarketplaceState(home: string, version: string) {
114114
return { installPath, pluginId };
115115
}
116116

117+
function clearMarketplaceIndex(home: string) {
118+
const databasePath = path.join(home, ".openclaw", "state", "openclaw.sqlite");
119+
const db = new DatabaseSync(databasePath);
120+
try {
121+
db.prepare(
122+
`
123+
UPDATE installed_plugin_index
124+
SET install_records_json = ?,
125+
plugins_json = ?,
126+
updated_at_ms = ?
127+
WHERE index_key = ?
128+
`,
129+
).run("{}", "[]", Date.now(), "installed-plugin-index");
130+
} finally {
131+
db.close();
132+
}
133+
}
134+
117135
describe("release plugin marketplace lifecycle assertions", () => {
118136
it("checks canonical marketplace metadata and stable managed install paths", () => {
119137
const home = makeTempDir(tempDirs, "openclaw-marketplace-lifecycle-");
@@ -162,6 +180,49 @@ describe("release plugin marketplace lifecycle assertions", () => {
162180
expect(result.stderr).toContain("expected install record version 0.0.2, got 0.0.1");
163181
});
164182

183+
it("seeds uninstall state and verifies complete cleanup with sentinels preserved", () => {
184+
const home = makeTempDir(tempDirs, "openclaw-marketplace-lifecycle-");
185+
const { installPath, pluginId } = writeMarketplaceState(home, "0.0.2");
186+
const sentinelPluginId = "release-marketplace-other";
187+
const sentinelPath = path.join(home, "marketplace", sentinelPluginId);
188+
const installPathFile = path.join(home, "install-path.txt");
189+
fs.mkdirSync(sentinelPath, { recursive: true });
190+
191+
const seeded = runHelper(home, [
192+
"seed-marketplace-uninstall-state",
193+
pluginId,
194+
sentinelPluginId,
195+
sentinelPath,
196+
installPathFile,
197+
]);
198+
expect(seeded.stderr).toBe("");
199+
expect(seeded.status).toBe(0);
200+
201+
const configPath = path.join(home, ".openclaw", "openclaw.json");
202+
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
203+
expect(config.plugins.allow).toEqual([pluginId, sentinelPluginId]);
204+
expect(config.plugins.deny).toEqual([pluginId, sentinelPluginId]);
205+
expect(config.plugins.load.paths).toEqual([installPath, sentinelPath]);
206+
207+
delete config.plugins.entries[pluginId];
208+
config.plugins.allow = [sentinelPluginId];
209+
config.plugins.deny = [sentinelPluginId];
210+
config.plugins.load.paths = [sentinelPath];
211+
fs.writeFileSync(configPath, `${JSON.stringify(config)}\n`, "utf8");
212+
fs.rmSync(installPath, { recursive: true });
213+
clearMarketplaceIndex(home);
214+
215+
const verified = runHelper(home, [
216+
"assert-marketplace-uninstalled",
217+
pluginId,
218+
sentinelPluginId,
219+
sentinelPath,
220+
installPathFile,
221+
]);
222+
expect(verified.stderr).toBe("");
223+
expect(verified.status).toBe(0);
224+
});
225+
165226
it("checks the exact dry-run and update outcome text", () => {
166227
const home = makeTempDir(tempDirs, "openclaw-marketplace-lifecycle-");
167228
const logPath = path.join(home, "update.log");

0 commit comments

Comments
 (0)