mirror of https://github.com/openclaw/openclaw.git
fix(plugins): address review feedback for Matrix recovery paths (#52899)
1. Narrow loadConfigForInstall() to catch only INVALID_CONFIG errors, letting real failures (fs permission, OOM) propagate. 2. Assert allow array is properly cleaned in stale-cleanup test. 3. Add comment clarifying version-resolution is already addressed via the shared VERSION constant. 4. Run cleanStaleMatrixPluginConfig() during install so persistPluginInstall() → writeConfigFile() does not fail validation on stale Matrix load paths.
This commit is contained in:
parent
3ae100a8d7
commit
489797ceaf
|
|
@ -1,4 +1,5 @@
|
|||
import fs from "node:fs";
|
||||
import { cleanStaleMatrixPluginConfig } from "../commands/doctor/providers/matrix.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { loadConfig, readBestEffortConfig } from "../config/config.js";
|
||||
import { installHooksFromNpmSpec, installHooksFromPath } from "../hooks/install.js";
|
||||
|
|
@ -170,12 +171,28 @@ async function tryInstallHookPackFromNpmSpec(params: {
|
|||
// loadConfig() throws when config is invalid; fall back to best-effort so
|
||||
// repair-oriented installs (e.g. reinstalling a broken Matrix plugin) can
|
||||
// still proceed from a partially valid config snapshot.
|
||||
// Only catch config-validation errors — real failures (fs permission, OOM)
|
||||
// must surface so the user sees the actual problem.
|
||||
// After loading, clean any stale Matrix plugin references so that
|
||||
// persistPluginInstall() → writeConfigFile() does not fail validation
|
||||
// on paths that no longer exist (#52899 concern 4).
|
||||
async function loadConfigForInstall(): Promise<OpenClawConfig> {
|
||||
let cfg: OpenClawConfig;
|
||||
try {
|
||||
return loadConfig();
|
||||
} catch {
|
||||
return readBestEffortConfig();
|
||||
cfg = loadConfig();
|
||||
} catch (err) {
|
||||
if (isConfigValidationError(err)) {
|
||||
cfg = await readBestEffortConfig();
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
const cleaned = await cleanStaleMatrixPluginConfig(cfg);
|
||||
return cleaned.config;
|
||||
}
|
||||
|
||||
function isConfigValidationError(err: unknown): boolean {
|
||||
return err instanceof Error && (err as { code?: string }).code === "INVALID_CONFIG";
|
||||
}
|
||||
|
||||
export async function runPluginInstallCommand(params: {
|
||||
|
|
|
|||
|
|
@ -170,6 +170,8 @@ describe("doctor matrix provider helpers", () => {
|
|||
// Config should have stale refs removed
|
||||
expect(result.config.plugins?.installs?.matrix).toBeUndefined();
|
||||
expect(result.config.plugins?.load?.paths).toEqual(["/other/path"]);
|
||||
// Allowlist should have matrix removed but keep other entries
|
||||
expect(result.config.plugins?.allow).toEqual(["other-plugin"]);
|
||||
});
|
||||
|
||||
it("returns no changes when Matrix install path exists", async () => {
|
||||
|
|
|
|||
|
|
@ -184,6 +184,8 @@ export type CreatePluginRuntimeOptions = {
|
|||
export function createPluginRuntime(_options: CreatePluginRuntimeOptions = {}): PluginRuntime {
|
||||
const mediaUnderstanding = createRuntimeMediaUnderstandingFacade();
|
||||
const runtime = {
|
||||
// Sourced from the shared OpenClaw version resolver (#52899) so plugins
|
||||
// always see the same version the CLI reports, avoiding API-version drift.
|
||||
version: VERSION,
|
||||
config: createRuntimeConfig(),
|
||||
agent: createRuntimeAgent(),
|
||||
|
|
|
|||
Loading…
Reference in New Issue