mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:20:43 +00:00
fix: allow run context during activation
This commit is contained in:
@@ -118,6 +118,39 @@ describe("plugin run context lifecycle", () => {
|
||||
).toEqual({ restored: true });
|
||||
});
|
||||
|
||||
it("allows run-context initialization during activating plugin registration", () => {
|
||||
const { config, registry } = createPluginRegistryFixture();
|
||||
const api = registry.createApi(
|
||||
createPluginRecord({
|
||||
id: "registration-run-context-plugin",
|
||||
name: "Registration Run Context Plugin",
|
||||
}),
|
||||
{ config },
|
||||
);
|
||||
|
||||
expect(
|
||||
api.setRunContext({
|
||||
runId: "run-registration",
|
||||
namespace: "state",
|
||||
value: { initialized: true },
|
||||
}),
|
||||
).toBe(true);
|
||||
expect(
|
||||
getPluginRunContext({
|
||||
pluginId: "registration-run-context-plugin",
|
||||
get: { runId: "run-registration", namespace: "state" },
|
||||
}),
|
||||
).toEqual({ initialized: true });
|
||||
|
||||
api.clearRunContext({ runId: "run-registration", namespace: "state" });
|
||||
expect(
|
||||
getPluginRunContext({
|
||||
pluginId: "registration-run-context-plugin",
|
||||
get: { runId: "run-registration", namespace: "state" },
|
||||
}),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("keeps restored active registry state after stale async cleanup finishes", async () => {
|
||||
let releaseCleanup: (() => void) | undefined;
|
||||
let markCleanupStarted: (() => void) | undefined;
|
||||
|
||||
@@ -2194,10 +2194,17 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) {
|
||||
const registrationCapabilities = resolvePluginRegistrationCapabilities(registrationMode);
|
||||
pluginRuntimeRecordById.set(record.id, record);
|
||||
const sideEffectGuard = createPluginSideEffectGuard(record.id);
|
||||
const isLoadedRecordInRegistry = () =>
|
||||
registry.plugins.some((plugin) => plugin.id === record.id && plugin.status === "loaded");
|
||||
const isActivatingLoadedRecord = () =>
|
||||
registryParams.activateGlobalSideEffects !== false &&
|
||||
record.enabled &&
|
||||
record.status === "loaded" &&
|
||||
!registry.plugins.some((plugin) => plugin.id === record.id);
|
||||
const shouldCommitWorkflowSideEffect = () =>
|
||||
sideEffectGuard.active &&
|
||||
!isPluginRegistryRetired(registry) &&
|
||||
registry.plugins.some((plugin) => plugin.id === record.id && plugin.status === "loaded");
|
||||
(isLoadedRecordInRegistry() || isActivatingLoadedRecord());
|
||||
return buildPluginApi({
|
||||
id: record.id,
|
||||
name: record.name,
|
||||
|
||||
Reference in New Issue
Block a user