fix: verify plugin config during install

This commit is contained in:
2026-04-04 17:30:56 +00:00
parent bcd47d8b39
commit f3a38d6455

View File

@@ -98,6 +98,14 @@ function setOpenclawConfig(key, value) {
exec(`openclaw config set ${key} '${JSON.stringify(value)}' --json`, { silent: true }); exec(`openclaw config set ${key} '${JSON.stringify(value)}' --json`, { silent: true });
} }
function assertConfigValue(key, predicate, description) {
const value = getOpenclawConfig(key, undefined);
if (!predicate(value)) {
throw new Error(`Config verification failed for ${key}: ${description}`);
}
return value;
}
function unsetOpenclawConfig(key) { function unsetOpenclawConfig(key) {
try { exec(`openclaw config unset ${key}`, { silent: true }); } catch {} try { exec(`openclaw config unset ${key}`, { silent: true }); } catch {}
} }
@@ -359,6 +367,7 @@ async function configure() {
paths.push(destDir); paths.push(destDir);
setOpenclawConfig('plugins.load.paths', paths); setOpenclawConfig('plugins.load.paths', paths);
} }
assertConfigValue('plugins.load.paths', (value) => Array.isArray(value) && value.includes(destDir), `missing ${destDir}`);
logOk(`plugins.load.paths includes ${destDir}`); logOk(`plugins.load.paths includes ${destDir}`);
const allow = getOpenclawConfig('plugins.allow', []); const allow = getOpenclawConfig('plugins.allow', []);
@@ -366,6 +375,7 @@ async function configure() {
allow.push(PLUGIN_NAME); allow.push(PLUGIN_NAME);
setOpenclawConfig('plugins.allow', allow); setOpenclawConfig('plugins.allow', allow);
} }
assertConfigValue('plugins.allow', (value) => Array.isArray(value) && value.includes(PLUGIN_NAME), `missing ${PLUGIN_NAME}`);
logOk(`plugins.allow includes ${PLUGIN_NAME}`); logOk(`plugins.allow includes ${PLUGIN_NAME}`);
const enabledKey = `plugins.entries.${PLUGIN_NAME}.enabled`; const enabledKey = `plugins.entries.${PLUGIN_NAME}.enabled`;
@@ -376,6 +386,8 @@ async function configure() {
if (getOpenclawConfig(configEnabledKey, undefined) === undefined) { if (getOpenclawConfig(configEnabledKey, undefined) === undefined) {
setOpenclawConfig(configEnabledKey, true); setOpenclawConfig(configEnabledKey, true);
} }
assertConfigValue(enabledKey, (value) => value === true, 'expected true');
assertConfigValue(configEnabledKey, (value) => value === true, 'expected true');
if (options.installMonitor === 'yes') { if (options.installMonitor === 'yes') {
const binaryPath = join(openclawPath, 'plugins', PLUGIN_NAME, 'bin', 'HarborForge.Monitor'); const binaryPath = join(openclawPath, 'plugins', PLUGIN_NAME, 'bin', 'HarborForge.Monitor');
@@ -383,13 +395,15 @@ async function configure() {
if (getOpenclawConfig(managedMonitorKey, undefined) === undefined) { if (getOpenclawConfig(managedMonitorKey, undefined) === undefined) {
setOpenclawConfig(managedMonitorKey, binaryPath); setOpenclawConfig(managedMonitorKey, binaryPath);
} }
assertConfigValue(managedMonitorKey, (value) => value === binaryPath, `expected ${binaryPath}`);
logOk(`managedMonitor configured → ${binaryPath}`); logOk(`managedMonitor configured → ${binaryPath}`);
} }
logOk('Plugin configured (remember to set apiKey in plugins.entries.harbor-forge.config)'); logOk('Plugin configured (remember to set apiKey in plugins.entries.harbor-forge.config)');
} catch (err) { } catch (err) {
logWarn(`Config failed: ${err.message}`); logErr(`Config failed: ${err.message}`);
throw err;
} }
} }