Write plugin versions while loading configs

The staging copy made by Config.set() went through the constructor, so
plugin migrations ran a second time on the live fields. A version-gated
migration was applied twice when setPluginVersions() changed the version.
Staging now copies the fields with update() instead.

A config saved without <plugin>.version got the running version as its
default, so setPluginVersions() saw no change and nothing saved the stamp.
The constructor now writes the registered plugin versions after the
migrations run and marks the config dirty when that changes a loaded value.
Controller.bootstrap() saves the instances that came out dirty, and
setPluginVersions() is gone.

Restructure the SyncHook and plugin config tests by method, and suggest the
controller config version for role migrations in the docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-10-14 16:37:03 +00:00
1 parent aec0fc7a1e
commit e455d17bb7
10 files changed
+188 -119

No files matched your search

+2 -23
View File
@@ -812,10 +812,10 @@ export function addPluginFieldDefinitions(
Config.fieldDefinitions[`${pluginInfo.name}.load_plugin`] = fieldDef;
// Version of the plugin the config was last loaded with, see setPluginVersions
// Version of the plugin the config was last loaded with, see Config.pluginVersions
Config.fieldDefinitions[`${pluginInfo.name}.version`] = {
type: "string",
initialValue: "version" in pluginInfo ? pluginInfo.version : "",
initialValue: "",
readonly: ["controller", "host"],
hidden: true,
};
@@ -845,24 +845,3 @@ export function addPluginConfigFields(pluginInfos: PluginNodeEnvInfo[] | PluginW
}
}
/**
* Set the version field of each plugin to the version that was loaded
*
* Done after loading a config so the plugin migrations can compare the
* stored version against the one now running.
*
* @param config - Config to update.
* @param pluginInfos - Plugins loaded.
* @returns true if any version changed.
*/
export function setPluginVersions(config: classes.Config<any>, pluginInfos: PluginNodeEnvInfo[]) {
let changed = false;
for (const pluginInfo of pluginInfos) {
const name = `${pluginInfo.name}.version`;
if (config.constructor.fieldDefinitions[name] && config.get(name) !== pluginInfo.version) {
config.set(name, pluginInfo.version);
changed = true;
}
}
return changed;
}