fix(test): require lifecycle uninstall config proof

This commit is contained in:
Vincent Koc
2026-06-06 23:46:46 +02:00
parent a78234a5d3
commit 39e27c8276
2 changed files with 18 additions and 2 deletions

View File

@@ -39,6 +39,10 @@ function config() {
return readJson(process.env.OPENCLAW_CONFIG_PATH ?? openclawPath("openclaw.json"));
}
function requiredConfig() {
return readRequiredJson(process.env.OPENCLAW_CONFIG_PATH ?? openclawPath("openclaw.json"));
}
function assert(condition, message) {
if (!condition) {
throw new Error(message);
@@ -117,7 +121,7 @@ function printInstallPath(pluginId) {
}
function assertUninstalled(pluginId) {
const cfg = config();
const cfg = requiredConfig();
const record = recordFor(pluginId);
assert(!record, `install record still present for ${pluginId}`);
assert(!cfg.plugins?.entries?.[pluginId], `plugin config entry still present for ${pluginId}`);

View File

@@ -1,6 +1,6 @@
// Plugin Lifecycle Probe tests cover plugin lifecycle probe script behavior.
import { spawnSync } from "node:child_process";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
@@ -72,4 +72,16 @@ describe("plugin lifecycle matrix probe", () => {
expect(result.status).not.toBe(0);
expect(result.stderr).toContain(`failed to read JSON from ${inspectPath}`);
});
it("rejects unreadable config during uninstall proof", () => {
const dir = makeTempDir();
const configPath = path.join(dir, ".openclaw", "openclaw.json");
mkdirSync(path.dirname(configPath), { recursive: true });
writeFileSync(configPath, "{ malformed\n", "utf8");
const result = runProbe(["assert-uninstalled", "lifecycle-claw"], dir);
expect(result.status).not.toBe(0);
expect(result.stderr).toContain(`failed to read JSON from ${configPath}`);
});
});